]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dialog.h
add possibility to specify the conversion to use in wxStringOutputStream; use it...
[wxWidgets.git] / include / wx / dialog.h
CommitLineData
dfe1eee3
VZ
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
65571936 9// Licence: wxWindows licence
dfe1eee3
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_DIALOG_H_BASE_
13#define _WX_DIALOG_H_BASE_
c801d85f 14
9f3a38fc 15#include "wx/defs.h"
7d9f12f3 16#include "wx/toplevel.h"
9f3a38fc 17
b5dbe15d
VS
18class WXDLLIMPEXP_FWD_CORE wxSizer;
19class WXDLLIMPEXP_FWD_CORE wxStdDialogButtonSizer;
3aa8e4ea
JS
20class WXDLLIMPEXP_FWD_CORE wxBoxSizer;
21class WXDLLIMPEXP_FWD_CORE wxDialogLayoutAdapter;
22class WXDLLIMPEXP_FWD_CORE wxDialog;
23class WXDLLIMPEXP_FWD_CORE wxButton;
24class WXDLLIMPEXP_FWD_CORE wxScrolledWindow;
acf2ac37 25
8b5ef6cf
VZ
26#define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
27
568883a4 28#ifdef __WXWINCE__
30dfe2ff 29#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
9ceeecb9
JS
30#else
31#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
568883a4 32#endif
8b5ef6cf 33
3aa8e4ea
JS
34// Layout adaptation levels, for SetLayoutAdaptationLevel
35
36// Don't do any layout adaptation
37#define wxDIALOG_ADAPTATION_NONE 0
38
39// Only look for wxStdDialogButtonSizer for non-scrolling part
40#define wxDIALOG_ADAPTATION_STANDARD_SIZER 1
41
42// Also look for any suitable sizer for non-scrolling part
43#define wxDIALOG_ADAPTATION_ANY_SIZER 2
44
45// Also look for 'loose' standard buttons for non-scrolling part
46#define wxDIALOG_ADAPTATION_LOOSE_BUTTONS 3
47
48// Layout adaptation mode, for SetLayoutAdaptationMode
49enum wxDialogLayoutAdaptationMode
50{
51 wxDIALOG_ADAPTATION_MODE_DEFAULT = 0, // use global adaptation enabled status
52 wxDIALOG_ADAPTATION_MODE_ENABLED = 1, // enable this dialog overriding global status
53 wxDIALOG_ADAPTATION_MODE_DISABLED = 2 // disable this dialog overriding global status
54};
55
53a2db12 56extern WXDLLIMPEXP_DATA_CORE(const char) wxDialogNameStr[];
0cc1d4ff 57
53a2db12 58class WXDLLIMPEXP_CORE wxDialogBase : public wxTopLevelWindow
c50f1fb9 59{
dfe1eee3 60public:
897b24cf
WS
61 enum
62 {
63 // all flags allowed in wxDialogBase::CreateButtonSizer()
64 ButtonSizerFlags = wxOK|wxCANCEL|wxYES|wxNO|wxHELP|wxNO_DEFAULT
65 };
66
6463b9f5 67 wxDialogBase() { Init(); }
82c9f85c
VZ
68 virtual ~wxDialogBase() { }
69
a9f620da 70 // define public wxDialog methods to be implemented by the derived classes
2158f4d7
VZ
71 virtual int ShowModal() = 0;
72 virtual void EndModal(int retCode) = 0;
73 virtual bool IsModal() const = 0;
74
82c9f85c 75
9ceeecb9 76 // Modal dialogs have a return code - usually the id of the last
dfe1eee3
VZ
77 // pressed button
78 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
79 int GetReturnCode() const { return m_returnCode; }
80
551f281b
VZ
81 // Set the identifier for the affirmative button: this button will close
82 // the dialog after validating data and calling TransferDataFromWindow()
83 void SetAffirmativeId(int affirmativeId);
9ceeecb9
JS
84 int GetAffirmativeId() const { return m_affirmativeId; }
85
551f281b
VZ
86 // Set identifier for Esc key translation: the button with this id will
87 // close the dialog without doing anything else; special value wxID_NONE
88 // means to not handle Esc at all while wxID_ANY means to map Esc to
89 // wxID_CANCEL if present and GetAffirmativeId() otherwise
90 void SetEscapeId(int escapeId);
2b4f7fbc 91 int GetEscapeId() const { return m_escapeId; }
2b4f7fbc 92
2229243b
VZ
93 // Returns the parent to use for modal dialogs if the user did not specify it
94 // explicitly
95 wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const;
96
d7260478 97#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
92afa2b1
RR
98 // splits text up at newlines and places the
99 // lines into a vertical wxBoxSizer
100 wxSizer *CreateTextSizer( const wxString &message );
d7260478 101#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
82c9f85c 102
25eb10d2
VZ
103 // returns a horizontal wxBoxSizer containing the given buttons
104 //
105 // notice that the returned sizer can be NULL if no buttons are put in the
106 // sizer (this mostly happens under smart phones and other atypical
107 // platforms which have hardware buttons replacing OK/Cancel and such)
108 wxSizer *CreateButtonSizer(long flags);
109
110 // returns the sizer containing CreateButtonSizer() below a separating
111 // static line for the platforms which use static lines for items
112 // separation (i.e. not Mac)
113 wxSizer *CreateSeparatedButtonSizer(long flags);
114
897b24cf 115#if wxUSE_BUTTON
acf2ac37 116 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
1e6feb95 117#endif // wxUSE_BUTTON
dfe1eee3 118
3aa8e4ea
JS
119 // Do layout adaptation
120 virtual bool DoLayoutAdaptation();
121
122 // Can we do layout adaptation?
123 virtual bool CanDoLayoutAdaptation();
124
125 // Returns a content window if there is one. This can be used by the layout adapter, for
126 // example to make the pages of a book control into scrolling windows
127 virtual wxWindow* GetContentWindow() const { return NULL; }
128
129 // Add an id to the list of main button identifiers that should be in the button sizer
130 void AddMainButtonId(wxWindowID id) { m_mainButtonIds.Add((int) id); }
131 wxArrayInt& GetMainButtonIds() { return m_mainButtonIds; }
132
133 // Is this id in the main button id array?
134 bool IsMainButtonId(wxWindowID id) const { return (m_mainButtonIds.Index((int) id) != wxNOT_FOUND); }
135
136 // Level of adaptation, from none (Level 0) to full (Level 3). To disable adaptation,
137 // set level 0, for example in your dialog constructor. You might
138 // do this if you know that you are displaying on a large screen and you don't want the
139 // dialog changed.
140 void SetLayoutAdaptationLevel(int level) { m_layoutAdaptationLevel = level; }
141 int GetLayoutAdaptationLevel() const { return m_layoutAdaptationLevel; }
142
143 /// Override global adaptation enabled/disabled status
144 void SetLayoutAdaptationMode(wxDialogLayoutAdaptationMode mode) { m_layoutAdaptationMode = mode; }
145 wxDialogLayoutAdaptationMode GetLayoutAdaptationMode() const { return m_layoutAdaptationMode; }
146
147 // Returns true if the adaptation has been done
148 void SetLayoutAdaptationDone(bool adaptationDone) { m_layoutAdaptationDone = adaptationDone; }
149 bool GetLayoutAdaptationDone() const { return m_layoutAdaptationDone; }
150
151 // Set layout adapter class, returning old adapter
152 static wxDialogLayoutAdapter* SetLayoutAdapter(wxDialogLayoutAdapter* adapter);
153 static wxDialogLayoutAdapter* GetLayoutAdapter() { return sm_layoutAdapter; }
154
155 // Global switch for layout adaptation
156 static bool IsLayoutAdaptationEnabled() { return sm_layoutAdaptation; }
157 static void EnableLayoutAdaptation(bool enable) { sm_layoutAdaptation = enable; }
158
f6bcfd97 159protected:
0be27418
VZ
160 // emulate click of a button with the given id if it's present in the dialog
161 //
162 // return true if button was "clicked" or false if we don't have it
163 bool EmulateButtonClickIfPresent(int id);
164
165 // this function is used by OnCharHook() to decide whether the given key
166 // should close the dialog
167 //
168 // for most platforms the default implementation (which just checks for
169 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
170 // could do something different if needed
171 virtual bool IsEscapeKey(const wxKeyEvent& event);
172
2158f4d7
VZ
173 // end either modal or modeless dialog, for the modal dialog rc is used as
174 // the dialog return code
175 void EndDialog(int rc);
176
551f281b
VZ
177 // call Validate() and TransferDataFromWindow() and close dialog with
178 // wxID_OK return code
179 void AcceptAndClose();
180
0be27418 181
9ceeecb9 182 // The return code from modal dialog
dfe1eee3 183 int m_returnCode;
7d9f12f3 184
9ceeecb9
JS
185 // The identifier for the affirmative button (usually wxID_OK)
186 int m_affirmativeId;
187
c6ece595
VZ
188 // The identifier for cancel button (usually wxID_CANCEL)
189 int m_escapeId;
190
3aa8e4ea
JS
191 // Flags whether layout adaptation has been done for this dialog
192 bool m_layoutAdaptationDone;
193
194 // Extra button identifiers to be taken as 'main' button identifiers
195 // to be placed in the non-scrolling area
196 wxArrayInt m_mainButtonIds;
197
198 // Adaptation level
199 int m_layoutAdaptationLevel;
200
201 // Local override for global adaptation enabled status
202 wxDialogLayoutAdaptationMode m_layoutAdaptationMode;
203
204 // Global layout adapter
205 static wxDialogLayoutAdapter* sm_layoutAdapter;
206
207 // Global adaptation switch
208 static bool sm_layoutAdaptation;
209
0be27418 210private:
2158f4d7
VZ
211 // common part of all ctors
212 void Init();
213
0be27418
VZ
214 // handle Esc key presses
215 void OnCharHook(wxKeyEvent& event);
216
2158f4d7
VZ
217 // handle closing the dialog window
218 void OnCloseWindow(wxCloseEvent& event);
219
220 // handle the standard buttons
a9f620da 221 void OnButton(wxCommandEvent& event);
2158f4d7
VZ
222
223 // update the background colour
224 void OnSysColourChanged(wxSysColourChangedEvent& event);
225
226
fc7a2a60 227 DECLARE_NO_COPY_CLASS(wxDialogBase)
7d9f12f3 228 DECLARE_EVENT_TABLE()
c50f1fb9
VZ
229};
230
3aa8e4ea
JS
231/*!
232 * Base class for layout adapters - code that, for example, turns a dialog into a
233 * scrolling dialog if there isn't enough screen space. You can derive further
234 * adapter classes to do any other kind of adaptation, such as applying a watermark, or adding
235 * a help mechanism.
236 */
237
53a2db12 238class WXDLLIMPEXP_CORE wxDialogLayoutAdapter: public wxObject
3aa8e4ea
JS
239{
240 DECLARE_CLASS(wxDialogLayoutAdapter)
241public:
242 wxDialogLayoutAdapter() {}
243
244 // Override this function to indicate that adaptation should be done
245 virtual bool CanDoLayoutAdaptation(wxDialog* dialog) = 0;
246
247 // Override this function to do the adaptation
248 virtual bool DoLayoutAdaptation(wxDialog* dialog) = 0;
249};
250
251/*!
252 * Standard adapter. Does scrolling adaptation for paged and regular dialogs.
253 *
254 */
255
53a2db12 256class WXDLLIMPEXP_CORE wxStandardDialogLayoutAdapter: public wxDialogLayoutAdapter
3aa8e4ea
JS
257{
258 DECLARE_CLASS(wxStandardDialogLayoutAdapter)
259public:
260 wxStandardDialogLayoutAdapter() {}
261
262// Overrides
263
264 // Indicate that adaptation should be done
265 virtual bool CanDoLayoutAdaptation(wxDialog* dialog);
266
267 // Do layout adaptation
268 virtual bool DoLayoutAdaptation(wxDialog* dialog);
269
270// Implementation
271
272 // Create the scrolled window
273 virtual wxScrolledWindow* CreateScrolledWindow(wxWindow* parent);
274
275 // Find a standard or horizontal box sizer
276 virtual wxSizer* FindButtonSizer(bool stdButtonSizer, wxDialog* dialog, wxSizer* sizer, int& retBorder, int accumlatedBorder = 0);
277
278 // Check if this sizer contains standard buttons, and so can be repositioned in the dialog
279 virtual bool IsOrdinaryButtonSizer(wxDialog* dialog, wxBoxSizer* sizer);
280
281 // Check if this is a standard button
282 virtual bool IsStandardButton(wxDialog* dialog, wxButton* button);
283
284 // Find 'loose' main buttons in the existing layout and add them to the standard dialog sizer
285 virtual bool FindLooseButtons(wxDialog* dialog, wxStdDialogButtonSizer* buttonSizer, wxSizer* sizer, int& count);
286
287 // Reparent the controls to the scrolled window, except those in buttonSizer
288 virtual void ReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL);
289 static void DoReparentControls(wxWindow* parent, wxWindow* reparentTo, wxSizer* buttonSizer = NULL);
290
291 // A function to fit the dialog around its contents, and then adjust for screen size.
292 // If scrolled windows are passed, scrolling is enabled in the required orientation(s).
293 virtual bool FitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow);
294 virtual bool FitWithScrolling(wxDialog* dialog, wxWindowList& windows);
295 static bool DoFitWithScrolling(wxDialog* dialog, wxScrolledWindow* scrolledWindow);
296 static bool DoFitWithScrolling(wxDialog* dialog, wxWindowList& windows);
297
298 // Find whether scrolling will be necessary for the dialog, returning wxVERTICAL, wxHORIZONTAL or both
299 virtual int MustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize);
300 static int DoMustScroll(wxDialog* dialog, wxSize& windowSize, wxSize& displaySize);
301};
7d9f12f3 302
c67d6888 303#if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
0e0de6b8
VS
304 #include "wx/univ/dialog.h"
305#else
4055ed82 306 #if defined(__WXPALMOS__)
ffecfa5a
JS
307 #include "wx/palmos/dialog.h"
308 #elif defined(__WXMSW__)
0e0de6b8
VS
309 #include "wx/msw/dialog.h"
310 #elif defined(__WXMOTIF__)
311 #include "wx/motif/dialog.h"
1be7a35c 312 #elif defined(__WXGTK20__)
0e0de6b8 313 #include "wx/gtk/dialog.h"
1be7a35c
MR
314 #elif defined(__WXGTK__)
315 #include "wx/gtk1/dialog.h"
0e0de6b8
VS
316 #elif defined(__WXMAC__)
317 #include "wx/mac/dialog.h"
e64df9bc
DE
318 #elif defined(__WXCOCOA__)
319 #include "wx/cocoa/dialog.h"
0e0de6b8
VS
320 #elif defined(__WXPM__)
321 #include "wx/os2/dialog.h"
0e0de6b8 322 #endif
c801d85f
KB
323#endif
324
325#endif
34138703 326 // _WX_DIALOG_H_BASE_