1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
44 #define wxWINDOW_HSCROLL 5998
45 #define wxWINDOW_VSCROLL 5997
46 #define MAC_SCROLLBAR_SIZE 16
48 #include <wx/mac/uma.h>
50 #if wxUSE_DRAG_AND_DROP
56 extern wxList wxPendingDelete
;
57 wxWindowMac
* gFocusWindow
= NULL
;
59 #if !USE_SHARED_LIBRARY
60 IMPLEMENT_DYNAMIC_CLASS(wxWindowMac
, wxEvtHandler
)
61 BEGIN_EVENT_TABLE(wxWindowMac
, wxEvtHandler
)
62 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
63 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
64 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
65 EVT_IDLE(wxWindowMac::OnIdle
)
66 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
73 // ===========================================================================
75 // ===========================================================================
77 // ---------------------------------------------------------------------------
78 // wxWindowMac utility functions
79 // ---------------------------------------------------------------------------
81 // Find an item given the Macintosh Window Reference
83 wxList
*wxWinMacWindowList
= NULL
;
84 wxWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
86 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
89 return (wxWindowMac
*)node
->Data();
92 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindowMac
*win
)
94 // adding NULL WindowRef is (first) surely a result of an error and
95 // (secondly) breaks menu command processing
96 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
98 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
99 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
102 void wxRemoveMacWindowAssociation(wxWindowMac
*win
)
104 wxWinMacWindowList
->DeleteObject(win
);
107 // ----------------------------------------------------------------------------
108 // constructors and such
109 // ----------------------------------------------------------------------------
111 WindowRef
wxWindowMac::s_macWindowInUpdate
= NULL
;
113 void wxWindowMac::Init()
118 m_macEraseOnRedraw
= true ;
121 m_doubleClickAllowed
= 0;
122 m_winCaptured
= FALSE
;
124 m_isBeingDeleted
= FALSE
;
127 m_mouseInWindow
= FALSE
;
131 m_backgroundTransparent
= FALSE
;
133 // as all windows are created with WS_VISIBLE style...
136 m_macWindowData
= NULL
;
137 m_macEraseOnRedraw
= true ;
144 m_hScrollBar
= NULL
;
145 m_vScrollBar
= NULL
;
147 #if wxUSE_DRAG_AND_DROP
148 m_pDropTarget
= NULL
;
153 wxWindowMac::~wxWindowMac()
155 // deleting a window while it is shown invalidates the region
157 wxWindowMac
* iter
= this ;
159 if ( iter
->m_macWindowData
)
164 iter
= iter
->GetParent() ;
169 m_isBeingDeleted
= TRUE
;
171 if ( s_lastMouseWindow
== this )
173 s_lastMouseWindow
= NULL
;
176 if ( gFocusWindow
== this )
178 gFocusWindow
= NULL
;
182 m_parent
->RemoveChild(this);
186 if ( m_macWindowData
)
188 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
189 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
190 delete m_macWindowData
;
191 wxRemoveMacWindowAssociation( this ) ;
196 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
200 const wxString
& name
)
202 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
204 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
207 parent
->AddChild(this);
211 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
212 m_width
= WidthDefault( size
.x
);
213 m_height
= HeightDefault( size
.y
) ;
214 #ifndef __WXUNIVERSAL__
215 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
217 MacCreateScrollBars( style
) ;
223 void wxWindowMac::SetFocus()
225 if ( gFocusWindow
== this )
228 if ( AcceptsFocus() )
234 if ( gFocusWindow
->m_caret
)
236 gFocusWindow
->m_caret
->OnKillFocus();
238 #endif // wxUSE_CARET
239 #ifndef __WXUNIVERSAL__
240 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
241 if ( control
&& control
->GetMacControl() )
243 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
244 control
->MacRedrawControl() ;
247 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
248 event
.SetEventObject(gFocusWindow
);
249 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
251 gFocusWindow
= this ;
257 m_caret
->OnSetFocus();
259 #endif // wxUSE_CARET
260 // panel wants to track the window which was the last to have focus in it
261 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
264 panel
->SetLastFocus((wxWindow
*)this);
266 #ifndef __WXUNIVERSAL__
267 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
268 if ( control
&& control
->GetMacControl() )
270 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
273 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
274 event
.SetEventObject(this);
275 GetEventHandler()->ProcessEvent(event
) ;
280 bool wxWindowMac::Enable(bool enable
)
282 if ( !wxWindowBase::Enable(enable
) )
285 wxWindowList::Node
*node
= GetChildren().GetFirst();
288 wxWindowMac
*child
= node
->GetData();
289 child
->Enable(enable
);
291 node
= node
->GetNext();
297 void wxWindowMac::CaptureMouse()
299 wxTheApp
->s_captureWindow
= this ;
302 wxWindow
* wxWindowBase::GetCapture()
304 return wxTheApp
->s_captureWindow
;
307 void wxWindowMac::ReleaseMouse()
309 wxTheApp
->s_captureWindow
= NULL
;
312 #if wxUSE_DRAG_AND_DROP
314 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
316 if ( m_pDropTarget
!= 0 ) {
317 delete m_pDropTarget
;
320 m_pDropTarget
= pDropTarget
;
321 if ( m_pDropTarget
!= 0 )
329 // Old style file-manager drag&drop
330 void wxWindowMac::DragAcceptFiles(bool accept
)
336 void wxWindowMac::DoGetSize(int *x
, int *y
) const
342 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
348 wxPoint
pt(GetParent()->GetClientAreaOrigin());
355 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
357 menu
->SetInvokingWindow(this);
359 ClientToScreen( &x
, &y
) ;
361 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
362 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
363 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
364 ::DeleteMenu( menu
->MacGetMenuId() ) ;
365 menu
->SetInvokingWindow(NULL
);
371 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
373 WindowRef window
= GetMacRootWindow() ;
381 ::SetPort( UMAGetWindowPort( window
) ) ;
382 ::GlobalToLocal( &localwhere
) ;
388 MacRootWindowToClient( x
, y
) ;
391 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
393 WindowRef window
= GetMacRootWindow() ;
395 MacClientToRootWindow( x
, y
) ;
403 ::SetPort( UMAGetWindowPort( window
) ) ;
404 ::SetOrigin( 0 , 0 ) ;
405 ::LocalToGlobal( &localwhere
) ;
411 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
413 if ( m_macWindowData
)
420 GetParent()->MacClientToRootWindow( x
, y
) ;
424 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
426 if ( m_macWindowData
)
433 GetParent()->MacRootWindowToClient( x
, y
) ;
437 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
439 if (m_cursor
== cursor
)
442 if (wxNullCursor
== cursor
)
444 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
449 if ( ! wxWindowBase::SetCursor( cursor
) )
453 wxASSERT_MSG( m_cursor
.Ok(),
454 wxT("cursor must be valid after call to the base version"));
457 wxWindowMac
*mouseWin
;
460 // Change the cursor NOW if we're within the correct window
462 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
464 if ( mouseWin
== this && !wxIsBusy() )
466 m_cursor
.MacInstall() ;
474 // Get size *available for subwindows* i.e. excluding menu bar etc.
475 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
480 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
481 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
483 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
490 MacClientToRootWindow( &x1
, &y1
) ;
491 MacClientToRootWindow( &w
, &h
) ;
493 WindowRef window
= NULL
;
494 wxWindowMac
*iter
= (wxWindowMac
*)this ;
496 int totW
= 10000 , totH
= 10000;
499 if ( iter
->m_macWindowData
)
501 totW
= iter
->m_width
;
502 totH
= iter
->m_height
;
506 iter
= iter
->GetParent() ;
509 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
511 (*y
) -= MAC_SCROLLBAR_SIZE
;
517 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
519 (*x
) -= MAC_SCROLLBAR_SIZE
;
529 // ----------------------------------------------------------------------------
531 // ----------------------------------------------------------------------------
535 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
537 wxWindowBase::DoSetToolTip(tooltip
);
540 m_tooltip
->SetWindow(this);
543 #endif // wxUSE_TOOLTIPS
545 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
547 DoSetSize( x
,y
, width
, height
) ;
550 // set the size of the window: if the dimensions are positive, just use them,
551 // but if any of them is equal to -1, it means that we must find the value for
552 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
553 // which case -1 is a valid value for x and y)
555 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
556 // the width/height to best suit our contents, otherwise we reuse the current
558 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
563 int former_w
= m_width
;
564 int former_h
= m_height
;
566 int currentX
, currentY
;
567 GetPosition(¤tX
, ¤tY
);
568 int currentW
,currentH
;
569 GetSize(¤tW
, ¤tH
);
571 int actualWidth
= width
;
572 int actualHeight
= height
;
575 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
577 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
580 wxSize
size( -1 , -1 ) ;
582 if (width
== -1 || height
== -1 )
584 size
= DoGetBestSize() ;
589 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
591 actualWidth
= size
.x
;
592 if ( actualWidth
== -1 )
597 actualWidth
= currentW
;
602 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
604 actualHeight
= size
.y
;
605 if ( actualHeight
== -1 )
610 actualHeight
= currentH
;
614 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
615 actualWidth
= m_minWidth
;
616 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
617 actualHeight
= m_minHeight
;
618 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
619 actualWidth
= m_maxWidth
;
620 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
621 actualHeight
= m_maxHeight
;
622 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
624 MacRepositionScrollBars() ; // we might have a real position shift
628 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
631 bool doMove
= false ;
632 bool doResize
= false ;
634 if ( actualX
!= former_x
|| actualY
!= former_y
)
638 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
643 if ( doMove
|| doResize
)
645 if ( m_macWindowData
)
650 // erase former position
651 wxMacDrawingHelper
focus( this ) ;
654 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
655 // ClipRect( &clientrect ) ;
656 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
661 m_width
= actualWidth
;
662 m_height
= actualHeight
;
663 if ( m_macWindowData
)
666 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
669 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
671 // the OS takes care of invalidating and erasing the new area
672 // we have erased the old one
674 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
676 wxFrame
* frame
= (wxFrame
*) this ;
677 frame
->PositionStatusBar();
678 frame
->PositionToolBar();
683 // erase new position
686 wxMacDrawingHelper
focus( this ) ;
689 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
690 // ClipRect( &clientrect ) ;
691 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
696 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
698 MacRepositionScrollBars() ;
701 wxPoint
point(m_x
, m_y
);
702 wxMoveEvent
event(point
, m_windowId
);
703 event
.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(event
) ;
708 MacRepositionScrollBars() ;
709 wxSize
size(m_width
, m_height
);
710 wxSizeEvent
event(size
, m_windowId
);
711 event
.SetEventObject(this);
712 GetEventHandler()->ProcessEvent(event
);
716 // For implementation purposes - sometimes decorations make the client area
719 wxPoint
wxWindowMac::GetClientAreaOrigin() const
721 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
724 // Makes an adjustment to the window position (for example, a frame that has
725 // a toolbar that it manages itself).
726 void wxWindowMac::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
728 if( !m_macWindowData
)
730 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
732 wxPoint
pt(GetParent()->GetClientAreaOrigin());
733 x
+= pt
.x
; y
+= pt
.y
;
738 void wxWindowMac::SetTitle(const wxString
& title
)
744 if( wxApp::s_macDefaultEncodingIsPC
)
745 label
= wxMacMakeMacStringFromPC( title
) ;
749 if ( m_macWindowData
)
750 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
753 wxString
wxWindowMac::GetTitle() const
758 bool wxWindowMac::Show(bool show
)
760 if ( !wxWindowBase::Show(show
) )
763 if ( m_macWindowData
)
767 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
768 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
769 // no need to generate events here, they will get them triggered by macos
770 // actually they should be , but apparently they are not
771 wxSize
size(m_width
, m_height
);
772 wxSizeEvent
event(size
, m_windowId
);
773 event
.SetEventObject(this);
774 GetEventHandler()->ProcessEvent(event
);
778 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
781 MacSuperShown( show
) ;
784 WindowRef window
= GetMacRootWindow() ;
785 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
786 if ( !win
->m_isBeingDeleted
)
797 void wxWindowMac::MacSuperShown( bool show
)
799 wxNode
*node
= GetChildren().First();
802 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
803 if ( child
->m_isShown
)
804 child
->MacSuperShown( show
) ;
809 bool wxWindowMac::MacIsReallyShown() const
811 if ( m_isShown
&& (m_parent
!= NULL
) ) {
812 return m_parent
->MacIsReallyShown();
816 bool status = m_isShown ;
817 wxWindowMac * win = this ;
818 while ( status && win->m_parent != NULL )
820 win = win->m_parent ;
821 status = win->m_isShown ;
827 int wxWindowMac::GetCharHeight() const
829 wxClientDC
dc ( (wxWindowMac
*)this ) ;
830 return dc
.GetCharHeight() ;
833 int wxWindowMac::GetCharWidth() const
835 wxClientDC
dc ( (wxWindowMac
*)this ) ;
836 return dc
.GetCharWidth() ;
839 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
840 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
842 const wxFont
*fontToUse
= theFont
;
846 wxClientDC
dc( (wxWindowMac
*) this ) ;
848 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
849 if ( externalLeading
)
850 *externalLeading
= le
;
859 void wxWindowMac::MacEraseBackground( Rect
*rect
)
862 WindowRef window = GetMacRootWindow() ;
863 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
865 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
867 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
869 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
870 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
871 // either a non gray background color or a non control window
873 wxWindowMac* parent = GetParent() ;
876 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
878 // if we have any other colours in the hierarchy
879 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
882 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
884 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
885 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
887 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
893 // we have arrived at a non control item
897 parent = parent->GetParent() ;
901 // if there is nothing special -> use default
902 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
907 RGBBackColor( &m_backgroundColour.GetPixel()) ;
912 for (wxNode *node = GetChildren().First(); node; node = node->Next())
914 wxWindowMac *child = (wxWindowMac*)node->Data();
916 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
917 SectRect( &clientrect , rect , &clientrect ) ;
919 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
920 if ( child->GetMacRootWindow() == window && child->IsShown() )
922 wxMacDrawingClientHelper focus( this ) ;
925 child->MacEraseBackground( &clientrect ) ;
932 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
937 wxMacDrawingClientHelper
focus( this ) ;
941 client
= GetClientAreaOrigin( ) ;
942 Rect clientrect
= { -client
.y
, -client
.x
, m_height
- client
.y
, m_width
- client
.x
} ;
943 // ClipRect( &clientrect ) ;
947 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
948 SectRect( &clientrect
, &r
, &clientrect
) ;
950 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
953 m_macEraseOnRedraw
= false ;
955 m_macEraseOnRedraw
= true ;
958 // Responds to colour changes: passes event on to children.
959 void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
961 wxNode
*node
= GetChildren().First();
964 // Only propagate to non-top-level windows
965 wxWindowMac
*win
= (wxWindowMac
*)node
->Data();
966 if ( win
->GetParent() )
968 wxSysColourChangedEvent event2
;
969 event
.m_eventObject
= win
;
970 win
->GetEventHandler()->ProcessEvent(event2
);
977 #if wxUSE_CARET && WXWIN_COMPATIBILITY
978 // ---------------------------------------------------------------------------
979 // Caret manipulation
980 // ---------------------------------------------------------------------------
982 void wxWindowMac::CreateCaret(int w
, int h
)
984 SetCaret(new wxCaret(this, w
, h
));
987 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
989 wxFAIL_MSG("not implemented");
992 void wxWindowMac::ShowCaret(bool show
)
994 wxCHECK_RET( m_caret
, "no caret to show" );
999 void wxWindowMac::DestroyCaret()
1004 void wxWindowMac::SetCaretPos(int x
, int y
)
1006 wxCHECK_RET( m_caret
, "no caret to move" );
1008 m_caret
->Move(x
, y
);
1011 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
1013 wxCHECK_RET( m_caret
, "no caret to get position of" );
1015 m_caret
->GetPosition(x
, y
);
1017 #endif // wxUSE_CARET
1019 wxWindowMac
*wxGetActiveWindow()
1021 // actually this is a windows-only concept
1025 // Coordinates relative to the window
1026 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1028 // We really dont move the mouse programmatically under mac
1031 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1033 // TODO : probably we would adopt the EraseEvent structure
1036 int wxWindowMac::GetScrollPos(int orient
) const
1038 if ( orient
== wxHORIZONTAL
)
1041 return m_hScrollBar
->GetThumbPosition() ;
1046 return m_vScrollBar
->GetThumbPosition() ;
1051 // This now returns the whole range, not just the number
1052 // of positions that we can scroll.
1053 int wxWindowMac::GetScrollRange(int orient
) const
1055 if ( orient
== wxHORIZONTAL
)
1058 return m_hScrollBar
->GetRange() ;
1063 return m_vScrollBar
->GetRange() ;
1068 int wxWindowMac::GetScrollThumb(int orient
) const
1070 if ( orient
== wxHORIZONTAL
)
1073 return m_hScrollBar
->GetThumbSize() ;
1078 return m_vScrollBar
->GetThumbSize() ;
1083 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1085 if ( orient
== wxHORIZONTAL
)
1088 m_hScrollBar
->SetThumbPosition( pos
) ;
1093 m_vScrollBar
->SetThumbPosition( pos
) ;
1097 void wxWindowMac::MacCreateRealWindow( const wxString
& title
,
1101 const wxString
& name
)
1104 m_windowStyle
= style
;
1125 m_macWindowData
= new MacWindowData() ;
1127 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1129 // translate the window attributes in the appropriate window class and attributes
1131 WindowClass wclass
= 0;
1132 WindowAttributes attr
= kWindowNoAttributes
;
1134 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1136 wclass
= kFloatingWindowClass
;
1137 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1139 attr
|= kWindowSideTitlebarAttribute
;
1142 else if ( HasFlag( wxCAPTION
) )
1144 if ( HasFlag( wxDIALOG_MODAL
) )
1146 wclass
= kMovableModalWindowClass
;
1150 wclass
= kDocumentWindowClass
;
1155 wclass
= kModalWindowClass
;
1158 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1160 attr
|= kWindowFullZoomAttribute
;
1161 attr
|= kWindowCollapseBoxAttribute
;
1163 if ( HasFlag( wxRESIZE_BORDER
) )
1165 attr
|= kWindowResizableAttribute
;
1167 if ( HasFlag( wxSYSTEM_MENU
) )
1169 attr
|= kWindowCloseBoxAttribute
;
1172 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1173 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1175 if( wxApp::s_macDefaultEncodingIsPC
)
1176 label
= wxMacMakeMacStringFromPC( title
) ;
1179 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1180 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1182 m_macWindowData
->m_macFocus
= NULL
;
1183 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1186 void wxWindowMac::MacPaint( wxPaintEvent
&event
)
1190 void wxWindowMac::MacPaintBorders( )
1192 if( m_macWindowData
)
1195 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1196 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1197 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1198 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1201 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1203 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1204 RGBColor pen1
= sunken
? white
: black
;
1205 RGBColor pen2
= sunken
? shadow
: face
;
1206 RGBColor pen3
= sunken
? face
: shadow
;
1207 RGBColor pen4
= sunken
? black
: white
;
1209 RGBForeColor( &pen1
) ;
1211 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1212 FrameRect( &rect
) ;
1214 RGBForeColor( &pen2
) ;
1216 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1217 FrameRect( &rect
) ;
1219 RGBForeColor( &pen3
) ;
1221 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1222 FrameRect( &rect
) ;
1224 RGBForeColor( &pen4
) ;
1227 LineTo( m_width
- 3 , 0 ) ;
1229 LineTo( 0 , m_height
- 3 ) ;
1232 else if (HasFlag(wxSIMPLE_BORDER
))
1234 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1235 RGBForeColor( &black
) ;
1236 FrameRect( &rect
) ;
1239 if ( this->GetParent() )
1241 wxPaintDC dc(GetParent());
1242 GetParent()->PrepareDC(dc);
1244 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1246 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1248 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1249 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1251 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1252 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1253 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1254 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1257 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1260 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1263 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1266 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1267 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1269 else if (HasFlag(wxDOUBLE_BORDER))
1271 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1273 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1274 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1276 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1277 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1278 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1279 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1282 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1285 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1288 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1291 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1292 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1294 else if (HasFlag(wxSIMPLE_BORDER))
1296 dc.SetPen(*wxBLACK_PEN);
1297 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1303 // New function that will replace some of the above.
1304 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1305 int range
, bool refresh
)
1307 if ( orient
== wxHORIZONTAL
)
1311 if ( range
== 0 || thumbVisible
>= range
)
1313 if ( m_hScrollBar
->IsShown() )
1314 m_hScrollBar
->Show(false) ;
1318 if ( !m_hScrollBar
->IsShown() )
1319 m_hScrollBar
->Show(true) ;
1320 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1328 if ( range
== 0 || thumbVisible
>= range
)
1330 if ( m_vScrollBar
->IsShown() )
1331 m_vScrollBar
->Show(false) ;
1335 if ( !m_vScrollBar
->IsShown() )
1336 m_vScrollBar
->Show(true) ;
1337 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1341 MacRepositionScrollBars() ;
1344 // Does a physical scroll
1345 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1347 wxMacDrawingClientHelper
focus( this ) ;
1350 int width
, height
;
1351 GetClientSize( &width
, &height
) ;
1353 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1355 RgnHandle updateRgn
= NewRgn() ;
1356 ClipRect( &scrollrect
) ;
1359 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1360 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1362 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1363 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1364 DisposeRgn( updateRgn
) ;
1367 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1369 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1370 if (child
== m_vScrollBar
) continue;
1371 if (child
== m_hScrollBar
) continue;
1372 if (child
->IsTopLevel()) continue;
1374 child
->GetPosition( &x
, &y
);
1376 child
->GetSize( &w
, &h
);
1377 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1382 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1384 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1386 wxScrollWinEvent wevent
;
1387 wevent
.SetPosition(event
.GetPosition());
1388 wevent
.SetOrientation(event
.GetOrientation());
1389 wevent
.m_eventObject
= this;
1391 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1392 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1394 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1395 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1397 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1398 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1400 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1401 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1403 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1404 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1406 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1407 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1409 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1410 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1413 GetEventHandler()->ProcessEvent(wevent
);
1417 bool wxWindowMac::SetFont(const wxFont
& font
)
1419 if ( !wxWindowBase::SetFont(font
) )
1428 // Get the window with the focus
1429 wxWindowMac
*wxWindowBase::FindFocus()
1431 return gFocusWindow
;
1434 #if WXWIN_COMPATIBILITY
1435 // If nothing defined for this, try the parent.
1436 // E.g. we may be a button loaded from a resource, with no callback function
1438 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1440 if ( GetEventHandler()->ProcessEvent(event
) )
1443 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1445 #endif // WXWIN_COMPATIBILITY_2
1447 #if WXWIN_COMPATIBILITY
1448 wxObject
* wxWindowMac::GetChild(int number
) const
1450 // Return a pointer to the Nth object in the Panel
1451 wxNode
*node
= GetChildren().First();
1454 node
= node
->Next();
1457 wxObject
*obj
= (wxObject
*)node
->Data();
1463 #endif // WXWIN_COMPATIBILITY
1465 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1467 // panel wants to track the window which was the last to have focus in it,
1468 // so we want to set ourselves as the window which last had focus
1470 // notice that it's also important to do it upwards the tree becaus
1471 // otherwise when the top level panel gets focus, it won't set it back to
1472 // us, but to some other sibling
1473 wxWindowMac
*win
= this;
1476 wxWindowMac
*parent
= win
->GetParent();
1477 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1480 panel
->SetLastFocus(win
);
1489 void wxWindowMac::Clear()
1491 if ( m_macWindowData
)
1493 wxMacDrawingClientHelper
helper ( this ) ;
1495 wxPoint origin
= GetClientAreaOrigin() ;
1496 GetClientSize( &w
, &h
) ;
1497 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1498 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1503 wxClientDC
dc(this);
1504 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1505 dc
.SetBackground(brush
);
1510 // Setup background and foreground colours correctly
1511 void wxWindowMac::SetupColours()
1514 SetBackgroundColour(GetParent()->GetBackgroundColour());
1517 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1520 // Check if we need to send a LEAVE event
1521 if (m_mouseInWindow)
1524 ::GetCursorPos(&pt);
1525 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1527 // Generate a LEAVE event
1528 m_mouseInWindow = FALSE;
1529 MSWOnMouseLeave(pt.x, pt.y, 0);
1534 // This calls the UI-update mechanism (querying windows for
1535 // menu/toolbar/control state information)
1539 // Raise the window to the top of the Z order
1540 void wxWindowMac::Raise()
1542 if ( m_macWindowData
)
1544 UMABringToFront( m_macWindowData
->m_macWindow
) ;
1548 // Lower the window to the bottom of the Z order
1549 void wxWindowMac::Lower()
1551 if ( m_macWindowData
)
1553 UMASendBehind( m_macWindowData
->m_macWindow
, NULL
) ;
1557 void wxWindowMac::DoSetClientSize(int width
, int height
)
1559 if ( width
!= -1 || height
!= -1 )
1562 if ( width
!= -1 && m_vScrollBar
)
1563 width
+= MAC_SCROLLBAR_SIZE
;
1564 if ( height
!= -1 && m_vScrollBar
)
1565 height
+= MAC_SCROLLBAR_SIZE
;
1567 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1568 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1570 DoSetSize( -1 , -1 , width
, height
) ;
1575 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1577 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1579 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1580 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1583 WindowRef window
= GetMacRootWindow() ;
1585 wxPoint
newPoint( point
) ;
1590 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1592 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1593 // added the m_isShown test --dmazzoni
1594 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1596 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1605 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1608 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1609 if ( ::FindWindow( pt
, &window
) == 3 )
1611 wxPoint
point( screenpoint
) ;
1612 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1615 win
->ScreenToClient( point
) ;
1616 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1622 extern int wxBusyCursorCount
;
1624 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1626 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1627 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1631 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1634 WindowRef window
= GetMacRootWindow() ;
1642 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1644 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1645 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1647 if (child
->MacDispatchMouseEvent(event
))
1655 if ( wxBusyCursorCount
== 0 )
1657 m_cursor
.MacInstall() ;
1660 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1662 // set focus to this window
1663 if (AcceptsFocus() && FindFocus()!=this)
1668 if ( event
.GetEventType() == wxEVT_MOTION
1669 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1670 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1671 wxToolTip::RelayEvent( this , event
);
1672 #endif // wxUSE_TOOLTIPS
1673 GetEventHandler()->ProcessEvent( event
) ;
1680 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1684 return m_tooltip
->GetTip() ;
1688 void wxWindowMac::MacFireMouseEvent( EventRecord
*ev
)
1690 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1691 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1692 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1694 event
.m_leftDown
= isDown
&& !controlDown
;
1695 event
.m_middleDown
= FALSE
;
1696 event
.m_rightDown
= isDown
&& controlDown
;
1698 if ( ev
->what
== mouseDown
)
1701 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1703 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1705 else if ( ev
->what
== mouseUp
)
1708 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1710 event
.SetEventType(wxEVT_LEFT_UP
) ;
1714 event
.SetEventType(wxEVT_MOTION
) ;
1717 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1718 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1719 event
.m_altDown
= ev
->modifiers
& optionKey
;
1720 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1722 Point localwhere
= ev
->where
;
1725 ::GetPort( &port
) ;
1726 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1727 ::GlobalToLocal( &localwhere
) ;
1730 if ( ev
->what
== mouseDown
)
1732 if ( ev
->when
- lastWhen
<= GetDblTime() )
1734 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1737 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1739 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1745 lastWhen
= ev
->when
;
1747 lastWhere
= localwhere
;
1750 event
.m_x
= localwhere
.h
;
1751 event
.m_y
= localwhere
.v
;
1756 wxPoint origin = GetClientAreaOrigin() ;
1758 event.m_x += origin.x ;
1759 event.m_y += origin.y ;
1762 event
.m_timeStamp
= ev
->when
;
1763 event
.SetEventObject(this);
1764 if ( wxTheApp
->s_captureWindow
)
1768 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1771 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1772 if ( ev
->what
== mouseUp
)
1774 wxTheApp
->s_captureWindow
= NULL
;
1775 if ( wxBusyCursorCount
== 0 )
1777 m_cursor
.MacInstall() ;
1783 MacDispatchMouseEvent( event
) ;
1787 void wxWindowMac::MacMouseDown( EventRecord
*ev
, short part
)
1789 MacFireMouseEvent( ev
) ;
1792 void wxWindowMac::MacMouseUp( EventRecord
*ev
, short part
)
1794 WindowPtr frontWindow
;
1799 MacFireMouseEvent( ev
) ;
1805 void wxWindowMac::MacMouseMoved( EventRecord
*ev
, short part
)
1807 WindowPtr frontWindow
;
1812 MacFireMouseEvent( ev
) ;
1817 void wxWindowMac::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1819 if ( !m_macWindowData
->m_macHasReceivedFirstActivate
)
1820 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1822 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1823 event
.m_timeStamp
= ev
->when
;
1824 event
.SetEventObject(this);
1826 GetEventHandler()->ProcessEvent(event
);
1829 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1830 // MacUpdateImmediately() ;
1833 void wxWindowMac::MacRedraw( RgnHandle updatergn
, long time
)
1835 // updatergn is always already clipped to our boundaries
1836 WindowRef window
= GetMacRootWindow() ;
1837 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1838 RgnHandle ownUpdateRgn
= NewRgn() ;
1839 CopyRgn( updatergn
, ownUpdateRgn
) ;
1840 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1842 wxMacDrawingHelper
focus( this ) ; // was client
1845 WindowRef window
= GetMacRootWindow() ;
1846 bool eraseBackground
= false ;
1847 if ( m_macWindowData
)
1848 eraseBackground
= true ;
1849 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1851 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1853 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1855 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1856 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1857 // either a non gray background color or a non control window
1860 wxWindowMac
* parent
= GetParent() ;
1863 if ( parent
->GetMacRootWindow() != window
)
1865 // we are in a different window on the mac system
1870 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1872 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1874 // if we have any other colours in the hierarchy
1875 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1878 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1879 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1882 GetRegionBounds( updatergn
, &box
) ;
1883 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1892 parent
= parent
->GetParent() ;
1896 // if there is nothing special -> use default
1897 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1902 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1904 // subtract all non transparent children from updatergn
1906 RgnHandle childarea
= NewRgn() ;
1907 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1909 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1910 // eventually test for transparent windows
1911 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1913 if ( child
->GetBackgroundColour() != m_backgroundColour
&& !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1915 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1916 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1920 DisposeRgn( childarea
) ;
1922 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1923 eraseBackground
= true ;
1924 SetClip( ownUpdateRgn
) ;
1925 if ( m_macEraseOnRedraw
) {
1926 if ( eraseBackground
)
1928 EraseRgn( ownUpdateRgn
) ;
1932 m_macEraseOnRedraw
= true ;
1937 RgnHandle newupdate
= NewRgn() ;
1938 wxSize point
= GetClientSize() ;
1939 wxPoint origin
= GetClientAreaOrigin() ;
1941 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1942 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1943 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1944 m_updateRegion
= newupdate
;
1945 DisposeRgn( newupdate
) ;
1950 event
.m_timeStamp
= time
;
1951 event
.SetEventObject(this);
1952 GetEventHandler()->ProcessEvent(event
);
1956 RgnHandle childupdate
= NewRgn() ;
1958 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1960 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1961 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1962 SectRgn( childupdate
, updatergn
, childupdate
) ;
1963 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1964 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1966 // because dialogs may also be children
1967 child
->MacRedraw( childupdate
, time
) ;
1970 DisposeRgn( childupdate
) ;
1971 // eventually a draw grow box here
1974 void wxWindowMac::MacUpdateImmediately()
1976 WindowRef window
= GetMacRootWindow() ;
1979 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1981 AGAPortHelper
help( GetWindowPort(window
) ) ;
1983 AGAPortHelper
help( (window
) ) ;
1985 SetOrigin( 0 , 0 ) ;
1986 BeginUpdate( window
) ;
1989 RgnHandle region
= NewRgn();
1993 GetPortVisibleRegion( GetWindowPort( window
), region
);
1995 // if windowshade gives incompatibility , take the follwing out
1996 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
1998 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
2000 DisposeRgn( region
);
2003 EndUpdate( window
) ;
2007 void wxWindowMac::MacUpdate( EventRecord
*ev
)
2009 WindowRef window
= (WindowRef
) ev
->message
;
2010 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2012 AGAPortHelper
help( GetWindowPort(window
) ) ;
2014 AGAPortHelper
help( (window
) ) ;
2016 SetOrigin( 0 , 0 ) ;
2017 BeginUpdate( window
) ;
2020 RgnHandle region
= NewRgn();
2024 GetPortVisibleRegion( GetWindowPort( window
), region
);
2026 // if windowshade gives incompatibility , take the follwing out
2027 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2029 MacRedraw( region
, ev
->when
) ;
2031 DisposeRgn( region
);
2034 EndUpdate( window
) ;
2037 WindowRef
wxWindowMac::GetMacRootWindow() const
2039 WindowRef window
= NULL
;
2040 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2044 if ( iter
->m_macWindowData
)
2045 return iter
->m_macWindowData
->m_macWindow
;
2047 iter
= iter
->GetParent() ;
2049 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2053 void wxWindowMac::MacCreateScrollBars( long style
)
2055 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2057 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2058 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2060 GetClientSize( &width
, &height
) ;
2062 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2063 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2064 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2065 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2067 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2068 vSize
, wxVERTICAL
);
2070 if ( style
& wxVSCROLL
)
2076 m_vScrollBar
->Show(false) ;
2078 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2079 hSize
, wxHORIZONTAL
);
2080 if ( style
& wxHSCROLL
)
2085 m_hScrollBar
->Show(false) ;
2088 // because the create does not take into account the client area origin
2089 MacRepositionScrollBars() ; // we might have a real position shift
2092 void wxWindowMac::MacRepositionScrollBars()
2094 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2095 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2097 // get real client area
2099 int width
= m_width
;
2100 int height
= m_height
;
2102 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2103 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2105 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2106 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2107 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2108 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2115 MacClientToRootWindow( &x
, &y
) ;
2116 MacClientToRootWindow( &w
, &h
) ;
2118 WindowRef window
= NULL
;
2119 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2121 int totW
= 10000 , totH
= 10000;
2124 if ( iter
->m_macWindowData
)
2126 totW
= iter
->m_width
;
2127 totH
= iter
->m_height
;
2131 iter
= iter
->GetParent() ;
2159 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2163 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2167 void wxWindowMac::MacKeyDown( EventRecord
*ev
)
2173 bool wxWindowMac::AcceptsFocus() const
2175 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2178 ControlHandle
wxWindowMac::MacGetContainerForEmbedding()
2180 if ( m_macWindowData
)
2181 return m_macWindowData
->m_macRootControl
;
2183 return GetParent()->MacGetContainerForEmbedding() ;
2186 void wxWindowMac::MacSuperChangedPosition()
2188 // only window-absolute structures have to be moved i.e. controls
2190 wxNode
*node
= GetChildren().First();
2193 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
2194 child
->MacSuperChangedPosition() ;
2195 node
= node
->Next();
2199 bool wxWindowMac::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2201 if ( window
== NULL
)
2207 ::GetPort(&currPort
);
2208 port
= UMAGetWindowPort( window
) ;
2209 if (currPort
!= port
)
2212 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2213 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2217 bool wxWindowMac::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2219 if ( window
== NULL
)
2224 ::GetPort(&currPort
);
2225 port
= UMAGetWindowPort( window
) ;
2226 if (currPort
!= port
)
2228 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2229 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2230 ::ClipRect(&clipRect
);
2233 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2234 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2235 Pattern whiteColor
;
2237 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2238 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2242 void wxWindowMac::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2244 if ( m_macWindowData
)
2250 clipRect
->right
= m_width
;
2251 clipRect
->bottom
= m_height
;
2252 *window
= m_macWindowData
->m_macWindow
;
2257 wxASSERT( GetParent() != NULL
) ;
2258 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2259 localOrigin
->h
+= m_x
;
2260 localOrigin
->v
+= m_y
;
2261 OffsetRect(clipRect
, -m_x
, -m_y
);
2266 myClip
.right
= m_width
;
2267 myClip
.bottom
= m_height
;
2268 SectRect(clipRect
, &myClip
, clipRect
);
2272 void wxWindowMac::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2274 // int width , height ;
2275 // GetClientSize( &width , &height ) ;
2277 if ( m_macWindowData
)
2283 clipRect
->right
= m_width
;//width;
2284 clipRect
->bottom
= m_height
;// height;
2285 *window
= m_macWindowData
->m_macWindow
;
2290 wxASSERT( GetParent() != NULL
) ;
2292 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2294 localOrigin
->h
+= m_x
;
2295 localOrigin
->v
+= m_y
;
2296 OffsetRect(clipRect
, -m_x
, -m_y
);
2301 myClip
.right
= m_width
;//width;
2302 myClip
.bottom
= m_height
;// height;
2303 SectRect(clipRect
, &myClip
, clipRect
);
2307 void wxWindowMac::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2309 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2311 int width
, height
;
2312 GetClientSize( &width
, &height
) ;
2314 client
= GetClientAreaOrigin( ) ;
2316 localOrigin
->h
+= client
.x
;
2317 localOrigin
->v
+= client
.y
;
2318 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2323 myClip
.right
= width
;
2324 myClip
.bottom
= height
;
2325 SectRect(clipRect
, &myClip
, clipRect
);
2328 long wxWindowMac::MacGetLeftBorderSize( ) const
2330 if( m_macWindowData
)
2333 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2337 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2341 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2348 long wxWindowMac::MacGetRightBorderSize( ) const
2350 if( m_macWindowData
)
2353 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2357 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2361 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2368 long wxWindowMac::MacGetTopBorderSize( ) const
2370 if( m_macWindowData
)
2373 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2377 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2381 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2388 long wxWindowMac::MacGetBottomBorderSize( ) const
2390 if( m_macWindowData
)
2393 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2397 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2401 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2408 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2410 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2414 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac
* theWindow
)
2420 wxWindowMac
*rootwin
;
2421 m_currentPort
= NULL
;
2423 GetPort( &m_formerPort
) ;
2426 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2427 m_currentPort
= UMAGetWindowPort( window
) ;
2428 if ( m_formerPort
!= m_currentPort
)
2429 SetPort( m_currentPort
) ;
2430 GetPenState( &m_savedPenState
) ;
2431 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2436 wxMacDrawingHelper::~wxMacDrawingHelper()
2440 SetPort( m_currentPort
) ;
2441 SetPenState( &m_savedPenState
) ;
2442 SetOrigin( 0 , 0 ) ;
2444 GetPortBounds( m_currentPort
, &portRect
) ;
2445 ClipRect( &portRect
) ;
2448 if ( m_formerPort
!= m_currentPort
)
2449 SetPort( m_formerPort
) ;
2452 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac
* theWindow
)
2458 wxWindowMac
*rootwin
;
2459 m_currentPort
= NULL
;
2461 GetPort( &m_formerPort
) ;
2465 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2466 m_currentPort
= UMAGetWindowPort( window
) ;
2467 if ( m_formerPort
!= m_currentPort
)
2468 SetPort( m_currentPort
) ;
2469 GetPenState( &m_savedPenState
) ;
2470 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2475 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2479 SetPort( m_currentPort
) ;
2480 SetPenState( &m_savedPenState
) ;
2481 SetOrigin( 0 , 0 ) ;
2483 GetPortBounds( m_currentPort
, &portRect
) ;
2484 ClipRect( &portRect
) ;
2487 if ( m_formerPort
!= m_currentPort
)
2488 SetPort( m_formerPort
) ;
2491 // Find the wxWindowMac at the current mouse position, returning the mouse
2493 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2495 pt
= wxGetMousePosition();
2496 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2500 // Get the current mouse position.
2501 wxPoint
wxGetMousePosition()
2504 wxGetMousePosition(& x
, & y
);
2505 return wxPoint(x
, y
);