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
;
179 // delete our drop target if we've got one
180 #if wxUSE_DRAG_AND_DROP
181 if ( m_dropTarget
!= NULL
)
186 #endif // wxUSE_DRAG_AND_DROP
190 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
194 const wxString
& name
)
196 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
199 // wxGTK doesn't allow to create controls with static box as the parent so
200 // this will result in a crash when the program is ported to wxGTK - warn
203 // the correct solution is to create the controls as siblings of the
205 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
206 _T("wxStaticBox can't be used as a window parent!") );
207 #endif // wxUSE_STATBOX
209 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
212 parent
->AddChild(this);
216 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
217 m_width
= WidthDefault( size
.x
);
218 m_height
= HeightDefault( size
.y
) ;
219 #ifndef __WXUNIVERSAL__
220 // Don't give scrollbars to wxControls unless they ask for them
221 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
222 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
224 MacCreateScrollBars( style
) ;
230 void wxWindowMac::SetFocus()
232 if ( gFocusWindow
== this )
235 if ( AcceptsFocus() )
241 if ( gFocusWindow
->m_caret
)
243 gFocusWindow
->m_caret
->OnKillFocus();
245 #endif // wxUSE_CARET
246 #ifndef __WXUNIVERSAL__
247 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
248 if ( control
&& control
->GetMacControl() )
250 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
251 control
->MacRedrawControl() ;
254 // Without testing the window id, for some reason
255 // a kill focus event can still be sent to
256 // the control just being focussed.
257 int thisId
= this->m_windowId
;
258 int gFocusWindowId
= gFocusWindow
->m_windowId
;
259 if (gFocusWindowId
!= thisId
)
261 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
262 event
.SetEventObject(gFocusWindow
);
263 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
266 gFocusWindow
= this ;
272 m_caret
->OnSetFocus();
274 #endif // wxUSE_CARET
275 // panel wants to track the window which was the last to have focus in it
276 wxChildFocusEvent
eventFocus(this);
277 GetEventHandler()->ProcessEvent(eventFocus
);
279 #ifndef __WXUNIVERSAL__
280 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
281 if ( control
&& control
->GetMacControl() )
283 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
286 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
287 event
.SetEventObject(this);
288 GetEventHandler()->ProcessEvent(event
) ;
293 bool wxWindowMac::Enable(bool enable
)
295 if ( !wxWindowBase::Enable(enable
) )
298 MacSuperEnabled( enable
) ;
303 void wxWindowMac::DoCaptureMouse()
305 wxTheApp
->s_captureWindow
= this ;
308 wxWindow
* wxWindowBase::GetCapture()
310 return wxTheApp
->s_captureWindow
;
313 void wxWindowMac::DoReleaseMouse()
315 wxTheApp
->s_captureWindow
= NULL
;
318 #if wxUSE_DRAG_AND_DROP
320 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
322 if ( m_dropTarget
!= 0 ) {
326 m_dropTarget
= pDropTarget
;
327 if ( m_dropTarget
!= 0 )
335 // Old style file-manager drag&drop
336 void wxWindowMac::DragAcceptFiles(bool accept
)
342 void wxWindowMac::DoGetSize(int *x
, int *y
) const
345 if(y
) *y
= m_height
;
348 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
354 if ( !IsTopLevel() && GetParent())
356 wxPoint
pt(GetParent()->GetClientAreaOrigin());
365 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
367 menu
->SetInvokingWindow(this);
369 ClientToScreen( &x
, &y
) ;
371 menu
->MacBeforeDisplay( true ) ;
372 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
373 if ( HiWord(menuResult
) != 0 )
376 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
377 wxMenuItem
* item
= NULL
;
379 item
= menu
->FindItem(id
, &realmenu
) ;
380 if (item
->IsCheckable())
382 item
->Check( !item
->IsChecked() ) ;
384 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
386 menu
->MacAfterDisplay( true ) ;
388 menu
->SetInvokingWindow(NULL
);
394 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
396 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
398 Point localwhere
= {0,0} ;
400 if(x
) localwhere
.h
= * x
;
401 if(y
) localwhere
.v
= * y
;
405 ::SetPort( UMAGetWindowPort( window
) ) ;
406 ::GlobalToLocal( &localwhere
) ;
409 if(x
) *x
= localwhere
.h
;
410 if(y
) *y
= localwhere
.v
;
412 MacRootWindowToWindow( x
, y
) ;
414 *x
-= MacGetLeftBorderSize() ;
416 *y
-= MacGetTopBorderSize() ;
419 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
421 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
424 *x
+= MacGetLeftBorderSize() ;
426 *y
+= MacGetTopBorderSize() ;
428 MacWindowToRootWindow( x
, y
) ;
430 Point localwhere
= { 0,0 };
431 if(x
) localwhere
.h
= * x
;
432 if(y
) localwhere
.v
= * y
;
436 ::SetPort( UMAGetWindowPort( window
) ) ;
438 ::LocalToGlobal( &localwhere
) ;
440 if(x
) *x
= localwhere
.h
;
441 if(y
) *y
= localwhere
.v
;
444 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
446 wxPoint origin
= GetClientAreaOrigin() ;
447 if(x
) *x
+= origin
.x
;
448 if(y
) *y
+= origin
.y
;
450 MacWindowToRootWindow( x
, y
) ;
453 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
455 wxPoint origin
= GetClientAreaOrigin() ;
456 MacRootWindowToWindow( x
, y
) ;
457 if(x
) *x
-= origin
.x
;
458 if(y
) *y
-= origin
.y
;
461 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
467 GetParent()->MacWindowToRootWindow( x
, y
) ;
471 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
477 GetParent()->MacRootWindowToWindow( x
, y
) ;
481 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
483 if (m_cursor
== cursor
)
486 if (wxNullCursor
== cursor
)
488 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
493 if ( ! wxWindowBase::SetCursor( cursor
) )
497 wxASSERT_MSG( m_cursor
.Ok(),
498 wxT("cursor must be valid after call to the base version"));
501 wxWindowMac
*mouseWin
;
504 // Change the cursor NOW if we're within the correct window
506 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
508 if ( mouseWin
== this && !wxIsBusy() )
510 m_cursor
.MacInstall() ;
518 // Get size *available for subwindows* i.e. excluding menu bar etc.
519 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
525 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
526 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
528 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
535 MacClientToRootWindow( &x1
, &y1
) ;
536 MacClientToRootWindow( &w
, &h
) ;
538 wxWindowMac
*iter
= (wxWindowMac
*)this ;
540 int totW
= 10000 , totH
= 10000;
543 if ( iter
->IsTopLevel() )
545 totW
= iter
->m_width
;
546 totH
= iter
->m_height
;
550 iter
= iter
->GetParent() ;
553 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
555 hh
-= MAC_SCROLLBAR_SIZE
;
561 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
563 ww
-= MAC_SCROLLBAR_SIZE
;
575 // ----------------------------------------------------------------------------
577 // ----------------------------------------------------------------------------
581 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
583 wxWindowBase::DoSetToolTip(tooltip
);
586 m_tooltip
->SetWindow(this);
589 #endif // wxUSE_TOOLTIPS
591 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
595 int former_w
= m_width
;
596 int former_h
= m_height
;
598 int actualWidth
= width
;
599 int actualHeight
= height
;
603 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
604 actualWidth
= m_minWidth
;
605 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
606 actualHeight
= m_minHeight
;
607 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
608 actualWidth
= m_maxWidth
;
609 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
610 actualHeight
= m_maxHeight
;
612 bool doMove
= false ;
613 bool doResize
= false ;
615 if ( actualX
!= former_x
|| actualY
!= former_y
)
619 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
624 if ( doMove
|| doResize
)
626 // erase former position
628 bool partialRepaint
= false ;
630 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
632 wxPoint
oldPos( m_x
, m_y
) ;
633 wxPoint
newPos( actualX
, actualY
) ;
634 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
635 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
636 if ( oldPos
== newPos
)
638 partialRepaint
= true ;
639 RgnHandle oldRgn
,newRgn
,diffRgn
;
643 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
644 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
645 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
646 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
647 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
648 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
651 DisposeRgn(diffRgn
) ;
655 if ( !partialRepaint
)
660 m_width
= actualWidth
;
661 m_height
= actualHeight
;
663 // update any low-level frame-relative positions
665 MacUpdateDimensions() ;
666 // erase new position
668 if ( !partialRepaint
)
671 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
673 MacRepositionScrollBars() ;
676 wxPoint
point(m_x
, m_y
);
677 wxMoveEvent
event(point
, m_windowId
);
678 event
.SetEventObject(this);
679 GetEventHandler()->ProcessEvent(event
) ;
683 MacRepositionScrollBars() ;
684 wxSize
size(m_width
, m_height
);
685 wxSizeEvent
event(size
, m_windowId
);
686 event
.SetEventObject(this);
687 GetEventHandler()->ProcessEvent(event
);
693 // set the size of the window: if the dimensions are positive, just use them,
694 // but if any of them is equal to -1, it means that we must find the value for
695 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
696 // which case -1 is a valid value for x and y)
698 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
699 // the width/height to best suit our contents, otherwise we reuse the current
701 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
703 // get the current size and position...
704 int currentX
, currentY
;
705 GetPosition(¤tX
, ¤tY
);
707 int currentW
,currentH
;
708 GetSize(¤tW
, ¤tH
);
710 // ... and don't do anything (avoiding flicker) if it's already ok
711 if ( x
== currentX
&& y
== currentY
&&
712 width
== currentW
&& height
== currentH
)
714 MacRepositionScrollBars() ; // we might have a real position shift
718 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
720 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
723 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
728 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
730 size
= DoGetBestSize();
735 // just take the current one
742 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
746 size
= DoGetBestSize();
748 //else: already called DoGetBestSize() above
754 // just take the current one
759 DoMoveWindow(x
, y
, width
, height
);
762 // For implementation purposes - sometimes decorations make the client area
765 wxPoint
wxWindowMac::GetClientAreaOrigin() const
767 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
770 void wxWindowMac::SetTitle(const wxString
& title
)
775 wxString
wxWindowMac::GetTitle() const
780 bool wxWindowMac::Show(bool show
)
782 if ( !wxWindowBase::Show(show
) )
785 MacSuperShown( show
) ;
791 void wxWindowMac::MacSuperShown( bool show
)
793 wxWindowListNode
*node
= GetChildren().GetFirst();
796 wxWindowMac
*child
= node
->GetData();
797 if ( child
->m_isShown
)
798 child
->MacSuperShown( show
) ;
799 node
= node
->GetNext();
803 void wxWindowMac::MacSuperEnabled( bool enabled
)
807 // to be absolutely correct we'd have to invalidate (with eraseBkground
808 // because unter MacOSX the frames are drawn with an addXXX mode)
811 wxWindowListNode
*node
= GetChildren().GetFirst();
814 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
815 if ( child
->m_isShown
)
816 child
->MacSuperEnabled( enabled
) ;
817 node
= node
->GetNext();
821 bool wxWindowMac::MacIsReallyShown() const
823 if ( m_isShown
&& (m_parent
!= NULL
) ) {
824 return m_parent
->MacIsReallyShown();
828 bool status = m_isShown ;
829 wxWindowMac * win = this ;
830 while ( status && win->m_parent != NULL )
832 win = win->m_parent ;
833 status = win->m_isShown ;
839 int wxWindowMac::GetCharHeight() const
841 wxClientDC
dc ( (wxWindowMac
*)this ) ;
842 return dc
.GetCharHeight() ;
845 int wxWindowMac::GetCharWidth() const
847 wxClientDC
dc ( (wxWindowMac
*)this ) ;
848 return dc
.GetCharWidth() ;
851 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
852 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
854 const wxFont
*fontToUse
= theFont
;
858 wxClientDC
dc( (wxWindowMac
*) this ) ;
860 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
861 if ( externalLeading
)
862 *externalLeading
= le
;
872 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
873 * we always intersect with the entire window, not only with the client area
876 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
878 if ( MacGetTopLevelWindow() == NULL
)
881 if ( !MacIsReallyShown() )
884 wxPoint client
= GetClientAreaOrigin();
887 int x2
= m_width
- client
.x
;
888 int y2
= m_height
- client
.y
;
890 if (IsKindOf( CLASSINFO(wxButton
)))
892 // buttons have an "aura"
899 Rect clientrect
= { y1
, x1
, y2
, x2
};
903 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
904 SectRect( &clientrect
, &r
, &clientrect
) ;
907 if ( !EmptyRect( &clientrect
) )
909 int top
= 0 , left
= 0 ;
911 MacClientToRootWindow( &left
, &top
) ;
912 OffsetRect( &clientrect
, left
, top
) ;
914 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
918 wxWindowMac
*wxGetActiveWindow()
920 // actually this is a windows-only concept
924 // Coordinates relative to the window
925 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
927 // We really don't move the mouse programmatically under Mac.
930 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
932 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
934 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
936 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
938 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
939 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
940 // either a non gray background color or a non control window
942 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
944 wxWindowMac
* parent
= GetParent() ;
947 if ( parent
->MacGetRootWindow() != window
)
949 // we are in a different window on the mac system
955 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
956 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
958 // if we have any other colours in the hierarchy
959 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
962 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
963 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
965 Rect extent
= { 0 , 0 , 0 , 0 } ;
968 wxSize size
= parent
->GetSize() ;
969 parent
->MacClientToRootWindow( &x
, &y
) ;
973 extent
.right
= x
+ size
.x
;
974 extent
.bottom
= y
+ size
.y
;
975 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
979 parent
= parent
->GetParent() ;
983 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
988 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
991 return m_macBackgroundBrush
;
994 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
996 event
.GetDC()->Clear() ;
999 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1001 wxWindowDC
dc(this) ;
1002 wxMacPortSetter
helper(&dc
) ;
1004 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1007 int wxWindowMac::GetScrollPos(int orient
) const
1009 if ( orient
== wxHORIZONTAL
)
1012 return m_hScrollBar
->GetThumbPosition() ;
1017 return m_vScrollBar
->GetThumbPosition() ;
1022 // This now returns the whole range, not just the number
1023 // of positions that we can scroll.
1024 int wxWindowMac::GetScrollRange(int orient
) const
1026 if ( orient
== wxHORIZONTAL
)
1029 return m_hScrollBar
->GetRange() ;
1034 return m_vScrollBar
->GetRange() ;
1039 int wxWindowMac::GetScrollThumb(int orient
) const
1041 if ( orient
== wxHORIZONTAL
)
1044 return m_hScrollBar
->GetThumbSize() ;
1049 return m_vScrollBar
->GetThumbSize() ;
1054 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1056 if ( orient
== wxHORIZONTAL
)
1059 m_hScrollBar
->SetThumbPosition( pos
) ;
1064 m_vScrollBar
->SetThumbPosition( pos
) ;
1068 void wxWindowMac::MacPaintBorders( int left
, int top
)
1073 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1074 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1075 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1076 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1079 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1081 #if wxMAC_USE_THEME_BORDER
1082 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1085 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1086 InsetRect( &rect , border , border );
1087 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1090 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1092 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1093 RGBForeColor( &face
);
1094 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1095 LineTo( left
+ 0 , top
+ 0 );
1096 LineTo( left
+ m_width
- 2 , top
+ 0 );
1098 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1099 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1100 LineTo( left
+ m_width
- 3 , top
+ 2 );
1102 RGBForeColor( sunken
? &face
: &black
);
1103 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1104 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1105 LineTo( left
+ m_width
- 1 , top
+ 0 );
1107 RGBForeColor( sunken
? &shadow
: &white
);
1108 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1109 LineTo( left
+ 1, top
+ 1 );
1110 LineTo( left
+ m_width
- 3 , top
+ 1 );
1112 RGBForeColor( sunken
? &white
: &shadow
);
1113 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1114 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1115 LineTo( left
+ m_width
- 2 , top
+ 1 );
1117 RGBForeColor( sunken
? &black
: &face
);
1118 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1119 LineTo( left
+ 2 , top
+ 2 );
1120 LineTo( left
+ m_width
- 4 , top
+ 2 );
1123 else if (HasFlag(wxSIMPLE_BORDER
))
1125 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1126 RGBForeColor( &black
) ;
1127 FrameRect( &rect
) ;
1131 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1133 if ( child
== m_hScrollBar
)
1134 m_hScrollBar
= NULL
;
1135 if ( child
== m_vScrollBar
)
1136 m_vScrollBar
= NULL
;
1138 wxWindowBase::RemoveChild( child
) ;
1141 // New function that will replace some of the above.
1142 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1143 int range
, bool refresh
)
1145 if ( orient
== wxHORIZONTAL
)
1149 if ( range
== 0 || thumbVisible
>= range
)
1151 if ( m_hScrollBar
->IsShown() )
1152 m_hScrollBar
->Show(false) ;
1156 if ( !m_hScrollBar
->IsShown() )
1157 m_hScrollBar
->Show(true) ;
1158 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1166 if ( range
== 0 || thumbVisible
>= range
)
1168 if ( m_vScrollBar
->IsShown() )
1169 m_vScrollBar
->Show(false) ;
1173 if ( !m_vScrollBar
->IsShown() )
1174 m_vScrollBar
->Show(true) ;
1175 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1179 MacRepositionScrollBars() ;
1182 // Does a physical scroll
1183 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1185 if( dx
== 0 && dy
==0 )
1190 wxClientDC
dc(this) ;
1191 wxMacPortSetter
helper(&dc
) ;
1193 int width
, height
;
1194 GetClientSize( &width
, &height
) ;
1196 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1197 RgnHandle updateRgn
= NewRgn() ;
1198 ClipRect( &scrollrect
) ;
1201 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1202 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1203 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1205 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1206 // we also have to scroll the update rgn in this rectangle
1207 // in order not to loose updates
1208 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1209 RgnHandle formerUpdateRgn
= NewRgn() ;
1210 RgnHandle scrollRgn
= NewRgn() ;
1211 RectRgn( scrollRgn
, &scrollrect
) ;
1212 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1214 LocalToGlobal( &pt
) ;
1215 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1216 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1217 if ( !EmptyRgn( formerUpdateRgn
) )
1219 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1220 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1221 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1223 InvalWindowRgn(rootWindow
, updateRgn
) ;
1224 DisposeRgn( updateRgn
) ;
1225 DisposeRgn( formerUpdateRgn
) ;
1226 DisposeRgn( scrollRgn
) ;
1229 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1231 wxWindowMac
*child
= node
->GetData();
1232 if (child
== m_vScrollBar
) continue;
1233 if (child
== m_hScrollBar
) continue;
1234 if (child
->IsTopLevel()) continue;
1237 child
->GetPosition( &x
, &y
);
1239 child
->GetSize( &w
, &h
);
1240 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1247 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1249 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1251 wxScrollWinEvent wevent
;
1252 wevent
.SetPosition(event
.GetPosition());
1253 wevent
.SetOrientation(event
.GetOrientation());
1254 wevent
.m_eventObject
= this;
1256 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
1257 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1258 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
1259 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1260 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
1261 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1262 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
1263 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1264 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
1265 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1266 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
1267 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1268 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
1269 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1270 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
1271 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1273 GetEventHandler()->ProcessEvent(wevent
);
1277 // Get the window with the focus
1278 wxWindowMac
*wxWindowBase::FindFocus()
1280 return gFocusWindow
;
1283 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1285 // panel wants to track the window which was the last to have focus in it,
1286 // so we want to set ourselves as the window which last had focus
1288 // notice that it's also important to do it upwards the tree becaus
1289 // otherwise when the top level panel gets focus, it won't set it back to
1290 // us, but to some other sibling
1292 // CS:don't know if this is still needed:
1293 //wxChildFocusEvent eventFocus(this);
1294 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1299 // Setup background and foreground colours correctly
1300 void wxWindowMac::SetupColours()
1303 SetBackgroundColour(GetParent()->GetBackgroundColour());
1306 void wxWindowMac::OnInternalIdle()
1308 // This calls the UI-update mechanism (querying windows for
1309 // menu/toolbar/control state information)
1310 if (wxUpdateUIEvent::CanUpdate(this))
1311 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1314 // Raise the window to the top of the Z order
1315 void wxWindowMac::Raise()
1319 // Lower the window to the bottom of the Z order
1320 void wxWindowMac::Lower()
1324 void wxWindowMac::DoSetClientSize(int width
, int height
)
1326 if ( width
!= -1 || height
!= -1 )
1329 if ( width
!= -1 && m_vScrollBar
)
1330 width
+= MAC_SCROLLBAR_SIZE
;
1331 if ( height
!= -1 && m_vScrollBar
)
1332 height
+= MAC_SCROLLBAR_SIZE
;
1334 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1335 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1337 DoSetSize( -1 , -1 , width
, height
) ;
1342 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1344 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1348 if ((point
.x
< 0) || (point
.y
< 0) ||
1349 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1354 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1355 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1359 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1361 wxPoint
newPoint( point
) ;
1363 if ( !IsTopLevel() )
1369 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1371 wxWindowMac
*child
= node
->GetData();
1372 // added the m_isShown test --dmazzoni
1373 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1375 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1384 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1388 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1389 if ( ::FindWindow( pt
, &window
) == 3 )
1392 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1395 // No, this yields the CLIENT are, we need the whole frame. RR.
1396 // point = win->ScreenToClient( point ) ;
1399 ::GetPort( &port
) ;
1400 ::SetPort( UMAGetWindowPort( window
) ) ;
1401 ::GlobalToLocal( &pt
) ;
1404 wxPoint
point( pt
.h
, pt
.v
) ;
1406 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1412 static wxWindow
*gs_lastWhich
= NULL
;
1414 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1416 // first trigger a set cursor event
1418 wxPoint clientorigin
= GetClientAreaOrigin() ;
1419 wxSize clientsize
= GetClientSize() ;
1421 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1423 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1425 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1426 if ( processedEvtSetCursor
&& event
.HasCursor() )
1428 cursor
= event
.GetCursor() ;
1433 // the test for processedEvtSetCursor is here to prevent using m_cursor
1434 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1435 // it - this is a way to say that our cursor shouldn't be used for this
1437 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1447 cursor
= *wxSTANDARD_CURSOR
;
1451 cursor
.MacInstall() ;
1453 return cursor
.Ok() ;
1456 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1458 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1459 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1463 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1466 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1474 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1476 wxWindowMac
*child
= node
->GetData();
1477 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1479 if (child
->MacDispatchMouseEvent(event
))
1484 wxWindow
* cursorTarget
= this ;
1485 wxPoint
cursorPoint( x
, y
) ;
1487 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1489 cursorTarget
= cursorTarget
->GetParent() ;
1491 cursorPoint
+= cursorTarget
->GetPosition() ;
1495 event
.SetEventObject( this ) ;
1497 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1499 // set focus to this window
1500 if (AcceptsFocus() && FindFocus()!=this)
1505 if ( event
.GetEventType() == wxEVT_MOTION
1506 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1507 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1508 wxToolTip::RelayEvent( this , event
);
1509 #endif // wxUSE_TOOLTIPS
1511 if (gs_lastWhich
!= this)
1513 gs_lastWhich
= this;
1515 // Double clicks must always occur on the same window
1516 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1517 event
.SetEventType( wxEVT_LEFT_DOWN
);
1518 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1519 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1521 // Same for mouse up events
1522 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1524 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1528 GetEventHandler()->ProcessEvent( event
) ;
1533 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1537 return m_tooltip
->GetTip() ;
1539 return wxEmptyString
;
1542 void wxWindowMac::Update()
1544 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1545 int top
= 0 , left
= 0 ;
1546 MacWindowToRootWindow( &left
, &top
) ;
1547 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1548 RgnHandle updateRgn
= NewRgn() ;
1549 // getting the update region in macos local coordinates
1550 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1552 ::GetPort( &port
) ;
1553 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1555 LocalToGlobal( &pt
) ;
1557 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1558 // translate to window local coordinates
1559 OffsetRgn( updateRgn
, -left
, -top
) ;
1560 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1561 MacRedraw( updateRgn
, 0 , true ) ;
1562 // for flushing and validating we need macos-local coordinates again
1563 OffsetRgn( updateRgn
, left
, top
) ;
1564 #if TARGET_API_MAC_CARBON
1565 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1567 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1570 ValidWindowRgn( rootWindow
, updateRgn
) ;
1571 DisposeRgn( updateRgn
) ;
1574 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1576 wxTopLevelWindowMac
* win
= NULL
;
1577 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1580 win
= wxFindWinFromMacWindow( window
) ;
1585 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1587 RgnHandle visRgn
= NewRgn() ;
1588 RgnHandle tempRgn
= NewRgn() ;
1589 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1591 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1593 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1594 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1596 int borderTop
= 14 ;
1597 int borderOther
= 4 ;
1599 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1600 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1603 if ( !IsTopLevel() )
1605 wxWindow
* parent
= GetParent() ;
1608 wxSize size
= parent
->GetSize() ;
1611 parent
->MacWindowToRootWindow( &x
, &y
) ;
1612 MacRootWindowToWindow( &x
, &y
) ;
1614 SetRectRgn( tempRgn
,
1615 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1616 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1617 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1619 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1620 if ( parent
->IsTopLevel() )
1622 parent
= parent
->GetParent() ;
1625 if ( respectChildrenAndSiblings
)
1627 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1629 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1631 wxWindowMac
*child
= node
->GetData();
1633 if ( !child
->IsTopLevel() && child
->IsShown() )
1635 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1636 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1638 int borderTop
= 14 ;
1639 int borderOther
= 4 ;
1641 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1642 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1644 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1649 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1651 bool thisWindowThrough
= false ;
1652 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1654 wxWindowMac
*sibling
= node
->GetData();
1655 if ( sibling
== this )
1657 thisWindowThrough
= true ;
1660 if( !thisWindowThrough
)
1665 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1667 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
) ;
1668 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1670 int borderTop
= 14 ;
1671 int borderOther
= 4 ;
1673 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
) ;
1674 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1676 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1681 m_macVisibleRegion
= visRgn
;
1682 DisposeRgn( visRgn
) ;
1683 DisposeRgn( tempRgn
) ;
1684 DisposeRgn( tempStaticBoxRgn
) ;
1685 return m_macVisibleRegion
;
1688 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1690 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1691 // updatergn is always already clipped to our boundaries
1692 // it is in window coordinates, not in client coordinates
1694 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1697 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1698 RgnHandle ownUpdateRgn
= NewRgn() ;
1699 CopyRgn( updatergn
, ownUpdateRgn
) ;
1701 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1703 // newupdate is the update region in client coordinates
1704 RgnHandle newupdate
= NewRgn() ;
1705 wxSize point
= GetClientSize() ;
1706 wxPoint origin
= GetClientAreaOrigin() ;
1707 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1708 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1709 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1710 m_updateRegion
= newupdate
;
1711 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1713 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1715 wxWindowDC
dc(this);
1716 if (!EmptyRgn(ownUpdateRgn
))
1717 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1718 wxEraseEvent
eevent( GetId(), &dc
);
1719 eevent
.SetEventObject( this );
1720 GetEventHandler()->ProcessEvent( eevent
);
1722 wxNcPaintEvent
eventNc( GetId() );
1723 eventNc
.SetEventObject( this );
1724 GetEventHandler()->ProcessEvent( eventNc
);
1726 DisposeRgn( ownUpdateRgn
) ;
1727 if ( !m_updateRegion
.Empty() )
1729 wxWindowList hiddenWindows
;
1730 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1732 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1734 if ( child
&& child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->GetMacControl() )
1736 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1737 hiddenWindows
.Append( child
) ;
1742 event
.m_timeStamp
= time
;
1743 event
.SetEventObject(this);
1744 GetEventHandler()->ProcessEvent(event
);
1746 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1748 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1750 if ( child
&& child
->GetMacControl() )
1752 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1758 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1760 RgnHandle childupdate
= NewRgn() ;
1761 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1763 // calculate the update region for the child windows by intersecting the window rectangle with our own
1764 // passed in update region and then offset it to be client-wise window coordinates again
1765 wxWindowMac
*child
= node
->GetData();
1766 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1767 SectRgn( childupdate
, updatergn
, childupdate
) ;
1768 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1769 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1771 // because dialogs may also be children
1772 child
->MacRedraw( childupdate
, time
, erase
) ;
1775 DisposeRgn( childupdate
) ;
1776 // eventually a draw grow box here
1780 WXHWND
wxWindowMac::MacGetRootWindow() const
1782 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1786 if ( iter
->IsTopLevel() )
1787 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1789 iter
= iter
->GetParent() ;
1791 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1795 void wxWindowMac::MacCreateScrollBars( long style
)
1797 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1799 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1800 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1802 GetClientSize( &width
, &height
) ;
1804 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1805 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1806 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1807 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1809 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1810 vSize
, wxVERTICAL
);
1812 if ( style
& wxVSCROLL
)
1818 m_vScrollBar
->Show(false) ;
1820 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1821 hSize
, wxHORIZONTAL
);
1822 if ( style
& wxHSCROLL
)
1827 m_hScrollBar
->Show(false) ;
1830 // because the create does not take into account the client area origin
1831 MacRepositionScrollBars() ; // we might have a real position shift
1834 void wxWindowMac::MacRepositionScrollBars()
1836 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1837 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1839 // get real client area
1841 int width
= m_width
;
1842 int height
= m_height
;
1844 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1845 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1847 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1848 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1849 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1850 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1857 MacClientToRootWindow( &x
, &y
) ;
1858 MacClientToRootWindow( &w
, &h
) ;
1860 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1862 int totW
= 10000 , totH
= 10000;
1865 if ( iter
->IsTopLevel() )
1867 totW
= iter
->m_width
;
1868 totH
= iter
->m_height
;
1872 iter
= iter
->GetParent() ;
1900 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1904 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1908 bool wxWindowMac::AcceptsFocus() const
1910 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1913 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1915 return GetParent()->MacGetContainerForEmbedding() ;
1918 void wxWindowMac::MacSuperChangedPosition()
1920 // only window-absolute structures have to be moved i.e. controls
1922 wxWindowListNode
*node
= GetChildren().GetFirst();
1925 wxWindowMac
*child
= node
->GetData();
1926 child
->MacSuperChangedPosition() ;
1927 node
= node
->GetNext();
1931 void wxWindowMac::MacTopLevelWindowChangedPosition()
1933 // only screen-absolute structures have to be moved i.e. glcanvas
1935 wxWindowListNode
*node
= GetChildren().GetFirst();
1938 wxWindowMac
*child
= node
->GetData();
1939 child
->MacTopLevelWindowChangedPosition() ;
1940 node
= node
->GetNext();
1943 long wxWindowMac::MacGetLeftBorderSize( ) const
1948 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1951 #if wxMAC_USE_THEME_BORDER
1953 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1958 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1961 #if wxMAC_USE_THEME_BORDER
1963 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1968 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1975 long wxWindowMac::MacGetRightBorderSize( ) const
1977 // they are all symmetric in mac themes
1978 return MacGetLeftBorderSize() ;
1981 long wxWindowMac::MacGetTopBorderSize( ) const
1983 // they are all symmetric in mac themes
1984 return MacGetLeftBorderSize() ;
1987 long wxWindowMac::MacGetBottomBorderSize( ) const
1989 // they are all symmetric in mac themes
1990 return MacGetLeftBorderSize() ;
1993 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1995 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1998 // Find the wxWindowMac at the current mouse position, returning the mouse
2000 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2002 pt
= wxGetMousePosition();
2003 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2007 // Get the current mouse position.
2008 wxPoint
wxGetMousePosition()
2011 wxGetMousePosition(& x
, & y
);
2012 return wxPoint(x
, y
);
2015 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2017 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2019 // copied from wxGTK : CS
2020 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2023 // (a) it's a command event and so is propagated to the parent
2024 // (b) under MSW it can be generated from kbd too
2025 // (c) it uses screen coords (because of (a))
2026 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2028 this->ClientToScreen(event
.GetPosition()));
2029 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )