Logo ROOT   6.12/07
Reference Guide
TGMdiMenu.cxx
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot 20/08/2004
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 
14  This file is part of TGMdi an extension to the xclass toolkit.
15  Copyright (C) 1998-2002 by Harald Radke, Hector Peraza.
16 
17  This application is free software; you can redistribute it and/or
18  modify it under the terms of the GNU Library General Public
19  License as published by the Free Software Foundation; either
20  version 2 of the License, or (at your option) any later version.
21 
22  This application is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  Library General Public License for more details.
26 
27  You should have received a copy of the GNU Library General Public
28  License along with this library; if not, write to the Free
29  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 
31 **************************************************************************/
32 
33 //////////////////////////////////////////////////////////////////////////
34 // //
35 // TGMdiMenu. //
36 // //
37 // This file contains the TGMdiMenuBar class. //
38 // //
39 //////////////////////////////////////////////////////////////////////////
40 
41 #include "TGMdi.h"
42 #include "TGMdiMenu.h"
43 #include "TList.h"
44 #include "Riostream.h"
45 
46 
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// TGMdiMenuBar constructor.
51 
52 TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
54 {
59 
60  fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
61  fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
62  fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
63 
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// TGMdiMenuBar destructor.
71 
73 {
74  if (!MustCleanup()) {
75  delete fLHint;
76  delete fLeftHint;
77  delete fRightHint;
78  delete fBarHint;
79  }
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Add popup menu to the MDI menu bar with layout hints l.
84 
86 {
87  fBar->AddPopup(s, menu, l);
88  // Layout();
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// This is called from TGMdiMainFrame on Maximize().
93 
95 {
96  // Hide all frames first
97  TGFrameElement *el;
98  TIter nextl(fLeft->GetList());
99  while ((el = (TGFrameElement *) nextl())) {
100  fLeft->HideFrame(el->fFrame);
101  }
102  TIter nextr(fRight->GetList());
103  while ((el = (TGFrameElement *) nextr())) {
104  fRight->HideFrame(el->fFrame);
105  }
106  // Then add specified frames
107  icon->ReparentWindow(fLeft);
108  buttons->ReparentWindow(fRight);
109  fLeft->AddFrame(icon, fLHint);
110  fRight->AddFrame(buttons, fLHint);
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// This is called from TGMdiMainFrame on Restore()
115 
117 {
118  // Remove specified frames
119  fLeft->RemoveFrame(icon);
120  fRight->RemoveFrame(buttons);
121  // Then show (restore) last frames
122  TGFrameElement *el;
123  el = (TGFrameElement *)fLeft->GetList()->Last();
124  if (el)
125  fLeft->ShowFrame(el->fFrame);
126  el = (TGFrameElement *)fRight->GetList()->Last();
127  if (el)
128  fRight->ShowFrame(el->fFrame);
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// This is called from TGMdiMainFrame on Maximize().
133 
135 {
136  // Hide all frames first
137  TGFrameElement *el;
138  TIter nextl(fLeft->GetList());
139  while ((el = (TGFrameElement *) nextl())) {
140  fLeft->HideFrame(el->fFrame);
141  }
142  TIter nextr(fRight->GetList());
143  while ((el = (TGFrameElement *) nextr())) {
144  fRight->HideFrame(el->fFrame);
145  }
146  // Then show specified frames
147  fLeft->ShowFrame(icon);
148  fRight->ShowFrame(buttons);
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Used to hide specific frames from menu bar
153 
155 {
156  // Hide specified frames
157  fLeft->HideFrame(icon);
158  fRight->HideFrame(buttons);
159 
160  // Then show (restore) last frames
161  TGFrameElement *el;
162  el = (TGFrameElement *)fLeft->GetList()->Last();
163  if (el)
164  fLeft->ShowFrame(el->fFrame);
165  el = (TGFrameElement *)fRight->GetList()->Last();
166  if (el)
167  fRight->ShowFrame(el->fFrame);
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Save a MDI menu as a C++ statement(s) on output stream out
172 
173 void TGMdiMenuBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
174 {
175  out << std::endl;
176  out << " // MDI menu bar" << std::endl;
177 
178  out << " TGMdiMenuBar *";
179  out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
180  << "," << GetWidth() << "," << GetHeight() << ");" << std::endl;
181  if (option && strstr(option, "keep_names"))
182  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
183 
184  if (!fList) return;
185 
186  out << " TGMenuBar *" << fBar->GetName() << " = " << GetName()
187  << "->GetMenuBar();" << std::endl;
188 
189  TGFrameElement *el;
190  TIter next(fBar->GetList());
191 
192  while ((el = (TGFrameElement *)next())) {
193  el->fFrame->SavePrimitive(out, option);
194  el->fLayout->SavePrimitive(out, option);
195  out << ");" << std::endl;
196  }
197 }
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1172
const TGWindow * fParent
Definition: TGWindow.h:37
void HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
Used to hide specific frames from menu bar.
Definition: TGMdiMenu.cxx:154
TGLayoutHints * fRightHint
Definition: TGMdiMenu.h:61
TGCompositeFrame * fLeft
Definition: TGMdiMenu.h:58
const char Option_t
Definition: RtypesCore.h:62
UInt_t GetHeight() const
Definition: TGFrame.h:272
TH1 * h
Definition: legend2.C:5
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:689
void AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:94
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1186
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a MDI menu as a C++ statement(s) on output stream out.
Definition: TGMdiMenu.cxx:173
UInt_t GetWidth() const
Definition: TGFrame.h:271
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1131
TGLayoutHints * fLayout
Definition: TGLayout.h:121
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 TList * GetList() const
Definition: TGFrame.h:369
virtual ~TGMdiMenuBar()
TGMdiMenuBar destructor.
Definition: TGMdiMenu.cxx:72
void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
Add popup menu to the MDI menu bar with layout hints l.
Definition: TGMdiMenu.cxx:85
TGCompositeFrame * fRight
Definition: TGMdiMenu.h:58
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
TList * fList
Definition: TGFrame.h:351
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
TGFrame * fFrame
Definition: TGLayout.h:119
TGMenuBar * fBar
Definition: TGMdiMenu.h:59
#define ClassImp(name)
Definition: Rtypes.h:359
static constexpr double s
void ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:134
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
TGMdiMenuBar(const TGWindow *p, Int_t w=1, Int_t h=20)
TGMdiMenuBar constructor.
Definition: TGMdiMenu.cxx:52
auto * l
Definition: textangle.C:4
void RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Restore()
Definition: TGMdiMenu.cxx:116
TGLayoutHints * fLeftHint
Definition: TGMdiMenu.h:60
TGLayoutHints * fBarHint
Definition: TGMdiMenu.h:61
TGLayoutHints * fLHint
Definition: TGMdiMenu.h:60
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=0)
Add popup menu to menu bar.
Definition: TGMenu.cxx:415
virtual Int_t MustCleanup() const
Definition: TGFrame.h:420