GUI MDI features.
#include <cstdio>
#include <cstdlib>
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 {
protected:
public:
TGMdiFrame *GetMdiFrame()
const {
return fMdiFrame; }
};
class 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 {
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)
{
fMenuBar = new TGMdiMenuBar(fMain, 10, 10);
fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300);
const TGPicture *pbg =
gClient->GetPicture(
"mditestbg.xpm");
if (pbg)
TGMdiFrame *mdiFrame;
TGMdiTestSubclass *t = new TGMdiTestSubclass(fMainFrame, 320, 240);
mdiFrame = t->GetMdiFrame();
gClient->GetColorByName(
"red", ic);
mdiFrame->
AddFrame(
new TGTextButton(mdiFrame,
new TGHotString(
"&Press me!"), 1),
mdiFrame->
Move(150, 200);
gClient->GetColorByName(
"green", ic);
mdiFrame->
AddFrame(
new TGTextButton(mdiFrame,
new TGHotString(
"Button 1"), 11),
mdiFrame->
AddFrame(
new TGTextButton(mdiFrame,
new TGHotString(
"Button 2"), 12),
mdiFrame->
Move(180, 220);
gClient->GetColorByName(
"blue", ic);
TGListBox *fListBox = new TGListBox(mdiFrame, 1);
mdiFrame->
Move(400, 300);
new TGMdiHintTest(fMainFrame, 200, 200);
InitMenu();
fMain->SetWindowName("MDI test");
fMain->SetClassHints("mdi test", "mdi test");
else
fMain->Resize(640, 400);
fMain->MapSubwindows();
fMain->MapWindow();
fMain->Layout();
}
void TGAppMainFrame::HandleMenu(
Int_t id)
{
switch (id) {
case M_FILE_NEW: new TGMdiFrame(fMainFrame, 200, 100); break;
case M_FILE_EXIT: CloseWindow(); break;
case M_WINDOW_CASCADE: fMainFrame->
Cascade();
break;
case M_WINDOW_OPAQUE:
} else {
}
break;
}
}
void TGAppMainFrame::InitMenu()
{
fMenuFile =
new TGPopupMenu(
gClient->GetRoot());
fMenuFile->
AddEntry(
new TGHotString(
"&New Window"), M_FILE_NEW);
fMenuFile->
AddEntry(
new TGHotString(
"&Close Window"), M_FILE_CLOSE);
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->
AddEntry(
new TGHotString(
"&Arrange icons"), M_WINDOW_ARRANGE);
fMenuWindow->
AddEntry(
new TGHotString(
"&Opaque resize"), M_WINDOW_OPAQUE);
fMenuHelp =
new TGPopupMenu(
gClient->GetRoot());
fMenuHelp->
AddEntry(
new TGHotString(
"&Contents"), M_HELP_CONTENTS);
fMenuHelp->
AddEntry(
new TGHotString(
"&About"), M_HELP_ABOUT);
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);
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->SetWindowIcon(
gClient->GetPicture(
"ofolder_t.xpm"));
}
Bool_t TGMdiTestSubclass::CloseWindow()
{
new TGMsgBox(
gClient->GetRoot(), fMdiFrame, fMdiFrame->GetWindowName(),
"Really want to close the window?",
return fMdiFrame->CloseWindow();
}
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);
fMdiFrame->AddFrame(fClose, lh);
fMdiFrame->AddFrame(fMenu, lh);
fMdiFrame->AddFrame(fMin, lh);
fMdiFrame->AddFrame(fMax, lh);
fMdiFrame->AddFrame(fSize, lh);
fMdiFrame->AddFrame(fHelp, lh);
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);
fWName->
Connect(
"TextChanged(char*)",
"TGMdiHintTest",
this,
"HandleText(char*)");
fMdiFrame->SetWindowIcon(
gClient->GetPicture(
"app_t.xpm"));
fMdiFrame->MapSubwindows();
fMdiFrame->Layout();
}
void TGMdiHintTest::HandleButtons()
{
int hints = 0;
fMdiFrame->SetMdiHints(hints);
}
void TGMdiHintTest::HandleText(const char *)
{
}
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
#define RQ_OBJECT(sender_class)
int Int_t
Signed integer 4 bytes (int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
externTApplication * gApplication
A frame containing two scrollbars (a horizontal and a vertical) and a viewport.
The base class for composite widgets (menu bars, list boxes, etc.).
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
void Layout() override
Layout the elements of the composite frame.
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)
This file contains the TGMdiFrame class.
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 Int_t Close(TGMdiFrame *frame)
Close MDI child window mdiframe.
TGFrame * GetContainer() const
Pixmap_t GetPicture() const
void AddText(Int_t pos, const char *text)
const char * GetString() const
TGTextBuffer * GetBuffer() const
virtual void SetBackgroundPixmap(Pixmap_t pixmap)
set background pixmap
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.
int main(int argc, char **argv)