Logo ROOT  
Reference Guide
mditest.C File Reference

Detailed Description

GUI MDI features

#include <stdio.h>
#include <stdlib.h>
#include <TApplication.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TGButton.h>
#include <TGTextEntry.h>
#include <TGCanvas.h>
#include <TGMenu.h>
#include <TGMdi.h>
#include <TGMsgBox.h>
#include <TGSlider.h>
#include <TGListBox.h>
#include <RQ_OBJECT.h>
enum EMenuIds {
M_FILE_NEW,
M_FILE_CLOSE,
M_FILE_EXIT,
M_WINDOW_HOR,
M_WINDOW_VERT,
M_WINDOW_CASCADE,
M_WINDOW_OPAQUE,
M_WINDOW_ARRANGE,
M_HELP_CONTENTS,
M_HELP_ABOUT
};
//----------------------------------------------------------------------
class TGMdiTestSubclass {
RQ_OBJECT("TGMdiTestSubclass")
protected:
TGMdiFrame *fMdiFrame;
TGCanvas *fCanvasWindow;
TGCompositeFrame *fContainer;
public:
TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h);
TGMdiFrame *GetMdiFrame() const { return fMdiFrame; }
virtual Bool_t CloseWindow();
};
class TGMdiHintTest {
RQ_OBJECT("TGMdiHintTest")
protected:
TGMdiFrame *fMdiFrame;
TGTextEntry *fWName;
TGCheckButton *fClose, *fMenu, *fMin, *fMax, *fSize, *fHelp;
public:
TGMdiHintTest(TGMdiMainFrame *main, int w, int h);
void HandleButtons();
void HandleText(const char *);
};
class TGAppMainFrame {
RQ_OBJECT("TGAppMainFrame")
protected:
TGMainFrame *fMain;
TGMdiMainFrame *fMainFrame;
TGMdiMenuBar *fMenuBar;
TGLayoutHints *fMenuBarItemLayout;
TGPopupMenu *fMenuFile, *fMenuWindow, *fMenuHelp;
void InitMenu();
void CloseWindow();
public:
TGAppMainFrame(const TGWindow *p, int w, int h);
void HandleMenu(Int_t id);
};
//----------------------------------------------------------------------
TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h)
{
fMain = new TGMainFrame(p, w, h, kVerticalFrame);
fMenuBar = new TGMdiMenuBar(fMain, 10, 10);
fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300);
fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
const TGPicture *pbg = gClient->GetPicture("mditestbg.xpm");
if (pbg)
TGMdiFrame *mdiFrame;
//--- 1
TGMdiTestSubclass *t = new TGMdiTestSubclass(fMainFrame, 320, 240);
mdiFrame = t->GetMdiFrame();
mdiFrame->SetWindowName("One");
mdiFrame->MapSubwindows();
mdiFrame->Layout();
//--- 2
ULong_t ic;
gClient->GetColorByName("red", ic);
mdiFrame = new TGMdiFrame(fMainFrame, 200, 200,
mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("&Press me!"), 1),
mdiFrame->SetWindowName("Two");
mdiFrame->MapSubwindows();
mdiFrame->Layout();
mdiFrame->Move(150, 200);
//--- 3
gClient->GetColorByName("green", ic);
mdiFrame = new TGMdiFrame(fMainFrame, 200, 200, kOwnBackground, ic);
mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 1"), 11),
mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 2"), 12),
mdiFrame->SetWindowName("Three");
mdiFrame->MapSubwindows();
mdiFrame->Layout();
mdiFrame->Move(180, 220);
//--- 4
gClient->GetColorByName("blue", ic);
mdiFrame = new TGMdiFrame(fMainFrame, 200, 400, kOwnBackground, ic);
TGListBox *fListBox = new TGListBox(mdiFrame,1);
fListBox->AddEntry("Entry 1", 1);
fListBox->AddEntry("Entry 2", 2);
fListBox->AddEntry("Entry 3", 3);
fListBox->AddEntry("Entry 4", 4);
fListBox->AddEntry("Entry 5", 5);
fListBox->AddEntry("Entry 6", 6);
fListBox->AddEntry("Entry 7", 7);
fListBox->AddEntry("Entry 8", 8);
fListBox->AddEntry("Entry 9", 9);
fListBox->Resize(100,70);
mdiFrame->AddFrame(fListBox,
mdiFrame->AddFrame(new TGHSlider(mdiFrame, 50, kSlider1, 1,
mdiFrame->Move(400, 300);
mdiFrame->SetWindowName("Four");
mdiFrame->MapSubwindows();
mdiFrame->Layout();
//--- 5
new TGMdiHintTest(fMainFrame, 200, 200);
InitMenu();
fMain->SetWindowName("MDI test");
fMain->SetClassHints("mdi test", "mdi test");
if (pbg && pbg->GetWidth() > 600 && pbg->GetHeight() > 400)
fMain->Resize(pbg->GetWidth(), pbg->GetHeight()+25);
else
fMain->Resize(640, 400);
fMain->MapSubwindows();
fMain->MapWindow();
fMain->Layout();
}
void TGAppMainFrame::HandleMenu(Int_t id)
{
// Handle menu items.
switch (id) {
case M_FILE_NEW:
new TGMdiFrame(fMainFrame, 200, 100);
break;
case M_FILE_CLOSE:
fMainFrame->Close(fMainFrame->GetCurrent());
break;
case M_FILE_EXIT:
CloseWindow();
break;
case M_WINDOW_HOR:
fMainFrame->TileHorizontal();
break;
case M_WINDOW_VERT:
fMainFrame->TileVertical();
break;
case M_WINDOW_CASCADE:
fMainFrame->Cascade();
break;
case M_WINDOW_ARRANGE:
fMainFrame->ArrangeMinimized();
break;
case M_WINDOW_OPAQUE:
if (fMenuWindow->IsEntryChecked(M_WINDOW_OPAQUE)) {
fMenuWindow->UnCheckEntry(M_WINDOW_OPAQUE);
} else {
fMenuWindow->CheckEntry(M_WINDOW_OPAQUE);
fMainFrame->SetResizeMode(kMdiOpaque);
}
break;
default:
fMainFrame->SetCurrent(id);
break;
}
}
void TGAppMainFrame::InitMenu()
{
fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fMenuFile = new TGPopupMenu(gClient->GetRoot());
fMenuFile->AddEntry(new TGHotString("&New Window"), M_FILE_NEW);
fMenuFile->AddEntry(new TGHotString("&Close Window"), M_FILE_CLOSE);
fMenuFile->AddSeparator();
fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT);
fMenuWindow = new TGPopupMenu(gClient->GetRoot());
fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR);
fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT);
fMenuWindow->AddEntry(new TGHotString("&Cascade"), M_WINDOW_CASCADE);
fMenuWindow->AddSeparator();
fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu());
fMenuWindow->AddSeparator();
fMenuWindow->AddEntry(new TGHotString("&Arrange icons"), M_WINDOW_ARRANGE);
fMenuWindow->AddSeparator();
fMenuWindow->AddEntry(new TGHotString("&Opaque resize"), M_WINDOW_OPAQUE);
fMenuWindow->CheckEntry(M_WINDOW_OPAQUE);
fMenuHelp = new TGPopupMenu(gClient->GetRoot());
fMenuHelp->AddEntry(new TGHotString("&Contents"), M_HELP_CONTENTS);
fMenuHelp->AddSeparator();
fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT);
fMenuHelp->DisableEntry(M_HELP_CONTENTS);
fMenuHelp->DisableEntry(M_HELP_ABOUT);
// menu message are handled by the class' HandleMenu() method
fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this,
"HandleMenu(Int_t)");
fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this,
"HandleMenu(Int_t)");
fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this,
"HandleMenu(Int_t)");
fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout);
fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout);
fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout);
}
void TGAppMainFrame::CloseWindow()
{
}
//----------------------------------------------------------------------
TGMdiTestSubclass::TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h)
{
fMdiFrame = new TGMdiFrame(main, w, h);
fMdiFrame->Connect("CloseWindow()", "TGMdiTestSubclass", this, "CloseWindow()");
fMdiFrame->DontCallClose();
fCanvasWindow = new TGCanvas(fMdiFrame, 400, 240);
fContainer = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 10, 10,
fMdiFrame->GetWhitePixel());
fContainer->SetLayoutManager(new TGTileLayout(fContainer, 8));
fCanvasWindow->SetContainer(fContainer);
for (int i = 0; i < 256; ++i)
fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
32, 32, kOwnBackground, (i+1) & 255),
fMdiFrame->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fMdiFrame->SetWindowIcon(gClient->GetPicture("ofolder_t.xpm"));
}
Bool_t TGMdiTestSubclass::CloseWindow()
{
int ret = 0;
new TGMsgBox(gClient->GetRoot(), fMdiFrame,
fMdiFrame->GetWindowName(), "Really want to close the window?",
if (ret == kMBYes) return fMdiFrame->CloseWindow();
return kFALSE;
}
//----------------------------------------------------------------------
TGMdiHintTest::TGMdiHintTest(TGMdiMainFrame *main, int w, int h)
{
fMdiFrame = new TGMdiFrame(main, w, h);
fClose = new TGCheckButton(fMdiFrame, new TGHotString("Close"), 11);
fMenu = new TGCheckButton(fMdiFrame, new TGHotString("Menu (left icon)"), 12);
fMin = new TGCheckButton(fMdiFrame, new TGHotString("Minimize"), 13);
fMax = new TGCheckButton(fMdiFrame, new TGHotString("Maximize"), 14);
fSize = new TGCheckButton(fMdiFrame, new TGHotString("Resize"), 15);
fHelp = new TGCheckButton(fMdiFrame, new TGHotString("Help"), 16);
TGLayoutHints *lh = new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 100, 5, 0);
fMdiFrame->AddFrame(fClose, lh);
fMdiFrame->AddFrame(fMenu, lh);
fMdiFrame->AddFrame(fMin, lh);
fMdiFrame->AddFrame(fMax, lh);
fMdiFrame->AddFrame(fSize, lh);
fMdiFrame->AddFrame(fHelp, lh);
fSize->SetState(kButtonDown);
fClose->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fMenu->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fMin->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fMax->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fSize->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fHelp->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()");
fWName = new TGTextEntry(fMdiFrame, (const char *)"", 20);
fMdiFrame->AddFrame(fWName, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
5, 5, 5, 5));
fWName->GetBuffer()->AddText(0, "MDI hints test");
fWName->Connect("TextChanged(char*)", "TGMdiHintTest", this, "HandleText(char*)");
fMdiFrame->SetMdiHints(kMdiDefaultHints);
fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString());
fMdiFrame->SetWindowIcon(gClient->GetPicture("app_t.xpm"));
fMdiFrame->MapSubwindows();
fMdiFrame->Layout();
}
void TGMdiHintTest::HandleButtons()
{
int hints = 0;
if (fClose->GetState() != kButtonUp) hints |= kMdiClose;
if (fMenu->GetState() != kButtonUp) hints |= kMdiMenu;
if (fMin->GetState() != kButtonUp) hints |= kMdiMinimize;
if (fMax->GetState() != kButtonUp) hints |= kMdiMaximize;
if (fSize->GetState() != kButtonUp) hints |= kMdiSize;
if (fHelp->GetState() != kButtonUp) hints |= kMdiHelp;
fMdiFrame->SetMdiHints(hints);
}
void TGMdiHintTest::HandleText(const char *)
{
fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString());
}
void mditest()
{
new TGAppMainFrame(gClient->GetRoot(), 640, 400);
}
//----------------------------------------------------------------------
#ifdef STANDALONE
int main(int argc, char **argv)
{
TApplication theApp("MdiTest", &argc, argv);
mditest();
theApp.Run();
return 0;
}
#endif
Authors
Ilka Antcheva, Fons Rademakers

