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 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
176 if ( frame
->GetLastFocus() == this )
177 frame
->SetLastFocus( NULL
) ;
180 if ( gFocusWindow
== this )
182 gFocusWindow
= NULL
;
186 m_parent
->RemoveChild(this);
192 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
196 const wxString
& name
)
198 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
200 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
203 parent
->AddChild(this);
207 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
208 m_width
= WidthDefault( size
.x
);
209 m_height
= HeightDefault( size
.y
) ;
210 #ifndef __WXUNIVERSAL__
211 // Don't give scrollbars to wxControls unless they ask for them
212 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
213 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
215 MacCreateScrollBars( style
) ;
221 void wxWindowMac::SetFocus()
223 if ( gFocusWindow
== this )
226 if ( AcceptsFocus() )
232 if ( gFocusWindow
->m_caret
)
234 gFocusWindow
->m_caret
->OnKillFocus();
236 #endif // wxUSE_CARET
237 #ifndef __WXUNIVERSAL__
238 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
239 if ( control
&& control
->GetMacControl() )
241 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
242 control
->MacRedrawControl() ;
245 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
246 event
.SetEventObject(gFocusWindow
);
247 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
249 gFocusWindow
= this ;
255 m_caret
->OnSetFocus();
257 #endif // wxUSE_CARET
258 // panel wants to track the window which was the last to have focus in it
259 wxChildFocusEvent
eventFocus(this);
260 GetEventHandler()->ProcessEvent(eventFocus
);
262 #ifndef __WXUNIVERSAL__
263 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
264 if ( control
&& control
->GetMacControl() )
266 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
269 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
270 event
.SetEventObject(this);
271 GetEventHandler()->ProcessEvent(event
) ;
276 bool wxWindowMac::Enable(bool enable
)
278 if ( !wxWindowBase::Enable(enable
) )
281 MacSuperEnabled( enable
) ;
286 void wxWindowMac::DoCaptureMouse()
288 wxTheApp
->s_captureWindow
= this ;
291 wxWindow
* wxWindowBase::GetCapture()
293 return wxTheApp
->s_captureWindow
;
296 void wxWindowMac::DoReleaseMouse()
298 wxTheApp
->s_captureWindow
= NULL
;
301 #if wxUSE_DRAG_AND_DROP
303 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
305 if ( m_dropTarget
!= 0 ) {
309 m_dropTarget
= pDropTarget
;
310 if ( m_dropTarget
!= 0 )
318 // Old style file-manager drag&drop
319 void wxWindowMac::DragAcceptFiles(bool accept
)
325 void wxWindowMac::DoGetSize(int *x
, int *y
) const
328 if(y
) *y
= m_height
;
331 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
337 if ( !IsTopLevel() && GetParent())
339 wxPoint
pt(GetParent()->GetClientAreaOrigin());
348 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
350 menu
->SetInvokingWindow(this);
352 ClientToScreen( &x
, &y
) ;
354 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
355 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
356 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
357 ::DeleteMenu( menu
->MacGetMenuId() ) ;
358 menu
->SetInvokingWindow(NULL
);
364 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
366 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
368 Point localwhere
= {0,0} ;
370 if(x
) localwhere
.h
= * x
;
371 if(y
) localwhere
.v
= * y
;
375 ::SetPort( UMAGetWindowPort( window
) ) ;
376 ::GlobalToLocal( &localwhere
) ;
379 if(x
) *x
= localwhere
.h
;
380 if(y
) *y
= localwhere
.v
;
382 MacRootWindowToWindow( x
, y
) ;
384 x
-= MacGetLeftBorderSize() ;
386 y
-= MacGetTopBorderSize() ;
389 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
391 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
394 x
+= MacGetLeftBorderSize() ;
396 y
+= MacGetTopBorderSize() ;
398 MacWindowToRootWindow( x
, y
) ;
400 Point localwhere
= { 0,0 };
401 if(x
) localwhere
.h
= * x
;
402 if(y
) localwhere
.v
= * y
;
406 ::SetPort( UMAGetWindowPort( window
) ) ;
408 ::LocalToGlobal( &localwhere
) ;
410 if(x
) *x
= localwhere
.h
;
411 if(y
) *y
= localwhere
.v
;
414 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
416 wxPoint origin
= GetClientAreaOrigin() ;
417 if(x
) *x
+= origin
.x
;
418 if(y
) *y
+= origin
.y
;
420 MacWindowToRootWindow( x
, y
) ;
423 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
425 wxPoint origin
= GetClientAreaOrigin() ;
426 MacRootWindowToWindow( x
, y
) ;
427 if(x
) *x
-= origin
.x
;
428 if(y
) *y
-= origin
.y
;
431 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
437 GetParent()->MacWindowToRootWindow( x
, y
) ;
441 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
447 GetParent()->MacRootWindowToWindow( x
, y
) ;
451 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
453 if (m_cursor
== cursor
)
456 if (wxNullCursor
== cursor
)
458 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
463 if ( ! wxWindowBase::SetCursor( cursor
) )
467 wxASSERT_MSG( m_cursor
.Ok(),
468 wxT("cursor must be valid after call to the base version"));
471 wxWindowMac
*mouseWin
;
474 // Change the cursor NOW if we're within the correct window
476 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
478 if ( mouseWin
== this && !wxIsBusy() )
480 m_cursor
.MacInstall() ;
488 // Get size *available for subwindows* i.e. excluding menu bar etc.
489 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
495 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
496 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
498 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
505 MacClientToRootWindow( &x1
, &y1
) ;
506 MacClientToRootWindow( &w
, &h
) ;
508 wxWindowMac
*iter
= (wxWindowMac
*)this ;
510 int totW
= 10000 , totH
= 10000;
513 if ( iter
->IsTopLevel() )
515 totW
= iter
->m_width
;
516 totH
= iter
->m_height
;
520 iter
= iter
->GetParent() ;
523 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
525 hh
-= MAC_SCROLLBAR_SIZE
;
531 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
533 ww
-= MAC_SCROLLBAR_SIZE
;
545 // ----------------------------------------------------------------------------
547 // ----------------------------------------------------------------------------
551 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
553 wxWindowBase::DoSetToolTip(tooltip
);
556 m_tooltip
->SetWindow(this);
559 #endif // wxUSE_TOOLTIPS
561 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
565 int former_w
= m_width
;
566 int former_h
= m_height
;
568 int actualWidth
= width
;
569 int actualHeight
= height
;
573 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
574 actualWidth
= m_minWidth
;
575 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
576 actualHeight
= m_minHeight
;
577 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
578 actualWidth
= m_maxWidth
;
579 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
580 actualHeight
= m_maxHeight
;
582 bool doMove
= false ;
583 bool doResize
= false ;
585 if ( actualX
!= former_x
|| actualY
!= former_y
)
589 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
594 if ( doMove
|| doResize
)
596 // erase former position
602 m_width
= actualWidth
;
603 m_height
= actualHeight
;
605 // update any low-level frame-relative positions
607 MacUpdateDimensions() ;
608 // erase new position
612 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
614 MacRepositionScrollBars() ;
617 wxPoint
point(m_x
, m_y
);
618 wxMoveEvent
event(point
, m_windowId
);
619 event
.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(event
) ;
624 MacRepositionScrollBars() ;
625 wxSize
size(m_width
, m_height
);
626 wxSizeEvent
event(size
, m_windowId
);
627 event
.SetEventObject(this);
628 GetEventHandler()->ProcessEvent(event
);
634 // set the size of the window: if the dimensions are positive, just use them,
635 // but if any of them is equal to -1, it means that we must find the value for
636 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
637 // which case -1 is a valid value for x and y)
639 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
640 // the width/height to best suit our contents, otherwise we reuse the current
642 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
644 // get the current size and position...
645 int currentX
, currentY
;
646 GetPosition(¤tX
, ¤tY
);
648 int currentW
,currentH
;
649 GetSize(¤tW
, ¤tH
);
651 // ... and don't do anything (avoiding flicker) if it's already ok
652 if ( x
== currentX
&& y
== currentY
&&
653 width
== currentW
&& height
== currentH
)
655 MacRepositionScrollBars() ; // we might have a real position shift
659 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
661 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
664 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
669 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
671 size
= DoGetBestSize();
676 // just take the current one
683 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
687 size
= DoGetBestSize();
689 //else: already called DoGetBestSize() above
695 // just take the current one
700 DoMoveWindow(x
, y
, width
, height
);
703 // For implementation purposes - sometimes decorations make the client area
706 wxPoint
wxWindowMac::GetClientAreaOrigin() const
708 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
711 void wxWindowMac::SetTitle(const wxString
& title
)
716 wxString
wxWindowMac::GetTitle() const
721 bool wxWindowMac::Show(bool show
)
723 if ( !wxWindowBase::Show(show
) )
727 WindowRef window = (WindowRef) MacGetRootWindow() ;
728 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
729 if ( win == NULL && win->m_isBeingDeleted )
732 MacSuperShown( show
) ;
737 if ( win && !win->m_isBeingDeleted )
748 void wxWindowMac::MacSuperShown( bool show
)
750 wxNode
*node
= GetChildren().First();
753 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
754 if ( child
->m_isShown
)
755 child
->MacSuperShown( show
) ;
760 void wxWindowMac::MacSuperEnabled( bool enabled
)
764 // to be absolutely correct we'd have to invalidate (with eraseBkground
765 // because unter MacOSX the frames are drawn with an addXXX mode)
768 wxNode
*node
= GetChildren().First();
771 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
772 if ( child
->m_isShown
)
773 child
->MacSuperEnabled( enabled
) ;
778 bool wxWindowMac::MacIsReallyShown() const
780 if ( m_isShown
&& (m_parent
!= NULL
) ) {
781 return m_parent
->MacIsReallyShown();
785 bool status = m_isShown ;
786 wxWindowMac * win = this ;
787 while ( status && win->m_parent != NULL )
789 win = win->m_parent ;
790 status = win->m_isShown ;
796 int wxWindowMac::GetCharHeight() const
798 wxClientDC
dc ( (wxWindowMac
*)this ) ;
799 return dc
.GetCharHeight() ;
802 int wxWindowMac::GetCharWidth() const
804 wxClientDC
dc ( (wxWindowMac
*)this ) ;
805 return dc
.GetCharWidth() ;
808 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
809 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
811 const wxFont
*fontToUse
= theFont
;
815 wxClientDC
dc( (wxWindowMac
*) this ) ;
817 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
818 if ( externalLeading
)
819 *externalLeading
= le
;
829 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
830 * we always intersect with the entire window, not only with the client area
833 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
835 if ( MacGetTopLevelWindow() == NULL
)
838 wxPoint client
= GetClientAreaOrigin();
841 int x2
= m_width
- client
.x
;
842 int y2
= m_height
- client
.y
;
844 if (IsKindOf( CLASSINFO(wxButton
)))
846 // buttons have an "aura"
853 Rect clientrect
= { y1
, x1
, y2
, x2
};
857 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
858 SectRect( &clientrect
, &r
, &clientrect
) ;
861 if ( !EmptyRect( &clientrect
) )
863 int top
= 0 , left
= 0 ;
865 MacClientToRootWindow( &left
, &top
) ;
866 OffsetRect( &clientrect
, left
, top
) ;
868 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
872 #if wxUSE_CARET && WXWIN_COMPATIBILITY
873 // ---------------------------------------------------------------------------
874 // Caret manipulation
875 // ---------------------------------------------------------------------------
877 void wxWindowMac::CreateCaret(int w
, int h
)
879 SetCaret(new wxCaret(this, w
, h
));
882 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
884 wxFAIL_MSG("not implemented");
887 void wxWindowMac::ShowCaret(bool show
)
889 wxCHECK_RET( m_caret
, "no caret to show" );
894 void wxWindowMac::DestroyCaret()
899 void wxWindowMac::SetCaretPos(int x
, int y
)
901 wxCHECK_RET( m_caret
, "no caret to move" );
906 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
908 wxCHECK_RET( m_caret
, "no caret to get position of" );
910 m_caret
->GetPosition(x
, y
);
912 #endif // wxUSE_CARET
914 wxWindowMac
*wxGetActiveWindow()
916 // actually this is a windows-only concept
920 // Coordinates relative to the window
921 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
923 // We really dont move the mouse programmatically under mac
926 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
928 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
930 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
932 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
934 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
935 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
936 // either a non gray background color or a non control window
938 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
940 wxWindowMac
* parent
= GetParent() ;
943 if ( parent
->MacGetRootWindow() != window
)
945 // we are in a different window on the mac system
951 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
952 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
954 // if we have any other colours in the hierarchy
955 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
958 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
959 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
961 Rect extent
= { 0 , 0 , 0 , 0 } ;
964 wxSize size
= parent
->GetSize() ;
965 parent
->MacClientToRootWindow( &x
, &y
) ;
969 extent
.right
= x
+ size
.x
;
970 extent
.bottom
= y
+ size
.y
;
971 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
975 parent
= parent
->GetParent() ;
979 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
984 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
987 return m_macBackgroundBrush
;
991 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
993 event
.GetDC()->Clear() ;
996 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
998 wxWindowDC
dc(this) ;
999 wxMacPortSetter
helper(&dc
) ;
1001 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1004 int wxWindowMac::GetScrollPos(int orient
) const
1006 if ( orient
== wxHORIZONTAL
)
1009 return m_hScrollBar
->GetThumbPosition() ;
1014 return m_vScrollBar
->GetThumbPosition() ;
1019 // This now returns the whole range, not just the number
1020 // of positions that we can scroll.
1021 int wxWindowMac::GetScrollRange(int orient
) const
1023 if ( orient
== wxHORIZONTAL
)
1026 return m_hScrollBar
->GetRange() ;
1031 return m_vScrollBar
->GetRange() ;
1036 int wxWindowMac::GetScrollThumb(int orient
) const
1038 if ( orient
== wxHORIZONTAL
)
1041 return m_hScrollBar
->GetThumbSize() ;
1046 return m_vScrollBar
->GetThumbSize() ;
1051 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1053 if ( orient
== wxHORIZONTAL
)
1056 m_hScrollBar
->SetThumbPosition( pos
) ;
1061 m_vScrollBar
->SetThumbPosition( pos
) ;
1065 void wxWindowMac::MacPaintBorders( int left
, int top
)
1070 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1071 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1072 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1073 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1076 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1078 #if wxMAC_USE_THEME_BORDER
1079 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1082 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1083 InsetRect( &rect , border , border );
1084 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1087 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1089 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1090 RGBForeColor( &face
);
1091 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1092 LineTo( left
+ 0 , top
+ 0 );
1093 LineTo( left
+ m_width
- 2 , top
+ 0 );
1095 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1096 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1097 LineTo( left
+ m_width
- 3 , top
+ 2 );
1099 RGBForeColor( sunken
? &face
: &black
);
1100 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1101 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1102 LineTo( left
+ m_width
- 1 , top
+ 0 );
1104 RGBForeColor( sunken
? &shadow
: &white
);
1105 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1106 LineTo( left
+ 1, top
+ 1 );
1107 LineTo( left
+ m_width
- 3 , top
+ 1 );
1109 RGBForeColor( sunken
? &white
: &shadow
);
1110 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1111 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1112 LineTo( left
+ m_width
- 2 , top
+ 1 );
1114 RGBForeColor( sunken
? &black
: &face
);
1115 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1116 LineTo( left
+ 2 , top
+ 2 );
1117 LineTo( left
+ m_width
- 4 , top
+ 2 );
1120 else if (HasFlag(wxSIMPLE_BORDER
))
1122 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1123 RGBForeColor( &black
) ;
1124 FrameRect( &rect
) ;
1128 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1130 if ( child
== m_hScrollBar
)
1131 m_hScrollBar
= NULL
;
1132 if ( child
== m_vScrollBar
)
1133 m_vScrollBar
= NULL
;
1135 wxWindowBase::RemoveChild( child
) ;
1138 // New function that will replace some of the above.
1139 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1140 int range
, bool refresh
)
1142 if ( orient
== wxHORIZONTAL
)
1146 if ( range
== 0 || thumbVisible
>= range
)
1148 if ( m_hScrollBar
->IsShown() )
1149 m_hScrollBar
->Show(false) ;
1153 if ( !m_hScrollBar
->IsShown() )
1154 m_hScrollBar
->Show(true) ;
1155 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1163 if ( range
== 0 || thumbVisible
>= range
)
1165 if ( m_vScrollBar
->IsShown() )
1166 m_vScrollBar
->Show(false) ;
1170 if ( !m_vScrollBar
->IsShown() )
1171 m_vScrollBar
->Show(true) ;
1172 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1176 MacRepositionScrollBars() ;
1179 // Does a physical scroll
1180 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1182 wxClientDC
dc(this) ;
1183 wxMacPortSetter
helper(&dc
) ;
1186 int width
, height
;
1187 GetClientSize( &width
, &height
) ;
1189 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1190 RgnHandle updateRgn
= NewRgn() ;
1191 ClipRect( &scrollrect
) ;
1194 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1195 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1196 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1198 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1199 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1200 DisposeRgn( updateRgn
) ;
1203 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1205 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1206 if (child
== m_vScrollBar
) continue;
1207 if (child
== m_hScrollBar
) continue;
1208 if (child
->IsTopLevel()) continue;
1211 child
->GetPosition( &x
, &y
);
1213 child
->GetSize( &w
, &h
);
1214 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1219 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1221 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1223 wxScrollWinEvent wevent
;
1224 wevent
.SetPosition(event
.GetPosition());
1225 wevent
.SetOrientation(event
.GetOrientation());
1226 wevent
.m_eventObject
= this;
1228 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1229 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1231 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1232 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1234 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1235 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1237 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1238 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1240 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1241 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1243 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1244 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1246 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1247 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1250 GetEventHandler()->ProcessEvent(wevent
);
1254 // Get the window with the focus
1255 wxWindowMac
*wxWindowBase::FindFocus()
1257 return gFocusWindow
;
1260 #if WXWIN_COMPATIBILITY
1261 // If nothing defined for this, try the parent.
1262 // E.g. we may be a button loaded from a resource, with no callback function
1264 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1266 if ( GetEventHandler()->ProcessEvent(event
) )
1269 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1271 #endif // WXWIN_COMPATIBILITY_2
1273 #if WXWIN_COMPATIBILITY
1274 wxObject
* wxWindowMac::GetChild(int number
) const
1276 // Return a pointer to the Nth object in the Panel
1277 wxNode
*node
= GetChildren().First();
1280 node
= node
->Next();
1283 wxObject
*obj
= (wxObject
*)node
->Data();
1289 #endif // WXWIN_COMPATIBILITY
1291 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1293 // panel wants to track the window which was the last to have focus in it,
1294 // so we want to set ourselves as the window which last had focus
1296 // notice that it's also important to do it upwards the tree becaus
1297 // otherwise when the top level panel gets focus, it won't set it back to
1298 // us, but to some other sibling
1300 // CS:don't know if this is still needed:
1301 //wxChildFocusEvent eventFocus(this);
1302 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1307 void wxWindowMac::Clear()
1309 wxClientDC
dc(this);
1310 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1311 dc
.SetBackground(brush
);
1315 // Setup background and foreground colours correctly
1316 void wxWindowMac::SetupColours()
1319 SetBackgroundColour(GetParent()->GetBackgroundColour());
1322 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1325 // Check if we need to send a LEAVE event
1326 if (m_mouseInWindow)
1329 ::GetCursorPos(&pt);
1330 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1332 // Generate a LEAVE event
1333 m_mouseInWindow = FALSE;
1334 MSWOnMouseLeave(pt.x, pt.y, 0);
1339 // This calls the UI-update mechanism (querying windows for
1340 // menu/toolbar/control state information)
1344 // Raise the window to the top of the Z order
1345 void wxWindowMac::Raise()
1349 // Lower the window to the bottom of the Z order
1350 void wxWindowMac::Lower()
1354 void wxWindowMac::DoSetClientSize(int width
, int height
)
1356 if ( width
!= -1 || height
!= -1 )
1359 if ( width
!= -1 && m_vScrollBar
)
1360 width
+= MAC_SCROLLBAR_SIZE
;
1361 if ( height
!= -1 && m_vScrollBar
)
1362 height
+= MAC_SCROLLBAR_SIZE
;
1364 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1365 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1367 DoSetSize( -1 , -1 , width
, height
) ;
1372 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1374 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1378 if ((point
.x
< 0) || (point
.y
< 0) ||
1379 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1384 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1385 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1389 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1391 wxPoint
newPoint( point
) ;
1393 if ( !IsTopLevel() )
1399 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1401 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1402 // added the m_isShown test --dmazzoni
1403 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1405 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1414 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1418 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1419 if ( ::FindWindow( pt
, &window
) == 3 )
1422 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1425 // No, this yields the CLIENT are, we need the whole frame. RR.
1426 // point = win->ScreenToClient( point ) ;
1429 ::GetPort( &port
) ;
1430 ::SetPort( UMAGetWindowPort( window
) ) ;
1431 ::GlobalToLocal( &pt
) ;
1434 wxPoint
point( pt
.h
, pt
.v
) ;
1436 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1442 extern int wxBusyCursorCount
;
1443 static wxWindow
*gs_lastWhich
= NULL
;
1445 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1447 // first trigger a set cursor event
1449 wxPoint clientorigin
= GetClientAreaOrigin() ;
1450 wxSize clientsize
= GetClientSize() ;
1452 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1454 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1456 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1457 if ( processedEvtSetCursor
&& event
.HasCursor() )
1459 cursor
= event
.GetCursor() ;
1464 // the test for processedEvtSetCursor is here to prevent using m_cursor
1465 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1466 // it - this is a way to say that our cursor shouldn't be used for this
1468 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1478 cursor
= *wxSTANDARD_CURSOR
;
1482 cursor
.MacInstall() ;
1484 return cursor
.Ok() ;
1487 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1489 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1490 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1494 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1497 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1505 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1507 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1508 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1510 if (child
->MacDispatchMouseEvent(event
))
1515 wxWindow
* cursorTarget
= this ;
1516 wxPoint
cursorPoint( x
, y
) ;
1518 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1520 cursorTarget
= cursorTarget
->GetParent() ;
1522 cursorPoint
+= cursorTarget
->GetPosition() ;
1526 event
.SetEventObject( this ) ;
1528 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1530 // set focus to this window
1531 if (AcceptsFocus() && FindFocus()!=this)
1536 if ( event
.GetEventType() == wxEVT_MOTION
1537 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1538 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1539 wxToolTip::RelayEvent( this , event
);
1540 #endif // wxUSE_TOOLTIPS
1542 if (gs_lastWhich
!= this)
1544 gs_lastWhich
= this;
1546 // Double clicks must always occur on the same window
1547 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1548 event
.SetEventType( wxEVT_LEFT_DOWN
);
1549 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1550 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1552 // Same for mouse up events
1553 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1555 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1559 GetEventHandler()->ProcessEvent( event
) ;
1564 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1568 return m_tooltip
->GetTip() ;
1573 void wxWindowMac::Update()
1575 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1578 win
->MacUpdate( 0 ) ;
1579 #if TARGET_API_MAC_CARBON
1580 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1582 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1588 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1590 wxTopLevelWindowMac
* win
= NULL
;
1591 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1594 win
= wxFindWinFromMacWindow( window
) ;
1599 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1601 RgnHandle visRgn
= NewRgn() ;
1602 RgnHandle tempRgn
= NewRgn() ;
1604 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1606 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1607 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1609 int borderTop
= 14 ;
1610 int borderOther
= 4 ;
1612 SetRectRgn( tempRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1613 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1616 if ( !IsTopLevel() )
1618 wxWindow
* parent
= GetParent() ;
1621 wxSize size
= parent
->GetSize() ;
1624 parent
->MacWindowToRootWindow( &x
, &y
) ;
1625 MacRootWindowToWindow( &x
, &y
) ;
1627 SetRectRgn( tempRgn
,
1628 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1629 x
+ size
.x
- parent
->MacGetLeftBorderSize() - parent
->MacGetRightBorderSize(),
1630 y
+ size
.y
- parent
->MacGetTopBorderSize() - parent
->MacGetBottomBorderSize()) ;
1632 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1633 if ( parent
->IsTopLevel() )
1635 parent
= parent
->GetParent() ;
1638 if ( respectChildrenAndSiblings
)
1640 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1642 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1644 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1646 if ( !child
->IsTopLevel() && child
->IsShown() )
1648 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1649 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1654 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1656 bool thisWindowThrough
= false ;
1657 for (wxNode
*node
= GetParent()->GetChildren().First(); node
; node
= node
->Next())
1659 wxWindowMac
*sibling
= (wxWindowMac
*)node
->Data();
1660 if ( sibling
== this )
1662 thisWindowThrough
= true ;
1665 if( !thisWindowThrough
)
1670 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1672 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
) ;
1673 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1678 m_macVisibleRegion
= visRgn
;
1679 DisposeRgn( visRgn
) ;
1680 DisposeRgn( tempRgn
) ;
1681 return m_macVisibleRegion
;
1684 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1686 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1687 // updatergn is always already clipped to our boundaries
1688 // it is in window coordinates, not in client coordinates
1690 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1693 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1694 RgnHandle ownUpdateRgn
= NewRgn() ;
1695 CopyRgn( updatergn
, ownUpdateRgn
) ;
1697 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1699 // newupdate is the update region in client coordinates
1700 RgnHandle newupdate
= NewRgn() ;
1701 wxSize point
= GetClientSize() ;
1702 wxPoint origin
= GetClientAreaOrigin() ;
1703 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1704 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1705 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1706 m_updateRegion
= newupdate
;
1707 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1709 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1711 wxWindowDC
dc(this);
1712 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1713 wxEraseEvent
eevent( GetId(), &dc
);
1714 eevent
.SetEventObject( this );
1715 GetEventHandler()->ProcessEvent( eevent
);
1717 wxNcPaintEvent
eventNc( GetId() );
1718 eventNc
.SetEventObject( this );
1719 GetEventHandler()->ProcessEvent( eventNc
);
1721 DisposeRgn( ownUpdateRgn
) ;
1722 if ( !m_updateRegion
.Empty() )
1725 event
.m_timeStamp
= time
;
1726 event
.SetEventObject(this);
1727 GetEventHandler()->ProcessEvent(event
);
1731 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1733 RgnHandle childupdate
= NewRgn() ;
1734 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1736 // calculate the update region for the child windows by intersecting the window rectangle with our own
1737 // passed in update region and then offset it to be client-wise window coordinates again
1738 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1739 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1740 SectRgn( childupdate
, updatergn
, childupdate
) ;
1741 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1742 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1744 // because dialogs may also be children
1745 child
->MacRedraw( childupdate
, time
, erase
) ;
1748 DisposeRgn( childupdate
) ;
1749 // eventually a draw grow box here
1753 WXHWND
wxWindowMac::MacGetRootWindow() const
1755 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1759 if ( iter
->IsTopLevel() )
1760 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1762 iter
= iter
->GetParent() ;
1764 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1768 void wxWindowMac::MacCreateScrollBars( long style
)
1770 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1772 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1773 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1775 GetClientSize( &width
, &height
) ;
1777 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1778 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1779 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1780 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1782 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1783 vSize
, wxVERTICAL
);
1785 if ( style
& wxVSCROLL
)
1791 m_vScrollBar
->Show(false) ;
1793 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1794 hSize
, wxHORIZONTAL
);
1795 if ( style
& wxHSCROLL
)
1800 m_hScrollBar
->Show(false) ;
1803 // because the create does not take into account the client area origin
1804 MacRepositionScrollBars() ; // we might have a real position shift
1807 void wxWindowMac::MacRepositionScrollBars()
1809 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1810 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1812 // get real client area
1814 int width
= m_width
;
1815 int height
= m_height
;
1817 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1818 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1820 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1821 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1822 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1823 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1830 MacClientToRootWindow( &x
, &y
) ;
1831 MacClientToRootWindow( &w
, &h
) ;
1833 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1835 int totW
= 10000 , totH
= 10000;
1838 if ( iter
->IsTopLevel() )
1840 totW
= iter
->m_width
;
1841 totH
= iter
->m_height
;
1845 iter
= iter
->GetParent() ;
1873 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1877 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1881 bool wxWindowMac::AcceptsFocus() const
1883 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1886 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1888 return GetParent()->MacGetContainerForEmbedding() ;
1891 void wxWindowMac::MacSuperChangedPosition()
1893 // only window-absolute structures have to be moved i.e. controls
1895 wxNode
*node
= GetChildren().First();
1898 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1899 child
->MacSuperChangedPosition() ;
1900 node
= node
->Next();
1904 void wxWindowMac::MacTopLevelWindowChangedPosition()
1906 // only screen-absolute structures have to be moved i.e. glcanvas
1908 wxNode
*node
= GetChildren().First();
1911 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1912 child
->MacTopLevelWindowChangedPosition() ;
1913 node
= node
->Next();
1916 long wxWindowMac::MacGetLeftBorderSize( ) const
1921 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1924 #if wxMAC_USE_THEME_BORDER
1926 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1931 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1934 #if wxMAC_USE_THEME_BORDER
1936 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1941 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1948 long wxWindowMac::MacGetRightBorderSize( ) const
1950 // they are all symmetric in mac themes
1951 return MacGetLeftBorderSize() ;
1954 long wxWindowMac::MacGetTopBorderSize( ) const
1956 // they are all symmetric in mac themes
1957 return MacGetLeftBorderSize() ;
1960 long wxWindowMac::MacGetBottomBorderSize( ) const
1962 // they are all symmetric in mac themes
1963 return MacGetLeftBorderSize() ;
1966 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1968 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1971 // Find the wxWindowMac at the current mouse position, returning the mouse
1973 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
1975 pt
= wxGetMousePosition();
1976 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
1980 // Get the current mouse position.
1981 wxPoint
wxGetMousePosition()
1984 wxGetMousePosition(& x
, & y
);
1985 return wxPoint(x
, y
);