Hi rooters, I have attached two classes (files .h and .C) which produce basically the same dialog box. The only difference is that one uses TGGroupFrame (*.good) and TGButtonGroup (*.bad). I would like to use the latest since it handles the exclusivity of the radio buttons. However it seems it does not take into account the layout hints and the radio buttons are placed at the bottom (with a big empty space at the top) instead of at the top. Did I forget anything?... To run this files: 1) Rename SettingsDialog.C.[good|bad] to SettingsDialog.C 2) Rename SettingsDialog.h.[good|bad] to SettingsDialog.h 3) Enter root 4) [root] .L SettingsDialog.C+ (it also works without compilation) 5) [root] SettingsDialog c I am using: Version 3.01/06 31 October 2001 * Linux 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) Thanks, Isidro +---------------------------+--------------------------------+ | Isidro González Caballero | mailto:Isidro.Gonzalez@cern.ch | | CERN-EP / Mailbox: F28010 | http://home.cern.ch/~iglez/ | | 1211 Geneva 23 | -o- | | Switzerland | Tel: +41 22 76 73060, 73316 | +---------------------------+--------------------------------+ #include "SettingsDialog.h" #include <TGString.h> SettingDialog::~SettingDialog() { } SettingDialog::SettingDialog() { // Create simple input dialog. const TGWindow *main = gClient->GetRoot(); fDialog = new TGTransientFrame(main, main, 100, 100, kVerticalFrame); fDialog->Connect("CloseWindow()", "SettingDialog", this, "CloseWindow()"); fLDialog = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0); // Main frame for materials and energy radio buttons fRadios = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame); fLRadios = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2); //------------- Group Frame for materials fLMaterial = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 5, 0); fGMaterial = new TGGroupFrame(fRadios, new TGString("Materials")); fRMaterial[0] = new TGRadioButton(fGMaterial, new TGHotString("All"), 11); fRMaterial[1] = new TGRadioButton(fGMaterial, new TGHotString("Aluminium"), 12); fRMaterial[2] = new TGRadioButton(fGMaterial, new TGHotString("Iron"), 13); fRMaterial[3] = new TGRadioButton(fGMaterial, new TGHotString("Lead"), 14); for (unsigned int i = 0; i < 4; ++i) { fGMaterial->AddFrame(fRMaterial[i], fLMaterial); fRMaterial[i]->Connect("Pressed()", "TestMsgBox", this, "DoRadio()"); } fRadios->AddFrame(fGMaterial,fLRadios); //------------ Group Frame for materials fLEnergy = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 5, 0); fGEnergy = new TGGroupFrame(fRadios, new TGString("Energies")); fREnergy[0] = new TGRadioButton(fGEnergy, new TGHotString("All"), 21); fREnergy[1] = new TGRadioButton(fGEnergy, new TGHotString("113 MeV"), 22); fREnergy[2] = new TGRadioButton(fGEnergy, new TGHotString("256 MeV"), 23); fREnergy[3] = new TGRadioButton(fGEnergy, new TGHotString("597 MeV"), 24); fREnergy[4] = new TGRadioButton(fGEnergy, new TGHotString("800 MeV"), 25); for (unsigned int i = 0; i < 5; ++i) { fGEnergy->AddFrame(fREnergy[i], fLEnergy); fREnergy[i]->Connect("Pressed()", "TestMsgBox", this, "DoRadio()"); } fRadios->AddFrame(fGEnergy,fLRadios); //Number of Events fText = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame); fLNEvents = new TGLabel(fText, new TGString("Number of Events:")); fENEvents = new TGTextEntry(fText, fTNEvents = new TGTextBuffer(7)); fTNEvents->AddText(0,"200000"); fENEvents->Resize(100, fENEvents->GetDefaultHeight()); fLText1 = new TGLayoutHints(kLHintsTop | kLHintsCenterY, 3, 5, 0, 0); fLText2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterY, 0, 2, 0, 0); fText->AddFrame(fLNEvents, fLText1); fText->AddFrame(fENEvents, fLText2); //Buttons fButtons = new TGHorizontalFrame(fDialog, 60, 20, kFixedWidth); fLButtons = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0); fOk = new TGTextButton(fButtons, "&Ok", 1); fCancel = new TGTextButton(fButtons, "&Cancel", 2); fOk->Connect("Clicked()", "SettingDialog", this, "DoOk()"); fCancel->Connect("Clicked()", "SettingDialog", this, "DoCancel()"); fButtons->AddFrame(fOk,fLButtons); fButtons->AddFrame(fCancel,fLButtons); //Add subframes fDialog->AddFrame(fRadios, fLDialog); fDialog->AddFrame(fText, fLDialog); fDialog->AddFrame(fButtons, fLDialog); fDialog->MapSubwindows(); fDialog->Resize(fDialog->GetDefaultSize()); fDialog->SetWindowName("Settings"); fDialog->MapWindow(); gClient->WaitFor(fDialog); } void SettingDialog::DoCancel() { // Handle Close button. fDialog->SendCloseMessage(); } /////////////////////////////////////////////////////////////////////////// // // // Input Dialog Widget // // // /////////////////////////////////////////////////////////////////////////// #ifndef SettingsDialog_h #define SettingsDialog_h 1 #include <TGFrame.h> #include <TGLayout.h> #include <TGButtonGroup.h> #include <TGTextEntry.h> #include <TGTextBuffer.h> #include <TGLabel.h> #include <TGButton.h> class SettingDialog { public: SettingDialog(); ~SettingDialog(); void DoCancel(); private: TGTransientFrame *fDialog; // transient frame, main dialog window TGLayoutHints *fLDialog; TGCompositeFrame *fRadios; // frame with materials and energy rad. buttons TGLayoutHints *fLRadios; //Materials TGGroupFrame *fGMaterial; //Group frame with material buttons TGRadioButton *fRMaterial[4]; TGLayoutHints *fLMaterial; //Energies TGGroupFrame *fGEnergy; //Group frame with energy buttons TGRadioButton *fREnergy[5]; TGLayoutHints *fLEnergy; //Text for NEvents TGCompositeFrame *fText; TGLayoutHints *fLText1, *fLText2; TGTextEntry *fENEvents; TGTextBuffer *fTNEvents; TGLabel *fLNEvents; //Buttons TGHorizontalFrame *fButtons; TGLayoutHints *fLButtons; TGTextButton *fOk,*fCancel; }; #endif /////////////////////////////////////////////////////////////////////////// // // // Input Dialog Widget // // // /////////////////////////////////////////////////////////////////////////// #ifndef SettingsDialog_h #define SettingsDialog_h 1 #include <TGFrame.h> #include <TGLayout.h> #include <TGButtonGroup.h> #include <TGTextEntry.h> #include <TGTextBuffer.h> #include <TGLabel.h> #include <TGButton.h> class SettingDialog { public: SettingDialog(); ~SettingDialog(); void DoCancel(); private: TGTransientFrame *fDialog; // transient frame, main dialog window TGLayoutHints *fLDialog; TGCompositeFrame *fRadios; // frame with materials and energy rad. buttons TGLayoutHints *fLRadios; //Materials TGButtonGroup *fGMaterial; //Group frame with material buttons TGRadioButton *fRMaterial[4]; TGLayoutHints *fLMaterial; //Energies TGButtonGroup *fGEnergy; //Group frame with energy buttons TGRadioButton *fREnergy[5]; TGLayoutHints *fLEnergy; //Text for NEvents TGCompositeFrame *fText; TGLayoutHints *fLText1, *fLText2; TGTextEntry *fENEvents; TGTextBuffer *fTNEvents; TGLabel *fLNEvents; //Buttons TGHorizontalFrame *fButtons; TGLayoutHints *fLButtons; TGTextButton *fOk,*fCancel; }; #endif #include "SettingsDialog.h" #include <TGString.h> SettingDialog::~SettingDialog() { } SettingDialog::SettingDialog() { // Create simple input dialog. const TGWindow *main = gClient->GetRoot(); fDialog = new TGTransientFrame(main, main, 100, 100, kVerticalFrame); fDialog->Connect("CloseWindow()", "SettingDialog", this, "CloseWindow()"); fLDialog = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 3, 0); // Main frame for materials and energy radio buttons fRadios = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame); fLRadios = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2); //------------- Group Frame for materials fLMaterial = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 5, 0); fGMaterial = new TGButtonGroup(fRadios, "Materials"); fRMaterial[0] = new TGRadioButton(fGMaterial, new TGHotString("All"), 11); fRMaterial[1] = new TGRadioButton(fGMaterial, new TGHotString("Aluminium"), 12); fRMaterial[2] = new TGRadioButton(fGMaterial, new TGHotString("Iron"), 13); fRMaterial[3] = new TGRadioButton(fGMaterial, new TGHotString("Lead"), 14); for (unsigned int i = 0; i < 4; ++i) { fGMaterial->AddFrame(fRMaterial[i], fLMaterial); fRMaterial[i]->Connect("Pressed()", "TestMsgBox", this, "DoRadio()"); } fRadios->AddFrame(fGMaterial,fLRadios); //------------ Group Frame for materials fLEnergy = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 5, 0); fGEnergy = new TGButtonGroup(fRadios, "Energies"); fREnergy[0] = new TGRadioButton(fGEnergy, new TGHotString("All"), 21); fREnergy[1] = new TGRadioButton(fGEnergy, new TGHotString("113 MeV"), 22); fREnergy[2] = new TGRadioButton(fGEnergy, new TGHotString("256 MeV"), 23); fREnergy[3] = new TGRadioButton(fGEnergy, new TGHotString("597 MeV"), 24); fREnergy[4] = new TGRadioButton(fGEnergy, new TGHotString("800 MeV"), 25); for (unsigned int i = 0; i < 5; ++i) { fGEnergy->AddFrame(fREnergy[i], fLEnergy); fREnergy[i]->Connect("Pressed()", "TestMsgBox", this, "DoRadio()"); } fRadios->AddFrame(fGEnergy,fLRadios); //Number of Events fText = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame); fLNEvents = new TGLabel(fText, new TGString("Number of Events:")); fENEvents = new TGTextEntry(fText, fTNEvents = new TGTextBuffer(7)); fTNEvents->AddText(0,"200000"); fENEvents->Resize(100, fENEvents->GetDefaultHeight()); fLText1 = new TGLayoutHints(kLHintsTop | kLHintsCenterY, 3, 5, 0, 0); fLText2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterY, 0, 2, 0, 0); fText->AddFrame(fLNEvents, fLText1); fText->AddFrame(fENEvents, fLText2); //Buttons fButtons = new TGHorizontalFrame(fDialog, 60, 20, kFixedWidth); fLButtons = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 5, 5, 0, 0); fOk = new TGTextButton(fButtons, "&Ok", 1); fCancel = new TGTextButton(fButtons, "&Cancel", 2); fOk->Connect("Clicked()", "SettingDialog", this, "DoOk()"); fCancel->Connect("Clicked()", "SettingDialog", this, "DoCancel()"); fButtons->AddFrame(fOk,fLButtons); fButtons->AddFrame(fCancel,fLButtons); //Add subframes fDialog->AddFrame(fRadios, fLDialog); fDialog->AddFrame(fText, fLDialog); fDialog->AddFrame(fButtons, fLDialog); fDialog->MapSubwindows(); fDialog->Resize(fDialog->GetDefaultSize()); fDialog->SetWindowName("Settings"); fDialog->MapWindow(); gClient->WaitFor(fDialog); } void SettingDialog::DoCancel() { // Handle Close button. fDialog->SendCloseMessage(); }
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET