]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
Fixed a rare wxAuiFloatingFrame dtor crash on MSW using a registration mechanism...
[wxWidgets.git] / src / common / wincmn.cpp
CommitLineData
7ec1983b 1/////////////////////////////////////////////////////////////////////////////
7ec69821 2// Name: src/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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
7ec1983b
VZ
10/////////////////////////////////////////////////////////////////////////////
11
f03fc89f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
f701d7ab 19
341287bf
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
f701d7ab 23#ifdef __BORLANDC__
f03fc89f 24 #pragma hdrstop
f701d7ab
JS
25#endif
26
f03fc89f
VZ
27#ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/log.h"
30 #include "wx/intl.h"
31 #include "wx/frame.h"
f03fc89f 32 #include "wx/window.h"
1e6feb95 33 #include "wx/control.h"
f03fc89f
VZ
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
106844da 36 #include "wx/statbox.h"
26bf1ce0 37 #include "wx/textctrl.h"
f03fc89f
VZ
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
a02dc3e3 40 #include "wx/msgdlg.h"
a37a5a73 41 #include "wx/statusbr.h"
e0cf3745 42 #include "wx/toolbar.h"
ed39ff57 43 #include "wx/dcclient.h"
7d59475e 44 #include "wx/scrolbar.h"
f03fc89f 45 #include "wx/layout.h"
ed2fbeb8 46 #include "wx/sizer.h"
8515098c 47 #include "wx/menu.h"
ed2fbeb8 48#endif //WX_PRECOMP
461e93f9 49
f03fc89f
VZ
50#if wxUSE_DRAG_AND_DROP
51 #include "wx/dnd.h"
52#endif // wxUSE_DRAG_AND_DROP
53
ed5317e5 54#if wxUSE_ACCESSIBILITY
7de59551 55 #include "wx/access.h"
ed5317e5
JS
56#endif
57
bd83cb56
VZ
58#if wxUSE_HELP
59 #include "wx/cshelp.h"
60#endif // wxUSE_HELP
61
f03fc89f
VZ
62#if wxUSE_TOOLTIPS
63 #include "wx/tooltip.h"
64#endif // wxUSE_TOOLTIPS
65
789295bf
VZ
66#if wxUSE_CARET
67 #include "wx/caret.h"
68#endif // wxUSE_CARET
69
ff9f7a12 70#if wxUSE_SYSTEM_OPTIONS
cab1a605 71 #include "wx/sysopt.h"
ff9f7a12
SC
72#endif
73
0118b60b 74// For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
c1da5058 75// The gtk includes don't pull any other headers in, at least not on my system - MR
0118b60b 76#ifdef __WXGTK__
6ef708cd
PC
77 #ifdef __WXGTK20__
78 #include <gtk/gtkversion.h>
79 #else
80 #include <gtk/gtkfeatures.h>
81 #endif
0118b60b
MR
82#endif
83
8bb6b2c0
VZ
84#include "wx/platinfo.h"
85
e7445ff8
PC
86// Windows List
87WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
88
eeb0bee1 89// globals
8bb08801 90#if wxUSE_MENUS
eeb0bee1 91wxMenu *wxCurrentPopupMenu = NULL;
8bb08801 92#endif // wxUSE_MENUS
eeb0bee1 93
f03fc89f
VZ
94// ----------------------------------------------------------------------------
95// static data
96// ----------------------------------------------------------------------------
97
f03fc89f
VZ
98
99IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
100
101// ----------------------------------------------------------------------------
102// event table
103// ----------------------------------------------------------------------------
104
105BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
106 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
107 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
a02dc3e3 108 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
bd83cb56
VZ
109
110#if wxUSE_HELP
e11f4636 111 EVT_HELP(wxID_ANY, wxWindowBase::OnHelp)
bd83cb56
VZ
112#endif // wxUSE_HELP
113
f03fc89f
VZ
114END_EVENT_TABLE()
115
116// ============================================================================
117// implementation of the common functionality of the wxWindow class
118// ============================================================================
119
120// ----------------------------------------------------------------------------
121// initialization
122// ----------------------------------------------------------------------------
123
124// the default initialization
72795335 125wxWindowBase::wxWindowBase()
f03fc89f
VZ
126{
127 // no window yet, no parent nor children
f03fc89f 128 m_parent = (wxWindow *)NULL;
e11f4636 129 m_windowId = wxID_ANY;
f03fc89f
VZ
130
131 // no constraints on the minimal window size
132 m_minWidth =
422d0ff0 133 m_maxWidth = wxDefaultCoord;
f03fc89f 134 m_minHeight =
422d0ff0 135 m_maxHeight = wxDefaultCoord;
f03fc89f 136
9f884528
RD
137 // invalidiated cache value
138 m_bestSizeCache = wxDefaultSize;
139
eefe6d4b
VZ
140 // window are created enabled and visible by default
141 m_isShown =
e11f4636 142 m_isEnabled = true;
f03fc89f 143
f03fc89f
VZ
144 // the default event handler is just this window
145 m_eventHandler = this;
146
88ac883a 147#if wxUSE_VALIDATORS
f03fc89f
VZ
148 // no validator
149 m_windowValidator = (wxValidator *) NULL;
88ac883a 150#endif // wxUSE_VALIDATORS
f03fc89f 151
1b69c815
VZ
152 // the colours/fonts are default for now, so leave m_font,
153 // m_backgroundColour and m_foregroundColour uninitialized and set those
08df3e44
VZ
154 m_hasBgCol =
155 m_hasFgCol =
e11f4636 156 m_hasFont = false;
f8ff87ed
VS
157 m_inheritBgCol =
158 m_inheritFgCol =
159 m_inheritFont = false;
e11f4636 160
f03fc89f 161 // no style bits
d80cd92a 162 m_exStyle =
f03fc89f 163 m_windowStyle = 0;
cab1a605 164
50c53860 165 m_backgroundStyle = wxBG_STYLE_SYSTEM;
f03fc89f 166
f03fc89f
VZ
167#if wxUSE_CONSTRAINTS
168 // no constraints whatsoever
169 m_constraints = (wxLayoutConstraints *) NULL;
170 m_constraintsInvolvedIn = (wxWindowList *) NULL;
461e93f9
JS
171#endif // wxUSE_CONSTRAINTS
172
f03fc89f 173 m_windowSizer = (wxSizer *) NULL;
be90c029 174 m_containingSizer = (wxSizer *) NULL;
e11f4636 175 m_autoLayout = false;
f03fc89f
VZ
176
177#if wxUSE_DRAG_AND_DROP
178 m_dropTarget = (wxDropTarget *)NULL;
179#endif // wxUSE_DRAG_AND_DROP
180
181#if wxUSE_TOOLTIPS
182 m_tooltip = (wxToolTip *)NULL;
183#endif // wxUSE_TOOLTIPS
789295bf
VZ
184
185#if wxUSE_CARET
186 m_caret = (wxCaret *)NULL;
187#endif // wxUSE_CARET
a2d93e73 188
574c939e 189#if wxUSE_PALETTE
e11f4636 190 m_hasCustomPalette = false;
574c939e
KB
191#endif // wxUSE_PALETTE
192
ed5317e5
JS
193#if wxUSE_ACCESSIBILITY
194 m_accessible = NULL;
195#endif
196
566d84a7 197 m_virtualSize = wxDefaultSize;
1b69c815 198
f4fe2f20
RR
199 m_scrollHelper = (wxScrollHelper *) NULL;
200
1b69c815 201 m_windowVariant = wxWINDOW_VARIANT_NORMAL;
ff9f7a12
SC
202#if wxUSE_SYSTEM_OPTIONS
203 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) )
204 {
205 m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ;
206 }
207#endif
69d90995 208
a2d93e73 209 // Whether we're using the current theme for this window (wxGTK only for now)
e11f4636 210 m_themeEnabled = false;
1b69c815
VZ
211
212 // VZ: this one shouldn't exist...
213 m_isBeingDeleted = false;
17808a75
VZ
214
215 m_freezeCount = 0;
f03fc89f
VZ
216}
217
218// common part of window creation process
219bool wxWindowBase::CreateBase(wxWindowBase *parent,
220 wxWindowID id,
74e3313b 221 const wxPoint& WXUNUSED(pos),
400a9e41 222 const wxSize& WXUNUSED(size),
f03fc89f 223 long style,
ac8d0c11 224 const wxValidator& wxVALIDATOR_PARAM(validator),
f03fc89f
VZ
225 const wxString& name)
226{
106844da
VZ
227#if wxUSE_STATBOX
228 // wxGTK doesn't allow to create controls with static box as the parent so
229 // this will result in a crash when the program is ported to wxGTK so warn
230 // the user about it
231
232 // if you get this assert, the correct solution is to create the controls
233 // as siblings of the static box
234 wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox),
235 _T("wxStaticBox can't be used as a window parent!") );
236#endif // wxUSE_STATBOX
237
925f154d
VZ
238 // ids are limited to 16 bits under MSW so if you care about portability,
239 // it's not a good idea to use ids out of this range (and negative ids are
77ffb593 240 // reserved for wxWidgets own usage)
f35fdf7e
VZ
241 wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767) ||
242 (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST),
925f154d
VZ
243 _T("invalid id value") );
244
f03fc89f 245 // generate a new id if the user doesn't care about it
f35fdf7e
VZ
246 if ( id == wxID_ANY )
247 {
248 m_windowId = NewControlId();
f35fdf7e
VZ
249 }
250 else // valid id specified
251 {
252 m_windowId = id;
253 }
f03fc89f 254
e96248c4
VZ
255 // don't use SetWindowStyleFlag() here, this function should only be called
256 // to change the flag after creation as it tries to reflect the changes in
257 // flags by updating the window dynamically and we don't need this here
258 m_windowStyle = style;
259
f03fc89f 260 SetName(name);
f03fc89f 261 SetParent(parent);
674ac8b9
VZ
262
263#if wxUSE_VALIDATORS
8d99be5f 264 SetValidator(validator);
674ac8b9 265#endif // wxUSE_VALIDATORS
f03fc89f 266
8ae6ce07
VZ
267 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
268 // have it too - like this it's possible to set it only in the top level
269 // dialog/frame and all children will inherit it by defult
270 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
271 {
9cb98d89 272 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
8ae6ce07
VZ
273 }
274
e11f4636 275 return true;
f03fc89f
VZ
276}
277
d63312a9
VZ
278bool wxWindowBase::ToggleWindowStyle(int flag)
279{
280 wxASSERT_MSG( flag, _T("flags with 0 value can't be toggled") );
281
282 bool rc;
283 long style = GetWindowStyleFlag();
284 if ( style & flag )
285 {
286 style &= ~flag;
287 rc = false;
288 }
289 else // currently off
290 {
291 style |= flag;
292 rc = true;
293 }
294
295 SetWindowStyleFlag(style);
296
297 return rc;
298}
299
f03fc89f
VZ
300// ----------------------------------------------------------------------------
301// destruction
302// ----------------------------------------------------------------------------
303
304// common clean up
305wxWindowBase::~wxWindowBase()
306{
349d1942
VS
307 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
308
f03fc89f
VZ
309 // FIXME if these 2 cases result from programming errors in the user code
310 // we should probably assert here instead of silently fixing them
311
312 // Just in case the window has been Closed, but we're then deleting
313 // immediately: don't leave dangling pointers.
314 wxPendingDelete.DeleteObject(this);
315
316 // Just in case we've loaded a top-level window via LoadNativeDialog but
317 // we weren't a dialog class
222ed1d6 318 wxTopLevelWindows.DeleteObject((wxWindow*)this);
a23fd0e1 319
eeb0bee1
VZ
320 // The associated popup menu can still be alive, disassociate from it in
321 // this case
322 if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this )
323 wxCurrentPopupMenu->SetInvokingWindow(NULL);
324
223d09f6 325 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
f03fc89f 326
f8ab85ae 327 // notify the parent about this window destruction
f09df8b2 328 if ( m_parent )
8e35ab96 329 m_parent->RemoveChild(this);
8e35ab96 330
789295bf 331#if wxUSE_CARET
a2b436fb 332 delete m_caret;
789295bf
VZ
333#endif // wxUSE_CARET
334
88ac883a 335#if wxUSE_VALIDATORS
a2b436fb 336 delete m_windowValidator;
88ac883a 337#endif // wxUSE_VALIDATORS
f03fc89f 338
f03fc89f
VZ
339#if wxUSE_CONSTRAINTS
340 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
341 // at deleted windows as they delete themselves.
342 DeleteRelatedConstraints();
343
344 if ( m_constraints )
345 {
346 // This removes any dangling pointers to this window in other windows'
347 // constraintsInvolvedIn lists.
348 UnsetConstraints(m_constraints);
349 delete m_constraints;
350 m_constraints = NULL;
351 }
461e93f9
JS
352#endif // wxUSE_CONSTRAINTS
353
be90c029 354 if ( m_containingSizer )
12a3f227 355 m_containingSizer->Detach( (wxWindow*)this );
be90c029 356
a2b436fb 357 delete m_windowSizer;
f03fc89f 358
f03fc89f 359#if wxUSE_DRAG_AND_DROP
a2b436fb 360 delete m_dropTarget;
f03fc89f
VZ
361#endif // wxUSE_DRAG_AND_DROP
362
363#if wxUSE_TOOLTIPS
a2b436fb 364 delete m_tooltip;
f03fc89f 365#endif // wxUSE_TOOLTIPS
b0ee47ff 366
ed5317e5 367#if wxUSE_ACCESSIBILITY
a2b436fb 368 delete m_accessible;
ed5317e5 369#endif
f03fc89f
VZ
370}
371
602a2e02
VZ
372void wxWindowBase::SendDestroyEvent()
373{
374 wxWindowDestroyEvent event;
375 event.SetEventObject(this);
376 event.SetId(GetId());
377 GetEventHandler()->ProcessEvent(event);
378}
379
f03fc89f
VZ
380bool wxWindowBase::Destroy()
381{
382 delete this;
383
e11f4636 384 return true;
f03fc89f
VZ
385}
386
387bool wxWindowBase::Close(bool force)
388{
389 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
390 event.SetEventObject(this);
f03fc89f
VZ
391 event.SetCanVeto(!force);
392
e11f4636 393 // return false if window wasn't closed because the application vetoed the
f03fc89f
VZ
394 // close event
395 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
396}
397
398bool wxWindowBase::DestroyChildren()
399{
222ed1d6 400 wxWindowList::compatibility_iterator node;
a23fd0e1 401 for ( ;; )
f03fc89f 402 {
a23fd0e1
VZ
403 // we iterate until the list becomes empty
404 node = GetChildren().GetFirst();
405 if ( !node )
406 break;
407
f03fc89f 408 wxWindow *child = node->GetData();
a23fd0e1 409
f303564d
VZ
410 // note that we really want to call delete and not ->Destroy() here
411 // because we want to delete the child immediately, before we are
412 // deleted, and delayed deletion would result in problems as our (top
413 // level) child could outlive its parent
414 delete child;
a23fd0e1
VZ
415
416 wxASSERT_MSG( !GetChildren().Find(child),
223d09f6 417 wxT("child didn't remove itself using RemoveChild()") );
f03fc89f
VZ
418 }
419
e11f4636 420 return true;
f03fc89f
VZ
421}
422
423// ----------------------------------------------------------------------------
f68586e5 424// size/position related methods
f03fc89f
VZ
425// ----------------------------------------------------------------------------
426
427// centre the window with respect to its parent in either (or both) directions
1f464296 428void wxWindowBase::DoCentre(int dir)
f03fc89f 429{
1f464296
VZ
430 wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(),
431 _T("this method only implements centering child windows") );
ef397583 432
1f464296 433 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir));
7631a292
RD
434}
435
f03fc89f
VZ
436// fits the window around the children
437void wxWindowBase::Fit()
438{
74205969 439 if ( !GetChildren().empty() )
f68586e5 440 {
1736f021 441 SetSize(GetBestSize());
f68586e5
VZ
442 }
443 //else: do nothing if we have no children
444}
f03fc89f 445
2b5f62a0
VZ
446// fits virtual size (ie. scrolled area etc.) around children
447void wxWindowBase::FitInside()
448{
449 if ( GetChildren().GetCount() > 0 )
450 {
451 SetVirtualSize( GetBestVirtualSize() );
452 }
453}
454
7d59475e
JS
455// On Mac, scrollbars are explicitly children.
456#ifdef __WXMAC__
457static bool wxHasRealChildren(const wxWindowBase* win)
458{
459 int realChildCount = 0;
cab1a605 460
7d59475e
JS
461 for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
462 node;
463 node = node->GetNext() )
464 {
465 wxWindow *win = node->GetData();
466 if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar)))
467 realChildCount ++;
468 }
469 return (realChildCount > 0);
470}
471#endif
ba889513 472
992b2ec4
VS
473void wxWindowBase::InvalidateBestSize()
474{
475 m_bestSizeCache = wxDefaultSize;
476
477 // parent's best size calculation may depend on its children's
5b7df27e
WS
478 // as long as child window we are in is not top level window itself
479 // (because the TLW size is never resized automatically)
480 // so let's invalidate it as well to be safe:
5ff84587 481 if (m_parent && !IsTopLevel())
992b2ec4
VS
482 m_parent->InvalidateBestSize();
483}
7d59475e 484
f68586e5
VZ
485// return the size best suited for the current window
486wxSize wxWindowBase::DoGetBestSize() const
487{
08a19f64 488 wxSize best;
2997ca30 489
ec5bb70d
VZ
490 if ( m_windowSizer )
491 {
7e0f7539 492 best = m_windowSizer->GetMinSize();
ec5bb70d
VZ
493 }
494#if wxUSE_CONSTRAINTS
495 else if ( m_constraints )
496 {
497 wxConstCast(this, wxWindowBase)->SatisfyConstraints();
498
499 // our minimal acceptable size is such that all our windows fit inside
500 int maxX = 0,
501 maxY = 0;
502
222ed1d6 503 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
ec5bb70d
VZ
504 node;
505 node = node->GetNext() )
506 {
507 wxLayoutConstraints *c = node->GetData()->GetConstraints();
508 if ( !c )
509 {
510 // it's not normal that we have an unconstrained child, but
511 // what can we do about it?
512 continue;
513 }
514
515 int x = c->right.GetValue(),
516 y = c->bottom.GetValue();
517
518 if ( x > maxX )
519 maxX = x;
520
521 if ( y > maxY )
522 maxY = y;
523
524 // TODO: we must calculate the overlaps somehow, otherwise we
525 // will never return a size bigger than the current one :-(
526 }
527
08a19f64 528 best = wxSize(maxX, maxY);
ec5bb70d
VZ
529 }
530#endif // wxUSE_CONSTRAINTS
7d59475e
JS
531 else if ( !GetChildren().empty()
532#ifdef __WXMAC__
533 && wxHasRealChildren(this)
534#endif
535 )
f03fc89f 536 {
54af2461
VZ
537 // our minimal acceptable size is such that all our visible child
538 // windows fit inside
f68586e5
VZ
539 int maxX = 0,
540 maxY = 0;
541
222ed1d6 542 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
f68586e5
VZ
543 node;
544 node = node->GetNext() )
42e69d6b 545 {
f68586e5 546 wxWindow *win = node->GetData();
54af2461
VZ
547 if ( win->IsTopLevel()
548 || !win->IsShown()
1e6feb95 549#if wxUSE_STATUSBAR
54af2461 550 || wxDynamicCast(win, wxStatusBar)
1e6feb95
VZ
551#endif // wxUSE_STATUSBAR
552 )
f68586e5
VZ
553 {
554 // dialogs and frames lie in different top level windows -
7d9fd004
VZ
555 // don't deal with them here; as for the status bars, they
556 // don't lie in the client area at all
f68586e5
VZ
557 continue;
558 }
559
560 int wx, wy, ww, wh;
561 win->GetPosition(&wx, &wy);
3f5513f5
VZ
562
563 // if the window hadn't been positioned yet, assume that it is in
564 // the origin
422d0ff0 565 if ( wx == wxDefaultCoord )
3f5513f5 566 wx = 0;
422d0ff0 567 if ( wy == wxDefaultCoord )
3f5513f5
VZ
568 wy = 0;
569
f68586e5
VZ
570 win->GetSize(&ww, &wh);
571 if ( wx + ww > maxX )
572 maxX = wx + ww;
573 if ( wy + wh > maxY )
574 maxY = wy + wh;
42e69d6b
VZ
575 }
576
08a19f64 577 best = wxSize(maxX, maxY);
f68586e5 578 }
997c7280 579 else // ! has children
f68586e5 580 {
c0bb586f
VZ
581 // for a generic window there is no natural best size so, if the
582 // minimal size is not set, use the current size but take care to
583 // remember it as minimal size for the next time because our best size
584 // should be constant: otherwise we could get into a situation when the
585 // window is initially at some size, then expanded to a larger size and
586 // then, when the containing window is shrunk back (because our initial
587 // best size had been used for computing the parent min size), we can't
588 // be shrunk back any more because our best size is now bigger
9240613a
VZ
589 wxSize size = GetMinSize();
590 if ( !size.IsFullySpecified() )
591 {
592 size.SetDefaults(GetSize());
593 wxConstCast(this, wxWindowBase)->SetMinSize(size);
594 }
c0bb586f
VZ
595
596 // return as-is, unadjusted by the client size difference.
9240613a 597 return size;
f03fc89f 598 }
08a19f64
RD
599
600 // Add any difference between size and client size
601 wxSize diff = GetSize() - GetClientSize();
602 best.x += wxMax(0, diff.x);
603 best.y += wxMax(0, diff.y);
604
605 return best;
f03fc89f
VZ
606}
607
333d7052
VZ
608// helper of GetWindowBorderSize(): as many ports don't implement support for
609// wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
610// fallbacks in this case
ce6fbc83 611static int wxGetMetricOrDefault(wxSystemMetric what)
333d7052
VZ
612{
613 int rc = wxSystemSettings::GetMetric(what);
614 if ( rc == -1 )
615 {
616 switch ( what )
617 {
618 case wxSYS_BORDER_X:
619 case wxSYS_BORDER_Y:
620 // 2D border is by default 1 pixel wide
621 rc = 1;
622 break;
623
624 case wxSYS_EDGE_X:
625 case wxSYS_EDGE_Y:
626 // 3D borders are by default 2 pixels
627 rc = 2;
628 break;
629
630 default:
631 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
632 rc = 0;
633 }
634 }
635
636 return rc;
637}
638
639wxSize wxWindowBase::GetWindowBorderSize() const
640{
641 wxSize size;
642
643 switch ( GetBorder() )
644 {
645 case wxBORDER_NONE:
646 // nothing to do, size is already (0, 0)
647 break;
648
649 case wxBORDER_SIMPLE:
650 case wxBORDER_STATIC:
651 size.x = wxGetMetricOrDefault(wxSYS_BORDER_X);
652 size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y);
653 break;
654
655 case wxBORDER_SUNKEN:
656 case wxBORDER_RAISED:
657 size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X),
658 wxGetMetricOrDefault(wxSYS_BORDER_X));
659 size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y),
660 wxGetMetricOrDefault(wxSYS_BORDER_Y));
661 break;
662
663 case wxBORDER_DOUBLE:
664 size.x = wxGetMetricOrDefault(wxSYS_EDGE_X) +
665 wxGetMetricOrDefault(wxSYS_BORDER_X);
666 size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y) +
667 wxGetMetricOrDefault(wxSYS_BORDER_Y);
668 break;
669
670 default:
671 wxFAIL_MSG(_T("Unknown border style."));
672 break;
673 }
674
675 // we have borders on both sides
676 return size*2;
677}
9f884528 678
170acdc9 679wxSize wxWindowBase::GetEffectiveMinSize() const
400a9e41 680{
9f884528
RD
681 // merge the best size with the min size, giving priority to the min size
682 wxSize min = GetMinSize();
683 if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
400a9e41 684 {
9f884528
RD
685 wxSize best = GetBestSize();
686 if (min.x == wxDefaultCoord) min.x = best.x;
687 if (min.y == wxDefaultCoord) min.y = best.y;
17c48da8 688 }
9f884528
RD
689 return min;
690}
17c48da8 691
42cfa184 692
170acdc9 693void wxWindowBase::SetInitialSize(const wxSize& size)
9f884528
RD
694{
695 // Set the min size to the size passed in. This will usually either be
696 // wxDefaultSize or the size passed to this window's ctor/Create function.
697 SetMinSize(size);
698
699 // Merge the size with the best size if needed
170acdc9 700 wxSize best = GetEffectiveMinSize();
cab1a605 701
9f884528
RD
702 // If the current size doesn't match then change it
703 if (GetSize() != best)
704 SetSize(best);
400a9e41
VZ
705}
706
9f884528 707
1e6feb95
VZ
708// by default the origin is not shifted
709wxPoint wxWindowBase::GetClientAreaOrigin() const
710{
c47addef 711 return wxPoint(0,0);
1e6feb95
VZ
712}
713
69d90995
SC
714void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
715{
1b69c815
VZ
716 if ( m_windowVariant != variant )
717 {
718 m_windowVariant = variant;
69d90995 719
1b69c815
VZ
720 DoSetWindowVariant(variant);
721 }
69d90995
SC
722}
723
724void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
725{
1b69c815
VZ
726 // adjust the font height to correspond to our new variant (notice that
727 // we're only called if something really changed)
728 wxFont font = GetFont();
729 int size = font.GetPointSize();
69d90995
SC
730 switch ( variant )
731 {
1b69c815
VZ
732 case wxWINDOW_VARIANT_NORMAL:
733 break;
734
735 case wxWINDOW_VARIANT_SMALL:
736 size *= 3;
737 size /= 4;
738 break;
739
740 case wxWINDOW_VARIANT_MINI:
741 size *= 2;
742 size /= 3;
743 break;
744
745 case wxWINDOW_VARIANT_LARGE:
746 size *= 5;
747 size /= 4;
748 break;
749
69d90995
SC
750 default:
751 wxFAIL_MSG(_T("unexpected window variant"));
1b69c815 752 break;
69d90995 753 }
1b69c815
VZ
754
755 font.SetPointSize(size);
756 SetFont(font);
69d90995
SC
757}
758
b21f4960
RR
759void wxWindowBase::DoSetSizeHints( int minW, int minH,
760 int maxW, int maxH,
f36978ba 761 int WXUNUSED(incW), int WXUNUSED(incH) )
b21f4960
RR
762{
763 wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
764 (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
765 _T("min width/height must be less than max width/height!") );
766
767 m_minWidth = minW;
768 m_maxWidth = maxW;
769 m_minHeight = minH;
770 m_maxHeight = maxH;
771}
772
773
f944aec0
VS
774#if WXWIN_COMPATIBILITY_2_8
775void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW), int WXUNUSED(minH),
776 int WXUNUSED(maxW), int WXUNUSED(maxH))
566d84a7 777{
566d84a7
RL
778}
779
f944aec0
VS
780void wxWindowBase::SetVirtualSizeHints(const wxSize& WXUNUSED(minsize),
781 const wxSize& WXUNUSED(maxsize))
566d84a7 782{
f944aec0
VS
783}
784#endif // WXWIN_COMPATIBILITY_2_8
1e2a653b 785
f944aec0
VS
786void wxWindowBase::DoSetVirtualSize( int x, int y )
787{
1e2a653b 788 m_virtualSize = wxSize(x, y);
566d84a7
RL
789}
790
791wxSize wxWindowBase::DoGetVirtualSize() const
792{
143e2719
VZ
793 // we should use the entire client area so if it is greater than our
794 // virtual size, expand it to fit (otherwise if the window is big enough we
795 // wouldn't be using parts of it)
c20ab85b 796 wxSize size = GetClientSize();
143e2719 797 if ( m_virtualSize.x > size.x )
c20ab85b
VZ
798 size.x = m_virtualSize.x;
799
143e2719 800 if ( m_virtualSize.y >= size.y )
c20ab85b
VZ
801 size.y = m_virtualSize.y;
802
803 return size;
566d84a7
RL
804}
805
3c81c9aa
VZ
806void wxWindowBase::DoGetScreenPosition(int *x, int *y) const
807{
808 // screen position is the same as (0, 0) in client coords for non TLWs (and
809 // TLWs override this method)
810 if ( x )
811 *x = 0;
812 if ( y )
813 *y = 0;
814
aa738eb8 815 ClientToScreen(x, y);
3c81c9aa
VZ
816}
817
f03fc89f
VZ
818// ----------------------------------------------------------------------------
819// show/hide/enable/disable the window
820// ----------------------------------------------------------------------------
821
822bool wxWindowBase::Show(bool show)
823{
824 if ( show != m_isShown )
825 {
826 m_isShown = show;
827
e11f4636 828 return true;
f03fc89f
VZ
829 }
830 else
831 {
e11f4636 832 return false;
f03fc89f
VZ
833 }
834}
835
47a8a4d5 836bool wxWindowBase::IsEnabled() const
f03fc89f 837{
47a8a4d5
VZ
838 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
839}
f03fc89f 840
47a8a4d5
VZ
841void wxWindowBase::NotifyWindowOnEnableChange(bool enabled)
842{
843#ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
844 DoEnable(enabled);
845#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
846
847 OnEnabled(enabled);
848
849 // If we are top-level then the logic doesn't apply - otherwise
850 // showing a modal dialog would result in total greying out (and ungreying
851 // out later) of everything which would be really ugly
852 if ( IsTopLevel() )
853 return;
854
855 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
856 node;
857 node = node->GetNext() )
f03fc89f 858 {
47a8a4d5
VZ
859 wxWindowBase * const child = node->GetData();
860 if ( !child->IsTopLevel() && child->IsThisEnabled() )
861 child->NotifyWindowOnEnableChange(enabled);
862 }
863}
864
865bool wxWindowBase::Enable(bool enable)
866{
867 if ( enable == IsThisEnabled() )
e11f4636 868 return false;
47a8a4d5
VZ
869
870 m_isEnabled = enable;
871
872#ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
873 DoEnable(enable);
874#else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
875 wxWindowBase * const parent = GetParent();
876 if( !IsTopLevel() && parent && !parent->IsEnabled() )
877 {
878 return true;
f03fc89f 879 }
47a8a4d5
VZ
880#endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
881
882 NotifyWindowOnEnableChange(enable);
883
884 return true;
f03fc89f 885}
9c72cf76 886
865a74c7 887bool wxWindowBase::IsShownOnScreen() const
9c72cf76 888{
8a6a997f
VS
889 // A window is shown on screen if it itself is shown and so are all its
890 // parents. But if a window is toplevel one, then its always visible on
891 // screen if IsShown() returns true, even if it has a hidden parent.
865a74c7 892 return IsShown() &&
8a6a997f 893 (IsTopLevel() || GetParent() == NULL || GetParent()->IsShownOnScreen());
9c72cf76
VS
894}
895
34636400
VZ
896// ----------------------------------------------------------------------------
897// RTTI
898// ----------------------------------------------------------------------------
899
900bool wxWindowBase::IsTopLevel() const
901{
e11f4636 902 return false;
34636400 903}
f03fc89f
VZ
904
905// ----------------------------------------------------------------------------
906// reparenting the window
907// ----------------------------------------------------------------------------
908
909void wxWindowBase::AddChild(wxWindowBase *child)
910{
223d09f6 911 wxCHECK_RET( child, wxT("can't add a NULL child") );
f03fc89f 912
f6bcfd97
BP
913 // this should never happen and it will lead to a crash later if it does
914 // because RemoveChild() will remove only one node from the children list
915 // and the other(s) one(s) will be left with dangling pointers in them
222ed1d6 916 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") );
f6bcfd97 917
222ed1d6 918 GetChildren().Append((wxWindow*)child);
f03fc89f
VZ
919 child->SetParent(this);
920}
921
922void wxWindowBase::RemoveChild(wxWindowBase *child)
923{
223d09f6 924 wxCHECK_RET( child, wxT("can't remove a NULL child") );
f03fc89f 925
222ed1d6
MB
926 GetChildren().DeleteObject((wxWindow *)child);
927 child->SetParent(NULL);
f03fc89f 928}
439b3bf1 929
f03fc89f
VZ
930bool wxWindowBase::Reparent(wxWindowBase *newParent)
931{
932 wxWindow *oldParent = GetParent();
933 if ( newParent == oldParent )
934 {
935 // nothing done
e11f4636 936 return false;
f03fc89f
VZ
937 }
938
47a8a4d5
VZ
939 const bool oldEnabledState = IsEnabled();
940
f03fc89f
VZ
941 // unlink this window from the existing parent.
942 if ( oldParent )
943 {
944 oldParent->RemoveChild(this);
945 }
946 else
947 {
222ed1d6 948 wxTopLevelWindows.DeleteObject((wxWindow *)this);
f03fc89f
VZ
949 }
950
951 // add it to the new one
952 if ( newParent )
953 {
954 newParent->AddChild(this);
955 }
956 else
957 {
222ed1d6 958 wxTopLevelWindows.Append((wxWindow *)this);
f03fc89f
VZ
959 }
960
47a8a4d5
VZ
961 // We need to notify window (and its subwindows) if by changing the parent
962 // we also change our enabled/disabled status.
963 const bool newEnabledState = IsEnabled();
964 if ( newEnabledState != oldEnabledState )
965 {
966 NotifyWindowOnEnableChange(newEnabledState);
967 }
968
e11f4636 969 return true;
f03fc89f
VZ
970}
971
972// ----------------------------------------------------------------------------
973// event handler stuff
974// ----------------------------------------------------------------------------
975
976void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
977{
3a074ba8
VZ
978 wxEvtHandler *handlerOld = GetEventHandler();
979
980 handler->SetNextHandler(handlerOld);
981
982 if ( handlerOld )
983 GetEventHandler()->SetPreviousHandler(handler);
984
f03fc89f
VZ
985 SetEventHandler(handler);
986}
987
988wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
989{
990 wxEvtHandler *handlerA = GetEventHandler();
991 if ( handlerA )
992 {
993 wxEvtHandler *handlerB = handlerA->GetNextHandler();
994 handlerA->SetNextHandler((wxEvtHandler *)NULL);
3a074ba8
VZ
995
996 if ( handlerB )
997 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
f03fc89f 998 SetEventHandler(handlerB);
3a074ba8 999
f03fc89f
VZ
1000 if ( deleteHandler )
1001 {
1002 delete handlerA;
1003 handlerA = (wxEvtHandler *)NULL;
1004 }
1005 }
1006
1007 return handlerA;
1008}
1009
2e36d5cf
VZ
1010bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
1011{
e11f4636 1012 wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") );
2e36d5cf
VZ
1013
1014 wxEvtHandler *handlerPrev = NULL,
1015 *handlerCur = GetEventHandler();
1016 while ( handlerCur )
1017 {
1018 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
1019
1020 if ( handlerCur == handler )
1021 {
1022 if ( handlerPrev )
1023 {
1024 handlerPrev->SetNextHandler(handlerNext);
1025 }
1026 else
1027 {
1028 SetEventHandler(handlerNext);
1029 }
1030
7a9c8d74
JS
1031 if ( handlerNext )
1032 {
1033 handlerNext->SetPreviousHandler ( handlerPrev );
1034 }
489bbac9 1035
2e36d5cf 1036 handler->SetNextHandler(NULL);
489bbac9 1037 handler->SetPreviousHandler(NULL);
2e36d5cf 1038
e11f4636 1039 return true;
2e36d5cf
VZ
1040 }
1041
1042 handlerPrev = handlerCur;
1043 handlerCur = handlerNext;
1044 }
1045
1046 wxFAIL_MSG( _T("where has the event handler gone?") );
1047
e11f4636 1048 return false;
2e36d5cf
VZ
1049}
1050
937013e0
VS
1051bool wxWindowBase::HandleWindowEvent(wxEvent& event) const
1052{
1053 return GetEventHandler()->SafelyProcessEvent(event);
1054}
1055
f03fc89f 1056// ----------------------------------------------------------------------------
1b69c815 1057// colours, fonts &c
f03fc89f
VZ
1058// ----------------------------------------------------------------------------
1059
b8e7b673
VZ
1060void wxWindowBase::InheritAttributes()
1061{
8afef133 1062 const wxWindowBase * const parent = GetParent();
b8e7b673
VZ
1063 if ( !parent )
1064 return;
1065
1066 // we only inherit attributes which had been explicitly set for the parent
1067 // which ensures that this only happens if the user really wants it and
1068 // not by default which wouldn't make any sense in modern GUIs where the
1069 // controls don't all use the same fonts (nor colours)
f8ff87ed 1070 if ( parent->m_inheritFont && !m_hasFont )
b8e7b673
VZ
1071 SetFont(parent->GetFont());
1072
1073 // in addition, there is a possibility to explicitly forbid inheriting
1074 // colours at each class level by overriding ShouldInheritColours()
1075 if ( ShouldInheritColours() )
1076 {
f8ff87ed 1077 if ( parent->m_inheritFgCol && !m_hasFgCol )
b8e7b673
VZ
1078 SetForegroundColour(parent->GetForegroundColour());
1079
eb96212b
VZ
1080 // inheriting (solid) background colour is wrong as it totally breaks
1081 // any kind of themed backgrounds
1082 //
1083 // instead, the controls should use the same background as their parent
1084 // (ideally by not drawing it at all)
1085#if 0
f8ff87ed 1086 if ( parent->m_inheritBgCol && !m_hasBgCol )
b8e7b673 1087 SetBackgroundColour(parent->GetBackgroundColour());
eb96212b 1088#endif // 0
b8e7b673
VZ
1089 }
1090}
1091
1b69c815
VZ
1092/* static */ wxVisualAttributes
1093wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
1094{
1095 // it is important to return valid values for all attributes from here,
1096 // GetXXX() below rely on this
1097 wxVisualAttributes attrs;
1098 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
1099 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1b69c815 1100
0477a857
JS
1101 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1102 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1103 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1104 // colour on other platforms.
1105
1106#if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1107 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1108#else
1109 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1110#endif
1b69c815
VZ
1111 return attrs;
1112}
1113
1114wxColour wxWindowBase::GetBackgroundColour() const
1115{
1117d56f 1116 if ( !m_backgroundColour.IsOk() )
1b69c815
VZ
1117 {
1118 wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
1119
1120 // get our default background colour
1121 wxColour colBg = GetDefaultAttributes().colBg;
1122
1123 // we must return some valid colour to avoid redoing this every time
1124 // and also to avoid surprizing the applications written for older
77ffb593 1125 // wxWidgets versions where GetBackgroundColour() always returned
1b69c815
VZ
1126 // something -- so give them something even if it doesn't make sense
1127 // for this window (e.g. it has a themed background)
1128 if ( !colBg.Ok() )
1129 colBg = GetClassDefaultAttributes().colBg;
1130
f604c658 1131 return colBg;
1b69c815 1132 }
f604c658
VS
1133 else
1134 return m_backgroundColour;
1b69c815
VZ
1135}
1136
1137wxColour wxWindowBase::GetForegroundColour() const
1138{
1139 // logic is the same as above
1140 if ( !m_hasFgCol && !m_foregroundColour.Ok() )
1141 {
1b69c815
VZ
1142 wxColour colFg = GetDefaultAttributes().colFg;
1143
1117d56f 1144 if ( !colFg.IsOk() )
1b69c815
VZ
1145 colFg = GetClassDefaultAttributes().colFg;
1146
f604c658 1147 return colFg;
1b69c815 1148 }
f604c658
VS
1149 else
1150 return m_foregroundColour;
1b69c815
VZ
1151}
1152
f03fc89f
VZ
1153bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
1154{
cab1a605 1155 if ( colour == m_backgroundColour )
e11f4636 1156 return false;
f03fc89f 1157
1117d56f 1158 m_hasBgCol = colour.IsOk();
17bcd9a6
VZ
1159 if ( m_backgroundStyle != wxBG_STYLE_CUSTOM )
1160 m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM;
1161
f8ff87ed 1162 m_inheritBgCol = m_hasBgCol;
f03fc89f 1163 m_backgroundColour = colour;
44dfb5ce 1164 SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
e11f4636 1165 return true;
f03fc89f
VZ
1166}
1167
1168bool wxWindowBase::SetForegroundColour( const wxColour &colour )
1169{
44dfb5ce 1170 if (colour == m_foregroundColour )
e11f4636 1171 return false;
f03fc89f 1172
1117d56f 1173 m_hasFgCol = colour.IsOk();
f8ff87ed 1174 m_inheritFgCol = m_hasFgCol;
f03fc89f 1175 m_foregroundColour = colour;
44dfb5ce 1176 SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
e11f4636 1177 return true;
f03fc89f
VZ
1178}
1179
1180bool wxWindowBase::SetCursor(const wxCursor& cursor)
1181{
8a9c2246
VZ
1182 // setting an invalid cursor is ok, it means that we don't have any special
1183 // cursor
a3ab1c18 1184 if ( m_cursor.IsSameAs(cursor) )
f03fc89f
VZ
1185 {
1186 // no change
e11f4636 1187 return false;
f03fc89f
VZ
1188 }
1189
8a9c2246 1190 m_cursor = cursor;
f03fc89f 1191
e11f4636 1192 return true;
f03fc89f
VZ
1193}
1194
f604c658 1195wxFont wxWindowBase::GetFont() const
1b69c815
VZ
1196{
1197 // logic is the same as in GetBackgroundColour()
1117d56f 1198 if ( !m_font.IsOk() )
1b69c815
VZ
1199 {
1200 wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
1201
1202 wxFont font = GetDefaultAttributes().font;
1117d56f 1203 if ( !font.IsOk() )
1b69c815
VZ
1204 font = GetClassDefaultAttributes().font;
1205
f604c658 1206 return font;
1b69c815 1207 }
f604c658
VS
1208 else
1209 return m_font;
1b69c815
VZ
1210}
1211
f03fc89f
VZ
1212bool wxWindowBase::SetFont(const wxFont& font)
1213{
1b69c815 1214 if ( font == m_font )
f03fc89f
VZ
1215 {
1216 // no change
e11f4636 1217 return false;
f03fc89f
VZ
1218 }
1219
1b69c815 1220 m_font = font;
1117d56f 1221 m_hasFont = font.IsOk();
f8ff87ed 1222 m_inheritFont = m_hasFont;
23895080 1223
583d7e55
VS
1224 InvalidateBestSize();
1225
e11f4636 1226 return true;
f03fc89f
VZ
1227}
1228
b95edd47
VZ
1229#if wxUSE_PALETTE
1230
1231void wxWindowBase::SetPalette(const wxPalette& pal)
1232{
e11f4636 1233 m_hasCustomPalette = true;
b95edd47
VZ
1234 m_palette = pal;
1235
1236 // VZ: can anyone explain me what do we do here?
1237 wxWindowDC d((wxWindow *) this);
1238 d.SetPalette(pal);
1239}
1240
1241wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
1242{
1243 wxWindow *win = (wxWindow *)this;
1244 while ( win && !win->HasCustomPalette() )
1245 {
1246 win = win->GetParent();
1247 }
1248
1249 return win;
1250}
1251
1252#endif // wxUSE_PALETTE
1253
789295bf
VZ
1254#if wxUSE_CARET
1255void wxWindowBase::SetCaret(wxCaret *caret)
1256{
1257 if ( m_caret )
1258 {
1259 delete m_caret;
1260 }
1261
1262 m_caret = caret;
1263
1264 if ( m_caret )
1265 {
1266 wxASSERT_MSG( m_caret->GetWindow() == this,
223d09f6 1267 wxT("caret should be created associated to this window") );
789295bf
VZ
1268 }
1269}
1270#endif // wxUSE_CARET
1271
88ac883a 1272#if wxUSE_VALIDATORS
f03fc89f
VZ
1273// ----------------------------------------------------------------------------
1274// validators
1275// ----------------------------------------------------------------------------
1276
1277void wxWindowBase::SetValidator(const wxValidator& validator)
1278{
1279 if ( m_windowValidator )
1280 delete m_windowValidator;
1281
1282 m_windowValidator = (wxValidator *)validator.Clone();
1283
1284 if ( m_windowValidator )
1b69c815 1285 m_windowValidator->SetWindow(this);
f03fc89f 1286}
88ac883a 1287#endif // wxUSE_VALIDATORS
f03fc89f
VZ
1288
1289// ----------------------------------------------------------------------------
1e6feb95 1290// update region stuff
f03fc89f
VZ
1291// ----------------------------------------------------------------------------
1292
1e6feb95
VZ
1293wxRect wxWindowBase::GetUpdateClientRect() const
1294{
1295 wxRegion rgnUpdate = GetUpdateRegion();
1296 rgnUpdate.Intersect(GetClientRect());
1297 wxRect rectUpdate = rgnUpdate.GetBox();
1298 wxPoint ptOrigin = GetClientAreaOrigin();
1299 rectUpdate.x -= ptOrigin.x;
1300 rectUpdate.y -= ptOrigin.y;
1301
1302 return rectUpdate;
1303}
1304
657b4fd4 1305bool wxWindowBase::DoIsExposed(int x, int y) const
f03fc89f
VZ
1306{
1307 return m_updateRegion.Contains(x, y) != wxOutRegion;
1308}
1309
657b4fd4 1310bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const
f03fc89f
VZ
1311{
1312 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1313}
1314
5da0803c
VZ
1315void wxWindowBase::ClearBackground()
1316{
1317 // wxGTK uses its own version, no need to add never used code
1318#ifndef __WXGTK__
1319 wxClientDC dc((wxWindow *)this);
1320 wxBrush brush(GetBackgroundColour(), wxSOLID);
1321 dc.SetBackground(brush);
1322 dc.Clear();
1323#endif // __WXGTK__
1324}
1325
f03fc89f 1326// ----------------------------------------------------------------------------
146ba0fe 1327// find child window by id or name
f03fc89f
VZ
1328// ----------------------------------------------------------------------------
1329
6b73af79 1330wxWindow *wxWindowBase::FindWindow(long id) const
f03fc89f
VZ
1331{
1332 if ( id == m_windowId )
1333 return (wxWindow *)this;
1334
1335 wxWindowBase *res = (wxWindow *)NULL;
222ed1d6 1336 wxWindowList::compatibility_iterator node;
f03fc89f
VZ
1337 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1338 {
1339 wxWindowBase *child = node->GetData();
1340 res = child->FindWindow( id );
1341 }
1342
1343 return (wxWindow *)res;
1344}
1345
6b73af79 1346wxWindow *wxWindowBase::FindWindow(const wxString& name) const
f03fc89f
VZ
1347{
1348 if ( name == m_windowName )
1349 return (wxWindow *)this;
1350
1351 wxWindowBase *res = (wxWindow *)NULL;
222ed1d6 1352 wxWindowList::compatibility_iterator node;
f03fc89f
VZ
1353 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1354 {
1355 wxWindow *child = node->GetData();
1356 res = child->FindWindow(name);
1357 }
1358
1359 return (wxWindow *)res;
1360}
1361
146ba0fe
VZ
1362
1363// find any window by id or name or label: If parent is non-NULL, look through
1364// children for a label or title matching the specified string. If NULL, look
1365// through all top-level windows.
1366//
1367// to avoid duplicating code we reuse the same helper function but with
1368// different comparators
1369
1370typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1371 const wxString& label, long id);
1372
1373static
1374bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1375 long WXUNUSED(id))
1376{
1377 return win->GetLabel() == label;
1378}
1379
1380static
1381bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1382 long WXUNUSED(id))
1383{
1384 return win->GetName() == label;
1385}
1386
1387static
1388bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1389 long id)
1390{
1391 return win->GetId() == id;
1392}
1393
1394// recursive helper for the FindWindowByXXX() functions
1395static
1396wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1397 const wxString& label,
1398 long id,
1399 wxFindWindowCmp cmp)
1400{
1401 if ( parent )
1402 {
1403 // see if this is the one we're looking for
1404 if ( (*cmp)(parent, label, id) )
1405 return (wxWindow *)parent;
1406
1407 // It wasn't, so check all its children
222ed1d6 1408 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
146ba0fe
VZ
1409 node;
1410 node = node->GetNext() )
1411 {
1412 // recursively check each child
1413 wxWindow *win = (wxWindow *)node->GetData();
1414 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1415 if (retwin)
1416 return retwin;
1417 }
1418 }
1419
1420 // Not found
1421 return NULL;
1422}
1423
1424// helper for FindWindowByXXX()
1425static
1426wxWindow *wxFindWindowHelper(const wxWindow *parent,
1427 const wxString& label,
1428 long id,
1429 wxFindWindowCmp cmp)
1430{
1431 if ( parent )
1432 {
1433 // just check parent and all its children
1434 return wxFindWindowRecursively(parent, label, id, cmp);
1435 }
1436
1437 // start at very top of wx's windows
222ed1d6 1438 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
146ba0fe
VZ
1439 node;
1440 node = node->GetNext() )
1441 {
1442 // recursively check each window & its children
1443 wxWindow *win = node->GetData();
1444 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1445 if (retwin)
1446 return retwin;
1447 }
1448
1449 return NULL;
1450}
1451
1452/* static */
1453wxWindow *
1454wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1455{
1456 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1457}
1458
1459/* static */
1460wxWindow *
1461wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1462{
1463 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1464
1465 if ( !win )
1466 {
1467 // fall back to the label
1468 win = FindWindowByLabel(title, parent);
1469 }
1470
1471 return win;
1472}
1473
1474/* static */
1475wxWindow *
1476wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1477{
525d8583 1478 return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds);
146ba0fe
VZ
1479}
1480
f03fc89f
VZ
1481// ----------------------------------------------------------------------------
1482// dialog oriented functions
1483// ----------------------------------------------------------------------------
1484
34636400 1485void wxWindowBase::MakeModal(bool modal)
f03fc89f 1486{
34636400
VZ
1487 // Disable all other windows
1488 if ( IsTopLevel() )
1489 {
222ed1d6 1490 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
34636400
VZ
1491 while (node)
1492 {
1493 wxWindow *win = node->GetData();
1494 if (win != this)
1495 win->Enable(!modal);
1496
1497 node = node->GetNext();
1498 }
1499 }
f03fc89f
VZ
1500}
1501
1502bool wxWindowBase::Validate()
1503{
88ac883a 1504#if wxUSE_VALIDATORS
d80cd92a
VZ
1505 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1506
222ed1d6 1507 wxWindowList::compatibility_iterator node;
f03fc89f
VZ
1508 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1509 {
1510 wxWindowBase *child = node->GetData();
1511 wxValidator *validator = child->GetValidator();
dcd6b914 1512 if ( validator && !validator->Validate((wxWindow *)this) )
f03fc89f 1513 {
e11f4636 1514 return false;
f03fc89f 1515 }
d80cd92a
VZ
1516
1517 if ( recurse && !child->Validate() )
1518 {
e11f4636 1519 return false;
d80cd92a 1520 }
f03fc89f 1521 }
88ac883a 1522#endif // wxUSE_VALIDATORS
f03fc89f 1523
e11f4636 1524 return true;
f03fc89f
VZ
1525}
1526
1527bool wxWindowBase::TransferDataToWindow()
1528{
88ac883a 1529#if wxUSE_VALIDATORS
d80cd92a
VZ
1530 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1531
222ed1d6 1532 wxWindowList::compatibility_iterator node;
f03fc89f
VZ
1533 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1534 {
1535 wxWindowBase *child = node->GetData();
1536 wxValidator *validator = child->GetValidator();
1537 if ( validator && !validator->TransferToWindow() )
1538 {
d80cd92a 1539 wxLogWarning(_("Could not transfer data to window"));
e30285ab 1540#if wxUSE_LOG
d80cd92a 1541 wxLog::FlushActive();
e30285ab 1542#endif // wxUSE_LOG
f03fc89f 1543
e11f4636 1544 return false;
f03fc89f 1545 }
d80cd92a
VZ
1546
1547 if ( recurse )
1548 {
a58a12e9 1549 if ( !child->TransferDataToWindow() )
d80cd92a
VZ
1550 {
1551 // warning already given
e11f4636 1552 return false;
d80cd92a
VZ
1553 }
1554 }
f03fc89f 1555 }
88ac883a 1556#endif // wxUSE_VALIDATORS
f03fc89f 1557
e11f4636 1558 return true;
f03fc89f
VZ
1559}
1560
1561bool wxWindowBase::TransferDataFromWindow()
1562{
88ac883a 1563#if wxUSE_VALIDATORS
d80cd92a
VZ
1564 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1565
222ed1d6 1566 wxWindowList::compatibility_iterator node;
f03fc89f
VZ
1567 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1568 {
1569 wxWindow *child = node->GetData();
d80cd92a
VZ
1570 wxValidator *validator = child->GetValidator();
1571 if ( validator && !validator->TransferFromWindow() )
f03fc89f 1572 {
d80cd92a
VZ
1573 // nop warning here because the application is supposed to give
1574 // one itself - we don't know here what might have gone wrongly
1575
e11f4636 1576 return false;
f03fc89f 1577 }
d80cd92a
VZ
1578
1579 if ( recurse )
1580 {
a58a12e9 1581 if ( !child->TransferDataFromWindow() )
d80cd92a
VZ
1582 {
1583 // warning already given
e11f4636 1584 return false;
d80cd92a
VZ
1585 }
1586 }
f03fc89f 1587 }
88ac883a 1588#endif // wxUSE_VALIDATORS
f03fc89f 1589
e11f4636 1590 return true;
f03fc89f
VZ
1591}
1592
1593void wxWindowBase::InitDialog()
1594{
1595 wxInitDialogEvent event(GetId());
1596 event.SetEventObject( this );
1597 GetEventHandler()->ProcessEvent(event);
1598}
1599
1600// ----------------------------------------------------------------------------
bd83cb56
VZ
1601// context-sensitive help support
1602// ----------------------------------------------------------------------------
1603
1604#if wxUSE_HELP
1605
1606// associate this help text with this window
1607void wxWindowBase::SetHelpText(const wxString& text)
1608{
1609 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1610 if ( helpProvider )
1611 {
1612 helpProvider->AddHelp(this, text);
1613 }
1614}
1615
1616// associate this help text with all windows with the same id as this
1617// one
1618void wxWindowBase::SetHelpTextForId(const wxString& text)
1619{
1620 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1621 if ( helpProvider )
1622 {
1623 helpProvider->AddHelp(GetId(), text);
1624 }
1625}
1626
1627// get the help string associated with this window (may be empty)
dc6588e7
VZ
1628// default implementation forwards calls to the help provider
1629wxString
1630wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt),
1631 wxHelpEvent::Origin WXUNUSED(origin)) const
bd83cb56
VZ
1632{
1633 wxString text;
1634 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1635 if ( helpProvider )
1636 {
1637 text = helpProvider->GetHelp(this);
1638 }
1639
1640 return text;
1641}
1642
1643// show help for this window
1644void wxWindowBase::OnHelp(wxHelpEvent& event)
1645{
1646 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1647 if ( helpProvider )
1648 {
dc6588e7 1649 if ( helpProvider->ShowHelpAtPoint(this, event.GetPosition(), event.GetOrigin()) )
bd83cb56
VZ
1650 {
1651 // skip the event.Skip() below
1652 return;
1653 }
1654 }
1655
1656 event.Skip();
1657}
1658
1659#endif // wxUSE_HELP
1660
1661// ----------------------------------------------------------------------------
602a2e02 1662// tooltips
f03fc89f
VZ
1663// ----------------------------------------------------------------------------
1664
1665#if wxUSE_TOOLTIPS
1666
1667void wxWindowBase::SetToolTip( const wxString &tip )
1668{
1669 // don't create the new tooltip if we already have one
1670 if ( m_tooltip )
1671 {
1672 m_tooltip->SetTip( tip );
1673 }
1674 else
1675 {
1676 SetToolTip( new wxToolTip( tip ) );
1677 }
1678
1679 // setting empty tooltip text does not remove the tooltip any more - use
1680 // SetToolTip((wxToolTip *)NULL) for this
1681}
1682
1683void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1684{
0cb57187
VZ
1685 if ( m_tooltip != tooltip )
1686 {
1687 if ( m_tooltip )
1688 delete m_tooltip;
f03fc89f 1689
0cb57187
VZ
1690 m_tooltip = tooltip;
1691 }
f03fc89f
VZ
1692}
1693
1694#endif // wxUSE_TOOLTIPS
1695
1696// ----------------------------------------------------------------------------
1697// constraints and sizers
1698// ----------------------------------------------------------------------------
1699
1700#if wxUSE_CONSTRAINTS
1701
1702void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1703{
1704 if ( m_constraints )
1705 {
1706 UnsetConstraints(m_constraints);
1707 delete m_constraints;
1708 }
1709 m_constraints = constraints;
1710 if ( m_constraints )
1711 {
1712 // Make sure other windows know they're part of a 'meaningful relationship'
1713 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1714 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1715 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1716 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1717 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1718 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1719 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1720 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1721 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1722 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1723 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1724 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1725 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1726 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1727 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1728 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1729 }
1730}
1731
1732// This removes any dangling pointers to this window in other windows'
1733// constraintsInvolvedIn lists.
1734void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1735{
1736 if ( c )
1737 {
1738 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1739 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1740 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1741 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1742 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1743 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1744 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1745 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1746 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1747 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1748 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1749 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1750 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1751 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1752 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1753 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1754 }
1755}
1756
1757// Back-pointer to other windows we're involved with, so if we delete this
1758// window, we must delete any constraints we're involved with.
1759void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1760{
1761 if ( !m_constraintsInvolvedIn )
1762 m_constraintsInvolvedIn = new wxWindowList;
222ed1d6
MB
1763 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
1764 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
f03fc89f
VZ
1765}
1766
1767// REMOVE back-pointer to other windows we're involved with.
1768void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1769{
1770 if ( m_constraintsInvolvedIn )
222ed1d6 1771 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
f03fc89f
VZ
1772}
1773
1774// Reset any constraints that mention this window
1775void wxWindowBase::DeleteRelatedConstraints()
1776{
1777 if ( m_constraintsInvolvedIn )
1778 {
222ed1d6 1779 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
f03fc89f
VZ
1780 while (node)
1781 {
1782 wxWindow *win = node->GetData();
1783 wxLayoutConstraints *constr = win->GetConstraints();
1784
1785 // Reset any constraints involving this window
1786 if ( constr )
1787 {
1788 constr->left.ResetIfWin(this);
1789 constr->top.ResetIfWin(this);
1790 constr->right.ResetIfWin(this);
1791 constr->bottom.ResetIfWin(this);
1792 constr->width.ResetIfWin(this);
1793 constr->height.ResetIfWin(this);
1794 constr->centreX.ResetIfWin(this);
1795 constr->centreY.ResetIfWin(this);
1796 }
1797
222ed1d6
MB
1798 wxWindowList::compatibility_iterator next = node->GetNext();
1799 m_constraintsInvolvedIn->Erase(node);
f03fc89f
VZ
1800 node = next;
1801 }
1802
1803 delete m_constraintsInvolvedIn;
1804 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1805 }
1806}
ec5bb70d
VZ
1807
1808#endif // wxUSE_CONSTRAINTS
f03fc89f 1809
3aa5d532 1810void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
f03fc89f 1811{
fb89cfc5
RD
1812 if ( sizer == m_windowSizer)
1813 return;
1b69c815 1814
e8cfff87
VZ
1815 if ( m_windowSizer )
1816 {
1817 m_windowSizer->SetContainingWindow(NULL);
1818
1819 if ( deleteOld )
1820 delete m_windowSizer;
1821 }
3417c2cd 1822
f03fc89f 1823 m_windowSizer = sizer;
e8cfff87
VZ
1824 if ( m_windowSizer )
1825 {
1826 m_windowSizer->SetContainingWindow((wxWindow *)this);
1827 }
566d84a7 1828
e8cfff87 1829 SetAutoLayout(m_windowSizer != NULL);
566d84a7
RL
1830}
1831
1832void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1833{
1834 SetSizer( sizer, deleteOld );
1835 sizer->SetSizeHints( (wxWindow*) this );
f03fc89f
VZ
1836}
1837
400a9e41 1838
1ebfafde
RD
1839void wxWindowBase::SetContainingSizer(wxSizer* sizer)
1840{
1841 // adding a window to a sizer twice is going to result in fatal and
1842 // hard to debug problems later because when deleting the second
1843 // associated wxSizerItem we're going to dereference a dangling
1844 // pointer; so try to detect this as early as possible
1845 wxASSERT_MSG( !sizer || m_containingSizer != sizer,
1846 _T("Adding a window to the same sizer twice?") );
1ebfafde 1847
400a9e41 1848 m_containingSizer = sizer;
1ebfafde 1849}
400a9e41 1850
ec5bb70d
VZ
1851#if wxUSE_CONSTRAINTS
1852
1853void wxWindowBase::SatisfyConstraints()
1854{
1855 wxLayoutConstraints *constr = GetConstraints();
1856 bool wasOk = constr && constr->AreSatisfied();
1857
1858 ResetConstraints(); // Mark all constraints as unevaluated
1859
1860 int noChanges = 1;
1861
1862 // if we're a top level panel (i.e. our parent is frame/dialog), our
1863 // own constraints will never be satisfied any more unless we do it
1864 // here
1865 if ( wasOk )
1866 {
1867 while ( noChanges > 0 )
1868 {
1869 LayoutPhase1(&noChanges);
1870 }
1871 }
1872
1873 LayoutPhase2(&noChanges);
1874}
1875
1876#endif // wxUSE_CONSTRAINTS
1877
f03fc89f
VZ
1878bool wxWindowBase::Layout()
1879{
3417c2cd 1880 // If there is a sizer, use it instead of the constraints
f03fc89f
VZ
1881 if ( GetSizer() )
1882 {
8d7eaf91 1883 int w = 0, h = 0;
566d84a7 1884 GetVirtualSize(&w, &h);
3417c2cd 1885 GetSizer()->SetDimension( 0, 0, w, h );
f03fc89f 1886 }
461e93f9 1887#if wxUSE_CONSTRAINTS
f1df0927 1888 else
f03fc89f 1889 {
ec5bb70d 1890 SatisfyConstraints(); // Find the right constraints values
f1df0927 1891 SetConstraintSizes(); // Recursively set the real window sizes
f03fc89f 1892 }
461e93f9 1893#endif
5d4b632b 1894
e11f4636 1895 return true;
f03fc89f
VZ
1896}
1897
461e93f9 1898#if wxUSE_CONSTRAINTS
ec5bb70d
VZ
1899
1900// first phase of the constraints evaluation: set our own constraints
f03fc89f
VZ
1901bool wxWindowBase::LayoutPhase1(int *noChanges)
1902{
1903 wxLayoutConstraints *constr = GetConstraints();
ec5bb70d
VZ
1904
1905 return !constr || constr->SatisfyConstraints(this, noChanges);
f03fc89f
VZ
1906}
1907
ec5bb70d 1908// second phase: set the constraints for our children
f03fc89f
VZ
1909bool wxWindowBase::LayoutPhase2(int *noChanges)
1910{
1911 *noChanges = 0;
1912
1913 // Layout children
1914 DoPhase(1);
ec5bb70d
VZ
1915
1916 // Layout grand children
f03fc89f 1917 DoPhase(2);
ec5bb70d 1918
e11f4636 1919 return true;
f03fc89f
VZ
1920}
1921
1922// Do a phase of evaluating child constraints
1923bool wxWindowBase::DoPhase(int phase)
1924{
ec5bb70d
VZ
1925 // the list containing the children for which the constraints are already
1926 // set correctly
f03fc89f 1927 wxWindowList succeeded;
ec5bb70d
VZ
1928
1929 // the max number of iterations we loop before concluding that we can't set
1930 // the constraints
1931 static const int maxIterations = 500;
1932
1933 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
f03fc89f 1934 {
ec5bb70d
VZ
1935 int noChanges = 0;
1936
1937 // loop over all children setting their constraints
222ed1d6 1938 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
ec5bb70d
VZ
1939 node;
1940 node = node->GetNext() )
f03fc89f
VZ
1941 {
1942 wxWindow *child = node->GetData();
ec5bb70d 1943 if ( child->IsTopLevel() )
f03fc89f 1944 {
ec5bb70d
VZ
1945 // top level children are not inside our client area
1946 continue;
1947 }
1948
1949 if ( !child->GetConstraints() || succeeded.Find(child) )
1950 {
1951 // this one is either already ok or nothing we can do about it
1952 continue;
1953 }
1954
1955 int tempNoChanges = 0;
1956 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1957 : child->LayoutPhase2(&tempNoChanges);
1958 noChanges += tempNoChanges;
1959
1960 if ( success )
1961 {
1962 succeeded.Append(child);
f03fc89f 1963 }
f03fc89f
VZ
1964 }
1965
ec5bb70d
VZ
1966 if ( !noChanges )
1967 {
1968 // constraints are set
1969 break;
1970 }
f03fc89f
VZ
1971 }
1972
e11f4636 1973 return true;
f03fc89f
VZ
1974}
1975
1976void wxWindowBase::ResetConstraints()
1977{
1978 wxLayoutConstraints *constr = GetConstraints();
1979 if ( constr )
1980 {
e11f4636
DS
1981 constr->left.SetDone(false);
1982 constr->top.SetDone(false);
1983 constr->right.SetDone(false);
1984 constr->bottom.SetDone(false);
1985 constr->width.SetDone(false);
1986 constr->height.SetDone(false);
1987 constr->centreX.SetDone(false);
1988 constr->centreY.SetDone(false);
f03fc89f 1989 }
f1df0927 1990
222ed1d6 1991 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
f03fc89f
VZ
1992 while (node)
1993 {
1994 wxWindow *win = node->GetData();
34636400 1995 if ( !win->IsTopLevel() )
f03fc89f
VZ
1996 win->ResetConstraints();
1997 node = node->GetNext();
1998 }
1999}
2000
2001// Need to distinguish between setting the 'fake' size for windows and sizers,
2002// and setting the real values.
2003void wxWindowBase::SetConstraintSizes(bool recurse)
2004{
2005 wxLayoutConstraints *constr = GetConstraints();
4b7f2165 2006 if ( constr && constr->AreSatisfied() )
f03fc89f
VZ
2007 {
2008 int x = constr->left.GetValue();
2009 int y = constr->top.GetValue();
2010 int w = constr->width.GetValue();
2011 int h = constr->height.GetValue();
2012
f03fc89f 2013 if ( (constr->width.GetRelationship() != wxAsIs ) ||
3417c2cd 2014 (constr->height.GetRelationship() != wxAsIs) )
f03fc89f 2015 {
3417c2cd 2016 SetSize(x, y, w, h);
f03fc89f
VZ
2017 }
2018 else
2019 {
3417c2cd
RR
2020 // If we don't want to resize this window, just move it...
2021 Move(x, y);
f03fc89f
VZ
2022 }
2023 }
2024 else if ( constr )
2025 {
4b7f2165 2026 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
f1df0927 2027 GetClassInfo()->GetClassName(),
4b7f2165 2028 GetName().c_str());
f03fc89f
VZ
2029 }
2030
2031 if ( recurse )
2032 {
222ed1d6 2033 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
f03fc89f
VZ
2034 while (node)
2035 {
2036 wxWindow *win = node->GetData();
e2f9212c 2037 if ( !win->IsTopLevel() && win->GetConstraints() )
f03fc89f
VZ
2038 win->SetConstraintSizes();
2039 node = node->GetNext();
2040 }
2041 }
2042}
2043
f03fc89f
VZ
2044// Only set the size/position of the constraint (if any)
2045void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
2046{
2047 wxLayoutConstraints *constr = GetConstraints();
2048 if ( constr )
2049 {
422d0ff0 2050 if ( x != wxDefaultCoord )
f03fc89f
VZ
2051 {
2052 constr->left.SetValue(x);
e11f4636 2053 constr->left.SetDone(true);
f03fc89f 2054 }
422d0ff0 2055 if ( y != wxDefaultCoord )
f03fc89f
VZ
2056 {
2057 constr->top.SetValue(y);
e11f4636 2058 constr->top.SetDone(true);
f03fc89f 2059 }
422d0ff0 2060 if ( w != wxDefaultCoord )
f03fc89f
VZ
2061 {
2062 constr->width.SetValue(w);
e11f4636 2063 constr->width.SetDone(true);
f03fc89f 2064 }
422d0ff0 2065 if ( h != wxDefaultCoord )
f03fc89f
VZ
2066 {
2067 constr->height.SetValue(h);
e11f4636 2068 constr->height.SetDone(true);
f03fc89f
VZ
2069 }
2070 }
2071}
2072
2073void wxWindowBase::MoveConstraint(int x, int y)
2074{
2075 wxLayoutConstraints *constr = GetConstraints();
2076 if ( constr )
2077 {
422d0ff0 2078 if ( x != wxDefaultCoord )
f03fc89f
VZ
2079 {
2080 constr->left.SetValue(x);
e11f4636 2081 constr->left.SetDone(true);
f03fc89f 2082 }
422d0ff0 2083 if ( y != wxDefaultCoord )
f03fc89f
VZ
2084 {
2085 constr->top.SetValue(y);
e11f4636 2086 constr->top.SetDone(true);
f03fc89f
VZ
2087 }
2088 }
2089}
2090
2091void wxWindowBase::GetSizeConstraint(int *w, int *h) const
2092{
2093 wxLayoutConstraints *constr = GetConstraints();
2094 if ( constr )
2095 {
2096 *w = constr->width.GetValue();
2097 *h = constr->height.GetValue();
2098 }
2099 else
2100 GetSize(w, h);
2101}
2102
2103void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
2104{
2105 wxLayoutConstraints *constr = GetConstraints();
2106 if ( constr )
2107 {
2108 *w = constr->width.GetValue();
2109 *h = constr->height.GetValue();
2110 }
2111 else
2112 GetClientSize(w, h);
2113}
2114
461e93f9
JS
2115void wxWindowBase::GetPositionConstraint(int *x, int *y) const
2116{
2117 wxLayoutConstraints *constr = GetConstraints();
2118 if ( constr )
2119 {
2120 *x = constr->left.GetValue();
2121 *y = constr->top.GetValue();
2122 }
2123 else
2124 GetPosition(x, y);
2125}
2126
2127#endif // wxUSE_CONSTRAINTS
2128
20a1eea1 2129void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
a200c35e
VS
2130{
2131 // don't do it for the dialogs/frames - they float independently of their
2132 // parent
2133 if ( !IsTopLevel() )
2134 {
2135 wxWindow *parent = GetParent();
2136 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
2137 {
2138 wxPoint pt(parent->GetClientAreaOrigin());
2139 x += pt.x;
2140 y += pt.y;
2141 }
2142 }
2143}
2144
f03fc89f 2145// ----------------------------------------------------------------------------
602a2e02 2146// Update UI processing
f03fc89f 2147// ----------------------------------------------------------------------------
7ec1983b 2148
e39af974 2149void wxWindowBase::UpdateWindowUI(long flags)
7ec1983b 2150{
26bf1ce0 2151 wxUpdateUIEvent event(GetId());
687706f5 2152 event.SetEventObject(this);
26bf1ce0
VZ
2153
2154 if ( GetEventHandler()->ProcessEvent(event) )
7ec1983b 2155 {
e39af974
JS
2156 DoUpdateWindowUI(event);
2157 }
7ec1983b 2158
e39af974
JS
2159 if (flags & wxUPDATE_UI_RECURSE)
2160 {
222ed1d6 2161 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
e39af974 2162 while (node)
f03fc89f 2163 {
e39af974
JS
2164 wxWindow* child = (wxWindow*) node->GetData();
2165 child->UpdateWindowUI(flags);
2166 node = node->GetNext();
26bf1ce0 2167 }
e39af974
JS
2168 }
2169}
f03fc89f 2170
e39af974 2171// do the window-specific processing after processing the update event
e39af974
JS
2172void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
2173{
2174 if ( event.GetSetEnabled() )
2175 Enable(event.GetEnabled());
e11f4636 2176
a3a4105d
VZ
2177 if ( event.GetSetShown() )
2178 Show(event.GetShown());
e39af974
JS
2179}
2180
f03fc89f
VZ
2181// ----------------------------------------------------------------------------
2182// dialog units translations
2183// ----------------------------------------------------------------------------
2184
2185wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
fd71308f
JS
2186{
2187 int charWidth = GetCharWidth();
2188 int charHeight = GetCharHeight();
cab1a605
WS
2189 wxPoint pt2 = wxDefaultPosition;
2190 if (pt.x != wxDefaultCoord)
1b69c815 2191 pt2.x = (int) ((pt.x * 4) / charWidth);
cab1a605 2192 if (pt.y != wxDefaultCoord)
1b69c815 2193 pt2.y = (int) ((pt.y * 8) / charHeight);
fd71308f
JS
2194
2195 return pt2;
2196}
2197
f03fc89f 2198wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
fd71308f
JS
2199{
2200 int charWidth = GetCharWidth();
2201 int charHeight = GetCharHeight();
cab1a605
WS
2202 wxPoint pt2 = wxDefaultPosition;
2203 if (pt.x != wxDefaultCoord)
1b69c815 2204 pt2.x = (int) ((pt.x * charWidth) / 4);
cab1a605 2205 if (pt.y != wxDefaultCoord)
1b69c815 2206 pt2.y = (int) ((pt.y * charHeight) / 8);
fd71308f
JS
2207
2208 return pt2;
2209}
2210
f03fc89f
VZ
2211// ----------------------------------------------------------------------------
2212// event handlers
2213// ----------------------------------------------------------------------------
2214
2215// propagate the colour change event to the subwindows
2216void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
2217{
222ed1d6 2218 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
f03fc89f
VZ
2219 while ( node )
2220 {
2221 // Only propagate to non-top-level windows
2222 wxWindow *win = node->GetData();
2223 if ( !win->IsTopLevel() )
2224 {
2225 wxSysColourChangedEvent event2;
687706f5 2226 event.SetEventObject(win);
f03fc89f
VZ
2227 win->GetEventHandler()->ProcessEvent(event2);
2228 }
2229
2230 node = node->GetNext();
2231 }
9a8477e1
VS
2232
2233 Refresh();
f03fc89f
VZ
2234}
2235
e39af974
JS
2236// the default action is to populate dialog with data when it's created,
2237// and nudge the UI into displaying itself correctly in case
2238// we've turned the wxUpdateUIEvents frequency down low.
f03fc89f
VZ
2239void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2240{
2241 TransferDataToWindow();
e11f4636 2242
e39af974
JS
2243 // Update the UI at this point
2244 UpdateWindowUI(wxUPDATE_UI_RECURSE);
f03fc89f
VZ
2245}
2246
00a77b7c
VZ
2247// ----------------------------------------------------------------------------
2248// menu-related functions
2249// ----------------------------------------------------------------------------
2250
2251#if wxUSE_MENUS
2252
eeb0bee1
VZ
2253bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y)
2254{
2255 wxCHECK_MSG( menu, false, "can't popup NULL menu" );
2256
2257 wxCurrentPopupMenu = menu;
2258 const bool rc = DoPopupMenu(menu, x, y);
2259 wxCurrentPopupMenu = NULL;
2260
2261 return rc;
2262}
2263
00a77b7c
VZ
2264// this is used to pass the id of the selected item from the menu event handler
2265// to the main function itself
2266//
2267// it's ok to use a global here as there can be at most one popup menu shown at
2268// any time
2269static int gs_popupMenuSelection = wxID_NONE;
2270
2271void wxWindowBase::InternalOnPopupMenu(wxCommandEvent& event)
2272{
2273 // store the id in a global variable where we'll retrieve it from later
2274 gs_popupMenuSelection = event.GetId();
2275}
2276
2277int
2278wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y)
2279{
2280 gs_popupMenuSelection = wxID_NONE;
2281
2282 Connect(wxEVT_COMMAND_MENU_SELECTED,
2283 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2284 NULL,
2285 this);
2286
2287 PopupMenu(&menu, x, y);
2288
2289 Disconnect(wxEVT_COMMAND_MENU_SELECTED,
2290 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2291 NULL,
2292 this);
2293
2294 return gs_popupMenuSelection;
2295}
2296
2297#endif // wxUSE_MENUS
2298
dddd1f21
VZ
2299// methods for drawing the sizers in a visible way
2300#ifdef __WXDEBUG__
2301
2302static void DrawSizers(wxWindowBase *win);
2303
2304static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false)
2305{
2306 wxClientDC dc((wxWindow *)win);
2307 dc.SetPen(*wxRED_PEN);
2308 dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH);
2309 dc.DrawRectangle(rect.Deflate(1, 1));
2310}
2311
2312static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2313{
2314 const wxSizerItemList& items = sizer->GetChildren();
2315 for ( wxSizerItemList::const_iterator i = items.begin(),
2316 end = items.end();
2317 i != end;
2318 ++i )
2319 {
2320 wxSizerItem *item = *i;
2321 if ( item->IsSizer() )
2322 {
2323 DrawBorder(win, item->GetRect().Deflate(2));
2324 DrawSizer(win, item->GetSizer());
2325 }
2326 else if ( item->IsSpacer() )
2327 {
2328 DrawBorder(win, item->GetRect().Deflate(2), true);
2329 }
2330 else if ( item->IsWindow() )
2331 {
2332 DrawSizers(item->GetWindow());
2333 }
2334 }
2335}
2336
2337static void DrawSizers(wxWindowBase *win)
2338{
2339 wxSizer *sizer = win->GetSizer();
2340 if ( sizer )
2341 {
2342 DrawBorder(win, win->GetClientSize());
2343 DrawSizer(win, sizer);
2344 }
2345 else // no sizer, still recurse into the children
2346 {
2347 const wxWindowList& children = win->GetChildren();
2348 for ( wxWindowList::const_iterator i = children.begin(),
2349 end = children.end();
2350 i != end;
2351 ++i )
2352 {
2353 DrawSizers(*i);
2354 }
2355 }
2356}
2357
2358#endif // __WXDEBUG__
2359
2360// process special middle clicks
a02dc3e3
VZ
2361void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2362{
2363 if ( event.ControlDown() && event.AltDown() )
2364 {
dddd1f21
VZ
2365#ifdef __WXDEBUG__
2366 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2367 if ( event.ShiftDown() )
2368 {
2369 DrawSizers(this);
2370 return;
2371 }
2372#endif // __WXDEBUG__
8cf304f8 2373 ::wxInfoMessageBox((wxWindow*)this);
a02dc3e3
VZ
2374 }
2375 else
2376 {
2377 event.Skip();
2378 }
2379}
2380
ed5317e5
JS
2381// ----------------------------------------------------------------------------
2382// accessibility
2383// ----------------------------------------------------------------------------
2384
2385#if wxUSE_ACCESSIBILITY
2386void wxWindowBase::SetAccessible(wxAccessible* accessible)
2387{
2aefc528 2388 if (m_accessible && (accessible != m_accessible))
ed5317e5
JS
2389 delete m_accessible;
2390 m_accessible = accessible;
2391 if (m_accessible)
2392 m_accessible->SetWindow((wxWindow*) this);
2393}
2394
2395// Returns the accessible object, creating if necessary.
2396wxAccessible* wxWindowBase::GetOrCreateAccessible()
2397{
2398 if (!m_accessible)
2399 m_accessible = CreateAccessible();
2400 return m_accessible;
2401}
2402
2403// Override to create a specific accessible object.
2404wxAccessible* wxWindowBase::CreateAccessible()
2405{
2406 return new wxWindowAccessible((wxWindow*) this);
2407}
2408
2409#endif
2410
f03fc89f
VZ
2411// ----------------------------------------------------------------------------
2412// list classes implementation
2413// ----------------------------------------------------------------------------
2414
ed1288c1
VZ
2415#if wxUSE_STL
2416
7ec69821 2417#include "wx/listimpl.cpp"
412e0d47 2418WX_DEFINE_LIST(wxWindowList)
ed1288c1 2419
602a2e02 2420#else // !wxUSE_STL
ed1288c1 2421
f03fc89f
VZ
2422void wxWindowListNode::DeleteData()
2423{
2424 delete (wxWindow *)GetData();
2425}
ed1288c1 2426
602a2e02 2427#endif // wxUSE_STL/!wxUSE_STL
f03fc89f 2428
1e6feb95
VZ
2429// ----------------------------------------------------------------------------
2430// borders
2431// ----------------------------------------------------------------------------
2432
aede4ebb 2433wxBorder wxWindowBase::GetBorder(long flags) const
1e6feb95 2434{
aede4ebb 2435 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
1e6feb95
VZ
2436 if ( border == wxBORDER_DEFAULT )
2437 {
2438 border = GetDefaultBorder();
2439 }
78cd9c69
JS
2440 else if ( border == wxBORDER_THEME )
2441 {
2442 border = GetDefaultBorderForControl();
2443 }
1e6feb95
VZ
2444
2445 return border;
2446}
2447
2448wxBorder wxWindowBase::GetDefaultBorder() const
2449{
2450 return wxBORDER_NONE;
2451}
2452
2453// ----------------------------------------------------------------------------
2454// hit testing
2455// ----------------------------------------------------------------------------
2456
2457wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2458{
2459 // here we just check if the point is inside the window or not
2460
2461 // check the top and left border first
2462 bool outside = x < 0 || y < 0;
2463 if ( !outside )
2464 {
2465 // check the right and bottom borders too
2466 wxSize size = GetSize();
2467 outside = x >= size.x || y >= size.y;
2468 }
2469
2470 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2471}
2472
94633ad9
VZ
2473// ----------------------------------------------------------------------------
2474// mouse capture
2475// ----------------------------------------------------------------------------
2476
2477struct WXDLLEXPORT wxWindowNext
2478{
2479 wxWindow *win;
2480 wxWindowNext *next;
786646f3 2481} *wxWindowBase::ms_winCaptureNext = NULL;
63e819f2
VS
2482wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL;
2483bool wxWindowBase::ms_winCaptureChanging = false;
94633ad9 2484
a83e1475 2485void wxWindowBase::CaptureMouse()
94633ad9 2486{
008202b7 2487 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
45e0dc94 2488
63e819f2
VS
2489 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") );
2490
2491 ms_winCaptureChanging = true;
2492
94633ad9
VZ
2493 wxWindow *winOld = GetCapture();
2494 if ( winOld )
2495 {
df2f507b 2496 ((wxWindowBase*) winOld)->DoReleaseMouse();
edd802c6 2497
94633ad9
VZ
2498 // save it on stack
2499 wxWindowNext *item = new wxWindowNext;
2500 item->win = winOld;
2501 item->next = ms_winCaptureNext;
2502 ms_winCaptureNext = item;
2503 }
2504 //else: no mouse capture to save
2505
2506 DoCaptureMouse();
63e819f2
VS
2507 ms_winCaptureCurrent = (wxWindow*)this;
2508
2509 ms_winCaptureChanging = false;
94633ad9
VZ
2510}
2511
a83e1475 2512void wxWindowBase::ReleaseMouse()
94633ad9 2513{
008202b7 2514 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
349d1942 2515
63e819f2
VS
2516 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") );
2517
63fd5f0b 2518 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
a7b09001 2519
63e819f2
VS
2520 ms_winCaptureChanging = true;
2521
94633ad9 2522 DoReleaseMouse();
63e819f2 2523 ms_winCaptureCurrent = NULL;
94633ad9
VZ
2524
2525 if ( ms_winCaptureNext )
2526 {
44f8caa7 2527 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
63e819f2 2528 ms_winCaptureCurrent = ms_winCaptureNext->win;
edd802c6 2529
94633ad9
VZ
2530 wxWindowNext *item = ms_winCaptureNext;
2531 ms_winCaptureNext = item->next;
2532 delete item;
2533 }
2534 //else: stack is empty, no previous capture
2535
63e819f2
VS
2536 ms_winCaptureChanging = false;
2537
94633ad9 2538 wxLogTrace(_T("mousecapture"),
e11f4636 2539 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
008202b7 2540 wx_static_cast(void*, GetCapture()));
94633ad9
VZ
2541}
2542
63e819f2
VS
2543static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
2544{
2545 wxMouseCaptureLostEvent event(win->GetId());
2546 event.SetEventObject(win);
40bdc5d6
VZ
2547 if ( !win->GetEventHandler()->ProcessEvent(event) )
2548 {
44038f9a
VS
2549 // windows must handle this event, otherwise the app wouldn't behave
2550 // correctly if it loses capture unexpectedly; see the discussion here:
2551 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2552 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
40bdc5d6
VZ
2553 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2554 }
63e819f2
VS
2555}
2556
2557/* static */
72f8c792 2558void wxWindowBase::NotifyCaptureLost()
63e819f2
VS
2559{
2560 // don't do anything if capture lost was expected, i.e. resulted from
2561 // a wx call to ReleaseMouse or CaptureMouse:
2562 if ( ms_winCaptureChanging )
2563 return;
2564
2565 // if the capture was lost unexpectedly, notify every window that has
2566 // capture (on stack or current) about it and clear the stack:
2567
2568 if ( ms_winCaptureCurrent )
2569 {
2570 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent);
2571 ms_winCaptureCurrent = NULL;
2572 }
2573
2574 while ( ms_winCaptureNext )
2575 {
2576 wxWindowNext *item = ms_winCaptureNext;
2577 ms_winCaptureNext = item->next;
2578
2579 DoNotifyWindowAboutCaptureLost(item->win);
2580
2581 delete item;
2582 }
2583}
2584
5048c832 2585#if wxUSE_HOTKEY
540b6b09
VZ
2586
2587bool
2588wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2589 int WXUNUSED(modifiers),
2590 int WXUNUSED(keycode))
5048c832
JS
2591{
2592 // not implemented
2593 return false;
2594}
2595
540b6b09 2596bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
5048c832
JS
2597{
2598 // not implemented
2599 return false;
2600}
540b6b09
VZ
2601
2602#endif // wxUSE_HOTKEY
7de59551 2603
4caf847c
VZ
2604// ----------------------------------------------------------------------------
2605// event processing
2606// ----------------------------------------------------------------------------
2607
ac8d0c11 2608bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
4caf847c 2609{
6eabf58c 2610#if wxUSE_VALIDATORS
4caf847c
VZ
2611 // Can only use the validator of the window which
2612 // is receiving the event
2613 if ( event.GetEventObject() == this )
2614 {
2615 wxValidator *validator = GetValidator();
2616 if ( validator && validator->ProcessEvent(event) )
2617 {
6eabf58c 2618 return true;
4caf847c
VZ
2619 }
2620 }
6eabf58c 2621#endif // wxUSE_VALIDATORS
4caf847c 2622
6eabf58c 2623 return false;
4caf847c
VZ
2624}
2625
4caf847c
VZ
2626bool wxWindowBase::TryParent(wxEvent& event)
2627{
90e572f1 2628 // carry on up the parent-child hierarchy if the propagation count hasn't
040e234d
VZ
2629 // reached zero yet
2630 if ( event.ShouldPropagate() )
4caf847c
VZ
2631 {
2632 // honour the requests to stop propagation at this window: this is
2633 // used by the dialogs, for example, to prevent processing the events
2634 // from the dialog controls in the parent frame which rarely, if ever,
2635 // makes sense
2636 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2637 {
2638 wxWindow *parent = GetParent();
2639 if ( parent && !parent->IsBeingDeleted() )
040e234d
VZ
2640 {
2641 wxPropagateOnce propagateOnce(event);
2642
4caf847c 2643 return parent->GetEventHandler()->ProcessEvent(event);
040e234d 2644 }
4caf847c
VZ
2645 }
2646 }
2647
2648 return wxEvtHandler::TryParent(event);
2649}
2650
c944775f
VZ
2651// ----------------------------------------------------------------------------
2652// window relationships
2653// ----------------------------------------------------------------------------
2654
2655wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const
2656{
2657 wxCHECK_MSG( GetParent(), NULL,
2658 _T("GetPrev/NextSibling() don't work for TLWs!") );
2659
2660 wxWindowList& siblings = GetParent()->GetChildren();
c52b9635 2661 wxWindowList::compatibility_iterator i = siblings.Find((wxWindow *)this);
c944775f
VZ
2662 wxCHECK_MSG( i, NULL, _T("window not a child of its parent?") );
2663
2664 if ( order == OrderBefore )
2665 i = i->GetPrevious();
2666 else // OrderAfter
2667 i = i->GetNext();
2668
2669 return i ? i->GetData() : NULL;
2670}
2671
5f6cfda7 2672// ----------------------------------------------------------------------------
a24de76b 2673// keyboard navigation
5f6cfda7
JS
2674// ----------------------------------------------------------------------------
2675
5644933f 2676// Navigates in the specified direction inside this window
553d2d7d 2677bool wxWindowBase::DoNavigateIn(int flags)
5f6cfda7 2678{
5644933f
VZ
2679#ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2680 // native code doesn't process our wxNavigationKeyEvents anyhow
553d2d7d 2681 wxUnusedVar(flags);
5644933f
VZ
2682 return false;
2683#else // !wxHAS_NATIVE_TAB_TRAVERSAL
5f6cfda7 2684 wxNavigationKeyEvent eventNav;
eedc82f4 2685 eventNav.SetFlags(flags);
5644933f
VZ
2686 eventNav.SetEventObject(FindFocus());
2687 return GetEventHandler()->ProcessEvent(eventNav);
2688#endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
5f6cfda7
JS
2689}
2690
c944775f 2691void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move)
a24de76b
VZ
2692{
2693 // check that we're not a top level window
2694 wxCHECK_RET( GetParent(),
2695 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2696
ef6816ef
VZ
2697 // detect the special case when we have nothing to do anyhow and when the
2698 // code below wouldn't work
2699 if ( win == this )
2700 return;
2701
a24de76b
VZ
2702 // find the target window in the siblings list
2703 wxWindowList& siblings = GetParent()->GetChildren();
2704 wxWindowList::compatibility_iterator i = siblings.Find(win);
2705 wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2706
2707 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2708 // can't just move the node around
feef1ecf
VZ
2709 wxWindow *self = (wxWindow *)this;
2710 siblings.DeleteObject(self);
c944775f 2711 if ( move == OrderAfter )
9e9300c4
VZ
2712 {
2713 i = i->GetNext();
2714 }
2715
2716 if ( i )
a24de76b 2717 {
feef1ecf 2718 siblings.Insert(i, self);
a24de76b 2719 }
c944775f 2720 else // OrderAfter and win was the last sibling
a24de76b 2721 {
feef1ecf 2722 siblings.Append(self);
a24de76b
VZ
2723 }
2724}
2725
0fe02759
VS
2726// ----------------------------------------------------------------------------
2727// focus handling
2728// ----------------------------------------------------------------------------
2729
2730/*static*/ wxWindow* wxWindowBase::FindFocus()
2731{
9c52a429 2732 wxWindowBase *win = DoFindFocus();
0fe02759
VS
2733 return win ? win->GetMainWindowOfCompositeControl() : NULL;
2734}
2735
3358af0f
VS
2736bool wxWindowBase::HasFocus() const
2737{
2738 wxWindowBase *win = DoFindFocus();
2739 return win == this ||
2740 win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl();
2741}
2742
33b494d6
VZ
2743// ----------------------------------------------------------------------------
2744// global functions
2745// ----------------------------------------------------------------------------
2746
2747wxWindow* wxGetTopLevelParent(wxWindow *win)
2748{
2749 while ( win && !win->IsTopLevel() )
2750 win = win->GetParent();
2751
2752 return win;
2753}
2754
ed5317e5
JS
2755#if wxUSE_ACCESSIBILITY
2756// ----------------------------------------------------------------------------
2757// accessible object for windows
2758// ----------------------------------------------------------------------------
2759
2760// Can return either a child object, or an integer
2761// representing the child element, starting from 1.
66b9ec3d 2762wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
ed5317e5
JS
2763{
2764 wxASSERT( GetWindow() != NULL );
2765 if (!GetWindow())
2766 return wxACC_FAIL;
2767
2768 return wxACC_NOT_IMPLEMENTED;
2769}
2770
2771// Returns the rectangle for this object (id = 0) or a child element (id > 0).
2772wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2773{
2774 wxASSERT( GetWindow() != NULL );
2775 if (!GetWindow())
2776 return wxACC_FAIL;
2777
c6e2af45
JS
2778 wxWindow* win = NULL;
2779 if (elementId == 0)
2780 {
2781 win = GetWindow();
2782 }
2783 else
2784 {
2785 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2786 {
ee6eb8d8 2787 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
c6e2af45
JS
2788 }
2789 else
2790 return wxACC_FAIL;
2791 }
2792 if (win)
2793 {
2794 rect = win->GetRect();
2795 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2796 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2797 return wxACC_OK;
2798 }
2799
ed5317e5
JS
2800 return wxACC_NOT_IMPLEMENTED;
2801}
2802
2803// Navigates from fromId to toId/toObject.
2804wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
66b9ec3d 2805 int* WXUNUSED(toId), wxAccessible** toObject)
ed5317e5
JS
2806{
2807 wxASSERT( GetWindow() != NULL );
2808 if (!GetWindow())
2809 return wxACC_FAIL;
2810
c6e2af45
JS
2811 switch (navDir)
2812 {
2813 case wxNAVDIR_FIRSTCHILD:
2814 {
2815 if (GetWindow()->GetChildren().GetCount() == 0)
2816 return wxACC_FALSE;
2817 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2818 *toObject = childWindow->GetOrCreateAccessible();
2819
2820 return wxACC_OK;
2821 }
2822 case wxNAVDIR_LASTCHILD:
2823 {
2824 if (GetWindow()->GetChildren().GetCount() == 0)
2825 return wxACC_FALSE;
2826 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2827 *toObject = childWindow->GetOrCreateAccessible();
2828
2829 return wxACC_OK;
2830 }
2831 case wxNAVDIR_RIGHT:
2832 case wxNAVDIR_DOWN:
2833 case wxNAVDIR_NEXT:
2834 {
ee6eb8d8
MB
2835 wxWindowList::compatibility_iterator node =
2836 wxWindowList::compatibility_iterator();
c6e2af45
JS
2837 if (fromId == 0)
2838 {
2839 // Can't navigate to sibling of this window
2840 // if we're a top-level window.
2841 if (!GetWindow()->GetParent())
2842 return wxACC_NOT_IMPLEMENTED;
2843
2844 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2845 }
2846 else
2847 {
2848 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
33b3f7c3 2849 node = GetWindow()->GetChildren().Item(fromId-1);
c6e2af45
JS
2850 }
2851
2852 if (node && node->GetNext())
2853 {
ee6eb8d8 2854 wxWindow* nextWindow = node->GetNext()->GetData();
c6e2af45
JS
2855 *toObject = nextWindow->GetOrCreateAccessible();
2856 return wxACC_OK;
2857 }
2858 else
2859 return wxACC_FALSE;
2860 }
2861 case wxNAVDIR_LEFT:
2862 case wxNAVDIR_UP:
2863 case wxNAVDIR_PREVIOUS:
2864 {
ee6eb8d8
MB
2865 wxWindowList::compatibility_iterator node =
2866 wxWindowList::compatibility_iterator();
c6e2af45
JS
2867 if (fromId == 0)
2868 {
2869 // Can't navigate to sibling of this window
2870 // if we're a top-level window.
2871 if (!GetWindow()->GetParent())
2872 return wxACC_NOT_IMPLEMENTED;
2873
2874 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2875 }
2876 else
2877 {
2878 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
33b3f7c3 2879 node = GetWindow()->GetChildren().Item(fromId-1);
c6e2af45
JS
2880 }
2881
2882 if (node && node->GetPrevious())
2883 {
ee6eb8d8 2884 wxWindow* previousWindow = node->GetPrevious()->GetData();
c6e2af45
JS
2885 *toObject = previousWindow->GetOrCreateAccessible();
2886 return wxACC_OK;
2887 }
2888 else
2889 return wxACC_FALSE;
2890 }
2891 }
2892
ed5317e5
JS
2893 return wxACC_NOT_IMPLEMENTED;
2894}
2895
2896// Gets the name of the specified object.
2897wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2898{
2899 wxASSERT( GetWindow() != NULL );
2900 if (!GetWindow())
2901 return wxACC_FAIL;
2902
2aefc528
JS
2903 wxString title;
2904
77ffb593 2905 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
2906 // child object.
2907 if (childId > 0)
2908 return wxACC_NOT_IMPLEMENTED;
2909
2910 // This will eventually be replaced by specialised
77ffb593 2911 // accessible classes, one for each kind of wxWidgets
2aefc528 2912 // control or window.
0b4f47a3 2913#if wxUSE_BUTTON
2aefc528
JS
2914 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2915 title = ((wxButton*) GetWindow())->GetLabel();
2916 else
0b4f47a3 2917#endif
2aefc528 2918 title = GetWindow()->GetName();
e11f4636 2919
ba889513 2920 if (!title.empty())
ed5317e5
JS
2921 {
2922 *name = title;
2923 return wxACC_OK;
2924 }
2925 else
2926 return wxACC_NOT_IMPLEMENTED;
2927}
2928
2929// Gets the number of children.
2930wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2931{
2932 wxASSERT( GetWindow() != NULL );
2933 if (!GetWindow())
2934 return wxACC_FAIL;
2935
2936 *childId = (int) GetWindow()->GetChildren().GetCount();
2937 return wxACC_OK;
2938}
2939
2940// Gets the specified child (starting from 1).
2941// If *child is NULL and return value is wxACC_OK,
2942// this means that the child is a simple element and
2943// not an accessible object.
2944wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2945{
2946 wxASSERT( GetWindow() != NULL );
2947 if (!GetWindow())
2948 return wxACC_FAIL;
2949
2950 if (childId == 0)
2951 {
2952 *child = this;
2953 return wxACC_OK;
2954 }
2955
2956 if (childId > (int) GetWindow()->GetChildren().GetCount())
2957 return wxACC_FAIL;
2958
ee6eb8d8 2959 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
ed5317e5
JS
2960 *child = childWindow->GetOrCreateAccessible();
2961 if (*child)
2962 return wxACC_OK;
2963 else
2964 return wxACC_FAIL;
2965}
2966
2967// Gets the parent, or NULL.
2968wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2969{
2970 wxASSERT( GetWindow() != NULL );
2971 if (!GetWindow())
2972 return wxACC_FAIL;
2973
2974 wxWindow* parentWindow = GetWindow()->GetParent();
c6e2af45 2975 if (!parentWindow)
ed5317e5
JS
2976 {
2977 *parent = NULL;
2978 return wxACC_OK;
2979 }
2980 else
2981 {
2982 *parent = parentWindow->GetOrCreateAccessible();
2983 if (*parent)
2984 return wxACC_OK;
2985 else
2986 return wxACC_FAIL;
2987 }
2988}
2989
2990// Performs the default action. childId is 0 (the action for this object)
2991// or > 0 (the action for a child).
2992// Return wxACC_NOT_SUPPORTED if there is no default action for this
2993// window (e.g. an edit control).
66b9ec3d 2994wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
ed5317e5
JS
2995{
2996 wxASSERT( GetWindow() != NULL );
2997 if (!GetWindow())
2998 return wxACC_FAIL;
2999
3000 return wxACC_NOT_IMPLEMENTED;
3001}
3002
3003// Gets the default action for this object (0) or > 0 (the action for a child).
3004// Return wxACC_OK even if there is no action. actionName is the action, or the empty
3005// string if there is no action.
3006// The retrieved string describes the action that is performed on an object,
3007// not what the object does as a result. For example, a toolbar button that prints
3008// a document has a default action of "Press" rather than "Prints the current document."
66b9ec3d 3009wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
ed5317e5
JS
3010{
3011 wxASSERT( GetWindow() != NULL );
3012 if (!GetWindow())
3013 return wxACC_FAIL;
3014
3015 return wxACC_NOT_IMPLEMENTED;
3016}
3017
3018// Returns the description for this object or a child.
66b9ec3d 3019wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
ed5317e5
JS
3020{
3021 wxASSERT( GetWindow() != NULL );
3022 if (!GetWindow())
3023 return wxACC_FAIL;
3024
dc6588e7 3025 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
ba889513 3026 if (!ht.empty())
2aefc528
JS
3027 {
3028 *description = ht;
3029 return wxACC_OK;
3030 }
ed5317e5
JS
3031 return wxACC_NOT_IMPLEMENTED;
3032}
3033
3034// Returns help text for this object or a child, similar to tooltip text.
66b9ec3d 3035wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
ed5317e5
JS
3036{
3037 wxASSERT( GetWindow() != NULL );
3038 if (!GetWindow())
3039 return wxACC_FAIL;
3040
dc6588e7 3041 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
ba889513 3042 if (!ht.empty())
ed5317e5
JS
3043 {
3044 *helpText = ht;
3045 return wxACC_OK;
3046 }
3047 return wxACC_NOT_IMPLEMENTED;
3048}
3049
3050// Returns the keyboard shortcut for this object or child.
3051// Return e.g. ALT+K
66b9ec3d 3052wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
ed5317e5
JS
3053{
3054 wxASSERT( GetWindow() != NULL );
3055 if (!GetWindow())
3056 return wxACC_FAIL;
3057
3058 return wxACC_NOT_IMPLEMENTED;
3059}
3060
3061// Returns a role constant.
3062wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
3063{
3064 wxASSERT( GetWindow() != NULL );
3065 if (!GetWindow())
3066 return wxACC_FAIL;
3067
77ffb593 3068 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
3069 // child object.
3070 if (childId > 0)
3071 return wxACC_NOT_IMPLEMENTED;
3072
3073 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3074 return wxACC_NOT_IMPLEMENTED;
3075#if wxUSE_STATUSBAR
3076 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3077 return wxACC_NOT_IMPLEMENTED;
3078#endif
3079#if wxUSE_TOOLBAR
3080 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3081 return wxACC_NOT_IMPLEMENTED;
3082#endif
3083
3084 //*role = wxROLE_SYSTEM_CLIENT;
3085 *role = wxROLE_SYSTEM_CLIENT;
3086 return wxACC_OK;
3087
66b9ec3d 3088 #if 0
ed5317e5 3089 return wxACC_NOT_IMPLEMENTED;
66b9ec3d 3090 #endif
ed5317e5
JS
3091}
3092
3093// Returns a state constant.
3094wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
3095{
3096 wxASSERT( GetWindow() != NULL );
3097 if (!GetWindow())
3098 return wxACC_FAIL;
3099
77ffb593 3100 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
3101 // child object.
3102 if (childId > 0)
3103 return wxACC_NOT_IMPLEMENTED;
3104
3105 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3106 return wxACC_NOT_IMPLEMENTED;
3107
3108#if wxUSE_STATUSBAR
3109 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3110 return wxACC_NOT_IMPLEMENTED;
3111#endif
3112#if wxUSE_TOOLBAR
3113 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3114 return wxACC_NOT_IMPLEMENTED;
3115#endif
3116
3117 *state = 0;
3118 return wxACC_OK;
3119
66b9ec3d 3120 #if 0
ed5317e5 3121 return wxACC_NOT_IMPLEMENTED;
66b9ec3d 3122 #endif
ed5317e5
JS
3123}
3124
3125// Returns a localized string representing the value for the object
3126// or child.
66b9ec3d 3127wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
ed5317e5
JS
3128{
3129 wxASSERT( GetWindow() != NULL );
3130 if (!GetWindow())
3131 return wxACC_FAIL;
3132
3133 return wxACC_NOT_IMPLEMENTED;
3134}
3135
3136// Selects the object or child.
66b9ec3d 3137wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
ed5317e5
JS
3138{
3139 wxASSERT( GetWindow() != NULL );
3140 if (!GetWindow())
3141 return wxACC_FAIL;
3142
3143 return wxACC_NOT_IMPLEMENTED;
3144}
3145
3146// Gets the window with the keyboard focus.
3147// If childId is 0 and child is NULL, no object in
3148// this subhierarchy has the focus.
3149// If this object has the focus, child should be 'this'.
66b9ec3d 3150wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
ed5317e5
JS
3151{
3152 wxASSERT( GetWindow() != NULL );
3153 if (!GetWindow())
3154 return wxACC_FAIL;
3155
3156 return wxACC_NOT_IMPLEMENTED;
3157}
3158
ca5c6ac3 3159#if wxUSE_VARIANT
ed5317e5
JS
3160// Gets a variant representing the selected children
3161// of this object.
3162// Acceptable values:
cab1a605 3163// - a null variant (IsNull() returns true)
ed5317e5
JS
3164// - a list variant (GetType() == wxT("list")
3165// - an integer representing the selected child element,
3166// or 0 if this object is selected (GetType() == wxT("long")
3167// - a "void*" pointer to a wxAccessible child object
66b9ec3d 3168wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
ed5317e5
JS
3169{
3170 wxASSERT( GetWindow() != NULL );
3171 if (!GetWindow())
3172 return wxACC_FAIL;
3173
3174 return wxACC_NOT_IMPLEMENTED;
3175}
ca5c6ac3 3176#endif // wxUSE_VARIANT
ed5317e5
JS
3177
3178#endif // wxUSE_ACCESSIBILITY
978af864
VZ
3179
3180// ----------------------------------------------------------------------------
3181// RTL support
3182// ----------------------------------------------------------------------------
3183
3184wxCoord
3185wxWindowBase::AdjustForLayoutDirection(wxCoord x,
3186 wxCoord width,
3187 wxCoord widthTotal) const
3188{
3189 if ( GetLayoutDirection() == wxLayout_RightToLeft )
3190 {
3191 x = widthTotal - x - width;
3192 }
3193
3194 return x;
3195}
3196
f35fdf7e 3197