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
844 int wxWindow::GetScrollPos(int orient
) const
846 if ( orient
== wxHORIZONTAL
)
849 return m_hScrollBar
->GetThumbPosition() ;
854 return m_vScrollBar
->GetThumbPosition() ;
859 // This now returns the whole range, not just the number
860 // of positions that we can scroll.
861 int wxWindow::GetScrollRange(int orient
) const
863 if ( orient
== wxHORIZONTAL
)
866 return m_hScrollBar
->GetRange() ;
871 return m_vScrollBar
->GetRange() ;
876 int wxWindow::GetScrollThumb(int orient
) const
878 if ( orient
== wxHORIZONTAL
)
881 return m_hScrollBar
->GetThumbSize() ;
886 return m_vScrollBar
->GetThumbSize() ;
891 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
893 if ( orient
== wxHORIZONTAL
)
896 m_hScrollBar
->SetThumbPosition( pos
) ;
901 m_vScrollBar
->SetThumbPosition( pos
) ;
905 // New function that will replace some of the above.
906 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
907 int range
, bool refresh
)
909 if ( orient
== wxHORIZONTAL
)
913 if ( range
== 0 || thumbVisible
>= range
)
915 if ( m_hScrollBar
->IsShown() )
916 m_hScrollBar
->Show(false) ;
920 if ( !m_hScrollBar
->IsShown() )
921 m_hScrollBar
->Show(true) ;
922 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
930 if ( range
== 0 || thumbVisible
>= range
)
932 if ( m_vScrollBar
->IsShown() )
933 m_vScrollBar
->Show(false) ;
937 if ( !m_vScrollBar
->IsShown() )
938 m_vScrollBar
->Show(true) ;
939 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
943 MacRepositionScrollBars() ;
946 // Does a physical scroll
947 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
949 wxMacDrawingClientHelper
focus( this ) ;
953 GetClientSize( &width
, &height
) ;
954 Rect scrollrect
= { 0 , 0 , height
, width
} ;
956 RgnHandle updateRgn
= NewRgn() ;
957 ClipRect( &scrollrect
) ;
960 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
961 SectRect( &scrollrect
, &r
, &scrollrect
) ;
963 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
964 InvalRgn( updateRgn
) ;
965 DisposeRgn( updateRgn
) ;
969 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
971 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
973 wxScrollWinEvent wevent
;
974 wevent
.SetPosition(event
.GetPosition());
975 wevent
.SetOrientation(event
.GetOrientation());
976 wevent
.m_eventObject
= this;
978 switch ( event
.m_eventType
)
980 case wxEVT_SCROLL_TOP
:
981 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
984 case wxEVT_SCROLL_BOTTOM
:
985 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
988 case wxEVT_SCROLL_LINEUP
:
989 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
992 case wxEVT_SCROLL_LINEDOWN
:
993 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
996 case wxEVT_SCROLL_PAGEUP
:
997 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1000 case wxEVT_SCROLL_PAGEDOWN
:
1001 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1004 case wxEVT_SCROLL_THUMBTRACK
:
1005 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1010 GetEventHandler()->ProcessEvent(wevent
);
1014 bool wxWindow::SetFont(const wxFont
& font
)
1016 if ( !wxWindowBase::SetFont(font
) )
1025 // Get the window with the focus
1026 wxWindow
*wxWindowBase::FindFocus()
1028 return gFocusWindow
;
1031 #if WXWIN_COMPATIBILITY
1032 // If nothing defined for this, try the parent.
1033 // E.g. we may be a button loaded from a resource, with no callback function
1035 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1037 if ( GetEventHandler()->ProcessEvent(event
) )
1040 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1042 #endif // WXWIN_COMPATIBILITY_2
1044 #if WXWIN_COMPATIBILITY
1045 wxObject
* wxWindow::GetChild(int number
) const
1047 // Return a pointer to the Nth object in the Panel
1048 wxNode
*node
= GetChildren().First();
1051 node
= node
->Next();
1054 wxObject
*obj
= (wxObject
*)node
->Data();
1060 #endif // WXWIN_COMPATIBILITY
1062 void wxWindow::Clear()
1064 if ( m_macWindowData
)
1066 wxMacDrawingClientHelper
helper ( this ) ;
1068 wxPoint origin
= GetClientAreaOrigin() ;
1069 GetClientSize( &w
, &h
) ;
1070 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1071 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1076 wxClientDC
dc(this);
1077 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1078 dc
.SetBackground(brush
);
1083 // Setup background and foreground colours correctly
1084 void wxWindow::SetupColours()
1087 SetBackgroundColour(GetParent()->GetBackgroundColour());
1090 void wxWindow::OnIdle(wxIdleEvent
& event
)
1093 // Check if we need to send a LEAVE event
1094 if (m_mouseInWindow)
1097 ::GetCursorPos(&pt);
1098 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1100 // Generate a LEAVE event
1101 m_mouseInWindow = FALSE;
1102 MSWOnMouseLeave(pt.x, pt.y, 0);
1107 // This calls the UI-update mechanism (querying windows for
1108 // menu/toolbar/control state information)
1112 // Raise the window to the top of the Z order
1113 void wxWindow::Raise()
1118 // Lower the window to the bottom of the Z order
1119 void wxWindow::Lower()
1124 void wxWindow::DoSetClientSize(int width
, int height
)
1126 if ( width
!= -1 || height
!= -1 )
1129 if ( width
!= -1 && m_vScrollBar
)
1130 width
+= MAC_SCROLLBAR_SIZE
;
1131 if ( height
!= -1 && m_vScrollBar
)
1132 height
+= MAC_SCROLLBAR_SIZE
;
1134 DoSetSize( -1 , -1 , width
, height
) ;
1139 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1141 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1143 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1144 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1147 WindowRef window
= GetMacRootWindow() ;
1149 wxPoint
newPoint( point
) ;
1154 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1156 wxWindow
*child
= (wxWindow
*)node
->Data();
1157 if ( child
->GetMacRootWindow() == window
)
1159 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1168 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1171 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1172 if ( ::FindWindow( pt
, &window
) == 3 )
1174 wxPoint
point( screenpoint
) ;
1175 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1176 win
->ScreenToClient( point
) ;
1177 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1182 extern int wxBusyCursorCount
;
1184 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1186 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1187 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1190 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1193 WindowRef window
= GetMacRootWindow() ;
1201 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1203 wxWindow
*child
= (wxWindow
*)node
->Data();
1204 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1206 if (child
->MacDispatchMouseEvent(event
))
1214 if ( wxBusyCursorCount
== 0 )
1216 m_cursor
.MacInstall() ;
1218 GetEventHandler()->ProcessEvent( event
) ;
1222 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1224 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1225 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1226 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1228 event
.m_leftDown
= isDown
&& !controlDown
;
1229 event
.m_middleDown
= FALSE
;
1230 event
.m_rightDown
= isDown
&& controlDown
;
1232 if ( ev
->what
== mouseDown
)
1235 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1237 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1239 else if ( ev
->what
== mouseUp
)
1242 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1244 event
.SetEventType(wxEVT_LEFT_UP
) ;
1248 event
.SetEventType(wxEVT_MOTION
) ;
1251 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1252 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1253 event
.m_altDown
= ev
->modifiers
& optionKey
;
1254 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1256 Point localwhere
= ev
->where
;
1259 ::GetPort( &port
) ;
1260 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1261 ::GlobalToLocal( &localwhere
) ;
1264 event
.m_x
= localwhere
.h
;
1265 event
.m_y
= localwhere
.v
;
1270 wxPoint origin = GetClientAreaOrigin() ;
1272 event.m_x += origin.x ;
1273 event.m_y += origin.y ;
1276 event
.m_timeStamp
= ev
->when
;
1277 event
.SetEventObject(this);
1278 if ( wxTheApp
->s_captureWindow
)
1282 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1285 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1286 if ( ev
->what
== mouseUp
)
1288 wxTheApp
->s_captureWindow
= NULL
;
1289 if ( wxBusyCursorCount
== 0 )
1291 m_cursor
.MacInstall() ;
1297 MacDispatchMouseEvent( event
) ;
1301 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1303 MacFireMouseEvent( ev
) ;
1306 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1308 WindowPtr frontWindow
;
1313 MacFireMouseEvent( ev
) ;
1319 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1321 WindowPtr frontWindow
;
1326 MacFireMouseEvent( ev
) ;
1331 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1333 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1334 event
.m_timeStamp
= ev
->when
;
1335 event
.SetEventObject(this);
1337 GetEventHandler()->ProcessEvent(event
);
1339 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1342 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1344 // updatergn is always already clipped to our boundaries
1345 WindowRef window
= GetMacRootWindow() ;
1346 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1348 wxMacDrawingClientHelper
focus( this ) ;
1351 WindowRef window
= GetMacRootWindow() ;
1352 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1354 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1356 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1358 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1359 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1360 // either a non gray background color or a non control window
1363 wxWindow
* parent
= GetParent() ;
1366 if ( parent
->GetMacRootWindow() != window
)
1368 // we are in a different window on the mac system
1373 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1375 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1377 // if we have any other colours in the hierarchy
1378 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1381 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1382 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1384 ApplyThemeBackground (kThemeBackgroundTabPane
, &(**updatergn
).rgnBBox
, kThemeStateActive
,8,true);
1393 parent
= parent
->GetParent() ;
1397 // if there is nothing special -> use default
1398 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1403 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1405 SetClip( updatergn
) ;
1406 EraseRgn( updatergn
) ;
1411 m_updateRegion
= updatergn
;
1413 event
.m_timeStamp
= time
;
1414 event
.SetEventObject(this);
1416 GetEventHandler()->ProcessEvent(event
);
1418 RgnHandle childupdate
= NewRgn() ;
1420 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1422 wxWindow
*child
= (wxWindow
*)node
->Data();
1426 child
->GetClientSize( &width
, &height
) ;
1428 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+width
, child
->m_y
+ height
) ;
1429 SectRgn( childupdate
, m_updateRegion
.GetWXHRGN() , childupdate
) ;
1430 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1431 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1433 // because dialogs may also be children
1434 child
->MacRedraw( childupdate
, time
) ;
1437 DisposeRgn( childupdate
) ;
1438 // eventually a draw grow box here
1441 void wxWindow::MacUpdateImmediately()
1443 WindowRef window
= GetMacRootWindow() ;
1446 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1447 BeginUpdate( window
) ;
1451 if ( !EmptyRgn( window
->visRgn
) )
1454 win
->MacRedraw( window
->visRgn
, wxTheApp
->sm_lastMessageTime
) ;
1457 wxMacDrawingHelper help( win ) ;
1458 SetOrigin( 0 , 0 ) ;
1459 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1460 UMAUpdateControls( window , window->visRgn ) ;
1461 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1466 EndUpdate( window
) ;
1470 void wxWindow::MacUpdate( EventRecord
*ev
)
1472 WindowRef window
= (WindowRef
) ev
->message
;
1473 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1475 BeginUpdate( window
) ;
1478 // if windowshade gives incompatibility , take the follwing out
1480 if ( !EmptyRgn( window
->visRgn
) )
1483 MacRedraw( window
->visRgn
, ev
->when
) ;
1486 wxMacDrawingHelper help( this ) ;
1487 SetOrigin( 0 , 0 ) ;
1488 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1489 UMAUpdateControls( window , window->visRgn ) ;
1490 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1495 EndUpdate( window
) ;
1498 WindowRef
wxWindow::GetMacRootWindow() const
1500 WindowRef window
= NULL
;
1501 wxWindow
*iter
= (wxWindow
*)this ;
1505 if ( iter
->m_macWindowData
)
1506 return iter
->m_macWindowData
->m_macWindow
;
1508 iter
= iter
->GetParent() ;
1510 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1514 void wxWindow::MacCreateScrollBars( long style
)
1516 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1517 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1518 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1520 if ( style
& wxVSCROLL
)
1522 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, wxPoint(m_width
-MAC_SCROLLBAR_SIZE
, 0),
1523 wxSize(MAC_SCROLLBAR_SIZE
, m_height
- adjust
), wxVERTICAL
);
1524 // m_vScrollBar->PushEventHandler( this ) ;
1526 if ( style
& wxHSCROLL
)
1528 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, wxPoint(0 , m_height
-MAC_SCROLLBAR_SIZE
),
1529 wxSize( m_width
- adjust
, MAC_SCROLLBAR_SIZE
), wxHORIZONTAL
);
1530 // m_hScrollBar->PushEventHandler( this ) ;
1533 // because the create does not take into account the client area origin
1534 MacRepositionScrollBars() ; // we might have a real position shift
1537 void wxWindow::MacRepositionScrollBars()
1539 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1540 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1544 m_vScrollBar
->SetSize( m_width
-MAC_SCROLLBAR_SIZE
, 0, MAC_SCROLLBAR_SIZE
, m_height
- adjust
, wxSIZE_USE_EXISTING
);
1548 m_hScrollBar
->SetSize( 0 , m_height
-MAC_SCROLLBAR_SIZE
,m_width
- adjust
, MAC_SCROLLBAR_SIZE
, wxSIZE_USE_EXISTING
);
1552 void wxWindow::MacKeyDown( EventRecord
*ev
)
1559 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1561 if ( m_macWindowData
)
1562 return m_macWindowData
->m_macRootControl
;
1564 return GetParent()->MacGetContainerForEmbedding() ;
1567 void wxWindow::MacSuperChangedPosition()
1569 // only window-absolute structures have to be moved i.e. controls
1571 wxNode
*node
= GetChildren().First();
1574 wxWindow
*child
= (wxWindow
*)node
->Data();
1575 child
->MacSuperChangedPosition() ;
1576 node
= node
->Next();
1580 bool wxWindow::MacSetupFocusPort( )
1588 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1589 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1592 bool wxWindow::MacSetupFocusClientPort( )
1600 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1601 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1604 bool wxWindow::MacSetupDrawingPort( )
1612 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1613 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1616 bool wxWindow::MacSetupDrawingClientPort( )
1624 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1625 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1629 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1631 if ( window
== NULL
)
1637 ::GetPort(&currPort
);
1638 port
= UMAGetWindowPort( window
) ;
1639 if (currPort
!= port
)
1642 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1646 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1648 if ( window
== NULL
)
1653 ::GetPort(&currPort
);
1654 port
= UMAGetWindowPort( window
) ;
1655 if (currPort
!= port
)
1658 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1659 ::ClipRect(&clipRect
);
1662 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
1663 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
1664 ::BackPat( &qd
.white
) ;
1665 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1669 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1671 if ( m_macWindowData
)
1677 clipRect
->right
= m_width
;
1678 clipRect
->bottom
= m_height
;
1679 *window
= m_macWindowData
->m_macWindow
;
1684 wxASSERT( GetParent() != NULL
) ;
1685 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
1686 localOrigin
->h
+= m_x
;
1687 localOrigin
->v
+= m_y
;
1688 OffsetRect(clipRect
, -m_x
, -m_y
);
1693 myClip
.right
= m_width
;
1694 myClip
.bottom
= m_height
;
1695 SectRect(clipRect
, &myClip
, clipRect
);
1699 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1701 int width
, height
;
1702 GetClientSize( &width
, &height
) ;
1704 if ( m_macWindowData
)
1710 clipRect
->right
= m_width
;//width;
1711 clipRect
->bottom
= m_height
;// height;
1712 *window
= m_macWindowData
->m_macWindow
;
1717 wxASSERT( GetParent() != NULL
) ;
1719 GetParent()->MacGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
1721 localOrigin
->h
+= m_x
;
1722 localOrigin
->v
+= m_y
;
1723 OffsetRect(clipRect
, -m_x
, -m_y
);
1728 myClip
.right
= width
;
1729 myClip
.bottom
= height
;
1730 SectRect(clipRect
, &myClip
, clipRect
);
1734 wxMacFocusHelper::wxMacFocusHelper( wxWindow
* theWindow
)
1741 m_currentPort
= NULL
;
1742 GetPort( &m_formerPort
) ;
1746 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1747 m_currentPort
= UMAGetWindowPort( window
) ;
1748 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1753 wxMacFocusHelper::~wxMacFocusHelper()
1757 SetOrigin( 0 , 0 ) ;
1759 if ( m_formerPort
!= m_currentPort
)
1760 SetPort( m_formerPort
) ;
1763 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
1770 m_currentPort
= NULL
;
1772 GetPort( &m_formerPort
) ;
1775 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1776 m_currentPort
= UMAGetWindowPort( window
) ;
1777 if ( m_formerPort
!= m_currentPort
)
1778 SetPort( m_currentPort
) ;
1779 GetPenState( &m_savedPenState
) ;
1780 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1785 wxMacDrawingHelper::~wxMacDrawingHelper()
1789 SetPenState( &m_savedPenState
) ;
1790 SetOrigin( 0 , 0 ) ;
1791 ClipRect( &m_currentPort
->portRect
) ;
1794 if ( m_formerPort
!= m_currentPort
)
1795 SetPort( m_formerPort
) ;
1798 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow
* theWindow
)
1805 m_currentPort
= NULL
;
1807 GetPort( &m_formerPort
) ;
1811 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1812 m_currentPort
= UMAGetWindowPort( window
) ;
1813 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1818 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1822 SetOrigin( 0 , 0 ) ;
1824 if ( m_formerPort
!= m_currentPort
)
1825 SetPort( m_formerPort
) ;
1828 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
1835 m_currentPort
= NULL
;
1837 GetPort( &m_formerPort
) ;
1841 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1842 m_currentPort
= UMAGetWindowPort( window
) ;
1843 if ( m_formerPort
!= m_currentPort
)
1844 SetPort( m_currentPort
) ;
1845 GetPenState( &m_savedPenState
) ;
1846 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1851 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1855 SetPenState( &m_savedPenState
) ;
1856 SetOrigin( 0 , 0 ) ;
1857 ClipRect( &m_currentPort
->portRect
) ;
1860 if ( m_formerPort
!= m_currentPort
)
1861 SetPort( m_formerPort
) ;