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 // Without testing the window id, for some reason
246 // a kill focus event can still be sent to
247 // the control just being focussed.
248 int thisId
= this->m_windowId
;
249 int gFocusWindowId
= gFocusWindow
->m_windowId
;
250 if (gFocusWindowId
!= thisId
)
252 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
253 event
.SetEventObject(gFocusWindow
);
254 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
257 gFocusWindow
= this ;
263 m_caret
->OnSetFocus();
265 #endif // wxUSE_CARET
266 // panel wants to track the window which was the last to have focus in it
267 wxChildFocusEvent
eventFocus(this);
268 GetEventHandler()->ProcessEvent(eventFocus
);
270 #ifndef __WXUNIVERSAL__
271 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
272 if ( control
&& control
->GetMacControl() )
274 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
277 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
278 event
.SetEventObject(this);
279 GetEventHandler()->ProcessEvent(event
) ;
284 bool wxWindowMac::Enable(bool enable
)
286 if ( !wxWindowBase::Enable(enable
) )
289 MacSuperEnabled( enable
) ;
294 void wxWindowMac::DoCaptureMouse()
296 wxTheApp
->s_captureWindow
= this ;
299 wxWindow
* wxWindowBase::GetCapture()
301 return wxTheApp
->s_captureWindow
;
304 void wxWindowMac::DoReleaseMouse()
306 wxTheApp
->s_captureWindow
= NULL
;
309 #if wxUSE_DRAG_AND_DROP
311 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
313 if ( m_dropTarget
!= 0 ) {
317 m_dropTarget
= pDropTarget
;
318 if ( m_dropTarget
!= 0 )
326 // Old style file-manager drag&drop
327 void wxWindowMac::DragAcceptFiles(bool accept
)
333 void wxWindowMac::DoGetSize(int *x
, int *y
) const
336 if(y
) *y
= m_height
;
339 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
345 if ( !IsTopLevel() && GetParent())
347 wxPoint
pt(GetParent()->GetClientAreaOrigin());
356 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
358 menu
->SetInvokingWindow(this);
360 ClientToScreen( &x
, &y
) ;
362 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
363 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
364 if ( HiWord(menuResult
) != 0 )
367 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
369 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
370 event
.m_timeStamp
= TickCount() ;
371 event
.SetEventObject(this->GetEventHandler());
373 GetEventHandler()->ProcessEvent(event
);
375 ::DeleteMenu( menu
->MacGetMenuId() ) ;
376 menu
->SetInvokingWindow(NULL
);
382 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
384 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
386 Point localwhere
= {0,0} ;
388 if(x
) localwhere
.h
= * x
;
389 if(y
) localwhere
.v
= * y
;
393 ::SetPort( UMAGetWindowPort( window
) ) ;
394 ::GlobalToLocal( &localwhere
) ;
397 if(x
) *x
= localwhere
.h
;
398 if(y
) *y
= localwhere
.v
;
400 MacRootWindowToWindow( x
, y
) ;
402 *x
-= MacGetLeftBorderSize() ;
404 *y
-= MacGetTopBorderSize() ;
407 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
409 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
412 *x
+= MacGetLeftBorderSize() ;
414 *y
+= MacGetTopBorderSize() ;
416 MacWindowToRootWindow( x
, y
) ;
418 Point localwhere
= { 0,0 };
419 if(x
) localwhere
.h
= * x
;
420 if(y
) localwhere
.v
= * y
;
424 ::SetPort( UMAGetWindowPort( window
) ) ;
426 ::LocalToGlobal( &localwhere
) ;
428 if(x
) *x
= localwhere
.h
;
429 if(y
) *y
= localwhere
.v
;
432 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
434 wxPoint origin
= GetClientAreaOrigin() ;
435 if(x
) *x
+= origin
.x
;
436 if(y
) *y
+= origin
.y
;
438 MacWindowToRootWindow( x
, y
) ;
441 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
443 wxPoint origin
= GetClientAreaOrigin() ;
444 MacRootWindowToWindow( x
, y
) ;
445 if(x
) *x
-= origin
.x
;
446 if(y
) *y
-= origin
.y
;
449 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
455 GetParent()->MacWindowToRootWindow( x
, y
) ;
459 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
465 GetParent()->MacRootWindowToWindow( x
, y
) ;
469 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
471 if (m_cursor
== cursor
)
474 if (wxNullCursor
== cursor
)
476 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
481 if ( ! wxWindowBase::SetCursor( cursor
) )
485 wxASSERT_MSG( m_cursor
.Ok(),
486 wxT("cursor must be valid after call to the base version"));
489 wxWindowMac
*mouseWin
;
492 // Change the cursor NOW if we're within the correct window
494 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
496 if ( mouseWin
== this && !wxIsBusy() )
498 m_cursor
.MacInstall() ;
506 // Get size *available for subwindows* i.e. excluding menu bar etc.
507 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
513 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
514 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
516 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
523 MacClientToRootWindow( &x1
, &y1
) ;
524 MacClientToRootWindow( &w
, &h
) ;
526 wxWindowMac
*iter
= (wxWindowMac
*)this ;
528 int totW
= 10000 , totH
= 10000;
531 if ( iter
->IsTopLevel() )
533 totW
= iter
->m_width
;
534 totH
= iter
->m_height
;
538 iter
= iter
->GetParent() ;
541 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
543 hh
-= MAC_SCROLLBAR_SIZE
;
549 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
551 ww
-= MAC_SCROLLBAR_SIZE
;
563 // ----------------------------------------------------------------------------
565 // ----------------------------------------------------------------------------
569 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
571 wxWindowBase::DoSetToolTip(tooltip
);
574 m_tooltip
->SetWindow(this);
577 #endif // wxUSE_TOOLTIPS
579 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
583 int former_w
= m_width
;
584 int former_h
= m_height
;
586 int actualWidth
= width
;
587 int actualHeight
= height
;
591 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
592 actualWidth
= m_minWidth
;
593 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
594 actualHeight
= m_minHeight
;
595 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
596 actualWidth
= m_maxWidth
;
597 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
598 actualHeight
= m_maxHeight
;
600 bool doMove
= false ;
601 bool doResize
= false ;
603 if ( actualX
!= former_x
|| actualY
!= former_y
)
607 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
612 if ( doMove
|| doResize
)
614 // erase former position
616 bool partialRepaint
= false ;
618 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
620 wxPoint
oldPos( m_x
, m_y
) ;
621 wxPoint
newPos( actualX
, actualY
) ;
622 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
623 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
624 if ( oldPos
== newPos
)
626 partialRepaint
= true ;
627 RgnHandle oldRgn
,newRgn
,diffRgn
;
631 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
632 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
633 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
634 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
635 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
636 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
639 DisposeRgn(diffRgn
) ;
643 if ( !partialRepaint
)
648 m_width
= actualWidth
;
649 m_height
= actualHeight
;
651 // update any low-level frame-relative positions
653 MacUpdateDimensions() ;
654 // erase new position
656 if ( !partialRepaint
)
659 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
661 MacRepositionScrollBars() ;
664 wxPoint
point(m_x
, m_y
);
665 wxMoveEvent
event(point
, m_windowId
);
666 event
.SetEventObject(this);
667 GetEventHandler()->ProcessEvent(event
) ;
671 MacRepositionScrollBars() ;
672 wxSize
size(m_width
, m_height
);
673 wxSizeEvent
event(size
, m_windowId
);
674 event
.SetEventObject(this);
675 GetEventHandler()->ProcessEvent(event
);
681 // set the size of the window: if the dimensions are positive, just use them,
682 // but if any of them is equal to -1, it means that we must find the value for
683 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
684 // which case -1 is a valid value for x and y)
686 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
687 // the width/height to best suit our contents, otherwise we reuse the current
689 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
691 // get the current size and position...
692 int currentX
, currentY
;
693 GetPosition(¤tX
, ¤tY
);
695 int currentW
,currentH
;
696 GetSize(¤tW
, ¤tH
);
698 // ... and don't do anything (avoiding flicker) if it's already ok
699 if ( x
== currentX
&& y
== currentY
&&
700 width
== currentW
&& height
== currentH
)
702 MacRepositionScrollBars() ; // we might have a real position shift
706 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
708 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
711 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
716 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
718 size
= DoGetBestSize();
723 // just take the current one
730 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
734 size
= DoGetBestSize();
736 //else: already called DoGetBestSize() above
742 // just take the current one
747 DoMoveWindow(x
, y
, width
, height
);
750 // For implementation purposes - sometimes decorations make the client area
753 wxPoint
wxWindowMac::GetClientAreaOrigin() const
755 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
758 void wxWindowMac::SetTitle(const wxString
& title
)
763 wxString
wxWindowMac::GetTitle() const
768 bool wxWindowMac::Show(bool show
)
770 if ( !wxWindowBase::Show(show
) )
774 WindowRef window = (WindowRef) MacGetRootWindow() ;
775 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
776 if ( win == NULL && win->m_isBeingDeleted )
779 MacSuperShown( show
) ;
784 if ( win && !win->m_isBeingDeleted )
795 void wxWindowMac::MacSuperShown( bool show
)
797 wxWindowListNode
*node
= GetChildren().GetFirst();
800 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
801 if ( child
->m_isShown
)
802 child
->MacSuperShown( show
) ;
803 node
= node
->GetNext();
807 void wxWindowMac::MacSuperEnabled( bool enabled
)
811 // to be absolutely correct we'd have to invalidate (with eraseBkground
812 // because unter MacOSX the frames are drawn with an addXXX mode)
815 wxWindowListNode
*node
= GetChildren().GetFirst();
818 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
819 if ( child
->m_isShown
)
820 child
->MacSuperEnabled( enabled
) ;
821 node
= node
->GetNext();
825 bool wxWindowMac::MacIsReallyShown() const
827 if ( m_isShown
&& (m_parent
!= NULL
) ) {
828 return m_parent
->MacIsReallyShown();
832 bool status = m_isShown ;
833 wxWindowMac * win = this ;
834 while ( status && win->m_parent != NULL )
836 win = win->m_parent ;
837 status = win->m_isShown ;
843 int wxWindowMac::GetCharHeight() const
845 wxClientDC
dc ( (wxWindowMac
*)this ) ;
846 return dc
.GetCharHeight() ;
849 int wxWindowMac::GetCharWidth() const
851 wxClientDC
dc ( (wxWindowMac
*)this ) ;
852 return dc
.GetCharWidth() ;
855 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
856 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
858 const wxFont
*fontToUse
= theFont
;
862 wxClientDC
dc( (wxWindowMac
*) this ) ;
864 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
865 if ( externalLeading
)
866 *externalLeading
= le
;
876 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
877 * we always intersect with the entire window, not only with the client area
880 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
882 if ( MacGetTopLevelWindow() == NULL
)
885 wxPoint client
= GetClientAreaOrigin();
888 int x2
= m_width
- client
.x
;
889 int y2
= m_height
- client
.y
;
891 if (IsKindOf( CLASSINFO(wxButton
)))
893 // buttons have an "aura"
900 Rect clientrect
= { y1
, x1
, y2
, x2
};
904 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
905 SectRect( &clientrect
, &r
, &clientrect
) ;
908 if ( !EmptyRect( &clientrect
) )
910 int top
= 0 , left
= 0 ;
912 MacClientToRootWindow( &left
, &top
) ;
913 OffsetRect( &clientrect
, left
, top
) ;
915 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
919 #if wxUSE_CARET && WXWIN_COMPATIBILITY
920 // ---------------------------------------------------------------------------
921 // Caret manipulation
922 // ---------------------------------------------------------------------------
924 void wxWindowMac::CreateCaret(int w
, int h
)
926 SetCaret(new wxCaret(this, w
, h
));
929 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
931 wxFAIL_MSG("not implemented");
934 void wxWindowMac::ShowCaret(bool show
)
936 wxCHECK_RET( m_caret
, "no caret to show" );
941 void wxWindowMac::DestroyCaret()
946 void wxWindowMac::SetCaretPos(int x
, int y
)
948 wxCHECK_RET( m_caret
, "no caret to move" );
953 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
955 wxCHECK_RET( m_caret
, "no caret to get position of" );
957 m_caret
->GetPosition(x
, y
);
959 #endif // wxUSE_CARET
961 wxWindowMac
*wxGetActiveWindow()
963 // actually this is a windows-only concept
967 // Coordinates relative to the window
968 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
970 // We really dont move the mouse programmatically under mac
973 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
975 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
977 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
979 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
981 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
982 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
983 // either a non gray background color or a non control window
985 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
987 wxWindowMac
* parent
= GetParent() ;
990 if ( parent
->MacGetRootWindow() != window
)
992 // we are in a different window on the mac system
998 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
999 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1001 // if we have any other colours in the hierarchy
1002 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1005 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1006 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1008 Rect extent
= { 0 , 0 , 0 , 0 } ;
1011 wxSize size
= parent
->GetSize() ;
1012 parent
->MacClientToRootWindow( &x
, &y
) ;
1016 extent
.right
= x
+ size
.x
;
1017 extent
.bottom
= y
+ size
.y
;
1018 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1022 parent
= parent
->GetParent() ;
1026 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1031 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1034 return m_macBackgroundBrush
;
1038 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1040 event
.GetDC()->Clear() ;
1043 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1045 wxWindowDC
dc(this) ;
1046 wxMacPortSetter
helper(&dc
) ;
1048 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1051 int wxWindowMac::GetScrollPos(int orient
) const
1053 if ( orient
== wxHORIZONTAL
)
1056 return m_hScrollBar
->GetThumbPosition() ;
1061 return m_vScrollBar
->GetThumbPosition() ;
1066 // This now returns the whole range, not just the number
1067 // of positions that we can scroll.
1068 int wxWindowMac::GetScrollRange(int orient
) const
1070 if ( orient
== wxHORIZONTAL
)
1073 return m_hScrollBar
->GetRange() ;
1078 return m_vScrollBar
->GetRange() ;
1083 int wxWindowMac::GetScrollThumb(int orient
) const
1085 if ( orient
== wxHORIZONTAL
)
1088 return m_hScrollBar
->GetThumbSize() ;
1093 return m_vScrollBar
->GetThumbSize() ;
1098 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1100 if ( orient
== wxHORIZONTAL
)
1103 m_hScrollBar
->SetThumbPosition( pos
) ;
1108 m_vScrollBar
->SetThumbPosition( pos
) ;
1112 void wxWindowMac::MacPaintBorders( int left
, int top
)
1117 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1118 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1119 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1120 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1123 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1125 #if wxMAC_USE_THEME_BORDER
1126 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1129 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1130 InsetRect( &rect , border , border );
1131 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1134 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1136 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1137 RGBForeColor( &face
);
1138 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1139 LineTo( left
+ 0 , top
+ 0 );
1140 LineTo( left
+ m_width
- 2 , top
+ 0 );
1142 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1143 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1144 LineTo( left
+ m_width
- 3 , top
+ 2 );
1146 RGBForeColor( sunken
? &face
: &black
);
1147 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1148 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1149 LineTo( left
+ m_width
- 1 , top
+ 0 );
1151 RGBForeColor( sunken
? &shadow
: &white
);
1152 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1153 LineTo( left
+ 1, top
+ 1 );
1154 LineTo( left
+ m_width
- 3 , top
+ 1 );
1156 RGBForeColor( sunken
? &white
: &shadow
);
1157 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1158 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1159 LineTo( left
+ m_width
- 2 , top
+ 1 );
1161 RGBForeColor( sunken
? &black
: &face
);
1162 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1163 LineTo( left
+ 2 , top
+ 2 );
1164 LineTo( left
+ m_width
- 4 , top
+ 2 );
1167 else if (HasFlag(wxSIMPLE_BORDER
))
1169 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1170 RGBForeColor( &black
) ;
1171 FrameRect( &rect
) ;
1175 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1177 if ( child
== m_hScrollBar
)
1178 m_hScrollBar
= NULL
;
1179 if ( child
== m_vScrollBar
)
1180 m_vScrollBar
= NULL
;
1182 wxWindowBase::RemoveChild( child
) ;
1185 // New function that will replace some of the above.
1186 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1187 int range
, bool refresh
)
1189 if ( orient
== wxHORIZONTAL
)
1193 if ( range
== 0 || thumbVisible
>= range
)
1195 if ( m_hScrollBar
->IsShown() )
1196 m_hScrollBar
->Show(false) ;
1200 if ( !m_hScrollBar
->IsShown() )
1201 m_hScrollBar
->Show(true) ;
1202 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1210 if ( range
== 0 || thumbVisible
>= range
)
1212 if ( m_vScrollBar
->IsShown() )
1213 m_vScrollBar
->Show(false) ;
1217 if ( !m_vScrollBar
->IsShown() )
1218 m_vScrollBar
->Show(true) ;
1219 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1223 MacRepositionScrollBars() ;
1226 // Does a physical scroll
1227 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1229 wxClientDC
dc(this) ;
1230 wxMacPortSetter
helper(&dc
) ;
1233 int width
, height
;
1234 GetClientSize( &width
, &height
) ;
1236 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1237 RgnHandle updateRgn
= NewRgn() ;
1238 ClipRect( &scrollrect
) ;
1241 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1242 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1243 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1245 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1246 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1247 DisposeRgn( updateRgn
) ;
1250 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1252 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1253 if (child
== m_vScrollBar
) continue;
1254 if (child
== m_hScrollBar
) continue;
1255 if (child
->IsTopLevel()) continue;
1258 child
->GetPosition( &x
, &y
);
1260 child
->GetSize( &w
, &h
);
1261 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1266 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1268 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1270 wxScrollWinEvent wevent
;
1271 wevent
.SetPosition(event
.GetPosition());
1272 wevent
.SetOrientation(event
.GetOrientation());
1273 wevent
.m_eventObject
= this;
1275 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1276 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1278 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1279 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1281 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1282 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1284 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1285 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1287 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1288 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1290 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1291 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1293 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1294 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1297 GetEventHandler()->ProcessEvent(wevent
);
1301 // Get the window with the focus
1302 wxWindowMac
*wxWindowBase::FindFocus()
1304 return gFocusWindow
;
1307 #if WXWIN_COMPATIBILITY
1308 // If nothing defined for this, try the parent.
1309 // E.g. we may be a button loaded from a resource, with no callback function
1311 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1313 if ( GetEventHandler()->ProcessEvent(event
) )
1316 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1318 #endif // WXWIN_COMPATIBILITY_2
1320 #if WXWIN_COMPATIBILITY
1321 wxObject
* wxWindowMac::GetChild(int number
) const
1323 // Return a pointer to the Nth object in the Panel
1324 wxNode
*node
= GetChildren().GetFirst();
1327 node
= node
->GetNext();
1330 wxObject
*obj
= (wxObject
*)node
->GetData();
1336 #endif // WXWIN_COMPATIBILITY
1338 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1340 // panel wants to track the window which was the last to have focus in it,
1341 // so we want to set ourselves as the window which last had focus
1343 // notice that it's also important to do it upwards the tree becaus
1344 // otherwise when the top level panel gets focus, it won't set it back to
1345 // us, but to some other sibling
1347 // CS:don't know if this is still needed:
1348 //wxChildFocusEvent eventFocus(this);
1349 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1354 void wxWindowMac::Clear()
1356 wxClientDC
dc(this);
1357 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1358 dc
.SetBackground(brush
);
1362 // Setup background and foreground colours correctly
1363 void wxWindowMac::SetupColours()
1366 SetBackgroundColour(GetParent()->GetBackgroundColour());
1369 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1372 // Check if we need to send a LEAVE event
1373 if (m_mouseInWindow)
1376 ::GetCursorPos(&pt);
1377 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1379 // Generate a LEAVE event
1380 m_mouseInWindow = FALSE;
1381 MSWOnMouseLeave(pt.x, pt.y, 0);
1386 // This calls the UI-update mechanism (querying windows for
1387 // menu/toolbar/control state information)
1391 // Raise the window to the top of the Z order
1392 void wxWindowMac::Raise()
1396 // Lower the window to the bottom of the Z order
1397 void wxWindowMac::Lower()
1401 void wxWindowMac::DoSetClientSize(int width
, int height
)
1403 if ( width
!= -1 || height
!= -1 )
1406 if ( width
!= -1 && m_vScrollBar
)
1407 width
+= MAC_SCROLLBAR_SIZE
;
1408 if ( height
!= -1 && m_vScrollBar
)
1409 height
+= MAC_SCROLLBAR_SIZE
;
1411 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1412 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1414 DoSetSize( -1 , -1 , width
, height
) ;
1419 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1421 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1425 if ((point
.x
< 0) || (point
.y
< 0) ||
1426 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1431 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1432 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1436 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1438 wxPoint
newPoint( point
) ;
1440 if ( !IsTopLevel() )
1446 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1448 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1449 // added the m_isShown test --dmazzoni
1450 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1452 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1461 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1465 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1466 if ( ::FindWindow( pt
, &window
) == 3 )
1469 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1472 // No, this yields the CLIENT are, we need the whole frame. RR.
1473 // point = win->ScreenToClient( point ) ;
1476 ::GetPort( &port
) ;
1477 ::SetPort( UMAGetWindowPort( window
) ) ;
1478 ::GlobalToLocal( &pt
) ;
1481 wxPoint
point( pt
.h
, pt
.v
) ;
1483 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1489 static wxWindow
*gs_lastWhich
= NULL
;
1491 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1493 // first trigger a set cursor event
1495 wxPoint clientorigin
= GetClientAreaOrigin() ;
1496 wxSize clientsize
= GetClientSize() ;
1498 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1500 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1502 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1503 if ( processedEvtSetCursor
&& event
.HasCursor() )
1505 cursor
= event
.GetCursor() ;
1510 // the test for processedEvtSetCursor is here to prevent using m_cursor
1511 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1512 // it - this is a way to say that our cursor shouldn't be used for this
1514 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1524 cursor
= *wxSTANDARD_CURSOR
;
1528 cursor
.MacInstall() ;
1530 return cursor
.Ok() ;
1533 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1535 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1536 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1540 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1543 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1551 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1553 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1554 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1556 if (child
->MacDispatchMouseEvent(event
))
1561 wxWindow
* cursorTarget
= this ;
1562 wxPoint
cursorPoint( x
, y
) ;
1564 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1566 cursorTarget
= cursorTarget
->GetParent() ;
1568 cursorPoint
+= cursorTarget
->GetPosition() ;
1572 event
.SetEventObject( this ) ;
1574 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1576 // set focus to this window
1577 if (AcceptsFocus() && FindFocus()!=this)
1582 if ( event
.GetEventType() == wxEVT_MOTION
1583 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1584 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1585 wxToolTip::RelayEvent( this , event
);
1586 #endif // wxUSE_TOOLTIPS
1588 if (gs_lastWhich
!= this)
1590 gs_lastWhich
= this;
1592 // Double clicks must always occur on the same window
1593 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1594 event
.SetEventType( wxEVT_LEFT_DOWN
);
1595 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1596 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1598 // Same for mouse up events
1599 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1601 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1605 GetEventHandler()->ProcessEvent( event
) ;
1610 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1614 return m_tooltip
->GetTip() ;
1619 void wxWindowMac::Update()
1621 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1624 win
->MacUpdate( 0 ) ;
1625 #if TARGET_API_MAC_CARBON
1626 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1628 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1634 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1636 wxTopLevelWindowMac
* win
= NULL
;
1637 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1640 win
= wxFindWinFromMacWindow( window
) ;
1645 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1647 RgnHandle visRgn
= NewRgn() ;
1648 RgnHandle tempRgn
= NewRgn() ;
1649 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1651 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1653 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1654 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1656 int borderTop
= 14 ;
1657 int borderOther
= 4 ;
1659 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1660 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1663 if ( !IsTopLevel() )
1665 wxWindow
* parent
= GetParent() ;
1668 wxSize size
= parent
->GetSize() ;
1671 parent
->MacWindowToRootWindow( &x
, &y
) ;
1672 MacRootWindowToWindow( &x
, &y
) ;
1674 SetRectRgn( tempRgn
,
1675 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1676 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1677 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1679 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1680 if ( parent
->IsTopLevel() )
1682 parent
= parent
->GetParent() ;
1685 if ( respectChildrenAndSiblings
)
1687 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1689 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1691 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1693 if ( !child
->IsTopLevel() && child
->IsShown() )
1695 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1696 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1698 int borderTop
= 14 ;
1699 int borderOther
= 4 ;
1701 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1702 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1704 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1709 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1711 bool thisWindowThrough
= false ;
1712 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1714 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1715 if ( sibling
== this )
1717 thisWindowThrough
= true ;
1720 if( !thisWindowThrough
)
1725 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1727 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
) ;
1728 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1730 int borderTop
= 14 ;
1731 int borderOther
= 4 ;
1733 SetRectRgn( tempStaticBoxRgn
, sibling
->m_x
- m_x
+ borderOther
, sibling
->m_y
- m_y
+ borderTop
, sibling
->m_x
+ sibling
->m_width
- m_x
- borderOther
, sibling
->m_y
+ sibling
->m_height
- m_y
- borderOther
) ;
1734 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1736 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1741 m_macVisibleRegion
= visRgn
;
1742 DisposeRgn( visRgn
) ;
1743 DisposeRgn( tempRgn
) ;
1744 DisposeRgn( tempStaticBoxRgn
) ;
1745 return m_macVisibleRegion
;
1748 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1750 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1751 // updatergn is always already clipped to our boundaries
1752 // it is in window coordinates, not in client coordinates
1754 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1757 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1758 RgnHandle ownUpdateRgn
= NewRgn() ;
1759 CopyRgn( updatergn
, ownUpdateRgn
) ;
1761 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1763 // newupdate is the update region in client coordinates
1764 RgnHandle newupdate
= NewRgn() ;
1765 wxSize point
= GetClientSize() ;
1766 wxPoint origin
= GetClientAreaOrigin() ;
1767 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1768 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1769 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1770 m_updateRegion
= newupdate
;
1771 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1773 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1775 wxWindowDC
dc(this);
1776 if (!EmptyRgn(ownUpdateRgn
))
1777 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1778 wxEraseEvent
eevent( GetId(), &dc
);
1779 eevent
.SetEventObject( this );
1780 GetEventHandler()->ProcessEvent( eevent
);
1782 wxNcPaintEvent
eventNc( GetId() );
1783 eventNc
.SetEventObject( this );
1784 GetEventHandler()->ProcessEvent( eventNc
);
1786 DisposeRgn( ownUpdateRgn
) ;
1787 if ( !m_updateRegion
.Empty() )
1790 event
.m_timeStamp
= time
;
1791 event
.SetEventObject(this);
1792 GetEventHandler()->ProcessEvent(event
);
1796 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1798 RgnHandle childupdate
= NewRgn() ;
1799 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1801 // calculate the update region for the child windows by intersecting the window rectangle with our own
1802 // passed in update region and then offset it to be client-wise window coordinates again
1803 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1804 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1805 SectRgn( childupdate
, updatergn
, childupdate
) ;
1806 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1807 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1809 // because dialogs may also be children
1810 child
->MacRedraw( childupdate
, time
, erase
) ;
1813 DisposeRgn( childupdate
) ;
1814 // eventually a draw grow box here
1818 WXHWND
wxWindowMac::MacGetRootWindow() const
1820 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1824 if ( iter
->IsTopLevel() )
1825 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1827 iter
= iter
->GetParent() ;
1829 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1833 void wxWindowMac::MacCreateScrollBars( long style
)
1835 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1837 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1838 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1840 GetClientSize( &width
, &height
) ;
1842 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1843 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1844 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1845 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1847 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1848 vSize
, wxVERTICAL
);
1850 if ( style
& wxVSCROLL
)
1856 m_vScrollBar
->Show(false) ;
1858 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1859 hSize
, wxHORIZONTAL
);
1860 if ( style
& wxHSCROLL
)
1865 m_hScrollBar
->Show(false) ;
1868 // because the create does not take into account the client area origin
1869 MacRepositionScrollBars() ; // we might have a real position shift
1872 void wxWindowMac::MacRepositionScrollBars()
1874 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1875 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1877 // get real client area
1879 int width
= m_width
;
1880 int height
= m_height
;
1882 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1883 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1885 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1886 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1887 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1888 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1895 MacClientToRootWindow( &x
, &y
) ;
1896 MacClientToRootWindow( &w
, &h
) ;
1898 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1900 int totW
= 10000 , totH
= 10000;
1903 if ( iter
->IsTopLevel() )
1905 totW
= iter
->m_width
;
1906 totH
= iter
->m_height
;
1910 iter
= iter
->GetParent() ;
1938 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1942 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1946 bool wxWindowMac::AcceptsFocus() const
1948 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1951 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1953 return GetParent()->MacGetContainerForEmbedding() ;
1956 void wxWindowMac::MacSuperChangedPosition()
1958 // only window-absolute structures have to be moved i.e. controls
1960 wxWindowListNode
*node
= GetChildren().GetFirst();
1963 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1964 child
->MacSuperChangedPosition() ;
1965 node
= node
->GetNext();
1969 void wxWindowMac::MacTopLevelWindowChangedPosition()
1971 // only screen-absolute structures have to be moved i.e. glcanvas
1973 wxWindowListNode
*node
= GetChildren().GetFirst();
1976 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1977 child
->MacTopLevelWindowChangedPosition() ;
1978 node
= node
->GetNext();
1981 long wxWindowMac::MacGetLeftBorderSize( ) const
1986 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1989 #if wxMAC_USE_THEME_BORDER
1991 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1996 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1999 #if wxMAC_USE_THEME_BORDER
2001 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2006 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2013 long wxWindowMac::MacGetRightBorderSize( ) const
2015 // they are all symmetric in mac themes
2016 return MacGetLeftBorderSize() ;
2019 long wxWindowMac::MacGetTopBorderSize( ) const
2021 // they are all symmetric in mac themes
2022 return MacGetLeftBorderSize() ;
2025 long wxWindowMac::MacGetBottomBorderSize( ) const
2027 // they are all symmetric in mac themes
2028 return MacGetLeftBorderSize() ;
2031 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2033 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2036 // Find the wxWindowMac at the current mouse position, returning the mouse
2038 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2040 pt
= wxGetMousePosition();
2041 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2045 // Get the current mouse position.
2046 wxPoint
wxGetMousePosition()
2049 wxGetMousePosition(& x
, & y
);
2050 return wxPoint(x
, y
);