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