Newer
Older
Bertrand Bellenot
committed
// @(#)root/test:$name: $:$id: stressGUI.cxx,v 1.0 exp $
// Author: Bertrand Bellenot
//
// ROOT GUI test suite.
//
// The suite of programs below tests many elements of the ROOT GUI classes
//
// The test can only be run as a standalone program.
// To build and run it:
//
// make stressGUI
// stressGUI
//
// To get a short help:
// stressGUI -help
//
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <snprintf.h>
Bertrand Bellenot
committed
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
#include <TString.h>
#include <TROOT.h>
#include <TClass.h>
#include <TEnv.h>
#include <TError.h>
#include <TBenchmark.h>
#include <TSystem.h>
#include <TApplication.h>
#include <TDatime.h>
#include <TFile.h>
#include <TObjArray.h>
#include <TGFrame.h>
#include <TImage.h>
#include <TCanvas.h>
#include <TMD5.h>
#include <TG3DLine.h>
#include <TGButton.h>
#include <TGButtonGroup.h>
#include <TGColorDialog.h>
#include <TGComboBox.h>
#include <TGLabel.h>
#include <TGListBox.h>
#include <TGListTree.h>
#include <TGMenu.h>
#include <TGMsgBox.h>
#include <TGNumberEntry.h>
#include <TGProgressBar.h>
#include <TGResourcePool.h>
#include <TGShutter.h>
#include <TGSimpleTable.h>
#include <TGTextEdit.h>
#include <TRootCanvas.h>
#include <TGTab.h>
#include <TGPack.h>
#include <TGColorDialog.h>
#include <TGFontDialog.h>
#include <TGTextEditDialogs.h>
#include <TGTableLayout.h>
#include <TGMdi.h>
#include <TGSlider.h>
#include <TGDoubleSlider.h>
#include <TGTripleSlider.h>
#include <TBrowser.h>
#include <TGPasswdDialog.h>
#include <TGImageMap.h>
#include <TASPaletteEditor.h>
#include <TControlBar.h>
Bertrand Bellenot
committed
#include <TGSpeedo.h>
#include <TGShapedFrame.h>
#include <TGSplitFrame.h>
#include <TGTextEditor.h>
#include <TRootHelpDialog.h>
#include <TGHtmlBrowser.h>
Bertrand Bellenot
committed
#include <HelpText.h>
#include <TSystemDirectory.h>
#include <TInterpreter.h>
#include <TStopwatch.h>
Bertrand Bellenot
committed
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
#include <TRecorder.h>
void stressGUI();
void ProcessFrame(TGFrame *f, const char *title);
// Tests functions.
void testLayout();
void testTextAlign();
void testGroupState();
void testLabels();
void testSplitButton();
void testTextEntries();
void testListTree();
void testShutter();
void testProgressBar();
void testNumberEntry();
void testEditor();
void testCanvas();
void testColorDlg();
void testFontDlg();
void testSearchDlg();
void testTableLayout();
void testPack();
void testSliders();
void testBrowsers();
void testSplitFrame();
void testControlBars();
void testHelpDialog();
void testPaletteEditor();
void testHtmlBrowser();
Bertrand Bellenot
committed
void run_tutorials();
void guitest_playback();
void dnd_playback();
void mditest_playback();
void fitpanel_playback();
void graph_edit_playback();
// Global variables.
RedirectHandle_t gRH;
Int_t gTestNum = 0;
Bool_t gOptionRef = kFALSE;
Bool_t gOptionKeep = kFALSE;
Bool_t gOptionFull = kFALSE;
char outfile[80];
char gLine[80];
Int_t sizes[100];
TString gTmpfilename;
TString gRootSys;
FILE *sgref = 0;
////////////////////////////////////////////////////////////////////////////////
/// Application main entry point.
Bertrand Bellenot
committed
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
int main(int argc, char *argv[])
{
// use $ROOTSYS/etc/system.rootrc default values
gEnv->ReadFile(TString::Format("%s/etc/system.rootrc",
gSystem->Getenv("ROOTSYS")), kEnvAll);
gOptionRef = kFALSE;
gOptionKeep = kFALSE;
gOptionFull = kFALSE;
gTmpfilename = "stress-gui";
FILE *f = gSystem->TempFileName(gTmpfilename);
fclose(f);
for (int i = 0; i < argc; i++) {
if (!strcmp(argv[i], "-ref")) gOptionRef = kTRUE;
if (!strcmp(argv[i], "-keep")) gOptionKeep = kTRUE;
if (!strcmp(argv[i], "-full")) gOptionFull = kTRUE;
if (!strcmp(argv[i], "-help") || !strcmp(argv[i], "-?")) {
printf("Usage: stressGUI [-ref] [-keep] [-full] [-help] [-?] \n");
printf("Options:\n");
printf("\n");
printf(" -ref: Generate the reference output file \"stressGUI.ref\"\n");
printf("\n");
printf(" -keep: Keep the png files even for passed tests\n");
printf(" (by default the png files are deleted)\n");
printf("\n");
printf(" -full: Full test: replay also recorder sessions\n");
printf(" (guitest, drag and drop, fitpanel, ...)\n");
printf("\n");
printf(" -help, -?: Print usage and exit\n");
return 0;
}
}
TApplication theApp("App", &argc, argv);
gBenchmark = new TBenchmark();
stressGUI();
theApp.Terminate();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Run all stress GUI tests.
Bertrand Bellenot
committed
void stressGUI()
{
if (gOptionRef) {
sgref = fopen("stressGUI.ref", "wt");
}
else {
// Read the reference file "stressGUI.ref"
sgref = fopen("stressGUI.ref", "rt");
if (sgref == 0) {
printf("\nReference file \"stressGUI.ref\" not found!\n");
printf("Please generate the reference file by executing\n");
printf("stressGUI with the -ref flag, as shown below:\n");
printf(" stressGUI -ref\n");
gSystem->Unlink(gTmpfilename.Data());
Bertrand Bellenot
committed
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
exit(0);
}
char line[160];
Int_t i = -1;
while (fgets(line, 160, sgref)) {
if ((i >= 0) && (strlen(line) > 15)) {
sscanf(&line[8], "%d", &sizes[i]);
}
i++;
}
fclose(sgref);
}
gRootSys = gSystem->UnixPathName(gSystem->Getenv("ROOTSYS"));
#ifdef WIN32
// remove the drive letter (e.g. "C:/") from $ROOTSYS, if any
if (gRootSys[1] == ':' && gRootSys[2] == '/')
gRootSys.Remove(0, 2);
#endif
gVirtualX->Warp(gClient->GetDisplayWidth()-50, gClient->GetDisplayHeight()-50,
gClient->GetDefaultRoot()->GetId());
// uncomment the next few lines to avoid (forbid) any mouse interaction
// gVirtualX->GrabPointer(gClient->GetDefaultRoot()->GetId(), kButtonPressMask |
// kButtonReleaseMask | kPointerMotionMask, kNone,
// gVirtualX->CreateCursor(kWatch), kTRUE, kFALSE);
if (gOptionRef) {
fprintf(sgref, "Test# Size#\n");
} else {
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting GUI - S T R E S S suite *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
}
gTestNum = 0;
gBenchmark->Start("stressGUI");
if (!gOptionRef) {
std::cout << "* Running macros in $ROOTSYS/tutorials/gui - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
}
run_tutorials();
if (!gOptionRef) {
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting Basic GUI Widgets - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
}
testLayout();
testTextAlign();
testGroupState();
testLabels();
testSplitButton();
testTextEntries();
testListTree();
testShutter();
testProgressBar();
testNumberEntry();
testTableLayout();
if (!gOptionRef) {
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting High Level GUI Widgets - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
}
testPack();
testSearchDlg();
testFontDlg();
testColorDlg();
testEditor();
testCanvas();
testSliders();
testBrowsers();
testSplitFrame();
testControlBars();
testHelpDialog();
testPaletteEditor();
testHtmlBrowser();
Bertrand Bellenot
committed
if (!gOptionRef) {
if (gOptionFull) {
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting Drag and Drop playback - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
dnd_playback();
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting MDI test playback - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
mditest_playback();
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting guitest recorder playback - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
guitest_playback();
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting fit panel recorder playback - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
fitpanel_playback();
std::cout << "**********************************************************************" <<std::endl;
std::cout << "* Starting graphic editors recorder playback - S T R E S S *" <<std::endl;
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
graph_edit_playback();
}
std::cout << "**********************************************************************" <<std::endl;
Bertrand Bellenot
committed
gBenchmark->Stop("stressGUI");
//Print table with results
Bool_t UNIX = strcmp(gSystem->GetName(), "Unix") == 0;
if (UNIX) {
Bertrand Bellenot
committed
TString sp = gSystem->GetFromPipe("uname -a");
sp.Resize(60);
printf("* SYS: %s\n",sp.Data());
if (strstr(gSystem->GetBuildNode(),"Linux")) {
sp = gSystem->GetFromPipe("lsb_release -d -s");
printf("* SYS: %s\n",sp.Data());
}
if (strstr(gSystem->GetBuildNode(),"Darwin")) {
sp = gSystem->GetFromPipe("sw_vers -productVersion");
sp += " Mac OS X ";
printf("* SYS: %s\n",sp.Data());
}
Bertrand Bellenot
committed
} else {
Bertrand Bellenot
committed
const char *os = gSystem->Getenv("OS");
Bertrand Bellenot
committed
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
if (!os) printf("* SYS: Windows 95\n");
else printf("* SYS: %s %s \n",os,gSystem->Getenv("PROCESSOR_IDENTIFIER"));
}
printf("**********************************************************************\n");
printf("* ");
gBenchmark->Print("stressGUI");
Double_t ct = gBenchmark->GetCpuTime("stressGUI"); // ref: 13 s
Double_t rt = gBenchmark->GetRealTime("stressGUI"); // ref: 300 s
// normalize at 1000 rootmarks
Double_t full_marks = 0.5 *((13.0/ct) + (300.0/rt));
if (!gOptionFull)
full_marks = 0.5 *((4.5/ct) + (35.0/rt));
const Double_t rootmarks = 1000.0 * full_marks;
printf("**********************************************************************\n");
printf("* ROOTMARKS = %6.1f * Root%-8s %d/%04d\n", rootmarks, gROOT->GetVersion(),
gROOT->GetVersionDate(), gROOT->GetVersionTime());
printf("**********************************************************************\n");
}
gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE); // ungrab pointer
if (gOptionRef) {
fclose(sgref);
}
gSystem->Unlink(gTmpfilename.Data());
#ifdef WIN32
gSystem->Exec("erase /q /s TxtEdit* >nul 2>&1");
gSystem->Exec("erase /q /s TxtView* >nul 2>&1");
#else
gSystem->Exec("rm -f TxtEdit*");
gSystem->Exec("rm -f TxtView*");
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Utilities
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// Return the size of the file "filename".
Bertrand Bellenot
committed
Int_t FileSize(const char *filename)
{
FileStat_t fs;
if (gSystem->GetPathInfo(filename, fs) == 0)
return (Int_t)fs.fSize;
return 0;
Bertrand Bellenot
committed
}
////////////////////////////////////////////////////////////////////////////////
/// Verify the file size.
Bertrand Bellenot
committed
Bool_t VerifySize(const char *filename, const char *title)
{
Int_t ftol = 0;
Bool_t success = kFALSE;
Int_t fsize = FileSize(filename);
// results depends on the files in $ROOTSYS/test
if (strstr(title, "Browser")) ftol = 350;
// not relevant as the CPU load and the background may vary...
if (strstr(title, "CPUMeter.C")) ftol = 50000;
if (strstr(title, "games.C")) ftol = 150;
if (strstr(title, "ntupleTableTest.C")) ftol = 100;
if (!gOptionRef) {
if ((fsize < sizes[gTestNum] - ftol) || (fsize > sizes[gTestNum] + ftol))
success = kFALSE;
else
success = kTRUE;
snprintf(gLine,80,"Test %2d: %s", gTestNum, title);
Bertrand Bellenot
committed
const Int_t nch = strlen(gLine);
if (success) {
std::cout << gLine;
for (Int_t i = nch; i < 67; i++) std::cout << ".";
std::cout << " OK" << std::endl;
Bertrand Bellenot
committed
} else {
std::cout << gLine;
for (Int_t i = nch; i < 63; i++) std::cout << ".";
std::cout << " FAILED" << std::endl;
std::cout << " File Size = " << fsize << std::endl;
std::cout << " Ref Size = " << sizes[gTestNum] << std::endl;
Bertrand Bellenot
committed
}
} else {
fprintf(sgref, "%5d%10d\n", gTestNum, fsize);
success = kTRUE;
}
if (!gOptionKeep && success) gSystem->Unlink(filename);
return success;
}
////////////////////////////////////////////////////////////////////////////////
/// Save a capture of frame f in a png file.
Bertrand Bellenot
committed
void ProcessFrame(TGFrame *f, const char *title)
{
Bertrand Bellenot
committed
gSystem->ProcessEvents();
gSystem->Sleep(250);
Bertrand Bellenot
committed
gSystem->ProcessEvents();
gErrorIgnoreLevel = 9999;
if (gOptionRef)
snprintf(outfile,80, "sgui_%02d_ref.png", gTestNum);
Bertrand Bellenot
committed
else
snprintf(outfile,80, "sgui_%02d.png", gTestNum);
Bertrand Bellenot
committed
TImage *img = TImage::Create();
f->RaiseWindow();
img->FromWindow(f->GetId());
img->WriteImage(outfile);
if (!gOptionRef) {
if (!strstr(title, "Pack Frames") &&
!strstr(title, "HTML Browser")) {
Bertrand Bellenot
committed
gSystem->RedirectOutput(gTmpfilename.Data(), "w", &gRH);
((TGMainFrame *)f)->SaveSource(Form("sgui_%02d.C", gTestNum));
gSystem->Unlink(Form("sgui_%02d.C", gTestNum));
gSystem->RedirectOutput(0, 0, &gRH);
}
}
VerifySize(outfile, title);
delete img;
gErrorIgnoreLevel = 0;
gTestNum++;
}
////////////////////////////////////////////////////////////////////////////////
/// Verify the size of a png file generated from a root macro.
Bertrand Bellenot
committed
void ProcessMacro(const char *macro, const char *title)
{
Int_t nbpass = 1, npass = 0;
TString capture = macro;
capture.ReplaceAll(".C", "_0.png");
if (strstr(macro, "games.C")) nbpass = 3;
if (strstr(macro, "galaxy_image.C")) nbpass = 2;
while (npass < nbpass) {
++npass;
capture.ReplaceAll(TString::Format("_%d.png", npass-1),
TString::Format("_%d.png", npass));
VerifySize(capture.Data(), title);
gTestNum++;
}
}
////////////////////////////////////////////////////////////////////////////////
Bertrand Bellenot
committed
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
void CloseMainframes()
{
TClass* clGMainFrame = TClass::GetClass("TGMainFrame");
TGWindow* win = 0;
TIter iWin(gClient->GetListOfWindows());
while ((win = (TGWindow*)iWin())) {
const TObject* winGetParent = win->GetParent();
Bool_t winIsMapped = kFALSE;
if (winGetParent == gClient->GetDefaultRoot())
winIsMapped = win->IsMapped();
if (winIsMapped && win->InheritsFrom(clGMainFrame)) {
((TGMainFrame *)win)->CloseWindow();
gSystem->Sleep(100);
}
gSystem->ProcessEvents();
}
gSystem->Sleep(100);
}
////////////////////////////////////////////////////////////////////////////////
// GUI Test code
////////////////////////////////////////////////////////////////////////////////
class ButtonLayoutWindow : public TGMainFrame {
private:
TGTextButton *test, *draw, *help, *ok, *cancel, *exit;
public:
ButtonLayoutWindow(const TGWindow *p, UInt_t w, UInt_t h);
};
////////////////////////////////////////////////////////////////////////////////
/// Create a container frames containing buttons
Bertrand Bellenot
committed
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
ButtonLayoutWindow::ButtonLayoutWindow(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
// one button is resized up to the parent width. Note! this width should be fixed!
TGVerticalFrame *hframe1 = new TGVerticalFrame(this, 170, 50, kFixedWidth);
test = new TGTextButton(hframe1, "&Test ");
// to take whole space we need to use kLHintsExpandX layout hints
hframe1->AddFrame(test, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,2,0,2,2));
AddFrame(hframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
// two buttons are resized up to the parent width. Note! this width should be fixed!
TGCompositeFrame *cframe1 = new TGCompositeFrame(this, 170, 20, kHorizontalFrame | kFixedWidth);
draw = new TGTextButton(cframe1, "&Draw");
// to share whole parent space we need to use kLHintsExpandX layout hints
cframe1->AddFrame(draw, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,2,2,2,2));
// button background will be set to yellow
ULong_t yellow;
gClient->GetColorByName("yellow", yellow);
help = new TGTextButton(cframe1, "&Help");
help->ChangeBackground(yellow);
cframe1->AddFrame(help, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,2,2,2,2));
AddFrame(cframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
// three buttons are resized up to the parent width. Note! this width should be fixed!
TGCompositeFrame *cframe2 = new TGCompositeFrame(this, 170, 20, kHorizontalFrame | kFixedWidth);
ok = new TGTextButton(cframe2, "OK");
ok->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
ok->SetEnabled(kFALSE);
// to share whole parent space we need to use kLHintsExpandX layout hints
cframe2->AddFrame(ok, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,3,2,2,2));
TGGC myGC = *gClient->GetResourcePool()->GetFrameGC();
//TGFont *myfont = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
cancel = new TGTextButton(cframe2, "Cancel ");
cancel->SetText("&Cancel ");
//if (myfont) cancel->SetFont(myfont->GetFontHandle());
ok->SetEnabled(kTRUE);
cancel->SetTextColor(yellow);
cancel->SetState(kButtonEngaged);
cframe2->AddFrame(cancel, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,3,2,2,2));
exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,2,0,2,2));
exit->SetText("&Exit ");
AddFrame(cframe2, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
SetWindowName("Buttons' Layout");
MapSubwindows();
Layout();
Resize(GetDefaultSize());
SetWMPosition(0, 0);
MapWindow();
}
////////////////////////////////////////////////////////////////////////////////
/// Test layout and different states of some buttons.
Bertrand Bellenot
committed
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
void testLayout()
{
ButtonLayoutWindow *f = new ButtonLayoutWindow(gClient->GetRoot(), 100, 100);
ProcessFrame((TGMainFrame*)f, "Buttons 1 (layout)");
f->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
class TextMargin : public TGHorizontalFrame {
protected:
TGNumberEntry *fEntry;
public:
TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p)
{
fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
AddFrame(fEntry, new TGLayoutHints(kLHintsLeft));
TGLabel *label = new TGLabel(this, name);
AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
}
TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }
};
class TextAlignWindow : public TGMainFrame {
protected:
TGTextButton *fButton; // button being tested
public:
TextAlignWindow();
void SetTextPosition(Int_t hid, Int_t vid);
};
////////////////////////////////////////////////////////////////////////////////
/// Set text position (alignment).
Bertrand Bellenot
committed
void TextAlignWindow::SetTextPosition(Int_t hid, Int_t vid)
{
Int_t tj = fButton->GetTextJustify();
tj &= ~kTextCenterX;
tj &= ~kTextLeft;
tj &= ~kTextRight;
tj &= ~kTextCenterY;
tj &= ~kTextTop;
tj &= ~kTextBottom;
tj |= hid;
tj |= vid;
fButton->SetTextJustify(tj);
}
////////////////////////////////////////////////////////////////////////////////
/// Main test window.
Bertrand Bellenot
committed
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
TextAlignWindow::TextAlignWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
{
SetCleanup(kDeepCleanup);
// Controls on right
TGVerticalFrame *controls = new TGVerticalFrame(this);
AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5));
// Separator
TGVertical3DLine *separator = new TGVertical3DLine(this);
AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
// Contents
TGHorizontalFrame *contents = new TGHorizontalFrame(this);
AddFrame(contents, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5));
// The button for test
fButton = new TGTextButton(contents,
"&This button has a multi-line label\nand shows features\navailable in the button classes");
fButton->Resize(300, 200);
fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also", 200);
contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 20, 20, 20, 20));
TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
group->SetTitlePos(TGGroupFrame::kCenter);
TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
disable->SetOn();
group->AddFrame(disable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
controls->AddFrame(group, new TGLayoutHints(kLHintsExpandX));
// control horizontal position of the text
TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
horizontal->SetTitlePos(TGGroupFrame::kCenter);
new TGRadioButton(horizontal, "Center", kTextCenterX);
new TGRadioButton(horizontal, "Left", kTextLeft);
new TGRadioButton(horizontal, "Right", kTextRight);
horizontal->SetButton(kTextCenterX);
controls->AddFrame(horizontal, new TGLayoutHints(kLHintsExpandX));
// control vertical position of the text
TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
vertical->SetTitlePos(TGGroupFrame::kCenter);
new TGRadioButton(vertical, "Center", kTextCenterY);
new TGRadioButton(vertical, "Top", kTextTop);
new TGRadioButton(vertical, "Bottom", kTextBottom);
vertical->SetButton(kTextCenterY);
controls->AddFrame(vertical, new TGLayoutHints(kLHintsExpandX));
// control margins of the text
TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
margins->SetTitlePos(TGGroupFrame::kCenter);
TextMargin *left = new TextMargin(margins, "Left");
margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
TextMargin *right = new TextMargin(margins, "Right");
margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
TextMargin *top = new TextMargin(margins, "Top");
margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
TextMargin *bottom = new TextMargin(margins, "Bottom");
margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
TGTextButton *quit = new TGTextButton(controls, "Quit");
controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 0, 0, 5));
SetWindowName("Button Test");
MapSubwindows();
Layout();
Resize(GetDefaultSize());
SetWMPosition(0, 0);
MapWindow();
}
////////////////////////////////////////////////////////////////////////////////
/// Test different text alignments in a TGTextButton.
Bertrand Bellenot
committed
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
void testTextAlign()
{
TextAlignWindow *f = new TextAlignWindow();
ProcessFrame((TGMainFrame*)f, "Buttons 2 (text alignment)");
f->SetTextPosition(kTextLeft, kTextTop);
ProcessFrame((TGMainFrame*)f, "Buttons 3 (text alignment)");
f->SetTextPosition(kTextCenterX, kTextTop);
ProcessFrame((TGMainFrame*)f, "Buttons 4 (text alignment)");
f->SetTextPosition(kTextRight, kTextTop);
ProcessFrame((TGMainFrame*)f, "Buttons 5 (text alignment)");
f->SetTextPosition(kTextRight, kTextCenterY);
ProcessFrame((TGMainFrame*)f, "Buttons 6 (text alignment)");
f->SetTextPosition(kTextRight, kTextBottom);
ProcessFrame((TGMainFrame*)f, "Buttons 7 (text alignment)");
f->SetTextPosition(kTextCenterX, kTextBottom);
ProcessFrame((TGMainFrame*)f, "Buttons 8 (text alignment)");
f->SetTextPosition(kTextLeft, kTextBottom);
ProcessFrame((TGMainFrame*)f, "Buttons 9 (text alignment)");
f->SetTextPosition(kTextLeft, kTextCenterY);
ProcessFrame((TGMainFrame*)f, "Buttons 10 (text alignment)");
f->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
class GroupStateWindow : public TGMainFrame {
public:
TGTextButton *fExit; // Exit text button
TGVButtonGroup *fButtonGroup; // Button group
TGCheckButton *fCheckb[4]; // Check buttons
TGRadioButton *fRadiob[2]; // Radio buttons
public:
GroupStateWindow(const TGWindow *p, UInt_t w, UInt_t h);
};
////////////////////////////////////////////////////////////////////////////////
/// Main window constructor.
Bertrand Bellenot
committed
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
GroupStateWindow::GroupStateWindow(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"), 100);
fCheckb[0]->SetToolTipText("Enable/Disable the button group");
fHL2->AddFrame(fCheckb[0], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"), 101);
fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"), 102);
fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"), 103);
fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"), 104);
fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"), 105);
fButtonGroup->Show();
fHL2->AddFrame(fButtonGroup, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
AddFrame(fHL2);
TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
fExit = new TGTextButton(fHL3, "&Exit", 106);
fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
//Default state
fCheckb[0]->SetOn();
fButtonGroup->SetState(kTRUE);
SetWindowName("My Button Group");
MapSubwindows();
Layout();
Resize(GetDefaultSize());
SetWMPosition(0, 0);
MapWindow();
fButtonGroup->SetRadioButtonExclusive(kTRUE);
fRadiob[1]->SetOn();
};
////////////////////////////////////////////////////////////////////////////////
/// Test enabled/disabled state of button group.
Bertrand Bellenot
committed
void testGroupState()
{
GroupStateWindow *f = new GroupStateWindow(gClient->GetRoot(), 100, 100);
ProcessFrame((TGMainFrame*)f, "Buttons 11 (group state)");
f->fCheckb[0]->SetOn(kFALSE);
f->fButtonGroup->SetState(kFALSE);
ProcessFrame((TGMainFrame*)f, "Buttons 12 (group state)");
f->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
class LabelsWindow : public TGMainFrame {
private:
TGLabel *fLbl1, *fLbl2, *fLbl3, *fLbl4;
public:
LabelsWindow(const TGWindow *p, UInt_t w, UInt_t h);
void SwitchState();
};
////////////////////////////////////////////////////////////////////////////////
/// Main window constructor.
Bertrand Bellenot
committed
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
LabelsWindow::LabelsWindow(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
// label + horizontal line
TGGC *fTextGC;
const TGFont *font = gClient->GetFont("-*-times-bold-r-*-*-18-*-*-*-*-*-*-*");
if (!font)
font = gClient->GetResourcePool()->GetDefaultFont();
FontStruct_t labelfont = font->GetFontStruct();
GCValues_t gval;
gval.fMask = kGCBackground | kGCFont | kGCForeground;
gval.fFont = font->GetFontHandle();
gClient->GetColorByName("yellow", gval.fBackground);
fTextGC = gClient->GetGC(&gval, kTRUE);
ULong_t bcolor, ycolor;
gClient->GetColorByName("yellow", ycolor);
gClient->GetColorByName("blue", bcolor);
// Create a main frame
fLbl1 = new TGLabel(this, "OwnFont & Bck/ForgrColor", fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
AddFrame(fLbl1, new TGLayoutHints(kLHintsNormal, 5, 5, 3, 4));
fLbl1->SetTextColor(ycolor);
fLbl2 = new TGLabel(this, "Own Font & ForegroundColor", fTextGC->GetGC(), labelfont);
AddFrame(fLbl2, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl2->SetTextColor(ycolor);
fLbl3 = new TGLabel(this, "Normal Label");
AddFrame(fLbl3, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl4 = new TGLabel(this, "Multi-line label, resized\nto 300x80 pixels",
fTextGC->GetGC(), labelfont, kChildFrame, bcolor);
AddFrame(fLbl4, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
fLbl4->SetTextColor(ycolor);
fLbl4->ChangeOptions(fLbl4->GetOptions() | kFixedSize);
fLbl4->Resize(350, 80);
// Create a horizontal frame containing two buttons
TGTextButton *toggle = new TGTextButton(this, "&Toggle Labels");
toggle->SetToolTipText("Click on the button to toggle label's state (enable/disable)");
AddFrame(toggle, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
TGTextButton *exit = new TGTextButton(this, "&Exit ");
AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
// Set a name to the main frame
SetWindowName("Labels");
MapSubwindows();
Layout();
Resize(GetDefaultSize());
SetWMPosition(0, 0);
MapWindow();
}
////////////////////////////////////////////////////////////////////////////////
/// Switch state of the labels.
Bertrand Bellenot
committed
void LabelsWindow::SwitchState()
{
if (fLbl1->IsDisabled()) {
fLbl1->Enable();
fLbl2->Enable();
fLbl3->Enable();
fLbl4->Enable();
} else {
fLbl1->Disable();
fLbl2->Disable();
fLbl3->Disable();
fLbl4->Disable();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Test different styles and the enabled/disabled state of labels.
Bertrand Bellenot
committed
void testLabels()
{
LabelsWindow *f = new LabelsWindow(gClient->GetRoot(), 200, 200);
ProcessFrame((TGMainFrame*)f, "Labels 1");
f->SwitchState();
ProcessFrame((TGMainFrame*)f, "Labels 2");
f->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
class SplitButtonWindow : public TGMainFrame {
public:
TGCheckButton *fCButton;
TGCheckButton *fEButton;
TGSplitButton *fMButton; // Split Button
TGPopupMenu *fPopMenu; // TGpopupMenu that will be attached to
// the button.
public:
SplitButtonWindow(const TGWindow *p, UInt_t w, UInt_t h);
};
////////////////////////////////////////////////////////////////////////////////
/// Main window constructor.
Bertrand Bellenot
committed
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
SplitButtonWindow::SplitButtonWindow(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
TGVerticalFrame *fVL = new TGVerticalFrame(this, 100, 100);
TGHorizontalFrame *fHL = new TGHorizontalFrame(fVL, 100, 40);
// Create a popup menu.
fPopMenu = new TGPopupMenu(gClient->GetRoot());
fPopMenu->AddEntry("Button &1", 1001);
fPopMenu->AddEntry("Button &2", 1002);
fPopMenu->DisableEntry(1002);
fPopMenu->AddEntry("Button &3", 1003);
fPopMenu->AddSeparator();
// Create a split button, the menu is adopted.
fMButton = new TGSplitButton(fHL, new TGHotString("Button &Options"),
fPopMenu, 1101);
// It is possible to add entries later
fPopMenu->AddEntry("En&try with really really long name", 1004);
fPopMenu->AddEntry("&Exit", 1005);
fCButton = new TGCheckButton(fHL, new TGHotString("Split"), 1102);
fCButton->SetState(kButtonDown);
// Add frames to their parent for layout.
fHL->AddFrame(fCButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
0, 10, 0, 0));
fEButton = new TGCheckButton(fHL, new TGHotString("Enable"), 1103);
fEButton->SetState(kButtonDown);
// Add frames to their parent for layout.
fHL->AddFrame(fEButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
0, 10, 0, 0));
fHL->AddFrame(fMButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
fVL->AddFrame(fHL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
AddFrame(fVL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
SetWindowName("SplitButton Test");
MapSubwindows();
Layout();
Resize(GetDefaultSize());
SetWMPosition(0, 0);
MapWindow();
}
////////////////////////////////////////////////////////////////////////////////
/// Test the different configurations/states of a split button.
Bertrand Bellenot
committed
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
void testSplitButton()
{
SplitButtonWindow *f = new SplitButtonWindow(gClient->GetRoot(),100,100);
f->fCButton->SetState(kButtonDown);
f->fEButton->SetState(kButtonDown);
f->fMButton->SetState(kButtonUp);
f->fMButton->SetSplit(kTRUE);
ProcessFrame((TGMainFrame*)f, "Split Button 1");
f->fCButton->SetState(kButtonUp);
f->fEButton->SetState(kButtonDown);
f->fMButton->SetState(kButtonUp);
f->fMButton->SetSplit(kFALSE);
ProcessFrame((TGMainFrame*)f, "Split Button 2");
f->fCButton->SetState(kButtonDown);
f->fEButton->SetState(kButtonUp);
f->fMButton->SetState(kButtonDisabled);
f->fMButton->SetSplit(kTRUE);
ProcessFrame((TGMainFrame*)f, "Split Button 3");
f->fCButton->SetState(kButtonUp);
f->fEButton->SetState(kButtonUp);
f->fMButton->SetState(kButtonDisabled);
f->fMButton->SetSplit(kFALSE);
ProcessFrame((TGMainFrame*)f, "Split Button 4");
f->CloseWindow();
}
////////////////////////////////////////////////////////////////////////////////
class GroupBox : public TGGroupFrame {
private:
TGComboBox *fCombo; // combo box
TGTextEntry *fEntry; // text entry