listBox.C: This macro gives an example of how to create a list box | Graphics User Interface | ntupleTableTest.C: This TableTest class is a simple example of how to use a TGTable |
// GUI MDI features // Author: Fons Rademakers 2/9/2004 #include <stdio.h> #include <stdlib.h> #include <TApplication.h> #include <TGClient.h> #include <TGFrame.h> #include <TGButton.h> #include <TGTextEntry.h> #include <TGCanvas.h> #include <TGMenu.h> #include <TGMdi.h> #include <TGMsgBox.h> #include <TGSlider.h> #include <TGListBox.h> #include <RQ_OBJECT.h> enum EMenuIds { M_FILE_NEW, M_FILE_CLOSE, M_FILE_EXIT, M_WINDOW_HOR, M_WINDOW_VERT, M_WINDOW_CASCADE, M_WINDOW_OPAQUE, M_WINDOW_ARRANGE, M_HELP_CONTENTS, M_HELP_ABOUT }; //---------------------------------------------------------------------- class TGMdiTestSubclass { RQ_OBJECT("TGMdiTestSubclass") protected: TGMdiFrame *fMdiFrame; TGCanvas *fCanvasWindow; TGCompositeFrame *fContainer; public: TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h); TGMdiFrame *GetMdiFrame() const { return fMdiFrame; } virtual Bool_t CloseWindow(); }; class TGMdiHintTest { RQ_OBJECT("TGMdiHintTest") protected: TGMdiFrame *fMdiFrame; TGTextEntry *fWName; TGCheckButton *fClose, *fMenu, *fMin, *fMax, *fSize, *fHelp; public: TGMdiHintTest(TGMdiMainFrame *main, int w, int h); void HandleButtons(); void HandleText(const char *); }; class TGAppMainFrame { RQ_OBJECT("TGAppMainFrame") protected: TGMainFrame *fMain; TGMdiMainFrame *fMainFrame; TGMdiMenuBar *fMenuBar; TGLayoutHints *fMenuBarItemLayout; TGPopupMenu *fMenuFile, *fMenuWindow, *fMenuHelp; void InitMenu(); void CloseWindow(); public: TGAppMainFrame(const TGWindow *p, int w, int h); void HandleMenu(Int_t id); }; //---------------------------------------------------------------------- TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h) { fMain = new TGMainFrame(p, w, h, kVerticalFrame); fMenuBar = new TGMdiMenuBar(fMain, 10, 10); fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300); fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); const TGPicture *pbg = gClient->GetPicture("mditestbg.xpm"); if (pbg) fMainFrame->GetContainer()->SetBackgroundPixmap(pbg->GetPicture()); TGMdiFrame *mdiFrame; //--- 1 TGMdiTestSubclass *t = new TGMdiTestSubclass(fMainFrame, 320, 240); mdiFrame = t->GetMdiFrame(); mdiFrame->SetMdiHints(kMdiClose | kMdiMenu); mdiFrame->SetWindowName("One"); mdiFrame->MapSubwindows(); mdiFrame->Layout(); //--- 2 ULong_t ic; gClient->GetColorByName("red", ic); mdiFrame = new TGMdiFrame(fMainFrame, 200, 200, kOwnBackground, ic); mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("&Press me!"), 1), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)); mdiFrame->SetMdiHints(kMdiDefaultHints | kMdiHelp); mdiFrame->SetWindowName("Two"); mdiFrame->MapSubwindows(); mdiFrame->Layout(); mdiFrame->Move(150, 200); //--- 3 gClient->GetColorByName("green", ic); mdiFrame = new TGMdiFrame(fMainFrame, 200, 200, kOwnBackground, ic); mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 1"), 11), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)); mdiFrame->AddFrame(new TGTextButton(mdiFrame, new TGHotString("Button 2"), 12), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)); mdiFrame->SetMdiHints(kMdiDefaultHints | kMdiHelp); mdiFrame->SetWindowName("Three"); mdiFrame->MapSubwindows(); mdiFrame->Layout(); mdiFrame->Move(180, 220); //--- 4 gClient->GetColorByName("blue", ic); mdiFrame = new TGMdiFrame(fMainFrame, 200, 400, kOwnBackground, ic); TGListBox *fListBox = new TGListBox(mdiFrame,1); fListBox->AddEntry("Entry 1", 1); fListBox->AddEntry("Entry 2", 2); fListBox->AddEntry("Entry 3", 3); fListBox->AddEntry("Entry 4", 4); fListBox->AddEntry("Entry 5", 5); fListBox->AddEntry("Entry 6", 6); fListBox->AddEntry("Entry 7", 7); fListBox->AddEntry("Entry 8", 8); fListBox->AddEntry("Entry 9", 9); fListBox->Resize(100,70); fListBox->SetMultipleSelections(kFALSE); mdiFrame->AddFrame(fListBox, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)); mdiFrame->AddFrame(new TGHSlider(mdiFrame, 50, kSlider1, 1, kHorizontalFrame, ic), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)); mdiFrame->Move(400, 300); mdiFrame->SetWindowName("Four"); mdiFrame->MapSubwindows(); mdiFrame->Layout(); //--- 5 new TGMdiHintTest(fMainFrame, 200, 200); InitMenu(); fMain->SetWindowName("MDI test"); fMain->SetClassHints("mdi test", "mdi test"); if (pbg && pbg->GetWidth() > 600 && pbg->GetHeight() > 400) fMain->Resize(pbg->GetWidth(), pbg->GetHeight()+25); else fMain->Resize(640, 400); fMain->MapSubwindows(); fMain->MapWindow(); fMain->Layout(); } void TGAppMainFrame::HandleMenu(Int_t id) { // Handle menu items. switch (id) { case M_FILE_NEW: new TGMdiFrame(fMainFrame, 200, 100); break; case M_FILE_CLOSE: fMainFrame->Close(fMainFrame->GetCurrent()); break; case M_FILE_EXIT: CloseWindow(); break; case M_WINDOW_HOR: fMainFrame->TileHorizontal(); break; case M_WINDOW_VERT: fMainFrame->TileVertical(); break; case M_WINDOW_CASCADE: fMainFrame->Cascade(); break; case M_WINDOW_ARRANGE: fMainFrame->ArrangeMinimized(); break; case M_WINDOW_OPAQUE: if (fMenuWindow->IsEntryChecked(M_WINDOW_OPAQUE)) { fMenuWindow->UnCheckEntry(M_WINDOW_OPAQUE); fMainFrame->SetResizeMode(kMdiNonOpaque); } else { fMenuWindow->CheckEntry(M_WINDOW_OPAQUE); fMainFrame->SetResizeMode(kMdiOpaque); } break; default: fMainFrame->SetCurrent(id); break; } } void TGAppMainFrame::InitMenu() { fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry(new TGHotString("&New Window"), M_FILE_NEW); fMenuFile->AddEntry(new TGHotString("&Close Window"), M_FILE_CLOSE); fMenuFile->AddSeparator(); fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT); fMenuWindow = new TGPopupMenu(gClient->GetRoot()); fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR); fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT); fMenuWindow->AddEntry(new TGHotString("&Cascade"), M_WINDOW_CASCADE); fMenuWindow->AddSeparator(); fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu()); fMenuWindow->AddSeparator(); fMenuWindow->AddEntry(new TGHotString("&Arrange icons"), M_WINDOW_ARRANGE); fMenuWindow->AddSeparator(); fMenuWindow->AddEntry(new TGHotString("&Opaque resize"), M_WINDOW_OPAQUE); fMenuWindow->CheckEntry(M_WINDOW_OPAQUE); fMenuHelp = new TGPopupMenu(gClient->GetRoot()); fMenuHelp->AddEntry(new TGHotString("&Contents"), M_HELP_CONTENTS); fMenuHelp->AddSeparator(); fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT); fMenuHelp->DisableEntry(M_HELP_CONTENTS); fMenuHelp->DisableEntry(M_HELP_ABOUT); // menu message are handled by the class' HandleMenu() method fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout); fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout); fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout); } void TGAppMainFrame::CloseWindow() { gApplication->Terminate(0); } //---------------------------------------------------------------------- TGMdiTestSubclass::TGMdiTestSubclass(TGMdiMainFrame *main, int w, int h) { fMdiFrame = new TGMdiFrame(main, w, h); fMdiFrame->Connect("CloseWindow()", "TGMdiTestSubclass", this, "CloseWindow()"); fMdiFrame->DontCallClose(); fCanvasWindow = new TGCanvas(fMdiFrame, 400, 240); fContainer = new TGCompositeFrame(fCanvasWindow->GetViewPort(), 10, 10, kHorizontalFrame | kOwnBackground, fMdiFrame->GetWhitePixel()); fContainer->SetLayoutManager(new TGTileLayout(fContainer, 8)); fCanvasWindow->SetContainer(fContainer); for (int i = 0; i < 256; ++i) fCanvasWindow->AddFrame(new TGFrame(fCanvasWindow->GetContainer(), 32, 32, kOwnBackground, (i+1) & 255), new TGLayoutHints(kLHintsNormal)); fMdiFrame->AddFrame(fCanvasWindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); fMdiFrame->SetWindowIcon(gClient->GetPicture("ofolder_t.xpm")); } Bool_t TGMdiTestSubclass::CloseWindow() { int ret = 0; new TGMsgBox(gClient->GetRoot(), fMdiFrame, fMdiFrame->GetWindowName(), "Really want to close the window?", kMBIconExclamation, kMBYes | kMBNo, &ret); if (ret == kMBYes) return fMdiFrame->CloseWindow(); return kFALSE; } //---------------------------------------------------------------------- TGMdiHintTest::TGMdiHintTest(TGMdiMainFrame *main, int w, int h) { fMdiFrame = new TGMdiFrame(main, w, h); fClose = new TGCheckButton(fMdiFrame, new TGHotString("Close"), 11); fMenu = new TGCheckButton(fMdiFrame, new TGHotString("Menu (left icon)"), 12); fMin = new TGCheckButton(fMdiFrame, new TGHotString("Minimize"), 13); fMax = new TGCheckButton(fMdiFrame, new TGHotString("Maximize"), 14); fSize = new TGCheckButton(fMdiFrame, new TGHotString("Resize"), 15); fHelp = new TGCheckButton(fMdiFrame, new TGHotString("Help"), 16); TGLayoutHints *lh = new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 100, 5, 0); fMdiFrame->AddFrame(fClose, lh); fMdiFrame->AddFrame(fMenu, lh); fMdiFrame->AddFrame(fMin, lh); fMdiFrame->AddFrame(fMax, lh); fMdiFrame->AddFrame(fSize, lh); fMdiFrame->AddFrame(fHelp, lh); fClose->SetState(kButtonDown); fMin->SetState(kButtonDown); fMenu->SetState(kButtonDown); fMax->SetState(kButtonDown); fSize->SetState(kButtonDown); fClose->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fMenu->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fMin->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fMax->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fSize->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fHelp->Connect("Clicked()", "TGMdiHintTest", this, "HandleButtons()"); fWName = new TGTextEntry(fMdiFrame, (const char *)"", 20); fMdiFrame->AddFrame(fWName, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5)); fWName->GetBuffer()->AddText(0, "MDI hints test"); fWName->Connect("TextChanged(char*)", "TGMdiHintTest", this, "HandleText(char*)"); fMdiFrame->SetMdiHints(kMdiDefaultHints); fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString()); fMdiFrame->SetWindowIcon(gClient->GetPicture("app_t.xpm")); fMdiFrame->MapSubwindows(); fMdiFrame->Layout(); } void TGMdiHintTest::HandleButtons() { int hints = 0; if (fClose->GetState() != kButtonUp) hints |= kMdiClose; if (fMenu->GetState() != kButtonUp) hints |= kMdiMenu; if (fMin->GetState() != kButtonUp) hints |= kMdiMinimize; if (fMax->GetState() != kButtonUp) hints |= kMdiMaximize; if (fSize->GetState() != kButtonUp) hints |= kMdiSize; if (fHelp->GetState() != kButtonUp) hints |= kMdiHelp; fMdiFrame->SetMdiHints(hints); } void TGMdiHintTest::HandleText(const char *) { fMdiFrame->SetWindowName(fWName->GetBuffer()->GetString()); } void mditest() { new TGAppMainFrame(gClient->GetRoot(), 640, 400); } //---------------------------------------------------------------------- #ifdef STANDALONE int main(int argc, char **argv) { TApplication theApp("MdiTest", &argc, argv); mditest(); theApp.Run(); return 0; } #endif mditest.C:1 mditest.C:2 mditest.C:3 mditest.C:4 mditest.C:5 mditest.C:6 mditest.C:7 mditest.C:8 mditest.C:9 mditest.C:10 mditest.C:11 mditest.C:12 mditest.C:13 mditest.C:14 mditest.C:15 mditest.C:16 mditest.C:17 mditest.C:18 mditest.C:19 mditest.C:20 mditest.C:21 mditest.C:22 mditest.C:23 mditest.C:24 mditest.C:25 mditest.C:26 mditest.C:27 mditest.C:28 mditest.C:29 mditest.C:30 mditest.C:31 mditest.C:32 mditest.C:33 mditest.C:34 mditest.C:35 mditest.C:36 mditest.C:37 mditest.C:38 mditest.C:39 mditest.C:40 mditest.C:41 mditest.C:42 mditest.C:43 mditest.C:44 mditest.C:45 mditest.C:46 mditest.C:47 mditest.C:48 mditest.C:49 mditest.C:50 mditest.C:51 mditest.C:52 mditest.C:53 mditest.C:54 mditest.C:55 mditest.C:56 mditest.C:57 mditest.C:58 mditest.C:59 mditest.C:60 mditest.C:61 mditest.C:62 mditest.C:63 mditest.C:64 mditest.C:65 mditest.C:66 mditest.C:67 mditest.C:68 mditest.C:69 mditest.C:70 mditest.C:71 mditest.C:72 mditest.C:73 mditest.C:74 mditest.C:75 mditest.C:76 mditest.C:77 mditest.C:78 mditest.C:79 mditest.C:80 mditest.C:81 mditest.C:82 mditest.C:83 mditest.C:84 mditest.C:85 mditest.C:86 mditest.C:87 mditest.C:88 mditest.C:89 mditest.C:90 mditest.C:91 mditest.C:92 mditest.C:93 mditest.C:94 mditest.C:95 mditest.C:96 mditest.C:97 mditest.C:98 mditest.C:99 mditest.C:100 mditest.C:101 mditest.C:102 mditest.C:103 mditest.C:104 mditest.C:105 mditest.C:106 mditest.C:107 mditest.C:108 mditest.C:109 mditest.C:110 mditest.C:111 mditest.C:112 mditest.C:113 mditest.C:114 mditest.C:115 mditest.C:116 mditest.C:117 mditest.C:118 mditest.C:119 mditest.C:120 mditest.C:121 mditest.C:122 mditest.C:123 mditest.C:124 mditest.C:125 mditest.C:126 mditest.C:127 mditest.C:128 mditest.C:129 mditest.C:130 mditest.C:131 mditest.C:132 mditest.C:133 mditest.C:134 mditest.C:135 mditest.C:136 mditest.C:137 mditest.C:138 mditest.C:139 mditest.C:140 mditest.C:141 mditest.C:142 mditest.C:143 mditest.C:144 mditest.C:145 mditest.C:146 mditest.C:147 mditest.C:148 mditest.C:149 mditest.C:150 mditest.C:151 mditest.C:152 mditest.C:153 mditest.C:154 mditest.C:155 mditest.C:156 mditest.C:157 mditest.C:158 mditest.C:159 mditest.C:160 mditest.C:161 mditest.C:162 mditest.C:163 mditest.C:164 mditest.C:165 mditest.C:166 mditest.C:167 mditest.C:168 mditest.C:169 mditest.C:170 mditest.C:171 mditest.C:172 mditest.C:173 mditest.C:174 mditest.C:175 mditest.C:176 mditest.C:177 mditest.C:178 mditest.C:179 mditest.C:180 mditest.C:181 mditest.C:182 mditest.C:183 mditest.C:184 mditest.C:185 mditest.C:186 mditest.C:187 mditest.C:188 mditest.C:189 mditest.C:190 mditest.C:191 mditest.C:192 mditest.C:193 mditest.C:194 mditest.C:195 mditest.C:196 mditest.C:197 mditest.C:198 mditest.C:199 mditest.C:200 mditest.C:201 mditest.C:202 mditest.C:203 mditest.C:204 mditest.C:205 mditest.C:206 mditest.C:207 mditest.C:208 mditest.C:209 mditest.C:210 mditest.C:211 mditest.C:212 mditest.C:213 mditest.C:214 mditest.C:215 mditest.C:216 mditest.C:217 mditest.C:218 mditest.C:219 mditest.C:220 mditest.C:221 mditest.C:222 mditest.C:223 mditest.C:224 mditest.C:225 mditest.C:226 mditest.C:227 mditest.C:228 mditest.C:229 mditest.C:230 mditest.C:231 mditest.C:232 mditest.C:233 mditest.C:234 mditest.C:235 mditest.C:236 mditest.C:237 mditest.C:238 mditest.C:239 mditest.C:240 mditest.C:241 mditest.C:242 mditest.C:243 mditest.C:244 mditest.C:245 mditest.C:246 mditest.C:247 mditest.C:248 mditest.C:249 mditest.C:250 mditest.C:251 mditest.C:252 mditest.C:253 mditest.C:254 mditest.C:255 mditest.C:256 mditest.C:257 mditest.C:258 mditest.C:259 mditest.C:260 mditest.C:261 mditest.C:262 mditest.C:263 mditest.C:264 mditest.C:265 mditest.C:266 mditest.C:267 mditest.C:268 mditest.C:269 mditest.C:270 mditest.C:271 mditest.C:272 mditest.C:273 mditest.C:274 mditest.C:275 mditest.C:276 mditest.C:277 mditest.C:278 mditest.C:279 mditest.C:280 mditest.C:281 mditest.C:282 mditest.C:283 mditest.C:284 mditest.C:285 mditest.C:286 mditest.C:287 mditest.C:288 mditest.C:289 mditest.C:290 mditest.C:291 mditest.C:292 mditest.C:293 mditest.C:294 mditest.C:295 mditest.C:296 mditest.C:297 mditest.C:298 mditest.C:299 mditest.C:300 mditest.C:301 mditest.C:302 mditest.C:303 mditest.C:304 mditest.C:305 mditest.C:306 mditest.C:307 mditest.C:308 mditest.C:309 mditest.C:310 mditest.C:311 mditest.C:312 mditest.C:313 mditest.C:314 mditest.C:315 mditest.C:316 mditest.C:317 mditest.C:318 mditest.C:319 mditest.C:320 mditest.C:321 mditest.C:322 mditest.C:323 mditest.C:324 mditest.C:325 mditest.C:326 mditest.C:327 mditest.C:328 mditest.C:329 mditest.C:330 mditest.C:331 mditest.C:332 mditest.C:333 mditest.C:334 mditest.C:335 mditest.C:336 mditest.C:337 mditest.C:338 mditest.C:339 mditest.C:340 mditest.C:341 mditest.C:342 mditest.C:343 mditest.C:344 mditest.C:345 mditest.C:346 mditest.C:347 mditest.C:348 mditest.C:349 mditest.C:350 mditest.C:351 mditest.C:352 mditest.C:353 mditest.C:354 mditest.C:355 mditest.C:356 mditest.C:357 mditest.C:358 mditest.C:359 mditest.C:360 mditest.C:361 mditest.C:362 mditest.C:363 mditest.C:364 mditest.C:365 mditest.C:366 mditest.C:367 mditest.C:368 mditest.C:369 mditest.C:370 mditest.C:371 mditest.C:372 mditest.C:373 mditest.C:374 mditest.C:375 mditest.C:376 mditest.C:377 mditest.C:378 mditest.C:379 mditest.C:380 mditest.C:381 mditest.C:382 mditest.C:383 mditest.C:384 mditest.C:385 mditest.C:386 mditest.C:387 mditest.C:388 mditest.C:389 mditest.C:390 mditest.C:391 mditest.C:392 mditest.C:393 mditest.C:394 mditest.C:395 mditest.C:396 mditest.C:397 mditest.C:398 mditest.C:399 mditest.C:400 mditest.C:401 mditest.C:402 mditest.C:403 mditest.C:404 mditest.C:405 mditest.C:406 mditest.C:407 mditest.C:408 mditest.C:409 mditest.C:410 mditest.C:411 mditest.C:412 mditest.C:413 mditest.C:414 mditest.C:415 mditest.C:416 |
|