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