guitest.cpp

Go to the documentation of this file.
00001 #include "guitest.h"
00002 
00003 
00004 
00005 EMsgBoxIcon mb_icon1[4] = { kMBIconStop, kMBIconQuestion,
00006                            kMBIconExclamation, kMBIconAsterisk };
00007 
00008 const char *filetypes1[] = { "All files",     "*",
00009                             "ROOT files",    "*.root",
00010                             "ROOT macros",   "*.C",
00011                             0,               0 };
00012 
00013 
00014 
00015 Int_t mb_button_id0[9] = { kMBYes, kMBNo, kMBOk, kMBApply,
00016                           kMBRetry, kMBIgnore, kMBCancel,
00017                           kMBClose, kMBDismiss };
00018 
00019 
00020 shutterData_t histo_data0[] = {
00021    { "h1_s.xpm",        "TH1",      1001,  0 },
00022    { "h2_s.xpm",        "TH2",      1002,  0 },
00023    { "h3_s.xpm",        "TH3",      1003,  0 },
00024    { "profile_s.xpm",   "TProfile", 1004,  0 },
00025    { 0,                 0,          0,     0 }
00026 };
00027 
00028 shutterData_t function_data0[] = {
00029    { "f1_s.xpm",        "TF1",      2001,  0 },
00030    { "f2_s.xpm",        "TF2",      2002,  0 },
00031    { 0,                 0,          0,     0 }
00032 };
00033 
00034 shutterData_t tree_data0[] = {
00035    { "ntuple_s.xpm",    "TNtuple",  3001,  0 },
00036    { "tree_s.xpm",      "TTree",    3002,  0 },
00037    { "chain_s.xpm",     "TChain",   3003,  0 },
00038    { 0,                 0,          0,     0 }
00039 };
00040 
00041 const char *editortxt1 =
00042 "This is the ROOT text edit widget TGTextEdit. It is not intended as\n"
00043 "a full developers editor, but it is relatively complete and can ideally\n"
00044 "be used to edit scripts or to present users editable config files, etc.\n\n"
00045 "The text edit widget supports standard emacs style ctrl-key navigation\n"
00046 "in addition to the arrow keys. By default the widget has under the right\n"
00047 "mouse button a popup menu giving access to several built-in functions.\n\n"
00048 "Cut, copy and paste between different editor windows and any other\n"
00049 "standard X11 text handling application is supported.\n\n"
00050 "Text can be selected with the mouse while holding the left button\n"
00051 "or with the arrow keys while holding the shift key pressed. Use the\n"
00052 "middle mouse button to paste text at the current mouse location.\n"
00053 "Mice with scroll-ball are properly supported.\n\n"
00054 "This are the currently defined key bindings:\n"
00055 "Left Arrow\n"
00056 "    Move the cursor one character leftwards.\n"
00057 "    Scroll when cursor is out of frame.\n"
00058 "Right Arrow\n"
00059 "    Move the cursor one character rightwards.\n"
00060 "    Scroll when cursor is out of frame.\n"
00061 "Backspace\n"
00062 "    Deletes the character on the left side of the text cursor and moves the\n"
00063 "    cursor one position to the left. If a text has been marked by the user\n"
00064 "    (e.g. by clicking and dragging) the cursor will be put at the beginning\n"
00065 "    of the marked text and the marked text will be removed.\n"
00066 "Home\n"
00067 "    Moves the text cursor to the left end of the line. If mark is TRUE text\n"
00068 "    will be marked towards the first position, if not any marked text will\n"
00069 "    be unmarked if the cursor is moved.\n"
00070 "End\n"
00071 "    Moves the text cursor to the right end of the line. If mark is TRUE text\n"
00072 "    will be marked towards the last position, if not any marked text will\n"
00073 "    be unmarked if the cursor is moved.\n"
00074 "Delete\n"
00075 "    Deletes the character on the right side of the text cursor. If a text\n"
00076 "    has been marked by the user (e.g. by clicking and dragging) the cursor\n"
00077 "    will be put at the beginning of the marked text and the marked text will\n"
00078 "    be removed.\n"
00079 "Shift - Left Arrow\n"
00080 "    Mark text one character leftwards.\n"
00081 "Shift - Right Arrow\n"
00082 "    Mark text one character rightwards.\n"
00083 "Control-A\n"
00084 "    Move the cursor to the beginning of the line.\n"
00085 "Control-B\n"
00086 "    Move the cursor one character leftwards.\n"
00087 "Control-C\n"
00088 "    Copy the marked text to the clipboard.\n"
00089 "Control-D\n"
00090 "    Delete the character to the right of the cursor.\n"
00091 "Control-E\n"
00092 "    Move the cursor to the end of the line.\n"
00093 "Control-F\n"
00094 "    Move the cursor one character rightwards.\n"
00095 "Control-H\n"
00096 "    Delete the character to the left of the cursor.\n"
00097 "Control-K\n"
00098 "    Delete marked text if any or delete all\n"
00099 "    characters to the right of the cursor.\n"
00100 "Control-U\n"
00101 "    Delete all characters on the line.\n"
00102 "Control-V\n"
00103 "    Paste the clipboard text into line edit.\n"
00104 "Control-X\n"
00105 "    Cut the marked text, copy to clipboard.\n"
00106 "Control-Y\n"
00107 "    Paste the clipboard text into line edit.\n"
00108 "\n"
00109 "All other keys with valid ASCII codes insert themselves into the line.";
00110 
00111 
00112 
00113 
00114 
00115 
00116 TileFrame::TileFrame(const TGWindow *p) :
00117    TGCompositeFrame(p, 10, 10, kHorizontalFrame, GetWhitePixel())
00118 {
00119    // Create tile view container. Used to show colormap.
00120 
00121    fCanvas = 0;
00122    SetLayoutManager(new TGTileLayout(this, 8));
00123 
00124    gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
00125                          kButtonPressMask | kButtonReleaseMask |
00126                          kPointerMotionMask, kNone, kNone);
00127 }
00128 
00129 Bool_t TileFrame::HandleButton(Event_t *event)
00130 {
00131    // Handle wheel mouse to scroll.
00132 
00133    Int_t page = 0;
00134    if (event->fCode == kButton4 || event->fCode == kButton5) {
00135    if (!fCanvas) return kTRUE;
00136    if (fCanvas->GetContainer()->GetHeight())
00137       page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
00138                            fCanvas->GetViewPort()->GetHeight()) /
00139                            fCanvas->GetContainer()->GetHeight());
00140    }
00141 
00142    if (event->fCode == kButton4) {
00143       //scroll up
00144       Int_t newpos = fCanvas->GetVsbPosition() - page;
00145       if (newpos < 0) newpos = 0;
00146       fCanvas->SetVsbPosition(newpos);
00147       return kTRUE;
00148    }
00149    if (event->fCode == kButton5) {
00150       // scroll down
00151       Int_t newpos = fCanvas->GetVsbPosition() + page;
00152       fCanvas->SetVsbPosition(newpos);
00153       return kTRUE;
00154    }
00155    return kTRUE;
00156 }
00157 
00158 
00159 TestMainFrame::TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
00160       : TGMainFrame(p, w, h)
00161 {
00162    // Create test main frame. A TGMainFrame is a top level window.
00163 
00164    // Create menubar and popup menus. The hint objects are used to place
00165    // and group the different menu widgets with respect to eachother.
00166    fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
00167                                       0, 0, 1, 1);
00168    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00169    fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00170 
00171    fMenuFile = new TGPopupMenu(fClient->GetRoot());
00172    fMenuFile->AddEntry("&Open...", M_FILE_OPEN);
00173    fMenuFile->AddEntry("&Save", M_FILE_SAVE);
00174    fMenuFile->AddEntry("S&ave as...", M_FILE_SAVEAS);
00175    fMenuFile->AddEntry("&Close", -1);
00176    fMenuFile->AddSeparator();
00177    fMenuFile->AddEntry("&Print", -1);
00178    fMenuFile->AddEntry("P&rint setup...", -1);
00179    fMenuFile->AddSeparator();
00180    fMenuFile->AddEntry("E&xit", M_FILE_EXIT);
00181 
00182    fMenuFile->DisableEntry(M_FILE_SAVEAS);
00183 
00184    fCascade2Menu = new TGPopupMenu(fClient->GetRoot());
00185    fCascade2Menu->AddEntry("ID = 2&1", M_CASCADE_1);
00186    fCascade2Menu->AddEntry("ID = 2&2", M_CASCADE_2);
00187    fCascade2Menu->AddEntry("ID = 2&3", M_CASCADE_3);
00188 
00189    fCascade1Menu = new TGPopupMenu(fClient->GetRoot());
00190    fCascade1Menu->AddEntry("ID = 4&1", 41);
00191    fCascade1Menu->AddEntry("ID = 4&2", 42);
00192    fCascade1Menu->AddEntry("ID = 4&3", 43);
00193    fCascade1Menu->AddSeparator();
00194    fCascade1Menu->AddPopup("Cascade&d 2", fCascade2Menu);
00195 
00196    fCascadeMenu = new TGPopupMenu(fClient->GetRoot());
00197    fCascadeMenu->AddEntry("ID = 5&1", 51);
00198    fCascadeMenu->AddEntry("ID = 5&2", 52);
00199    fCascadeMenu->AddEntry("ID = 5&3", 53);
00200    fCascadeMenu->AddSeparator();
00201    fCascadeMenu->AddPopup("&Cascaded 1", fCascade1Menu);
00202    fCascadeMenu->AddPopup("C&ascaded 2", fCascade2Menu);
00203 
00204    fMenuTest = new TGPopupMenu(fClient->GetRoot());
00205    fMenuTest->AddLabel("Test different features...");
00206    fMenuTest->AddSeparator();
00207    fMenuTest->AddEntry("&Dialog...", M_TEST_DLG);
00208    fMenuTest->AddEntry("&Message Box...", M_TEST_MSGBOX);
00209    fMenuTest->AddEntry("&Sliders...", M_TEST_SLIDER);
00210    fMenuTest->AddEntry("Sh&utter...", M_TEST_SHUTTER);
00211    fMenuTest->AddEntry("&Progress...", M_TEST_PROGRESS);
00212    fMenuTest->AddSeparator();
00213    fMenuTest->AddPopup("&Cascaded menus", fCascadeMenu);
00214 
00215    fMenuHelp = new TGPopupMenu(fClient->GetRoot());
00216    fMenuHelp->AddEntry("&Contents", M_HELP_CONTENTS);
00217    fMenuHelp->AddEntry("&Search...", M_HELP_SEARCH);
00218    fMenuHelp->AddSeparator();
00219    fMenuHelp->AddEntry("&About", M_HELP_ABOUT);
00220 
00221    // Menu button messages are handled by the main frame (i.e. "this")
00222    // ProcessMessage() method.
00223    fMenuFile->Associate(this);
00224    fMenuTest->Associate(this);
00225    fMenuHelp->Associate(this);
00226    fCascadeMenu->Associate(this);
00227    fCascade1Menu->Associate(this);
00228    fCascade2Menu->Associate(this);
00229 
00230    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
00231    fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
00232    fMenuBar->AddPopup("&Test", fMenuTest, fMenuBarItemLayout);
00233    fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
00234 
00235    AddFrame(fMenuBar, fMenuBarLayout);
00236 
00237    // Create TGCanvas and a canvas container which uses a tile layout manager
00238    fCanvasWindow = new TGCanvas(this, 400, 240);
00239    fContainer = new TileFrame(fCanvasWindow->GetViewPort());
00240    fContainer->SetCanvas(fCanvasWindow);
00241    fCanvasWindow->SetContainer(fContainer);
00242 
00243    // Fill canvas with 256 colored frames (notice that doing it this way
00244    // causes a memory leak when deleting the canvas (i.e. the TGFrame's and
00245    // TGLayoutHints are NOT adopted by the canvas).
00246    // Best is to create a TList and store all frame and layout pointers
00247    // in it. When deleting the canvas just delete contents of list.
00248    for (int i=0; i < 256; ++i)
00249       fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
00250                                           32, 32, 0, (i+1)&255),
00251                               new TGLayoutHints(kLHintsExpandY | kLHintsRight));
00252 
00253    AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
00254                                              0, 0, 2, 2));
00255 
00256    // Create status frame containing a button and a text entry widget
00257    fStatusFrame = new TGCompositeFrame(this, 60, 20, kHorizontalFrame |
00258                                                      kSunkenFrame);
00259 
00260    fTestButton = new TGTextButton(fStatusFrame, "&Open editor...", 150);
00261    fTestButton->Associate(this);
00262    fTestButton->SetToolTipText("Pops up editor");
00263    fStatusFrame->AddFrame(fTestButton, new TGLayoutHints(kLHintsTop |
00264                           kLHintsLeft, 2, 0, 2, 2));
00265    fTestText = new TGTextEntry(fStatusFrame, new TGTextBuffer(100));
00266    fTestText->SetToolTipText("This is a text entry widget");
00267    fTestText->Resize(300, fTestText->GetDefaultHeight());
00268    fStatusFrame->AddFrame(fTestText, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00269                                                        10, 2, 2, 2));
00270    AddFrame(fStatusFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
00271             0, 0, 1, 0));
00272 
00273    SetWindowName("GuiTest");
00274 
00275    MapSubwindows();
00276 
00277    // we need to use GetDefault...() to initialize the layout algorithm...
00278    Resize(GetDefaultSize());
00279    //Resize(400, 200);
00280 
00281    MapWindow();
00282 }
00283 
00284 TestMainFrame::~TestMainFrame()
00285 {
00286    // Delete all created widgets.
00287 
00288    delete fTestButton;
00289    delete fTestText;
00290 
00291    delete fStatusFrame;
00292    delete fContainer;
00293    delete fCanvasWindow;
00294 
00295    delete fMenuBarLayout;
00296    delete fMenuBarItemLayout;
00297    delete fMenuBarHelpLayout;
00298 
00299    delete fMenuBar;
00300    delete fMenuFile;
00301    delete fMenuTest;
00302    delete fMenuHelp;
00303    delete fCascadeMenu;
00304    delete fCascade1Menu;
00305    delete fCascade2Menu;
00306 }
00307 
00308 void TestMainFrame::CloseWindow()
00309 {
00310    // Got close message for this MainFrame. Terminate the application
00311    // or returns from the TApplication event loop (depending on the
00312    // argument specified in TApplication::Run()).
00313 
00314    gApplication->Terminate(0);
00315 }
00316 
00317 Bool_t TestMainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00318 {
00319    // Handle messages send to the TestMainFrame object. E.g. all menu button
00320    // messages.
00321 
00322    switch (GET_MSG(msg)) {
00323 
00324       case kC_COMMAND:
00325          switch (GET_SUBMSG(msg)) {
00326 
00327             case kCM_BUTTON:
00328                //printf("Button was pressed, id = %ld\n", parm1);
00329                if (parm1 == 150) {
00330                   Editor *ed = new Editor(this, 600, 400);
00331                   ed->LoadBuffer(editortxt1);
00332                   ed->Popup();
00333                }
00334               break;
00335 
00336             case kCM_MENUSELECT:
00337                //printf("Pointer over menu entry, id=%ld\n", parm1);
00338                break;
00339 
00340             case kCM_MENU:
00341                switch (parm1) {
00342 
00343                   case M_FILE_OPEN:
00344                      {
00345                         static TString dir(".");
00346                         TGFileInfo fi;
00347                         fi.fFileTypes = filetypes1;
00348                         fi.fIniDir    = StrDup(dir);
00349                         new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
00350                         printf("Open file: %s (dir: %s)\n", fi.fFilename,
00351                                fi.fIniDir);
00352                         dir = fi.fIniDir;
00353                      }
00354                      break;
00355 
00356                   case M_TEST_DLG:
00357                      new TestDialog(fClient->GetRoot(), this, 400, 200);
00358                      break;
00359 
00360                   case M_FILE_SAVE:
00361                      printf("M_FILE_SAVE\n");
00362                      break;
00363 
00364                   case M_FILE_EXIT:
00365                      CloseWindow();   // this also terminates theApp
00366                      break;
00367 
00368                   case M_TEST_MSGBOX:
00369                      new TestMsgBox(fClient->GetRoot(), this, 400, 200);
00370                      break;
00371 
00372                   case M_TEST_SLIDER:
00373                      new TestSliders(fClient->GetRoot(), this, 400, 200);
00374                      break;
00375 
00376                   case M_TEST_SHUTTER:
00377                      new TestShutter(fClient->GetRoot(), this, 400, 200);
00378                      break;
00379 
00380                   case M_TEST_PROGRESS:
00381                      new TestProgress(fClient->GetRoot(), this, 600, 300);
00382                      break;
00383 
00384                   default:
00385                      break;
00386                }
00387             default:
00388                break;
00389          }
00390       default:
00391          break;
00392    }
00393    return kTRUE;
00394 }
00395 
00396 TestDialog::TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w,
00397                        UInt_t h, UInt_t options)
00398     : TGTransientFrame(p, main, w, h, options)
00399 {
00400    // Create a dialog window. A dialog window pops up with respect to its
00401    // "main" window.
00402 
00403    // Used to store GUI elements that need to be deleted in the ctor.
00404    fCleanup = new TList;
00405 
00406    fFrame1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
00407 
00408    fOkButton = new TGTextButton(fFrame1, "&Ok", 1);
00409    fOkButton->Associate(this);
00410    fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2);
00411    fCancelButton->Associate(this);
00412 
00413    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
00414                            2, 2, 2, 2);
00415    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1);
00416 
00417    fFrame1->AddFrame(fOkButton, fL1);
00418    fFrame1->AddFrame(fCancelButton, fL1);
00419 
00420    fFrame1->Resize(150, fOkButton->GetDefaultHeight());
00421    AddFrame(fFrame1, fL2);
00422 
00423    //--------- create Tab widget and some composite frames for Tab testing
00424 
00425    fTab = new TGTab(this, 300, 300);
00426    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
00427 
00428    TGCompositeFrame *tf = fTab->AddTab("Tab 1");
00429    fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
00430    fF1->AddFrame(new TGTextButton(fF1, "&Test button", 0), fL3);
00431    fF1->AddFrame(fTxt1 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
00432    fF1->AddFrame(fTxt2 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
00433    tf->AddFrame(fF1, fL3);
00434    fTxt1->Resize(150, fTxt1->GetDefaultHeight());
00435    fTxt2->Resize(150, fTxt2->GetDefaultHeight());
00436 
00437    tf = fTab->AddTab("Tab 2");
00438    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
00439                            200, 2, 2, 2);
00440    fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
00441    fF2->AddFrame(fBtn1 = new TGTextButton(fF2, "&Button 1", 0), fL1);
00442    fF2->AddFrame(fBtn2 = new TGTextButton(fF2, "B&utton 2", 0), fL1);
00443    fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "C&heck 1", 0), fL1);
00444    fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Chec&k 2", 0), fL1);
00445    fF2->AddFrame(fRad1 = new TGRadioButton(fF2, "&Radio 1", 81), fL1);
00446    fF2->AddFrame(fRad2 = new TGRadioButton(fF2, "R&adio 2", 82), fL1);
00447    fCombo = new TGComboBox(fF2, 88);
00448    fF2->AddFrame(fCombo, fL3);
00449 
00450    tf->AddFrame(fF2, fL3);
00451 
00452    int i;
00453    for (i = 0; i < 20; i++) {
00454       char tmp[20];
00455 
00456       sprintf(tmp, "Entry %i", i+1);
00457       fCombo->AddEntry(tmp, i+1);
00458    }
00459 
00460    fCombo->Resize(150, 20);
00461 
00462    fBtn1->Associate(this);
00463    fBtn2->Associate(this);
00464    fChk1->Associate(this);
00465    fChk2->Associate(this);
00466    fRad1->Associate(this);
00467    fRad2->Associate(this);
00468 
00469    //-------------- embedded canvas demo
00470    fFillHistos = kFALSE;
00471    fHpx   = 0;
00472    fHpxpy = 0;
00473 
00474    tf = fTab->AddTab("Tab 3");
00475    fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
00476    fStartB = new TGTextButton(fF3, "Start &Filling Hists", 40);
00477    fStopB  = new TGTextButton(fF3, "&Stop Filling Hists", 41);
00478    fStartB->Associate(this);
00479    fStopB->Associate(this);
00480    fF3->AddFrame(fStartB, fL3);
00481    fF3->AddFrame(fStopB, fL3);
00482 
00483    fF5 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
00484 
00485    fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX |
00486                            kLHintsExpandY, 5, 5, 5, 5);
00487    fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 100);
00488    fF5->AddFrame(fEc1, fL4);
00489    fEc2 = new TRootEmbeddedCanvas("ec2", fF5, 100, 100);
00490    fF5->AddFrame(fEc2, fL4);
00491 
00492    tf->AddFrame(fF3, fL3);
00493    tf->AddFrame(fF5, fL4);
00494 
00495    fEc1->GetCanvas()->SetBorderMode(0);
00496    fEc2->GetCanvas()->SetBorderMode(0);
00497 
00498    // make tab yellow
00499    ULong_t yellow;
00500    fClient->GetColorByName("yellow", yellow);
00501    TGTabElement *tabel = fTab->GetTabTab(2);
00502    tabel->ChangeBackground(yellow);
00503 
00504    //-------------- end embedded canvas demo
00505 
00506    TGTextButton *bt;
00507    tf = fTab->AddTab("Tab 4");
00508    fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
00509    fF4->AddFrame(bt = new TGTextButton(fF4, "A&dd Entry", 90), fL3);
00510    bt->Associate(this);
00511    fCleanup->Add(bt);
00512    fF4->AddFrame(bt = new TGTextButton(fF4, "Remove &Entry", 91), fL3);
00513    bt->Associate(this);
00514    fCleanup->Add(bt);
00515    fF4->AddFrame(fListBox = new TGListBox(fF4, 89), fL3);
00516    fF4->AddFrame(fCheckMulti = new TGCheckButton(fF4, "&Mutli Selectable", 92), fL3);
00517    fCheckMulti->Associate(this);
00518    tf->AddFrame(fF4, fL3);
00519 
00520    for (i=0; i < 20; ++i) {
00521       char tmp[20];
00522 
00523       sprintf(tmp, "Entry %i", i+1);
00524       fListBox->AddEntry(tmp, i+1);
00525    }
00526    fFirstEntry = 1;
00527    fLastEntry  = 20;
00528 
00529    fListBox->Resize(150, 80);
00530 
00531    //--- tab 5
00532    tf = fTab->AddTab("Tab 5");
00533    tf->SetLayoutManager(new TGHorizontalLayout(tf));
00534 
00535    fF6 = new TGGroupFrame(tf, "Options", kVerticalFrame);
00536    tf->AddFrame(fF6, fL3);
00537 
00538    // 2 column, n rows
00539    fF6->SetLayoutManager(new TGMatrixLayout(fF6, 0, 2, 10));
00540    char buff[100];
00541    int j;
00542    for (j = 0; j < 4; j++) {
00543       sprintf(buff, "Module %i", j+1);
00544       fF6->AddFrame(new TGLabel(fF6, new TGHotString(buff)));
00545 
00546       TGTextBuffer *tbuf = new TGTextBuffer(10);
00547       tbuf->AddText(0, "0.0");
00548 
00549       TGTextEntry  *tent = new TGTextEntry(fF6, tbuf);
00550       tent->Resize(50, tent->GetDefaultHeight());
00551       tent->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
00552       fCleanup->Add(tent);
00553       fF6->AddFrame(tent);
00554    }
00555    fF6->Resize(fF6->GetDefaultSize());
00556 
00557    // another matrix with text and buttons
00558    fF7 = new TGGroupFrame(tf, "Tab Handling", kVerticalFrame);
00559    tf->AddFrame(fF7, fL3);
00560 
00561    fF7->SetLayoutManager(new TGMatrixLayout(fF7, 0, 1, 10));
00562 
00563    fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab", 101));
00564    bt->Associate(this);
00565    bt->Resize(90, bt->GetDefaultHeight());
00566    fCleanup->Add(bt);
00567 
00568    fF7->AddFrame(bt = new TGTextButton(fF7, "Add Tab", 103));
00569    bt->Associate(this);
00570    bt->Resize(90, bt->GetDefaultHeight());
00571    fCleanup->Add(bt);
00572 
00573    fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab 5", 102));
00574    bt->Associate(this);
00575    bt->Resize(90, bt->GetDefaultHeight());
00576    fCleanup->Add(bt);
00577 
00578    fF7->Resize(fF6->GetDefaultSize());
00579 
00580    //--- end of last tab
00581 
00582    TGLayoutHints *fL5 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
00583                                           kLHintsExpandY, 2, 2, 5, 1);
00584    AddFrame(fTab, fL5);
00585 
00586    MapSubwindows();
00587    Resize(GetDefaultSize());
00588 
00589    // position relative to the parent's window
00590    Window_t wdum;
00591    int ax, ay;
00592    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
00593                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
00594                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
00595                           ax, ay, wdum);
00596    Move(ax, ay);
00597 
00598    SetWindowName("Dialog");
00599 
00600    MapWindow();
00601    //fClient->WaitFor(this);    // otherwise canvas contextmenu does not work
00602 }
00603 
00604 TestDialog::~TestDialog()
00605 {
00606    // Delete test dialog widgets.
00607 
00608    fCleanup->Delete();
00609    delete fCleanup;
00610    delete fOkButton;
00611    delete fCancelButton;
00612    delete fStartB; delete fStopB;
00613    delete fFrame1;
00614    delete fBtn1; delete fBtn2;
00615    delete fChk1; delete fChk2;
00616    delete fRad1; delete fRad2;
00617    delete fTxt1; delete fTxt2;
00618    delete fEc1; delete fEc2;
00619    delete fListBox; delete fCheckMulti;
00620    delete fF1; delete fF2; delete fF3; delete fF4; delete fF5;
00621    delete fF6; delete fF7;
00622    delete fCombo;
00623    delete fTab;
00624    delete fL3; delete fL4;
00625    delete fL1; delete fL2;
00626    delete fHpx; delete fHpxpy;
00627 }
00628 
00629 void TestDialog::FillHistos()
00630 {
00631    // Fill histograms till user clicks "Stop Filling" button.
00632 
00633    static int cnt;
00634 
00635    if (!fHpx) {
00636       fHpx   = new TH1F("hpx","This is the px distribution",100,-4,4);
00637       fHpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
00638       fHpx->SetFillColor(kRed);
00639       cnt = 0;
00640    }
00641 
00642    const int kUPDATE = 1000;
00643    float px, py;
00644    TCanvas *c1 = fEc1->GetCanvas();
00645    TCanvas *c2 = fEc2->GetCanvas();
00646 
00647    while (fFillHistos) {
00648       gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
00649       fHpx->Fill(px);
00650       fHpxpy->Fill(px,py);
00651       cnt++;
00652       if (!(cnt % kUPDATE)) {
00653          if (cnt == kUPDATE) {
00654             c1->cd();
00655             fHpx->Draw();
00656             c2->cd();
00657             fHpxpy->Draw("cont");
00658          }
00659          c1->Modified();
00660          c1->Update();
00661          c2->Modified();
00662          c2->Update();
00663          gSystem->ProcessEvents();  // handle GUI events
00664       }
00665    }
00666 }
00667 
00668 void TestDialog::CloseWindow()
00669 {
00670    // Called when window is closed via the window manager.
00671 
00672    delete this;
00673 }
00674 
00675 Bool_t TestDialog::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00676 {
00677    // Process messages coming from widgets associated with the dialog.
00678 
00679    char tmp[20];
00680    static int newtab = 0;
00681 
00682    switch (GET_MSG(msg)) {
00683       case kC_COMMAND:
00684 
00685          switch (GET_SUBMSG(msg)) {
00686             case kCM_BUTTON:
00687                switch(parm1) {
00688                   case 1:
00689                   case 2:
00690                      printf("\nTerminating dialog: %s pressed\n",
00691                             (parm1 == 1) ? "OK" : "Cancel");
00692                      CloseWindow();
00693                      break;
00694                   case 40:  // start histogram filling
00695                      fFillHistos = kTRUE;
00696                      FillHistos();
00697                      break;
00698                   case 41:  // stop histogram filling
00699                      fFillHistos = kFALSE;
00700                      break;
00701                   case 90:  // add one entry in list box
00702                      fLastEntry++;
00703                      sprintf(tmp, "Entry %i", fLastEntry);
00704                      fListBox->AddEntry(tmp, fLastEntry);
00705                      fListBox->MapSubwindows();
00706                      fListBox->Layout();
00707                      break;
00708                   case 91:  // remove one entry in list box
00709                      if (fFirstEntry < fLastEntry) {
00710                         fListBox->RemoveEntry(fFirstEntry);
00711                         fListBox->Layout();
00712                         fFirstEntry++;
00713                      }
00714                      break;
00715                   case 101:  // remove tabs
00716                      {
00717                         TString s = fTab->GetTabTab(0)->GetString();
00718                         if (s == "Tab 3") {
00719                            // Need to delete the embedded canvases
00720                            // since RemoveTab() will Destroy the container
00721                            // window, which in turn will destroy the embedded
00722                            // canvas windows.
00723                            SafeDelete(fEc1);
00724                            SafeDelete(fEc2);
00725                         }
00726                         fTab->RemoveTab(0);
00727                         fTab->Layout();
00728                      }
00729                      break;
00730                   case 102:  // remove tab 5
00731                      {
00732                         int nt = fTab->GetNumberOfTabs();
00733                         for (int i = 0 ; i < nt; i++) {
00734                            TString s = fTab->GetTabTab(i)->GetString();
00735                            if (s == "Tab 5") {
00736                               fTab->RemoveTab(i);
00737                               fTab->Layout();
00738                            }
00739                         }
00740                      }
00741                      break;
00742                   case 103:  // add tabs
00743                      sprintf(tmp, "New Tab %d", ++newtab);
00744                      fTab->AddTab(tmp);
00745                      fTab->MapSubwindows();
00746                      fTab->Layout();
00747                      break;
00748                   default:
00749                      break;
00750                }
00751                break;
00752             case kCM_RADIOBUTTON:
00753                switch (parm1) {
00754                   case 81:
00755                      fRad2->SetState(kButtonUp);
00756                      break;
00757                   case 82:
00758                      fRad1->SetState(kButtonUp);
00759                      break;
00760                }
00761                break;
00762             case kCM_CHECKBUTTON:
00763                switch (parm1) {
00764                   case 92:
00765                      fListBox->SetMultipleSelections(fCheckMulti->GetState());
00766                      break;
00767                   default:
00768                      break;
00769                }
00770                break;
00771             case kCM_TAB:
00772                printf("Tab item %ld activated\n", parm1);
00773                break;
00774             default:
00775                break;
00776          }
00777          break;
00778 
00779       default:
00780          break;
00781    }
00782    return kTRUE;
00783 }
00784 
00785 TestMsgBox::TestMsgBox(const TGWindow *p, const TGWindow *main,
00786                        UInt_t w, UInt_t h, UInt_t options) :
00787      TGTransientFrame(p, main, w, h, options),
00788      fRedTextGC(TGButton::GetDefaultGC())
00789 {
00790    // Create message box test dialog. Use this dialog to select the different
00791    // message dialog box styles and show the message dialog by clicking the
00792    // "Test" button.
00793 
00794    //------------------------------
00795    // Set foreground color in graphics context for drawing of
00796    // TGlabel and TGButtons with text in red.
00797 
00798    ULong_t red;
00799    fClient->GetColorByName("red", red);
00800    fRedTextGC.SetForeground(red);
00801    //---------------------------------
00802 
00803    int i, ax, ay;
00804 
00805    ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
00806 
00807    f1 = new TGCompositeFrame(this, 60, 20, kVerticalFrame | kFixedWidth);
00808    f2 = new TGCompositeFrame(this, 60, 20, kVerticalFrame);
00809    f3 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
00810    f4 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
00811    f5 = new TGCompositeFrame(f2, 60, 20, kHorizontalFrame);
00812 
00813    fTestButton = new TGTextButton(f1, "&Test", 1, fRedTextGC());
00814 
00815    // Change background of fTestButton to green
00816    ULong_t green;
00817    fClient->GetColorByName("green", green);
00818    fTestButton->ChangeBackground(green);
00819 
00820    fCloseButton = new TGTextButton(f1, "&Close", 2);
00821    fPictButton = new TGPictureButton(f1, fClient->GetPicture("mb_stop_s.xpm"));
00822 
00823    f1->Resize(fTestButton->GetDefaultWidth()+40, GetDefaultHeight());
00824 
00825    fTestButton->Associate(this);
00826    fCloseButton->Associate(this);
00827    fPictButton->Associate(this);
00828 
00829    fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX,
00830                            2, 2, 3, 0);
00831    fL2 = new TGLayoutHints(kLHintsTop | kLHintsRight | kLHintsExpandX,
00832                            2, 5, 0, 2);
00833    fL21 = new TGLayoutHints(kLHintsTop | kLHintsRight,
00834                             2, 5, 10, 0);
00835 
00836    f1->AddFrame(fTestButton, fL1);
00837    f1->AddFrame(fCloseButton, fL1);
00838    f1->AddFrame(fPictButton, fL1);
00839    AddFrame(f1, fL21);
00840 
00841    //--------- create check and radio buttons groups
00842 
00843    fG1 = new TGGroupFrame(f3, new TGString("Buttons"));
00844    fG2 = new TGGroupFrame(f3, new TGString("Icons"));
00845 
00846    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft |
00847                            kLHintsExpandX | kLHintsExpandY,
00848                            2, 2, 2, 2);
00849    fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft,
00850                            0, 0, 5, 0);
00851 
00852    fC[0] = new TGCheckButton(fG1, new TGHotString("Yes"),     -1);
00853    fC[1] = new TGCheckButton(fG1, new TGHotString("No"),      -1);
00854    fC[2] = new TGCheckButton(fG1, new TGHotString("OK"),      -1);
00855    fC[3] = new TGCheckButton(fG1, new TGHotString("Apply"),   -1);
00856    fC[4] = new TGCheckButton(fG1, new TGHotString("Retry"),   -1);
00857    fC[5] = new TGCheckButton(fG1, new TGHotString("Ignore"),  -1);
00858    fC[6] = new TGCheckButton(fG1, new TGHotString("Cancel"),  -1);
00859    fC[7] = new TGCheckButton(fG1, new TGHotString("Close"),   -1);
00860    fC[8] = new TGCheckButton(fG1, new TGHotString("Dismiss"), -1);
00861 
00862    for (i=0; i<9; ++i) fG1->AddFrame(fC[i], fL4);
00863 
00864    fR[0] = new TGRadioButton(fG2, new TGHotString("Stop"),        21);
00865    fR[1] = new TGRadioButton(fG2, new TGHotString("Question"),    22);
00866    fR[2] = new TGRadioButton(fG2, new TGHotString("Exclamation"), 23);
00867    fR[3] = new TGRadioButton(fG2, new TGHotString("Asterisk"),    24);
00868 
00869    for (i = 0; i < 4; ++i) {
00870       fG2->AddFrame(fR[i], fL4);
00871       fR[i]->Associate(this);
00872    }
00873 
00874    fC[2]->SetState(kButtonDown);
00875    fR[0]->SetState(kButtonDown);
00876 
00877    f3->AddFrame(fG1, fL3);
00878    f3->AddFrame(fG2, fL3);
00879 
00880    fLtitle = new TGLabel(f4, new TGString("Title:"), fRedTextGC());
00881    fLmsg   = new TGLabel(f5, new TGString("Message:"));
00882 
00883    fTitle = new TGTextEntry(f4, fTbtitle = new TGTextBuffer(100));
00884    fMsg   = new TGTextEntry(f5, fTbmsg = new TGTextBuffer(100));
00885 
00886    fTbtitle->AddText(0, "MsgBox");
00887    fTbmsg->AddText(0, "This is a test message box.");
00888 
00889    fTitle->Resize(300, fTitle->GetDefaultHeight());
00890    fMsg->Resize(300, fMsg->GetDefaultHeight());
00891 
00892    fL5 = new TGLayoutHints(kLHintsLeft | kLHintsCenterY,
00893                            3, 5, 0, 0);
00894    fL6 = new TGLayoutHints(kLHintsRight | kLHintsCenterY,
00895                            0, 2, 0, 0);
00896 
00897    f4->AddFrame(fLtitle, fL5);
00898    f4->AddFrame(fTitle, fL6);
00899    f5->AddFrame(fLmsg, fL5);
00900    f5->AddFrame(fMsg, fL6);
00901 
00902    f2->AddFrame(f3, fL1);
00903    f2->AddFrame(f4, fL1);
00904    f2->AddFrame(f5, fL1);
00905 
00906    AddFrame(f2, fL2);
00907 
00908    MapSubwindows();
00909    Resize(GetDefaultSize());
00910 
00911    // position relative to the parent's window
00912    Window_t wdum;
00913    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
00914                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
00915                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
00916                           ax, ay, wdum);
00917    Move(ax, ay);
00918 
00919    SetWindowName("Message Box Test");
00920 
00921    MapWindow();
00922    fClient->WaitFor(this);
00923 }
00924 
00925 // Order is important when deleting frames. Delete children first,
00926 // parents last.
00927 
00928 TestMsgBox::~TestMsgBox()
00929 {
00930    // Delete widgets created by dialog.
00931 
00932    delete fTestButton; delete fCloseButton;
00933    delete fC[0]; delete fC[1]; delete fC[2]; delete fC[3];
00934    delete fC[4]; delete fC[5]; delete fC[6]; delete fC[7]; delete fC[8];
00935    delete fR[0]; delete fR[1]; delete fR[2]; delete fR[3];
00936    delete fTitle; delete fLtitle;
00937    delete fMsg; delete fLmsg;
00938    delete f3; delete f4; delete f5; delete f2; delete f1;
00939    delete fL1; delete fL2; delete fL3; delete fL4; delete fL5; delete fL6;
00940    delete fL21;
00941 }
00942 
00943 void TestMsgBox::CloseWindow()
00944 {
00945    // Close dialog in response to window manager close.
00946 
00947    delete this;
00948 }
00949 
00950 Bool_t TestMsgBox::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00951 {
00952    // Process messages sent to this dialog.
00953 
00954    int i, buttons, retval;
00955    EMsgBoxIcon icontype = kMBIconStop;
00956 
00957    switch(GET_MSG(msg)) {
00958       case kC_COMMAND:
00959 
00960          switch(GET_SUBMSG(msg)) {
00961             case kCM_BUTTON:
00962                switch(parm1) {
00963                   case 1:
00964                      buttons = 0;
00965                      for (i=0; i<9; ++i)
00966                         if (fC[i]->GetState() == kButtonDown)
00967                            buttons |= mb_button_id0[i];
00968 
00969                      for (i=0; i<4; ++i)
00970                         if (fR[i]->GetState() == kButtonDown)
00971                            { icontype = mb_icon1[i]; break; }
00972 
00973                      new TGMsgBox(fClient->GetRoot(), this,
00974                                   fTbtitle->GetString(), fTbmsg->GetString(),
00975                                   icontype, buttons, &retval);
00976                      break;
00977 
00978                   case 2:
00979                      CloseWindow();
00980                      break;
00981 
00982                }
00983                break;
00984 
00985             case kCM_RADIOBUTTON:
00986             case kCM_CHECKBUTTON:
00987                if (parm1 >= 21 && parm1 <= 24) {
00988                   for (i=0; i<4; ++i)
00989                      if (fR[i]->WidgetId() != parm1)
00990                         fR[i]->SetState(kButtonUp);
00991                }
00992                break;
00993 
00994             default:
00995                break;
00996          }
00997          break;
00998 
00999       default:
01000          break;
01001    }
01002 
01003    return kTRUE;
01004 }
01005 
01006 TestSliders::TestSliders(const TGWindow *p, const TGWindow *main,
01007                          UInt_t w, UInt_t h) :
01008     TGTransientFrame(p, main, w, h)
01009 {
01010    // Dialog used to test the different supported sliders.
01011 
01012    ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
01013 
01014    fVframe1 = new TGVerticalFrame(this, 0, 0, 0);
01015 
01016    fTeh1 = new TGTextEntry(fVframe1, fTbh1 = new TGTextBuffer(10), HId1);
01017    fTev1 = new TGTextEntry(fVframe1, fTbv1 = new TGTextBuffer(10), VId1);
01018    fTbh1->AddText(0, "0");
01019    fTbv1->AddText(0, "0");
01020 
01021    fTeh1->Associate(this);
01022    fTev1->Associate(this);
01023 
01024    fHslider1 = new TGHSlider(fVframe1, 100, kSlider1 | kScaleBoth, HSId1);
01025    fHslider1->Associate(this);
01026    fHslider1->SetRange(0,50);
01027 
01028    fVslider1 = new TGVSlider(fVframe1, 100, kSlider2 | kScaleBoth, VSId1);
01029    fVslider1->Associate(this);
01030    fVslider1->SetRange(0,8);
01031 
01032    fVframe1->Resize(100, 100);
01033 
01034    fVframe2 = new TGVerticalFrame(this, 0, 0, 0);
01035    fTeh2 = new TGTextEntry(fVframe2, fTbh2 = new TGTextBuffer(10), HId2);
01036    fTev2 = new TGTextEntry(fVframe2, fTbv2 = new TGTextBuffer(10), VId2);
01037    fTbh2->AddText(0, "0");
01038    fTbv2->AddText(0, "0");
01039 
01040    fTeh2->Associate(this);
01041    fTev2->Associate(this);
01042 
01043    fHslider2 = new TGHSlider(fVframe2, 150, kSlider2 | kScaleBoth, HSId2);
01044    fHslider2->Associate(this);
01045    fHslider2->SetRange(0,3);
01046 
01047    fVslider2 = new TGDoubleVSlider(fVframe2, 100, kDoubleScaleBoth, VSId2);
01048    fVslider2->Associate(this);
01049    fVslider2->SetRange(-10,10);
01050 
01051    fVframe2->Resize(100, 100);
01052 
01053    //--- layout for buttons: top align, equally expand horizontally
01054    fBly = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 3, 0);
01055 
01056    //--- layout for the frame: place at bottom, right aligned
01057    fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsRight, 20, 10, 15, 0);
01058 
01059    fVframe1->AddFrame(fHslider1, fBly);
01060    fVframe1->AddFrame(fVslider1, fBly);
01061    fVframe1->AddFrame(fTeh1, fBly);
01062    fVframe1->AddFrame(fTev1, fBly);
01063 
01064    fVframe2->AddFrame(fHslider2, fBly);
01065    fVframe2->AddFrame(fVslider2, fBly);
01066    fVframe2->AddFrame(fTeh2, fBly);
01067    fVframe2->AddFrame(fTev2, fBly);
01068 
01069    AddFrame(fVframe2, fBfly1);
01070    AddFrame(fVframe1, fBfly1);
01071 
01072    SetWindowName("Slider Test");
01073    TGDimension size = GetDefaultSize();
01074    Resize(size);
01075 
01076    SetWMSize(size.fWidth, size.fHeight);
01077    SetWMSizeHints(size.fWidth, size.fHeight, size.fWidth, size.fHeight, 0, 0);
01078    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
01079                               kMWMDecorMinimize | kMWMDecorMenu,
01080                kMWMFuncAll |  kMWMFuncResize    | kMWMFuncMaximize |
01081                               kMWMFuncMinimize,
01082                kMWMInputModeless);
01083 
01084    // position relative to the parent's window
01085    Window_t wdummy;
01086    int ax, ay;
01087    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
01088                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
01089                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
01090                           ax, ay, wdummy);
01091    Move(ax, ay);
01092 
01093    MapSubwindows();
01094    MapWindow();
01095 
01096    fClient->WaitFor(this);
01097 }
01098 
01099 TestSliders::~TestSliders()
01100 {
01101    // Delete dialog.
01102 
01103    delete fVframe1;
01104    delete fVframe2;
01105    delete fBfly1; delete fBly;
01106    delete fHslider1; delete fHslider2;
01107    delete fVslider1; delete fVslider2;
01108    delete fTeh1; delete fTeh2; delete fTev1; delete fTev2;
01109 }
01110 
01111 void TestSliders::CloseWindow()
01112 {
01113    // Called when window is closed via the window manager.
01114 
01115    delete this;
01116 }
01117 
01118 Bool_t TestSliders::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
01119 {
01120    // Process slider messages.
01121 
01122    char buf[10];
01123 
01124    switch (GET_MSG(msg)) {
01125       case kC_TEXTENTRY:
01126          switch (GET_SUBMSG(msg)) {
01127             case kTE_TEXTCHANGED:
01128                switch (parm1) {
01129                   case HId1:
01130                      fHslider1->SetPosition(atoi(fTbh1->GetString()));
01131                      break;
01132                   case VId1:
01133                      fVslider1->SetPosition(atoi(fTbv1->GetString()));
01134                      break;
01135                   case HId2:
01136                      fHslider2->SetPosition(atoi(fTbh2->GetString()));
01137                      break;
01138                   case VId2:
01139                      fVslider2->SetPosition(atoi(fTbv2->GetString()),
01140                                             atoi(fTbv2->GetString())+2);
01141                      break;
01142                }
01143                break;
01144          }
01145          break;
01146       case kC_VSLIDER:
01147       case kC_HSLIDER:
01148          switch (GET_SUBMSG(msg)) {
01149             case kSL_POS:
01150                sprintf(buf, "%ld", parm2);
01151                switch (parm1) {
01152                   case HSId1:
01153                      fTbh1->Clear();
01154                      fTbh1->AddText(0, buf);
01155                      fClient->NeedRedraw(fTeh1);
01156                      break;
01157                   case VSId1:
01158                      fTbv1->Clear();
01159                      fTbv1->AddText(0, buf);
01160                      fClient->NeedRedraw(fTev1);
01161                      break;
01162                   case HSId2:
01163                      fTbh2->Clear();
01164                      fTbh2->AddText(0, buf);
01165                      fClient->NeedRedraw(fTeh2);
01166                      break;
01167                   case VSId2:
01168                      sprintf(buf, "%f", fVslider2->GetMinPosition());
01169                      fTbv2->Clear();
01170                      fTbv2->AddText(0, buf);
01171                      fClient->NeedRedraw(fTev2);
01172                      break;
01173                }
01174                break;
01175          }
01176          break;
01177       default:
01178          break;
01179    }
01180    return kTRUE;
01181 }
01182 
01183 TestShutter::TestShutter(const TGWindow *p, const TGWindow *main,
01184                          UInt_t w, UInt_t h) :
01185    TGTransientFrame(p, main, w, h)
01186 {
01187    // Create transient frame containing a shutter widget.
01188 
01189    fDefaultPic = fClient->GetPicture("folder_s.xpm");
01190    fShutter = new TGShutter(this, kSunkenFrame);
01191 
01192    fTrash = new TList;
01193 
01194    AddShutterItem("Histograms", histo_data0);
01195    AddShutterItem("Functions", function_data0);
01196    AddShutterItem("Trees", tree_data0);
01197 
01198    fLayout = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
01199    AddFrame(fShutter, fLayout);
01200 
01201    MapSubwindows();
01202    Resize(80, 300);
01203 
01204    // position relative to the parent's window
01205    Window_t wdum;
01206    int ax, ay;
01207    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
01208                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
01209                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
01210                           ax, ay, wdum);
01211    Move(ax, ay);
01212 
01213    SetWindowName("Shutter Test");
01214 
01215    MapWindow();
01216    //fClient->WaitFor(this);
01217 }
01218 
01219 void TestShutter::AddShutterItem(const char *name, shutterData_t data[])
01220 {
01221    TGShutterItem    *item;
01222    TGCompositeFrame *container;
01223    TGButton         *button;
01224    const TGPicture  *buttonpic;
01225    static int id = 5001;
01226 
01227    TGLayoutHints *l = new TGLayoutHints(kLHintsTop | kLHintsCenterX,
01228                                         5, 5, 5, 0);
01229    fTrash->Add(l);
01230 
01231    item = new TGShutterItem(fShutter, new TGHotString(name), id++);
01232    container = (TGCompositeFrame *) item->GetContainer();
01233    fTrash->Add(item);
01234 
01235    for (int i=0; data[i].pixmap_name != 0; i++) {
01236       buttonpic = fClient->GetPicture(data[i].pixmap_name);
01237       if (!buttonpic) {
01238          Warning("AddShutterItem", "missing pixmap \"%s\", using default",
01239                  data[i].pixmap_name);
01240          buttonpic = fDefaultPic;
01241       }
01242 
01243       button = new TGPictureButton(container, buttonpic, data[i].id);
01244       fTrash->Add(button);
01245       container->AddFrame(button, l);
01246       button->Associate(this);
01247       button->SetToolTipText(data[i].tip_text);
01248       data[i].button = button;
01249    }
01250 
01251    fShutter->AddItem(item);
01252 }
01253 
01254 TestShutter::~TestShutter()
01255 {
01256    delete fLayout;
01257    delete fShutter;
01258    fTrash->Delete();
01259    delete fTrash;
01260 }
01261 
01262 void TestShutter::CloseWindow()
01263 {
01264    delete this;
01265 }
01266 
01267 Bool_t TestShutter::ProcessMessage(Long_t, Long_t parm1, Long_t)
01268 {
01269    // Process messages sent to this dialog.
01270 
01271    printf("Shutter button %d\n", (Int_t)parm1);
01272    return kTRUE;
01273 }
01274 
01275 TestProgress::TestProgress(const TGWindow *p, const TGWindow *main,
01276                            UInt_t w, UInt_t h) :
01277     TGTransientFrame(p, main, w, h)
01278 {
01279    // Dialog used to test the different supported progress bars.
01280 
01281    ChangeOptions((GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
01282 
01283    fHframe1 = new TGHorizontalFrame(this, 0, 0, 0);
01284 
01285    fVProg1 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
01286    fVProg1->SetBarColor("purple");
01287    fVProg2 = new TGVProgressBar(fHframe1, TGProgressBar::kFancy, 300);
01288    fVProg2->SetFillType(TGProgressBar::kBlockFill);
01289    fVProg2->SetBarColor("green");
01290 
01291    fHframe1->Resize(300, 300);
01292 
01293    fVframe1 = new TGVerticalFrame(this, 0, 0, 0);
01294 
01295    fHProg1 = new TGHProgressBar(fVframe1, 300);
01296    fHProg1->ShowPosition();
01297    fHProg2 = new TGHProgressBar(fVframe1, TGProgressBar::kFancy, 300);
01298    fHProg2->SetBarColor("lightblue");
01299    fHProg2->ShowPosition(kTRUE, kFALSE, "%.0f events");
01300    fHProg3 = new TGHProgressBar(fVframe1, TGProgressBar::kStandard, 300);
01301    fHProg3->SetFillType(TGProgressBar::kBlockFill);
01302 
01303    fGO = new TGTextButton(fVframe1, "Go", 10);
01304    fGO->Associate(this);
01305 
01306    fVframe1->Resize(300, 300);
01307 
01308    fHint1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 10, 5, 5);
01309    fHint2 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5,  5, 10);
01310    fHint3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 0, 50, 50, 0);
01311    fHint4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 0, 0, 0, 0);
01312    fHint5 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0);
01313 
01314    fHframe1->AddFrame(fVProg1, fHint1);
01315    fHframe1->AddFrame(fVProg2, fHint1);
01316 
01317    fVframe1->AddFrame(fHProg1, fHint2);
01318    fVframe1->AddFrame(fHProg2, fHint2);
01319    fVframe1->AddFrame(fHProg3, fHint2);
01320    fVframe1->AddFrame(fGO,     fHint3);
01321 
01322    AddFrame(fHframe1, fHint4);
01323    AddFrame(fVframe1, fHint5);
01324 
01325    SetWindowName("Progress Test");
01326    TGDimension size = GetDefaultSize();
01327    Resize(size);
01328 
01329    // position relative to the parent's window
01330    Window_t wdummy;
01331    int ax, ay;
01332    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
01333                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
01334                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
01335                           ax, ay, wdummy);
01336    Move(ax, ay);
01337 
01338    MapSubwindows();
01339    MapWindow();
01340 
01341    fClient->WaitFor(this);
01342 }
01343 
01344 TestProgress::~TestProgress()
01345 {
01346    // Delete dialog.
01347 
01348    delete fHframe1;
01349    delete fVframe1;
01350    delete fVProg1; delete fVProg2;
01351    delete fHProg1; delete fHProg2; delete fHProg3;
01352    delete fHint1; delete fHint2; delete fHint3; delete fHint4; delete fHint5;
01353    delete fGO; fGO = 0; // to get cleanly out of the loop in ProcessMessage
01354 }
01355 
01356 void TestProgress::CloseWindow()
01357 {
01358    // Called when window is closed via the window manager.
01359 
01360    delete this;
01361 }
01362 
01363 Bool_t TestProgress::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
01364 {
01365    // Process slider messages.
01366 
01367    switch (GET_MSG(msg)) {
01368       case kC_COMMAND:
01369          switch (GET_SUBMSG(msg)) {
01370             case kCM_BUTTON:
01371                switch (parm1) {
01372                   case 10:
01373                      {
01374                         fVProg1->Reset(); fVProg2->Reset();
01375                         fHProg1->Reset(); fHProg2->Reset(); fHProg3->Reset();
01376                         fVProg2->SetBarColor("green");
01377                         int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
01378                         int inc1 = 4, inc2 = 3, inc3 = 2, inc4 = 1;
01379                         while (cnt1 < 100 || cnt2 < 100 || cnt3 < 100 || cnt4 <100) {
01380                            if (cnt1 < 100) {
01381                               cnt1 += inc1;
01382                               fVProg1->Increment(inc1);
01383                            }
01384                            if (cnt2 < 100) {
01385                               cnt2 += inc2;
01386                               fVProg2->Increment(inc2);
01387                               if (cnt2 > 75)
01388                                  fVProg2->SetBarColor("red");
01389                            }
01390                            if (cnt3 < 100) {
01391                               cnt3 += inc3;
01392                               fHProg1->Increment(inc3);
01393                            }
01394                            if (cnt4 < 100) {
01395                               cnt4 += inc4;
01396                               fHProg2->Increment(inc4);
01397                               fHProg3->Increment(inc4);
01398                            }
01399                            gSystem->Sleep(100);
01400                            gSystem->ProcessEvents();
01401                            // if user closed window return
01402                            if (!fGO) return kTRUE;
01403                         }
01404                      }
01405                      break;
01406                   default:
01407                      break;
01408                }
01409                break;
01410             default:
01411                break;
01412          }
01413          break;
01414       default:
01415          break;
01416    }
01417    return kTRUE;
01418 }
01419 
01420 Editor::Editor(const TGWindow *main, UInt_t w, UInt_t h) :
01421     TGTransientFrame(gClient->GetRoot(), main, w, h)
01422 {
01423    // Create an editor in a dialog.
01424 
01425    fEdit = new TGTextEdit(this, w, h, kSunkenFrame | kDoubleBorder);
01426    fL1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3);
01427    AddFrame(fEdit, fL1);
01428 
01429    fOK = new TGTextButton(this, "  &OK  ");
01430    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
01431    AddFrame(fOK, fL2);
01432 
01433    SetTitle();
01434 
01435    MapSubwindows();
01436 
01437    Resize(GetDefaultSize());
01438 
01439    // position relative to the parent's window
01440    Window_t wdum;
01441    int ax, ay;
01442    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
01443                           ((TGFrame *) main)->GetWidth() - (fWidth >> 1),
01444                           (((TGFrame *) main)->GetHeight() - fHeight) >> 1,
01445                           ax, ay, wdum);
01446    Move(ax, ay);
01447    SetWMPosition(ax, ay);
01448 }
01449 
01450 Editor::~Editor()
01451 {
01452    // Delete editor dialog.
01453 
01454    delete fEdit;
01455    delete fOK;
01456    delete fL1;
01457    delete fL2;
01458 }
01459 
01460 void Editor::SetTitle()
01461 {
01462    // Set title in editor window.
01463 
01464    TGText *txt = GetEditor()->GetText();
01465    Bool_t untitled = !strlen(txt->GetFileName()) ? kTRUE : kFALSE;
01466 
01467    char title[256];
01468    if (untitled)
01469       sprintf(title, "ROOT Editor - Untitled");
01470    else
01471       sprintf(title, "ROOT Editor - %s", txt->GetFileName());
01472 
01473    SetWindowName(title);
01474    SetIconName(title);
01475 }
01476 
01477 void Editor::Popup()
01478 {
01479    // Show editor.
01480 
01481    MapWindow();
01482 }
01483 
01484 void Editor::LoadBuffer(const char *buffer)
01485 {
01486    // Load a text buffer in the editor.
01487 
01488    fEdit->LoadBuffer(buffer);
01489 }
01490 
01491 void Editor::LoadFile(const char *file)
01492 {
01493    // Load a file in the editor.
01494 
01495    fEdit->LoadFile(file);
01496 }
01497 
01498 void Editor::CloseWindow()
01499 {
01500    // Called when closed via window manager action.
01501 
01502    delete this;
01503 }
01504 
01505 Bool_t Editor::ProcessMessage(Long_t msg, Long_t, Long_t)
01506 {
01507    // Process OK button.
01508 
01509    switch (GET_MSG(msg)) {
01510       case kC_COMMAND:
01511          switch (GET_SUBMSG(msg)) {
01512             case kCM_BUTTON:
01513                // Only one button and one action...
01514                delete this;
01515                break;
01516             default:
01517                break;
01518          }
01519          break;
01520       case kC_TEXTVIEW:
01521          switch (GET_SUBMSG(msg)) {
01522             case kTXT_CLOSE:
01523                // close window
01524                delete this;
01525                break;
01526             case kTXT_OPEN:
01527                SetTitle();
01528                break;
01529             case kTXT_SAVE:
01530                SetTitle();
01531                break;
01532             default:
01533                break;
01534          }
01535       default:
01536          break;
01537    }
01538 
01539    return kTRUE;
01540 }

Generated on Tue Jul 5 14:22:21 2011 for ROOT_528-00b_version by  doxygen 1.5.1