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 // //
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 
45 #include <iostream>
46 
47 
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// TGMdiMenuBar constructor.
52 
53 TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
55 {
60 
61  fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
62  fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
63  fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
64 
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// TGMdiMenuBar destructor.
72 
74 {
75  if (!MustCleanup()) {
76  delete fLHint;
77  delete fLeftHint;
78  delete fRightHint;
79  delete fBarHint;
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Add popup menu to the MDI menu bar with layout hints l.
85 
87 {
88  fBar->AddPopup(s, menu, l);
89  // Layout();
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// This is called from TGMdiMainFrame on Maximize().
94 
96 {
97  // Hide all frames first
98  TGFrameElement *el;
99  TIter nextl(fLeft->GetList());
100  while ((el = (TGFrameElement *) nextl())) {
101  fLeft->HideFrame(el->fFrame);
102  }
103  TIter nextr(fRight->GetList());
104  while ((el = (TGFrameElement *) nextr())) {
105  fRight->HideFrame(el->fFrame);
106  }
107  // Then add specified frames
108  icon->ReparentWindow(fLeft);
109  buttons->ReparentWindow(fRight);
110  fLeft->AddFrame(icon, fLHint);
111  fRight->AddFrame(buttons, fLHint);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// This is called from TGMdiMainFrame on Restore()
116 
118 {
119  // Remove specified frames
120  fLeft->RemoveFrame(icon);
121  fRight->RemoveFrame(buttons);
122  // Then show (restore) last frames
123  TGFrameElement *el;
124  el = (TGFrameElement *)fLeft->GetList()->Last();
125  if (el)
126  fLeft->ShowFrame(el->fFrame);
127  el = (TGFrameElement *)fRight->GetList()->Last();
128  if (el)
129  fRight->ShowFrame(el->fFrame);
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// This is called from TGMdiMainFrame on Maximize().
134 
136 {
137  // Hide all frames first
138  TGFrameElement *el;
139  TIter nextl(fLeft->GetList());
140  while ((el = (TGFrameElement *) nextl())) {
141  fLeft->HideFrame(el->fFrame);
142  }
143  TIter nextr(fRight->GetList());
144  while ((el = (TGFrameElement *) nextr())) {
145  fRight->HideFrame(el->fFrame);
146  }
147  // Then show specified frames
148  fLeft->ShowFrame(icon);
149  fRight->ShowFrame(buttons);
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Used to hide specific frames from menu bar
154 
156 {
157  // Hide specified frames
158  fLeft->HideFrame(icon);
159  fRight->HideFrame(buttons);
160 
161  // Then show (restore) last frames
162  TGFrameElement *el;
163  el = (TGFrameElement *)fLeft->GetList()->Last();
164  if (el)
165  fLeft->ShowFrame(el->fFrame);
166  el = (TGFrameElement *)fRight->GetList()->Last();
167  if (el)
168  fRight->ShowFrame(el->fFrame);
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Save a MDI menu as a C++ statement(s) on output stream out
173 
174 void TGMdiMenuBar::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
175 {
176  out << std::endl;
177  out << " // MDI menu bar" << std::endl;
178 
179  out << " TGMdiMenuBar *";
180  out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
181  << "," << GetWidth() << "," << GetHeight() << ");" << std::endl;
182  if (option && strstr(option, "keep_names"))
183  out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
184 
185  if (!fList) return;
186 
187  out << " TGMenuBar *" << fBar->GetName() << " = " << GetName()
188  << "->GetMenuBar();" << std::endl;
189 
190  TGFrameElement *el;
191  TIter next(fBar->GetList());
192 
193  while ((el = (TGFrameElement *)next())) {
194  el->fFrame->SavePrimitive(out, option);
195  el->fLayout->SavePrimitive(out, option);
196  out << ");" << std::endl;
197  }
198 }
TGMdiMenuBar::fLeftHint
TGLayoutHints * fLeftHint
Definition: TGMdiMenu.h:60
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:135
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:250
TGFrameElement::fLayout
TGLayoutHints * fLayout
Definition: TGLayout.h:121
TGWindow
Definition: TGWindow.h:31
TGCompositeFrame::GetList
virtual TList * GetList() const
Definition: TGFrame.h:347
TGCompositeFrame::TGCompositeFrame
TGCompositeFrame(const TGCompositeFrame &)
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TGHotString
Definition: TGString.h:52
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGMdiMenuBar::TGMdiMenuBar
TGMdiMenuBar(const TGWindow *p, Int_t w=1, Int_t h=20)
TGMdiMenuBar constructor.
Definition: TGMdiMenu.cxx:53
TGMdiMenu.h
TGMdiMenuBar::fLeft
TGCompositeFrame * fLeft
Definition: TGMdiMenu.h:58
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:3192
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TGMdiMenuBar::fLHint
TGLayoutHints * fLHint
Definition: TGMdiMenu.h:60
TList.h
TList::Last
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:692
TGMdiMenuBar::HideFrames
void HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
Used to hide specific frames from menu bar.
Definition: TGMdiMenu.cxx:155
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:174
TGFrame::GetWidth
UInt_t GetWidth() const
Definition: TGFrame.h:249
TGCompositeFrame::fList
TList * fList
Definition: TGFrame.h:329
TGFrameElement::fFrame
TGFrame * fFrame
Definition: TGLayout.h:119
TGMenuBar::AddPopup
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=0)
Add popup menu to menu bar.
Definition: TGMenu.cxx:417
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:45
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
h
#define h(i)
Definition: RSha256.hxx:124
TGWindow::GetName
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:317
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:227
TGCompositeFrame::HideFrame
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1175
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:39
TGLayoutHints
Definition: TGLayout.h:57
TGMdiButtons
Definition: TGMdiDecorFrame.h:138
TGCompositeFrame::MustCleanup
virtual Int_t MustCleanup() const
Definition: TGFrame.h:398
TGLayoutHints::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TGLayout.cxx:1004
TGMdiMenuBar::RemoveFrames
void RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Restore()
Definition: TGMdiMenu.cxx:117
TGCompositeFrame::RemoveFrame
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1134
TGMdiMenuBar::fRight
TGCompositeFrame * fRight
Definition: TGMdiMenu.h:58
TGMdiTitleIcon
Definition: TGMdiDecorFrame.h:159
TGMdiMenuBar::~TGMdiMenuBar
virtual ~TGMdiMenuBar()
TGMdiMenuBar destructor.
Definition: TGMdiMenu.cxx:73
TGMdiMenuBar::AddFrames
void AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:95
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGMdiMenuBar::fBarHint
TGLayoutHints * fBarHint
Definition: TGMdiMenu.h:61
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:86
TGMdiMenuBar::fBar
TGMenuBar * fBar
Definition: TGMdiMenu.h:59
TGPopupMenu
Definition: TGMenu.h:123
TGMdiMenuBar::fRightHint
TGLayoutHints * fRightHint
Definition: TGMdiMenu.h:61
TGFrameElement
Definition: TGLayout.h:112
TIter
Definition: TCollection.h:233
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGMenuBar
Definition: TGMenu.h:304
TGCompositeFrame
Definition: TGFrame.h:324
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TGCompositeFrame::ShowFrame
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1189
TGWindow::fParent
const TGWindow * fParent
Definition: TGWindow.h:36
TGMdiMenuBar
Definition: TGMdiMenu.h:53