Public Member Functions | |
TestDialog (const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options=kVerticalFrame) | |
virtual | ~TestDialog () |
void | DoClose () |
void | CloseWindow () |
void | DoOK () |
void | DoCancel () |
void | DoTab (Int_t id) |
void | HandleButtons (Int_t id=-1) |
void | HandleEmbeddedCanvas (Int_t event, Int_t x, Int_t y, TObject *sel) |
Private Member Functions | |
void | FillHistos () |
Private Attributes | |
TGTransientFrame * | fMain |
TGCompositeFrame * | fFrame1 |
TGCompositeFrame * | fF1 |
TGCompositeFrame * | fF2 |
TGCompositeFrame * | fF3 |
TGCompositeFrame * | fF4 |
TGCompositeFrame * | fF5 |
TGGroupFrame * | fF6 |
TGGroupFrame * | fF7 |
TGButton * | fOkButton |
TGButton * | fCancelButton |
TGButton * | fStartB |
TGButton * | fStopB |
TGButton * | fBtn1 |
TGButton * | fBtn2 |
TGButton * | fChk1 |
TGButton * | fChk2 |
TGButton * | fRad1 |
TGButton * | fRad2 |
TGPictureButton * | fPicBut1 |
TGCheckButton * | fCheck1 |
TGCheckButton * | fCheckMulti |
TGListBox * | fListBox |
TGComboBox * | fCombo |
TGTab * | fTab |
TGTextEntry * | fTxt1 |
TGTextEntry * | fTxt2 |
TGLayoutHints * | fL1 |
TGLayoutHints * | fL2 |
TGLayoutHints * | fL3 |
TGLayoutHints * | fL4 |
TRootEmbeddedCanvas * | fEc1 |
TRootEmbeddedCanvas * | fEc2 |
Int_t | fFirstEntry |
Int_t | fLastEntry |
Bool_t | fFillHistos |
TH1F * | fHpx |
TH2F * | fHpxpy |
Definition at line 267 of file guitest.C.
TestDialog::TestDialog | ( | const TGWindow * | p, | |
const TGWindow * | main, | |||
UInt_t | w, | |||
UInt_t | h, | |||
UInt_t | options = kVerticalFrame | |||
) |
Definition at line 956 of file guitest.C.
00958 { 00959 // Create a dialog window. A dialog window pops up with respect to its 00960 // "main" window. 00961 00962 fMain = new TGTransientFrame(p, main, w, h, options); 00963 fMain->Connect("CloseWindow()", "TestDialog", this, "DoClose()"); 00964 fMain->DontCallClose(); // to avoid double deletions. 00965 00966 // use hierarchical cleaning 00967 fMain->SetCleanup(kDeepCleanup); 00968 00969 fFrame1 = new TGHorizontalFrame(fMain, 60, 20, kFixedWidth); 00970 00971 fOkButton = new TGTextButton(fFrame1, "&Ok", 1); 00972 fOkButton->Connect("Clicked()", "TestDialog", this, "DoOK()"); 00973 fCancelButton = new TGTextButton(fFrame1, "&Cancel", 2); 00974 fCancelButton->Connect("Clicked()", "TestDialog", this, "DoCancel()"); 00975 00976 fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 00977 2, 2, 2, 2); 00978 fL2 = new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1); 00979 00980 fFrame1->AddFrame(fOkButton, fL1); 00981 fFrame1->AddFrame(fCancelButton, fL1); 00982 00983 fFrame1->Resize(150, fOkButton->GetDefaultHeight()); 00984 fMain->AddFrame(fFrame1, fL2); 00985 00986 //--------- create Tab widget and some composite frames for Tab testing 00987 00988 fTab = new TGTab(fMain, 300, 300); 00989 fTab->Connect("Selected(Int_t)", "TestDialog", this, "DoTab(Int_t)"); 00990 00991 fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5); 00992 00993 TGCompositeFrame *tf = fTab->AddTab("Tab 1"); 00994 fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame); 00995 fF1->AddFrame(new TGTextButton(fF1, "&Test button", 0), fL3); 00996 fF1->AddFrame(fTxt1 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3); 00997 fF1->AddFrame(fTxt2 = new TGTextEntry(fF1, new TGTextBuffer(100)), fL3); 00998 tf->AddFrame(fF1, fL3); 00999 fTxt1->Resize(150, fTxt1->GetDefaultHeight()); 01000 fTxt2->Resize(150, fTxt2->GetDefaultHeight()); 01001 01002 tf = fTab->AddTab("Tab 2"); 01003 fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 01004 200, 2, 2, 2); 01005 fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame); 01006 fF2->AddFrame(fBtn1 = new TGTextButton(fF2, "&Button 1", 61), fL1); 01007 fF2->AddFrame(fBtn2 = new TGTextButton(fF2, "B&utton 2", 62), fL1); 01008 fF2->AddFrame(fChk1 = new TGCheckButton(fF2, "C&heck 1", 71), fL1); 01009 fF2->AddFrame(fChk2 = new TGCheckButton(fF2, "Chec&k 2", 72), fL1); 01010 fF2->AddFrame(fRad1 = new TGRadioButton(fF2, "&Radio 1", 81), fL1); 01011 fF2->AddFrame(fRad2 = new TGRadioButton(fF2, "R&adio 2", 82), fL1); 01012 fCombo = new TGComboBox(fF2, 88); 01013 fF2->AddFrame(fCombo, fL3); 01014 01015 tf->AddFrame(fF2, fL3); 01016 01017 int i; 01018 char tmp[20]; 01019 for (i = 0; i < 20; i++) { 01020 01021 sprintf(tmp, "Entry %i", i+1); 01022 fCombo->AddEntry(tmp, i+1); 01023 } 01024 01025 fCombo->Resize(150, 20); 01026 01027 fBtn1->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01028 fBtn2->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01029 fChk1->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01030 fChk2->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01031 fRad1->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01032 fRad2->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01033 01034 //-------------- embedded canvas demo 01035 fFillHistos = kFALSE; 01036 fHpx = 0; 01037 fHpxpy = 0; 01038 01039 tf = fTab->AddTab("Tab 3"); 01040 fF3 = new TGCompositeFrame(tf, 60, 20, kHorizontalFrame); 01041 fStartB = new TGTextButton(fF3, "Start &Filling Hists", 40); 01042 fStopB = new TGTextButton(fF3, "&Stop Filling Hists", 41); 01043 fStartB->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01044 fStopB->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01045 fF3->AddFrame(fStartB, fL3); 01046 fF3->AddFrame(fStopB, fL3); 01047 01048 fF5 = new TGCompositeFrame(tf, 60, 60, kHorizontalFrame); 01049 01050 fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | 01051 kLHintsExpandY, 5, 5, 5, 5); 01052 fEc1 = new TRootEmbeddedCanvas("ec1", fF5, 100, 100); 01053 fF5->AddFrame(fEc1, fL4); 01054 fEc2 = new TRootEmbeddedCanvas("ec2", fF5, 100, 100); 01055 fF5->AddFrame(fEc2, fL4); 01056 01057 tf->AddFrame(fF3, fL3); 01058 tf->AddFrame(fF5, fL4); 01059 01060 fEc1->GetCanvas()->SetBorderMode(0); 01061 fEc2->GetCanvas()->SetBorderMode(0); 01062 fEc1->GetCanvas()->SetBit(kNoContextMenu); 01063 fEc1->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 01064 "TestDialog", this, 01065 "HandleEmbeddedCanvas(Int_t,Int_t,Int_t,TObject*)"); 01066 01067 // make tab yellow 01068 Pixel_t yellow; 01069 gClient->GetColorByName("yellow", yellow); 01070 TGTabElement *tabel = fTab->GetTabTab("Tab 3"); 01071 tabel->ChangeBackground(yellow); 01072 01073 //-------------- end embedded canvas demo 01074 01075 TGTextButton *bt; 01076 tf = fTab->AddTab("Tab 4"); 01077 fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame); 01078 fF4->AddFrame(bt = new TGTextButton(fF4, "A&dd Entry", 90), fL3); 01079 bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01080 01081 fF4->AddFrame(bt = new TGTextButton(fF4, "Remove &Entry", 91), fL3); 01082 bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01083 01084 fF4->AddFrame(fListBox = new TGListBox(fF4, 89), fL3); 01085 fF4->AddFrame(fCheckMulti = new TGCheckButton(fF4, "&Mutli Selectable", 92), fL3); 01086 fCheckMulti->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01087 tf->AddFrame(fF4, fL3); 01088 01089 for (i = 0; i < 20; ++i) { 01090 sprintf(tmp, "Entry %i", i); 01091 fListBox->AddEntry(tmp, i); 01092 } 01093 fFirstEntry = 0; 01094 fLastEntry = 20; 01095 01096 fListBox->Resize(150, 80); 01097 01098 //--- tab 5 01099 tf = fTab->AddTab("Tab 5"); 01100 tf->SetLayoutManager(new TGHorizontalLayout(tf)); 01101 01102 fF6 = new TGGroupFrame(tf, "Options", kVerticalFrame); 01103 fF6->SetTitlePos(TGGroupFrame::kRight); // right aligned 01104 tf->AddFrame(fF6, fL3); 01105 01106 // 2 column, n rows 01107 fF6->SetLayoutManager(new TGMatrixLayout(fF6, 0, 2, 10)); 01108 char buff[100]; 01109 int j; 01110 for (j = 0; j < 4; j++) { 01111 sprintf(buff, "Module %i", j+1); 01112 fF6->AddFrame(new TGLabel(fF6, new TGHotString(buff))); 01113 01114 TGTextBuffer *tbuf = new TGTextBuffer(10); 01115 tbuf->AddText(0, "0.0"); 01116 01117 TGTextEntry *tent = new TGTextEntry(fF6, tbuf); 01118 tent->Resize(50, tent->GetDefaultHeight()); 01119 tent->SetFont("-adobe-courier-bold-r-*-*-14-*-*-*-*-*-iso8859-1"); 01120 fF6->AddFrame(tent); 01121 } 01122 fF6->Resize(); 01123 01124 // another matrix with text and buttons 01125 fF7 = new TGGroupFrame(tf, "Tab Handling", kVerticalFrame); 01126 tf->AddFrame(fF7, fL3); 01127 01128 fF7->SetLayoutManager(new TGMatrixLayout(fF7, 0, 1, 10)); 01129 01130 fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab", 101)); 01131 bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01132 bt->Resize(90, bt->GetDefaultHeight()); 01133 01134 fF7->AddFrame(bt = new TGTextButton(fF7, "Add Tab", 103)); 01135 bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01136 bt->Resize(90, bt->GetDefaultHeight()); 01137 01138 fF7->AddFrame(bt = new TGTextButton(fF7, "Remove Tab 5", 102)); 01139 bt->Connect("Clicked()", "TestDialog", this, "HandleButtons()"); 01140 bt->Resize(90, bt->GetDefaultHeight()); 01141 01142 fF7->Resize(fF6->GetDefaultSize()); 01143 01144 //--- end of last tab 01145 01146 TGLayoutHints *fL5 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX | 01147 kLHintsExpandY, 2, 2, 5, 1); 01148 fMain->AddFrame(fTab, fL5); 01149 01150 fMain->MapSubwindows(); 01151 fMain->Resize(); 01152 01153 // position relative to the parent's window 01154 fMain->CenterOnParent(); 01155 01156 fMain->SetWindowName("Dialog"); 01157 01158 fMain->MapWindow(); 01159 //gClient->WaitFor(fMain); // otherwise canvas contextmenu does not work 01160 }
TestDialog::~TestDialog | ( | ) | [virtual] |
void TestDialog::FillHistos | ( | ) | [private] |
Definition at line 1169 of file guitest.C.
Referenced by HandleButtons().
01170 { 01171 // Fill histograms till user clicks "Stop Filling" button. 01172 01173 static int cnt; 01174 01175 if (!fHpx) { 01176 fHpx = new TH1F("hpx","This is the px distribution",100,-4,4); 01177 fHpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4); 01178 fHpx->SetFillColor(kRed); 01179 cnt = 0; 01180 } 01181 01182 const int kUPDATE = 1000; 01183 float px, py; 01184 TCanvas *c1 = fEc1->GetCanvas(); 01185 TCanvas *c2 = fEc2->GetCanvas(); 01186 01187 while (fFillHistos) { 01188 gRandom->Rannor(px,py); //px and py will be two gaussian random numbers 01189 fHpx->Fill(px); 01190 fHpxpy->Fill(px,py); 01191 cnt++; 01192 if (!(cnt % kUPDATE)) { 01193 if (cnt == kUPDATE) { 01194 c1->cd(); 01195 fHpx->Draw(); 01196 c2->cd(); 01197 fHpxpy->Draw("cont"); 01198 } 01199 c1->Modified(); 01200 c1->Update(); 01201 c2->Modified(); 01202 c2->Update(); 01203 gSystem->ProcessEvents(); // handle GUI events 01204 } 01205 } 01206 }
void TestDialog::DoClose | ( | ) |
Definition at line 1208 of file guitest.C.
01209 { 01210 printf("\nTerminating dialog: via window manager\n"); 01211 if (fFillHistos) { 01212 fFillHistos = kFALSE; 01213 TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()"); 01214 } else 01215 CloseWindow(); 01216 01217 // Close the Ged editor if it was activated. 01218 if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0) 01219 TVirtualPadEditor::Terminate(); 01220 }
void TestDialog::CloseWindow | ( | ) |
void TestDialog::DoOK | ( | ) |
Definition at line 1229 of file guitest.C.
01230 { 01231 fFillHistos = kFALSE; 01232 printf("\nTerminating dialog: OK pressed\n"); 01233 // Add protection against double-clicks 01234 fOkButton->SetState(kButtonDisabled); 01235 fCancelButton->SetState(kButtonDisabled); 01236 01237 // Send a close message to the main frame. This will trigger the 01238 // emission of a CloseWindow() signal, which will then call 01239 // TestDialog::CloseWindow(). Calling directly CloseWindow() will cause 01240 // a segv since the OK button is still accessed after the DoOK() method. 01241 // This works since the close message is handled synchronous (via 01242 // message going to/from X server). 01243 //fMain->SendCloseMessage(); 01244 01245 // The same effect can be obtained by using a singleshot timer: 01246 TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()"); 01247 01248 // Close the Ged editor if it was activated. 01249 if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0) 01250 TVirtualPadEditor::Terminate(); 01251 }
void TestDialog::DoCancel | ( | ) |
Definition at line 1254 of file guitest.C.
01255 { 01256 fFillHistos = kFALSE; 01257 printf("\nTerminating dialog: Cancel pressed\n"); 01258 // Add protection against double-clicks 01259 fOkButton->SetState(kButtonDisabled); 01260 fCancelButton->SetState(kButtonDisabled); 01261 TTimer::SingleShot(150, "TestDialog", this, "CloseWindow()"); 01262 // Close the Ged editor if it was activated. 01263 if (TVirtualPadEditor::GetPadEditor(kFALSE) != 0) 01264 TVirtualPadEditor::Terminate(); 01265 }
void TestDialog::DoTab | ( | Int_t | id | ) |
void TestDialog::HandleButtons | ( | Int_t | id = -1 |
) |
Definition at line 1267 of file guitest.C.
01268 { 01269 // Handle different buttons. 01270 01271 if (id == -1) { 01272 TGButton *btn = (TGButton *) gTQSender; 01273 id = btn->WidgetId(); 01274 } 01275 01276 printf("DoButton: id = %d\n", id); 01277 01278 char tmp[20]; 01279 static int newtab = 0; 01280 01281 switch (id) { 01282 case 40: // start histogram filling 01283 fFillHistos = kTRUE; 01284 FillHistos(); 01285 break; 01286 case 41: // stop histogram filling 01287 fFillHistos = kFALSE; 01288 break; 01289 case 61: // show item 1 in the combo box 01290 fCombo->Select(1); 01291 break; 01292 case 62: // show item 2 in the combo box 01293 fCombo->Select(2); 01294 break; 01295 case 90: // add one entry in list box 01296 fLastEntry++; 01297 sprintf(tmp, "Entry %i", fLastEntry); 01298 fListBox->AddEntry(tmp, fLastEntry); 01299 fListBox->MapSubwindows(); 01300 fListBox->Layout(); 01301 break; 01302 case 91: // remove one entry in list box 01303 if (fFirstEntry <= fLastEntry) { 01304 fListBox->RemoveEntry(fFirstEntry); 01305 fListBox->Layout(); 01306 fFirstEntry++; 01307 } 01308 break; 01309 case 101: // remove tabs 01310 { 01311 TString s = fTab->GetTabTab(0)->GetString(); 01312 if ((s == "Tab 3") && (fMain->MustCleanup() != kDeepCleanup)) { 01313 // Need to delete the embedded canvases 01314 // since RemoveTab() will Destroy the container 01315 // window, which in turn will destroy the embedded 01316 // canvas windows. 01317 delete fEc1; fEc1 = 0; 01318 delete fEc2; fEc2 = 0; 01319 } 01320 fTab->RemoveTab(0); 01321 fTab->Layout(); 01322 } 01323 break; 01324 case 102: // remove tab 5 01325 { 01326 int nt = fTab->GetNumberOfTabs(); 01327 for (int i = 0 ; i < nt; i++) { 01328 TString s = fTab->GetTabTab(i)->GetString(); 01329 if (s == "Tab 5") { 01330 fTab->RemoveTab(i); 01331 fTab->Layout(); 01332 break; 01333 } 01334 } 01335 } 01336 break; 01337 case 103: // add tabs 01338 sprintf(tmp, "New Tab %d", ++newtab); 01339 fTab->AddTab(tmp); 01340 fTab->MapSubwindows(); 01341 fTab->Layout(); 01342 break; 01343 case 81: 01344 fRad2->SetState(kButtonUp); 01345 break; 01346 case 82: 01347 fRad1->SetState(kButtonUp); 01348 break; 01349 case 92: 01350 fListBox->SetMultipleSelections(fCheckMulti->GetState()); 01351 break; 01352 default: 01353 break; 01354 } 01355 }
void TestDialog::HandleEmbeddedCanvas | ( | Int_t | event, | |
Int_t | x, | |||
Int_t | y, | |||
TObject * | sel | |||
) |
TGTransientFrame* TestDialog::fMain [private] |
Definition at line 272 of file guitest.C.
Referenced by HandleButtons(), TestDialog(), and ~TestDialog().
TGCompositeFrame* TestDialog::fFrame1 [private] |
TGCompositeFrame * TestDialog::fF1 [private] |
TGCompositeFrame * TestDialog::fF2 [private] |
TGCompositeFrame * TestDialog::fF3 [private] |
TGCompositeFrame * TestDialog::fF4 [private] |
TGCompositeFrame * TestDialog::fF5 [private] |
TGGroupFrame* TestDialog::fF6 [private] |
TGGroupFrame * TestDialog::fF7 [private] |
TGButton* TestDialog::fOkButton [private] |
TGButton * TestDialog::fCancelButton [private] |
TGButton * TestDialog::fStartB [private] |
TGButton * TestDialog::fStopB [private] |
TGButton* TestDialog::fBtn1 [private] |
TGButton * TestDialog::fBtn2 [private] |
TGButton * TestDialog::fChk1 [private] |
TGButton * TestDialog::fChk2 [private] |
TGButton * TestDialog::fRad1 [private] |
TGButton * TestDialog::fRad2 [private] |
TGPictureButton* TestDialog::fPicBut1 [private] |
TGCheckButton* TestDialog::fCheck1 [private] |
TGCheckButton* TestDialog::fCheckMulti [private] |
TGListBox* TestDialog::fListBox [private] |
TGComboBox* TestDialog::fCombo [private] |
TGTab* TestDialog::fTab [private] |
TGTextEntry* TestDialog::fTxt1 [private] |
TGTextEntry * TestDialog::fTxt2 [private] |
TGLayoutHints* TestDialog::fL1 [private] |
TGLayoutHints * TestDialog::fL2 [private] |
TGLayoutHints * TestDialog::fL3 [private] |
TGLayoutHints * TestDialog::fL4 [private] |
TRootEmbeddedCanvas* TestDialog::fEc1 [private] |
Definition at line 285 of file guitest.C.
Referenced by FillHistos(), HandleButtons(), and TestDialog().
TRootEmbeddedCanvas * TestDialog::fEc2 [private] |
Definition at line 285 of file guitest.C.
Referenced by FillHistos(), HandleButtons(), and TestDialog().
Int_t TestDialog::fFirstEntry [private] |
Int_t TestDialog::fLastEntry [private] |
Bool_t TestDialog::fFillHistos [private] |
Definition at line 288 of file guitest.C.
Referenced by DoCancel(), DoClose(), DoOK(), FillHistos(), HandleButtons(), and TestDialog().
TH1F* TestDialog::fHpx [private] |
TH2F* TestDialog::fHpxpy [private] |