Logo ROOT  
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#include "TVirtualX.h"
33
35
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a method argument prompt dialog.
40
42 const char *title, Bool_t okB, Bool_t cancelB, Bool_t applyB,
43 Bool_t helpB) : TGTransientFrame(gClient->GetRoot(), main, 200, 100)
44{
45 fMenu = cmenu;
46
47 fOk = okB;
48 fCancel = cancelB;
49 fApply = applyB;
50 fHelp = helpB;
51
52 fWidgets = new TList;
53
54 fL1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 0, 0, 5, 0);
55 fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
56
57 SetWindowName(title);
58 SetIconName(title);
60
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Delete the dialog.
66
68{
70 delete fWidgets;
71 delete fL1;
72 delete fL2;
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Add a label and text input field.
77
78void TRootDialog::Add(const char *argname, const char *value, const char *type)
79{
80 TGLabel *l = new TGLabel(this, argname);
81 TString svalue(value);
82 // keep double backslashes (e.g. in case of LateX formatting, like \\gamma)
83 svalue.ReplaceAll("\\", "\\\\");
84 TGTextBuffer *b = new TGTextBuffer(20); b->AddText(0, svalue.Data());
85 TGTextEntry *t = new TGTextEntry(this, b);
86
87 t->Connect("TabPressed()", "TRootDialog", this, "TabPressed()");
88
89 t->Associate(fMenu);
90 t->Resize(260, t->GetDefaultHeight());
91 AddFrame(l, fL1);
92 AddFrame(t, fL2);
93
94 fWidgets->Add(l);
95 fWidgets->Add(t); // TGTextBuffer will be deleted by TGTextEntry
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Get parameter string (called by contextmenu after OK or Apply has
101/// been selected).
102
104{
105 static TString params;
106 TString param;
107
108 TObjString *str;
109 TObject *obj;
110
111 Int_t selfobjpos;
114 else
115 selfobjpos = -1;
116
117 params.Clear();
118 TIter next(fWidgets);
119 Int_t nparam = 0;
120
121 while ((obj = next())) { // first element is label, skip...
122 if (obj->IsA() != TGLabel::Class()) break;
123 obj = next(); // get either TGTextEntry or TGComboBox
124 str = (TObjString *) next(); // get type string
125
126 nparam++;
127
128 const char *type = str ? str->GetString().Data() : 0;
129 const char *data = 0;
130
131 if (obj && obj->IsA() == TGTextEntry::Class())
132 data = ((TGTextEntry *) obj)->GetBuffer()->GetString();
133
134 // TODO: Combobox...
135
136 // if necessary, replace the selected object by it's address
137 if (selfobjpos == nparam-1) {
138 if (params.Length()) params += ",";
139 param = TString::Format("(TObject*)0x%lx",
141 params += param;
142 }
143
144 if (params.Length()) params += ",";
145 if (type && data) {
146 if (!strncmp(type, "char*", 5))
147 param = TString::Format("\"%s\"", data);
148 else
149 param = TString::Format("(%s)%s", type, data);
150 } else
151 param = "0";
152
153 params += param;
154 }
155
156 // if selected object is the last argument, have to insert it here
157 if (selfobjpos == nparam) {
158 if (params.Length()) params += ",";
159 param = TString::Format("(TObject*)0x%lx",
161 params += param;
162 }
163
164 return params.Data();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Popup dialog.
169
171{
172 //--- create the OK, Apply and Cancel buttons
173
174 UInt_t nb = 0, width = 0, height = 0;
175
176 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
178
179 // put hf as last in the list to be deleted
180 fWidgets->Add(l1);
181
183 if (fOk) {
184 b = new TGTextButton(hf, "&OK", 1);
185 fWidgets->Add(b);
186 b->Associate(fMenu);
187 hf->AddFrame(b, l1);
188 height = b->GetDefaultHeight();
189 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
190 }
191 if (fApply) {
192 b = new TGTextButton(hf, "&Apply", 2);
193 fWidgets->Add(b);
194 b->Associate(fMenu);
195 hf->AddFrame(b, l1);
196 height = b->GetDefaultHeight();
197 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
198 }
199 if (fCancel) {
200 b = new TGTextButton(hf, "&Cancel", 3);
201 fWidgets->Add(b);
202 b->Associate(fMenu);
203 hf->AddFrame(b, l1);
204 height = b->GetDefaultHeight();
205 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
206 }
207 if (fHelp) {
208 b = new TGTextButton(hf, "Online &Help", 4);
209 fWidgets->Add(b);
210 b->Associate(fMenu);
211 hf->AddFrame(b, l1);
212 height = b->GetDefaultHeight();
213 width = TMath::Max(width, b->GetDefaultWidth()); ++nb;
214 }
215
216 // place buttons at the bottom
217 l1 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
218 fWidgets->Add(l1);
219 fWidgets->Add(hf);
220
221 AddFrame(hf, l1);
222
223 // keep the buttons centered and with the same width
224 hf->Resize((width + 20) * nb, height);
225
226 // map all widgets and calculate size of dialog
228
230 height = GetDefaultHeight();
231
232 Resize(width, height);
233
234 // position relative to the parent's window
236
237 // make the message box non-resizable
238 SetWMSize(width, height);
239 SetWMSizeHints(width, height, width, height, 0, 0);
240
246
247 MapWindow();
248 fClient->WaitFor(this);
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Called when closed via window manager action.
253
255{
256 // Send Cancel button message to context menu eventhandler
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Handle Tab keyboard navigation in this dialog.
262
264{
265 Bool_t setNext = kFALSE;
266 TGTextEntry *entry;
267 TIter next(fWidgets);
268
269 while ( TObject* obj = next() ) {
270 if ( obj->IsA() == TGTextEntry::Class() ) {
271 entry = (TGTextEntry*) obj;
272 if ( entry == gBlinkingEntry ) {
273 setNext = kTRUE;
274 } else if ( setNext ) {
275 entry->SetFocus();
276 entry->End();
277 return;
278 }
279 }
280 }
281
282 next.Reset();
283 while ( TObject* obj = next() ) {
284 if ( obj->IsA() == TGTextEntry::Class() ) {
285 entry = (TGTextEntry*) obj;
286 entry->SetFocus();
287 entry->End();
288 return;
289 }
290 }
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// The key press event handler in this dialog.
295
297{
298 char tmp[10];
299 UInt_t keysym;
300 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
301 if ((EKeySym)keysym == kKey_Tab) {
302
303 TGTextEntry *entry;
304 TIter next(fWidgets);
305
306 while ( TObject* obj = next() ) {
307 if ( obj->IsA() == TGTextEntry::Class() ) {
308 entry = (TGTextEntry*) obj;
309 entry->TabPressed();
310 return kTRUE;
311 }
312 }
313 }
314
315 return TGMainFrame::HandleKey(event);
316}
void Class()
Definition: Class.C:29
const Mask_t kKeyPressMask
Definition: GuiTypes.h:158
@ kFixedWidth
Definition: GuiTypes.h:387
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
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
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:74
@ kMWMFuncAll
Definition: TGFrame.h:58
@ kMWMFuncResize
Definition: TGFrame.h:59
@ kMWMDecorMaximize
Definition: TGFrame.h:78
@ kMWMDecorMinimize
Definition: TGFrame.h:77
@ kMWMDecorMenu
Definition: TGFrame.h:76
@ kMWMDecorAll
Definition: TGFrame.h:72
@ kMWMFuncMaximize
Definition: TGFrame.h:62
@ kMWMInputModeless
Definition: TGFrame.h:66
@ kMWMFuncMinimize
Definition: TGFrame.h:61
@ 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: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()
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:1101
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:349
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1148
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:351
virtual void SetEditDisabled(UInt_t on=1)
Set edit disable flag for this frame and subframes.
Definition: TGFrame.cxx:1006
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition: TGFrame.cxx:323
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:216
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:629
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:589
virtual void MapWindow()
map window
Definition: TGFrame.h:229
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1761
virtual Bool_t HandleKey(Event_t *event)
Handle keyboard events.
Definition: TGFrame.cxx:1566
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1851
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1826
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:1864
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1748
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:1915
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
@ kEditDisable
Definition: TGWindow.h:58
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:469
Collectable string class.
Definition: TObjString.h:28
const TString & GetString() const
Definition: TObjString.h:46
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:866
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:41
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:78
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:67
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:1176
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:2311
int main(int argc, char **argv)
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition: Utility.cxx:614
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
auto * l
Definition: textangle.C:4