Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGShutter.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 18/9/2000
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TGShutter
14 \ingroup guiwidgets
15
16A shutter widget contains a set of shutter items that can be
17open and closed like a shutter.
18This widget is usefull to group a large number of options in
19a number of categories.
20
21*/
22
23
24#include "TGShutter.h"
25#include "TGButton.h"
26#include "TList.h"
27#include "TTimer.h"
28
29#include <iostream>
30
31
34
35////////////////////////////////////////////////////////////////////////////////
36/// Create shutter frame.
37
39 TGCompositeFrame(p, 10, 10, options)
40{
41 fSelectedItem = 0;
42 fClosingItem = 0;
46 fTimer = 0;
47 fTrash = new TList;
48
50
51 // layout manager is not used
52 delete fLayoutManager;
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Cleanup shutter widget.
58
60{
61 if (fTimer) delete fTimer;
62
63 if (!MustCleanup()) {
64 fTrash->Delete();
65 }
66 delete fTrash;
67 fTrash = 0;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Add shutter item to shutter frame.
72
74{
76 AddFrame(item, hints);
77 fTrash->Add(hints);
78 if (!fSelectedItem) {
79 fSelectedItem = item;
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Remove item from shutter
85
86void TGShutter::RemoveItem(const char *name)
87{
88 TGShutterItem *item = GetItem(name);
89
90 if (!item) {
91 return;
92 }
93
94 if (fList->GetEntries() <= 1) {
95 return;
96 }
97
98 if (item == fSelectedItem) {
100 if (fe) {
102 if (!sel) {
103 sel = (TGFrameElement*)fList->After(fe);
104 }
105 if (!sel) {
106 return;
107 }
109 }
110 }
111 RemoveFrame(item);
112
113 item->DestroyWindow();
114 delete item;
115 Layout();
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Remove selected page
120
122{
123 if (!fSelectedItem) {
124 return;
125 }
127 RemoveItem(btn->GetString().Data());
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Rename selected page
132
134{
135 if (!fSelectedItem) {
136 return;
137 }
139 btn->SetText(name);
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Add new page (shutter item)
144
146{
147 static int id = 1000;
148 TGShutterItem *item = new TGShutterItem(this, new TGHotString(name), id++);
149 AddItem(item);
151 Layout();
152 return item;
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Handle shutter messages.
157
159{
160 if (!fList) return kFALSE;
161
162 TGFrameElement *el;
163 TGShutterItem *child, *item = 0;
164
165 TIter next(fList);
166 while ((el = (TGFrameElement *) next())) {
167 child = (TGShutterItem *) el->fFrame;
168 if (parm1 == child->WidgetId()) {
169 item = child;
170 break;
171 }
172 }
173
174 if (!item) return kFALSE;
175
176 if (!fSelectedItem)
178 if (fSelectedItem == item) return kTRUE;
179
184 fSelectedItem = item;
187
188 if (!fTimer) fTimer = new TTimer(this, 6); //10);
189 fTimer->Reset();
190 fTimer->TurnOn();
191
192 return kTRUE;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Shutter item animation.
197
199{
200 if (!fClosingItem) return kFALSE;
202 fHeightIncrement += 5;
203 if (fClosingHeight > 0) {
204 fTimer->Reset();
205 } else {
206 fClosingItem = 0;
207 fClosingHeight = 0;
208 fTimer->TurnOff();
209 }
210 Layout();
211
212 return kTRUE;
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Layout shutter items.
217
219{
220 TGFrameElement *el;
222 Int_t y, bh, exh;
223
224 if (!fList) return;
225
226 if (!fSelectedItem)
228
229 exh = Int_t(fHeight - (fBorderWidth << 1));
230 TIter next(fList);
231 while ((el = (TGFrameElement *) next())) {
232 child = (TGShutterItem *) el->fFrame;
233 bh = child->fButton->GetDefaultHeight();
234 exh -= bh;
235 }
236
237 y = fBorderWidth;
238 next.Reset();
239 while ((el = (TGFrameElement *) next())) {
240 child = (TGShutterItem *) el->fFrame;
241 bh = child->fButton->GetDefaultHeight();
242 if (child == fSelectedItem) {
243 if (fClosingItem)
244 child->fCanvas->SetScrolling(TGCanvas::kCanvasNoScroll);
245 else
246 child->fCanvas->SetScrolling(TGCanvas::kCanvasScrollVertical);
247 child->ShowFrame(child->fCanvas);
248 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
249 exh - fClosingHeight + bh);
250 y += exh - fClosingHeight + bh;
251 } else if (child == fClosingItem) {
252 child->fCanvas->SetScrolling(TGCanvas::kCanvasNoScroll);
253 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
254 fClosingHeight + bh);
255 y += fClosingHeight + bh;
256 } else {
257 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1), bh);
258 child->HideFrame(child->fCanvas);
259 y += bh;
260 }
261 }
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Set item to be the currently open shutter item.
266
268{
269 fSelectedItem = item;
270 fSelectedItem->Selected(); // emit signal
271 Layout();
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Set item to be the currently open shutter item.
276
278{
279 TGShutterItem *item = GetItem(name);
280 if (!item) {
281 return;
282 }
283 SetSelectedItem(item);
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Disable/enbale shutter item.
288
290{
291 TGShutterItem *item = GetItem(name);
292 if (!item) {
293 return;
294 }
295
296 item->GetButton()->SetEnabled(on);
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// returns a shutter item by name (name is hot string of shutter item)
301
303{
304 TGFrameElement *el;
305 TGShutterItem *item = 0;
306
307 TIter next(fList);
308
309 while ((el = (TGFrameElement *) next())) {
310 TGTextButton *btn;
311 item = (TGShutterItem *)el->fFrame;
312 btn = (TGTextButton*)item->GetButton();
313 if (btn->GetString() == name) return item;
314 }
315
316 return item;
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Return the default / minimal size of the widget.
321
323{
326 return TGDimension(w, h);
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Set the default / minimal size of the widget.
331
333{
334 fDefWidth = w;
335 fDefHeight = h;
336}
337
338
339////////////////////////////////////////////////////////////////////////////////
340/// Create a shutter item.
341
343 UInt_t options) :
344 TGVerticalFrame (p, 10, 10, options), TGWidget (id)
345{
346 if (!p && !s) {
347 MakeZombie();
348 // coverity [uninit_ctor]
349 return;
350 }
351 fButton = new TGTextButton(this, s, id);
352 fCanvas = new TGCanvas(this, 10, 10, kChildFrame);
356
359
361
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Clan up shutter item.
370
372{
373 if (!IsZombie() && !MustCleanup()) {
374 delete fL1;
375 delete fL2;
376 delete fButton;
377 delete fContainer;
378 delete fCanvas;
379 }
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Save a shutter item widget as a C++ statement(s) on output stream out
384
385void TGShutterItem::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
386{
387 char quote = '"';
389 const char *text = b->GetText()->GetString();
390 char hotpos = b->GetText()->GetHotPos();
391 Int_t lentext = b->GetText()->GetLength();
392 char *outext = new char[lentext+2]; // should be +2 because of \0
393 Int_t i=0;
394
395 while (lentext) {
396 if (i == hotpos-1) {
397 outext[i] = '&';
398 i++;
399 }
400 outext[i] = *text;
401 i++;
402 text++;
403 lentext--;
404 }
405 outext[i]=0;
406
407 out << std::endl;
408 out << " // " << quote << outext << quote << " shutter item " << std::endl;
409 out << " TGShutterItem *";
410 out << GetName() << " = new TGShutterItem(" << fParent->GetName()
411 << ", new TGHotString(" << quote << outext << quote << "),"
412 << fButton->WidgetId() << "," << GetOptionString() << ");" << std::endl;
413
414 delete [] outext;
415 if (option && strstr(option, "keep_names"))
416 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
417
418 TList *list = ((TGCompositeFrame *)GetContainer())->GetList();
419
420 if (!list) return;
421
422 out << " TGCompositeFrame *" << GetContainer()->GetName()
423 << " = (TGCompositeFrame *)" << GetName() << "->GetContainer();" << std::endl;
424
425 TGFrameElement *el;
426 TIter next(list);
427
428 while ((el = (TGFrameElement *) next())) {
429 el->fFrame->SavePrimitive(out, option);
430 out << " " << GetContainer()->GetName() <<"->AddFrame(" << el->fFrame->GetName();
431 el->fLayout->SavePrimitive(out, option);
432 out << ");"<< std::endl;
433 }
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Save a shutter widget as a C++ statement(s) on output stream out.
438
439void TGShutter::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
440{
441 out << std::endl;
442 out << " // shutter" << std::endl;
443
444 out << " TGShutter *";
445 out << GetName() << " = new TGShutter(" << fParent->GetName() << ","
446 << GetOptionString() << ");" << std::endl;
447
448 if ((fDefWidth > 0) || (fDefHeight > 0)) {
449 out << " " << GetName() << "->SetDefaultSize(";
450 out << fDefWidth << "," << fDefHeight << ");" << std::endl;
451 }
452 if (option && strstr(option, "keep_names"))
453 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
454
455 if (!fList) return;
456
457 TGFrameElement *el;
458 TIter next(fList);
459
460 while ((el = (TGFrameElement *) next())) {
461 el->fFrame->SavePrimitive(out, option);
462 out << " " << GetName() <<"->AddItem(" << el->fFrame->GetName();
463 //el->fLayout->SavePrimitive(out, option);
464 out << ");"<< std::endl;
465 }
466
467 out << " " << GetName() << "->SetSelectedItem("
468 << GetSelectedItem()->GetName() << ");" << std::endl;
469 out << " " <<GetName()<< "->Resize("<<GetWidth()<<","<<GetHeight()<<");"<<std::endl;
470}
471
@ kChildFrame
Definition GuiTypes.h:379
@ kFixedWidth
Definition GuiTypes.h:387
@ kFixedHeight
Definition GuiTypes.h:389
@ kOwnBackground
Definition GuiTypes.h:391
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:110
virtual Int_t GetEntries() const
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:459
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
Definition TGCanvas.h:192
virtual void SetContainer(TGFrame *f)
Definition TGCanvas.h:222
TGViewPort * GetViewPort() const
Definition TGCanvas.h:217
@ kCanvasNoScroll
Definition TGCanvas.h:205
@ kCanvasScrollVertical
Definition TGCanvas.h:207
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition TGClient.cxx:481
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
TGLayoutManager * fLayoutManager
layout manager
Definition TGFrame.h:291
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual TList * GetList() const
Definition TGFrame.h:310
Int_t MustCleanup() const override
Definition TGFrame.h:360
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
TList * fList
container of frame elements
Definition TGFrame.h:292
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1149
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a frame widget as a C++ statement(s) on output stream out.
Definition TGFrame.cxx:3230
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:312
TGFrameElement * GetFrameElement() const
Definition TGFrame.h:235
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save layout hints as a C++ statement(s) on output stream out.
Definition TGLayout.cxx:975
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a shutter item widget as a C++ statement(s) on output stream out.
TGLayoutHints * fL2
positioning hints
Definition TGShutter.h:33
TGFrame * fContainer
container in canvas containing shutter items
Definition TGShutter.h:32
~TGShutterItem() override
Clan up shutter item.
TGCanvas * fCanvas
canvas of shutter item
Definition TGShutter.h:31
TGLayoutHints * fL1
Definition TGShutter.h:33
TGButton * GetButton() const
Definition TGShutter.h:44
virtual void Selected()
Definition TGShutter.h:46
TGButton * fButton
shutter item button
Definition TGShutter.h:30
TGShutterItem(const TGShutterItem &)=delete
TGFrame * GetContainer() const
Definition TGShutter.h:45
A shutter widget contains a set of shutter items that can be open and closed like a shutter.
Definition TGShutter.h:55
virtual void AddItem(TGShutterItem *item)
Add shutter item to shutter frame.
Definition TGShutter.cxx:73
virtual void RemovePage()
Remove selected page.
TGShutterItem * fClosingItem
Item closing down.
Definition TGShutter.h:60
TGDimension GetDefaultSize() const override
Return the default / minimal size of the widget.
TTimer * fTimer
Timer for animation.
Definition TGShutter.h:58
Bool_t ProcessMessage(Longptr_t cmd, Longptr_t parm1, Longptr_t parm2) override
Handle shutter messages.
TGShutterItem * GetItem(const char *name)
returns a shutter item by name (name is hot string of shutter item)
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a shutter widget as a C++ statement(s) on output stream out.
UInt_t fDefHeight
Default height.
Definition TGShutter.h:66
TGShutterItem * fSelectedItem
Item currently open.
Definition TGShutter.h:59
virtual void EnableItem(const char *name, Bool_t on=kTRUE)
Disable/enbale shutter item.
virtual void SetSelectedItem(TGShutterItem *item)
Set item to be the currently open shutter item.
TGShutter(const TGShutter &)=delete
TList * fTrash
Items that need to be cleaned up.
Definition TGShutter.h:61
Int_t fHeightIncrement
Height delta.
Definition TGShutter.h:62
virtual void SetDefaultSize(UInt_t w, UInt_t h)
Set the default / minimal size of the widget.
void Layout() override
Layout shutter items.
Int_t fClosingHeight
Closing items current height.
Definition TGShutter.h:63
virtual void Selected(TGShutterItem *item)
Definition TGShutter.h:96
TGShutterItem * GetSelectedItem() const
Definition TGShutter.h:84
Int_t fClosingHadScrollbar
Closing item had a scroll bar.
Definition TGShutter.h:64
~TGShutter() override
Cleanup shutter widget.
Definition TGShutter.cxx:59
virtual TGShutterItem * AddPage(const char *item="Page")
Add new page (shutter item)
virtual void RenamePage(const char *name)
Rename selected page.
UInt_t fDefWidth
Default width.
Definition TGShutter.h:65
Bool_t HandleTimer(TTimer *t) override
Shutter item animation.
virtual void RemoveItem(const char *name)
Remove item from shutter.
Definition TGShutter.cxx:86
Yield an action as soon as it is clicked.
Definition TGButton.h:142
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition TGButton.cxx:644
TString GetString() const
Definition TGButton.h:191
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
The widget base class.
Definition TGWidget.h:43
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
Int_t WidgetId() const
Definition TGWidget.h:68
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition TGWindow.h:113
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableLayout
window layout cannot be edited
Definition TGWindow.h:60
@ kEditDisableBtnEnable
window can handle mouse button events
Definition TGWindow.h:64
@ kEditDisableGrab
window grab cannot be edited
Definition TGWindow.h:59
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:192
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void Reset()
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:328
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
Definition TList.cxx:369
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:83
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:153
void MakeZombie()
Definition TObject.h:53
const char * Data() const
Definition TString.h:376
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOff()
Remove timer from system timer list.
Definition TTimer.cxx:231
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:243
void Reset()
Reset the timer.
Definition TTimer.cxx:159
Double_t y[n]
Definition legend1.C:17