Logo ROOT   6.16/01
Reference Guide
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// //
14// TRootDialog //
15// //
16// A TRootDialog is used to prompt for the arguments of an object's //
17// member function. A TRootDialog is created via the context menu's //
18// when selecting a member function taking arguments. //
19// //
20//////////////////////////////////////////////////////////////////////////
21
22#include "TRootDialog.h"
23#include "TRootContextMenu.h"
24#include "TContextMenu.h"
25#include "TClassMenuItem.h"
26#include "TList.h"
27#include "TGLabel.h"
28#include "TGTextEntry.h"
29#include "TGButton.h"
30#include "TObjString.h"
31#include "KeySymbols.h"
32
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a method argument prompt dialog.
39
41 const char *title, Bool_t okB, Bool_t cancelB, Bool_t applyB,
42 Bool_t helpB) : TGTransientFrame(gClient->GetRoot(), main, 200, 100)
43{
44 fMenu = cmenu;
45
46 fOk = okB;
47 fCancel = cancelB;
48 fApply = applyB;
49 fHelp = helpB;
50
51 fWidgets = new TList;
52
53 fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
54 fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
55
56 SetWindowName(title);
57 SetIconName(title);
59
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Delete the dialog.
65
67{
69 delete fWidgets;
70 delete fL1;
71 delete fL2;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Add a label and text input field.
76
77void TRootDialog::Add(const char *argname, const char *value, const char *type)
78{
79 TGLabel *l = new TGLabel(this, argname);
80 TString svalue(value);
81 // keep double backslashes (e.g. in case of LateX formatting, like \\gamma)
82 svalue.ReplaceAll("\\", "\\\\");
83 TGTextBuffer *b = new TGTextBuffer(20); b->AddText(0, svalue.Data());
84 TGTextEntry *t = new TGTextEntry(this, b);
85
86 t->Connect("TabPressed()", "TRootDialog", this, "TabPressed()");
87
88 t->Associate(fMenu);
89 t->Resize(260, t->GetDefaultHeight());
90 AddFrame(l, fL1);
91 AddFrame(t, fL2);
92
93 fWidgets->Add(l);
94 fWidgets->Add(t); // TGTextBuffer will be deleted by TGTextEntry
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Get parameter string (called by contextmenu after OK or Apply has
100/// been selected).
101
103{
104 static TString params;
105 TString param;
106
107 TObjString *str;
108 TObject *obj;
109
110 Int_t selfobjpos;
113 else
114 selfobjpos = -1;
115
116 params.Clear();
117 TIter next(fWidgets);
118 Int_t nparam = 0;
119
120 while ((obj = next())) { // first element is label, skip...
121 if (obj->IsA() != TGLabel::Class()) break;
122 obj = next(); // get either TGTextEntry or TGComboBox
123 str = (TObjString *) next(); // get type string
124
125 nparam++;
126
127 const char *type = str ? str->GetString().Data() : 0;
128 const char *data = 0;
129
130 if (obj && obj->IsA() == TGTextEntry::Class())
131 data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
132
133 // TODO: Combobox...
134
135 // if necessary, replace the selected object by it's address
136 if (selfobjpos == nparam-1) {
137 if (params.Length()) params += ",";
138 param = TString::Format("(TObject*)0x%lx",
140 params += param;
141 }
142
143 if (params.Length()) params += ",";
144 if (type && data) {
145 if (!strncmp(type, "char*", 5))
146 param = TString::Format("\"%s\"", data);
147 else
148 param = TString::Format("(%s)%s", type, data);
149 } else
150 param = "0";
151
152 params += param;
153 }
154
155 // if selected object is the last argument, have to insert it here
156 if (selfobjpos == nparam) {
157 if (params.Length()) params += ",";
158 param = TString::Format("(TObject*)0x%lx",
160 params += param;
161 }
162
163 return params.Data();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Popup dialog.
168
170{
171 //--- create the OK, Apply and Cancel buttons
172
173 UInt_t nb = 0, width = 0, height = 0;
174
175 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
177
178 // put hf as last in the list to be deleted
179 fWidgets->Add(l1);
180
182 if (fOk) {
183 b = new TGTextButton(hf, "&OK", 1);
184 fWidgets->Add(b);
185 b->Associate(fMenu);
186 hf->AddFrame(b, l1);
187 height = b->GetDefaultHeight();
188 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
189 }
190 if (fApply) {
191 b = new TGTextButton(hf, "&Apply", 2);
192 fWidgets->Add(b);
193 b->Associate(fMenu);
194 hf->AddFrame(b, l1);
195 height = b->GetDefaultHeight();
196 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
197 }
198 if (fCancel) {
199 b = new TGTextButton(hf, "&Cancel", 3);
200 fWidgets->Add(b);
201 b->Associate(fMenu);
202 hf->AddFrame(b, l1);
203 height = b->GetDefaultHeight();
204 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
205 }
206 if (fHelp) {
207 b = new TGTextButton(hf, "Online &Help", 4);
208 fWidgets->Add(b);
209 b->Associate(fMenu);
210 hf->AddFrame(b, l1);
211 height = b->GetDefaultHeight();
212 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
213 }
214
215 // place buttons at the bottom
216 l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
217 fWidgets->Add(l1);
218 fWidgets->Add(hf);
219
220 AddFrame(hf, l1);
221
222 // keep the buttons centered and with the same width
223 hf->Resize((width + 20) * nb, height);
224
225 // map all widgets and calculate size of dialog
227
229 height = GetDefaultHeight();
230
231 Resize(width, height);
232
233 // position relative to the parent's window
235
236 // make the message box non-resizable
237 SetWMSize(width, height);
238 SetWMSizeHints(width, height, width, height, 0, 0);
239
245
246 MapWindow();
247 fClient->WaitFor(this);
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Called when closed via window manager action.
252
254{
255 // Send Cancel button message to context menu eventhandler
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Handle Tab keyboard navigation in this dialog.
261
263{
264 Bool_t setNext = kFALSE;
265 TGTextEntry *entry;
266 TIter next(fWidgets);
267
268 while ( TObject* obj = next() ) {
269 if ( obj->IsA() == TGTextEntry::Class() ) {
270 entry = (TGTextEntry*) obj;
271 if ( entry == gBlinkingEntry ) {
272 setNext = kTRUE;
273 } else if ( setNext ) {
274 entry->SetFocus();
275 entry->End();
276 return;
277 }
278 }
279 }
280
281 next.Reset();
282 while ( TObject* obj = next() ) {
283 if ( obj->IsA() == TGTextEntry::Class() ) {
284 entry = (TGTextEntry*) obj;
285 entry->SetFocus();
286 entry->End();
287 return;
288 }
289 }
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// The key press event handler in this dialog.
294
296{
297 char tmp[10];
298 UInt_t keysym;
299 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
300 if ((EKeySym)keysym == kKey_Tab) {
301
302 TGTextEntry *entry;
303 TIter next(fWidgets);
304
305 while ( TObject* obj = next() ) {
306 if ( obj->IsA() == TGTextEntry::Class() ) {
307 entry = (TGTextEntry*) obj;
308 entry->TabPressed();
309 return kTRUE;
310 }
311 }
312 }
313
314 return TGMainFrame::HandleKey(event);
315}
void Class()
Definition: Class.C:29
const Mask_t kKeyPressMask
Definition: GuiTypes.h:158
const Mask_t kLeaveWindowMask
Definition: GuiTypes.h:167
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:166
EKeySym
Definition: KeySymbols.h:25
@ kKey_Tab
Definition: KeySymbols.h:27
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
#define gClient
Definition: TGClient.h:166
@ kMWMDecorResizeH
Definition: TGFrame.h:96
@ kMWMFuncAll
Definition: TGFrame.h:80
@ kMWMFuncResize
Definition: TGFrame.h:81
@ kMWMDecorMaximize
Definition: TGFrame.h:100
@ kMWMDecorMinimize
Definition: TGFrame.h:99
@ kMWMDecorMenu
Definition: TGFrame.h:98
@ kMWMDecorAll
Definition: TGFrame.h:94
@ kMWMFuncMaximize
Definition: TGFrame.h:84
@ kMWMInputModeless
Definition: TGFrame.h:88
@ kMWMFuncMinimize
Definition: TGFrame.h:83
@ kFixedWidth
Definition: TGFrame.h:65
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsBottom
Definition: TGLayout.h:36
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
int type
Definition: TGX11.cxx:120
TGTextEntry * gBlinkingEntry
#define gVirtualX
Definition: TVirtualX.h:345
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kC_COMMAND
@ kCM_BUTTON
virtual Int_t GetSelfObjectPos() const
virtual TContextMenu * GetContextMenu() const
virtual TClassMenuItem * GetSelectedMenuItem()
Definition: TContextMenu.h:88
virtual TObject * GetSelectedObject()
Definition: TContextMenu.h:86
void WaitFor(TGWindow *w)
Wait for window to be destroyed.
Definition: TGClient.cxx:708
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:371
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:373
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1004
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:321
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:627
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void MapWindow()
Definition: TGFrame.h:251
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1759
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events.
Definition: TGFrame.cxx:1564
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1849
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1824
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
Give the window manager minimum and maximum size hints.
Definition: TGFrame.cxx:1862
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
TGClient * fClient
Definition: TGObject.h:37
virtual void SetFocus()
Set focus to this text entry.
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.
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition: TGFrame.cxx:1913
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
@ kEditDisable
Definition: TGWindow.h:59
void Reset()
Definition: TCollection.h:252
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
Collectable string class.
Definition: TObjString.h:28
const TString & GetString() const
Definition: TObjString.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
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:867
virtual Bool_t HandleKey(Event_t *event)
The key press event handler in this dialog.
TGLayoutHints * fL2
Definition: TRootDialog.h:36
TRootDialog(TRootContextMenu *cmenu=0, const TGWindow *main=0, 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.
Definition: TRootDialog.cxx:40
TGLayoutHints * fL1
Definition: TRootDialog.h:35
virtual void Add(const char *argname, const char *value, const char *type)
Add a label and text input field.
Definition: TRootDialog.cxx:77
Bool_t fHelp
Definition: TRootDialog.h:41
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
Definition: TRootDialog.h:39
Bool_t fApply
Definition: TRootDialog.h:40
TList * fWidgets
Definition: TRootDialog.h:37
virtual void Popup()
Popup dialog.
Bool_t fOk
Definition: TRootDialog.h:38
virtual ~TRootDialog()
Delete the dialog.
Definition: TRootDialog.cxx:66
virtual void CloseWindow()
Called when closed via window manager action.
TRootContextMenu * fMenu
Definition: TRootDialog.h:34
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1151
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
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:2286
int main(int argc, char **argv)
int GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, Bool_t check=kTRUE)
Retrieve a linear buffer pointer from the given pyobject.
Definition: Utility.cxx:539
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
auto * l
Definition: textangle.C:4