]> git.saurik.com Git - wxWidgets.git/blame - src/qt/dialog.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[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
e3065973 250void wxDialog::OnCloseWindow(wxCloseEvent& event)
7c78e7c7 251{
e3065973 252 // We'll send a Cancel message by default,
01b2eeec 253 // which may close the dialog.
e3065973
JS
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.
7c78e7c7 265
01b2eeec 266 static wxList closing;
e3065973 267
01b2eeec 268 if ( closing.Member(this) )
e3065973
JS
269 return;
270
01b2eeec 271 closing.Append(this);
e3065973
JS
272
273 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
274 cancelEvent.SetEventObject( this );
275 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
01b2eeec
KB
276
277 closing.DeleteObject(this);
01b2eeec 278}
7c78e7c7 279
01b2eeec
KB
280// Destroy the window (delayed, if a managed window)
281bool wxDialog::Destroy()
7c78e7c7 282{
01b2eeec
KB
283 if (!wxPendingDelete.Member(this))
284 wxPendingDelete.Append(this);
285 return TRUE;
286}
7c78e7c7 287
01b2eeec 288void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
7c78e7c7 289{
01b2eeec
KB
290 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
291 Refresh();
292}
7c78e7c7 293