]> git.saurik.com Git - wxWidgets.git/blame - src/qt/dialog.cpp
some clean up of the code
[wxWidgets.git] / src / qt / dialog.cpp
CommitLineData
7c78e7c7
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialog.cpp
01b2eeec
KB
3// Purpose: wxDialog class
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
7c78e7c7
RR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dialog.h"
14#endif
15
16#include "wx/dialog.h"
01b2eeec 17#include "wx/utils.h"
7c78e7c7
RR
18#include "wx/frame.h"
19#include "wx/app.h"
01b2eeec 20#include "wx/settings.h"
7c78e7c7 21
01b2eeec
KB
22// Lists to keep track of windows, so we can disable/enable them
23// for modal dialogs
24wxList wxModalDialogs;
25wxList wxModelessWindows; // Frames and modeless dialogs
7c78e7c7
RR
26extern wxList wxPendingDelete;
27
01b2eeec
KB
28#if !USE_SHARED_LIBRARY
29IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
7c78e7c7 30
01b2eeec
KB
31BEGIN_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)
7c78e7c7
RR
38END_EVENT_TABLE()
39
01b2eeec 40#endif
7c78e7c7 41
01b2eeec 42wxDialog::wxDialog()
7c78e7c7 43{
01b2eeec
KB
44 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
45}
7c78e7c7 46
01b2eeec
KB
47bool 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)
7c78e7c7 53{
01b2eeec 54 m_windowStyle = style;
7c78e7c7 55
01b2eeec
KB
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
74void wxDialog::SetModal(bool flag)
7c78e7c7 75{
01b2eeec
KB
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}
7c78e7c7 86
01b2eeec 87wxDialog::~wxDialog()
7c78e7c7 88{
01b2eeec
KB
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}
7c78e7c7 106
01b2eeec
KB
107// By default, pressing escape cancels the dialog
108void wxDialog::OnCharHook(wxKeyEvent& event)
7c78e7c7 109{
01b2eeec
KB
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);
7c78e7c7 119
01b2eeec
KB
120 return;
121 }
122 }
123 // We didn't process this event.
124 event.Skip();
125}
126
127void wxDialog::Iconize(bool WXUNUSED(iconize))
7c78e7c7 128{
01b2eeec
KB
129 // TODO
130}
7c78e7c7 131
01b2eeec 132bool wxDialog::IsIconized() const
7c78e7c7 133{
01b2eeec
KB
134 // TODO
135 return FALSE;
136}
7c78e7c7 137
01b2eeec 138void wxDialog::SetClientSize(int width, int height)
7c78e7c7 139{
01b2eeec
KB
140 // TODO
141}
142
143void wxDialog::GetPosition(int *x, int *y) const
144{
145 // TODO
146}
7c78e7c7 147
01b2eeec 148bool wxDialog::Show(bool show)
7c78e7c7 149{
01b2eeec
KB
150 // TODO
151 return FALSE;
152}
153
154void wxDialog::SetTitle(const wxString& title)
155{
156 // TODO
157}
158
159wxString wxDialog::GetTitle() const
160{
161 // TODO
162 return wxString("");
163}
164
165void 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)
7c78e7c7 172 {
01b2eeec
KB
173 frame = (wxFrame*)GetParent() ;
174 if (frame)
7c78e7c7 175 {
01b2eeec
KB
176 frame->GetPosition(&x_offset,&y_offset) ;
177 frame->GetSize(&display_width,&display_height) ;
7c78e7c7 178 }
01b2eeec
KB
179 }
180 else
181 frame = NULL ;
7c78e7c7 182
01b2eeec
KB
183 if (frame==NULL)
184 {
185 wxDisplaySize(&display_width, &display_height);
186 x_offset = 0 ;
187 y_offset = 0 ;
188 }
7c78e7c7 189
01b2eeec
KB
190 GetSize(&width, &height);
191 GetPosition(&x, &y);
7c78e7c7 192
01b2eeec
KB
193 if (direction & wxHORIZONTAL)
194 x = (int)((display_width - width)/2);
195 if (direction & wxVERTICAL)
196 y = (int)((display_height - height)/2);
7c78e7c7 197
01b2eeec 198 SetSize(x+x_offset, y+y_offset, width, height);
7c78e7c7
RR
199}
200
01b2eeec
KB
201// Replacement for Show(TRUE) for modal dialogs - returns return code
202int wxDialog::ShowModal()
7c78e7c7 203{
01b2eeec
KB
204 m_windowStyle |= wxDIALOG_MODAL;
205 // TODO: modal showing
206 Show(TRUE);
207 return GetReturnCode();
208}
7c78e7c7 209
01b2eeec
KB
210void wxDialog::EndModal(int retCode)
211{
212 SetReturnCode(retCode);
213 // TODO modal un-showing
214 Show(FALSE);
7c78e7c7
RR
215}
216
01b2eeec
KB
217// Standard buttons
218void wxDialog::OnOK(wxCommandEvent& event)
7c78e7c7 219{
01b2eeec
KB
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}
7c78e7c7 231
01b2eeec 232void wxDialog::OnApply(wxCommandEvent& event)
7c78e7c7 233{
01b2eeec
KB
234 if (Validate())
235 TransferDataFromWindow();
236 // TODO probably need to disable the Apply button until things change again
237}
7c78e7c7 238
01b2eeec
KB
239void 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}
7c78e7c7 249
01b2eeec 250bool wxDialog::OnClose()
7c78e7c7 251{
01b2eeec
KB
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()
7c78e7c7 255
01b2eeec
KB
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
272void wxDialog::OnCloseWindow(wxCloseEvent& event)
273{
274 // Compatibility
275 if ( GetEventHandler()->OnClose() || event.GetForce())
276 {
277 this->Destroy();
278 }
279}
7c78e7c7 280
01b2eeec
KB
281// Destroy the window (delayed, if a managed window)
282bool wxDialog::Destroy()
7c78e7c7 283{
01b2eeec
KB
284 if (!wxPendingDelete.Member(this))
285 wxPendingDelete.Append(this);
286 return TRUE;
287}
7c78e7c7 288
01b2eeec 289void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
7c78e7c7 290{
01b2eeec
KB
291 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
292 Refresh();
293}
7c78e7c7 294