Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
guitest.C File Reference

Detailed Description

Test program for ROOT native GUI classes Exactly like $ROOTSYS/test/guitest.cxx but using the new signal and slots communication mechanism.

It is now possible to run this entire test program in the interpreter. Do either:

.x guitest.C
.x guitest.C++
#include <stdlib.h>
#include <TROOT.h>
#include <TClass.h>
#include <TApplication.h>
#include <TVirtualX.h>
#include <TGResourcePool.h>
#include <TGListBox.h>
#include <TGListTree.h>
#include <TGFSContainer.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TGIcon.h>
#include <TGLabel.h>
#include <TGButton.h>
#include <TGTextEntry.h>
#include <TGNumberEntry.h>
#include <TGMsgBox.h>
#include <TGMenu.h>
#include <TGCanvas.h>
#include <TGComboBox.h>
#include <TGTab.h>
#include <TGSlider.h>
#include <TGDoubleSlider.h>
#include <TGFileDialog.h>
#include <TGTextEdit.h>
#include <TGShutter.h>
#include <TGProgressBar.h>
#include <TGColorSelect.h>
#include <RQ_OBJECT.h>
#include <TCanvas.h>
#include <TColor.h>
#include <TH1.h>
#include <TH2.h>
#include <TRandom.h>
#include <TSystem.h>
#include <TEnv.h>
#include <TFile.h>
#include <TKey.h>
#include <TGFontDialog.h>
enum ETestCommandIdentifiers {
M_FILE_OPEN,
M_FILE_SAVE,
M_FILE_SAVEAS,
M_FILE_PRINT,
M_FILE_PRINTSETUP,
M_FILE_EXIT,
M_TEST_DLG,
M_TEST_MSGBOX,
M_TEST_SLIDER,
M_TEST_SHUTTER,
M_TEST_DIRLIST,
M_TEST_FILELIST,
M_TEST_PROGRESS,
M_TEST_NUMBERENTRY,
M_TEST_FONTDIALOG,
M_TEST_NEWMENU,
M_VIEW_ENBL_DOCK,
M_VIEW_ENBL_HIDE,
M_VIEW_DOCK,
M_VIEW_UNDOCK,
M_HELP_CONTENTS,
M_HELP_SEARCH,
M_HELP_ABOUT,
M_CASCADE_1,
M_CASCADE_2,
M_CASCADE_3,
M_NEW_REMOVEMENU,
VId1,
HId1,
VId2,
HId2,
VSId1,
HSId1,
VSId2,
HSId2
};
Int_t mb_button_id[13] = { kMBYes, kMBNo, kMBOk, kMBApply,
const char *filetypes[] = { "All files", "*",
"ROOT files", "*.root",
"ROOT macros", "*.C",
"Text files", "*.[tT][xX][tT]",
0, 0 };
struct shutterData_t {
const char *pixmap_name;
const char *tip_text;
TGButton *button;
};
shutterData_t histo_data[] = {
{ "h1_s.xpm", "TH1", 1001, 0 },
{ "h2_s.xpm", "TH2", 1002, 0 },
{ "h3_s.xpm", "TH3", 1003, 0 },
{ "profile_s.xpm", "TProfile", 1004, 0 },
{ 0, 0, 0, 0 }
};
shutterData_t function_data[] = {
{ "f1_s.xpm", "TF1", 2001, 0 },
{ "f2_s.xpm", "TF2", 2002, 0 },
{ 0, 0, 0, 0 }
};
shutterData_t tree_data[] = {
{ "ntuple_s.xpm", "TNtuple", 3001, 0 },
{ "tree_s.xpm", "TTree", 3002, 0 },
{ "chain_s.xpm", "TChain", 3003, 0 },
{ 0, 0, 0, 0 }
};
const char *editortxt1 =
"This is the ROOT text edit widget TGTextEdit. It is not intended as\n"
"a full developers editor, but it is relatively complete and can ideally\n"
"be used to edit scripts or to present users editable config files, etc.\n\n"
"The text edit widget supports standard emacs style ctrl-key navigation\n"
"in addition to the arrow keys. By default the widget has under the right\n"
"mouse button a popup menu giving access to several built-in functions.\n\n"
"Cut, copy and paste between different editor windows and any other\n"
"standard text handling application is supported.\n\n"
"Text can be selected with the mouse while holding the left button\n"
"or with the arrow keys while holding the shift key pressed. Use the\n"
"middle mouse button to paste text at the current mouse location."
;
const char *editortxt2 =
"Mice with scroll-ball are properly supported.\n\n"
"This are the currently defined key bindings:\n"
"Left Arrow\n"
" Move the cursor one character leftwards.\n"
" Scroll when cursor is out of frame.\n"
"Right Arrow\n"
" Move the cursor one character rightwards.\n"
" Scroll when cursor is out of frame.\n"
"Backspace\n"
" Deletes the character on the left side of the text cursor and moves the\n"
" cursor one position to the left. If a text has been marked by the user"
;
const char *editortxt3 =
" (e.g. by clicking and dragging) the cursor will be put at the beginning\n"
" of the marked text and the marked text will be removed.\n"
"Home\n"
" Moves the text cursor to the left end of the line. If mark is TRUE text\n"
" will be marked towards the first position, if not any marked text will\n"
" be unmarked if the cursor is moved.\n"
"End\n"
" Moves the text cursor to the right end of the line. If mark is TRUE text\n"
" will be marked towards the last position, if not any marked text will\n"
" be unmarked if the cursor is moved.\n"
"Delete"
;
const char *editortxt4 =
" Deletes the character on the right side of the text cursor. If a text\n"
" has been marked by the user (e.g. by clicking and dragging) the cursor\n"
" will be put at the beginning of the marked text and the marked text will\n"
" be removed.\n"
"Shift - Left Arrow\n"
" Mark text one character leftwards.\n"
"Shift - Right Arrow\n"
" Mark text one character rightwards.\n"
"Control-A\n"
" Select the whole text.\n"
"Control-B\n"
" Move the cursor one character leftwards."
;
const char *editortxt5 =
"Control-C\n"
" Copy the marked text to the clipboard.\n"
"Control-D\n"
" Delete the character to the right of the cursor.\n"
"Control-E\n"
" Move the cursor to the end of the line.\n"
"Control-F\n"
" Start Search Dialog.\n"
"Control-H\n"
" Delete the character to the left of the cursor.\n"
"Control-K\n"
" Delete marked text if any or delete all\n"
" characters to the right of the cursor.\n"
"Control-L\n"
" Start GoTo Line Dialog"
;
const char *editortxt6 =
"Control-U\n"
" Delete all characters on the line.\n"
"Control-V\n"
" Paste the clipboard text into line edit.\n"
"Control-X\n"
" Cut the marked text, copy to clipboard.\n"
"Control-Y\n"
" Paste the clipboard text into line edit.\n"
"Control-Z\n"
" Undo action.\n\n"
"All other keys with valid ASCII codes insert themselves into the line.";
class TileFrame;
class TestMainFrame {
RQ_OBJECT("TestMainFrame")
private:
TGMainFrame *fMain;
TGDockableFrame *fMenuDock;
TGCompositeFrame *fStatusFrame;
TGCanvas *fCanvasWindow;
TileFrame *fContainer;
TGTextEntry *fTestText;
TGButton *fTestButton;
TGColorSelect *fColorSel;
TGMenuBar *fMenuBar;
TGPopupMenu *fMenuFile, *fMenuTest, *fMenuView, *fMenuHelp;
TGPopupMenu *fCascadeMenu, *fCascade1Menu, *fCascade2Menu;
TGPopupMenu *fMenuNew1, *fMenuNew2;
TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout, *fMenuBarHelpLayout;
public:
TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~TestMainFrame();
// slots
void CloseWindow();
void DoButton();
void HandleMenu(Int_t id);
void HandlePopup() { printf("menu popped up\n"); }
void HandlePopdown() { printf("menu popped down\n"); }
void Created() { Emit("Created()"); } //*SIGNAL*
void Welcome() { printf("TestMainFrame has been created. Welcome!\n"); }
};
class TestDialog {
RQ_OBJECT("TestDialog")
private:
TGCompositeFrame *fFrame1, *fF1, *fF2, *fF3, *fF4, *fF5;
TGGroupFrame *fF6, *fF7;
TGButton *fOkButton, *fCancelButton, *fStartB, *fStopB;
TGButton *fBtn1, *fBtn2, *fChk1, *fChk2, *fRad1, *fRad2;
TGPictureButton *fPicBut1;
TGCheckButton *fCheck1;
TGCheckButton *fCheckMulti;
TGListBox *fListBox;
TGComboBox *fCombo;
TGTab *fTab;
TGTextEntry *fTxt1, *fTxt2;
TGLayoutHints *fL1, *fL2, *fL3, *fL4;
TRootEmbeddedCanvas *fEc1, *fEc2;
Int_t fFirstEntry;
Int_t fLastEntry;
Bool_t fFillHistos;
TH1F *fHpx;
TH2F *fHpxpy;
void FillHistos();
public:
TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
UInt_t options = kVerticalFrame);
virtual ~TestDialog();
// slots
void DoClose();
void CloseWindow();
void DoOK();
void DoCancel();
void DoTab(Int_t id);
void HandleButtons(Int_t id = -1);
void HandleEmbeddedCanvas(Int_t event, Int_t x, Int_t y, TObject *sel);
};
class TestMsgBox {
RQ_OBJECT("TestMsgBox")
private:
TGCompositeFrame *f1, *f2, *f3, *f4, *f5;
TGButton *fTestButton, *fCloseButton;
TGPictureButton *fPictButton;
TGRadioButton *fR[4];
TGCheckButton *fC[13];
TGGroupFrame *fG1, *fG2;
TGLayoutHints *fL1, *fL2, *fL3, *fL4, *fL5, *fL6, *fL21;
TGTextEntry *fTitle, *fMsg;
TGTextBuffer *fTbtitle, *fTbmsg;
TGLabel *fLtitle, *fLmsg;
TGGC fRedTextGC;
public:
TestMsgBox(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
UInt_t options = kVerticalFrame);
virtual ~TestMsgBox();
// slots
void TryToClose();
void CloseWindow();
void DoClose();
void DoRadio();
void DoTest();
};
class TestSliders {
RQ_OBJECT("TestSliders")
private:
TGVerticalFrame *fVframe1, *fVframe2;
TGLayoutHints *fBly, *fBfly1;
TGHSlider *fHslider1, *fHslider2;
TGVSlider *fVslider1;
TGDoubleVSlider *fVslider2;
TGTextEntry *fTeh1, *fTev1, *fTeh2, *fTev2;
TGTextBuffer *fTbh1, *fTbv1, *fTbh2, *fTbv2;
public:
TestSliders(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestSliders();
// slots
void CloseWindow();
void DoText(const char *text);
void DoSlider(Int_t pos = 0);
};
class TestShutter {
RQ_OBJECT("TestShutter")
private:
TGShutter *fShutter;
TGLayoutHints *fLayout;
const TGPicture *fDefaultPic;
public:
TestShutter(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
~TestShutter();
void AddShutterItem(const char *name, shutterData_t *data);
// slots
void CloseWindow();
void HandleButtons();
};
class TestDirList {
RQ_OBJECT("TestDirList")
protected:
TGListTree *fContents;
const TGPicture *fIcon;
TString DirName(TGListTreeItem* item);
public:
TestDirList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestDirList();
// slots
void OnDoubleClick(TGListTreeItem* item, Int_t btn);
void CloseWindow();
};
class TestFileList {
RQ_OBJECT("TestFileList")
protected:
TGFileContainer *fContents;
TGPopupMenu *fMenu;
void DisplayFile(const TString &fname);
void DisplayDirectory(const TString &fname);
void DisplayObject(const TString& fname,const TString& name);
public:
TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestFileList();
// slots
void OnDoubleClick(TGLVEntry*,Int_t);
void DoMenu(Int_t);
void CloseWindow();
};
class TestProgress {
private:
TGHorizontalFrame *fHframe1;
TGVerticalFrame *fVframe1;
TGLayoutHints *fHint1, *fHint2, *fHint3, *fHint4, *fHint5;
TGHProgressBar *fHProg1, *fHProg2, *fHProg3;
TGVProgressBar *fVProg1, *fVProg2;
Bool_t fClose;
public:
TestProgress(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestProgress();
// slots
void CloseWindow();
void DoClose();
void DoGo();
};
class EntryTestDlg {
private:
TGLabel *fLabel[13];
TGNumberEntry *fNumericEntries[13];
TGCheckButton *fLowerLimit;
TGCheckButton *fUpperLimit;
TGNumberEntry *fLimits[2];
TGCheckButton *fPositive;
TGCheckButton *fNonNegative;
TGButton *fSetButton;
TGButton *fExitButton;
// static const char *const numlabel[13];
// static const Double_t numinit[13];
public:
EntryTestDlg(const TGWindow *p, const TGWindow *main);
virtual ~EntryTestDlg();
// slots
void CloseWindow();
void SetLimits();
void DoOK();
};
class Editor {
private:
TGTransientFrame *fMain; // main frame of this widget
TGTextEdit *fEdit; // text edit widget
TGTextButton *fOK; // OK button
TGLayoutHints *fL1; // layout of TGTextEdit
TGLayoutHints *fL2; // layout of OK button
public:
Editor(const TGWindow *main, UInt_t w, UInt_t h);
virtual ~Editor();
void LoadFile(const char *file);
void LoadBuffer(const char *buffer);
void AddBuffer(const char *buffer);
TGTextEdit *GetEditor() const { return fEdit; }
void SetTitle();
void Popup();
// slots
void CloseWindow();
void DoOK();
void DoOpen();
void DoSave();
void DoClose();
};
class TileFrame {
RQ_OBJECT("TileFrame")
private:
TGCanvas *fCanvas;
public:
TileFrame(const TGWindow *p);
virtual ~TileFrame() { delete fFrame; }
TGFrame *GetFrame() const { return fFrame; }
void SetCanvas(TGCanvas *canvas) { fCanvas = canvas; }
void HandleMouseWheel(Event_t *event);
};
TileFrame::TileFrame(const TGWindow *p)
{
// Create tile view container. Used to show colormap.
fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
fFrame->Connect("ProcessedEvent(Event_t*)", "TileFrame", this,
"HandleMouseWheel(Event_t*)");
fCanvas = 0;
fFrame->SetLayoutManager(new TGTileLayout(fFrame, 8));
gVirtualX->GrabButton(fFrame->GetId(), kAnyButton, kAnyModifier,
}
void TileFrame::HandleMouseWheel(Event_t *event)
{
// Handle mouse wheel to scroll.
if (event->fType != kButtonPress && event->fType != kButtonRelease)
return;
Int_t page = 0;
if (event->fCode == kButton4 || event->fCode == kButton5) {
if (!fCanvas) return;
if (fCanvas->GetContainer()->GetHeight())
page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
fCanvas->GetViewPort()->GetHeight()) /
fCanvas->GetContainer()->GetHeight());
}
if (event->fCode == kButton4) {
//scroll up
Int_t newpos = fCanvas->GetVsbPosition() - page;
if (newpos < 0) newpos = 0;
fCanvas->SetVsbPosition(newpos);
}
if (event->fCode == kButton5) {
// scroll down
Int_t newpos = fCanvas->GetVsbPosition() + page;
fCanvas->SetVsbPosition(newpos);
}
}
TestMainFrame::TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
{
// Create test main frame. A TGMainFrame is a top level window.
fMain = new TGMainFrame(p, w, h);
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fMain->Connect("CloseWindow()", "TestMainFrame", this, "CloseWindow()");
// Create menubar and popup menus. The hint objects are used to place
// and group the different menu widgets with respect to eachother.
fMenuDock = new TGDockableFrame(fMain);
fMain->AddFrame(fMenuDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
fMenuDock->SetWindowName("GuiTest Menu");
fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
fMenuFile = new TGPopupMenu(gClient->GetRoot());
fMenuFile->AddEntry("&Open...", M_FILE_OPEN);
fMenuFile->AddEntry("&Save", M_FILE_SAVE);
fMenuFile->AddEntry("S&ave as...", M_FILE_SAVEAS);
fMenuFile->AddEntry("&Close", -1);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Print", M_FILE_PRINT);
fMenuFile->AddEntry("P&rint setup...", M_FILE_PRINTSETUP);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("E&xit", M_FILE_EXIT);
fMenuFile->DisableEntry(M_FILE_SAVEAS);
fMenuFile->HideEntry(M_FILE_PRINT);
fCascade2Menu = new TGPopupMenu(gClient->GetRoot());
fCascade2Menu->AddEntry("ID = 2&3", M_CASCADE_1);
fCascade2Menu->AddEntry("ID = 2&4", M_CASCADE_2);
fCascade2Menu->AddEntry("ID = 2&5", M_CASCADE_3);
fCascade1Menu = new TGPopupMenu(gClient->GetRoot());
fCascade1Menu->AddEntry("ID = 4&1", 41);
fCascade1Menu->AddEntry("ID = 4&2", 42);
fCascade1Menu->AddEntry("ID = 4&3", 43);
fCascade1Menu->AddSeparator();
fCascade1Menu->AddPopup("Cascade&d 2", fCascade2Menu);
fCascadeMenu = new TGPopupMenu(gClient->GetRoot());
fCascadeMenu->AddEntry("ID = 5&1", 51);
fCascadeMenu->AddEntry("ID = 5&2", 52);
fCascadeMenu->AddEntry("ID = 5&3", 53);
fCascadeMenu->AddSeparator();
fCascadeMenu->AddPopup("&Cascaded 1", fCascade1Menu);
fMenuTest = new TGPopupMenu(gClient->GetRoot());
fMenuTest->AddLabel("Test different features...");
fMenuTest->AddSeparator();
fMenuTest->AddEntry("&Dialog...", M_TEST_DLG);
fMenuTest->AddEntry("&Message Box...", M_TEST_MSGBOX);
fMenuTest->AddEntry("&Sliders...", M_TEST_SLIDER);
fMenuTest->AddEntry("Sh&utter...", M_TEST_SHUTTER);
fMenuTest->AddEntry("&List Directory...", M_TEST_DIRLIST);
fMenuTest->AddEntry("&File List...", M_TEST_FILELIST);
fMenuTest->AddEntry("&Progress...", M_TEST_PROGRESS);
fMenuTest->AddEntry("&Number Entry...", M_TEST_NUMBERENTRY);
fMenuTest->AddEntry("F&ont Dialog...", M_TEST_FONTDIALOG);
fMenuTest->AddSeparator();
fMenuTest->AddEntry("Add New Menus", M_TEST_NEWMENU);
fMenuTest->AddSeparator();
fMenuTest->AddPopup("&Cascaded menus", fCascadeMenu);
fMenuView = new TGPopupMenu(gClient->GetRoot());
fMenuView->AddEntry("&Dock", M_VIEW_DOCK);
fMenuView->AddEntry("&Undock", M_VIEW_UNDOCK);
fMenuView->AddSeparator();
fMenuView->AddEntry("Enable U&ndock", M_VIEW_ENBL_DOCK);
fMenuView->AddEntry("Enable &Hide", M_VIEW_ENBL_HIDE);
fMenuView->DisableEntry(M_VIEW_DOCK);
fMenuDock->EnableUndock(kTRUE);
fMenuDock->EnableHide(kTRUE);
fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
// When using the DockButton of the MenuDock,
// the states 'enable' and 'disable' of menus have to be updated.
fMenuDock->Connect("Undocked()", "TestMainFrame", this, "HandleMenu(=M_VIEW_UNDOCK)");
fMenuHelp = new TGPopupMenu(gClient->GetRoot());
fMenuHelp->AddEntry("&Contents", M_HELP_CONTENTS);
fMenuHelp->AddEntry("&Search...", M_HELP_SEARCH);
fMenuHelp->AddSeparator();
fMenuHelp->AddEntry("&About", M_HELP_ABOUT);
fMenuNew1 = new TGPopupMenu();
fMenuNew1->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
fMenuNew2 = new TGPopupMenu();
fMenuNew2->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
// Menu button messages are handled by the main frame (i.e. "this")
// HandleMenu() method.
fMenuFile->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuFile->Connect("PoppedUp()", "TestMainFrame", this, "HandlePopup()");
fMenuFile->Connect("PoppedDown()", "TestMainFrame", this, "HandlePopdown()");
fMenuTest->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuView->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuHelp->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fCascadeMenu->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fCascade1Menu->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fCascade2Menu->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuNew1->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuNew2->Connect("Activated(Int_t)", "TestMainFrame", this,
"HandleMenu(Int_t)");
fMenuBar = new TGMenuBar(fMenuDock, 1, 1, kHorizontalFrame);
fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
fMenuBar->AddPopup("&Test", fMenuTest, fMenuBarItemLayout);
fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout);
fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
fMenuDock->AddFrame(fMenuBar, fMenuBarLayout);
// Create TGCanvas and a canvas container which uses a tile layout manager
fCanvasWindow = new TGCanvas(fMain, 400, 240);
fContainer = new TileFrame(fCanvasWindow->GetViewPort());
fContainer->SetCanvas(fCanvasWindow);
fCanvasWindow->SetContainer(fContainer->GetFrame());
// use hierarchical cleaning for container
fContainer->GetFrame()->SetCleanup(kDeepCleanup);
// Fill canvas with 256 colored frames
for (int i=0; i < 256; ++i)
fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
32, 32, 0, TColor::RGB2Pixel(0,0,(i+1)&255)),
fMain->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0, 0, 2, 2));
// Create status frame containing a button and a text entry widget
fStatusFrame = new TGCompositeFrame(fMain, 60, 20, kHorizontalFrame |
fTestButton = new TGTextButton(fStatusFrame, "&Open editor...", 150);
fTestButton->Connect("Clicked()", "TestMainFrame", this, "DoButton()");
fTestButton->SetToolTipText("Pops up\ntext editor");
fStatusFrame->AddFrame(fTestButton, new TGLayoutHints(kLHintsTop |
kLHintsLeft, 2, 0, 2, 2));
fTestText = new TGTextEntry(fStatusFrame, new TGTextBuffer(100));
fTestText->SetToolTipText("This is a text entry widget");
fTestText->Resize(300, fTestText->GetDefaultHeight());
fStatusFrame->AddFrame(fTestText, new TGLayoutHints(kLHintsTop | kLHintsLeft,
10, 2, 2, 2));
Pixel_t yellow;
gClient->GetColorByName("yellow", yellow);
fColorSel = new TGColorSelect(fStatusFrame, yellow, 0);
fStatusFrame->AddFrame(fColorSel, new TGLayoutHints(kLHintsTop |
kLHintsLeft, 2, 0, 2, 2));
fMain->AddFrame(fStatusFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
0, 0, 1, 0));
fMain->SetWindowName("GuiTest Signal/Slots");
fMain->MapSubwindows();
// we need to use GetDefault...() to initialize the layout algorithm...
fMain->Resize();
fMain->MapWindow();
fMain->Print();
Connect("Created()", "TestMainFrame", this, "Welcome()");
Created();
}
TestMainFrame::~TestMainFrame()
{
// Delete all created widgets.
delete fMenuFile;
delete fMenuTest;
delete fMenuView;
delete fMenuHelp;
delete fCascadeMenu;
delete fCascade1Menu;
delete fCascade2Menu;
delete fMenuNew1;
delete fMenuNew2;
delete fContainer;
delete fMain;
}
void TestMainFrame::CloseWindow()
{
// Got close message for this MainFrame. Terminates the application.
}
void TestMainFrame::DoButton()
{
// Handle button click.
Editor *ed = new Editor(fMain, 600, 400);
ed->LoadBuffer(editortxt1);
ed->AddBuffer(editortxt2);
ed->AddBuffer(editortxt3);
ed->AddBuffer(editortxt4);
ed->AddBuffer(editortxt5);
ed->AddBuffer(editortxt6);
ed->Popup();
}
void TestMainFrame::HandleMenu(Int_t id)
{
// Handle menu items.
switch (id) {
case M_FILE_OPEN:
{
static TString dir(".");
fi.fFileTypes = filetypes;
fi.SetIniDir(dir);
printf("fIniDir = %s\n", fi.fIniDir);
new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi);
printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir;
}
break;
case M_FILE_SAVE:
printf("M_FILE_SAVE\n");
break;
case M_FILE_PRINT:
printf("M_FILE_PRINT\n");
printf("Hiding itself, select \"Print Setup...\" to enable again\n");
fMenuFile->HideEntry(M_FILE_PRINT);
break;
case M_FILE_PRINTSETUP:
printf("M_FILE_PRINTSETUP\n");
printf("Enabling \"Print\"\n");
fMenuFile->EnableEntry(M_FILE_PRINT);
break;
case M_FILE_EXIT:
CloseWindow(); // terminate theApp no need to use SendCloseMessage()
break;
case M_TEST_DLG:
new TestDialog(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_MSGBOX:
new TestMsgBox(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_SLIDER:
new TestSliders(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_SHUTTER:
new TestShutter(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_DIRLIST:
new TestDirList(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_FILELIST:
new TestFileList(gClient->GetRoot(), fMain, 400, 200);
break;
case M_TEST_PROGRESS:
new TestProgress(gClient->GetRoot(), fMain, 600, 300);
break;
case M_TEST_NUMBERENTRY:
new EntryTestDlg(gClient->GetRoot(), fMain);
break;
case M_TEST_FONTDIALOG:
{
new TGFontDialog(gClient->GetRoot(), fMain, &prop);
if (prop.fName != "")
printf("Selected font: %s, size %d, italic %s, bold %s, color 0x%lx, align %u\n",
prop.fName.Data(), prop.fSize, prop.fItalic ? "yes" : "no",
prop.fBold ? "yes" : "no", prop.fColor, prop.fAlign);
}
break;
case M_TEST_NEWMENU:
{
if (fMenuTest->IsEntryChecked(M_TEST_NEWMENU)) {
HandleMenu(M_NEW_REMOVEMENU);
return;
}
fMenuTest->CheckEntry(M_TEST_NEWMENU);
TGPopupMenu *p = fMenuBar->GetPopup("Test");
fMenuBar->AddPopup("New 1", fMenuNew1, fMenuBarItemLayout, p);
p = fMenuBar->GetPopup("Help");
fMenuBar->AddPopup("New 2", fMenuNew2, fMenuBarItemLayout, p);
fMenuBar->MapSubwindows();
fMenuBar->Layout();
TGMenuEntry *e = fMenuTest->GetEntry("Add New Menus");
fMenuTest->AddEntry("Remove New Menus", M_NEW_REMOVEMENU, 0, 0, e);
}
break;
case M_NEW_REMOVEMENU:
{
fMenuBar->RemovePopup("New 1");
fMenuBar->RemovePopup("New 2");
fMenuBar->Layout();
fMenuTest->DeleteEntry(M_NEW_REMOVEMENU);
fMenuTest->UnCheckEntry(M_TEST_NEWMENU);
}
break;
case M_VIEW_ENBL_DOCK:
fMenuDock->EnableUndock(!fMenuDock->EnableUndock());
if (fMenuDock->EnableUndock()) {
fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->EnableEntry(M_VIEW_UNDOCK);
} else {
fMenuView->UnCheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->DisableEntry(M_VIEW_UNDOCK);
}
break;
case M_VIEW_ENBL_HIDE:
fMenuDock->EnableHide(!fMenuDock->EnableHide());
if (fMenuDock->EnableHide()) {
fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
} else {
fMenuView->UnCheckEntry(M_VIEW_ENBL_HIDE);
}
break;
case M_VIEW_DOCK:
fMenuDock->DockContainer();
fMenuView->EnableEntry(M_VIEW_UNDOCK);
fMenuView->DisableEntry(M_VIEW_DOCK);
break;
case M_VIEW_UNDOCK:
fMenuDock->UndockContainer();
fMenuView->EnableEntry(M_VIEW_DOCK);
fMenuView->DisableEntry(M_VIEW_UNDOCK);
break;
default:
printf("Menu item %d selected\n", id);
break;
}
}
TestDialog::TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w,
UInt_t h, UInt_t options)
{
// Create a dialog window. A dialog window pops up with respect to its
// "main" window.
fMain = new TGTransientFrame(p, main, w, h, options);
fMain->Connect("CloseWindow()", "TestDialog", this, "DoClose()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fFrame1 = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
fOkButton = new TGTextButton(fFrame1, "&Ok", 1);
fOkButton->Connect("Clicked()", "TestDialog", this, "DoOK()");
fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2);
fCancelButton->Connect("Clicked()", "TestDialog", this, "DoCancel()");
2, 2, 2, 2);
fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1);
fFrame1->AddFrame(fOkButton, fL1);
fFrame1->AddFrame(fCancelButton, fL1);
fFrame1->Resize(150, fOkButton->GetDefaultHeight());
fMain->AddFrame(fFrame1, fL2);
//--------- create Tab widget and some composite frames for Tab testing
fTab = new TGTab(fMain, 300, 300);
fTab->Connect("Selected(Int_t)", "TestDialog", this, "DoTab(Int_t)");
fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
TGCompositeFrame *tf = fTab->AddTab("Tab 1");
fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF1->AddFrame(new TGTextButton(fF1, "&Test button", 0), fL3);
fF1->AddFrame(fTxt1 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
fF1->AddFrame(fTxt2 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
tf->AddFrame(fF1, fL3);
fTxt1->Resize(150, fTxt1->GetDefaultHeight());
fTxt2->Resize(150, fTxt2->GetDefaultHeight());
tf = fTab->AddTab("Tab 2");
200, 2, 2, 2);
fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF2->AddFrame(fBtn1 = new TGTextButton(fF2, "&Button 1", 61), fL1);
fF2->AddFrame(fBtn2 = new TGTextButton(fF2, "B&utton 2", 62), fL1);
fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "C&heck 1", 71), fL1);
fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Chec&k 2", 72), fL1);
fF2->AddFrame(fRad1 = new TGRadioButton(fF2, "&Radio 1", 81), fL1);
fF2->AddFrame(fRad2 = new TGRadioButton(fF2, "R&adio 2", 82), fL1);
fCombo = new TGComboBox(fF2, 88);
fF2->AddFrame(fCombo, fL3);
tf->AddFrame(fF2, fL3);
int i;
char tmp[20];
for (i = 0; i < 20; i++) {
sprintf(tmp, "Entry %i", i+1);
fCombo->AddEntry(tmp, i+1);
}
fCombo->Resize(150, 20);
fBtn1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fBtn2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fChk1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fChk2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fRad1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fRad2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
//-------------- embedded canvas demo
fFillHistos = kFALSE;
fHpx = 0;
fHpxpy = 0;
tf = fTab->AddTab("Tab 3");
fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
fStartB = new TGTextButton(fF3, "Start &Filling Hists", 40);
fStopB = new TGTextButton(fF3, "&Stop Filling Hists", 41);
fStartB->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fStopB->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fF3->AddFrame(fStartB, fL3);
fF3->AddFrame(fStopB, fL3);
fF5 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
kLHintsExpandY, 5, 5, 5, 5);
fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 100);
fF5->AddFrame(fEc1, fL4);
fEc2 = new TRootEmbeddedCanvas("ec2", fF5, 100, 100);
fF5->AddFrame(fEc2, fL4);
tf->AddFrame(fF3, fL3);
tf->AddFrame(fF5, fL4);
fEc1->GetCanvas()->SetBorderMode(0);
fEc2->GetCanvas()->SetBorderMode(0);
fEc1->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"TestDialog", this,
"HandleEmbeddedCanvas(Int_t,Int_t,Int_t,TObject*)");
// make tab yellow
Pixel_t yellow;
gClient->GetColorByName("yellow", yellow);
TGTabElement *tabel = fTab->GetTabTab("Tab 3");
tabel->ChangeBackground(yellow);
//-------------- end embedded canvas demo
tf = fTab->AddTab("Tab 4");
fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF4->AddFrame(bt = new TGTextButton(fF4, "A&dd Entry", 90), fL3);
bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fF4->AddFrame(bt = new TGTextButton(fF4, "Remove &Entry", 91), fL3);
bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
fF4->AddFrame(fListBox = new TGListBox(fF4, 89), fL3);
fF4->AddFrame(fCheckMulti = new TGCheckButton(fF4, "&Mutli Selectable", 92), fL3);
fCheckMulti->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
tf->AddFrame(fF4, fL3);
for (i = 0; i < 20; ++i) {
sprintf(tmp, "Entry %i", i);
fListBox->AddEntry(tmp, i);
}
fFirstEntry = 0;
fLastEntry = 20;
fListBox->Resize(150, 80);
//--- tab 5
tf = fTab->AddTab("Tab 5");
fF6 = new TGGroupFrame(tf, "Options", kVerticalFrame);
fF6->SetTitlePos(TGGroupFrame::kRight); // right aligned
tf->AddFrame(fF6, fL3);
// 2 column, n rows
fF6->SetLayoutManager(new TGMatrixLayout(fF6, 0, 2, 10));
char buff[100];
int j;
for (j = 0; j < 4; j++) {
sprintf(buff, "Module %i", j+1);
fF6->AddFrame(new TGLabel(fF6, new TGHotString(buff)));
TGTextBuffer *tbuf = new TGTextBuffer(10);
tbuf->AddText(0, "0.0");
TGTextEntry *tent = new TGTextEntry(fF6, tbuf);
tent->Resize(50, tent->GetDefaultHeight());
tent->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
fF6->AddFrame(tent);
}
fF6->Resize();
// another matrix with text and buttons
fF7 = new TGGroupFrame(tf, "Tab Handling", kVerticalFrame);
tf->AddFrame(fF7, fL3);
fF7->SetLayoutManager(new TGMatrixLayout(fF7, 0, 1, 10));
fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab", 101));
bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
bt->Resize(90, bt->GetDefaultHeight());
fF7->AddFrame(bt = new TGTextButton(fF7, "Add Tab", 103));
bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
bt->Resize(90, bt->GetDefaultHeight());
fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab 5", 102));
bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
bt->Resize(90, bt->GetDefaultHeight());
fF7->Resize(fF6->GetDefaultSize());
//--- end of last tab
kLHintsExpandY, 2, 2, 5, 1);
fMain->AddFrame(fTab, fL5);
fMain->MapSubwindows();
fMain->Resize();
// position relative to the parent's window
fMain->CenterOnParent();
fMain->SetWindowName("Dialog");
fMain->MapWindow();
//gClient->WaitFor(fMain); // otherwise canvas contextmenu does not work
}
TestDialog::~TestDialog()
{
// Delete test dialog widgets.
fMain->DeleteWindow(); // deletes fMain
}
void TestDialog::FillHistos()
{
// Fill histograms till user clicks "Stop Filling" button.
static int cnt;
if (!fHpx) {
fHpx = new TH1F("hpx","This is the px distribution",100,-4,4);
fHpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
cnt = 0;
}
const int kUPDATE = 1000;
float px, py;
TCanvas *c1 = fEc1->GetCanvas();
TCanvas *c2 = fEc2->GetCanvas();
while (fFillHistos) {
gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
fHpx->Fill(px);
fHpxpy->Fill(px,py);
cnt++;
if (!(cnt % kUPDATE)) {
if (cnt == kUPDATE) {
c1->cd();
fHpx->Draw();
c2->cd();
fHpxpy->Draw("cont");
}
c1->Modified();
c1->Update();
c2->Modified();
c2->Update();
gSystem->ProcessEvents(); // handle GUI events
}
}
}
void TestDialog::DoClose()
{
printf("\nTerminating dialog: via window manager\n");
if (fFillHistos) {
fFillHistos = kFALSE;
TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
} else
CloseWindow();
// Close the Ged editor if it was activated.
}
void TestDialog::CloseWindow()
{
// Called when window is closed via the window manager.
delete this;
}
void TestDialog::DoOK()
{
fFillHistos = kFALSE;
printf("\nTerminating dialog: OK pressed\n");
// Add protection against double-clicks
fCancelButton->SetState(kButtonDisabled);
// Send a close message to the main frame. This will trigger the
// emission of a CloseWindow() signal, which will then call
// TestDialog::CloseWindow(). Calling directly CloseWindow() will cause
// a segv since the OK button is still accessed after the DoOK() method.
// This works since the close message is handled synchronous (via
// message going to/from X server).
//fMain->SendCloseMessage();
// The same effect can be obtained by using a singleshot timer:
TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
// Close the Ged editor if it was activated.
}
void TestDialog::DoCancel()
{
fFillHistos = kFALSE;
printf("\nTerminating dialog: Cancel pressed\n");
// Add protection against double-clicks
fCancelButton->SetState(kButtonDisabled);
TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
// Close the Ged editor if it was activated.
}
void TestDialog::HandleButtons(Int_t id)
{
// Handle different buttons.
if (id == -1) {
id = btn->WidgetId();
}
printf("DoButton: id = %d\n", id);
char tmp[20];
static int newtab = 0;
switch (id) {
case 40: // start histogram filling
fFillHistos = kTRUE;
FillHistos();
break;
case 41: // stop histogram filling
fFillHistos = kFALSE;
break;
case 61: // show item 1 in the combo box
fCombo->Select(1);
break;
case 62: // show item 2 in the combo box
fCombo->Select(2);
break;
case 90: // add one entry in list box
fLastEntry++;
sprintf(tmp, "Entry %i", fLastEntry);
fListBox->AddEntry(tmp, fLastEntry);
fListBox->MapSubwindows();
fListBox->Layout();
break;
case 91: // remove one entry in list box
if (fFirstEntry <= fLastEntry) {
fListBox->RemoveEntry(fFirstEntry);
fListBox->Layout();
fFirstEntry++;
}
break;
case 101: // remove tabs
{
TString s = fTab->GetTabTab(0)->GetString();
if ((s == "Tab 3") && (fMain->MustCleanup() != kDeepCleanup)) {
// Need to delete the embedded canvases
// since RemoveTab() will Destroy the container
// window, which in turn will destroy the embedded
// canvas windows.
delete fEc1; fEc1 = 0;
delete fEc2; fEc2 = 0;
}
fTab->RemoveTab(0);
fTab->Layout();
}
break;
case 102: // remove tab 5
{
int nt = fTab->GetNumberOfTabs();
for (int i = 0 ; i < nt; i++) {
TString s = fTab->GetTabTab(i)->GetString();
if (s == "Tab 5") {
fTab->RemoveTab(i);
fTab->Layout();
break;
}
}
}
break;
case 103: // add tabs
sprintf(tmp, "New Tab %d", ++newtab);
fTab->AddTab(tmp);
fTab->MapSubwindows();
fTab->Layout();
break;
case 81:
break;
case 82:
break;
case 92:
fListBox->SetMultipleSelections(fCheckMulti->GetState());
break;
default:
break;
}
}
void TestDialog::DoTab(Int_t id)
{
printf("Tab item %d activated\n", id);
}
void TestDialog::HandleEmbeddedCanvas(Int_t event, Int_t x, Int_t y,
TObject *sel)
{
// Handle events in the left embedded canvas.
if (event == kButton3Down)
printf("event = %d, x = %d, y = %d, obj = %s::%s\n", event, x, y,
sel->IsA()->GetName(), sel->GetName());
}
TestMsgBox::TestMsgBox(const TGWindow *p, const TGWindow *main,
UInt_t w, UInt_t h, UInt_t options) :
fRedTextGC(TGButton::GetDefaultGC())
{
// Create message box test dialog. Use this dialog to select the different
// message dialog box styles and show the message dialog by clicking the
// "Test" button.
fMain = new TGTransientFrame(p, main, w, h, options);
fMain->Connect("CloseWindow()", "TestMsgBox", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
//------------------------------
// Set foreground color in graphics context for drawing of
// TGlabel and TGButtons with text in red.
Pixel_t red;
gClient->GetColorByName("red", red);
fRedTextGC.SetForeground(red);
//---------------------------------
int i;
fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
f1 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame | kFixedWidth);
f2 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
f3 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
f4 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
f5 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
fTestButton = new TGTextButton(f1, "&Test", 1, fRedTextGC());
fTestButton->Connect("Clicked()", "TestMsgBox", this, "DoTest()");
// Change background of fTestButton to green
Pixel_t green;
gClient->GetColorByName("green", green);
fTestButton->ChangeBackground(green);
fCloseButton = new TGTextButton(f1, "&Close", 2);
fCloseButton->Connect("Clicked()", "TestMsgBox", this, "DoClose()");
fPictButton = new TGPictureButton(f1, gClient->GetPicture("mb_stop_s.xpm"));
f1->Resize(fTestButton->GetDefaultWidth()+40, fMain->GetDefaultHeight());
2, 2, 3, 0);
2, 5, 0, 2);
2, 5, 10, 0);
f1->AddFrame(fTestButton, fL1);
f1->AddFrame(fCloseButton, fL1);
f1->AddFrame(fPictButton, fL1);
fMain->AddFrame(f1, fL21);
//--------- create check and radio buttons groups
fG1 = new TGGroupFrame(f3, new TGString("Buttons"),kVerticalFrame|kRaisedFrame);
fG2 = new TGGroupFrame(f3, new TGString("Icons"),kVerticalFrame|kRaisedFrame);
2, 2, 2, 2);
0, 0, 5, 0);
fC[0] = new TGCheckButton(fG1, new TGHotString("Yes"), -1);
fC[1] = new TGCheckButton(fG1, new TGHotString("No"), -1);
fC[2] = new TGCheckButton(fG1, new TGHotString("OK"), -1);
fC[3] = new TGCheckButton(fG1, new TGHotString("Apply"), -1);
fC[4] = new TGCheckButton(fG1, new TGHotString("Retry"), -1);
fC[5] = new TGCheckButton(fG1, new TGHotString("Ignore"), -1);
fC[6] = new TGCheckButton(fG1, new TGHotString("Cancel"), -1);
fC[7] = new TGCheckButton(fG1, new TGHotString("Close"), -1);
fC[8] = new TGCheckButton(fG1, new TGHotString("Yes to All"), -1);
fC[9] = new TGCheckButton(fG1, new TGHotString("No to All"), -1);
fC[10] = new TGCheckButton(fG1, new TGHotString("Newer Only"), -1);
fC[11] = new TGCheckButton(fG1, new TGHotString("Append"), -1);
fC[12] = new TGCheckButton(fG1, new TGHotString("Dismiss"), -1);
for (i=0; i<13; ++i) fG1->AddFrame(fC[i], fL4);
fR[0] = new TGRadioButton(fG2, new TGHotString("Stop"), 21);
fR[1] = new TGRadioButton(fG2, new TGHotString("Question"), 22);
fR[2] = new TGRadioButton(fG2, new TGHotString("Exclamation"), 23);
fR[3] = new TGRadioButton(fG2, new TGHotString("Asterisk"), 24);
for (i = 0; i < 4; ++i) {
fG2->AddFrame(fR[i], fL4);
fR[i]->Connect("Clicked()", "TestMsgBox", this, "DoRadio()");
}
f3->AddFrame(fG1, fL3);
f3->AddFrame(fG2, fL3);
fLtitle = new TGLabel(f4, new TGString("Title:"), fRedTextGC());
fLmsg = new TGLabel(f5, new TGString("Message:"));
fTitle = new TGTextEntry(f4, fTbtitle = new TGTextBuffer(100));
fMsg = new TGTextEntry(f5, fTbmsg = new TGTextBuffer(100));
fTbtitle->AddText(0, "MsgBox");
fTbmsg->AddText(0, "This is a test message box.");
fTitle->Resize(300, fTitle->GetDefaultHeight());
fMsg->Resize(300, fMsg->GetDefaultHeight());
3, 5, 0, 0);
0, 2, 0, 0);
f4->AddFrame(fLtitle, fL5);
f4->AddFrame(fTitle, fL6);
f5->AddFrame(fLmsg, fL5);
f5->AddFrame(fMsg, fL6);
f2->AddFrame(f3, fL1);
f2->AddFrame(f4, fL1);
f2->AddFrame(f5, fL1);
fMain->AddFrame(f2, fL2);
fMain->MapSubwindows();
fMain->Resize();
// position relative to the parent's window
fMain->CenterOnParent();
fMain->SetWindowName("Message Box Test");
fMain->MapWindow();
gClient->WaitFor(fMain);
}
// Order is important when deleting frames. Delete children first,
// parents last.
TestMsgBox::~TestMsgBox()
{
// Delete widgets created by dialog.
fMain->DeleteWindow(); // deletes fMain
}
void TestMsgBox::CloseWindow()
{
// Close dialog in response to window manager close.
delete this;
}
void TestMsgBox::DoClose()
{
// Handle Close button.
CloseWindow();
}
void TestMsgBox::DoTest()
{
// Handle test button.
int i, buttons, retval;
buttons = 0;
for (i = 0; i < 13; i++)
if (fC[i]->GetState() == kButtonDown)
buttons |= mb_button_id[i];
for (i = 0; i < 4; i++)
if (fR[i]->GetState() == kButtonDown) {
icontype = mb_icon[i];
break;
}
// Since the message dialog box is created, we disable the
// signal/slot communication mechanism, in order to ensure we
// can't close the fMain window while the message box is open.
fMain->Disconnect("CloseWindow()");
fMain->Connect("CloseWindow()", "TestMsgBox", this, "TryToClose()");
new TGMsgBox(gClient->GetRoot(), fMain,
fTbtitle->GetString(), fTbmsg->GetString(),
icontype, buttons, &retval);
fMain->Disconnect("CloseWindow()");
fMain->Connect("CloseWindow()", "TestMsgBox", this, "CloseWindow()");
}
void TestMsgBox::TryToClose()
{
// The user try to close the main window,
// while a message dialog box is still open.
printf("Can't close the window '%s' : a message box is still open\n", fMain->GetWindowName());
}
void TestMsgBox::DoRadio()
{
// Handle radio buttons.
Int_t id = btn->WidgetId();
if (id >= 21 && id <= 24) {
for (int i = 0; i < 4; i++)
if (fR[i]->WidgetId() != id)
fR[i]->SetState(kButtonUp);
}
}
TestSliders::TestSliders(const TGWindow *p, const TGWindow *main,
{
// Dialog used to test the different supported sliders.
fMain = new TGTransientFrame(p, main, w, h);
fMain->Connect("CloseWindow()", "TestSliders", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
fVframe1 = new TGVerticalFrame(fMain, 0, 0, 0);
fTeh1 = new TGTextEntry(fVframe1, fTbh1 = new TGTextBuffer(10), HId1);
fTev1 = new TGTextEntry(fVframe1, fTbv1 = new TGTextBuffer(10), VId1);
fTbh1->AddText(0, "0");
fTbv1->AddText(0, "0");
fTeh1->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
fTev1->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
fHslider1 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, HSId1);
fHslider1->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
fHslider1->SetRange(0,50);
fVslider1 = new TGVSlider(fVframe1, 100, kSlider2 | kScaleBoth, VSId1);
fVslider1->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
fVslider1->SetRange(0,8);
fVframe1->Resize(100, 100);
fVframe2 = new TGVerticalFrame(fMain, 0, 0, 0);
fTeh2 = new TGTextEntry(fVframe2, fTbh2 = new TGTextBuffer(10), HId2);
fTev2 = new TGTextEntry(fVframe2, fTbv2 = new TGTextBuffer(10), VId2);
fTbh2->AddText(0, "0");
fTbv2->AddText(0, "0");
fTeh2->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
fTev2->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
fHslider2 = new TGHSlider(fVframe2, 150, kSlider2 | kScaleBoth, HSId2);
fHslider2->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
fHslider2->SetRange(0,3);
fVslider2 = new TGDoubleVSlider(fVframe2, 100, kDoubleScaleBoth, VSId2);
fVslider2->SetRange(-10,10);
fVslider2->Connect("PositionChanged()", "TestSliders", this, "DoSlider()");
fVframe2->Resize(100, 100);
//--- layout for buttons: top align, equally expand horizontally
fBly = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 3, 0);
//--- layout for the frame: place at bottom, right aligned
fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsRight, 20, 10, 15, 0);
fVframe1->AddFrame(fHslider1, fBly);
fVframe1->AddFrame(fVslider1, fBly);
fVframe1->AddFrame(fTeh1, fBly);
fVframe1->AddFrame(fTev1, fBly);
fVframe2->AddFrame(fHslider2, fBly);
fVframe2->AddFrame(fVslider2, fBly);
fVframe2->AddFrame(fTeh2, fBly);
fVframe2->AddFrame(fTev2, fBly);
fMain->AddFrame(fVframe2, fBfly1);
fMain->AddFrame(fVframe1, fBfly1);
fMain->SetWindowName("Slider Test");
TGDimension size = fMain->GetDefaultSize();
fMain->Resize(size);
fMain->SetWMSize(size.fWidth, size.fHeight);
fMain->SetWMSizeHints(size.fWidth, size.fHeight, size.fWidth, size.fHeight, 0, 0);
// position relative to the parent's window
fMain->CenterOnParent();
fMain->MapSubwindows();
fMain->MapWindow();
gClient->WaitFor(fMain);
}
TestSliders::~TestSliders()
{
// Delete dialog.
fMain->DeleteWindow(); // deletes fMain
}
void TestSliders::CloseWindow()
{
// Called when window is closed via the window manager.
delete this;
}
void TestSliders::DoText(const char * /*text*/)
{
// Handle text entry widgets.
Int_t id = te->WidgetId();
switch (id) {
case HId1:
fHslider1->SetPosition(atoi(fTbh1->GetString()));
break;
case VId1:
fVslider1->SetPosition(atoi(fTbv1->GetString()));
break;
case HId2:
fHslider2->SetPosition(atoi(fTbh2->GetString()));
break;
case VId2:
fVslider2->SetPosition(atoi(fTbv2->GetString()),
atoi(fTbv2->GetString())+2);
break;
default:
break;
}
}
void TestSliders::DoSlider(Int_t pos)
{
// Handle slider widgets.
if (frm->IsA()->InheritsFrom(TGSlider::Class())) {
TGSlider *sl = (TGSlider*) frm;
id = sl->WidgetId();
} else {
id = sd->WidgetId();
}
char buf[32];
sprintf(buf, "%d", pos);
#ifdef CINT_FIXED
switch (id) {
case HSId1:
#else
if (id == HSId1) {
#endif
fTbh1->Clear();
fTbh1->AddText(0, buf);
// Re-align the cursor with the characters.
fTeh1->Deselect();
gClient->NeedRedraw(fTeh1);
#ifdef CINT_FIXED
break;
case VSId1:
#else
}
else if (id == VSId1) {
#endif
fTbv1->Clear();
fTbv1->AddText(0, buf);
fTev1->Deselect();
gClient->NeedRedraw(fTev1);
#ifdef CINT_FIXED
break;
case HSId2:
#else
}
else if (id == HSId2) {
#endif
fTbh2->Clear();
fTbh2->AddText(0, buf);
fTeh2->Deselect();
gClient->NeedRedraw(fTeh2);
#ifdef CINT_FIXED
break;
case VSId2:
#else
}
else if (id == VSId2) {
#endif
sprintf(buf, "%f", fVslider2->GetMinPosition());
fTbv2->Clear();
fTbv2->AddText(0, buf);
fTev2->Deselect();
gClient->NeedRedraw(fTev2);
#ifdef CINT_FIXED
break;
default:
break;
#endif
}
}
TestShutter::TestShutter(const TGWindow *p, const TGWindow *main,
{
// Create transient frame containing a shutter widget.
fMain = new TGTransientFrame(p, main, w, h);
fMain->Connect("CloseWindow()", "TestShutter", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fDefaultPic = gClient->GetPicture("folder_s.xpm");
fShutter = new TGShutter(fMain, kSunkenFrame);
AddShutterItem("Histograms", histo_data);
AddShutterItem("Functions", function_data);
AddShutterItem("Trees", tree_data);
fMain->AddFrame(fShutter, fLayout);
fMain->MapSubwindows();
fMain->Resize(80, 300);
// position relative to the parent's window
fMain->CenterOnParent();
fMain->SetWindowName("Shutter Test");
fMain->MapWindow();
//gClient->WaitFor(fMain);
}
void TestShutter::AddShutterItem(const char *name, shutterData_t *data)
{
TGCompositeFrame *container;
TGButton *button;
const TGPicture *buttonpic;
static int id = 5001;
5, 5, 5, 0);
item = new TGShutterItem(fShutter, new TGHotString(name), id++);
container = (TGCompositeFrame *) item->GetContainer();
for (int i=0; data[i].pixmap_name != 0; i++) {
buttonpic = gClient->GetPicture(data[i].pixmap_name);
if (!buttonpic) {
printf("<TestShutter::AddShutterItem>: missing pixmap \"%s\", using default",
data[i].pixmap_name);
buttonpic = fDefaultPic;
}
button = new TGPictureButton(container, buttonpic, data[i].id);
container->AddFrame(button, l);
button->Connect("Clicked()", "TestShutter", this, "HandleButtons()");
button->SetToolTipText(data[i].tip_text);
data[i].button = button;
}
fShutter->AddItem(item);
}
TestShutter::~TestShutter()
{
// dtor
gClient->FreePicture(fDefaultPic);
fMain->DeleteWindow(); // deletes fMain
}
void TestShutter::CloseWindow()
{
delete this;
}
void TestShutter::HandleButtons()
{
printf("Shutter button %d\n", btn->WidgetId());
}
TestDirList::TestDirList(const TGWindow *p, const TGWindow *main,
{
// Create transient frame containing a dirlist widget.
fMain = new TGTransientFrame(p, main, w, h);
fMain->Connect("CloseWindow()", "TestDirList", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
fIcon = gClient->GetPicture("rootdb_t.xpm");
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
TGCanvas* canvas = new TGCanvas(fMain, 500, 300);
fContents = new TGListTree(canvas, kHorizontalFrame);
fMain->AddFrame(canvas,lo);
fContents->Connect("DoubleClicked(TGListTreeItem*,Int_t)","TestDirList",this,
"OnDoubleClick(TGListTreeItem*,Int_t)");
fContents->Connect("Clicked(TGListTreeItem*,Int_t)","TestDirList",this,
"OnDoubleClick(TGListTreeItem*,Int_t)");
#ifdef G__WIN32
fContents->AddItem(0,"c:\\"); // browse the upper directory
#else
fContents->AddItem(0,"/"); // browse the upper directory
#endif
// position relative to the parent's window
fMain->CenterOnParent();
fMain->SetWindowName("List Dir Test");
fMain->MapSubwindows();
fMain->Resize();
fMain->MapWindow();
}
TestDirList::~TestDirList()
{
// Cleanup.
gClient->FreePicture(fIcon);
delete fContents;
fMain->DeleteWindow(); // delete fMain
}
void TestDirList::CloseWindow()
{
delete this;
}
TString TestDirList::DirName(TGListTreeItem* item)
{
// Returns an absolute path.
TGListTreeItem* parent;
TString dirname = item->GetText();
while ((parent = item->GetParent())) {
gSystem->PrependPathName(parent->GetText(),dirname);
item = parent;
}
return dirname;
}
void TestDirList::OnDoubleClick(TGListTreeItem* item, Int_t btn)
{
// Show contents of directory.
if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return;
// use UserData to indicate that item was already browsed
item->SetUserData((void*)1);
TSystemDirectory dir(item->GetText(),DirName(item));
TList *files = dir.GetListOfFiles();
if (files) {
TIter next(files);
TString fname;
while ((file=(TSystemFile*)next())) {
fname = file->GetName();
if (file->IsDirectory()) {
if ((fname!="..") && (fname!=".")) { // skip it
fContents->AddItem(item,fname);
}
} else if (fname.EndsWith(".root")) { // add root files
fContents->AddItem(item,fname,fIcon,fIcon);
}
}
delete files;
}
}
TestFileList::TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h)
{
// Create transient frame containing a filelist widget.
fMain = new TGTransientFrame(p, main, w, h);
fMain->Connect("CloseWindow()", "TestDirList", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
TGMenuBar* mb = new TGMenuBar(fMain);
fMain->AddFrame(mb, lo);
fMenu = mb->AddPopup("&View");
fMenu->AddEntry("Lar&ge Icons",kLVLargeIcons);
fMenu->AddEntry("S&mall Icons",kLVSmallIcons);
fMenu->AddEntry("&List", kLVList);
fMenu->AddEntry("&Details", kLVDetails);
fMenu->AddSeparator();
fMenu->AddEntry("&Close", 10);
fMenu->Connect("Activated(Int_t)","TestFileList",this,"DoMenu(Int_t)");
TGListView* lv = new TGListView(fMain, w, h);
fMain->AddFrame(lv,lo);
Pixel_t white;
gClient->GetColorByName("white", white);
fContents = new TGFileContainer(lv, kSunkenFrame,white);
fContents->Connect("DoubleClicked(TGFrame*,Int_t)", "TestFileList", this,
"OnDoubleClick(TGLVEntry*,Int_t)");
// position relative to the parent's window
fMain->CenterOnParent();
fMain->SetWindowName("File List Test");
fMain->MapSubwindows();
fMain->MapWindow();
fContents->SetDefaultHeaders();
fContents->DisplayDirectory();
fContents->AddFile(".."); // up level directory
fContents->Resize();
fContents->StopRefreshTimer(); // stop refreshing
fMain->Resize();
}
TestFileList::~TestFileList()
{
// Cleanup.
delete fContents;
fMain->DeleteWindow(); // deletes fMain
}
void TestFileList::DoMenu(Int_t mode)
{
// Switch view mode.
if (mode<10) {
fContents->SetViewMode((EListViewMode)mode);
} else {
delete this;
}
}
void TestFileList::DisplayFile(const TString &fname)
{
// Display content of ROOT file.
TFile file(fname);
fContents->RemoveAll();
fContents->AddFile(gSystem->WorkingDirectory());
fContents->SetPagePosition(0,0);
fContents->SetColHeaders("Name","Title");
TIter next(file.GetListOfKeys());
TKey *key;
while ((key=(TKey*)next())) {
TString cname = key->GetClassName();
TString name = key->GetName();
TGLVEntry *entry = new TGLVEntry(fContents,name,cname);
entry->SetSubnames(key->GetTitle());
fContents->AddItem(entry);
// user data is a filename
entry->SetUserData((void*)StrDup(fname));
}
fMain->Resize();
}
void TestFileList::DisplayDirectory(const TString &fname)
{
// Display content of directory.
fContents->SetDefaultHeaders();
fContents->ChangeDirectory(fname);
fContents->DisplayDirectory();
fContents->AddFile(".."); // up level directory
fMain->Resize();
}
void TestFileList::DisplayObject(const TString& fname,const TString& name)
{
// Browse object located in file.
static TFile *file = 0;
if (file) delete file; // close
file = new TFile(fname); // reopen
TObject* obj = file->Get(name);
if (obj) {
if (!obj->IsFolder()) {
obj->Browse(0);
} else obj->Print();
}
gDirectory = sav;
}
void TestFileList::OnDoubleClick(TGLVEntry *f, Int_t btn)
{
// Handle double click.
if (btn != kButton1) return;
// set kWatch cursor
ULong_t cur = gVirtualX->CreateCursor(kWatch);
gVirtualX->SetCursor(fContents->GetId(), cur);
TString name(f->GetTitle());
const char* fname = (const char*)f->GetUserData();
if (fname) {
DisplayObject(fname, name);
} else if (name.EndsWith(".root")) {
DisplayFile(name);
} else {
DisplayDirectory(name);
}
// set kPointer cursor
cur = gVirtualX->CreateCursor(kPointer);
gVirtualX->SetCursor(fContents->GetId(), cur);
}
void TestFileList::CloseWindow()
{
delete this;
}
TestProgress::TestProgress(const TGWindow *p, const TGWindow *main,
{
// Dialog used to test the different supported progress bars.
fClose = kTRUE;
fMain = new TGTransientFrame(p, main, w, h);
fMain->Connect("CloseWindow()", "TestProgress", this, "DoClose()");
fMain->DontCallClose();
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
fHframe1 = new TGHorizontalFrame(fMain, 0, 0, 0);
fVProg1 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
fVProg1->SetBarColor("purple");
fVProg2 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
fVProg2->SetFillType(TGProgressBar::kBlockFill);
fVProg2->SetBarColor("green");
fHframe1->Resize(300, 300);
fVframe1 = new TGVerticalFrame(fMain, 0, 0, 0);
fHProg1 = new TGHProgressBar(fVframe1, 300);
fHProg1->ShowPosition();
fHProg2 = new TGHProgressBar(fVframe1, TGProgressBar::kFancy, 300);
fHProg2->SetBarColor("lightblue");
fHProg2->ShowPosition(kTRUE, kFALSE, "%.0f events");
fHProg3 = new TGHProgressBar(fVframe1, TGProgressBar::kStandard, 300);
fHProg3->SetFillType(TGProgressBar::kBlockFill);
fGO = new TGTextButton(fVframe1, "Go", 10);
fGO->Connect("Clicked()", "TestProgress", this, "DoGo()");
fVframe1->Resize(300, 300);
fHint1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 10, 5, 5);
fHint2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 10);
fHint3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 50, 50, 0);
fHint4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0);
fHint5 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0);
fHframe1->AddFrame(fVProg1, fHint1);
fHframe1->AddFrame(fVProg2, fHint1);
fVframe1->AddFrame(fHProg1, fHint2);
fVframe1->AddFrame(fHProg2, fHint2);
fVframe1->AddFrame(fHProg3, fHint2);
fVframe1->AddFrame(fGO, fHint3);
fMain->AddFrame(fHframe1, fHint4);
fMain->AddFrame(fVframe1, fHint5);
fMain->SetWindowName("Progress Test");
TGDimension size = fMain->GetDefaultSize();
fMain->Resize(size);
// position relative to the parent's window
fMain->CenterOnParent();
fMain->MapSubwindows();
fMain->MapWindow();
gClient->WaitFor(fMain);
}
TestProgress::~TestProgress()
{
// Delete dialog.
fMain->DeleteWindow(); // deletes fMain
}
void TestProgress::CloseWindow()
{
// Called when window is closed via the window manager.
delete this;
}
void TestProgress::DoClose()
{
// If fClose is false we are still in event processing loop in DoGo().
// In that case, set the close flag true and use a timer to call
// CloseWindow(). This gives us change to get out of the DoGo() loop.
// Note: calling SendCloseMessage() will not work since that will
// bring us back here (CloseWindow() signal is connected to this method)
// with the fClose flag true, which will cause window deletion while
// still being in the event processing loop (since SendCloseMessage()
// is directly processed in ProcessEvents() without exiting DoGo()).
if (fClose)
CloseWindow();
else {
fClose = kTRUE;
TTimer::SingleShot(150, "TestProgress", this, "CloseWindow()");
}
}
void TestProgress::DoGo()
{
// Handle Go button.
fClose = kFALSE;
fVProg1->Reset(); fVProg2->Reset();
fHProg1->Reset(); fHProg2->Reset(); fHProg3->Reset();
fVProg2->SetBarColor("green");
int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
int inc1 = 4, inc2 = 3, inc3 = 2, inc4 = 1;
while (cnt1 < 100 || cnt2 < 100 || cnt3 < 100 || cnt4 <100) {
if (cnt1 < 100) {
cnt1 += inc1;
fVProg1->Increment(inc1);
}
if (cnt2 < 100) {
cnt2 += inc2;
fVProg2->Increment(inc2);
if (cnt2 > 75)
fVProg2->SetBarColor("red");
}
if (cnt3 < 100) {
cnt3 += inc3;
fHProg1->Increment(inc3);
}
if (cnt4 < 100) {
cnt4 += inc4;
fHProg2->Increment(inc4);
fHProg3->Increment(inc4);
}
gSystem->Sleep(100);
// if user closed window return
if (fClose) return;
}
fClose = kTRUE;
}
// TGNumberEntry widget test dialog
//const char *const EntryTestDlg::numlabel[] = {
const char *numlabel[] = {
"Integer",
"One digit real",
"Two digit real",
"Three digit real",
"Four digit real",
"Real",
"Degree.min.sec",
"Min:sec",
"Hour:min",
"Hour:min:sec",
"Day/month/year",
"Month/day/year",
"Hex"
};
//const Double_t EntryTestDlg::numinit[] = {
const Double_t numinit[] = {
12345, 1.0, 1.00, 1.000, 1.0000, 1.2E-12,
90 * 3600, 120 * 60, 12 * 60, 12 * 3600 + 15 * 60,
19991121, 19991121, (Double_t) 0xDEADFACEU
};
EntryTestDlg::EntryTestDlg(const TGWindow *p, const TGWindow *main)
{
// build widgets
fMain = new TGTransientFrame(p, main, 10, 10, kHorizontalFrame);
fMain->Connect("CloseWindow()", "EntryTestDlg", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
TGGC myGC = *gClient->GetResourcePool()->GetFrameGC();
TGFont *myfont = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
if (myfont) myGC.SetFont(myfont->GetFontHandle());
fF1 = new TGVerticalFrame(fMain, 200, 300);
fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
fMain->AddFrame(fF1, fL1);
fL2 = new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2);
for (int i = 0; i < 13; i++) {
fF[i] = new TGHorizontalFrame(fF1, 200, 30);
fF1->AddFrame(fF[i], fL2);
fNumericEntries[i] = new TGNumberEntry(fF[i], numinit[i], 12, i + 20,
fF[i]->AddFrame(fNumericEntries[i], fL2);
fLabel[i] = new TGLabel(fF[i], numlabel[i], myGC(), myfont->GetFontStruct());
fF[i]->AddFrame(fLabel[i], fL2);
}
fF2 = new TGVerticalFrame(fMain, 200, 500);
fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
fMain->AddFrame(fF2, fL3);
fLowerLimit = new TGCheckButton(fF2, "lower limit:", 4);
fF2->AddFrame(fLowerLimit, fL3);
fLimits[0] = new TGNumberEntry(fF2, 0, 12, 10);
fLimits[0]->SetLogStep(kFALSE);
fF2->AddFrame(fLimits[0], fL3);
fUpperLimit = new TGCheckButton(fF2, "upper limit:", 5);
fF2->AddFrame(fUpperLimit, fL3);
fLimits[1] = new TGNumberEntry(fF2, 0, 12, 11);
fLimits[1]->SetLogStep(kFALSE);
fF2->AddFrame(fLimits[1], fL3);
fPositive = new TGCheckButton(fF2, "Positive", 6);
fF2->AddFrame(fPositive, fL3);
fNonNegative = new TGCheckButton(fF2, "Non negative", 7);
fF2->AddFrame(fNonNegative, fL3);
fSetButton = new TGTextButton(fF2, " Set ", 2);
fSetButton->Connect("Clicked()", "EntryTestDlg", this, "SetLimits()");
fF2->AddFrame(fSetButton, fL3);
fExitButton = new TGTextButton(fF2, " Close ", 1);
fExitButton->Connect("Clicked()", "EntryTestDlg", this, "DoOK()");
fF2->AddFrame(fExitButton, fL3);
// set dialog box title
fMain->SetWindowName("Number Entry Test");
fMain->SetIconName("Number Entry Test");
fMain->SetClassHints("NumberEntryDlg", "NumberEntryDlg");
// resize & move to center
fMain->MapSubwindows();
UInt_t width = fMain->GetDefaultWidth();
UInt_t height = fMain->GetDefaultHeight();
fMain->Resize(width, height);
fMain->CenterOnParent();
// make the message box non-resizable
fMain->SetWMSize(width, height);
fMain->SetWMSizeHints(width, height, width, height, 0, 0);
fMain->MapWindow();
gClient->WaitFor(fMain);
}
EntryTestDlg::~EntryTestDlg()
{
// dtor
fMain->DeleteWindow();
}
void EntryTestDlg::CloseWindow()
{
delete this;
}
void EntryTestDlg::DoOK()
{
// Handle ok button.
fMain->SendCloseMessage();
}
void EntryTestDlg::SetLimits()
{
Double_t min = fLimits[0]->GetNumber();
Bool_t low = (fLowerLimit->GetState() == kButtonDown);
Double_t max = fLimits[1]->GetNumber();
Bool_t high = (fUpperLimit->GetState() == kButtonDown);
if (low && high) {
} else if (low) {
} else if (high) {
} else {
}
Bool_t pos = (fPositive->GetState() == kButtonDown);
Bool_t nneg = (fNonNegative->GetState() == kButtonDown);
if (pos) {
} else if (nneg) {
} else {
}
for (int i = 0; i < 13; i++) {
fNumericEntries[i]->SetFormat(fNumericEntries[i]->GetNumStyle(), attr);
fNumericEntries[i]->SetLimits(lim, min, max);
}
}
Editor::Editor(const TGWindow *main, UInt_t w, UInt_t h)
{
// Create an editor in a dialog.
fMain = new TGTransientFrame(gClient->GetRoot(), main, w, h);
fMain->Connect("CloseWindow()", "Editor", this, "CloseWindow()");
fMain->DontCallClose(); // to avoid double deletions.
// use hierarchical cleaning
fMain->SetCleanup(kDeepCleanup);
fEdit = new TGTextEdit(fMain, w, h, kSunkenFrame | kDoubleBorder);
fL1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3);
fMain->AddFrame(fEdit, fL1);
fEdit->Connect("Opened()", "Editor", this, "DoOpen()");
fEdit->Connect("Saved()", "Editor", this, "DoSave()");
fEdit->Connect("Closed()", "Editor", this, "DoClose()");
// set selected text colors
Pixel_t pxl;
gClient->GetColorByName("#3399ff", pxl);
fEdit->SetSelectBack(pxl);
fEdit->SetSelectFore(TGFrame::GetWhitePixel());
fOK = new TGTextButton(fMain, " &OK ");
fOK->Connect("Clicked()", "Editor", this, "DoOK()");
fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
fMain->AddFrame(fOK, fL2);
SetTitle();
fMain->MapSubwindows();
fMain->Resize();
// editor covers right half of parent window
fMain->CenterOnParent(kTRUE, TGTransientFrame::kRight);
}
Editor::~Editor()
{
// Delete editor dialog.
fMain->DeleteWindow(); // deletes fMain
}
void Editor::SetTitle()
{
// Set title in editor window.
TGText *txt = GetEditor()->GetText();
Bool_t untitled = !strlen(txt->GetFileName()) ? kTRUE : kFALSE;
char title[256];
if (untitled)
sprintf(title, "ROOT Editor - Untitled");
else
sprintf(title, "ROOT Editor - %s", txt->GetFileName());
fMain->SetWindowName(title);
fMain->SetIconName(title);
}
void Editor::Popup()
{
// Show editor.
fMain->MapWindow();
}
void Editor::LoadBuffer(const char *buffer)
{
// Load a text buffer in the editor.
fEdit->LoadBuffer(buffer);
}
void Editor::LoadFile(const char *file)
{
// Load a file in the editor.
fEdit->LoadFile(file);
}
void Editor::AddBuffer(const char *buffer)
{
// Add text to the editor.
TGText txt;
txt.LoadBuffer(buffer);
fEdit->AddText(&txt);
}
void Editor::CloseWindow()
{
// Called when closed via window manager action.
delete this;
}
void Editor::DoOK()
{
// Handle ok button.
CloseWindow();
}
void Editor::DoOpen()
{
SetTitle();
}
void Editor::DoSave()
{
SetTitle();
}
void Editor::DoClose()
{
// Handle close button.
CloseWindow();
}
void guitest()
{
new TestMainFrame(gClient->GetRoot(), 400, 220);
}
//---- Main program ------------------------------------------------------------
#ifdef STANDALONE
int main(int argc, char **argv)
{
TApplication theApp("App", &argc, argv);
if (gROOT->IsBatch()) {
fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]);
return 1;
}
guitest();
theApp.Run();
return 0;
}
#endif
@ kButton3Down
Definition Buttons.h:17
@ kButtonRelease
Definition GuiTypes.h:60
@ kButtonPress
Definition GuiTypes.h:60
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
const Mask_t kAnyModifier
Definition GuiTypes.h:210
const Mask_t kPointerMotionMask
Definition GuiTypes.h:163
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kVerticalFrame
Definition GuiTypes.h:381
@ kDoubleBorder
Definition GuiTypes.h:385
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
@ kWatch
Definition GuiTypes.h:375
@ kPointer
Definition GuiTypes.h:375
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
@ kButton4
Definition GuiTypes.h:215
@ kButton5
Definition GuiTypes.h:215
@ kButton1
Definition GuiTypes.h:214
@ kAnyButton
Definition GuiTypes.h:214
#define RQ_OBJECT(sender_class)
Definition RQ_OBJECT.h:87
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
unsigned long ULong_t
Definition RtypesCore.h:55
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
@ kRed
Definition Rtypes.h:66
R__EXTERN TApplication * gApplication
#define gDirectory
Definition TDirectory.h:290
include TDocParser_001 C image html pict1_TDocParser_001 png width
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:166
@ kDoubleScaleBoth
@ kFDOpen
@ kMWMDecorResizeH
Definition TGFrame.h:73
@ kMWMFuncAll
Definition TGFrame.h:57
@ kMWMFuncResize
Definition TGFrame.h:58
@ kMWMDecorMaximize
Definition TGFrame.h:77
@ kMWMDecorMinimize
Definition TGFrame.h:76
@ kMWMDecorMenu
Definition TGFrame.h:75
@ kMWMDecorAll
Definition TGFrame.h:71
@ kMWMFuncMaximize
Definition TGFrame.h:61
@ kMWMInputModeless
Definition TGFrame.h:65
@ kMWMFuncMinimize
Definition TGFrame.h:60
@ kDeepCleanup
Definition TGFrame.h:50
@ kLHintsRight
Definition TGLayout.h:33
@ kLHintsExpandY
Definition TGLayout.h:38
@ kLHintsLeft
Definition TGLayout.h:31
@ kLHintsCenterY
Definition TGLayout.h:35
@ kLHintsCenterX
Definition TGLayout.h:32
@ kLHintsBottom
Definition TGLayout.h:36
@ kLHintsTop
Definition TGLayout.h:34
@ kLHintsExpandX
Definition TGLayout.h:37
EListViewMode
Definition TGListView.h:39
@ kLVDetails
Definition TGListView.h:43
@ kLVSmallIcons
Definition TGListView.h:41
@ kLVList
Definition TGListView.h:42
@ kLVLargeIcons
Definition TGListView.h:40
@ kMBNo
Definition TGMsgBox.h:39
@ kMBIgnore
Definition TGMsgBox.h:43
@ kMBApply
Definition TGMsgBox.h:41
@ kMBNoAll
Definition TGMsgBox.h:48
@ kMBClose
Definition TGMsgBox.h:45
@ kMBYes
Definition TGMsgBox.h:38
@ kMBAppend
Definition TGMsgBox.h:49
@ kMBRetry
Definition TGMsgBox.h:42
@ kMBCancel
Definition TGMsgBox.h:44
@ kMBOk
Definition TGMsgBox.h:40
@ kMBYesAll
Definition TGMsgBox.h:47
@ kMBNewer
Definition TGMsgBox.h:50
@ kMBDismiss
Definition TGMsgBox.h:46
EMsgBoxIcon
Definition TGMsgBox.h:28
@ kMBIconExclamation
Definition TGMsgBox.h:31
@ kMBIconAsterisk
Definition TGMsgBox.h:32
@ kMBIconStop
Definition TGMsgBox.h:29
@ kMBIconQuestion
Definition TGMsgBox.h:30
@ kScaleBoth
Definition TGSlider.h:62
@ kSlider2
Definition TGSlider.h:57
@ kSlider1
Definition TGSlider.h:56
XFontStruct * id
Definition TGX11.cxx:109
char name[80]
Definition TGX11.cxx:110
@ kNoContextMenu
Definition TObject.h:360
R__EXTERN void * gTQSender
Definition TQObject.h:46
#define gROOT
Definition TROOT.h:406
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2510
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define gVirtualX
Definition TVirtualX.h:338
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 void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
The Canvas class.
Definition TCanvas.h:23
static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
Convert r,g,b to graphics system dependent pixel value.
Definition TColor.cxx:2054
Describe directory structure in memory.
Definition TDirectory.h:45
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:398
virtual EButtonState GetState() const
Definition TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:188
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
virtual void AddEntry(TGString *s, Int_t id)
Definition TGComboBox.h:106
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:985
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102
virtual void Layout()
Layout the elements of the composite frame.
Definition TGFrame.cxx:1242
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1149
virtual void RemoveAll()
Remove all items from the container.
Definition TGCanvas.cxx:637
virtual void SetPagePosition(const TGPosition &pos)
Set page position.
Definition TGCanvas.cxx:760
UInt_t fHeight
Definition TGDimension.h:30
UInt_t fWidth
Definition TGDimension.h:29
virtual Float_t GetMinPosition() const
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
char * fFilename
const char ** fFileTypes
char * fIniDir
void SetIniDir(const char *inidir)
Set directory name.
FontStruct_t GetFontStruct() const
Definition TGFont.h:193
FontH_t GetFontHandle() const
Definition TGFont.h:192
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:694
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:214
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:215
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:261
virtual void ChangeBackground(Pixel_t back)
Change frame background color.
Definition TGFrame.cxx:278
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
Definition TGGC.h:31
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:410
void SetForeground(Pixel_t v)
Set foreground color.
Definition TGGC.cxx:277
virtual TGDimension GetDefaultSize() const
Returns default size.
Definition TGFrame.cxx:2090
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition TGFrame.h:628
virtual void SetSubnames(const char *n1="", const char *n2="", const char *n3="", const char *n4="", const char *n5="", const char *n6="", const char *n7="", const char *n8="", const char *n9="", const char *n10="", const char *n11="", const char *n12="")
Sets new subnames.
void SetUserData(void *userData)
Definition TGListView.h:112
virtual void Resize(UInt_t w, UInt_t h)
Resize the listbox widget.
virtual void RemoveEntry(Int_t id=-1)
remove entry with id.
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:326
virtual void Layout()
Layout the listbox components.
virtual const char * GetText() const =0
TGListTreeItem * GetParent() const
Definition TGListTree.h:73
virtual void * GetUserData() const =0
virtual void SetUserData(void *, Bool_t=kFALSE)
Definition TGListTree.h:94
void AddItem(TGListTreeItem *parent, TGListTreeItem *item)
Add given item to list tree.
virtual void AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l, TGPopupMenu *before=0)
Add popup menu to menu bar.
Definition TGMenu.cxx:417
Handle_t GetId() const
Definition TGObject.h:47
Pixmap_t GetPicture() const
Definition TGPicture.h:65
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:1151
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
TGFrame * GetContainer() const
Definition TGShutter.h:59
virtual void AddItem(TGShutterItem *item)
Add shutter item to shutter frame.
Definition TGShutter.cxx:72
virtual void SetPosition(Int_t pos)
Definition TGSlider.h:105
virtual void SetRange(Int_t min, Int_t max)
Definition TGSlider.h:101
const char * GetString() const
Definition TGTab.h:159
Definition TGTab.h:62
TGTabElement * GetTabTab(Int_t tabIndex) const
Return the tab element of tab with index tabIndex.
Definition TGTab.cxx:614
Int_t GetNumberOfTabs() const
Return number of tabs.
Definition TGTab.cxx:660
virtual void RemoveTab(Int_t tabIndex=-1, Bool_t storeRemoved=kTRUE)
Remove container and tab of tab with index tabIndex.
Definition TGTab.cxx:394
virtual TGCompositeFrame * AddTab(TGString *text)
Add a tab to the tab widget.
Definition TGTab.cxx:343
void AddText(Int_t pos, const char *text)
const char * GetString() const
Int_t GetCursorPosition() const
void Deselect()
Deselects all text (i.e.
virtual void SetCursorPosition(Int_t pos)
Set the cursor position to newPos.
virtual void SetFont(TGFont *font, Bool_t local=kTRUE)
Changes text font specified by pointer to TGFont object.
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
Definition TGText.cxx:513
const char * GetFileName() const
Definition TGText.h:98
Int_t WidgetId() const
Definition TGWidget.h:78
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3350
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:251
Int_t Fill(Double_t)
Invalid Fill method.
Definition TH2.cxx:294
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual const char * GetClassName() const
Definition TKey.h:76
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition TKey.cxx:1532
A doubly linked list.
Definition TList.h:44
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:37
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TObject.cxx:475
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition TObject.cxx:121
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition TObject.cxx:552
void SetBorderMode(Short_t bordermode) override
Definition TPad.h:317
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:866
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:500
TCanvas * GetCanvas() const
Basic string class.
Definition TString.h:136
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2197
const char * Data() const
Definition TString.h:369
Describes an Operating System directory for the browser.
A TSystemFile describes an operating system file.
Definition TSystemFile.h:29
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1079
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:861
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:438
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:870
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:417
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
This static function calls a slot after a given time interval.
Definition TTimer.cxx:256
static TVirtualPadEditor * GetPadEditor(Bool_t load=kTRUE)
Returns the pad editor dialog. Static method.
static void Terminate()
Close the global pad editor. Static method.
TText * text
int main()
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11
return c2
Definition legend2.C:14
Definition file.py:1
const char * cnt
Definition TXMLSetup.cxx:75
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
UInt_t fCode
key or button code
Definition GuiTypes.h:180
auto * lv
Definition textalign.C:5
auto * l
Definition textangle.C:4
Authors
Ilka Antcheva, Bertrand Bellenot, Fons Rademakers, Valeri Onuchin

Definition in file guitest.C.