Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootDialog.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 20/02/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TRootDialog
14 \ingroup guiwidgets
15
16A TRootDialog is used to prompt for the arguments of an object's
17member function. A TRootDialog is created via the context menu's
18when selecting a member function taking arguments.
19
20*/
21
22
23#include "TRootDialog.h"
24#include "TRootContextMenu.h"
25#include "TContextMenu.h"
26#include "TClassMenuItem.h"
27#include "TList.h"
28#include "TGLabel.h"
29#include "TGTextEntry.h"
30#include "TGButton.h"
31#include "TObjString.h"
32#include "KeySymbols.h"
33#include "TVirtualX.h"
34
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Create a method argument prompt dialog.
41
43 const char *title, Bool_t okB, Bool_t cancelB, Bool_t applyB,
44 Bool_t helpB) : TGTransientFrame(gClient->GetRoot(), main, 200, 100)
45{
46 fMenu = cmenu;
47
48 fOk = okB;
49 fCancel = cancelB;
50 fApply = applyB;
51 fHelp = helpB;
52
53 fWidgets = new TList;
54
55 fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
56 fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
57
58 SetWindowName(title);
59 SetIconName(title);
61
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Delete the dialog.
67
69{
71 delete fWidgets;
72 delete fL1;
73 delete fL2;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// Add a label and text input field.
78
79void TRootDialog::Add(const char *argname, const char *value, const char *type)
80{
81 TGLabel *l = new TGLabel(this, argname);
82 TString svalue(value);
83 // keep double backslashes (e.g. in case of LateX formatting, like \\gamma)
84 svalue.ReplaceAll("\\", "\\\\");
85 TGTextBuffer *b = new TGTextBuffer(20); b->AddText(0, svalue.Data());
86 TGTextEntry *t = new TGTextEntry(this, b);
87
88 t->Connect("TabPressed()", "TRootDialog", this, "TabPressed()");
89
90 t->Associate(fMenu);
91 t->Resize(260, t->GetDefaultHeight());
92 AddFrame(l, fL1);
93 AddFrame(t, fL2);
94
95 fWidgets->Add(l);
96 fWidgets->Add(t); // TGTextBuffer will be deleted by TGTextEntry
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Get parameter string (called by contextmenu after OK or Apply has
102/// been selected).
103
105{
106 static TString params;
107 TString param;
108
109 TObjString *str;
110 TObject *obj;
111
112 Int_t selfobjpos;
115 else
116 selfobjpos = -1;
117
118 params.Clear();
119 TIter next(fWidgets);
120 Int_t nparam = 0;
121
122 while ((obj = next())) { // first element is label, skip...
123 if (obj->IsA() != TGLabel::Class()) break;
124 obj = next(); // get either TGTextEntry or TGComboBox
125 str = (TObjString *) next(); // get type string
126
127 nparam++;
128
129 const char *type = str ? str->GetString().Data() : 0;
130 const char *data = 0;
131
132 if (obj && obj->IsA() == TGTextEntry::Class())
133 data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
134
135 // TODO: Combobox...
136
137 // if necessary, replace the selected object by it's address
138 if (selfobjpos == nparam-1) {
139 if (params.Length()) params += ",";
140 param = TString::Format("(TObject*)0x%zx",
142 params += param;
143 }
144
145 if (params.Length()) params += ",";
146 if (type && data) {
147 if (!strncmp(type, "char*", 5))
148 param = TString::Format("\"%s\"", data);
149 else
150 param = TString::Format("(%s)%s", type, data);
151 } else
152 param = "0";
153
154 params += param;
155 }
156
157 // if selected object is the last argument, have to insert it here
158 if (selfobjpos == nparam) {
159 if (params.Length()) params += ",";
160 param = TString::Format("(TObject*)0x%zx",
162 params += param;
163 }
164
165 return params.Data();
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Popup dialog.
170
172{
173 //--- create the OK, Apply and Cancel buttons
174
175 UInt_t nb = 0, width = 0, height = 0;
176
177 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
179
180 // put hf as last in the list to be deleted
181 fWidgets->Add(l1);
182
184 if (fOk) {
185 b = new TGTextButton(hf, "&OK", 1);
186 fWidgets->Add(b);
187 b->Associate(fMenu);
188 hf->AddFrame(b, l1);
189 height = b->GetDefaultHeight();
190 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
191 }
192 if (fApply) {
193 b = new TGTextButton(hf, "&Apply", 2);
194 fWidgets->Add(b);
195 b->Associate(fMenu);
196 hf->AddFrame(b, l1);
197 height = b->GetDefaultHeight();
198 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
199 }
200 if (fCancel) {
201 b = new TGTextButton(hf, "&Cancel", 3);
202 fWidgets->Add(b);
203 b->Associate(fMenu);
204 hf->AddFrame(b, l1);
205 height = b->GetDefaultHeight();
206 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
207 }
208 if (fHelp) {
209 b = new TGTextButton(hf, "Online &Help", 4);
210 fWidgets->Add(b);
211 b->Associate(fMenu);
212 hf->AddFrame(b, l1);
213 height = b->GetDefaultHeight();
214 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
215 }
216
217 // place buttons at the bottom
218 l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
219 fWidgets->Add(l1);
220 fWidgets->Add(hf);
221
222 AddFrame(hf, l1);
223
224 // keep the buttons centered and with the same width
225 hf->Resize((width + 20) * nb, height);
226
227 // map all widgets and calculate size of dialog
229
232
234
235 // position relative to the parent's window
237
238 // make the message box non-resizable
241
247
248 MapWindow();
249 fClient->WaitFor(this);
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Called when closed via window manager action.
254
256{
257 // Send Cancel button message to context menu eventhandler
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Handle Tab keyboard navigation in this dialog.
263
265{
266 Bool_t setNext = kFALSE;
267 TGTextEntry *entry;
268 TIter next(fWidgets);
269
270 while ( TObject* obj = next() ) {
271 if ( obj->IsA() == TGTextEntry::Class() ) {
272 entry = (TGTextEntry*) obj;
273 if ( entry == gBlinkingEntry ) {
274 setNext = kTRUE;
275 } else if ( setNext ) {
276 entry->SetFocus();
277 entry->End();
278 return;
279 }
280 }
281 }
282
283 next.Reset();
284 while ( TObject* obj = next() ) {
285 if ( obj->IsA() == TGTextEntry::Class() ) {
286 entry = (TGTextEntry*) obj;
287 entry->SetFocus();
288 entry->End();
289 return;
290 }
291 }
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// The key press event handler in this dialog.
296
298{
299 char tmp[10];
300 UInt_t keysym;
301 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
302 if ((EKeySym)keysym == kKey_Tab) {
303
304 TGTextEntry *entry;
305 TIter next(fWidgets);
306
307 while ( TObject* obj = next() ) {
308 if ( obj->IsA() == TGTextEntry::Class() ) {
309 entry = (TGTextEntry*) obj;
310 entry->TabPressed();
311 return kTRUE;
312 }
313 }
314 }
315
317}
const Mask_t kKeyPressMask
Definition GuiTypes.h:159
@ kFixedWidth
Definition GuiTypes.h:387
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:168
const Mask_t kEnterWindowMask
Definition GuiTypes.h:167
EKeySym
Definition KeySymbols.h:25
@ kKey_Tab
Definition KeySymbols.h:27
int main()
Definition Prototype.cxx:12
#define b(i)
Definition RSha256.hxx:100
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define gClient
Definition TGClient.h:157
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorMaximize
Definition TGFrame.h:69
@ kMWMDecorMinimize
Definition TGFrame.h:68
@ kMWMDecorMenu
Definition TGFrame.h:67
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kMWMFuncMinimize
Definition TGFrame.h:52
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
TGTextEntry * gBlinkingEntry
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetMWMHints
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
TGTextEntry * gBlinkingEntry
#define gVirtualX
Definition TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kC_COMMAND
@ kCM_BUTTON
virtual Int_t GetSelfObjectPos() const
virtual TContextMenu * GetContextMenu() const
virtual TClassMenuItem * GetSelectedMenuItem()
virtual TObject * GetSelectedObject()
void WaitFor(TGWindow *w)
Wait for window to be destroyed.
Definition TGClient.cxx:709
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:314
void SetEditDisabled(UInt_t on=1) override
Set edit disable flag for this frame and subframes.
Definition TGFrame.cxx:1022
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:339
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
void MapWindow() override
map window
Definition TGFrame.h:204
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
static TClass * Class()
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1893
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
Bool_t HandleKey(Event_t *event) override
Handle keyboard events.
Definition TGFrame.cxx:1606
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
virtual void SetFocus()
Set focus to this text entry.
static TClass * Class()
virtual void TabPressed()
This signal is emitted when the <TAB> key is pressed.
void End(Bool_t mark=kFALSE)
Moves the text cursor to the right end of the line.
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:498
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1957
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
ROOT GUI Window base class.
Definition TGWindow.h:23
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
void Reset()
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
Mother of all ROOT objects.
Definition TObject.h:41
virtual TClass * IsA() const
Definition TObject.h:245
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:869
This class provides an interface to context sensitive popup menus.
A TRootDialog is used to prompt for the arguments of an object's member function.
Definition TRootDialog.h:21
TGLayoutHints * fL2
text entry layout
Definition TRootDialog.h:26
TGLayoutHints * fL1
label layout
Definition TRootDialog.h:25
void CloseWindow() override
Called when closed via window manager action.
virtual void Add(const char *argname, const char *value, const char *type)
Add a label and text input field.
TRootDialog(TRootContextMenu *cmenu=nullptr, const TGWindow *main=nullptr, const char *title="ROOT Dialog", Bool_t okB=kTRUE, Bool_t cancelB=kTRUE, Bool_t applyB=kFALSE, Bool_t helpB=kTRUE)
Create a method argument prompt dialog.
Bool_t fHelp
if true show Online Help button
Definition TRootDialog.h:31
virtual const char * GetParameters()
Get parameter string (called by contextmenu after OK or Apply has been selected).
void TabPressed()
Handle Tab keyboard navigation in this dialog.
Bool_t fCancel
if true show Cancel button
Definition TRootDialog.h:29
Bool_t fApply
if true show Apply button
Definition TRootDialog.h:30
TList * fWidgets
label and text field widgets created in dialog
Definition TRootDialog.h:27
virtual void Popup()
Popup dialog.
Bool_t fOk
if true show OK button
Definition TRootDialog.h:28
virtual ~TRootDialog()
Delete the dialog.
TRootContextMenu * fMenu
associated context menu
Definition TRootDialog.h:24
Bool_t HandleKey(Event_t *event) override
The key press event handler in this dialog.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1221
const char * Data() const
Definition TString.h:380
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2356
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Event structure.
Definition GuiTypes.h:174
TLine l
Definition textangle.C:4