]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
some wxArtProv docs
[wxWidgets.git] / src / common / wincmn.cpp
CommitLineData
7ec1983b 1/////////////////////////////////////////////////////////////////////////////
f03fc89f 2// Name: 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$
f03fc89f 8// Copyright: (c) wxWindows team
7ec1983b
VZ
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
f03fc89f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
f701d7ab 19
58654ed0
VZ
20#ifdef __GNUG__
21 #pragma implementation "windowbase.h"
22#endif
23
341287bf
JS
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
f701d7ab 27#ifdef __BORLANDC__
f03fc89f 28 #pragma hdrstop
f701d7ab
JS
29#endif
30
f03fc89f
VZ
31#ifndef WX_PRECOMP
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/frame.h"
36 #include "wx/defs.h"
37 #include "wx/window.h"
1e6feb95 38 #include "wx/control.h"
f03fc89f
VZ
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
26bf1ce0 41 #include "wx/textctrl.h"
f03fc89f
VZ
42 #include "wx/settings.h"
43 #include "wx/dialog.h"
a02dc3e3 44 #include "wx/msgdlg.h"
a37a5a73 45 #include "wx/statusbr.h"
f03fc89f
VZ
46#endif //WX_PRECOMP
47
48#if wxUSE_CONSTRAINTS
49 #include "wx/layout.h"
50#endif // wxUSE_CONSTRAINTS
51
461e93f9
JS
52#include "wx/sizer.h"
53
f03fc89f
VZ
54#if wxUSE_DRAG_AND_DROP
55 #include "wx/dnd.h"
56#endif // wxUSE_DRAG_AND_DROP
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
f03fc89f
VZ
70// ----------------------------------------------------------------------------
71// static data
72// ----------------------------------------------------------------------------
73
42e69d6b 74int wxWindowBase::ms_lastControlId = -200;
f03fc89f
VZ
75
76IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
77
78// ----------------------------------------------------------------------------
79// event table
80// ----------------------------------------------------------------------------
81
82BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
83 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
84 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
a02dc3e3 85 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
bd83cb56
VZ
86
87#if wxUSE_HELP
88 EVT_HELP(-1, wxWindowBase::OnHelp)
89#endif // wxUSE_HELP
90
f03fc89f
VZ
91END_EVENT_TABLE()
92
93// ============================================================================
94// implementation of the common functionality of the wxWindow class
95// ============================================================================
96
97// ----------------------------------------------------------------------------
98// initialization
99// ----------------------------------------------------------------------------
100
101// the default initialization
102void wxWindowBase::InitBase()
103{
104 // no window yet, no parent nor children
f03fc89f
VZ
105 m_parent = (wxWindow *)NULL;
106 m_windowId = -1;
107 m_children.DeleteContents( FALSE ); // don't auto delete node data
108
109 // no constraints on the minimal window size
110 m_minWidth =
111 m_minHeight =
112 m_maxWidth =
113 m_maxHeight = -1;
114
115 // window is created enabled but it's not visible yet
116 m_isShown = FALSE;
117 m_isEnabled = TRUE;
118
f03fc89f
VZ
119 // the default event handler is just this window
120 m_eventHandler = this;
121
88ac883a 122#if wxUSE_VALIDATORS
f03fc89f
VZ
123 // no validator
124 m_windowValidator = (wxValidator *) NULL;
88ac883a 125#endif // wxUSE_VALIDATORS
f03fc89f
VZ
126
127 // use the system default colours
a756f210
VS
128 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
129 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
f6e4e9ea 130
8bf30fe9
VZ
131 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
132 // so the font is *not* really set - but calls to SetFont() later won't do
133 // anything because m_font appears to be already set!
134#ifndef __WXMSW__
a756f210 135 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
8bf30fe9 136#endif // __WXMSW__
807a903e 137
08df3e44
VZ
138 // the colours/fonts are default for now
139 m_hasBgCol =
140 m_hasFgCol =
141 m_hasFont = FALSE;
142
f03fc89f 143 // no style bits
d80cd92a 144 m_exStyle =
f03fc89f
VZ
145 m_windowStyle = 0;
146
147 // an optimization for the event processing: checking this flag is much
148 // faster than using IsKindOf(CLASSINFO(wxWindow))
149 m_isWindow = TRUE;
150
151#if wxUSE_CONSTRAINTS
152 // no constraints whatsoever
153 m_constraints = (wxLayoutConstraints *) NULL;
154 m_constraintsInvolvedIn = (wxWindowList *) NULL;
461e93f9
JS
155#endif // wxUSE_CONSTRAINTS
156
f03fc89f 157 m_windowSizer = (wxSizer *) NULL;
be90c029 158 m_containingSizer = (wxSizer *) NULL;
f03fc89f 159 m_autoLayout = FALSE;
f03fc89f
VZ
160
161#if wxUSE_DRAG_AND_DROP
162 m_dropTarget = (wxDropTarget *)NULL;
163#endif // wxUSE_DRAG_AND_DROP
164
165#if wxUSE_TOOLTIPS
166 m_tooltip = (wxToolTip *)NULL;
167#endif // wxUSE_TOOLTIPS
789295bf
VZ
168
169#if wxUSE_CARET
170 m_caret = (wxCaret *)NULL;
171#endif // wxUSE_CARET
a2d93e73 172
574c939e 173#if wxUSE_PALETTE
b95edd47 174 m_hasCustomPalette = FALSE;
574c939e
KB
175#endif // wxUSE_PALETTE
176
a2d93e73
JS
177 // Whether we're using the current theme for this window (wxGTK only for now)
178 m_themeEnabled = FALSE;
f03fc89f
VZ
179}
180
181// common part of window creation process
182bool wxWindowBase::CreateBase(wxWindowBase *parent,
183 wxWindowID id,
74e3313b
VZ
184 const wxPoint& WXUNUSED(pos),
185 const wxSize& WXUNUSED(size),
f03fc89f 186 long style,
8d99be5f 187 const wxValidator& validator,
f03fc89f
VZ
188 const wxString& name)
189{
190 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
191 // member variables - check that it has been called (will catch the case
192 // when a new ctor is added which doesn't call InitWindow)
223d09f6 193 wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
f03fc89f
VZ
194
195 // generate a new id if the user doesn't care about it
69418a8e 196 m_windowId = id == -1 ? NewControlId() : id;
f03fc89f
VZ
197
198 SetName(name);
199 SetWindowStyleFlag(style);
200 SetParent(parent);
674ac8b9
VZ
201
202#if wxUSE_VALIDATORS
8d99be5f 203 SetValidator(validator);
674ac8b9 204#endif // wxUSE_VALIDATORS
f03fc89f 205
8ae6ce07
VZ
206 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
207 // have it too - like this it's possible to set it only in the top level
208 // dialog/frame and all children will inherit it by defult
209 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
210 {
211 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
212 }
213
f03fc89f
VZ
214 return TRUE;
215}
216
217// ----------------------------------------------------------------------------
218// destruction
219// ----------------------------------------------------------------------------
220
221// common clean up
222wxWindowBase::~wxWindowBase()
223{
349d1942
VS
224 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
225
f03fc89f
VZ
226 // FIXME if these 2 cases result from programming errors in the user code
227 // we should probably assert here instead of silently fixing them
228
229 // Just in case the window has been Closed, but we're then deleting
230 // immediately: don't leave dangling pointers.
231 wxPendingDelete.DeleteObject(this);
232
233 // Just in case we've loaded a top-level window via LoadNativeDialog but
234 // we weren't a dialog class
235 wxTopLevelWindows.DeleteObject(this);
a23fd0e1 236
223d09f6 237 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
f03fc89f 238
789295bf
VZ
239#if wxUSE_CARET
240 if ( m_caret )
241 delete m_caret;
242#endif // wxUSE_CARET
243
88ac883a 244#if wxUSE_VALIDATORS
f03fc89f
VZ
245 if ( m_windowValidator )
246 delete m_windowValidator;
88ac883a 247#endif // wxUSE_VALIDATORS
f03fc89f 248
f03fc89f
VZ
249#if wxUSE_CONSTRAINTS
250 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
251 // at deleted windows as they delete themselves.
252 DeleteRelatedConstraints();
253
254 if ( m_constraints )
255 {
256 // This removes any dangling pointers to this window in other windows'
257 // constraintsInvolvedIn lists.
258 UnsetConstraints(m_constraints);
259 delete m_constraints;
260 m_constraints = NULL;
261 }
262
461e93f9
JS
263#endif // wxUSE_CONSTRAINTS
264
be90c029
RD
265 if ( m_containingSizer )
266 m_containingSizer->Remove((wxWindow*)this);
267
f03fc89f
VZ
268 if ( m_windowSizer )
269 delete m_windowSizer;
270
f03fc89f
VZ
271#if wxUSE_DRAG_AND_DROP
272 if ( m_dropTarget )
273 delete m_dropTarget;
274#endif // wxUSE_DRAG_AND_DROP
275
276#if wxUSE_TOOLTIPS
277 if ( m_tooltip )
278 delete m_tooltip;
279#endif // wxUSE_TOOLTIPS
b0ee47ff
VZ
280
281 // reset the dangling pointer our parent window may keep to us
282 if ( m_parent && m_parent->GetDefaultItem() == this )
283 {
284 m_parent->SetDefaultItem(NULL);
285 }
f03fc89f
VZ
286}
287
288bool wxWindowBase::Destroy()
289{
290 delete this;
291
292 return TRUE;
293}
294
295bool wxWindowBase::Close(bool force)
296{
297 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
298 event.SetEventObject(this);
299#if WXWIN_COMPATIBILITY
300 event.SetForce(force);
301#endif // WXWIN_COMPATIBILITY
302 event.SetCanVeto(!force);
303
304 // return FALSE if window wasn't closed because the application vetoed the
305 // close event
306 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
307}
308
309bool wxWindowBase::DestroyChildren()
310{
311 wxWindowList::Node *node;
a23fd0e1 312 for ( ;; )
f03fc89f 313 {
a23fd0e1
VZ
314 // we iterate until the list becomes empty
315 node = GetChildren().GetFirst();
316 if ( !node )
317 break;
318
f03fc89f 319 wxWindow *child = node->GetData();
a23fd0e1 320
223d09f6 321 wxASSERT_MSG( child, wxT("children list contains empty nodes") );
a23fd0e1 322
1a77875b 323 child->Show(FALSE);
eb082a08 324 delete child;
a23fd0e1
VZ
325
326 wxASSERT_MSG( !GetChildren().Find(child),
223d09f6 327 wxT("child didn't remove itself using RemoveChild()") );
f03fc89f
VZ
328 }
329
330 return TRUE;
331}
332
333// ----------------------------------------------------------------------------
f68586e5 334// size/position related methods
f03fc89f
VZ
335// ----------------------------------------------------------------------------
336
337// centre the window with respect to its parent in either (or both) directions
338void wxWindowBase::Centre(int direction)
339{
f6bcfd97
BP
340 // the position/size of the parent window or of the entire screen
341 wxPoint posParent;
f03fc89f
VZ
342 int widthParent, heightParent;
343
f6bcfd97
BP
344 wxWindow *parent = NULL;
345
346 if ( !(direction & wxCENTRE_ON_SCREEN) )
f03fc89f 347 {
f6bcfd97
BP
348 // find the parent to centre this window on: it should be the
349 // immediate parent for the controls but the top level parent for the
350 // top level windows (like dialogs)
351 parent = GetParent();
352 if ( IsTopLevel() )
353 {
354 while ( parent && !parent->IsTopLevel() )
355 {
356 parent = parent->GetParent();
357 }
358 }
359
360 // did we find the parent?
361 if ( !parent )
362 {
363 // no other choice
364 direction |= wxCENTRE_ON_SCREEN;
365 }
f03fc89f 366 }
10fcf31a
VZ
367
368 if ( direction & wxCENTRE_ON_SCREEN )
f03fc89f
VZ
369 {
370 // centre with respect to the whole screen
371 wxDisplaySize(&widthParent, &heightParent);
372 }
10fcf31a
VZ
373 else
374 {
f6bcfd97
BP
375 if ( IsTopLevel() )
376 {
377 // centre on the parent
378 parent->GetSize(&widthParent, &heightParent);
379
380 // adjust to the parents position
381 posParent = parent->GetPosition();
382 }
383 else
384 {
385 // centre inside the parents client rectangle
386 parent->GetClientSize(&widthParent, &heightParent);
387 }
10fcf31a 388 }
f03fc89f
VZ
389
390 int width, height;
391 GetSize(&width, &height);
392
c39eda94
VZ
393 int xNew = -1,
394 yNew = -1;
f03fc89f
VZ
395
396 if ( direction & wxHORIZONTAL )
c39eda94 397 xNew = (widthParent - width)/2;
f03fc89f
VZ
398
399 if ( direction & wxVERTICAL )
c39eda94 400 yNew = (heightParent - height)/2;
f03fc89f 401
f6bcfd97
BP
402 xNew += posParent.x;
403 yNew += posParent.y;
7631a292 404
ef397583
GT
405 // Base size of the visible dimensions of the display
406 // to take into account the taskbar
407 wxRect rect = wxGetClientDisplayRect();
408 wxSize size (rect.width,rect.height);
409
ede7020a
VS
410 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
411 // but it may mean that the window is placed on other than the main
412 // display. Therefore we only make sure centered window is on the main display
413 // if the parent is at least partially present here.
414 if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display
ef397583
GT
415 {
416 if (xNew < 0)
417 xNew = 0;
418 else if (xNew+width > size.x)
419 xNew = size.x-width-1;
420 }
ede7020a 421 if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display
ef397583
GT
422 {
423 if (yNew+height > size.y)
424 yNew = size.y-height-1;
425
426 // Make certain that the title bar is initially visible
427 // always, even if this would push the bottom of the
428 // dialog of the visible area of the display
429 if (yNew < 0)
430 yNew = 0;
431 }
432
0fff366e
VZ
433 // move the window to this position (keeping the old size but using
434 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
db89aa76 435 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
7631a292
RD
436}
437
f03fc89f
VZ
438// fits the window around the children
439void wxWindowBase::Fit()
440{
f68586e5
VZ
441 if ( GetChildren().GetCount() > 0 )
442 {
ba81034d
VZ
443 wxSize size = DoGetBestSize();
444
445 // for compatibility with the old versions and because it really looks
446 // slightly more pretty like this, add a pad
447 size.x += 7;
448 size.y += 14;
449
450 SetClientSize(size);
f68586e5
VZ
451 }
452 //else: do nothing if we have no children
453}
f03fc89f 454
f68586e5
VZ
455// return the size best suited for the current window
456wxSize wxWindowBase::DoGetBestSize() const
457{
458 if ( GetChildren().GetCount() > 0 )
f03fc89f 459 {
f68586e5
VZ
460 // our minimal acceptable size is such that all our windows fit inside
461 int maxX = 0,
462 maxY = 0;
463
464 for ( wxWindowList::Node *node = GetChildren().GetFirst();
465 node;
466 node = node->GetNext() )
42e69d6b 467 {
f68586e5 468 wxWindow *win = node->GetData();
1e6feb95
VZ
469 if ( win->IsTopLevel()
470#if wxUSE_STATUSBAR
471 || wxDynamicCast(win, wxStatusBar)
472#endif // wxUSE_STATUSBAR
473 )
f68586e5
VZ
474 {
475 // dialogs and frames lie in different top level windows -
7d9fd004
VZ
476 // don't deal with them here; as for the status bars, they
477 // don't lie in the client area at all
f68586e5
VZ
478 continue;
479 }
480
481 int wx, wy, ww, wh;
482 win->GetPosition(&wx, &wy);
3f5513f5
VZ
483
484 // if the window hadn't been positioned yet, assume that it is in
485 // the origin
486 if ( wx == -1 )
487 wx = 0;
488 if ( wy == -1 )
489 wy = 0;
490
f68586e5
VZ
491 win->GetSize(&ww, &wh);
492 if ( wx + ww > maxX )
493 maxX = wx + ww;
494 if ( wy + wh > maxY )
495 maxY = wy + wh;
42e69d6b
VZ
496 }
497
ba81034d 498 return wxSize(maxX, maxY);
f68586e5
VZ
499 }
500 else
501 {
502 // for a generic window there is no natural best size - just use the
503 // current one
504 return GetSize();
f03fc89f 505 }
f03fc89f
VZ
506}
507
1e6feb95
VZ
508// by default the origin is not shifted
509wxPoint wxWindowBase::GetClientAreaOrigin() const
510{
511 return wxPoint(0, 0);
512}
513
f03fc89f 514// set the min/max size of the window
f03fc89f
VZ
515void wxWindowBase::SetSizeHints(int minW, int minH,
516 int maxW, int maxH,
517 int WXUNUSED(incW), int WXUNUSED(incH))
518{
519 m_minWidth = minW;
520 m_maxWidth = maxW;
521 m_minHeight = minH;
522 m_maxHeight = maxH;
523}
524
525// ----------------------------------------------------------------------------
526// show/hide/enable/disable the window
527// ----------------------------------------------------------------------------
528
529bool wxWindowBase::Show(bool show)
530{
531 if ( show != m_isShown )
532 {
533 m_isShown = show;
534
535 return TRUE;
536 }
537 else
538 {
539 return FALSE;
540 }
541}
542
543bool wxWindowBase::Enable(bool enable)
544{
545 if ( enable != m_isEnabled )
546 {
547 m_isEnabled = enable;
548
549 return TRUE;
550 }
551 else
552 {
553 return FALSE;
554 }
555}
34636400
VZ
556// ----------------------------------------------------------------------------
557// RTTI
558// ----------------------------------------------------------------------------
559
560bool wxWindowBase::IsTopLevel() const
561{
8487f887 562 return FALSE;
34636400 563}
f03fc89f
VZ
564
565// ----------------------------------------------------------------------------
566// reparenting the window
567// ----------------------------------------------------------------------------
568
569void wxWindowBase::AddChild(wxWindowBase *child)
570{
223d09f6 571 wxCHECK_RET( child, wxT("can't add a NULL child") );
f03fc89f 572
f6bcfd97
BP
573 // this should never happen and it will lead to a crash later if it does
574 // because RemoveChild() will remove only one node from the children list
575 // and the other(s) one(s) will be left with dangling pointers in them
576 wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );
577
f03fc89f
VZ
578 GetChildren().Append(child);
579 child->SetParent(this);
580}
581
582void wxWindowBase::RemoveChild(wxWindowBase *child)
583{
223d09f6 584 wxCHECK_RET( child, wxT("can't remove a NULL child") );
f03fc89f
VZ
585
586 GetChildren().DeleteObject(child);
587 child->SetParent((wxWindow *)NULL);
588}
439b3bf1 589
f03fc89f
VZ
590bool wxWindowBase::Reparent(wxWindowBase *newParent)
591{
592 wxWindow *oldParent = GetParent();
593 if ( newParent == oldParent )
594 {
595 // nothing done
596 return FALSE;
597 }
598
599 // unlink this window from the existing parent.
600 if ( oldParent )
601 {
602 oldParent->RemoveChild(this);
603 }
604 else
605 {
606 wxTopLevelWindows.DeleteObject(this);
607 }
608
609 // add it to the new one
610 if ( newParent )
611 {
612 newParent->AddChild(this);
613 }
614 else
615 {
616 wxTopLevelWindows.Append(this);
617 }
618
619 return TRUE;
620}
621
622// ----------------------------------------------------------------------------
623// event handler stuff
624// ----------------------------------------------------------------------------
625
626void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
627{
628 handler->SetNextHandler(GetEventHandler());
629 SetEventHandler(handler);
630}
631
632wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
633{
634 wxEvtHandler *handlerA = GetEventHandler();
635 if ( handlerA )
636 {
637 wxEvtHandler *handlerB = handlerA->GetNextHandler();
638 handlerA->SetNextHandler((wxEvtHandler *)NULL);
639 SetEventHandler(handlerB);
640 if ( deleteHandler )
641 {
642 delete handlerA;
643 handlerA = (wxEvtHandler *)NULL;
644 }
645 }
646
647 return handlerA;
648}
649
2e36d5cf
VZ
650bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
651{
652 wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") );
653
654 wxEvtHandler *handlerPrev = NULL,
655 *handlerCur = GetEventHandler();
656 while ( handlerCur )
657 {
658 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
659
660 if ( handlerCur == handler )
661 {
662 if ( handlerPrev )
663 {
664 handlerPrev->SetNextHandler(handlerNext);
665 }
666 else
667 {
668 SetEventHandler(handlerNext);
669 }
670
671 handler->SetNextHandler(NULL);
672
673 return TRUE;
674 }
675
676 handlerPrev = handlerCur;
677 handlerCur = handlerNext;
678 }
679
680 wxFAIL_MSG( _T("where has the event handler gone?") );
681
682 return FALSE;
683}
684
f03fc89f
VZ
685// ----------------------------------------------------------------------------
686// cursors, fonts &c
687// ----------------------------------------------------------------------------
688
689bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
690{
691 if ( !colour.Ok() || (colour == m_backgroundColour) )
692 return FALSE;
693
694 m_backgroundColour = colour;
695
23895080
VZ
696 m_hasBgCol = TRUE;
697
f03fc89f
VZ
698 return TRUE;
699}
700
701bool wxWindowBase::SetForegroundColour( const wxColour &colour )
702{
703 if ( !colour.Ok() || (colour == m_foregroundColour) )
704 return FALSE;
705
706 m_foregroundColour = colour;
707
23895080
VZ
708 m_hasFgCol = TRUE;
709
f03fc89f
VZ
710 return TRUE;
711}
712
713bool wxWindowBase::SetCursor(const wxCursor& cursor)
714{
8a9c2246
VZ
715 // setting an invalid cursor is ok, it means that we don't have any special
716 // cursor
13588544 717 if ( m_cursor == cursor )
f03fc89f
VZ
718 {
719 // no change
720 return FALSE;
721 }
722
8a9c2246 723 m_cursor = cursor;
f03fc89f
VZ
724
725 return TRUE;
726}
727
728bool wxWindowBase::SetFont(const wxFont& font)
729{
730 // don't try to set invalid font, always fall back to the default
731 const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
732
8bf30fe9 733 if ( fontOk == m_font )
f03fc89f
VZ
734 {
735 // no change
736 return FALSE;
737 }
738
739 m_font = fontOk;
740
23895080
VZ
741 m_hasFont = TRUE;
742
f03fc89f
VZ
743 return TRUE;
744}
745
b95edd47
VZ
746#if wxUSE_PALETTE
747
748void wxWindowBase::SetPalette(const wxPalette& pal)
749{
750 m_hasCustomPalette = TRUE;
751 m_palette = pal;
752
753 // VZ: can anyone explain me what do we do here?
754 wxWindowDC d((wxWindow *) this);
755 d.SetPalette(pal);
756}
757
758wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
759{
760 wxWindow *win = (wxWindow *)this;
761 while ( win && !win->HasCustomPalette() )
762 {
763 win = win->GetParent();
764 }
765
766 return win;
767}
768
769#endif // wxUSE_PALETTE
770
789295bf
VZ
771#if wxUSE_CARET
772void wxWindowBase::SetCaret(wxCaret *caret)
773{
774 if ( m_caret )
775 {
776 delete m_caret;
777 }
778
779 m_caret = caret;
780
781 if ( m_caret )
782 {
783 wxASSERT_MSG( m_caret->GetWindow() == this,
223d09f6 784 wxT("caret should be created associated to this window") );
789295bf
VZ
785 }
786}
787#endif // wxUSE_CARET
788
88ac883a 789#if wxUSE_VALIDATORS
f03fc89f
VZ
790// ----------------------------------------------------------------------------
791// validators
792// ----------------------------------------------------------------------------
793
794void wxWindowBase::SetValidator(const wxValidator& validator)
795{
796 if ( m_windowValidator )
797 delete m_windowValidator;
798
799 m_windowValidator = (wxValidator *)validator.Clone();
800
801 if ( m_windowValidator )
802 m_windowValidator->SetWindow(this) ;
803}
88ac883a 804#endif // wxUSE_VALIDATORS
f03fc89f
VZ
805
806// ----------------------------------------------------------------------------
1e6feb95 807// update region stuff
f03fc89f
VZ
808// ----------------------------------------------------------------------------
809
1e6feb95
VZ
810wxRect wxWindowBase::GetUpdateClientRect() const
811{
812 wxRegion rgnUpdate = GetUpdateRegion();
813 rgnUpdate.Intersect(GetClientRect());
814 wxRect rectUpdate = rgnUpdate.GetBox();
815 wxPoint ptOrigin = GetClientAreaOrigin();
816 rectUpdate.x -= ptOrigin.x;
817 rectUpdate.y -= ptOrigin.y;
818
819 return rectUpdate;
820}
821
f03fc89f
VZ
822bool wxWindowBase::IsExposed(int x, int y) const
823{
824 return m_updateRegion.Contains(x, y) != wxOutRegion;
825}
826
827bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
828{
829 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
830}
831
832// ----------------------------------------------------------------------------
833// find window by id or name
834// ----------------------------------------------------------------------------
835
836wxWindow *wxWindowBase::FindWindow( long id )
837{
838 if ( id == m_windowId )
839 return (wxWindow *)this;
840
841 wxWindowBase *res = (wxWindow *)NULL;
842 wxWindowList::Node *node;
843 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
844 {
845 wxWindowBase *child = node->GetData();
846 res = child->FindWindow( id );
847 }
848
849 return (wxWindow *)res;
850}
851
852wxWindow *wxWindowBase::FindWindow( const wxString& name )
853{
854 if ( name == m_windowName )
855 return (wxWindow *)this;
856
857 wxWindowBase *res = (wxWindow *)NULL;
858 wxWindowList::Node *node;
859 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
860 {
861 wxWindow *child = node->GetData();
862 res = child->FindWindow(name);
863 }
864
865 return (wxWindow *)res;
866}
867
868// ----------------------------------------------------------------------------
869// dialog oriented functions
870// ----------------------------------------------------------------------------
871
34636400 872void wxWindowBase::MakeModal(bool modal)
f03fc89f 873{
34636400
VZ
874 // Disable all other windows
875 if ( IsTopLevel() )
876 {
877 wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
878 while (node)
879 {
880 wxWindow *win = node->GetData();
881 if (win != this)
882 win->Enable(!modal);
883
884 node = node->GetNext();
885 }
886 }
f03fc89f
VZ
887}
888
889bool wxWindowBase::Validate()
890{
88ac883a 891#if wxUSE_VALIDATORS
d80cd92a
VZ
892 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
893
f03fc89f
VZ
894 wxWindowList::Node *node;
895 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
896 {
897 wxWindowBase *child = node->GetData();
898 wxValidator *validator = child->GetValidator();
dcd6b914 899 if ( validator && !validator->Validate((wxWindow *)this) )
f03fc89f
VZ
900 {
901 return FALSE;
902 }
d80cd92a
VZ
903
904 if ( recurse && !child->Validate() )
905 {
906 return FALSE;
907 }
f03fc89f 908 }
88ac883a 909#endif // wxUSE_VALIDATORS
f03fc89f
VZ
910
911 return TRUE;
912}
913
914bool wxWindowBase::TransferDataToWindow()
915{
88ac883a 916#if wxUSE_VALIDATORS
d80cd92a
VZ
917 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
918
f03fc89f
VZ
919 wxWindowList::Node *node;
920 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
921 {
922 wxWindowBase *child = node->GetData();
923 wxValidator *validator = child->GetValidator();
924 if ( validator && !validator->TransferToWindow() )
925 {
d80cd92a
VZ
926 wxLogWarning(_("Could not transfer data to window"));
927 wxLog::FlushActive();
f03fc89f
VZ
928
929 return FALSE;
930 }
d80cd92a
VZ
931
932 if ( recurse )
933 {
a58a12e9 934 if ( !child->TransferDataToWindow() )
d80cd92a
VZ
935 {
936 // warning already given
937 return FALSE;
938 }
939 }
f03fc89f 940 }
88ac883a 941#endif // wxUSE_VALIDATORS
f03fc89f
VZ
942
943 return TRUE;
944}
945
946bool wxWindowBase::TransferDataFromWindow()
947{
88ac883a 948#if wxUSE_VALIDATORS
d80cd92a
VZ
949 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
950
f03fc89f
VZ
951 wxWindowList::Node *node;
952 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
953 {
954 wxWindow *child = node->GetData();
d80cd92a
VZ
955 wxValidator *validator = child->GetValidator();
956 if ( validator && !validator->TransferFromWindow() )
f03fc89f 957 {
d80cd92a
VZ
958 // nop warning here because the application is supposed to give
959 // one itself - we don't know here what might have gone wrongly
960
f03fc89f
VZ
961 return FALSE;
962 }
d80cd92a
VZ
963
964 if ( recurse )
965 {
a58a12e9 966 if ( !child->TransferDataFromWindow() )
d80cd92a
VZ
967 {
968 // warning already given
969 return FALSE;
970 }
971 }
f03fc89f 972 }
88ac883a 973#endif // wxUSE_VALIDATORS
f03fc89f
VZ
974
975 return TRUE;
976}
977
978void wxWindowBase::InitDialog()
979{
980 wxInitDialogEvent event(GetId());
981 event.SetEventObject( this );
982 GetEventHandler()->ProcessEvent(event);
983}
984
985// ----------------------------------------------------------------------------
bd83cb56
VZ
986// context-sensitive help support
987// ----------------------------------------------------------------------------
988
989#if wxUSE_HELP
990
991// associate this help text with this window
992void wxWindowBase::SetHelpText(const wxString& text)
993{
994 wxHelpProvider *helpProvider = wxHelpProvider::Get();
995 if ( helpProvider )
996 {
997 helpProvider->AddHelp(this, text);
998 }
999}
1000
1001// associate this help text with all windows with the same id as this
1002// one
1003void wxWindowBase::SetHelpTextForId(const wxString& text)
1004{
1005 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1006 if ( helpProvider )
1007 {
1008 helpProvider->AddHelp(GetId(), text);
1009 }
1010}
1011
1012// get the help string associated with this window (may be empty)
1013wxString wxWindowBase::GetHelpText() const
1014{
1015 wxString text;
1016 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1017 if ( helpProvider )
1018 {
1019 text = helpProvider->GetHelp(this);
1020 }
1021
1022 return text;
1023}
1024
1025// show help for this window
1026void wxWindowBase::OnHelp(wxHelpEvent& event)
1027{
1028 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1029 if ( helpProvider )
1030 {
1031 if ( helpProvider->ShowHelp(this) )
1032 {
1033 // skip the event.Skip() below
1034 return;
1035 }
1036 }
1037
1038 event.Skip();
1039}
1040
1041#endif // wxUSE_HELP
1042
1043// ----------------------------------------------------------------------------
574c939e 1044// tooltipsroot.Replace("\\", "/");
f03fc89f
VZ
1045// ----------------------------------------------------------------------------
1046
1047#if wxUSE_TOOLTIPS
1048
1049void wxWindowBase::SetToolTip( const wxString &tip )
1050{
1051 // don't create the new tooltip if we already have one
1052 if ( m_tooltip )
1053 {
1054 m_tooltip->SetTip( tip );
1055 }
1056 else
1057 {
1058 SetToolTip( new wxToolTip( tip ) );
1059 }
1060
1061 // setting empty tooltip text does not remove the tooltip any more - use
1062 // SetToolTip((wxToolTip *)NULL) for this
1063}
1064
1065void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1066{
1067 if ( m_tooltip )
1068 delete m_tooltip;
1069
1070 m_tooltip = tooltip;
1071}
1072
1073#endif // wxUSE_TOOLTIPS
1074
1075// ----------------------------------------------------------------------------
1076// constraints and sizers
1077// ----------------------------------------------------------------------------
1078
1079#if wxUSE_CONSTRAINTS
1080
1081void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1082{
1083 if ( m_constraints )
1084 {
1085 UnsetConstraints(m_constraints);
1086 delete m_constraints;
1087 }
1088 m_constraints = constraints;
1089 if ( m_constraints )
1090 {
1091 // Make sure other windows know they're part of a 'meaningful relationship'
1092 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1093 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1094 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1095 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1096 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1097 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1098 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1099 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1100 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1101 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1102 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1103 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1104 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1105 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1106 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1107 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1108 }
1109}
1110
1111// This removes any dangling pointers to this window in other windows'
1112// constraintsInvolvedIn lists.
1113void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1114{
1115 if ( c )
1116 {
1117 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1118 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1119 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1120 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1121 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1122 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1123 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1124 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1125 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1126 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1127 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1128 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1129 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1130 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1131 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1132 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1133 }
1134}
1135
1136// Back-pointer to other windows we're involved with, so if we delete this
1137// window, we must delete any constraints we're involved with.
1138void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1139{
1140 if ( !m_constraintsInvolvedIn )
1141 m_constraintsInvolvedIn = new wxWindowList;
1142 if ( !m_constraintsInvolvedIn->Find(otherWin) )
1143 m_constraintsInvolvedIn->Append(otherWin);
1144}
1145
1146// REMOVE back-pointer to other windows we're involved with.
1147void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1148{
1149 if ( m_constraintsInvolvedIn )
1150 m_constraintsInvolvedIn->DeleteObject(otherWin);
1151}
1152
1153// Reset any constraints that mention this window
1154void wxWindowBase::DeleteRelatedConstraints()
1155{
1156 if ( m_constraintsInvolvedIn )
1157 {
1158 wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst();
1159 while (node)
1160 {
1161 wxWindow *win = node->GetData();
1162 wxLayoutConstraints *constr = win->GetConstraints();
1163
1164 // Reset any constraints involving this window
1165 if ( constr )
1166 {
1167 constr->left.ResetIfWin(this);
1168 constr->top.ResetIfWin(this);
1169 constr->right.ResetIfWin(this);
1170 constr->bottom.ResetIfWin(this);
1171 constr->width.ResetIfWin(this);
1172 constr->height.ResetIfWin(this);
1173 constr->centreX.ResetIfWin(this);
1174 constr->centreY.ResetIfWin(this);
1175 }
1176
1177 wxWindowList::Node *next = node->GetNext();
1178 delete node;
1179 node = next;
1180 }
1181
1182 delete m_constraintsInvolvedIn;
1183 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1184 }
1185}
461e93f9 1186#endif
f03fc89f 1187
3aa5d532 1188void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
f03fc89f 1189{
3aa5d532 1190 if (m_windowSizer && deleteOld) delete m_windowSizer;
3417c2cd 1191
f03fc89f 1192 m_windowSizer = sizer;
f03fc89f
VZ
1193}
1194
1195bool wxWindowBase::Layout()
1196{
3417c2cd 1197 // If there is a sizer, use it instead of the constraints
f03fc89f
VZ
1198 if ( GetSizer() )
1199 {
f1df0927
VZ
1200 int w, h;
1201 GetClientSize(&w, &h);
1202
3417c2cd 1203 GetSizer()->SetDimension( 0, 0, w, h );
f03fc89f 1204 }
461e93f9 1205#if wxUSE_CONSTRAINTS
f1df0927 1206 else
f03fc89f 1207 {
4b7f2165
VZ
1208 wxLayoutConstraints *constr = GetConstraints();
1209 bool wasOk = constr && constr->AreSatisfied();
1210
f1df0927 1211 ResetConstraints(); // Mark all constraints as unevaluated
4b7f2165
VZ
1212
1213 // if we're a top level panel (i.e. our parent is frame/dialog), our
1214 // own constraints will never be satisfied any more unless we do it
1215 // here
1216 if ( wasOk )
1217 {
1218 int noChanges = 1;
1219 while ( noChanges > 0 )
1220 {
1221 constr->SatisfyConstraints(this, &noChanges);
1222 }
1223 }
1224
1225 DoPhase(1); // Layout children
1226 DoPhase(2); // Layout grand children
f1df0927 1227 SetConstraintSizes(); // Recursively set the real window sizes
f03fc89f 1228 }
461e93f9 1229#endif
5d4b632b 1230
f03fc89f
VZ
1231 return TRUE;
1232}
1233
461e93f9 1234#if wxUSE_CONSTRAINTS
f03fc89f
VZ
1235// Do a phase of evaluating constraints: the default behaviour. wxSizers may
1236// do a similar thing, but also impose their own 'constraints' and order the
1237// evaluation differently.
1238bool wxWindowBase::LayoutPhase1(int *noChanges)
1239{
1240 wxLayoutConstraints *constr = GetConstraints();
1241 if ( constr )
1242 {
1243 return constr->SatisfyConstraints(this, noChanges);
1244 }
1245 else
1246 return TRUE;
1247}
1248
1249bool wxWindowBase::LayoutPhase2(int *noChanges)
1250{
1251 *noChanges = 0;
1252
1253 // Layout children
1254 DoPhase(1);
1255 DoPhase(2);
1256 return TRUE;
1257}
1258
1259// Do a phase of evaluating child constraints
1260bool wxWindowBase::DoPhase(int phase)
1261{
1262 int noIterations = 0;
1263 int maxIterations = 500;
1264 int noChanges = 1;
1265 int noFailures = 0;
1266 wxWindowList succeeded;
1267 while ((noChanges > 0) && (noIterations < maxIterations))
1268 {
1269 noChanges = 0;
1270 noFailures = 0;
1271 wxWindowList::Node *node = GetChildren().GetFirst();
1272 while (node)
1273 {
1274 wxWindow *child = node->GetData();
34636400 1275 if ( !child->IsTopLevel() )
f03fc89f
VZ
1276 {
1277 wxLayoutConstraints *constr = child->GetConstraints();
1278 if ( constr )
1279 {
1280 if ( !succeeded.Find(child) )
1281 {
1282 int tempNoChanges = 0;
1283 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1284 noChanges += tempNoChanges;
1285 if ( success )
1286 {
1287 succeeded.Append(child);
1288 }
1289 }
1290 }
1291 }
1292 node = node->GetNext();
1293 }
1294
1295 noIterations++;
1296 }
1297
1298 return TRUE;
1299}
1300
1301void wxWindowBase::ResetConstraints()
1302{
1303 wxLayoutConstraints *constr = GetConstraints();
1304 if ( constr )
1305 {
1306 constr->left.SetDone(FALSE);
1307 constr->top.SetDone(FALSE);
1308 constr->right.SetDone(FALSE);
1309 constr->bottom.SetDone(FALSE);
1310 constr->width.SetDone(FALSE);
1311 constr->height.SetDone(FALSE);
1312 constr->centreX.SetDone(FALSE);
1313 constr->centreY.SetDone(FALSE);
1314 }
f1df0927 1315
f03fc89f
VZ
1316 wxWindowList::Node *node = GetChildren().GetFirst();
1317 while (node)
1318 {
1319 wxWindow *win = node->GetData();
34636400 1320 if ( !win->IsTopLevel() )
f03fc89f
VZ
1321 win->ResetConstraints();
1322 node = node->GetNext();
1323 }
1324}
1325
1326// Need to distinguish between setting the 'fake' size for windows and sizers,
1327// and setting the real values.
1328void wxWindowBase::SetConstraintSizes(bool recurse)
1329{
1330 wxLayoutConstraints *constr = GetConstraints();
4b7f2165 1331 if ( constr && constr->AreSatisfied() )
f03fc89f
VZ
1332 {
1333 int x = constr->left.GetValue();
1334 int y = constr->top.GetValue();
1335 int w = constr->width.GetValue();
1336 int h = constr->height.GetValue();
1337
f03fc89f 1338 if ( (constr->width.GetRelationship() != wxAsIs ) ||
3417c2cd 1339 (constr->height.GetRelationship() != wxAsIs) )
f03fc89f 1340 {
3417c2cd 1341 SetSize(x, y, w, h);
f03fc89f
VZ
1342 }
1343 else
1344 {
3417c2cd
RR
1345 // If we don't want to resize this window, just move it...
1346 Move(x, y);
f03fc89f
VZ
1347 }
1348 }
1349 else if ( constr )
1350 {
4b7f2165 1351 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
f1df0927 1352 GetClassInfo()->GetClassName(),
4b7f2165 1353 GetName().c_str());
f03fc89f
VZ
1354 }
1355
1356 if ( recurse )
1357 {
1358 wxWindowList::Node *node = GetChildren().GetFirst();
1359 while (node)
1360 {
1361 wxWindow *win = node->GetData();
e2f9212c 1362 if ( !win->IsTopLevel() && win->GetConstraints() )
f03fc89f
VZ
1363 win->SetConstraintSizes();
1364 node = node->GetNext();
1365 }
1366 }
1367}
1368
f03fc89f
VZ
1369// Only set the size/position of the constraint (if any)
1370void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1371{
1372 wxLayoutConstraints *constr = GetConstraints();
1373 if ( constr )
1374 {
1375 if ( x != -1 )
1376 {
1377 constr->left.SetValue(x);
1378 constr->left.SetDone(TRUE);
1379 }
1380 if ( y != -1 )
1381 {
1382 constr->top.SetValue(y);
1383 constr->top.SetDone(TRUE);
1384 }
1385 if ( w != -1 )
1386 {
1387 constr->width.SetValue(w);
1388 constr->width.SetDone(TRUE);
1389 }
1390 if ( h != -1 )
1391 {
1392 constr->height.SetValue(h);
1393 constr->height.SetDone(TRUE);
1394 }
1395 }
1396}
1397
1398void wxWindowBase::MoveConstraint(int x, int y)
1399{
1400 wxLayoutConstraints *constr = GetConstraints();
1401 if ( constr )
1402 {
1403 if ( x != -1 )
1404 {
1405 constr->left.SetValue(x);
1406 constr->left.SetDone(TRUE);
1407 }
1408 if ( y != -1 )
1409 {
1410 constr->top.SetValue(y);
1411 constr->top.SetDone(TRUE);
1412 }
1413 }
1414}
1415
1416void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1417{
1418 wxLayoutConstraints *constr = GetConstraints();
1419 if ( constr )
1420 {
1421 *w = constr->width.GetValue();
1422 *h = constr->height.GetValue();
1423 }
1424 else
1425 GetSize(w, h);
1426}
1427
1428void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1429{
1430 wxLayoutConstraints *constr = GetConstraints();
1431 if ( constr )
1432 {
1433 *w = constr->width.GetValue();
1434 *h = constr->height.GetValue();
1435 }
1436 else
1437 GetClientSize(w, h);
1438}
1439
461e93f9
JS
1440void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1441{
1442 wxLayoutConstraints *constr = GetConstraints();
1443 if ( constr )
1444 {
1445 *x = constr->left.GetValue();
1446 *y = constr->top.GetValue();
1447 }
1448 else
1449 GetPosition(x, y);
1450}
1451
1452#endif // wxUSE_CONSTRAINTS
1453
20a1eea1 1454void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
a200c35e
VS
1455{
1456 // don't do it for the dialogs/frames - they float independently of their
1457 // parent
1458 if ( !IsTopLevel() )
1459 {
1460 wxWindow *parent = GetParent();
1461 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1462 {
1463 wxPoint pt(parent->GetClientAreaOrigin());
1464 x += pt.x;
1465 y += pt.y;
1466 }
1467 }
1468}
1469
f03fc89f
VZ
1470// ----------------------------------------------------------------------------
1471// do Update UI processing for child controls
1472// ----------------------------------------------------------------------------
7ec1983b
VZ
1473
1474// TODO: should this be implemented for the child window rather
1475// than the parent? Then you can override it e.g. for wxCheckBox
1476// to do the Right Thing rather than having to assume a fixed number
1477// of control classes.
f03fc89f 1478void wxWindowBase::UpdateWindowUI()
7ec1983b 1479{
1e6feb95 1480#if wxUSE_CONTROLS
26bf1ce0
VZ
1481 wxUpdateUIEvent event(GetId());
1482 event.m_eventObject = this;
1483
1484 if ( GetEventHandler()->ProcessEvent(event) )
7ec1983b 1485 {
26bf1ce0
VZ
1486 if ( event.GetSetEnabled() )
1487 Enable(event.GetEnabled());
7ec1983b 1488
26bf1ce0 1489 if ( event.GetSetText() )
f03fc89f 1490 {
f7637829 1491 wxControl *control = wxDynamicCastThis(wxControl);
26bf1ce0 1492 if ( control )
34636400 1493 {
1e6feb95 1494#if wxUSE_TEXTCTRL
26bf1ce0
VZ
1495 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1496 if ( text )
1497 text->SetValue(event.GetText());
1498 else
1e6feb95 1499#endif // wxUSE_TEXTCTRL
34636400
VZ
1500 control->SetLabel(event.GetText());
1501 }
26bf1ce0 1502 }
f03fc89f 1503
88ac883a 1504#if wxUSE_CHECKBOX
f7637829 1505 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
26bf1ce0
VZ
1506 if ( checkbox )
1507 {
1508 if ( event.GetSetChecked() )
1509 checkbox->SetValue(event.GetChecked());
1510 }
88ac883a
VZ
1511#endif // wxUSE_CHECKBOX
1512
b3402d0d 1513#if wxUSE_RADIOBTN
f7637829 1514 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
26bf1ce0
VZ
1515 if ( radiobtn )
1516 {
1517 if ( event.GetSetChecked() )
1518 radiobtn->SetValue(event.GetChecked());
f03fc89f 1519 }
b3402d0d 1520#endif // wxUSE_RADIOBTN
7ec1983b 1521 }
1e6feb95 1522#endif // wxUSE_CONTROLS
7ec1983b 1523}
fd71308f 1524
f03fc89f
VZ
1525// ----------------------------------------------------------------------------
1526// dialog units translations
1527// ----------------------------------------------------------------------------
1528
1529wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
fd71308f
JS
1530{
1531 int charWidth = GetCharWidth();
1532 int charHeight = GetCharHeight();
5d9c2818
RD
1533 wxPoint pt2(-1, -1);
1534 if (pt.x != -1)
1535 pt2.x = (int) ((pt.x * 4) / charWidth) ;
1536 if (pt.y != -1)
1537 pt2.y = (int) ((pt.y * 8) / charHeight) ;
fd71308f
JS
1538
1539 return pt2;
1540}
1541
f03fc89f 1542wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
fd71308f
JS
1543{
1544 int charWidth = GetCharWidth();
1545 int charHeight = GetCharHeight();
5d9c2818
RD
1546 wxPoint pt2(-1, -1);
1547 if (pt.x != -1)
1548 pt2.x = (int) ((pt.x * charWidth) / 4) ;
1549 if (pt.y != -1)
1550 pt2.y = (int) ((pt.y * charHeight) / 8) ;
fd71308f
JS
1551
1552 return pt2;
1553}
1554
f03fc89f
VZ
1555// ----------------------------------------------------------------------------
1556// event handlers
1557// ----------------------------------------------------------------------------
1558
1559// propagate the colour change event to the subwindows
1560void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
1561{
1562 wxWindowList::Node *node = GetChildren().GetFirst();
1563 while ( node )
1564 {
1565 // Only propagate to non-top-level windows
1566 wxWindow *win = node->GetData();
1567 if ( !win->IsTopLevel() )
1568 {
1569 wxSysColourChangedEvent event2;
1570 event.m_eventObject = win;
1571 win->GetEventHandler()->ProcessEvent(event2);
1572 }
1573
1574 node = node->GetNext();
1575 }
1576}
1577
1578// the default action is to populate dialog with data when it's created
1579void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1580{
1581 TransferDataToWindow();
1582}
1583
a02dc3e3
VZ
1584// process Ctrl-Alt-mclick
1585void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1586{
1e6feb95 1587#if wxUSE_MSGDLG
a02dc3e3
VZ
1588 if ( event.ControlDown() && event.AltDown() )
1589 {
1590 // don't translate these strings
1591 wxString port;
af3062a8
VZ
1592
1593#ifdef __WXUNIVERSAL__
1594 port = _T("Univ/");
1595#endif // __WXUNIVERSAL__
1596
a02dc3e3
VZ
1597 switch ( wxGetOsVersion() )
1598 {
1599 case wxMOTIF_X: port = _T("Motif"); break;
ff8fda36
GD
1600 case wxMAC:
1601 case wxMAC_DARWIN: port = _T("Mac"); break;
a02dc3e3
VZ
1602 case wxBEOS: port = _T("BeOS"); break;
1603 case wxGTK:
1604 case wxGTK_WIN32:
1605 case wxGTK_OS2:
1606 case wxGTK_BEOS: port = _T("GTK"); break;
1607 case wxWINDOWS:
1608 case wxPENWINDOWS:
1609 case wxWINDOWS_NT:
1610 case wxWIN32S:
1611 case wxWIN95:
1612 case wxWIN386: port = _T("MS Windows"); break;
1613 case wxMGL_UNIX:
1614 case wxMGL_X:
1615 case wxMGL_WIN32:
1616 case wxMGL_OS2: port = _T("MGL"); break;
1617 case wxWINDOWS_OS2:
1618 case wxOS2_PM: port = _T("OS/2"); break;
1619 default: port = _T("unknown"); break;
1620 }
1621
1622 wxMessageBox(wxString::Format(
1623 _T(
af3062a8 1624 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
a02dc3e3
VZ
1625 ),
1626 port.c_str(),
1627 wxMAJOR_VERSION,
1628 wxMINOR_VERSION,
1629 wxRELEASE_NUMBER,
3f562374
VZ
1630#if wxUSE_UNICODE
1631 L" (Unicode)",
1632#else
1633 "",
1634#endif
1635 __TDATE__,
1636 __TTIME__
a02dc3e3
VZ
1637 ),
1638 _T("wxWindows information"),
1639 wxICON_INFORMATION | wxOK,
1640 (wxWindow *)this);
1641 }
1642 else
1e6feb95 1643#endif // wxUSE_MSGDLG
a02dc3e3
VZ
1644 {
1645 event.Skip();
1646 }
1647}
1648
f03fc89f
VZ
1649// ----------------------------------------------------------------------------
1650// list classes implementation
1651// ----------------------------------------------------------------------------
1652
1653void wxWindowListNode::DeleteData()
1654{
1655 delete (wxWindow *)GetData();
1656}
1657
1e6feb95
VZ
1658// ----------------------------------------------------------------------------
1659// borders
1660// ----------------------------------------------------------------------------
1661
1662wxBorder wxWindowBase::GetBorder() const
1663{
1664 wxBorder border = (wxBorder)(m_windowStyle & wxBORDER_MASK);
1665 if ( border == wxBORDER_DEFAULT )
1666 {
1667 border = GetDefaultBorder();
1668 }
1669
1670 return border;
1671}
1672
1673wxBorder wxWindowBase::GetDefaultBorder() const
1674{
1675 return wxBORDER_NONE;
1676}
1677
1678// ----------------------------------------------------------------------------
1679// hit testing
1680// ----------------------------------------------------------------------------
1681
1682wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
1683{
1684 // here we just check if the point is inside the window or not
1685
1686 // check the top and left border first
1687 bool outside = x < 0 || y < 0;
1688 if ( !outside )
1689 {
1690 // check the right and bottom borders too
1691 wxSize size = GetSize();
1692 outside = x >= size.x || y >= size.y;
1693 }
1694
1695 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
1696}
1697
94633ad9
VZ
1698// ----------------------------------------------------------------------------
1699// mouse capture
1700// ----------------------------------------------------------------------------
1701
1702struct WXDLLEXPORT wxWindowNext
1703{
1704 wxWindow *win;
1705 wxWindowNext *next;
786646f3 1706} *wxWindowBase::ms_winCaptureNext = NULL;
94633ad9 1707
a83e1475 1708void wxWindowBase::CaptureMouse()
94633ad9
VZ
1709{
1710 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
45e0dc94 1711
94633ad9
VZ
1712 wxWindow *winOld = GetCapture();
1713 if ( winOld )
1714 {
df2f507b 1715 ((wxWindowBase*) winOld)->DoReleaseMouse();
3edb5d30 1716
94633ad9
VZ
1717 // save it on stack
1718 wxWindowNext *item = new wxWindowNext;
1719 item->win = winOld;
1720 item->next = ms_winCaptureNext;
1721 ms_winCaptureNext = item;
1722 }
1723 //else: no mouse capture to save
1724
1725 DoCaptureMouse();
1726}
1727
a83e1475 1728void wxWindowBase::ReleaseMouse()
94633ad9 1729{
349d1942
VS
1730 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(0x%08x)"), this);
1731
a7b09001
VS
1732 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") )
1733
94633ad9
VZ
1734 DoReleaseMouse();
1735
1736 if ( ms_winCaptureNext )
1737 {
44f8caa7 1738 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
3edb5d30 1739
94633ad9
VZ
1740 wxWindowNext *item = ms_winCaptureNext;
1741 ms_winCaptureNext = item->next;
1742 delete item;
1743 }
1744 //else: stack is empty, no previous capture
1745
1746 wxLogTrace(_T("mousecapture"),
1747 _T("After ReleaseMouse() mouse is captured by 0x%08x"),
1748 GetCapture());
1749}
1750
34c3ffca 1751// vi:sts=4:sw=4:et