Definition in file mditest.C.

kMdiMinimize
@ kMdiMinimize
Definition: TGMdiMainFrame.h:62
TGMdiFrame::SetMdiHints
virtual void SetMdiHints(ULong_t mdihints)
Set MDI hints, also used to identify titlebar buttons.
Definition: TGMdiFrame.cxx:93
TGListBox
Definition: TGListBox.h:288
TGPopupMenu::IsEntryChecked
virtual Bool_t IsEntryChecked(Int_t id)
Return true if menu item is checked.
Definition: TGMenu.cxx:1844
TGPopupMenu::AddPopup
virtual void AddPopup(TGHotString *s, TGPopupMenu *popup, TGMenuEntry *before=0, const TGPicture *p=0)
Add a (cascading) popup menu to a popup menu.
Definition: TGMenu.cxx:1151
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:38
TGCheckButton::SetState
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1203
TGMainFrame
Definition: TGFrame.h:444
TGMdiMainFrame::Close
virtual Int_t Close(TGMdiFrame *frame)
Close MDI child window mdiframe.
Definition: TGMdiMainFrame.cxx:958
TGPicture
Definition: TGPicture.h:36
kMdiMaximize
@ kMdiMaximize
Definition: TGMdiMainFrame.h:63
TGPicture::GetWidth
UInt_t GetWidth() const
Definition: TGPicture.h:63
kButtonDown
@ kButtonDown
Definition: TGButton.h:60
TGSlider.h
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
TGMsgBox
Definition: TGMsgBox.h:63
TGListBox::SetMultipleSelections
virtual void SetMultipleSelections(Bool_t multi=kTRUE)
Definition: TGListBox.h:326
TGHotString
Definition: TGString.h:52
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGMdiFrame::SetWindowName
void SetWindowName(const char *name)
Set MDI window name (set titlebar title).
Definition: TGMdiFrame.cxx:102
TGListBox::Resize
virtual void Resize(UInt_t w, UInt_t h)
Resize the listbox widget.
Definition: TGListBox.cxx:1420
TGHSlider
Definition: TGSlider.h:154
kButtonUp
@ kButtonUp
Definition: TGButton.h:59
TGTextButton
Definition: TGButton.h:142
Int_t
int Int_t
Definition: RtypesCore.h:45
RQ_OBJECT
#define RQ_OBJECT(sender_class)
Definition: RQ_OBJECT.h:87
TGMdiMainFrame::TileVertical
virtual void TileVertical()
Definition: TGMdiMainFrame.h:194
kMBYes
@ kMBYes
Definition: TGMsgBox.h:42
kMdiOpaque
@ kMdiOpaque
Definition: TGMdiMainFrame.h:76
TGMdiMainFrame::TileHorizontal
virtual void TileHorizontal()
Definition: TGMdiMainFrame.h:193
TGTextEntry::GetBuffer
TGTextBuffer * GetBuffer() const
Definition: TGTextEntry.h:127
TGWindow::SetBackgroundPixmap
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
Definition: TGWindow.cxx:229
TGMdi.h
TGPopupMenu::DisableEntry
virtual void DisableEntry(Int_t id)
Disable entry (disabled entries appear in a sunken relieve).
Definition: TGMenu.cxx:1723
kMBNo
@ kMBNo
Definition: TGMsgBox.h:43
TGFrame
Definition: TGFrame.h:105
kMdiHelp
@ kMdiHelp
Definition: TGMdiMainFrame.h:64
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGPopupMenu::UnCheckEntry
virtual void UnCheckEntry(Int_t id)
Uncheck menu entry (i.e. remove check mark).
Definition: TGMenu.cxx:1806
kOwnBackground
@ kOwnBackground
Definition: GuiTypes.h:391
TGPopupMenu::AddEntry
virtual void AddEntry(TGHotString *s, Int_t id, void *ud=0, const TGPicture *p=0, TGMenuEntry *before=0)
Add a menu entry.
Definition: TGMenu.cxx:989
kMdiNonOpaque
@ kMdiNonOpaque
Definition: TGMdiMainFrame.h:77
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TGCheckButton
Definition: TGButton.h:264
TGPopupMenu::AddSeparator
virtual void AddSeparator(TGMenuEntry *before=0)
Add a menu separator to the menu.
Definition: TGMenu.cxx:1059
TGMdiMainFrame::GetCurrent
TGMdiFrame * GetCurrent() const
Return pointer on current (active) MDI child window.
Definition: TGMdiMainFrame.cxx:1047
kLHintsNormal
@ kLHintsNormal
Definition: TGLayout.h:45
TGMdiMainFrame::Cascade
virtual void Cascade()
Definition: TGMdiMainFrame.h:192
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
h
#define h(i)
Definition: RSha256.hxx:124
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1149
TGMdiFrame
Definition: TGMdiFrame.h:51
TGTextEntry
Definition: TGTextEntry.h:39
kMBIconExclamation
@ kMBIconExclamation
Definition: TGMsgBox.h:41
TGMdiMainFrame
Definition: TGMdiMainFrame.h:138
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGMdiMainFrame::ArrangeMinimized
virtual void ArrangeMinimized()
This is an attempt to an "smart" minimized window re-arrangement.
Definition: TGMdiMainFrame.cxx:675
TGFrame.h
main
int main(int argc, char **argv)
Definition: histspeedtest.cxx:751
TGLayoutHints
Definition: TGLayout.h:57
RQ_OBJECT.h
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TApplication::Terminate
virtual void Terminate(Int_t status=0)
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
TGClient.h
TGListBox.h
TGTileLayout
Definition: TGLayout.h:276
TGPopupMenu::CheckEntry
virtual void CheckEntry(Int_t id)
Check a menu entry (i.e. add a check mark in front of it).
Definition: TGMenu.cxx:1781
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGMdiMainFrame::SetCurrent
Bool_t SetCurrent(TGMdiFrameList *newcurrent)
Set current (active) MDI child window (by frame list).
Definition: TGMdiMainFrame.cxx:329
kMdiClose
@ kMdiClose
Definition: TGMdiMainFrame.h:58
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
kMdiSize
@ kMdiSize
Definition: TGMdiMainFrame.h:61
TQObject::Connect
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:864
TGMdiMainFrame::GetContainer
TGFrame * GetContainer() const
Definition: TGMdiMainFrame.h:204
TGMsgBox.h
TGPicture::GetPicture
Pixmap_t GetPicture() const
Definition: TGPicture.h:65
TGButton::GetState
virtual EButtonState GetState() const
Definition: TGButton.h:112
TGTextEntry.h
TGButton.h
TGPopupMenu
Definition: TGMenu.h:123
TGCanvas.h
TGMdiMainFrame::GetWinListMenu
TGPopupMenu * GetWinListMenu() const
Definition: TGMdiMainFrame.h:208
TGMdiMainFrame::SetResizeMode
void SetResizeMode(Int_t mode=kMdiDefaultResizeMode)
Set MDI windows resize mode (opaque or transparent).
Definition: TGMdiMainFrame.cxx:151
kSlider1
@ kSlider1
Definition: TGSlider.h:56
fSize
size_t fSize
Definition: DeclareConverters.h:342
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TApplication
Definition: TApplication.h:39
TGMdiFrame::Move
virtual void Move(Int_t x, Int_t y)
Move MDI window at position x, y.
Definition: TGMdiFrame.cxx:136
kMdiMenu
@ kMdiMenu
Definition: TGMdiMainFrame.h:65
TGListBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Add entry with specified string and id to listbox.
Definition: TGListBox.cxx:1212
TGCompositeFrame
Definition: TGFrame.h:324
TGCanvas
Definition: TGCanvas.h:202
TGPicture::GetHeight
UInt_t GetHeight() const
Definition: TGPicture.h:64
TGTextBuffer::AddText
void AddText(Int_t pos, const char *text)
Definition: TGTextBuffer.h:55
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
TGMenu.h
TGCompositeFrame::Layout
virtual void Layout()
Layout the elements of the composite frame.
Definition: TGFrame.cxx:1242
TGTextBuffer::GetString
const char * GetString() const
Definition: TGTextBuffer.h:53
kMdiDefaultHints
@ kMdiDefaultHints
Definition: TGMdiMainFrame.h:66
TGMdiMenuBar
Definition: TGMdiMenu.h:53