]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/dialog.cpp
9b72fb0f6952560a2ac85697b6c37560d8025e99
[wxWidgets.git] / src / stubs / 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 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
30
31 BEGIN_EVENT_TABLE(wxDialog, wxPanel)
32 EVT_BUTTON(wxID_OK, wxDialog::OnOK)
33 EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
34 EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
35 EVT_CHAR_HOOK(wxDialog::OnCharHook)
36 EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
37 EVT_CLOSE(wxDialog::OnCloseWindow)
38 END_EVENT_TABLE()
39
40 #endif
41
42 wxDialog::wxDialog()
43 {
44 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
45 }
46
47 bool wxDialog::Create(wxWindow *parent, wxWindowID id,
48 const wxString& title,
49 const wxPoint& pos,
50 const wxSize& size,
51 long style,
52 const wxString& name)
53 {
54 m_windowStyle = style;
55
56 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
57 SetName(name);
58
59 if (!parent)
60 wxTopLevelWindows.Append(this);
61
62 if (parent) parent->AddChild(this);
63
64 if ( id == -1 )
65 m_windowId = (int)NewControlId();
66 else
67 m_windowId = id;
68
69 // TODO: create dialog
70
71 return FALSE;
72 }
73
74 void wxDialog::SetModal(bool flag)
75 {
76 if ( flag )
77 m_windowStyle |= wxDIALOG_MODAL ;
78 else
79 if ( m_windowStyle & wxDIALOG_MODAL )
80 m_windowStyle -= wxDIALOG_MODAL ;
81
82 wxModelessWindows.DeleteObject(this);
83 if (!flag)
84 wxModelessWindows.Append(this);
85 }
86
87 wxDialog::~wxDialog()
88 {
89 // TODO
90 wxTopLevelWindows.DeleteObject(this);
91
92 if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL )
93 wxModelessWindows.DeleteObject(this);
94
95 // If this is the last top-level window, exit.
96 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
97 {
98 wxTheApp->SetTopWindow(NULL);
99
100 if (wxTheApp->GetExitOnFrameDelete())
101 {
102 // TODO: exit
103 }
104 }
105 }
106
107 // By default, pressing escape cancels the dialog
108 void wxDialog::OnCharHook(wxKeyEvent& event)
109 {
110 if (GetHWND())
111 {
112 if (event.m_keyCode == WXK_ESCAPE)
113 {
114 // Behaviour changed in 2.0: we'll send a Cancel message
115 // to the dialog instead of Close.
116 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
117 cancelEvent.SetEventObject( this );
118 GetEventHandler()->ProcessEvent(cancelEvent);
119
120 return;
121 }
122 }
123 // We didn't process this event.
124 event.Skip();
125 }
126
127 void wxDialog::Iconize(bool WXUNUSED(iconize))
128 {
129 // TODO
130 }
131
132 bool wxDialog::IsIconized() const
133 {
134 // TODO
135 return FALSE;
136 }
137
138 void wxDialog::SetClientSize(int width, int height)
139 {
140 // TODO
141 }
142
143 void wxDialog::GetPosition(int *x, int *y) const
144 {
145 // TODO
146 }
147
148 bool wxDialog::Show(bool show)
149 {
150 // TODO
151 return FALSE;
152 }
153
154 void wxDialog::SetTitle(const wxString& title)
155 {
156 // TODO
157 }
158
159 wxString wxDialog::GetTitle() const
160 {
161 // TODO
162 return wxString("");
163 }
164
165 void wxDialog::Centre(int direction)
166 {
167 int x_offset,y_offset ;
168 int display_width, display_height;
169 int width, height, x, y;
170 wxFrame *frame ;
171 if (direction & wxCENTER_FRAME)
172 {
173 frame = (wxFrame*)GetParent() ;
174 if (frame)
175 {
176 frame->GetPosition(&x_offset,&y_offset) ;
177 frame->GetSize(&display_width,&display_height) ;
178 }
179 }
180 else
181 frame = NULL ;
182
183 if (frame==NULL)
184 {
185 wxDisplaySize(&display_width, &display_height);
186 x_offset = 0 ;
187 y_offset = 0 ;
188 }
189
190 GetSize(&width, &height);
191 GetPosition(&x, &y);
192
193 if (direction & wxHORIZONTAL)
194 x = (int)((display_width - width)/2);
195 if (direction & wxVERTICAL)
196 y = (int)((display_height - height)/2);
197
198 SetSize(x+x_offset, y+y_offset, width, height);
199 }
200
201 // Replacement for Show(TRUE) for modal dialogs - returns return code
202 int wxDialog::ShowModal()
203 {
204 m_windowStyle |= wxDIALOG_MODAL;
205 // TODO: modal showing
206 Show(TRUE);
207 return GetReturnCode();
208 }
209
210 void wxDialog::EndModal(int retCode)
211 {
212 SetReturnCode(retCode);
213 // TODO modal un-showing
214 Show(FALSE);
215 }
216
217 // Standard buttons
218 void wxDialog::OnOK(wxCommandEvent& event)
219 {
220 if ( Validate() && TransferDataFromWindow() )
221 {
222 if ( IsModal() )
223 EndModal(wxID_OK);
224 else
225 {
226 SetReturnCode(wxID_OK);
227 this->Show(FALSE);
228 }
229 }
230 }
231
232 void wxDialog::OnApply(wxCommandEvent& event)
233 {
234 if (Validate())
235 TransferDataFromWindow();
236 // TODO probably need to disable the Apply button until things change again
237 }
238
239 void wxDialog::OnCancel(wxCommandEvent& event)
240 {
241 if ( IsModal() )
242 EndModal(wxID_CANCEL);
243 else
244 {
245 SetReturnCode(wxID_CANCEL);
246 this->Show(FALSE);
247 }
248 }
249
250 bool wxDialog::OnClose()
251 {
252 // Behaviour changed in 2.0: we'll send a Cancel message by default,
253 // which may close the dialog.
254 // Check for looping if the Cancel event handler calls Close()
255
256 static wxList closing;
257
258 if ( closing.Member(this) )
259 return FALSE;
260
261 closing.Append(this);
262
263 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
264 cancelEvent.SetEventObject( this );
265 GetEventHandler()->ProcessEvent(cancelEvent);
266
267 closing.DeleteObject(this);
268
269 return FALSE;
270 }
271
272 void wxDialog::OnCloseWindow(wxCloseEvent& event)
273 {
274 // Compatibility
275 if ( GetEventHandler()->OnClose() || event.GetForce())
276 {
277 this->Destroy();
278 }
279 }
280
281 // Destroy the window (delayed, if a managed window)
282 bool wxDialog::Destroy()
283 {
284 if (!wxPendingDelete.Member(this))
285 wxPendingDelete.Append(this);
286 return TRUE;
287 }
288
289 void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
290 {
291 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
292 Refresh();
293 }
294