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
)
67 // ===========================================================================
69 // ===========================================================================
71 // ---------------------------------------------------------------------------
72 // wxWindow utility functions
73 // ---------------------------------------------------------------------------
75 // Find an item given the Macintosh Window Reference
77 wxList
*wxWinMacWindowList
= NULL
;
78 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
80 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
83 return (wxWindow
*)node
->Data();
86 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
88 // adding NULL WindowRef is (first) surely a result of an error and
89 // (secondly) breaks menu command processing
90 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
92 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
93 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
96 void wxRemoveMacWindowAssociation(wxWindow
*win
)
98 wxWinMacWindowList
->DeleteObject(win
);
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 void wxWindow::Init()
111 m_doubleClickAllowed
= 0;
112 m_winCaptured
= FALSE
;
114 m_isBeingDeleted
= FALSE
;
117 m_mouseInWindow
= FALSE
;
121 m_backgroundTransparent
= FALSE
;
123 // as all windows are created with WS_VISIBLE style...
126 m_macWindowData
= NULL
;
133 m_hScrollBar
= NULL
;
134 m_vScrollBar
= NULL
;
136 #if wxUSE_DRAG_AND_DROP
137 m_pDropTarget
= NULL
;
142 wxWindow::~wxWindow()
144 m_isBeingDeleted
= TRUE
;
146 if ( s_lastMouseWindow
== this )
148 s_lastMouseWindow
= NULL
;
151 if ( gFocusWindow
== this )
153 gFocusWindow
= NULL
;
157 m_parent
->RemoveChild(this);
161 if ( m_macWindowData
)
163 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
164 delete m_macWindowData
;
165 wxRemoveMacWindowAssociation( this ) ;
170 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
174 const wxString
& name
)
176 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
178 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
181 parent
->AddChild(this);
185 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
186 m_width
= WidthDefault( size
.x
);
187 m_height
= HeightDefault( size
.y
) ;
189 MacCreateScrollBars( style
) ;
194 void wxWindow::SetFocus()
196 if ( AcceptsFocus() )
200 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
201 if ( control
&& control
->GetMacControl() )
203 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
205 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
206 event
.SetEventObject(gFocusWindow
);
207 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
209 gFocusWindow
= this ;
211 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
212 if ( control
&& control
->GetMacControl() )
214 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
217 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
218 event
.SetEventObject(this);
219 GetEventHandler()->ProcessEvent(event
) ;
224 bool wxWindow::Enable(bool enable
)
226 if ( !wxWindowBase::Enable(enable
) )
229 HWND hWnd = GetHwnd();
231 ::EnableWindow(hWnd, (BOOL)enable);
234 wxWindowList::Node
*node
= GetChildren().GetFirst();
237 wxWindow
*child
= node
->GetData();
238 child
->Enable(enable
);
240 node
= node
->GetNext();
246 void wxWindow::CaptureMouse()
248 wxTheApp
->s_captureWindow
= this ;
251 void wxWindow::ReleaseMouse()
253 wxTheApp
->s_captureWindow
= NULL
;
256 #if wxUSE_DRAG_AND_DROP
258 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
260 if ( m_pDropTarget
!= 0 ) {
261 delete m_pDropTarget
;
264 m_pDropTarget
= pDropTarget
;
265 if ( m_pDropTarget
!= 0 )
273 // Old style file-manager drag&drop
274 void wxWindow::DragAcceptFiles(bool accept
)
280 void wxWindow::DoGetSize(int *x
, int *y
) const
286 void wxWindow::DoGetPosition(int *x
, int *y
) const
292 wxPoint
pt(GetParent()->GetClientAreaOrigin());
298 void wxWindow::DoScreenToClient(int *x
, int *y
) const
300 WindowRef window
= GetMacRootWindow() ;
308 ::SetPort( UMAGetWindowPort( window
) ) ;
309 ::GlobalToLocal( &localwhere
) ;
315 MacRootWindowToClient( x
, y
) ;
318 void wxWindow::DoClientToScreen(int *x
, int *y
) const
320 WindowRef window
= GetMacRootWindow() ;
322 MacClientToRootWindow( x
, y
) ;
330 ::SetPort( UMAGetWindowPort( window
) ) ;
331 ::LocalToGlobal( &localwhere
) ;
337 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
339 if ( m_macWindowData
)
346 GetParent()->MacClientToRootWindow( x
, y
) ;
350 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
352 if ( m_macWindowData
)
359 GetParent()->MacRootWindowToClient( x
, y
) ;
363 bool wxWindow::SetCursor(const wxCursor
& cursor
)
365 if ( !wxWindowBase::SetCursor(cursor
) )
371 wxASSERT_MSG( m_cursor
.Ok(),
372 wxT("cursor must be valid after call to the base version"));
378 // Change the cursor NOW if we're within the correct window
380 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
382 if ( mouseWin
== this && !wxIsBusy() )
384 cursor
.MacInstall() ;
392 // Get size *available for subwindows* i.e. excluding menu bar etc.
393 void wxWindow::DoGetClientSize(int *x
, int *y
) const
398 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
399 (*x
) -= MAC_SCROLLBAR_SIZE
;
400 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
401 (*y
) -= MAC_SCROLLBAR_SIZE
;
404 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
408 int former_w
= m_width
;
409 int former_h
= m_height
;
411 int currentX
, currentY
;
412 GetPosition(¤tX
, ¤tY
);
413 int currentW
,currentH
;
414 GetSize(¤tW
, ¤tH
);
416 int actualWidth
= width
;
417 int actualHeight
= height
;
420 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
422 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
425 actualWidth
= currentW
;
427 actualHeight
= currentH
;
429 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
431 MacRepositionScrollBars() ; // we might have a real position shift
435 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
438 bool doMove
= false ;
439 bool doResize
= false ;
441 if ( actualX
!= former_x
|| actualY
!= former_y
)
445 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
450 if ( doMove
|| doResize
)
452 if ( m_macWindowData
)
457 // erase former position
459 wxMacDrawingClientHelper
focus( this ) ;
462 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
463 InvalRect( &clientrect
) ;
469 m_width
= actualWidth
;
470 m_height
= actualHeight
;
471 if ( m_macWindowData
)
474 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
477 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
479 // the OS takes care of invalidating and erasing
481 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
483 wxFrame
* frame
= (wxFrame
*) this ;
484 frame
->PositionStatusBar();
485 frame
->PositionToolBar();
490 // erase new position
492 wxMacDrawingClientHelper
focus( this ) ;
495 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
496 InvalRect( &clientrect
) ;
500 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
502 MacRepositionScrollBars() ;
505 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
506 event
.SetEventObject(this);
507 GetEventHandler()->ProcessEvent(event
) ;
511 MacRepositionScrollBars() ;
512 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
513 event
.SetEventObject(this);
514 GetEventHandler()->ProcessEvent(event
);
518 // For implementation purposes - sometimes decorations make the client area
521 wxPoint
wxWindow::GetClientAreaOrigin() const
523 return wxPoint(0, 0);
526 // Makes an adjustment to the window position (for example, a frame that has
527 // a toolbar that it manages itself).
528 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
530 if( !m_macWindowData
)
532 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
534 wxPoint
pt(GetParent()->GetClientAreaOrigin());
535 x
+= pt
.x
; y
+= pt
.y
;
540 void wxWindow::SetTitle(const wxString
& title
)
546 if( wxApp::s_macDefaultEncodingIsPC
)
547 label
= wxMacMakeMacStringFromPC( title
) ;
551 if ( m_macWindowData
)
552 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
555 wxString
wxWindow::GetTitle() const
560 bool wxWindow::Show(bool show
)
562 if ( !wxWindowBase::Show(show
) )
565 if ( m_macWindowData
)
569 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
570 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
571 // no need to generate events here, they will get them triggered by macos
572 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
573 event
.SetEventObject(this);
574 GetEventHandler()->ProcessEvent(event
);
578 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
586 int wxWindow::GetCharHeight() const
588 wxClientDC
dc ( (wxWindow
*)this ) ;
589 return dc
.GetCharHeight() ;
592 int wxWindow::GetCharWidth() const
594 wxClientDC
dc ( (wxWindow
*)this ) ;
595 return dc
.GetCharWidth() ;
598 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
599 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
601 const wxFont
*fontToUse
= theFont
;
610 *descent = tm.tmDescent;
611 if ( externalLeading )
612 *externalLeading = tm.tmExternalLeading;
617 void wxWindow::MacEraseBackground( Rect
*rect
)
619 WindowRef window
= GetMacRootWindow() ;
620 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
622 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
624 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
626 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
627 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
628 // either a non gray background color or a non control window
630 wxWindow
* parent
= GetParent() ;
633 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
635 // if we have any other colours in the hierarchy
636 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
639 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
641 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
642 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
644 ApplyThemeBackground (kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
650 // we have arrived at a non control item
654 parent
= parent
->GetParent() ;
658 // if there is nothing special -> use default
659 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
664 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
669 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
671 wxWindow
*child
= (wxWindow
*)node
->Data();
675 // child->GetClientSize( &width , &height ) ;
677 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
678 SectRect( &clientrect
, rect
, &clientrect
) ;
680 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
681 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
683 wxMacDrawingClientHelper
focus( this ) ;
686 child
->MacEraseBackground( &clientrect
) ;
692 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
694 wxMacDrawingClientHelper
focus( this ) ;
698 GetClientSize( &width
, &height
) ;
699 Rect clientrect
= { 0 , 0 , height
, width
} ;
700 ClipRect( &clientrect
) ;
704 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
705 SectRect( &clientrect
, &r
, &clientrect
) ;
707 InvalRect( &clientrect
) ;
711 MacEraseBackground( &clientrect ) ;
717 // Responds to colour changes: passes event on to children.
718 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
720 wxNode
*node
= GetChildren().First();
723 // Only propagate to non-top-level windows
724 wxWindow
*win
= (wxWindow
*)node
->Data();
725 if ( win
->GetParent() )
727 wxSysColourChangedEvent event2
;
728 event
.m_eventObject
= win
;
729 win
->GetEventHandler()->ProcessEvent(event2
);
736 #if wxUSE_CARET && WXWIN_COMPATIBILITY
737 // ---------------------------------------------------------------------------
738 // Caret manipulation
739 // ---------------------------------------------------------------------------
741 void wxWindow::CreateCaret(int w
, int h
)
743 SetCaret(new wxCaret(this, w
, h
));
746 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
748 wxFAIL_MSG("not implemented");
751 void wxWindow::ShowCaret(bool show
)
753 wxCHECK_RET( m_caret
, "no caret to show" );
758 void wxWindow::DestroyCaret()
763 void wxWindow::SetCaretPos(int x
, int y
)
765 wxCHECK_RET( m_caret
, "no caret to move" );
770 void wxWindow::GetCaretPos(int *x
, int *y
) const
772 wxCHECK_RET( m_caret
, "no caret to get position of" );
774 m_caret
->GetPosition(x
, y
);
776 #endif // wxUSE_CARET
778 wxWindow
*wxGetActiveWindow()
780 // actually this is a windows-only concept
784 // Coordinates relative to the window
785 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
787 // We really dont move the mouse programmatically under mac
790 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
792 // TODO : probably we would adopt the EraseEvent structure
796 int wxWindow::GetScrollPos(int orient
) const
798 if ( orient
== wxHORIZONTAL
)
801 return m_hScrollBar
->GetThumbPosition() ;
806 return m_vScrollBar
->GetThumbPosition() ;
811 // This now returns the whole range, not just the number
812 // of positions that we can scroll.
813 int wxWindow::GetScrollRange(int orient
) const
815 if ( orient
== wxHORIZONTAL
)
818 return m_hScrollBar
->GetRange() ;
823 return m_vScrollBar
->GetRange() ;
828 int wxWindow::GetScrollThumb(int orient
) const
830 if ( orient
== wxHORIZONTAL
)
833 return m_hScrollBar
->GetThumbSize() ;
838 return m_vScrollBar
->GetThumbSize() ;
843 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
845 if ( orient
== wxHORIZONTAL
)
848 m_hScrollBar
->SetThumbPosition( pos
) ;
853 m_vScrollBar
->SetThumbPosition( pos
) ;
857 // New function that will replace some of the above.
858 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
859 int range
, bool refresh
)
861 if ( orient
== wxHORIZONTAL
)
865 if ( range
== 0 || thumbVisible
>= range
)
867 if ( m_hScrollBar
->IsShown() )
868 m_hScrollBar
->Show(false) ;
872 if ( !m_hScrollBar
->IsShown() )
873 m_hScrollBar
->Show(true) ;
874 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
882 if ( range
== 0 || thumbVisible
>= range
)
884 if ( m_vScrollBar
->IsShown() )
885 m_vScrollBar
->Show(false) ;
889 if ( !m_vScrollBar
->IsShown() )
890 m_vScrollBar
->Show(true) ;
891 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
895 MacRepositionScrollBars() ;
898 // Does a physical scroll
899 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
901 wxMacDrawingClientHelper
focus( this ) ;
905 GetClientSize( &width
, &height
) ;
906 Rect scrollrect
= { 0 , 0 , height
, width
} ;
908 RgnHandle updateRgn
= NewRgn() ;
909 ClipRect( &scrollrect
) ;
912 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
913 SectRect( &scrollrect
, &r
, &scrollrect
) ;
915 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
916 InvalRgn( updateRgn
) ;
917 DisposeRgn( updateRgn
) ;
921 bool wxWindow::SetFont(const wxFont
& font
)
923 if ( !wxWindowBase::SetFont(font
) )
932 // Get the window with the focus
933 wxWindow
*wxWindowBase::FindFocus()
935 return gFocusWindow
;
938 #if WXWIN_COMPATIBILITY
939 // If nothing defined for this, try the parent.
940 // E.g. we may be a button loaded from a resource, with no callback function
942 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
944 if ( GetEventHandler()->ProcessEvent(event
) )
947 m_parent
->GetEventHandler()->OnCommand(win
, event
);
949 #endif // WXWIN_COMPATIBILITY_2
951 #if WXWIN_COMPATIBILITY
952 wxObject
* wxWindow::GetChild(int number
) const
954 // Return a pointer to the Nth object in the Panel
955 wxNode
*node
= GetChildren().First();
961 wxObject
*obj
= (wxObject
*)node
->Data();
967 #endif // WXWIN_COMPATIBILITY
969 void wxWindow::Clear()
971 if ( m_macWindowData
)
973 wxMacDrawingClientHelper
helper ( this ) ;
975 wxPoint origin
= GetClientAreaOrigin() ;
976 GetClientSize( &w
, &h
) ;
977 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
978 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
984 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
985 dc
.SetBackground(brush
);
990 // Setup background and foreground colours correctly
991 void wxWindow::SetupColours()
994 SetBackgroundColour(GetParent()->GetBackgroundColour());
997 void wxWindow::OnIdle(wxIdleEvent
& event
)
1000 // Check if we need to send a LEAVE event
1001 if (m_mouseInWindow)
1004 ::GetCursorPos(&pt);
1005 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1007 // Generate a LEAVE event
1008 m_mouseInWindow = FALSE;
1009 MSWOnMouseLeave(pt.x, pt.y, 0);
1014 // This calls the UI-update mechanism (querying windows for
1015 // menu/toolbar/control state information)
1019 // Raise the window to the top of the Z order
1020 void wxWindow::Raise()
1025 // Lower the window to the bottom of the Z order
1026 void wxWindow::Lower()
1031 void wxWindow::DoSetClientSize(int width
, int height
)
1033 if ( width
!= -1 || height
!= -1 )
1036 if ( width
!= -1 && m_vScrollBar
)
1037 width
+= MAC_SCROLLBAR_SIZE
;
1038 if ( height
!= -1 && m_vScrollBar
)
1039 height
+= MAC_SCROLLBAR_SIZE
;
1041 DoSetSize( -1 , -1 , width
, height
) ;
1046 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1048 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1050 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1051 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1054 WindowRef window
= GetMacRootWindow() ;
1056 wxPoint
newPoint( point
) ;
1061 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1063 wxWindow
*child
= (wxWindow
*)node
->Data();
1064 if ( child
->GetMacRootWindow() == window
)
1066 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1075 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1078 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1079 if ( ::FindWindow( pt
, &window
) == 3 )
1081 wxPoint
point( screenpoint
) ;
1082 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1083 win
->ScreenToClient( point
) ;
1084 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1089 extern int wxBusyCursorCount
;
1091 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1093 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1094 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1097 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1100 WindowRef window
= GetMacRootWindow() ;
1108 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1110 wxWindow
*child
= (wxWindow
*)node
->Data();
1111 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1113 if (child
->MacDispatchMouseEvent(event
))
1121 if ( wxBusyCursorCount
== 0 )
1123 m_cursor
.MacInstall() ;
1125 GetEventHandler()->ProcessEvent( event
) ;
1129 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1131 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1132 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1133 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1135 event
.m_leftDown
= isDown
&& !controlDown
;
1136 event
.m_middleDown
= FALSE
;
1137 event
.m_rightDown
= isDown
&& controlDown
;
1139 if ( ev
->what
== mouseDown
)
1142 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1144 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1146 else if ( ev
->what
== mouseUp
)
1149 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1151 event
.SetEventType(wxEVT_LEFT_UP
) ;
1155 event
.SetEventType(wxEVT_MOTION
) ;
1158 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1159 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1160 event
.m_altDown
= ev
->modifiers
& optionKey
;
1161 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1163 Point localwhere
= ev
->where
;
1166 ::GetPort( &port
) ;
1167 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1168 ::GlobalToLocal( &localwhere
) ;
1171 event
.m_x
= localwhere
.h
;
1172 event
.m_y
= localwhere
.v
;
1177 wxPoint origin = GetClientAreaOrigin() ;
1179 event.m_x += origin.x ;
1180 event.m_y += origin.y ;
1183 event
.m_timeStamp
= ev
->when
;
1184 event
.SetEventObject(this);
1185 if ( wxTheApp
->s_captureWindow
)
1189 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1192 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1193 if ( ev
->what
== mouseUp
)
1195 wxTheApp
->s_captureWindow
= NULL
;
1196 if ( wxBusyCursorCount
== 0 )
1198 m_cursor
.MacInstall() ;
1204 MacDispatchMouseEvent( event
) ;
1208 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1210 MacFireMouseEvent( ev
) ;
1213 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1215 WindowPtr frontWindow
;
1220 MacFireMouseEvent( ev
) ;
1226 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1228 WindowPtr frontWindow
;
1233 MacFireMouseEvent( ev
) ;
1238 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1240 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1241 event
.m_timeStamp
= ev
->when
;
1242 event
.SetEventObject(this);
1244 GetEventHandler()->ProcessEvent(event
);
1246 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1249 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1251 // updatergn is always already clipped to our boundaries
1252 WindowRef window
= GetMacRootWindow() ;
1253 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1255 wxMacDrawingClientHelper
focus( this ) ;
1258 WindowRef window
= GetMacRootWindow() ;
1259 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1261 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1263 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1265 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1266 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1267 // either a non gray background color or a non control window
1270 wxWindow
* parent
= GetParent() ;
1273 if ( parent
->GetMacRootWindow() != window
)
1275 // we are in a different window on the mac system
1280 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1282 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1284 // if we have any other colours in the hierarchy
1285 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1288 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1289 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1291 ApplyThemeBackground (kThemeBackgroundTabPane
, &(**updatergn
).rgnBBox
, kThemeStateActive
,8,true);
1300 parent
= parent
->GetParent() ;
1304 // if there is nothing special -> use default
1305 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1310 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1312 SetClip( updatergn
) ;
1313 EraseRgn( updatergn
) ;
1318 m_updateRegion
= updatergn
;
1320 event
.m_timeStamp
= time
;
1321 event
.SetEventObject(this);
1323 GetEventHandler()->ProcessEvent(event
);
1325 RgnHandle childupdate
= NewRgn() ;
1327 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1329 wxWindow
*child
= (wxWindow
*)node
->Data();
1333 child
->GetClientSize( &width
, &height
) ;
1335 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+width
, child
->m_y
+ height
) ;
1336 SectRgn( childupdate
, m_updateRegion
.GetWXHRGN() , childupdate
) ;
1337 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1338 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1340 // because dialogs may also be children
1341 child
->MacRedraw( childupdate
, time
) ;
1344 DisposeRgn( childupdate
) ;
1345 // eventually a draw grow box here
1348 void wxWindow::MacUpdateImmediately()
1350 WindowRef window
= GetMacRootWindow() ;
1353 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1354 BeginUpdate( window
) ;
1358 if ( !EmptyRgn( window
->visRgn
) )
1361 win
->MacRedraw( window
->visRgn
, wxTheApp
->sm_lastMessageTime
) ;
1364 wxMacDrawingHelper help( win ) ;
1365 SetOrigin( 0 , 0 ) ;
1366 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1367 UMAUpdateControls( window , window->visRgn ) ;
1368 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1373 EndUpdate( window
) ;
1377 void wxWindow::MacUpdate( EventRecord
*ev
)
1379 WindowRef window
= (WindowRef
) ev
->message
;
1380 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1382 BeginUpdate( window
) ;
1385 // if windowshade gives incompatibility , take the follwing out
1387 if ( !EmptyRgn( window
->visRgn
) )
1390 MacRedraw( window
->visRgn
, ev
->when
) ;
1393 wxMacDrawingHelper help( this ) ;
1394 SetOrigin( 0 , 0 ) ;
1395 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1396 UMAUpdateControls( window , window->visRgn ) ;
1397 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1402 EndUpdate( window
) ;
1405 WindowRef
wxWindow::GetMacRootWindow() const
1407 WindowRef window
= NULL
;
1408 wxWindow
*iter
= (wxWindow
*)this ;
1412 if ( iter
->m_macWindowData
)
1413 return iter
->m_macWindowData
->m_macWindow
;
1415 iter
= iter
->GetParent() ;
1417 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1421 void wxWindow::MacCreateScrollBars( long style
)
1423 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1424 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1425 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1427 if ( style
& wxVSCROLL
)
1429 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, wxPoint(m_width
-MAC_SCROLLBAR_SIZE
, 0),
1430 wxSize(MAC_SCROLLBAR_SIZE
, m_height
- adjust
), wxVERTICAL
);
1432 if ( style
& wxHSCROLL
)
1434 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, wxPoint(0 , m_height
-MAC_SCROLLBAR_SIZE
),
1435 wxSize( m_width
- adjust
, MAC_SCROLLBAR_SIZE
), wxHORIZONTAL
);
1437 // because the create does not take into account the client area origin
1438 MacRepositionScrollBars() ; // we might have a real position shift
1441 void wxWindow::MacRepositionScrollBars()
1443 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1444 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1448 m_vScrollBar
->SetSize( m_width
-MAC_SCROLLBAR_SIZE
, 0, MAC_SCROLLBAR_SIZE
, m_height
- adjust
, wxSIZE_USE_EXISTING
);
1452 m_hScrollBar
->SetSize( 0 , m_height
-MAC_SCROLLBAR_SIZE
,m_width
- adjust
, MAC_SCROLLBAR_SIZE
, wxSIZE_USE_EXISTING
);
1456 void wxWindow::MacKeyDown( EventRecord
*ev
)
1463 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1465 if ( m_macWindowData
)
1466 return m_macWindowData
->m_macRootControl
;
1468 return GetParent()->MacGetContainerForEmbedding() ;
1471 void wxWindow::MacSuperChangedPosition()
1473 // only window-absolute structures have to be moved i.e. controls
1475 wxNode
*node
= GetChildren().First();
1478 wxWindow
*child
= (wxWindow
*)node
->Data();
1479 child
->MacSuperChangedPosition() ;
1480 node
= node
->Next();
1484 bool wxWindow::MacSetupFocusPort( )
1492 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1493 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1496 bool wxWindow::MacSetupFocusClientPort( )
1504 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1505 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1508 bool wxWindow::MacSetupDrawingPort( )
1516 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1517 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1520 bool wxWindow::MacSetupDrawingClientPort( )
1528 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1529 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1533 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1535 if ( window
== NULL
)
1541 ::GetPort(&currPort
);
1542 port
= UMAGetWindowPort( window
) ;
1543 if (currPort
!= port
)
1546 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1550 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1552 if ( window
== NULL
)
1557 ::GetPort(&currPort
);
1558 port
= UMAGetWindowPort( window
) ;
1559 if (currPort
!= port
)
1562 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1563 ::ClipRect(&clipRect
);
1566 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
1567 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
1568 ::BackPat( &qd
.white
) ;
1569 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1573 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1575 if ( m_macWindowData
)
1581 clipRect
->right
= m_width
;
1582 clipRect
->bottom
= m_height
;
1583 *window
= m_macWindowData
->m_macWindow
;
1588 wxASSERT( GetParent() != NULL
) ;
1589 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
1590 localOrigin
->h
+= m_x
;
1591 localOrigin
->v
+= m_y
;
1592 OffsetRect(clipRect
, -m_x
, -m_y
);
1597 myClip
.right
= m_width
;
1598 myClip
.bottom
= m_height
;
1599 SectRect(clipRect
, &myClip
, clipRect
);
1603 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1605 int width
, height
;
1606 GetClientSize( &width
, &height
) ;
1608 if ( m_macWindowData
)
1614 clipRect
->right
= m_width
;//width;
1615 clipRect
->bottom
= m_height
;// height;
1616 *window
= m_macWindowData
->m_macWindow
;
1621 wxASSERT( GetParent() != NULL
) ;
1623 GetParent()->MacGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
1625 localOrigin
->h
+= m_x
;
1626 localOrigin
->v
+= m_y
;
1627 OffsetRect(clipRect
, -m_x
, -m_y
);
1632 myClip
.right
= width
;
1633 myClip
.bottom
= height
;
1634 SectRect(clipRect
, &myClip
, clipRect
);
1638 wxMacFocusHelper::wxMacFocusHelper( wxWindow
* theWindow
)
1645 m_currentPort
= NULL
;
1646 GetPort( &m_formerPort
) ;
1650 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1651 m_currentPort
= UMAGetWindowPort( window
) ;
1652 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1657 wxMacFocusHelper::~wxMacFocusHelper()
1661 SetOrigin( 0 , 0 ) ;
1663 if ( m_formerPort
!= m_currentPort
)
1664 SetPort( m_formerPort
) ;
1667 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
1674 m_currentPort
= NULL
;
1676 GetPort( &m_formerPort
) ;
1679 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1680 m_currentPort
= UMAGetWindowPort( window
) ;
1681 if ( m_formerPort
!= m_currentPort
)
1682 SetPort( m_currentPort
) ;
1683 GetPenState( &m_savedPenState
) ;
1684 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1689 wxMacDrawingHelper::~wxMacDrawingHelper()
1693 SetPenState( &m_savedPenState
) ;
1694 SetOrigin( 0 , 0 ) ;
1695 ClipRect( &m_currentPort
->portRect
) ;
1698 if ( m_formerPort
!= m_currentPort
)
1699 SetPort( m_formerPort
) ;
1702 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow
* theWindow
)
1709 m_currentPort
= NULL
;
1711 GetPort( &m_formerPort
) ;
1715 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1716 m_currentPort
= UMAGetWindowPort( window
) ;
1717 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1722 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1726 SetOrigin( 0 , 0 ) ;
1728 if ( m_formerPort
!= m_currentPort
)
1729 SetPort( m_formerPort
) ;
1732 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
1739 m_currentPort
= NULL
;
1741 GetPort( &m_formerPort
) ;
1745 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1746 m_currentPort
= UMAGetWindowPort( window
) ;
1747 if ( m_formerPort
!= m_currentPort
)
1748 SetPort( m_currentPort
) ;
1749 GetPenState( &m_savedPenState
) ;
1750 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1755 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1759 SetPenState( &m_savedPenState
) ;
1760 SetOrigin( 0 , 0 ) ;
1761 ClipRect( &m_currentPort
->portRect
) ;
1764 if ( m_formerPort
!= m_currentPort
)
1765 SetPort( m_formerPort
) ;
1768 // ----------------------------------------------------------------------------
1769 // list classes implementation
1770 // ----------------------------------------------------------------------------
1772 void wxWindowListNode::DeleteData()
1774 delete (wxWindow
*)GetData();