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