Logo ROOT  
Reference Guide
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// //
14// TGShutter, TGShutterItem //
15// //
16// A shutter widget contains a set of shutter items that can be //
17// open and closed like a shutter. //
18// This widget is usefull to group a large number of options in //
19// a number of categories. //
20// //
21//////////////////////////////////////////////////////////////////////////
22
23#include "TGShutter.h"
24#include "TGButton.h"
25#include "TList.h"
26#include "TTimer.h"
27#include "Riostream.h"
28
29
32
33////////////////////////////////////////////////////////////////////////////////
34/// Create shutter frame.
35
37 TGCompositeFrame(p, 10, 10, options)
38{
39 fSelectedItem = 0;
40 fClosingItem = 0;
44 fTimer = 0;
45 fTrash = new TList;
46
48
49 // layout manager is not used
50 delete fLayoutManager;
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Cleanup shutter widget.
56
58{
59 if (fTimer) delete fTimer;
60
61 if (!MustCleanup()) {
62 fTrash->Delete();
63 }
64 delete fTrash;
65 fTrash = 0;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Add shutter item to shutter frame.
70
72{
74 AddFrame(item, hints);
75 fTrash->Add(hints);
76 if (!fSelectedItem) {
77 fSelectedItem = item;
78 }
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Remove item from shutter
83
84void TGShutter::RemoveItem(const char *name)
85{
86 TGShutterItem *item = GetItem(name);
87
88 if (!item) {
89 return;
90 }
91
92 if (fList->GetEntries() <= 1) {
93 return;
94 }
95
96 if (item == fSelectedItem) {
98 if (fe) {
100 if (!sel) {
101 sel = (TGFrameElement*)fList->After(fe);
102 }
103 if (!sel) {
104 return;
105 }
107 }
108 }
109 RemoveFrame(item);
110
111 item->DestroyWindow();
112 delete item;
113 Layout();
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Remove selected page
118
120{
121 if (!fSelectedItem) {
122 return;
123 }
125 RemoveItem(btn->GetString().Data());
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Rename selected page
130
132{
133 if (!fSelectedItem) {
134 return;
135 }
137 btn->SetText(name);
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Add new page (shutter item)
142
144{
145 static int id = 1000;
146 TGShutterItem *item = new TGShutterItem(this, new TGHotString(name), id++);
147 AddItem(item);
149 Layout();
150 return item;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Handle shutter messages.
155
157{
158 if (!fList) return kFALSE;
159
160 TGFrameElement *el;
161 TGShutterItem *child, *item = 0;
162
163 TIter next(fList);
164 while ((el = (TGFrameElement *) next())) {
165 child = (TGShutterItem *) el->fFrame;
166 if (parm1 == child->WidgetId()) {
167 item = child;
168 break;
169 }
170 }
171
172 if (!item) return kFALSE;
173
174 if (!fSelectedItem)
176 if (fSelectedItem == item) return kTRUE;
177
182 fSelectedItem = item;
185
186 if (!fTimer) fTimer = new TTimer(this, 6); //10);
187 fTimer->Reset();
188 fTimer->TurnOn();
189
190 return kTRUE;
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Shutter item animation.
195
197{
198 if (!fClosingItem) return kFALSE;
200 fHeightIncrement += 5;
201 if (fClosingHeight > 0) {
202 fTimer->Reset();
203 } else {
204 fClosingItem = 0;
205 fClosingHeight = 0;
206 fTimer->TurnOff();
207 }
208 Layout();
209
210 return kTRUE;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Layout shutter items.
215
217{
218 TGFrameElement *el;
219 TGShutterItem *child;
220 Int_t y, bh, exh;
221
222 if (!fList) return;
223
224 if (!fSelectedItem)
226
227 exh = Int_t(fHeight - (fBorderWidth << 1));
228 TIter next(fList);
229 while ((el = (TGFrameElement *) next())) {
230 child = (TGShutterItem *) el->fFrame;
231 bh = child->fButton->GetDefaultHeight();
232 exh -= bh;
233 }
234
235 y = fBorderWidth;
236 next.Reset();
237 while ((el = (TGFrameElement *) next())) {
238 child = (TGShutterItem *) el->fFrame;
239 bh = child->fButton->GetDefaultHeight();
240 if (child == fSelectedItem) {
241 if (fClosingItem)
243 else
245 child->ShowFrame(child->fCanvas);
246 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
247 exh - fClosingHeight + bh);
248 y += exh - fClosingHeight + bh;
249 } else if (child == fClosingItem) {
251 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1),
252 fClosingHeight + bh);
253 y += fClosingHeight + bh;
254 } else {
255 child->MoveResize(fBorderWidth, y, fWidth - (fBorderWidth << 1), bh);
256 child->HideFrame(child->fCanvas);
257 y += bh;
258 }
259 }
260}
261
262////////////////////////////////////////////////////////////////////////////////
263/// Set item to be the currently open shutter item.
264
266{
267 fSelectedItem = item;
268 fSelectedItem->Selected(); // emit signal
269 Layout();
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Set item to be the currently open shutter item.
274
276{
277 TGShutterItem *item = GetItem(name);
278 if (!item) {
279 return;
280 }
281 SetSelectedItem(item);
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Disable/enbale shutter item.
286
287void TGShutter::EnableItem(const char *name, Bool_t on)
288{
289 TGShutterItem *item = GetItem(name);
290 if (!item) {
291 return;
292 }
293
294 item->GetButton()->SetEnabled(on);
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// returns a shutter item by name (name is hot string of shutter item)
299
301{
302 TGFrameElement *el;
303 TGShutterItem *item = 0;
304
305 TIter next(fList);
306
307 while ((el = (TGFrameElement *) next())) {
308 TGTextButton *btn;
309 item = (TGShutterItem *)el->fFrame;
310 btn = (TGTextButton*)item->GetButton();
311 if (btn->GetString() == name) return item;
312 }
313
314 return item;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Return the default / minimal size of the widget.
319
321{
322 UInt_t w = (GetOptions() & kFixedWidth) || (fDefWidth == 0) ? fWidth : fDefWidth;
324 return TGDimension(w, h);
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Set the default / minimal size of the widget.
329
331{
332 fDefWidth = w;
333 fDefHeight = h;
334}
335
336
337////////////////////////////////////////////////////////////////////////////////
338/// Create a shutter item.
339
341 UInt_t options) :
342 TGVerticalFrame (p, 10, 10, options), TGWidget (id)
343{
344 if (!p && !s) {
345 MakeZombie();
346 // coverity [uninit_ctor]
347 return;
348 }
349 fButton = new TGTextButton(this, s, id);
350 fCanvas = new TGCanvas(this, 10, 10, kChildFrame);
354
357
358 fButton->Associate((TGFrame *) p);
359
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Clan up shutter item.
368
370{
371 if (!IsZombie() && !MustCleanup()) {
372 delete fL1;
373 delete fL2;
374 delete fButton;
375 delete fContainer;
376 delete fCanvas;
377 }
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Save a shutter item widget as a C++ statement(s) on output stream out
382
383void TGShutterItem::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
384{
385 char quote = '"';
387 const char *text = b->GetText()->GetString();
388 char hotpos = b->GetText()->GetHotPos();
389 Int_t lentext = b->GetText()->GetLength();
390 char *outext = new char[lentext+2]; // should be +2 because of \0
391 Int_t i=0;
392
393 while (lentext) {
394 if (i == hotpos-1) {
395 outext[i] = '&';
396 i++;
397 }
398 outext[i] = *text;
399 i++;
400 text++;
401 lentext--;
402 }
403 outext[i]=0;
404
405 out << std::endl;
406 out << " // " << quote << outext << quote << " shutter item " << std::endl;
407 out << " TGShutterItem *";
408 out << GetName() << " = new TGShutterItem(" << fParent->GetName()
409 << ", new TGHotString(" << quote << outext << quote << "),"
410 << fButton->WidgetId() << "," << GetOptionString() << ");" << std::endl;
411
412 delete [] outext;
413 if (option && strstr(option, "keep_names"))
414 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
415
416 TList *list = ((TGCompositeFrame *)GetContainer())->GetList();
417
418 if (!list) return;
419
420 out << " TGCompositeFrame *" << GetContainer()->GetName()
421 << " = (TGCompositeFrame *)" << GetName() << "->GetContainer();" << std::endl;
422
423 TGFrameElement *el;
424 TIter next(list);
425
426 while ((el = (TGFrameElement *) next())) {
427 el->fFrame->SavePrimitive(out, option);
428 out << " " << GetContainer()->GetName() <<"->AddFrame(" << el->fFrame->GetName();
429 el->fLayout->SavePrimitive(out, option);
430 out << ");"<< std::endl;
431 }
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Save a shutter widget as a C++ statement(s) on output stream out.
436
437void TGShutter::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
438{
439 out << std::endl;
440 out << " // shutter" << std::endl;
441
442 out << " TGShutter *";
443 out << GetName() << " = new TGShutter(" << fParent->GetName() << ","
444 << GetOptionString() << ");" << std::endl;
445
446 if ((fDefWidth > 0) || (fDefHeight > 0)) {
447 out << " " << GetName() << "->SetDefaultSize(";
448 out << fDefWidth << "," << fDefHeight << ");" << std::endl;
449 }
450 if (option && strstr(option, "keep_names"))
451 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
452
453 if (!fList) return;
454
455 TGFrameElement *el;
456 TIter next(fList);
457
458 while ((el = (TGFrameElement *) next())) {
459 el->fFrame->SavePrimitive(out, option);
460 out << " " << GetName() <<"->AddItem(" << el->fFrame->GetName();
461 //el->fLayout->SavePrimitive(out, option);
462 out << ");"<< std::endl;
463 }
464
465 out << " " << GetName() << "->SetSelectedItem("
466 << GetSelectedItem()->GetName() << ");" << std::endl;
467 out << " " <<GetName()<< "->Resize("<<GetWidth()<<","<<GetHeight()<<");"<<std::endl;
468}
469
@ 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:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
@ kLHintsExpandY
Definition: TGLayout.h:38
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
virtual Int_t GetEntries() const
Definition: TCollection.h:177
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:411
virtual void SetContainer(TGFrame *f)
Definition: TGCanvas.h:232
TGViewPort * GetViewPort() const
Definition: TGCanvas.h:227
@ kCanvasNoScroll
Definition: TGCanvas.h:215
@ kCanvasScrollVertical
Definition: TGCanvas.h:217
void SetScrolling(Int_t scrolling)
Set scrolling policy.
Definition: TGCanvas.cxx:2418
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:480
TGLayoutManager * fLayoutManager
Definition: TGFrame.h:328
virtual TList * GetList() const
Definition: TGFrame.h:347
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual Int_t MustCleanup() const
Definition: TGFrame.h:398
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1188
TList * fList
Definition: TGFrame.h:329
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1133
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1174
TGLayoutHints * fLayout
Definition: TGLayout.h:121
TGFrame * fFrame
Definition: TGLayout.h:119
UInt_t fHeight
Definition: TGFrame.h:113
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
Int_t fBorderWidth
Definition: TGFrame.h:118
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a frame widget as a C++ statement(s) on output stream out.
Definition: TGFrame.cxx:3191
TGFrameElement * GetFrameElement() const
Definition: TGFrame.h:260
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:296
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:667
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2464
UInt_t fWidth
Definition: TGFrame.h:112
UInt_t GetHeight() const
Definition: TGFrame.h:250
virtual void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0)
Move and/or resize the frame.
Definition: TGFrame.cxx:613
UInt_t GetWidth() const
Definition: TGFrame.h:249
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1003
TGClient * fClient
Definition: TGObject.h:37
TGShutterItem(const TGShutterItem &)
TGLayoutHints * fL2
Definition: TGShutter.h:47
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a shutter item widget as a C++ statement(s) on output stream out.
Definition: TGShutter.cxx:383
TGFrame * fContainer
Definition: TGShutter.h:46
virtual ~TGShutterItem()
Clan up shutter item.
Definition: TGShutter.cxx:369
TGCanvas * fCanvas
Definition: TGShutter.h:45
TGLayoutHints * fL1
Definition: TGShutter.h:47
TGButton * GetButton() const
Definition: TGShutter.h:58
virtual void Selected()
Definition: TGShutter.h:60
TGButton * fButton
Definition: TGShutter.h:44
TGFrame * GetContainer() const
Definition: TGShutter.h:59
virtual void AddItem(TGShutterItem *item)
Add shutter item to shutter frame.
Definition: TGShutter.cxx:71
virtual void RemovePage()
Remove selected page.
Definition: TGShutter.cxx:119
TGShutterItem * fClosingItem
Definition: TGShutter.h:74
TTimer * fTimer
Definition: TGShutter.h:72
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a shutter widget as a C++ statement(s) on output stream out.
Definition: TGShutter.cxx:437
TGShutterItem * GetItem(const char *name)
returns a shutter item by name (name is hot string of shutter item)
Definition: TGShutter.cxx:300
virtual void Layout()
Layout shutter items.
Definition: TGShutter.cxx:216
virtual Bool_t HandleTimer(TTimer *t)
Shutter item animation.
Definition: TGShutter.cxx:196
UInt_t fDefHeight
Definition: TGShutter.h:80
TGShutterItem * fSelectedItem
Definition: TGShutter.h:73
virtual void EnableItem(const char *name, Bool_t on=kTRUE)
Disable/enbale shutter item.
Definition: TGShutter.cxx:287
virtual void SetSelectedItem(TGShutterItem *item)
Set item to be the currently open shutter item.
Definition: TGShutter.cxx:265
TList * fTrash
Definition: TGShutter.h:75
Int_t fHeightIncrement
Definition: TGShutter.h:76
virtual void SetDefaultSize(UInt_t w, UInt_t h)
Set the default / minimal size of the widget.
Definition: TGShutter.cxx:330
Int_t fClosingHeight
Definition: TGShutter.h:77
virtual TGDimension GetDefaultSize() const
Return the default / minimal size of the widget.
Definition: TGShutter.cxx:320
virtual void Selected(TGShutterItem *item)
Definition: TGShutter.h:110
TGShutterItem * GetSelectedItem() const
Definition: TGShutter.h:98
Int_t fClosingHadScrollbar
Definition: TGShutter.h:78
virtual TGShutterItem * AddPage(const char *item="Page")
Add new page (shutter item)
Definition: TGShutter.cxx:143
virtual ~TGShutter()
Cleanup shutter widget.
Definition: TGShutter.cxx:57
virtual Bool_t ProcessMessage(Long_t cmd, Long_t parm1, Long_t parm2)
Handle shutter messages.
Definition: TGShutter.cxx:156
virtual void RenamePage(const char *name)
Rename selected page.
Definition: TGShutter.cxx:131
TGShutter(const TGShutter &)
UInt_t fDefWidth
Definition: TGShutter.h:79
virtual void RemoveItem(const char *name)
Remove item from shutter.
Definition: TGShutter.cxx:84
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:596
TString GetString() const
Definition: TGButton.h:191
TGVerticalFrame(const TGWindow *p=0, UInt_t w=1, UInt_t h=1, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition: TGFrame.h:414
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
Int_t WidgetId() const
Definition: TGWidget.h:80
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:326
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:114
const TGWindow * fParent
Definition: TGWindow.h:36
@ kEditDisableLayout
Definition: TGWindow.h:61
@ kEditDisableBtnEnable
Definition: TGWindow.h:65
@ kEditDisableGrab
Definition: TGWindow.h:60
virtual void DestroyWindow()
destroy window
Definition: TGWindow.cxx:182
UInt_t fEditDisabled
Definition: TGWindow.h:40
void Reset()
Definition: TCollection.h:252
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:329
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TList.cxx:370
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition: TObject.h:149
void MakeZombie()
Definition: TObject.h:49
const char * Data() const
Definition: TString.h:364
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
virtual void TurnOff()
Remove timer from system timer list.
Definition: TTimer.cxx:229
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:241
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
TText * text
Double_t y[n]
Definition: legend1.C:17
static constexpr double s