]>
Commit | Line | Data |
---|---|---|
7ec1983b | 1 | ///////////////////////////////////////////////////////////////////////////// |
f03fc89f | 2 | // Name: common/window.cpp |
7ec1983b VZ |
3 | // Purpose: common (to all ports) wxWindow functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 13/07/98 | |
7 | // RCS-ID: $Id$ | |
f03fc89f | 8 | // Copyright: (c) wxWindows team |
7ec1983b VZ |
9 | // Licence: wxWindows license |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
f03fc89f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f701d7ab | 19 | |
58654ed0 VZ |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "windowbase.h" | |
22 | #endif | |
23 | ||
341287bf JS |
24 | // For compilers that support precompilation, includes "wx.h". |
25 | #include "wx/wxprec.h" | |
26 | ||
f701d7ab | 27 | #ifdef __BORLANDC__ |
f03fc89f | 28 | #pragma hdrstop |
f701d7ab JS |
29 | #endif |
30 | ||
f03fc89f VZ |
31 | #ifndef WX_PRECOMP |
32 | #include "wx/string.h" | |
33 | #include "wx/log.h" | |
34 | #include "wx/intl.h" | |
35 | #include "wx/frame.h" | |
36 | #include "wx/defs.h" | |
37 | #include "wx/window.h" | |
1e6feb95 | 38 | #include "wx/control.h" |
f03fc89f VZ |
39 | #include "wx/checkbox.h" |
40 | #include "wx/radiobut.h" | |
26bf1ce0 | 41 | #include "wx/textctrl.h" |
f03fc89f VZ |
42 | #include "wx/settings.h" |
43 | #include "wx/dialog.h" | |
a02dc3e3 | 44 | #include "wx/msgdlg.h" |
a37a5a73 | 45 | #include "wx/statusbr.h" |
f03fc89f VZ |
46 | #endif //WX_PRECOMP |
47 | ||
48 | #if wxUSE_CONSTRAINTS | |
49 | #include "wx/layout.h" | |
3417c2cd | 50 | #include "wx/sizer.h" |
f03fc89f VZ |
51 | #endif // wxUSE_CONSTRAINTS |
52 | ||
53 | #if wxUSE_DRAG_AND_DROP | |
54 | #include "wx/dnd.h" | |
55 | #endif // wxUSE_DRAG_AND_DROP | |
56 | ||
bd83cb56 VZ |
57 | #if wxUSE_HELP |
58 | #include "wx/cshelp.h" | |
59 | #endif // wxUSE_HELP | |
60 | ||
f03fc89f VZ |
61 | #if wxUSE_TOOLTIPS |
62 | #include "wx/tooltip.h" | |
63 | #endif // wxUSE_TOOLTIPS | |
64 | ||
789295bf VZ |
65 | #if wxUSE_CARET |
66 | #include "wx/caret.h" | |
67 | #endif // wxUSE_CARET | |
68 | ||
f03fc89f VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // static data | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
42e69d6b | 73 | int wxWindowBase::ms_lastControlId = -200; |
f03fc89f VZ |
74 | |
75 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
76 | ||
77 | // ---------------------------------------------------------------------------- | |
78 | // event table | |
79 | // ---------------------------------------------------------------------------- | |
80 | ||
81 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
82 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
83 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 84 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
85 | |
86 | #if wxUSE_HELP | |
87 | EVT_HELP(-1, wxWindowBase::OnHelp) | |
88 | #endif // wxUSE_HELP | |
89 | ||
f03fc89f VZ |
90 | END_EVENT_TABLE() |
91 | ||
92 | // ============================================================================ | |
93 | // implementation of the common functionality of the wxWindow class | |
94 | // ============================================================================ | |
95 | ||
96 | // ---------------------------------------------------------------------------- | |
97 | // initialization | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
100 | // the default initialization | |
101 | void wxWindowBase::InitBase() | |
102 | { | |
103 | // no window yet, no parent nor children | |
f03fc89f VZ |
104 | m_parent = (wxWindow *)NULL; |
105 | m_windowId = -1; | |
106 | m_children.DeleteContents( FALSE ); // don't auto delete node data | |
107 | ||
108 | // no constraints on the minimal window size | |
109 | m_minWidth = | |
110 | m_minHeight = | |
111 | m_maxWidth = | |
112 | m_maxHeight = -1; | |
113 | ||
114 | // window is created enabled but it's not visible yet | |
115 | m_isShown = FALSE; | |
116 | m_isEnabled = TRUE; | |
117 | ||
8d99be5f | 118 | // no client data (yet) |
f03fc89f | 119 | m_clientData = NULL; |
1e6feb95 | 120 | m_clientDataType = wxClientData_None; |
f03fc89f VZ |
121 | |
122 | // the default event handler is just this window | |
123 | m_eventHandler = this; | |
124 | ||
88ac883a | 125 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
126 | // no validator |
127 | m_windowValidator = (wxValidator *) NULL; | |
88ac883a | 128 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
129 | |
130 | // use the system default colours | |
807a903e | 131 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE); |
f6e4e9ea JS |
132 | m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); |
133 | ||
8bf30fe9 VZ |
134 | // don't set the font here for wxMSW as we don't call WM_SETFONT here and |
135 | // so the font is *not* really set - but calls to SetFont() later won't do | |
136 | // anything because m_font appears to be already set! | |
137 | #ifndef __WXMSW__ | |
807a903e | 138 | m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); |
8bf30fe9 | 139 | #endif // __WXMSW__ |
807a903e | 140 | |
f03fc89f | 141 | // no style bits |
d80cd92a | 142 | m_exStyle = |
f03fc89f VZ |
143 | m_windowStyle = 0; |
144 | ||
145 | // an optimization for the event processing: checking this flag is much | |
146 | // faster than using IsKindOf(CLASSINFO(wxWindow)) | |
147 | m_isWindow = TRUE; | |
148 | ||
149 | #if wxUSE_CONSTRAINTS | |
150 | // no constraints whatsoever | |
151 | m_constraints = (wxLayoutConstraints *) NULL; | |
152 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
153 | m_windowSizer = (wxSizer *) NULL; | |
f03fc89f VZ |
154 | m_autoLayout = FALSE; |
155 | #endif // wxUSE_CONSTRAINTS | |
156 | ||
157 | #if wxUSE_DRAG_AND_DROP | |
158 | m_dropTarget = (wxDropTarget *)NULL; | |
159 | #endif // wxUSE_DRAG_AND_DROP | |
160 | ||
161 | #if wxUSE_TOOLTIPS | |
162 | m_tooltip = (wxToolTip *)NULL; | |
163 | #endif // wxUSE_TOOLTIPS | |
789295bf VZ |
164 | |
165 | #if wxUSE_CARET | |
166 | m_caret = (wxCaret *)NULL; | |
167 | #endif // wxUSE_CARET | |
a2d93e73 JS |
168 | |
169 | // Whether we're using the current theme for this window (wxGTK only for now) | |
170 | m_themeEnabled = FALSE; | |
f03fc89f VZ |
171 | } |
172 | ||
173 | // common part of window creation process | |
174 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
175 | wxWindowID id, | |
74e3313b VZ |
176 | const wxPoint& WXUNUSED(pos), |
177 | const wxSize& WXUNUSED(size), | |
f03fc89f | 178 | long style, |
8d99be5f | 179 | const wxValidator& validator, |
f03fc89f VZ |
180 | const wxString& name) |
181 | { | |
182 | // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other | |
183 | // member variables - check that it has been called (will catch the case | |
184 | // when a new ctor is added which doesn't call InitWindow) | |
223d09f6 | 185 | wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") ); |
f03fc89f VZ |
186 | |
187 | // generate a new id if the user doesn't care about it | |
69418a8e | 188 | m_windowId = id == -1 ? NewControlId() : id; |
f03fc89f VZ |
189 | |
190 | SetName(name); | |
191 | SetWindowStyleFlag(style); | |
192 | SetParent(parent); | |
674ac8b9 VZ |
193 | |
194 | #if wxUSE_VALIDATORS | |
8d99be5f | 195 | SetValidator(validator); |
674ac8b9 | 196 | #endif // wxUSE_VALIDATORS |
f03fc89f | 197 | |
8ae6ce07 VZ |
198 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
199 | // have it too - like this it's possible to set it only in the top level | |
200 | // dialog/frame and all children will inherit it by defult | |
201 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
202 | { | |
203 | SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY); | |
204 | } | |
205 | ||
f03fc89f VZ |
206 | return TRUE; |
207 | } | |
208 | ||
209 | // ---------------------------------------------------------------------------- | |
210 | // destruction | |
211 | // ---------------------------------------------------------------------------- | |
212 | ||
213 | // common clean up | |
214 | wxWindowBase::~wxWindowBase() | |
215 | { | |
216 | // FIXME if these 2 cases result from programming errors in the user code | |
217 | // we should probably assert here instead of silently fixing them | |
218 | ||
219 | // Just in case the window has been Closed, but we're then deleting | |
220 | // immediately: don't leave dangling pointers. | |
221 | wxPendingDelete.DeleteObject(this); | |
222 | ||
223 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
224 | // we weren't a dialog class | |
225 | wxTopLevelWindows.DeleteObject(this); | |
a23fd0e1 | 226 | |
223d09f6 | 227 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 228 | |
789295bf VZ |
229 | #if wxUSE_CARET |
230 | if ( m_caret ) | |
231 | delete m_caret; | |
232 | #endif // wxUSE_CARET | |
233 | ||
88ac883a | 234 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
235 | if ( m_windowValidator ) |
236 | delete m_windowValidator; | |
88ac883a | 237 | #endif // wxUSE_VALIDATORS |
f03fc89f | 238 | |
6ccec5fc | 239 | // we only delete object data, not untyped |
1e6feb95 | 240 | if ( m_clientDataType == wxClientData_Object ) |
f03fc89f VZ |
241 | delete m_clientObject; |
242 | ||
243 | #if wxUSE_CONSTRAINTS | |
244 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
245 | // at deleted windows as they delete themselves. | |
246 | DeleteRelatedConstraints(); | |
247 | ||
248 | if ( m_constraints ) | |
249 | { | |
250 | // This removes any dangling pointers to this window in other windows' | |
251 | // constraintsInvolvedIn lists. | |
252 | UnsetConstraints(m_constraints); | |
253 | delete m_constraints; | |
254 | m_constraints = NULL; | |
255 | } | |
256 | ||
257 | if ( m_windowSizer ) | |
258 | delete m_windowSizer; | |
259 | ||
f03fc89f VZ |
260 | #endif // wxUSE_CONSTRAINTS |
261 | ||
262 | #if wxUSE_DRAG_AND_DROP | |
263 | if ( m_dropTarget ) | |
264 | delete m_dropTarget; | |
265 | #endif // wxUSE_DRAG_AND_DROP | |
266 | ||
267 | #if wxUSE_TOOLTIPS | |
268 | if ( m_tooltip ) | |
269 | delete m_tooltip; | |
270 | #endif // wxUSE_TOOLTIPS | |
b0ee47ff VZ |
271 | |
272 | // reset the dangling pointer our parent window may keep to us | |
273 | if ( m_parent && m_parent->GetDefaultItem() == this ) | |
274 | { | |
275 | m_parent->SetDefaultItem(NULL); | |
276 | } | |
f03fc89f VZ |
277 | } |
278 | ||
279 | bool wxWindowBase::Destroy() | |
280 | { | |
281 | delete this; | |
282 | ||
283 | return TRUE; | |
284 | } | |
285 | ||
286 | bool wxWindowBase::Close(bool force) | |
287 | { | |
288 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
289 | event.SetEventObject(this); | |
290 | #if WXWIN_COMPATIBILITY | |
291 | event.SetForce(force); | |
292 | #endif // WXWIN_COMPATIBILITY | |
293 | event.SetCanVeto(!force); | |
294 | ||
295 | // return FALSE if window wasn't closed because the application vetoed the | |
296 | // close event | |
297 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
298 | } | |
299 | ||
300 | bool wxWindowBase::DestroyChildren() | |
301 | { | |
302 | wxWindowList::Node *node; | |
a23fd0e1 | 303 | for ( ;; ) |
f03fc89f | 304 | { |
a23fd0e1 VZ |
305 | // we iterate until the list becomes empty |
306 | node = GetChildren().GetFirst(); | |
307 | if ( !node ) | |
308 | break; | |
309 | ||
f03fc89f | 310 | wxWindow *child = node->GetData(); |
a23fd0e1 | 311 | |
223d09f6 | 312 | wxASSERT_MSG( child, wxT("children list contains empty nodes") ); |
a23fd0e1 | 313 | |
1a77875b | 314 | child->Show(FALSE); |
eb082a08 | 315 | delete child; |
a23fd0e1 VZ |
316 | |
317 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 318 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
319 | } |
320 | ||
321 | return TRUE; | |
322 | } | |
323 | ||
324 | // ---------------------------------------------------------------------------- | |
f68586e5 | 325 | // size/position related methods |
f03fc89f VZ |
326 | // ---------------------------------------------------------------------------- |
327 | ||
328 | // centre the window with respect to its parent in either (or both) directions | |
329 | void wxWindowBase::Centre(int direction) | |
330 | { | |
f6bcfd97 BP |
331 | // the position/size of the parent window or of the entire screen |
332 | wxPoint posParent; | |
f03fc89f VZ |
333 | int widthParent, heightParent; |
334 | ||
f6bcfd97 BP |
335 | wxWindow *parent = NULL; |
336 | ||
337 | if ( !(direction & wxCENTRE_ON_SCREEN) ) | |
f03fc89f | 338 | { |
f6bcfd97 BP |
339 | // find the parent to centre this window on: it should be the |
340 | // immediate parent for the controls but the top level parent for the | |
341 | // top level windows (like dialogs) | |
342 | parent = GetParent(); | |
343 | if ( IsTopLevel() ) | |
344 | { | |
345 | while ( parent && !parent->IsTopLevel() ) | |
346 | { | |
347 | parent = parent->GetParent(); | |
348 | } | |
349 | } | |
350 | ||
351 | // did we find the parent? | |
352 | if ( !parent ) | |
353 | { | |
354 | // no other choice | |
355 | direction |= wxCENTRE_ON_SCREEN; | |
356 | } | |
f03fc89f | 357 | } |
10fcf31a VZ |
358 | |
359 | if ( direction & wxCENTRE_ON_SCREEN ) | |
f03fc89f VZ |
360 | { |
361 | // centre with respect to the whole screen | |
362 | wxDisplaySize(&widthParent, &heightParent); | |
363 | } | |
10fcf31a VZ |
364 | else |
365 | { | |
f6bcfd97 BP |
366 | if ( IsTopLevel() ) |
367 | { | |
368 | // centre on the parent | |
369 | parent->GetSize(&widthParent, &heightParent); | |
370 | ||
371 | // adjust to the parents position | |
372 | posParent = parent->GetPosition(); | |
373 | } | |
374 | else | |
375 | { | |
376 | // centre inside the parents client rectangle | |
377 | parent->GetClientSize(&widthParent, &heightParent); | |
378 | } | |
10fcf31a | 379 | } |
f03fc89f VZ |
380 | |
381 | int width, height; | |
382 | GetSize(&width, &height); | |
383 | ||
c39eda94 VZ |
384 | int xNew = -1, |
385 | yNew = -1; | |
f03fc89f VZ |
386 | |
387 | if ( direction & wxHORIZONTAL ) | |
c39eda94 | 388 | xNew = (widthParent - width)/2; |
f03fc89f VZ |
389 | |
390 | if ( direction & wxVERTICAL ) | |
c39eda94 | 391 | yNew = (heightParent - height)/2; |
f03fc89f | 392 | |
f6bcfd97 BP |
393 | xNew += posParent.x; |
394 | yNew += posParent.y; | |
7631a292 | 395 | |
ef397583 GT |
396 | // Base size of the visible dimensions of the display |
397 | // to take into account the taskbar | |
398 | wxRect rect = wxGetClientDisplayRect(); | |
399 | wxSize size (rect.width,rect.height); | |
400 | ||
401 | if (posParent.x >= 0) // if parent is on the main display | |
402 | { | |
403 | if (xNew < 0) | |
404 | xNew = 0; | |
405 | else if (xNew+width > size.x) | |
406 | xNew = size.x-width-1; | |
407 | } | |
408 | if (posParent.y >= 0) // if parent is on the main display | |
409 | { | |
410 | if (yNew+height > size.y) | |
411 | yNew = size.y-height-1; | |
412 | ||
413 | // Make certain that the title bar is initially visible | |
414 | // always, even if this would push the bottom of the | |
415 | // dialog of the visible area of the display | |
416 | if (yNew < 0) | |
417 | yNew = 0; | |
418 | } | |
419 | ||
0fff366e VZ |
420 | // move the window to this position (keeping the old size but using |
421 | // SetSize() and not Move() to allow xNew and/or yNew to be -1) | |
db89aa76 | 422 | SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE); |
7631a292 RD |
423 | } |
424 | ||
f03fc89f VZ |
425 | // fits the window around the children |
426 | void wxWindowBase::Fit() | |
427 | { | |
f68586e5 VZ |
428 | if ( GetChildren().GetCount() > 0 ) |
429 | { | |
ba81034d VZ |
430 | wxSize size = DoGetBestSize(); |
431 | ||
432 | // for compatibility with the old versions and because it really looks | |
433 | // slightly more pretty like this, add a pad | |
434 | size.x += 7; | |
435 | size.y += 14; | |
436 | ||
437 | SetClientSize(size); | |
f68586e5 VZ |
438 | } |
439 | //else: do nothing if we have no children | |
440 | } | |
f03fc89f | 441 | |
f68586e5 VZ |
442 | // return the size best suited for the current window |
443 | wxSize wxWindowBase::DoGetBestSize() const | |
444 | { | |
445 | if ( GetChildren().GetCount() > 0 ) | |
f03fc89f | 446 | { |
f68586e5 VZ |
447 | // our minimal acceptable size is such that all our windows fit inside |
448 | int maxX = 0, | |
449 | maxY = 0; | |
450 | ||
451 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
452 | node; | |
453 | node = node->GetNext() ) | |
42e69d6b | 454 | { |
f68586e5 | 455 | wxWindow *win = node->GetData(); |
1e6feb95 VZ |
456 | if ( win->IsTopLevel() |
457 | #if wxUSE_STATUSBAR | |
458 | || wxDynamicCast(win, wxStatusBar) | |
459 | #endif // wxUSE_STATUSBAR | |
460 | ) | |
f68586e5 VZ |
461 | { |
462 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
463 | // don't deal with them here; as for the status bars, they |
464 | // don't lie in the client area at all | |
f68586e5 VZ |
465 | continue; |
466 | } | |
467 | ||
468 | int wx, wy, ww, wh; | |
469 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
470 | |
471 | // if the window hadn't been positioned yet, assume that it is in | |
472 | // the origin | |
473 | if ( wx == -1 ) | |
474 | wx = 0; | |
475 | if ( wy == -1 ) | |
476 | wy = 0; | |
477 | ||
f68586e5 VZ |
478 | win->GetSize(&ww, &wh); |
479 | if ( wx + ww > maxX ) | |
480 | maxX = wx + ww; | |
481 | if ( wy + wh > maxY ) | |
482 | maxY = wy + wh; | |
42e69d6b VZ |
483 | } |
484 | ||
ba81034d | 485 | return wxSize(maxX, maxY); |
f68586e5 VZ |
486 | } |
487 | else | |
488 | { | |
489 | // for a generic window there is no natural best size - just use the | |
490 | // current one | |
491 | return GetSize(); | |
f03fc89f | 492 | } |
f03fc89f VZ |
493 | } |
494 | ||
1e6feb95 VZ |
495 | // by default the origin is not shifted |
496 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
497 | { | |
498 | return wxPoint(0, 0); | |
499 | } | |
500 | ||
f03fc89f | 501 | // set the min/max size of the window |
f03fc89f VZ |
502 | void wxWindowBase::SetSizeHints(int minW, int minH, |
503 | int maxW, int maxH, | |
504 | int WXUNUSED(incW), int WXUNUSED(incH)) | |
505 | { | |
506 | m_minWidth = minW; | |
507 | m_maxWidth = maxW; | |
508 | m_minHeight = minH; | |
509 | m_maxHeight = maxH; | |
510 | } | |
511 | ||
512 | // ---------------------------------------------------------------------------- | |
513 | // show/hide/enable/disable the window | |
514 | // ---------------------------------------------------------------------------- | |
515 | ||
516 | bool wxWindowBase::Show(bool show) | |
517 | { | |
518 | if ( show != m_isShown ) | |
519 | { | |
520 | m_isShown = show; | |
521 | ||
522 | return TRUE; | |
523 | } | |
524 | else | |
525 | { | |
526 | return FALSE; | |
527 | } | |
528 | } | |
529 | ||
530 | bool wxWindowBase::Enable(bool enable) | |
531 | { | |
532 | if ( enable != m_isEnabled ) | |
533 | { | |
534 | m_isEnabled = enable; | |
535 | ||
536 | return TRUE; | |
537 | } | |
538 | else | |
539 | { | |
540 | return FALSE; | |
541 | } | |
542 | } | |
34636400 VZ |
543 | // ---------------------------------------------------------------------------- |
544 | // RTTI | |
545 | // ---------------------------------------------------------------------------- | |
546 | ||
547 | bool wxWindowBase::IsTopLevel() const | |
548 | { | |
8487f887 | 549 | return FALSE; |
34636400 | 550 | } |
f03fc89f VZ |
551 | |
552 | // ---------------------------------------------------------------------------- | |
553 | // reparenting the window | |
554 | // ---------------------------------------------------------------------------- | |
555 | ||
556 | void wxWindowBase::AddChild(wxWindowBase *child) | |
557 | { | |
223d09f6 | 558 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 559 | |
f6bcfd97 BP |
560 | // this should never happen and it will lead to a crash later if it does |
561 | // because RemoveChild() will remove only one node from the children list | |
562 | // and the other(s) one(s) will be left with dangling pointers in them | |
563 | wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") ); | |
564 | ||
f03fc89f VZ |
565 | GetChildren().Append(child); |
566 | child->SetParent(this); | |
567 | } | |
568 | ||
569 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
570 | { | |
223d09f6 | 571 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f VZ |
572 | |
573 | GetChildren().DeleteObject(child); | |
574 | child->SetParent((wxWindow *)NULL); | |
575 | } | |
439b3bf1 | 576 | |
f03fc89f VZ |
577 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
578 | { | |
579 | wxWindow *oldParent = GetParent(); | |
580 | if ( newParent == oldParent ) | |
581 | { | |
582 | // nothing done | |
583 | return FALSE; | |
584 | } | |
585 | ||
586 | // unlink this window from the existing parent. | |
587 | if ( oldParent ) | |
588 | { | |
589 | oldParent->RemoveChild(this); | |
590 | } | |
591 | else | |
592 | { | |
593 | wxTopLevelWindows.DeleteObject(this); | |
594 | } | |
595 | ||
596 | // add it to the new one | |
597 | if ( newParent ) | |
598 | { | |
599 | newParent->AddChild(this); | |
600 | } | |
601 | else | |
602 | { | |
603 | wxTopLevelWindows.Append(this); | |
604 | } | |
605 | ||
606 | return TRUE; | |
607 | } | |
608 | ||
609 | // ---------------------------------------------------------------------------- | |
610 | // event handler stuff | |
611 | // ---------------------------------------------------------------------------- | |
612 | ||
613 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
614 | { | |
615 | handler->SetNextHandler(GetEventHandler()); | |
616 | SetEventHandler(handler); | |
617 | } | |
618 | ||
619 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
620 | { | |
621 | wxEvtHandler *handlerA = GetEventHandler(); | |
622 | if ( handlerA ) | |
623 | { | |
624 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
625 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
626 | SetEventHandler(handlerB); | |
627 | if ( deleteHandler ) | |
628 | { | |
629 | delete handlerA; | |
630 | handlerA = (wxEvtHandler *)NULL; | |
631 | } | |
632 | } | |
633 | ||
634 | return handlerA; | |
635 | } | |
636 | ||
637 | // ---------------------------------------------------------------------------- | |
638 | // cursors, fonts &c | |
639 | // ---------------------------------------------------------------------------- | |
640 | ||
641 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) | |
642 | { | |
643 | if ( !colour.Ok() || (colour == m_backgroundColour) ) | |
644 | return FALSE; | |
645 | ||
646 | m_backgroundColour = colour; | |
647 | ||
648 | return TRUE; | |
649 | } | |
650 | ||
651 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
652 | { | |
653 | if ( !colour.Ok() || (colour == m_foregroundColour) ) | |
654 | return FALSE; | |
655 | ||
656 | m_foregroundColour = colour; | |
657 | ||
658 | return TRUE; | |
659 | } | |
660 | ||
661 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
662 | { | |
8a9c2246 VZ |
663 | // setting an invalid cursor is ok, it means that we don't have any special |
664 | // cursor | |
13588544 | 665 | if ( m_cursor == cursor ) |
f03fc89f VZ |
666 | { |
667 | // no change | |
668 | return FALSE; | |
669 | } | |
670 | ||
8a9c2246 | 671 | m_cursor = cursor; |
f03fc89f VZ |
672 | |
673 | return TRUE; | |
674 | } | |
675 | ||
676 | bool wxWindowBase::SetFont(const wxFont& font) | |
677 | { | |
678 | // don't try to set invalid font, always fall back to the default | |
679 | const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT; | |
680 | ||
8bf30fe9 | 681 | if ( fontOk == m_font ) |
f03fc89f VZ |
682 | { |
683 | // no change | |
684 | return FALSE; | |
685 | } | |
686 | ||
687 | m_font = fontOk; | |
688 | ||
689 | return TRUE; | |
690 | } | |
691 | ||
789295bf VZ |
692 | #if wxUSE_CARET |
693 | void wxWindowBase::SetCaret(wxCaret *caret) | |
694 | { | |
695 | if ( m_caret ) | |
696 | { | |
697 | delete m_caret; | |
698 | } | |
699 | ||
700 | m_caret = caret; | |
701 | ||
702 | if ( m_caret ) | |
703 | { | |
704 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 705 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
706 | } |
707 | } | |
708 | #endif // wxUSE_CARET | |
709 | ||
88ac883a | 710 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
711 | // ---------------------------------------------------------------------------- |
712 | // validators | |
713 | // ---------------------------------------------------------------------------- | |
714 | ||
715 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
716 | { | |
717 | if ( m_windowValidator ) | |
718 | delete m_windowValidator; | |
719 | ||
720 | m_windowValidator = (wxValidator *)validator.Clone(); | |
721 | ||
722 | if ( m_windowValidator ) | |
723 | m_windowValidator->SetWindow(this) ; | |
724 | } | |
88ac883a | 725 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
726 | |
727 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 728 | // update region stuff |
f03fc89f VZ |
729 | // ---------------------------------------------------------------------------- |
730 | ||
1e6feb95 VZ |
731 | wxRect wxWindowBase::GetUpdateClientRect() const |
732 | { | |
733 | wxRegion rgnUpdate = GetUpdateRegion(); | |
734 | rgnUpdate.Intersect(GetClientRect()); | |
735 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
736 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
737 | rectUpdate.x -= ptOrigin.x; | |
738 | rectUpdate.y -= ptOrigin.y; | |
739 | ||
740 | return rectUpdate; | |
741 | } | |
742 | ||
f03fc89f VZ |
743 | bool wxWindowBase::IsExposed(int x, int y) const |
744 | { | |
745 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
746 | } | |
747 | ||
748 | bool wxWindowBase::IsExposed(int x, int y, int w, int h) const | |
749 | { | |
750 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
751 | } | |
752 | ||
753 | // ---------------------------------------------------------------------------- | |
754 | // find window by id or name | |
755 | // ---------------------------------------------------------------------------- | |
756 | ||
757 | wxWindow *wxWindowBase::FindWindow( long id ) | |
758 | { | |
759 | if ( id == m_windowId ) | |
760 | return (wxWindow *)this; | |
761 | ||
762 | wxWindowBase *res = (wxWindow *)NULL; | |
763 | wxWindowList::Node *node; | |
764 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
765 | { | |
766 | wxWindowBase *child = node->GetData(); | |
767 | res = child->FindWindow( id ); | |
768 | } | |
769 | ||
770 | return (wxWindow *)res; | |
771 | } | |
772 | ||
773 | wxWindow *wxWindowBase::FindWindow( const wxString& name ) | |
774 | { | |
775 | if ( name == m_windowName ) | |
776 | return (wxWindow *)this; | |
777 | ||
778 | wxWindowBase *res = (wxWindow *)NULL; | |
779 | wxWindowList::Node *node; | |
780 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) | |
781 | { | |
782 | wxWindow *child = node->GetData(); | |
783 | res = child->FindWindow(name); | |
784 | } | |
785 | ||
786 | return (wxWindow *)res; | |
787 | } | |
788 | ||
789 | // ---------------------------------------------------------------------------- | |
790 | // dialog oriented functions | |
791 | // ---------------------------------------------------------------------------- | |
792 | ||
34636400 | 793 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 794 | { |
34636400 VZ |
795 | // Disable all other windows |
796 | if ( IsTopLevel() ) | |
797 | { | |
798 | wxWindowList::Node *node = wxTopLevelWindows.GetFirst(); | |
799 | while (node) | |
800 | { | |
801 | wxWindow *win = node->GetData(); | |
802 | if (win != this) | |
803 | win->Enable(!modal); | |
804 | ||
805 | node = node->GetNext(); | |
806 | } | |
807 | } | |
f03fc89f VZ |
808 | } |
809 | ||
810 | bool wxWindowBase::Validate() | |
811 | { | |
88ac883a | 812 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
813 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
814 | ||
f03fc89f VZ |
815 | wxWindowList::Node *node; |
816 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
817 | { | |
818 | wxWindowBase *child = node->GetData(); | |
819 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 820 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f VZ |
821 | { |
822 | return FALSE; | |
823 | } | |
d80cd92a VZ |
824 | |
825 | if ( recurse && !child->Validate() ) | |
826 | { | |
827 | return FALSE; | |
828 | } | |
f03fc89f | 829 | } |
88ac883a | 830 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
831 | |
832 | return TRUE; | |
833 | } | |
834 | ||
835 | bool wxWindowBase::TransferDataToWindow() | |
836 | { | |
88ac883a | 837 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
838 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
839 | ||
f03fc89f VZ |
840 | wxWindowList::Node *node; |
841 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
842 | { | |
843 | wxWindowBase *child = node->GetData(); | |
844 | wxValidator *validator = child->GetValidator(); | |
845 | if ( validator && !validator->TransferToWindow() ) | |
846 | { | |
d80cd92a VZ |
847 | wxLogWarning(_("Could not transfer data to window")); |
848 | wxLog::FlushActive(); | |
f03fc89f VZ |
849 | |
850 | return FALSE; | |
851 | } | |
d80cd92a VZ |
852 | |
853 | if ( recurse ) | |
854 | { | |
a58a12e9 | 855 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
856 | { |
857 | // warning already given | |
858 | return FALSE; | |
859 | } | |
860 | } | |
f03fc89f | 861 | } |
88ac883a | 862 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
863 | |
864 | return TRUE; | |
865 | } | |
866 | ||
867 | bool wxWindowBase::TransferDataFromWindow() | |
868 | { | |
88ac883a | 869 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
870 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
871 | ||
f03fc89f VZ |
872 | wxWindowList::Node *node; |
873 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) | |
874 | { | |
875 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
876 | wxValidator *validator = child->GetValidator(); |
877 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 878 | { |
d80cd92a VZ |
879 | // nop warning here because the application is supposed to give |
880 | // one itself - we don't know here what might have gone wrongly | |
881 | ||
f03fc89f VZ |
882 | return FALSE; |
883 | } | |
d80cd92a VZ |
884 | |
885 | if ( recurse ) | |
886 | { | |
a58a12e9 | 887 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
888 | { |
889 | // warning already given | |
890 | return FALSE; | |
891 | } | |
892 | } | |
f03fc89f | 893 | } |
88ac883a | 894 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
895 | |
896 | return TRUE; | |
897 | } | |
898 | ||
899 | void wxWindowBase::InitDialog() | |
900 | { | |
901 | wxInitDialogEvent event(GetId()); | |
902 | event.SetEventObject( this ); | |
903 | GetEventHandler()->ProcessEvent(event); | |
904 | } | |
905 | ||
906 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
907 | // context-sensitive help support |
908 | // ---------------------------------------------------------------------------- | |
909 | ||
910 | #if wxUSE_HELP | |
911 | ||
912 | // associate this help text with this window | |
913 | void wxWindowBase::SetHelpText(const wxString& text) | |
914 | { | |
915 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
916 | if ( helpProvider ) | |
917 | { | |
918 | helpProvider->AddHelp(this, text); | |
919 | } | |
920 | } | |
921 | ||
922 | // associate this help text with all windows with the same id as this | |
923 | // one | |
924 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
925 | { | |
926 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
927 | if ( helpProvider ) | |
928 | { | |
929 | helpProvider->AddHelp(GetId(), text); | |
930 | } | |
931 | } | |
932 | ||
933 | // get the help string associated with this window (may be empty) | |
934 | wxString wxWindowBase::GetHelpText() const | |
935 | { | |
936 | wxString text; | |
937 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
938 | if ( helpProvider ) | |
939 | { | |
940 | text = helpProvider->GetHelp(this); | |
941 | } | |
942 | ||
943 | return text; | |
944 | } | |
945 | ||
946 | // show help for this window | |
947 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
948 | { | |
949 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
950 | if ( helpProvider ) | |
951 | { | |
952 | if ( helpProvider->ShowHelp(this) ) | |
953 | { | |
954 | // skip the event.Skip() below | |
955 | return; | |
956 | } | |
957 | } | |
958 | ||
959 | event.Skip(); | |
960 | } | |
961 | ||
962 | #endif // wxUSE_HELP | |
963 | ||
964 | // ---------------------------------------------------------------------------- | |
f03fc89f VZ |
965 | // tooltips |
966 | // ---------------------------------------------------------------------------- | |
967 | ||
968 | #if wxUSE_TOOLTIPS | |
969 | ||
970 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
971 | { | |
972 | // don't create the new tooltip if we already have one | |
973 | if ( m_tooltip ) | |
974 | { | |
975 | m_tooltip->SetTip( tip ); | |
976 | } | |
977 | else | |
978 | { | |
979 | SetToolTip( new wxToolTip( tip ) ); | |
980 | } | |
981 | ||
982 | // setting empty tooltip text does not remove the tooltip any more - use | |
983 | // SetToolTip((wxToolTip *)NULL) for this | |
984 | } | |
985 | ||
986 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
987 | { | |
988 | if ( m_tooltip ) | |
989 | delete m_tooltip; | |
990 | ||
991 | m_tooltip = tooltip; | |
992 | } | |
993 | ||
994 | #endif // wxUSE_TOOLTIPS | |
995 | ||
996 | // ---------------------------------------------------------------------------- | |
997 | // constraints and sizers | |
998 | // ---------------------------------------------------------------------------- | |
999 | ||
1000 | #if wxUSE_CONSTRAINTS | |
1001 | ||
1002 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1003 | { | |
1004 | if ( m_constraints ) | |
1005 | { | |
1006 | UnsetConstraints(m_constraints); | |
1007 | delete m_constraints; | |
1008 | } | |
1009 | m_constraints = constraints; | |
1010 | if ( m_constraints ) | |
1011 | { | |
1012 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1013 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1014 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1015 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1016 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1017 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1018 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1019 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1020 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1021 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1022 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1023 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1024 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1025 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1026 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1027 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1028 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1029 | } | |
1030 | } | |
1031 | ||
1032 | // This removes any dangling pointers to this window in other windows' | |
1033 | // constraintsInvolvedIn lists. | |
1034 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1035 | { | |
1036 | if ( c ) | |
1037 | { | |
1038 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1039 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1040 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1041 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1042 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1043 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1044 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1045 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1046 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1047 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1048 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1049 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1050 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1051 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1052 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1053 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | // Back-pointer to other windows we're involved with, so if we delete this | |
1058 | // window, we must delete any constraints we're involved with. | |
1059 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1060 | { | |
1061 | if ( !m_constraintsInvolvedIn ) | |
1062 | m_constraintsInvolvedIn = new wxWindowList; | |
1063 | if ( !m_constraintsInvolvedIn->Find(otherWin) ) | |
1064 | m_constraintsInvolvedIn->Append(otherWin); | |
1065 | } | |
1066 | ||
1067 | // REMOVE back-pointer to other windows we're involved with. | |
1068 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1069 | { | |
1070 | if ( m_constraintsInvolvedIn ) | |
1071 | m_constraintsInvolvedIn->DeleteObject(otherWin); | |
1072 | } | |
1073 | ||
1074 | // Reset any constraints that mention this window | |
1075 | void wxWindowBase::DeleteRelatedConstraints() | |
1076 | { | |
1077 | if ( m_constraintsInvolvedIn ) | |
1078 | { | |
1079 | wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst(); | |
1080 | while (node) | |
1081 | { | |
1082 | wxWindow *win = node->GetData(); | |
1083 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1084 | ||
1085 | // Reset any constraints involving this window | |
1086 | if ( constr ) | |
1087 | { | |
1088 | constr->left.ResetIfWin(this); | |
1089 | constr->top.ResetIfWin(this); | |
1090 | constr->right.ResetIfWin(this); | |
1091 | constr->bottom.ResetIfWin(this); | |
1092 | constr->width.ResetIfWin(this); | |
1093 | constr->height.ResetIfWin(this); | |
1094 | constr->centreX.ResetIfWin(this); | |
1095 | constr->centreY.ResetIfWin(this); | |
1096 | } | |
1097 | ||
1098 | wxWindowList::Node *next = node->GetNext(); | |
1099 | delete node; | |
1100 | node = next; | |
1101 | } | |
1102 | ||
1103 | delete m_constraintsInvolvedIn; | |
1104 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
1105 | } | |
1106 | } | |
1107 | ||
1108 | void wxWindowBase::SetSizer(wxSizer *sizer) | |
1109 | { | |
3417c2cd RR |
1110 | if (m_windowSizer) delete m_windowSizer; |
1111 | ||
f03fc89f | 1112 | m_windowSizer = sizer; |
f03fc89f VZ |
1113 | } |
1114 | ||
1115 | bool wxWindowBase::Layout() | |
1116 | { | |
3417c2cd | 1117 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
1118 | if ( GetSizer() ) |
1119 | { | |
f1df0927 VZ |
1120 | int w, h; |
1121 | GetClientSize(&w, &h); | |
1122 | ||
3417c2cd | 1123 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 1124 | } |
f1df0927 | 1125 | else |
f03fc89f | 1126 | { |
4b7f2165 VZ |
1127 | wxLayoutConstraints *constr = GetConstraints(); |
1128 | bool wasOk = constr && constr->AreSatisfied(); | |
1129 | ||
f1df0927 | 1130 | ResetConstraints(); // Mark all constraints as unevaluated |
4b7f2165 VZ |
1131 | |
1132 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
1133 | // own constraints will never be satisfied any more unless we do it | |
1134 | // here | |
1135 | if ( wasOk ) | |
1136 | { | |
1137 | int noChanges = 1; | |
1138 | while ( noChanges > 0 ) | |
1139 | { | |
1140 | constr->SatisfyConstraints(this, &noChanges); | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | DoPhase(1); // Layout children | |
1145 | DoPhase(2); // Layout grand children | |
f1df0927 | 1146 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 1147 | } |
5d4b632b | 1148 | |
f03fc89f VZ |
1149 | return TRUE; |
1150 | } | |
1151 | ||
1152 | ||
1153 | // Do a phase of evaluating constraints: the default behaviour. wxSizers may | |
1154 | // do a similar thing, but also impose their own 'constraints' and order the | |
1155 | // evaluation differently. | |
1156 | bool wxWindowBase::LayoutPhase1(int *noChanges) | |
1157 | { | |
1158 | wxLayoutConstraints *constr = GetConstraints(); | |
1159 | if ( constr ) | |
1160 | { | |
1161 | return constr->SatisfyConstraints(this, noChanges); | |
1162 | } | |
1163 | else | |
1164 | return TRUE; | |
1165 | } | |
1166 | ||
1167 | bool wxWindowBase::LayoutPhase2(int *noChanges) | |
1168 | { | |
1169 | *noChanges = 0; | |
1170 | ||
1171 | // Layout children | |
1172 | DoPhase(1); | |
1173 | DoPhase(2); | |
1174 | return TRUE; | |
1175 | } | |
1176 | ||
1177 | // Do a phase of evaluating child constraints | |
1178 | bool wxWindowBase::DoPhase(int phase) | |
1179 | { | |
1180 | int noIterations = 0; | |
1181 | int maxIterations = 500; | |
1182 | int noChanges = 1; | |
1183 | int noFailures = 0; | |
1184 | wxWindowList succeeded; | |
1185 | while ((noChanges > 0) && (noIterations < maxIterations)) | |
1186 | { | |
1187 | noChanges = 0; | |
1188 | noFailures = 0; | |
1189 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1190 | while (node) | |
1191 | { | |
1192 | wxWindow *child = node->GetData(); | |
34636400 | 1193 | if ( !child->IsTopLevel() ) |
f03fc89f VZ |
1194 | { |
1195 | wxLayoutConstraints *constr = child->GetConstraints(); | |
1196 | if ( constr ) | |
1197 | { | |
1198 | if ( !succeeded.Find(child) ) | |
1199 | { | |
1200 | int tempNoChanges = 0; | |
1201 | bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ; | |
1202 | noChanges += tempNoChanges; | |
1203 | if ( success ) | |
1204 | { | |
1205 | succeeded.Append(child); | |
1206 | } | |
1207 | } | |
1208 | } | |
1209 | } | |
1210 | node = node->GetNext(); | |
1211 | } | |
1212 | ||
1213 | noIterations++; | |
1214 | } | |
1215 | ||
1216 | return TRUE; | |
1217 | } | |
1218 | ||
1219 | void wxWindowBase::ResetConstraints() | |
1220 | { | |
1221 | wxLayoutConstraints *constr = GetConstraints(); | |
1222 | if ( constr ) | |
1223 | { | |
1224 | constr->left.SetDone(FALSE); | |
1225 | constr->top.SetDone(FALSE); | |
1226 | constr->right.SetDone(FALSE); | |
1227 | constr->bottom.SetDone(FALSE); | |
1228 | constr->width.SetDone(FALSE); | |
1229 | constr->height.SetDone(FALSE); | |
1230 | constr->centreX.SetDone(FALSE); | |
1231 | constr->centreY.SetDone(FALSE); | |
1232 | } | |
f1df0927 | 1233 | |
f03fc89f VZ |
1234 | wxWindowList::Node *node = GetChildren().GetFirst(); |
1235 | while (node) | |
1236 | { | |
1237 | wxWindow *win = node->GetData(); | |
34636400 | 1238 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1239 | win->ResetConstraints(); |
1240 | node = node->GetNext(); | |
1241 | } | |
1242 | } | |
1243 | ||
1244 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1245 | // and setting the real values. | |
1246 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1247 | { | |
1248 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 1249 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
1250 | { |
1251 | int x = constr->left.GetValue(); | |
1252 | int y = constr->top.GetValue(); | |
1253 | int w = constr->width.GetValue(); | |
1254 | int h = constr->height.GetValue(); | |
1255 | ||
f03fc89f | 1256 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 1257 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 1258 | { |
3417c2cd | 1259 | SetSize(x, y, w, h); |
f03fc89f VZ |
1260 | } |
1261 | else | |
1262 | { | |
3417c2cd RR |
1263 | // If we don't want to resize this window, just move it... |
1264 | Move(x, y); | |
f03fc89f VZ |
1265 | } |
1266 | } | |
1267 | else if ( constr ) | |
1268 | { | |
4b7f2165 | 1269 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 1270 | GetClassInfo()->GetClassName(), |
4b7f2165 | 1271 | GetName().c_str()); |
f03fc89f VZ |
1272 | } |
1273 | ||
1274 | if ( recurse ) | |
1275 | { | |
1276 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1277 | while (node) | |
1278 | { | |
1279 | wxWindow *win = node->GetData(); | |
34636400 | 1280 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1281 | win->SetConstraintSizes(); |
1282 | node = node->GetNext(); | |
1283 | } | |
1284 | } | |
1285 | } | |
1286 | ||
f03fc89f VZ |
1287 | // Only set the size/position of the constraint (if any) |
1288 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
1289 | { | |
1290 | wxLayoutConstraints *constr = GetConstraints(); | |
1291 | if ( constr ) | |
1292 | { | |
1293 | if ( x != -1 ) | |
1294 | { | |
1295 | constr->left.SetValue(x); | |
1296 | constr->left.SetDone(TRUE); | |
1297 | } | |
1298 | if ( y != -1 ) | |
1299 | { | |
1300 | constr->top.SetValue(y); | |
1301 | constr->top.SetDone(TRUE); | |
1302 | } | |
1303 | if ( w != -1 ) | |
1304 | { | |
1305 | constr->width.SetValue(w); | |
1306 | constr->width.SetDone(TRUE); | |
1307 | } | |
1308 | if ( h != -1 ) | |
1309 | { | |
1310 | constr->height.SetValue(h); | |
1311 | constr->height.SetDone(TRUE); | |
1312 | } | |
1313 | } | |
1314 | } | |
1315 | ||
1316 | void wxWindowBase::MoveConstraint(int x, int y) | |
1317 | { | |
1318 | wxLayoutConstraints *constr = GetConstraints(); | |
1319 | if ( constr ) | |
1320 | { | |
1321 | if ( x != -1 ) | |
1322 | { | |
1323 | constr->left.SetValue(x); | |
1324 | constr->left.SetDone(TRUE); | |
1325 | } | |
1326 | if ( y != -1 ) | |
1327 | { | |
1328 | constr->top.SetValue(y); | |
1329 | constr->top.SetDone(TRUE); | |
1330 | } | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
1335 | { | |
1336 | wxLayoutConstraints *constr = GetConstraints(); | |
1337 | if ( constr ) | |
1338 | { | |
1339 | *w = constr->width.GetValue(); | |
1340 | *h = constr->height.GetValue(); | |
1341 | } | |
1342 | else | |
1343 | GetSize(w, h); | |
1344 | } | |
1345 | ||
1346 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
1347 | { | |
1348 | wxLayoutConstraints *constr = GetConstraints(); | |
1349 | if ( constr ) | |
1350 | { | |
1351 | *w = constr->width.GetValue(); | |
1352 | *h = constr->height.GetValue(); | |
1353 | } | |
1354 | else | |
1355 | GetClientSize(w, h); | |
1356 | } | |
1357 | ||
1358 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const | |
1359 | { | |
1360 | wxLayoutConstraints *constr = GetConstraints(); | |
1361 | if ( constr ) | |
1362 | { | |
1363 | *x = constr->left.GetValue(); | |
1364 | *y = constr->top.GetValue(); | |
1365 | } | |
1366 | else | |
1367 | GetPosition(x, y); | |
1368 | } | |
1369 | ||
1370 | #endif // wxUSE_CONSTRAINTS | |
1371 | ||
1372 | // ---------------------------------------------------------------------------- | |
1373 | // do Update UI processing for child controls | |
1374 | // ---------------------------------------------------------------------------- | |
7ec1983b VZ |
1375 | |
1376 | // TODO: should this be implemented for the child window rather | |
1377 | // than the parent? Then you can override it e.g. for wxCheckBox | |
1378 | // to do the Right Thing rather than having to assume a fixed number | |
1379 | // of control classes. | |
f03fc89f | 1380 | void wxWindowBase::UpdateWindowUI() |
7ec1983b | 1381 | { |
1e6feb95 | 1382 | #if wxUSE_CONTROLS |
26bf1ce0 VZ |
1383 | wxUpdateUIEvent event(GetId()); |
1384 | event.m_eventObject = this; | |
1385 | ||
1386 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 1387 | { |
26bf1ce0 VZ |
1388 | if ( event.GetSetEnabled() ) |
1389 | Enable(event.GetEnabled()); | |
7ec1983b | 1390 | |
26bf1ce0 | 1391 | if ( event.GetSetText() ) |
f03fc89f | 1392 | { |
f7637829 | 1393 | wxControl *control = wxDynamicCastThis(wxControl); |
26bf1ce0 | 1394 | if ( control ) |
34636400 | 1395 | { |
1e6feb95 | 1396 | #if wxUSE_TEXTCTRL |
26bf1ce0 VZ |
1397 | wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl); |
1398 | if ( text ) | |
1399 | text->SetValue(event.GetText()); | |
1400 | else | |
1e6feb95 | 1401 | #endif // wxUSE_TEXTCTRL |
34636400 VZ |
1402 | control->SetLabel(event.GetText()); |
1403 | } | |
26bf1ce0 | 1404 | } |
f03fc89f | 1405 | |
88ac883a | 1406 | #if wxUSE_CHECKBOX |
f7637829 | 1407 | wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox); |
26bf1ce0 VZ |
1408 | if ( checkbox ) |
1409 | { | |
1410 | if ( event.GetSetChecked() ) | |
1411 | checkbox->SetValue(event.GetChecked()); | |
1412 | } | |
88ac883a VZ |
1413 | #endif // wxUSE_CHECKBOX |
1414 | ||
b3402d0d | 1415 | #if wxUSE_RADIOBTN |
f7637829 | 1416 | wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton); |
26bf1ce0 VZ |
1417 | if ( radiobtn ) |
1418 | { | |
1419 | if ( event.GetSetChecked() ) | |
1420 | radiobtn->SetValue(event.GetChecked()); | |
f03fc89f | 1421 | } |
b3402d0d | 1422 | #endif // wxUSE_RADIOBTN |
7ec1983b | 1423 | } |
1e6feb95 | 1424 | #endif // wxUSE_CONTROLS |
7ec1983b | 1425 | } |
fd71308f | 1426 | |
f03fc89f VZ |
1427 | // ---------------------------------------------------------------------------- |
1428 | // dialog units translations | |
1429 | // ---------------------------------------------------------------------------- | |
1430 | ||
1431 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
1432 | { |
1433 | int charWidth = GetCharWidth(); | |
1434 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1435 | wxPoint pt2(-1, -1); |
1436 | if (pt.x != -1) | |
1437 | pt2.x = (int) ((pt.x * 4) / charWidth) ; | |
1438 | if (pt.y != -1) | |
1439 | pt2.y = (int) ((pt.y * 8) / charHeight) ; | |
fd71308f JS |
1440 | |
1441 | return pt2; | |
1442 | } | |
1443 | ||
f03fc89f | 1444 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
1445 | { |
1446 | int charWidth = GetCharWidth(); | |
1447 | int charHeight = GetCharHeight(); | |
5d9c2818 RD |
1448 | wxPoint pt2(-1, -1); |
1449 | if (pt.x != -1) | |
1450 | pt2.x = (int) ((pt.x * charWidth) / 4) ; | |
1451 | if (pt.y != -1) | |
1452 | pt2.y = (int) ((pt.y * charHeight) / 8) ; | |
fd71308f JS |
1453 | |
1454 | return pt2; | |
1455 | } | |
1456 | ||
8d99be5f VZ |
1457 | // ---------------------------------------------------------------------------- |
1458 | // client data | |
1459 | // ---------------------------------------------------------------------------- | |
1460 | ||
1461 | void wxWindowBase::DoSetClientObject( wxClientData *data ) | |
1462 | { | |
1e6feb95 | 1463 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, |
223d09f6 | 1464 | wxT("can't have both object and void client data") ); |
8d99be5f VZ |
1465 | |
1466 | if ( m_clientObject ) | |
1467 | delete m_clientObject; | |
1468 | ||
1469 | m_clientObject = data; | |
1e6feb95 | 1470 | m_clientDataType = wxClientData_Object; |
8d99be5f VZ |
1471 | } |
1472 | ||
1473 | wxClientData *wxWindowBase::DoGetClientObject() const | |
1474 | { | |
0d7ea902 VZ |
1475 | // it's not an error to call GetClientObject() on a window which doesn't |
1476 | // have client data at all - NULL will be returned | |
1e6feb95 | 1477 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, |
223d09f6 | 1478 | wxT("this window doesn't have object client data") ); |
8d99be5f VZ |
1479 | |
1480 | return m_clientObject; | |
1481 | } | |
1482 | ||
1483 | void wxWindowBase::DoSetClientData( void *data ) | |
1484 | { | |
1e6feb95 | 1485 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, |
223d09f6 | 1486 | wxT("can't have both object and void client data") ); |
8d99be5f VZ |
1487 | |
1488 | m_clientData = data; | |
1e6feb95 | 1489 | m_clientDataType = wxClientData_Void; |
8d99be5f VZ |
1490 | } |
1491 | ||
1492 | void *wxWindowBase::DoGetClientData() const | |
1493 | { | |
0d7ea902 VZ |
1494 | // it's not an error to call GetClientData() on a window which doesn't have |
1495 | // client data at all - NULL will be returned | |
1e6feb95 | 1496 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, |
223d09f6 | 1497 | wxT("this window doesn't have void client data") ); |
8d99be5f VZ |
1498 | |
1499 | return m_clientData; | |
1500 | } | |
1501 | ||
f03fc89f VZ |
1502 | // ---------------------------------------------------------------------------- |
1503 | // event handlers | |
1504 | // ---------------------------------------------------------------------------- | |
1505 | ||
1506 | // propagate the colour change event to the subwindows | |
1507 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
1508 | { | |
1509 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1510 | while ( node ) | |
1511 | { | |
1512 | // Only propagate to non-top-level windows | |
1513 | wxWindow *win = node->GetData(); | |
1514 | if ( !win->IsTopLevel() ) | |
1515 | { | |
1516 | wxSysColourChangedEvent event2; | |
1517 | event.m_eventObject = win; | |
1518 | win->GetEventHandler()->ProcessEvent(event2); | |
1519 | } | |
1520 | ||
1521 | node = node->GetNext(); | |
1522 | } | |
1523 | } | |
1524 | ||
1525 | // the default action is to populate dialog with data when it's created | |
1526 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) | |
1527 | { | |
1528 | TransferDataToWindow(); | |
1529 | } | |
1530 | ||
a02dc3e3 VZ |
1531 | // process Ctrl-Alt-mclick |
1532 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) | |
1533 | { | |
1e6feb95 | 1534 | #if wxUSE_MSGDLG |
a02dc3e3 VZ |
1535 | if ( event.ControlDown() && event.AltDown() ) |
1536 | { | |
1537 | // don't translate these strings | |
1538 | wxString port; | |
1539 | switch ( wxGetOsVersion() ) | |
1540 | { | |
1541 | case wxMOTIF_X: port = _T("Motif"); break; | |
1542 | case wxMACINTOSH: port = _T("Mac"); break; | |
1543 | case wxBEOS: port = _T("BeOS"); break; | |
1544 | case wxGTK: | |
1545 | case wxGTK_WIN32: | |
1546 | case wxGTK_OS2: | |
1547 | case wxGTK_BEOS: port = _T("GTK"); break; | |
1548 | case wxWINDOWS: | |
1549 | case wxPENWINDOWS: | |
1550 | case wxWINDOWS_NT: | |
1551 | case wxWIN32S: | |
1552 | case wxWIN95: | |
1553 | case wxWIN386: port = _T("MS Windows"); break; | |
1554 | case wxMGL_UNIX: | |
1555 | case wxMGL_X: | |
1556 | case wxMGL_WIN32: | |
1557 | case wxMGL_OS2: port = _T("MGL"); break; | |
1558 | case wxWINDOWS_OS2: | |
1559 | case wxOS2_PM: port = _T("OS/2"); break; | |
1560 | default: port = _T("unknown"); break; | |
1561 | } | |
1562 | ||
1563 | wxMessageBox(wxString::Format( | |
1564 | _T( | |
f6bcfd97 | 1565 | " wxWindows Library (%s port)\nVersion %u.%u.%u, compiled at %s %s\n Copyright (c) 1995-2000 wxWindows team" |
a02dc3e3 VZ |
1566 | ), |
1567 | port.c_str(), | |
1568 | wxMAJOR_VERSION, | |
1569 | wxMINOR_VERSION, | |
1570 | wxRELEASE_NUMBER, | |
1571 | __DATE__, | |
1572 | __TIME__ | |
1573 | ), | |
1574 | _T("wxWindows information"), | |
1575 | wxICON_INFORMATION | wxOK, | |
1576 | (wxWindow *)this); | |
1577 | } | |
1578 | else | |
1e6feb95 | 1579 | #endif // wxUSE_MSGDLG |
a02dc3e3 VZ |
1580 | { |
1581 | event.Skip(); | |
1582 | } | |
1583 | } | |
1584 | ||
f03fc89f VZ |
1585 | // ---------------------------------------------------------------------------- |
1586 | // list classes implementation | |
1587 | // ---------------------------------------------------------------------------- | |
1588 | ||
1589 | void wxWindowListNode::DeleteData() | |
1590 | { | |
1591 | delete (wxWindow *)GetData(); | |
1592 | } | |
1593 | ||
1e6feb95 VZ |
1594 | // ---------------------------------------------------------------------------- |
1595 | // borders | |
1596 | // ---------------------------------------------------------------------------- | |
1597 | ||
1598 | wxBorder wxWindowBase::GetBorder() const | |
1599 | { | |
1600 | wxBorder border = (wxBorder)(m_windowStyle & wxBORDER_MASK); | |
1601 | if ( border == wxBORDER_DEFAULT ) | |
1602 | { | |
1603 | border = GetDefaultBorder(); | |
1604 | } | |
1605 | ||
1606 | return border; | |
1607 | } | |
1608 | ||
1609 | wxBorder wxWindowBase::GetDefaultBorder() const | |
1610 | { | |
1611 | return wxBORDER_NONE; | |
1612 | } | |
1613 | ||
1614 | // ---------------------------------------------------------------------------- | |
1615 | // hit testing | |
1616 | // ---------------------------------------------------------------------------- | |
1617 | ||
1618 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
1619 | { | |
1620 | // here we just check if the point is inside the window or not | |
1621 | ||
1622 | // check the top and left border first | |
1623 | bool outside = x < 0 || y < 0; | |
1624 | if ( !outside ) | |
1625 | { | |
1626 | // check the right and bottom borders too | |
1627 | wxSize size = GetSize(); | |
1628 | outside = x >= size.x || y >= size.y; | |
1629 | } | |
1630 | ||
1631 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
1632 | } | |
1633 |