Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGMsgBox.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id: d25b6f3b0b2546fe028288bd22c21588bdd1b8c1 $
2// Author: Fons Rademakers 09/01/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 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23
24/** \class TMsgBox
25 \ingroup guiwidgets
26
27A message dialog box.
28
29*/
30
31
32#include "TGMsgBox.h"
33#include "TGButton.h"
34#include "TGIcon.h"
35#include "TGLabel.h"
36#include "TGPicture.h"
37#include "TList.h"
38#include "KeySymbols.h"
39#include "TVirtualX.h"
40#include "strlcpy.h"
41
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Create a message dialog box.
46
48 const char *title, const char *msg, const TGPicture *icon,
51 TGTransientFrame(p, main, 10, 10, options)
52{
53 if (p)
54 PMsgBox(title, msg, icon, buttons, ret_code, text_align);
55 else
56 MakeZombie();
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Create a message dialog box with the following parameters:.
61/// title: Window title
62/// msg: Message to be shown ('\n' may be used to split it in lines)
63/// icon: Picture to be shown at the left on the dialog window.
64/// It might take any of the following values:
65/// kMBIconStop, kMBIconQuestion,
66/// kMBIconExclamation, kMBIconAsterisk
67/// buttons: Buttons to be shown at the botton of the dialog window.
68/// Look at EMsgBoxButton for the different possible values.
69/// ret_code: It will hold the value of the button pressed when the
70/// dialog is closed
71/// options: Frame options of this dialog window.
72/// text_align: Align options for 'msg'. See ETextJustification for the values.
73
75 const char *title, const char *msg, EMsgBoxIcon icon,
78 TGTransientFrame(p, main, 10, 10, options)
79{
80 const TGPicture *icon_pic;
81
82 switch (icon) {
83 case kMBIconStop:
84 icon_pic = fClient->GetPicture("mb_stop_s.xpm");
85 if (!icon_pic) Error("TGMsgBox", "mb_stop_s.xpm not found");
86 break;
87
88 case kMBIconQuestion:
89 icon_pic = fClient->GetPicture("mb_question_s.xpm");
90 if (!icon_pic) Error("TGMsgBox", "mb_question_s.xpm not found");
91 break;
92
94 icon_pic = fClient->GetPicture("mb_exclamation_s.xpm");
95 if (!icon_pic) Error("TGMsgBox", "mb_exclamation_s.xpm not found");
96 break;
97
98 case kMBIconAsterisk:
99 icon_pic = fClient->GetPicture("mb_asterisk_s.xpm");
100 if (!icon_pic) Error("TGMsgBox", "mb_asterisk_s.xpm not found");
101 break;
102
103 default:
104 icon_pic = 0;
105 break;
106 }
107
108 if (p)
110 else
111 MakeZombie();
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Protected, common message dialog box initialization.
116
117void TGMsgBox::PMsgBox(const char *title, const char *msg,
118 const TGPicture *icon, Int_t buttons, Int_t *ret_code,
120{
122
123 fYes = fNo = fOK = fApply = fRetry = fIgnore = fCancel = fClose =
125 fIcon = 0;
126 fMsgList = new TList;
128 nb = width = 0;
129
130 // create the buttons
131
132 fButtonFrame = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
133 fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 3, 3, 0, 0);
134
135 buttons &= (kMBYes | kMBNo | kMBOk | kMBApply |
138 if (buttons == 0) buttons = kMBDismiss;
139
140 if (buttons & kMBYes) {
141 fYes = new TGTextButton(fButtonFrame, new TGHotString("&Yes"), kMBYes);
142 fYes->Associate(this);
144 width = std::max(width, fYes->GetDefaultWidth()); ++nb;
145 }
146
147 if (buttons & kMBNo) {
148 fNo = new TGTextButton(fButtonFrame, new TGHotString("&No"), kMBNo);
149 fNo->Associate(this);
151 width = std::max(width, fNo->GetDefaultWidth()); ++nb;
152 }
153
154 if (buttons & kMBOk) {
155 fOK = new TGTextButton(fButtonFrame, new TGHotString("&OK"), kMBOk);
156 fOK->Associate(this);
158 width = std::max(width, fOK->GetDefaultWidth()); ++nb;
159 }
160
161 if (buttons & kMBApply) {
162 fApply = new TGTextButton(fButtonFrame, new TGHotString("&Apply"), kMBApply);
163 fApply->Associate(this);
165 width = std::max(width, fApply->GetDefaultWidth()); ++nb;
166 }
167
168 if (buttons & kMBRetry) {
169 fRetry = new TGTextButton(fButtonFrame, new TGHotString("&Retry"), kMBRetry);
170 fRetry->Associate(this);
172 width = std::max(width, fRetry->GetDefaultWidth()); ++nb;
173 }
174
175 if (buttons & kMBIgnore) {
176 fIgnore = new TGTextButton(fButtonFrame, new TGHotString("&Ignore"), kMBIgnore);
177 fIgnore->Associate(this);
179 width = std::max(width, fIgnore->GetDefaultWidth()); ++nb;
180 }
181
182 if (buttons & kMBCancel) {
183 fCancel = new TGTextButton(fButtonFrame, new TGHotString("&Cancel"), kMBCancel);
184 fCancel->Associate(this);
186 width = std::max(width, fCancel->GetDefaultWidth()); ++nb;
187 }
188
189 if (buttons & kMBClose) {
190 fClose = new TGTextButton(fButtonFrame, new TGHotString("C&lose"), kMBClose);
191 fClose->Associate(this);
193 width = std::max(width, fClose->GetDefaultWidth()); ++nb;
194 }
195
196 if (buttons & kMBYesAll) {
197 fYesAll = new TGTextButton(fButtonFrame, new TGHotString("Y&es to All"), kMBYesAll);
198 fYesAll->Associate(this);
200 width = std::max(width, fYesAll->GetDefaultWidth()); ++nb;
201 }
202
203 if (buttons & kMBNoAll) {
204 fNoAll = new TGTextButton(fButtonFrame, new TGHotString("No &to All"), kMBNoAll);
205 fNoAll->Associate(this);
207 width = std::max(width, fNoAll->GetDefaultWidth()); ++nb;
208 }
209
210 if (buttons & kMBNewer) {
211 fNewer = new TGTextButton(fButtonFrame, new TGHotString("Ne&wer Only"), kMBNewer);
212 fNewer->Associate(this);
214 width = std::max(width, fNewer->GetDefaultWidth()); ++nb;
215 }
216
217 if (buttons & kMBAppend) {
218 fAppend = new TGTextButton(fButtonFrame, new TGHotString("A&ppend"), kMBAppend);
219 fAppend->Associate(this);
221 width = std::max(width, fAppend->GetDefaultWidth()); ++nb;
222 }
223
224 if (buttons & kMBDismiss) {
226 fDismiss->Associate(this);
228 width = std::max(width, fDismiss->GetDefaultWidth()); ++nb;
229 }
230
231 // place buttons at the bottom
232
233 fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
235
236 // keep the buttons centered and with the same width
237
239
240 fIconFrame = new TGHorizontalFrame(this, 60, 20);
241
242 fL3 = new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2);
243
244 if (icon) {
245 fIcon = new TGIcon(fIconFrame, icon, icon->GetWidth(), icon->GetHeight());
247 }
248
250
252 4, 2, 2, 2);
253 fL5 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 10, 10, 7, 2);
254
255 // make one label per line of the message
256 TGLabel *label;
257
258 char *line;
259 char *tmpMsg, *nextLine;
260
261 int len = strlen(msg) + 1;
262 tmpMsg = new char[len];
264
265 line = tmpMsg;
267 while ((nextLine = strchr(line, '\n'))) {
268 *nextLine = 0;
269 label = new TGLabel(fLabelFrame, line);
271 fMsgList->Add(label);
272 fLabelFrame->AddFrame(label, fL4);
273 line = nextLine + 1;
274 }
275
276 label = new TGLabel(fLabelFrame, line);
278 fMsgList->Add(label);
279 fLabelFrame->AddFrame(label, fL4);
280 delete [] tmpMsg;
281
284
286
289
292
293 // position relative to the parent's window
294
296
297 // make the message box non-resizable
298
301
302 // set names
303
304 SetWindowName(title);
305 SetIconName(title);
306 SetClassHints("ROOT", "MsgBox");
307
313
314 MapRaised();
315 fClient->WaitFor(this);
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Destroy message dialog box.
320
322{
323 if (IsZombie()) return;
324 if (fYes) delete fYes;
325 if (fNo) delete fNo;
326 if (fOK) delete fOK;
327 if (fApply) delete fApply;
328 if (fRetry) delete fRetry;
329 if (fIgnore) delete fIgnore;
330 if (fCancel) delete fCancel;
331 if (fClose) delete fClose;
332 if (fDismiss) delete fDismiss;
333 if (fYesAll) delete fYesAll;
334 if (fNoAll) delete fNoAll;
335 if (fNewer) delete fNewer;
336 if (fAppend) delete fAppend;
337
338 if (fIcon) delete fIcon;
339 delete fButtonFrame;
340 delete fIconFrame;
341 delete fLabelFrame;
342 fMsgList->Delete();
343 delete fMsgList;
344 delete fL1; delete fL2; delete fL3; delete fL4; delete fL5;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Close dialog box. Before deleting itself it sets the return code
349/// to kMBClose.
350
352{
353 if (fRetCode) *fRetCode = kMBClose;
354 DeleteWindow();
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Process message dialog box event.
359
361{
362 switch (GET_MSG(msg)) {
363 case kC_COMMAND:
364 switch (GET_SUBMSG(msg)) {
365 case kCM_BUTTON:
366 if (fRetCode) *fRetCode = (Int_t) parm1;
367 DeleteWindow();
368 break;
369
370 default:
371 break;
372 }
373 break;
374 default:
375 break;
376 }
377 return kTRUE;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Handle enter and escape keys (used as Ok and Cancel for now).
382
384{
385 if (event->fType == kGKeyPress) {
387 char input[10];
388 gVirtualX->LookupString(event, input, sizeof(input), keysym);
389
390 if ((EKeySym)keysym == kKey_Escape) {
391 if (fCancel) {
393 DeleteWindow();
394 }
395 return kTRUE;
396 }
397 else if ((EKeySym)keysym == kKey_Enter || (EKeySym)keysym == kKey_Return) {
398 if (fOK) {
399 if (fRetCode) *fRetCode = (Int_t) kMBOk;
400 DeleteWindow();
401 }
402 return kTRUE;
403 }
404 }
405 return TGMainFrame::HandleKey(event);
406}
407
@ kGKeyPress
Definition GuiTypes.h:60
const Mask_t kKeyPressMask
Definition GuiTypes.h:159
@ kFixedWidth
Definition GuiTypes.h:387
EKeySym
Definition KeySymbols.h:25
@ kKey_Return
Definition KeySymbols.h:30
@ kKey_Escape
Definition KeySymbols.h:26
@ kKey_Enter
Definition KeySymbols.h:31
int main()
Definition Prototype.cxx:12
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
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.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
@ 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
@ kMBNo
Definition TGMsgBox.h:32
@ kMBIgnore
Definition TGMsgBox.h:36
@ kMBApply
Definition TGMsgBox.h:34
@ kMBNoAll
Definition TGMsgBox.h:41
@ kMBClose
Definition TGMsgBox.h:38
@ kMBYes
Definition TGMsgBox.h:31
@ kMBAppend
Definition TGMsgBox.h:42
@ kMBRetry
Definition TGMsgBox.h:35
@ kMBCancel
Definition TGMsgBox.h:37
@ kMBOk
Definition TGMsgBox.h:33
@ kMBYesAll
Definition TGMsgBox.h:40
@ kMBNewer
Definition TGMsgBox.h:43
@ kMBDismiss
Definition TGMsgBox.h:39
EMsgBoxIcon
Definition TGMsgBox.h:21
@ kMBIconExclamation
Definition TGMsgBox.h:24
@ kMBIconAsterisk
Definition TGMsgBox.h:25
@ kMBIconStop
Definition TGMsgBox.h:22
@ kMBIconQuestion
Definition TGMsgBox.h:23
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
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 UChar_t len
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 height
#define gVirtualX
Definition TVirtualX.h:337
Int_t GET_MSG(Long_t val)
@ kC_COMMAND
@ kCM_BUTTON
Int_t GET_SUBMSG(Long_t val)
void WaitFor(TGWindow *w)
Wait for window to be destroyed.
Definition TGClient.cxx:717
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition TGClient.cxx:288
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 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 GetDefaultWidth() const
Definition TGFrame.h:192
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:268
void MapRaised() override
map raised
Definition TGFrame.h:207
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
This class handles GUI icons.
Definition TGIcon.h:22
This class handles GUI labels.
Definition TGLabel.h:24
void SetTextJustify(Int_t tmode)
Set text justification.
Definition TGLabel.cxx:395
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
void SetClassHints(const char *className, const char *resourceName)
Set the windows class and resource name.
Definition TGFrame.cxx:1850
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
TGButton * fNoAll
buttons in dialog box
Definition TGMsgBox.h:57
TGButton * fYes
Definition TGMsgBox.h:55
TGButton * fOK
Definition TGMsgBox.h:55
TGLayoutHints * fL5
layout hints
Definition TGMsgBox.h:63
TGLayoutHints * fL2
Definition TGMsgBox.h:63
TGLayoutHints * fL1
Definition TGMsgBox.h:63
TList * fMsgList
text (list of TGLabels)
Definition TGMsgBox.h:64
TGButton * fYesAll
Definition TGMsgBox.h:57
TGHorizontalFrame * fIconFrame
frame containing icon and text
Definition TGMsgBox.h:61
void PMsgBox(const char *title, const char *msg, const TGPicture *icon, Int_t buttons, Int_t *ret_code, Int_t text_align)
Protected, common message dialog box initialization.
Definition TGMsgBox.cxx:117
TGVerticalFrame * fLabelFrame
frame containing text
Definition TGMsgBox.h:62
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process message dialog box event.
Definition TGMsgBox.cxx:360
TGMsgBox(const TGMsgBox &)=delete
TGButton * fNo
Definition TGMsgBox.h:55
TGLayoutHints * fL3
Definition TGMsgBox.h:63
Bool_t HandleKey(Event_t *event) override
Handle enter and escape keys (used as Ok and Cancel for now).
Definition TGMsgBox.cxx:383
TGButton * fAppend
Definition TGMsgBox.h:58
TGButton * fRetry
Definition TGMsgBox.h:56
TGHorizontalFrame * fButtonFrame
frame containing buttons
Definition TGMsgBox.h:60
TGButton * fIgnore
Definition TGMsgBox.h:56
TGButton * fDismiss
buttons in dialog box
Definition TGMsgBox.h:58
~TGMsgBox() override
Destroy message dialog box.
Definition TGMsgBox.cxx:321
TGButton * fCancel
buttons in dialog box
Definition TGMsgBox.h:56
TGIcon * fIcon
icon
Definition TGMsgBox.h:59
TGLayoutHints * fL4
Definition TGMsgBox.h:63
TGButton * fClose
Definition TGMsgBox.h:57
TGButton * fNewer
Definition TGMsgBox.h:58
Int_t * fRetCode
address to store return code
Definition TGMsgBox.h:65
void CloseWindow() override
Close dialog box.
Definition TGMsgBox.cxx:351
TGButton * fApply
buttons in dialog box
Definition TGMsgBox.h:55
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
UInt_t GetHeight() const
Definition TGPicture.h:53
UInt_t GetWidth() const
Definition TGPicture.h:52
Yield an action as soon as it is clicked.
Definition TGButton.h:142
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
A composite frame that layout their children in vertical way.
Definition TGFrame.h:376
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
ROOT GUI Window base class.
Definition TGWindow.h:23
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
R__ALWAYS_INLINE Bool_t IsZombie() const
Definition TObject.h:159
void MakeZombie()
Definition TObject.h:53
TLine * line
Event structure.
Definition GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175