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