]>
Commit | Line | Data |
---|---|---|
7c78e7c7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
01b2eeec KB |
2 | // Name: windows.cpp |
3 | // Purpose: wxWindow | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
7c78e7c7 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
7c78e7c7 RR |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "window.h" | |
14 | #endif | |
15 | ||
01b2eeec KB |
16 | #include "wx/setup.h" |
17 | #include "wx/menu.h" | |
7c78e7c7 | 18 | #include "wx/dc.h" |
01b2eeec KB |
19 | #include "wx/dcclient.h" |
20 | #include "wx/utils.h" | |
7c78e7c7 | 21 | #include "wx/app.h" |
01b2eeec | 22 | #include "wx/panel.h" |
7c78e7c7 | 23 | #include "wx/layout.h" |
7c78e7c7 | 24 | #include "wx/dialog.h" |
01b2eeec KB |
25 | #include "wx/listbox.h" |
26 | #include "wx/button.h" | |
27 | #include "wx/settings.h" | |
7c78e7c7 | 28 | #include "wx/msgdlg.h" |
01b2eeec KB |
29 | |
30 | #include "wx/menuitem.h" | |
31 | #include "wx/log.h" | |
32 | ||
47d67540 | 33 | #if wxUSE_DRAG_AND_DROP |
7c78e7c7 | 34 | #include "wx/dnd.h" |
01b2eeec | 35 | #endif |
7c78e7c7 | 36 | |
01b2eeec | 37 | #include <string.h> |
7c78e7c7 RR |
38 | |
39 | extern wxList wxPendingDelete; | |
7c78e7c7 | 40 | |
01b2eeec KB |
41 | #if !USE_SHARED_LIBRARY |
42 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) | |
7c78e7c7 RR |
43 | |
44 | BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) | |
01b2eeec KB |
45 | EVT_CHAR(wxWindow::OnChar) |
46 | EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) | |
7c78e7c7 RR |
47 | EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) |
48 | EVT_INIT_DIALOG(wxWindow::OnInitDialog) | |
49 | EVT_IDLE(wxWindow::OnIdle) | |
50 | END_EVENT_TABLE() | |
51 | ||
01b2eeec KB |
52 | #endif |
53 | ||
54 | ||
55 | // Constructor | |
7c78e7c7 RR |
56 | wxWindow::wxWindow() |
57 | { | |
01b2eeec KB |
58 | // Generic |
59 | m_windowId = 0; | |
60 | m_windowStyle = 0; | |
61 | m_windowParent = NULL; | |
62 | m_windowEventHandler = this; | |
63 | m_windowName = ""; | |
64 | m_windowCursor = *wxSTANDARD_CURSOR; | |
65 | m_children = new wxList; | |
7c78e7c7 | 66 | m_constraints = NULL; |
01b2eeec | 67 | m_constraintsInvolvedIn = NULL; |
7c78e7c7 | 68 | m_windowSizer = NULL; |
01b2eeec KB |
69 | m_sizerParent = NULL; |
70 | m_autoLayout = FALSE; | |
71 | m_windowValidator = NULL; | |
72 | m_defaultItem = NULL; | |
73 | m_returnCode = 0; | |
74 | m_caretWidth = 0; m_caretHeight = 0; | |
75 | m_caretEnabled = FALSE; | |
76 | m_caretShown = FALSE; | |
77 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; | |
78 | m_foregroundColour = *wxBLACK; | |
79 | m_defaultForegroundColour = *wxBLACK ; | |
80 | m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
81 | ||
47d67540 | 82 | #if wxUSE_DRAG_AND_DROP |
01b2eeec KB |
83 | m_pDropTarget = NULL; |
84 | #endif | |
85 | } | |
7c78e7c7 | 86 | |
01b2eeec KB |
87 | // Destructor |
88 | wxWindow::~wxWindow() | |
7c78e7c7 | 89 | { |
01b2eeec KB |
90 | // Have to delete constraints/sizer FIRST otherwise |
91 | // sizers may try to look at deleted windows as they | |
92 | // delete themselves. | |
47d67540 | 93 | #if wxUSE_CONSTRAINTS |
01b2eeec KB |
94 | DeleteRelatedConstraints(); |
95 | if (m_constraints) | |
96 | { | |
97 | // This removes any dangling pointers to this window | |
98 | // in other windows' constraintsInvolvedIn lists. | |
99 | UnsetConstraints(m_constraints); | |
100 | delete m_constraints; | |
101 | m_constraints = NULL; | |
102 | } | |
103 | if (m_windowSizer) | |
104 | { | |
105 | delete m_windowSizer; | |
106 | m_windowSizer = NULL; | |
107 | } | |
108 | // If this is a child of a sizer, remove self from parent | |
109 | if (m_sizerParent) | |
110 | m_sizerParent->RemoveChild((wxWindow *)this); | |
111 | #endif | |
7c78e7c7 | 112 | |
01b2eeec KB |
113 | if (m_windowParent) |
114 | m_windowParent->RemoveChild(this); | |
7c78e7c7 | 115 | |
01b2eeec KB |
116 | DestroyChildren(); |
117 | ||
118 | // TODO: destroy the window | |
7c78e7c7 | 119 | |
01b2eeec KB |
120 | delete m_children; |
121 | m_children = NULL; | |
122 | ||
123 | // Just in case the window has been Closed, but | |
124 | // we're then deleting immediately: don't leave | |
125 | // dangling pointers. | |
126 | wxPendingDelete.DeleteObject(this); | |
127 | ||
128 | if ( m_windowValidator ) | |
129 | delete m_windowValidator; | |
130 | } | |
131 | ||
132 | // Destroy the window (delayed, if a managed window) | |
133 | bool wxWindow::Destroy() | |
7c78e7c7 | 134 | { |
01b2eeec KB |
135 | delete this; |
136 | return TRUE; | |
137 | } | |
138 | ||
139 | // Constructor | |
140 | bool wxWindow::Create(wxWindow *parent, wxWindowID id, | |
141 | const wxPoint& pos, | |
142 | const wxSize& size, | |
143 | long style, | |
144 | const wxString& name) | |
145 | { | |
146 | // Generic | |
147 | m_windowId = 0; | |
148 | m_windowStyle = 0; | |
149 | m_windowParent = NULL; | |
150 | m_windowEventHandler = this; | |
151 | m_windowName = ""; | |
152 | m_windowCursor = *wxSTANDARD_CURSOR; | |
153 | m_constraints = NULL; | |
154 | m_constraintsInvolvedIn = NULL; | |
155 | m_windowSizer = NULL; | |
156 | m_sizerParent = NULL; | |
157 | m_autoLayout = FALSE; | |
158 | m_windowValidator = NULL; | |
159 | ||
47d67540 | 160 | #if wxUSE_DRAG_AND_DROP |
01b2eeec KB |
161 | m_pDropTarget = NULL; |
162 | #endif | |
163 | ||
164 | m_caretWidth = 0; m_caretHeight = 0; | |
165 | m_caretEnabled = FALSE; | |
166 | m_caretShown = FALSE; | |
167 | m_minSizeX = -1; | |
168 | m_minSizeY = -1; | |
169 | m_maxSizeX = -1; | |
170 | m_maxSizeY = -1; | |
171 | m_defaultItem = NULL; | |
172 | m_windowParent = NULL; | |
173 | if (!parent) | |
174 | return FALSE; | |
175 | ||
176 | if (parent) parent->AddChild(this); | |
177 | ||
178 | m_returnCode = 0; | |
179 | ||
180 | SetName(name); | |
181 | ||
182 | if ( id == -1 ) | |
183 | m_windowId = (int)NewControlId(); | |
184 | else | |
185 | m_windowId = id; | |
186 | ||
187 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; | |
188 | m_foregroundColour = *wxBLACK; | |
189 | m_defaultForegroundColour = *wxBLACK ; | |
190 | m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; | |
191 | ||
192 | m_windowStyle = style; | |
7c78e7c7 | 193 | |
01b2eeec KB |
194 | if ( id == -1 ) |
195 | m_windowId = (int)NewControlId(); | |
196 | else | |
197 | m_windowId = id; | |
198 | ||
199 | // TODO: create the window | |
200 | ||
201 | return TRUE; | |
202 | } | |
203 | ||
204 | void wxWindow::SetFocus() | |
7c78e7c7 | 205 | { |
01b2eeec KB |
206 | // TODO |
207 | } | |
7c78e7c7 | 208 | |
01b2eeec | 209 | void wxWindow::Enable(bool enable) |
7c78e7c7 | 210 | { |
01b2eeec KB |
211 | // TODO |
212 | } | |
7c78e7c7 | 213 | |
01b2eeec | 214 | void wxWindow::CaptureMouse() |
7c78e7c7 | 215 | { |
01b2eeec KB |
216 | // TODO |
217 | } | |
7c78e7c7 | 218 | |
01b2eeec | 219 | void wxWindow::ReleaseMouse() |
7c78e7c7 | 220 | { |
01b2eeec KB |
221 | // TODO |
222 | } | |
7c78e7c7 | 223 | |
01b2eeec KB |
224 | // Push/pop event handler (i.e. allow a chain of event handlers |
225 | // be searched) | |
226 | void wxWindow::PushEventHandler(wxEvtHandler *handler) | |
7c78e7c7 | 227 | { |
01b2eeec KB |
228 | handler->SetNextHandler(GetEventHandler()); |
229 | SetEventHandler(handler); | |
230 | } | |
7c78e7c7 | 231 | |
01b2eeec KB |
232 | wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) |
233 | { | |
234 | if ( GetEventHandler() ) | |
235 | { | |
236 | wxEvtHandler *handlerA = GetEventHandler(); | |
237 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
238 | handlerA->SetNextHandler(NULL); | |
239 | SetEventHandler(handlerB); | |
240 | if ( deleteHandler ) | |
241 | { | |
242 | delete handlerA; | |
243 | return NULL; | |
244 | } | |
245 | else | |
246 | return handlerA; | |
247 | } | |
248 | else | |
249 | return NULL; | |
250 | } | |
251 | ||
47d67540 | 252 | #if wxUSE_DRAG_AND_DROP |
01b2eeec KB |
253 | |
254 | void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) | |
7c78e7c7 | 255 | { |
01b2eeec KB |
256 | if ( m_pDropTarget != 0 ) { |
257 | m_pDropTarget->Revoke(m_hWnd); | |
258 | delete m_pDropTarget; | |
259 | } | |
7c78e7c7 | 260 | |
01b2eeec KB |
261 | m_pDropTarget = pDropTarget; |
262 | if ( m_pDropTarget != 0 ) | |
263 | m_pDropTarget->Register(m_hWnd); | |
264 | } | |
265 | ||
266 | #endif | |
267 | ||
268 | // Old style file-manager drag&drop | |
269 | void wxWindow::DragAcceptFiles(bool accept) | |
7c78e7c7 | 270 | { |
01b2eeec KB |
271 | // TODO |
272 | } | |
7c78e7c7 | 273 | |
01b2eeec KB |
274 | // Get total size |
275 | void wxWindow::GetSize(int *x, int *y) const | |
7c78e7c7 | 276 | { |
01b2eeec KB |
277 | // TODO |
278 | } | |
7c78e7c7 | 279 | |
01b2eeec | 280 | void wxWindow::GetPosition(int *x, int *y) const |
7c78e7c7 | 281 | { |
01b2eeec KB |
282 | // TODO |
283 | } | |
7c78e7c7 | 284 | |
01b2eeec | 285 | void wxWindow::ScreenToClient(int *x, int *y) const |
7c78e7c7 | 286 | { |
01b2eeec KB |
287 | // TODO |
288 | } | |
7c78e7c7 | 289 | |
01b2eeec | 290 | void wxWindow::ClientToScreen(int *x, int *y) const |
7c78e7c7 | 291 | { |
01b2eeec KB |
292 | // TODO |
293 | } | |
7c78e7c7 | 294 | |
01b2eeec | 295 | void wxWindow::SetCursor(const wxCursor& cursor) |
7c78e7c7 | 296 | { |
01b2eeec KB |
297 | m_windowCursor = cursor; |
298 | if (m_windowCursor.Ok()) | |
7c78e7c7 | 299 | { |
01b2eeec | 300 | // TODO |
7c78e7c7 | 301 | } |
01b2eeec | 302 | } |
7c78e7c7 | 303 | |
7c78e7c7 | 304 | |
01b2eeec KB |
305 | // Get size *available for subwindows* i.e. excluding menu bar etc. |
306 | void wxWindow::GetClientSize(int *x, int *y) const | |
7c78e7c7 | 307 | { |
01b2eeec KB |
308 | // TODO |
309 | } | |
7c78e7c7 | 310 | |
01b2eeec | 311 | void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) |
7c78e7c7 | 312 | { |
01b2eeec KB |
313 | // TODO |
314 | } | |
7c78e7c7 | 315 | |
01b2eeec | 316 | void wxWindow::SetClientSize(int width, int height) |
7c78e7c7 | 317 | { |
01b2eeec | 318 | // TODO |
7c78e7c7 RR |
319 | } |
320 | ||
01b2eeec KB |
321 | // For implementation purposes - sometimes decorations make the client area |
322 | // smaller | |
323 | wxPoint wxWindow::GetClientAreaOrigin() const | |
7c78e7c7 | 324 | { |
01b2eeec KB |
325 | return wxPoint(0, 0); |
326 | } | |
7c78e7c7 | 327 | |
01b2eeec KB |
328 | // Makes an adjustment to the window position (for example, a frame that has |
329 | // a toolbar that it manages itself). | |
330 | void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) | |
7c78e7c7 | 331 | { |
01b2eeec KB |
332 | if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) |
333 | { | |
334 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
335 | x += pt.x; y += pt.y; | |
336 | } | |
337 | } | |
7c78e7c7 | 338 | |
01b2eeec | 339 | bool wxWindow::Show(bool show) |
7c78e7c7 | 340 | { |
01b2eeec KB |
341 | // TODO |
342 | return FALSE; | |
343 | } | |
7c78e7c7 | 344 | |
01b2eeec | 345 | bool wxWindow::IsShown() const |
7c78e7c7 | 346 | { |
01b2eeec KB |
347 | // TODO |
348 | return FALSE; | |
349 | } | |
7c78e7c7 | 350 | |
01b2eeec | 351 | int wxWindow::GetCharHeight() const |
7c78e7c7 | 352 | { |
01b2eeec KB |
353 | // TODO |
354 | return 0; | |
355 | } | |
7c78e7c7 | 356 | |
01b2eeec | 357 | int wxWindow::GetCharWidth() const |
7c78e7c7 | 358 | { |
01b2eeec KB |
359 | // TODO |
360 | return 0; | |
361 | } | |
7c78e7c7 | 362 | |
01b2eeec KB |
363 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, |
364 | int *descent, int *externalLeading, const wxFont *theFont, bool) const | |
7c78e7c7 | 365 | { |
01b2eeec KB |
366 | wxFont *fontToUse = (wxFont *)theFont; |
367 | if (!fontToUse) | |
368 | fontToUse = (wxFont *) & m_windowFont; | |
7c78e7c7 | 369 | |
01b2eeec KB |
370 | // TODO |
371 | } | |
7c78e7c7 | 372 | |
16e93305 | 373 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
7c78e7c7 | 374 | { |
01b2eeec KB |
375 | // TODO |
376 | } | |
7c78e7c7 | 377 | |
01b2eeec KB |
378 | // Responds to colour changes: passes event on to children. |
379 | void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) | |
7c78e7c7 | 380 | { |
01b2eeec KB |
381 | wxNode *node = GetChildren()->First(); |
382 | while ( node ) | |
383 | { | |
384 | // Only propagate to non-top-level windows | |
385 | wxWindow *win = (wxWindow *)node->Data(); | |
386 | if ( win->GetParent() ) | |
387 | { | |
388 | wxSysColourChangedEvent event2; | |
389 | event.m_eventObject = win; | |
390 | win->GetEventHandler()->ProcessEvent(event2); | |
391 | } | |
7c78e7c7 | 392 | |
01b2eeec KB |
393 | node = node->Next(); |
394 | } | |
395 | } | |
7c78e7c7 | 396 | |
01b2eeec KB |
397 | // This can be called by the app (or wxWindows) to do default processing for the current |
398 | // event. Save message/event info in wxWindow so they can be used in this function. | |
399 | long wxWindow::Default() | |
7c78e7c7 | 400 | { |
01b2eeec KB |
401 | // TODO |
402 | return 0; | |
403 | } | |
7c78e7c7 | 404 | |
01b2eeec | 405 | void wxWindow::InitDialog() |
7c78e7c7 | 406 | { |
01b2eeec KB |
407 | wxInitDialogEvent event(GetId()); |
408 | event.SetEventObject( this ); | |
409 | GetEventHandler()->ProcessEvent(event); | |
410 | } | |
7c78e7c7 | 411 | |
01b2eeec KB |
412 | // Default init dialog behaviour is to transfer data to window |
413 | void wxWindow::OnInitDialog(wxInitDialogEvent& event) | |
7c78e7c7 | 414 | { |
01b2eeec KB |
415 | TransferDataToWindow(); |
416 | } | |
7c78e7c7 | 417 | |
01b2eeec KB |
418 | // Caret manipulation |
419 | void wxWindow::CreateCaret(int w, int h) | |
7c78e7c7 | 420 | { |
01b2eeec KB |
421 | m_caretWidth = w; |
422 | m_caretHeight = h; | |
423 | m_caretEnabled = TRUE; | |
424 | } | |
7c78e7c7 | 425 | |
01b2eeec | 426 | void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) |
7c78e7c7 | 427 | { |
01b2eeec KB |
428 | // TODO |
429 | } | |
7c78e7c7 | 430 | |
01b2eeec | 431 | void wxWindow::ShowCaret(bool show) |
7c78e7c7 | 432 | { |
01b2eeec KB |
433 | // TODO |
434 | } | |
7c78e7c7 | 435 | |
01b2eeec | 436 | void wxWindow::DestroyCaret() |
7c78e7c7 | 437 | { |
01b2eeec KB |
438 | // TODO |
439 | m_caretEnabled = FALSE; | |
440 | } | |
7c78e7c7 | 441 | |
01b2eeec | 442 | void wxWindow::SetCaretPos(int x, int y) |
7c78e7c7 | 443 | { |
01b2eeec KB |
444 | // TODO |
445 | } | |
7c78e7c7 | 446 | |
01b2eeec | 447 | void wxWindow::GetCaretPos(int *x, int *y) const |
7c78e7c7 | 448 | { |
01b2eeec KB |
449 | // TODO |
450 | } | |
7c78e7c7 | 451 | |
01b2eeec | 452 | wxWindow *wxGetActiveWindow() |
7c78e7c7 | 453 | { |
01b2eeec KB |
454 | // TODO |
455 | return NULL; | |
456 | } | |
7c78e7c7 | 457 | |
01b2eeec | 458 | void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) |
7c78e7c7 | 459 | { |
01b2eeec KB |
460 | m_minSizeX = minW; |
461 | m_minSizeY = minH; | |
462 | m_maxSizeX = maxW; | |
463 | m_maxSizeY = maxH; | |
464 | } | |
7c78e7c7 | 465 | |
01b2eeec | 466 | void wxWindow::Centre(int direction) |
7c78e7c7 | 467 | { |
01b2eeec | 468 | int x, y, width, height, panel_width, panel_height, new_x, new_y; |
7c78e7c7 | 469 | |
01b2eeec KB |
470 | wxWindow *father = (wxWindow *)GetParent(); |
471 | if (!father) | |
472 | return; | |
7c78e7c7 | 473 | |
01b2eeec KB |
474 | father->GetClientSize(&panel_width, &panel_height); |
475 | GetSize(&width, &height); | |
476 | GetPosition(&x, &y); | |
7c78e7c7 | 477 | |
01b2eeec KB |
478 | new_x = -1; |
479 | new_y = -1; | |
7c78e7c7 | 480 | |
01b2eeec KB |
481 | if (direction & wxHORIZONTAL) |
482 | new_x = (int)((panel_width - width)/2); | |
7c78e7c7 | 483 | |
01b2eeec KB |
484 | if (direction & wxVERTICAL) |
485 | new_y = (int)((panel_height - height)/2); | |
7c78e7c7 | 486 | |
01b2eeec | 487 | SetSize(new_x, new_y, -1, -1); |
7c78e7c7 | 488 | |
01b2eeec | 489 | } |
7c78e7c7 | 490 | |
01b2eeec KB |
491 | // Coordinates relative to the window |
492 | void wxWindow::WarpPointer (int x_pos, int y_pos) | |
7c78e7c7 | 493 | { |
01b2eeec KB |
494 | // TODO |
495 | } | |
7c78e7c7 | 496 | |
01b2eeec | 497 | void wxWindow::OnEraseBackground(wxEraseEvent& event) |
7c78e7c7 | 498 | { |
01b2eeec KB |
499 | // TODO |
500 | Default(); | |
501 | } | |
7c78e7c7 | 502 | |
01b2eeec | 503 | int wxWindow::GetScrollPos(int orient) const |
7c78e7c7 | 504 | { |
01b2eeec KB |
505 | // TODO |
506 | return 0; | |
507 | } | |
7c78e7c7 | 508 | |
01b2eeec KB |
509 | // This now returns the whole range, not just the number |
510 | // of positions that we can scroll. | |
511 | int wxWindow::GetScrollRange(int orient) const | |
7c78e7c7 | 512 | { |
01b2eeec KB |
513 | // TODO |
514 | return 0; | |
515 | } | |
7c78e7c7 | 516 | |
01b2eeec | 517 | int wxWindow::GetScrollThumb(int orient) const |
7c78e7c7 | 518 | { |
01b2eeec KB |
519 | // TODO |
520 | return 0; | |
521 | } | |
7c78e7c7 | 522 | |
01b2eeec | 523 | void wxWindow::SetScrollPos(int orient, int pos, bool refresh) |
7c78e7c7 | 524 | { |
01b2eeec KB |
525 | // TODO |
526 | return 0; | |
527 | } | |
7c78e7c7 | 528 | |
01b2eeec KB |
529 | // New function that will replace some of the above. |
530 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, | |
531 | int range, bool refresh) | |
7c78e7c7 | 532 | { |
01b2eeec KB |
533 | // TODO |
534 | } | |
7c78e7c7 | 535 | |
01b2eeec | 536 | // Does a physical scroll |
16e93305 | 537 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) |
7c78e7c7 | 538 | { |
01b2eeec KB |
539 | // TODO |
540 | return 0; | |
541 | } | |
7c78e7c7 | 542 | |
01b2eeec | 543 | void wxWindow::SetFont(const wxFont& font) |
7c78e7c7 | 544 | { |
01b2eeec | 545 | m_windowFont = font; |
7c78e7c7 | 546 | |
01b2eeec KB |
547 | if (!m_windowFont.Ok()) |
548 | return; | |
549 | // TODO | |
550 | } | |
7c78e7c7 | 551 | |
01b2eeec | 552 | void wxWindow::OnChar(wxKeyEvent& event) |
7c78e7c7 | 553 | { |
01b2eeec KB |
554 | if ( event.KeyCode() == WXK_TAB ) { |
555 | // propagate the TABs to the parent - it's up to it to decide what | |
556 | // to do with it | |
557 | if ( GetParent() ) { | |
558 | if ( GetParent()->ProcessEvent(event) ) | |
559 | return; | |
560 | } | |
561 | } | |
562 | } | |
7c78e7c7 | 563 | |
01b2eeec | 564 | void wxWindow::OnPaint(wxPaintEvent& event) |
7c78e7c7 | 565 | { |
01b2eeec KB |
566 | Default(); |
567 | } | |
7c78e7c7 | 568 | |
01b2eeec | 569 | bool wxWindow::IsEnabled() const |
7c78e7c7 | 570 | { |
01b2eeec KB |
571 | // TODO |
572 | return FALSE; | |
573 | } | |
7c78e7c7 | 574 | |
01b2eeec KB |
575 | // Dialog support: override these and call |
576 | // base class members to add functionality | |
577 | // that can't be done using validators. | |
578 | // NOTE: these functions assume that controls | |
579 | // are direct children of this window, not grandchildren | |
580 | // or other levels of descendant. | |
581 | ||
582 | // Transfer values to controls. If returns FALSE, | |
583 | // it's an application error (pops up a dialog) | |
584 | bool wxWindow::TransferDataToWindow() | |
585 | { | |
586 | wxNode *node = GetChildren()->First(); | |
587 | while ( node ) | |
588 | { | |
589 | wxWindow *child = (wxWindow *)node->Data(); | |
590 | if ( child->GetValidator() && | |
591 | !child->GetValidator()->TransferToWindow() ) | |
592 | { | |
593 | wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); | |
594 | return FALSE; | |
595 | } | |
596 | ||
597 | node = node->Next(); | |
598 | } | |
599 | return TRUE; | |
600 | } | |
7c78e7c7 | 601 | |
01b2eeec KB |
602 | // Transfer values from controls. If returns FALSE, |
603 | // validation failed: don't quit | |
604 | bool wxWindow::TransferDataFromWindow() | |
605 | { | |
606 | wxNode *node = GetChildren()->First(); | |
607 | while ( node ) | |
608 | { | |
609 | wxWindow *child = (wxWindow *)node->Data(); | |
610 | if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) | |
611 | { | |
612 | return FALSE; | |
613 | } | |
614 | ||
615 | node = node->Next(); | |
616 | } | |
617 | return TRUE; | |
618 | } | |
619 | ||
620 | bool wxWindow::Validate() | |
7c78e7c7 | 621 | { |
01b2eeec KB |
622 | wxNode *node = GetChildren()->First(); |
623 | while ( node ) | |
624 | { | |
625 | wxWindow *child = (wxWindow *)node->Data(); | |
626 | if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) | |
627 | { | |
628 | return FALSE; | |
629 | } | |
7c78e7c7 | 630 | |
01b2eeec KB |
631 | node = node->Next(); |
632 | } | |
633 | return TRUE; | |
634 | } | |
635 | ||
636 | // Get the window with the focus | |
637 | wxWindow *wxWindow::FindFocus() | |
7c78e7c7 | 638 | { |
01b2eeec KB |
639 | // TODO |
640 | return NULL; | |
641 | } | |
7c78e7c7 | 642 | |
01b2eeec | 643 | void wxWindow::AddChild(wxWindow *child) |
7c78e7c7 | 644 | { |
01b2eeec KB |
645 | GetChildren()->Append(child); |
646 | child->m_windowParent = this; | |
647 | } | |
7c78e7c7 | 648 | |
01b2eeec | 649 | void wxWindow::RemoveChild(wxWindow *child) |
7c78e7c7 | 650 | { |
01b2eeec KB |
651 | if (GetChildren()) |
652 | GetChildren()->DeleteObject(child); | |
653 | child->m_windowParent = NULL; | |
654 | } | |
7c78e7c7 | 655 | |
01b2eeec | 656 | void wxWindow::DestroyChildren() |
7c78e7c7 | 657 | { |
01b2eeec KB |
658 | if (GetChildren()) { |
659 | wxNode *node; | |
660 | while ((node = GetChildren()->First()) != (wxNode *)NULL) { | |
661 | wxWindow *child; | |
662 | if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { | |
663 | delete child; | |
664 | if ( GetChildren()->Member(child) ) | |
665 | delete node; | |
666 | } | |
667 | } /* while */ | |
668 | } | |
669 | } | |
7c78e7c7 | 670 | |
01b2eeec | 671 | void wxWindow::MakeModal(bool modal) |
7c78e7c7 | 672 | { |
01b2eeec KB |
673 | // Disable all other windows |
674 | if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) | |
675 | { | |
676 | wxNode *node = wxTopLevelWindows.First(); | |
677 | while (node) | |
678 | { | |
679 | wxWindow *win = (wxWindow *)node->Data(); | |
680 | if (win != this) | |
681 | win->Enable(!modal); | |
7c78e7c7 | 682 | |
01b2eeec KB |
683 | node = node->Next(); |
684 | } | |
685 | } | |
686 | } | |
7c78e7c7 | 687 | |
01b2eeec KB |
688 | // If nothing defined for this, try the parent. |
689 | // E.g. we may be a button loaded from a resource, with no callback function | |
690 | // defined. | |
691 | void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) | |
7c78e7c7 | 692 | { |
01b2eeec KB |
693 | if (GetEventHandler()->ProcessEvent(event) ) |
694 | return; | |
695 | if (m_windowParent) | |
696 | m_windowParent->GetEventHandler()->OnCommand(win, event); | |
697 | } | |
7c78e7c7 | 698 | |
01b2eeec | 699 | void wxWindow::SetConstraints(wxLayoutConstraints *c) |
7c78e7c7 RR |
700 | { |
701 | if (m_constraints) | |
702 | { | |
703 | UnsetConstraints(m_constraints); | |
704 | delete m_constraints; | |
705 | } | |
01b2eeec | 706 | m_constraints = c; |
7c78e7c7 RR |
707 | if (m_constraints) |
708 | { | |
709 | // Make sure other windows know they're part of a 'meaningful relationship' | |
710 | if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this)) | |
711 | m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
712 | if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this)) | |
713 | m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
714 | if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this)) | |
715 | m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
716 | if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this)) | |
717 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
718 | if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this)) | |
719 | m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
720 | if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this)) | |
721 | m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
722 | if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this)) | |
723 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
724 | if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) | |
725 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); | |
726 | } | |
7c78e7c7 | 727 | } |
7c78e7c7 RR |
728 | |
729 | // This removes any dangling pointers to this window | |
730 | // in other windows' constraintsInvolvedIn lists. | |
731 | void wxWindow::UnsetConstraints(wxLayoutConstraints *c) | |
732 | { | |
733 | if (c) | |
734 | { | |
735 | if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
736 | c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
737 | if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this)) | |
738 | c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
739 | if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this)) | |
740 | c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
741 | if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this)) | |
742 | c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
743 | if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this)) | |
744 | c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
745 | if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this)) | |
746 | c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
747 | if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this)) | |
748 | c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
749 | if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this)) | |
750 | c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this); | |
751 | } | |
752 | } | |
753 | ||
754 | // Back-pointer to other windows we're involved with, so if we delete | |
755 | // this window, we must delete any constraints we're involved with. | |
756 | void wxWindow::AddConstraintReference(wxWindow *otherWin) | |
757 | { | |
758 | if (!m_constraintsInvolvedIn) | |
759 | m_constraintsInvolvedIn = new wxList; | |
760 | if (!m_constraintsInvolvedIn->Member(otherWin)) | |
761 | m_constraintsInvolvedIn->Append(otherWin); | |
762 | } | |
763 | ||
764 | // REMOVE back-pointer to other windows we're involved with. | |
765 | void wxWindow::RemoveConstraintReference(wxWindow *otherWin) | |
766 | { | |
767 | if (m_constraintsInvolvedIn) | |
768 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
769 | } | |
770 | ||
771 | // Reset any constraints that mention this window | |
01b2eeec | 772 | void wxWindow::DeleteRelatedConstraints() |
7c78e7c7 RR |
773 | { |
774 | if (m_constraintsInvolvedIn) | |
775 | { | |
776 | wxNode *node = m_constraintsInvolvedIn->First(); | |
777 | while (node) | |
778 | { | |
779 | wxWindow *win = (wxWindow *)node->Data(); | |
780 | wxNode *next = node->Next(); | |
781 | wxLayoutConstraints *constr = win->GetConstraints(); | |
782 | ||
783 | // Reset any constraints involving this window | |
784 | if (constr) | |
785 | { | |
786 | constr->left.ResetIfWin((wxWindow *)this); | |
787 | constr->top.ResetIfWin((wxWindow *)this); | |
788 | constr->right.ResetIfWin((wxWindow *)this); | |
789 | constr->bottom.ResetIfWin((wxWindow *)this); | |
790 | constr->width.ResetIfWin((wxWindow *)this); | |
791 | constr->height.ResetIfWin((wxWindow *)this); | |
792 | constr->centreX.ResetIfWin((wxWindow *)this); | |
793 | constr->centreY.ResetIfWin((wxWindow *)this); | |
794 | } | |
795 | delete node; | |
796 | node = next; | |
797 | } | |
798 | delete m_constraintsInvolvedIn; | |
799 | m_constraintsInvolvedIn = NULL; | |
800 | } | |
801 | } | |
802 | ||
803 | void wxWindow::SetSizer(wxSizer *sizer) | |
804 | { | |
805 | m_windowSizer = sizer; | |
806 | if (sizer) | |
807 | sizer->SetSizerParent((wxWindow *)this); | |
808 | } | |
809 | ||
810 | /* | |
811 | * New version | |
812 | */ | |
813 | ||
01b2eeec | 814 | bool wxWindow::Layout() |
7c78e7c7 RR |
815 | { |
816 | if (GetConstraints()) | |
817 | { | |
818 | int w, h; | |
819 | GetClientSize(&w, &h); | |
820 | GetConstraints()->width.SetValue(w); | |
821 | GetConstraints()->height.SetValue(h); | |
822 | } | |
823 | ||
824 | // If top level (one sizer), evaluate the sizer's constraints. | |
825 | if (GetSizer()) | |
826 | { | |
827 | int noChanges; | |
828 | GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated | |
829 | GetSizer()->LayoutPhase1(&noChanges); | |
830 | GetSizer()->LayoutPhase2(&noChanges); | |
831 | GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes | |
832 | return TRUE; | |
833 | } | |
834 | else | |
835 | { | |
836 | // Otherwise, evaluate child constraints | |
837 | ResetConstraints(); // Mark all constraints as unevaluated | |
838 | DoPhase(1); // Just one phase need if no sizers involved | |
839 | DoPhase(2); | |
840 | SetConstraintSizes(); // Recursively set the real window sizes | |
841 | } | |
842 | return TRUE; | |
843 | } | |
844 | ||
845 | ||
846 | // Do a phase of evaluating constraints: | |
847 | // the default behaviour. wxSizers may do a similar | |
848 | // thing, but also impose their own 'constraints' | |
849 | // and order the evaluation differently. | |
850 | bool wxWindow::LayoutPhase1(int *noChanges) | |
851 | { | |
852 | wxLayoutConstraints *constr = GetConstraints(); | |
853 | if (constr) | |
854 | { | |
855 | return constr->SatisfyConstraints((wxWindow *)this, noChanges); | |
856 | } | |
857 | else | |
858 | return TRUE; | |
859 | } | |
860 | ||
861 | bool wxWindow::LayoutPhase2(int *noChanges) | |
862 | { | |
863 | *noChanges = 0; | |
864 | ||
865 | // Layout children | |
866 | DoPhase(1); | |
867 | DoPhase(2); | |
868 | return TRUE; | |
869 | } | |
870 | ||
871 | // Do a phase of evaluating child constraints | |
872 | bool wxWindow::DoPhase(int phase) | |
873 | { | |
874 | int noIterations = 0; | |
875 | int maxIterations = 500; | |
876 | int noChanges = 1; | |
877 | int noFailures = 0; | |
878 | wxList succeeded; | |
879 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
880 | { | |
881 | noChanges = 0; | |
882 | noFailures = 0; | |
883 | wxNode *node = GetChildren()->First(); | |
884 | while (node) | |
885 | { | |
886 | wxWindow *child = (wxWindow *)node->Data(); | |
887 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog))) | |
888 | { | |
889 | wxLayoutConstraints *constr = child->GetConstraints(); | |
890 | if (constr) | |
891 | { | |
892 | if (succeeded.Member(child)) | |
893 | { | |
894 | } | |
895 | else | |
896 | { | |
897 | int tempNoChanges = 0; | |
898 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
899 | noChanges += tempNoChanges; | |
900 | if (success) | |
901 | { | |
902 | succeeded.Append(child); | |
903 | } | |
904 | } | |
905 | } | |
906 | } | |
907 | node = node->Next(); | |
908 | } | |
909 | noIterations ++; | |
910 | } | |
911 | return TRUE; | |
912 | } | |
913 | ||
01b2eeec | 914 | void wxWindow::ResetConstraints() |
7c78e7c7 RR |
915 | { |
916 | wxLayoutConstraints *constr = GetConstraints(); | |
917 | if (constr) | |
918 | { | |
919 | constr->left.SetDone(FALSE); | |
920 | constr->top.SetDone(FALSE); | |
921 | constr->right.SetDone(FALSE); | |
922 | constr->bottom.SetDone(FALSE); | |
923 | constr->width.SetDone(FALSE); | |
924 | constr->height.SetDone(FALSE); | |
925 | constr->centreX.SetDone(FALSE); | |
926 | constr->centreY.SetDone(FALSE); | |
927 | } | |
928 | wxNode *node = GetChildren()->First(); | |
929 | while (node) | |
930 | { | |
931 | wxWindow *win = (wxWindow *)node->Data(); | |
932 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
933 | win->ResetConstraints(); | |
934 | node = node->Next(); | |
935 | } | |
936 | } | |
937 | ||
938 | // Need to distinguish between setting the 'fake' size for | |
939 | // windows and sizers, and setting the real values. | |
940 | void wxWindow::SetConstraintSizes(bool recurse) | |
941 | { | |
942 | wxLayoutConstraints *constr = GetConstraints(); | |
943 | if (constr && constr->left.GetDone() && constr->right.GetDone() && | |
944 | constr->width.GetDone() && constr->height.GetDone()) | |
945 | { | |
946 | int x = constr->left.GetValue(); | |
947 | int y = constr->top.GetValue(); | |
948 | int w = constr->width.GetValue(); | |
949 | int h = constr->height.GetValue(); | |
950 | ||
951 | // If we don't want to resize this window, just move it... | |
952 | if ((constr->width.GetRelationship() != wxAsIs) || | |
953 | (constr->height.GetRelationship() != wxAsIs)) | |
954 | { | |
955 | // Calls Layout() recursively. AAAGH. How can we stop that. | |
956 | // Simply take Layout() out of non-top level OnSizes. | |
957 | SizerSetSize(x, y, w, h); | |
958 | } | |
959 | else | |
960 | { | |
961 | SizerMove(x, y); | |
962 | } | |
963 | } | |
964 | else if (constr) | |
965 | { | |
966 | char *windowClass = this->GetClassInfo()->GetClassName(); | |
967 | ||
968 | wxString winName; | |
01b2eeec KB |
969 | if (GetName() == "") |
970 | winName = "unnamed"; | |
971 | else | |
972 | winName = GetName(); | |
7c78e7c7 RR |
973 | wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName); |
974 | if (!constr->left.GetDone()) | |
975 | wxDebugMsg(" unsatisfied 'left' constraint.\n"); | |
976 | if (!constr->right.GetDone()) | |
977 | wxDebugMsg(" unsatisfied 'right' constraint.\n"); | |
978 | if (!constr->width.GetDone()) | |
979 | wxDebugMsg(" unsatisfied 'width' constraint.\n"); | |
980 | if (!constr->height.GetDone()) | |
981 | wxDebugMsg(" unsatisfied 'height' constraint.\n"); | |
982 | wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n"); | |
983 | } | |
984 | ||
985 | if (recurse) | |
986 | { | |
987 | wxNode *node = GetChildren()->First(); | |
988 | while (node) | |
989 | { | |
990 | wxWindow *win = (wxWindow *)node->Data(); | |
991 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))) | |
992 | win->SetConstraintSizes(); | |
993 | node = node->Next(); | |
994 | } | |
995 | } | |
996 | } | |
997 | ||
998 | // This assumes that all sizers are 'on' the same | |
999 | // window, i.e. the parent of this window. | |
1000 | void wxWindow::TransformSizerToActual(int *x, int *y) const | |
1001 | { | |
1002 | if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || | |
01b2eeec | 1003 | m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) |
7c78e7c7 RR |
1004 | return; |
1005 | ||
1006 | int xp, yp; | |
1007 | m_sizerParent->GetPosition(&xp, &yp); | |
1008 | m_sizerParent->TransformSizerToActual(&xp, &yp); | |
1009 | *x += xp; | |
1010 | *y += yp; | |
1011 | } | |
1012 | ||
1013 | void wxWindow::SizerSetSize(int x, int y, int w, int h) | |
1014 | { | |
01b2eeec KB |
1015 | int xx = x; |
1016 | int yy = y; | |
7c78e7c7 RR |
1017 | TransformSizerToActual(&xx, &yy); |
1018 | SetSize(xx, yy, w, h); | |
1019 | } | |
1020 | ||
1021 | void wxWindow::SizerMove(int x, int y) | |
1022 | { | |
01b2eeec KB |
1023 | int xx = x; |
1024 | int yy = y; | |
7c78e7c7 RR |
1025 | TransformSizerToActual(&xx, &yy); |
1026 | Move(xx, yy); | |
1027 | } | |
1028 | ||
1029 | // Only set the size/position of the constraint (if any) | |
1030 | void wxWindow::SetSizeConstraint(int x, int y, int w, int h) | |
1031 | { | |
1032 | wxLayoutConstraints *constr = GetConstraints(); | |
1033 | if (constr) | |
1034 | { | |
1035 | if (x != -1) | |
1036 | { | |
1037 | constr->left.SetValue(x); | |
1038 | constr->left.SetDone(TRUE); | |
1039 | } | |
1040 | if (y != -1) | |
1041 | { | |
1042 | constr->top.SetValue(y); | |
1043 | constr->top.SetDone(TRUE); | |
1044 | } | |
1045 | if (w != -1) | |
1046 | { | |
1047 | constr->width.SetValue(w); | |
1048 | constr->width.SetDone(TRUE); | |
1049 | } | |
1050 | if (h != -1) | |
1051 | { | |
1052 | constr->height.SetValue(h); | |
1053 | constr->height.SetDone(TRUE); | |
1054 | } | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | void wxWindow::MoveConstraint(int x, int y) | |
1059 | { | |
1060 | wxLayoutConstraints *constr = GetConstraints(); | |
1061 | if (constr) | |
1062 | { | |
1063 | if (x != -1) | |
1064 | { | |
1065 | constr->left.SetValue(x); | |
1066 | constr->left.SetDone(TRUE); | |
1067 | } | |
1068 | if (y != -1) | |
1069 | { | |
1070 | constr->top.SetValue(y); | |
1071 | constr->top.SetDone(TRUE); | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | void wxWindow::GetSizeConstraint(int *w, int *h) const | |
1077 | { | |
1078 | wxLayoutConstraints *constr = GetConstraints(); | |
1079 | if (constr) | |
1080 | { | |
1081 | *w = constr->width.GetValue(); | |
1082 | *h = constr->height.GetValue(); | |
1083 | } | |
1084 | else | |
1085 | GetSize(w, h); | |
1086 | } | |
1087 | ||
1088 | void wxWindow::GetClientSizeConstraint(int *w, int *h) const | |
1089 | { | |
1090 | wxLayoutConstraints *constr = GetConstraints(); | |
1091 | if (constr) | |
1092 | { | |
1093 | *w = constr->width.GetValue(); | |
1094 | *h = constr->height.GetValue(); | |
1095 | } | |
1096 | else | |
1097 | GetClientSize(w, h); | |
1098 | } | |
1099 | ||
1100 | void wxWindow::GetPositionConstraint(int *x, int *y) const | |
1101 | { | |
1102 | wxLayoutConstraints *constr = GetConstraints(); | |
1103 | if (constr) | |
1104 | { | |
1105 | *x = constr->left.GetValue(); | |
1106 | *y = constr->top.GetValue(); | |
1107 | } | |
1108 | else | |
1109 | GetPosition(x, y); | |
1110 | } | |
1111 | ||
01b2eeec KB |
1112 | bool wxWindow::Close(bool force) |
1113 | { | |
1114 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
1115 | event.SetEventObject(this); | |
e3065973 | 1116 | #if WXWIN_COMPATIBILITY |
01b2eeec | 1117 | event.SetForce(force); |
e3065973 JS |
1118 | #endif |
1119 | event.SetCanVeto(!force); | |
01b2eeec KB |
1120 | |
1121 | return GetEventHandler()->ProcessEvent(event); | |
1122 | } | |
1123 | ||
1124 | wxObject* wxWindow::GetChild(int number) const | |
1125 | { | |
1126 | // Return a pointer to the Nth object in the window | |
1127 | if (!GetChildren()) | |
1128 | return(NULL) ; | |
1129 | wxNode *node = GetChildren()->First(); | |
1130 | int n = number; | |
1131 | while (node && n--) | |
1132 | node = node->Next() ; | |
1133 | if (node) | |
1134 | { | |
1135 | wxObject *obj = (wxObject *)node->Data(); | |
1136 | return(obj) ; | |
1137 | } | |
1138 | else | |
1139 | return NULL ; | |
1140 | } | |
1141 | ||
1142 | void wxWindow::OnDefaultAction(wxControl *initiatingItem) | |
1143 | { | |
1144 | // Obsolete function | |
1145 | } | |
1146 | ||
1147 | void wxWindow::Clear() | |
1148 | { | |
1149 | wxClientDC dc(this); | |
1150 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1151 | dc.SetBackground(brush); | |
1152 | dc.Clear(); | |
1153 | } | |
1154 | ||
1155 | // Fits the panel around the items | |
1156 | void wxWindow::Fit() | |
1157 | { | |
1158 | int maxX = 0; | |
1159 | int maxY = 0; | |
1160 | wxNode *node = GetChildren()->First(); | |
1161 | while ( node ) | |
1162 | { | |
1163 | wxWindow *win = (wxWindow *)node->Data(); | |
1164 | int wx, wy, ww, wh; | |
1165 | win->GetPosition(&wx, &wy); | |
1166 | win->GetSize(&ww, &wh); | |
1167 | if ( wx + ww > maxX ) | |
1168 | maxX = wx + ww; | |
1169 | if ( wy + wh > maxY ) | |
1170 | maxY = wy + wh; | |
1171 | ||
1172 | node = node->Next(); | |
1173 | } | |
1174 | SetClientSize(maxX + 5, maxY + 5); | |
1175 | } | |
1176 | ||
1177 | void wxWindow::SetValidator(const wxValidator& validator) | |
1178 | { | |
1179 | if ( m_windowValidator ) | |
1180 | delete m_windowValidator; | |
1181 | m_windowValidator = validator.Clone(); | |
1182 | ||
1183 | if ( m_windowValidator ) | |
1184 | m_windowValidator->SetWindow(this) ; | |
1185 | } | |
1186 | ||
1187 | // Find a window by id or name | |
1188 | wxWindow *wxWindow::FindWindow(long id) | |
1189 | { | |
1190 | if ( GetId() == id) | |
1191 | return this; | |
1192 | ||
1193 | wxNode *node = GetChildren()->First(); | |
1194 | while ( node ) | |
1195 | { | |
1196 | wxWindow *child = (wxWindow *)node->Data(); | |
1197 | wxWindow *found = child->FindWindow(id); | |
1198 | if ( found ) | |
1199 | return found; | |
1200 | node = node->Next(); | |
1201 | } | |
1202 | return NULL; | |
1203 | } | |
1204 | ||
1205 | wxWindow *wxWindow::FindWindow(const wxString& name) | |
1206 | { | |
1207 | if ( GetName() == name) | |
1208 | return this; | |
1209 | ||
1210 | wxNode *node = GetChildren()->First(); | |
1211 | while ( node ) | |
1212 | { | |
1213 | wxWindow *child = (wxWindow *)node->Data(); | |
1214 | wxWindow *found = child->FindWindow(name); | |
1215 | if ( found ) | |
1216 | return found; | |
1217 | node = node->Next(); | |
1218 | } | |
1219 | return NULL; | |
1220 | } | |
1221 | ||
1222 | void wxWindow::OnIdle(wxIdleEvent& event) | |
1223 | { | |
1224 | /* TODO: you may need to do something like this | |
1225 | * if your GUI doesn't generate enter/leave events | |
1226 | ||
1227 | // Check if we need to send a LEAVE event | |
1228 | if (m_mouseInWindow) | |
1229 | { | |
1230 | POINT pt; | |
1231 | ::GetCursorPos(&pt); | |
1232 | if (::WindowFromPoint(pt) != (HWND) GetHWND()) | |
1233 | { | |
1234 | // Generate a LEAVE event | |
1235 | m_mouseInWindow = FALSE; | |
1236 | MSWOnMouseLeave(pt.x, pt.y, 0); | |
1237 | } | |
1238 | } | |
1239 | */ | |
1240 | ||
1241 | // This calls the UI-update mechanism (querying windows for | |
1242 | // menu/toolbar/control state information) | |
1243 | UpdateWindowUI(); | |
1244 | } | |
1245 | ||
1246 | // Raise the window to the top of the Z order | |
1247 | void wxWindow::Raise() | |
1248 | { | |
1249 | // TODO | |
1250 | } | |
1251 | ||
1252 | // Lower the window to the bottom of the Z order | |
1253 | void wxWindow::Lower() | |
1254 | { | |
1255 | // TODO | |
1256 | } | |
1257 | ||
7c78e7c7 RR |
1258 | bool wxWindow::AcceptsFocus() const |
1259 | { | |
01b2eeec KB |
1260 | return IsShown() && IsEnabled(); |
1261 | } | |
1262 | ||
1263 | // Update region access | |
1264 | wxRegion wxWindow::GetUpdateRegion() const | |
1265 | { | |
1266 | return m_updateRegion; | |
7c78e7c7 RR |
1267 | } |
1268 | ||
01b2eeec | 1269 | bool wxWindow::IsExposed(int x, int y, int w, int h) const |
7c78e7c7 | 1270 | { |
01b2eeec | 1271 | return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); |
7c78e7c7 | 1272 | } |
01b2eeec KB |
1273 | |
1274 | bool wxWindow::IsExposed(const wxPoint& pt) const | |
1275 | { | |
1276 | return (m_updateRegion.Contains(pt) != wxOutRegion); | |
1277 | } | |
1278 | ||
1279 | bool wxWindow::IsExposed(const wxRect& rect) const | |
1280 | { | |
1281 | return (m_updateRegion.Contains(rect) != wxOutRegion); | |
1282 | } | |
1283 | ||
1284 |