ROOT logo

From $ROOTSYS/tutorials/gui/textEntries.C

// Author: Valeriy Onuchin   25/08/2007
//
// 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) :
   TGGroupFrame(p, name) 
{
   // Group frame containing combobox and text entry.

   TGHorizontalFrame *horz = new TGHorizontalFrame(this);
   AddFrame(horz, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY));
   TGLabel *label = new TGLabel(horz, title);
   horz->AddFrame(label, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));

   fCombo = new TGComboBox(horz);
   horz->AddFrame(fCombo, new TGLayoutHints(kLHintsRight | kLHintsExpandY,
                                            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(Int_t)");
   combo->Select(TGTextEntry::kNormal);

   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(Int_t)");
   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();
}
 textEntries.C:1
 textEntries.C:2
 textEntries.C:3
 textEntries.C:4
 textEntries.C:5
 textEntries.C:6
 textEntries.C:7
 textEntries.C:8
 textEntries.C:9
 textEntries.C:10
 textEntries.C:11
 textEntries.C:12
 textEntries.C:13
 textEntries.C:14
 textEntries.C:15
 textEntries.C:16
 textEntries.C:17
 textEntries.C:18
 textEntries.C:19
 textEntries.C:20
 textEntries.C:21
 textEntries.C:22
 textEntries.C:23
 textEntries.C:24
 textEntries.C:25
 textEntries.C:26
 textEntries.C:27
 textEntries.C:28
 textEntries.C:29
 textEntries.C:30
 textEntries.C:31
 textEntries.C:32
 textEntries.C:33
 textEntries.C:34
 textEntries.C:35
 textEntries.C:36
 textEntries.C:37
 textEntries.C:38
 textEntries.C:39
 textEntries.C:40
 textEntries.C:41
 textEntries.C:42
 textEntries.C:43
 textEntries.C:44
 textEntries.C:45
 textEntries.C:46
 textEntries.C:47
 textEntries.C:48
 textEntries.C:49
 textEntries.C:50
 textEntries.C:51
 textEntries.C:52
 textEntries.C:53
 textEntries.C:54
 textEntries.C:55
 textEntries.C:56
 textEntries.C:57
 textEntries.C:58
 textEntries.C:59
 textEntries.C:60
 textEntries.C:61
 textEntries.C:62
 textEntries.C:63
 textEntries.C:64
 textEntries.C:65
 textEntries.C:66
 textEntries.C:67
 textEntries.C:68
 textEntries.C:69
 textEntries.C:70
 textEntries.C:71
 textEntries.C:72
 textEntries.C:73
 textEntries.C:74
 textEntries.C:75
 textEntries.C:76
 textEntries.C:77
 textEntries.C:78
 textEntries.C:79
 textEntries.C:80
 textEntries.C:81
 textEntries.C:82
 textEntries.C:83
 textEntries.C:84
 textEntries.C:85
 textEntries.C:86
 textEntries.C:87
 textEntries.C:88
 textEntries.C:89
 textEntries.C:90
 textEntries.C:91
 textEntries.C:92
 textEntries.C:93
 textEntries.C:94
 textEntries.C:95
 textEntries.C:96
 textEntries.C:97
 textEntries.C:98
 textEntries.C:99
 textEntries.C:100
 textEntries.C:101
 textEntries.C:102
 textEntries.C:103
 textEntries.C:104
 textEntries.C:105
 textEntries.C:106
 textEntries.C:107
 textEntries.C:108
 textEntries.C:109
 textEntries.C:110
 textEntries.C:111
 textEntries.C:112
 textEntries.C:113
 textEntries.C:114
 textEntries.C:115
 textEntries.C:116
 textEntries.C:117
 textEntries.C:118
 textEntries.C:119
 textEntries.C:120
 textEntries.C:121
 textEntries.C:122
 textEntries.C:123
 textEntries.C:124
 textEntries.C:125
 textEntries.C:126
 textEntries.C:127
 textEntries.C:128
 textEntries.C:129
 textEntries.C:130
 textEntries.C:131
 textEntries.C:132
 textEntries.C:133
 textEntries.C:134
 textEntries.C:135
 textEntries.C:136
 textEntries.C:137
 textEntries.C:138
 textEntries.C:139
 textEntries.C:140
 textEntries.C:141
 textEntries.C:142
 textEntries.C:143
 textEntries.C:144
 textEntries.C:145
thumb