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"
45 #define wxWINDOW_HSCROLL 5998
46 #define wxWINDOW_VSCROLL 5997
47 #define MAC_SCROLLBAR_SIZE 16
49 #include "wx/mac/uma.h"
52 #include <ToolUtils.h>
55 #if wxUSE_DRAG_AND_DROP
61 extern wxList wxPendingDelete
;
62 wxWindowMac
* gFocusWindow
= NULL
;
64 #ifdef __WXUNIVERSAL__
65 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
67 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
68 #endif // __WXUNIVERSAL__/__WXMAC__
70 #if !USE_SHARED_LIBRARY
72 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
73 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
74 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
75 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
76 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
77 EVT_IDLE(wxWindowMac::OnIdle
)
78 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 #define wxMAC_DEBUG_REDRAW 0
84 #ifndef wxMAC_DEBUG_REDRAW
85 #define wxMAC_DEBUG_REDRAW 0
88 #define wxMAC_USE_THEME_BORDER 0
91 // ===========================================================================
93 // ===========================================================================
96 // ----------------------------------------------------------------------------
97 // constructors and such
98 // ----------------------------------------------------------------------------
100 void wxWindowMac::Init()
106 m_doubleClickAllowed
= 0;
107 m_winCaptured
= FALSE
;
109 m_isBeingDeleted
= FALSE
;
112 m_mouseInWindow
= FALSE
;
116 m_backgroundTransparent
= FALSE
;
118 // as all windows are created with WS_VISIBLE style...
126 m_hScrollBar
= NULL
;
127 m_vScrollBar
= NULL
;
129 m_label
= wxEmptyString
;
133 wxWindowMac::~wxWindowMac()
135 // deleting a window while it is shown invalidates the region
137 wxWindowMac
* iter
= this ;
139 if ( iter
->IsTopLevel() )
144 iter
= iter
->GetParent() ;
149 m_isBeingDeleted
= TRUE
;
151 #ifndef __WXUNIVERSAL__
152 // VS: make sure there's no wxFrame with last focus set to us:
153 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
155 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
158 if ( frame
->GetLastFocus() == this )
160 frame
->SetLastFocus((wxWindow
*)NULL
);
165 #endif // __WXUNIVERSAL__
167 if ( s_lastMouseWindow
== this )
169 s_lastMouseWindow
= NULL
;
172 if ( gFocusWindow
== this )
174 gFocusWindow
= NULL
;
178 m_parent
->RemoveChild(this);
184 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
188 const wxString
& name
)
190 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
192 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
195 parent
->AddChild(this);
199 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
200 m_width
= WidthDefault( size
.x
);
201 m_height
= HeightDefault( size
.y
) ;
202 #ifndef __WXUNIVERSAL__
203 // Don't give scrollbars to wxControls unless they ask for them
204 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
205 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
207 MacCreateScrollBars( style
) ;
213 void wxWindowMac::SetFocus()
215 if ( gFocusWindow
== this )
218 if ( AcceptsFocus() )
224 if ( gFocusWindow
->m_caret
)
226 gFocusWindow
->m_caret
->OnKillFocus();
228 #endif // wxUSE_CARET
229 #ifndef __WXUNIVERSAL__
230 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
231 if ( control
&& control
->GetMacControl() )
233 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
234 control
->MacRedrawControl() ;
237 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
238 event
.SetEventObject(gFocusWindow
);
239 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
241 gFocusWindow
= this ;
247 m_caret
->OnSetFocus();
249 #endif // wxUSE_CARET
250 // panel wants to track the window which was the last to have focus in it
251 wxChildFocusEvent
eventFocus(this);
252 GetEventHandler()->ProcessEvent(eventFocus
);
254 #ifndef __WXUNIVERSAL__
255 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
256 if ( control
&& control
->GetMacControl() )
258 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
261 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
262 event
.SetEventObject(this);
263 GetEventHandler()->ProcessEvent(event
) ;
268 bool wxWindowMac::Enable(bool enable
)
270 if ( !wxWindowBase::Enable(enable
) )
273 MacSuperEnabled( enable
) ;
278 void wxWindowMac::DoCaptureMouse()
280 wxTheApp
->s_captureWindow
= this ;
283 wxWindow
* wxWindowBase::GetCapture()
285 return wxTheApp
->s_captureWindow
;
288 void wxWindowMac::DoReleaseMouse()
290 wxTheApp
->s_captureWindow
= NULL
;
293 #if wxUSE_DRAG_AND_DROP
295 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
297 if ( m_dropTarget
!= 0 ) {
301 m_dropTarget
= pDropTarget
;
302 if ( m_dropTarget
!= 0 )
310 // Old style file-manager drag&drop
311 void wxWindowMac::DragAcceptFiles(bool accept
)
317 void wxWindowMac::DoGetSize(int *x
, int *y
) const
320 if(y
) *y
= m_height
;
323 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
329 if ( !IsTopLevel() && GetParent())
331 wxPoint
pt(GetParent()->GetClientAreaOrigin());
340 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
342 menu
->SetInvokingWindow(this);
344 ClientToScreen( &x
, &y
) ;
346 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
347 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
348 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
349 ::DeleteMenu( menu
->MacGetMenuId() ) ;
350 menu
->SetInvokingWindow(NULL
);
356 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
358 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
360 Point localwhere
= {0,0} ;
362 if(x
) localwhere
.h
= * x
;
363 if(y
) localwhere
.v
= * y
;
367 ::SetPort( UMAGetWindowPort( window
) ) ;
368 ::GlobalToLocal( &localwhere
) ;
371 if(x
) *x
= localwhere
.h
;
372 if(y
) *y
= localwhere
.v
;
374 MacRootWindowToWindow( x
, y
) ;
376 x
-= MacGetLeftBorderSize() ;
378 y
-= MacGetTopBorderSize() ;
381 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
383 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
386 x
+= MacGetLeftBorderSize() ;
388 y
+= MacGetTopBorderSize() ;
390 MacWindowToRootWindow( x
, y
) ;
392 Point localwhere
= { 0,0 };
393 if(x
) localwhere
.h
= * x
;
394 if(y
) localwhere
.v
= * y
;
398 ::SetPort( UMAGetWindowPort( window
) ) ;
400 ::LocalToGlobal( &localwhere
) ;
402 if(x
) *x
= localwhere
.h
;
403 if(y
) *y
= localwhere
.v
;
406 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
408 wxPoint origin
= GetClientAreaOrigin() ;
409 if(x
) *x
+= origin
.x
;
410 if(y
) *y
+= origin
.y
;
412 MacWindowToRootWindow( x
, y
) ;
415 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
417 wxPoint origin
= GetClientAreaOrigin() ;
418 MacRootWindowToWindow( x
, y
) ;
419 if(x
) *x
-= origin
.x
;
420 if(y
) *y
-= origin
.y
;
423 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
429 GetParent()->MacWindowToRootWindow( x
, y
) ;
433 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
439 GetParent()->MacRootWindowToWindow( x
, y
) ;
443 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
445 if (m_cursor
== cursor
)
448 if (wxNullCursor
== cursor
)
450 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
455 if ( ! wxWindowBase::SetCursor( cursor
) )
459 wxASSERT_MSG( m_cursor
.Ok(),
460 wxT("cursor must be valid after call to the base version"));
463 wxWindowMac
*mouseWin
;
466 // Change the cursor NOW if we're within the correct window
468 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
470 if ( mouseWin
== this && !wxIsBusy() )
472 m_cursor
.MacInstall() ;
480 // Get size *available for subwindows* i.e. excluding menu bar etc.
481 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
487 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
488 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
490 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
497 MacClientToRootWindow( &x1
, &y1
) ;
498 MacClientToRootWindow( &w
, &h
) ;
500 wxWindowMac
*iter
= (wxWindowMac
*)this ;
502 int totW
= 10000 , totH
= 10000;
505 if ( iter
->IsTopLevel() )
507 totW
= iter
->m_width
;
508 totH
= iter
->m_height
;
512 iter
= iter
->GetParent() ;
515 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
517 hh
-= MAC_SCROLLBAR_SIZE
;
523 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
525 ww
-= MAC_SCROLLBAR_SIZE
;
537 // ----------------------------------------------------------------------------
539 // ----------------------------------------------------------------------------
543 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
545 wxWindowBase::DoSetToolTip(tooltip
);
548 m_tooltip
->SetWindow(this);
551 #endif // wxUSE_TOOLTIPS
553 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
557 int former_w
= m_width
;
558 int former_h
= m_height
;
560 int actualWidth
= width
;
561 int actualHeight
= height
;
565 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
566 actualWidth
= m_minWidth
;
567 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
568 actualHeight
= m_minHeight
;
569 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
570 actualWidth
= m_maxWidth
;
571 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
572 actualHeight
= m_maxHeight
;
574 bool doMove
= false ;
575 bool doResize
= false ;
577 if ( actualX
!= former_x
|| actualY
!= former_y
)
581 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
586 if ( doMove
|| doResize
)
588 // erase former position
594 m_width
= actualWidth
;
595 m_height
= actualHeight
;
597 // update any low-level frame-relative positions
599 MacUpdateDimensions() ;
600 // erase new position
604 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
606 MacRepositionScrollBars() ;
609 wxPoint
point(m_x
, m_y
);
610 wxMoveEvent
event(point
, m_windowId
);
611 event
.SetEventObject(this);
612 GetEventHandler()->ProcessEvent(event
) ;
616 MacRepositionScrollBars() ;
617 wxSize
size(m_width
, m_height
);
618 wxSizeEvent
event(size
, m_windowId
);
619 event
.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(event
);
626 // set the size of the window: if the dimensions are positive, just use them,
627 // but if any of them is equal to -1, it means that we must find the value for
628 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
629 // which case -1 is a valid value for x and y)
631 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
632 // the width/height to best suit our contents, otherwise we reuse the current
634 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
636 // get the current size and position...
637 int currentX
, currentY
;
638 GetPosition(¤tX
, ¤tY
);
640 int currentW
,currentH
;
641 GetSize(¤tW
, ¤tH
);
643 // ... and don't do anything (avoiding flicker) if it's already ok
644 if ( x
== currentX
&& y
== currentY
&&
645 width
== currentW
&& height
== currentH
)
647 MacRepositionScrollBars() ; // we might have a real position shift
651 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
653 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
656 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
661 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
663 size
= DoGetBestSize();
668 // just take the current one
675 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
679 size
= DoGetBestSize();
681 //else: already called DoGetBestSize() above
687 // just take the current one
692 DoMoveWindow(x
, y
, width
, height
);
695 // For implementation purposes - sometimes decorations make the client area
698 wxPoint
wxWindowMac::GetClientAreaOrigin() const
700 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
703 void wxWindowMac::SetTitle(const wxString
& title
)
708 wxString
wxWindowMac::GetTitle() const
713 bool wxWindowMac::Show(bool show
)
715 if ( !wxWindowBase::Show(show
) )
719 WindowRef window = (WindowRef) MacGetRootWindow() ;
720 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
721 if ( win == NULL && win->m_isBeingDeleted )
724 MacSuperShown( show
) ;
729 if ( win && !win->m_isBeingDeleted )
740 void wxWindowMac::MacSuperShown( bool show
)
742 wxNode
*node
= GetChildren().First();
745 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
746 if ( child
->m_isShown
)
747 child
->MacSuperShown( show
) ;
752 void wxWindowMac::MacSuperEnabled( bool enabled
)
756 // to be absolutely correct we'd have to invalidate (with eraseBkground
757 // because unter MacOSX the frames are drawn with an addXXX mode)
760 wxNode
*node
= GetChildren().First();
763 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
764 if ( child
->m_isShown
)
765 child
->MacSuperEnabled( enabled
) ;
770 bool wxWindowMac::MacIsReallyShown() const
772 if ( m_isShown
&& (m_parent
!= NULL
) ) {
773 return m_parent
->MacIsReallyShown();
777 bool status = m_isShown ;
778 wxWindowMac * win = this ;
779 while ( status && win->m_parent != NULL )
781 win = win->m_parent ;
782 status = win->m_isShown ;
788 int wxWindowMac::GetCharHeight() const
790 wxClientDC
dc ( (wxWindowMac
*)this ) ;
791 return dc
.GetCharHeight() ;
794 int wxWindowMac::GetCharWidth() const
796 wxClientDC
dc ( (wxWindowMac
*)this ) ;
797 return dc
.GetCharWidth() ;
800 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
801 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
803 const wxFont
*fontToUse
= theFont
;
807 wxClientDC
dc( (wxWindowMac
*) this ) ;
809 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
810 if ( externalLeading
)
811 *externalLeading
= le
;
821 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
822 * we always intersect with the entire window, not only with the client area
825 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
827 if ( MacGetTopLevelWindow() == NULL
)
830 wxPoint client
= GetClientAreaOrigin();
833 int x2
= m_width
- client
.x
;
834 int y2
= m_height
- client
.y
;
836 if (IsKindOf( CLASSINFO(wxButton
)))
838 // buttons have an "aura"
845 Rect clientrect
= { y1
, x1
, y2
, x2
};
849 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
850 SectRect( &clientrect
, &r
, &clientrect
) ;
853 if ( !EmptyRect( &clientrect
) )
855 int top
= 0 , left
= 0 ;
857 MacClientToRootWindow( &left
, &top
) ;
858 OffsetRect( &clientrect
, left
, top
) ;
860 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
864 #if wxUSE_CARET && WXWIN_COMPATIBILITY
865 // ---------------------------------------------------------------------------
866 // Caret manipulation
867 // ---------------------------------------------------------------------------
869 void wxWindowMac::CreateCaret(int w
, int h
)
871 SetCaret(new wxCaret(this, w
, h
));
874 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
876 wxFAIL_MSG("not implemented");
879 void wxWindowMac::ShowCaret(bool show
)
881 wxCHECK_RET( m_caret
, "no caret to show" );
886 void wxWindowMac::DestroyCaret()
891 void wxWindowMac::SetCaretPos(int x
, int y
)
893 wxCHECK_RET( m_caret
, "no caret to move" );
898 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
900 wxCHECK_RET( m_caret
, "no caret to get position of" );
902 m_caret
->GetPosition(x
, y
);
904 #endif // wxUSE_CARET
906 wxWindowMac
*wxGetActiveWindow()
908 // actually this is a windows-only concept
912 // Coordinates relative to the window
913 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
915 // We really dont move the mouse programmatically under mac
918 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
920 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
922 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
924 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
926 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
927 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
928 // either a non gray background color or a non control window
930 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
932 wxWindowMac
* parent
= GetParent() ;
935 if ( parent
->MacGetRootWindow() != window
)
937 // we are in a different window on the mac system
943 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
944 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
946 // if we have any other colours in the hierarchy
947 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
950 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
951 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
953 Rect extent
= { 0 , 0 , 0 , 0 } ;
956 wxSize size
= parent
->GetSize() ;
957 parent
->MacClientToRootWindow( &x
, &y
) ;
961 extent
.right
= x
+ size
.x
;
962 extent
.bottom
= y
+ size
.y
;
963 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
967 parent
= parent
->GetParent() ;
971 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
976 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
979 return m_macBackgroundBrush
;
983 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
985 event
.GetDC()->Clear() ;
988 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
990 wxWindowDC
dc(this) ;
991 wxMacPortSetter
helper(&dc
) ;
993 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
996 int wxWindowMac::GetScrollPos(int orient
) const
998 if ( orient
== wxHORIZONTAL
)
1001 return m_hScrollBar
->GetThumbPosition() ;
1006 return m_vScrollBar
->GetThumbPosition() ;
1011 // This now returns the whole range, not just the number
1012 // of positions that we can scroll.
1013 int wxWindowMac::GetScrollRange(int orient
) const
1015 if ( orient
== wxHORIZONTAL
)
1018 return m_hScrollBar
->GetRange() ;
1023 return m_vScrollBar
->GetRange() ;
1028 int wxWindowMac::GetScrollThumb(int orient
) const
1030 if ( orient
== wxHORIZONTAL
)
1033 return m_hScrollBar
->GetThumbSize() ;
1038 return m_vScrollBar
->GetThumbSize() ;
1043 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1045 if ( orient
== wxHORIZONTAL
)
1048 m_hScrollBar
->SetThumbPosition( pos
) ;
1053 m_vScrollBar
->SetThumbPosition( pos
) ;
1057 void wxWindowMac::MacPaintBorders( int left
, int top
)
1062 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1063 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1064 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1065 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1068 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1070 #if wxMAC_USE_THEME_BORDER
1071 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1074 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1075 InsetRect( &rect , border , border );
1076 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1079 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1081 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1082 RGBForeColor( &face
);
1083 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1084 LineTo( left
+ 0 , top
+ 0 );
1085 LineTo( left
+ m_width
- 2 , top
+ 0 );
1087 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1088 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1089 LineTo( left
+ m_width
- 3 , top
+ 2 );
1091 RGBForeColor( sunken
? &face
: &black
);
1092 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1093 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1094 LineTo( left
+ m_width
- 1 , top
+ 0 );
1096 RGBForeColor( sunken
? &shadow
: &white
);
1097 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1098 LineTo( left
+ 1, top
+ 1 );
1099 LineTo( left
+ m_width
- 3 , top
+ 1 );
1101 RGBForeColor( sunken
? &white
: &shadow
);
1102 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1103 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1104 LineTo( left
+ m_width
- 2 , top
+ 1 );
1106 RGBForeColor( sunken
? &black
: &face
);
1107 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1108 LineTo( left
+ 2 , top
+ 2 );
1109 LineTo( left
+ m_width
- 4 , top
+ 2 );
1112 else if (HasFlag(wxSIMPLE_BORDER
))
1114 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1115 RGBForeColor( &black
) ;
1116 FrameRect( &rect
) ;
1120 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1122 if ( child
== m_hScrollBar
)
1123 m_hScrollBar
= NULL
;
1124 if ( child
== m_vScrollBar
)
1125 m_vScrollBar
= NULL
;
1127 wxWindowBase::RemoveChild( child
) ;
1130 // New function that will replace some of the above.
1131 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1132 int range
, bool refresh
)
1134 if ( orient
== wxHORIZONTAL
)
1138 if ( range
== 0 || thumbVisible
>= range
)
1140 if ( m_hScrollBar
->IsShown() )
1141 m_hScrollBar
->Show(false) ;
1145 if ( !m_hScrollBar
->IsShown() )
1146 m_hScrollBar
->Show(true) ;
1147 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1155 if ( range
== 0 || thumbVisible
>= range
)
1157 if ( m_vScrollBar
->IsShown() )
1158 m_vScrollBar
->Show(false) ;
1162 if ( !m_vScrollBar
->IsShown() )
1163 m_vScrollBar
->Show(true) ;
1164 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1168 MacRepositionScrollBars() ;
1171 // Does a physical scroll
1172 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1174 wxClientDC
dc(this) ;
1175 wxMacPortSetter
helper(&dc
) ;
1178 int width
, height
;
1179 GetClientSize( &width
, &height
) ;
1181 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1182 RgnHandle updateRgn
= NewRgn() ;
1183 ClipRect( &scrollrect
) ;
1186 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1187 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1188 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1190 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1191 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1192 DisposeRgn( updateRgn
) ;
1195 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1197 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1198 if (child
== m_vScrollBar
) continue;
1199 if (child
== m_hScrollBar
) continue;
1200 if (child
->IsTopLevel()) continue;
1203 child
->GetPosition( &x
, &y
);
1205 child
->GetSize( &w
, &h
);
1206 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1211 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1213 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1215 wxScrollWinEvent wevent
;
1216 wevent
.SetPosition(event
.GetPosition());
1217 wevent
.SetOrientation(event
.GetOrientation());
1218 wevent
.m_eventObject
= this;
1220 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1221 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1223 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1224 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1226 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1227 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1229 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1230 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1232 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1233 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1235 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1236 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1238 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1239 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1242 GetEventHandler()->ProcessEvent(wevent
);
1246 // Get the window with the focus
1247 wxWindowMac
*wxWindowBase::FindFocus()
1249 return gFocusWindow
;
1252 #if WXWIN_COMPATIBILITY
1253 // If nothing defined for this, try the parent.
1254 // E.g. we may be a button loaded from a resource, with no callback function
1256 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1258 if ( GetEventHandler()->ProcessEvent(event
) )
1261 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1263 #endif // WXWIN_COMPATIBILITY_2
1265 #if WXWIN_COMPATIBILITY
1266 wxObject
* wxWindowMac::GetChild(int number
) const
1268 // Return a pointer to the Nth object in the Panel
1269 wxNode
*node
= GetChildren().First();
1272 node
= node
->Next();
1275 wxObject
*obj
= (wxObject
*)node
->Data();
1281 #endif // WXWIN_COMPATIBILITY
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 void wxWindowMac::Clear()
1301 wxClientDC
dc(this);
1302 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1303 dc
.SetBackground(brush
);
1307 // Setup background and foreground colours correctly
1308 void wxWindowMac::SetupColours()
1311 SetBackgroundColour(GetParent()->GetBackgroundColour());
1314 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1317 // Check if we need to send a LEAVE event
1318 if (m_mouseInWindow)
1321 ::GetCursorPos(&pt);
1322 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1324 // Generate a LEAVE event
1325 m_mouseInWindow = FALSE;
1326 MSWOnMouseLeave(pt.x, pt.y, 0);
1331 // This calls the UI-update mechanism (querying windows for
1332 // menu/toolbar/control state information)
1336 // Raise the window to the top of the Z order
1337 void wxWindowMac::Raise()
1341 // Lower the window to the bottom of the Z order
1342 void wxWindowMac::Lower()
1346 void wxWindowMac::DoSetClientSize(int width
, int height
)
1348 if ( width
!= -1 || height
!= -1 )
1351 if ( width
!= -1 && m_vScrollBar
)
1352 width
+= MAC_SCROLLBAR_SIZE
;
1353 if ( height
!= -1 && m_vScrollBar
)
1354 height
+= MAC_SCROLLBAR_SIZE
;
1356 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1357 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1359 DoSetSize( -1 , -1 , width
, height
) ;
1364 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1366 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1370 if ((point
.x
< 0) || (point
.y
< 0) ||
1371 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1376 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1377 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1381 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1383 wxPoint
newPoint( point
) ;
1385 if ( !IsTopLevel() )
1391 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1393 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1394 // added the m_isShown test --dmazzoni
1395 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1397 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1406 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1410 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1411 if ( ::FindWindow( pt
, &window
) == 3 )
1414 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1417 // No, this yields the CLIENT are, we need the whole frame. RR.
1418 // point = win->ScreenToClient( point ) ;
1421 ::GetPort( &port
) ;
1422 ::SetPort( UMAGetWindowPort( window
) ) ;
1423 ::GlobalToLocal( &pt
) ;
1426 wxPoint
point( pt
.h
, pt
.v
) ;
1428 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1434 extern int wxBusyCursorCount
;
1435 static wxWindow
*gs_lastWhich
= NULL
;
1437 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1439 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1440 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1444 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1447 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1455 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1457 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1458 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1460 if (child
->MacDispatchMouseEvent(event
))
1467 event
.SetEventObject( this ) ;
1469 if ( wxBusyCursorCount
== 0 )
1471 m_cursor
.MacInstall() ;
1474 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1476 // set focus to this window
1477 if (AcceptsFocus() && FindFocus()!=this)
1482 if ( event
.GetEventType() == wxEVT_MOTION
1483 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1484 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1485 wxToolTip::RelayEvent( this , event
);
1486 #endif // wxUSE_TOOLTIPS
1488 if (gs_lastWhich
!= this)
1490 gs_lastWhich
= this;
1492 // Double clicks must always occur on the same window
1493 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1494 event
.SetEventType( wxEVT_LEFT_DOWN
);
1495 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1496 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1498 // Same for mouse up events
1499 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1501 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1505 GetEventHandler()->ProcessEvent( event
) ;
1510 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1514 return m_tooltip
->GetTip() ;
1519 void wxWindowMac::Update()
1521 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1524 win
->MacUpdate( 0 ) ;
1525 #if TARGET_API_MAC_CARBON
1526 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1528 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1534 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1536 wxTopLevelWindowMac
* win
= NULL
;
1537 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1540 win
= wxFindWinFromMacWindow( window
) ;
1545 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1547 RgnHandle visRgn
= NewRgn() ;
1548 RgnHandle tempRgn
= NewRgn() ;
1550 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1552 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1553 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1555 int borderTop
= 14 ;
1556 int borderOther
= 4 ;
1558 SetRectRgn( tempRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1559 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1562 if ( !IsTopLevel() )
1564 wxWindow
* parent
= GetParent() ;
1567 wxSize size
= parent
->GetSize() ;
1570 parent
->MacWindowToRootWindow( &x
, &y
) ;
1571 MacRootWindowToWindow( &x
, &y
) ;
1573 SetRectRgn( tempRgn
,
1574 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1575 x
+ size
.x
- parent
->MacGetLeftBorderSize() - parent
->MacGetRightBorderSize(),
1576 y
+ size
.y
- parent
->MacGetTopBorderSize() - parent
->MacGetBottomBorderSize()) ;
1578 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1579 if ( parent
->IsTopLevel() )
1581 parent
= parent
->GetParent() ;
1584 if ( respectChildrenAndSiblings
)
1586 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1588 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1590 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1592 if ( !child
->IsTopLevel() && child
->IsShown() )
1594 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1595 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1600 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1602 bool thisWindowThrough
= false ;
1603 for (wxNode
*node
= GetParent()->GetChildren().First(); node
; node
= node
->Next())
1605 wxWindowMac
*sibling
= (wxWindowMac
*)node
->Data();
1606 if ( sibling
== this )
1608 thisWindowThrough
= true ;
1611 if( !thisWindowThrough
)
1616 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1618 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
) ;
1619 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1624 m_macVisibleRegion
= visRgn
;
1625 DisposeRgn( visRgn
) ;
1626 DisposeRgn( tempRgn
) ;
1627 return m_macVisibleRegion
;
1630 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1632 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1633 // updatergn is always already clipped to our boundaries
1634 // it is in window coordinates, not in client coordinates
1636 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1639 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1640 RgnHandle ownUpdateRgn
= NewRgn() ;
1641 CopyRgn( updatergn
, ownUpdateRgn
) ;
1643 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1645 // newupdate is the update region in client coordinates
1646 RgnHandle newupdate
= NewRgn() ;
1647 wxSize point
= GetClientSize() ;
1648 wxPoint origin
= GetClientAreaOrigin() ;
1649 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1650 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1651 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1652 m_updateRegion
= newupdate
;
1653 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1655 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1657 wxWindowDC
dc(this);
1658 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1659 wxEraseEvent
eevent( GetId(), &dc
);
1660 eevent
.SetEventObject( this );
1661 GetEventHandler()->ProcessEvent( eevent
);
1663 wxNcPaintEvent
eventNc( GetId() );
1664 eventNc
.SetEventObject( this );
1665 GetEventHandler()->ProcessEvent( eventNc
);
1667 DisposeRgn( ownUpdateRgn
) ;
1668 if ( !m_updateRegion
.Empty() )
1671 event
.m_timeStamp
= time
;
1672 event
.SetEventObject(this);
1673 GetEventHandler()->ProcessEvent(event
);
1677 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1679 RgnHandle childupdate
= NewRgn() ;
1680 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1682 // calculate the update region for the child windows by intersecting the window rectangle with our own
1683 // passed in update region and then offset it to be client-wise window coordinates again
1684 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1685 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1686 SectRgn( childupdate
, updatergn
, childupdate
) ;
1687 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1688 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1690 // because dialogs may also be children
1691 child
->MacRedraw( childupdate
, time
, erase
) ;
1694 DisposeRgn( childupdate
) ;
1695 // eventually a draw grow box here
1699 WXHWND
wxWindowMac::MacGetRootWindow() const
1701 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1705 if ( iter
->IsTopLevel() )
1706 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1708 iter
= iter
->GetParent() ;
1710 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1714 void wxWindowMac::MacCreateScrollBars( long style
)
1716 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1718 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1719 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1721 GetClientSize( &width
, &height
) ;
1723 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1724 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1725 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1726 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1728 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1729 vSize
, wxVERTICAL
);
1731 if ( style
& wxVSCROLL
)
1737 m_vScrollBar
->Show(false) ;
1739 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1740 hSize
, wxHORIZONTAL
);
1741 if ( style
& wxHSCROLL
)
1746 m_hScrollBar
->Show(false) ;
1749 // because the create does not take into account the client area origin
1750 MacRepositionScrollBars() ; // we might have a real position shift
1753 void wxWindowMac::MacRepositionScrollBars()
1755 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1756 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1758 // get real client area
1760 int width
= m_width
;
1761 int height
= m_height
;
1763 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1764 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1766 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1767 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1768 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1769 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1776 MacClientToRootWindow( &x
, &y
) ;
1777 MacClientToRootWindow( &w
, &h
) ;
1779 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1781 int totW
= 10000 , totH
= 10000;
1784 if ( iter
->IsTopLevel() )
1786 totW
= iter
->m_width
;
1787 totH
= iter
->m_height
;
1791 iter
= iter
->GetParent() ;
1819 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1823 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1827 bool wxWindowMac::AcceptsFocus() const
1829 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1832 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1834 return GetParent()->MacGetContainerForEmbedding() ;
1837 void wxWindowMac::MacSuperChangedPosition()
1839 // only window-absolute structures have to be moved i.e. controls
1841 wxNode
*node
= GetChildren().First();
1844 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1845 child
->MacSuperChangedPosition() ;
1846 node
= node
->Next();
1850 void wxWindowMac::MacTopLevelWindowChangedPosition()
1852 // only screen-absolute structures have to be moved i.e. glcanvas
1854 wxNode
*node
= GetChildren().First();
1857 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1858 child
->MacTopLevelWindowChangedPosition() ;
1859 node
= node
->Next();
1862 long wxWindowMac::MacGetLeftBorderSize( ) const
1867 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1870 #if wxMAC_USE_THEME_BORDER
1872 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1877 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1880 #if wxMAC_USE_THEME_BORDER
1882 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1887 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1894 long wxWindowMac::MacGetRightBorderSize( ) const
1896 // they are all symmetric in mac themes
1897 return MacGetLeftBorderSize() ;
1900 long wxWindowMac::MacGetTopBorderSize( ) const
1902 // they are all symmetric in mac themes
1903 return MacGetLeftBorderSize() ;
1906 long wxWindowMac::MacGetBottomBorderSize( ) const
1908 // they are all symmetric in mac themes
1909 return MacGetLeftBorderSize() ;
1912 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1914 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1917 // Find the wxWindowMac at the current mouse position, returning the mouse
1919 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
1921 pt
= wxGetMousePosition();
1922 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
1926 // Get the current mouse position.
1927 wxPoint
wxGetMousePosition()
1930 wxGetMousePosition(& x
, & y
);
1931 return wxPoint(x
, y
);