1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDialogBase class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DIALOG_H_BASE_
13 #define _WX_DIALOG_H_BASE_
16 #include "wx/containr.h"
17 #include "wx/toplevel.h"
19 class WXDLLEXPORT wxSizer
;
20 class WXDLLEXPORT wxStdDialogButtonSizer
;
22 #define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
25 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
27 #define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
30 extern WXDLLEXPORT_DATA(const wxChar
) wxDialogNameStr
[];
32 class WXDLLEXPORT wxDialogBase
: public wxTopLevelWindow
37 // all flags allowed in wxDialogBase::CreateButtonSizer()
38 ButtonSizerFlags
= wxOK
|wxCANCEL
|wxYES
|wxNO
|wxHELP
|wxNO_DEFAULT
41 wxDialogBase() { Init(); }
42 virtual ~wxDialogBase() { }
44 // define public wxDialog methods 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;
50 // Modal dialogs have a return code - usually the id of the last
52 void SetReturnCode(int returnCode
) { m_returnCode
= returnCode
; }
53 int GetReturnCode() const { return m_returnCode
; }
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
);
58 int GetAffirmativeId() const { return m_affirmativeId
; }
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
);
65 int GetEscapeId() const { return m_escapeId
; }
67 #if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
68 // splits text up at newlines and places the
69 // lines into a vertical wxBoxSizer
70 wxSizer
*CreateTextSizer( const wxString
&message
);
71 #endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
73 // returns a horizontal wxBoxSizer containing the given buttons
75 // notice that the returned sizer can be NULL if no buttons are put in the
76 // sizer (this mostly happens under smart phones and other atypical
77 // platforms which have hardware buttons replacing OK/Cancel and such)
78 wxSizer
*CreateButtonSizer(long flags
);
80 // returns the sizer containing CreateButtonSizer() below a separating
81 // static line for the platforms which use static lines for items
82 // separation (i.e. not Mac)
83 wxSizer
*CreateSeparatedButtonSizer(long flags
);
86 wxStdDialogButtonSizer
*CreateStdDialogButtonSizer( long flags
);
87 #endif // wxUSE_BUTTON
90 // emulate click of a button with the given id if it's present in the dialog
92 // return true if button was "clicked" or false if we don't have it
93 bool EmulateButtonClickIfPresent(int id
);
95 // this function is used by OnCharHook() to decide whether the given key
96 // should close the dialog
98 // for most platforms the default implementation (which just checks for
99 // Esc) is sufficient, but Mac port also adds Cmd-. here and other ports
100 // could do something different if needed
101 virtual bool IsEscapeKey(const wxKeyEvent
& event
);
103 // end either modal or modeless dialog, for the modal dialog rc is used as
104 // the dialog return code
105 void EndDialog(int rc
);
107 // call Validate() and TransferDataFromWindow() and close dialog with
108 // wxID_OK return code
109 void AcceptAndClose();
112 // The return code from modal dialog
115 // The identifier for the affirmative button (usually wxID_OK)
118 // The identifier for cancel button (usually wxID_CANCEL)
122 // common part of all ctors
125 // handle Esc key presses
126 void OnCharHook(wxKeyEvent
& event
);
128 // handle closing the dialog window
129 void OnCloseWindow(wxCloseEvent
& event
);
131 // handle the standard buttons
132 void OnButton(wxCommandEvent
& event
);
134 // update the background colour
135 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
138 DECLARE_NO_COPY_CLASS(wxDialogBase
)
139 DECLARE_EVENT_TABLE()
140 WX_DECLARE_CONTROL_CONTAINER();
144 #if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
145 #include "wx/univ/dialog.h"
147 #if defined(__WXPALMOS__)
148 #include "wx/palmos/dialog.h"
149 #elif defined(__WXMSW__)
150 #include "wx/msw/dialog.h"
151 #elif defined(__WXMOTIF__)
152 #include "wx/motif/dialog.h"
153 #elif defined(__WXGTK20__)
154 #include "wx/gtk/dialog.h"
155 #elif defined(__WXGTK__)
156 #include "wx/gtk1/dialog.h"
157 #elif defined(__WXMAC__)
158 #include "wx/mac/dialog.h"
159 #elif defined(__WXCOCOA__)
160 #include "wx/cocoa/dialog.h"
161 #elif defined(__WXPM__)
162 #include "wx/os2/dialog.h"
167 // _WX_DIALOG_H_BASE_