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