ROOT  6.06/09
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 
36 TGShutter::TGShutter(const TGWindow *p, UInt_t options) :
37  TGCompositeFrame(p, 10, 10, options)
38 {
39  fSelectedItem = 0;
40  fClosingItem = 0;
41  fHeightIncrement = 1;
42  fClosingHeight = 0;
43  fClosingHadScrollbar = kFALSE;
44  fTimer = 0;
45  fTrash = new TList;
46 
47  fDefWidth = fDefHeight = 0;
48 
49  // layout manager is not used
50  delete fLayoutManager;
51  fLayoutManager = 0;
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 
84 void 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 
131 void TGShutter::RenamePage(const char *name)
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);
148  MapSubwindows();
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 
178  fHeightIncrement = 1;
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 
287 void 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 
383 void 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 
437 void 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 
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1172
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual void SetDefaultSize(UInt_t w, UInt_t h)
Set the default / minimal size of the widget.
Definition: TGShutter.cxx:330
const TGWindow * fParent
Definition: TGWindow.h:43
virtual Bool_t ProcessMessage(Long_t cmd, Long_t parm1, Long_t parm2)
Handle shutter messages.
Definition: TGShutter.cxx:156
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:404
virtual void RemovePage()
Remove selected page.
Definition: TGShutter.cxx:119
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:611
Int_t fBorderWidth
Definition: TGFrame.h:156
Int_t fHeightIncrement
Definition: TGShutter.h:82
void Reset()
Reset the timer.
Definition: TTimer.cxx:155
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual void EnableItem(const char *name, Bool_t on=kTRUE)
Disable/enbale shutter item.
Definition: TGShutter.cxx:287
const char Option_t
Definition: RtypesCore.h:62
virtual void Selected(TGShutterItem *item)
Definition: TGShutter.h:116
TH1 * h
Definition: legend2.C:5
UInt_t GetWidth() const
Definition: TGFrame.h:287
virtual void SetContainer(TGFrame *f)
Definition: TGCanvas.h:234
Bool_t IsZombie() const
Definition: TObject.h:141
virtual TList * GetList() const
Definition: TGFrame.h:385
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1186
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t HandleTimer(TTimer *t)
Shutter item animation.
Definition: TGShutter.cxx:196
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
Pixel_t GetShadow(Pixel_t base_color) const
Return pixel value of shadow color based on base_color.
Definition: TGClient.cxx:478
UInt_t GetHeight() const
Definition: TGFrame.h:288
TString GetString() const
Definition: TGButton.h:195
virtual void SetSelectedItem(TGShutterItem *item)
Set item to be the currently open shutter item.
Definition: TGShutter.cxx:265
void Reset()
Definition: TCollection.h:161
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1131
const char * Data() const
Definition: TString.h:349
virtual void AddItem(TGShutterItem *item)
Add shutter item to shutter frame.
Definition: TGShutter.cxx:71
TGLayoutHints * fLayout
Definition: TGLayout.h:127
ClassImp(TGShutterItem) ClassImp(TGShutter) TGShutter
Create shutter frame.
Definition: TGShutter.cxx:30
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:288
virtual TGDimension GetDefaultSize() const
Return the default / minimal size of the widget.
Definition: TGShutter.cxx:320
TTimer * fTimer
Definition: TGShutter.h:78
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual UInt_t GetOptions() const
Definition: TGFrame.h:260
virtual ~TGShutter()
Cleanup shutter widget.
Definition: TGShutter.cxx:57
TGButton * GetButton() const
Definition: TGShutter.h:64
TGLayoutHints * fL1
Definition: TGShutter.h:53
TGFrameElement * GetFrameElement() const
Definition: TGFrame.h:298
if(pyself &&pyself!=Py_None)
virtual void RemoveItem(const char *name)
Remove item from shutter.
Definition: TGShutter.cxx:84
virtual ~TGShutterItem()
Clan up shutter item.
Definition: TGShutter.cxx:369
TGShutterItem * GetItem(const char *name)
returns a shutter item by name (name is hot string of shutter item)
Definition: TGShutter.cxx:300
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
TList * fTrash
Definition: TGShutter.h:81
TGButton * fButton
Definition: TGShutter.h:50
char * out
Definition: TBase64.cxx:29
virtual TGShutterItem * AddPage(const char *item="Page")
Add new page (shutter item)
Definition: TGShutter.cxx:143
A doubly linked list.
Definition: TList.h:47
UInt_t fDefHeight
Definition: TGShutter.h:86
TGFrame * GetContainer() const
Definition: TGShutter.h:65
virtual Int_t MustCleanup() const
Definition: TGFrame.h:436
UInt_t fDefWidth
Definition: TGShutter.h:85
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:3188
TList * fList
Definition: TGFrame.h:367
virtual void Selected()
Definition: TGShutter.h:66
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TList.cxx:321
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:90
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
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void TurnOff()
Remove timer from system timer list.
Definition: TTimer.cxx:227
TGFrame * fFrame
Definition: TGLayout.h:125
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
TGVerticalFrame(const TGWindow *p=0, UInt_t w=1, UInt_t h=1, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition: TGFrame.h:452
TGLayoutHints * fL2
Definition: TGShutter.h:53
void SetScrolling(Int_t scrolling)
Set scrolling policy.
Definition: TGCanvas.cxx:2420
UInt_t fWidth
Definition: TGFrame.h:150
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:52
virtual void SetText(TGHotString *new_label)
Set new button text.
Definition: TGButton.cxx:594
virtual void Layout()
Layout shutter items.
Definition: TGShutter.cxx:216
Int_t WidgetId() const
Definition: TGWidget.h:86
long Long_t
Definition: RtypesCore.h:50
TGShutterItem(const TGShutterItem &)
TGShutterItem * GetSelectedItem() const
Definition: TGShutter.h:104
Int_t fClosingHeight
Definition: TGShutter.h:83
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
TText * text
Int_t GetLength() const
Definition: TGString.h:43
Double_t y[n]
Definition: legend1.C:17
TGShutterItem * fSelectedItem
Definition: TGShutter.h:79
TGCanvas * fCanvas
Definition: TGShutter.h:51
UInt_t fHeight
Definition: TGFrame.h:151
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGShutterItem * fClosingItem
Definition: TGShutter.h:80
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:556
virtual void SetEditDisabled(UInt_t on=kEditDisable)
Definition: TGWindow.h:119
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:254
virtual void Add(TObject *obj)
Definition: TList.h:81
TGClient * fClient
Definition: TGObject.h:41
void MakeZombie()
Definition: TObject.h:68
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
virtual void RenamePage(const char *name)
Rename selected page.
Definition: TGShutter.cxx:131
UInt_t fEditDisabled
Definition: TGWindow.h:47
const char * GetString() const
Definition: TGString.h:44
const TGHotString * GetText() const
Definition: TGButton.h:193
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:239
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
virtual void DestroyWindow()
Definition: TGWindow.h:94
Int_t GetHotPos() const
Definition: TGString.h:72
TGViewPort * GetViewPort() const
Definition: TGCanvas.h:229