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