]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dialog.h
make wxChoice and wxListBox inherit from wxControlWithItems and not wxControl for...
[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 16#include "wx/toplevel.h"
9f3a38fc 17
b5dbe15d
VS
18class WXDLLIMPEXP_FWD_CORE wxSizer;
19class WXDLLIMPEXP_FWD_CORE wxStdDialogButtonSizer;
acf2ac37 20
8b5ef6cf
VZ
21#define wxDIALOG_NO_PARENT 0x0001 // Don't make owned by apps top window
22
568883a4 23#ifdef __WXWINCE__
30dfe2ff 24#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxMAXIMIZE | wxCLOSE_BOX | wxNO_BORDER)
9ceeecb9
JS
25#else
26#define wxDEFAULT_DIALOG_STYLE (wxCAPTION | wxSYSTEM_MENU | wxCLOSE_BOX)
568883a4 27#endif
8b5ef6cf 28
63ec432b 29extern WXDLLEXPORT_DATA(const wxChar) wxDialogNameStr[];
0cc1d4ff 30
7d9f12f3 31class WXDLLEXPORT wxDialogBase : public wxTopLevelWindow
c50f1fb9 32{
dfe1eee3 33public:
897b24cf
WS
34 enum
35 {
36 // all flags allowed in wxDialogBase::CreateButtonSizer()
37 ButtonSizerFlags = wxOK|wxCANCEL|wxYES|wxNO|wxHELP|wxNO_DEFAULT
38 };
39
6463b9f5 40 wxDialogBase() { Init(); }
82c9f85c
VZ
41 virtual ~wxDialogBase() { }
42
a9f620da 43 // define public wxDialog methods to be implemented by the derived classes
2158f4d7
VZ
44 virtual int ShowModal() = 0;
45 virtual void EndModal(int retCode) = 0;
46 virtual bool IsModal() const = 0;
47
82c9f85c 48
9ceeecb9 49 // Modal dialogs have a return code - usually the id of the last
dfe1eee3
VZ
50 // pressed button
51 void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
52 int GetReturnCode() const { return m_returnCode; }
53
551f281b
VZ
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);
9ceeecb9
JS
57 int GetAffirmativeId() const { return m_affirmativeId; }
58
551f281b
VZ
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);
2b4f7fbc 64 int GetEscapeId() const { return m_escapeId; }
2b4f7fbc 65
2229243b
VZ
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
d7260478 70#if wxUSE_STATTEXT // && wxUSE_TEXTCTRL
92afa2b1
RR
71 // splits text up at newlines and places the
72 // lines into a vertical wxBoxSizer
73 wxSizer *CreateTextSizer( const wxString &message );
d7260478 74#endif // wxUSE_STATTEXT // && wxUSE_TEXTCTRL
82c9f85c 75
25eb10d2
VZ
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
897b24cf 88#if wxUSE_BUTTON
acf2ac37 89 wxStdDialogButtonSizer *CreateStdDialogButtonSizer( long flags );
1e6feb95 90#endif // wxUSE_BUTTON
dfe1eee3 91
f6bcfd97 92protected:
0be27418
VZ
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
2158f4d7
VZ
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
551f281b
VZ
110 // call Validate() and TransferDataFromWindow() and close dialog with
111 // wxID_OK return code
112 void AcceptAndClose();
113
0be27418 114
9ceeecb9 115 // The return code from modal dialog
dfe1eee3 116 int m_returnCode;
7d9f12f3 117
9ceeecb9
JS
118 // The identifier for the affirmative button (usually wxID_OK)
119 int m_affirmativeId;
120
c6ece595
VZ
121 // The identifier for cancel button (usually wxID_CANCEL)
122 int m_escapeId;
123
0be27418 124private:
2158f4d7
VZ
125 // common part of all ctors
126 void Init();
127
0be27418
VZ
128 // handle Esc key presses
129 void OnCharHook(wxKeyEvent& event);
130
2158f4d7
VZ
131 // handle closing the dialog window
132 void OnCloseWindow(wxCloseEvent& event);
133
134 // handle the standard buttons
a9f620da 135 void OnButton(wxCommandEvent& event);
2158f4d7
VZ
136
137 // update the background colour
138 void OnSysColourChanged(wxSysColourChangedEvent& event);
139
140
fc7a2a60 141 DECLARE_NO_COPY_CLASS(wxDialogBase)
7d9f12f3 142 DECLARE_EVENT_TABLE()
c50f1fb9
VZ
143};
144
7d9f12f3 145
c67d6888 146#if defined(__WXUNIVERSAL__) && !defined(__WXMICROWIN__)
0e0de6b8
VS
147 #include "wx/univ/dialog.h"
148#else
4055ed82 149 #if defined(__WXPALMOS__)
ffecfa5a
JS
150 #include "wx/palmos/dialog.h"
151 #elif defined(__WXMSW__)
0e0de6b8
VS
152 #include "wx/msw/dialog.h"
153 #elif defined(__WXMOTIF__)
154 #include "wx/motif/dialog.h"
1be7a35c 155 #elif defined(__WXGTK20__)
0e0de6b8 156 #include "wx/gtk/dialog.h"
1be7a35c
MR
157 #elif defined(__WXGTK__)
158 #include "wx/gtk1/dialog.h"
0e0de6b8
VS
159 #elif defined(__WXMAC__)
160 #include "wx/mac/dialog.h"
e64df9bc
DE
161 #elif defined(__WXCOCOA__)
162 #include "wx/cocoa/dialog.h"
0e0de6b8
VS
163 #elif defined(__WXPM__)
164 #include "wx/os2/dialog.h"
0e0de6b8 165 #endif
c801d85f
KB
166#endif
167
168#endif
34138703 169 // _WX_DIALOG_H_BASE_