KWWidgets
vtkKWMessageDialog.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWMessageDialog.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWMessageDialog - a message dialog superclass
15 // .SECTION Description
16 // A generic superclass for MessageDialog boxes.
17 
18 #ifndef __vtkKWMessageDialog_h
19 #define __vtkKWMessageDialog_h
20 
21 #include "vtkKWDialog.h"
22 
23 class vtkKWApplication;
24 class vtkKWCheckButton;
25 class vtkKWFrame;
26 class vtkKWMessage;
27 class vtkKWLabel;
28 class vtkKWPushButton;
29 
31 {
32 public:
33  static vtkKWMessageDialog* New();
34  vtkTypeRevisionMacro(vtkKWMessageDialog,vtkKWDialog);
35  void PrintSelf(ostream& os, vtkIndent indent);
36 
37  // Description:
38  // Set the text of the message
39  virtual void SetText(const char *);
40 
41  // Description:
42  // Set/Get the width of the message, in pixels)
43  virtual void SetTextWidth(int);
44  virtual int GetTextWidth();
45 
46  // Description:
47  // Status of the dialog. This subclass defines a new 'Other' status on
48  // top of the usual one (active e.g. displayed, canceled, OK'ed). This
49  // status is triggered by pressing the 'Other' button.
50  //BTX
51  enum
52  {
53  StatusOther = 100
54  };
55  //ETX
56 
57  // Description:
58  // Set the style of the message box.
59  // No effect if called after Create()
60  //BTX
61  enum
62  {
63  StyleMessage = 0,
64  StyleYesNo,
65  StyleOkCancel,
66  StyleOkOtherCancel,
67  StyleCancel
68  };
69  //ETX
70  virtual void SetStyle(int);
71  vtkGetMacro(Style,int);
72  void SetStyleToMessage();
73  void SetStyleToYesNo();
74  void SetStyleToOkCancel();
75  void SetStyleToOkOtherCancel();
76  void SetStyleToCancel();
77 
78  // Description:
79  // Set different options for the dialog.
80  //BTX
81  enum
82  {
83  RememberYes = 0x00002,
84  RememberNo = 0x00004,
85  ErrorIcon = 0x00008,
86  WarningIcon = 0x00010,
87  QuestionIcon = 0x00020,
88  YesDefault = 0x00040,
89  NoDefault = 0x00080,
90  OkDefault = 0x00100,
91  CancelDefault = 0x00200,
92  Beep = 0x00400,
93  PackVertically = 0x00800,
94  InvokeAtPointer = 0x01000,
95  CustomIcon = 0x02000,
96  Resizable = 0x04000
97  };
98  //ETX
99  vtkSetMacro(Options, int);
100  vtkGetMacro(Options, int);
101 
102  // Description:
103  // The label displayed on the OK button. Only used when
104  // the style is OkCancel.
105  vtkSetStringMacro(OKButtonText);
106  vtkGetStringMacro(OKButtonText);
107 
108  // Description:
109  // The label displayed on the cancel button. Only used when
110  // the style is OkCancel.
111  vtkSetStringMacro(CancelButtonText);
112  vtkGetStringMacro(CancelButtonText);
113 
114  // Description:
115  // The label displayed on the other button. Only used when
116  // the style is OkOtherCancel.
117  vtkSetStringMacro(OtherButtonText);
118  vtkGetStringMacro(OtherButtonText);
119 
120  // Description:
121  // Utility methods to create various dialog windows.
122  // icon is a enumerated icon type described in vtkKWIcon.
123  // title is a title string of the dialog. name is the dialog name
124  // used for the registry. message is the text message displayed
125  // in the dialog. masterwin is a pointer to a widget belonging to the window
126  // you want this message dialog to be a child of (or the window directly).
127  static void PopupMessage(vtkKWApplication *app,
128  vtkKWWidget *masterWin,
129  const char* title,
130  const char* message, int options = 0);
131  static int PopupYesNo(vtkKWApplication *app,
132  vtkKWWidget *masterWin,
133  const char* title,
134  const char* message, int options = 0);
135  static int PopupYesNo(vtkKWApplication *app,
136  vtkKWWidget *masterWin,
137  const char* name,
138  const char* title, const char* message,
139  int options = 0);
140  static int PopupOkCancel(vtkKWApplication *app,
141  vtkKWWidget *masterWin,
142  const char* title,
143  const char* message, int options = 0);
144 
145  // Description:
146  // Retrieve the frame where the message is.
147  vtkGetObjectMacro(TopFrame, vtkKWFrame);
148  vtkGetObjectMacro(MessageDialogFrame, vtkKWFrame);
149  vtkGetObjectMacro(BottomFrame, vtkKWFrame);
150  vtkGetObjectMacro(Icon, vtkKWLabel);
151 
152  // Description:
153  // Accessor for OK and cancel button
154  vtkGetObjectMacro(OKButton, vtkKWPushButton);
155  vtkGetObjectMacro(CancelButton, vtkKWPushButton);
156  vtkGetObjectMacro(OtherButton, vtkKWPushButton);
157 
158  // Description:
159  // Set or get the message dialog name. This name is use to save/restore
160  // information about this specific dialog in the registry (for example,
161  // bypass the dialog altogether by clicking on a specific button
162  // automatically).
163  // This should not be confused with
164  // the message dialog title that can be set using the superclass
165  // SetTitle() method.
166  vtkSetStringMacro(DialogName);
167  vtkGetStringMacro(DialogName);
168 
169  // Description:
170  // Store/retrieve a message dialog response for a given application
171  // in/from the registry.
172  // This can be used to prevent the user from answering the same question
173  // again and again (for ex: "Are you sure you want to exit the application").
174  // 'dialogname' is the name of a dialog (most likely its DialogName ivar).
175  // The 'response' is arbitrary but most likely the value returned by a
176  // call to Invoke() on the dialog.
177  static int RestoreMessageDialogResponseFromRegistry(
178  vtkKWApplication *app, const char *dialogname);
179  static void SaveMessageDialogResponseToRegistry(
180  vtkKWApplication *app, const char *dialogname, int response);
181 
182  // Description:
183  // Display the dialog.
184  // Override the superclass to set up keybindings and options
185  virtual void Display();
186 
187  // Description:
188  // Dialog can be also used by performing individual steps of Invoke. These
189  // steps are initialize: PreInvoke(), finalize: PostInvoke(), and check if
190  // user responded IsUserDoneWithDialog(). Use this method only if you
191  // want to bypass the event loop used in Invoke() by creating your own
192  // and checking for IsUserDoneWithDialog().
193  // Override the superclass to handle DialogName
194  virtual int PreInvoke();
195  virtual void PostInvoke();
196 
197  // Description::
198  // Callback. Close this Dialog (for the third button)
199  virtual void Other();
200 
201  // Description:
202  // Set the icon on the message dialog.
203  // Legacy. Do not call anymore. Is called automatically by Create().
204  virtual void SetIcon();
205 
206 protected:
209 
210  // Description:
211  // Create the widget.
212  virtual void CreateWidget();
213 
214  int Style;
215  int Default;
216  int Options;
217  char *DialogName;
218  char *DialogText;
219 
220  vtkSetStringMacro(DialogText);
221  vtkGetStringMacro(DialogText);
222 
223  vtkKWFrame *TopFrame;
224  vtkKWFrame *MessageDialogFrame;
225  vtkKWFrame *BottomFrame;
226  vtkKWMessage *Message;
227  vtkKWFrame *ButtonFrame;
228  vtkKWPushButton *OKButton;
229  vtkKWPushButton *CancelButton;
230  vtkKWPushButton *OtherButton;
231  vtkKWLabel *Icon;
232  vtkKWFrame *OKFrame;
233  vtkKWFrame *CancelFrame;
234  vtkKWFrame *OtherFrame;
235  vtkKWCheckButton *CheckButton;
236 
237  // Description:
238  // Get the value of the check box for remembering the answer from
239  // the user.
240  int GetRememberMessage();
241 
242  char* OKButtonText;
243  char* CancelButtonText;
244  char* OtherButtonText;
245 
246  // Description:
247  // Update the buttons or message
248  virtual void UpdateButtons();
249  virtual void PackButtons();
250  virtual void UpdateMessage();
251 
252  // Description:
253  // Pack
254  virtual void Pack();
255 
256 private:
257  vtkKWMessageDialog(const vtkKWMessageDialog&); // Not implemented
258  void operator=(const vtkKWMessageDialog&); // Not implemented
259 };
260 
261 
262 #endif