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