Logo ROOT  
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 /** \class TGMdiMenu.
35  \ingroup guiwidgets
36 
37 This file contains the TGMdiMenuBar class.
38 
39 */
40 
41 
42 #include "TGMdi.h"
43 #include "TGMdiMenu.h"
44 #include "TList.h"
45 
46 #include <iostream>
47 
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// TGMdiMenuBar constructor.
53 
54 TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
56 {
61 
62  fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
63  fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
64  fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
65 
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// TGMdiMenuBar destructor.
73 
75 {
76  if (!MustCleanup()) {
77  delete fLHint;
78  delete fLeftHint;
79  delete fRightHint;
80  delete fBarHint;
81  }
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Add popup menu to the MDI menu bar with layout hints l.
86 
88 {
89  fBar->AddPopup(s, menu, l);
90  // Layout();
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// This is called from TGMdiMainFrame on Maximize().
95 
97 {
98  // Hide all frames first
99  TGFrameElement *el;
100  TIter nextl(fLeft->GetList());
101  while ((el = (TGFrameElement *) nextl())) {
102  fLeft->HideFrame(el->fFrame);
103  }
104  TIter nextr(fRight->GetList());
105  while ((el = (TGFrameElement *) nextr())) {
106  fRight->HideFrame(el->fFrame);
107  }
108  // Then add specified frames
109  icon->ReparentWindow(fLeft);
110  buttons->ReparentWindow(fRight);
111  fLeft->AddFrame(icon, fLHint);
112  fRight->AddFrame(buttons, fLHint);
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// This is called from TGMdiMainFrame on Restore()
117 
119 {
120  // Remove specified frames
121  fLeft->RemoveFrame(icon);
122  fRight->RemoveFrame(buttons);
123  // Then show (restore) last frames
124  TGFrameElement *el;
125  el = (TGFrameElement *)fLeft->GetList()->Last();
126  if (el)
127  fLeft->ShowFrame(el->fFrame);
128  el = (TGFrameElement *)fRight->GetList()->Last();
129  if (el)
130  fRight->ShowFrame(el->fFrame);
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// This is called from TGMdiMainFrame on Maximize().
135 
137 {
138  // Hide all frames first
139  TGFrameElement *el;
140  TIter nextl(fLeft->GetList());
141  while ((el = (TGFrameElement *) nextl())) {
142  fLeft->HideFrame(el->fFrame);
143  }
144  TIter nextr(fRight->GetList());
145  while ((el = (TGFrameElement *) nextr())) {
146  fRight->HideFrame(el->fFrame);
147  }
148  // Then show specified frames
149  fLeft->ShowFrame(icon);
150  fRight->ShowFrame(buttons);
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Used to hide specific frames from menu bar
155 
157 {
158  // Hide specified frames
159  fLeft->HideFrame(icon);
160  fRight->HideFrame(buttons);
161 
162  // Then show (restore) last frames
163  TGFrameElement *el;
164  el = (TGFrameElement *)fLeft->GetList()->Last();
165  if (el)
166  fLeft->ShowFrame(el->fFrame);
167  el = (TGFrameElement *)fRight->GetList()->Last();
168  if (el)
169  fRight->ShowFrame(el->fFrame);
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Save a MDI menu as a C++ statement(s) on output stream out
174 
175 void TGMdiMenuBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
176 {
177  out << std::endl;
178  out << " // MDI menu bar" << std::endl;
179 
180  out << " TGMdiMenuBar *";
181  out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
182  << "," << GetWidth() << "," << GetHeight() << ");" << std::endl;
183  if (option && strstr(option, "keep_names"))
184  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
185 
186  if (!fList) return;
187 
188  out << " TGMenuBar *" << fBar->GetName() << " = " << GetName()
189  << "->GetMenuBar();" << std::endl;
190 
191  TGFrameElement *el;
192  TIter next(fBar->GetList());
193 
194  while ((el = (TGFrameElement *)next())) {
195  el->fFrame->SavePrimitive(out, option);
196  el->fLayout->SavePrimitive(out, option);
197  out << ");" << std::endl;
198  }
199 }
TGMdiMenuBar::fLeftHint
TGLayoutHints * fLeftHint
Definition: TGMdiMenu.h:53
l
auto * l
Definition: textangle.C:4
TGMdiMenuBar::ShowFrames
void ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:136
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:225
TGFrameElement::fLayout
TGLayoutHints * fLayout
Definition: TGLayout.h:114
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
TGCompositeFrame::GetList
virtual TList * GetList() const
Definition: TGFrame.h:310
Option_t
const char Option_t
Definition: RtypesCore.h:66
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGHotString
TGHotString is a string with a "hot" character underlined.
Definition: TGString.h:42
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:24
TGMdiMenuBar::TGMdiMenuBar
TGMdiMenuBar(const TGWindow *p, Int_t w=1, Int_t h=20)
TGMdiMenuBar constructor.
Definition: TGMdiMenu.cxx:54
TGMdiMenu.h
TGMdiMenuBar::fLeft
TGCompositeFrame * fLeft
Definition: TGMdiMenu.h:51
TGFrame::SavePrimitive
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:3207
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TGMdiMenuBar::fLHint
TGLayoutHints * fLHint
Definition: TGMdiMenu.h:53
TList.h
TList::Last
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:693
TGMdiMenuBar::HideFrames
void HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
Used to hide specific frames from menu bar.
Definition: TGMdiMenu.cxx:156
TGMdi.h
TGMdiMenuBar::SavePrimitive
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:175
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:224
TGCompositeFrame::fList
TList * fList
Definition: TGFrame.h:292
TGFrameElement::fFrame
TGFrame * fFrame
Definition: TGLayout.h:112
TGMenuBar::AddPopup
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=0)
Add popup menu to menu bar.
Definition: TGMenu.cxx:418
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:32
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:28
h
#define h(i)
Definition: RSha256.hxx:106
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
TGFrame::ReparentWindow
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:202
TGCompositeFrame::HideFrame
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1190
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:26
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
TGMdiButtons
Definition: TGMdiDecorFrame.h:129
TGCompositeFrame::MustCleanup
virtual Int_t MustCleanup() const
Definition: TGFrame.h:361
TGLayoutHints::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save layout hints as a C++ statement(s) on output stream out.
Definition: TGLayout.cxx:975
TGMdiMenuBar::RemoveFrames
void RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Restore()
Definition: TGMdiMenu.cxx:118
TGCompositeFrame::RemoveFrame
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1149
TGMdiMenuBar::fRight
TGCompositeFrame * fRight
Definition: TGMdiMenu.h:51
TGMdiTitleIcon
Definition: TGMdiDecorFrame.h:150
TGMdiMenuBar::~TGMdiMenuBar
virtual ~TGMdiMenuBar()
TGMdiMenuBar destructor.
Definition: TGMdiMenu.cxx:74
TGMdiMenuBar::AddFrames
void AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:96
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGMdiMenuBar::fBarHint
TGLayoutHints * fBarHint
Definition: TGMdiMenu.h:54
TGMdiMenuBar::AddPopup
void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
Add popup menu to the MDI menu bar with layout hints l.
Definition: TGMdiMenu.cxx:87
TGMdiMenuBar::fBar
TGMenuBar * fBar
Definition: TGMdiMenu.h:52
TGPopupMenu
This class creates a popup menu object.
Definition: TGMenu.h:110
TGMdiMenuBar::fRightHint
TGLayoutHints * fRightHint
Definition: TGMdiMenu.h:54
TGFrameElement
Definition: TGLayout.h:105
TIter
Definition: TCollection.h:233
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:30
TGCompositeFrame::TGCompositeFrame
TGCompositeFrame(const TGCompositeFrame &)=delete
TGMenuBar
This class creates a menu bar.
Definition: TGMenu.h:289
TGCompositeFrame
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TGCompositeFrame::ShowFrame
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1204
TGWindow::fParent
const TGWindow * fParent
Definition: TGWindow.h:28
TGMdiMenuBar
Definition: TGMdiMenu.h:46