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
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) {
97 TGFrameElement *fe = (TGFrameElement*)fList->FindObject(item->GetFrameElement());
98 if (fe) {
99 TGFrameElement *sel = (TGFrameElement*)fList->Before(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 }
124 TGTextButton *btn = (TGTextButton*)fSelectedItem->GetButton();
125 RemoveItem(btn->GetString().Data());
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Rename selected page
130
132{
133 if (!fSelectedItem) {
134 return;
135 }
136 TGTextButton *btn = (TGTextButton*)fSelectedItem->GetButton();
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)
175 fSelectedItem = (TGShutterItem*) ((TGFrameElement*)fList->First())->fFrame;
176 if (fSelectedItem == item) return kTRUE;
177
180 fClosingHeight = fClosingItem->GetHeight();
181 fClosingHeight -= fClosingItem->fButton->GetDefaultHeight();
182 fSelectedItem = item;
184 fSelectedItem->Selected();
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)
225 fSelectedItem = (TGShutterItem*) ((TGFrameElement*)GetList()->First())->fFrame;
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);
351 fContainer = new TGVerticalFrame(fCanvas->GetViewPort(), 10, 10, kOwnBackground);
352 fCanvas->SetContainer(fContainer);
353 fContainer->SetBackgroundColor(fClient->GetShadow(GetDefaultFrameBackground()));
354
357
358 fButton->Associate((TGFrame *) p);
359
360 fCanvas->SetEditDisabled(kEditDisableGrab | kEditDisableLayout);
362 fContainer->SetEditDisabled(kEditDisableGrab);
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{
386 TString outtext = b->GetText()->GetString();
387 Int_t hotpos = b->GetText()->GetHotPos();
388 if ((hotpos > 0) && (hotpos < outtext.Length()))
389 outtext.Insert(hotpos - 1, "&");
390
391 out << "\n // \"" << outtext << "\" shutter item \n";
392 out << " TGShutterItem *" << GetName() << " = new TGShutterItem(" << fParent->GetName() << ", new TGHotString(\""
393 << outtext.ReplaceSpecialCppChars() << "\"), " << fButton->WidgetId() << ", " << GetOptionString()
394 << ");\n";
395
396 if (option && strstr(option, "keep_names"))
397 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
398
399 TList *list = ((TGCompositeFrame *)GetContainer())->GetList();
400
401 if (!list)
402 return;
403
404 out << " TGCompositeFrame *" << GetContainer()->GetName() << " = (TGCompositeFrame *)" << GetName()
405 << "->GetContainer();\n";
406
407 TIter next(list);
408 while (auto el = static_cast<TGFrameElement *>(next())) {
409 el->fFrame->SavePrimitive(out, option);
410 out << " " << GetContainer()->GetName() << "->AddFrame(" << el->fFrame->GetName();
411 el->fLayout->SavePrimitive(out, option);
412 out << ");\n";
413 }
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Save a shutter widget as a C++ statement(s) on output stream out.
418
419void TGShutter::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
420{
421 out << "\n // shutter\n";
422
423 out << " TGShutter *" << GetName() << " = new TGShutter(" << fParent->GetName() << "," << GetOptionString()
424 << ");\n";
425
426 if ((fDefWidth > 0) || (fDefHeight > 0)) {
427 out << " " << GetName() << "->SetDefaultSize(";
428 out << fDefWidth << "," << fDefHeight << ");\n";
429 }
430 if (option && strstr(option, "keep_names"))
431 out << " " << GetName() << "->SetName(\"" << GetName() << "\");\n";
432
433 if (!fList)
434 return;
435
436 TIter next(fList);
437
438 while (auto el = static_cast<TGFrameElement *>(next())) {
439 el->fFrame->SavePrimitive(out, option);
440 out << " " << GetName() << "->AddItem(" << el->fFrame->GetName();
441 // el->fLayout->SavePrimitive(out, option);
442 out << ");\n";
443 }
444
445 out << " " << GetName() << "->SetSelectedItem(" << GetSelectedItem()->GetName() << ");\n";
446 out << " " << GetName() << "->Resize(" << GetWidth() << "," << GetHeight() << ");\n";
447}
@ kChildFrame
Definition GuiTypes.h:380
@ kFixedWidth
Definition GuiTypes.h:388
@ kFixedHeight
Definition GuiTypes.h:390
@ kOwnBackground
Definition GuiTypes.h:392
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
XFontStruct * id
Definition TGX11.cxx:147
char name[80]
Definition TGX11.cxx:148
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:453
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
Definition TGCanvas.h:192
@ kCanvasNoScroll
Definition TGCanvas.h:205
@ kCanvasScrollVertical
Definition TGCanvas.h:207
void SetScrolling(Int_t scrolling)
Set scrolling policy.
TGLayoutManager * fLayoutManager
layout manager
Definition TGFrame.h:293
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
virtual TList * GetList() const
Definition TGFrame.h:312
Int_t MustCleanup() const override
Definition TGFrame.h:362
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
TGCompositeFrame(const TGCompositeFrame &)=delete
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition TGFrame.cxx:1196
TList * fList
container of frame elements
Definition TGFrame.h:294
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition TGFrame.cxx:1141
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition TGFrame.cxx:1182
TGFrame * fFrame
Definition TGLayout.h:112
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:621
TGFrame(const TGFrame &)=delete
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
TGFrameElement * GetFrameElement() const
Definition TGFrame.h:237
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:675
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2512
UInt_t fWidth
frame width
Definition TGFrame.h:87
UInt_t GetHeight() const
Definition TGFrame.h:227
UInt_t GetWidth() const
Definition TGFrame.h:226
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
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
TGButton * fButton
shutter item button
Definition TGShutter.h:30
TGShutterItem(const TGShutterItem &)=delete
TGFrame * GetContainer() const
Definition TGShutter.h:45
virtual void AddItem(TGShutterItem *item)
Add shutter item to shutter frame.
Definition TGShutter.cxx:71
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:57
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:84
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:638
TString GetString() const
Definition TGButton.h:191
TGVerticalFrame(const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
Definition TGFrame.h:378
TGWidget(const TGWidget &tgw)
Definition TGWidget.h:51
Int_t WidgetId() const
Definition TGWidget.h:68
ROOT GUI Window base class.
Definition TGWindow.h:23
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
TGWindow(Window_t id)
Definition TGWindow.h:34
virtual void DestroyWindow()
destroy window
Definition TGWindow.cxx:190
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:334
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void Reset()
A doubly linked list.
Definition TList.h:38
void MakeZombie()
Definition TObject.h:55
Bool_t IsZombie() const
Definition TObject.h:161
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:670
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1121
const char * Data() const
Definition TString.h:384
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
Double_t y[n]
Definition legend1.C:17