1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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"
38 #include "wx/spinctrl.h"
40 #include "wx/geometry.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if wxUSE_DRAG_AND_DROP
62 extern wxList wxPendingDelete
;
63 wxWindowMac
* gFocusWindow
= NULL
;
65 #ifdef __WXUNIVERSAL__
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
69 #endif // __WXUNIVERSAL__/__WXMAC__
71 #if !USE_SHARED_LIBRARY
73 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
74 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
75 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
76 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
77 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
78 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
79 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
89 #define wxMAC_USE_THEME_BORDER 0
92 // ===========================================================================
94 // ===========================================================================
97 // ----------------------------------------------------------------------------
98 // constructors and such
99 // ----------------------------------------------------------------------------
101 void wxWindowMac::Init()
103 m_backgroundTransparent
= FALSE
;
105 // as all windows are created with WS_VISIBLE style...
113 m_hScrollBar
= NULL
;
114 m_vScrollBar
= NULL
;
118 wxWindowMac::~wxWindowMac()
122 // deleting a window while it is shown invalidates the region
124 wxWindowMac
* iter
= this ;
126 if ( iter
->IsTopLevel() )
131 iter
= iter
->GetParent() ;
136 m_isBeingDeleted
= TRUE
;
138 #ifndef __WXUNIVERSAL__
139 // VS: make sure there's no wxFrame with last focus set to us:
140 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
142 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
145 if ( frame
->GetLastFocus() == this )
147 frame
->SetLastFocus((wxWindow
*)NULL
);
152 #endif // __WXUNIVERSAL__
154 if ( s_lastMouseWindow
== this )
156 s_lastMouseWindow
= NULL
;
159 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
162 if ( frame
->GetLastFocus() == this )
163 frame
->SetLastFocus( NULL
) ;
166 if ( gFocusWindow
== this )
168 gFocusWindow
= NULL
;
173 // delete our drop target if we've got one
174 #if wxUSE_DRAG_AND_DROP
175 if ( m_dropTarget
!= NULL
)
180 #endif // wxUSE_DRAG_AND_DROP
184 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
188 const wxString
& name
)
190 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
193 // wxGTK doesn't allow to create controls with static box as the parent so
194 // this will result in a crash when the program is ported to wxGTK - warn
197 // the correct solution is to create the controls as siblings of the
199 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
200 _T("wxStaticBox can't be used as a window parent!") );
201 #endif // wxUSE_STATBOX
203 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
206 parent
->AddChild(this);
210 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
211 m_width
= WidthDefault( size
.x
);
212 m_height
= HeightDefault( size
.y
) ;
213 #ifndef __WXUNIVERSAL__
214 // Don't give scrollbars to wxControls unless they ask for them
215 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
216 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
218 MacCreateScrollBars( style
) ;
222 wxWindowCreateEvent
event(this);
223 GetEventHandler()->AddPendingEvent(event
);
228 void wxWindowMac::SetFocus()
230 if ( gFocusWindow
== this )
233 if ( AcceptsFocus() )
239 if ( gFocusWindow
->m_caret
)
241 gFocusWindow
->m_caret
->OnKillFocus();
243 #endif // wxUSE_CARET
244 #ifndef __WXUNIVERSAL__
245 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
246 if ( control
&& control
->GetMacControl() )
248 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
249 control
->MacRedrawControl() ;
252 // Without testing the window id, for some reason
253 // a kill focus event can still be sent to
254 // the control just being focussed.
255 int thisId
= this->m_windowId
;
256 int gFocusWindowId
= gFocusWindow
->m_windowId
;
257 if (gFocusWindowId
!= thisId
)
259 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
260 event
.SetEventObject(gFocusWindow
);
261 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
264 gFocusWindow
= this ;
270 m_caret
->OnSetFocus();
272 #endif // wxUSE_CARET
273 // panel wants to track the window which was the last to have focus in it
274 wxChildFocusEvent
eventFocus(this);
275 GetEventHandler()->ProcessEvent(eventFocus
);
277 #ifndef __WXUNIVERSAL__
278 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
279 if ( control
&& control
->GetMacControl() )
281 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
284 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
285 event
.SetEventObject(this);
286 GetEventHandler()->ProcessEvent(event
) ;
291 bool wxWindowMac::Enable(bool enable
)
293 if ( !wxWindowBase::Enable(enable
) )
296 MacSuperEnabled( enable
) ;
301 void wxWindowMac::DoCaptureMouse()
303 wxTheApp
->s_captureWindow
= this ;
306 wxWindow
* wxWindowBase::GetCapture()
308 return wxTheApp
->s_captureWindow
;
311 void wxWindowMac::DoReleaseMouse()
313 wxTheApp
->s_captureWindow
= NULL
;
316 #if wxUSE_DRAG_AND_DROP
318 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
320 if ( m_dropTarget
!= 0 ) {
324 m_dropTarget
= pDropTarget
;
325 if ( m_dropTarget
!= 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
352 if ( !IsTopLevel() && GetParent())
354 wxPoint
pt(GetParent()->GetClientAreaOrigin());
363 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
365 menu
->SetInvokingWindow(this);
368 if ( x
== -1 && y
== -1 )
370 wxPoint mouse
= wxGetMousePosition();
371 x
= mouse
.x
; y
= mouse
.y
;
375 ClientToScreen( &x
, &y
) ;
378 menu
->MacBeforeDisplay( true ) ;
379 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
380 if ( HiWord(menuResult
) != 0 )
383 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
384 wxMenuItem
* item
= NULL
;
386 item
= menu
->FindItem(id
, &realmenu
) ;
387 if (item
->IsCheckable())
389 item
->Check( !item
->IsChecked() ) ;
391 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
393 menu
->MacAfterDisplay( true ) ;
395 menu
->SetInvokingWindow(NULL
);
401 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
403 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
405 Point localwhere
= {0,0} ;
407 if(x
) localwhere
.h
= * x
;
408 if(y
) localwhere
.v
= * y
;
412 ::SetPort( UMAGetWindowPort( window
) ) ;
413 ::GlobalToLocal( &localwhere
) ;
416 if(x
) *x
= localwhere
.h
;
417 if(y
) *y
= localwhere
.v
;
419 MacRootWindowToWindow( x
, y
) ;
421 *x
-= MacGetLeftBorderSize() ;
423 *y
-= MacGetTopBorderSize() ;
426 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
428 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
431 *x
+= MacGetLeftBorderSize() ;
433 *y
+= MacGetTopBorderSize() ;
435 MacWindowToRootWindow( x
, y
) ;
437 Point localwhere
= { 0,0 };
438 if(x
) localwhere
.h
= * x
;
439 if(y
) localwhere
.v
= * y
;
443 ::SetPort( UMAGetWindowPort( window
) ) ;
445 ::LocalToGlobal( &localwhere
) ;
447 if(x
) *x
= localwhere
.h
;
448 if(y
) *y
= localwhere
.v
;
451 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
453 wxPoint origin
= GetClientAreaOrigin() ;
454 if(x
) *x
+= origin
.x
;
455 if(y
) *y
+= origin
.y
;
457 MacWindowToRootWindow( x
, y
) ;
460 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
462 wxPoint origin
= GetClientAreaOrigin() ;
463 MacRootWindowToWindow( x
, y
) ;
464 if(x
) *x
-= origin
.x
;
465 if(y
) *y
-= origin
.y
;
468 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
474 GetParent()->MacWindowToRootWindow( x
, y
) ;
478 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
484 GetParent()->MacRootWindowToWindow( x
, y
) ;
488 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
490 if (m_cursor
== cursor
)
493 if (wxNullCursor
== cursor
)
495 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
500 if ( ! wxWindowBase::SetCursor( cursor
) )
504 wxASSERT_MSG( m_cursor
.Ok(),
505 wxT("cursor must be valid after call to the base version"));
508 wxWindowMac
*mouseWin
;
511 // Change the cursor NOW if we're within the correct window
513 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
515 if ( mouseWin
== this && !wxIsBusy() )
517 m_cursor
.MacInstall() ;
525 // Get size *available for subwindows* i.e. excluding menu bar etc.
526 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
532 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
533 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
535 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
542 MacClientToRootWindow( &x1
, &y1
) ;
543 MacClientToRootWindow( &w
, &h
) ;
545 wxWindowMac
*iter
= (wxWindowMac
*)this ;
547 int totW
= 10000 , totH
= 10000;
550 if ( iter
->IsTopLevel() )
552 totW
= iter
->m_width
;
553 totH
= iter
->m_height
;
557 iter
= iter
->GetParent() ;
560 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
562 hh
-= MAC_SCROLLBAR_SIZE
;
568 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
570 ww
-= MAC_SCROLLBAR_SIZE
;
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
588 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
590 wxWindowBase::DoSetToolTip(tooltip
);
593 m_tooltip
->SetWindow(this);
596 #endif // wxUSE_TOOLTIPS
598 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
602 int former_w
= m_width
;
603 int former_h
= m_height
;
605 int actualWidth
= width
;
606 int actualHeight
= height
;
610 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
611 actualWidth
= m_minWidth
;
612 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
613 actualHeight
= m_minHeight
;
614 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
615 actualWidth
= m_maxWidth
;
616 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
617 actualHeight
= m_maxHeight
;
619 bool doMove
= false ;
620 bool doResize
= false ;
622 if ( actualX
!= former_x
|| actualY
!= former_y
)
626 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
631 if ( doMove
|| doResize
)
633 // erase former position
635 bool partialRepaint
= false ;
637 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
639 wxPoint
oldPos( m_x
, m_y
) ;
640 wxPoint
newPos( actualX
, actualY
) ;
641 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
642 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
643 if ( oldPos
== newPos
)
645 partialRepaint
= true ;
646 RgnHandle oldRgn
,newRgn
,diffRgn
;
651 // invalidate the differences between the old and the new area
653 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
654 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
655 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
656 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
657 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
658 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
660 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really
661 // changing pixels...
663 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 ||
664 MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 )
666 RgnHandle innerOldRgn
, innerNewRgn
;
667 innerOldRgn
= NewRgn() ;
668 innerNewRgn
= NewRgn() ;
670 SetRectRgn(innerOldRgn
, oldPos
.x
+ MacGetLeftBorderSize() , oldPos
.y
+ MacGetTopBorderSize() ,
671 oldPos
.x
+ m_width
- MacGetRightBorderSize() , oldPos
.y
+ m_height
- MacGetBottomBorderSize() ) ;
672 DiffRgn( oldRgn
, innerOldRgn
, diffRgn
) ;
673 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
675 SetRectRgn(innerNewRgn
, newPos
.x
+ MacGetLeftBorderSize() , newPos
.y
+ MacGetTopBorderSize() ,
676 newPos
.x
+ actualWidth
- MacGetRightBorderSize() , newPos
.y
+ actualHeight
- MacGetBottomBorderSize() ) ;
677 DiffRgn( newRgn
, innerNewRgn
, diffRgn
) ;
678 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
680 DisposeRgn( innerOldRgn
) ;
681 DisposeRgn( innerNewRgn
) ;
686 DisposeRgn(diffRgn
) ;
690 if ( !partialRepaint
)
695 m_width
= actualWidth
;
696 m_height
= actualHeight
;
698 // update any low-level frame-relative positions
700 MacUpdateDimensions() ;
701 // erase new position
703 if ( !partialRepaint
)
706 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
708 MacRepositionScrollBars() ;
711 wxPoint
point(m_x
, m_y
);
712 wxMoveEvent
event(point
, m_windowId
);
713 event
.SetEventObject(this);
714 GetEventHandler()->ProcessEvent(event
) ;
718 MacRepositionScrollBars() ;
719 wxSize
size(m_width
, m_height
);
720 wxSizeEvent
event(size
, m_windowId
);
721 event
.SetEventObject(this);
722 GetEventHandler()->ProcessEvent(event
);
728 // set the size of the window: if the dimensions are positive, just use them,
729 // but if any of them is equal to -1, it means that we must find the value for
730 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
731 // which case -1 is a valid value for x and y)
733 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
734 // the width/height to best suit our contents, otherwise we reuse the current
736 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
738 // get the current size and position...
739 int currentX
, currentY
;
740 GetPosition(¤tX
, ¤tY
);
742 int currentW
,currentH
;
743 GetSize(¤tW
, ¤tH
);
745 // ... and don't do anything (avoiding flicker) if it's already ok
746 if ( x
== currentX
&& y
== currentY
&&
747 width
== currentW
&& height
== currentH
)
749 MacRepositionScrollBars() ; // we might have a real position shift
753 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
755 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
758 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
763 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
765 size
= DoGetBestSize();
770 // just take the current one
777 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
781 size
= DoGetBestSize();
783 //else: already called DoGetBestSize() above
789 // just take the current one
794 DoMoveWindow(x
, y
, width
, height
);
797 // For implementation purposes - sometimes decorations make the client area
800 wxPoint
wxWindowMac::GetClientAreaOrigin() const
802 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
805 void wxWindowMac::SetTitle(const wxString
& title
)
810 wxString
wxWindowMac::GetTitle() const
815 bool wxWindowMac::Show(bool show
)
817 if ( !wxWindowBase::Show(show
) )
820 MacSuperShown( show
) ;
826 void wxWindowMac::MacSuperShown( bool show
)
828 wxWindowListNode
*node
= GetChildren().GetFirst();
831 wxWindowMac
*child
= node
->GetData();
832 if ( child
->m_isShown
)
833 child
->MacSuperShown( show
) ;
834 node
= node
->GetNext();
838 void wxWindowMac::MacSuperEnabled( bool enabled
)
842 // to be absolutely correct we'd have to invalidate (with eraseBkground
843 // because unter MacOSX the frames are drawn with an addXXX mode)
846 wxWindowListNode
*node
= GetChildren().GetFirst();
849 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
850 if ( child
->m_isShown
)
851 child
->MacSuperEnabled( enabled
) ;
852 node
= node
->GetNext();
856 bool wxWindowMac::MacIsReallyShown() const
858 if ( m_isShown
&& (m_parent
!= NULL
&& !IsTopLevel() ) ) {
859 return m_parent
->MacIsReallyShown();
863 bool status = m_isShown ;
864 wxWindowMac * win = this ;
865 while ( status && win->m_parent != NULL )
867 win = win->m_parent ;
868 status = win->m_isShown ;
874 int wxWindowMac::GetCharHeight() const
876 wxClientDC
dc ( (wxWindowMac
*)this ) ;
877 return dc
.GetCharHeight() ;
880 int wxWindowMac::GetCharWidth() const
882 wxClientDC
dc ( (wxWindowMac
*)this ) ;
883 return dc
.GetCharWidth() ;
886 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
887 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
889 const wxFont
*fontToUse
= theFont
;
893 wxClientDC
dc( (wxWindowMac
*) this ) ;
895 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
896 if ( externalLeading
)
897 *externalLeading
= le
;
907 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
908 * we always intersect with the entire window, not only with the client area
911 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
913 if ( MacGetTopLevelWindow() == NULL
)
916 if ( !MacIsReallyShown() )
919 wxPoint client
= GetClientAreaOrigin();
922 int x2
= m_width
- client
.x
;
923 int y2
= m_height
- client
.y
;
925 if (IsKindOf( CLASSINFO(wxButton
)))
927 // buttons have an "aura"
934 Rect clientrect
= { y1
, x1
, y2
, x2
};
938 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
939 SectRect( &clientrect
, &r
, &clientrect
) ;
942 if ( !EmptyRect( &clientrect
) )
944 int top
= 0 , left
= 0 ;
946 MacClientToRootWindow( &left
, &top
) ;
947 OffsetRect( &clientrect
, left
, top
) ;
949 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
953 wxWindowMac
*wxGetActiveWindow()
955 // actually this is a windows-only concept
959 // Coordinates relative to the window
960 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
962 // We really don't move the mouse programmatically under Mac.
965 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
967 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
969 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
971 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
973 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
974 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
975 // either a non gray background color or a non control window
977 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
979 wxWindowMac
* parent
= GetParent() ;
982 if ( parent
->MacGetRootWindow() != window
)
984 // we are in a different window on the mac system
990 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
991 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
993 // if we have any other colours in the hierarchy
994 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
997 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
998 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1000 Rect extent
= { 0 , 0 , 0 , 0 } ;
1003 wxSize size
= parent
->GetSize() ;
1004 parent
->MacClientToRootWindow( &x
, &y
) ;
1008 extent
.right
= x
+ size
.x
;
1009 extent
.bottom
= y
+ size
.y
;
1010 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1014 parent
= parent
->GetParent() ;
1018 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1023 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1026 return m_macBackgroundBrush
;
1029 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1031 event
.GetDC()->Clear() ;
1034 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1036 wxWindowDC
dc(this) ;
1037 wxMacPortSetter
helper(&dc
) ;
1039 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1042 int wxWindowMac::GetScrollPos(int orient
) const
1044 if ( orient
== wxHORIZONTAL
)
1047 return m_hScrollBar
->GetThumbPosition() ;
1052 return m_vScrollBar
->GetThumbPosition() ;
1057 // This now returns the whole range, not just the number
1058 // of positions that we can scroll.
1059 int wxWindowMac::GetScrollRange(int orient
) const
1061 if ( orient
== wxHORIZONTAL
)
1064 return m_hScrollBar
->GetRange() ;
1069 return m_vScrollBar
->GetRange() ;
1074 int wxWindowMac::GetScrollThumb(int orient
) const
1076 if ( orient
== wxHORIZONTAL
)
1079 return m_hScrollBar
->GetThumbSize() ;
1084 return m_vScrollBar
->GetThumbSize() ;
1089 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1091 if ( orient
== wxHORIZONTAL
)
1094 m_hScrollBar
->SetThumbPosition( pos
) ;
1099 m_vScrollBar
->SetThumbPosition( pos
) ;
1103 void wxWindowMac::MacPaintBorders( int left
, int top
)
1109 wxGetOsVersion( &major
, &minor
);
1111 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1112 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1114 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1115 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1116 // OS X has lighter border edges than classic:
1119 darkShadow
.red
= 0x8E8E;
1120 darkShadow
.green
= 0x8E8E;
1121 darkShadow
.blue
= 0x8E8E;
1122 lightShadow
.red
= 0xBDBD;
1123 lightShadow
.green
= 0xBDBD;
1124 lightShadow
.blue
= 0xBDBD;
1129 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1131 #if wxMAC_USE_THEME_BORDER
1132 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1135 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1136 InsetRect( &rect , border , border );
1137 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1140 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1142 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1143 RGBForeColor( &face
);
1144 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1145 LineTo( left
+ 0 , top
+ 0 );
1146 LineTo( left
+ m_width
- 2 , top
+ 0 );
1148 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1149 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1150 LineTo( left
+ m_width
- 3 , top
+ 2 );
1152 RGBForeColor( sunken
? &face
: &darkShadow
);
1153 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1154 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1155 LineTo( left
+ m_width
- 1 , top
+ 0 );
1157 RGBForeColor( sunken
? &lightShadow
: &white
);
1158 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1159 LineTo( left
+ 1, top
+ 1 );
1160 LineTo( left
+ m_width
- 3 , top
+ 1 );
1162 RGBForeColor( sunken
? &white
: &lightShadow
);
1163 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1164 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1165 LineTo( left
+ m_width
- 2 , top
+ 1 );
1167 RGBForeColor( sunken
? &darkShadow
: &face
);
1168 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1169 LineTo( left
+ 2 , top
+ 2 );
1170 LineTo( left
+ m_width
- 4 , top
+ 2 );
1173 else if (HasFlag(wxSIMPLE_BORDER
))
1175 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1176 RGBForeColor( &darkShadow
) ;
1177 FrameRect( &rect
) ;
1181 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1183 if ( child
== m_hScrollBar
)
1184 m_hScrollBar
= NULL
;
1185 if ( child
== m_vScrollBar
)
1186 m_vScrollBar
= NULL
;
1188 wxWindowBase::RemoveChild( child
) ;
1191 // New function that will replace some of the above.
1192 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1193 int range
, bool refresh
)
1195 if ( orient
== wxHORIZONTAL
)
1199 if ( range
== 0 || thumbVisible
>= range
)
1201 if ( m_hScrollBar
->IsShown() )
1202 m_hScrollBar
->Show(false) ;
1206 if ( !m_hScrollBar
->IsShown() )
1207 m_hScrollBar
->Show(true) ;
1208 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1216 if ( range
== 0 || thumbVisible
>= range
)
1218 if ( m_vScrollBar
->IsShown() )
1219 m_vScrollBar
->Show(false) ;
1223 if ( !m_vScrollBar
->IsShown() )
1224 m_vScrollBar
->Show(true) ;
1225 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1229 MacRepositionScrollBars() ;
1232 // Does a physical scroll
1233 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1235 if( dx
== 0 && dy
==0 )
1240 wxClientDC
dc(this) ;
1241 wxMacPortSetter
helper(&dc
) ;
1243 int width
, height
;
1244 GetClientSize( &width
, &height
) ;
1246 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1247 RgnHandle updateRgn
= NewRgn() ;
1248 ClipRect( &scrollrect
) ;
1251 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1252 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1253 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1255 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1256 // we also have to scroll the update rgn in this rectangle
1257 // in order not to loose updates
1258 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1259 RgnHandle formerUpdateRgn
= NewRgn() ;
1260 RgnHandle scrollRgn
= NewRgn() ;
1261 RectRgn( scrollRgn
, &scrollrect
) ;
1262 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1264 LocalToGlobal( &pt
) ;
1265 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1266 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1267 if ( !EmptyRgn( formerUpdateRgn
) )
1269 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1270 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1271 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1273 InvalWindowRgn(rootWindow
, updateRgn
) ;
1274 DisposeRgn( updateRgn
) ;
1275 DisposeRgn( formerUpdateRgn
) ;
1276 DisposeRgn( scrollRgn
) ;
1279 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1281 wxWindowMac
*child
= node
->GetData();
1282 if (child
== m_vScrollBar
) continue;
1283 if (child
== m_hScrollBar
) continue;
1284 if (child
->IsTopLevel()) continue;
1287 child
->GetPosition( &x
, &y
);
1289 child
->GetSize( &w
, &h
);
1293 if (rect
->Intersects(rc
))
1294 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1298 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1306 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1308 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1310 wxScrollWinEvent wevent
;
1311 wevent
.SetPosition(event
.GetPosition());
1312 wevent
.SetOrientation(event
.GetOrientation());
1313 wevent
.m_eventObject
= this;
1315 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
1316 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1317 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
1318 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1319 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
1320 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1321 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
1322 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1323 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
1324 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1325 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
1326 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1327 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
1328 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1329 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
1330 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1332 GetEventHandler()->ProcessEvent(wevent
);
1336 // Get the window with the focus
1337 wxWindowMac
*wxWindowBase::FindFocus()
1339 return gFocusWindow
;
1342 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1344 // panel wants to track the window which was the last to have focus in it,
1345 // so we want to set ourselves as the window which last had focus
1347 // notice that it's also important to do it upwards the tree becaus
1348 // otherwise when the top level panel gets focus, it won't set it back to
1349 // us, but to some other sibling
1351 // CS:don't know if this is still needed:
1352 //wxChildFocusEvent eventFocus(this);
1353 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1358 // Setup background and foreground colours correctly
1359 void wxWindowMac::SetupColours()
1362 SetBackgroundColour(GetParent()->GetBackgroundColour());
1365 void wxWindowMac::OnInternalIdle()
1367 // This calls the UI-update mechanism (querying windows for
1368 // menu/toolbar/control state information)
1369 if (wxUpdateUIEvent::CanUpdate(this))
1370 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1373 // Raise the window to the top of the Z order
1374 void wxWindowMac::Raise()
1378 // Lower the window to the bottom of the Z order
1379 void wxWindowMac::Lower()
1383 void wxWindowMac::DoSetClientSize(int width
, int height
)
1385 if ( width
!= -1 || height
!= -1 )
1388 if ( width
!= -1 && m_vScrollBar
)
1389 width
+= MAC_SCROLLBAR_SIZE
;
1390 if ( height
!= -1 && m_vScrollBar
)
1391 height
+= MAC_SCROLLBAR_SIZE
;
1393 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1394 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1396 DoSetSize( -1 , -1 , width
, height
) ;
1401 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1403 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1407 if ((point
.x
< 0) || (point
.y
< 0) ||
1408 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1413 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1414 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1418 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1420 wxPoint
newPoint( point
) ;
1422 if ( !IsTopLevel() )
1428 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1430 wxWindowMac
*child
= node
->GetData();
1431 // added the m_isShown test --dmazzoni
1432 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1434 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1443 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1447 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1448 if ( ::FindWindow( pt
, &window
) == 3 )
1451 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1454 // No, this yields the CLIENT are, we need the whole frame. RR.
1455 // point = win->ScreenToClient( point ) ;
1458 ::GetPort( &port
) ;
1459 ::SetPort( UMAGetWindowPort( window
) ) ;
1460 ::GlobalToLocal( &pt
) ;
1463 wxPoint
point( pt
.h
, pt
.v
) ;
1465 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1471 static wxWindow
*gs_lastWhich
= NULL
;
1473 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1475 // first trigger a set cursor event
1477 wxPoint clientorigin
= GetClientAreaOrigin() ;
1478 wxSize clientsize
= GetClientSize() ;
1480 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1482 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1484 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1485 if ( processedEvtSetCursor
&& event
.HasCursor() )
1487 cursor
= event
.GetCursor() ;
1492 // the test for processedEvtSetCursor is here to prevent using m_cursor
1493 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1494 // it - this is a way to say that our cursor shouldn't be used for this
1496 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1506 cursor
= *wxSTANDARD_CURSOR
;
1510 cursor
.MacInstall() ;
1512 return cursor
.Ok() ;
1515 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1517 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1518 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1522 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1525 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1533 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1535 wxWindowMac
*child
= node
->GetData();
1536 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1538 if (child
->MacDispatchMouseEvent(event
))
1543 wxWindow
* cursorTarget
= this ;
1544 wxPoint
cursorPoint( x
, y
) ;
1546 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1548 cursorTarget
= cursorTarget
->GetParent() ;
1550 cursorPoint
+= cursorTarget
->GetPosition() ;
1554 event
.SetEventObject( this ) ;
1556 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1558 // set focus to this window
1559 if (AcceptsFocus() && FindFocus()!=this)
1564 if ( event
.GetEventType() == wxEVT_MOTION
1565 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1566 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1567 wxToolTip::RelayEvent( this , event
);
1568 #endif // wxUSE_TOOLTIPS
1570 if (gs_lastWhich
!= this)
1572 gs_lastWhich
= this;
1574 // Double clicks must always occur on the same window
1575 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1576 event
.SetEventType( wxEVT_LEFT_DOWN
);
1577 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1578 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1580 // Same for mouse up events
1581 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1583 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1587 GetEventHandler()->ProcessEvent( event
) ;
1592 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1596 return m_tooltip
->GetTip() ;
1598 return wxEmptyString
;
1601 void wxWindowMac::Update()
1603 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1604 int top
= 0 , left
= 0 ;
1605 MacWindowToRootWindow( &left
, &top
) ;
1606 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1607 RgnHandle updateRgn
= NewRgn() ;
1608 // getting the update region in macos local coordinates
1609 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1611 ::GetPort( &port
) ;
1612 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1614 LocalToGlobal( &pt
) ;
1616 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1617 // translate to window local coordinates
1618 OffsetRgn( updateRgn
, -left
, -top
) ;
1619 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1620 MacRedraw( updateRgn
, 0 , true ) ;
1621 // for flushing and validating we need macos-local coordinates again
1622 OffsetRgn( updateRgn
, left
, top
) ;
1623 #if TARGET_API_MAC_CARBON
1624 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1626 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1629 ValidWindowRgn( rootWindow
, updateRgn
) ;
1630 DisposeRgn( updateRgn
) ;
1633 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1635 wxTopLevelWindowMac
* win
= NULL
;
1636 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1639 win
= wxFindWinFromMacWindow( window
) ;
1644 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1646 RgnHandle visRgn
= NewRgn() ;
1647 RgnHandle tempRgn
= NewRgn() ;
1648 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1650 if ( MacIsReallyShown() )
1652 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1654 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1655 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1657 int borderTop
= 14 ;
1658 int borderOther
= 4 ;
1659 if ( UMAGetSystemVersion() >= 0x1030 )
1662 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1663 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1666 if ( !IsTopLevel() )
1668 wxWindow
* parent
= GetParent() ;
1671 wxSize size
= parent
->GetSize() ;
1674 parent
->MacWindowToRootWindow( &x
, &y
) ;
1675 MacRootWindowToWindow( &x
, &y
) ;
1677 SetRectRgn( tempRgn
,
1678 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1679 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1680 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1682 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1683 if ( parent
->IsTopLevel() )
1685 parent
= parent
->GetParent() ;
1688 if ( respectChildrenAndSiblings
)
1690 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1692 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1694 wxWindowMac
*child
= node
->GetData();
1696 if ( !child
->IsTopLevel() && child
->IsShown() )
1698 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1699 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1701 int borderTop
= 14 ;
1702 int borderOther
= 4 ;
1703 if ( UMAGetSystemVersion() >= 0x1030 )
1706 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1707 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1709 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1714 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1716 bool thisWindowThrough
= false ;
1717 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1719 wxWindowMac
*sibling
= node
->GetData();
1720 if ( sibling
== this )
1722 thisWindowThrough
= true ;
1725 if( !thisWindowThrough
)
1730 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1732 SetRectRgn( tempRgn
, sibling
->m_x
- m_x
, sibling
->m_y
- m_y
, sibling
->m_x
+ sibling
->m_width
- m_x
, sibling
->m_y
+ sibling
->m_height
- m_y
) ;
1733 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1735 int borderTop
= 14 ;
1736 int borderOther
= 4 ;
1737 if ( UMAGetSystemVersion() >= 0x1030 )
1740 SetRectRgn( tempStaticBoxRgn
, sibling
->m_x
- m_x
+ borderOther
, sibling
->m_y
- m_y
+ borderTop
, sibling
->m_x
+ sibling
->m_width
- m_x
- borderOther
, sibling
->m_y
+ sibling
->m_height
- m_y
- borderOther
) ;
1741 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1743 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1749 m_macVisibleRegion
= visRgn
;
1750 DisposeRgn( visRgn
) ;
1751 DisposeRgn( tempRgn
) ;
1752 DisposeRgn( tempStaticBoxRgn
) ;
1753 return m_macVisibleRegion
;
1756 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1758 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1759 // updatergn is always already clipped to our boundaries
1760 // it is in window coordinates, not in client coordinates
1762 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1765 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1766 RgnHandle ownUpdateRgn
= NewRgn() ;
1767 CopyRgn( updatergn
, ownUpdateRgn
) ;
1769 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1771 // newupdate is the update region in client coordinates
1772 RgnHandle newupdate
= NewRgn() ;
1773 wxSize point
= GetClientSize() ;
1774 wxPoint origin
= GetClientAreaOrigin() ;
1775 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1776 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1777 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1778 m_updateRegion
= newupdate
;
1779 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1781 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1783 wxWindowDC
dc(this);
1784 if (!EmptyRgn(ownUpdateRgn
))
1785 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1786 wxEraseEvent
eevent( GetId(), &dc
);
1787 eevent
.SetEventObject( this );
1788 GetEventHandler()->ProcessEvent( eevent
);
1790 wxNcPaintEvent
eventNc( GetId() );
1791 eventNc
.SetEventObject( this );
1792 GetEventHandler()->ProcessEvent( eventNc
);
1794 DisposeRgn( ownUpdateRgn
) ;
1795 if ( !m_updateRegion
.Empty() )
1797 wxWindowList hiddenWindows
;
1798 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1800 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1802 if ( child
&& child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->GetMacControl() )
1804 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1805 hiddenWindows
.Append( child
) ;
1810 event
.m_timeStamp
= time
;
1811 event
.SetEventObject(this);
1812 GetEventHandler()->ProcessEvent(event
);
1814 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1816 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1818 if ( child
&& child
->GetMacControl() )
1820 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1826 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1828 RgnHandle childupdate
= NewRgn() ;
1829 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1831 // calculate the update region for the child windows by intersecting the window rectangle with our own
1832 // passed in update region and then offset it to be client-wise window coordinates again
1833 wxWindowMac
*child
= node
->GetData();
1834 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1835 SectRgn( childupdate
, updatergn
, childupdate
) ;
1836 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1837 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1839 // because dialogs may also be children
1840 child
->MacRedraw( childupdate
, time
, erase
) ;
1843 DisposeRgn( childupdate
) ;
1844 // eventually a draw grow box here
1848 WXHWND
wxWindowMac::MacGetRootWindow() const
1850 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1854 if ( iter
->IsTopLevel() )
1855 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1857 iter
= iter
->GetParent() ;
1859 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1863 void wxWindowMac::MacCreateScrollBars( long style
)
1865 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1867 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1868 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1870 GetClientSize( &width
, &height
) ;
1872 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1873 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1874 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1875 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1877 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1878 vSize
, wxVERTICAL
);
1880 if ( style
& wxVSCROLL
)
1886 m_vScrollBar
->Show(false) ;
1888 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1889 hSize
, wxHORIZONTAL
);
1890 if ( style
& wxHSCROLL
)
1895 m_hScrollBar
->Show(false) ;
1898 // because the create does not take into account the client area origin
1899 MacRepositionScrollBars() ; // we might have a real position shift
1902 void wxWindowMac::MacRepositionScrollBars()
1904 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1905 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1907 // get real client area
1909 int width
= m_width
;
1910 int height
= m_height
;
1912 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1913 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1915 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1916 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1917 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1918 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1925 MacClientToRootWindow( &x
, &y
) ;
1926 MacClientToRootWindow( &w
, &h
) ;
1928 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1930 int totW
= 10000 , totH
= 10000;
1933 if ( iter
->IsTopLevel() )
1935 totW
= iter
->m_width
;
1936 totH
= iter
->m_height
;
1940 iter
= iter
->GetParent() ;
1968 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1972 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1976 bool wxWindowMac::AcceptsFocus() const
1978 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1981 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1983 return GetParent()->MacGetContainerForEmbedding() ;
1986 void wxWindowMac::MacSuperChangedPosition()
1988 // only window-absolute structures have to be moved i.e. controls
1990 wxWindowListNode
*node
= GetChildren().GetFirst();
1993 wxWindowMac
*child
= node
->GetData();
1994 child
->MacSuperChangedPosition() ;
1995 node
= node
->GetNext();
1999 void wxWindowMac::MacTopLevelWindowChangedPosition()
2001 // only screen-absolute structures have to be moved i.e. glcanvas
2003 wxWindowListNode
*node
= GetChildren().GetFirst();
2006 wxWindowMac
*child
= node
->GetData();
2007 child
->MacTopLevelWindowChangedPosition() ;
2008 node
= node
->GetNext();
2011 long wxWindowMac::MacGetLeftBorderSize( ) const
2016 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2019 #if wxMAC_USE_THEME_BORDER
2021 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2026 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2029 #if wxMAC_USE_THEME_BORDER
2031 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2036 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2043 long wxWindowMac::MacGetRightBorderSize( ) const
2045 // they are all symmetric in mac themes
2046 return MacGetLeftBorderSize() ;
2049 long wxWindowMac::MacGetTopBorderSize( ) const
2051 // they are all symmetric in mac themes
2052 return MacGetLeftBorderSize() ;
2055 long wxWindowMac::MacGetBottomBorderSize( ) const
2057 // they are all symmetric in mac themes
2058 return MacGetLeftBorderSize() ;
2061 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2063 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2066 // Find the wxWindowMac at the current mouse position, returning the mouse
2068 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2070 pt
= wxGetMousePosition();
2071 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2075 // Get the current mouse position.
2076 wxPoint
wxGetMousePosition()
2079 wxGetMousePosition(& x
, & y
);
2080 return wxPoint(x
, y
);
2083 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2085 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2087 // copied from wxGTK : CS
2088 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2091 // (a) it's a command event and so is propagated to the parent
2092 // (b) under MSW it can be generated from kbd too
2093 // (c) it uses screen coords (because of (a))
2094 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2096 this->ClientToScreen(event
.GetPosition()));
2097 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )