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
37This 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
54TGMdiMenuBar::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
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
175void 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}
@ kHorizontalFrame
Definition: GuiTypes.h:382
#define h(i)
Definition: RSha256.hxx:106
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
@ kLHintsRight
Definition: TGLayout.h:26
@ kLHintsLeft
Definition: TGLayout.h:24
@ kLHintsCenterY
Definition: TGLayout.h:28
@ kLHintsNormal
Definition: TGLayout.h:32
@ kLHintsExpandX
Definition: TGLayout.h:30
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TGCompositeFrame(const TGCompositeFrame &)=delete
virtual Int_t MustCleanup() const
Definition: TGFrame.h:361
virtual TList * GetList() const
Definition: TGFrame.h:310
virtual void ShowFrame(TGFrame *f)
Show sub frame.
Definition: TGFrame.cxx:1204
TList * fList
container of frame elements
Definition: TGFrame.h:292
virtual void RemoveFrame(TGFrame *f)
Remove frame from composite frame.
Definition: TGFrame.cxx:1149
virtual void HideFrame(TGFrame *f)
Hide sub frame.
Definition: TGFrame.cxx:1190
TGLayoutHints * fLayout
Definition: TGLayout.h:114
TGFrame * fFrame
Definition: TGLayout.h:112
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
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:3213
UInt_t GetHeight() const
Definition: TGFrame.h:225
UInt_t GetWidth() const
Definition: TGFrame.h:224
TGHotString is a string with a "hot" character underlined.
Definition: TGString.h:42
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
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
void HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
Used to hide specific frames from menu bar.
Definition: TGMdiMenu.cxx:156
TGMenuBar * fBar
standard menu bar
Definition: TGMdiMenu.h:52
TGCompositeFrame * fLeft
Definition: TGMdiMenu.h:51
virtual ~TGMdiMenuBar()
TGMdiMenuBar destructor.
Definition: TGMdiMenu.cxx:74
void ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:136
void AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Maximize().
Definition: TGMdiMenu.cxx:96
TGLayoutHints * fLHint
Definition: TGMdiMenu.h:53
TGLayoutHints * fRightHint
Definition: TGMdiMenu.h:54
TGLayoutHints * fBarHint
right layout hints
Definition: TGMdiMenu.h:54
void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
Add popup menu to the MDI menu bar with layout hints l.
Definition: TGMdiMenu.cxx:87
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
TGLayoutHints * fLeftHint
left layout hints
Definition: TGMdiMenu.h:53
TGMdiMenuBar(const TGWindow *p, Int_t w=1, Int_t h=20)
TGMdiMenuBar constructor.
Definition: TGMdiMenu.cxx:54
TGCompositeFrame * fRight
left and right parts of MDI menu bar
Definition: TGMdiMenu.h:51
void RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
This is called from TGMdiMainFrame on Restore()
Definition: TGMdiMenu.cxx:118
The TGMenu.h header contains all different menu classes.
Definition: TGMenu.h:282
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=0)
Add popup menu to menu bar.
Definition: TGMenu.cxx:418
This class creates a popup menu object.
Definition: TGMenu.h:110
ROOT GUI Window base class.
Definition: TGWindow.h:23
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
const TGWindow * fParent
Parent window.
Definition: TGWindow.h:28
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:693
static constexpr double s
auto * l
Definition: textangle.C:4