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()
106 m_isBeingDeleted
= FALSE
;
107 m_backgroundTransparent
= FALSE
;
109 // as all windows are created with WS_VISIBLE style...
117 m_hScrollBar
= NULL
;
118 m_vScrollBar
= NULL
;
120 m_label
= wxEmptyString
;
124 wxWindowMac::~wxWindowMac()
128 // deleting a window while it is shown invalidates the region
130 wxWindowMac
* iter
= this ;
132 if ( iter
->IsTopLevel() )
137 iter
= iter
->GetParent() ;
142 m_isBeingDeleted
= TRUE
;
144 #ifndef __WXUNIVERSAL__
145 // VS: make sure there's no wxFrame with last focus set to us:
146 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
148 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
151 if ( frame
->GetLastFocus() == this )
153 frame
->SetLastFocus((wxWindow
*)NULL
);
158 #endif // __WXUNIVERSAL__
160 if ( s_lastMouseWindow
== this )
162 s_lastMouseWindow
= NULL
;
165 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
168 if ( frame
->GetLastFocus() == this )
169 frame
->SetLastFocus( NULL
) ;
172 if ( gFocusWindow
== this )
174 gFocusWindow
= NULL
;
177 // CS: copied from MSW :
178 // VS: destroy children first and _then_ detach *this from its parent.
179 // If we'd do it the other way around, children wouldn't be able
180 // find their parent frame (see above).
184 m_parent
->RemoveChild(this);
186 // delete our drop target if we've got one
187 #if wxUSE_DRAG_AND_DROP
188 if ( m_dropTarget
!= NULL
)
193 #endif // wxUSE_DRAG_AND_DROP
197 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
201 const wxString
& name
)
203 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
206 // wxGTK doesn't allow to create controls with static box as the parent so
207 // this will result in a crash when the program is ported to wxGTK - warn
210 // the correct solution is to create the controls as siblings of the
212 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
213 _T("wxStaticBox can't be used as a window parent!") );
214 #endif // wxUSE_STATBOX
216 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
219 parent
->AddChild(this);
223 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
224 m_width
= WidthDefault( size
.x
);
225 m_height
= HeightDefault( size
.y
) ;
226 #ifndef __WXUNIVERSAL__
227 // Don't give scrollbars to wxControls unless they ask for them
228 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
229 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
231 MacCreateScrollBars( style
) ;
237 void wxWindowMac::SetFocus()
239 if ( gFocusWindow
== this )
242 if ( AcceptsFocus() )
248 if ( gFocusWindow
->m_caret
)
250 gFocusWindow
->m_caret
->OnKillFocus();
252 #endif // wxUSE_CARET
253 #ifndef __WXUNIVERSAL__
254 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
255 if ( control
&& control
->GetMacControl() )
257 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
258 control
->MacRedrawControl() ;
261 // Without testing the window id, for some reason
262 // a kill focus event can still be sent to
263 // the control just being focussed.
264 int thisId
= this->m_windowId
;
265 int gFocusWindowId
= gFocusWindow
->m_windowId
;
266 if (gFocusWindowId
!= thisId
)
268 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
269 event
.SetEventObject(gFocusWindow
);
270 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
273 gFocusWindow
= this ;
279 m_caret
->OnSetFocus();
281 #endif // wxUSE_CARET
282 // panel wants to track the window which was the last to have focus in it
283 wxChildFocusEvent
eventFocus(this);
284 GetEventHandler()->ProcessEvent(eventFocus
);
286 #ifndef __WXUNIVERSAL__
287 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
288 if ( control
&& control
->GetMacControl() )
290 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
293 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
294 event
.SetEventObject(this);
295 GetEventHandler()->ProcessEvent(event
) ;
300 bool wxWindowMac::Enable(bool enable
)
302 if ( !wxWindowBase::Enable(enable
) )
305 MacSuperEnabled( enable
) ;
310 void wxWindowMac::DoCaptureMouse()
312 wxTheApp
->s_captureWindow
= this ;
315 wxWindow
* wxWindowBase::GetCapture()
317 return wxTheApp
->s_captureWindow
;
320 void wxWindowMac::DoReleaseMouse()
322 wxTheApp
->s_captureWindow
= NULL
;
325 #if wxUSE_DRAG_AND_DROP
327 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
329 if ( m_dropTarget
!= 0 ) {
333 m_dropTarget
= pDropTarget
;
334 if ( m_dropTarget
!= 0 )
342 // Old style file-manager drag&drop
343 void wxWindowMac::DragAcceptFiles(bool accept
)
349 void wxWindowMac::DoGetSize(int *x
, int *y
) const
352 if(y
) *y
= m_height
;
355 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
361 if ( !IsTopLevel() && GetParent())
363 wxPoint
pt(GetParent()->GetClientAreaOrigin());
372 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
374 menu
->SetInvokingWindow(this);
376 ClientToScreen( &x
, &y
) ;
378 menu
->MacBeforeDisplay( true ) ;
379 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
380 if ( HiWord(menuResult
) != 0 )
383 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
384 wxMenuItem
* item
= NULL
;
386 item
= menu
->FindItem(id
, &realmenu
) ;
387 if (item
->IsCheckable())
389 item
->Check( !item
->IsChecked() ) ;
391 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
393 menu
->MacAfterDisplay( true ) ;
395 menu
->SetInvokingWindow(NULL
);
401 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
403 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
405 Point localwhere
= {0,0} ;
407 if(x
) localwhere
.h
= * x
;
408 if(y
) localwhere
.v
= * y
;
412 ::SetPort( UMAGetWindowPort( window
) ) ;
413 ::GlobalToLocal( &localwhere
) ;
416 if(x
) *x
= localwhere
.h
;
417 if(y
) *y
= localwhere
.v
;
419 MacRootWindowToWindow( x
, y
) ;
421 *x
-= MacGetLeftBorderSize() ;
423 *y
-= MacGetTopBorderSize() ;
426 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
428 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
431 *x
+= MacGetLeftBorderSize() ;
433 *y
+= MacGetTopBorderSize() ;
435 MacWindowToRootWindow( x
, y
) ;
437 Point localwhere
= { 0,0 };
438 if(x
) localwhere
.h
= * x
;
439 if(y
) localwhere
.v
= * y
;
443 ::SetPort( UMAGetWindowPort( window
) ) ;
445 ::LocalToGlobal( &localwhere
) ;
447 if(x
) *x
= localwhere
.h
;
448 if(y
) *y
= localwhere
.v
;
451 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
453 wxPoint origin
= GetClientAreaOrigin() ;
454 if(x
) *x
+= origin
.x
;
455 if(y
) *y
+= origin
.y
;
457 MacWindowToRootWindow( x
, y
) ;
460 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
462 wxPoint origin
= GetClientAreaOrigin() ;
463 MacRootWindowToWindow( x
, y
) ;
464 if(x
) *x
-= origin
.x
;
465 if(y
) *y
-= origin
.y
;
468 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
474 GetParent()->MacWindowToRootWindow( x
, y
) ;
478 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
484 GetParent()->MacRootWindowToWindow( x
, y
) ;
488 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
490 if (m_cursor
== cursor
)
493 if (wxNullCursor
== cursor
)
495 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
500 if ( ! wxWindowBase::SetCursor( cursor
) )
504 wxASSERT_MSG( m_cursor
.Ok(),
505 wxT("cursor must be valid after call to the base version"));
508 wxWindowMac
*mouseWin
;
511 // Change the cursor NOW if we're within the correct window
513 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
515 if ( mouseWin
== this && !wxIsBusy() )
517 m_cursor
.MacInstall() ;
525 // Get size *available for subwindows* i.e. excluding menu bar etc.
526 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
532 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
533 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
535 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
542 MacClientToRootWindow( &x1
, &y1
) ;
543 MacClientToRootWindow( &w
, &h
) ;
545 wxWindowMac
*iter
= (wxWindowMac
*)this ;
547 int totW
= 10000 , totH
= 10000;
550 if ( iter
->IsTopLevel() )
552 totW
= iter
->m_width
;
553 totH
= iter
->m_height
;
557 iter
= iter
->GetParent() ;
560 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
562 hh
-= MAC_SCROLLBAR_SIZE
;
568 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
570 ww
-= MAC_SCROLLBAR_SIZE
;
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
588 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
590 wxWindowBase::DoSetToolTip(tooltip
);
593 m_tooltip
->SetWindow(this);
596 #endif // wxUSE_TOOLTIPS
598 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
602 int former_w
= m_width
;
603 int former_h
= m_height
;
605 int actualWidth
= width
;
606 int actualHeight
= height
;
610 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
611 actualWidth
= m_minWidth
;
612 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
613 actualHeight
= m_minHeight
;
614 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
615 actualWidth
= m_maxWidth
;
616 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
617 actualHeight
= m_maxHeight
;
619 bool doMove
= false ;
620 bool doResize
= false ;
622 if ( actualX
!= former_x
|| actualY
!= former_y
)
626 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
631 if ( doMove
|| doResize
)
633 // erase former position
635 bool partialRepaint
= false ;
637 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
639 wxPoint
oldPos( m_x
, m_y
) ;
640 wxPoint
newPos( actualX
, actualY
) ;
641 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
642 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
643 if ( oldPos
== newPos
)
645 partialRepaint
= true ;
646 RgnHandle oldRgn
,newRgn
,diffRgn
;
650 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
651 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
652 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
653 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
654 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
655 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
658 DisposeRgn(diffRgn
) ;
662 if ( !partialRepaint
)
667 m_width
= actualWidth
;
668 m_height
= actualHeight
;
670 // update any low-level frame-relative positions
672 MacUpdateDimensions() ;
673 // erase new position
675 if ( !partialRepaint
)
678 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
680 MacRepositionScrollBars() ;
683 wxPoint
point(m_x
, m_y
);
684 wxMoveEvent
event(point
, m_windowId
);
685 event
.SetEventObject(this);
686 GetEventHandler()->ProcessEvent(event
) ;
690 MacRepositionScrollBars() ;
691 wxSize
size(m_width
, m_height
);
692 wxSizeEvent
event(size
, m_windowId
);
693 event
.SetEventObject(this);
694 GetEventHandler()->ProcessEvent(event
);
700 // set the size of the window: if the dimensions are positive, just use them,
701 // but if any of them is equal to -1, it means that we must find the value for
702 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
703 // which case -1 is a valid value for x and y)
705 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
706 // the width/height to best suit our contents, otherwise we reuse the current
708 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
710 // get the current size and position...
711 int currentX
, currentY
;
712 GetPosition(¤tX
, ¤tY
);
714 int currentW
,currentH
;
715 GetSize(¤tW
, ¤tH
);
717 // ... and don't do anything (avoiding flicker) if it's already ok
718 if ( x
== currentX
&& y
== currentY
&&
719 width
== currentW
&& height
== currentH
)
721 MacRepositionScrollBars() ; // we might have a real position shift
725 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
727 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
730 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
735 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
737 size
= DoGetBestSize();
742 // just take the current one
749 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
753 size
= DoGetBestSize();
755 //else: already called DoGetBestSize() above
761 // just take the current one
766 DoMoveWindow(x
, y
, width
, height
);
769 // For implementation purposes - sometimes decorations make the client area
772 wxPoint
wxWindowMac::GetClientAreaOrigin() const
774 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
777 void wxWindowMac::SetTitle(const wxString
& title
)
782 wxString
wxWindowMac::GetTitle() const
787 bool wxWindowMac::Show(bool show
)
789 if ( !wxWindowBase::Show(show
) )
792 MacSuperShown( show
) ;
798 void wxWindowMac::MacSuperShown( bool show
)
800 wxWindowListNode
*node
= GetChildren().GetFirst();
803 wxWindowMac
*child
= node
->GetData();
804 if ( child
->m_isShown
)
805 child
->MacSuperShown( show
) ;
806 node
= node
->GetNext();
810 void wxWindowMac::MacSuperEnabled( bool enabled
)
814 // to be absolutely correct we'd have to invalidate (with eraseBkground
815 // because unter MacOSX the frames are drawn with an addXXX mode)
818 wxWindowListNode
*node
= GetChildren().GetFirst();
821 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
822 if ( child
->m_isShown
)
823 child
->MacSuperEnabled( enabled
) ;
824 node
= node
->GetNext();
828 bool wxWindowMac::MacIsReallyShown() const
830 if ( m_isShown
&& (m_parent
!= NULL
) ) {
831 return m_parent
->MacIsReallyShown();
835 bool status = m_isShown ;
836 wxWindowMac * win = this ;
837 while ( status && win->m_parent != NULL )
839 win = win->m_parent ;
840 status = win->m_isShown ;
846 int wxWindowMac::GetCharHeight() const
848 wxClientDC
dc ( (wxWindowMac
*)this ) ;
849 return dc
.GetCharHeight() ;
852 int wxWindowMac::GetCharWidth() const
854 wxClientDC
dc ( (wxWindowMac
*)this ) ;
855 return dc
.GetCharWidth() ;
858 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
859 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
861 const wxFont
*fontToUse
= theFont
;
865 wxClientDC
dc( (wxWindowMac
*) this ) ;
867 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
868 if ( externalLeading
)
869 *externalLeading
= le
;
879 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
880 * we always intersect with the entire window, not only with the client area
883 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
885 if ( MacGetTopLevelWindow() == NULL
)
888 if ( !MacIsReallyShown() )
891 wxPoint client
= GetClientAreaOrigin();
894 int x2
= m_width
- client
.x
;
895 int y2
= m_height
- client
.y
;
897 if (IsKindOf( CLASSINFO(wxButton
)))
899 // buttons have an "aura"
906 Rect clientrect
= { y1
, x1
, y2
, x2
};
910 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
911 SectRect( &clientrect
, &r
, &clientrect
) ;
914 if ( !EmptyRect( &clientrect
) )
916 int top
= 0 , left
= 0 ;
918 MacClientToRootWindow( &left
, &top
) ;
919 OffsetRect( &clientrect
, left
, top
) ;
921 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
925 wxWindowMac
*wxGetActiveWindow()
927 // actually this is a windows-only concept
931 // Coordinates relative to the window
932 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
934 // We really don't move the mouse programmatically under Mac.
937 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
939 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
941 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
943 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
945 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
946 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
947 // either a non gray background color or a non control window
949 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
951 wxWindowMac
* parent
= GetParent() ;
954 if ( parent
->MacGetRootWindow() != window
)
956 // we are in a different window on the mac system
962 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
963 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
965 // if we have any other colours in the hierarchy
966 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
969 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
970 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
972 Rect extent
= { 0 , 0 , 0 , 0 } ;
975 wxSize size
= parent
->GetSize() ;
976 parent
->MacClientToRootWindow( &x
, &y
) ;
980 extent
.right
= x
+ size
.x
;
981 extent
.bottom
= y
+ size
.y
;
982 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
986 parent
= parent
->GetParent() ;
990 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
995 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
998 return m_macBackgroundBrush
;
1001 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1003 event
.GetDC()->Clear() ;
1006 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1008 wxWindowDC
dc(this) ;
1009 wxMacPortSetter
helper(&dc
) ;
1011 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1014 int wxWindowMac::GetScrollPos(int orient
) const
1016 if ( orient
== wxHORIZONTAL
)
1019 return m_hScrollBar
->GetThumbPosition() ;
1024 return m_vScrollBar
->GetThumbPosition() ;
1029 // This now returns the whole range, not just the number
1030 // of positions that we can scroll.
1031 int wxWindowMac::GetScrollRange(int orient
) const
1033 if ( orient
== wxHORIZONTAL
)
1036 return m_hScrollBar
->GetRange() ;
1041 return m_vScrollBar
->GetRange() ;
1046 int wxWindowMac::GetScrollThumb(int orient
) const
1048 if ( orient
== wxHORIZONTAL
)
1051 return m_hScrollBar
->GetThumbSize() ;
1056 return m_vScrollBar
->GetThumbSize() ;
1061 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1063 if ( orient
== wxHORIZONTAL
)
1066 m_hScrollBar
->SetThumbPosition( pos
) ;
1071 m_vScrollBar
->SetThumbPosition( pos
) ;
1075 void wxWindowMac::MacPaintBorders( int left
, int top
)
1080 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1081 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1082 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1083 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1086 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1088 #if wxMAC_USE_THEME_BORDER
1089 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1092 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1093 InsetRect( &rect , border , border );
1094 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1097 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1099 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1100 RGBForeColor( &face
);
1101 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1102 LineTo( left
+ 0 , top
+ 0 );
1103 LineTo( left
+ m_width
- 2 , top
+ 0 );
1105 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1106 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1107 LineTo( left
+ m_width
- 3 , top
+ 2 );
1109 RGBForeColor( sunken
? &face
: &black
);
1110 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1111 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1112 LineTo( left
+ m_width
- 1 , top
+ 0 );
1114 RGBForeColor( sunken
? &shadow
: &white
);
1115 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1116 LineTo( left
+ 1, top
+ 1 );
1117 LineTo( left
+ m_width
- 3 , top
+ 1 );
1119 RGBForeColor( sunken
? &white
: &shadow
);
1120 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1121 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1122 LineTo( left
+ m_width
- 2 , top
+ 1 );
1124 RGBForeColor( sunken
? &black
: &face
);
1125 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1126 LineTo( left
+ 2 , top
+ 2 );
1127 LineTo( left
+ m_width
- 4 , top
+ 2 );
1130 else if (HasFlag(wxSIMPLE_BORDER
))
1132 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1133 RGBForeColor( &black
) ;
1134 FrameRect( &rect
) ;
1138 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1140 if ( child
== m_hScrollBar
)
1141 m_hScrollBar
= NULL
;
1142 if ( child
== m_vScrollBar
)
1143 m_vScrollBar
= NULL
;
1145 wxWindowBase::RemoveChild( child
) ;
1148 // New function that will replace some of the above.
1149 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1150 int range
, bool refresh
)
1152 if ( orient
== wxHORIZONTAL
)
1156 if ( range
== 0 || thumbVisible
>= range
)
1158 if ( m_hScrollBar
->IsShown() )
1159 m_hScrollBar
->Show(false) ;
1163 if ( !m_hScrollBar
->IsShown() )
1164 m_hScrollBar
->Show(true) ;
1165 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1173 if ( range
== 0 || thumbVisible
>= range
)
1175 if ( m_vScrollBar
->IsShown() )
1176 m_vScrollBar
->Show(false) ;
1180 if ( !m_vScrollBar
->IsShown() )
1181 m_vScrollBar
->Show(true) ;
1182 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1186 MacRepositionScrollBars() ;
1189 // Does a physical scroll
1190 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1192 if( dx
== 0 && dy
==0 )
1197 wxClientDC
dc(this) ;
1198 wxMacPortSetter
helper(&dc
) ;
1200 int width
, height
;
1201 GetClientSize( &width
, &height
) ;
1203 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1204 RgnHandle updateRgn
= NewRgn() ;
1205 ClipRect( &scrollrect
) ;
1208 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1209 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1210 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1212 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1213 // we also have to scroll the update rgn in this rectangle
1214 // in order not to loose updates
1215 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1216 RgnHandle formerUpdateRgn
= NewRgn() ;
1217 RgnHandle scrollRgn
= NewRgn() ;
1218 RectRgn( scrollRgn
, &scrollrect
) ;
1219 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1221 LocalToGlobal( &pt
) ;
1222 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1223 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1224 if ( !EmptyRgn( formerUpdateRgn
) )
1226 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1227 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1228 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1230 InvalWindowRgn(rootWindow
, updateRgn
) ;
1231 DisposeRgn( updateRgn
) ;
1232 DisposeRgn( formerUpdateRgn
) ;
1233 DisposeRgn( scrollRgn
) ;
1236 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1238 wxWindowMac
*child
= node
->GetData();
1239 if (child
== m_vScrollBar
) continue;
1240 if (child
== m_hScrollBar
) continue;
1241 if (child
->IsTopLevel()) continue;
1244 child
->GetPosition( &x
, &y
);
1246 child
->GetSize( &w
, &h
);
1247 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1254 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1256 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1258 wxScrollWinEvent wevent
;
1259 wevent
.SetPosition(event
.GetPosition());
1260 wevent
.SetOrientation(event
.GetOrientation());
1261 wevent
.m_eventObject
= this;
1263 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
1264 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1265 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
1266 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1267 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
1268 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1269 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
1270 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1271 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
1272 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1273 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
1274 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1275 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
1276 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1277 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
1278 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1280 GetEventHandler()->ProcessEvent(wevent
);
1284 // Get the window with the focus
1285 wxWindowMac
*wxWindowBase::FindFocus()
1287 return gFocusWindow
;
1290 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1292 // panel wants to track the window which was the last to have focus in it,
1293 // so we want to set ourselves as the window which last had focus
1295 // notice that it's also important to do it upwards the tree becaus
1296 // otherwise when the top level panel gets focus, it won't set it back to
1297 // us, but to some other sibling
1299 // CS:don't know if this is still needed:
1300 //wxChildFocusEvent eventFocus(this);
1301 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1306 // Setup background and foreground colours correctly
1307 void wxWindowMac::SetupColours()
1310 SetBackgroundColour(GetParent()->GetBackgroundColour());
1313 void wxWindowMac::OnInternalIdle()
1315 // This calls the UI-update mechanism (querying windows for
1316 // menu/toolbar/control state information)
1317 if (wxUpdateUIEvent::CanUpdate(this))
1318 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1321 // Raise the window to the top of the Z order
1322 void wxWindowMac::Raise()
1326 // Lower the window to the bottom of the Z order
1327 void wxWindowMac::Lower()
1331 void wxWindowMac::DoSetClientSize(int width
, int height
)
1333 if ( width
!= -1 || height
!= -1 )
1336 if ( width
!= -1 && m_vScrollBar
)
1337 width
+= MAC_SCROLLBAR_SIZE
;
1338 if ( height
!= -1 && m_vScrollBar
)
1339 height
+= MAC_SCROLLBAR_SIZE
;
1341 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1342 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1344 DoSetSize( -1 , -1 , width
, height
) ;
1349 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1351 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1355 if ((point
.x
< 0) || (point
.y
< 0) ||
1356 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1361 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1362 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1366 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1368 wxPoint
newPoint( point
) ;
1370 if ( !IsTopLevel() )
1376 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1378 wxWindowMac
*child
= node
->GetData();
1379 // added the m_isShown test --dmazzoni
1380 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1382 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1391 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1395 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1396 if ( ::FindWindow( pt
, &window
) == 3 )
1399 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1402 // No, this yields the CLIENT are, we need the whole frame. RR.
1403 // point = win->ScreenToClient( point ) ;
1406 ::GetPort( &port
) ;
1407 ::SetPort( UMAGetWindowPort( window
) ) ;
1408 ::GlobalToLocal( &pt
) ;
1411 wxPoint
point( pt
.h
, pt
.v
) ;
1413 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1419 static wxWindow
*gs_lastWhich
= NULL
;
1421 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1423 // first trigger a set cursor event
1425 wxPoint clientorigin
= GetClientAreaOrigin() ;
1426 wxSize clientsize
= GetClientSize() ;
1428 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1430 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1432 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1433 if ( processedEvtSetCursor
&& event
.HasCursor() )
1435 cursor
= event
.GetCursor() ;
1440 // the test for processedEvtSetCursor is here to prevent using m_cursor
1441 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1442 // it - this is a way to say that our cursor shouldn't be used for this
1444 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1454 cursor
= *wxSTANDARD_CURSOR
;
1458 cursor
.MacInstall() ;
1460 return cursor
.Ok() ;
1463 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1465 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1466 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1470 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1473 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1481 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1483 wxWindowMac
*child
= node
->GetData();
1484 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1486 if (child
->MacDispatchMouseEvent(event
))
1491 wxWindow
* cursorTarget
= this ;
1492 wxPoint
cursorPoint( x
, y
) ;
1494 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1496 cursorTarget
= cursorTarget
->GetParent() ;
1498 cursorPoint
+= cursorTarget
->GetPosition() ;
1502 event
.SetEventObject( this ) ;
1504 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1506 // set focus to this window
1507 if (AcceptsFocus() && FindFocus()!=this)
1512 if ( event
.GetEventType() == wxEVT_MOTION
1513 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1514 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1515 wxToolTip::RelayEvent( this , event
);
1516 #endif // wxUSE_TOOLTIPS
1518 if (gs_lastWhich
!= this)
1520 gs_lastWhich
= this;
1522 // Double clicks must always occur on the same window
1523 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1524 event
.SetEventType( wxEVT_LEFT_DOWN
);
1525 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1526 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1528 // Same for mouse up events
1529 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1531 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1535 GetEventHandler()->ProcessEvent( event
) ;
1540 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1544 return m_tooltip
->GetTip() ;
1546 return wxEmptyString
;
1549 void wxWindowMac::Update()
1551 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1552 int top
= 0 , left
= 0 ;
1553 MacWindowToRootWindow( &left
, &top
) ;
1554 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1555 RgnHandle updateRgn
= NewRgn() ;
1556 // getting the update region in macos local coordinates
1557 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1559 ::GetPort( &port
) ;
1560 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1562 LocalToGlobal( &pt
) ;
1564 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1565 // translate to window local coordinates
1566 OffsetRgn( updateRgn
, -left
, -top
) ;
1567 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1568 MacRedraw( updateRgn
, 0 , true ) ;
1569 // for flushing and validating we need macos-local coordinates again
1570 OffsetRgn( updateRgn
, left
, top
) ;
1571 #if TARGET_API_MAC_CARBON
1572 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1574 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1577 ValidWindowRgn( rootWindow
, updateRgn
) ;
1578 DisposeRgn( updateRgn
) ;
1581 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1583 wxTopLevelWindowMac
* win
= NULL
;
1584 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1587 win
= wxFindWinFromMacWindow( window
) ;
1592 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1594 RgnHandle visRgn
= NewRgn() ;
1595 RgnHandle tempRgn
= NewRgn() ;
1596 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1598 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1600 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1601 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1603 int borderTop
= 14 ;
1604 int borderOther
= 4 ;
1606 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1607 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1610 if ( !IsTopLevel() )
1612 wxWindow
* parent
= GetParent() ;
1615 wxSize size
= parent
->GetSize() ;
1618 parent
->MacWindowToRootWindow( &x
, &y
) ;
1619 MacRootWindowToWindow( &x
, &y
) ;
1621 SetRectRgn( tempRgn
,
1622 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1623 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1624 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1626 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1627 if ( parent
->IsTopLevel() )
1629 parent
= parent
->GetParent() ;
1632 if ( respectChildrenAndSiblings
)
1634 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1636 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1638 wxWindowMac
*child
= node
->GetData();
1640 if ( !child
->IsTopLevel() && child
->IsShown() )
1642 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1643 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1645 int borderTop
= 14 ;
1646 int borderOther
= 4 ;
1648 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1649 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1651 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1656 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1658 bool thisWindowThrough
= false ;
1659 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1661 wxWindowMac
*sibling
= node
->GetData();
1662 if ( sibling
== this )
1664 thisWindowThrough
= true ;
1667 if( !thisWindowThrough
)
1672 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1674 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
) ;
1675 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1677 int borderTop
= 14 ;
1678 int borderOther
= 4 ;
1680 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
) ;
1681 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1683 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1688 m_macVisibleRegion
= visRgn
;
1689 DisposeRgn( visRgn
) ;
1690 DisposeRgn( tempRgn
) ;
1691 DisposeRgn( tempStaticBoxRgn
) ;
1692 return m_macVisibleRegion
;
1695 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1697 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1698 // updatergn is always already clipped to our boundaries
1699 // it is in window coordinates, not in client coordinates
1701 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1704 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1705 RgnHandle ownUpdateRgn
= NewRgn() ;
1706 CopyRgn( updatergn
, ownUpdateRgn
) ;
1708 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1710 // newupdate is the update region in client coordinates
1711 RgnHandle newupdate
= NewRgn() ;
1712 wxSize point
= GetClientSize() ;
1713 wxPoint origin
= GetClientAreaOrigin() ;
1714 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1715 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1716 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1717 m_updateRegion
= newupdate
;
1718 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1720 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1722 wxWindowDC
dc(this);
1723 if (!EmptyRgn(ownUpdateRgn
))
1724 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1725 wxEraseEvent
eevent( GetId(), &dc
);
1726 eevent
.SetEventObject( this );
1727 GetEventHandler()->ProcessEvent( eevent
);
1729 wxNcPaintEvent
eventNc( GetId() );
1730 eventNc
.SetEventObject( this );
1731 GetEventHandler()->ProcessEvent( eventNc
);
1733 DisposeRgn( ownUpdateRgn
) ;
1734 if ( !m_updateRegion
.Empty() )
1736 wxWindowList hiddenWindows
;
1737 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1739 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1741 if ( child
&& child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->GetMacControl() )
1743 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1744 hiddenWindows
.Append( child
) ;
1749 event
.m_timeStamp
= time
;
1750 event
.SetEventObject(this);
1751 GetEventHandler()->ProcessEvent(event
);
1753 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1755 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1757 if ( child
&& child
->GetMacControl() )
1759 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1765 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1767 RgnHandle childupdate
= NewRgn() ;
1768 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1770 // calculate the update region for the child windows by intersecting the window rectangle with our own
1771 // passed in update region and then offset it to be client-wise window coordinates again
1772 wxWindowMac
*child
= node
->GetData();
1773 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1774 SectRgn( childupdate
, updatergn
, childupdate
) ;
1775 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1776 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1778 // because dialogs may also be children
1779 child
->MacRedraw( childupdate
, time
, erase
) ;
1782 DisposeRgn( childupdate
) ;
1783 // eventually a draw grow box here
1787 WXHWND
wxWindowMac::MacGetRootWindow() const
1789 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1793 if ( iter
->IsTopLevel() )
1794 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1796 iter
= iter
->GetParent() ;
1798 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1802 void wxWindowMac::MacCreateScrollBars( long style
)
1804 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1806 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1807 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1809 GetClientSize( &width
, &height
) ;
1811 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1812 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1813 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1814 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1816 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1817 vSize
, wxVERTICAL
);
1819 if ( style
& wxVSCROLL
)
1825 m_vScrollBar
->Show(false) ;
1827 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1828 hSize
, wxHORIZONTAL
);
1829 if ( style
& wxHSCROLL
)
1834 m_hScrollBar
->Show(false) ;
1837 // because the create does not take into account the client area origin
1838 MacRepositionScrollBars() ; // we might have a real position shift
1841 void wxWindowMac::MacRepositionScrollBars()
1843 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1844 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1846 // get real client area
1848 int width
= m_width
;
1849 int height
= m_height
;
1851 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1852 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1854 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1855 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1856 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1857 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1864 MacClientToRootWindow( &x
, &y
) ;
1865 MacClientToRootWindow( &w
, &h
) ;
1867 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1869 int totW
= 10000 , totH
= 10000;
1872 if ( iter
->IsTopLevel() )
1874 totW
= iter
->m_width
;
1875 totH
= iter
->m_height
;
1879 iter
= iter
->GetParent() ;
1907 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1911 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1915 bool wxWindowMac::AcceptsFocus() const
1917 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1920 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1922 return GetParent()->MacGetContainerForEmbedding() ;
1925 void wxWindowMac::MacSuperChangedPosition()
1927 // only window-absolute structures have to be moved i.e. controls
1929 wxWindowListNode
*node
= GetChildren().GetFirst();
1932 wxWindowMac
*child
= node
->GetData();
1933 child
->MacSuperChangedPosition() ;
1934 node
= node
->GetNext();
1938 void wxWindowMac::MacTopLevelWindowChangedPosition()
1940 // only screen-absolute structures have to be moved i.e. glcanvas
1942 wxWindowListNode
*node
= GetChildren().GetFirst();
1945 wxWindowMac
*child
= node
->GetData();
1946 child
->MacTopLevelWindowChangedPosition() ;
1947 node
= node
->GetNext();
1950 long wxWindowMac::MacGetLeftBorderSize( ) const
1955 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1958 #if wxMAC_USE_THEME_BORDER
1960 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1965 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1968 #if wxMAC_USE_THEME_BORDER
1970 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1975 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1982 long wxWindowMac::MacGetRightBorderSize( ) const
1984 // they are all symmetric in mac themes
1985 return MacGetLeftBorderSize() ;
1988 long wxWindowMac::MacGetTopBorderSize( ) const
1990 // they are all symmetric in mac themes
1991 return MacGetLeftBorderSize() ;
1994 long wxWindowMac::MacGetBottomBorderSize( ) const
1996 // they are all symmetric in mac themes
1997 return MacGetLeftBorderSize() ;
2000 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2002 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2005 // Find the wxWindowMac at the current mouse position, returning the mouse
2007 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2009 pt
= wxGetMousePosition();
2010 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2014 // Get the current mouse position.
2015 wxPoint
wxGetMousePosition()
2018 wxGetMousePosition(& x
, & y
);
2019 return wxPoint(x
, y
);
2022 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2024 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2026 // copied from wxGTK : CS
2027 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2030 // (a) it's a command event and so is propagated to the parent
2031 // (b) under MSW it can be generated from kbd too
2032 // (c) it uses screen coords (because of (a))
2033 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2035 this->ClientToScreen(event
.GetPosition()));
2036 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )