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()->ProcessEvent(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);
367 ClientToScreen( &x
, &y
) ;
369 menu
->MacBeforeDisplay( true ) ;
370 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
371 if ( HiWord(menuResult
) != 0 )
374 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
375 wxMenuItem
* item
= NULL
;
377 item
= menu
->FindItem(id
, &realmenu
) ;
378 if (item
->IsCheckable())
380 item
->Check( !item
->IsChecked() ) ;
382 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
384 menu
->MacAfterDisplay( true ) ;
386 menu
->SetInvokingWindow(NULL
);
392 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
394 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
396 Point localwhere
= {0,0} ;
398 if(x
) localwhere
.h
= * x
;
399 if(y
) localwhere
.v
= * y
;
403 ::SetPort( UMAGetWindowPort( window
) ) ;
404 ::GlobalToLocal( &localwhere
) ;
407 if(x
) *x
= localwhere
.h
;
408 if(y
) *y
= localwhere
.v
;
410 MacRootWindowToWindow( x
, y
) ;
412 *x
-= MacGetLeftBorderSize() ;
414 *y
-= MacGetTopBorderSize() ;
417 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
419 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
422 *x
+= MacGetLeftBorderSize() ;
424 *y
+= MacGetTopBorderSize() ;
426 MacWindowToRootWindow( x
, y
) ;
428 Point localwhere
= { 0,0 };
429 if(x
) localwhere
.h
= * x
;
430 if(y
) localwhere
.v
= * y
;
434 ::SetPort( UMAGetWindowPort( window
) ) ;
436 ::LocalToGlobal( &localwhere
) ;
438 if(x
) *x
= localwhere
.h
;
439 if(y
) *y
= localwhere
.v
;
442 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
444 wxPoint origin
= GetClientAreaOrigin() ;
445 if(x
) *x
+= origin
.x
;
446 if(y
) *y
+= origin
.y
;
448 MacWindowToRootWindow( x
, y
) ;
451 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
453 wxPoint origin
= GetClientAreaOrigin() ;
454 MacRootWindowToWindow( x
, y
) ;
455 if(x
) *x
-= origin
.x
;
456 if(y
) *y
-= origin
.y
;
459 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
465 GetParent()->MacWindowToRootWindow( x
, y
) ;
469 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
475 GetParent()->MacRootWindowToWindow( x
, y
) ;
479 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
481 if (m_cursor
== cursor
)
484 if (wxNullCursor
== cursor
)
486 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
491 if ( ! wxWindowBase::SetCursor( cursor
) )
495 wxASSERT_MSG( m_cursor
.Ok(),
496 wxT("cursor must be valid after call to the base version"));
499 wxWindowMac
*mouseWin
;
502 // Change the cursor NOW if we're within the correct window
504 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
506 if ( mouseWin
== this && !wxIsBusy() )
508 m_cursor
.MacInstall() ;
516 // Get size *available for subwindows* i.e. excluding menu bar etc.
517 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
523 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
524 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
526 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
533 MacClientToRootWindow( &x1
, &y1
) ;
534 MacClientToRootWindow( &w
, &h
) ;
536 wxWindowMac
*iter
= (wxWindowMac
*)this ;
538 int totW
= 10000 , totH
= 10000;
541 if ( iter
->IsTopLevel() )
543 totW
= iter
->m_width
;
544 totH
= iter
->m_height
;
548 iter
= iter
->GetParent() ;
551 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
553 hh
-= MAC_SCROLLBAR_SIZE
;
559 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
561 ww
-= MAC_SCROLLBAR_SIZE
;
573 // ----------------------------------------------------------------------------
575 // ----------------------------------------------------------------------------
579 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
581 wxWindowBase::DoSetToolTip(tooltip
);
584 m_tooltip
->SetWindow(this);
587 #endif // wxUSE_TOOLTIPS
589 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
593 int former_w
= m_width
;
594 int former_h
= m_height
;
596 int actualWidth
= width
;
597 int actualHeight
= height
;
601 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
602 actualWidth
= m_minWidth
;
603 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
604 actualHeight
= m_minHeight
;
605 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
606 actualWidth
= m_maxWidth
;
607 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
608 actualHeight
= m_maxHeight
;
610 bool doMove
= false ;
611 bool doResize
= false ;
613 if ( actualX
!= former_x
|| actualY
!= former_y
)
617 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
622 if ( doMove
|| doResize
)
624 // erase former position
626 bool partialRepaint
= false ;
628 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
630 wxPoint
oldPos( m_x
, m_y
) ;
631 wxPoint
newPos( actualX
, actualY
) ;
632 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
633 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
634 if ( oldPos
== newPos
)
636 partialRepaint
= true ;
637 RgnHandle oldRgn
,newRgn
,diffRgn
;
641 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
642 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
643 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
644 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
645 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
646 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
649 DisposeRgn(diffRgn
) ;
653 if ( !partialRepaint
)
658 m_width
= actualWidth
;
659 m_height
= actualHeight
;
661 // update any low-level frame-relative positions
663 MacUpdateDimensions() ;
664 // erase new position
666 if ( !partialRepaint
)
669 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
671 MacRepositionScrollBars() ;
674 wxPoint
point(m_x
, m_y
);
675 wxMoveEvent
event(point
, m_windowId
);
676 event
.SetEventObject(this);
677 GetEventHandler()->ProcessEvent(event
) ;
681 MacRepositionScrollBars() ;
682 wxSize
size(m_width
, m_height
);
683 wxSizeEvent
event(size
, m_windowId
);
684 event
.SetEventObject(this);
685 GetEventHandler()->ProcessEvent(event
);
691 // set the size of the window: if the dimensions are positive, just use them,
692 // but if any of them is equal to -1, it means that we must find the value for
693 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
694 // which case -1 is a valid value for x and y)
696 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
697 // the width/height to best suit our contents, otherwise we reuse the current
699 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
701 // get the current size and position...
702 int currentX
, currentY
;
703 GetPosition(¤tX
, ¤tY
);
705 int currentW
,currentH
;
706 GetSize(¤tW
, ¤tH
);
708 // ... and don't do anything (avoiding flicker) if it's already ok
709 if ( x
== currentX
&& y
== currentY
&&
710 width
== currentW
&& height
== currentH
)
712 MacRepositionScrollBars() ; // we might have a real position shift
716 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
718 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
721 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
726 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
728 size
= DoGetBestSize();
733 // just take the current one
740 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
744 size
= DoGetBestSize();
746 //else: already called DoGetBestSize() above
752 // just take the current one
757 DoMoveWindow(x
, y
, width
, height
);
760 // For implementation purposes - sometimes decorations make the client area
763 wxPoint
wxWindowMac::GetClientAreaOrigin() const
765 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
768 void wxWindowMac::SetTitle(const wxString
& title
)
773 wxString
wxWindowMac::GetTitle() const
778 bool wxWindowMac::Show(bool show
)
780 if ( !wxWindowBase::Show(show
) )
783 MacSuperShown( show
) ;
789 void wxWindowMac::MacSuperShown( bool show
)
791 wxWindowListNode
*node
= GetChildren().GetFirst();
794 wxWindowMac
*child
= node
->GetData();
795 if ( child
->m_isShown
)
796 child
->MacSuperShown( show
) ;
797 node
= node
->GetNext();
801 void wxWindowMac::MacSuperEnabled( bool enabled
)
805 // to be absolutely correct we'd have to invalidate (with eraseBkground
806 // because unter MacOSX the frames are drawn with an addXXX mode)
809 wxWindowListNode
*node
= GetChildren().GetFirst();
812 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
813 if ( child
->m_isShown
)
814 child
->MacSuperEnabled( enabled
) ;
815 node
= node
->GetNext();
819 bool wxWindowMac::MacIsReallyShown() const
821 if ( m_isShown
&& (m_parent
!= NULL
) ) {
822 return m_parent
->MacIsReallyShown();
826 bool status = m_isShown ;
827 wxWindowMac * win = this ;
828 while ( status && win->m_parent != NULL )
830 win = win->m_parent ;
831 status = win->m_isShown ;
837 int wxWindowMac::GetCharHeight() const
839 wxClientDC
dc ( (wxWindowMac
*)this ) ;
840 return dc
.GetCharHeight() ;
843 int wxWindowMac::GetCharWidth() const
845 wxClientDC
dc ( (wxWindowMac
*)this ) ;
846 return dc
.GetCharWidth() ;
849 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
850 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
852 const wxFont
*fontToUse
= theFont
;
856 wxClientDC
dc( (wxWindowMac
*) this ) ;
858 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
859 if ( externalLeading
)
860 *externalLeading
= le
;
870 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
871 * we always intersect with the entire window, not only with the client area
874 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
876 if ( MacGetTopLevelWindow() == NULL
)
879 if ( !MacIsReallyShown() )
882 wxPoint client
= GetClientAreaOrigin();
885 int x2
= m_width
- client
.x
;
886 int y2
= m_height
- client
.y
;
888 if (IsKindOf( CLASSINFO(wxButton
)))
890 // buttons have an "aura"
897 Rect clientrect
= { y1
, x1
, y2
, x2
};
901 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
902 SectRect( &clientrect
, &r
, &clientrect
) ;
905 if ( !EmptyRect( &clientrect
) )
907 int top
= 0 , left
= 0 ;
909 MacClientToRootWindow( &left
, &top
) ;
910 OffsetRect( &clientrect
, left
, top
) ;
912 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
916 wxWindowMac
*wxGetActiveWindow()
918 // actually this is a windows-only concept
922 // Coordinates relative to the window
923 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
925 // We really don't move the mouse programmatically under Mac.
928 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
930 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
932 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
934 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
936 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
937 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
938 // either a non gray background color or a non control window
940 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
942 wxWindowMac
* parent
= GetParent() ;
945 if ( parent
->MacGetRootWindow() != window
)
947 // we are in a different window on the mac system
953 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
954 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
956 // if we have any other colours in the hierarchy
957 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
960 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
961 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
963 Rect extent
= { 0 , 0 , 0 , 0 } ;
966 wxSize size
= parent
->GetSize() ;
967 parent
->MacClientToRootWindow( &x
, &y
) ;
971 extent
.right
= x
+ size
.x
;
972 extent
.bottom
= y
+ size
.y
;
973 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
977 parent
= parent
->GetParent() ;
981 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
986 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
989 return m_macBackgroundBrush
;
992 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
994 event
.GetDC()->Clear() ;
997 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
999 wxWindowDC
dc(this) ;
1000 wxMacPortSetter
helper(&dc
) ;
1002 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1005 int wxWindowMac::GetScrollPos(int orient
) const
1007 if ( orient
== wxHORIZONTAL
)
1010 return m_hScrollBar
->GetThumbPosition() ;
1015 return m_vScrollBar
->GetThumbPosition() ;
1020 // This now returns the whole range, not just the number
1021 // of positions that we can scroll.
1022 int wxWindowMac::GetScrollRange(int orient
) const
1024 if ( orient
== wxHORIZONTAL
)
1027 return m_hScrollBar
->GetRange() ;
1032 return m_vScrollBar
->GetRange() ;
1037 int wxWindowMac::GetScrollThumb(int orient
) const
1039 if ( orient
== wxHORIZONTAL
)
1042 return m_hScrollBar
->GetThumbSize() ;
1047 return m_vScrollBar
->GetThumbSize() ;
1052 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1054 if ( orient
== wxHORIZONTAL
)
1057 m_hScrollBar
->SetThumbPosition( pos
) ;
1062 m_vScrollBar
->SetThumbPosition( pos
) ;
1066 void wxWindowMac::MacPaintBorders( int left
, int top
)
1071 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1072 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1073 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1074 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1077 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1079 #if wxMAC_USE_THEME_BORDER
1080 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1083 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1084 InsetRect( &rect , border , border );
1085 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1088 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1090 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1091 RGBForeColor( &face
);
1092 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1093 LineTo( left
+ 0 , top
+ 0 );
1094 LineTo( left
+ m_width
- 2 , top
+ 0 );
1096 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1097 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1098 LineTo( left
+ m_width
- 3 , top
+ 2 );
1100 RGBForeColor( sunken
? &face
: &black
);
1101 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1102 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1103 LineTo( left
+ m_width
- 1 , top
+ 0 );
1105 RGBForeColor( sunken
? &shadow
: &white
);
1106 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1107 LineTo( left
+ 1, top
+ 1 );
1108 LineTo( left
+ m_width
- 3 , top
+ 1 );
1110 RGBForeColor( sunken
? &white
: &shadow
);
1111 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1112 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1113 LineTo( left
+ m_width
- 2 , top
+ 1 );
1115 RGBForeColor( sunken
? &black
: &face
);
1116 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1117 LineTo( left
+ 2 , top
+ 2 );
1118 LineTo( left
+ m_width
- 4 , top
+ 2 );
1121 else if (HasFlag(wxSIMPLE_BORDER
))
1123 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1124 RGBForeColor( &black
) ;
1125 FrameRect( &rect
) ;
1129 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1131 if ( child
== m_hScrollBar
)
1132 m_hScrollBar
= NULL
;
1133 if ( child
== m_vScrollBar
)
1134 m_vScrollBar
= NULL
;
1136 wxWindowBase::RemoveChild( child
) ;
1139 // New function that will replace some of the above.
1140 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1141 int range
, bool refresh
)
1143 if ( orient
== wxHORIZONTAL
)
1147 if ( range
== 0 || thumbVisible
>= range
)
1149 if ( m_hScrollBar
->IsShown() )
1150 m_hScrollBar
->Show(false) ;
1154 if ( !m_hScrollBar
->IsShown() )
1155 m_hScrollBar
->Show(true) ;
1156 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1164 if ( range
== 0 || thumbVisible
>= range
)
1166 if ( m_vScrollBar
->IsShown() )
1167 m_vScrollBar
->Show(false) ;
1171 if ( !m_vScrollBar
->IsShown() )
1172 m_vScrollBar
->Show(true) ;
1173 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1177 MacRepositionScrollBars() ;
1180 // Does a physical scroll
1181 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1183 if( dx
== 0 && dy
==0 )
1188 wxClientDC
dc(this) ;
1189 wxMacPortSetter
helper(&dc
) ;
1191 int width
, height
;
1192 GetClientSize( &width
, &height
) ;
1194 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1195 RgnHandle updateRgn
= NewRgn() ;
1196 ClipRect( &scrollrect
) ;
1199 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1200 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1201 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1203 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1204 // we also have to scroll the update rgn in this rectangle
1205 // in order not to loose updates
1206 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1207 RgnHandle formerUpdateRgn
= NewRgn() ;
1208 RgnHandle scrollRgn
= NewRgn() ;
1209 RectRgn( scrollRgn
, &scrollrect
) ;
1210 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1212 LocalToGlobal( &pt
) ;
1213 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1214 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1215 if ( !EmptyRgn( formerUpdateRgn
) )
1217 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1218 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1219 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1221 InvalWindowRgn(rootWindow
, updateRgn
) ;
1222 DisposeRgn( updateRgn
) ;
1223 DisposeRgn( formerUpdateRgn
) ;
1224 DisposeRgn( scrollRgn
) ;
1227 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1229 wxWindowMac
*child
= node
->GetData();
1230 if (child
== m_vScrollBar
) continue;
1231 if (child
== m_hScrollBar
) continue;
1232 if (child
->IsTopLevel()) continue;
1235 child
->GetPosition( &x
, &y
);
1237 child
->GetSize( &w
, &h
);
1238 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1245 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1247 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1249 wxScrollWinEvent wevent
;
1250 wevent
.SetPosition(event
.GetPosition());
1251 wevent
.SetOrientation(event
.GetOrientation());
1252 wevent
.m_eventObject
= this;
1254 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
1255 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1256 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
1257 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1258 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
1259 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1260 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
1261 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1262 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
1263 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1264 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
1265 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1266 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
1267 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1268 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
1269 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1271 GetEventHandler()->ProcessEvent(wevent
);
1275 // Get the window with the focus
1276 wxWindowMac
*wxWindowBase::FindFocus()
1278 return gFocusWindow
;
1281 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1283 // panel wants to track the window which was the last to have focus in it,
1284 // so we want to set ourselves as the window which last had focus
1286 // notice that it's also important to do it upwards the tree becaus
1287 // otherwise when the top level panel gets focus, it won't set it back to
1288 // us, but to some other sibling
1290 // CS:don't know if this is still needed:
1291 //wxChildFocusEvent eventFocus(this);
1292 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1297 // Setup background and foreground colours correctly
1298 void wxWindowMac::SetupColours()
1301 SetBackgroundColour(GetParent()->GetBackgroundColour());
1304 void wxWindowMac::OnInternalIdle()
1306 // This calls the UI-update mechanism (querying windows for
1307 // menu/toolbar/control state information)
1308 if (wxUpdateUIEvent::CanUpdate(this))
1309 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1312 // Raise the window to the top of the Z order
1313 void wxWindowMac::Raise()
1317 // Lower the window to the bottom of the Z order
1318 void wxWindowMac::Lower()
1322 void wxWindowMac::DoSetClientSize(int width
, int height
)
1324 if ( width
!= -1 || height
!= -1 )
1327 if ( width
!= -1 && m_vScrollBar
)
1328 width
+= MAC_SCROLLBAR_SIZE
;
1329 if ( height
!= -1 && m_vScrollBar
)
1330 height
+= MAC_SCROLLBAR_SIZE
;
1332 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1333 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1335 DoSetSize( -1 , -1 , width
, height
) ;
1340 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1342 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1346 if ((point
.x
< 0) || (point
.y
< 0) ||
1347 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1352 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1353 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1357 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1359 wxPoint
newPoint( point
) ;
1361 if ( !IsTopLevel() )
1367 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1369 wxWindowMac
*child
= node
->GetData();
1370 // added the m_isShown test --dmazzoni
1371 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1373 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1382 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1386 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1387 if ( ::FindWindow( pt
, &window
) == 3 )
1390 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1393 // No, this yields the CLIENT are, we need the whole frame. RR.
1394 // point = win->ScreenToClient( point ) ;
1397 ::GetPort( &port
) ;
1398 ::SetPort( UMAGetWindowPort( window
) ) ;
1399 ::GlobalToLocal( &pt
) ;
1402 wxPoint
point( pt
.h
, pt
.v
) ;
1404 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1410 static wxWindow
*gs_lastWhich
= NULL
;
1412 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1414 // first trigger a set cursor event
1416 wxPoint clientorigin
= GetClientAreaOrigin() ;
1417 wxSize clientsize
= GetClientSize() ;
1419 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1421 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1423 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1424 if ( processedEvtSetCursor
&& event
.HasCursor() )
1426 cursor
= event
.GetCursor() ;
1431 // the test for processedEvtSetCursor is here to prevent using m_cursor
1432 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1433 // it - this is a way to say that our cursor shouldn't be used for this
1435 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1445 cursor
= *wxSTANDARD_CURSOR
;
1449 cursor
.MacInstall() ;
1451 return cursor
.Ok() ;
1454 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1456 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1457 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1461 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1464 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1472 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1474 wxWindowMac
*child
= node
->GetData();
1475 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1477 if (child
->MacDispatchMouseEvent(event
))
1482 wxWindow
* cursorTarget
= this ;
1483 wxPoint
cursorPoint( x
, y
) ;
1485 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1487 cursorTarget
= cursorTarget
->GetParent() ;
1489 cursorPoint
+= cursorTarget
->GetPosition() ;
1493 event
.SetEventObject( this ) ;
1495 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1497 // set focus to this window
1498 if (AcceptsFocus() && FindFocus()!=this)
1503 if ( event
.GetEventType() == wxEVT_MOTION
1504 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1505 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1506 wxToolTip::RelayEvent( this , event
);
1507 #endif // wxUSE_TOOLTIPS
1509 if (gs_lastWhich
!= this)
1511 gs_lastWhich
= this;
1513 // Double clicks must always occur on the same window
1514 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1515 event
.SetEventType( wxEVT_LEFT_DOWN
);
1516 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1517 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1519 // Same for mouse up events
1520 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1522 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1526 GetEventHandler()->ProcessEvent( event
) ;
1531 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1535 return m_tooltip
->GetTip() ;
1537 return wxEmptyString
;
1540 void wxWindowMac::Update()
1542 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1543 int top
= 0 , left
= 0 ;
1544 MacWindowToRootWindow( &left
, &top
) ;
1545 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1546 RgnHandle updateRgn
= NewRgn() ;
1547 // getting the update region in macos local coordinates
1548 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1550 ::GetPort( &port
) ;
1551 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1553 LocalToGlobal( &pt
) ;
1555 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1556 // translate to window local coordinates
1557 OffsetRgn( updateRgn
, -left
, -top
) ;
1558 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1559 MacRedraw( updateRgn
, 0 , true ) ;
1560 // for flushing and validating we need macos-local coordinates again
1561 OffsetRgn( updateRgn
, left
, top
) ;
1562 #if TARGET_API_MAC_CARBON
1563 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1565 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1568 ValidWindowRgn( rootWindow
, updateRgn
) ;
1569 DisposeRgn( updateRgn
) ;
1572 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1574 wxTopLevelWindowMac
* win
= NULL
;
1575 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1578 win
= wxFindWinFromMacWindow( window
) ;
1583 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1585 RgnHandle visRgn
= NewRgn() ;
1586 RgnHandle tempRgn
= NewRgn() ;
1587 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1589 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1591 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1592 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1594 int borderTop
= 14 ;
1595 int borderOther
= 4 ;
1597 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1598 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1601 if ( !IsTopLevel() )
1603 wxWindow
* parent
= GetParent() ;
1606 wxSize size
= parent
->GetSize() ;
1609 parent
->MacWindowToRootWindow( &x
, &y
) ;
1610 MacRootWindowToWindow( &x
, &y
) ;
1612 SetRectRgn( tempRgn
,
1613 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1614 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1615 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1617 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1618 if ( parent
->IsTopLevel() )
1620 parent
= parent
->GetParent() ;
1623 if ( respectChildrenAndSiblings
)
1625 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1627 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1629 wxWindowMac
*child
= node
->GetData();
1631 if ( !child
->IsTopLevel() && child
->IsShown() )
1633 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1634 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1636 int borderTop
= 14 ;
1637 int borderOther
= 4 ;
1639 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1640 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1642 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1647 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1649 bool thisWindowThrough
= false ;
1650 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1652 wxWindowMac
*sibling
= node
->GetData();
1653 if ( sibling
== this )
1655 thisWindowThrough
= true ;
1658 if( !thisWindowThrough
)
1663 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1665 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
) ;
1666 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1668 int borderTop
= 14 ;
1669 int borderOther
= 4 ;
1671 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
) ;
1672 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1674 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1679 m_macVisibleRegion
= visRgn
;
1680 DisposeRgn( visRgn
) ;
1681 DisposeRgn( tempRgn
) ;
1682 DisposeRgn( tempStaticBoxRgn
) ;
1683 return m_macVisibleRegion
;
1686 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1688 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1689 // updatergn is always already clipped to our boundaries
1690 // it is in window coordinates, not in client coordinates
1692 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1695 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1696 RgnHandle ownUpdateRgn
= NewRgn() ;
1697 CopyRgn( updatergn
, ownUpdateRgn
) ;
1699 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1701 // newupdate is the update region in client coordinates
1702 RgnHandle newupdate
= NewRgn() ;
1703 wxSize point
= GetClientSize() ;
1704 wxPoint origin
= GetClientAreaOrigin() ;
1705 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1706 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1707 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1708 m_updateRegion
= newupdate
;
1709 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1711 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1713 wxWindowDC
dc(this);
1714 if (!EmptyRgn(ownUpdateRgn
))
1715 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1716 wxEraseEvent
eevent( GetId(), &dc
);
1717 eevent
.SetEventObject( this );
1718 GetEventHandler()->ProcessEvent( eevent
);
1720 wxNcPaintEvent
eventNc( GetId() );
1721 eventNc
.SetEventObject( this );
1722 GetEventHandler()->ProcessEvent( eventNc
);
1724 DisposeRgn( ownUpdateRgn
) ;
1725 if ( !m_updateRegion
.Empty() )
1727 wxWindowList hiddenWindows
;
1728 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1730 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1732 if ( child
&& child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->GetMacControl() )
1734 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1735 hiddenWindows
.Append( child
) ;
1740 event
.m_timeStamp
= time
;
1741 event
.SetEventObject(this);
1742 GetEventHandler()->ProcessEvent(event
);
1744 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1746 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1748 if ( child
&& child
->GetMacControl() )
1750 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1756 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1758 RgnHandle childupdate
= NewRgn() ;
1759 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1761 // calculate the update region for the child windows by intersecting the window rectangle with our own
1762 // passed in update region and then offset it to be client-wise window coordinates again
1763 wxWindowMac
*child
= node
->GetData();
1764 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1765 SectRgn( childupdate
, updatergn
, childupdate
) ;
1766 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1767 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1769 // because dialogs may also be children
1770 child
->MacRedraw( childupdate
, time
, erase
) ;
1773 DisposeRgn( childupdate
) ;
1774 // eventually a draw grow box here
1778 WXHWND
wxWindowMac::MacGetRootWindow() const
1780 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1784 if ( iter
->IsTopLevel() )
1785 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1787 iter
= iter
->GetParent() ;
1789 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1793 void wxWindowMac::MacCreateScrollBars( long style
)
1795 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1797 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1798 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1800 GetClientSize( &width
, &height
) ;
1802 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1803 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1804 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1805 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1807 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1808 vSize
, wxVERTICAL
);
1810 if ( style
& wxVSCROLL
)
1816 m_vScrollBar
->Show(false) ;
1818 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1819 hSize
, wxHORIZONTAL
);
1820 if ( style
& wxHSCROLL
)
1825 m_hScrollBar
->Show(false) ;
1828 // because the create does not take into account the client area origin
1829 MacRepositionScrollBars() ; // we might have a real position shift
1832 void wxWindowMac::MacRepositionScrollBars()
1834 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1835 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1837 // get real client area
1839 int width
= m_width
;
1840 int height
= m_height
;
1842 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1843 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1845 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1846 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1847 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1848 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1855 MacClientToRootWindow( &x
, &y
) ;
1856 MacClientToRootWindow( &w
, &h
) ;
1858 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1860 int totW
= 10000 , totH
= 10000;
1863 if ( iter
->IsTopLevel() )
1865 totW
= iter
->m_width
;
1866 totH
= iter
->m_height
;
1870 iter
= iter
->GetParent() ;
1898 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1902 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1906 bool wxWindowMac::AcceptsFocus() const
1908 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1911 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1913 return GetParent()->MacGetContainerForEmbedding() ;
1916 void wxWindowMac::MacSuperChangedPosition()
1918 // only window-absolute structures have to be moved i.e. controls
1920 wxWindowListNode
*node
= GetChildren().GetFirst();
1923 wxWindowMac
*child
= node
->GetData();
1924 child
->MacSuperChangedPosition() ;
1925 node
= node
->GetNext();
1929 void wxWindowMac::MacTopLevelWindowChangedPosition()
1931 // only screen-absolute structures have to be moved i.e. glcanvas
1933 wxWindowListNode
*node
= GetChildren().GetFirst();
1936 wxWindowMac
*child
= node
->GetData();
1937 child
->MacTopLevelWindowChangedPosition() ;
1938 node
= node
->GetNext();
1941 long wxWindowMac::MacGetLeftBorderSize( ) const
1946 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1949 #if wxMAC_USE_THEME_BORDER
1951 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1956 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1959 #if wxMAC_USE_THEME_BORDER
1961 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1966 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1973 long wxWindowMac::MacGetRightBorderSize( ) const
1975 // they are all symmetric in mac themes
1976 return MacGetLeftBorderSize() ;
1979 long wxWindowMac::MacGetTopBorderSize( ) const
1981 // they are all symmetric in mac themes
1982 return MacGetLeftBorderSize() ;
1985 long wxWindowMac::MacGetBottomBorderSize( ) const
1987 // they are all symmetric in mac themes
1988 return MacGetLeftBorderSize() ;
1991 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1993 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1996 // Find the wxWindowMac at the current mouse position, returning the mouse
1998 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2000 pt
= wxGetMousePosition();
2001 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2005 // Get the current mouse position.
2006 wxPoint
wxGetMousePosition()
2009 wxGetMousePosition(& x
, & y
);
2010 return wxPoint(x
, y
);
2013 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2015 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2017 // copied from wxGTK : CS
2018 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2021 // (a) it's a command event and so is propagated to the parent
2022 // (b) under MSW it can be generated from kbd too
2023 // (c) it uses screen coords (because of (a))
2024 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2026 this->ClientToScreen(event
.GetPosition()));
2027 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )