forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguitest.cxx
2445 lines (2000 loc) · 73.5 KB
/
guitest.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/test:$Id$
// Author: Fons Rademakers 07/03/98
// guitest.cxx: test program for ROOT native GUI classes.
// To run it do: make guitest; guitest
// Another version with identical functionality but using the new signals
// and slots communication mechanism can be found in $ROOTSYS/tutorials.
// That version can be run entirely in the interpreter.
#include <stdlib.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TVirtualX.h>
#include <TVirtualPadEditor.h>
#include <TGResourcePool.h>
#include <TGListBox.h>
#include <TGListTree.h>
#include <TGFSContainer.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TGIcon.h>
#include <TGLabel.h>
#include <TGButton.h>
#include <TGTextEntry.h>
#include <TGNumberEntry.h>
#include <TGMsgBox.h>
#include <TGMenu.h>
#include <TGCanvas.h>
#include <TGComboBox.h>
#include <TGTab.h>
#include <TGSlider.h>
#include <TGDoubleSlider.h>
#include <TGFileDialog.h>
#include <TGTextEdit.h>
#include <TGShutter.h>
#include <TGProgressBar.h>
#include <TGColorSelect.h>
#include <TRootEmbeddedCanvas.h>
#include <TCanvas.h>
#include <TColor.h>
#include <TH1.h>
#include <TH2.h>
#include <TRandom.h>
#include <TSystem.h>
#include <TSystemDirectory.h>
#include <TFile.h>
#include <TKey.h>
#include <TGDockableFrame.h>
#include <TGFontDialog.h>
enum ETestCommandIdentifiers {
M_FILE_OPEN,
M_FILE_SAVE,
M_FILE_SAVEAS,
M_FILE_PRINT,
M_FILE_PRINTSETUP,
M_FILE_EXIT,
M_TEST_DLG,
M_TEST_MSGBOX,
M_TEST_SLIDER,
M_TEST_SHUTTER,
M_TEST_DIRLIST,
M_TEST_FILELIST,
M_TEST_PROGRESS,
M_TEST_NUMBERENTRY,
M_TEST_FONTDIALOG,
M_TEST_NEWMENU,
M_VIEW_ENBL_DOCK,
M_VIEW_ENBL_HIDE,
M_VIEW_DOCK,
M_VIEW_UNDOCK,
M_HELP_CONTENTS,
M_HELP_SEARCH,
M_HELP_ABOUT,
M_CASCADE_1,
M_CASCADE_2,
M_CASCADE_3,
M_NEW_REMOVEMENU,
VId1,
HId1,
VId2,
HId2,
VSId1,
HSId1,
VSId2,
HSId2,
ColorSel
};
Int_t mb_button_id[13] = { kMBYes, kMBNo, kMBOk, kMBApply,
kMBRetry, kMBIgnore, kMBCancel,
kMBClose, kMBYesAll, kMBNoAll,
kMBNewer, kMBAppend, kMBDismiss};
EMsgBoxIcon mb_icon[4] = { kMBIconStop, kMBIconQuestion,
kMBIconExclamation, kMBIconAsterisk };
const char *filetypes[] = { "All files", "*",
"ROOT files", "*.root",
"ROOT macros", "*.C",
0, 0 };
struct shutterData_t {
const char *pixmap_name;
const char *tip_text;
Int_t id;
TGButton *button;
};
shutterData_t histo_data[] = {
{ "h1_s.xpm", "TH1", 1001, 0 },
{ "h2_s.xpm", "TH2", 1002, 0 },
{ "h3_s.xpm", "TH3", 1003, 0 },
{ "profile_s.xpm", "TProfile", 1004, 0 },
{ 0, 0, 0, 0 }
};
shutterData_t function_data[] = {
{ "f1_s.xpm", "TF1", 2001, 0 },
{ "f2_s.xpm", "TF2", 2002, 0 },
{ 0, 0, 0, 0 }
};
shutterData_t tree_data[] = {
{ "ntuple_s.xpm", "TNtuple", 3001, 0 },
{ "tree_s.xpm", "TTree", 3002, 0 },
{ "chain_s.xpm", "TChain", 3003, 0 },
{ 0, 0, 0, 0 }
};
const char *editortxt =
"This is the ROOT text edit widget TGTextEdit. It is not intended as\n"
"a full developers editor, but it is relatively complete and can ideally\n"
"be used to edit scripts or to present users editable config files, etc.\n\n"
"The text edit widget supports standard emacs style ctrl-key navigation\n"
"in addition to the arrow keys. By default the widget has under the right\n"
"mouse button a popup menu giving access to several built-in functions.\n\n"
"Cut, copy and paste between different editor windows and any other\n"
"standard text handling application is supported.\n\n"
"Text can be selected with the mouse while holding the left button\n"
"or with the arrow keys while holding the shift key pressed. Use the\n"
"middle mouse button to paste text at the current mouse location.\n"
"Mice with scroll-ball are properly supported.\n\n"
"This are the currently defined key bindings:\n"
"Left Arrow\n"
" Move the cursor one character leftwards.\n"
" Scroll when cursor is out of frame.\n"
"Right Arrow\n"
" Move the cursor one character rightwards.\n"
" Scroll when cursor is out of frame.\n"
"Backspace\n"
" Deletes the character on the left side of the text cursor and moves the\n"
" cursor one position to the left. If a text has been marked by the user\n"
" (e.g. by clicking and dragging) the cursor will be put at the beginning\n"
" of the marked text and the marked text will be removed.\n"
"Home\n"
" Moves the text cursor to the left end of the line. If mark is TRUE text\n"
" will be marked towards the first position, if not any marked text will\n"
" be unmarked if the cursor is moved.\n"
"End\n"
" Moves the text cursor to the right end of the line. If mark is TRUE text\n"
" will be marked towards the last position, if not any marked text will\n"
" be unmarked if the cursor is moved.\n"
"Delete\n"
" Deletes the character on the right side of the text cursor. If a text\n"
" has been marked by the user (e.g. by clicking and dragging) the cursor\n"
" will be put at the beginning of the marked text and the marked text will\n"
" be removed.\n"
" Deletes the character on the right side of the text cursor. If a text\n"
" has been marked by the user (e.g. by clicking and dragging) the cursor\n"
" will be put at the beginning of the marked text and the marked text will\n"
" be removed.\n"
"Shift - Left Arrow\n"
" Mark text one character leftwards.\n"
"Shift - Right Arrow\n"
" Mark text one character rightwards.\n"
"Control-A\n"
" Select the whole text.\n"
"Control-B\n"
" Move the cursor one character leftwards."
"Control-C\n"
" Copy the marked text to the clipboard.\n"
"Control-D\n"
" Delete the character to the right of the cursor.\n"
"Control-E\n"
" Move the cursor to the end of the line.\n"
"Control-F\n"
" Start Search Dialog.\n"
"Control-H\n"
" Delete the character to the left of the cursor.\n"
"Control-K\n"
" Delete marked text if any or delete all\n"
" characters to the right of the cursor.\n"
"Control-L\n"
" Start GoTo Line Dialog\n"
"Control-U\n"
" Delete all characters on the line.\n"
"Control-V\n"
" Paste the clipboard text into line edit.\n"
"Control-X\n"
" Cut the marked text, copy to clipboard.\n"
"Control-Y\n"
" Paste the clipboard text into line edit.\n"
"Control-Z\n"
" Undo action.\n\n"
"All other keys with valid ASCII codes insert themselves into the line.";
class TileFrame;
class TestMainFrame : public TGMainFrame {
private:
TGDockableFrame *fMenuDock;
TGCompositeFrame *fStatusFrame;
TGCanvas *fCanvasWindow;
TileFrame *fContainer;
TGTextEntry *fTestText;
TGButton *fTestButton;
TGColorSelect *fColorSel;
TGMenuBar *fMenuBar;
TGPopupMenu *fMenuFile, *fMenuTest, *fMenuView, *fMenuHelp;
TGPopupMenu *fCascadeMenu, *fCascade1Menu, *fCascade2Menu;
TGPopupMenu *fMenuNew1, *fMenuNew2;
TGLayoutHints *fMenuBarLayout, *fMenuBarItemLayout, *fMenuBarHelpLayout;
public:
TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~TestMainFrame();
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
};
class TestDialog : public TGTransientFrame {
private:
TGCompositeFrame *fFrame1, *fF1, *fF2, *fF3, *fF4, *fF5;
TGGroupFrame *fF6, *fF7;
TGButton *fOkButton, *fCancelButton, *fStartB, *fStopB;
TGButton *fBtn1, *fBtn2, *fChk1, *fChk2, *fRad1, *fRad2;
TGCheckButton *fCheckMulti;
TGListBox *fListBox;
TGComboBox *fCombo;
TGTab *fTab;
TGTextEntry *fTxt1, *fTxt2;
TGLayoutHints *fL1, *fL2, *fL3, *fL4;
TRootEmbeddedCanvas *fEc1, *fEc2;
Int_t fFirstEntry;
Int_t fLastEntry;
Bool_t fFillHistos;
TH1F *fHpx;
TH2F *fHpxpy;
void FillHistos();
public:
TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
UInt_t options = kVerticalFrame);
virtual ~TestDialog();
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestMsgBox : public TGTransientFrame {
private:
TGCompositeFrame *f1, *f2, *f3, *f4, *f5;
TGButton *fTestButton, *fCloseButton;
TGPictureButton *fPictButton;
TGRadioButton *fR[4];
TGCheckButton *fC[13];
TGGroupFrame *fG1, *fG2;
TGLayoutHints *fL1, *fL2, *fL3, *fL4, *fL5, *fL6, *fL21;
TGTextEntry *fTitle, *fMsg;
TGTextBuffer *fTbtitle, *fTbmsg;
TGLabel *fLtitle, *fLmsg;
TGGC fRedTextGC;
public:
TestMsgBox(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
UInt_t options = kVerticalFrame);
virtual ~TestMsgBox();
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestSliders : public TGTransientFrame {
private:
TGVerticalFrame *fVframe1, *fVframe2;
TGLayoutHints *fBly, *fBfly1;
TGHSlider *fHslider1, *fHslider2;
TGVSlider *fVslider1;
TGDoubleVSlider *fVslider2;
TGTextEntry *fTeh1, *fTev1, *fTeh2, *fTev2;
TGTextBuffer *fTbh1, *fTbv1, *fTbh2, *fTbv2;
public:
TestSliders(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestSliders();
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestShutter : public TGTransientFrame {
private:
TGShutter *fShutter;
TGLayoutHints *fLayout;
const TGPicture *fDefaultPic;
public:
TestShutter(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
~TestShutter();
void AddShutterItem(const char *name, shutterData_t data[]);
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestDirList : public TGTransientFrame {
protected:
TGListTree *fContents;
TString DirName(TGListTreeItem* item);
const TGPicture *fIcon;
public:
TestDirList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestDirList();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestFileList : public TGTransientFrame {
protected:
TGFileContainer *fContents;
TGPopupMenu *fMenu;
virtual void DisplayFile(const TString &fname);
virtual void DisplayDirectory(const TString &fname);
virtual void DisplayObject(const TString& fname,const TString& name);
virtual void OnDoubleClick(TGLVEntry*,Int_t);
virtual void DoMenu(Int_t);
public:
TestFileList(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestFileList();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TestProgress : public TGTransientFrame {
private:
TGHorizontalFrame *fHframe1;
TGVerticalFrame *fVframe1;
TGLayoutHints *fHint1, *fHint2, *fHint3, *fHint4, *fHint5;
TGHProgressBar *fHProg1, *fHProg2, *fHProg3;
TGVProgressBar *fVProg1, *fVProg2;
TGTextButton *fGO;
public:
TestProgress(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h);
virtual ~TestProgress();
virtual void CloseWindow();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class EntryTestDlg : public TGTransientFrame {
private:
TGVerticalFrame *fF1;
TGVerticalFrame *fF2;
TGHorizontalFrame *fF[13];
TGLayoutHints *fL1;
TGLayoutHints *fL2;
TGLayoutHints *fL3;
TGLabel *fLabel[13];
TGNumberEntry *fNumericEntries[13];
TGCheckButton *fLowerLimit;
TGCheckButton *fUpperLimit;
TGNumberEntry *fLimits[2];
TGCheckButton *fPositive;
TGCheckButton *fNonNegative;
TGButton *fSetButton;
TGButton *fExitButton;
static const char *const numlabel[13];
static const Double_t numinit[13];
public:
EntryTestDlg(const TGWindow *p, const TGWindow *main);
virtual ~EntryTestDlg();
virtual void CloseWindow();
void SetLimits();
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
};
class Editor : public TGTransientFrame {
private:
TGTextEdit *fEdit; // text edit widget
TGTextButton *fOK; // OK button
TGLayoutHints *fL1; // layout of TGTextEdit
TGLayoutHints *fL2; // layout of OK button
public:
Editor(const TGWindow *main, UInt_t w, UInt_t h);
virtual ~Editor();
void LoadBuffer(const char *buffer);
void LoadFile(const char *file);
TGTextEdit *GetEditor() const { return fEdit; }
void SetTitle();
void Popup();
void CloseWindow();
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
};
class TileFrame : public TGCompositeFrame {
private:
TGCanvas *fCanvas;
public:
TileFrame(const TGWindow *p);
virtual ~TileFrame() { }
void SetCanvas(TGCanvas *canvas) { fCanvas = canvas; }
Bool_t HandleButton(Event_t *event);
};
TileFrame::TileFrame(const TGWindow *p) :
TGCompositeFrame(p, 10, 10, kHorizontalFrame, GetWhitePixel())
{
// Create tile view container. Used to show colormap.
fCanvas = 0;
SetLayoutManager(new TGTileLayout(this, 8));
// Handle only buttons 4 and 5 used by the wheel mouse to scroll
gVirtualX->GrabButton(fId, kButton4, kAnyModifier,
kButtonPressMask | kButtonReleaseMask,
kNone, kNone);
gVirtualX->GrabButton(fId, kButton5, kAnyModifier,
kButtonPressMask | kButtonReleaseMask,
kNone, kNone);
}
Bool_t TileFrame::HandleButton(Event_t *event)
{
// Handle wheel mouse to scroll.
Int_t page = 0;
if (event->fCode == kButton4 || event->fCode == kButton5) {
if (!fCanvas) return kTRUE;
if (fCanvas->GetContainer()->GetHeight())
page = Int_t(Float_t(fCanvas->GetViewPort()->GetHeight() *
fCanvas->GetViewPort()->GetHeight()) /
fCanvas->GetContainer()->GetHeight());
}
if (event->fCode == kButton4) {
//scroll up
Int_t newpos = fCanvas->GetVsbPosition() - page;
if (newpos < 0) newpos = 0;
fCanvas->SetVsbPosition(newpos);
return kTRUE;
}
if (event->fCode == kButton5) {
// scroll down
Int_t newpos = fCanvas->GetVsbPosition() + page;
fCanvas->SetVsbPosition(newpos);
return kTRUE;
}
return kTRUE;
}
TestMainFrame::TestMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{
// Create test main frame. A TGMainFrame is a top level window.
// use hierarchical cleaning
SetCleanup(kDeepCleanup);
// Create menubar and popup menus. The hint objects are used to place
// and group the different menu widgets with respect to eachother.
fMenuDock = new TGDockableFrame(this);
AddFrame(fMenuDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
fMenuDock->SetWindowName("GuiTest Menu");
fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
fMenuFile = new TGPopupMenu(fClient->GetRoot());
fMenuFile->AddEntry("&Open...", M_FILE_OPEN);
fMenuFile->AddEntry("&Save", M_FILE_SAVE);
fMenuFile->AddEntry("S&ave as...", M_FILE_SAVEAS);
fMenuFile->AddEntry("&Close", -1);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Print", M_FILE_PRINT);
fMenuFile->AddEntry("P&rint setup...", M_FILE_PRINTSETUP);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("E&xit", M_FILE_EXIT);
fMenuFile->DisableEntry(M_FILE_SAVEAS);
fMenuFile->HideEntry(M_FILE_PRINT);
fCascade2Menu = new TGPopupMenu(fClient->GetRoot());
fCascade2Menu->AddEntry("ID = 2&3", M_CASCADE_1);
fCascade2Menu->AddEntry("ID = 2&4", M_CASCADE_2);
fCascade2Menu->AddEntry("ID = 2&5", M_CASCADE_3);
fCascade1Menu = new TGPopupMenu(fClient->GetRoot());
fCascade1Menu->AddEntry("ID = 4&1", 41);
fCascade1Menu->AddEntry("ID = 4&2", 42);
fCascade1Menu->AddEntry("ID = 4&3", 43);
fCascade1Menu->AddSeparator();
fCascade1Menu->AddPopup("Cascade&d 2", fCascade2Menu);
fCascadeMenu = new TGPopupMenu(fClient->GetRoot());
fCascadeMenu->AddEntry("ID = 5&1", 51);
fCascadeMenu->AddEntry("ID = 5&2", 52);
fCascadeMenu->AddEntry("ID = 5&3", 53);
fCascadeMenu->AddSeparator();
fCascadeMenu->AddPopup("&Cascaded 1", fCascade1Menu);
fMenuTest = new TGPopupMenu(fClient->GetRoot());
fMenuTest->AddLabel("Test different features...");
fMenuTest->AddSeparator();
fMenuTest->AddEntry("&Dialog...", M_TEST_DLG);
fMenuTest->AddEntry("&Message Box...", M_TEST_MSGBOX);
fMenuTest->AddEntry("&Sliders...", M_TEST_SLIDER);
fMenuTest->AddEntry("Sh&utter...", M_TEST_SHUTTER);
fMenuTest->AddEntry("&List Directory...", M_TEST_DIRLIST);
fMenuTest->AddEntry("&File List...", M_TEST_FILELIST);
fMenuTest->AddEntry("&Progress...", M_TEST_PROGRESS);
fMenuTest->AddEntry("&Number Entry...", M_TEST_NUMBERENTRY);
fMenuTest->AddEntry("F&ont Dialog...", M_TEST_FONTDIALOG);
fMenuTest->AddSeparator();
fMenuTest->AddEntry("Add New Menus", M_TEST_NEWMENU);
fMenuTest->AddSeparator();
fMenuTest->AddPopup("&Cascaded menus", fCascadeMenu);
fMenuView = new TGPopupMenu(gClient->GetRoot());
fMenuView->AddEntry("&Dock", M_VIEW_DOCK);
fMenuView->AddEntry("&Undock", M_VIEW_UNDOCK);
fMenuView->AddSeparator();
fMenuView->AddEntry("Enable U&ndock", M_VIEW_ENBL_DOCK);
fMenuView->AddEntry("Enable &Hide", M_VIEW_ENBL_HIDE);
fMenuView->DisableEntry(M_VIEW_DOCK);
fMenuDock->EnableUndock(kTRUE);
fMenuDock->EnableHide(kTRUE);
fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
fMenuHelp = new TGPopupMenu(fClient->GetRoot());
fMenuHelp->AddEntry("&Contents", M_HELP_CONTENTS);
fMenuHelp->AddEntry("&Search...", M_HELP_SEARCH);
fMenuHelp->AddSeparator();
fMenuHelp->AddEntry("&About", M_HELP_ABOUT);
fMenuNew1 = new TGPopupMenu();
fMenuNew1->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
fMenuNew2 = new TGPopupMenu();
fMenuNew2->AddEntry("Remove New Menus", M_NEW_REMOVEMENU);
// Menu button messages are handled by the main frame (i.e. "this")
// ProcessMessage() method.
fMenuFile->Associate(this);
fMenuTest->Associate(this);
fMenuView->Associate(this);
fMenuHelp->Associate(this);
fCascadeMenu->Associate(this);
fCascade1Menu->Associate(this);
fCascade2Menu->Associate(this);
fMenuNew1->Associate(this);
fMenuNew2->Associate(this);
fMenuBar = new TGMenuBar(fMenuDock, 1, 1, kHorizontalFrame);
fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
fMenuBar->AddPopup("&Test", fMenuTest, fMenuBarItemLayout);
fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout);
fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
fMenuDock->AddFrame(fMenuBar, fMenuBarLayout);
// Create TGCanvas and a canvas container which uses a tile layout manager
fCanvasWindow = new TGCanvas(this, 400, 240);
fContainer = new TileFrame(fCanvasWindow->GetViewPort());
fContainer->SetCanvas(fCanvasWindow);
fCanvasWindow->SetContainer(fContainer);
// use hierarchical cleaning for container
fContainer->SetCleanup(kDeepCleanup);
// Fill canvas with 256 colored frames
for (int i=0; i < 256; ++i)
fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(),
32, 32, 0, TColor::RGB2Pixel(0,0,(i+1)&255)),
new TGLayoutHints(kLHintsExpandY | kLHintsRight));
AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
0, 0, 2, 2));
// Create status frame containing a button and a text entry widget
fStatusFrame = new TGCompositeFrame(this, 60, 20, kHorizontalFrame |
kSunkenFrame);
fTestButton = new TGTextButton(fStatusFrame, "&Open editor...", 150);
fTestButton->Associate(this);
fTestButton->SetToolTipText("Pops up\ntext editor");
fStatusFrame->AddFrame(fTestButton, new TGLayoutHints(kLHintsTop |
kLHintsLeft, 2, 0, 2, 2));
fTestText = new TGTextEntry(fStatusFrame, new TGTextBuffer(100));
fTestText->SetToolTipText("This is a text entry widget");
fTestText->Resize(300, fTestText->GetDefaultHeight());
fStatusFrame->AddFrame(fTestText, new TGLayoutHints(kLHintsTop | kLHintsLeft,
10, 2, 2, 2));
Pixel_t yellow;
fClient->GetColorByName("yellow", yellow);
fColorSel = new TGColorSelect(fStatusFrame, yellow, ColorSel);
fStatusFrame->AddFrame(fColorSel, new TGLayoutHints(kLHintsTop |
kLHintsLeft, 2, 0, 2, 2));
AddFrame(fStatusFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
0, 0, 1, 0));
SetWindowName("GuiTest");
MapSubwindows();
// we need to use GetDefault...() to initialize the layout algorithm...
Resize(); // resize to default size
MapWindow();
Print();
}
TestMainFrame::~TestMainFrame()
{
// Delete all created widgets.
delete fMenuFile;
delete fMenuTest;
delete fMenuView;
delete fMenuHelp;
delete fCascadeMenu;
delete fCascade1Menu;
delete fCascade2Menu;
delete fMenuNew1;
delete fMenuNew2;
delete fContainer;
}
void TestMainFrame::CloseWindow()
{
// Got close message for this MainFrame. Terminate the application
// or returns from the TApplication event loop (depending on the
// argument specified in TApplication::Run()).
gApplication->Terminate(0);
}
Bool_t TestMainFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
// Handle messages send to the TestMainFrame object. E.g. all menu button
// messages.
switch (GET_MSG(msg)) {
case kC_COMMAND:
switch (GET_SUBMSG(msg)) {
case kCM_BUTTON:
//printf("Button was pressed, id = %ld\n", parm1);
if (parm1 == 150) {
Editor *ed = new Editor(this, 600, 400);
ed->LoadBuffer(editortxt);
ed->Popup();
}
break;
case kCM_MENUSELECT:
//printf("Pointer over menu entry, id=%ld\n", parm1);
break;
case kCM_MENU:
switch (parm1) {
case M_FILE_OPEN:
{
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = filetypes;
fi.SetIniDir(dir);
new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
printf("Open file: %s (dir: %s)\n", fi.fFilename,
fi.fIniDir);
dir = fi.fIniDir;
}
break;
case M_FILE_SAVE:
printf("M_FILE_SAVE\n");
break;
case M_FILE_PRINT:
printf("M_FILE_PRINT\n");
printf("Hiding itself, select \"Print Setup...\" to enable again\n");
fMenuFile->HideEntry(M_FILE_PRINT);
break;
case M_FILE_PRINTSETUP:
printf("M_FILE_PRINTSETUP\n");
printf("Enabling \"Print\"\n");
fMenuFile->EnableEntry(M_FILE_PRINT);
break;
case M_FILE_EXIT:
CloseWindow(); // this also terminates theApp
break;
case M_TEST_DLG:
new TestDialog(fClient->GetRoot(), this, 400, 200);
break;
case M_TEST_MSGBOX:
new TestMsgBox(fClient->GetRoot(), this, 400, 200);
break;
case M_TEST_SLIDER:
new TestSliders(fClient->GetRoot(), this, 400, 200);
break;
case M_TEST_SHUTTER:
new TestShutter(fClient->GetRoot(), this, 400, 200);
break;
case M_TEST_DIRLIST:
new TestDirList(gClient->GetRoot(), this, 400, 200);
break;
case M_TEST_FILELIST:
new TestFileList(gClient->GetRoot(), this, 400, 200);
break;
case M_TEST_PROGRESS:
new TestProgress(fClient->GetRoot(), this, 600, 300);
break;
case M_TEST_NUMBERENTRY:
new EntryTestDlg(fClient->GetRoot(), this);
break;
case M_TEST_FONTDIALOG:
{
TGFontDialog::FontProp_t prop;
new TGFontDialog(fClient->GetRoot(), this, &prop);
if (prop.fName != "")
printf("Selected font: %s, size %d, italic %s, bold %s, color 0x%lx, align %u\n",
prop.fName.Data(), prop.fSize, prop.fItalic ? "yes" : "no",
prop.fBold ? "yes" : "no", prop.fColor, prop.fAlign);
}
break;
case M_TEST_NEWMENU:
{
if (fMenuTest->IsEntryChecked(M_TEST_NEWMENU)) {
ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU),
M_NEW_REMOVEMENU, 0);
return kTRUE;
}
fMenuTest->CheckEntry(M_TEST_NEWMENU);
TGPopupMenu *p = fMenuBar->GetPopup("Test");
fMenuBar->AddPopup("New 1", fMenuNew1, fMenuBarItemLayout, p);
p = fMenuBar->GetPopup("Help");
fMenuBar->AddPopup("New 2", fMenuNew2, fMenuBarItemLayout, p);
fMenuBar->MapSubwindows();
fMenuBar->Layout();
TGMenuEntry *e = fMenuTest->GetEntry("Add New Menus");
fMenuTest->AddEntry("Remove New Menus", M_NEW_REMOVEMENU, 0, 0, e);
}
break;
case M_NEW_REMOVEMENU:
{
fMenuBar->RemovePopup("New 1");
fMenuBar->RemovePopup("New 2");
fMenuBar->Layout();
fMenuTest->DeleteEntry(M_NEW_REMOVEMENU);
fMenuTest->UnCheckEntry(M_TEST_NEWMENU);
}
break;
case M_VIEW_ENBL_DOCK:
fMenuDock->EnableUndock(!fMenuDock->EnableUndock());
if (fMenuDock->EnableUndock()) {
fMenuView->CheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->EnableEntry(M_VIEW_UNDOCK);
} else {
fMenuView->UnCheckEntry(M_VIEW_ENBL_DOCK);
fMenuView->DisableEntry(M_VIEW_UNDOCK);
}
break;
case M_VIEW_ENBL_HIDE:
fMenuDock->EnableHide(!fMenuDock->EnableHide());
if (fMenuDock->EnableHide()) {
fMenuView->CheckEntry(M_VIEW_ENBL_HIDE);
} else {
fMenuView->UnCheckEntry(M_VIEW_ENBL_HIDE);
}
break;
case M_VIEW_DOCK:
fMenuDock->DockContainer();
fMenuView->EnableEntry(M_VIEW_UNDOCK);
fMenuView->DisableEntry(M_VIEW_DOCK);
break;
case M_VIEW_UNDOCK:
fMenuDock->UndockContainer();
fMenuView->EnableEntry(M_VIEW_DOCK);
fMenuView->DisableEntry(M_VIEW_UNDOCK);
break;
default:
break;
}
default:
break;
}
default:
break;
}
if (fMenuDock->IsUndocked()) {
fMenuView->EnableEntry(M_VIEW_DOCK);
fMenuView->DisableEntry(M_VIEW_UNDOCK);
} else {
fMenuView->EnableEntry(M_VIEW_UNDOCK);
fMenuView->DisableEntry(M_VIEW_DOCK);
}
return kTRUE;
}
TestDialog::TestDialog(const TGWindow *p, const TGWindow *main, UInt_t w,
UInt_t h, UInt_t options)
: TGTransientFrame(p, main, w, h, options)
{
// Create a dialog window. A dialog window pops up with respect to its
// "main" window.
// use hierarchical cleani
SetCleanup(kDeepCleanup);
fFrame1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
fOkButton = new TGTextButton(fFrame1, "&Ok", 1);
fOkButton->Associate(this);
fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2);
fCancelButton->Associate(this);
fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
2, 2, 2, 2);
fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1);
fFrame1->AddFrame(fOkButton, fL1);
fFrame1->AddFrame(fCancelButton, fL1);
fFrame1->Resize(150, fOkButton->GetDefaultHeight());
AddFrame(fFrame1, fL2);
//--------- create Tab widget and some composite frames for Tab testing
fTab = new TGTab(this, 300, 300);
fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
TGCompositeFrame *tf = fTab->AddTab("Tab 1");
fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF1->AddFrame(new TGTextButton(fF1, "&Test button", 0), fL3);
fF1->AddFrame(fTxt1 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
fF1->AddFrame(fTxt2 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3);
tf->AddFrame(fF1, fL3);
fTxt1->Resize(150, fTxt1->GetDefaultHeight());
fTxt2->Resize(150, fTxt2->GetDefaultHeight());
tf = fTab->AddTab("Tab 2");
fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
200, 2, 2, 2);
fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF2->AddFrame(fBtn1 = new TGTextButton(fF2, "&Button 1", 0), fL1);
fF2->AddFrame(fBtn2 = new TGTextButton(fF2, "B&utton 2", 0), fL1);
fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "C&heck 1", 0), fL1);
fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Chec&k 2", 0), fL1);
fF2->AddFrame(fRad1 = new TGRadioButton(fF2, "&Radio 1", 81), fL1);
fF2->AddFrame(fRad2 = new TGRadioButton(fF2, "R&adio 2", 82), fL1);
fCombo = new TGComboBox(fF2, 88);
fF2->AddFrame(fCombo, fL3);
tf->AddFrame(fF2, fL3);
int i;
for (i = 0; i < 20; i++) {
char tmp[20];
sprintf(tmp, "Entry %i", i+1);
fCombo->AddEntry(tmp, i+1);
}
fCombo->Resize(150, 20);
fBtn1->Associate(this);
fBtn2->Associate(this);
fChk1->Associate(this);
fChk2->Associate(this);
fRad1->Associate(this);
fRad2->Associate(this);
//-------------- embedded canvas demo
fFillHistos = kFALSE;
fHpx = 0;
fHpxpy = 0;
tf = fTab->AddTab("Tab 3");
fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame);
fStartB = new TGTextButton(fF3, "Start &Filling Hists", 40);
fStopB = new TGTextButton(fF3, "&Stop Filling Hists", 41);
fStartB->Associate(this);
fStopB->Associate(this);
fF3->AddFrame(fStartB, fL3);
fF3->AddFrame(fStopB, fL3);
fF5 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame);
fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX |
kLHintsExpandY, 5, 5, 5, 5);
fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 100);
fF5->AddFrame(fEc1, fL4);
fEc2 = new TRootEmbeddedCanvas("ec2", fF5, 100, 100);
fF5->AddFrame(fEc2, fL4);
tf->AddFrame(fF3, fL3);
tf->AddFrame(fF5, fL4);
fEc1->GetCanvas()->SetBorderMode(0);
fEc2->GetCanvas()->SetBorderMode(0);
// make tab yellow
Pixel_t yellow;
fClient->GetColorByName("yellow", yellow);
TGTabElement *tabel = fTab->GetTabTab("Tab 3");;
tabel->ChangeBackground(yellow);
//-------------- end embedded canvas demo
TGTextButton *bt;
tf = fTab->AddTab("Tab 4");
fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
fF4->AddFrame(bt = new TGTextButton(fF4, "A&dd Entry", 90), fL3);
bt->Associate(this);