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