Logo ROOT  
Reference Guide
TGDockableFrame.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Abdelhalim Ssadik 07/07/04
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23//////////////////////////////////////////////////////////////////////////
24// //
25// A TGDockableFrame is a frame with handles that allow it to be //
26// undocked (i.e. put in a transient frame of its own) and to be docked //
27// again or hidden and shown again. It uses the TGDockButton, which is //
28// a button with two vertical bars (||) and TGDockHideButton, which is //
29// a button with a small triangle. The TGUndockedFrame is a transient //
30// frame that on closure will put the frame back in the dock. //
31// //
32//////////////////////////////////////////////////////////////////////////
33
34#include "TColor.h"
35#include "TGFrame.h"
36#include "TGWidget.h"
37#include "TGButton.h"
38#include "TGDockableFrame.h"
39#include "TGWindow.h"
40#include "TList.h"
41#include "TVirtualX.h"
42#include "Riostream.h"
43
44
49
50////////////////////////////////////////////////////////////////////////////////
51/// Create a dock button (i.e. button with two vertical bars).
52
54 TGButton (p, id, GetDefaultGC()(), kChildFrame)
55{
59
61
62 Float_t r, g, b, h, l, s;
64 TColor::RGB2HLS(r, g, b, h, l, s);
65 l = l + (1. - l) * 45. / 100.;
66 TColor::HLS2RGB(h, l, s, r, g, b);
68
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Delete dock button.
75
77{
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Handle dock button crossing events.
82
84{
86 if (event->fType == kLeaveNotify) {
88 } else if (event->fType == kEnterNotify) {
90 }
91 if (IsEnabled())
92 fClient->NeedRedraw(this);
93
94 return kTRUE;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Draw borders of dock button.
99
101{
102 int options = GetOptions();
103
105 ;
106 else if (fMouseOn == kTRUE && IsEnabled()) {
109 } else {
112 }
113 gVirtualX->ClearWindow(fId);
115
116 ChangeOptions(options);
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Draw the dock button, i.e. two vertical lines.
121
123{
124 int x = 1, y = 0;
125
126 DrawBorder();
127 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
128
129 for (int i = 0; i < 5; i +=4) {
130 gVirtualX->DrawLine(fId, GetHilightGC()(), i+x, y+1, i+x, fHeight-y-3);
131 gVirtualX->DrawLine(fId, GetShadowGC()(), i+x+1, y+1, i+x+1, fHeight-y-3);
132 }
133}
134
135
136////////////////////////////////////////////////////////////////////////////////
137/// Create a dock hide button (i.e. button with small triangle).
138
140 TGDockButton (p, 2)
141{
142 Resize(10, 8);
143 fAspectRatio = 0;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Draw dock hide button.
149
151{
152 int x = 1, y = 0;
153
154 DrawBorder();
155 if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
156
157 if (fAspectRatio) {
158 gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+1, x+5, y+3);
159 gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+5, x+5, y+3);
160 gVirtualX->DrawLine(fId, GetHilightGC()(), x, y+1, x, y+5);
161 } else {
162 gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+1, x+1, y+3);
163 gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+5, x+1, y+3);
164 gVirtualX->DrawLine(fId, GetBlackGC()(), x+6, y+1, x+6, y+5);
165 }
166}
167
168
169////////////////////////////////////////////////////////////////////////////////
170/// Create the undocked (transient) frame.
171
173 TGTransientFrame(p, dockable ? dockable->GetMainFrame() : 0, 10, 10)
174{
175 SetWindowName("");
176 fDockable = dockable;
177
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Delete undocked frame. Puts back dockable frame in its original container.
188
190{
191 if (fDockable && !fDockable->fDeleted) {
193 }
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Fix the size of the undocked frame so it cannot be changed via the WM.
198
200{
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Close undocked frame (called via WM close button).
208
210{
211 DeleteWindow();
212}
213
214
215////////////////////////////////////////////////////////////////////////////////
216/// Create a dockable frame widget.
217
220{
222
225 fLb = new TGLayoutHints(kLHintsExpandY | kLHintsLeft, 0, 2, 0, 0);
227
228 fButtons = new TGCompositeFrame(this, 10, 10, kVerticalFrame);
234
236
237 fContainer = new TGCompositeFrame(this, 10, 10);
238
240
243 fHidden = kFALSE;
244 fFrame = 0;
247
248 fDockButton->Associate(this);
249 fHideButton->Associate(this);
250
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Cleanup dockable frame.
258
260{
261 // Just set the flag and delete fFrame. The other components
262 // are deleted in TGCompositeFrame destructor.
263 if (fFrame) {
264 fDeleted = kTRUE;
265 delete fFrame;
266 }
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Add frame to dockable frame container. Frame and hints are NOT adopted.
271
273{
274 f->ReparentWindow(fContainer);
275 fContainer->AddFrame(f, fHints = hints);
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Undock container.
281
283{
284 int ax, ay;
285 Window_t wdummy;
286
287 if (fFrame || !fEnableUndock) return;
288
291
296
297 gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(), fX,
298 fY + fFrame->GetHeight(), ax, ay, wdummy);
299
301
303 fFrame->Resize(size);
304 if (fFixedSize)
305 fFrame->FixSize();
306 fFrame->MapWindow();
307 fFrame->Move(ax, ay);
308
309 if (((TGFrame *)fParent)->IsComposite()) // paranoia check
310 ((TGCompositeFrame *)fParent)->HideFrame(this);
311
312 Layout();
313
315 Undocked();
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Dock container back to TGDockableFrame.
320
322{
323 if (!fFrame) return;
324 if (del) {
325 delete fFrame; // this will call DockContainer again with del = kFALSE
326 return;
327 }
328
332
333 // kludge! (for special case)
335
336 Layout();
337 if (((TGFrame *)fParent)->IsComposite()) // paranoia check
338 ((TGCompositeFrame *)fParent)->ShowFrame(this);
339
340 // fFrame is just being deleted (we're here called by TGUndockedFrame's
341 // destructor) so just set it NULL below to avoid eventual problems in
342 // TGDockableFrame's destructor.
343
344 fFrame = 0;
345
347 Docked();
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Show dock container.
352
354{
355 if (!fHidden) return;
356
360 if (((TGFrame *)fParent)->IsComposite()) // paranoia check
361 ((TGCompositeFrame *)fParent)->Layout();
362 fHidden = kFALSE;
363
365}
366
367////////////////////////////////////////////////////////////////////////////////
368/// Hide dock container.
369
371{
372 if (fHidden || !fEnableHide) return;
373
377 if (((TGFrame *)fParent)->IsComposite()) // paranoia check
378 ((TGCompositeFrame *)fParent)->Layout();
379 fHidden = kTRUE;
380
382}
383
384////////////////////////////////////////////////////////////////////////////////
385/// Process dockable frame messages.
386
388{
389 switch (GET_MSG(msg)) {
390 case kC_COMMAND:
391 switch (GET_SUBMSG(msg)) {
392 case kCM_BUTTON:
393 switch (parm1) {
394 case 1:
395 if (!fHidden) UndockContainer();
396 break;
397 case 2:
398 if (!fHidden)
400 else
402 break;
403 }
404 break;
405 }
406 break;
407 }
408
409 return kTRUE;
410}
411
412////////////////////////////////////////////////////////////////////////////////
413/// Enable undocking.
414
416{
417 fEnableUndock = onoff;
418 if (onoff)
420 else
422 Layout();
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Enable hiding.
427
429{
430 fEnableHide = onoff;
431 if (onoff)
433 else
435 Layout();
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Set window name so it appear as title of the undock window.
440
442{
443 fDockName = "";
444 if (name) {
445 fDockName = name;
447 }
448}
449
450////////////////////////////////////////////////////////////////////////////////
451/// Save a dockable frame widget as a C++ statement(s) on output stream out.
452
453void TGDockableFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
454{
455 char quote = '"';
456
457 out << std::endl << " // dockable frame" << std::endl;
458 out << " TGDockableFrame *";
459 out << GetName()<<" = new TGDockableFrame(" << fParent->GetName();
460
461 if (GetOptions() == kHorizontalFrame) {
462 if (fWidgetId == -1) {
463 out << ");" << std::endl;
464 } else {
465 out << "," << fWidgetId << ");" << std::endl;
466 }
467 } else {
468 out << "," << fWidgetId << "," << GetOptionString() << ");" << std::endl;
469 }
470 if (option && strstr(option, "keep_names"))
471 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
472
473 if (GetContainer()->GetList()->First()) {
474 out << " TGCompositeFrame *" << GetContainer()->GetName() << " = "
475 << GetName() << "->GetContainer();" << std::endl;
476
477 TGFrameElement *el;
478 TIter next(GetContainer()->GetList());
479
480 while ((el = (TGFrameElement *) next())) {
481 el->fFrame->SavePrimitive(out, option);
482 out << " " << GetName() << "->AddFrame(" << el->fFrame->GetName();
483 el->fLayout->SavePrimitive(out, option);
484 out << ");"<< std::endl;
485 }
486 }
487 out << std::endl << " // next lines belong to the dockable frame widget" << std::endl;
488 if (EnableUndock())
489 out << " " << GetName() << "->EnableUndock(kTRUE);" << std::endl;
490 else
491 out << " " << GetName() << "->EnableUndock(kFALSE);" << std::endl;
492
493 if (EnableHide())
494 out << " " << GetName() << "->EnableHide(kTRUE);" << std::endl;
495 else
496 out << " " << GetName() << "->EnableHide(kFALSE);" << std::endl;
497
498 if (fDockName != "")
499 out << " " << GetName() << "->SetWindowName(" << quote << fDockName
500 << quote << ");" << std::endl;
501
502 if (IsUndocked())
503 out << " " << GetName() << "->UndockContainer();" << std::endl;
504 else
505 out << " " << GetName() << "->DockContainer();" << std::endl;
506
507 if (IsHidden())
508 out << " " << GetName() << "->HideContainer();" << std::endl;
509
510 out << std::endl;
511}
@ kEnterNotify
Definition: GuiTypes.h:60
@ kLeaveNotify
Definition: GuiTypes.h:60
@ kChildFrame
Definition: GuiTypes.h:379
@ kVerticalFrame
Definition: GuiTypes.h:381
@ kHorizontalFrame
Definition: GuiTypes.h:382
@ kFixedSize
Definition: GuiTypes.h:390
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
Handle_t Window_t
Definition: GuiTypes.h:28
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
#define g(i)
Definition: RSha256.hxx:105
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
@ kButtonDown
Definition: TGButton.h:54
@ kButtonEngaged
Definition: TGButton.h:55
@ kMWMDecorResizeH
Definition: TGFrame.h:74
@ kMWMFuncAll
Definition: TGFrame.h:58
@ kMWMFuncResize
Definition: TGFrame.h:59
@ kMWMDecorMaximize
Definition: TGFrame.h:78
@ kMWMDecorMinimize
Definition: TGFrame.h:77
@ kMWMDecorMenu
Definition: TGFrame.h:76
@ kMWMDecorAll
Definition: TGFrame.h:72
@ kMWMFuncMaximize
Definition: TGFrame.h:62
@ kMWMInputModeless
Definition: TGFrame.h:66
@ kMWMFuncMinimize
Definition: TGFrame.h:61
@ kLHintsExpandY
Definition: TGLayout.h:38
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
@ kWidgetIsEnabled
Definition: TGWidget.h:48
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
#define gVirtualX
Definition: TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kDOCK_UNDOCK
@ kDOCK_DOCK
@ kC_COMMAND
@ kDOCK_SHOW
@ kCM_BUTTON
@ kDOCK_HIDE
@ kC_DOCK
Int_t GET_SUBMSG(Long_t val)
static void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t &r, Float_t &g, Float_t &b)
Static method to compute RGB from HLS.
Definition: TColor.cxx:1454
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition: TColor.cxx:2054
static void Pixel2RGB(ULong_t pixel, Int_t &r, Int_t &g, Int_t &b)
Convert machine dependent pixel value (obtained via RGB2Pixel or via Number2Pixel() or via TColor::Ge...
Definition: TColor.cxx:2092
static void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t &h, Float_t &l, Float_t &s)
Static method to compute HLS from RGB.
Definition: TColor.cxx:1594
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:356
EButtonState fState
Definition: TGButton.h:75
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
virtual TList * GetList() const
Definition: TGFrame.h:347
Bool_t IsComposite() const
Definition: TGFrame.h:390
TGCompositeFrame(const TGCompositeFrame &)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1241
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1027
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1056
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:353
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
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1006
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
virtual Bool_t HandleCrossing(Event_t *event)
Handle dock button crossing events.
TGDockButton(const TGCompositeFrame *p=0, Int_t id=1)
Create a dock button (i.e. button with two vertical bars).
virtual void DrawBorder()
Draw borders of dock button.
virtual ~TGDockButton()
Delete dock button.
virtual void DoRedraw()
Draw the dock button, i.e. two vertical lines.
virtual void DoRedraw()
Draw dock hide button.
TGDockHideButton(const TGCompositeFrame *p=0)
Create a dock hide button (i.e. button with small triangle).
void SetAspectRatio(Int_t a)
void DockContainer(Int_t del=kTRUE)
Dock container back to TGDockableFrame.
friend class TGUndockedFrame
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a dockable frame widget as a C++ statement(s) on output stream out.
TGCompositeFrame * fButtons
virtual ~TGDockableFrame()
Cleanup dockable frame.
TGUndockedFrame * fFrame
TGLayoutHints * fLb
TGDockableFrame(const TGDockableFrame &)
Bool_t IsHidden() const
TGCompositeFrame * GetContainer() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *hints)
Add frame to dockable frame container. Frame and hints are NOT adopted.
TGCompositeFrame * fContainer
void UndockContainer()
Undock container.
virtual void Undocked()
void HideContainer()
Hide dock container.
virtual Bool_t ProcessMessage(Long_t, Long_t, Long_t)
Process dockable frame messages.
Bool_t EnableUndock() const
TGLayoutHints * fHints
void SetWindowName(const char *name)
Set window name so it appear as title of the undock window.
Bool_t EnableHide() const
TGDockButton * fDockButton
void ShowContainer()
Show dock container.
TGDockHideButton * fHideButton
virtual void Docked()
TGLayoutHints * fLc
Bool_t IsUndocked() const
TGLayoutHints * fLayout
Definition: TGLayout.h:121
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ChangeOptions(UInt_t options)
Change frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:305
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:323
static const TGGC & GetBlackGC()
Get black graphics context.
Definition: TGFrame.cxx:719
Int_t fX
Definition: TGFrame.h:110
virtual void ReparentWindow(const TGWindow *p, Int_t x=0, Int_t y=0)
Reparent window, make p the new parent and position the window at position (x,y) in new parent.
Definition: TGFrame.h:227
UInt_t fHeight
Definition: TGFrame.h:113
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:215
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
virtual void DrawBorder()
Draw frame border.
Definition: TGFrame.cxx:405
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
TGDimension GetSize() const
Definition: TGFrame.h:255
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:739
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:296
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:629
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:260
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2464
Int_t fY
Definition: TGFrame.h:111
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:749
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:577
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
UInt_t fWidth
Definition: TGFrame.h:112
UInt_t GetHeight() const
Definition: TGFrame.h:250
virtual void MapWindow()
map window
Definition: TGFrame.h:229
Pixel_t fBackground
Definition: TGFrame.h:120
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
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1851
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1826
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGFrame.cxx:1864
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1748
TGClient * fClient
Definition: TGObject.h:37
Handle_t GetId() const
Definition: TGObject.h:47
Handle_t fId
Definition: TGObject.h:36
TGUndockedFrame(const TGUndockedFrame &)
void FixSize()
Fix the size of the undocked frame so it cannot be changed via the WM.
virtual ~TGUndockedFrame()
Delete undocked frame. Puts back dockable frame in its original container.
TGDockableFrame * fDockable
void CloseWindow()
Close undocked frame (called via WM close button).
Int_t fWidgetId
Definition: TGWidget.h:58
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
Int_t fWidgetFlags
Definition: TGWidget.h:59
const TGWindow * fMsgWindow
Definition: TGWidget.h:60
Bool_t IsEnabled() const
Definition: TGWidget.h:81
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:119
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:326
const TGWindow * fParent
Definition: TGWindow.h:36
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
static constexpr double s
EGEventType fType
Definition: GuiTypes.h:174
auto * l
Definition: textangle.C:4