]> git.saurik.com Git - wxWidgets.git/blob - src/qt/dialog.cpp
added wxUSE_NOTEBOOK to include/wx/msw/setup0.h, removed wxUSE_RADIOBUTTON (we
[wxWidgets.git] / src / qt / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialog.cpp
3 // Purpose: wxDialog class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dialog.h"
14 #endif
15
16 #include "wx/dialog.h"
17 #include "wx/utils.h"
18 #include "wx/frame.h"
19 #include "wx/app.h"
20 #include "wx/settings.h"
21
22 // Lists to keep track of windows, so we can disable/enable them
23 // for modal dialogs
24 wxList wxModalDialogs;
25 wxList wxModelessWindows; // Frames and modeless dialogs
26 extern wxList wxPendingDelete;
27
28 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
29
30 BEGIN_EVENT_TABLE(wxDialog, wxPanel)
31 EVT_BUTTON(wxID_OK, wxDialog::OnOK)
32 EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
33 EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
34 EVT_CHAR_HOOK(wxDialog::OnCharHook)
35 EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
36 EVT_CLOSE(wxDialog::OnCloseWindow)
37 END_EVENT_TABLE()
38
39
40 wxDialog::wxDialog()
41 {
42 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
43 }
44
45 bool wxDialog::Create(wxWindow *parent, wxWindowID id,
46 const wxString& title,
47 const wxPoint& pos,
48 const wxSize& size,
49 long style,
50 const wxString& name)
51 {
52 m_windowStyle = style;
53
54 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
55 SetName(name);
56
57 if (!parent)
58 wxTopLevelWindows.Append(this);
59
60 if (parent) parent->AddChild(this);
61
62 if ( id == -1 )
63 m_windowId = (int)NewControlId();
64 else
65 m_windowId = id;
66
67 // TODO: create dialog
68
69 return FALSE;
70 }
71
72 void wxDialog::SetModal(bool flag)
73 {
74 if ( flag )
75 m_windowStyle |= wxDIALOG_MODAL ;
76 else
77 if ( m_windowStyle & wxDIALOG_MODAL )
78 m_windowStyle -= wxDIALOG_MODAL ;
79
80 wxModelessWindows.DeleteObject(this);
81 if (!flag)
82 wxModelessWindows.Append(this);
83 }
84
85 wxDialog::~wxDialog()
86 {
87 // TODO
88 wxTopLevelWindows.DeleteObject(this);
89
90 if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL )
91 wxModelessWindows.DeleteObject(this);
92
93 // If this is the last top-level window, exit.
94 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
95 {
96 wxTheApp->SetTopWindow(NULL);
97
98 if (wxTheApp->GetExitOnFrameDelete())
99 {
100 // TODO: exit
101 }
102 }
103 }
104
105 // By default, pressing escape cancels the dialog
106 void wxDialog::OnCharHook(wxKeyEvent& event)
107 {
108 if (GetHWND())
109 {
110 if (event.m_keyCode == WXK_ESCAPE)
111 {
112 // Behaviour changed in 2.0: we'll send a Cancel message
113 // to the dialog instead of Close.
114 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
115 cancelEvent.SetEventObject( this );
116 GetEventHandler()->ProcessEvent(cancelEvent);
117
118 return;
119 }
120 }
121 // We didn't process this event.
122 event.Skip();
123 }
124
125 void wxDialog::Iconize(bool WXUNUSED(iconize))
126 {
127 // TODO
128 }
129
130 bool wxDialog::IsIconized() const
131 {
132 // TODO
133 return FALSE;
134 }
135
136 void wxDialog::SetClientSize(int width, int height)
137 {
138 // TODO
139 }
140
141 void wxDialog::GetPosition(int *x, int *y) const
142 {
143 // TODO
144 }
145
146 bool wxDialog::Show(bool show)
147 {
148 // TODO
149 return FALSE;
150 }
151
152 void wxDialog::SetTitle(const wxString& title)
153 {
154 // TODO
155 }
156
157 wxString wxDialog::GetTitle() const
158 {
159 // TODO
160 return wxString("");
161 }
162
163 void wxDialog::Centre(int direction)
164 {
165 int x_offset,y_offset ;
166 int display_width, display_height;
167 int width, height, x, y;
168 wxFrame *frame ;
169 if (direction & wxCENTER_FRAME)
170 {
171 frame = (wxFrame*)GetParent() ;
172 if (frame)
173 {
174 frame->GetPosition(&x_offset,&y_offset) ;
175 frame->GetSize(&display_width,&display_height) ;
176 }
177 }
178 else
179 frame = NULL ;
180
181 if (frame==NULL)
182 {
183 wxDisplaySize(&display_width, &display_height);
184 x_offset = 0 ;
185 y_offset = 0 ;
186 }
187
188 GetSize(&width, &height);
189 GetPosition(&x, &y);
190
191 if (direction & wxHORIZONTAL)
192 x = (int)((display_width - width)/2);
193 if (direction & wxVERTICAL)
194 y = (int)((display_height - height)/2);
195
196 SetSize(x+x_offset, y+y_offset, width, height);
197 }
198
199 // Replacement for Show(TRUE) for modal dialogs - returns return code
200 int wxDialog::ShowModal()
201 {
202 m_windowStyle |= wxDIALOG_MODAL;
203 // TODO: modal showing
204 Show(TRUE);
205 return GetReturnCode();
206 }
207
208 void wxDialog::EndModal(int retCode)
209 {
210 SetReturnCode(retCode);
211 // TODO modal un-showing
212 Show(FALSE);
213 }
214
215 // Standard buttons
216 void wxDialog::OnOK(wxCommandEvent& event)
217 {
218 if ( Validate() && TransferDataFromWindow() )
219 {
220 if ( IsModal() )
221 EndModal(wxID_OK);
222 else
223 {
224 SetReturnCode(wxID_OK);
225 this->Show(FALSE);
226 }
227 }
228 }
229
230 void wxDialog::OnApply(wxCommandEvent& event)
231 {
232 if (Validate())
233 TransferDataFromWindow();
234 // TODO probably need to disable the Apply button until things change again
235 }
236
237 void wxDialog::OnCancel(wxCommandEvent& event)
238 {
239 if ( IsModal() )
240 EndModal(wxID_CANCEL);
241 else
242 {
243 SetReturnCode(wxID_CANCEL);
244 this->Show(FALSE);
245 }
246 }
247
248 void wxDialog::OnCloseWindow(wxCloseEvent& event)
249 {
250 // We'll send a Cancel message by default,
251 // which may close the dialog.
252 // Check for looping if the Cancel event handler calls Close().
253
254 // Note that if a cancel button and handler aren't present in the dialog,
255 // nothing will happen when you close the dialog via the window manager, or
256 // via Close().
257 // We wouldn't want to destroy the dialog by default, since the dialog may have been
258 // created on the stack.
259 // However, this does mean that calling dialog->Close() won't delete the dialog
260 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
261 // sure to destroy the dialog.
262 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
263
264 static wxList closing;
265
266 if ( closing.Member(this) )
267 return;
268
269 closing.Append(this);
270
271 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
272 cancelEvent.SetEventObject( this );
273 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
274
275 closing.DeleteObject(this);
276 }
277
278 // Destroy the window (delayed, if a managed window)
279 bool wxDialog::Destroy()
280 {
281 if (!wxPendingDelete.Member(this))
282 wxPendingDelete.Append(this);
283 return TRUE;
284 }
285
286 void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
287 {
288 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
289 Refresh();
290 }
291