]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dialog.cpp
More samples makefiles
[wxWidgets.git] / src / os2 / 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 (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);
117
118 return;
119 }
120 // We didn't process this event.
121 event.Skip();
122 }
123
124 void wxDialog::Iconize(bool WXUNUSED(iconize))
125 {
126 // TODO
127 }
128
129 bool wxDialog::IsIconized() const
130 {
131 // TODO
132 return FALSE;
133 }
134
135 void wxDialog::GetPosition(int *x, int *y) const
136 {
137 // TODO
138 }
139
140 bool wxDialog::Show(bool show)
141 {
142 // TODO
143 return FALSE;
144 }
145
146 void wxDialog::SetTitle(const wxString& title)
147 {
148 // TODO
149 }
150
151 wxString wxDialog::GetTitle() const
152 {
153 // TODO
154 return wxString("");
155 }
156
157 void wxDialog::Centre(int direction)
158 {
159 int x_offset,y_offset ;
160 int display_width, display_height;
161 int width, height, x, y;
162 wxWindow *parent = GetParent();
163 if ((direction & wxCENTER_FRAME) && parent)
164 {
165 parent->GetPosition(&x_offset,&y_offset) ;
166 parent->GetSize(&display_width,&display_height) ;
167 }
168 else
169 {
170 wxDisplaySize(&display_width, &display_height);
171 x_offset = 0 ;
172 y_offset = 0 ;
173 }
174
175 GetSize(&width, &height);
176 GetPosition(&x, &y);
177
178 if (direction & wxHORIZONTAL)
179 x = (int)((display_width - width)/2);
180 if (direction & wxVERTICAL)
181 y = (int)((display_height - height)/2);
182
183 SetSize(x+x_offset, y+y_offset, width, height);
184 }
185
186 // Replacement for Show(TRUE) for modal dialogs - returns return code
187 int wxDialog::ShowModal()
188 {
189 m_windowStyle |= wxDIALOG_MODAL;
190 // TODO: modal showing
191 Show(TRUE);
192 return GetReturnCode();
193 }
194
195 void wxDialog::EndModal(int retCode)
196 {
197 SetReturnCode(retCode);
198 // TODO modal un-showing
199 Show(FALSE);
200 }
201
202 // Standard buttons
203 void wxDialog::OnOK(wxCommandEvent& event)
204 {
205 if ( Validate() && TransferDataFromWindow() )
206 {
207 if ( IsModal() )
208 EndModal(wxID_OK);
209 else
210 {
211 SetReturnCode(wxID_OK);
212 this->Show(FALSE);
213 }
214 }
215 }
216
217 void wxDialog::OnApply(wxCommandEvent& event)
218 {
219 if (Validate())
220 TransferDataFromWindow();
221 // TODO probably need to disable the Apply button until things change again
222 }
223
224 void wxDialog::OnCancel(wxCommandEvent& event)
225 {
226 if ( IsModal() )
227 EndModal(wxID_CANCEL);
228 else
229 {
230 SetReturnCode(wxID_CANCEL);
231 this->Show(FALSE);
232 }
233 }
234
235 void wxDialog::OnCloseWindow(wxCloseEvent& event)
236 {
237 // We'll send a Cancel message by default,
238 // which may close the dialog.
239 // Check for looping if the Cancel event handler calls Close().
240
241 // Note that if a cancel button and handler aren't present in the dialog,
242 // nothing will happen when you close the dialog via the window manager, or
243 // via Close().
244 // We wouldn't want to destroy the dialog by default, since the dialog may have been
245 // created on the stack.
246 // However, this does mean that calling dialog->Close() won't delete the dialog
247 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
248 // sure to destroy the dialog.
249 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
250
251 static wxList closing;
252
253 if ( closing.Member(this) )
254 return;
255
256 closing.Append(this);
257
258 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
259 cancelEvent.SetEventObject( this );
260 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
261
262 closing.DeleteObject(this);
263 }
264
265 // Destroy the window (delayed, if a managed window)
266 bool wxDialog::Destroy()
267 {
268 if (!wxPendingDelete.Member(this))
269 wxPendingDelete.Append(this);
270 return TRUE;
271 }
272
273 void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
274 {
275 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
276 Refresh();
277 }
278
279 void wxDialog::Fit()
280 {
281 }