1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
30 #include "wx/notebook.h"
31 #include "wx/tabctrl.h"
32 // TODO remove the line below, just for lookup-up convenience CS
33 #include "wx/mac/window.h"
35 #include "wx/menuitem.h"
38 #define wxWINDOW_HSCROLL 5998
39 #define wxWINDOW_VSCROLL 5997
40 #define MAC_SCROLLBAR_SIZE 16
42 #include <wx/mac/uma.h>
44 #if wxUSE_DRAG_AND_DROP
50 extern wxList wxPendingDelete
;
51 wxWindow
* gFocusWindow
= NULL
;
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
56 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
57 EVT_CHAR(wxWindow::OnChar
)
58 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
59 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
60 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
61 EVT_IDLE(wxWindow::OnIdle
)
62 EVT_PAINT(wxWindow::OnPaint
)
76 m_macWindowData
= NULL
;
82 // these are the defaults for MSW
88 m_windowParent
= NULL
;
89 m_windowEventHandler
= this;
91 m_windowCursor
= *wxSTANDARD_CURSOR
;
92 m_children
= new wxWindowList
;
94 m_constraintsInvolvedIn
= NULL
;
98 m_windowValidator
= NULL
;
101 m_caretWidth
= 0; m_caretHeight
= 0;
102 m_caretEnabled
= FALSE
;
103 m_caretShown
= FALSE
;
104 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
105 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
106 m_foregroundColour
= *wxBLACK
;
107 m_hScrollBar
= NULL
;
108 m_vScrollBar
= NULL
;
109 m_mouseInWindow
= FALSE
;
111 #if wxUSE_DRAG_AND_DROP
112 m_pDropTarget
= NULL
;
117 wxWindow::~wxWindow()
119 if ( s_lastMouseWindow
== this )
121 s_lastMouseWindow
= NULL
;
123 // Have to delete constraints/sizer FIRST otherwise
124 // sizers may try to look at deleted windows as they
125 // delete themselves.
126 #if wxUSE_CONSTRAINTS
127 DeleteRelatedConstraints();
130 // This removes any dangling pointers to this window
131 // in other windows' constraintsInvolvedIn lists.
132 UnsetConstraints(m_constraints
);
133 delete m_constraints
;
134 m_constraints
= NULL
;
138 delete m_windowSizer
;
139 m_windowSizer
= NULL
;
141 // If this is a child of a sizer, remove self from parent
143 m_sizerParent
->RemoveChild((wxWindow
*)this);
146 if ( FindFocus() == this )
148 // really a bad thing - maybe an error ?
149 // we cannot even send it a kill focus message at this stage
150 gFocusWindow
= NULL
;
154 m_windowParent
->RemoveChild(this);
158 if ( m_macWindowData
)
160 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
161 delete m_macWindowData
;
162 wxRemoveMacWindowAssociation( this ) ;
168 // Just in case the window has been Closed, but
169 // we're then deleting immediately: don't leave
170 // dangling pointers.
171 wxPendingDelete
.DeleteObject(this);
173 if ( m_windowValidator
)
174 delete m_windowValidator
;
177 // Destroy the window (delayed, if a managed window)
178 bool wxWindow::Destroy()
185 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
189 const wxString
& name
)
195 m_windowParent
= NULL
;
196 m_windowEventHandler
= this;
198 m_windowCursor
= *wxSTANDARD_CURSOR
;
199 m_constraints
= NULL
;
200 m_constraintsInvolvedIn
= NULL
;
201 m_windowSizer
= NULL
;
202 m_sizerParent
= NULL
;
203 m_autoLayout
= FALSE
;
204 m_windowValidator
= NULL
;
206 #if wxUSE_DRAG_AND_DROP
207 m_pDropTarget
= NULL
;
210 m_caretWidth
= 0; m_caretHeight
= 0;
211 m_caretEnabled
= FALSE
;
212 m_caretShown
= FALSE
;
217 m_defaultItem
= NULL
;
218 m_windowParent
= NULL
;
222 if (parent
) parent
->AddChild(this);
229 m_windowId
= (int)NewControlId();
233 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
234 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
235 m_foregroundColour
= *wxBLACK
;
237 m_windowStyle
= style
;
240 m_windowId
= (int)NewControlId();
246 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
250 MacCreateScrollBars( style
) ;
255 void wxWindow::SetFocus()
257 if ( AcceptsFocus() )
261 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
262 if ( control
&& control
->GetMacControl() )
264 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
266 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
267 event
.SetEventObject(gFocusWindow
);
268 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
270 gFocusWindow
= this ;
272 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
273 if ( control
&& control
->GetMacControl() )
275 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
278 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
279 event
.SetEventObject(this);
280 GetEventHandler()->ProcessEvent(event
) ;
285 void wxWindow::Enable(bool enable
)
287 if ( m_macEnabled
== enable
)
290 m_macEnabled
= enable
;
292 MacSuperEnabled( enable
) ;
296 void wxWindow::CaptureMouse()
298 wxTheApp
->s_captureWindow
= this ;
301 void wxWindow::ReleaseMouse()
303 wxTheApp
->s_captureWindow
= NULL
;
306 // Push/pop event handler (i.e. allow a chain of event handlers
308 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
310 handler
->SetNextHandler(GetEventHandler());
311 SetEventHandler(handler
);
314 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
316 if ( GetEventHandler() )
318 wxEvtHandler
*handlerA
= GetEventHandler();
319 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
320 handlerA
->SetNextHandler(NULL
);
321 SetEventHandler(handlerB
);
334 #if wxUSE_DRAG_AND_DROP
336 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
338 if ( m_pDropTarget
!= 0 ) {
339 delete m_pDropTarget
;
342 m_pDropTarget
= pDropTarget
;
343 if ( m_pDropTarget
!= 0 )
351 // Old style file-manager drag&drop
352 void wxWindow::DragAcceptFiles(bool accept
)
358 void wxWindow::GetSize(int *x
, int *y
) const
364 void wxWindow::GetPosition(int *x
, int *y
) const
370 wxPoint
pt(GetParent()->GetClientAreaOrigin());
376 void wxWindow::ScreenToClient(int *x
, int *y
) const
378 WindowRef window
= GetMacRootWindow() ;
386 ::SetPort( UMAGetWindowPort( window
) ) ;
387 ::GlobalToLocal( &localwhere
) ;
393 MacRootWindowToClient( x
, y
) ;
396 void wxWindow::ClientToScreen(int *x
, int *y
) const
398 WindowRef window
= GetMacRootWindow() ;
400 MacClientToRootWindow( x
, y
) ;
408 ::SetPort( UMAGetWindowPort( window
) ) ;
409 ::LocalToGlobal( &localwhere
) ;
415 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
417 if ( m_macWindowData
)
424 GetParent()->MacClientToRootWindow( x
, y
) ;
428 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
430 if ( m_macWindowData
)
437 GetParent()->MacRootWindowToClient( x
, y
) ;
441 void wxWindow::SetCursor(const wxCursor
& cursor
)
443 m_windowCursor
= cursor
;
444 if (m_windowCursor
.Ok())
446 // since this only affects the window-cursor, we adopt the same
447 // behaviour as windows -> it will only change on mouse moved events
448 // otherwise the ::WxSetCursor routine will have to be used
453 // Get size *available for subwindows* i.e. excluding menu bar etc.
454 void wxWindow::GetClientSize(int *x
, int *y
) const
459 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
460 (*x
) -= MAC_SCROLLBAR_SIZE
;
461 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
462 (*y
) -= MAC_SCROLLBAR_SIZE
;
465 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
469 int former_w
= m_width
;
470 int former_h
= m_height
;
472 int currentX
, currentY
;
473 GetPosition(¤tX
, ¤tY
);
474 int currentW
,currentH
;
475 GetSize(¤tW
, ¤tH
);
477 int actualWidth
= width
;
478 int actualHeight
= height
;
481 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
483 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
486 actualWidth
= currentW
;
488 actualHeight
= currentH
;
490 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
492 MacRepositionScrollBars() ; // we might have a real position shift
496 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
499 bool doMove
= false ;
500 bool doResize
= false ;
502 if ( actualX
!= former_x
|| actualY
!= former_y
)
506 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
511 if ( doMove
|| doResize
)
513 if ( m_macWindowData
)
518 // erase former position
520 wxMacDrawingClientHelper
focus( this ) ;
523 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
524 InvalRect( &clientrect
) ;
530 m_width
= actualWidth
;
531 m_height
= actualHeight
;
532 if ( m_macWindowData
)
535 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
538 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
540 // the OS takes care of invalidating and erasing
542 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
544 wxFrame
* frame
= (wxFrame
*) this ;
545 frame
->PositionStatusBar();
546 frame
->PositionToolBar();
551 // erase new position
553 wxMacDrawingClientHelper
focus( this ) ;
556 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
557 InvalRect( &clientrect
) ;
561 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
563 MacRepositionScrollBars() ;
566 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
567 event
.SetEventObject(this);
568 GetEventHandler()->ProcessEvent(event
) ;
572 MacRepositionScrollBars() ;
573 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
574 event
.SetEventObject(this);
575 GetEventHandler()->ProcessEvent(event
);
579 // For implementation purposes - sometimes decorations make the client area
582 wxPoint
wxWindow::GetClientAreaOrigin() const
584 return wxPoint(0, 0);
587 // Makes an adjustment to the window position (for example, a frame that has
588 // a toolbar that it manages itself).
589 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
591 if( !m_macWindowData
)
593 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
595 wxPoint
pt(GetParent()->GetClientAreaOrigin());
596 x
+= pt
.x
; y
+= pt
.y
;
601 void wxWindow::SetTitle(const wxString
& title
)
605 if( wxApp::s_macDefaultEncodingIsPC
)
606 label
= wxMacMakeMacStringFromPC( title
) ;
610 if ( m_macWindowData
)
611 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
614 wxString
wxWindow::GetTitle() const
616 if ( m_macWindowData
)
620 UMAGetWTitleC( m_macWindowData
->m_macWindow
, title
) ;
621 if( wxApp::s_macDefaultEncodingIsPC
)
622 label
= wxMacMakePCStringFromMac( title
) ;
628 return wxEmptyString
;
631 void wxWindow::Centre(int direction
)
633 int x_offset
,y_offset
;
634 int display_width
, display_height
;
635 int width
, height
, x
, y
;
636 wxWindow
*parent
= GetParent();
637 if ((direction
& wxCENTER_FRAME
) && parent
)
639 parent
->GetPosition(&x_offset
,&y_offset
) ;
640 parent
->GetSize(&display_width
,&display_height
) ;
644 wxDisplaySize(&display_width
, &display_height
);
646 y_offset
= LMGetMBarHeight() + LMGetMBarHeight() / 2 ; // approx. the window title height
649 GetSize(&width
, &height
);
652 if (direction
& wxHORIZONTAL
)
653 x
= (int)((display_width
- width
)/2);
654 if (direction
& wxVERTICAL
)
655 y
= (int)((display_height
- height
)/2);
657 SetSize(x
+x_offset
, y
+y_offset
, width
, height
);
661 bool wxWindow::Show(bool show
)
663 if ( m_macShown
== show
)
667 if ( m_macWindowData
)
671 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
672 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
673 // no need to generate events here, they will get them triggered by macos
674 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
675 event
.SetEventObject(this);
676 GetEventHandler()->ProcessEvent(event
);
680 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
684 MacSuperShown( show
) ;
688 bool wxWindow::IsShown() const
693 int wxWindow::GetCharHeight() const
695 wxClientDC
dc ( (wxWindow
*)this ) ;
696 return dc
.GetCharHeight() ;
699 int wxWindow::GetCharWidth() const
701 wxClientDC
dc ( (wxWindow
*)this ) ;
702 return dc
.GetCharWidth() ;
705 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
706 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
708 wxFont
*fontToUse
= (wxFont
*)theFont
;
710 fontToUse
= (wxFont
*) & m_windowFont
;
715 void wxWindow::MacEraseBackground( Rect
*rect
)
717 WindowRef window
= GetMacRootWindow() ;
718 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
720 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
722 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
724 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
725 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
726 // either a non gray background color or a non control window
728 wxWindow
* parent
= GetParent() ;
731 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
733 // if we have any other colours in the hierarchy
734 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
737 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
739 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
740 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
742 ApplyThemeBackground (kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
748 // we have arrived at a non control item
752 parent
= parent
->GetParent() ;
756 // if there is nothing special -> use default
757 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
762 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
767 for (wxNode
*node
= m_children
->First(); node
; node
= node
->Next())
769 wxWindow
*child
= (wxWindow
*)node
->Data();
773 // child->GetClientSize( &width , &height ) ;
775 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
776 SectRect( &clientrect
, rect
, &clientrect
) ;
778 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
779 if ( child
->GetMacRootWindow() == window
&& child
->IsReallyShown() )
781 wxMacDrawingClientHelper
focus( this ) ;
784 child
->MacEraseBackground( &clientrect
) ;
790 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
792 wxMacDrawingClientHelper
focus( this ) ;
796 GetClientSize( &width
, &height
) ;
797 Rect clientrect
= { 0 , 0 , height
, width
} ;
798 ClipRect( &clientrect
) ;
802 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
803 SectRect( &clientrect
, &r
, &clientrect
) ;
805 InvalRect( &clientrect
) ;
809 MacEraseBackground( &clientrect ) ;
815 // Responds to colour changes: passes event on to children.
816 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
818 wxNode
*node
= GetChildren().First();
821 // Only propagate to non-top-level windows
822 wxWindow
*win
= (wxWindow
*)node
->Data();
823 if ( win
->GetParent() )
825 wxSysColourChangedEvent event2
;
826 event
.m_eventObject
= win
;
827 win
->GetEventHandler()->ProcessEvent(event2
);
834 // This can be called by the app (or wxWindows) to do default processing for the current
835 // event. Save message/event info in wxWindow so they can be used in this function.
836 long wxWindow::Default()
842 void wxWindow::InitDialog()
844 wxInitDialogEvent
event(GetId());
845 event
.SetEventObject( this );
846 GetEventHandler()->ProcessEvent(event
);
849 // Default init dialog behaviour is to transfer data to window
850 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
852 TransferDataToWindow();
855 // Caret manipulation
856 void wxWindow::CreateCaret(int w
, int h
)
860 m_caretEnabled
= TRUE
;
863 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
868 void wxWindow::ShowCaret(bool show
)
873 void wxWindow::DestroyCaret()
876 m_caretEnabled
= FALSE
;
879 void wxWindow::SetCaretPos(int x
, int y
)
884 void wxWindow::GetCaretPos(int *x
, int *y
) const
889 wxWindow
*wxGetActiveWindow()
891 // actually this is a windows-only concept
895 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
), int WXUNUSED(incH
))
904 // Coordinates relative to the window
905 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
907 // We really dont move the mouse programmatically under mac
910 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
912 // TODO : probably we would adopt the EraseEvent structure
916 int wxWindow::GetScrollPos(int orient
) const
918 if ( orient
== wxHORIZONTAL
)
921 return m_hScrollBar
->GetThumbPosition() ;
926 return m_vScrollBar
->GetThumbPosition() ;
931 // This now returns the whole range, not just the number
932 // of positions that we can scroll.
933 int wxWindow::GetScrollRange(int orient
) const
935 if ( orient
== wxHORIZONTAL
)
938 return m_hScrollBar
->GetRange() ;
943 return m_vScrollBar
->GetRange() ;
948 int wxWindow::GetScrollThumb(int orient
) const
950 if ( orient
== wxHORIZONTAL
)
953 return m_hScrollBar
->GetThumbSize() ;
958 return m_vScrollBar
->GetThumbSize() ;
963 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
965 if ( orient
== wxHORIZONTAL
)
968 m_hScrollBar
->SetThumbPosition( pos
) ;
973 m_vScrollBar
->SetThumbPosition( pos
) ;
977 // New function that will replace some of the above.
978 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
979 int range
, bool refresh
)
981 if ( orient
== wxHORIZONTAL
)
985 if ( range
== 0 || thumbVisible
>= range
)
987 if ( m_hScrollBar
->IsShown() )
988 m_hScrollBar
->Show(false) ;
992 if ( !m_hScrollBar
->IsShown() )
993 m_hScrollBar
->Show(true) ;
994 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1002 if ( range
== 0 || thumbVisible
>= range
)
1004 if ( m_vScrollBar
->IsShown() )
1005 m_vScrollBar
->Show(false) ;
1009 if ( !m_vScrollBar
->IsShown() )
1010 m_vScrollBar
->Show(true) ;
1011 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1015 MacRepositionScrollBars() ;
1018 // Does a physical scroll
1019 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1021 wxMacDrawingClientHelper
focus( this ) ;
1024 int width
, height
;
1025 GetClientSize( &width
, &height
) ;
1026 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1028 RgnHandle updateRgn
= NewRgn() ;
1029 ClipRect( &scrollrect
) ;
1032 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1033 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1035 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1036 InvalRgn( updateRgn
) ;
1037 DisposeRgn( updateRgn
) ;
1041 void wxWindow::SetFont(const wxFont
& font
)
1043 m_windowFont
= font
;
1045 if (!m_windowFont
.Ok())
1050 void wxWindow::OnChar(wxKeyEvent
& event
)
1052 if ( event
.KeyCode() == WXK_TAB
) {
1053 // propagate the TABs to the parent - it's up to it to decide what
1055 if ( GetParent() ) {
1056 if ( GetParent()->ProcessEvent(event
) )
1062 void wxWindow::OnPaint(wxPaintEvent
& event
)
1065 if ( m_macWindowData )
1067 wxMacDrawingClientHelper helper ( this ) ;
1069 GetUpdateRegion().GetBox( x , y , w , h ) ;
1070 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1071 Rect r = { y , x, y+h , x+w } ;
1076 wxMacDrawingClientHelper helper ( this ) ;
1078 GetUpdateRegion().GetBox( x , y , w , h ) ;
1079 RGBBackColor( &m_backgroundColour.GetPixel() ) ;
1080 Rect r = { y , x, y+h , x+w } ;
1086 bool wxWindow::IsEnabled() const
1088 return m_macEnabled
;
1091 // Dialog support: override these and call
1092 // base class members to add functionality
1093 // that can't be done using validators.
1094 // NOTE: these functions assume that controls
1095 // are direct children of this window, not grandchildren
1096 // or other levels of descendant.
1098 // Transfer values to controls. If returns FALSE,
1099 // it's an application error (pops up a dialog)
1100 bool wxWindow::TransferDataToWindow()
1102 wxNode
*node
= GetChildren().First();
1105 wxWindow
*child
= (wxWindow
*)node
->Data();
1106 if ( child
->GetValidator() &&
1107 !child
->GetValidator()->TransferToWindow() )
1109 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1113 node
= node
->Next();
1118 // Transfer values from controls. If returns FALSE,
1119 // validation failed: don't quit
1120 bool wxWindow::TransferDataFromWindow()
1122 wxNode
*node
= GetChildren().First();
1125 wxWindow
*child
= (wxWindow
*)node
->Data();
1126 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1131 node
= node
->Next();
1136 bool wxWindow::Validate()
1138 wxNode
*node
= GetChildren().First();
1141 wxWindow
*child
= (wxWindow
*)node
->Data();
1142 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1147 node
= node
->Next();
1152 // Get the window with the focus
1153 wxWindow
*wxWindow::FindFocus()
1155 return gFocusWindow
;
1158 // ----------------------------------------------------------------------------
1160 // ----------------------------------------------------------------------------
1162 bool wxWindow::IsTopLevel() const
1164 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
1167 void wxWindow::AddChild(wxWindow
*child
)
1169 GetChildren().Append(child
);
1170 child
->m_windowParent
= this;
1173 void wxWindow::RemoveChild(wxWindow
*child
)
1175 GetChildren().DeleteObject(child
);
1176 child
->m_windowParent
= NULL
;
1179 void wxWindow::DestroyChildren()
1182 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1184 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1186 if ( GetChildren().Find(child
) )
1192 void wxWindow::MakeModal(bool modal
)
1194 // Disable all other windows
1195 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1197 wxNode
*node
= wxTopLevelWindows
.First();
1200 wxWindow
*win
= (wxWindow
*)node
->Data();
1202 win
->Enable(!modal
);
1204 node
= node
->Next();
1209 // If nothing defined for this, try the parent.
1210 // E.g. we may be a button loaded from a resource, with no callback function
1212 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1214 if (GetEventHandler()->ProcessEvent(event
) )
1217 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1220 // ----------------------------------------------------------------------------
1221 // constraints and sizers
1222 // ----------------------------------------------------------------------------
1224 #if wxUSE_CONSTRAINTS
1226 void wxWindow::SetConstraints( wxLayoutConstraints
*constraints
)
1228 if ( m_constraints
)
1230 UnsetConstraints(m_constraints
);
1231 delete m_constraints
;
1233 m_constraints
= constraints
;
1234 if ( m_constraints
)
1236 // Make sure other windows know they're part of a 'meaningful relationship'
1237 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1238 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1239 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1240 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1241 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1242 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1243 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1244 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1245 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1246 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1247 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1248 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1249 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1250 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1251 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1252 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1256 // This removes any dangling pointers to this window in other windows'
1257 // constraintsInvolvedIn lists.
1258 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1262 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1263 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1264 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1265 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1266 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1267 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1268 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1269 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1270 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1271 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1272 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1273 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1274 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1275 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1276 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1277 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1281 // Back-pointer to other windows we're involved with, so if we delete this
1282 // window, we must delete any constraints we're involved with.
1283 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1285 if ( !m_constraintsInvolvedIn
)
1286 m_constraintsInvolvedIn
= new wxWindowList
;
1287 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1288 m_constraintsInvolvedIn
->Append(otherWin
);
1291 // REMOVE back-pointer to other windows we're involved with.
1292 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1294 if ( m_constraintsInvolvedIn
)
1295 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1298 // Reset any constraints that mention this window
1299 void wxWindow::DeleteRelatedConstraints()
1301 if ( m_constraintsInvolvedIn
)
1303 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1306 wxWindow
*win
= node
->GetData();
1307 wxLayoutConstraints
*constr
= win
->GetConstraints();
1309 // Reset any constraints involving this window
1312 constr
->left
.ResetIfWin(this);
1313 constr
->top
.ResetIfWin(this);
1314 constr
->right
.ResetIfWin(this);
1315 constr
->bottom
.ResetIfWin(this);
1316 constr
->width
.ResetIfWin(this);
1317 constr
->height
.ResetIfWin(this);
1318 constr
->centreX
.ResetIfWin(this);
1319 constr
->centreY
.ResetIfWin(this);
1322 wxWindowList::Node
*next
= node
->GetNext();
1327 delete m_constraintsInvolvedIn
;
1328 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1332 void wxWindow::SetSizer(wxSizer
*sizer
)
1334 if (m_windowSizer
) delete m_windowSizer
;
1336 m_windowSizer
= sizer
;
1339 bool wxWindow::Layout()
1342 GetClientSize(&w
, &h
);
1344 // If there is a sizer, use it instead of the constraints
1347 GetSizer()->SetDimension( 0, 0, w
, h
);
1351 if ( GetConstraints() )
1353 GetConstraints()->width
.SetValue(w
);
1354 GetConstraints()->height
.SetValue(h
);
1357 // Evaluate child constraints
1358 ResetConstraints(); // Mark all constraints as unevaluated
1359 DoPhase(1); // Just one phase need if no sizers involved
1361 SetConstraintSizes(); // Recursively set the real window sizes
1367 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
1368 // do a similar thing, but also impose their own 'constraints' and order the
1369 // evaluation differently.
1370 bool wxWindow::LayoutPhase1(int *noChanges
)
1372 wxLayoutConstraints
*constr
= GetConstraints();
1375 return constr
->SatisfyConstraints(this, noChanges
);
1381 bool wxWindow::LayoutPhase2(int *noChanges
)
1391 // Do a phase of evaluating child constraints
1392 bool wxWindow::DoPhase(int phase
)
1394 int noIterations
= 0;
1395 int maxIterations
= 500;
1398 wxWindowList succeeded
;
1399 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1403 wxWindowList::Node
*node
= GetChildren().GetFirst();
1406 wxWindow
*child
= node
->GetData();
1407 if ( !child
->IsTopLevel() )
1409 wxLayoutConstraints
*constr
= child
->GetConstraints();
1412 if ( !succeeded
.Find(child
) )
1414 int tempNoChanges
= 0;
1415 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1416 noChanges
+= tempNoChanges
;
1419 succeeded
.Append(child
);
1424 node
= node
->GetNext();
1433 void wxWindow::ResetConstraints()
1435 wxLayoutConstraints
*constr
= GetConstraints();
1438 constr
->left
.SetDone(FALSE
);
1439 constr
->top
.SetDone(FALSE
);
1440 constr
->right
.SetDone(FALSE
);
1441 constr
->bottom
.SetDone(FALSE
);
1442 constr
->width
.SetDone(FALSE
);
1443 constr
->height
.SetDone(FALSE
);
1444 constr
->centreX
.SetDone(FALSE
);
1445 constr
->centreY
.SetDone(FALSE
);
1447 wxWindowList::Node
*node
= GetChildren().GetFirst();
1450 wxWindow
*win
= node
->GetData();
1451 if ( !win
->IsTopLevel() )
1452 win
->ResetConstraints();
1453 node
= node
->GetNext();
1457 // Need to distinguish between setting the 'fake' size for windows and sizers,
1458 // and setting the real values.
1459 void wxWindow::SetConstraintSizes(bool recurse
)
1461 wxLayoutConstraints
*constr
= GetConstraints();
1462 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1463 constr
->width
.GetDone() && constr
->height
.GetDone())
1465 int x
= constr
->left
.GetValue();
1466 int y
= constr
->top
.GetValue();
1467 int w
= constr
->width
.GetValue();
1468 int h
= constr
->height
.GetValue();
1470 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1471 (constr
->height
.GetRelationship() != wxAsIs
) )
1473 SetSize(x
, y
, w
, h
);
1477 // If we don't want to resize this window, just move it...
1483 char *windowClass
= GetClassInfo()->GetClassName();
1486 if ( GetName() == _T("") )
1487 winName
= _T("unnamed");
1489 winName
= GetName();
1490 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1491 (const char *)windowClass
,
1492 (const char *)winName
);
1493 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1494 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1495 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1496 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1497 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1502 wxWindowList::Node
*node
= GetChildren().GetFirst();
1505 wxWindow
*win
= node
->GetData();
1506 if ( !win
->IsTopLevel() )
1507 win
->SetConstraintSizes();
1508 node
= node
->GetNext();
1513 // Only set the size/position of the constraint (if any)
1514 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1516 wxLayoutConstraints
*constr
= GetConstraints();
1521 constr
->left
.SetValue(x
);
1522 constr
->left
.SetDone(TRUE
);
1526 constr
->top
.SetValue(y
);
1527 constr
->top
.SetDone(TRUE
);
1531 constr
->width
.SetValue(w
);
1532 constr
->width
.SetDone(TRUE
);
1536 constr
->height
.SetValue(h
);
1537 constr
->height
.SetDone(TRUE
);
1542 void wxWindow::MoveConstraint(int x
, int y
)
1544 wxLayoutConstraints
*constr
= GetConstraints();
1549 constr
->left
.SetValue(x
);
1550 constr
->left
.SetDone(TRUE
);
1554 constr
->top
.SetValue(y
);
1555 constr
->top
.SetDone(TRUE
);
1560 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1562 wxLayoutConstraints
*constr
= GetConstraints();
1565 *w
= constr
->width
.GetValue();
1566 *h
= constr
->height
.GetValue();
1572 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1574 wxLayoutConstraints
*constr
= GetConstraints();
1577 *w
= constr
->width
.GetValue();
1578 *h
= constr
->height
.GetValue();
1581 GetClientSize(w
, h
);
1584 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1586 wxLayoutConstraints
*constr
= GetConstraints();
1589 *x
= constr
->left
.GetValue();
1590 *y
= constr
->top
.GetValue();
1596 #endif // wxUSE_CONSTRAINTS
1598 bool wxWindow::Close(bool force
)
1600 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1601 event
.SetEventObject(this);
1602 #if WXWIN_COMPATIBILITY
1603 event
.SetForce(force
);
1605 event
.SetCanVeto(!force
);
1607 return GetEventHandler()->ProcessEvent(event
);
1610 wxObject
* wxWindow::GetChild(int number
) const
1612 // Return a pointer to the Nth object in the window
1613 wxNode
*node
= GetChildren().First();
1616 node
= node
->Next() ;
1619 wxObject
*obj
= (wxObject
*)node
->Data();
1626 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1628 // Obsolete function
1631 void wxWindow::Clear()
1633 if ( m_macWindowData
)
1635 wxMacDrawingClientHelper
helper ( this ) ;
1637 wxPoint origin
= GetClientAreaOrigin() ;
1638 GetClientSize( &w
, &h
) ;
1639 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1640 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1645 wxClientDC
dc(this);
1646 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1647 dc
.SetBackground(brush
);
1652 // Fits the panel around the items
1653 void wxWindow::Fit()
1657 wxNode
*node
= GetChildren().First();
1660 wxWindow
*win
= (wxWindow
*)node
->Data();
1662 win
->GetPosition(&wx
, &wy
);
1663 win
->GetSize(&ww
, &wh
);
1664 if ( wx
+ ww
> maxX
)
1666 if ( wy
+ wh
> maxY
)
1669 node
= node
->Next();
1671 SetClientSize(maxX
+ 5, maxY
+ 5);
1674 void wxWindow::SetValidator(const wxValidator
& validator
)
1676 if ( m_windowValidator
)
1677 delete m_windowValidator
;
1678 m_windowValidator
= validator
.Clone();
1680 if ( m_windowValidator
)
1681 m_windowValidator
->SetWindow(this) ;
1684 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1686 m_acceleratorTable
= accel
;
1689 // Find a window by id or name
1690 wxWindow
*wxWindow::FindWindow(long id
)
1695 wxNode
*node
= GetChildren().First();
1698 wxWindow
*child
= (wxWindow
*)node
->Data();
1699 wxWindow
*found
= child
->FindWindow(id
);
1702 node
= node
->Next();
1707 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1709 if ( GetName() == name
)
1712 wxNode
*node
= GetChildren().First();
1715 wxWindow
*child
= (wxWindow
*)node
->Data();
1716 wxWindow
*found
= child
->FindWindow(name
);
1719 node
= node
->Next();
1724 void wxWindow::OnIdle(wxIdleEvent
& event
)
1727 // Check if we need to send a LEAVE event
1728 if (m_mouseInWindow)
1731 ::GetCursorPos(&pt);
1732 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1734 // Generate a LEAVE event
1735 m_mouseInWindow = FALSE;
1736 MSWOnMouseLeave(pt.x, pt.y, 0);
1741 // This calls the UI-update mechanism (querying windows for
1742 // menu/toolbar/control state information)
1746 // Raise the window to the top of the Z order
1747 void wxWindow::Raise()
1752 // Lower the window to the bottom of the Z order
1753 void wxWindow::Lower()
1758 bool wxWindow::AcceptsFocus() const
1760 return IsShown() && IsEnabled() && MacCanFocus() ;
1763 // Update region access
1764 wxRegion
wxWindow::GetUpdateRegion() const
1766 return m_updateRegion
;
1769 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1771 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1774 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1776 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1779 bool wxWindow::IsExposed(const wxRect
& rect
) const
1781 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1785 * Allocates control IDs
1788 int wxWindow::NewControlId()
1790 static int s_controlId
= 0;
1795 void wxWindow::DoSetClientSize(int width
, int height
)
1797 if ( width
!= -1 || height
!= -1 )
1800 if ( width
!= -1 && m_vScrollBar
)
1801 width
+= MAC_SCROLLBAR_SIZE
;
1802 if ( height
!= -1 && m_vScrollBar
)
1803 height
+= MAC_SCROLLBAR_SIZE
;
1805 DoSetSize( -1 , -1 , width
, height
) ;
1809 // ------------------------
1810 wxList
*wxWinMacWindowList
= NULL
;
1811 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
1813 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
1816 return (wxWindow
*)node
->Data();
1819 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
1821 // adding NULL WindowRef is (first) surely a result of an error and
1822 // (secondly) breaks menu command processing
1823 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
1825 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
1826 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
1829 void wxRemoveMacWindowAssociation(wxWindow
*win
)
1831 wxWinMacWindowList
->DeleteObject(win
);
1834 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1836 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1838 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1839 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1842 WindowRef window
= GetMacRootWindow() ;
1844 wxPoint
newPoint( point
) ;
1851 for (wxNode
*node
= m_children
->First(); node
; node
= node
->Next())
1853 wxWindow
*child
= (wxWindow
*)node
->Data();
1854 if ( child
->GetMacRootWindow() == window
)
1856 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1866 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1869 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1870 if ( ::FindWindow( pt
, &window
) == 3 )
1872 wxPoint
point( screenpoint
) ;
1873 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1874 win
->ScreenToClient( point
) ;
1875 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1880 extern int wxBusyCursorCount
;
1882 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1884 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1885 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1888 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1891 WindowRef window
= GetMacRootWindow() ;
1901 for (wxNode
*node
= m_children
->First(); node
; node
= node
->Next())
1903 wxWindow
*child
= (wxWindow
*)node
->Data();
1904 if ( child
->GetMacRootWindow() == window
&& child
->IsReallyShown() && child
->IsReallyEnabled() )
1906 if (child
->MacDispatchMouseEvent(event
))
1915 if ( wxBusyCursorCount
== 0 )
1917 m_windowCursor
.MacInstall() ;
1919 GetEventHandler()->ProcessEvent( event
) ;
1923 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1925 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1926 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1927 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1929 event
.m_leftDown
= isDown
&& !controlDown
;
1930 event
.m_middleDown
= FALSE
;
1931 event
.m_rightDown
= isDown
&& controlDown
;
1933 if ( ev
->what
== mouseDown
)
1936 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1938 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1940 else if ( ev
->what
== mouseUp
)
1943 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1945 event
.SetEventType(wxEVT_LEFT_UP
) ;
1949 event
.SetEventType(wxEVT_MOTION
) ;
1952 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1953 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1954 event
.m_altDown
= ev
->modifiers
& optionKey
;
1955 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1957 Point localwhere
= ev
->where
;
1960 ::GetPort( &port
) ;
1961 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1962 ::GlobalToLocal( &localwhere
) ;
1965 event
.m_x
= localwhere
.h
;
1966 event
.m_y
= localwhere
.v
;
1971 wxPoint origin = GetClientAreaOrigin() ;
1973 event.m_x += origin.x ;
1974 event.m_y += origin.y ;
1977 event
.m_timeStamp
= ev
->when
;
1978 event
.SetEventObject(this);
1979 if ( wxTheApp
->s_captureWindow
)
1983 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1986 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1987 if ( ev
->what
== mouseUp
)
1989 wxTheApp
->s_captureWindow
= NULL
;
1990 if ( wxBusyCursorCount
== 0 )
1992 m_windowCursor
.MacInstall() ;
1998 MacDispatchMouseEvent( event
) ;
2002 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
2004 MacFireMouseEvent( ev
) ;
2007 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
2009 WindowPtr frontWindow
;
2014 MacFireMouseEvent( ev
) ;
2020 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
2022 WindowPtr frontWindow
;
2027 MacFireMouseEvent( ev
) ;
2032 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
2034 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
2035 event
.m_timeStamp
= ev
->when
;
2036 event
.SetEventObject(this);
2038 GetEventHandler()->ProcessEvent(event
);
2040 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
2043 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
2045 // updatergn is always already clipped to our boundaries
2046 WindowRef window
= GetMacRootWindow() ;
2047 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
2049 wxMacDrawingClientHelper
focus( this ) ;
2052 WindowRef window
= GetMacRootWindow() ;
2053 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
2055 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
2057 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
2059 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
2060 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
2061 // either a non gray background color or a non control window
2064 wxWindow
* parent
= GetParent() ;
2067 if ( parent
->GetMacRootWindow() != window
)
2069 // we are in a different window on the mac system
2074 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
2076 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
2078 // if we have any other colours in the hierarchy
2079 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
2082 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
2083 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
2085 ApplyThemeBackground (kThemeBackgroundTabPane
, &(**updatergn
).rgnBBox
, kThemeStateActive
,8,true);
2094 parent
= parent
->GetParent() ;
2098 // if there is nothing special -> use default
2099 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
2104 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
2106 SetClip( updatergn
) ;
2107 EraseRgn( updatergn
) ;
2112 m_updateRegion
= updatergn
;
2114 event
.m_timeStamp
= time
;
2115 event
.SetEventObject(this);
2117 GetEventHandler()->ProcessEvent(event
);
2119 RgnHandle childupdate
= NewRgn() ;
2121 for (wxNode
*node
= m_children
->First(); node
; node
= node
->Next())
2123 wxWindow
*child
= (wxWindow
*)node
->Data();
2127 child
->GetClientSize( &width
, &height
) ;
2129 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+width
, child
->m_y
+ height
) ;
2130 SectRgn( childupdate
, m_updateRegion
.GetWXHRGN() , childupdate
) ;
2131 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
2132 if ( child
->GetMacRootWindow() == window
&& child
->IsReallyShown() )
2134 // because dialogs may also be children
2135 child
->MacRedraw( childupdate
, time
) ;
2138 DisposeRgn( childupdate
) ;
2139 // eventually a draw grow box here
2142 void wxWindow::MacUpdateImmediately()
2144 WindowRef window
= GetMacRootWindow() ;
2147 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
2148 BeginUpdate( window
) ;
2152 if ( !EmptyRgn( window
->visRgn
) )
2155 win
->MacRedraw( window
->visRgn
, wxTheApp
->sm_lastMessageTime
) ;
2158 wxMacDrawingHelper help( win ) ;
2159 SetOrigin( 0 , 0 ) ;
2160 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
2161 UMAUpdateControls( window , window->visRgn ) ;
2162 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2167 EndUpdate( window
) ;
2171 void wxWindow::MacUpdate( EventRecord
*ev
)
2173 WindowRef window
= (WindowRef
) ev
->message
;
2174 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
2176 BeginUpdate( window
) ;
2179 // if windowshade gives incompatibility , take the follwing out
2181 if ( !EmptyRgn( window
->visRgn
) )
2184 MacRedraw( window
->visRgn
, ev
->when
) ;
2187 wxMacDrawingHelper help( this ) ;
2188 SetOrigin( 0 , 0 ) ;
2189 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
2190 UMAUpdateControls( window , window->visRgn ) ;
2191 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
2196 EndUpdate( window
) ;
2199 WindowRef
wxWindow::GetMacRootWindow() const
2201 WindowRef window
= NULL
;
2202 wxWindow
*iter
= (wxWindow
*)this ;
2206 if ( iter
->m_macWindowData
)
2207 return iter
->m_macWindowData
->m_macWindow
;
2209 iter
= iter
->GetParent() ;
2211 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2215 void wxWindow::MacCreateScrollBars( long style
)
2217 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2218 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2219 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2221 if ( style
& wxVSCROLL
)
2223 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, wxPoint(m_width
-MAC_SCROLLBAR_SIZE
, 0),
2224 wxSize(MAC_SCROLLBAR_SIZE
, m_height
- adjust
), wxVERTICAL
);
2226 if ( style
& wxHSCROLL
)
2228 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, wxPoint(0 , m_height
-MAC_SCROLLBAR_SIZE
),
2229 wxSize( m_width
- adjust
, MAC_SCROLLBAR_SIZE
), wxHORIZONTAL
);
2231 // because the create does not take into account the client area origin
2232 MacRepositionScrollBars() ; // we might have a real position shift
2235 void wxWindow::MacRepositionScrollBars()
2237 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2238 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2242 m_vScrollBar
->SetSize( m_width
-MAC_SCROLLBAR_SIZE
, 0, MAC_SCROLLBAR_SIZE
, m_height
- adjust
, wxSIZE_USE_EXISTING
);
2246 m_hScrollBar
->SetSize( 0 , m_height
-MAC_SCROLLBAR_SIZE
,m_width
- adjust
, MAC_SCROLLBAR_SIZE
, wxSIZE_USE_EXISTING
);
2250 void wxWindow::MacKeyDown( EventRecord
*ev
)
2257 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2259 if ( m_macWindowData
)
2260 return m_macWindowData
->m_macRootControl
;
2262 return GetParent()->MacGetContainerForEmbedding() ;
2265 void wxWindow::MacSuperChangedPosition()
2267 // only window-absolute structures have to be moved i.e. controls
2269 wxNode
*node
= GetChildren().First();
2272 wxWindow
*child
= (wxWindow
*)node
->Data();
2273 child
->MacSuperChangedPosition() ;
2274 node
= node
->Next();
2278 bool wxWindow::IsReallyShown() const
2280 if ( m_macWindowData
)
2283 return m_macShown
&& GetParent()->IsReallyShown() ;
2286 bool wxWindow::IsReallyEnabled() const
2288 if ( m_macWindowData
)
2289 return m_macEnabled
;
2291 return m_macEnabled
&& GetParent()->IsReallyEnabled() ;
2294 void wxWindow::MacSuperEnabled( bool enabled
)
2296 wxNode
*node
= GetChildren().First();
2299 wxWindow
*child
= (wxWindow
*)node
->Data();
2300 if ( child
->m_macEnabled
)
2301 child
->MacSuperEnabled( enabled
) ;
2302 node
= node
->Next();
2305 void wxWindow::MacSuperShown( bool show
)
2307 wxNode
*node
= GetChildren().First();
2310 wxWindow
*child
= (wxWindow
*)node
->Data();
2311 if ( child
->m_macShown
)
2312 child
->MacSuperShown( show
) ;
2313 node
= node
->Next();
2317 bool wxWindow::MacSetupFocusPort( )
2325 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2326 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
2329 bool wxWindow::MacSetupFocusClientPort( )
2337 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2338 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
2341 bool wxWindow::MacSetupDrawingPort( )
2349 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2350 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2353 bool wxWindow::MacSetupDrawingClientPort( )
2361 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2362 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2366 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2368 if ( window
== NULL
)
2374 ::GetPort(&currPort
);
2375 port
= UMAGetWindowPort( window
) ;
2376 if (currPort
!= port
)
2379 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2383 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2385 if ( window
== NULL
)
2390 ::GetPort(&currPort
);
2391 port
= UMAGetWindowPort( window
) ;
2392 if (currPort
!= port
)
2395 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2396 ::ClipRect(&clipRect
);
2399 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2400 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2401 ::BackPat( &qd
.white
) ;
2402 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2406 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2408 if ( m_macWindowData
)
2414 clipRect
->right
= m_width
;
2415 clipRect
->bottom
= m_height
;
2416 *window
= m_macWindowData
->m_macWindow
;
2421 wxASSERT( GetParent() != NULL
) ;
2422 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2423 localOrigin
->h
+= m_x
;
2424 localOrigin
->v
+= m_y
;
2425 OffsetRect(clipRect
, -m_x
, -m_y
);
2430 myClip
.right
= m_width
;
2431 myClip
.bottom
= m_height
;
2432 SectRect(clipRect
, &myClip
, clipRect
);
2436 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2438 int width
, height
;
2439 GetClientSize( &width
, &height
) ;
2441 if ( m_macWindowData
)
2447 clipRect
->right
= m_width
;//width;
2448 clipRect
->bottom
= m_height
;// height;
2449 *window
= m_macWindowData
->m_macWindow
;
2454 wxASSERT( GetParent() != NULL
) ;
2456 GetParent()->MacGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2458 localOrigin
->h
+= m_x
;
2459 localOrigin
->v
+= m_y
;
2460 OffsetRect(clipRect
, -m_x
, -m_y
);
2465 myClip
.right
= width
;
2466 myClip
.bottom
= height
;
2467 SectRect(clipRect
, &myClip
, clipRect
);
2471 wxMacFocusHelper::wxMacFocusHelper( wxWindow
* theWindow
)
2478 m_currentPort
= NULL
;
2479 GetPort( &m_formerPort
) ;
2483 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2484 m_currentPort
= UMAGetWindowPort( window
) ;
2485 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
2490 wxMacFocusHelper::~wxMacFocusHelper()
2494 SetOrigin( 0 , 0 ) ;
2496 if ( m_formerPort
!= m_currentPort
)
2497 SetPort( m_formerPort
) ;
2500 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2507 m_currentPort
= NULL
;
2509 GetPort( &m_formerPort
) ;
2512 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2513 m_currentPort
= UMAGetWindowPort( window
) ;
2514 if ( m_formerPort
!= m_currentPort
)
2515 SetPort( m_currentPort
) ;
2516 GetPenState( &m_savedPenState
) ;
2517 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2522 wxMacDrawingHelper::~wxMacDrawingHelper()
2526 SetPenState( &m_savedPenState
) ;
2527 SetOrigin( 0 , 0 ) ;
2528 ClipRect( &m_currentPort
->portRect
) ;
2531 if ( m_formerPort
!= m_currentPort
)
2532 SetPort( m_formerPort
) ;
2535 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow
* theWindow
)
2542 m_currentPort
= NULL
;
2544 GetPort( &m_formerPort
) ;
2548 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2549 m_currentPort
= UMAGetWindowPort( window
) ;
2550 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
2555 wxMacFocusClientHelper::~wxMacFocusClientHelper()
2559 SetOrigin( 0 , 0 ) ;
2561 if ( m_formerPort
!= m_currentPort
)
2562 SetPort( m_formerPort
) ;
2565 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2572 m_currentPort
= NULL
;
2574 GetPort( &m_formerPort
) ;
2578 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2579 m_currentPort
= UMAGetWindowPort( window
) ;
2580 if ( m_formerPort
!= m_currentPort
)
2581 SetPort( m_currentPort
) ;
2582 GetPenState( &m_savedPenState
) ;
2583 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2588 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2592 SetPenState( &m_savedPenState
) ;
2593 SetOrigin( 0 , 0 ) ;
2594 ClipRect( &m_currentPort
->portRect
) ;
2597 if ( m_formerPort
!= m_currentPort
)
2598 SetPort( m_formerPort
) ;
2601 // ----------------------------------------------------------------------------
2602 // list classes implementation
2603 // ----------------------------------------------------------------------------
2605 void wxWindowListNode::DeleteData()
2607 delete (wxWindow
*)GetData();