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