Hi Christian, below some more answers to your questions. Cheers, Fons. "cstrato@EUnet.at" wrote: > > Dear Rooters > > Below I enclose a simple macro displaying the outline for a dialogbox. > I would like to use this macro (gui1.C) to ask some questions related > to the use of the GUI classes: > > 1, Memory leaks: > In line 84 I use the following code, similar to code found in guitest.C: > > fFrameInfo->AddFrame(new TGLabel(fFrameInfo,new TGString("Last > Name")), > new TGLayoutHints(kLHintsTop | kLHintsLeft)); > Here TGLabel, TGString and TGLayoutHints are created within a function, > but never explicitely deleted. Does this result in memory leaks when the > > dialogbox will be closed, or will these objects be deleted > automatically? > Explained in previous mail. > > 2, TGGroupFrame "Author Info": > Here I use TGMatrixLayout which results in a large distance between > TGLabel > and TGTextEntry. Is there a better way to implement it? > Could I use TGTableLayout, and how do I need to implement this? (line 71 > > results in segmentation error) > How can I make sure that TGTextEntry extends to the right end of a frame > > without using Resize()? > Explained by Brett Viren and his TGTableLayout. > > 3, Tabulator key: > Usually, the tabulator key is used to move from one Textentry field to > the > next. Is there a way to implement this behavior in this case? > You can move from TGTextEntry to the next by calling TGTextEntry::SetFocus(). However, there was no way to bind the "standard" <TAB> key to do this. In the version of ROOT in CVS this is now possible. The TGTextEntry now generates a "TabPressed()" signal to which you can bind the focus changing method. See modified source below of your original gui1.C. > 4, Choose Directory: > Sometimes it is necessary to select a directory. For these purposes, the > > Open-Dialogboxes often have an extra button "Choose Directory". > In the current macro I select a directory using TGFileDialog, however, > this is not completely satisfactorily: When I select a directory, then > the selected directory is stored in TGFileInfo.fFilename instead of > TGFileInfo.fIniDir. > Is there a way to easily extend TGFileDialog, so that it displays a > button "Choose Directory"? > Currently use TSystem::GetPathInfo() to check if the returned fFilename is a directory or a normal file. > > 5, Size of "OK"-button: > What is the best way to ensure that "Cancel" and "OK" button have the > same size? (fOkBtn->Resize(150,20) on line 116 has no effect) > See modified gui1.C below. The trick is to use the kLHintsExpandX layout hint which will divide equally the available fixed space in the horizontal frame between the buttons. > 6, Return-key for "OK"-button: > Usually, pressing the Return-key is analogous to clicking the > "OK"-button. > How can I implement this in the macro? > (Maybe, this could be implemented in class TGTextButton?) > The TGTextEntry emits the "ReturnPressed()" signal when the return or enter key is hit. Just connect it to "FPressOK()". > > 7, Position of main window: > Why does "fMain->SetWMPosition(140,120)" on line 127 place the main > window at top-left instead of the position (140,120)? > The SetWMPosition() is a hint to the Window Manager. The WM might not honor this request due to the active window placement policy in effect (like random or tiled window placement). You can force the placement using fMain->Move(140,120). See below. //--------------------------------------// // macro gui1.C // //--------------------------------------// #include <stdio.h> #include <stdlib.h> #include <iostream.h> #include <TROOT.h> #include <TApplication.h> #include <TVirtualX.h> #include <RQ_OBJECT.h> #include <TGFrame.h> #include <TGMenu.h> #include <TGTextEntry.h> #include <TGTextBuffer.h> #include <TGListBox.h> #include <TGFileDialog.h> #include <TSystem.h> #include <TEnv.h> const char *filetypes[] = { "All files", "*", "ROOT files", "*.root", "ROOT macros", "*.C", 0, 0 }; class TNewDlog { RQ_OBJECT() private: TGMainFrame *fMain; TGCompositeFrame *fFrameLT; TGGroupFrame *fFrameInfo; TGTextEntry *fNameF; TGTextBuffer *fBufF; TGTextEntry *fNameL; TGTextBuffer *fBufL; TGGroupFrame *fFrameDir; // TGListBox *fDir; TGTextEntry *fDir; TGTextBuffer *fBufDir; TGButton *fBrowseBtn; TGCompositeFrame *fFrameLB; TGButton *fOkBtn; TGButton *fCancelBtn; public: TNewDlog(const TGWindow *vWindow, UInt_t vWidth, UInt_t vHeight, UInt_t vOptions = kVerticalFrame); virtual ~TNewDlog(); // slots void FCloseWindow(); void FBrowse(); void FPressOK(); void FCancel(); void FChangeFocus(); }; TNewDlog::TNewDlog(const TGWindow *vWindow, UInt_t vWidth, UInt_t vHeight, UInt_t vOptions) { fMain = new TGMainFrame(vWindow, vWidth, vHeight, vOptions); fMain->Connect("CloseWindow()", "TNewDlog", this, "FCloseWindow()"); // FrameLT for subframes fFrameLT = new TGCompositeFrame(fMain, 200, 20, kVerticalFrame); fMain->AddFrame(fFrameLT, new TGLayoutHints(kLHintsLeft | kLHintsTop)); // Subframe Project Info fFrameInfo = new TGGroupFrame(fFrameLT, "Author Info", kVerticalFrame); // fFrameInfo->SetLayoutManager(new TGTableLayout(fFrameInfo,2,2)); //error fFrameInfo->SetLayoutManager(new TGMatrixLayout(fFrameInfo,0,2,10)); fFrameLT->AddFrame(fFrameInfo, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5,5,5,5)); fFrameInfo->AddFrame(new TGLabel(fFrameInfo,new TGString("First Name")), new TGLayoutHints(kLHintsTop | kLHintsLeft)); fNameF = new TGTextEntry(fFrameInfo, fBufF = new TGTextBuffer(100), -1); fNameF->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); fNameF->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); fFrameInfo->AddFrame(fNameF, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2)); fNameF->Resize(250, fNameF->GetDefaultHeight()); fFrameInfo->AddFrame(new TGLabel(fFrameInfo,new TGString("Last Name")), new TGLayoutHints(kLHintsTop | kLHintsLeft)); fNameL = new TGTextEntry(fFrameInfo, fBufL = new TGTextBuffer(100), -1); fNameL->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); fNameL->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); fFrameInfo->AddFrame(fNameL, new TGLayoutHints(kLHintsTop | kLHintsLeft, 2, 2, 2, 2)); fNameL->Resize(250, fNameL->GetDefaultHeight()); // Subframe Directory fFrameDir = new TGGroupFrame(fFrameLT, "Directory", kHorizontalFrame); fFrameLT->AddFrame(fFrameDir, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,5, 5, 5, 5)); fDir = new TGTextEntry(fFrameDir, fBufDir = new TGTextBuffer(255), -1); fDir->Connect("ReturnPressed()", "TNewDlog", this, "FPressOK()"); fDir->Connect("TabPressed()", "TNewDlog", this, "FChangeFocus()"); // fDir = new TGListBox(fFrameDir,-1); fDir->Resize(400,20); char tmp[255]; sprintf(tmp,"%s",gSystem->WorkingDirectory()); fDir->SetText(tmp); // fDir->AddEntry(tmp,1); fFrameDir->AddFrame(fDir, new TGLayoutHints(kLHintsLeft|kLHintsTop,2,2,2,2)); fBrowseBtn = new TGTextButton(fFrameDir, "&Browse...", 1); fBrowseBtn->Connect("Clicked()", "TNewDlog", this, "FBrowse()"); fFrameDir->AddFrame(fBrowseBtn, new TGLayoutHints(kLHintsRight | kLHintsTop)); // FrameLB for OK, Cancel fFrameLB = new TGHorizontalFrame(fMain, 200, 20, kFixedWidth); fMain->AddFrame(fFrameLB, new TGLayoutHints(kLHintsLeft | kLHintsBottom)); fOkBtn = new TGTextButton(fFrameLB, "&OK", 1); fOkBtn->Connect("Clicked()", "TNewDlog", this, "FPressOK()"); //fOkBtn->Resize(150,20); // does not work fFrameLB->AddFrame(fOkBtn, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); fCancelBtn = new TGTextButton(fFrameLB, "&Cancel", 1); fCancelBtn->Connect("Clicked()", "TNewDlog", this, "FCancel()"); fFrameLB->AddFrame(fCancelBtn, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5)); fFrameLB->Resize(150, fOkBtn->GetDefaultHeight()); fMain->MapSubwindows(); fMain->Resize(fMain->GetDefaultSize()); fMain->SetWMPosition(140,120); fMain->Move(140,120); // fMain->Resize(400,220); fMain->SetWindowName("New Dialog"); fMain->MapWindow(); }//Constructor //----------------------------------------------------------------------// TNewDlog::~TNewDlog() { delete fOkBtn; delete fCancelBtn; delete fFrameLB; delete fBrowseBtn; delete fDir; delete fFrameDir; delete fNameL; delete fNameF; delete fFrameInfo; delete fFrameLT; delete fMain; }//Destructor //----------------------------------------------------------------------// void TNewDlog::FCloseWindow() { delete this; }//FCloseWindow //----------------------------------------------------------------------// void TNewDlog::FBrowse() { printf("Browse\n"); TGFileInfo fi; fi.fFileTypes = filetypes; fi.fIniDir = fBufDir->GetString(); printf("fIniDir = %s\n", fi.fIniDir); new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi); printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); fDir->SetText(fi.fIniDir); }//FBrowseProject //----------------------------------------------------------------------// void TNewDlog::FCancel() { // Clear entries fBufF->Clear(); fBufL->Clear(); printf("Cancel\n"); }//FCancel //----------------------------------------------------------------------// void TNewDlog::FPressOK() { cout << "First Name: " << fBufF->GetString() << endl; cout << "Last Name: " << fBufL->GetString() << endl; cout << "Directory: " << fBufDir->GetString() << endl; fMain->SendCloseMessage(); }//FPressOK //----------------------------------------------------------------------// void TNewDlog::FChangeFocus() { if (gTQSender == fNameF) fNameL->SetFocus(); if (gTQSender == fNameL) fDir->SetFocus(); if (gTQSender == fDir) fNameF->SetFocus(); } //----------------------------------------------------------------------// void gui1() { new TNewDlog(gClient->GetRoot(), 400, 220); } //-------------------------END-------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:57 MET