1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
8 // Copyright: (c) AUTHOR
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_IDLE(wxWindowMac::OnIdle
)
79 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
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()
107 m_doubleClickAllowed
= 0;
108 m_winCaptured
= FALSE
;
110 m_isBeingDeleted
= FALSE
;
113 m_mouseInWindow
= FALSE
;
117 m_backgroundTransparent
= FALSE
;
119 // as all windows are created with WS_VISIBLE style...
127 m_hScrollBar
= NULL
;
128 m_vScrollBar
= NULL
;
130 m_label
= wxEmptyString
;
134 wxWindowMac::~wxWindowMac()
136 // deleting a window while it is shown invalidates the region
138 wxWindowMac
* iter
= this ;
140 if ( iter
->IsTopLevel() )
145 iter
= iter
->GetParent() ;
150 m_isBeingDeleted
= TRUE
;
152 #ifndef __WXUNIVERSAL__
153 // VS: make sure there's no wxFrame with last focus set to us:
154 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
156 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
159 if ( frame
->GetLastFocus() == this )
161 frame
->SetLastFocus((wxWindow
*)NULL
);
166 #endif // __WXUNIVERSAL__
168 if ( s_lastMouseWindow
== this )
170 s_lastMouseWindow
= NULL
;
173 if ( gFocusWindow
== this )
175 gFocusWindow
= NULL
;
179 m_parent
->RemoveChild(this);
185 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
189 const wxString
& name
)
191 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
193 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
196 parent
->AddChild(this);
200 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
201 m_width
= WidthDefault( size
.x
);
202 m_height
= HeightDefault( size
.y
) ;
203 #ifndef __WXUNIVERSAL__
204 // Don't give scrollbars to wxControls unless they ask for them
205 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
206 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
208 MacCreateScrollBars( style
) ;
214 void wxWindowMac::SetFocus()
216 if ( gFocusWindow
== this )
219 if ( AcceptsFocus() )
225 if ( gFocusWindow
->m_caret
)
227 gFocusWindow
->m_caret
->OnKillFocus();
229 #endif // wxUSE_CARET
230 #ifndef __WXUNIVERSAL__
231 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
232 if ( control
&& control
->GetMacControl() )
234 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
235 control
->MacRedrawControl() ;
238 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
239 event
.SetEventObject(gFocusWindow
);
240 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
242 gFocusWindow
= this ;
248 m_caret
->OnSetFocus();
250 #endif // wxUSE_CARET
251 // panel wants to track the window which was the last to have focus in it
252 wxChildFocusEvent
eventFocus(this);
253 GetEventHandler()->ProcessEvent(eventFocus
);
255 #ifndef __WXUNIVERSAL__
256 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
257 if ( control
&& control
->GetMacControl() )
259 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
262 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
263 event
.SetEventObject(this);
264 GetEventHandler()->ProcessEvent(event
) ;
269 bool wxWindowMac::Enable(bool enable
)
271 if ( !wxWindowBase::Enable(enable
) )
274 MacSuperEnabled( enable
) ;
279 void wxWindowMac::DoCaptureMouse()
281 wxTheApp
->s_captureWindow
= this ;
284 wxWindow
* wxWindowBase::GetCapture()
286 return wxTheApp
->s_captureWindow
;
289 void wxWindowMac::DoReleaseMouse()
291 wxTheApp
->s_captureWindow
= NULL
;
294 #if wxUSE_DRAG_AND_DROP
296 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
298 if ( m_dropTarget
!= 0 ) {
302 m_dropTarget
= pDropTarget
;
303 if ( m_dropTarget
!= 0 )
311 // Old style file-manager drag&drop
312 void wxWindowMac::DragAcceptFiles(bool accept
)
318 void wxWindowMac::DoGetSize(int *x
, int *y
) const
321 if(y
) *y
= m_height
;
324 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
330 if ( !IsTopLevel() && GetParent())
332 wxPoint
pt(GetParent()->GetClientAreaOrigin());
341 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
343 menu
->SetInvokingWindow(this);
345 ClientToScreen( &x
, &y
) ;
347 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
348 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
349 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
350 ::DeleteMenu( menu
->MacGetMenuId() ) ;
351 menu
->SetInvokingWindow(NULL
);
357 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
359 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
361 Point localwhere
= {0,0} ;
363 if(x
) localwhere
.h
= * x
;
364 if(y
) localwhere
.v
= * y
;
368 ::SetPort( UMAGetWindowPort( window
) ) ;
369 ::GlobalToLocal( &localwhere
) ;
372 if(x
) *x
= localwhere
.h
;
373 if(y
) *y
= localwhere
.v
;
375 MacRootWindowToWindow( x
, y
) ;
377 x
-= MacGetLeftBorderSize() ;
379 y
-= MacGetTopBorderSize() ;
382 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
384 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
387 x
+= MacGetLeftBorderSize() ;
389 y
+= MacGetTopBorderSize() ;
391 MacWindowToRootWindow( x
, y
) ;
393 Point localwhere
= { 0,0 };
394 if(x
) localwhere
.h
= * x
;
395 if(y
) localwhere
.v
= * y
;
399 ::SetPort( UMAGetWindowPort( window
) ) ;
401 ::LocalToGlobal( &localwhere
) ;
403 if(x
) *x
= localwhere
.h
;
404 if(y
) *y
= localwhere
.v
;
407 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
409 wxPoint origin
= GetClientAreaOrigin() ;
410 if(x
) *x
+= origin
.x
;
411 if(y
) *y
+= origin
.y
;
413 MacWindowToRootWindow( x
, y
) ;
416 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
418 wxPoint origin
= GetClientAreaOrigin() ;
419 MacRootWindowToWindow( x
, y
) ;
420 if(x
) *x
-= origin
.x
;
421 if(y
) *y
-= origin
.y
;
424 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
430 GetParent()->MacWindowToRootWindow( x
, y
) ;
434 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
440 GetParent()->MacRootWindowToWindow( x
, y
) ;
444 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
446 if (m_cursor
== cursor
)
449 if (wxNullCursor
== cursor
)
451 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
456 if ( ! wxWindowBase::SetCursor( cursor
) )
460 wxASSERT_MSG( m_cursor
.Ok(),
461 wxT("cursor must be valid after call to the base version"));
464 wxWindowMac
*mouseWin
;
467 // Change the cursor NOW if we're within the correct window
469 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
471 if ( mouseWin
== this && !wxIsBusy() )
473 m_cursor
.MacInstall() ;
481 // Get size *available for subwindows* i.e. excluding menu bar etc.
482 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
488 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
489 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
491 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
498 MacClientToRootWindow( &x1
, &y1
) ;
499 MacClientToRootWindow( &w
, &h
) ;
501 wxWindowMac
*iter
= (wxWindowMac
*)this ;
503 int totW
= 10000 , totH
= 10000;
506 if ( iter
->IsTopLevel() )
508 totW
= iter
->m_width
;
509 totH
= iter
->m_height
;
513 iter
= iter
->GetParent() ;
516 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
518 hh
-= MAC_SCROLLBAR_SIZE
;
524 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
526 ww
-= MAC_SCROLLBAR_SIZE
;
538 // ----------------------------------------------------------------------------
540 // ----------------------------------------------------------------------------
544 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
546 wxWindowBase::DoSetToolTip(tooltip
);
549 m_tooltip
->SetWindow(this);
552 #endif // wxUSE_TOOLTIPS
554 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
558 int former_w
= m_width
;
559 int former_h
= m_height
;
561 int actualWidth
= width
;
562 int actualHeight
= height
;
566 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
567 actualWidth
= m_minWidth
;
568 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
569 actualHeight
= m_minHeight
;
570 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
571 actualWidth
= m_maxWidth
;
572 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
573 actualHeight
= m_maxHeight
;
575 bool doMove
= false ;
576 bool doResize
= false ;
578 if ( actualX
!= former_x
|| actualY
!= former_y
)
582 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
587 if ( doMove
|| doResize
)
589 // erase former position
595 m_width
= actualWidth
;
596 m_height
= actualHeight
;
598 // update any low-level frame-relative positions
600 MacUpdateDimensions() ;
601 // erase new position
605 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
607 MacRepositionScrollBars() ;
610 wxPoint
point(m_x
, m_y
);
611 wxMoveEvent
event(point
, m_windowId
);
612 event
.SetEventObject(this);
613 GetEventHandler()->ProcessEvent(event
) ;
617 MacRepositionScrollBars() ;
618 wxSize
size(m_width
, m_height
);
619 wxSizeEvent
event(size
, m_windowId
);
620 event
.SetEventObject(this);
621 GetEventHandler()->ProcessEvent(event
);
627 // set the size of the window: if the dimensions are positive, just use them,
628 // but if any of them is equal to -1, it means that we must find the value for
629 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
630 // which case -1 is a valid value for x and y)
632 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
633 // the width/height to best suit our contents, otherwise we reuse the current
635 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
637 // get the current size and position...
638 int currentX
, currentY
;
639 GetPosition(¤tX
, ¤tY
);
641 int currentW
,currentH
;
642 GetSize(¤tW
, ¤tH
);
644 // ... and don't do anything (avoiding flicker) if it's already ok
645 if ( x
== currentX
&& y
== currentY
&&
646 width
== currentW
&& height
== currentH
)
648 MacRepositionScrollBars() ; // we might have a real position shift
652 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
654 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
657 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
662 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
664 size
= DoGetBestSize();
669 // just take the current one
676 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
680 size
= DoGetBestSize();
682 //else: already called DoGetBestSize() above
688 // just take the current one
693 DoMoveWindow(x
, y
, width
, height
);
696 // For implementation purposes - sometimes decorations make the client area
699 wxPoint
wxWindowMac::GetClientAreaOrigin() const
701 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
704 void wxWindowMac::SetTitle(const wxString
& title
)
709 wxString
wxWindowMac::GetTitle() const
714 bool wxWindowMac::Show(bool show
)
716 if ( !wxWindowBase::Show(show
) )
720 WindowRef window = (WindowRef) MacGetRootWindow() ;
721 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
722 if ( win == NULL && win->m_isBeingDeleted )
725 MacSuperShown( show
) ;
730 if ( win && !win->m_isBeingDeleted )
741 void wxWindowMac::MacSuperShown( bool show
)
743 wxNode
*node
= GetChildren().First();
746 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
747 if ( child
->m_isShown
)
748 child
->MacSuperShown( show
) ;
753 void wxWindowMac::MacSuperEnabled( bool enabled
)
757 // to be absolutely correct we'd have to invalidate (with eraseBkground
758 // because unter MacOSX the frames are drawn with an addXXX mode)
761 wxNode
*node
= GetChildren().First();
764 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
765 if ( child
->m_isShown
)
766 child
->MacSuperEnabled( enabled
) ;
771 bool wxWindowMac::MacIsReallyShown() const
773 if ( m_isShown
&& (m_parent
!= NULL
) ) {
774 return m_parent
->MacIsReallyShown();
778 bool status = m_isShown ;
779 wxWindowMac * win = this ;
780 while ( status && win->m_parent != NULL )
782 win = win->m_parent ;
783 status = win->m_isShown ;
789 int wxWindowMac::GetCharHeight() const
791 wxClientDC
dc ( (wxWindowMac
*)this ) ;
792 return dc
.GetCharHeight() ;
795 int wxWindowMac::GetCharWidth() const
797 wxClientDC
dc ( (wxWindowMac
*)this ) ;
798 return dc
.GetCharWidth() ;
801 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
802 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
804 const wxFont
*fontToUse
= theFont
;
808 wxClientDC
dc( (wxWindowMac
*) this ) ;
810 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
811 if ( externalLeading
)
812 *externalLeading
= le
;
822 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
823 * we always intersect with the entire window, not only with the client area
826 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
828 if ( MacGetTopLevelWindow() == NULL
)
831 wxPoint client
= GetClientAreaOrigin();
834 int x2
= m_width
- client
.x
;
835 int y2
= m_height
- client
.y
;
837 if (IsKindOf( CLASSINFO(wxButton
)))
839 // buttons have an "aura"
846 Rect clientrect
= { y1
, x1
, y2
, x2
};
850 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
851 SectRect( &clientrect
, &r
, &clientrect
) ;
854 if ( !EmptyRect( &clientrect
) )
856 int top
= 0 , left
= 0 ;
858 MacClientToRootWindow( &left
, &top
) ;
859 OffsetRect( &clientrect
, left
, top
) ;
861 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
865 #if wxUSE_CARET && WXWIN_COMPATIBILITY
866 // ---------------------------------------------------------------------------
867 // Caret manipulation
868 // ---------------------------------------------------------------------------
870 void wxWindowMac::CreateCaret(int w
, int h
)
872 SetCaret(new wxCaret(this, w
, h
));
875 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
877 wxFAIL_MSG("not implemented");
880 void wxWindowMac::ShowCaret(bool show
)
882 wxCHECK_RET( m_caret
, "no caret to show" );
887 void wxWindowMac::DestroyCaret()
892 void wxWindowMac::SetCaretPos(int x
, int y
)
894 wxCHECK_RET( m_caret
, "no caret to move" );
899 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
901 wxCHECK_RET( m_caret
, "no caret to get position of" );
903 m_caret
->GetPosition(x
, y
);
905 #endif // wxUSE_CARET
907 wxWindowMac
*wxGetActiveWindow()
909 // actually this is a windows-only concept
913 // Coordinates relative to the window
914 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
916 // We really dont move the mouse programmatically under mac
919 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
921 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
923 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
925 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
927 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
928 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
929 // either a non gray background color or a non control window
931 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
933 wxWindowMac
* parent
= GetParent() ;
936 if ( parent
->MacGetRootWindow() != window
)
938 // we are in a different window on the mac system
944 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
945 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
947 // if we have any other colours in the hierarchy
948 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
951 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
952 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
954 Rect extent
= { 0 , 0 , 0 , 0 } ;
957 wxSize size
= parent
->GetSize() ;
958 parent
->MacClientToRootWindow( &x
, &y
) ;
962 extent
.right
= x
+ size
.x
;
963 extent
.bottom
= y
+ size
.y
;
964 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
968 parent
= parent
->GetParent() ;
972 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
977 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
980 return m_macBackgroundBrush
;
984 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
986 event
.GetDC()->Clear() ;
989 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
991 wxWindowDC
dc(this) ;
992 wxMacPortSetter
helper(&dc
) ;
994 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
997 int wxWindowMac::GetScrollPos(int orient
) const
999 if ( orient
== wxHORIZONTAL
)
1002 return m_hScrollBar
->GetThumbPosition() ;
1007 return m_vScrollBar
->GetThumbPosition() ;
1012 // This now returns the whole range, not just the number
1013 // of positions that we can scroll.
1014 int wxWindowMac::GetScrollRange(int orient
) const
1016 if ( orient
== wxHORIZONTAL
)
1019 return m_hScrollBar
->GetRange() ;
1024 return m_vScrollBar
->GetRange() ;
1029 int wxWindowMac::GetScrollThumb(int orient
) const
1031 if ( orient
== wxHORIZONTAL
)
1034 return m_hScrollBar
->GetThumbSize() ;
1039 return m_vScrollBar
->GetThumbSize() ;
1044 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1046 if ( orient
== wxHORIZONTAL
)
1049 m_hScrollBar
->SetThumbPosition( pos
) ;
1054 m_vScrollBar
->SetThumbPosition( pos
) ;
1058 void wxWindowMac::MacPaintBorders( int left
, int top
)
1063 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1064 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1065 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1066 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1069 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1071 #if wxMAC_USE_THEME_BORDER
1072 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1075 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1076 InsetRect( &rect , border , border );
1077 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1080 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1082 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1083 RGBForeColor( &face
);
1084 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1085 LineTo( left
+ 0 , top
+ 0 );
1086 LineTo( left
+ m_width
- 2 , top
+ 0 );
1088 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1089 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1090 LineTo( left
+ m_width
- 3 , top
+ 2 );
1092 RGBForeColor( sunken
? &face
: &black
);
1093 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1094 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1095 LineTo( left
+ m_width
- 1 , top
+ 0 );
1097 RGBForeColor( sunken
? &shadow
: &white
);
1098 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1099 LineTo( left
+ 1, top
+ 1 );
1100 LineTo( left
+ m_width
- 3 , top
+ 1 );
1102 RGBForeColor( sunken
? &white
: &shadow
);
1103 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1104 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1105 LineTo( left
+ m_width
- 2 , top
+ 1 );
1107 RGBForeColor( sunken
? &black
: &face
);
1108 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1109 LineTo( left
+ 2 , top
+ 2 );
1110 LineTo( left
+ m_width
- 4 , top
+ 2 );
1113 else if (HasFlag(wxSIMPLE_BORDER
))
1115 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1116 RGBForeColor( &black
) ;
1117 FrameRect( &rect
) ;
1121 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1123 if ( child
== m_hScrollBar
)
1124 m_hScrollBar
= NULL
;
1125 if ( child
== m_vScrollBar
)
1126 m_vScrollBar
= NULL
;
1128 wxWindowBase::RemoveChild( child
) ;
1131 // New function that will replace some of the above.
1132 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1133 int range
, bool refresh
)
1135 if ( orient
== wxHORIZONTAL
)
1139 if ( range
== 0 || thumbVisible
>= range
)
1141 if ( m_hScrollBar
->IsShown() )
1142 m_hScrollBar
->Show(false) ;
1146 if ( !m_hScrollBar
->IsShown() )
1147 m_hScrollBar
->Show(true) ;
1148 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1156 if ( range
== 0 || thumbVisible
>= range
)
1158 if ( m_vScrollBar
->IsShown() )
1159 m_vScrollBar
->Show(false) ;
1163 if ( !m_vScrollBar
->IsShown() )
1164 m_vScrollBar
->Show(true) ;
1165 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1169 MacRepositionScrollBars() ;
1172 // Does a physical scroll
1173 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1175 wxClientDC
dc(this) ;
1176 wxMacPortSetter
helper(&dc
) ;
1179 int width
, height
;
1180 GetClientSize( &width
, &height
) ;
1182 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1183 RgnHandle updateRgn
= NewRgn() ;
1184 ClipRect( &scrollrect
) ;
1187 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1188 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1189 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1191 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1192 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1193 DisposeRgn( updateRgn
) ;
1196 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1198 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1199 if (child
== m_vScrollBar
) continue;
1200 if (child
== m_hScrollBar
) continue;
1201 if (child
->IsTopLevel()) continue;
1204 child
->GetPosition( &x
, &y
);
1206 child
->GetSize( &w
, &h
);
1207 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1212 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1214 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1216 wxScrollWinEvent wevent
;
1217 wevent
.SetPosition(event
.GetPosition());
1218 wevent
.SetOrientation(event
.GetOrientation());
1219 wevent
.m_eventObject
= this;
1221 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1222 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1224 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1225 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1227 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1228 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1230 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1231 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1233 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1234 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1236 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1237 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1239 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1240 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1243 GetEventHandler()->ProcessEvent(wevent
);
1247 // Get the window with the focus
1248 wxWindowMac
*wxWindowBase::FindFocus()
1250 return gFocusWindow
;
1253 #if WXWIN_COMPATIBILITY
1254 // If nothing defined for this, try the parent.
1255 // E.g. we may be a button loaded from a resource, with no callback function
1257 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1259 if ( GetEventHandler()->ProcessEvent(event
) )
1262 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1264 #endif // WXWIN_COMPATIBILITY_2
1266 #if WXWIN_COMPATIBILITY
1267 wxObject
* wxWindowMac::GetChild(int number
) const
1269 // Return a pointer to the Nth object in the Panel
1270 wxNode
*node
= GetChildren().First();
1273 node
= node
->Next();
1276 wxObject
*obj
= (wxObject
*)node
->Data();
1282 #endif // WXWIN_COMPATIBILITY
1284 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1286 // panel wants to track the window which was the last to have focus in it,
1287 // so we want to set ourselves as the window which last had focus
1289 // notice that it's also important to do it upwards the tree becaus
1290 // otherwise when the top level panel gets focus, it won't set it back to
1291 // us, but to some other sibling
1293 // CS:don't know if this is still needed:
1294 //wxChildFocusEvent eventFocus(this);
1295 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1300 void wxWindowMac::Clear()
1302 wxClientDC
dc(this);
1303 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1304 dc
.SetBackground(brush
);
1308 // Setup background and foreground colours correctly
1309 void wxWindowMac::SetupColours()
1312 SetBackgroundColour(GetParent()->GetBackgroundColour());
1315 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1318 // Check if we need to send a LEAVE event
1319 if (m_mouseInWindow)
1322 ::GetCursorPos(&pt);
1323 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1325 // Generate a LEAVE event
1326 m_mouseInWindow = FALSE;
1327 MSWOnMouseLeave(pt.x, pt.y, 0);
1332 // This calls the UI-update mechanism (querying windows for
1333 // menu/toolbar/control state information)
1337 // Raise the window to the top of the Z order
1338 void wxWindowMac::Raise()
1342 // Lower the window to the bottom of the Z order
1343 void wxWindowMac::Lower()
1347 void wxWindowMac::DoSetClientSize(int width
, int height
)
1349 if ( width
!= -1 || height
!= -1 )
1352 if ( width
!= -1 && m_vScrollBar
)
1353 width
+= MAC_SCROLLBAR_SIZE
;
1354 if ( height
!= -1 && m_vScrollBar
)
1355 height
+= MAC_SCROLLBAR_SIZE
;
1357 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1358 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1360 DoSetSize( -1 , -1 , width
, height
) ;
1365 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1367 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1371 if ((point
.x
< 0) || (point
.y
< 0) ||
1372 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1377 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1378 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1382 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1384 wxPoint
newPoint( point
) ;
1386 if ( !IsTopLevel() )
1392 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1394 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1395 // added the m_isShown test --dmazzoni
1396 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1398 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1407 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1411 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1412 if ( ::FindWindow( pt
, &window
) == 3 )
1415 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1418 // No, this yields the CLIENT are, we need the whole frame. RR.
1419 // point = win->ScreenToClient( point ) ;
1422 ::GetPort( &port
) ;
1423 ::SetPort( UMAGetWindowPort( window
) ) ;
1424 ::GlobalToLocal( &pt
) ;
1427 wxPoint
point( pt
.h
, pt
.v
) ;
1429 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1435 extern int wxBusyCursorCount
;
1436 static wxWindow
*gs_lastWhich
= NULL
;
1438 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1440 // first trigger a set cursor event
1442 wxPoint clientorigin
= GetClientAreaOrigin() ;
1443 wxSize clientsize
= GetClientSize() ;
1445 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1447 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1449 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1450 if ( processedEvtSetCursor
&& event
.HasCursor() )
1452 cursor
= event
.GetCursor() ;
1457 // the test for processedEvtSetCursor is here to prevent using m_cursor
1458 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1459 // it - this is a way to say that our cursor shouldn't be used for this
1461 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1471 cursor
= *wxSTANDARD_CURSOR
;
1475 cursor
.MacInstall() ;
1477 return cursor
.Ok() ;
1480 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1482 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1483 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1487 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1490 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1498 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1500 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1501 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1503 if (child
->MacDispatchMouseEvent(event
))
1508 wxWindow
* cursorTarget
= this ;
1509 wxPoint
cursorPoint( x
, y
) ;
1511 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1513 cursorTarget
= cursorTarget
->GetParent() ;
1515 cursorPoint
+= cursorTarget
->GetPosition() ;
1519 event
.SetEventObject( this ) ;
1521 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1523 // set focus to this window
1524 if (AcceptsFocus() && FindFocus()!=this)
1529 if ( event
.GetEventType() == wxEVT_MOTION
1530 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1531 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1532 wxToolTip::RelayEvent( this , event
);
1533 #endif // wxUSE_TOOLTIPS
1535 if (gs_lastWhich
!= this)
1537 gs_lastWhich
= this;
1539 // Double clicks must always occur on the same window
1540 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1541 event
.SetEventType( wxEVT_LEFT_DOWN
);
1542 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1543 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1545 // Same for mouse up events
1546 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1548 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1552 GetEventHandler()->ProcessEvent( event
) ;
1557 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1561 return m_tooltip
->GetTip() ;
1566 void wxWindowMac::Update()
1568 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1571 win
->MacUpdate( 0 ) ;
1572 #if TARGET_API_MAC_CARBON
1573 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1575 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
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() ;
1597 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1599 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1600 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1602 int borderTop
= 14 ;
1603 int borderOther
= 4 ;
1605 SetRectRgn( tempRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1606 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1609 if ( !IsTopLevel() )
1611 wxWindow
* parent
= GetParent() ;
1614 wxSize size
= parent
->GetSize() ;
1617 parent
->MacWindowToRootWindow( &x
, &y
) ;
1618 MacRootWindowToWindow( &x
, &y
) ;
1620 SetRectRgn( tempRgn
,
1621 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1622 x
+ size
.x
- parent
->MacGetLeftBorderSize() - parent
->MacGetRightBorderSize(),
1623 y
+ size
.y
- parent
->MacGetTopBorderSize() - parent
->MacGetBottomBorderSize()) ;
1625 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1626 if ( parent
->IsTopLevel() )
1628 parent
= parent
->GetParent() ;
1631 if ( respectChildrenAndSiblings
)
1633 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1635 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1637 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1639 if ( !child
->IsTopLevel() && child
->IsShown() )
1641 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1642 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1647 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1649 bool thisWindowThrough
= false ;
1650 for (wxNode
*node
= GetParent()->GetChildren().First(); node
; node
= node
->Next())
1652 wxWindowMac
*sibling
= (wxWindowMac
*)node
->Data();
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 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1671 m_macVisibleRegion
= visRgn
;
1672 DisposeRgn( visRgn
) ;
1673 DisposeRgn( tempRgn
) ;
1674 return m_macVisibleRegion
;
1677 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1679 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1680 // updatergn is always already clipped to our boundaries
1681 // it is in window coordinates, not in client coordinates
1683 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1686 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1687 RgnHandle ownUpdateRgn
= NewRgn() ;
1688 CopyRgn( updatergn
, ownUpdateRgn
) ;
1690 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1692 // newupdate is the update region in client coordinates
1693 RgnHandle newupdate
= NewRgn() ;
1694 wxSize point
= GetClientSize() ;
1695 wxPoint origin
= GetClientAreaOrigin() ;
1696 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1697 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1698 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1699 m_updateRegion
= newupdate
;
1700 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1702 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1704 wxWindowDC
dc(this);
1705 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1706 wxEraseEvent
eevent( GetId(), &dc
);
1707 eevent
.SetEventObject( this );
1708 GetEventHandler()->ProcessEvent( eevent
);
1710 wxNcPaintEvent
eventNc( GetId() );
1711 eventNc
.SetEventObject( this );
1712 GetEventHandler()->ProcessEvent( eventNc
);
1714 DisposeRgn( ownUpdateRgn
) ;
1715 if ( !m_updateRegion
.Empty() )
1718 event
.m_timeStamp
= time
;
1719 event
.SetEventObject(this);
1720 GetEventHandler()->ProcessEvent(event
);
1724 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1726 RgnHandle childupdate
= NewRgn() ;
1727 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1729 // calculate the update region for the child windows by intersecting the window rectangle with our own
1730 // passed in update region and then offset it to be client-wise window coordinates again
1731 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1732 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1733 SectRgn( childupdate
, updatergn
, childupdate
) ;
1734 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1735 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1737 // because dialogs may also be children
1738 child
->MacRedraw( childupdate
, time
, erase
) ;
1741 DisposeRgn( childupdate
) ;
1742 // eventually a draw grow box here
1746 WXHWND
wxWindowMac::MacGetRootWindow() const
1748 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1752 if ( iter
->IsTopLevel() )
1753 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1755 iter
= iter
->GetParent() ;
1757 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1761 void wxWindowMac::MacCreateScrollBars( long style
)
1763 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1765 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1766 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1768 GetClientSize( &width
, &height
) ;
1770 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1771 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1772 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1773 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1775 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1776 vSize
, wxVERTICAL
);
1778 if ( style
& wxVSCROLL
)
1784 m_vScrollBar
->Show(false) ;
1786 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1787 hSize
, wxHORIZONTAL
);
1788 if ( style
& wxHSCROLL
)
1793 m_hScrollBar
->Show(false) ;
1796 // because the create does not take into account the client area origin
1797 MacRepositionScrollBars() ; // we might have a real position shift
1800 void wxWindowMac::MacRepositionScrollBars()
1802 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1803 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1805 // get real client area
1807 int width
= m_width
;
1808 int height
= m_height
;
1810 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1811 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1813 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1814 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1815 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1816 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1823 MacClientToRootWindow( &x
, &y
) ;
1824 MacClientToRootWindow( &w
, &h
) ;
1826 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1828 int totW
= 10000 , totH
= 10000;
1831 if ( iter
->IsTopLevel() )
1833 totW
= iter
->m_width
;
1834 totH
= iter
->m_height
;
1838 iter
= iter
->GetParent() ;
1866 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1870 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1874 bool wxWindowMac::AcceptsFocus() const
1876 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1879 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1881 return GetParent()->MacGetContainerForEmbedding() ;
1884 void wxWindowMac::MacSuperChangedPosition()
1886 // only window-absolute structures have to be moved i.e. controls
1888 wxNode
*node
= GetChildren().First();
1891 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1892 child
->MacSuperChangedPosition() ;
1893 node
= node
->Next();
1897 void wxWindowMac::MacTopLevelWindowChangedPosition()
1899 // only screen-absolute structures have to be moved i.e. glcanvas
1901 wxNode
*node
= GetChildren().First();
1904 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1905 child
->MacTopLevelWindowChangedPosition() ;
1906 node
= node
->Next();
1909 long wxWindowMac::MacGetLeftBorderSize( ) const
1914 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1917 #if wxMAC_USE_THEME_BORDER
1919 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1924 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1927 #if wxMAC_USE_THEME_BORDER
1929 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1934 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1941 long wxWindowMac::MacGetRightBorderSize( ) const
1943 // they are all symmetric in mac themes
1944 return MacGetLeftBorderSize() ;
1947 long wxWindowMac::MacGetTopBorderSize( ) const
1949 // they are all symmetric in mac themes
1950 return MacGetLeftBorderSize() ;
1953 long wxWindowMac::MacGetBottomBorderSize( ) const
1955 // they are all symmetric in mac themes
1956 return MacGetLeftBorderSize() ;
1959 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1961 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1964 // Find the wxWindowMac at the current mouse position, returning the mouse
1966 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
1968 pt
= wxGetMousePosition();
1969 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
1973 // Get the current mouse position.
1974 wxPoint
wxGetMousePosition()
1977 wxGetMousePosition(& x
, & y
);
1978 return wxPoint(x
, y
);