]> git.saurik.com Git - wxWidgets.git/blame - src/stubs/dialog.cpp
Next attempt at dynlib.cpp
[wxWidgets.git] / src / stubs / dialog.cpp
CommitLineData
93cf77c0
JS
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
24wxList wxModalDialogs;
25wxList wxModelessWindows; // Frames and modeless dialogs
26extern wxList wxPendingDelete;
27
28#if !USE_SHARED_LIBRARY
29IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
30
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)
38END_EVENT_TABLE()
39
40#endif
41
42wxDialog::wxDialog()
43{
44 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
45}
46
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)
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
74void 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
87wxDialog::~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
108void wxDialog::OnCharHook(wxKeyEvent& event)
109{
34138703 110 if (event.m_keyCode == WXK_ESCAPE)
93cf77c0 111 {
93cf77c0
JS
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);
117
118 return;
93cf77c0
JS
119 }
120 // We didn't process this event.
121 event.Skip();
122}
123
124void wxDialog::Iconize(bool WXUNUSED(iconize))
125{
126 // TODO
127}
128
129bool wxDialog::IsIconized() const
130{
131 // TODO
132 return FALSE;
133}
134
135void wxDialog::SetClientSize(int width, int height)
136{
137 // TODO
138}
139
140void wxDialog::GetPosition(int *x, int *y) const
141{
142 // TODO
143}
144
145bool wxDialog::Show(bool show)
146{
147 // TODO
148 return FALSE;
149}
150
151void wxDialog::SetTitle(const wxString& title)
152{
153 // TODO
154}
155
156wxString wxDialog::GetTitle() const
157{
158 // TODO
159 return wxString("");
160}
161
162void wxDialog::Centre(int direction)
163{
164 int x_offset,y_offset ;
165 int display_width, display_height;
166 int width, height, x, y;
167 wxFrame *frame ;
168 if (direction & wxCENTER_FRAME)
169 {
170 frame = (wxFrame*)GetParent() ;
171 if (frame)
172 {
173 frame->GetPosition(&x_offset,&y_offset) ;
174 frame->GetSize(&display_width,&display_height) ;
175 }
176 }
177 else
178 frame = NULL ;
179
180 if (frame==NULL)
181 {
182 wxDisplaySize(&display_width, &display_height);
183 x_offset = 0 ;
184 y_offset = 0 ;
185 }
186
187 GetSize(&width, &height);
188 GetPosition(&x, &y);
189
190 if (direction & wxHORIZONTAL)
191 x = (int)((display_width - width)/2);
192 if (direction & wxVERTICAL)
193 y = (int)((display_height - height)/2);
194
195 SetSize(x+x_offset, y+y_offset, width, height);
196}
197
198// Replacement for Show(TRUE) for modal dialogs - returns return code
199int wxDialog::ShowModal()
200{
201 m_windowStyle |= wxDIALOG_MODAL;
202 // TODO: modal showing
203 Show(TRUE);
204 return GetReturnCode();
205}
206
207void wxDialog::EndModal(int retCode)
208{
209 SetReturnCode(retCode);
210 // TODO modal un-showing
211 Show(FALSE);
212}
213
214// Standard buttons
215void wxDialog::OnOK(wxCommandEvent& event)
216{
217 if ( Validate() && TransferDataFromWindow() )
218 {
219 if ( IsModal() )
220 EndModal(wxID_OK);
221 else
222 {
223 SetReturnCode(wxID_OK);
224 this->Show(FALSE);
225 }
226 }
227}
228
229void wxDialog::OnApply(wxCommandEvent& event)
230{
231 if (Validate())
232 TransferDataFromWindow();
233 // TODO probably need to disable the Apply button until things change again
234}
235
236void wxDialog::OnCancel(wxCommandEvent& event)
237{
238 if ( IsModal() )
239 EndModal(wxID_CANCEL);
240 else
241 {
242 SetReturnCode(wxID_CANCEL);
243 this->Show(FALSE);
244 }
245}
246
247bool wxDialog::OnClose()
248{
249 // Behaviour changed in 2.0: we'll send a Cancel message by default,
250 // which may close the dialog.
251 // Check for looping if the Cancel event handler calls Close()
252
253 static wxList closing;
254
255 if ( closing.Member(this) )
256 return FALSE;
257
258 closing.Append(this);
259
260 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
261 cancelEvent.SetEventObject( this );
262 GetEventHandler()->ProcessEvent(cancelEvent);
263
264 closing.DeleteObject(this);
265
266 return FALSE;
267}
268
269void wxDialog::OnCloseWindow(wxCloseEvent& event)
270{
271 // Compatibility
272 if ( GetEventHandler()->OnClose() || event.GetForce())
273 {
274 this->Destroy();
275 }
276}
277
278// Destroy the window (delayed, if a managed window)
279bool wxDialog::Destroy()
280{
281 if (!wxPendingDelete.Member(this))
282 wxPendingDelete.Append(this);
283 return TRUE;
284}
285
286void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
287{
288 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
289 Refresh();
290}
291