1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
25 #include "wx/dcclient.h"
26 #include "wx/layout.h"
27 #include "wx/dialog.h"
28 #include "wx/listbox.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/button.h"
32 #include "wx/settings.h"
33 #include "wx/msgdlg.h"
35 #include "wx/notebook.h"
36 #include "wx/tabctrl.h"
37 #include "wx/tooltip.h"
38 #include "wx/statusbr.h"
39 #include "wx/menuitem.h"
40 #include "wx/spinctrl.h"
41 #include "wx/geometry.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
49 #define MAC_SCROLLBAR_SIZE 16
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
57 #if wxUSE_DRAG_AND_DROP
63 extern wxList wxPendingDelete
;
64 wxWindowMac
* gFocusWindow
= NULL
;
66 #ifdef __WXUNIVERSAL__
67 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
70 #endif // __WXUNIVERSAL__/__WXMAC__
72 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
73 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
74 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
75 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
76 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
79 #define wxMAC_DEBUG_REDRAW 0
80 #ifndef wxMAC_DEBUG_REDRAW
81 #define wxMAC_DEBUG_REDRAW 0
84 #define wxMAC_USE_THEME_BORDER 0
87 // ===========================================================================
89 // ===========================================================================
92 // ----------------------------------------------------------------------------
93 // constructors and such
94 // ----------------------------------------------------------------------------
96 void wxWindowMac::Init()
98 m_backgroundTransparent
= false;
100 // as all windows are created with WS_VISIBLE style...
108 m_hScrollBar
= NULL
;
109 m_vScrollBar
= NULL
;
113 wxWindowMac::~wxWindowMac()
117 // deleting a window while it is shown invalidates the region
119 wxWindowMac
* iter
= this ;
121 if ( iter
->IsTopLevel() )
126 iter
= iter
->GetParent() ;
131 m_isBeingDeleted
= true;
133 #ifndef __WXUNIVERSAL__
134 // VS: make sure there's no wxFrame with last focus set to us:
135 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
137 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
140 if ( frame
->GetLastFocus() == this )
142 frame
->SetLastFocus((wxWindow
*)NULL
);
147 #endif // __WXUNIVERSAL__
149 if ( s_lastMouseWindow
== this )
151 s_lastMouseWindow
= NULL
;
154 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
157 if ( frame
->GetLastFocus() == this )
158 frame
->SetLastFocus( NULL
) ;
161 if ( gFocusWindow
== this )
163 gFocusWindow
= NULL
;
168 // delete our drop target if we've got one
169 #if wxUSE_DRAG_AND_DROP
170 if ( m_dropTarget
!= NULL
)
175 #endif // wxUSE_DRAG_AND_DROP
179 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
183 const wxString
& name
)
185 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
188 // wxGTK doesn't allow to create controls with static box as the parent so
189 // this will result in a crash when the program is ported to wxGTK - warn
192 // the correct solution is to create the controls as siblings of the
194 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
195 _T("wxStaticBox can't be used as a window parent!") );
196 #endif // wxUSE_STATBOX
198 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
201 parent
->AddChild(this);
205 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
206 m_width
= WidthDefault( size
.x
);
207 m_height
= HeightDefault( size
.y
) ;
208 #ifndef __WXUNIVERSAL__
209 // Don't give scrollbars to wxControls unless they ask for them
210 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
211 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
213 MacCreateScrollBars( style
) ;
217 wxWindowCreateEvent
event(this);
218 GetEventHandler()->AddPendingEvent(event
);
223 void wxWindowMac::SetFocus()
225 if ( gFocusWindow
== this )
228 if ( AcceptsFocus() )
234 if ( gFocusWindow
->m_caret
)
236 gFocusWindow
->m_caret
->OnKillFocus();
238 #endif // wxUSE_CARET
239 #ifndef __WXUNIVERSAL__
240 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
241 if ( control
&& control
->GetMacControl() )
243 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
244 control
->MacRedrawControl() ;
247 // Without testing the window id, for some reason
248 // a kill focus event can still be sent to
249 // the control just being focussed.
250 int thisId
= this->m_windowId
;
251 int gFocusWindowId
= gFocusWindow
->m_windowId
;
252 if (gFocusWindowId
!= thisId
)
254 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
255 event
.SetEventObject(gFocusWindow
);
256 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
259 gFocusWindow
= this ;
265 m_caret
->OnSetFocus();
267 #endif // wxUSE_CARET
268 // panel wants to track the window which was the last to have focus in it
269 wxChildFocusEvent
eventFocus(this);
270 GetEventHandler()->ProcessEvent(eventFocus
);
272 #ifndef __WXUNIVERSAL__
273 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
274 if ( control
&& control
->GetMacControl() )
276 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
279 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
280 event
.SetEventObject(this);
281 GetEventHandler()->ProcessEvent(event
) ;
286 bool wxWindowMac::Enable(bool enable
)
288 if ( !wxWindowBase::Enable(enable
) )
291 MacSuperEnabled( enable
) ;
296 void wxWindowMac::DoCaptureMouse()
298 wxTheApp
->s_captureWindow
= this ;
301 wxWindow
* wxWindowBase::GetCapture()
303 return wxTheApp
->s_captureWindow
;
306 void wxWindowMac::DoReleaseMouse()
308 wxTheApp
->s_captureWindow
= NULL
;
311 #if wxUSE_DRAG_AND_DROP
313 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
315 if ( m_dropTarget
!= 0 ) {
319 m_dropTarget
= pDropTarget
;
320 if ( m_dropTarget
!= 0 )
328 // Old style file-manager drag&drop
329 void wxWindowMac::DragAcceptFiles(bool accept
)
335 void wxWindowMac::DoGetSize(int *x
, int *y
) const
338 if(y
) *y
= m_height
;
341 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
347 if ( !IsTopLevel() && GetParent())
349 wxPoint
pt(GetParent()->GetClientAreaOrigin());
358 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
360 menu
->SetInvokingWindow(this);
363 if ( x
== -1 && y
== -1 )
365 wxPoint mouse
= wxGetMousePosition();
366 x
= mouse
.x
; y
= mouse
.y
;
370 ClientToScreen( &x
, &y
) ;
373 menu
->MacBeforeDisplay( true ) ;
374 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
375 if ( HiWord(menuResult
) != 0 )
378 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
379 wxMenuItem
* item
= NULL
;
381 item
= menu
->FindItem(id
, &realmenu
) ;
382 if (item
->IsCheckable())
384 item
->Check( !item
->IsChecked() ) ;
386 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
388 menu
->MacAfterDisplay( true ) ;
390 menu
->SetInvokingWindow(NULL
);
396 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
398 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
400 Point localwhere
= {0,0} ;
402 if(x
) localwhere
.h
= * x
;
403 if(y
) localwhere
.v
= * y
;
407 ::SetPort( UMAGetWindowPort( window
) ) ;
408 ::GlobalToLocal( &localwhere
) ;
411 if(x
) *x
= localwhere
.h
;
412 if(y
) *y
= localwhere
.v
;
414 MacRootWindowToWindow( x
, y
) ;
416 *x
-= MacGetLeftBorderSize() ;
418 *y
-= MacGetTopBorderSize() ;
421 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
423 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
426 *x
+= MacGetLeftBorderSize() ;
428 *y
+= MacGetTopBorderSize() ;
430 MacWindowToRootWindow( x
, y
) ;
432 Point localwhere
= { 0,0 };
433 if(x
) localwhere
.h
= * x
;
434 if(y
) localwhere
.v
= * y
;
438 ::SetPort( UMAGetWindowPort( window
) ) ;
440 ::LocalToGlobal( &localwhere
) ;
442 if(x
) *x
= localwhere
.h
;
443 if(y
) *y
= localwhere
.v
;
446 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
448 wxPoint origin
= GetClientAreaOrigin() ;
449 if(x
) *x
+= origin
.x
;
450 if(y
) *y
+= origin
.y
;
452 MacWindowToRootWindow( x
, y
) ;
455 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
457 wxPoint origin
= GetClientAreaOrigin() ;
458 MacRootWindowToWindow( x
, y
) ;
459 if(x
) *x
-= origin
.x
;
460 if(y
) *y
-= origin
.y
;
463 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
469 GetParent()->MacWindowToRootWindow( x
, y
) ;
473 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
479 GetParent()->MacRootWindowToWindow( x
, y
) ;
483 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
485 if (m_cursor
== cursor
)
488 if (wxNullCursor
== cursor
)
490 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
495 if ( ! wxWindowBase::SetCursor( cursor
) )
499 wxASSERT_MSG( m_cursor
.Ok(),
500 wxT("cursor must be valid after call to the base version"));
503 wxWindowMac
*mouseWin
;
506 // Change the cursor NOW if we're within the correct window
508 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
510 if ( mouseWin
== this && !wxIsBusy() )
512 m_cursor
.MacInstall() ;
520 // Get size *available for subwindows* i.e. excluding menu bar etc.
521 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
527 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
528 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
530 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
537 MacClientToRootWindow( &x1
, &y1
) ;
538 MacClientToRootWindow( &w
, &h
) ;
540 wxWindowMac
*iter
= (wxWindowMac
*)this ;
542 int totW
= 10000 , totH
= 10000;
545 if ( iter
->IsTopLevel() )
547 totW
= iter
->m_width
;
548 totH
= iter
->m_height
;
552 iter
= iter
->GetParent() ;
555 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
557 hh
-= MAC_SCROLLBAR_SIZE
;
563 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
565 ww
-= MAC_SCROLLBAR_SIZE
;
577 // ----------------------------------------------------------------------------
579 // ----------------------------------------------------------------------------
583 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
585 wxWindowBase::DoSetToolTip(tooltip
);
588 m_tooltip
->SetWindow(this);
591 #endif // wxUSE_TOOLTIPS
593 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
597 int former_w
= m_width
;
598 int former_h
= m_height
;
600 int actualWidth
= width
;
601 int actualHeight
= height
;
605 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
606 actualWidth
= m_minWidth
;
607 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
608 actualHeight
= m_minHeight
;
609 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
610 actualWidth
= m_maxWidth
;
611 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
612 actualHeight
= m_maxHeight
;
614 bool doMove
= false ;
615 bool doResize
= false ;
617 if ( actualX
!= former_x
|| actualY
!= former_y
)
621 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
626 if ( doMove
|| doResize
)
628 // erase former position
630 bool partialRepaint
= false ;
632 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
634 wxPoint
oldPos( m_x
, m_y
) ;
635 wxPoint
newPos( actualX
, actualY
) ;
636 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
637 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
638 if ( oldPos
== newPos
)
640 partialRepaint
= true ;
641 RgnHandle oldRgn
,newRgn
,diffRgn
;
646 // invalidate the differences between the old and the new area
648 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
649 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
650 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
651 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
652 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
653 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
655 // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really
656 // changing pixels...
658 if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 ||
659 MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 )
661 RgnHandle innerOldRgn
, innerNewRgn
;
662 innerOldRgn
= NewRgn() ;
663 innerNewRgn
= NewRgn() ;
665 SetRectRgn(innerOldRgn
, oldPos
.x
+ MacGetLeftBorderSize() , oldPos
.y
+ MacGetTopBorderSize() ,
666 oldPos
.x
+ m_width
- MacGetRightBorderSize() , oldPos
.y
+ m_height
- MacGetBottomBorderSize() ) ;
667 DiffRgn( oldRgn
, innerOldRgn
, diffRgn
) ;
668 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
670 SetRectRgn(innerNewRgn
, newPos
.x
+ MacGetLeftBorderSize() , newPos
.y
+ MacGetTopBorderSize() ,
671 newPos
.x
+ actualWidth
- MacGetRightBorderSize() , newPos
.y
+ actualHeight
- MacGetBottomBorderSize() ) ;
672 DiffRgn( newRgn
, innerNewRgn
, diffRgn
) ;
673 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
675 DisposeRgn( innerOldRgn
) ;
676 DisposeRgn( innerNewRgn
) ;
681 DisposeRgn(diffRgn
) ;
685 if ( !partialRepaint
)
690 m_width
= actualWidth
;
691 m_height
= actualHeight
;
693 // update any low-level frame-relative positions
695 MacUpdateDimensions() ;
696 // erase new position
698 if ( !partialRepaint
)
701 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
703 MacRepositionScrollBars() ;
706 wxPoint
point(m_x
, m_y
);
707 wxMoveEvent
event(point
, m_windowId
);
708 event
.SetEventObject(this);
709 GetEventHandler()->ProcessEvent(event
) ;
713 MacRepositionScrollBars() ;
714 wxSize
size(m_width
, m_height
);
715 wxSizeEvent
event(size
, m_windowId
);
716 event
.SetEventObject(this);
717 GetEventHandler()->ProcessEvent(event
);
723 // set the size of the window: if the dimensions are positive, just use them,
724 // but if any of them is equal to -1, it means that we must find the value for
725 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
726 // which case -1 is a valid value for x and y)
728 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
729 // the width/height to best suit our contents, otherwise we reuse the current
731 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
733 // get the current size and position...
734 int currentX
, currentY
;
735 GetPosition(¤tX
, ¤tY
);
737 int currentW
,currentH
;
738 GetSize(¤tW
, ¤tH
);
740 // ... and don't do anything (avoiding flicker) if it's already ok
741 if ( x
== currentX
&& y
== currentY
&&
742 width
== currentW
&& height
== currentH
)
744 MacRepositionScrollBars() ; // we might have a real position shift
748 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
750 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
753 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
758 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
760 size
= DoGetBestSize();
765 // just take the current one
772 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
776 size
= DoGetBestSize();
778 //else: already called DoGetBestSize() above
784 // just take the current one
789 DoMoveWindow(x
, y
, width
, height
);
792 // For implementation purposes - sometimes decorations make the client area
795 wxPoint
wxWindowMac::GetClientAreaOrigin() const
797 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
800 void wxWindowMac::SetLabel(const wxString
& label
)
805 wxString
wxWindowMac::GetLabel() const
810 bool wxWindowMac::Show(bool show
)
812 if ( !wxWindowBase::Show(show
) )
815 MacSuperShown( show
) ;
821 void wxWindowMac::MacSuperShown( bool show
)
823 wxWindowListNode
*node
= GetChildren().GetFirst();
826 wxWindowMac
*child
= node
->GetData();
827 if ( child
->m_isShown
)
828 child
->MacSuperShown( show
) ;
829 node
= node
->GetNext();
833 void wxWindowMac::MacSuperEnabled( bool enabled
)
837 // to be absolutely correct we'd have to invalidate (with eraseBkground
838 // because unter MacOSX the frames are drawn with an addXXX mode)
841 wxWindowListNode
*node
= GetChildren().GetFirst();
844 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
845 if ( child
->m_isShown
)
846 child
->MacSuperEnabled( enabled
) ;
847 node
= node
->GetNext();
851 bool wxWindowMac::MacIsReallyShown() const
853 if ( m_isShown
&& (m_parent
!= NULL
&& !IsTopLevel() ) ) {
854 return m_parent
->MacIsReallyShown();
858 bool status = m_isShown ;
859 wxWindowMac * win = this ;
860 while ( status && win->m_parent != NULL )
862 win = win->m_parent ;
863 status = win->m_isShown ;
869 int wxWindowMac::GetCharHeight() const
871 wxClientDC
dc ( (wxWindowMac
*)this ) ;
872 return dc
.GetCharHeight() ;
875 int wxWindowMac::GetCharWidth() const
877 wxClientDC
dc ( (wxWindowMac
*)this ) ;
878 return dc
.GetCharWidth() ;
881 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
882 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
884 const wxFont
*fontToUse
= theFont
;
888 wxClientDC
dc( (wxWindowMac
*) this ) ;
890 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
891 if ( externalLeading
)
892 *externalLeading
= le
;
902 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
903 * we always intersect with the entire window, not only with the client area
906 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
908 if ( MacGetTopLevelWindow() == NULL
)
911 if ( !MacIsReallyShown() )
914 wxPoint client
= GetClientAreaOrigin();
917 int x2
= m_width
- client
.x
;
918 int y2
= m_height
- client
.y
;
920 if (IsKindOf( CLASSINFO(wxButton
)))
922 // buttons have an "aura"
929 Rect clientrect
= { y1
, x1
, y2
, x2
};
933 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
934 SectRect( &clientrect
, &r
, &clientrect
) ;
937 if ( !EmptyRect( &clientrect
) )
939 int top
= 0 , left
= 0 ;
941 MacClientToRootWindow( &left
, &top
) ;
942 OffsetRect( &clientrect
, left
, top
) ;
944 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
948 wxWindowMac
*wxGetActiveWindow()
950 // actually this is a windows-only concept
954 // Coordinates relative to the window
955 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
957 // We really don't move the mouse programmatically under Mac.
960 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
962 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
964 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
966 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
968 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
969 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
970 // either a non gray background color or a non control window
972 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
974 wxWindowMac
* parent
= GetParent() ;
977 if ( parent
->MacGetRootWindow() != (WXWindow
) window
)
979 // we are in a different window on the mac system
985 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
986 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
988 // if we have any other colours in the hierarchy
989 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
992 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
993 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
995 Rect extent
= { 0 , 0 , 0 , 0 } ;
998 wxSize size
= parent
->GetSize() ;
999 parent
->MacClientToRootWindow( &x
, &y
) ;
1003 extent
.right
= x
+ size
.x
;
1004 extent
.bottom
= y
+ size
.y
;
1005 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1009 parent
= parent
->GetParent() ;
1013 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1018 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1021 return m_macBackgroundBrush
;
1024 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1026 event
.GetDC()->Clear() ;
1029 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1031 wxWindowDC
dc(this) ;
1032 wxMacPortSetter
helper(&dc
) ;
1034 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1037 int wxWindowMac::GetScrollPos(int orient
) const
1039 if ( orient
== wxHORIZONTAL
)
1042 return m_hScrollBar
->GetThumbPosition() ;
1047 return m_vScrollBar
->GetThumbPosition() ;
1052 // This now returns the whole range, not just the number
1053 // of positions that we can scroll.
1054 int wxWindowMac::GetScrollRange(int orient
) const
1056 if ( orient
== wxHORIZONTAL
)
1059 return m_hScrollBar
->GetRange() ;
1064 return m_vScrollBar
->GetRange() ;
1069 int wxWindowMac::GetScrollThumb(int orient
) const
1071 if ( orient
== wxHORIZONTAL
)
1074 return m_hScrollBar
->GetThumbSize() ;
1079 return m_vScrollBar
->GetThumbSize() ;
1084 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1086 if ( orient
== wxHORIZONTAL
)
1089 m_hScrollBar
->SetThumbPosition( pos
) ;
1094 m_vScrollBar
->SetThumbPosition( pos
) ;
1098 void wxWindowMac::MacPaintBorders( int left
, int top
)
1104 wxGetOsVersion( &major
, &minor
);
1106 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1107 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1109 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1110 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1111 // OS X has lighter border edges than classic:
1114 darkShadow
.red
= 0x8E8E;
1115 darkShadow
.green
= 0x8E8E;
1116 darkShadow
.blue
= 0x8E8E;
1117 lightShadow
.red
= 0xBDBD;
1118 lightShadow
.green
= 0xBDBD;
1119 lightShadow
.blue
= 0xBDBD;
1124 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1126 #if wxMAC_USE_THEME_BORDER
1127 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1130 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1131 InsetRect( &rect , border , border );
1132 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1135 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1137 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1138 RGBForeColor( &face
);
1139 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1140 LineTo( left
+ 0 , top
+ 0 );
1141 LineTo( left
+ m_width
- 2 , top
+ 0 );
1143 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1144 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1145 LineTo( left
+ m_width
- 3 , top
+ 2 );
1147 RGBForeColor( sunken
? &face
: &darkShadow
);
1148 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1149 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1150 LineTo( left
+ m_width
- 1 , top
+ 0 );
1152 RGBForeColor( sunken
? &lightShadow
: &white
);
1153 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1154 LineTo( left
+ 1, top
+ 1 );
1155 LineTo( left
+ m_width
- 3 , top
+ 1 );
1157 RGBForeColor( sunken
? &white
: &lightShadow
);
1158 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1159 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1160 LineTo( left
+ m_width
- 2 , top
+ 1 );
1162 RGBForeColor( sunken
? &darkShadow
: &face
);
1163 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1164 LineTo( left
+ 2 , top
+ 2 );
1165 LineTo( left
+ m_width
- 4 , top
+ 2 );
1168 else if (HasFlag(wxSIMPLE_BORDER
))
1170 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1171 RGBForeColor( &darkShadow
) ;
1172 FrameRect( &rect
) ;
1176 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1178 if ( child
== m_hScrollBar
)
1179 m_hScrollBar
= NULL
;
1180 if ( child
== m_vScrollBar
)
1181 m_vScrollBar
= NULL
;
1183 wxWindowBase::RemoveChild( child
) ;
1186 // New function that will replace some of the above.
1187 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1188 int range
, bool refresh
)
1190 if ( orient
== wxHORIZONTAL
)
1194 if ( range
== 0 || thumbVisible
>= range
)
1196 if ( m_hScrollBar
->IsShown() )
1197 m_hScrollBar
->Show(false) ;
1201 if ( !m_hScrollBar
->IsShown() )
1202 m_hScrollBar
->Show(true) ;
1203 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1211 if ( range
== 0 || thumbVisible
>= range
)
1213 if ( m_vScrollBar
->IsShown() )
1214 m_vScrollBar
->Show(false) ;
1218 if ( !m_vScrollBar
->IsShown() )
1219 m_vScrollBar
->Show(true) ;
1220 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1224 MacRepositionScrollBars() ;
1227 // Does a physical scroll
1228 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1230 if( dx
== 0 && dy
==0 )
1235 wxClientDC
dc(this) ;
1236 wxMacPortSetter
helper(&dc
) ;
1238 int width
, height
;
1239 GetClientSize( &width
, &height
) ;
1241 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1242 RgnHandle updateRgn
= NewRgn() ;
1243 ClipRect( &scrollrect
) ;
1246 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1247 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1248 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1250 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1251 // we also have to scroll the update rgn in this rectangle
1252 // in order not to loose updates
1253 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1254 RgnHandle formerUpdateRgn
= NewRgn() ;
1255 RgnHandle scrollRgn
= NewRgn() ;
1256 RectRgn( scrollRgn
, &scrollrect
) ;
1257 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1259 LocalToGlobal( &pt
) ;
1260 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1261 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1262 if ( !EmptyRgn( formerUpdateRgn
) )
1264 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1265 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1266 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1268 InvalWindowRgn(rootWindow
, updateRgn
) ;
1269 DisposeRgn( updateRgn
) ;
1270 DisposeRgn( formerUpdateRgn
) ;
1271 DisposeRgn( scrollRgn
) ;
1274 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1276 wxWindowMac
*child
= node
->GetData();
1277 if (child
== m_vScrollBar
) continue;
1278 if (child
== m_hScrollBar
) continue;
1279 if (child
->IsTopLevel()) continue;
1282 child
->GetPosition( &x
, &y
);
1284 child
->GetSize( &w
, &h
);
1288 if (rect
->Intersects(rc
))
1289 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1293 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1301 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1303 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1305 wxScrollWinEvent wevent
;
1306 wevent
.SetPosition(event
.GetPosition());
1307 wevent
.SetOrientation(event
.GetOrientation());
1308 wevent
.SetEventObject(this);
1310 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1311 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1312 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1313 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1314 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1315 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1316 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1317 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1318 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1319 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1320 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1321 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1322 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1323 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1324 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1325 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1327 GetEventHandler()->ProcessEvent(wevent
);
1331 // Get the window with the focus
1332 wxWindowMac
*wxWindowBase::DoFindFocus()
1334 return gFocusWindow
;
1337 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1339 // panel wants to track the window which was the last to have focus in it,
1340 // so we want to set ourselves as the window which last had focus
1342 // notice that it's also important to do it upwards the tree becaus
1343 // otherwise when the top level panel gets focus, it won't set it back to
1344 // us, but to some other sibling
1346 // CS:don't know if this is still needed:
1347 //wxChildFocusEvent eventFocus(this);
1348 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1353 // Setup background and foreground colours correctly
1354 void wxWindowMac::SetupColours()
1357 SetBackgroundColour(GetParent()->GetBackgroundColour());
1360 void wxWindowMac::OnInternalIdle()
1362 // This calls the UI-update mechanism (querying windows for
1363 // menu/toolbar/control state information)
1364 if (wxUpdateUIEvent::CanUpdate(this))
1365 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1368 // Raise the window to the top of the Z order
1369 void wxWindowMac::Raise()
1373 // Lower the window to the bottom of the Z order
1374 void wxWindowMac::Lower()
1378 void wxWindowMac::DoSetClientSize(int width
, int height
)
1380 if ( width
!= -1 || height
!= -1 )
1383 if ( width
!= -1 && m_vScrollBar
)
1384 width
+= MAC_SCROLLBAR_SIZE
;
1385 if ( height
!= -1 && m_vScrollBar
)
1386 height
+= MAC_SCROLLBAR_SIZE
;
1388 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1389 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1391 DoSetSize( -1 , -1 , width
, height
) ;
1396 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1398 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1402 if ((point
.x
< 0) || (point
.y
< 0) ||
1403 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1408 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1409 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1413 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1415 wxPoint
newPoint( point
) ;
1417 if ( !IsTopLevel() )
1423 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1425 wxWindowMac
*child
= node
->GetData();
1426 // added the m_isShown test --dmazzoni
1427 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->m_isShown
)
1429 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1438 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1442 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1443 if ( ::FindWindow( pt
, &window
) == 3 )
1446 wxWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1449 // No, this yields the CLIENT are, we need the whole frame. RR.
1450 // point = win->ScreenToClient( point ) ;
1453 ::GetPort( &port
) ;
1454 ::SetPort( UMAGetWindowPort( window
) ) ;
1455 ::GlobalToLocal( &pt
) ;
1458 wxPoint
point( pt
.h
, pt
.v
) ;
1460 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1466 static wxWindow
*gs_lastWhich
= NULL
;
1468 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1470 // first trigger a set cursor event
1472 wxPoint clientorigin
= GetClientAreaOrigin() ;
1473 wxSize clientsize
= GetClientSize() ;
1475 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1477 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1479 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1480 if ( processedEvtSetCursor
&& event
.HasCursor() )
1482 cursor
= event
.GetCursor() ;
1487 // the test for processedEvtSetCursor is here to prevent using m_cursor
1488 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1489 // it - this is a way to say that our cursor shouldn't be used for this
1491 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1501 cursor
= *wxSTANDARD_CURSOR
;
1505 cursor
.MacInstall() ;
1507 return cursor
.Ok() ;
1510 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1512 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1513 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1517 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1520 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1528 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1530 wxWindowMac
*child
= node
->GetData();
1531 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && child
->IsEnabled() )
1533 if (child
->MacDispatchMouseEvent(event
))
1538 wxWindow
* cursorTarget
= this ;
1539 wxPoint
cursorPoint( x
, y
) ;
1541 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1543 cursorTarget
= cursorTarget
->GetParent() ;
1545 cursorPoint
+= cursorTarget
->GetPosition() ;
1549 event
.SetEventObject( this ) ;
1551 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1553 // set focus to this window
1554 if (AcceptsFocus() && FindFocus()!=this)
1559 if ( event
.GetEventType() == wxEVT_MOTION
1560 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1561 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1562 wxToolTip::RelayEvent( this , event
);
1563 #endif // wxUSE_TOOLTIPS
1565 if (gs_lastWhich
!= this)
1567 gs_lastWhich
= this;
1569 // Double clicks must always occur on the same window
1570 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1571 event
.SetEventType( wxEVT_LEFT_DOWN
);
1572 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1573 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1575 // Same for mouse up events
1576 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1578 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1582 GetEventHandler()->ProcessEvent( event
) ;
1587 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1591 return m_tooltip
->GetTip() ;
1593 return wxEmptyString
;
1596 void wxWindowMac::Update()
1598 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1599 int top
= 0 , left
= 0 ;
1600 MacWindowToRootWindow( &left
, &top
) ;
1601 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1602 RgnHandle updateRgn
= NewRgn() ;
1603 // getting the update region in macos local coordinates
1604 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1606 ::GetPort( &port
) ;
1607 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1609 LocalToGlobal( &pt
) ;
1611 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1612 // translate to window local coordinates
1613 OffsetRgn( updateRgn
, -left
, -top
) ;
1614 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1615 MacRedraw( updateRgn
, 0 , true ) ;
1616 // for flushing and validating we need macos-local coordinates again
1617 OffsetRgn( updateRgn
, left
, top
) ;
1618 #if TARGET_API_MAC_CARBON
1619 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1621 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1624 ValidWindowRgn( rootWindow
, updateRgn
) ;
1625 DisposeRgn( updateRgn
) ;
1628 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1630 wxTopLevelWindowMac
* win
= NULL
;
1631 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1634 win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1639 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1641 RgnHandle visRgn
= NewRgn() ;
1642 RgnHandle tempRgn
= NewRgn() ;
1643 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1645 if ( MacIsReallyShown() )
1647 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1649 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1650 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1652 int borderTop
= 14 ;
1653 int borderOther
= 4 ;
1654 if ( UMAGetSystemVersion() >= 0x1030 )
1657 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1658 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1661 if ( !IsTopLevel() )
1663 wxWindow
* parent
= GetParent() ;
1666 wxSize size
= parent
->GetSize() ;
1669 parent
->MacWindowToRootWindow( &x
, &y
) ;
1670 MacRootWindowToWindow( &x
, &y
) ;
1672 SetRectRgn( tempRgn
,
1673 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1674 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1675 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1677 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1678 if ( parent
->IsTopLevel() )
1680 parent
= parent
->GetParent() ;
1683 if ( respectChildrenAndSiblings
)
1685 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1687 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1689 wxWindowMac
*child
= node
->GetData();
1691 if ( !child
->IsTopLevel() && child
->IsShown() )
1693 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1694 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1696 int borderTop
= 14 ;
1697 int borderOther
= 4 ;
1698 if ( UMAGetSystemVersion() >= 0x1030 )
1701 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1702 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1704 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1709 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1711 bool thisWindowThrough
= false ;
1712 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1714 wxWindowMac
*sibling
= node
->GetData();
1715 if ( sibling
== this )
1717 thisWindowThrough
= true ;
1720 if( !thisWindowThrough
)
1725 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1727 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
) ;
1728 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1730 int borderTop
= 14 ;
1731 int borderOther
= 4 ;
1732 if ( UMAGetSystemVersion() >= 0x1030 )
1735 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
) ;
1736 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1738 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1744 m_macVisibleRegion
= visRgn
;
1745 DisposeRgn( visRgn
) ;
1746 DisposeRgn( tempRgn
) ;
1747 DisposeRgn( tempStaticBoxRgn
) ;
1748 return m_macVisibleRegion
;
1751 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1753 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1754 // updatergn is always already clipped to our boundaries
1755 // it is in window coordinates, not in client coordinates
1757 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1760 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1761 RgnHandle ownUpdateRgn
= NewRgn() ;
1762 CopyRgn( updatergn
, ownUpdateRgn
) ;
1764 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1766 // newupdate is the update region in client coordinates
1767 RgnHandle newupdate
= NewRgn() ;
1768 wxSize point
= GetClientSize() ;
1769 wxPoint origin
= GetClientAreaOrigin() ;
1770 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1771 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1772 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1773 m_updateRegion
= newupdate
;
1774 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1776 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1778 wxWindowDC
dc(this);
1779 if (!EmptyRgn(ownUpdateRgn
))
1780 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1781 wxEraseEvent
eevent( GetId(), &dc
);
1782 eevent
.SetEventObject( this );
1783 GetEventHandler()->ProcessEvent( eevent
);
1785 wxNcPaintEvent
eventNc( GetId() );
1786 eventNc
.SetEventObject( this );
1787 GetEventHandler()->ProcessEvent( eventNc
);
1789 DisposeRgn( ownUpdateRgn
) ;
1790 if ( !m_updateRegion
.Empty() )
1792 wxWindowList hiddenWindows
;
1793 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1795 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1797 if ( child
&& child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && child
->GetMacControl() )
1799 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1800 hiddenWindows
.Append( child
) ;
1805 event
.SetTimestamp(time
);
1806 event
.SetEventObject(this);
1807 GetEventHandler()->ProcessEvent(event
);
1809 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1811 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1813 if ( child
&& child
->GetMacControl() )
1815 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1821 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1823 RgnHandle childupdate
= NewRgn() ;
1824 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1826 // calculate the update region for the child windows by intersecting the window rectangle with our own
1827 // passed in update region and then offset it to be client-wise window coordinates again
1828 wxWindowMac
*child
= node
->GetData();
1829 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1830 SectRgn( childupdate
, updatergn
, childupdate
) ;
1831 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1832 if ( child
->MacGetRootWindow() == (WXWindow
) window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1834 // because dialogs may also be children
1835 child
->MacRedraw( childupdate
, time
, erase
) ;
1838 DisposeRgn( childupdate
) ;
1839 // eventually a draw grow box here
1843 WXWindow
wxWindowMac::MacGetRootWindow() const
1845 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1849 if ( iter
->IsTopLevel() )
1850 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1852 iter
= iter
->GetParent() ;
1854 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1858 void wxWindowMac::MacCreateScrollBars( long style
)
1860 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1862 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1863 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1865 GetClientSize( &width
, &height
) ;
1867 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1868 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1869 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1870 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1872 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1873 vSize
, wxVERTICAL
);
1875 if ( style
& wxVSCROLL
)
1881 m_vScrollBar
->Show(false) ;
1883 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1884 hSize
, wxHORIZONTAL
);
1885 if ( style
& wxHSCROLL
)
1890 m_hScrollBar
->Show(false) ;
1893 // because the create does not take into account the client area origin
1894 MacRepositionScrollBars() ; // we might have a real position shift
1897 void wxWindowMac::MacRepositionScrollBars()
1899 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1900 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1902 // get real client area
1904 int width
= m_width
;
1905 int height
= m_height
;
1907 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1908 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1910 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1911 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1912 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1913 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1920 MacClientToRootWindow( &x
, &y
) ;
1921 MacClientToRootWindow( &w
, &h
) ;
1923 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1925 int totW
= 10000 , totH
= 10000;
1928 if ( iter
->IsTopLevel() )
1930 totW
= iter
->m_width
;
1931 totH
= iter
->m_height
;
1935 iter
= iter
->GetParent() ;
1963 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1967 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1971 bool wxWindowMac::AcceptsFocus() const
1973 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1976 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1978 return GetParent()->MacGetContainerForEmbedding() ;
1981 void wxWindowMac::MacSuperChangedPosition()
1983 // only window-absolute structures have to be moved i.e. controls
1985 wxWindowListNode
*node
= GetChildren().GetFirst();
1988 wxWindowMac
*child
= node
->GetData();
1989 child
->MacSuperChangedPosition() ;
1990 node
= node
->GetNext();
1994 void wxWindowMac::MacTopLevelWindowChangedPosition()
1996 // only screen-absolute structures have to be moved i.e. glcanvas
1998 wxWindowListNode
*node
= GetChildren().GetFirst();
2001 wxWindowMac
*child
= node
->GetData();
2002 child
->MacTopLevelWindowChangedPosition() ;
2003 node
= node
->GetNext();
2006 long wxWindowMac::MacGetLeftBorderSize( ) const
2011 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2014 #if wxMAC_USE_THEME_BORDER
2016 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2021 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2024 #if wxMAC_USE_THEME_BORDER
2026 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2031 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2038 long wxWindowMac::MacGetRightBorderSize( ) const
2040 // they are all symmetric in mac themes
2041 return MacGetLeftBorderSize() ;
2044 long wxWindowMac::MacGetTopBorderSize( ) const
2046 // they are all symmetric in mac themes
2047 return MacGetLeftBorderSize() ;
2050 long wxWindowMac::MacGetBottomBorderSize( ) const
2052 // they are all symmetric in mac themes
2053 return MacGetLeftBorderSize() ;
2056 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2058 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2061 // Find the wxWindowMac at the current mouse position, returning the mouse
2063 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2065 pt
= wxGetMousePosition();
2066 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2070 // Get the current mouse position.
2071 wxPoint
wxGetMousePosition()
2074 wxGetMousePosition(& x
, & y
);
2075 return wxPoint(x
, y
);
2078 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2080 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2082 // copied from wxGTK : CS
2083 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2086 // (a) it's a command event and so is propagated to the parent
2087 // (b) under MSW it can be generated from kbd too
2088 // (c) it uses screen coords (because of (a))
2089 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2091 this->ClientToScreen(event
.GetPosition()));
2092 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )