]> git.saurik.com Git - wxWidgets.git/blame - src/qt/dialog.cpp
attempts at making modal dialogs without parent work - failed
[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 28IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
7c78e7c7 29
01b2eeec
KB
30BEGIN_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)
7c78e7c7
RR
37END_EVENT_TABLE()
38
7c78e7c7 39
01b2eeec 40wxDialog::wxDialog()
7c78e7c7 41{
01b2eeec
KB
42 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
43}
7c78e7c7 44
01b2eeec
KB
45bool 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)
7c78e7c7 51{
01b2eeec 52 m_windowStyle = style;
7c78e7c7 53
01b2eeec
KB
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
72void wxDialog::SetModal(bool flag)
7c78e7c7 73{
01b2eeec
KB
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}
7c78e7c7 84
01b2eeec 85wxDialog::~wxDialog()
7c78e7c7 86{
01b2eeec
KB
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}
7c78e7c7 104
01b2eeec
KB
105// By default, pressing escape cancels the dialog
106void wxDialog::OnCharHook(wxKeyEvent& event)
7c78e7c7 107{
01b2eeec
KB
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);
7c78e7c7 117
01b2eeec
KB
118 return;
119 }
120 }
121 // We didn't process this event.
122 event.Skip();
123}
124
125void wxDialog::Iconize(bool WXUNUSED(iconize))
7c78e7c7 126{
01b2eeec
KB
127 // TODO
128}
7c78e7c7 129
01b2eeec 130bool wxDialog::IsIconized() const
7c78e7c7 131{
01b2eeec
KB
132 // TODO
133 return FALSE;
134}
7c78e7c7 135
01b2eeec 136void wxDialog::SetClientSize(int width, int height)
7c78e7c7 137{
01b2eeec
KB
138 // TODO
139}
140
141void wxDialog::GetPosition(int *x, int *y) const
142{
143 // TODO
144}
7c78e7c7 145
01b2eeec 146bool wxDialog::Show(bool show)
7c78e7c7 147{
01b2eeec
KB
148 // TODO
149 return FALSE;
150}
151
152void wxDialog::SetTitle(const wxString& title)
153{
154 // TODO
155}
156
157wxString wxDialog::GetTitle() const
158{
159 // TODO
160 return wxString("");
161}
162
163void 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)
7c78e7c7 170 {
01b2eeec
KB
171 frame = (wxFrame*)GetParent() ;
172 if (frame)
7c78e7c7 173 {
01b2eeec
KB
174 frame->GetPosition(&x_offset,&y_offset) ;
175 frame->GetSize(&display_width,&display_height) ;
7c78e7c7 176 }
01b2eeec
KB
177 }
178 else
179 frame = NULL ;
7c78e7c7 180
01b2eeec
KB
181 if (frame==NULL)
182 {
183 wxDisplaySize(&display_width, &display_height);
184 x_offset = 0 ;
185 y_offset = 0 ;
186 }
7c78e7c7 187
01b2eeec
KB
188 GetSize(&width, &height);
189 GetPosition(&x, &y);
7c78e7c7 190
01b2eeec
KB
191 if (direction & wxHORIZONTAL)
192 x = (int)((display_width - width)/2);
193 if (direction & wxVERTICAL)
194 y = (int)((display_height - height)/2);
7c78e7c7 195
01b2eeec 196 SetSize(x+x_offset, y+y_offset, width, height);
7c78e7c7
RR
197}
198
01b2eeec
KB
199// Replacement for Show(TRUE) for modal dialogs - returns return code
200int wxDialog::ShowModal()
7c78e7c7 201{
01b2eeec
KB
202 m_windowStyle |= wxDIALOG_MODAL;
203 // TODO: modal showing
204 Show(TRUE);
205 return GetReturnCode();
206}
7c78e7c7 207
01b2eeec
KB
208void wxDialog::EndModal(int retCode)
209{
210 SetReturnCode(retCode);
211 // TODO modal un-showing
212 Show(FALSE);
7c78e7c7
RR
213}
214
01b2eeec
KB
215// Standard buttons
216void wxDialog::OnOK(wxCommandEvent& event)
7c78e7c7 217{
01b2eeec
KB
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}
7c78e7c7 229
01b2eeec 230void wxDialog::OnApply(wxCommandEvent& event)
7c78e7c7 231{
01b2eeec
KB
232 if (Validate())
233 TransferDataFromWindow();
234 // TODO probably need to disable the Apply button until things change again
235}
7c78e7c7 236
01b2eeec
KB
237void 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}
7c78e7c7 247
e3065973 248void wxDialog::OnCloseWindow(wxCloseEvent& event)
7c78e7c7 249{
e3065973 250 // We'll send a Cancel message by default,
01b2eeec 251 // which may close the dialog.
e3065973
JS
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.
7c78e7c7 263
01b2eeec 264 static wxList closing;
e3065973 265
01b2eeec 266 if ( closing.Member(this) )
e3065973
JS
267 return;
268
01b2eeec 269 closing.Append(this);
e3065973
JS
270
271 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
272 cancelEvent.SetEventObject( this );
273 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
01b2eeec
KB
274
275 closing.DeleteObject(this);
01b2eeec 276}
7c78e7c7 277
01b2eeec
KB
278// Destroy the window (delayed, if a managed window)
279bool wxDialog::Destroy()
7c78e7c7 280{
01b2eeec
KB
281 if (!wxPendingDelete.Member(this))
282 wxPendingDelete.Append(this);
283 return TRUE;
284}
7c78e7c7 285
01b2eeec 286void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
7c78e7c7 287{
01b2eeec
KB
288 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
289 Refresh();
290}
7c78e7c7 291