]> git.saurik.com Git - wxWidgets.git/blob - src/qt/dialog.cpp
1. wxStaticLine implemented (generic (ugly) and MSW versions)
[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 #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 void wxDialog::OnCloseWindow(wxCloseEvent& event)
251 {
252 // 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 // Note that if a cancel button and handler aren't present in the dialog,
257 // nothing will happen when you close the dialog via the window manager, or
258 // via Close().
259 // We wouldn't want to destroy the dialog by default, since the dialog may have been
260 // created on the stack.
261 // However, this does mean that calling dialog->Close() won't delete the dialog
262 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
263 // sure to destroy the dialog.
264 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
265
266 static wxList closing;
267
268 if ( closing.Member(this) )
269 return;
270
271 closing.Append(this);
272
273 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
274 cancelEvent.SetEventObject( this );
275 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
276
277 closing.DeleteObject(this);
278 }
279
280 // Destroy the window (delayed, if a managed window)
281 bool wxDialog::Destroy()
282 {
283 if (!wxPendingDelete.Member(this))
284 wxPendingDelete.Append(this);
285 return TRUE;
286 }
287
288 void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
289 {
290 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
291 Refresh();
292 }
293