]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dialog.h
Adapted to API changes with respect to GetTextExtent (patch #1709152).
[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
VS
16#include "wx/containr.h"
17#include "wx/toplevel.h"
9f3a38fc 18
acf2ac37
RR
19class WXDLLEXPORT wxSizer;
20class WXDLLEXPORT wxStdDialogButtonSizer;
21
8b5ef6cf
VZ
22#define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
23
568883a4 24#ifdef __WXWINCE__
30dfe2ff 25#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
9ceeecb9
JS
26#else
27#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
568883a4 28#endif
8b5ef6cf 29
63ec432b 30extern WXDLLEXPORT_DATA(const wxChar) wxDialogNameStr[];
0cc1d4ff 31
7d9f12f3 32class WXDLLEXPORT wxDialogBase : public wxTopLevelWindow
c50f1fb9 33{
dfe1eee3 34public:
897b24cf
WS
35 enum
36 {
37 // all flags allowed in wxDialogBase::CreateButtonSizer()
38 ButtonSizerFlags = wxOK|wxCANCEL|wxYES|wxNO|wxHELP|wxNO_DEFAULT
39 };
40
6463b9f5 41 wxDialogBase() { Init(); }
82c9f85c
VZ
42 virtual ~wxDialogBase() { }
43
a9f620da 44 // define public wxDialog methods to be implemented by the derived classes
2158f4d7
VZ
45 virtual int ShowModal() = 0;
46 virtual void EndModal(int retCode) = 0;
47 virtual bool IsModal() const = 0;
48
82c9f85c 49
9ceeecb9 50 // Modal dialogs have a return code - usually the id of the last
dfe1eee3
VZ
51 // pressed button
52 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
53 int GetReturnCode() const { return m_returnCode; }
54
551f281b
VZ
55 // Set the identifier for the affirmative button: this button will close
56 // the dialog after validating data and calling TransferDataFromWindow()
57 void SetAffirmativeId(int affirmativeId);
9ceeecb9
JS
58 int GetAffirmativeId() const { return m_affirmativeId; }
59
551f281b
VZ
60 // Set identifier for Esc key translation: the button with this id will
61 // close the dialog without doing anything else; special value wxID_NONE
62 // means to not handle Esc at all while wxID_ANY means to map Esc to
63 // wxID_CANCEL if present and GetAffirmativeId() otherwise
64 void SetEscapeId(int escapeId);
2b4f7fbc 65 int GetEscapeId() const { return m_escapeId; }
2b4f7fbc 66
2229243b
VZ
67 // Returns the parent to use for modal dialogs if the user did not specify it
68 // explicitly
69 wxWindow *GetParentForModalDialog(wxWindow *parent = NULL) const;
70
d7260478 71#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
92afa2b1
RR
72 // splits text up at newlines and places the
73 // lines into a vertical wxBoxSizer
74 wxSizer *CreateTextSizer( const wxString &message );
d7260478 75#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
82c9f85c 76
25eb10d2
VZ
77 // returns a horizontal wxBoxSizer containing the given buttons
78 //
79 // notice that the returned sizer can be NULL if no buttons are put in the
80 // sizer (this mostly happens under smart phones and other atypical
81 // platforms which have hardware buttons replacing OK/Cancel and such)
82 wxSizer *CreateButtonSizer(long flags);
83
84 // returns the sizer containing CreateButtonSizer() below a separating
85 // static line for the platforms which use static lines for items
86 // separation (i.e. not Mac)
87 wxSizer *CreateSeparatedButtonSizer(long flags);
88
897b24cf 89#if wxUSE_BUTTON
acf2ac37 90 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
1e6feb95 91#endif // wxUSE_BUTTON
dfe1eee3 92
f6bcfd97 93protected:
0be27418
VZ
94 // emulate click of a button with the given id if it's present in the dialog
95 //
96 // return true if button was "clicked" or false if we don't have it
97 bool EmulateButtonClickIfPresent(int id);
98
99 // this function is used by OnCharHook() to decide whether the given key
100 // should close the dialog
101 //
102 // for most platforms the default implementation (which just checks for
103 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
104 // could do something different if needed
105 virtual bool IsEscapeKey(const wxKeyEvent& event);
106
2158f4d7
VZ
107 // end either modal or modeless dialog, for the modal dialog rc is used as
108 // the dialog return code
109 void EndDialog(int rc);
110
551f281b
VZ
111 // call Validate() and TransferDataFromWindow() and close dialog with
112 // wxID_OK return code
113 void AcceptAndClose();
114
0be27418 115
9ceeecb9 116 // The return code from modal dialog
dfe1eee3 117 int m_returnCode;
7d9f12f3 118
9ceeecb9
JS
119 // The identifier for the affirmative button (usually wxID_OK)
120 int m_affirmativeId;
121
c6ece595
VZ
122 // The identifier for cancel button (usually wxID_CANCEL)
123 int m_escapeId;
124
0be27418 125private:
2158f4d7
VZ
126 // common part of all ctors
127 void Init();
128
0be27418
VZ
129 // handle Esc key presses
130 void OnCharHook(wxKeyEvent& event);
131
2158f4d7
VZ
132 // handle closing the dialog window
133 void OnCloseWindow(wxCloseEvent& event);
134
135 // handle the standard buttons
a9f620da 136 void OnButton(wxCommandEvent& event);
2158f4d7
VZ
137
138 // update the background colour
139 void OnSysColourChanged(wxSysColourChangedEvent& event);
140
141
fc7a2a60 142 DECLARE_NO_COPY_CLASS(wxDialogBase)
7d9f12f3
VS
143 DECLARE_EVENT_TABLE()
144 WX_DECLARE_CONTROL_CONTAINER();
c50f1fb9
VZ
145};
146
7d9f12f3 147
c67d6888 148#if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
0e0de6b8
VS
149 #include "wx/univ/dialog.h"
150#else
4055ed82 151 #if defined(__WXPALMOS__)
ffecfa5a
JS
152 #include "wx/palmos/dialog.h"
153 #elif defined(__WXMSW__)
0e0de6b8
VS
154 #include "wx/msw/dialog.h"
155 #elif defined(__WXMOTIF__)
156 #include "wx/motif/dialog.h"
1be7a35c 157 #elif defined(__WXGTK20__)
0e0de6b8 158 #include "wx/gtk/dialog.h"
1be7a35c
MR
159 #elif defined(__WXGTK__)
160 #include "wx/gtk1/dialog.h"
0e0de6b8
VS
161 #elif defined(__WXMAC__)
162 #include "wx/mac/dialog.h"
e64df9bc
DE
163 #elif defined(__WXCOCOA__)
164 #include "wx/cocoa/dialog.h"
0e0de6b8
VS
165 #elif defined(__WXPM__)
166 #include "wx/os2/dialog.h"
0e0de6b8 167 #endif
c801d85f
KB
168#endif
169
170#endif
34138703 171 // _WX_DIALOG_H_BASE_