Logo ROOT   master
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 {
57  fMouseOn = kFALSE;
58  Resize(10, GetDefaultHeight());
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 
70  SetWindowName();
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) {
87  fMouseOn = kFALSE;
88  } else if (event->fType == kEnterNotify) {
89  fMouseOn = kTRUE;
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;
144  SetWindowName();
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 
183  SetWindowName();
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 
218 TGDockableFrame::TGDockableFrame(const TGWindow *p, int id, UInt_t /*options*/)
220 {
222 
225  fLb = new TGLayoutHints(kLHintsExpandY | kLHintsLeft, 0, 2, 0, 0);
227 
228  fButtons = new TGCompositeFrame(this, 10, 10, kVerticalFrame);
229  fButtons->SetCleanup();
234 
236 
237  fContainer = new TGCompositeFrame(this, 10, 10);
238 
240 
241  fEnableHide = kTRUE;
243  fHidden = kFALSE;
244  fFrame = 0;
245  fDeleted = kFALSE;
246  fFixedSize = kTRUE;
247 
248  fDockButton->Associate(this);
249  fHideButton->Associate(this);
250 
251  MapSubwindows();
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);
276  fContainer->Layout();
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// Undock container.
281 
283 {
284  int ax, ay;
285  Window_t wdummy;
286 
287  if (fFrame || !fEnableUndock) return;
288 
291 
292  TGDimension size = fContainer->GetSize();
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 
330  fContainer->ReparentWindow(this);
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)
399  HideContainer();
400  else
401  ShowContainer();
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 
453 void 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 }
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1173
const TGWindow * fParent
Definition: TGWindow.h:36
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:588
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:222
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:322
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:1747
#define g(i)
Definition: RSha256.hxx:105
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:738
UInt_t GetHeight() const
Definition: TGFrame.h:250
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
Int_t fY
Definition: TGFrame.h:111
virtual void DrawBorder()
Draw frame border.
Definition: TGFrame.cxx:404
Pixel_t fBackground
Definition: TGFrame.h:120
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1187
#define f(i)
Definition: RSha256.hxx:104
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:356
Handle_t GetId() const
Definition: TGObject.h:47
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1240
TGDockHideButton * fHideButton
Bool_t EnableUndock() const
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1132
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:110
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:1863
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
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:628
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:295
virtual TList * GetList() const
Definition: TGFrame.h:347
TGLayoutHints * fLb
static constexpr double s
XFontStruct * id
Definition: TGX11.cxx:108
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:2041
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:1591
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:1451
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:3190
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:353
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:318
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:1026
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:215
TGCompositeFrame * fContainer
static const TGGC & GetBlackGC()
Get black graphics context.
Definition: TGFrame.cxx:718
#define gVirtualX
Definition: TVirtualX.h:338
#define h(i)
Definition: RSha256.hxx:106
UInt_t fWidth
Definition: TGFrame.h:112
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:576
Int_t GET_MSG(Long_t val)
const Bool_t kFALSE
Definition: RtypesCore.h:88
friend class TGUndockedFrame
TGDimension GetSize() const
Definition: TGFrame.h:255
long Long_t
Definition: RtypesCore.h:50
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
TGLayoutHints * fHints
#define ClassImp(name)
Definition: Rtypes.h:365
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1005
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:1055
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.
UInt_t fHeight
Definition: TGFrame.h:113
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1100
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:1147
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:390
auto * l
Definition: textangle.C:4
virtual void MapWindow()
map window
Definition: TGFrame.h:229
TGClient * fClient
Definition: TGObject.h:37
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:234
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:1850
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
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:2463
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:259
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1825
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:304
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:748
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:2079
virtual void SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:119