Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
47 ClassImp(TGMdiMenuBar);
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// TGMdiMenuBar constructor.
51 
52 TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
53  TGCompositeFrame(p, w, h, kHorizontalFrame)
54 {
55  fLHint = new TGLayoutHints(kLHintsNormal);
56  fLeftHint = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1);
57  fBarHint = new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 1, 1, 1, 1);
58  fRightHint = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 1, 2, 1, 1);
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 
64  AddFrame(fLeft, fLeftHint);
65  AddFrame(fBar, fBarHint);
66  AddFrame(fRight, fRightHint);
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// TGMdiMenuBar destructor.
71 
72 TGMdiMenuBar::~TGMdiMenuBar()
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 
85 void TGMdiMenuBar::AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
86 {
87  fBar->AddPopup(s, menu, l);
88  // Layout();
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// This is called from TGMdiMainFrame on Maximize().
93 
94 void TGMdiMenuBar::AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
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 
116 void TGMdiMenuBar::RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
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 
134 void TGMdiMenuBar::ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
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 
154 void TGMdiMenuBar::HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
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 }