guitest.C

Go to the documentation of this file.
00001 // Test program for ROOT native GUI classes 
00002 // exactly like $ROOTSYS/test/guitest.cxx but using the new signal and slots
00003 // communication mechanism. It is now possible to run this entire
00004 // test program in the interpreter. Do either:
00005 // .x guitest.C
00006 // .x guitest.C++
00007 // Authors: Bertrand Bellenot, Ilka Antcheva, Fons Rademakers,
00008 //          Valeri Onuchin
00009 
00010 #include <stdlib.h>
00011 
00012 #include <TROOT.h>
00013 #include <TClass.h>
00014 #include <TApplication.h>
00015 #include <TVirtualX.h>
00016 #include <TVirtualPadEditor.h>
00017 #include <TGResourcePool.h>
00018 #include <TGListBox.h>
00019 #include <TGListTree.h>
00020 #include <TGFSContainer.h>
00021 #include <TGClient.h>
00022 #include <TGFrame.h>
00023 #include <TGIcon.h>
00024 #include <TGLabel.h>
00025 #include <TGButton.h>
00026 #include <TGTextEntry.h>
00027 #include <TGNumberEntry.h>
00028 #include <TGMsgBox.h>
00029 #include <TGMenu.h>
00030 #include <TGCanvas.h>
00031 #include <TGComboBox.h>
00032 #include <TGTab.h>
00033 #include <TGSlider.h>
00034 #include <TGDoubleSlider.h>
00035 #include <TGFileDialog.h>
00036 #include <TGTextEdit.h>
00037 #include <TGShutter.h>
00038 #include <TGProgressBar.h>
00039 #include <TGColorSelect.h>
00040 #include <RQ_OBJECT.h>
00041 #include <TRootEmbeddedCanvas.h>
00042 #include <TCanvas.h>
00043 #include <TColor.h>
00044 #include <TH1.h>
00045 #include <TH2.h>
00046 #include <TRandom.h>
00047 #include <TSystem.h>
00048 #include <TSystemDirectory.h>
00049 #include <TEnv.h>
00050 #include <TFile.h>
00051 #include <TKey.h>
00052 #include <TGDockableFrame.h>
00053 #include <TGFontDialog.h>
00054 
00055 
00056 enum ETestCommandIdentifiers {
00057    M_FILE_OPEN,
00058    M_FILE_SAVE,
00059    M_FILE_SAVEAS,
00060    M_FILE_PRINT,
00061    M_FILE_PRINTSETUP,
00062    M_FILE_EXIT,
00063 
00064    M_TEST_DLG,
00065    M_TEST_MSGBOX,
00066    M_TEST_SLIDER,
00067    M_TEST_SHUTTER,
00068    M_TEST_DIRLIST,
00069    M_TEST_FILELIST,
00070    M_TEST_PROGRESS,
00071    M_TEST_NUMBERENTRY,
00072    M_TEST_FONTDIALOG,
00073    M_TEST_NEWMENU,
00074 
00075    M_VIEW_ENBL_DOCK,
00076    M_VIEW_ENBL_HIDE,
00077    M_VIEW_DOCK,
00078    M_VIEW_UNDOCK,
00079 
00080    M_HELP_CONTENTS,
00081    M_HELP_SEARCH,
00082    M_HELP_ABOUT,
00083 
00084    M_CASCADE_1,
00085    M_CASCADE_2,
00086    M_CASCADE_3,
00087 
00088    M_NEW_REMOVEMENU,
00089 
00090    VId1,
00091    HId1,
00092    VId2,
00093    HId2,
00094 
00095    VSId1,
00096    HSId1,
00097    VSId2,
00098    HSId2
00099 };
00100 
00101 
00102 Int_t mb_button_id[13] = { kMBYes, kMBNo, kMBOk, kMBApply,
00103                            kMBRetry, kMBIgnore, kMBCancel,
00104                            kMBClose, kMBYesAll, kMBNoAll, 
00105                            kMBNewer, kMBAppend, kMBDismiss};
00106 
00107 EMsgBoxIcon mb_icon[4] = { kMBIconStop, kMBIconQuestion,
00108                            kMBIconExclamation, kMBIconAsterisk };
00109 
00110 const char *filetypes[] = { "All files",     "*",
00111                             "ROOT files",    "*.root",
00112                             "ROOT macros",   "*.C",
00113                             "Text files",    "*.[tT][xX][tT]",
00114                             0,               0 };
00115 
00116 struct shutterData_t {
00117    const char *pixmap_name;
00118    const char *tip_text;
00119    Int_t       id;
00120    TGButton   *button;
00121 };
00122 
00123 shutterData_t histo_data[] = {
00124    { "h1_s.xpm",        "TH1",      1001,  0 },
00125    { "h2_s.xpm",        "TH2",      1002,  0 },
00126    { "h3_s.xpm",        "TH3",      1003,  0 },
00127    { "profile_s.xpm",   "TProfile", 1004,  0 },
00128    { 0,                 0,          0,     0 }
00129 };
00130 
00131 shutterData_t function_data[] = {
00132    { "f1_s.xpm",        "TF1",      2001,  0 },
00133    { "f2_s.xpm",        "TF2",      2002,  0 },
00134    { 0,                 0,          0,     0 }
00135 };
00136 
00137 shutterData_t tree_data[] = {
00138    { "ntuple_s.xpm",    "TNtuple",  3001,  0 },
00139    { "tree_s.xpm",      "TTree",    3002,  0 },
00140    { "chain_s.xpm",     "TChain",   3003,  0 },
00141    { 0,                 0,          0,     0 }
00142 };
00143 
00144 
00145 const char *editortxt1 =
00146 "This is the ROOT text edit widget TGTextEdit. It is not intended as\n"
00147 "a full developers editor, but it is relatively complete and can ideally\n"
00148 "be used to edit scripts or to present users editable config files, etc.\n\n"
00149 "The text edit widget supports standard emacs style ctrl-key navigation\n"
00150 "in addition to the arrow keys. By default the widget has under the right\n"
00151 "mouse button a popup menu giving access to several built-in functions.\n\n"
00152 "Cut, copy and paste between different editor windows and any other\n"
00153 "standard text handling application is supported.\n\n"
00154 "Text can be selected with the mouse while holding the left button\n"
00155 "or with the arrow keys while holding the shift key pressed. Use the\n"
00156 "middle mouse button to paste text at the current mouse location."
00157 ;
00158 const char *editortxt2 =
00159 "Mice with scroll-ball are properly supported.\n\n"
00160 "This are the currently defined key bindings:\n"
00161 "Left Arrow\n"
00162 "    Move the cursor one character leftwards.\n"
00163 "    Scroll when cursor is out of frame.\n"
00164 "Right Arrow\n"
00165 "    Move the cursor one character rightwards.\n"
00166 "    Scroll when cursor is out of frame.\n"
00167 "Backspace\n"
00168 "    Deletes the character on the left side of the text cursor and moves the\n"
00169 "    cursor one position to the left. If a text has been marked by the user"
00170 ;
00171 const char *editortxt3 =
00172 "    (e.g. by clicking and dragging) the cursor will be put at the beginning\n"
00173 "    of the marked text and the marked text will be removed.\n"
00174 "Home\n"
00175 "    Moves the text cursor to the left end of the line. If mark is TRUE text\n"
00176 "    will be marked towards the first position, if not any marked text will\n"
00177 "    be unmarked if the cursor is moved.\n"
00178 "End\n"
00179 "    Moves the text cursor to the right end of the line. If mark is TRUE text\n"
00180 "    will be marked towards the last position, if not any marked text will\n"
00181 "    be unmarked if the cursor is moved.\n"
00182 "Delete"
00183 ;
00184 const char *editortxt4 =
00185 "    Deletes the character on the right side of the text cursor. If a text\n"
00186 "    has been marked by the user (e.g. by clicking and dragging) the cursor\n"
00187 "    will be put at the beginning of the marked text and the marked text will\n"
00188 "    be removed.\n"
00189 "Shift - Left Arrow\n"
00190 "    Mark text one character leftwards.\n"
00191 "Shift - Right Arrow\n"
00192 "    Mark text one character rightwards.\n"
00193 "Control-A\n"
00194 "    Select the whole text.\n"
00195 "Control-B\n"
00196 "    Move the cursor one character leftwards."
00197 ;
00198 const char *editortxt5 =
00199 "Control-C\n"
00200 "    Copy the marked text to the clipboard.\n"
00201 "Control-D\n"
00202 "    Delete the character to the right of the cursor.\n"
00203 "Control-E\n"
00204 "    Move the cursor to the end of the line.\n"
00205 "Control-F\n"
00206 "    Start Search Dialog.\n"
00207 "Control-H\n"
00208 "    Delete the character to the left of the cursor.\n"
00209 "Control-K\n"
00210 "    Delete marked text if any or delete all\n"
00211 "    characters to the right of the cursor.\n"
00212 "Control-L\n"
00213 "    Start GoTo Line Dialog"
00214 ;
00215 const char *editortxt6 =
00216 "Control-U\n"
00217 "    Delete all characters on the line.\n"
00218 "Control-V\n"
00219 "    Paste the clipboard text into line edit.\n"
00220 "Control-X\n"
00221 "    Cut the marked text, copy to clipboard.\n"
00222 "Control-Y\n"
00223 "    Paste the clipboard text into line edit.\n"
00224 "Control-Z\n"
00225 "    Undo action.\n\n"
00226 "All other keys with valid ASCII codes insert themselves into the line.";
00227 
00228 
00229 class TileFrame;
00230 
00231 
00232 class TestMainFrame {
00233 
00234 RQ_OBJECT("TestMainFrame")
00235 
00236 private:
00237    TGMainFrame        *fMain;
00238    TGDockableFrame    *fMenuDock;
00239    TGCompositeFrame   *fStatusFrame;
00240    TGCanvas           *fCanvasWindow;
00241    TileFrame          *fContainer;
00242    TGTextEntry        *fTestText;
00243    TGButton           *fTestButton;
00244    TGColorSelect      *fColorSel;
00245 
00246    TGMenuBar          *fMenuBar;
00247    TGPopupMenu        *fMenuFile, *fMenuTest, *fMenuView, *fMenuHelp;
00248    TGPopupMenu        *fCascadeMenu, *fCascade1Menu, *fCascade2Menu;
00249    TGPopupMenu        *fMenuNew1, *fMenuNew2;
00250    TGLayoutHints      *fMenuBarLayout, *fMenuBarItemLayout, *fMenuBarHelpLayout;
00251 
00252 public:
00253    TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
00254    virtual ~TestMainFrame();
00255 
00256    // slots
00257    void CloseWindow();
00258    void DoButton();
00259    void HandleMenu(Int_t id);
00260    void HandlePopup() { printf("menu popped up\n"); }
00261    void HandlePopdown() { printf("menu popped down\n"); }
00262 
00263    void Created() { Emit("Created()"); } //*SIGNAL*
00264    void Welcome() { printf("TestMainFrame has been created. Welcome!\n"); }
00265 };
00266 
00267 class TestDialog {
00268 
00269 RQ_OBJECT("TestDialog")
00270 
00271 private:
00272    TGTransientFrame    *fMain;
00273    TGCompositeFrame    *fFrame1, *fF1, *fF2, *fF3, *fF4, *fF5;
00274    TGGroupFrame        *fF6, *fF7;
00275    TGButton            *fOkButton, *fCancelButton, *fStartB, *fStopB;
00276    TGButton            *fBtn1, *fBtn2, *fChk1, *fChk2, *fRad1, *fRad2;
00277    TGPictureButton     *fPicBut1;
00278    TGCheckButton       *fCheck1;
00279    TGCheckButton       *fCheckMulti;
00280    TGListBox           *fListBox;
00281    TGComboBox          *fCombo;
00282    TGTab               *fTab;
00283    TGTextEntry         *fTxt1, *fTxt2;
00284    TGLayoutHints       *fL1, *fL2, *fL3, *fL4;
00285    TRootEmbeddedCanvas *fEc1, *fEc2;
00286    Int_t                fFirstEntry;
00287    Int_t                fLastEntry;
00288    Bool_t               fFillHistos;
00289    TH1F                *fHpx;
00290    TH2F                *fHpxpy;
00291 
00292    void FillHistos();
00293 
00294 public:
00295    TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
00296                UInt_t options = kVerticalFrame);
00297    virtual ~TestDialog();
00298 
00299    // slots
00300    void DoClose();
00301    void CloseWindow();
00302    void DoOK();
00303    void DoCancel();
00304    void DoTab(Int_t id);
00305    void HandleButtons(Int_t id = -1);
00306    void HandleEmbeddedCanvas(Int_t event, Int_t x, Int_t y, TObject *sel);
00307 };
00308 
00309 class TestMsgBox {
00310 
00311 RQ_OBJECT("TestMsgBox")
00312 
00313 private:
00314    TGTransientFrame     *fMain;
00315    TGCompositeFrame     *f1, *f2, *f3, *f4, *f5;
00316    TGButton             *fTestButton, *fCloseButton;
00317    TGPictureButton      *fPictButton;
00318    TGRadioButton        *fR[4];
00319    TGCheckButton        *fC[13];
00320    TGGroupFrame         *fG1, *fG2;
00321    TGLayoutHints        *fL1, *fL2, *fL3, *fL4, *fL5, *fL6, *fL21;
00322    TGTextEntry          *fTitle, *fMsg;
00323    TGTextBuffer         *fTbtitle, *fTbmsg;
00324    TGLabel              *fLtitle, *fLmsg;
00325    TGGC                  fRedTextGC;
00326 
00327 public:
00328    TestMsgBox(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
00329               UInt_t options = kVerticalFrame);
00330    virtual ~TestMsgBox();
00331 
00332    // slots
00333    void TryToClose();
00334    void CloseWindow();
00335    void DoClose();
00336    void DoRadio();
00337    void DoTest();
00338 };
00339 
00340 
00341 class TestSliders {
00342 
00343 RQ_OBJECT("TestSliders")
00344 
00345 private:
00346    TGTransientFrame  *fMain;
00347    TGVerticalFrame   *fVframe1, *fVframe2;
00348    TGLayoutHints     *fBly, *fBfly1;
00349    TGHSlider         *fHslider1, *fHslider2;
00350    TGVSlider         *fVslider1;
00351    TGDoubleVSlider   *fVslider2;
00352    TGTextEntry       *fTeh1, *fTev1, *fTeh2, *fTev2;
00353    TGTextBuffer      *fTbh1, *fTbv1, *fTbh2, *fTbv2;
00354 
00355 public:
00356    TestSliders(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
00357    virtual ~TestSliders();
00358 
00359    // slots
00360    void CloseWindow();
00361    void DoText(const char *text);
00362    void DoSlider(Int_t pos = 0);
00363 };
00364 
00365 
00366 class TestShutter {
00367 
00368 RQ_OBJECT("TestShutter")
00369 
00370 private:
00371    TGTransientFrame *fMain;
00372    TGShutter        *fShutter;
00373    TGLayoutHints    *fLayout;
00374    const TGPicture  *fDefaultPic;
00375 
00376 public:
00377    TestShutter(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
00378    ~TestShutter();
00379 
00380    void AddShutterItem(const char *name, shutterData_t *data);
00381 
00382    // slots
00383    void CloseWindow();
00384    void HandleButtons();
00385 };
00386 
00387 
00388 class TestDirList {
00389 
00390 RQ_OBJECT("TestDirList")
00391 
00392 protected:
00393    TGTransientFrame *fMain;
00394    TGListTree       *fContents;
00395    const TGPicture  *fIcon;
00396    TString DirName(TGListTreeItem* item);
00397 
00398 public:
00399    TestDirList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
00400    virtual ~TestDirList();
00401 
00402    // slots
00403    void OnDoubleClick(TGListTreeItem* item, Int_t btn);
00404    void CloseWindow();
00405 };
00406 
00407 
00408 class TestFileList {
00409 
00410 RQ_OBJECT("TestFileList")
00411 
00412 protected:
00413    TGTransientFrame *fMain;
00414    TGFileContainer  *fContents;
00415    TGPopupMenu      *fMenu;
00416 
00417    void DisplayFile(const TString &fname);
00418    void DisplayDirectory(const TString &fname);
00419    void DisplayObject(const TString& fname,const TString& name);
00420 
00421 public:
00422    TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
00423    virtual ~TestFileList();
00424 
00425    // slots
00426    void OnDoubleClick(TGLVEntry*,Int_t);
00427    void DoMenu(Int_t);
00428    void CloseWindow();
00429 };
00430 
00431 class TestProgress {
00432 
00433 private:
00434    TGTransientFrame  *fMain;
00435    TGHorizontalFrame *fHframe1;
00436    TGVerticalFrame   *fVframe1;
00437    TGLayoutHints     *fHint1, *fHint2, *fHint3, *fHint4, *fHint5;
00438    TGHProgressBar    *fHProg1, *fHProg2, *fHProg3;
00439    TGVProgressBar    *fVProg1, *fVProg2;
00440    TGTextButton      *fGO;
00441    Bool_t             fClose;
00442 
00443 public:
00444    TestProgress(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
00445    virtual ~TestProgress();
00446 
00447    // slots
00448    void CloseWindow();
00449    void DoClose();
00450    void DoGo();
00451 };
00452 
00453 
00454 class EntryTestDlg {
00455 
00456 private:
00457    TGTransientFrame     *fMain;
00458    TGVerticalFrame      *fF1;
00459    TGVerticalFrame      *fF2;
00460    TGHorizontalFrame    *fF[13];
00461    TGLayoutHints        *fL1;
00462    TGLayoutHints        *fL2;
00463    TGLayoutHints        *fL3;
00464    TGLabel              *fLabel[13];
00465    TGNumberEntry        *fNumericEntries[13];
00466    TGCheckButton        *fLowerLimit;
00467    TGCheckButton        *fUpperLimit;
00468    TGNumberEntry        *fLimits[2];
00469    TGCheckButton        *fPositive;
00470    TGCheckButton        *fNonNegative;
00471    TGButton             *fSetButton;
00472    TGButton             *fExitButton;
00473 
00474 //   static const char *const numlabel[13];
00475 //   static const Double_t numinit[13];
00476 
00477 public:
00478    EntryTestDlg(const TGWindow *p, const TGWindow *main);
00479    virtual ~EntryTestDlg();
00480 
00481    // slots
00482    void CloseWindow();
00483    void SetLimits();
00484    void DoOK();
00485 };
00486 
00487 
00488 class Editor {
00489 
00490 private:
00491    TGTransientFrame *fMain;   // main frame of this widget
00492    TGTextEdit       *fEdit;   // text edit widget
00493    TGTextButton     *fOK;     // OK button
00494    TGLayoutHints    *fL1;     // layout of TGTextEdit
00495    TGLayoutHints    *fL2;     // layout of OK button
00496 
00497 public:
00498    Editor(const TGWindow *main, UInt_t w, UInt_t h);
00499    virtual ~Editor();
00500 
00501    void   LoadFile(const char *file);
00502    void   LoadBuffer(const char *buffer);
00503    void   AddBuffer(const char *buffer);
00504 
00505    TGTextEdit *GetEditor() const { return fEdit; }
00506 
00507    void   SetTitle();
00508    void   Popup();
00509 
00510    // slots
00511    void   CloseWindow();
00512    void   DoOK();
00513    void   DoOpen();
00514    void   DoSave();
00515    void   DoClose();
00516 };
00517 
00518 
00519 class TileFrame {
00520 
00521 RQ_OBJECT("TileFrame")
00522 
00523 private:
00524    TGCompositeFrame *fFrame;
00525    TGCanvas         *fCanvas;
00526 
00527 public:
00528    TileFrame(const TGWindow *p);
00529    virtual ~TileFrame() { delete fFrame; }
00530 
00531    TGFrame *GetFrame() const { return fFrame; }
00532 
00533    void SetCanvas(TGCanvas *canvas) { fCanvas = canvas; }
00534    void HandleMouseWheel(Event_t *event);
00535 };
00536 
00537 TileFrame::TileFrame(const TGWindow *p)
00538 {
00539    // Create tile view container. Used to show colormap.
00540 
00541    fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
00542                                  TGFrame::GetWhitePixel());
00543    fFrame->Connect("ProcessedEvent(Event_t*)", "TileFrame", this,
00544                    "HandleMouseWheel(Event_t*)");
00545    fCanvas = 0;
00546    fFrame->SetLayoutManager(new TGTileLayout(fFrame, 8));
00547 
00548    gVirtualX->GrabButton(fFrame->GetId(), kAnyButton, kAnyModifier,
00549                          kButtonPressMask | kButtonReleaseMask |
00550                          kPointerMotionMask, kNone, kNone);
00551 }
00552 
00553 void TileFrame::HandleMouseWheel(Event_t *event)
00554 {
00555    // Handle mouse wheel to scroll.
00556 
00557    if (event->fType != kButtonPress && event->fType != kButtonRelease)
00558       return;
00559 
00560    Int_t page = 0;
00561    if (event->fCode == kButton4 || event->fCode == kButton5) {
00562       if (!fCanvas) return;
00563       if (fCanvas->GetContainer()->GetHeight())
00564          page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00565                               fCanvas->GetViewPort()->GetHeight()) /
00566                               fCanvas->GetContainer()->GetHeight());
00567    }
00568 
00569    if (event->fCode == kButton4) {
00570       //scroll up
00571       Int_t newpos = fCanvas->GetVsbPosition() - page;
00572       if (newpos < 0) newpos = 0;
00573       fCanvas->SetVsbPosition(newpos);
00574    }
00575    if (event->fCode == kButton5) {
00576       // scroll down
00577       Int_t newpos = fCanvas->GetVsbPosition() + page;
00578       fCanvas->SetVsbPosition(newpos);
00579    }
00580 }
00581 
00582 
00583 TestMainFrame::TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
00584 {
00585    // Create test main frame. A TGMainFrame is a top level window.
00586 
00587    fMain = new TGMainFrame(p, w, h);
00588 
00589    // use hierarchical cleaning
00590    fMain->SetCleanup(kDeepCleanup);
00591 
00592    fMain->Connect("CloseWindow()", "TestMainFrame", this, "CloseWindow()");
00593 
00594    // Create menubar and popup menus. The hint objects are used to place
00595    // and group the different menu widgets with respect to eachother.
00596    fMenuDock = new TGDockableFrame(fMain);
00597    fMain->AddFrame(fMenuDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
00598    fMenuDock->SetWindowName("GuiTest Menu");
00599 
00600    fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
00601    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00602    fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00603 
00604    fMenuFile = new TGPopupMenu(gClient->GetRoot());
00605    fMenuFile->AddEntry("&Open...", M_FILE_OPEN);
00606    fMenuFile->AddEntry("&Save", M_FILE_SAVE);
00607    fMenuFile->AddEntry("S&ave as...", M_FILE_SAVEAS);
00608    fMenuFile->AddEntry("&Close", -1);
00609    fMenuFile->AddSeparator();
00610    fMenuFile->AddEntry("&Print", M_FILE_PRINT);
00611    fMenuFile->AddEntry("P&rint setup...", M_FILE_PRINTSETUP);
00612    fMenuFile->AddSeparator();
00613    fMenuFile->AddEntry("E&xit", M_FILE_EXIT);
00614 
00615    fMenuFile->DisableEntry(M_FILE_SAVEAS);
00616    fMenuFile->HideEntry(M_FILE_PRINT);
00617 
00618    fCascade2Menu = new TGPopupMenu(gClient->GetRoot());
00619    fCascade2Menu->AddEntry("ID = 2&3", M_CASCADE_1);
00620    fCascade2Menu->AddEntry("ID = 2&4", M_CASCADE_2);
00621    fCascade2Menu->AddEntry("ID = 2&5", M_CASCADE_3);
00622 
00623    fCascade1Menu = new TGPopupMenu(gClient->GetRoot());
00624    fCascade1Menu->AddEntry("ID = 4&1", 41);
00625    fCascade1Menu->AddEntry("ID = 4&2", 42);
00626    fCascade1Menu->AddEntry("ID = 4&3", 43);
00627    fCascade1Menu->AddSeparator();
00628    fCascade1Menu->AddPopup("Cascade&d 2", fCascade2Menu);
00629 
00630    fCascadeMenu = new TGPopupMenu(gClient->GetRoot());
00631    fCascadeMenu->AddEntry("ID = 5&1", 51);
00632    fCascadeMenu->AddEntry("ID = 5&2", 52);
00633    fCascadeMenu->AddEntry("ID = 5&3", 53);
00634    fCascadeMenu->AddSeparator();
00635    fCascadeMenu->AddPopup("&Cascaded 1", fCascade1Menu);
00636 
00637    fMenuTest = new TGPopupMenu(gClient->GetRoot());
00638    fMenuTest->AddLabel("Test different features...");
00639    fMenuTest->AddSeparator();
00640    fMenuTest->AddEntry("&Dialog...", M_TEST_DLG);
00641    fMenuTest->AddEntry("&Message Box...", M_TEST_MSGBOX);
00642    fMenuTest->AddEntry("&Sliders...", M_TEST_SLIDER);
00643    fMenuTest->AddEntry("Sh&utter...", M_TEST_SHUTTER);
00644    fMenuTest->AddEntry("&List Directory...", M_TEST_DIRLIST);
00645    fMenuTest->AddEntry("&File List...", M_TEST_FILELIST);
00646    fMenuTest->AddEntry("&Progress...", M_TEST_PROGRESS);
00647    fMenuTest->AddEntry("&Number Entry...", M_TEST_NUMBERENTRY);
00648    fMenuTest->AddEntry("F&ont Dialog...", M_TEST_FONTDIALOG);
00649    fMenuTest->AddSeparator();
00650    fMenuTest->AddEntry("Add New Menus", M_TEST_NEWMENU);
00651    fMenuTest->AddSeparator();
00652    fMenuTest->AddPopup("&Cascaded menus", fCascadeMenu);
00653 
00654    fMenuView = new TGPopupMenu(gClient->GetRoot());
00655    fMenuView->AddEntry("&Dock", M_VIEW_DOCK);
00656    fMenuView->AddEntry("&Undock", M_VIEW_UNDOCK);
00657    fMenuView->AddSeparator();
00658    fMenuView->AddEntry("Enable U&ndock", M_VIEW_ENBL_DOCK);
00659    fMenuView->AddEntry("Enable &Hide", M_VIEW_ENBL_HIDE);
00660    fMenuView->DisableEntry(M_VIEW_DOCK);
00661 
00662    fMenuDock->EnableUndock(kTRUE);
00663    fMenuDock->EnableHide(kTRUE);
00664    fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
00665    fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
00666 
00667    // When using the DockButton of the MenuDock,
00668    // the states 'enable' and 'disable' of menus have to be updated.
00669    fMenuDock->Connect("Undocked()", "TestMainFrame", this, "HandleMenu(=M_VIEW_UNDOCK)");
00670 
00671    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
00672    fMenuHelp->AddEntry("&Contents", M_HELP_CONTENTS);
00673    fMenuHelp->AddEntry("&Search...", M_HELP_SEARCH);
00674    fMenuHelp->AddSeparator();
00675    fMenuHelp->AddEntry("&About", M_HELP_ABOUT);
00676 
00677    fMenuNew1 = new TGPopupMenu();
00678    fMenuNew1->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
00679 
00680    fMenuNew2 = new TGPopupMenu();
00681    fMenuNew2->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
00682 
00683    // Menu button messages are handled by the main frame (i.e. "this")
00684    // HandleMenu() method.
00685    fMenuFile->Connect("Activated(Int_t)", "TestMainFrame", this,
00686                       "HandleMenu(Int_t)");
00687    fMenuFile->Connect("PoppedUp()", "TestMainFrame", this, "HandlePopup()");
00688    fMenuFile->Connect("PoppedDown()", "TestMainFrame", this, "HandlePopdown()");
00689    fMenuTest->Connect("Activated(Int_t)", "TestMainFrame", this,
00690                       "HandleMenu(Int_t)");
00691    fMenuView->Connect("Activated(Int_t)", "TestMainFrame", this,
00692                       "HandleMenu(Int_t)");
00693    fMenuHelp->Connect("Activated(Int_t)", "TestMainFrame", this,
00694                       "HandleMenu(Int_t)");
00695    fCascadeMenu->Connect("Activated(Int_t)", "TestMainFrame", this,
00696                          "HandleMenu(Int_t)");
00697    fCascade1Menu->Connect("Activated(Int_t)", "TestMainFrame", this,
00698                           "HandleMenu(Int_t)");
00699    fCascade2Menu->Connect("Activated(Int_t)", "TestMainFrame", this,
00700                           "HandleMenu(Int_t)");
00701    fMenuNew1->Connect("Activated(Int_t)", "TestMainFrame", this,
00702                       "HandleMenu(Int_t)");
00703    fMenuNew2->Connect("Activated(Int_t)", "TestMainFrame", this,
00704                       "HandleMenu(Int_t)");
00705 
00706    fMenuBar = new TGMenuBar(fMenuDock, 1, 1, kHorizontalFrame);
00707    fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
00708    fMenuBar->AddPopup("&Test", fMenuTest, fMenuBarItemLayout);
00709    fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout);
00710    fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
00711 
00712    fMenuDock->AddFrame(fMenuBar, fMenuBarLayout);
00713 
00714    // Create TGCanvas and a canvas container which uses a tile layout manager
00715    fCanvasWindow = new TGCanvas(fMain, 400, 240);
00716    fContainer = new TileFrame(fCanvasWindow->GetViewPort());
00717    fContainer->SetCanvas(fCanvasWindow);
00718    fCanvasWindow->SetContainer(fContainer->GetFrame());
00719 
00720    // use hierarchical cleaning for container
00721    fContainer->GetFrame()->SetCleanup(kDeepCleanup);
00722 
00723    // Fill canvas with 256 colored frames
00724    for (int i=0; i < 256; ++i)
00725       fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
00726                               32, 32, 0, TColor::RGB2Pixel(0,0,(i+1)&255)),
00727                               new TGLayoutHints(kLHintsExpandY | kLHintsRight));
00728 
00729    fMain->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
00730                                                     0, 0, 2, 2));
00731 
00732    // Create status frame containing a button and a text entry widget
00733    fStatusFrame = new TGCompositeFrame(fMain, 60, 20, kHorizontalFrame |
00734                                                       kSunkenFrame);
00735 
00736    fTestButton = new TGTextButton(fStatusFrame, "&Open editor...", 150);
00737    fTestButton->Connect("Clicked()", "TestMainFrame", this, "DoButton()");
00738    fTestButton->SetToolTipText("Pops up\ntext editor");
00739    fStatusFrame->AddFrame(fTestButton, new TGLayoutHints(kLHintsTop |
00740                           kLHintsLeft, 2, 0, 2, 2));
00741    fTestText = new TGTextEntry(fStatusFrame, new TGTextBuffer(100));
00742    fTestText->SetToolTipText("This is a text entry widget");
00743    fTestText->Resize(300, fTestText->GetDefaultHeight());
00744    fStatusFrame->AddFrame(fTestText, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00745                                                        10, 2, 2, 2));
00746    Pixel_t yellow;
00747    gClient->GetColorByName("yellow", yellow);
00748    fColorSel = new TGColorSelect(fStatusFrame, yellow, 0);
00749    fStatusFrame->AddFrame(fColorSel, new TGLayoutHints(kLHintsTop |
00750                           kLHintsLeft, 2, 0, 2, 2));
00751 
00752    fMain->AddFrame(fStatusFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
00753                    0, 0, 1, 0));
00754 
00755    fMain->SetWindowName("GuiTest Signal/Slots");
00756 
00757    fMain->MapSubwindows();
00758 
00759    // we need to use GetDefault...() to initialize the layout algorithm...
00760    fMain->Resize();
00761    fMain->MapWindow();
00762    fMain->Print();
00763    Connect("Created()", "TestMainFrame", this, "Welcome()");
00764    Created();
00765 }
00766 
00767 TestMainFrame::~TestMainFrame()
00768 {
00769    // Delete all created widgets.
00770 
00771    delete fMenuFile;
00772    delete fMenuTest;
00773    delete fMenuView;
00774    delete fMenuHelp;
00775    delete fCascadeMenu;
00776    delete fCascade1Menu;
00777    delete fCascade2Menu;
00778    delete fMenuNew1;
00779    delete fMenuNew2;
00780 
00781    delete fContainer;
00782    delete fMain;
00783 }
00784 
00785 void TestMainFrame::CloseWindow()
00786 {
00787    // Got close message for this MainFrame. Terminates the application.
00788 
00789    gApplication->Terminate();
00790 }
00791 
00792 void TestMainFrame::DoButton()
00793 {
00794    // Handle button click.
00795 
00796    Editor *ed = new Editor(fMain, 600, 400);
00797    ed->LoadBuffer(editortxt1);
00798    ed->AddBuffer(editortxt2);
00799    ed->AddBuffer(editortxt3);
00800    ed->AddBuffer(editortxt4);
00801    ed->AddBuffer(editortxt5);
00802    ed->AddBuffer(editortxt6);
00803    ed->Popup();
00804 }
00805 
00806 void TestMainFrame::HandleMenu(Int_t id)
00807 {
00808    // Handle menu items.
00809 
00810    switch (id) {
00811 
00812       case M_FILE_OPEN:
00813          {
00814             static TString dir(".");
00815             TGFileInfo fi;
00816             fi.fFileTypes = filetypes;
00817             fi.fIniDir    = StrDup(dir);
00818             printf("fIniDir = %s\n", fi.fIniDir);
00819             new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi);
00820             printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
00821             dir = fi.fIniDir;
00822          }
00823          break;
00824 
00825       case M_FILE_SAVE:
00826          printf("M_FILE_SAVE\n");
00827          break;
00828 
00829       case M_FILE_PRINT:
00830          printf("M_FILE_PRINT\n");
00831          printf("Hiding itself, select \"Print Setup...\" to enable again\n");
00832          fMenuFile->HideEntry(M_FILE_PRINT);
00833          break;
00834 
00835       case M_FILE_PRINTSETUP:
00836          printf("M_FILE_PRINTSETUP\n");
00837          printf("Enabling \"Print\"\n");
00838          fMenuFile->EnableEntry(M_FILE_PRINT);
00839          break;
00840 
00841       case M_FILE_EXIT:
00842          CloseWindow();   // terminate theApp no need to use SendCloseMessage()
00843          break;
00844 
00845       case M_TEST_DLG:
00846          new TestDialog(gClient->GetRoot(), fMain, 400, 200);
00847          break;
00848 
00849       case M_TEST_MSGBOX:
00850          new TestMsgBox(gClient->GetRoot(), fMain, 400, 200);
00851          break;
00852 
00853       case M_TEST_SLIDER:
00854          new TestSliders(gClient->GetRoot(), fMain, 400, 200);
00855          break;
00856 
00857       case M_TEST_SHUTTER:
00858          new TestShutter(gClient->GetRoot(), fMain, 400, 200);
00859          break;
00860 
00861       case M_TEST_DIRLIST:
00862          new TestDirList(gClient->GetRoot(), fMain, 400, 200);
00863          break;
00864 
00865      case M_TEST_FILELIST:
00866          new TestFileList(gClient->GetRoot(), fMain, 400, 200);
00867          break;
00868 
00869       case M_TEST_PROGRESS:
00870          new TestProgress(gClient->GetRoot(), fMain, 600, 300);
00871          break;
00872 
00873       case M_TEST_NUMBERENTRY:
00874          new EntryTestDlg(gClient->GetRoot(), fMain);
00875          break;
00876 
00877       case M_TEST_FONTDIALOG:
00878          {
00879             TGFontDialog::FontProp_t prop;
00880             new TGFontDialog(gClient->GetRoot(), fMain, &prop);
00881             if (prop.fName != "")
00882                printf("Selected font: %s, size %d, italic %s, bold %s, color 0x%lx, align %u\n",
00883                       prop.fName.Data(), prop.fSize, prop.fItalic ? "yes" : "no",
00884                       prop.fBold ? "yes" : "no", prop.fColor, prop.fAlign);
00885          }
00886          break;
00887 
00888       case M_TEST_NEWMENU:
00889          {
00890             if (fMenuTest->IsEntryChecked(M_TEST_NEWMENU)) {
00891                HandleMenu(M_NEW_REMOVEMENU);
00892                return;
00893             }
00894             fMenuTest->CheckEntry(M_TEST_NEWMENU);
00895             TGPopupMenu *p = fMenuBar->GetPopup("Test");
00896             fMenuBar->AddPopup("New 1", fMenuNew1, fMenuBarItemLayout, p);
00897             p = fMenuBar->GetPopup("Help");
00898             fMenuBar->AddPopup("New 2", fMenuNew2, fMenuBarItemLayout, p);
00899             fMenuBar->MapSubwindows();
00900             fMenuBar->Layout();
00901 
00902             TGMenuEntry *e = fMenuTest->GetEntry("Add New Menus");
00903             fMenuTest->AddEntry("Remove New Menus", M_NEW_REMOVEMENU, 0, 0, e);
00904          }
00905          break;
00906 
00907       case M_NEW_REMOVEMENU:
00908          {
00909             fMenuBar->RemovePopup("New 1");
00910             fMenuBar->RemovePopup("New 2");
00911             fMenuBar->Layout();
00912             fMenuTest->DeleteEntry(M_NEW_REMOVEMENU);
00913             fMenuTest->UnCheckEntry(M_TEST_NEWMENU);
00914          }
00915          break;
00916 
00917       case M_VIEW_ENBL_DOCK:
00918          fMenuDock->EnableUndock(!fMenuDock->EnableUndock());
00919          if (fMenuDock->EnableUndock()) {
00920             fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
00921             fMenuView->EnableEntry(M_VIEW_UNDOCK);
00922          } else {
00923             fMenuView->UnCheckEntry(M_VIEW_ENBL_DOCK);
00924             fMenuView->DisableEntry(M_VIEW_UNDOCK);
00925          }
00926          break;
00927 
00928       case M_VIEW_ENBL_HIDE:
00929          fMenuDock->EnableHide(!fMenuDock->EnableHide());
00930          if (fMenuDock->EnableHide()) {
00931             fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
00932          } else {
00933             fMenuView->UnCheckEntry(M_VIEW_ENBL_HIDE);
00934          }
00935          break;
00936 
00937        case M_VIEW_DOCK:
00938          fMenuDock->DockContainer();
00939          fMenuView->EnableEntry(M_VIEW_UNDOCK);
00940          fMenuView->DisableEntry(M_VIEW_DOCK);
00941          break;
00942 
00943        case M_VIEW_UNDOCK:
00944          fMenuDock->UndockContainer();
00945          fMenuView->EnableEntry(M_VIEW_DOCK);
00946          fMenuView->DisableEntry(M_VIEW_UNDOCK);
00947          break;
00948 
00949       default:
00950          printf("Menu item %d selected\n", id);
00951          break;
00952    }
00953 }
00954 
00955 
00956 TestDialog::TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w,
00957                        UInt_t h, UInt_t options)
00958 {
00959    // Create a dialog window. A dialog window pops up with respect to its
00960    // "main" window.
00961 
00962    fMain = new TGTransientFrame(p, main, w, h, options);
00963    fMain->Connect("CloseWindow()", "TestDialog", this, "DoClose()");
00964    fMain->DontCallClose(); // to avoid double deletions.
00965 
00966    // use hierarchical cleaning
00967    fMain->SetCleanup(kDeepCleanup);
00968 
00969    fFrame1 = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth);
00970 
00971    fOkButton = new TGTextButton(fFrame1, "&Ok", 1);
00972    fOkButton->Connect("Clicked()", "TestDialog", this, "DoOK()");
00973    fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2);
00974    fCancelButton->Connect("Clicked()", "TestDialog", this, "DoCancel()");
00975 
00976    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
00977                            2, 2, 2, 2);
00978    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1);
00979 
00980    fFrame1->AddFrame(fOkButton, fL1);
00981    fFrame1->AddFrame(fCancelButton, fL1);
00982 
00983    fFrame1->Resize(150, fOkButton->GetDefaultHeight());
00984    fMain->AddFrame(fFrame1, fL2);
00985 
00986    //--------- create Tab widget and some composite frames for Tab testing
00987 
00988    fTab = new TGTab(fMain, 300, 300);
00989    fTab->Connect("Selected(Int_t)", "TestDialog", this, "DoTab(Int_t)");
00990 
00991    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
00992 
00993    TGCompositeFrame *tf = fTab->AddTab("Tab 1");
00994    fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
00995    fF1->AddFrame(new TGTextButton(fF1, "&Test button", 0), fL3);
00996    fF1->AddFrame(fTxt1 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
00997    fF1->AddFrame(fTxt2 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
00998    tf->AddFrame(fF1, fL3);
00999    fTxt1->Resize(150, fTxt1->GetDefaultHeight());
01000    fTxt2->Resize(150, fTxt2->GetDefaultHeight());
01001 
01002    tf = fTab->AddTab("Tab 2");
01003    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
01004                            200, 2, 2, 2);
01005    fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
01006    fF2->AddFrame(fBtn1 = new TGTextButton(fF2, "&Button 1", 61), fL1);
01007    fF2->AddFrame(fBtn2 = new TGTextButton(fF2, "B&utton 2", 62), fL1);
01008    fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "C&heck 1", 71), fL1);
01009    fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Chec&k 2", 72), fL1);
01010    fF2->AddFrame(fRad1 = new TGRadioButton(fF2, "&Radio 1", 81), fL1);
01011    fF2->AddFrame(fRad2 = new TGRadioButton(fF2, "R&adio 2", 82), fL1);
01012    fCombo = new TGComboBox(fF2, 88);
01013    fF2->AddFrame(fCombo, fL3);
01014 
01015    tf->AddFrame(fF2, fL3);
01016 
01017    int i;
01018    char tmp[20];
01019    for (i = 0; i < 20; i++) {
01020 
01021       sprintf(tmp, "Entry %i", i+1);
01022       fCombo->AddEntry(tmp, i+1);
01023    }
01024 
01025    fCombo->Resize(150, 20);
01026 
01027    fBtn1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01028    fBtn2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01029    fChk1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01030    fChk2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01031    fRad1->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01032    fRad2->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01033 
01034    //-------------- embedded canvas demo
01035    fFillHistos = kFALSE;
01036    fHpx   = 0;
01037    fHpxpy = 0;
01038 
01039    tf = fTab->AddTab("Tab 3");
01040    fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
01041    fStartB = new TGTextButton(fF3, "Start &Filling Hists", 40);
01042    fStopB  = new TGTextButton(fF3, "&Stop Filling Hists", 41);
01043    fStartB->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01044    fStopB->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01045    fF3->AddFrame(fStartB, fL3);
01046    fF3->AddFrame(fStopB, fL3);
01047 
01048    fF5 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
01049 
01050    fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX |
01051                            kLHintsExpandY, 5, 5, 5, 5);
01052    fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 100);
01053    fF5->AddFrame(fEc1, fL4);
01054    fEc2 = new TRootEmbeddedCanvas("ec2", fF5, 100, 100);
01055    fF5->AddFrame(fEc2, fL4);
01056 
01057    tf->AddFrame(fF3, fL3);
01058    tf->AddFrame(fF5, fL4);
01059 
01060    fEc1->GetCanvas()->SetBorderMode(0);
01061    fEc2->GetCanvas()->SetBorderMode(0);
01062    fEc1->GetCanvas()->SetBit(kNoContextMenu);
01063    fEc1->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
01064                               "TestDialog", this,
01065                               "HandleEmbeddedCanvas(Int_t,Int_t,Int_t,TObject*)");
01066 
01067    // make tab yellow
01068    Pixel_t yellow;
01069    gClient->GetColorByName("yellow", yellow);
01070    TGTabElement *tabel = fTab->GetTabTab("Tab 3");
01071    tabel->ChangeBackground(yellow);
01072 
01073    //-------------- end embedded canvas demo
01074 
01075    TGTextButton *bt;
01076    tf = fTab->AddTab("Tab 4");
01077    fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
01078    fF4->AddFrame(bt = new TGTextButton(fF4, "A&dd Entry", 90), fL3);
01079    bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01080 
01081    fF4->AddFrame(bt = new TGTextButton(fF4, "Remove &Entry", 91), fL3);
01082    bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01083 
01084    fF4->AddFrame(fListBox = new TGListBox(fF4, 89), fL3);
01085    fF4->AddFrame(fCheckMulti = new TGCheckButton(fF4, "&Mutli Selectable", 92), fL3);
01086    fCheckMulti->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01087    tf->AddFrame(fF4, fL3);
01088 
01089    for (i = 0; i < 20; ++i)  {
01090       sprintf(tmp, "Entry %i", i);
01091       fListBox->AddEntry(tmp, i);
01092    }
01093    fFirstEntry = 0;
01094    fLastEntry  = 20;
01095 
01096    fListBox->Resize(150, 80);
01097 
01098    //--- tab 5
01099    tf = fTab->AddTab("Tab 5");
01100    tf->SetLayoutManager(new TGHorizontalLayout(tf));
01101 
01102    fF6 = new TGGroupFrame(tf, "Options", kVerticalFrame);
01103    fF6->SetTitlePos(TGGroupFrame::kRight); // right aligned
01104    tf->AddFrame(fF6, fL3);
01105 
01106    // 2 column, n rows
01107    fF6->SetLayoutManager(new TGMatrixLayout(fF6, 0, 2, 10));
01108    char buff[100];
01109    int j;
01110    for (j = 0; j < 4; j++) {
01111       sprintf(buff, "Module %i", j+1);
01112       fF6->AddFrame(new TGLabel(fF6, new TGHotString(buff)));
01113 
01114       TGTextBuffer *tbuf = new TGTextBuffer(10);
01115       tbuf->AddText(0, "0.0");
01116 
01117       TGTextEntry  *tent = new TGTextEntry(fF6, tbuf);
01118       tent->Resize(50, tent->GetDefaultHeight());
01119       tent->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
01120       fF6->AddFrame(tent);
01121    }
01122    fF6->Resize();
01123 
01124    // another matrix with text and buttons
01125    fF7 = new TGGroupFrame(tf, "Tab Handling", kVerticalFrame);
01126    tf->AddFrame(fF7, fL3);
01127 
01128    fF7->SetLayoutManager(new TGMatrixLayout(fF7, 0, 1, 10));
01129 
01130    fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab", 101));
01131    bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01132    bt->Resize(90, bt->GetDefaultHeight());
01133 
01134    fF7->AddFrame(bt = new TGTextButton(fF7, "Add Tab", 103));
01135    bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01136    bt->Resize(90, bt->GetDefaultHeight());
01137 
01138    fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab 5", 102));
01139    bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()");
01140    bt->Resize(90, bt->GetDefaultHeight());
01141 
01142    fF7->Resize(fF6->GetDefaultSize());
01143 
01144    //--- end of last tab
01145 
01146    TGLayoutHints *fL5 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
01147                                           kLHintsExpandY, 2, 2, 5, 1);
01148    fMain->AddFrame(fTab, fL5);
01149 
01150    fMain->MapSubwindows();
01151    fMain->Resize();
01152 
01153    // position relative to the parent's window
01154    fMain->CenterOnParent();
01155 
01156    fMain->SetWindowName("Dialog");
01157 
01158    fMain->MapWindow();
01159    //gClient->WaitFor(fMain);    // otherwise canvas contextmenu does not work
01160 }
01161 
01162 TestDialog::~TestDialog()
01163 {
01164    // Delete test dialog widgets.
01165 
01166    fMain->DeleteWindow();  // deletes fMain
01167 }
01168 
01169 void TestDialog::FillHistos()
01170 {
01171    // Fill histograms till user clicks "Stop Filling" button.
01172 
01173    static int cnt;
01174 
01175    if (!fHpx) {
01176       fHpx   = new TH1F("hpx","This is the px distribution",100,-4,4);
01177       fHpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
01178       fHpx->SetFillColor(kRed);
01179       cnt = 0;
01180    }
01181 
01182    const int kUPDATE = 1000;
01183    float px, py;
01184    TCanvas *c1 = fEc1->GetCanvas();
01185    TCanvas *c2 = fEc2->GetCanvas();
01186 
01187    while (fFillHistos) {
01188       gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
01189       fHpx->Fill(px);
01190       fHpxpy->Fill(px,py);
01191       cnt++;
01192       if (!(cnt % kUPDATE)) {
01193          if (cnt == kUPDATE) {
01194             c1->cd();
01195             fHpx->Draw();
01196             c2->cd();
01197             fHpxpy->Draw("cont");
01198          }
01199          c1->Modified();
01200          c1->Update();
01201          c2->Modified();
01202          c2->Update();
01203          gSystem->ProcessEvents();  // handle GUI events
01204       }
01205    }
01206 }
01207 
01208 void TestDialog::DoClose()
01209 {
01210    printf("\nTerminating dialog: via window manager\n");
01211    if (fFillHistos) {
01212       fFillHistos = kFALSE;
01213       TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
01214    } else
01215       CloseWindow();
01216 
01217    // Close the Ged editor if it was activated.
01218    if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
01219       TVirtualPadEditor::Terminate();
01220 }
01221 
01222 void TestDialog::CloseWindow()
01223 {
01224    // Called when window is closed via the window manager.
01225 
01226    delete this;
01227 }
01228 
01229 void TestDialog::DoOK()
01230 {
01231    fFillHistos = kFALSE;
01232    printf("\nTerminating dialog: OK pressed\n");
01233    // Add protection against double-clicks
01234    fOkButton->SetState(kButtonDisabled);
01235    fCancelButton->SetState(kButtonDisabled);
01236 
01237    // Send a close message to the main frame. This will trigger the
01238    // emission of a CloseWindow() signal, which will then call
01239    // TestDialog::CloseWindow(). Calling directly CloseWindow() will cause
01240    // a segv since the OK button is still accessed after the DoOK() method.
01241    // This works since the close message is handled synchronous (via
01242    // message going to/from X server).
01243    //fMain->SendCloseMessage();
01244 
01245    // The same effect can be obtained by using a singleshot timer:
01246    TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
01247 
01248    // Close the Ged editor if it was activated.
01249    if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
01250       TVirtualPadEditor::Terminate();
01251 }
01252 
01253 
01254 void TestDialog::DoCancel()
01255 {
01256    fFillHistos = kFALSE;
01257    printf("\nTerminating dialog: Cancel pressed\n");
01258    // Add protection against double-clicks
01259    fOkButton->SetState(kButtonDisabled);
01260    fCancelButton->SetState(kButtonDisabled);
01261    TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()");
01262    // Close the Ged editor if it was activated.
01263    if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0)
01264       TVirtualPadEditor::Terminate();
01265 }
01266 
01267 void TestDialog::HandleButtons(Int_t id)
01268 {
01269    // Handle different buttons.
01270 
01271    if (id == -1) {
01272       TGButton *btn = (TGButton *) gTQSender;
01273       id = btn->WidgetId();
01274    }
01275 
01276    printf("DoButton: id = %d\n", id);
01277 
01278    char tmp[20];
01279    static int newtab = 0;
01280 
01281    switch (id) {
01282       case 40:  // start histogram filling
01283          fFillHistos = kTRUE;
01284          FillHistos();
01285          break;
01286       case 41:  // stop histogram filling
01287          fFillHistos = kFALSE;
01288          break;
01289       case 61:  // show item 1 in the combo box
01290          fCombo->Select(1);
01291          break;
01292       case 62:  // show item 2 in the combo box
01293          fCombo->Select(2);
01294          break;
01295       case 90:  // add one entry in list box
01296          fLastEntry++;
01297          sprintf(tmp, "Entry %i", fLastEntry);
01298          fListBox->AddEntry(tmp, fLastEntry);
01299          fListBox->MapSubwindows();
01300          fListBox->Layout();
01301          break;
01302       case 91:  // remove one entry in list box
01303          if (fFirstEntry <= fLastEntry) {
01304             fListBox->RemoveEntry(fFirstEntry);
01305             fListBox->Layout();
01306             fFirstEntry++;
01307          }
01308          break;
01309       case 101:  // remove tabs
01310          {
01311             TString s = fTab->GetTabTab(0)->GetString();
01312             if ((s == "Tab 3") && (fMain->MustCleanup() != kDeepCleanup)) {
01313                // Need to delete the embedded canvases
01314                // since RemoveTab() will Destroy the container
01315                // window, which in turn will destroy the embedded
01316                // canvas windows.
01317                delete fEc1; fEc1 = 0;
01318                delete fEc2; fEc2 = 0;
01319             }
01320             fTab->RemoveTab(0);
01321             fTab->Layout();
01322          }
01323          break;
01324       case 102:  // remove tab 5
01325          {
01326             int nt = fTab->GetNumberOfTabs();
01327             for (int i = 0 ; i < nt; i++) {
01328                TString s = fTab->GetTabTab(i)->GetString();
01329                if (s == "Tab 5") {
01330                   fTab->RemoveTab(i);
01331                   fTab->Layout();
01332                   break;
01333                }
01334             }
01335          }
01336          break;
01337       case 103:  // add tabs
01338          sprintf(tmp, "New Tab %d", ++newtab);
01339          fTab->AddTab(tmp);
01340          fTab->MapSubwindows();
01341          fTab->Layout();
01342          break;
01343       case 81:
01344          fRad2->SetState(kButtonUp);
01345          break;
01346       case 82:
01347          fRad1->SetState(kButtonUp);
01348          break;
01349       case 92:
01350          fListBox->SetMultipleSelections(fCheckMulti->GetState());
01351          break;
01352       default:
01353          break;
01354    }
01355 }
01356 
01357 void TestDialog::DoTab(Int_t id)
01358 {
01359    printf("Tab item %d activated\n", id);
01360 }
01361 
01362 void TestDialog::HandleEmbeddedCanvas(Int_t event, Int_t x, Int_t y,
01363                                       TObject *sel)
01364 {
01365    // Handle events in the left embedded canvas.
01366 
01367    if (event == kButton3Down)
01368       printf("event = %d, x = %d, y = %d, obj = %s::%s\n", event, x, y,
01369              sel->IsA()->GetName(), sel->GetName());
01370 }
01371 
01372 TestMsgBox::TestMsgBox(const TGWindow *p, const TGWindow *main,
01373                        UInt_t w, UInt_t h, UInt_t options) :
01374      fRedTextGC(TGButton::GetDefaultGC())
01375 {
01376    // Create message box test dialog. Use this dialog to select the different
01377    // message dialog box styles and show the message dialog by clicking the
01378    // "Test" button.
01379 
01380    fMain = new TGTransientFrame(p, main, w, h, options);
01381    fMain->Connect("CloseWindow()", "TestMsgBox", this, "CloseWindow()");
01382    fMain->DontCallClose(); // to avoid double deletions.
01383 
01384    // use hierarchical cleaning
01385    fMain->SetCleanup(kDeepCleanup);
01386 
01387    //------------------------------
01388    // Set foreground color in graphics context for drawing of
01389    // TGlabel and TGButtons with text in red.
01390 
01391    Pixel_t red;
01392    gClient->GetColorByName("red", red);
01393    fRedTextGC.SetForeground(red);
01394    //---------------------------------
01395 
01396    int i;
01397 
01398    fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
01399 
01400    f1 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame | kFixedWidth);
01401    f2 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
01402    f3 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
01403    f4 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
01404    f5 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
01405 
01406    fTestButton = new TGTextButton(f1, "&Test", 1, fRedTextGC());
01407    fTestButton->Connect("Clicked()", "TestMsgBox", this, "DoTest()");
01408 
01409    // Change background of fTestButton to green
01410    Pixel_t green;
01411    gClient->GetColorByName("green", green);
01412    fTestButton->ChangeBackground(green);
01413 
01414    fCloseButton = new TGTextButton(f1, "&Close", 2);
01415    fCloseButton->Connect("Clicked()", "TestMsgBox", this, "DoClose()");
01416 
01417    fPictButton = new TGPictureButton(f1, gClient->GetPicture("mb_stop_s.xpm"));
01418 
01419    f1->Resize(fTestButton->GetDefaultWidth()+40, fMain->GetDefaultHeight());
01420 
01421    fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX,
01422                            2, 2, 3, 0);
01423    fL2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
01424                            2, 5, 0, 2);
01425    fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight,
01426                             2, 5, 10, 0);
01427 
01428    f1->AddFrame(fTestButton, fL1);
01429    f1->AddFrame(fCloseButton, fL1);
01430    f1->AddFrame(fPictButton, fL1);
01431    fMain->AddFrame(f1, fL21);
01432 
01433    //--------- create check and radio buttons groups
01434 
01435    fG1 = new TGGroupFrame(f3, new TGString("Buttons"),kVerticalFrame|kRaisedFrame);
01436    fG2 = new TGGroupFrame(f3, new TGString("Icons"),kVerticalFrame|kRaisedFrame);
01437 
01438    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft |
01439                            kLHintsExpandX | kLHintsExpandY,
01440                            2, 2, 2, 2);
01441    fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft,
01442                            0, 0, 5, 0);
01443 
01444    fC[0]  = new TGCheckButton(fG1, new TGHotString("Yes"),        -1);
01445    fC[1]  = new TGCheckButton(fG1, new TGHotString("No"),         -1);
01446    fC[2]  = new TGCheckButton(fG1, new TGHotString("OK"),         -1);
01447    fC[3]  = new TGCheckButton(fG1, new TGHotString("Apply"),      -1);
01448    fC[4]  = new TGCheckButton(fG1, new TGHotString("Retry"),      -1);
01449    fC[5]  = new TGCheckButton(fG1, new TGHotString("Ignore"),     -1);
01450    fC[6]  = new TGCheckButton(fG1, new TGHotString("Cancel"),     -1);
01451    fC[7]  = new TGCheckButton(fG1, new TGHotString("Close"),      -1);
01452    fC[8]  = new TGCheckButton(fG1, new TGHotString("Yes to All"), -1);
01453    fC[9]  = new TGCheckButton(fG1, new TGHotString("No to All"),  -1);
01454    fC[10] = new TGCheckButton(fG1, new TGHotString("Newer Only"), -1);
01455    fC[11] = new TGCheckButton(fG1, new TGHotString("Append"),     -1);
01456    fC[12] = new TGCheckButton(fG1, new TGHotString("Dismiss"),    -1);
01457 
01458    for (i=0; i<13; ++i) fG1->AddFrame(fC[i], fL4);
01459 
01460    fR[0] = new TGRadioButton(fG2, new TGHotString("Stop"),        21);
01461    fR[1] = new TGRadioButton(fG2, new TGHotString("Question"),    22);
01462    fR[2] = new TGRadioButton(fG2, new TGHotString("Exclamation"), 23);
01463    fR[3] = new TGRadioButton(fG2, new TGHotString("Asterisk"),    24);
01464 
01465    for (i = 0; i < 4; ++i) {
01466       fG2->AddFrame(fR[i], fL4);
01467       fR[i]->Connect("Clicked()", "TestMsgBox", this, "DoRadio()");
01468    }
01469 
01470    fC[2]->SetState(kButtonDown);
01471    fR[0]->SetState(kButtonDown);
01472 
01473    f3->AddFrame(fG1, fL3);
01474    f3->AddFrame(fG2, fL3);
01475 
01476    fLtitle = new TGLabel(f4, new TGString("Title:"), fRedTextGC());
01477    fLmsg   = new TGLabel(f5, new TGString("Message:"));
01478 
01479    fTitle = new TGTextEntry(f4, fTbtitle = new TGTextBuffer(100));
01480    fMsg   = new TGTextEntry(f5, fTbmsg = new TGTextBuffer(100));
01481 
01482    fTbtitle->AddText(0, "MsgBox");
01483    fTbmsg->AddText(0, "This is a test message box.");
01484 
01485    fTitle->Resize(300, fTitle->GetDefaultHeight());
01486    fMsg->Resize(300, fMsg->GetDefaultHeight());
01487 
01488    fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
01489                            3, 5, 0, 0);
01490    fL6 = new TGLayoutHints(kLHintsRight | kLHintsCenterY,
01491                            0, 2, 0, 0);
01492 
01493    f4->AddFrame(fLtitle, fL5);
01494    f4->AddFrame(fTitle, fL6);
01495    f5->AddFrame(fLmsg, fL5);
01496    f5->AddFrame(fMsg, fL6);
01497 
01498    f2->AddFrame(f3, fL1);
01499    f2->AddFrame(f4, fL1);
01500    f2->AddFrame(f5, fL1);
01501 
01502    fMain->AddFrame(f2, fL2);
01503 
01504    fMain->MapSubwindows();
01505    fMain->Resize();
01506 
01507    // position relative to the parent's window
01508    fMain->CenterOnParent();
01509 
01510    fMain->SetWindowName("Message Box Test");
01511 
01512    fMain->MapWindow();
01513    gClient->WaitFor(fMain);
01514 }
01515 
01516 // Order is important when deleting frames. Delete children first,
01517 // parents last.
01518 
01519 TestMsgBox::~TestMsgBox()
01520 {
01521    // Delete widgets created by dialog.
01522 
01523    fMain->DeleteWindow();  // deletes fMain
01524 }
01525 
01526 void TestMsgBox::CloseWindow()
01527 {
01528    // Close dialog in response to window manager close.
01529 
01530    delete this;
01531 }
01532 
01533 void TestMsgBox::DoClose()
01534 {
01535    // Handle Close button.
01536 
01537    CloseWindow();
01538 }
01539 
01540 void TestMsgBox::DoTest()
01541 {
01542    // Handle test button.
01543 
01544    int i, buttons, retval;
01545    EMsgBoxIcon icontype = kMBIconStop;
01546 
01547    buttons = 0;
01548    for (i = 0; i < 13; i++)
01549       if (fC[i]->GetState() == kButtonDown)
01550          buttons |= mb_button_id[i];
01551 
01552    for (i = 0; i < 4; i++)
01553       if (fR[i]->GetState() == kButtonDown) {
01554          icontype = mb_icon[i];
01555          break;
01556       }
01557 
01558    // Since the message dialog box is created, we disable the
01559    // signal/slot communication mechanism, in order to ensure we
01560    // can't close the fMain window while the message box is open.
01561    fMain->Disconnect("CloseWindow()");
01562    fMain->Connect("CloseWindow()", "TestMsgBox", this, "TryToClose()");
01563    new TGMsgBox(gClient->GetRoot(), fMain,
01564                 fTbtitle->GetString(), fTbmsg->GetString(),
01565                 icontype, buttons, &retval);
01566    fMain->Disconnect("CloseWindow()");
01567    fMain->Connect("CloseWindow()", "TestMsgBox", this, "CloseWindow()");
01568 
01569 }
01570 
01571 void TestMsgBox::TryToClose()
01572 {
01573    // The user try to close the main window,
01574    //  while a message dialog box is still open.
01575    printf("Can't close the window '%s' : a message box is still open\n", fMain->GetWindowName());
01576 }
01577 
01578 void TestMsgBox::DoRadio()
01579 {
01580    // Handle radio buttons.
01581 
01582    TGButton *btn = (TGButton *) gTQSender;
01583    Int_t id = btn->WidgetId();
01584 
01585    if (id >= 21 && id <= 24) {
01586       for (int i = 0; i < 4; i++)
01587          if (fR[i]->WidgetId() != id)
01588             fR[i]->SetState(kButtonUp);
01589    }
01590 }
01591 
01592 
01593 TestSliders::TestSliders(const TGWindow *p, const TGWindow *main,
01594                          UInt_t w, UInt_t h)
01595 {
01596    // Dialog used to test the different supported sliders.
01597 
01598    fMain = new TGTransientFrame(p, main, w, h);
01599    fMain->Connect("CloseWindow()", "TestSliders", this, "CloseWindow()");
01600    fMain->DontCallClose(); // to avoid double deletions.
01601 
01602    // use hierarchical cleaning
01603    fMain->SetCleanup(kDeepCleanup);
01604 
01605    fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
01606 
01607    fVframe1 = new TGVerticalFrame(fMain, 0, 0, 0);
01608 
01609    fTeh1 = new TGTextEntry(fVframe1, fTbh1 = new TGTextBuffer(10), HId1);
01610    fTev1 = new TGTextEntry(fVframe1, fTbv1 = new TGTextBuffer(10), VId1);
01611    fTbh1->AddText(0, "0");
01612    fTbv1->AddText(0, "0");
01613 
01614    fTeh1->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
01615    fTev1->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
01616 
01617    fHslider1 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, HSId1);
01618    fHslider1->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
01619    fHslider1->SetRange(0,50);
01620 
01621    fVslider1 = new TGVSlider(fVframe1, 100, kSlider2 | kScaleBoth, VSId1);
01622    fVslider1->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
01623    fVslider1->SetRange(0,8);
01624 
01625    fVframe1->Resize(100, 100);
01626 
01627    fVframe2 = new TGVerticalFrame(fMain, 0, 0, 0);
01628    fTeh2 = new TGTextEntry(fVframe2, fTbh2 = new TGTextBuffer(10), HId2);
01629    fTev2 = new TGTextEntry(fVframe2, fTbv2 = new TGTextBuffer(10), VId2);
01630    fTbh2->AddText(0, "0");
01631    fTbv2->AddText(0, "0");
01632 
01633    fTeh2->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
01634    fTev2->Connect("TextChanged(char*)", "TestSliders", this, "DoText(char*)");
01635 
01636    fHslider2 = new TGHSlider(fVframe2, 150, kSlider2 | kScaleBoth, HSId2);
01637    fHslider2->Connect("PositionChanged(Int_t)", "TestSliders", this, "DoSlider(Int_t)");
01638    fHslider2->SetRange(0,3);
01639 
01640    fVslider2 = new TGDoubleVSlider(fVframe2, 100, kDoubleScaleBoth, VSId2);
01641 
01642    fVslider2->SetRange(-10,10);
01643    fVslider2->Connect("PositionChanged()", "TestSliders", this, "DoSlider()");
01644    fVframe2->Resize(100, 100);
01645 
01646    //--- layout for buttons: top align, equally expand horizontally
01647    fBly = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 3, 0);
01648 
01649    //--- layout for the frame: place at bottom, right aligned
01650    fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsRight, 20, 10, 15, 0);
01651 
01652    fVframe1->AddFrame(fHslider1, fBly);
01653    fVframe1->AddFrame(fVslider1, fBly);
01654    fVframe1->AddFrame(fTeh1, fBly);
01655    fVframe1->AddFrame(fTev1, fBly);
01656 
01657    fVframe2->AddFrame(fHslider2, fBly);
01658    fVframe2->AddFrame(fVslider2, fBly);
01659    fVframe2->AddFrame(fTeh2, fBly);
01660    fVframe2->AddFrame(fTev2, fBly);
01661 
01662    fMain->AddFrame(fVframe2, fBfly1);
01663    fMain->AddFrame(fVframe1, fBfly1);
01664 
01665    fMain->SetWindowName("Slider Test");
01666    TGDimension size = fMain->GetDefaultSize();
01667    fMain->Resize(size);
01668 
01669    fMain->SetWMSize(size.fWidth, size.fHeight);
01670    fMain->SetWMSizeHints(size.fWidth, size.fHeight, size.fWidth, size.fHeight, 0, 0);
01671    fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
01672                                      kMWMDecorMinimize | kMWMDecorMenu,
01673                       kMWMFuncAll |  kMWMFuncResize    | kMWMFuncMaximize |
01674                                      kMWMFuncMinimize,
01675                       kMWMInputModeless);
01676 
01677    // position relative to the parent's window
01678    fMain->CenterOnParent();
01679 
01680    fMain->MapSubwindows();
01681    fMain->MapWindow();
01682 
01683    gClient->WaitFor(fMain);
01684 }
01685 
01686 TestSliders::~TestSliders()
01687 {
01688    // Delete dialog.
01689 
01690    fMain->DeleteWindow();  // deletes fMain
01691 }
01692 
01693 void TestSliders::CloseWindow()
01694 {
01695    // Called when window is closed via the window manager.
01696 
01697    delete this;
01698 }
01699 
01700 void TestSliders::DoText(const char * /*text*/)
01701 {
01702    // Handle text entry widgets.
01703 
01704    TGTextEntry *te = (TGTextEntry *) gTQSender;
01705    Int_t id = te->WidgetId();
01706 
01707    switch (id) {
01708       case HId1:
01709          fHslider1->SetPosition(atoi(fTbh1->GetString()));
01710          break;
01711       case VId1:
01712          fVslider1->SetPosition(atoi(fTbv1->GetString()));
01713          break;
01714       case HId2:
01715          fHslider2->SetPosition(atoi(fTbh2->GetString()));
01716          break;
01717       case VId2:
01718          fVslider2->SetPosition(atoi(fTbv2->GetString()),
01719                                      atoi(fTbv2->GetString())+2);
01720          break;
01721       default:
01722          break;
01723    }
01724 }
01725 
01726 void TestSliders::DoSlider(Int_t pos)
01727 {
01728    // Handle slider widgets.
01729 
01730    Int_t id;
01731    TGFrame *frm = (TGFrame *) gTQSender;
01732    if (frm->IsA()->InheritsFrom(TGSlider::Class())) {
01733       TGSlider *sl = (TGSlider*) frm;
01734       id = sl->WidgetId();
01735    } else {
01736       TGDoubleSlider *sd = (TGDoubleSlider *) frm;
01737       id = sd->WidgetId();
01738    }
01739 
01740    char buf[32];
01741    sprintf(buf, "%d", pos);
01742 
01743 #ifdef CINT_FIXED
01744    switch (id) {
01745    case HSId1:
01746 #else
01747    if (id == HSId1) {
01748 #endif
01749       fTbh1->Clear();
01750       fTbh1->AddText(0, buf);
01751       // Re-align the cursor with the characters.
01752       fTeh1->SetCursorPosition(fTeh1->GetCursorPosition());
01753       fTeh1->Deselect();
01754       gClient->NeedRedraw(fTeh1);
01755 #ifdef CINT_FIXED
01756       break;
01757    case VSId1:
01758 #else
01759    }
01760    else if (id == VSId1) {
01761 #endif
01762       fTbv1->Clear();
01763       fTbv1->AddText(0, buf);
01764       fTev1->SetCursorPosition(fTev1->GetCursorPosition());
01765       fTev1->Deselect();
01766       gClient->NeedRedraw(fTev1);
01767 #ifdef CINT_FIXED
01768       break;
01769    case HSId2:
01770 #else
01771    }
01772    else if (id == HSId2) {
01773 #endif
01774       fTbh2->Clear();
01775       fTbh2->AddText(0, buf);
01776       fTeh2->SetCursorPosition(fTeh2->GetCursorPosition());
01777       fTeh2->Deselect();
01778       gClient->NeedRedraw(fTeh2);
01779 #ifdef CINT_FIXED
01780       break;
01781    case VSId2:
01782 #else
01783    }
01784    else if (id == VSId2) {
01785 #endif
01786       sprintf(buf, "%f", fVslider2->GetMinPosition());
01787       fTbv2->Clear();
01788       fTbv2->AddText(0, buf);
01789       fTev2->SetCursorPosition(fTev2->GetCursorPosition());
01790       fTev2->Deselect();
01791       gClient->NeedRedraw(fTev2);
01792 #ifdef CINT_FIXED
01793       break;
01794    default:
01795       break;
01796 #endif
01797    }
01798 }
01799 
01800 
01801 TestShutter::TestShutter(const TGWindow *p, const TGWindow *main,
01802                          UInt_t w, UInt_t h)
01803 {
01804    // Create transient frame containing a shutter widget.
01805 
01806    fMain = new TGTransientFrame(p, main, w, h);
01807    fMain->Connect("CloseWindow()", "TestShutter", this, "CloseWindow()");
01808    fMain->DontCallClose(); // to avoid double deletions.
01809 
01810    // use hierarchical cleaning
01811    fMain->SetCleanup(kDeepCleanup);
01812 
01813    fDefaultPic = gClient->GetPicture("folder_s.xpm");
01814    fShutter = new TGShutter(fMain, kSunkenFrame);
01815 
01816    AddShutterItem("Histograms", histo_data);
01817    AddShutterItem("Functions", function_data);
01818    AddShutterItem("Trees", tree_data);
01819 
01820    fLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
01821    fMain->AddFrame(fShutter, fLayout);
01822 
01823    fMain->MapSubwindows();
01824    fMain->Resize(80, 300);
01825 
01826    // position relative to the parent's window
01827    fMain->CenterOnParent();
01828 
01829    fMain->SetWindowName("Shutter Test");
01830 
01831    fMain->MapWindow();
01832    //gClient->WaitFor(fMain);
01833 }
01834 
01835 void TestShutter::AddShutterItem(const char *name, shutterData_t *data)
01836 {
01837    TGShutterItem    *item;
01838    TGCompositeFrame *container;
01839    TGButton         *button;
01840    const TGPicture  *buttonpic;
01841    static int id = 5001;
01842 
01843    TGLayoutHints *l = new TGLayoutHints(kLHintsTop | kLHintsCenterX,
01844                                         5, 5, 5, 0);
01845 
01846    item = new TGShutterItem(fShutter, new TGHotString(name), id++);
01847    container = (TGCompositeFrame *) item->GetContainer();
01848 
01849    for (int i=0; data[i].pixmap_name != 0; i++) {
01850       buttonpic = gClient->GetPicture(data[i].pixmap_name);
01851       if (!buttonpic) {
01852          printf("<TestShutter::AddShutterItem>: missing pixmap \"%s\", using default",
01853                 data[i].pixmap_name);
01854          buttonpic = fDefaultPic;
01855       }
01856 
01857       button = new TGPictureButton(container, buttonpic, data[i].id);
01858 
01859       container->AddFrame(button, l);
01860       button->Connect("Clicked()", "TestShutter", this, "HandleButtons()");
01861       button->SetToolTipText(data[i].tip_text);
01862       data[i].button = button;
01863    }
01864 
01865    fShutter->AddItem(item);
01866 }
01867 
01868 TestShutter::~TestShutter()
01869 {
01870    // dtor
01871 
01872    gClient->FreePicture(fDefaultPic);
01873    fMain->DeleteWindow();  // deletes fMain
01874 }
01875 
01876 void TestShutter::CloseWindow()
01877 {
01878    delete this;
01879 }
01880 
01881 void TestShutter::HandleButtons()
01882 {
01883    TGButton *btn = (TGButton *) gTQSender;
01884    printf("Shutter button %d\n", btn->WidgetId());
01885 }
01886 
01887 
01888 TestDirList::TestDirList(const TGWindow *p, const TGWindow *main,
01889                          UInt_t w, UInt_t h)
01890 {
01891    // Create transient frame containing a dirlist widget.
01892 
01893    fMain = new TGTransientFrame(p, main, w, h);
01894    fMain->Connect("CloseWindow()", "TestDirList", this, "CloseWindow()");
01895    fMain->DontCallClose(); // to avoid double deletions.
01896 
01897    fIcon = gClient->GetPicture("rootdb_t.xpm");
01898    TGLayoutHints *lo;
01899 
01900    // use hierarchical cleaning
01901    fMain->SetCleanup(kDeepCleanup);
01902 
01903    TGCanvas* canvas = new TGCanvas(fMain, 500, 300);
01904    fContents = new TGListTree(canvas, kHorizontalFrame);
01905    lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kLHintsBottom);
01906    fMain->AddFrame(canvas,lo);
01907    fContents->Connect("DoubleClicked(TGListTreeItem*,Int_t)","TestDirList",this,
01908                       "OnDoubleClick(TGListTreeItem*,Int_t)");
01909    fContents->Connect("Clicked(TGListTreeItem*,Int_t)","TestDirList",this,
01910                       "OnDoubleClick(TGListTreeItem*,Int_t)");
01911 #ifdef G__WIN32
01912    fContents->AddItem(0,"c:\\");  // browse the upper directory
01913 #else
01914    fContents->AddItem(0,"/");  // browse the upper directory
01915 #endif
01916 
01917    // position relative to the parent's window
01918    fMain->CenterOnParent();
01919 
01920    fMain->SetWindowName("List Dir Test");
01921 
01922    fMain->MapSubwindows();
01923    fMain->Resize();
01924    fMain->MapWindow();
01925 }
01926 
01927 TestDirList::~TestDirList()
01928 {
01929    // Cleanup.
01930 
01931    gClient->FreePicture(fIcon);
01932    delete fContents;
01933    fMain->DeleteWindow();  // delete fMain
01934 }
01935 
01936 void TestDirList::CloseWindow()
01937 {
01938    delete this;
01939 }
01940 
01941 TString TestDirList::DirName(TGListTreeItem* item)
01942 {
01943    // Returns an absolute path.
01944 
01945    TGListTreeItem* parent;
01946    TString dirname = item->GetText();
01947 
01948    while ((parent=item->GetParent())) {
01949       dirname = gSystem->ConcatFileName(parent->GetText(),dirname);
01950       item = parent;
01951    }
01952 
01953    return dirname;
01954 }
01955 
01956 void TestDirList::OnDoubleClick(TGListTreeItem* item, Int_t btn)
01957 {
01958    // Show contents of directory.
01959 
01960    if ((btn!=kButton1) || !item || (Bool_t)item->GetUserData()) return;
01961 
01962    // use UserData to indicate that item was already browsed
01963    item->SetUserData((void*)1);
01964 
01965    TSystemDirectory dir(item->GetText(),DirName(item));
01966 
01967    TList *files = dir.GetListOfFiles();
01968 
01969    if (files) {
01970       TIter next(files);
01971       TSystemFile *file;
01972       TString fname;
01973 
01974       while ((file=(TSystemFile*)next())) {
01975          fname = file->GetName();
01976          if (file->IsDirectory()) {
01977             if ((fname!="..") && (fname!=".")) { // skip it
01978                fContents->AddItem(item,fname);
01979             }
01980          } else if (fname.EndsWith(".root")) {   // add root files
01981             fContents->AddItem(item,fname,fIcon,fIcon);
01982          }
01983       }
01984       delete files;
01985    }
01986 }
01987 
01988 
01989 TestFileList::TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h)
01990 {
01991    // Create transient frame containing a filelist widget.
01992 
01993    TGLayoutHints *lo;
01994 
01995    fMain = new TGTransientFrame(p, main, w, h);
01996    fMain->Connect("CloseWindow()", "TestDirList", this, "CloseWindow()");
01997    fMain->DontCallClose(); // to avoid double deletions.
01998 
01999    // use hierarchical cleaning
02000    fMain->SetCleanup(kDeepCleanup);
02001 
02002    TGMenuBar* mb = new TGMenuBar(fMain);
02003    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
02004    fMain->AddFrame(mb, lo);
02005 
02006    fMenu = mb->AddPopup("&View");
02007    fMenu->AddEntry("Lar&ge Icons",kLVLargeIcons);
02008    fMenu->AddEntry("S&mall Icons",kLVSmallIcons);
02009    fMenu->AddEntry("&List",       kLVList);
02010    fMenu->AddEntry("&Details",    kLVDetails);
02011    fMenu->AddSeparator();
02012    fMenu->AddEntry("&Close",      10);
02013    fMenu->Connect("Activated(Int_t)","TestFileList",this,"DoMenu(Int_t)");
02014 
02015    TGListView* lv = new TGListView(fMain, w, h);
02016    lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
02017    fMain->AddFrame(lv,lo);
02018 
02019    Pixel_t white;
02020    gClient->GetColorByName("white", white);
02021    fContents = new TGFileContainer(lv, kSunkenFrame,white);
02022    fContents->Connect("DoubleClicked(TGFrame*,Int_t)", "TestFileList", this,
02023                       "OnDoubleClick(TGLVEntry*,Int_t)");
02024 
02025    // position relative to the parent's window
02026    fMain->CenterOnParent();
02027 
02028    fMain->SetWindowName("File List Test");
02029    fMain->MapSubwindows();
02030    fMain->MapWindow();
02031    fContents->SetDefaultHeaders();
02032    fContents->DisplayDirectory();
02033    fContents->AddFile("..");        // up level directory
02034    fContents->Resize();
02035    fContents->StopRefreshTimer();   // stop refreshing
02036    fMain->Resize();
02037 }
02038 
02039 TestFileList::~TestFileList()
02040 {
02041    // Cleanup.
02042 
02043    delete fContents;
02044    fMain->DeleteWindow();  // deletes fMain
02045 }
02046 
02047 void TestFileList::DoMenu(Int_t mode)
02048 {
02049    // Switch view mode.
02050 
02051    if (mode<10) {
02052       fContents->SetViewMode((EListViewMode)mode);
02053    } else {
02054       delete this;
02055    }
02056 }
02057 
02058 void TestFileList::DisplayFile(const TString &fname)
02059 {
02060    // Display content of ROOT file.
02061 
02062    TFile file(fname);
02063    fContents->RemoveAll();
02064    fContents->AddFile(gSystem->WorkingDirectory());
02065    fContents->SetPagePosition(0,0);
02066    fContents->SetColHeaders("Name","Title");
02067 
02068    TIter next(file.GetListOfKeys());
02069    TKey *key;
02070 
02071    while ((key=(TKey*)next())) {
02072       TString cname = key->GetClassName();
02073       TString name = key->GetName();
02074       TGLVEntry *entry = new TGLVEntry(fContents,name,cname);
02075       entry->SetSubnames(key->GetTitle());
02076       fContents->AddItem(entry);
02077 
02078       // user data is a filename
02079       entry->SetUserData((void*)StrDup(fname));
02080    }
02081    fMain->Resize();
02082 }
02083 
02084 void TestFileList::DisplayDirectory(const TString &fname)
02085 {
02086    // Display content of directory.
02087 
02088    fContents->SetDefaultHeaders();
02089    gSystem->ChangeDirectory(fname);
02090    fContents->ChangeDirectory(fname);
02091    fContents->DisplayDirectory();
02092    fContents->AddFile("..");  // up level directory
02093    fMain->Resize();
02094 }
02095 
02096 void TestFileList::DisplayObject(const TString& fname,const TString& name)
02097 {
02098    // Browse object located in file.
02099 
02100    TDirectory *sav = gDirectory;
02101 
02102    static TFile *file = 0;
02103    if (file) delete file;     // close
02104    file = new TFile(fname);   // reopen
02105 
02106    TObject* obj = file->Get(name);
02107    if (obj) {
02108       if (!obj->IsFolder()) {
02109          obj->Browse(0);
02110       } else obj->Print();
02111    }
02112    gDirectory = sav;
02113 }
02114 
02115 void TestFileList::OnDoubleClick(TGLVEntry *f, Int_t btn)
02116 {
02117    // Handle double click.
02118 
02119    if (btn != kButton1) return;
02120 
02121    // set kWatch cursor
02122    ULong_t cur = gVirtualX->CreateCursor(kWatch);
02123    gVirtualX->SetCursor(fContents->GetId(), cur);
02124 
02125    TString name(f->GetTitle());
02126    const char* fname = (const char*)f->GetUserData();
02127 
02128    if (fname) {
02129       DisplayObject(fname, name);
02130    } else if (name.EndsWith(".root")) {
02131       DisplayFile(name);
02132    } else {
02133       DisplayDirectory(name);
02134    }
02135    // set kPointer cursor
02136    cur = gVirtualX->CreateCursor(kPointer);
02137    gVirtualX->SetCursor(fContents->GetId(), cur);
02138 }
02139 
02140 void TestFileList::CloseWindow()
02141 {
02142    delete this;
02143 }
02144 
02145 TestProgress::TestProgress(const TGWindow *p, const TGWindow *main,
02146                            UInt_t w, UInt_t h)
02147 {
02148    // Dialog used to test the different supported progress bars.
02149 
02150    fClose = kTRUE;
02151 
02152    fMain = new TGTransientFrame(p, main, w, h);
02153    fMain->Connect("CloseWindow()", "TestProgress", this, "DoClose()");
02154    fMain->DontCallClose();
02155 
02156    // use hierarchical cleaning
02157    fMain->SetCleanup(kDeepCleanup);
02158 
02159    fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
02160 
02161    fHframe1 = new TGHorizontalFrame(fMain, 0, 0, 0);
02162 
02163    fVProg1 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
02164    fVProg1->SetBarColor("purple");
02165    fVProg2 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
02166    fVProg2->SetFillType(TGProgressBar::kBlockFill);
02167    fVProg2->SetBarColor("green");
02168 
02169    fHframe1->Resize(300, 300);
02170 
02171    fVframe1 = new TGVerticalFrame(fMain, 0, 0, 0);
02172 
02173    fHProg1 = new TGHProgressBar(fVframe1, 300);
02174    fHProg1->ShowPosition();
02175    fHProg2 = new TGHProgressBar(fVframe1, TGProgressBar::kFancy, 300);
02176    fHProg2->SetBarColor("lightblue");
02177    fHProg2->ShowPosition(kTRUE, kFALSE, "%.0f events");
02178    fHProg3 = new TGHProgressBar(fVframe1, TGProgressBar::kStandard, 300);
02179    fHProg3->SetFillType(TGProgressBar::kBlockFill);
02180 
02181    fGO = new TGTextButton(fVframe1, "Go", 10);
02182    fGO->Connect("Clicked()", "TestProgress", this, "DoGo()");
02183 
02184    fVframe1->Resize(300, 300);
02185 
02186    fHint1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 10, 5, 5);
02187    fHint2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5,  5, 10);
02188    fHint3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 50, 50, 0);
02189    fHint4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0);
02190    fHint5 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0);
02191 
02192    fHframe1->AddFrame(fVProg1, fHint1);
02193    fHframe1->AddFrame(fVProg2, fHint1);
02194 
02195    fVframe1->AddFrame(fHProg1, fHint2);
02196    fVframe1->AddFrame(fHProg2, fHint2);
02197    fVframe1->AddFrame(fHProg3, fHint2);
02198    fVframe1->AddFrame(fGO,     fHint3);
02199 
02200    fMain->AddFrame(fHframe1, fHint4);
02201    fMain->AddFrame(fVframe1, fHint5);
02202 
02203    fMain->SetWindowName("Progress Test");
02204    TGDimension size = fMain->GetDefaultSize();
02205    fMain->Resize(size);
02206 
02207    // position relative to the parent's window
02208    fMain->CenterOnParent();
02209 
02210    fMain->MapSubwindows();
02211    fMain->MapWindow();
02212 
02213    gClient->WaitFor(fMain);
02214 }
02215 
02216 TestProgress::~TestProgress()
02217 {
02218    // Delete dialog.
02219 
02220    fMain->DeleteWindow();   // deletes fMain
02221 }
02222 
02223 void TestProgress::CloseWindow()
02224 {
02225    // Called when window is closed via the window manager.
02226 
02227    delete this;
02228 }
02229 
02230 void TestProgress::DoClose()
02231 {
02232    // If fClose is false we are still in event processing loop in DoGo().
02233    // In that case, set the close flag true and use a timer to call
02234    // CloseWindow(). This gives us change to get out of the DoGo() loop.
02235    // Note: calling SendCloseMessage() will not work since that will
02236    // bring us back here (CloseWindow() signal is connected to this method)
02237    // with the fClose flag true, which will cause window deletion while
02238    // still being in the event processing loop (since SendCloseMessage()
02239    // is directly processed in ProcessEvents() without exiting DoGo()).
02240 
02241    if (fClose)
02242       CloseWindow();
02243    else {
02244       fClose = kTRUE;
02245       TTimer::SingleShot(150, "TestProgress", this, "CloseWindow()");
02246    }
02247 }
02248 
02249 void TestProgress::DoGo()
02250 {
02251    // Handle Go button.
02252 
02253    fClose = kFALSE;
02254    fVProg1->Reset(); fVProg2->Reset();
02255    fHProg1->Reset(); fHProg2->Reset(); fHProg3->Reset();
02256    fVProg2->SetBarColor("green");
02257    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
02258    int inc1 = 4, inc2 = 3, inc3 = 2, inc4 = 1;
02259    while (cnt1 < 100 || cnt2 < 100 || cnt3 < 100 || cnt4 <100) {
02260       if (cnt1 < 100) {
02261          cnt1 += inc1;
02262          fVProg1->Increment(inc1);
02263       }
02264       if (cnt2 < 100) {
02265          cnt2 += inc2;
02266          fVProg2->Increment(inc2);
02267          if (cnt2 > 75)
02268             fVProg2->SetBarColor("red");
02269       }
02270       if (cnt3 < 100) {
02271          cnt3 += inc3;
02272          fHProg1->Increment(inc3);
02273       }
02274       if (cnt4 < 100) {
02275          cnt4 += inc4;
02276          fHProg2->Increment(inc4);
02277          fHProg3->Increment(inc4);
02278       }
02279       gSystem->Sleep(100);
02280       gSystem->ProcessEvents();
02281       // if user closed window return
02282       if (fClose) return;
02283    }
02284    fClose = kTRUE;
02285 }
02286 
02287 
02288 // TGNumberEntry widget test dialog
02289 //const char *const EntryTestDlg::numlabel[] = {
02290 const char *numlabel[] = {
02291    "Integer",
02292    "One digit real",
02293    "Two digit real",
02294    "Three digit real",
02295    "Four digit real",
02296    "Real",
02297    "Degree.min.sec",
02298    "Min:sec",
02299    "Hour:min",
02300    "Hour:min:sec",
02301    "Day/month/year",
02302    "Month/day/year",
02303    "Hex"
02304 };
02305 
02306 //const Double_t EntryTestDlg::numinit[] = {
02307 const Double_t numinit[] = {
02308    12345, 1.0, 1.00, 1.000, 1.0000, 1.2E-12,
02309    90 * 3600, 120 * 60, 12 * 60, 12 * 3600 + 15 * 60,
02310    19991121, 19991121, (Double_t) 0xDEADFACEU
02311 };
02312 
02313 EntryTestDlg::EntryTestDlg(const TGWindow *p, const TGWindow *main)
02314 {
02315    // build widgets
02316    fMain = new TGTransientFrame(p, main, 10, 10, kHorizontalFrame);
02317    fMain->Connect("CloseWindow()", "EntryTestDlg", this, "CloseWindow()");
02318    fMain->DontCallClose(); // to avoid double deletions.
02319 
02320    // use hierarchical cleaning
02321    fMain->SetCleanup(kDeepCleanup);
02322 
02323    TGGC myGC = *gClient->GetResourcePool()->GetFrameGC();
02324    TGFont *myfont = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
02325    if (myfont) myGC.SetFont(myfont->GetFontHandle());
02326 
02327    fF1 = new TGVerticalFrame(fMain, 200, 300);
02328    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
02329    fMain->AddFrame(fF1, fL1);
02330    fL2 = new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2);
02331    for (int i = 0; i < 13; i++) {
02332       fF[i] = new TGHorizontalFrame(fF1, 200, 30);
02333       fF1->AddFrame(fF[i], fL2);
02334       fNumericEntries[i] = new TGNumberEntry(fF[i], numinit[i], 12, i + 20,
02335                                              (TGNumberFormat::EStyle) i);
02336       fF[i]->AddFrame(fNumericEntries[i], fL2);
02337       fLabel[i] = new TGLabel(fF[i], numlabel[i], myGC(), myfont->GetFontStruct());
02338       fF[i]->AddFrame(fLabel[i], fL2);
02339    }
02340    fF2 = new TGVerticalFrame(fMain, 200, 500);
02341    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2);
02342    fMain->AddFrame(fF2, fL3);
02343    fLowerLimit = new TGCheckButton(fF2, "lower limit:", 4);
02344    fF2->AddFrame(fLowerLimit, fL3);
02345    fLimits[0] = new TGNumberEntry(fF2, 0, 12, 10);
02346    fLimits[0]->SetLogStep(kFALSE);
02347    fF2->AddFrame(fLimits[0], fL3);
02348    fUpperLimit = new TGCheckButton(fF2, "upper limit:", 5);
02349    fF2->AddFrame(fUpperLimit, fL3);
02350    fLimits[1] = new TGNumberEntry(fF2, 0, 12, 11);
02351    fLimits[1]->SetLogStep(kFALSE);
02352    fF2->AddFrame(fLimits[1], fL3);
02353    fPositive = new TGCheckButton(fF2, "Positive", 6);
02354    fF2->AddFrame(fPositive, fL3);
02355    fNonNegative = new TGCheckButton(fF2, "Non negative", 7);
02356    fF2->AddFrame(fNonNegative, fL3);
02357    fSetButton = new TGTextButton(fF2, " Set ", 2);
02358    fSetButton->Connect("Clicked()", "EntryTestDlg", this, "SetLimits()");
02359    fF2->AddFrame(fSetButton, fL3);
02360    fExitButton = new TGTextButton(fF2, " Close ", 1);
02361    fExitButton->Connect("Clicked()", "EntryTestDlg", this, "DoOK()");
02362    fF2->AddFrame(fExitButton, fL3);
02363 
02364    // set dialog box title
02365    fMain->SetWindowName("Number Entry Test");
02366    fMain->SetIconName("Number Entry Test");
02367    fMain->SetClassHints("NumberEntryDlg", "NumberEntryDlg");
02368    // resize & move to center
02369    fMain->MapSubwindows();
02370    UInt_t width = fMain->GetDefaultWidth();
02371    UInt_t height = fMain->GetDefaultHeight();
02372    fMain->Resize(width, height);
02373    fMain->CenterOnParent();
02374    // make the message box non-resizable
02375    fMain->SetWMSize(width, height);
02376    fMain->SetWMSizeHints(width, height, width, height, 0, 0);
02377    fMain->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
02378                       kMWMDecorMinimize | kMWMDecorMenu,
02379                       kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
02380                       kMWMFuncMinimize, kMWMInputModeless);
02381 
02382    fMain->MapWindow();
02383    gClient->WaitFor(fMain);
02384 }
02385 
02386 EntryTestDlg::~EntryTestDlg()
02387 {
02388    // dtor
02389 
02390    fMain->DeleteWindow();
02391 }
02392 
02393 void EntryTestDlg::CloseWindow()
02394 {
02395    delete this;
02396 }
02397 
02398 void EntryTestDlg::DoOK()
02399 {
02400    // Handle ok button.
02401 
02402    fMain->SendCloseMessage();
02403 }
02404 
02405 void EntryTestDlg::SetLimits()
02406 {
02407    Double_t min = fLimits[0]->GetNumber();
02408    Bool_t low = (fLowerLimit->GetState() == kButtonDown);
02409    Double_t max = fLimits[1]->GetNumber();
02410    Bool_t high = (fUpperLimit->GetState() == kButtonDown);
02411    TGNumberFormat::ELimit lim;
02412    if (low && high) {
02413       lim = TGNumberFormat::kNELLimitMinMax;
02414    } else if (low) {
02415       lim = TGNumberFormat::kNELLimitMin;
02416    } else if (high) {
02417       lim = TGNumberFormat::kNELLimitMax;
02418    } else {
02419       lim = TGNumberFormat::kNELNoLimits;
02420    }
02421    Bool_t pos = (fPositive->GetState() == kButtonDown);
02422    Bool_t nneg = (fNonNegative->GetState() == kButtonDown);
02423    TGNumberFormat::EAttribute attr;
02424    if (pos) {
02425       attr = TGNumberFormat::kNEAPositive;
02426    } else if (nneg) {
02427       attr = TGNumberFormat::kNEANonNegative;
02428    } else {
02429       attr = TGNumberFormat::kNEAAnyNumber;
02430    }
02431    for (int i = 0; i < 13; i++) {
02432       fNumericEntries[i]->SetFormat(fNumericEntries[i]->GetNumStyle(), attr);
02433       fNumericEntries[i]->SetLimits(lim, min, max);
02434    }
02435 }
02436 
02437 
02438 Editor::Editor(const TGWindow *main, UInt_t w, UInt_t h)
02439 {
02440    // Create an editor in a dialog.
02441 
02442    fMain = new TGTransientFrame(gClient->GetRoot(), main, w, h);
02443    fMain->Connect("CloseWindow()", "Editor", this, "CloseWindow()");
02444    fMain->DontCallClose(); // to avoid double deletions.
02445 
02446    // use hierarchical cleaning
02447    fMain->SetCleanup(kDeepCleanup);
02448 
02449    fEdit = new TGTextEdit(fMain, w, h, kSunkenFrame | kDoubleBorder);
02450    fL1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3);
02451    fMain->AddFrame(fEdit, fL1);
02452    fEdit->Connect("Opened()", "Editor", this, "DoOpen()");
02453    fEdit->Connect("Saved()",  "Editor", this, "DoSave()");
02454    fEdit->Connect("Closed()", "Editor", this, "DoClose()");
02455 
02456    // set selected text colors
02457    Pixel_t pxl;
02458    gClient->GetColorByName("#ccccff", pxl);
02459    fEdit->SetSelectBack(pxl);
02460    fEdit->SetSelectFore(TGFrame::GetBlackPixel());
02461 
02462    fOK = new TGTextButton(fMain, "  &OK  ");
02463    fOK->Connect("Clicked()", "Editor", this, "DoOK()");
02464    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
02465    fMain->AddFrame(fOK, fL2);
02466 
02467    SetTitle();
02468 
02469    fMain->MapSubwindows();
02470 
02471    fMain->Resize();
02472 
02473    // editor covers right half of parent window
02474    fMain->CenterOnParent(kTRUE, TGTransientFrame::kRight);
02475 }
02476 
02477 Editor::~Editor()
02478 {
02479    // Delete editor dialog.
02480 
02481    fMain->DeleteWindow();  // deletes fMain
02482 }
02483 
02484 void Editor::SetTitle()
02485 {
02486    // Set title in editor window.
02487 
02488    TGText *txt = GetEditor()->GetText();
02489    Bool_t untitled = !strlen(txt->GetFileName()) ? kTRUE : kFALSE;
02490 
02491    char title[256];
02492    if (untitled)
02493       sprintf(title, "ROOT Editor - Untitled");
02494    else
02495       sprintf(title, "ROOT Editor - %s", txt->GetFileName());
02496 
02497    fMain->SetWindowName(title);
02498    fMain->SetIconName(title);
02499 }
02500 
02501 void Editor::Popup()
02502 {
02503    // Show editor.
02504 
02505    fMain->MapWindow();
02506 }
02507 
02508 void Editor::LoadBuffer(const char *buffer)
02509 {
02510    // Load a text buffer in the editor.
02511 
02512    fEdit->LoadBuffer(buffer);
02513 }
02514 
02515 void Editor::LoadFile(const char *file)
02516 {
02517    // Load a file in the editor.
02518 
02519    fEdit->LoadFile(file);
02520 }
02521 
02522 void Editor::AddBuffer(const  char *buffer)
02523 {
02524    // Add text to the editor.
02525 
02526    TGText txt;
02527    txt.LoadBuffer(buffer);
02528    fEdit->AddText(&txt);
02529 }
02530 
02531 void Editor::CloseWindow()
02532 {
02533    // Called when closed via window manager action.
02534 
02535    delete this;
02536 }
02537 
02538 void Editor::DoOK()
02539 {
02540    // Handle ok button.
02541 
02542    CloseWindow();
02543 }
02544 
02545 void Editor::DoOpen()
02546 {
02547    SetTitle();
02548 }
02549 
02550 void Editor::DoSave()
02551 {
02552    SetTitle();
02553 }
02554 
02555 void Editor::DoClose()
02556 {
02557    // Handle close button.
02558 
02559    CloseWindow();
02560 }
02561 
02562 
02563 void guitest()
02564 {
02565    new TestMainFrame(gClient->GetRoot(), 400, 220);
02566 }
02567 
02568 //---- Main program ------------------------------------------------------------
02569 #ifdef STANDALONE
02570 int main(int argc, char **argv)
02571 {
02572    TApplication theApp("App", &argc, argv);
02573 
02574    if (gROOT->IsBatch()) {
02575       fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]);
02576       return 1;
02577    }
02578 
02579    guitest();
02580 
02581    theApp.Run();
02582 
02583    return 0;
02584 }
02585 #endif

Generated on Tue Jul 5 15:44:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1