Logo ROOT   6.12/07
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 "TMessage.h"
37 #include "TGWidget.h"
38 #include "TGButton.h"
39 #include "TGDockableFrame.h"
40 #include "TGWindow.h"
41 #include "TList.h"
42 #include "TVirtualX.h"
43 #include "Riostream.h"
44 
45 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Create a dock button (i.e. button with two vertical bars).
53 
55  TGButton (p, id, GetDefaultGC()(), kChildFrame)
56 {
58  fMouseOn = kFALSE;
59  Resize(10, GetDefaultHeight());
60 
62 
63  Float_t r, g, b, h, l, s;
64  TColor::Pixel2RGB(fNormBg, r, g, b);
65  TColor::RGB2HLS(r, g, b, h, l, s);
66  l = l + (1. - l) * 45. / 100.;
67  TColor::HLS2RGB(h, l, s, r, g, b);
68  fHiBg = TColor::RGB2Pixel(r, g, b);
69 
71  SetWindowName();
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Delete dock button.
76 
78 {
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Handle dock button crossing events.
83 
85 {
87  if (event->fType == kLeaveNotify) {
88  fMouseOn = kFALSE;
89  } else if (event->fType == kEnterNotify) {
90  fMouseOn = kTRUE;
91  }
92  if (IsEnabled())
93  fClient->NeedRedraw(this);
94 
95  return kTRUE;
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Draw borders of dock button.
100 
102 {
103  int options = GetOptions();
104 
106  ;
107  else if (fMouseOn == kTRUE && IsEnabled()) {
110  } else {
113  }
114  gVirtualX->ClearWindow(fId);
116 
117  ChangeOptions(options);
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Draw the dock button, i.e. two vertical lines.
122 
124 {
125  int x = 1, y = 0;
126 
127  DrawBorder();
128  if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
129 
130  for (int i = 0; i < 5; i +=4) {
131  gVirtualX->DrawLine(fId, GetHilightGC()(), i+x, y+1, i+x, fHeight-y-3);
132  gVirtualX->DrawLine(fId, GetShadowGC()(), i+x+1, y+1, i+x+1, fHeight-y-3);
133  }
134 }
135 
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Create a dock hide button (i.e. button with small triangle).
139 
141  TGDockButton (p, 2)
142 {
143  Resize(10, 8);
144  fAspectRatio = 0;
145  SetWindowName();
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Draw dock hide button.
150 
152 {
153  int x = 1, y = 0;
154 
155  DrawBorder();
156  if (fState == kButtonDown || fState == kButtonEngaged) { ++x; ++y; }
157 
158  if (fAspectRatio) {
159  gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+1, x+5, y+3);
160  gVirtualX->DrawLine(fId, GetBlackGC()(), x+1, y+5, x+5, y+3);
161  gVirtualX->DrawLine(fId, GetHilightGC()(), x, y+1, x, y+5);
162  } else {
163  gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+1, x+1, y+3);
164  gVirtualX->DrawLine(fId, GetHilightGC()(), x+5, y+5, x+1, y+3);
165  gVirtualX->DrawLine(fId, GetBlackGC()(), x+6, y+1, x+6, y+5);
166  }
167 }
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Create the undocked (transient) frame.
172 
174  TGTransientFrame(p, dockable ? dockable->GetMainFrame() : 0, 10, 10)
175 {
176  SetWindowName("");
177  fDockable = dockable;
178 
184  SetWindowName();
185 }
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Delete undocked frame. Puts back dockable frame in its original container.
189 
191 {
192  if (fDockable && !fDockable->fDeleted) {
194  }
195 }
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Fix the size of the undocked frame so it cannot be changed via the WM.
199 
201 {
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Close undocked frame (called via WM close button).
209 
211 {
212  DeleteWindow();
213 }
214 
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Create a dockable frame widget.
218 
219 TGDockableFrame::TGDockableFrame(const TGWindow *p, int id, UInt_t /*options*/)
220  : TGCompositeFrame(p, 10, 10, kHorizontalFrame), TGWidget(id)
221 {
223 
226  fLb = new TGLayoutHints(kLHintsExpandY | kLHintsLeft, 0, 2, 0, 0);
228 
229  fButtons = new TGCompositeFrame(this, 10, 10, kVerticalFrame);
230  fButtons->SetCleanup();
235 
237 
238  fContainer = new TGCompositeFrame(this, 10, 10);
239 
241 
242  fEnableHide = kTRUE;
244  fHidden = kFALSE;
245  fFrame = 0;
246  fDeleted = kFALSE;
247  fFixedSize = kTRUE;
248 
249  fDockButton->Associate(this);
250  fHideButton->Associate(this);
251 
252  MapSubwindows();
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 /// Cleanup dockable frame.
259 
261 {
262  // Just set the flag and delete fFrame. The other components
263  // are deleted in TGCompositeFrame destructor.
264  if (fFrame) {
265  fDeleted = kTRUE;
266  delete fFrame;
267  }
268 }
269 
270 ////////////////////////////////////////////////////////////////////////////////
271 /// Add frame to dockable frame container. Frame and hints are NOT adopted.
272 
274 {
276  fContainer->AddFrame(f, fHints = hints);
277  fContainer->Layout();
278 }
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Undock container.
282 
284 {
285  int ax, ay;
286  Window_t wdummy;
287 
288  if (fFrame || !fEnableUndock) return;
289 
292 
293  TGDimension size = fContainer->GetSize();
297 
298  gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(), fX,
299  fY + fFrame->GetHeight(), ax, ay, wdummy);
300 
302 
304  fFrame->Resize(size);
305  if (fFixedSize)
306  fFrame->FixSize();
307  fFrame->MapWindow();
308  fFrame->Move(ax, ay);
309 
310  if (((TGFrame *)fParent)->IsComposite()) // paranoia check
311  ((TGCompositeFrame *)fParent)->HideFrame(this);
312 
313  Layout();
314 
316  Undocked();
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// Dock container back to TGDockableFrame.
321 
323 {
324  if (!fFrame) return;
325  if (del) {
326  delete fFrame; // this will call DockContainer again with del = kFALSE
327  return;
328  }
329 
331  fContainer->ReparentWindow(this);
333 
334  // kludge! (for special case)
336 
337  Layout();
338  if (((TGFrame *)fParent)->IsComposite()) // paranoia check
339  ((TGCompositeFrame *)fParent)->ShowFrame(this);
340 
341  // fFrame is just being deleted (we're here called by TGUndockedFrame's
342  // destructor) so just set it NULL below to avoid eventual problems in
343  // TGDockableFrame's destructor.
344 
345  fFrame = 0;
346 
348  Docked();
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Show dock container.
353 
355 {
356  if (!fHidden) return;
357 
361  if (((TGFrame *)fParent)->IsComposite()) // paranoia check
362  ((TGCompositeFrame *)fParent)->Layout();
363  fHidden = kFALSE;
364 
366 }
367 
368 ////////////////////////////////////////////////////////////////////////////////
369 /// Hide dock container.
370 
372 {
373  if (fHidden || !fEnableHide) return;
374 
378  if (((TGFrame *)fParent)->IsComposite()) // paranoia check
379  ((TGCompositeFrame *)fParent)->Layout();
380  fHidden = kTRUE;
381 
383 }
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// Process dockable frame messages.
387 
389 {
390  switch (GET_MSG(msg)) {
391  case kC_COMMAND:
392  switch (GET_SUBMSG(msg)) {
393  case kCM_BUTTON:
394  switch (parm1) {
395  case 1:
396  if (!fHidden) UndockContainer();
397  break;
398  case 2:
399  if (!fHidden)
400  HideContainer();
401  else
402  ShowContainer();
403  break;
404  }
405  break;
406  }
407  break;
408  }
409 
410  return kTRUE;
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Enable undocking.
415 
417 {
418  fEnableUndock = onoff;
419  if (onoff)
421  else
423  Layout();
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// Enable hiding.
428 
430 {
431  fEnableHide = onoff;
432  if (onoff)
434  else
436  Layout();
437 }
438 
439 ////////////////////////////////////////////////////////////////////////////////
440 /// Set window name so it appear as title of the undock window.
441 
443 {
444  fDockName = "";
445  if (name) {
446  fDockName = name;
448  }
449 }
450 
451 ////////////////////////////////////////////////////////////////////////////////
452 /// Save a dockable frame widget as a C++ statement(s) on output stream out.
453 
454 void TGDockableFrame::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
455 {
456  char quote = '"';
457 
458  out << std::endl << " // dockable frame" << std::endl;
459  out << " TGDockableFrame *";
460  out << GetName()<<" = new TGDockableFrame(" << fParent->GetName();
461 
462  if (GetOptions() == kHorizontalFrame) {
463  if (fWidgetId == -1) {
464  out << ");" << std::endl;
465  } else {
466  out << "," << fWidgetId << ");" << std::endl;
467  }
468  } else {
469  out << "," << fWidgetId << "," << GetOptionString() << ");" << std::endl;
470  }
471  if (option && strstr(option, "keep_names"))
472  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
473 
474  if (GetContainer()->GetList()->First()) {
475  out << " TGCompositeFrame *" << GetContainer()->GetName() << " = "
476  << GetName() << "->GetContainer();" << std::endl;
477 
478  TGFrameElement *el;
479  TIter next(GetContainer()->GetList());
480 
481  while ((el = (TGFrameElement *) next())) {
482  el->fFrame->SavePrimitive(out, option);
483  out << " " << GetName() << "->AddFrame(" << el->fFrame->GetName();
484  el->fLayout->SavePrimitive(out, option);
485  out << ");"<< std::endl;
486  }
487  }
488  out << std::endl << " // next lines belong to the dockable frame widget" << std::endl;
489  if (EnableUndock())
490  out << " " << GetName() << "->EnableUndock(kTRUE);" << std::endl;
491  else
492  out << " " << GetName() << "->EnableUndock(kFALSE);" << std::endl;
493 
494  if (EnableHide())
495  out << " " << GetName() << "->EnableHide(kTRUE);" << std::endl;
496  else
497  out << " " << GetName() << "->EnableHide(kFALSE);" << std::endl;
498 
499  if (fDockName != "")
500  out << " " << GetName() << "->SetWindowName(" << quote << fDockName
501  << quote << ");" << std::endl;
502 
503  if (IsUndocked())
504  out << " " << GetName() << "->UndockContainer();" << std::endl;
505  else
506  out << " " << GetName() << "->DockContainer();" << std::endl;
507 
508  if (IsHidden())
509  out << " " << GetName() << "->HideContainer();" << std::endl;
510 
511  out << std::endl;
512 }
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1172
const TGWindow * fParent
Definition: TGWindow.h:37
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual ~TGUndockedFrame()
Delete undocked frame. Puts back dockable frame in its original container.
virtual void AddFrame(TGFrame *f, TGLayoutHints *hints)
Add frame to dockable frame container. Frame and hints are NOT adopted.
TGUndockedFrame(const TGUndockedFrame &)
TGDockButton(const TGCompositeFrame *p=0, Int_t id=1)
Create a dock button (i.e. button with two vertical bars).
virtual UInt_t GetOptions() const
Definition: TGFrame.h:244
virtual void DoRedraw()
Draw the dock button, i.e. two vertical lines.
TGLayoutHints * fLc
float Float_t
Definition: RtypesCore.h:53
void DockContainer(Int_t del=kTRUE)
Dock container back to TGDockableFrame.
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
const char Option_t
Definition: RtypesCore.h:62
virtual void Docked()
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:737
UInt_t GetHeight() const
Definition: TGFrame.h:272
TH1 * h
Definition: legend2.C:5
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
Int_t fY
Definition: TGFrame.h:133
virtual void DrawBorder()
Draw frame border.
Definition: TGFrame.cxx:403
Pixel_t fBackground
Definition: TGFrame.h:142
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
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
virtual ~TGDockButton()
Delete dock button.
TGCompositeFrame * fButtons
TGDockableFrame * fDockable
Int_t fWidgetId
Definition: TGWidget.h:58
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
Definition: TGButton.cxx:354
Handle_t GetId() const
Definition: TGObject.h:47
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1239
TGDockHideButton * fHideButton
Bool_t EnableUndock() const
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1131
TGLayoutHints * fLayout
Definition: TGLayout.h:121
Double_t x[n]
Definition: legend1.C:17
Bool_t EnableHide() const
TGCompositeFrame * GetContainer() const
Int_t fX
Definition: TGFrame.h:132
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:1862
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:249
TGCompositeFrame(const TGCompositeFrame &)
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:294
virtual TList * GetList() const
Definition: TGFrame.h:369
TGLayoutHints * fLb
Bool_t IsUndocked() const
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:2028
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a dockable frame widget as a C++ statement(s) on output stream out.
virtual Bool_t ProcessMessage(Long_t, Long_t, Long_t)
Process dockable frame messages.
const TGWindow * fMsgWindow
Definition: TGWidget.h:60
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:1578
TGDockHideButton(const TGCompositeFrame *p=0)
Create a dock hide button (i.e. button with small triangle).
Bool_t IsHidden() const
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:1438
void CloseWindow()
Close undocked frame (called via WM close button).
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:3187
ROOT::R::TRInterface & r
Definition: Object.C:4
EGEventType fType
Definition: GuiTypes.h:174
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:375
Int_t GET_SUBMSG(Long_t val)
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
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
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:221
virtual ~TGDockableFrame()
Cleanup dockable frame.
unsigned int UInt_t
Definition: RtypesCore.h:42
TGFrame * fFrame
Definition: TGLayout.h:119
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1025
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:237
TGCompositeFrame * fContainer
static const TGGC & GetBlackGC()
Get black graphics context.
Definition: TGFrame.cxx:717
#define gVirtualX
Definition: TVirtualX.h:350
UInt_t fWidth
Definition: TGFrame.h:134
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:575
Int_t GET_MSG(Long_t val)
const Bool_t kFALSE
Definition: RtypesCore.h:88
friend class TGUndockedFrame
TGDimension GetSize() const
Definition: TGFrame.h:277
long Long_t
Definition: RtypesCore.h:50
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
TGLayoutHints * fHints
#define ClassImp(name)
Definition: Rtypes.h:359
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1004
virtual void DrawBorder()
Draw borders of dock button.
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
TGDockButton * fDockButton
virtual Bool_t HandleCrossing(Event_t *event)
Handle dock button crossing events.
Double_t y[n]
Definition: legend1.C:17
void ShowContainer()
Show dock container.
static constexpr double s
UInt_t fHeight
Definition: TGFrame.h:135
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void DoRedraw()
Draw dock hide button.
TGDockableFrame(const TGDockableFrame &)
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
Bool_t IsEnabled() const
Definition: TGWidget.h:81
void SetAspectRatio(Int_t a)
Handle_t fId
Definition: TGObject.h:36
void HideContainer()
Hide dock container.
Handle_t Window_t
Definition: GuiTypes.h:28
Bool_t IsComposite() const
Definition: TGFrame.h:412
auto * l
Definition: textangle.C:4
virtual void MapWindow()
Definition: TGFrame.h:251
TGClient * fClient
Definition: TGObject.h:37
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:232
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1849
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
Int_t fWidgetFlags
Definition: TGWidget.h:59
void FixSize()
Fix the size of the undocked frame so it cannot be changed via the WM.
EButtonState fState
Definition: TGButton.h:75
virtual void Undocked()
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition: TGFrame.cxx:2460
void SetWindowName(const char *name)
Set window name so it appear as title of the undock window.
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:258
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1824
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void ChangeOptions(UInt_t options)
Change frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:303
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:747
char name[80]
Definition: TGX11.cxx:109
void UndockContainer()
Undock container.
TGUndockedFrame * fFrame
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:2066
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:118
static constexpr double g