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_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
58 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
59 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
60 EVT_IDLE(wxWindow::OnIdle
)
61 // EVT_SCROLL(wxWindow::OnScroll)
68 // ===========================================================================
70 // ===========================================================================
72 // ---------------------------------------------------------------------------
73 // wxWindow utility functions
74 // ---------------------------------------------------------------------------
76 // Find an item given the Macintosh Window Reference
78 wxList
*wxWinMacWindowList
= NULL
;
79 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
81 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
84 return (wxWindow
*)node
->Data();
87 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
89 // adding NULL WindowRef is (first) surely a result of an error and
90 // (secondly) breaks menu command processing
91 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
93 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
94 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
97 void wxRemoveMacWindowAssociation(wxWindow
*win
)
99 wxWinMacWindowList
->DeleteObject(win
);
102 // ----------------------------------------------------------------------------
103 // constructors and such
104 // ----------------------------------------------------------------------------
106 void wxWindow::Init()
112 m_doubleClickAllowed
= 0;
113 m_winCaptured
= FALSE
;
115 m_isBeingDeleted
= FALSE
;
118 m_mouseInWindow
= FALSE
;
122 m_backgroundTransparent
= FALSE
;
124 // as all windows are created with WS_VISIBLE style...
127 m_macWindowData
= NULL
;
134 m_hScrollBar
= NULL
;
135 m_vScrollBar
= NULL
;
137 #if wxUSE_DRAG_AND_DROP
138 m_pDropTarget
= NULL
;
143 wxWindow::~wxWindow()
145 m_isBeingDeleted
= TRUE
;
147 if ( s_lastMouseWindow
== this )
149 s_lastMouseWindow
= NULL
;
152 if ( gFocusWindow
== this )
154 gFocusWindow
= NULL
;
158 m_parent
->RemoveChild(this);
162 if ( m_macWindowData
)
164 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
165 delete m_macWindowData
;
166 wxRemoveMacWindowAssociation( this ) ;
171 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
175 const wxString
& name
)
177 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
179 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
182 parent
->AddChild(this);
186 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
187 m_width
= WidthDefault( size
.x
);
188 m_height
= HeightDefault( size
.y
) ;
190 MacCreateScrollBars( style
) ;
195 void wxWindow::SetFocus()
197 if ( AcceptsFocus() )
201 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
202 if ( control
&& control
->GetMacControl() )
204 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
206 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
207 event
.SetEventObject(gFocusWindow
);
208 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
210 gFocusWindow
= this ;
212 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
213 if ( control
&& control
->GetMacControl() )
215 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
218 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
219 event
.SetEventObject(this);
220 GetEventHandler()->ProcessEvent(event
) ;
225 bool wxWindow::Enable(bool enable
)
227 if ( !wxWindowBase::Enable(enable
) )
230 HWND hWnd = GetHwnd();
232 ::EnableWindow(hWnd, (BOOL)enable);
235 wxWindowList::Node
*node
= GetChildren().GetFirst();
238 wxWindow
*child
= node
->GetData();
239 child
->Enable(enable
);
241 node
= node
->GetNext();
247 void wxWindow::CaptureMouse()
249 wxTheApp
->s_captureWindow
= this ;
252 void wxWindow::ReleaseMouse()
254 wxTheApp
->s_captureWindow
= NULL
;
257 #if wxUSE_DRAG_AND_DROP
259 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
261 if ( m_pDropTarget
!= 0 ) {
262 delete m_pDropTarget
;
265 m_pDropTarget
= pDropTarget
;
266 if ( m_pDropTarget
!= 0 )
274 // Old style file-manager drag&drop
275 void wxWindow::DragAcceptFiles(bool accept
)
281 void wxWindow::DoGetSize(int *x
, int *y
) const
287 void wxWindow::DoGetPosition(int *x
, int *y
) const
293 wxPoint
pt(GetParent()->GetClientAreaOrigin());
299 wxSize
wxWindow::DoGetBestSize()
301 return wxSize( 0 , 0 ) ;
304 bool wxWindow::Reparent(wxWindow
*parent
)
306 if ( !wxWindowBase::Reparent(parent
) )
312 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
314 menu
->SetInvokingWindow(this);
316 ClientToScreen( &x
, &y
) ;
318 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
319 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
320 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
321 ::DeleteMenu( menu
->MacGetMenuId() ) ;
322 menu
->SetInvokingWindow(NULL
);
327 void wxWindow::DoScreenToClient(int *x
, int *y
) const
329 WindowRef window
= GetMacRootWindow() ;
337 ::SetPort( UMAGetWindowPort( window
) ) ;
338 ::GlobalToLocal( &localwhere
) ;
344 MacRootWindowToClient( x
, y
) ;
347 void wxWindow::DoClientToScreen(int *x
, int *y
) const
349 WindowRef window
= GetMacRootWindow() ;
351 MacClientToRootWindow( x
, y
) ;
359 ::SetPort( UMAGetWindowPort( window
) ) ;
360 ::LocalToGlobal( &localwhere
) ;
366 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
368 if ( m_macWindowData
)
375 GetParent()->MacClientToRootWindow( x
, y
) ;
379 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
381 if ( m_macWindowData
)
388 GetParent()->MacRootWindowToClient( x
, y
) ;
392 bool wxWindow::SetCursor(const wxCursor
& cursor
)
394 if ( !wxWindowBase::SetCursor(cursor
) )
400 wxASSERT_MSG( m_cursor
.Ok(),
401 wxT("cursor must be valid after call to the base version"));
407 // Change the cursor NOW if we're within the correct window
409 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
411 if ( mouseWin
== this && !wxIsBusy() )
413 cursor
.MacInstall() ;
421 // Get size *available for subwindows* i.e. excluding menu bar etc.
422 void wxWindow::DoGetClientSize(int *x
, int *y
) const
427 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
428 (*x
) -= MAC_SCROLLBAR_SIZE
;
429 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
430 (*y
) -= MAC_SCROLLBAR_SIZE
;
434 // ----------------------------------------------------------------------------
436 // ----------------------------------------------------------------------------
440 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
442 wxWindowBase::DoSetToolTip(tooltip
);
445 // m_tooltip->SetWindow(this);
448 #endif // wxUSE_TOOLTIPS
450 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
452 DoSetSize( x
,y
, width
, height
) ;
455 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
459 int former_w
= m_width
;
460 int former_h
= m_height
;
462 int currentX
, currentY
;
463 GetPosition(¤tX
, ¤tY
);
464 int currentW
,currentH
;
465 GetSize(¤tW
, ¤tH
);
467 int actualWidth
= width
;
468 int actualHeight
= height
;
471 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
473 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
476 actualWidth
= currentW
;
478 actualHeight
= currentH
;
480 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
482 MacRepositionScrollBars() ; // we might have a real position shift
486 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
489 bool doMove
= false ;
490 bool doResize
= false ;
492 if ( actualX
!= former_x
|| actualY
!= former_y
)
496 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
501 if ( doMove
|| doResize
)
503 if ( m_macWindowData
)
508 // erase former position
510 wxMacDrawingClientHelper
focus( this ) ;
513 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
514 InvalRect( &clientrect
) ;
520 m_width
= actualWidth
;
521 m_height
= actualHeight
;
522 if ( m_macWindowData
)
525 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
528 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
530 // the OS takes care of invalidating and erasing
532 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
534 wxFrame
* frame
= (wxFrame
*) this ;
535 frame
->PositionStatusBar();
536 frame
->PositionToolBar();
541 // erase new position
543 wxMacDrawingClientHelper
focus( this ) ;
546 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
547 InvalRect( &clientrect
) ;
551 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
553 MacRepositionScrollBars() ;
556 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
557 event
.SetEventObject(this);
558 GetEventHandler()->ProcessEvent(event
) ;
562 MacRepositionScrollBars() ;
563 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
564 event
.SetEventObject(this);
565 GetEventHandler()->ProcessEvent(event
);
569 // For implementation purposes - sometimes decorations make the client area
572 wxPoint
wxWindow::GetClientAreaOrigin() const
574 return wxPoint(0, 0);
577 // Makes an adjustment to the window position (for example, a frame that has
578 // a toolbar that it manages itself).
579 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
581 if( !m_macWindowData
)
583 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
585 wxPoint
pt(GetParent()->GetClientAreaOrigin());
586 x
+= pt
.x
; y
+= pt
.y
;
591 void wxWindow::SetTitle(const wxString
& title
)
597 if( wxApp::s_macDefaultEncodingIsPC
)
598 label
= wxMacMakeMacStringFromPC( title
) ;
602 if ( m_macWindowData
)
603 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
606 wxString
wxWindow::GetTitle() const
611 bool wxWindow::Show(bool show
)
613 if ( !wxWindowBase::Show(show
) )
616 if ( m_macWindowData
)
620 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
621 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
622 // no need to generate events here, they will get them triggered by macos
623 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
624 event
.SetEventObject(this);
625 GetEventHandler()->ProcessEvent(event
);
629 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
637 int wxWindow::GetCharHeight() const
639 wxClientDC
dc ( (wxWindow
*)this ) ;
640 return dc
.GetCharHeight() ;
643 int wxWindow::GetCharWidth() const
645 wxClientDC
dc ( (wxWindow
*)this ) ;
646 return dc
.GetCharWidth() ;
649 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
650 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
652 const wxFont
*fontToUse
= theFont
;
656 wxClientDC
dc( this ) ;
658 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
659 *externalLeading
= le
;
665 void wxWindow::MacEraseBackground( Rect
*rect
)
667 WindowRef window
= GetMacRootWindow() ;
668 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
670 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
672 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
674 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
675 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
676 // either a non gray background color or a non control window
678 wxWindow
* parent
= GetParent() ;
681 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
683 // if we have any other colours in the hierarchy
684 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
687 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
689 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
690 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
692 ApplyThemeBackground (kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
698 // we have arrived at a non control item
702 parent
= parent
->GetParent() ;
706 // if there is nothing special -> use default
707 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
712 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
717 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
719 wxWindow
*child
= (wxWindow
*)node
->Data();
723 // child->GetClientSize( &width , &height ) ;
725 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
726 SectRect( &clientrect
, rect
, &clientrect
) ;
728 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
729 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
731 wxMacDrawingClientHelper
focus( this ) ;
734 child
->MacEraseBackground( &clientrect
) ;
740 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
742 wxMacDrawingClientHelper
focus( this ) ;
746 GetClientSize( &width
, &height
) ;
747 Rect clientrect
= { 0 , 0 , height
, width
} ;
748 ClipRect( &clientrect
) ;
752 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
753 SectRect( &clientrect
, &r
, &clientrect
) ;
755 InvalRect( &clientrect
) ;
759 MacEraseBackground( &clientrect ) ;
765 // Responds to colour changes: passes event on to children.
766 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
768 wxNode
*node
= GetChildren().First();
771 // Only propagate to non-top-level windows
772 wxWindow
*win
= (wxWindow
*)node
->Data();
773 if ( win
->GetParent() )
775 wxSysColourChangedEvent event2
;
776 event
.m_eventObject
= win
;
777 win
->GetEventHandler()->ProcessEvent(event2
);
784 #if wxUSE_CARET && WXWIN_COMPATIBILITY
785 // ---------------------------------------------------------------------------
786 // Caret manipulation
787 // ---------------------------------------------------------------------------
789 void wxWindow::CreateCaret(int w
, int h
)
791 SetCaret(new wxCaret(this, w
, h
));
794 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
796 wxFAIL_MSG("not implemented");
799 void wxWindow::ShowCaret(bool show
)
801 wxCHECK_RET( m_caret
, "no caret to show" );
806 void wxWindow::DestroyCaret()
811 void wxWindow::SetCaretPos(int x
, int y
)
813 wxCHECK_RET( m_caret
, "no caret to move" );
818 void wxWindow::GetCaretPos(int *x
, int *y
) const
820 wxCHECK_RET( m_caret
, "no caret to get position of" );
822 m_caret
->GetPosition(x
, y
);
824 #endif // wxUSE_CARET
826 wxWindow
*wxGetActiveWindow()
828 // actually this is a windows-only concept
832 // Coordinates relative to the window
833 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
835 // We really dont move the mouse programmatically under mac
838 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
840 // TODO : probably we would adopt the EraseEvent structure
843 int wxWindow::GetScrollPos(int orient
) const
845 if ( orient
== wxHORIZONTAL
)
848 return m_hScrollBar
->GetThumbPosition() ;
853 return m_vScrollBar
->GetThumbPosition() ;
858 // This now returns the whole range, not just the number
859 // of positions that we can scroll.
860 int wxWindow::GetScrollRange(int orient
) const
862 if ( orient
== wxHORIZONTAL
)
865 return m_hScrollBar
->GetRange() ;
870 return m_vScrollBar
->GetRange() ;
875 int wxWindow::GetScrollThumb(int orient
) const
877 if ( orient
== wxHORIZONTAL
)
880 return m_hScrollBar
->GetThumbSize() ;
885 return m_vScrollBar
->GetThumbSize() ;
890 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
892 if ( orient
== wxHORIZONTAL
)
895 m_hScrollBar
->SetThumbPosition( pos
) ;
900 m_vScrollBar
->SetThumbPosition( pos
) ;
904 // New function that will replace some of the above.
905 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
906 int range
, bool refresh
)
908 if ( orient
== wxHORIZONTAL
)
912 if ( range
== 0 || thumbVisible
>= range
)
914 if ( m_hScrollBar
->IsShown() )
915 m_hScrollBar
->Show(false) ;
919 if ( !m_hScrollBar
->IsShown() )
920 m_hScrollBar
->Show(true) ;
921 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
929 if ( range
== 0 || thumbVisible
>= range
)
931 if ( m_vScrollBar
->IsShown() )
932 m_vScrollBar
->Show(false) ;
936 if ( !m_vScrollBar
->IsShown() )
937 m_vScrollBar
->Show(true) ;
938 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
942 MacRepositionScrollBars() ;
945 // Does a physical scroll
946 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
948 wxMacDrawingClientHelper
focus( this ) ;
952 GetClientSize( &width
, &height
) ;
953 Rect scrollrect
= { 0 , 0 , height
, width
} ;
955 RgnHandle updateRgn
= NewRgn() ;
956 ClipRect( &scrollrect
) ;
959 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
960 SectRect( &scrollrect
, &r
, &scrollrect
) ;
962 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
963 InvalRgn( updateRgn
) ;
964 DisposeRgn( updateRgn
) ;
968 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
970 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
972 wxScrollWinEvent wevent
;
973 wevent
.SetPosition(event
.GetPosition());
974 wevent
.SetOrientation(event
.GetOrientation());
975 wevent
.m_eventObject
= this;
977 switch ( event
.m_eventType
)
979 case wxEVT_SCROLL_TOP
:
980 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
983 case wxEVT_SCROLL_BOTTOM
:
984 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
987 case wxEVT_SCROLL_LINEUP
:
988 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
991 case wxEVT_SCROLL_LINEDOWN
:
992 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
995 case wxEVT_SCROLL_PAGEUP
:
996 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
999 case wxEVT_SCROLL_PAGEDOWN
:
1000 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1003 case wxEVT_SCROLL_THUMBTRACK
:
1004 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1009 GetEventHandler()->ProcessEvent(wevent
);
1013 bool wxWindow::SetFont(const wxFont
& font
)
1015 if ( !wxWindowBase::SetFont(font
) )
1024 // Get the window with the focus
1025 wxWindow
*wxWindowBase::FindFocus()
1027 return gFocusWindow
;
1030 #if WXWIN_COMPATIBILITY
1031 // If nothing defined for this, try the parent.
1032 // E.g. we may be a button loaded from a resource, with no callback function
1034 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1036 if ( GetEventHandler()->ProcessEvent(event
) )
1039 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1041 #endif // WXWIN_COMPATIBILITY_2
1043 #if WXWIN_COMPATIBILITY
1044 wxObject
* wxWindow::GetChild(int number
) const
1046 // Return a pointer to the Nth object in the Panel
1047 wxNode
*node
= GetChildren().First();
1050 node
= node
->Next();
1053 wxObject
*obj
= (wxObject
*)node
->Data();
1059 #endif // WXWIN_COMPATIBILITY
1061 void wxWindow::Clear()
1063 if ( m_macWindowData
)
1065 wxMacDrawingClientHelper
helper ( this ) ;
1067 wxPoint origin
= GetClientAreaOrigin() ;
1068 GetClientSize( &w
, &h
) ;
1069 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1070 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1075 wxClientDC
dc(this);
1076 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1077 dc
.SetBackground(brush
);
1082 // Setup background and foreground colours correctly
1083 void wxWindow::SetupColours()
1086 SetBackgroundColour(GetParent()->GetBackgroundColour());
1089 void wxWindow::OnIdle(wxIdleEvent
& event
)
1092 // Check if we need to send a LEAVE event
1093 if (m_mouseInWindow)
1096 ::GetCursorPos(&pt);
1097 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1099 // Generate a LEAVE event
1100 m_mouseInWindow = FALSE;
1101 MSWOnMouseLeave(pt.x, pt.y, 0);
1106 // This calls the UI-update mechanism (querying windows for
1107 // menu/toolbar/control state information)
1111 // Raise the window to the top of the Z order
1112 void wxWindow::Raise()
1117 // Lower the window to the bottom of the Z order
1118 void wxWindow::Lower()
1123 void wxWindow::DoSetClientSize(int width
, int height
)
1125 if ( width
!= -1 || height
!= -1 )
1128 if ( width
!= -1 && m_vScrollBar
)
1129 width
+= MAC_SCROLLBAR_SIZE
;
1130 if ( height
!= -1 && m_vScrollBar
)
1131 height
+= MAC_SCROLLBAR_SIZE
;
1133 DoSetSize( -1 , -1 , width
, height
) ;
1138 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1140 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1142 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1143 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1146 WindowRef window
= GetMacRootWindow() ;
1148 wxPoint
newPoint( point
) ;
1153 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1155 wxWindow
*child
= (wxWindow
*)node
->Data();
1156 if ( child
->GetMacRootWindow() == window
)
1158 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1167 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1170 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1171 if ( ::FindWindow( pt
, &window
) == 3 )
1173 wxPoint
point( screenpoint
) ;
1174 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1175 win
->ScreenToClient( point
) ;
1176 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1181 extern int wxBusyCursorCount
;
1183 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1185 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1186 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1189 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1192 WindowRef window
= GetMacRootWindow() ;
1200 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1202 wxWindow
*child
= (wxWindow
*)node
->Data();
1203 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1205 if (child
->MacDispatchMouseEvent(event
))
1213 if ( wxBusyCursorCount
== 0 )
1215 m_cursor
.MacInstall() ;
1217 GetEventHandler()->ProcessEvent( event
) ;
1221 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1223 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1224 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1225 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1227 event
.m_leftDown
= isDown
&& !controlDown
;
1228 event
.m_middleDown
= FALSE
;
1229 event
.m_rightDown
= isDown
&& controlDown
;
1231 if ( ev
->what
== mouseDown
)
1234 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1236 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1238 else if ( ev
->what
== mouseUp
)
1241 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1243 event
.SetEventType(wxEVT_LEFT_UP
) ;
1247 event
.SetEventType(wxEVT_MOTION
) ;
1250 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1251 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1252 event
.m_altDown
= ev
->modifiers
& optionKey
;
1253 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1255 Point localwhere
= ev
->where
;
1258 ::GetPort( &port
) ;
1259 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1260 ::GlobalToLocal( &localwhere
) ;
1263 event
.m_x
= localwhere
.h
;
1264 event
.m_y
= localwhere
.v
;
1269 wxPoint origin = GetClientAreaOrigin() ;
1271 event.m_x += origin.x ;
1272 event.m_y += origin.y ;
1275 event
.m_timeStamp
= ev
->when
;
1276 event
.SetEventObject(this);
1277 if ( wxTheApp
->s_captureWindow
)
1281 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1284 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1285 if ( ev
->what
== mouseUp
)
1287 wxTheApp
->s_captureWindow
= NULL
;
1288 if ( wxBusyCursorCount
== 0 )
1290 m_cursor
.MacInstall() ;
1296 MacDispatchMouseEvent( event
) ;
1300 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1302 MacFireMouseEvent( ev
) ;
1305 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1307 WindowPtr frontWindow
;
1312 MacFireMouseEvent( ev
) ;
1318 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1320 WindowPtr frontWindow
;
1325 MacFireMouseEvent( ev
) ;
1330 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1332 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1333 event
.m_timeStamp
= ev
->when
;
1334 event
.SetEventObject(this);
1336 GetEventHandler()->ProcessEvent(event
);
1338 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1341 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1343 // updatergn is always already clipped to our boundaries
1344 WindowRef window
= GetMacRootWindow() ;
1345 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1347 wxMacDrawingClientHelper
focus( this ) ;
1350 WindowRef window
= GetMacRootWindow() ;
1351 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1353 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1355 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1357 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1358 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1359 // either a non gray background color or a non control window
1362 wxWindow
* parent
= GetParent() ;
1365 if ( parent
->GetMacRootWindow() != window
)
1367 // we are in a different window on the mac system
1372 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1374 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1376 // if we have any other colours in the hierarchy
1377 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1380 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1381 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1383 ApplyThemeBackground (kThemeBackgroundTabPane
, &(**updatergn
).rgnBBox
, kThemeStateActive
,8,true);
1392 parent
= parent
->GetParent() ;
1396 // if there is nothing special -> use default
1397 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1402 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1404 SetClip( updatergn
) ;
1405 EraseRgn( updatergn
) ;
1410 m_updateRegion
= updatergn
;
1412 event
.m_timeStamp
= time
;
1413 event
.SetEventObject(this);
1415 GetEventHandler()->ProcessEvent(event
);
1417 RgnHandle childupdate
= NewRgn() ;
1419 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1421 wxWindow
*child
= (wxWindow
*)node
->Data();
1425 child
->GetClientSize( &width
, &height
) ;
1427 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+width
, child
->m_y
+ height
) ;
1428 SectRgn( childupdate
, m_updateRegion
.GetWXHRGN() , childupdate
) ;
1429 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1430 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1432 // because dialogs may also be children
1433 child
->MacRedraw( childupdate
, time
) ;
1436 DisposeRgn( childupdate
) ;
1437 // eventually a draw grow box here
1440 void wxWindow::MacUpdateImmediately()
1442 WindowRef window
= GetMacRootWindow() ;
1445 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1446 BeginUpdate( window
) ;
1450 if ( !EmptyRgn( window
->visRgn
) )
1453 win
->MacRedraw( window
->visRgn
, wxTheApp
->sm_lastMessageTime
) ;
1456 wxMacDrawingHelper help( win ) ;
1457 SetOrigin( 0 , 0 ) ;
1458 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1459 UMAUpdateControls( window , window->visRgn ) ;
1460 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1465 EndUpdate( window
) ;
1469 void wxWindow::MacUpdate( EventRecord
*ev
)
1471 WindowRef window
= (WindowRef
) ev
->message
;
1472 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1474 BeginUpdate( window
) ;
1477 // if windowshade gives incompatibility , take the follwing out
1479 if ( !EmptyRgn( window
->visRgn
) )
1482 MacRedraw( window
->visRgn
, ev
->when
) ;
1485 wxMacDrawingHelper help( this ) ;
1486 SetOrigin( 0 , 0 ) ;
1487 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1488 UMAUpdateControls( window , window->visRgn ) ;
1489 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1494 EndUpdate( window
) ;
1497 WindowRef
wxWindow::GetMacRootWindow() const
1499 WindowRef window
= NULL
;
1500 wxWindow
*iter
= (wxWindow
*)this ;
1504 if ( iter
->m_macWindowData
)
1505 return iter
->m_macWindowData
->m_macWindow
;
1507 iter
= iter
->GetParent() ;
1509 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1513 void wxWindow::MacCreateScrollBars( long style
)
1515 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1516 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1517 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1519 if ( style
& wxVSCROLL
)
1521 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, wxPoint(m_width
-MAC_SCROLLBAR_SIZE
, 0),
1522 wxSize(MAC_SCROLLBAR_SIZE
, m_height
- adjust
), wxVERTICAL
);
1523 // m_vScrollBar->PushEventHandler( this ) ;
1525 if ( style
& wxHSCROLL
)
1527 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, wxPoint(0 , m_height
-MAC_SCROLLBAR_SIZE
),
1528 wxSize( m_width
- adjust
, MAC_SCROLLBAR_SIZE
), wxHORIZONTAL
);
1529 // m_hScrollBar->PushEventHandler( this ) ;
1532 // because the create does not take into account the client area origin
1533 MacRepositionScrollBars() ; // we might have a real position shift
1536 void wxWindow::MacRepositionScrollBars()
1538 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1539 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1543 m_vScrollBar
->SetSize( m_width
-MAC_SCROLLBAR_SIZE
, 0, MAC_SCROLLBAR_SIZE
, m_height
- adjust
, wxSIZE_USE_EXISTING
);
1547 m_hScrollBar
->SetSize( 0 , m_height
-MAC_SCROLLBAR_SIZE
,m_width
- adjust
, MAC_SCROLLBAR_SIZE
, wxSIZE_USE_EXISTING
);
1551 void wxWindow::MacKeyDown( EventRecord
*ev
)
1558 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1560 if ( m_macWindowData
)
1561 return m_macWindowData
->m_macRootControl
;
1563 return GetParent()->MacGetContainerForEmbedding() ;
1566 void wxWindow::MacSuperChangedPosition()
1568 // only window-absolute structures have to be moved i.e. controls
1570 wxNode
*node
= GetChildren().First();
1573 wxWindow
*child
= (wxWindow
*)node
->Data();
1574 child
->MacSuperChangedPosition() ;
1575 node
= node
->Next();
1579 bool wxWindow::MacSetupFocusPort( )
1587 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1588 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1591 bool wxWindow::MacSetupFocusClientPort( )
1599 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1600 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1603 bool wxWindow::MacSetupDrawingPort( )
1611 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1612 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1615 bool wxWindow::MacSetupDrawingClientPort( )
1623 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1624 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1628 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1630 if ( window
== NULL
)
1636 ::GetPort(&currPort
);
1637 port
= UMAGetWindowPort( window
) ;
1638 if (currPort
!= port
)
1641 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1645 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1647 if ( window
== NULL
)
1652 ::GetPort(&currPort
);
1653 port
= UMAGetWindowPort( window
) ;
1654 if (currPort
!= port
)
1657 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1658 ::ClipRect(&clipRect
);
1661 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
1662 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
1663 ::BackPat( &qd
.white
) ;
1664 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1668 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1670 if ( m_macWindowData
)
1676 clipRect
->right
= m_width
;
1677 clipRect
->bottom
= m_height
;
1678 *window
= m_macWindowData
->m_macWindow
;
1683 wxASSERT( GetParent() != NULL
) ;
1684 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
1685 localOrigin
->h
+= m_x
;
1686 localOrigin
->v
+= m_y
;
1687 OffsetRect(clipRect
, -m_x
, -m_y
);
1692 myClip
.right
= m_width
;
1693 myClip
.bottom
= m_height
;
1694 SectRect(clipRect
, &myClip
, clipRect
);
1698 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1700 int width
, height
;
1701 GetClientSize( &width
, &height
) ;
1703 if ( m_macWindowData
)
1709 clipRect
->right
= m_width
;//width;
1710 clipRect
->bottom
= m_height
;// height;
1711 *window
= m_macWindowData
->m_macWindow
;
1716 wxASSERT( GetParent() != NULL
) ;
1718 GetParent()->MacGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
1720 localOrigin
->h
+= m_x
;
1721 localOrigin
->v
+= m_y
;
1722 OffsetRect(clipRect
, -m_x
, -m_y
);
1727 myClip
.right
= width
;
1728 myClip
.bottom
= height
;
1729 SectRect(clipRect
, &myClip
, clipRect
);
1733 wxMacFocusHelper::wxMacFocusHelper( wxWindow
* theWindow
)
1740 m_currentPort
= NULL
;
1741 GetPort( &m_formerPort
) ;
1745 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1746 m_currentPort
= UMAGetWindowPort( window
) ;
1747 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1752 wxMacFocusHelper::~wxMacFocusHelper()
1756 SetOrigin( 0 , 0 ) ;
1758 if ( m_formerPort
!= m_currentPort
)
1759 SetPort( m_formerPort
) ;
1762 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
1769 m_currentPort
= NULL
;
1771 GetPort( &m_formerPort
) ;
1774 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1775 m_currentPort
= UMAGetWindowPort( window
) ;
1776 if ( m_formerPort
!= m_currentPort
)
1777 SetPort( m_currentPort
) ;
1778 GetPenState( &m_savedPenState
) ;
1779 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1784 wxMacDrawingHelper::~wxMacDrawingHelper()
1788 SetPenState( &m_savedPenState
) ;
1789 SetOrigin( 0 , 0 ) ;
1790 ClipRect( &m_currentPort
->portRect
) ;
1793 if ( m_formerPort
!= m_currentPort
)
1794 SetPort( m_formerPort
) ;
1797 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow
* theWindow
)
1804 m_currentPort
= NULL
;
1806 GetPort( &m_formerPort
) ;
1810 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1811 m_currentPort
= UMAGetWindowPort( window
) ;
1812 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1817 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1821 SetOrigin( 0 , 0 ) ;
1823 if ( m_formerPort
!= m_currentPort
)
1824 SetPort( m_formerPort
) ;
1827 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
1834 m_currentPort
= NULL
;
1836 GetPort( &m_formerPort
) ;
1840 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1841 m_currentPort
= UMAGetWindowPort( window
) ;
1842 if ( m_formerPort
!= m_currentPort
)
1843 SetPort( m_currentPort
) ;
1844 GetPenState( &m_savedPenState
) ;
1845 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1850 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1854 SetPenState( &m_savedPenState
) ;
1855 SetOrigin( 0 , 0 ) ;
1856 ClipRect( &m_currentPort
->portRect
) ;
1859 if ( m_formerPort
!= m_currentPort
)
1860 SetPort( m_formerPort
) ;