centralized Esc key handling for closing the dialogs in wxDialogBase:
[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 void Init();
45
46 // Modal dialogs have a return code - usually the id of the last
47 // pressed button
48 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
49 int GetReturnCode() const { return m_returnCode; }
50
51 // The identifier for the affirmative button
52 void SetAffirmativeId(int affirmativeId) { m_affirmativeId = affirmativeId; }
53 int GetAffirmativeId() const { return m_affirmativeId; }
54
55 // Identifier for Esc key translation
56 void SetEscapeId(int escapeId) { m_escapeId = escapeId; }
57 int GetEscapeId() const { return m_escapeId; }
58
59 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
60 // splits text up at newlines and places the
61 // lines into a vertical wxBoxSizer
62 wxSizer *CreateTextSizer( const wxString &message );
63 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
64
65 // places buttons into a horizontal wxBoxSizer
66 wxSizer *CreateButtonSizer( long flags,
67 bool separated = false,
68 wxCoord distance = 0 );
69 #if wxUSE_BUTTON
70 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
71 #endif // wxUSE_BUTTON
72
73 protected:
74 // emulate click of a button with the given id if it's present in the dialog
75 //
76 // return true if button was "clicked" or false if we don't have it
77 bool EmulateButtonClickIfPresent(int id);
78
79 // this function is used by OnCharHook() to decide whether the given key
80 // should close the dialog
81 //
82 // for most platforms the default implementation (which just checks for
83 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
84 // could do something different if needed
85 virtual bool IsEscapeKey(const wxKeyEvent& event);
86
87
88 // The return code from modal dialog
89 int m_returnCode;
90
91 // The identifier for the affirmative button (usually wxID_OK)
92 int m_affirmativeId;
93
94 // The identifier for cancel button (usually wxID_CANCEL)
95 int m_escapeId;
96
97 private:
98 // handle Esc key presses
99 void OnCharHook(wxKeyEvent& event);
100
101 DECLARE_NO_COPY_CLASS(wxDialogBase)
102 DECLARE_EVENT_TABLE()
103 WX_DECLARE_CONTROL_CONTAINER();
104 };
105
106
107 #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
108 #include "wx/univ/dialog.h"
109 #else
110 #if defined(__WXPALMOS__)
111 #include "wx/palmos/dialog.h"
112 #elif defined(__WXMSW__)
113 #include "wx/msw/dialog.h"
114 #elif defined(__WXMOTIF__)
115 #include "wx/motif/dialog.h"
116 #elif defined(__WXGTK20__)
117 #include "wx/gtk/dialog.h"
118 #elif defined(__WXGTK__)
119 #include "wx/gtk1/dialog.h"
120 #elif defined(__WXMAC__)
121 #include "wx/mac/dialog.h"
122 #elif defined(__WXCOCOA__)
123 #include "wx/cocoa/dialog.h"
124 #elif defined(__WXPM__)
125 #include "wx/os2/dialog.h"
126 #endif
127 #endif
128
129 #endif
130 // _WX_DIALOG_H_BASE_