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
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;
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);
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
112 if (fMenu->GetContextMenu()->GetSelectedMenuItem())
113 selfobjpos = fMenu->GetContextMenu()->GetSelectedMenuItem()->GetSelfObjectPos();
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%zx",
140 (size_t)fMenu->GetContextMenu()->GetSelectedObject());
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%zx",
160 (size_t)fMenu->GetContextMenu()->GetSelectedObject());
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
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 = std::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 = std::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 = std::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 = std::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
231
233
234 // position relative to the parent's window
236
237 // make the message box non-resizable
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{
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];
300 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
301 if ((EKeySym)keysym == kKey_Tab) {
302
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}
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:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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:337
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kC_COMMAND
@ kCM_BUTTON
virtual TContextMenu * GetContextMenu() const
void WaitFor(TGWindow *w)
Wait for window to be destroyed.
Definition TGClient.cxx:717
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:314
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
UInt_t GetDefaultHeight() const override
Definition TGFrame.h:316
void SetEditDisabled(UInt_t on=1) override
Set edit disable flag for this frame and subframes.
Definition TGFrame.cxx:1014
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:331
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:193
void MapWindow() override
map window
Definition TGFrame.h:206
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:637
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
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:1793
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
Bool_t HandleKey(Event_t *event) override
Handle keyboard events.
Definition TGFrame.cxx:1598
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
static TClass * Class()
Defines transient windows that typically are used for dialogs windows.
Definition TGFrame.h:500
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1949
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:467
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual TClass * IsA() const
Definition TObject.h:246
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:865
This class provides an interface to context sensitive popup menus.
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
~TRootDialog() override
Delete the dialog.
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
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:138
Ssiz_t Length() const
Definition TString.h:425
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1241
const char * Data() const
Definition TString.h:384
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:2384
Event structure.
Definition GuiTypes.h:174
TLine l
Definition textangle.C:4