Logo ROOT  
Reference Guide
textEntries.C File Reference

Detailed Description

This macro gives an example of how to set/change text entry attributes. To run it do either:

.x textEntries.C
.x textEntries.C++
#include <TGTextEntry.h>
#include <TGButtonGroup.h>
#include <TGLabel.h>
#include <TGComboBox.h>
#include <TApplication.h>
//////////// auxilary class ///////////////////////////////////////////////////
class GroupBox : public TGGroupFrame {
private:
TGComboBox *fCombo; // combo box
TGTextEntry *fEntry; // text entry
public:
GroupBox(const TGWindow *p, const char *name, const char *title);
TGTextEntry *GetEntry() const { return fEntry; }
TGComboBox *GetCombo() const { return fCombo; }
ClassDef(GroupBox, 0)
};
//______________________________________________________________________________
GroupBox::GroupBox(const TGWindow *p, const char *name, const char *title) :
{
// Group frame containing combobox and text entry.
TGLabel *label = new TGLabel(horz, title);
fCombo = new TGComboBox(horz);
5, 0, 5, 5));
fCombo->Resize(100, 20);
fEntry = new TGTextEntry(this);
AddFrame(fEntry, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
}
////////////////////////////////////////////////////////////////////////////////
class TextEntryWindow {
protected:
TGMainFrame *fMain; // main frame
GroupBox *fEcho; // echo mode (echo, password, no echo)
GroupBox *fAlign; // alignment (left, right, center)
GroupBox *fAccess; // read-only mode
GroupBox *fBorder; // border mode
public:
TextEntryWindow();
virtual ~TextEntryWindow() { delete fMain; }
ClassDef(TextEntryWindow, 0);
};
//______________________________________________________________________________
TextEntryWindow::TextEntryWindow()
{
// Main test window.
TGComboBox *combo;
TGTextEntry *entry;
fMain = new TGMainFrame(gClient->GetRoot(), 10, 10, kVerticalFrame);
// recusively delete all subframes on exit
fMain->SetCleanup(kDeepCleanup);
fEcho = new GroupBox(fMain, "Echo", "Mode:");
fMain->AddFrame(fEcho, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
combo = fEcho->GetCombo();
entry = fEcho->GetEntry();
// add entries
combo->AddEntry("Normal", TGTextEntry::kNormal);
combo->AddEntry("Password", TGTextEntry::kPassword);
combo->AddEntry("No Echo", TGTextEntry::kNoEcho);
combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEchoMode(TGTextEntry::EEchoMode)");
fAlign = new GroupBox(fMain, "Alignment", "Type:");
fMain->AddFrame(fAlign, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
combo = fAlign->GetCombo();
entry = fAlign->GetEntry();
// add entries
combo->AddEntry("Left", kTextLeft);
combo->AddEntry("Centered", kTextCenterX);
combo->AddEntry("Right", kTextRight);
combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetAlignment(ETextJustification)");
combo->Select(kTextLeft);
fAccess = new GroupBox(fMain, "Access", "Read-only:");
fMain->AddFrame(fAccess, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
combo = fAccess->GetCombo();
entry = fAccess->GetEntry();
// add entries
combo->AddEntry("False", 1);
combo->AddEntry("True", 0);
combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetEnabled(Int_t)");
combo->Select(1);
fBorder = new GroupBox(fMain, "Border", "Drawn:");
fMain->AddFrame(fBorder, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
combo = fBorder->GetCombo();
entry = fBorder->GetEntry();
// add entries
combo->AddEntry("False", 0);
combo->AddEntry("True", 1);
combo->Connect("Selected(Int_t)", "TGTextEntry", entry, "SetFrameDrawn(Int_t)");
combo->Select(1);
// terminate ROOT session when window is closed
fMain->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
fMain->DontCallClose();
fMain->MapSubwindows();
fMain->Resize();
// set minimum width, height
fMain->SetWMSizeHints(fMain->GetDefaultWidth(), fMain->GetDefaultHeight(),
1000, 1000, 0, 0);
fMain->SetWindowName("Text Entries");
fMain->MapRaised();
}
////////////////////////////////////////////////////////////////////////////////
void textEntries()
{
// Main program.
new TextEntryWindow();
}
Author
Valeriy Onuchin 25/08/2007

Definition in file textEntries.C.

TGTextEntry::kNoEcho
@ kNoEcho
Definition: TGTextEntry.h:42
TGComboBox.h
TGWindow
Definition: TGWindow.h:31
TGMainFrame
Definition: TGFrame.h:444
TGComboBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:106
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGLabel
Definition: TGLabel.h:32
TGComboBox::Select
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:451
kTextCenterX
@ kTextCenterX
Definition: TGWidget.h:42
TGHorizontalFrame
Definition: TGFrame.h:423
gClient
#define gClient
Definition: TGClient.h:166
kTextLeft
@ kTextLeft
Definition: TGWidget.h:40
TApplication.h
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGTextEntry
Definition: TGTextEntry.h:39
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:39
TGLayoutHints
Definition: TGLayout.h:57
TGTextEntry::kPassword
@ kPassword
Definition: TGTextEntry.h:42
TGGroupFrame
Definition: TGFrame.h:587
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
TGTextEntry::kNormal
@ kNormal
Definition: TGTextEntry.h:42
TGComboBox
Definition: TGComboBox.h:67
TGLabel.h
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:864
TGTextEntry.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
kTextRight
@ kTextRight
Definition: TGWidget.h:41
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102