Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
size_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
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
bool Bool_t
Definition RtypesCore.h:63
R__EXTERN TApplication * gApplication
@ kButtonDown
Definition TGButton.h:54
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
@ 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
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
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
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=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual void Layout()
Layout the elements of the composite frame.
Definition TGFrame.cxx:1257
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
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:128
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
virtual void Resize(UInt_t w, UInt_t h)
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:398
This file contains the TGMdiFrame class.
Definition TGMdiFrame.h:44
virtual void Move(Int_t x, Int_t y)
Move MDI window at position x, y.
virtual void SetMdiHints(ULong_t mdihints)
Set MDI hints, also used to identify titlebar buttons.
void SetWindowName(const char *name)
Set MDI window name (set titlebar title).
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
Authors
Ilka Antcheva, Fons Rademakers

Definition in file mditest.C.