Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mditest.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// GUI MDI features
4///
5/// \macro_code
6///
7/// \authors Ilka Antcheva, Fons Rademakers
8
9#include <cstdio>
10#include <cstdlib>
11
12#include <TApplication.h>
13#include <TGClient.h>
14#include <TGFrame.h>
15#include <TGButton.h>
16#include <TGTextEntry.h>
17#include <TGCanvas.h>
18#include <TGMenu.h>
19#include <TGMdi.h>
20#include <TGMsgBox.h>
21#include <TGSlider.h>
22#include <TGListBox.h>
23#include <RQ_OBJECT.h>
24
25enum EMenuIds {
26 M_FILE_NEW,
27 M_FILE_CLOSE,
28 M_FILE_EXIT,
29
30 M_WINDOW_HOR,
31 M_WINDOW_VERT,
32 M_WINDOW_CASCADE,
33 M_WINDOW_OPAQUE,
34 M_WINDOW_ARRANGE,
35
36 M_HELP_CONTENTS,
37 M_HELP_ABOUT
38};
39
40
41//----------------------------------------------------------------------
42
43class TGMdiTestSubclass {
44
45RQ_OBJECT("TGMdiTestSubclass")
46
47protected:
48 TGMdiFrame *fMdiFrame;
49 TGCanvas *fCanvasWindow;
50 TGCompositeFrame *fContainer;
51
52public:
53 TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h);
54
55 TGMdiFrame *GetMdiFrame() const { return fMdiFrame; }
56 virtual Bool_t CloseWindow();
57};
58
59class TGMdiHintTest {
60
61RQ_OBJECT("TGMdiHintTest")
62
63protected:
64 TGMdiFrame *fMdiFrame;
65 TGTextEntry *fWName;
66 TGCheckButton *fClose, *fMenu, *fMin, *fMax, *fSize, *fHelp;
67
68public:
69 TGMdiHintTest(TGMdiMainFrame *main, int w, int h);
70
71 void HandleButtons();
72 void HandleText(const char *);
73};
74
75class TGAppMainFrame {
76
77RQ_OBJECT("TGAppMainFrame")
78
79protected:
80 TGMainFrame *fMain;
81 TGMdiMainFrame *fMainFrame;
82 TGMdiMenuBar *fMenuBar;
83 TGLayoutHints *fMenuBarItemLayout;
84 TGPopupMenu *fMenuFile, *fMenuWindow, *fMenuHelp;
85
86 void InitMenu();
87 void CloseWindow();
88
89public:
90 TGAppMainFrame(const TGWindow *p, int w, int h);
91
92 void HandleMenu(Int_t id);
93};
94
95//----------------------------------------------------------------------
96
97TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h)
98{
99 fMain = new TGMainFrame(p, w, h, kVerticalFrame);
100 fMenuBar = new TGMdiMenuBar(fMain, 10, 10);
101 fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
102
103 fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300);
104 fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
105
106 const TGPicture *pbg = gClient->GetPicture("mditestbg.xpm");
107 if (pbg)
108 fMainFrame->GetContainer()->SetBackgroundPixmap(pbg->GetPicture());
109
110 TGMdiFrame *mdiFrame;
111
112 //--- 1
113
114 TGMdiTestSubclass *t = new TGMdiTestSubclass(fMainFrame, 320, 240);
115 mdiFrame = t->GetMdiFrame();
116 mdiFrame->SetMdiHints(kMdiClose | kMdiMenu);
117 mdiFrame->SetWindowName("One");
118 mdiFrame->MapSubwindows();
119 mdiFrame->Layout();
120
121 //--- 2
122
123 ULong_t ic;
124 gClient->GetColorByName("red", ic);
125 mdiFrame = new TGMdiFrame(fMainFrame, 200, 200,
126 kOwnBackground, ic);
127 mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("&Press me!"), 1),
130 mdiFrame->SetWindowName("Two");
131 mdiFrame->MapSubwindows();
132 mdiFrame->Layout();
133 mdiFrame->Move(150, 200);
134
135 //--- 3
136
137 gClient->GetColorByName("green", ic);
138 mdiFrame = new TGMdiFrame(fMainFrame, 200, 200, kOwnBackground, ic);
139 mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 1"), 11),
141 mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 2"), 12),
144 mdiFrame->SetWindowName("Three");
145 mdiFrame->MapSubwindows();
146 mdiFrame->Layout();
147 mdiFrame->Move(180, 220);
148
149 //--- 4
150
151 gClient->GetColorByName("blue", ic);
152 mdiFrame = new TGMdiFrame(fMainFrame, 200, 400, kOwnBackground, ic);
153
154 TGListBox *fListBox = new TGListBox(mdiFrame,1);
155 fListBox->AddEntry("Entry 1", 1);
156 fListBox->AddEntry("Entry 2", 2);
157 fListBox->AddEntry("Entry 3", 3);
158 fListBox->AddEntry("Entry 4", 4);
159 fListBox->AddEntry("Entry 5", 5);
160 fListBox->AddEntry("Entry 6", 6);
161 fListBox->AddEntry("Entry 7", 7);
162 fListBox->AddEntry("Entry 8", 8);
163 fListBox->AddEntry("Entry 9", 9);
164 fListBox->Resize(100,70);
165 fListBox->SetMultipleSelections(kFALSE);
166 mdiFrame->AddFrame(fListBox,
168 mdiFrame->AddFrame(new TGHSlider(mdiFrame, 50, kSlider1, 1,
169 kHorizontalFrame, ic),
171 mdiFrame->Move(400, 300);
172 mdiFrame->SetWindowName("Four");
173 mdiFrame->MapSubwindows();
174 mdiFrame->Layout();
175
176 //--- 5
177
178 new TGMdiHintTest(fMainFrame, 200, 200);
179
180 InitMenu();
181
182 fMain->SetWindowName("MDI test");
183 fMain->SetClassHints("mdi test", "mdi test");
184
185 if (pbg && pbg->GetWidth() > 600 && pbg->GetHeight() > 400)
186 fMain->Resize(pbg->GetWidth(), pbg->GetHeight()+25);
187 else
188 fMain->Resize(640, 400);
189
190 fMain->MapSubwindows();
191 fMain->MapWindow();
192 fMain->Layout();
193}
194
195void TGAppMainFrame::HandleMenu(Int_t id)
196{
197 // Handle menu items.
198
199 switch (id) {
200 case M_FILE_NEW:
201 new TGMdiFrame(fMainFrame, 200, 100);
202 break;
203
204 case M_FILE_CLOSE:
205 fMainFrame->Close(fMainFrame->GetCurrent());
206 break;
207
208 case M_FILE_EXIT:
209 CloseWindow();
210 break;
211
212 case M_WINDOW_HOR:
213 fMainFrame->TileHorizontal();
214 break;
215
216 case M_WINDOW_VERT:
217 fMainFrame->TileVertical();
218 break;
219
220 case M_WINDOW_CASCADE:
221 fMainFrame->Cascade();
222 break;
223
224 case M_WINDOW_ARRANGE:
225 fMainFrame->ArrangeMinimized();
226 break;
227
228 case M_WINDOW_OPAQUE:
229 if (fMenuWindow->IsEntryChecked(M_WINDOW_OPAQUE)) {
230 fMenuWindow->UnCheckEntry(M_WINDOW_OPAQUE);
231 fMainFrame->SetResizeMode(kMdiNonOpaque);
232 } else {
233 fMenuWindow->CheckEntry(M_WINDOW_OPAQUE);
234 fMainFrame->SetResizeMode(kMdiOpaque);
235 }
236 break;
237
238 default:
239 fMainFrame->SetCurrent(id);
240 break;
241 }
242}
243
244void TGAppMainFrame::InitMenu()
245{
246 fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
247
248 fMenuFile = new TGPopupMenu(gClient->GetRoot());
249 fMenuFile->AddEntry(new TGHotString("&New Window"), M_FILE_NEW);
250 fMenuFile->AddEntry(new TGHotString("&Close Window"), M_FILE_CLOSE);
251 fMenuFile->AddSeparator();
252 fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT);
253
254 fMenuWindow = new TGPopupMenu(gClient->GetRoot());
255 fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR);
256 fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT);
257 fMenuWindow->AddEntry(new TGHotString("&Cascade"), M_WINDOW_CASCADE);
258 fMenuWindow->AddSeparator();
259 fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu());
260 fMenuWindow->AddSeparator();
261 fMenuWindow->AddEntry(new TGHotString("&Arrange icons"), M_WINDOW_ARRANGE);
262 fMenuWindow->AddSeparator();
263 fMenuWindow->AddEntry(new TGHotString("&Opaque resize"), M_WINDOW_OPAQUE);
264
265 fMenuWindow->CheckEntry(M_WINDOW_OPAQUE);
266
267 fMenuHelp = new TGPopupMenu(gClient->GetRoot());
268 fMenuHelp->AddEntry(new TGHotString("&Contents"), M_HELP_CONTENTS);
269 fMenuHelp->AddSeparator();
270 fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT);
271
272 fMenuHelp->DisableEntry(M_HELP_CONTENTS);
273 fMenuHelp->DisableEntry(M_HELP_ABOUT);
274
275 // menu message are handled by the class' HandleMenu() method
276 fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this,
277 "HandleMenu(Int_t)");
278 fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this,
279 "HandleMenu(Int_t)");
280 fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this,
281 "HandleMenu(Int_t)");
282
283 fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout);
284 fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout);
285 fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout);
286}
287
288void TGAppMainFrame::CloseWindow()
289{
291}
292
293//----------------------------------------------------------------------
294
295TGMdiTestSubclass::TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h)
296{
297 fMdiFrame = new TGMdiFrame(main, w, h);
298 fMdiFrame->Connect("CloseWindow()", "TGMdiTestSubclass", this, "CloseWindow()");
299 fMdiFrame->DontCallClose();
300
301 fCanvasWindow = new TGCanvas(fMdiFrame, 400, 240);
302 fContainer = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 10, 10,
304 fMdiFrame->GetWhitePixel());
305 fContainer->SetLayoutManager(new TGTileLayout(fContainer, 8));
306 fCanvasWindow->SetContainer(fContainer);
307
308 for (int i = 0; i < 256; ++i)
309 fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
310 32, 32, kOwnBackground, (i+1) & 255),
312
313 fMdiFrame->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
314
315 fMdiFrame->SetWindowIcon(gClient->GetPicture("ofolder_t.xpm"));
316}
317
318Bool_t TGMdiTestSubclass::CloseWindow()
319{
320 int ret = 0;
321
322 new TGMsgBox(gClient->GetRoot(), fMdiFrame,
323 fMdiFrame->GetWindowName(), "Really want to close the window?",
325
326 if (ret == kMBYes) return fMdiFrame->CloseWindow();
327
328 return kFALSE;
329}
330
331
332//----------------------------------------------------------------------
333
334TGMdiHintTest::TGMdiHintTest(TGMdiMainFrame *main, int w, int h)
335{
336 fMdiFrame = new TGMdiFrame(main, w, h);
337
338 fClose = new TGCheckButton(fMdiFrame, new TGHotString("Close"), 11);
339 fMenu = new TGCheckButton(fMdiFrame, new TGHotString("Menu (left icon)"), 12);
340 fMin = new TGCheckButton(fMdiFrame, new TGHotString("Minimize"), 13);
341 fMax = new TGCheckButton(fMdiFrame, new TGHotString("Maximize"), 14);
342 fSize = new TGCheckButton(fMdiFrame, new TGHotString("Resize"), 15);
343 fHelp = new TGCheckButton(fMdiFrame, new TGHotString("Help"), 16);
344
345 TGLayoutHints *lh = new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 100, 5, 0);
346
347 fMdiFrame->AddFrame(fClose, lh);
348 fMdiFrame->AddFrame(fMenu, lh);
349 fMdiFrame->AddFrame(fMin, lh);
350 fMdiFrame->AddFrame(fMax, lh);
351 fMdiFrame->AddFrame(fSize, lh);
352 fMdiFrame->AddFrame(fHelp, lh);
353
354 fClose->SetState(kButtonDown);
355 fMin->SetState(kButtonDown);
356 fMenu->SetState(kButtonDown);
357 fMax->SetState(kButtonDown);
358 fSize->SetState(kButtonDown);
359
360 fClose->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
361 fMenu->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
362 fMin->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
363 fMax->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
364 fSize->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
365 fHelp->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
366
367 fWName = new TGTextEntry(fMdiFrame, (const char *)"", 20);
368 fMdiFrame->AddFrame(fWName, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
369 5, 5, 5, 5));
370
371 fWName->GetBuffer()->AddText(0, "MDI hints test");
372 fWName->Connect("TextChanged(char*)", "TGMdiHintTest", this, "HandleText(char*)");
373
374 fMdiFrame->SetMdiHints(kMdiDefaultHints);
375 fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString());
376
377 fMdiFrame->SetWindowIcon(gClient->GetPicture("app_t.xpm"));
378
379 fMdiFrame->MapSubwindows();
380 fMdiFrame->Layout();
381}
382
383void TGMdiHintTest::HandleButtons()
384{
385 int hints = 0;
386
387 if (fClose->GetState() != kButtonUp) hints |= kMdiClose;
388 if (fMenu->GetState() != kButtonUp) hints |= kMdiMenu;
389 if (fMin->GetState() != kButtonUp) hints |= kMdiMinimize;
390 if (fMax->GetState() != kButtonUp) hints |= kMdiMaximize;
391 if (fSize->GetState() != kButtonUp) hints |= kMdiSize;
392 if (fHelp->GetState() != kButtonUp) hints |= kMdiHelp;
393
394 fMdiFrame->SetMdiHints(hints);
395}
396
397void TGMdiHintTest::HandleText(const char *)
398{
399 fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString());
400}
401
402void mditest()
403{
404 new TGAppMainFrame(gClient->GetRoot(), 640, 400);
405}
406
407//----------------------------------------------------------------------
408
409#ifdef STANDALONE
410int main(int argc, char **argv)
411{
412 TApplication theApp("MdiTest", &argc, argv);
413
414 mditest();
415
416 theApp.Run();
417
418 return 0;
419}
420#endif
dim_t fSize
@ kVerticalFrame
Definition GuiTypes.h:381
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kOwnBackground
Definition GuiTypes.h:391
int main()
Definition Prototype.cxx:12
#define RQ_OBJECT(sender_class)
Definition RQ_OBJECT.h:87
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
R__EXTERN TApplication * gApplication
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:156
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsNormal
Definition TGLayout.h:32
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kMdiNonOpaque
@ kMdiOpaque
@ kMdiMinimize
@ kMdiHelp
@ kMdiMenu
@ kMdiSize
@ kMdiMaximize
@ kMdiClose
@ kMdiDefaultHints
@ kMBNo
Definition TGMsgBox.h:32
@ kMBYes
Definition TGMsgBox.h:31
@ kMBIconExclamation
Definition TGMsgBox.h:24
@ kSlider1
Definition TGSlider.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual EButtonState GetState() const
Definition TGButton.h:112
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
Definition TGCanvas.h:192
Selects different options.
Definition TGButton.h:264
void SetState(EButtonState state, Bool_t emit=kFALSE) override
Set check button state.
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void Layout() override
Layout the elements of the composite frame.
Definition TGFrame.cxx:1257
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
Concrete class for horizontal slider.
Definition TGSlider.h:119
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
A listbox is a box, possibly with scrollbar, containing entries.
Definition TGListBox.h:221
void Resize(UInt_t w, UInt_t h) override
Resize the listbox widget.
virtual void AddEntry(TGString *s, Int_t id)
Add entry with specified string and id to listbox.
virtual void SetMultipleSelections(Bool_t multi=kTRUE)
Definition TGListBox.h:259
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
This file contains the TGMdiFrame class.
Definition TGMdiFrame.h:42
virtual void SetMdiHints(ULong_t mdihints)
Set MDI hints, also used to identify titlebar buttons.
void SetWindowName(const char *name) override
Set MDI window name (set titlebar title).
void Move(Int_t x, Int_t y) override
Move MDI window at position x, y.
This file contains the TGMdiMainFrame class.
Bool_t SetCurrent(TGMdiFrameList *newcurrent)
Set current (active) MDI child window (by frame list).
void SetResizeMode(Int_t mode=kMdiDefaultResizeMode)
Set MDI windows resize mode (opaque or transparent).
TGMdiFrame * GetCurrent() const
Return pointer on current (active) MDI child window.
virtual void ArrangeMinimized()
This is an attempt to an "smart" minimized window re-arrangement.
TGPopupMenu * GetWinListMenu() const
virtual void TileHorizontal()
virtual void TileVertical()
virtual void Cascade()
virtual Int_t Close(TGMdiFrame *frame)
Close MDI child window mdiframe.
TGFrame * GetContainer() const
void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
Add popup menu to the MDI menu bar with layout hints l.
Definition TGMdiMenu.cxx:87
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
UInt_t GetHeight() const
Definition TGPicture.h:53
Pixmap_t GetPicture() const
Definition TGPicture.h:54
UInt_t GetWidth() const
Definition TGPicture.h:52
This class creates a popup menu object.
Definition TGMenu.h:110
virtual Bool_t IsEntryChecked(Int_t id)
Return true if menu item is checked.
Definition TGMenu.cxx:1845
virtual void AddPopup(TGHotString *s, TGPopupMenu *popup, TGMenuEntry *before=nullptr, const TGPicture *p=nullptr)
Add a (cascading) popup menu to a popup menu.
Definition TGMenu.cxx:1152
virtual void CheckEntry(Int_t id)
Check a menu entry (i.e. add a check mark in front of it).
Definition TGMenu.cxx:1782
virtual void DisableEntry(Int_t id)
Disable entry (disabled entries appear in a sunken relieve).
Definition TGMenu.cxx:1724
virtual void UnCheckEntry(Int_t id)
Uncheck menu entry (i.e. remove check mark).
Definition TGMenu.cxx:1807
virtual void AddSeparator(TGMenuEntry *before=nullptr)
Add a menu separator to the menu.
Definition TGMenu.cxx:1060
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
Add a menu entry.
Definition TGMenu.cxx:990
void AddText(Int_t pos, const char *text)
const char * GetString() const
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
TGTextBuffer * GetBuffer() const
This is a layout manager for the TGListView widget.
Definition TGLayout.h:303
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition TGWindow.cxx:248
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869