Make the main message of wxGenericMessageDialog stand out.
[wxWidgets.git] / include / wx / dialog.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dialog.h
3 // Purpose: wxDialogBase class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29.06.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DIALOG_H_BASE_
13 #define _WX_DIALOG_H_BASE_
14
15 #include "wx/defs.h"
16 #include "wx/toplevel.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxSizer;
19 class WXDLLIMPEXP_FWD_CORE wxStdDialogButtonSizer;
20 class WXDLLIMPEXP_FWD_CORE wxBoxSizer;
21 class WXDLLIMPEXP_FWD_CORE wxDialogLayoutAdapter;
22 class WXDLLIMPEXP_FWD_CORE wxDialog;
23 class WXDLLIMPEXP_FWD_CORE wxButton;
24 class WXDLLIMPEXP_FWD_CORE wxScrolledWindow;
25 class wxTextSizerWrapper;
26
27 // Also see the bit summary table in wx/toplevel.h.
28
29 #define wxDIALOG_NO_PARENT 0x0100 // Don't make owned by apps top window
30
31 #ifdef __WXWINCE__
32 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
33 #else
34 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
35 #endif
36
37 // Layout adaptation levels, for SetLayoutAdaptationLevel
38
39 // Don't do any layout adaptation
40 #define wxDIALOG_ADAPTATION_NONE 0
41
42 // Only look for wxStdDialogButtonSizer for non-scrolling part
43 #define wxDIALOG_ADAPTATION_STANDARD_SIZER 1
44
45 // Also look for any suitable sizer for non-scrolling part
46 #define wxDIALOG_ADAPTATION_ANY_SIZER 2
47
48 // Also look for 'loose' standard buttons for non-scrolling part
49 #define wxDIALOG_ADAPTATION_LOOSE_BUTTONS 3
50
51 // Layout adaptation mode, for SetLayoutAdaptationMode
52 enum wxDialogLayoutAdaptationMode
53 {
54 wxDIALOG_ADAPTATION_MODE_DEFAULT = 0, // use global adaptation enabled status
55 wxDIALOG_ADAPTATION_MODE_ENABLED = 1, // enable this dialog overriding global status
56 wxDIALOG_ADAPTATION_MODE_DISABLED = 2 // disable this dialog overriding global status
57 };
58
59 enum wxDialogModality
60 {
61 wxDIALOG_MODALITY_NONE = 0,
62 wxDIALOG_MODALITY_WINDOW_MODAL = 1,
63 wxDIALOG_MODALITY_APP_MODAL = 2
64 };
65
66 extern WXDLLIMPEXP_DATA_CORE(const char) wxDialogNameStr[];
67
68 class WXDLLIMPEXP_CORE wxDialogBase : public wxTopLevelWindow
69 {
70 public:
71 wxDialogBase() { Init(); }
72 virtual ~wxDialogBase() { }
73
74 // define public wxDialog methods to be implemented by the derived classes
75 virtual int ShowModal() = 0;
76 virtual void EndModal(int retCode) = 0;
77 virtual bool IsModal() const = 0;
78 // show the dialog frame-modally (needs a parent), using app-modal
79 // dialogs on platforms that don't support it
80 virtual void ShowWindowModal () ;
81 virtual void SendWindowModalDialogEvent ( wxEventType type );
82
83 // Modal dialogs have a return code - usually the id of the last
84 // pressed button
85 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
86 int GetReturnCode() const { return m_returnCode; }
87
88 // Set the identifier for the affirmative button: this button will close
89 // the dialog after validating data and calling TransferDataFromWindow()
90 void SetAffirmativeId(int affirmativeId);
91 int GetAffirmativeId() const { return m_affirmativeId; }
92
93 // Set identifier for Esc key translation: the button with this id will
94 // close the dialog without doing anything else; special value wxID_NONE
95 // means to not handle Esc at all while wxID_ANY means to map Esc to
96 // wxID_CANCEL if present and GetAffirmativeId() otherwise
97 void SetEscapeId(int escapeId);
98 int GetEscapeId() const { return m_escapeId; }
99
100 // Find the parent to use for modal dialog: try to use the specified parent
101 // but fall back to the current active window or main application window as
102 // last resort if it is unsuitable.
103 //
104 // As this function is often called from the ctor, the window style may be
105 // not set yet and hence must be passed explicitly to it so that we could
106 // check whether it contains wxDIALOG_NO_PARENT bit.
107 //
108 // This function always returns a valid top level window or NULL.
109 wxWindow *GetParentForModalDialog(wxWindow *parent, long style) const;
110
111 // This overload can only be used for already initialized windows, i.e. not
112 // from the ctor. It uses the current window parent and style.
113 wxWindow *GetParentForModalDialog() const
114 {
115 return GetParentForModalDialog(GetParent(), GetWindowStyle());
116 }
117
118 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
119 // splits text up at newlines and places the lines into a vertical
120 // wxBoxSizer
121 wxSizer *CreateTextSizer( const wxString& message );
122
123 // same as above but uses a customized wxTextSizerWrapper to create
124 // non-standard controls for the lines
125 wxSizer *CreateTextSizer( const wxString& message,
126 wxTextSizerWrapper& wrapper );
127 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
128
129 // returns a horizontal wxBoxSizer containing the given buttons
130 //
131 // notice that the returned sizer can be NULL if no buttons are put in the
132 // sizer (this mostly happens under smart phones and other atypical
133 // platforms which have hardware buttons replacing OK/Cancel and such)
134 wxSizer *CreateButtonSizer(long flags);
135
136 // returns the sizer containing CreateButtonSizer() below a separating
137 // static line for the platforms which use static lines for items
138 // separation (i.e. not Mac)
139 wxSizer *CreateSeparatedButtonSizer(long flags);
140
141 #if wxUSE_BUTTON
142 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
143 #endif // wxUSE_BUTTON
144
145 // Do layout adaptation
146 virtual bool DoLayoutAdaptation();
147
148 // Can we do layout adaptation?
149 virtual bool CanDoLayoutAdaptation();
150
151 // Returns a content window if there is one. This can be used by the layout adapter, for
152 // example to make the pages of a book control into scrolling windows
153 virtual wxWindow* GetContentWindow() const { return NULL; }
154
155 // Add an id to the list of main button identifiers that should be in the button sizer
156 void AddMainButtonId(wxWindowID id) { m_mainButtonIds.Add((int) id); }
157 wxArrayInt& GetMainButtonIds() { return m_mainButtonIds; }
158
159 // Is this id in the main button id array?
160 bool IsMainButtonId(wxWindowID id) const { return (m_mainButtonIds.Index((int) id) != wxNOT_FOUND); }
161
162 // Level of adaptation, from none (Level 0) to full (Level 3). To disable adaptation,
163 // set level 0, for example in your dialog constructor. You might
164 // do this if you know that you are displaying on a large screen and you don't want the
165 // dialog changed.
166 void SetLayoutAdaptationLevel(int level) { m_layoutAdaptationLevel = level; }
167 int GetLayoutAdaptationLevel() const { return m_layoutAdaptationLevel; }
168
169 /// Override global adaptation enabled/disabled status
170 void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode) { m_layoutAdaptationMode = mode; }
171 wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const { return m_layoutAdaptationMode; }
172
173 // Returns true if the adaptation has been done
174 void SetLayoutAdaptationDone(bool adaptationDone) { m_layoutAdaptationDone = adaptationDone; }
175 bool GetLayoutAdaptationDone() const { return m_layoutAdaptationDone; }
176
177 // Set layout adapter class, returning old adapter
178 static wxDialogLayoutAdapter* SetLayoutAdapter(wxDialogLayoutAdapter* adapter);
179 static wxDialogLayoutAdapter* GetLayoutAdapter() { return sm_layoutAdapter; }
180
181 // Global switch for layout adaptation
182 static bool IsLayoutAdaptationEnabled() { return sm_layoutAdaptation; }
183 static void EnableLayoutAdaptation(bool enable) { sm_layoutAdaptation = enable; }
184
185 // modality kind
186 virtual wxDialogModality GetModality() const;
187 protected:
188 // emulate click of a button with the given id if it's present in the dialog
189 //
190 // return true if button was "clicked" or false if we don't have it
191 bool EmulateButtonClickIfPresent(int id);
192
193 // this function is used by OnCharHook() to decide whether the given key
194 // should close the dialog
195 //
196 // for most platforms the default implementation (which just checks for
197 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
198 // could do something different if needed
199 virtual bool IsEscapeKey(const wxKeyEvent& event);
200
201 // end either modal or modeless dialog, for the modal dialog rc is used as
202 // the dialog return code
203 void EndDialog(int rc);
204
205 // call Validate() and TransferDataFromWindow() and close dialog with
206 // wxID_OK return code
207 void AcceptAndClose();
208
209 // The return code from modal dialog
210 int m_returnCode;
211
212 // The identifier for the affirmative button (usually wxID_OK)
213 int m_affirmativeId;
214
215 // The identifier for cancel button (usually wxID_CANCEL)
216 int m_escapeId;
217
218 // Flags whether layout adaptation has been done for this dialog
219 bool m_layoutAdaptationDone;
220
221 // Extra button identifiers to be taken as 'main' button identifiers
222 // to be placed in the non-scrolling area
223 wxArrayInt m_mainButtonIds;
224
225 // Adaptation level
226 int m_layoutAdaptationLevel;
227
228 // Local override for global adaptation enabled status
229 wxDialogLayoutAdaptationMode m_layoutAdaptationMode;
230
231 // Global layout adapter
232 static wxDialogLayoutAdapter* sm_layoutAdapter;
233
234 // Global adaptation switch
235 static bool sm_layoutAdaptation;
236
237 private:
238 // common part of all ctors
239 void Init();
240
241 // helper of GetParentForModalDialog(): returns the passed in window if it
242 // can be used as our parent or NULL if it can't
243 wxWindow *CheckIfCanBeUsedAsParent(wxWindow *parent) const;
244
245 // handle Esc key presses
246 void OnCharHook(wxKeyEvent& event);
247
248 // handle closing the dialog window
249 void OnCloseWindow(wxCloseEvent& event);
250
251 // handle the standard buttons
252 void OnButton(wxCommandEvent& event);
253
254 // update the background colour
255 void OnSysColourChanged(wxSysColourChangedEvent& event);
256
257
258 wxDECLARE_NO_COPY_CLASS(wxDialogBase);
259 DECLARE_EVENT_TABLE()
260 };
261
262 /*!
263 * Base class for layout adapters - code that, for example, turns a dialog into a
264 * scrolling dialog if there isn't enough screen space. You can derive further
265 * adapter classes to do any other kind of adaptation, such as applying a watermark, or adding
266 * a help mechanism.
267 */
268
269 class WXDLLIMPEXP_CORE wxDialogLayoutAdapter: public wxObject
270 {
271 DECLARE_CLASS(wxDialogLayoutAdapter)
272 public:
273 wxDialogLayoutAdapter() {}
274
275 // Override this function to indicate that adaptation should be done
276 virtual bool CanDoLayoutAdaptation(wxDialog* dialog) = 0;
277
278 // Override this function to do the adaptation
279 virtual bool DoLayoutAdaptation(wxDialog* dialog) = 0;
280 };
281
282 /*!
283 * Standard adapter. Does scrolling adaptation for paged and regular dialogs.
284 *
285 */
286
287 class WXDLLIMPEXP_CORE wxStandardDialogLayoutAdapter: public wxDialogLayoutAdapter
288 {
289 DECLARE_CLASS(wxStandardDialogLayoutAdapter)
290 public:
291 wxStandardDialogLayoutAdapter() {}
292
293 // Overrides
294
295 // Indicate that adaptation should be done
296 virtual bool CanDoLayoutAdaptation(wxDialog* dialog);
297
298 // Do layout adaptation
299 virtual bool DoLayoutAdaptation(wxDialog* dialog);
300
301 // Implementation
302
303 // Create the scrolled window
304 virtual wxScrolledWindow* CreateScrolledWindow(wxWindow* parent);
305
306 // Find a standard or horizontal box sizer
307 virtual wxSizer* FindButtonSizer(bool stdButtonSizer, wxDialog* dialog, wxSizer* sizer, int& retBorder, int accumlatedBorder = 0);
308
309 // Check if this sizer contains standard buttons, and so can be repositioned in the dialog
310 virtual bool IsOrdinaryButtonSizer(wxDialog* dialog, wxBoxSizer* sizer);
311
312 // Check if this is a standard button
313 virtual bool IsStandardButton(wxDialog* dialog, wxButton* button);
314
315 // Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
316 virtual bool FindLooseButtons(wxDialog* dialog, wxStdDialogButtonSizer* buttonSizer, wxSizer* sizer, int& count);
317
318 // Reparent the controls to the scrolled window, except those in buttonSizer
319 virtual void ReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL);
320 static void DoReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL);
321
322 // A function to fit the dialog around its contents, and then adjust for screen size.
323 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
324 virtual bool FitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow);
325 virtual bool FitWithScrolling(wxDialog* dialog, wxWindowList& windows);
326 static bool DoFitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow);
327 static bool DoFitWithScrolling(wxDialog* dialog, wxWindowList& windows);
328
329 // Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
330 virtual int MustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize);
331 static int DoMustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize);
332 };
333
334 #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
335 #include "wx/univ/dialog.h"
336 #else
337 #if defined(__WXPALMOS__)
338 #include "wx/palmos/dialog.h"
339 #elif defined(__WXMSW__)
340 #include "wx/msw/dialog.h"
341 #elif defined(__WXMOTIF__)
342 #include "wx/motif/dialog.h"
343 #elif defined(__WXGTK20__)
344 #include "wx/gtk/dialog.h"
345 #elif defined(__WXGTK__)
346 #include "wx/gtk1/dialog.h"
347 #elif defined(__WXMAC__)
348 #include "wx/osx/dialog.h"
349 #elif defined(__WXCOCOA__)
350 #include "wx/cocoa/dialog.h"
351 #elif defined(__WXPM__)
352 #include "wx/os2/dialog.h"
353 #endif
354 #endif
355
356 class WXDLLIMPEXP_CORE wxWindowModalDialogEvent : public wxCommandEvent
357 {
358 public:
359 wxWindowModalDialogEvent (wxEventType commandType = wxEVT_NULL, int id = 0)
360 : wxCommandEvent(commandType, id) { }
361
362 wxDialog *GetDialog() const
363 { return wxStaticCast(GetEventObject(), wxDialog); }
364
365 int GetReturnCode() const
366 { return GetDialog()->GetReturnCode(); }
367
368 virtual wxEvent *Clone() const { return new wxWindowModalDialogEvent (*this); }
369
370 private:
371 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowModalDialogEvent )
372 };
373
374 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_WINDOW_MODAL_DIALOG_CLOSED , wxWindowModalDialogEvent );
375
376 typedef void (wxEvtHandler::*wxWindowModalDialogEventFunction)(wxWindowModalDialogEvent &);
377
378 #define wxWindowModalDialogEventHandler(func) \
379 wxEVENT_HANDLER_CAST(wxWindowModalDialogEventFunction, func)
380
381 #endif
382 // _WX_DIALOG_H_BASE_