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