]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
fixes to toolbar, seems to work
[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 // Whether we're using the current theme for this window (wxGTK only for now)
178 m_themeEnabled = FALSE;
179 }
180
181 // common part of window creation process
182 bool wxWindowBase::CreateBase(wxWindowBase *parent,
183 wxWindowID id,
184 const wxPoint& WXUNUSED(pos),
185 const wxSize& WXUNUSED(size),
186 long style,
187 const wxValidator& validator,
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)
193 wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
194
195 // generate a new id if the user doesn't care about it
196 m_windowId = id == -1 ? NewControlId() : id;
197
198 SetName(name);
199 SetWindowStyleFlag(style);
200 SetParent(parent);
201
202 #if wxUSE_VALIDATORS
203 SetValidator(validator);
204 #endif // wxUSE_VALIDATORS
205
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
214 return TRUE;
215 }
216
217 // ----------------------------------------------------------------------------
218 // destruction
219 // ----------------------------------------------------------------------------
220
221 // common clean up
222 wxWindowBase::~wxWindowBase()
223 {
224 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
225
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);
236
237 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
238
239 #if wxUSE_CARET
240 if ( m_caret )
241 delete m_caret;
242 #endif // wxUSE_CARET
243
244 #if wxUSE_VALIDATORS
245 if ( m_windowValidator )
246 delete m_windowValidator;
247 #endif // wxUSE_VALIDATORS
248
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
263 #endif // wxUSE_CONSTRAINTS
264
265 if ( m_containingSizer )
266 m_containingSizer->Remove((wxWindow*)this);
267
268 if ( m_windowSizer )
269 delete m_windowSizer;
270
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
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 }
286 }
287
288 bool wxWindowBase::Destroy()
289 {
290 delete this;
291
292 return TRUE;
293 }
294
295 bool 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
309 bool wxWindowBase::DestroyChildren()
310 {
311 wxWindowList::Node *node;
312 for ( ;; )
313 {
314 // we iterate until the list becomes empty
315 node = GetChildren().GetFirst();
316 if ( !node )
317 break;
318
319 wxWindow *child = node->GetData();
320
321 wxASSERT_MSG( child, wxT("children list contains empty nodes") );
322
323 child->Show(FALSE);
324 delete child;
325
326 wxASSERT_MSG( !GetChildren().Find(child),
327 wxT("child didn't remove itself using RemoveChild()") );
328 }
329
330 return TRUE;
331 }
332
333 // ----------------------------------------------------------------------------
334 // size/position related methods
335 // ----------------------------------------------------------------------------
336
337 // centre the window with respect to its parent in either (or both) directions
338 void wxWindowBase::Centre(int direction)
339 {
340 // the position/size of the parent window or of the entire screen
341 wxPoint posParent;
342 int widthParent, heightParent;
343
344 wxWindow *parent = NULL;
345
346 if ( !(direction & wxCENTRE_ON_SCREEN) )
347 {
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 }
366 }
367
368 if ( direction & wxCENTRE_ON_SCREEN )
369 {
370 // centre with respect to the whole screen
371 wxDisplaySize(&widthParent, &heightParent);
372 }
373 else
374 {
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 }
388 }
389
390 int width, height;
391 GetSize(&width, &height);
392
393 int xNew = -1,
394 yNew = -1;
395
396 if ( direction & wxHORIZONTAL )
397 xNew = (widthParent - width)/2;
398
399 if ( direction & wxVERTICAL )
400 yNew = (heightParent - height)/2;
401
402 xNew += posParent.x;
403 yNew += posParent.y;
404
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
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
415 {
416 if (xNew < 0)
417 xNew = 0;
418 else if (xNew+width > size.x)
419 xNew = size.x-width-1;
420 }
421 if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display
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
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)
435 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
436 }
437
438 // fits the window around the children
439 void wxWindowBase::Fit()
440 {
441 if ( GetChildren().GetCount() > 0 )
442 {
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);
451 }
452 //else: do nothing if we have no children
453 }
454
455 // return the size best suited for the current window
456 wxSize wxWindowBase::DoGetBestSize() const
457 {
458 if ( GetChildren().GetCount() > 0 )
459 {
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() )
467 {
468 wxWindow *win = node->GetData();
469 if ( win->IsTopLevel()
470 #if wxUSE_STATUSBAR
471 || wxDynamicCast(win, wxStatusBar)
472 #endif // wxUSE_STATUSBAR
473 )
474 {
475 // dialogs and frames lie in different top level windows -
476 // don't deal with them here; as for the status bars, they
477 // don't lie in the client area at all
478 continue;
479 }
480
481 int wx, wy, ww, wh;
482 win->GetPosition(&wx, &wy);
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
491 win->GetSize(&ww, &wh);
492 if ( wx + ww > maxX )
493 maxX = wx + ww;
494 if ( wy + wh > maxY )
495 maxY = wy + wh;
496 }
497
498 return wxSize(maxX, maxY);
499 }
500 else
501 {
502 // for a generic window there is no natural best size - just use the
503 // current one
504 return GetSize();
505 }
506 }
507
508 // by default the origin is not shifted
509 wxPoint wxWindowBase::GetClientAreaOrigin() const
510 {
511 return wxPoint(0, 0);
512 }
513
514 // set the min/max size of the window
515 void 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
529 bool 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
543 bool 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 }
556 // ----------------------------------------------------------------------------
557 // RTTI
558 // ----------------------------------------------------------------------------
559
560 bool wxWindowBase::IsTopLevel() const
561 {
562 return FALSE;
563 }
564
565 // ----------------------------------------------------------------------------
566 // reparenting the window
567 // ----------------------------------------------------------------------------
568
569 void wxWindowBase::AddChild(wxWindowBase *child)
570 {
571 wxCHECK_RET( child, wxT("can't add a NULL child") );
572
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
578 GetChildren().Append(child);
579 child->SetParent(this);
580 }
581
582 void wxWindowBase::RemoveChild(wxWindowBase *child)
583 {
584 wxCHECK_RET( child, wxT("can't remove a NULL child") );
585
586 GetChildren().DeleteObject(child);
587 child->SetParent((wxWindow *)NULL);
588 }
589
590 bool 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
626 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
627 {
628 handler->SetNextHandler(GetEventHandler());
629 SetEventHandler(handler);
630 }
631
632 wxEvtHandler *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
650 bool 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
685 // ----------------------------------------------------------------------------
686 // cursors, fonts &c
687 // ----------------------------------------------------------------------------
688
689 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
690 {
691 if ( !colour.Ok() || (colour == m_backgroundColour) )
692 return FALSE;
693
694 m_backgroundColour = colour;
695
696 m_hasBgCol = TRUE;
697
698 return TRUE;
699 }
700
701 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
702 {
703 if ( !colour.Ok() || (colour == m_foregroundColour) )
704 return FALSE;
705
706 m_foregroundColour = colour;
707
708 m_hasFgCol = TRUE;
709
710 return TRUE;
711 }
712
713 bool wxWindowBase::SetCursor(const wxCursor& cursor)
714 {
715 // setting an invalid cursor is ok, it means that we don't have any special
716 // cursor
717 if ( m_cursor == cursor )
718 {
719 // no change
720 return FALSE;
721 }
722
723 m_cursor = cursor;
724
725 return TRUE;
726 }
727
728 bool 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
733 if ( fontOk == m_font )
734 {
735 // no change
736 return FALSE;
737 }
738
739 m_font = fontOk;
740
741 m_hasFont = TRUE;
742
743 return TRUE;
744 }
745
746 #if wxUSE_PALETTE
747
748 void 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
758 wxWindow *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
771 #if wxUSE_CARET
772 void 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,
784 wxT("caret should be created associated to this window") );
785 }
786 }
787 #endif // wxUSE_CARET
788
789 #if wxUSE_VALIDATORS
790 // ----------------------------------------------------------------------------
791 // validators
792 // ----------------------------------------------------------------------------
793
794 void 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 }
804 #endif // wxUSE_VALIDATORS
805
806 // ----------------------------------------------------------------------------
807 // update region stuff
808 // ----------------------------------------------------------------------------
809
810 wxRect 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
822 bool wxWindowBase::IsExposed(int x, int y) const
823 {
824 return m_updateRegion.Contains(x, y) != wxOutRegion;
825 }
826
827 bool 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
836 wxWindow *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
852 wxWindow *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
872 void wxWindowBase::MakeModal(bool modal)
873 {
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 }
887 }
888
889 bool wxWindowBase::Validate()
890 {
891 #if wxUSE_VALIDATORS
892 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
893
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();
899 if ( validator && !validator->Validate((wxWindow *)this) )
900 {
901 return FALSE;
902 }
903
904 if ( recurse && !child->Validate() )
905 {
906 return FALSE;
907 }
908 }
909 #endif // wxUSE_VALIDATORS
910
911 return TRUE;
912 }
913
914 bool wxWindowBase::TransferDataToWindow()
915 {
916 #if wxUSE_VALIDATORS
917 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
918
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 {
926 wxLogWarning(_("Could not transfer data to window"));
927 wxLog::FlushActive();
928
929 return FALSE;
930 }
931
932 if ( recurse )
933 {
934 if ( !child->TransferDataToWindow() )
935 {
936 // warning already given
937 return FALSE;
938 }
939 }
940 }
941 #endif // wxUSE_VALIDATORS
942
943 return TRUE;
944 }
945
946 bool wxWindowBase::TransferDataFromWindow()
947 {
948 #if wxUSE_VALIDATORS
949 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
950
951 wxWindowList::Node *node;
952 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
953 {
954 wxWindow *child = node->GetData();
955 wxValidator *validator = child->GetValidator();
956 if ( validator && !validator->TransferFromWindow() )
957 {
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
961 return FALSE;
962 }
963
964 if ( recurse )
965 {
966 if ( !child->TransferDataFromWindow() )
967 {
968 // warning already given
969 return FALSE;
970 }
971 }
972 }
973 #endif // wxUSE_VALIDATORS
974
975 return TRUE;
976 }
977
978 void wxWindowBase::InitDialog()
979 {
980 wxInitDialogEvent event(GetId());
981 event.SetEventObject( this );
982 GetEventHandler()->ProcessEvent(event);
983 }
984
985 // ----------------------------------------------------------------------------
986 // context-sensitive help support
987 // ----------------------------------------------------------------------------
988
989 #if wxUSE_HELP
990
991 // associate this help text with this window
992 void 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
1003 void 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)
1013 wxString 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
1026 void 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 // ----------------------------------------------------------------------------
1044 // tooltipsroot.Replace("\\", "/");
1045 // ----------------------------------------------------------------------------
1046
1047 #if wxUSE_TOOLTIPS
1048
1049 void 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
1065 void 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
1081 void 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.
1113 void 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.
1138 void 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.
1147 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1148 {
1149 if ( m_constraintsInvolvedIn )
1150 m_constraintsInvolvedIn->DeleteObject(otherWin);
1151 }
1152
1153 // Reset any constraints that mention this window
1154 void 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 }
1186 #endif
1187
1188 void wxWindowBase::SetSizer(wxSizer *sizer)
1189 {
1190 if (m_windowSizer) delete m_windowSizer;
1191
1192 m_windowSizer = sizer;
1193 }
1194
1195 bool wxWindowBase::Layout()
1196 {
1197 // If there is a sizer, use it instead of the constraints
1198 if ( GetSizer() )
1199 {
1200 int w, h;
1201 GetClientSize(&w, &h);
1202
1203 GetSizer()->SetDimension( 0, 0, w, h );
1204 }
1205 #if wxUSE_CONSTRAINTS
1206 else
1207 {
1208 wxLayoutConstraints *constr = GetConstraints();
1209 bool wasOk = constr && constr->AreSatisfied();
1210
1211 ResetConstraints(); // Mark all constraints as unevaluated
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
1227 SetConstraintSizes(); // Recursively set the real window sizes
1228 }
1229 #endif
1230
1231 return TRUE;
1232 }
1233
1234 #if wxUSE_CONSTRAINTS
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.
1238 bool 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
1249 bool 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
1260 bool 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();
1275 if ( !child->IsTopLevel() )
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
1301 void 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 }
1315
1316 wxWindowList::Node *node = GetChildren().GetFirst();
1317 while (node)
1318 {
1319 wxWindow *win = node->GetData();
1320 if ( !win->IsTopLevel() )
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.
1328 void wxWindowBase::SetConstraintSizes(bool recurse)
1329 {
1330 wxLayoutConstraints *constr = GetConstraints();
1331 if ( constr && constr->AreSatisfied() )
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
1338 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1339 (constr->height.GetRelationship() != wxAsIs) )
1340 {
1341 SetSize(x, y, w, h);
1342 }
1343 else
1344 {
1345 // If we don't want to resize this window, just move it...
1346 Move(x, y);
1347 }
1348 }
1349 else if ( constr )
1350 {
1351 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1352 GetClassInfo()->GetClassName(),
1353 GetName().c_str());
1354 }
1355
1356 if ( recurse )
1357 {
1358 wxWindowList::Node *node = GetChildren().GetFirst();
1359 while (node)
1360 {
1361 wxWindow *win = node->GetData();
1362 if ( !win->IsTopLevel() && win->GetConstraints() )
1363 win->SetConstraintSizes();
1364 node = node->GetNext();
1365 }
1366 }
1367 }
1368
1369 // Only set the size/position of the constraint (if any)
1370 void 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
1398 void 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
1416 void 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
1428 void 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
1440 void 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
1454 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
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
1470 // ----------------------------------------------------------------------------
1471 // do Update UI processing for child controls
1472 // ----------------------------------------------------------------------------
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.
1478 void wxWindowBase::UpdateWindowUI()
1479 {
1480 #if wxUSE_CONTROLS
1481 wxUpdateUIEvent event(GetId());
1482 event.m_eventObject = this;
1483
1484 if ( GetEventHandler()->ProcessEvent(event) )
1485 {
1486 if ( event.GetSetEnabled() )
1487 Enable(event.GetEnabled());
1488
1489 if ( event.GetSetText() )
1490 {
1491 wxControl *control = wxDynamicCastThis(wxControl);
1492 if ( control )
1493 {
1494 #if wxUSE_TEXTCTRL
1495 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1496 if ( text )
1497 text->SetValue(event.GetText());
1498 else
1499 #endif // wxUSE_TEXTCTRL
1500 control->SetLabel(event.GetText());
1501 }
1502 }
1503
1504 #if wxUSE_CHECKBOX
1505 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
1506 if ( checkbox )
1507 {
1508 if ( event.GetSetChecked() )
1509 checkbox->SetValue(event.GetChecked());
1510 }
1511 #endif // wxUSE_CHECKBOX
1512
1513 #if wxUSE_RADIOBTN
1514 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
1515 if ( radiobtn )
1516 {
1517 if ( event.GetSetChecked() )
1518 radiobtn->SetValue(event.GetChecked());
1519 }
1520 #endif // wxUSE_RADIOBTN
1521 }
1522 #endif // wxUSE_CONTROLS
1523 }
1524
1525 // ----------------------------------------------------------------------------
1526 // dialog units translations
1527 // ----------------------------------------------------------------------------
1528
1529 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
1530 {
1531 int charWidth = GetCharWidth();
1532 int charHeight = GetCharHeight();
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) ;
1538
1539 return pt2;
1540 }
1541
1542 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
1543 {
1544 int charWidth = GetCharWidth();
1545 int charHeight = GetCharHeight();
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) ;
1551
1552 return pt2;
1553 }
1554
1555 // ----------------------------------------------------------------------------
1556 // event handlers
1557 // ----------------------------------------------------------------------------
1558
1559 // propagate the colour change event to the subwindows
1560 void 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
1579 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1580 {
1581 TransferDataToWindow();
1582 }
1583
1584 // process Ctrl-Alt-mclick
1585 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1586 {
1587 #if wxUSE_MSGDLG
1588 if ( event.ControlDown() && event.AltDown() )
1589 {
1590 // don't translate these strings
1591 wxString port;
1592
1593 #ifdef __WXUNIVERSAL__
1594 port = _T("Univ/");
1595 #endif // __WXUNIVERSAL__
1596
1597 switch ( wxGetOsVersion() )
1598 {
1599 case wxMOTIF_X: port = _T("Motif"); break;
1600 case wxMAC:
1601 case wxMAC_DARWIN: port = _T("Mac"); break;
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(
1624 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1625 ),
1626 port.c_str(),
1627 wxMAJOR_VERSION,
1628 wxMINOR_VERSION,
1629 wxRELEASE_NUMBER,
1630 #if wxUSE_UNICODE
1631 L" (Unicode)",
1632 #else
1633 "",
1634 #endif
1635 __TDATE__,
1636 __TTIME__
1637 ),
1638 _T("wxWindows information"),
1639 wxICON_INFORMATION | wxOK,
1640 (wxWindow *)this);
1641 }
1642 else
1643 #endif // wxUSE_MSGDLG
1644 {
1645 event.Skip();
1646 }
1647 }
1648
1649 // ----------------------------------------------------------------------------
1650 // list classes implementation
1651 // ----------------------------------------------------------------------------
1652
1653 void wxWindowListNode::DeleteData()
1654 {
1655 delete (wxWindow *)GetData();
1656 }
1657
1658 // ----------------------------------------------------------------------------
1659 // borders
1660 // ----------------------------------------------------------------------------
1661
1662 wxBorder 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
1673 wxBorder wxWindowBase::GetDefaultBorder() const
1674 {
1675 return wxBORDER_NONE;
1676 }
1677
1678 // ----------------------------------------------------------------------------
1679 // hit testing
1680 // ----------------------------------------------------------------------------
1681
1682 wxHitTest 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
1698 // ----------------------------------------------------------------------------
1699 // mouse capture
1700 // ----------------------------------------------------------------------------
1701
1702 struct WXDLLEXPORT wxWindowNext
1703 {
1704 wxWindow *win;
1705 wxWindowNext *next;
1706 } *wxWindowBase::ms_winCaptureNext = NULL;
1707
1708 void wxWindowBase::CaptureMouse()
1709 {
1710 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
1711
1712 wxWindow *winOld = GetCapture();
1713 if ( winOld )
1714 {
1715 ((wxWindowBase*) winOld)->DoReleaseMouse();
1716
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
1728 void wxWindowBase::ReleaseMouse()
1729 {
1730 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(0x%08x)"), this);
1731
1732 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") )
1733
1734 DoReleaseMouse();
1735
1736 if ( ms_winCaptureNext )
1737 {
1738 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
1739
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