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 #ifdef __WXUNIVERSAL__
60 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
62 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
63 #endif // __WXUNIVERSAL__/__WXMAC__
65 #if !USE_SHARED_LIBRARY
67 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
68 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
69 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
70 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
71 EVT_IDLE(wxWindowMac::OnIdle
)
72 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
79 // ===========================================================================
81 // ===========================================================================
83 // ---------------------------------------------------------------------------
84 // wxWindowMac utility functions
85 // ---------------------------------------------------------------------------
87 // Find an item given the Macintosh Window Reference
89 wxList
*wxWinMacWindowList
= NULL
;
90 wxWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
92 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
95 return (wxWindowMac
*)node
->Data();
98 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindowMac
*win
)
100 // adding NULL WindowRef is (first) surely a result of an error and
101 // (secondly) breaks menu command processing
102 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
104 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
105 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
108 void wxRemoveMacWindowAssociation(wxWindowMac
*win
)
110 wxWinMacWindowList
->DeleteObject(win
);
113 // ----------------------------------------------------------------------------
114 // constructors and such
115 // ----------------------------------------------------------------------------
117 WindowRef
wxWindowMac::s_macWindowInUpdate
= NULL
;
119 void wxWindowMac::Init()
124 m_macEraseOnRedraw
= true ;
127 m_doubleClickAllowed
= 0;
128 m_winCaptured
= FALSE
;
130 m_isBeingDeleted
= FALSE
;
133 m_mouseInWindow
= FALSE
;
137 m_backgroundTransparent
= FALSE
;
139 // as all windows are created with WS_VISIBLE style...
142 m_macWindowData
= NULL
;
143 m_macEraseOnRedraw
= true ;
150 m_hScrollBar
= NULL
;
151 m_vScrollBar
= NULL
;
153 #if wxUSE_DRAG_AND_DROP
154 m_pDropTarget
= NULL
;
159 wxWindowMac::~wxWindowMac()
161 // deleting a window while it is shown invalidates the region
163 wxWindowMac
* iter
= this ;
165 if ( iter
->m_macWindowData
)
170 iter
= iter
->GetParent() ;
175 m_isBeingDeleted
= TRUE
;
177 if ( s_lastMouseWindow
== this )
179 s_lastMouseWindow
= NULL
;
182 if ( gFocusWindow
== this )
184 gFocusWindow
= NULL
;
188 m_parent
->RemoveChild(this);
192 if ( m_macWindowData
)
194 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
195 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
196 delete m_macWindowData
;
197 wxRemoveMacWindowAssociation( this ) ;
202 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
206 const wxString
& name
)
208 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
210 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
213 parent
->AddChild(this);
217 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
218 m_width
= WidthDefault( size
.x
);
219 m_height
= HeightDefault( size
.y
) ;
220 #ifndef __WXUNIVERSAL__
221 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
223 MacCreateScrollBars( style
) ;
229 void wxWindowMac::SetFocus()
231 if ( gFocusWindow
== this )
234 if ( AcceptsFocus() )
240 if ( gFocusWindow
->m_caret
)
242 gFocusWindow
->m_caret
->OnKillFocus();
244 #endif // wxUSE_CARET
245 #ifndef __WXUNIVERSAL__
246 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
247 if ( control
&& control
->GetMacControl() )
249 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
250 control
->MacRedrawControl() ;
253 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
254 event
.SetEventObject(gFocusWindow
);
255 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
257 gFocusWindow
= this ;
263 m_caret
->OnSetFocus();
265 #endif // wxUSE_CARET
266 // panel wants to track the window which was the last to have focus in it
267 wxChildFocusEvent
eventFocus(this);
268 (void)GetEventHandler()->ProcessEvent(eventFocus
);
270 #ifndef __WXUNIVERSAL__
271 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
272 if ( control
&& control
->GetMacControl() )
274 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
277 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
278 event
.SetEventObject(this);
279 GetEventHandler()->ProcessEvent(event
) ;
284 bool wxWindowMac::Enable(bool enable
)
286 if ( !wxWindowBase::Enable(enable
) )
289 wxWindowList::Node
*node
= GetChildren().GetFirst();
292 wxWindowMac
*child
= node
->GetData();
293 child
->Enable(enable
);
295 node
= node
->GetNext();
301 void wxWindowMac::CaptureMouse()
303 wxTheApp
->s_captureWindow
= this ;
306 wxWindow
* wxWindowBase::GetCapture()
308 return wxTheApp
->s_captureWindow
;
311 void wxWindowMac::ReleaseMouse()
313 wxTheApp
->s_captureWindow
= NULL
;
316 #if wxUSE_DRAG_AND_DROP
318 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
320 if ( m_pDropTarget
!= 0 ) {
321 delete m_pDropTarget
;
324 m_pDropTarget
= pDropTarget
;
325 if ( m_pDropTarget
!= 0 )
333 // Old style file-manager drag&drop
334 void wxWindowMac::DragAcceptFiles(bool accept
)
340 void wxWindowMac::DoGetSize(int *x
, int *y
) const
343 if(y
) *y
= m_height
;
346 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
354 wxPoint
pt(GetParent()->GetClientAreaOrigin());
363 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
365 menu
->SetInvokingWindow(this);
367 ClientToScreen( &x
, &y
) ;
369 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
370 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
371 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
372 ::DeleteMenu( menu
->MacGetMenuId() ) ;
373 menu
->SetInvokingWindow(NULL
);
379 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
381 WindowRef window
= GetMacRootWindow() ;
383 Point localwhere
= {0,0} ;
385 if(x
) localwhere
.h
= * x
;
386 if(y
) localwhere
.v
= * y
;
390 ::SetPort( UMAGetWindowPort( window
) ) ;
391 ::GlobalToLocal( &localwhere
) ;
394 if(x
) *x
= localwhere
.h
;
395 if(y
) *y
= localwhere
.v
;
397 MacRootWindowToClient( x
, y
) ;
400 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
402 WindowRef window
= GetMacRootWindow() ;
404 MacClientToRootWindow( x
, y
) ;
406 Point localwhere
= { 0,0 };
407 if(x
) localwhere
.h
= * x
;
408 if(y
) localwhere
.v
= * y
;
412 ::SetPort( UMAGetWindowPort( window
) ) ;
413 ::SetOrigin( 0 , 0 ) ;
414 ::LocalToGlobal( &localwhere
) ;
416 if(x
) *x
= localwhere
.h
;
417 if(y
) *y
= localwhere
.v
;
420 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
422 if ( m_macWindowData
== NULL
)
426 GetParent()->MacClientToRootWindow( x
, y
) ;
430 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
432 if ( m_macWindowData
== NULL
)
436 GetParent()->MacRootWindowToClient( x
, y
) ;
440 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
442 if (m_cursor
== cursor
)
445 if (wxNullCursor
== cursor
)
447 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
452 if ( ! wxWindowBase::SetCursor( cursor
) )
456 wxASSERT_MSG( m_cursor
.Ok(),
457 wxT("cursor must be valid after call to the base version"));
460 wxWindowMac
*mouseWin
;
463 // Change the cursor NOW if we're within the correct window
465 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
467 if ( mouseWin
== this && !wxIsBusy() )
469 m_cursor
.MacInstall() ;
477 // Get size *available for subwindows* i.e. excluding menu bar etc.
478 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
484 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
485 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
487 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
494 MacClientToRootWindow( &x1
, &y1
) ;
495 MacClientToRootWindow( &w
, &h
) ;
497 wxWindowMac
*iter
= (wxWindowMac
*)this ;
499 int totW
= 10000 , totH
= 10000;
502 if ( iter
->m_macWindowData
)
504 totW
= iter
->m_width
;
505 totH
= iter
->m_height
;
509 iter
= iter
->GetParent() ;
512 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
514 hh
-= MAC_SCROLLBAR_SIZE
;
520 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
522 ww
-= MAC_SCROLLBAR_SIZE
;
534 // ----------------------------------------------------------------------------
536 // ----------------------------------------------------------------------------
540 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
542 wxWindowBase::DoSetToolTip(tooltip
);
545 m_tooltip
->SetWindow(this);
548 #endif // wxUSE_TOOLTIPS
550 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
554 int former_w
= m_width
;
555 int former_h
= m_height
;
557 int actualWidth
= width
;
558 int actualHeight
= height
;
562 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
563 actualWidth
= m_minWidth
;
564 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
565 actualHeight
= m_minHeight
;
566 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
567 actualWidth
= m_maxWidth
;
568 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
569 actualHeight
= m_maxHeight
;
571 bool doMove
= false ;
572 bool doResize
= false ;
574 if ( actualX
!= former_x
|| actualY
!= former_y
)
578 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
583 if ( doMove
|| doResize
)
585 if ( m_macWindowData
)
590 // erase former position
591 wxMacDrawingHelper
focus( this ) ;
594 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
595 // ClipRect( &clientrect ) ;
596 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
601 m_width
= actualWidth
;
602 m_height
= actualHeight
;
603 if ( m_macWindowData
)
606 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
609 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
611 // the OS takes care of invalidating and erasing the new area
612 // we have erased the old one
614 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
616 wxFrame
* frame
= (wxFrame
*) this ;
617 frame
->PositionStatusBar();
618 frame
->PositionToolBar();
623 // erase new position
626 wxMacDrawingHelper
focus( this ) ;
629 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
630 // ClipRect( &clientrect ) ;
631 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
636 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
638 MacRepositionScrollBars() ;
641 wxPoint
point(m_x
, m_y
);
642 wxMoveEvent
event(point
, m_windowId
);
643 event
.SetEventObject(this);
644 GetEventHandler()->ProcessEvent(event
) ;
648 MacRepositionScrollBars() ;
649 wxSize
size(m_width
, m_height
);
650 wxSizeEvent
event(size
, m_windowId
);
651 event
.SetEventObject(this);
652 GetEventHandler()->ProcessEvent(event
);
658 // set the size of the window: if the dimensions are positive, just use them,
659 // but if any of them is equal to -1, it means that we must find the value for
660 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
661 // which case -1 is a valid value for x and y)
663 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
664 // the width/height to best suit our contents, otherwise we reuse the current
666 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
668 // get the current size and position...
669 int currentX
, currentY
;
670 GetPosition(¤tX
, ¤tY
);
671 int currentW
,currentH
;
672 GetSize(¤tW
, ¤tH
);
674 // ... and don't do anything (avoiding flicker) if it's already ok
675 if ( x
== currentX
&& y
== currentY
&&
676 width
== currentW
&& height
== currentH
)
678 MacRepositionScrollBars() ; // we might have a real position shift
682 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
684 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
687 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
692 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
694 size
= DoGetBestSize();
699 // just take the current one
706 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
710 size
= DoGetBestSize();
712 //else: already called DoGetBestSize() above
718 // just take the current one
723 DoMoveWindow(x
, y
, width
, height
);
726 // For implementation purposes - sometimes decorations make the client area
729 wxPoint
wxWindowMac::GetClientAreaOrigin() const
731 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
734 // Makes an adjustment to the window position (for example, a frame that has
735 // a toolbar that it manages itself).
736 void wxWindowMac::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
738 if( !m_macWindowData
)
740 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
742 wxPoint
pt(GetParent()->GetClientAreaOrigin());
743 x
+= pt
.x
; y
+= pt
.y
;
748 void wxWindowMac::SetTitle(const wxString
& title
)
754 if( wxApp::s_macDefaultEncodingIsPC
)
755 label
= wxMacMakeMacStringFromPC( title
) ;
759 if ( m_macWindowData
)
760 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
763 wxString
wxWindowMac::GetTitle() const
768 bool wxWindowMac::Show(bool show
)
770 if ( !wxWindowBase::Show(show
) )
773 if ( m_macWindowData
)
777 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
778 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
779 // no need to generate events here, they will get them triggered by macos
780 // actually they should be , but apparently they are not
781 wxSize
size(m_width
, m_height
);
782 wxSizeEvent
event(size
, m_windowId
);
783 event
.SetEventObject(this);
784 GetEventHandler()->ProcessEvent(event
);
788 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
791 MacSuperShown( show
) ;
794 WindowRef window
= GetMacRootWindow() ;
795 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
796 if ( win
&& !win
->m_isBeingDeleted
)
807 void wxWindowMac::MacSuperShown( bool show
)
809 wxNode
*node
= GetChildren().First();
812 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
813 if ( child
->m_isShown
)
814 child
->MacSuperShown( show
) ;
819 bool wxWindowMac::MacIsReallyShown() const
821 if ( m_isShown
&& (m_parent
!= NULL
) ) {
822 return m_parent
->MacIsReallyShown();
826 bool status = m_isShown ;
827 wxWindowMac * win = this ;
828 while ( status && win->m_parent != NULL )
830 win = win->m_parent ;
831 status = win->m_isShown ;
837 int wxWindowMac::GetCharHeight() const
839 wxClientDC
dc ( (wxWindowMac
*)this ) ;
840 return dc
.GetCharHeight() ;
843 int wxWindowMac::GetCharWidth() const
845 wxClientDC
dc ( (wxWindowMac
*)this ) ;
846 return dc
.GetCharWidth() ;
849 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
850 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
852 const wxFont
*fontToUse
= theFont
;
856 wxClientDC
dc( (wxWindowMac
*) this ) ;
858 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
859 if ( externalLeading
)
860 *externalLeading
= le
;
869 void wxWindowMac::MacEraseBackground( Rect
*rect
)
872 WindowRef window = GetMacRootWindow() ;
873 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
875 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
877 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
879 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
880 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
881 // either a non gray background color or a non control window
883 wxWindowMac* parent = GetParent() ;
886 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
888 // if we have any other colours in the hierarchy
889 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
892 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
894 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
895 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
897 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
903 // we have arrived at a non control item
907 parent = parent->GetParent() ;
911 // if there is nothing special -> use default
912 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
917 RGBBackColor( &m_backgroundColour.GetPixel()) ;
922 for (wxNode *node = GetChildren().First(); node; node = node->Next())
924 wxWindowMac *child = (wxWindowMac*)node->Data();
926 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
927 SectRect( &clientrect , rect , &clientrect ) ;
929 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
930 if ( child->GetMacRootWindow() == window && child->IsShown() )
932 wxMacDrawingClientHelper focus( this ) ;
935 child->MacEraseBackground( &clientrect ) ;
942 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
947 wxMacDrawingClientHelper
focus( this ) ;
951 client
= GetClientAreaOrigin( ) ;
952 Rect clientrect
= { -client
.y
, -client
.x
, m_height
- client
.y
, m_width
- client
.x
} ;
953 // ClipRect( &clientrect ) ;
957 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
958 SectRect( &clientrect
, &r
, &clientrect
) ;
960 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
963 m_macEraseOnRedraw
= false ;
965 m_macEraseOnRedraw
= true ;
968 // Responds to colour changes: passes event on to children.
969 void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
971 wxNode
*node
= GetChildren().First();
974 // Only propagate to non-top-level windows
975 wxWindowMac
*win
= (wxWindowMac
*)node
->Data();
976 if ( win
->GetParent() )
978 wxSysColourChangedEvent event2
;
979 event
.m_eventObject
= win
;
980 win
->GetEventHandler()->ProcessEvent(event2
);
987 #if wxUSE_CARET && WXWIN_COMPATIBILITY
988 // ---------------------------------------------------------------------------
989 // Caret manipulation
990 // ---------------------------------------------------------------------------
992 void wxWindowMac::CreateCaret(int w
, int h
)
994 SetCaret(new wxCaret(this, w
, h
));
997 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
999 wxFAIL_MSG("not implemented");
1002 void wxWindowMac::ShowCaret(bool show
)
1004 wxCHECK_RET( m_caret
, "no caret to show" );
1006 m_caret
->Show(show
);
1009 void wxWindowMac::DestroyCaret()
1014 void wxWindowMac::SetCaretPos(int x
, int y
)
1016 wxCHECK_RET( m_caret
, "no caret to move" );
1018 m_caret
->Move(x
, y
);
1021 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
1023 wxCHECK_RET( m_caret
, "no caret to get position of" );
1025 m_caret
->GetPosition(x
, y
);
1027 #endif // wxUSE_CARET
1029 wxWindowMac
*wxGetActiveWindow()
1031 // actually this is a windows-only concept
1035 // Coordinates relative to the window
1036 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1038 // We really dont move the mouse programmatically under mac
1041 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1043 // TODO : probably we would adopt the EraseEvent structure
1046 int wxWindowMac::GetScrollPos(int orient
) const
1048 if ( orient
== wxHORIZONTAL
)
1051 return m_hScrollBar
->GetThumbPosition() ;
1056 return m_vScrollBar
->GetThumbPosition() ;
1061 // This now returns the whole range, not just the number
1062 // of positions that we can scroll.
1063 int wxWindowMac::GetScrollRange(int orient
) const
1065 if ( orient
== wxHORIZONTAL
)
1068 return m_hScrollBar
->GetRange() ;
1073 return m_vScrollBar
->GetRange() ;
1078 int wxWindowMac::GetScrollThumb(int orient
) const
1080 if ( orient
== wxHORIZONTAL
)
1083 return m_hScrollBar
->GetThumbSize() ;
1088 return m_vScrollBar
->GetThumbSize() ;
1093 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1095 if ( orient
== wxHORIZONTAL
)
1098 m_hScrollBar
->SetThumbPosition( pos
) ;
1103 m_vScrollBar
->SetThumbPosition( pos
) ;
1107 void wxWindowMac::MacCreateRealWindow( const wxString
& title
,
1111 const wxString
& name
)
1114 m_windowStyle
= style
;
1135 m_macWindowData
= new MacWindowData() ;
1137 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1139 // translate the window attributes in the appropriate window class and attributes
1141 WindowClass wclass
= 0;
1142 WindowAttributes attr
= kWindowNoAttributes
;
1144 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1146 wclass
= kFloatingWindowClass
;
1147 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1149 attr
|= kWindowSideTitlebarAttribute
;
1152 else if ( HasFlag( wxCAPTION
) )
1154 if ( HasFlag( wxDIALOG_MODAL
) )
1156 wclass
= kMovableModalWindowClass
;
1160 wclass
= kDocumentWindowClass
;
1165 wclass
= kModalWindowClass
;
1168 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1170 attr
|= kWindowFullZoomAttribute
;
1171 attr
|= kWindowCollapseBoxAttribute
;
1173 if ( HasFlag( wxRESIZE_BORDER
) )
1175 attr
|= kWindowResizableAttribute
;
1177 if ( HasFlag( wxSYSTEM_MENU
) )
1179 attr
|= kWindowCloseBoxAttribute
;
1182 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1183 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1185 if( wxApp::s_macDefaultEncodingIsPC
)
1186 label
= wxMacMakeMacStringFromPC( title
) ;
1189 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1190 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1192 m_macWindowData
->m_macFocus
= NULL
;
1193 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1196 void wxWindowMac::MacPaint( wxPaintEvent
&event
)
1200 void wxWindowMac::MacPaintBorders( )
1202 if( m_macWindowData
)
1205 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1206 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1207 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1208 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1211 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1213 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1214 RGBColor pen1
= sunken
? white
: black
;
1215 RGBColor pen2
= sunken
? shadow
: face
;
1216 RGBColor pen3
= sunken
? face
: shadow
;
1217 RGBColor pen4
= sunken
? black
: white
;
1219 RGBForeColor( &pen1
) ;
1221 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1222 FrameRect( &rect
) ;
1224 RGBForeColor( &pen2
) ;
1226 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1227 FrameRect( &rect
) ;
1229 RGBForeColor( &pen3
) ;
1231 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1232 FrameRect( &rect
) ;
1234 RGBForeColor( &pen4
) ;
1237 LineTo( m_width
- 3 , 0 ) ;
1239 LineTo( 0 , m_height
- 3 ) ;
1242 else if (HasFlag(wxSIMPLE_BORDER
))
1244 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1245 RGBForeColor( &black
) ;
1246 FrameRect( &rect
) ;
1249 if ( this->GetParent() )
1251 wxPaintDC dc(GetParent());
1252 GetParent()->PrepareDC(dc);
1254 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1256 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1258 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1259 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1261 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1262 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1263 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1264 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1267 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1270 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1273 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1276 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1277 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1279 else if (HasFlag(wxDOUBLE_BORDER))
1281 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1283 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1284 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1286 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1287 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1288 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1289 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1292 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1295 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1298 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1301 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1302 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1304 else if (HasFlag(wxSIMPLE_BORDER))
1306 dc.SetPen(*wxBLACK_PEN);
1307 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1313 // New function that will replace some of the above.
1314 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1315 int range
, bool refresh
)
1317 if ( orient
== wxHORIZONTAL
)
1321 if ( range
== 0 || thumbVisible
>= range
)
1323 if ( m_hScrollBar
->IsShown() )
1324 m_hScrollBar
->Show(false) ;
1328 if ( !m_hScrollBar
->IsShown() )
1329 m_hScrollBar
->Show(true) ;
1330 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1338 if ( range
== 0 || thumbVisible
>= range
)
1340 if ( m_vScrollBar
->IsShown() )
1341 m_vScrollBar
->Show(false) ;
1345 if ( !m_vScrollBar
->IsShown() )
1346 m_vScrollBar
->Show(true) ;
1347 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1351 MacRepositionScrollBars() ;
1354 // Does a physical scroll
1355 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1357 wxMacDrawingClientHelper
focus( this ) ;
1360 int width
, height
;
1361 GetClientSize( &width
, &height
) ;
1363 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1365 RgnHandle updateRgn
= NewRgn() ;
1366 ClipRect( &scrollrect
) ;
1369 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1370 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1372 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1373 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1374 DisposeRgn( updateRgn
) ;
1377 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1379 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1380 if (child
== m_vScrollBar
) continue;
1381 if (child
== m_hScrollBar
) continue;
1382 if (child
->IsTopLevel()) continue;
1384 child
->GetPosition( &x
, &y
);
1386 child
->GetSize( &w
, &h
);
1387 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1392 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1394 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1396 wxScrollWinEvent wevent
;
1397 wevent
.SetPosition(event
.GetPosition());
1398 wevent
.SetOrientation(event
.GetOrientation());
1399 wevent
.m_eventObject
= this;
1401 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1402 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1404 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1405 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1407 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1408 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1410 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1411 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1413 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1414 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1416 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1417 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1419 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1420 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1423 GetEventHandler()->ProcessEvent(wevent
);
1427 bool wxWindowMac::SetFont(const wxFont
& font
)
1429 if ( !wxWindowBase::SetFont(font
) )
1438 // Get the window with the focus
1439 wxWindowMac
*wxWindowBase::FindFocus()
1441 return gFocusWindow
;
1444 #if WXWIN_COMPATIBILITY
1445 // If nothing defined for this, try the parent.
1446 // E.g. we may be a button loaded from a resource, with no callback function
1448 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1450 if ( GetEventHandler()->ProcessEvent(event
) )
1453 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1455 #endif // WXWIN_COMPATIBILITY_2
1457 #if WXWIN_COMPATIBILITY
1458 wxObject
* wxWindowMac::GetChild(int number
) const
1460 // Return a pointer to the Nth object in the Panel
1461 wxNode
*node
= GetChildren().First();
1464 node
= node
->Next();
1467 wxObject
*obj
= (wxObject
*)node
->Data();
1473 #endif // WXWIN_COMPATIBILITY
1475 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1477 // panel wants to track the window which was the last to have focus in it,
1478 // so we want to set ourselves as the window which last had focus
1480 // notice that it's also important to do it upwards the tree becaus
1481 // otherwise when the top level panel gets focus, it won't set it back to
1482 // us, but to some other sibling
1484 // CS:don't know if this is still needed:
1485 //wxChildFocusEvent eventFocus(this);
1486 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1491 void wxWindowMac::Clear()
1493 if ( m_macWindowData
)
1495 wxMacDrawingClientHelper
helper ( this ) ;
1497 wxPoint origin
= GetClientAreaOrigin() ;
1498 GetClientSize( &w
, &h
) ;
1499 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1500 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1505 wxClientDC
dc(this);
1506 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1507 dc
.SetBackground(brush
);
1512 // Setup background and foreground colours correctly
1513 void wxWindowMac::SetupColours()
1516 SetBackgroundColour(GetParent()->GetBackgroundColour());
1519 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1522 // Check if we need to send a LEAVE event
1523 if (m_mouseInWindow)
1526 ::GetCursorPos(&pt);
1527 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1529 // Generate a LEAVE event
1530 m_mouseInWindow = FALSE;
1531 MSWOnMouseLeave(pt.x, pt.y, 0);
1536 // This calls the UI-update mechanism (querying windows for
1537 // menu/toolbar/control state information)
1541 // Raise the window to the top of the Z order
1542 void wxWindowMac::Raise()
1544 if ( m_macWindowData
)
1546 UMABringToFront( m_macWindowData
->m_macWindow
) ;
1550 // Lower the window to the bottom of the Z order
1551 void wxWindowMac::Lower()
1553 if ( m_macWindowData
)
1555 UMASendBehind( m_macWindowData
->m_macWindow
, NULL
) ;
1559 void wxWindowMac::DoSetClientSize(int width
, int height
)
1561 if ( width
!= -1 || height
!= -1 )
1564 if ( width
!= -1 && m_vScrollBar
)
1565 width
+= MAC_SCROLLBAR_SIZE
;
1566 if ( height
!= -1 && m_vScrollBar
)
1567 height
+= MAC_SCROLLBAR_SIZE
;
1569 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1570 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1572 DoSetSize( -1 , -1 , width
, height
) ;
1577 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1579 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1581 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1582 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1585 WindowRef window
= GetMacRootWindow() ;
1587 wxPoint
newPoint( point
) ;
1592 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1594 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1595 // added the m_isShown test --dmazzoni
1596 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1598 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1607 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1610 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1611 if ( ::FindWindow( pt
, &window
) == 3 )
1613 wxPoint
point( screenpoint
) ;
1614 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1617 win
->ScreenToClient( point
) ;
1618 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1624 extern int wxBusyCursorCount
;
1626 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1628 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1629 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1633 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1636 WindowRef window
= GetMacRootWindow() ;
1644 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1646 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1647 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1649 if (child
->MacDispatchMouseEvent(event
))
1657 if ( wxBusyCursorCount
== 0 )
1659 m_cursor
.MacInstall() ;
1662 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1664 // set focus to this window
1665 if (AcceptsFocus() && FindFocus()!=this)
1670 if ( event
.GetEventType() == wxEVT_MOTION
1671 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1672 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1673 wxToolTip::RelayEvent( this , event
);
1674 #endif // wxUSE_TOOLTIPS
1675 GetEventHandler()->ProcessEvent( event
) ;
1682 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1686 return m_tooltip
->GetTip() ;
1690 void wxWindowMac::MacFireMouseEvent( EventRecord
*ev
)
1692 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1693 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1694 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1696 event
.m_leftDown
= isDown
&& !controlDown
;
1697 event
.m_middleDown
= FALSE
;
1698 event
.m_rightDown
= isDown
&& controlDown
;
1700 if ( ev
->what
== mouseDown
)
1703 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1705 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1707 else if ( ev
->what
== mouseUp
)
1710 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1712 event
.SetEventType(wxEVT_LEFT_UP
) ;
1716 event
.SetEventType(wxEVT_MOTION
) ;
1719 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1720 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1721 event
.m_altDown
= ev
->modifiers
& optionKey
;
1722 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1724 Point localwhere
= ev
->where
;
1727 ::GetPort( &port
) ;
1728 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1729 ::GlobalToLocal( &localwhere
) ;
1732 if ( ev
->what
== mouseDown
)
1734 if ( ev
->when
- lastWhen
<= GetDblTime() )
1736 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1739 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1741 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1747 lastWhen
= ev
->when
;
1749 lastWhere
= localwhere
;
1752 event
.m_x
= localwhere
.h
;
1753 event
.m_y
= localwhere
.v
;
1758 wxPoint origin = GetClientAreaOrigin() ;
1760 event.m_x += origin.x ;
1761 event.m_y += origin.y ;
1764 event
.m_timeStamp
= ev
->when
;
1765 event
.SetEventObject(this);
1766 if ( wxTheApp
->s_captureWindow
)
1770 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1773 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1774 if ( ev
->what
== mouseUp
)
1776 wxTheApp
->s_captureWindow
= NULL
;
1777 if ( wxBusyCursorCount
== 0 )
1779 m_cursor
.MacInstall() ;
1785 MacDispatchMouseEvent( event
) ;
1789 void wxWindowMac::MacMouseDown( EventRecord
*ev
, short part
)
1791 MacFireMouseEvent( ev
) ;
1794 void wxWindowMac::MacMouseUp( EventRecord
*ev
, short part
)
1800 MacFireMouseEvent( ev
) ;
1806 void wxWindowMac::MacMouseMoved( EventRecord
*ev
, short part
)
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
) ;
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 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2043 if ( iter
->m_macWindowData
)
2044 return iter
->m_macWindowData
->m_macWindow
;
2046 iter
= iter
->GetParent() ;
2048 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2052 void wxWindowMac::MacCreateScrollBars( long style
)
2054 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2056 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2057 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2059 GetClientSize( &width
, &height
) ;
2061 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2062 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2063 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2064 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2066 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2067 vSize
, wxVERTICAL
);
2069 if ( style
& wxVSCROLL
)
2075 m_vScrollBar
->Show(false) ;
2077 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2078 hSize
, wxHORIZONTAL
);
2079 if ( style
& wxHSCROLL
)
2084 m_hScrollBar
->Show(false) ;
2087 // because the create does not take into account the client area origin
2088 MacRepositionScrollBars() ; // we might have a real position shift
2091 void wxWindowMac::MacRepositionScrollBars()
2093 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2094 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2096 // get real client area
2098 int width
= m_width
;
2099 int height
= m_height
;
2101 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2102 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2104 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2105 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2106 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2107 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2114 MacClientToRootWindow( &x
, &y
) ;
2115 MacClientToRootWindow( &w
, &h
) ;
2117 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2119 int totW
= 10000 , totH
= 10000;
2122 if ( iter
->m_macWindowData
)
2124 totW
= iter
->m_width
;
2125 totH
= iter
->m_height
;
2129 iter
= iter
->GetParent() ;
2157 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2161 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2165 void wxWindowMac::MacKeyDown( EventRecord
*ev
)
2171 bool wxWindowMac::AcceptsFocus() const
2173 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2176 ControlHandle
wxWindowMac::MacGetContainerForEmbedding()
2178 if ( m_macWindowData
)
2179 return m_macWindowData
->m_macRootControl
;
2181 return GetParent()->MacGetContainerForEmbedding() ;
2184 void wxWindowMac::MacSuperChangedPosition()
2186 // only window-absolute structures have to be moved i.e. controls
2188 wxNode
*node
= GetChildren().First();
2191 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
2192 child
->MacSuperChangedPosition() ;
2193 node
= node
->Next();
2197 bool wxWindowMac::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2199 if ( window
== NULL
)
2205 ::GetPort(&currPort
);
2206 port
= UMAGetWindowPort( window
) ;
2207 if (currPort
!= port
)
2210 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2211 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2215 bool wxWindowMac::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2217 if ( window
== NULL
)
2222 ::GetPort(&currPort
);
2223 port
= UMAGetWindowPort( window
) ;
2224 if (currPort
!= port
)
2226 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2227 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2228 ::ClipRect(&clipRect
);
2231 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2232 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2233 Pattern whiteColor
;
2235 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2236 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2240 void wxWindowMac::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2242 if ( m_macWindowData
)
2248 clipRect
->right
= m_width
;
2249 clipRect
->bottom
= m_height
;
2250 *window
= m_macWindowData
->m_macWindow
;
2255 wxASSERT( GetParent() != NULL
) ;
2256 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2257 localOrigin
->h
+= m_x
;
2258 localOrigin
->v
+= m_y
;
2259 OffsetRect(clipRect
, -m_x
, -m_y
);
2264 myClip
.right
= m_width
;
2265 myClip
.bottom
= m_height
;
2266 SectRect(clipRect
, &myClip
, clipRect
);
2270 void wxWindowMac::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2272 // int width , height ;
2273 // GetClientSize( &width , &height ) ;
2275 if ( m_macWindowData
)
2281 clipRect
->right
= m_width
;//width;
2282 clipRect
->bottom
= m_height
;// height;
2283 *window
= m_macWindowData
->m_macWindow
;
2288 wxASSERT( GetParent() != NULL
) ;
2290 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2292 localOrigin
->h
+= m_x
;
2293 localOrigin
->v
+= m_y
;
2294 OffsetRect(clipRect
, -m_x
, -m_y
);
2299 myClip
.right
= m_width
;//width;
2300 myClip
.bottom
= m_height
;// height;
2301 SectRect(clipRect
, &myClip
, clipRect
);
2305 void wxWindowMac::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2307 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2309 int width
, height
;
2310 GetClientSize( &width
, &height
) ;
2312 client
= GetClientAreaOrigin( ) ;
2314 localOrigin
->h
+= client
.x
;
2315 localOrigin
->v
+= client
.y
;
2316 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2321 myClip
.right
= width
;
2322 myClip
.bottom
= height
;
2323 SectRect(clipRect
, &myClip
, clipRect
);
2326 long wxWindowMac::MacGetLeftBorderSize( ) const
2328 if( m_macWindowData
)
2331 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2335 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2339 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2346 long wxWindowMac::MacGetRightBorderSize( ) const
2348 if( m_macWindowData
)
2351 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2355 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2359 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2366 long wxWindowMac::MacGetTopBorderSize( ) const
2368 if( m_macWindowData
)
2371 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2375 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2379 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2386 long wxWindowMac::MacGetBottomBorderSize( ) const
2388 if( m_macWindowData
)
2391 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2395 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2399 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2406 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2408 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2412 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac
* theWindow
)
2418 wxWindowMac
*rootwin
;
2419 m_currentPort
= NULL
;
2421 GetPort( &m_formerPort
) ;
2424 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2425 m_currentPort
= UMAGetWindowPort( window
) ;
2426 if ( m_formerPort
!= m_currentPort
)
2427 SetPort( m_currentPort
) ;
2428 GetPenState( &m_savedPenState
) ;
2429 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2434 wxMacDrawingHelper::~wxMacDrawingHelper()
2438 SetPort( m_currentPort
) ;
2439 SetPenState( &m_savedPenState
) ;
2440 SetOrigin( 0 , 0 ) ;
2442 GetPortBounds( m_currentPort
, &portRect
) ;
2443 ClipRect( &portRect
) ;
2446 if ( m_formerPort
!= m_currentPort
)
2447 SetPort( m_formerPort
) ;
2450 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac
* theWindow
)
2456 wxWindowMac
*rootwin
;
2457 m_currentPort
= NULL
;
2459 GetPort( &m_formerPort
) ;
2463 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2464 m_currentPort
= UMAGetWindowPort( window
) ;
2465 if ( m_formerPort
!= m_currentPort
)
2466 SetPort( m_currentPort
) ;
2467 GetPenState( &m_savedPenState
) ;
2468 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2473 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2477 SetPort( m_currentPort
) ;
2478 SetPenState( &m_savedPenState
) ;
2479 SetOrigin( 0 , 0 ) ;
2481 GetPortBounds( m_currentPort
, &portRect
) ;
2482 ClipRect( &portRect
) ;
2485 if ( m_formerPort
!= m_currentPort
)
2486 SetPort( m_formerPort
) ;
2489 // Find the wxWindowMac at the current mouse position, returning the mouse
2491 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2493 pt
= wxGetMousePosition();
2494 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2498 // Get the current mouse position.
2499 wxPoint
wxGetMousePosition()
2502 wxGetMousePosition(& x
, & y
);
2503 return wxPoint(x
, y
);