moved all wxDialog event handlers to wxDialogBase to avoid code duplication
[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/containr.h"
17 #include "wx/toplevel.h"
18
19 class WXDLLEXPORT wxSizer;
20 class WXDLLEXPORT wxStdDialogButtonSizer;
21
22 #define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
23
24 #ifdef __WXWINCE__
25 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
26 #else
27 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
28 #endif
29
30 extern WXDLLEXPORT_DATA(const wxChar) wxDialogNameStr[];
31
32 class WXDLLEXPORT wxDialogBase : public wxTopLevelWindow
33 {
34 public:
35 enum
36 {
37 // all flags allowed in wxDialogBase::CreateButtonSizer()
38 ButtonSizerFlags = wxOK|wxCANCEL|wxYES|wxNO|wxHELP|wxNO_DEFAULT
39 };
40
41 wxDialogBase() { Init(); }
42 virtual ~wxDialogBase() { }
43
44 // public wxDialog API, to be implemented by the derived classes
45 virtual int ShowModal() = 0;
46 virtual void EndModal(int retCode) = 0;
47 virtual bool IsModal() const = 0;
48
49
50 // Modal dialogs have a return code - usually the id of the last
51 // pressed button
52 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
53 int GetReturnCode() const { return m_returnCode; }
54
55 // The identifier for the affirmative button
56 void SetAffirmativeId(int affirmativeId) { m_affirmativeId = affirmativeId; }
57 int GetAffirmativeId() const { return m_affirmativeId; }
58
59 // Identifier for Esc key translation
60 void SetEscapeId(int escapeId) { m_escapeId = escapeId; }
61 int GetEscapeId() const { return m_escapeId; }
62
63 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
64 // splits text up at newlines and places the
65 // lines into a vertical wxBoxSizer
66 wxSizer *CreateTextSizer( const wxString &message );
67 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
68
69 // places buttons into a horizontal wxBoxSizer
70 wxSizer *CreateButtonSizer( long flags,
71 bool separated = false,
72 wxCoord distance = 0 );
73 #if wxUSE_BUTTON
74 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
75 #endif // wxUSE_BUTTON
76
77 protected:
78 // emulate click of a button with the given id if it's present in the dialog
79 //
80 // return true if button was "clicked" or false if we don't have it
81 bool EmulateButtonClickIfPresent(int id);
82
83 // this function is used by OnCharHook() to decide whether the given key
84 // should close the dialog
85 //
86 // for most platforms the default implementation (which just checks for
87 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
88 // could do something different if needed
89 virtual bool IsEscapeKey(const wxKeyEvent& event);
90
91 // end either modal or modeless dialog, for the modal dialog rc is used as
92 // the dialog return code
93 void EndDialog(int rc);
94
95
96 // The return code from modal dialog
97 int m_returnCode;
98
99 // The identifier for the affirmative button (usually wxID_OK)
100 int m_affirmativeId;
101
102 // The identifier for cancel button (usually wxID_CANCEL)
103 int m_escapeId;
104
105 private:
106 // common part of all ctors
107 void Init();
108
109 // handle Esc key presses
110 void OnCharHook(wxKeyEvent& event);
111
112 // handle closing the dialog window
113 void OnCloseWindow(wxCloseEvent& event);
114
115 // handle the standard buttons
116 void OnOK(wxCommandEvent& event);
117 void OnApply(wxCommandEvent& event);
118 void OnCancel(wxCommandEvent& event);
119
120 // update the background colour
121 void OnSysColourChanged(wxSysColourChangedEvent& event);
122
123
124 DECLARE_NO_COPY_CLASS(wxDialogBase)
125 DECLARE_EVENT_TABLE()
126 WX_DECLARE_CONTROL_CONTAINER();
127 };
128
129
130 #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
131 #include "wx/univ/dialog.h"
132 #else
133 #if defined(__WXPALMOS__)
134 #include "wx/palmos/dialog.h"
135 #elif defined(__WXMSW__)
136 #include "wx/msw/dialog.h"
137 #elif defined(__WXMOTIF__)
138 #include "wx/motif/dialog.h"
139 #elif defined(__WXGTK20__)
140 #include "wx/gtk/dialog.h"
141 #elif defined(__WXGTK__)
142 #include "wx/gtk1/dialog.h"
143 #elif defined(__WXMAC__)
144 #include "wx/mac/dialog.h"
145 #elif defined(__WXCOCOA__)
146 #include "wx/cocoa/dialog.h"
147 #elif defined(__WXPM__)
148 #include "wx/os2/dialog.h"
149 #endif
150 #endif
151
152 #endif
153 // _WX_DIALOG_H_BASE_