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") );
201 // wxGTK doesn't allow to create controls with static box as the parent so
202 // this will result in a crash when the program is ported to wxGTK - warn
205 // the correct solution is to create the controls as siblings of the
207 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
208 _T("wxStaticBox can't be used as a window parent!") );
209 #endif // wxUSE_STATBOX
211 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
214 parent
->AddChild(this);
218 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
219 m_width
= WidthDefault( size
.x
);
220 m_height
= HeightDefault( size
.y
) ;
221 #ifndef __WXUNIVERSAL__
222 // Don't give scrollbars to wxControls unless they ask for them
223 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
224 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
226 MacCreateScrollBars( style
) ;
232 void wxWindowMac::SetFocus()
234 if ( gFocusWindow
== this )
237 if ( AcceptsFocus() )
243 if ( gFocusWindow
->m_caret
)
245 gFocusWindow
->m_caret
->OnKillFocus();
247 #endif // wxUSE_CARET
248 #ifndef __WXUNIVERSAL__
249 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
250 if ( control
&& control
->GetMacControl() )
252 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
253 control
->MacRedrawControl() ;
256 // Without testing the window id, for some reason
257 // a kill focus event can still be sent to
258 // the control just being focussed.
259 int thisId
= this->m_windowId
;
260 int gFocusWindowId
= gFocusWindow
->m_windowId
;
261 if (gFocusWindowId
!= thisId
)
263 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
264 event
.SetEventObject(gFocusWindow
);
265 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
268 gFocusWindow
= this ;
274 m_caret
->OnSetFocus();
276 #endif // wxUSE_CARET
277 // panel wants to track the window which was the last to have focus in it
278 wxChildFocusEvent
eventFocus(this);
279 GetEventHandler()->ProcessEvent(eventFocus
);
281 #ifndef __WXUNIVERSAL__
282 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
283 if ( control
&& control
->GetMacControl() )
285 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
288 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
289 event
.SetEventObject(this);
290 GetEventHandler()->ProcessEvent(event
) ;
295 bool wxWindowMac::Enable(bool enable
)
297 if ( !wxWindowBase::Enable(enable
) )
300 MacSuperEnabled( enable
) ;
305 void wxWindowMac::DoCaptureMouse()
307 wxTheApp
->s_captureWindow
= this ;
310 wxWindow
* wxWindowBase::GetCapture()
312 return wxTheApp
->s_captureWindow
;
315 void wxWindowMac::DoReleaseMouse()
317 wxTheApp
->s_captureWindow
= NULL
;
320 #if wxUSE_DRAG_AND_DROP
322 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
324 if ( m_dropTarget
!= 0 ) {
328 m_dropTarget
= pDropTarget
;
329 if ( m_dropTarget
!= 0 )
337 // Old style file-manager drag&drop
338 void wxWindowMac::DragAcceptFiles(bool accept
)
344 void wxWindowMac::DoGetSize(int *x
, int *y
) const
347 if(y
) *y
= m_height
;
350 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
356 if ( !IsTopLevel() && GetParent())
358 wxPoint
pt(GetParent()->GetClientAreaOrigin());
367 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
369 menu
->SetInvokingWindow(this);
371 ClientToScreen( &x
, &y
) ;
373 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
374 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
375 if ( HiWord(menuResult
) != 0 )
378 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
380 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
381 event
.m_timeStamp
= TickCount() ;
382 event
.SetEventObject(this->GetEventHandler());
384 GetEventHandler()->ProcessEvent(event
);
386 ::DeleteMenu( menu
->MacGetMenuId() ) ;
387 menu
->SetInvokingWindow(NULL
);
393 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
395 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
397 Point localwhere
= {0,0} ;
399 if(x
) localwhere
.h
= * x
;
400 if(y
) localwhere
.v
= * y
;
404 ::SetPort( UMAGetWindowPort( window
) ) ;
405 ::GlobalToLocal( &localwhere
) ;
408 if(x
) *x
= localwhere
.h
;
409 if(y
) *y
= localwhere
.v
;
411 MacRootWindowToWindow( x
, y
) ;
413 *x
-= MacGetLeftBorderSize() ;
415 *y
-= MacGetTopBorderSize() ;
418 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
420 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
423 *x
+= MacGetLeftBorderSize() ;
425 *y
+= MacGetTopBorderSize() ;
427 MacWindowToRootWindow( x
, y
) ;
429 Point localwhere
= { 0,0 };
430 if(x
) localwhere
.h
= * x
;
431 if(y
) localwhere
.v
= * y
;
435 ::SetPort( UMAGetWindowPort( window
) ) ;
437 ::LocalToGlobal( &localwhere
) ;
439 if(x
) *x
= localwhere
.h
;
440 if(y
) *y
= localwhere
.v
;
443 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
445 wxPoint origin
= GetClientAreaOrigin() ;
446 if(x
) *x
+= origin
.x
;
447 if(y
) *y
+= origin
.y
;
449 MacWindowToRootWindow( x
, y
) ;
452 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
454 wxPoint origin
= GetClientAreaOrigin() ;
455 MacRootWindowToWindow( x
, y
) ;
456 if(x
) *x
-= origin
.x
;
457 if(y
) *y
-= origin
.y
;
460 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
466 GetParent()->MacWindowToRootWindow( x
, y
) ;
470 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
476 GetParent()->MacRootWindowToWindow( x
, y
) ;
480 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
482 if (m_cursor
== cursor
)
485 if (wxNullCursor
== cursor
)
487 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
492 if ( ! wxWindowBase::SetCursor( cursor
) )
496 wxASSERT_MSG( m_cursor
.Ok(),
497 wxT("cursor must be valid after call to the base version"));
500 wxWindowMac
*mouseWin
;
503 // Change the cursor NOW if we're within the correct window
505 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
507 if ( mouseWin
== this && !wxIsBusy() )
509 m_cursor
.MacInstall() ;
517 // Get size *available for subwindows* i.e. excluding menu bar etc.
518 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
524 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
525 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
527 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
534 MacClientToRootWindow( &x1
, &y1
) ;
535 MacClientToRootWindow( &w
, &h
) ;
537 wxWindowMac
*iter
= (wxWindowMac
*)this ;
539 int totW
= 10000 , totH
= 10000;
542 if ( iter
->IsTopLevel() )
544 totW
= iter
->m_width
;
545 totH
= iter
->m_height
;
549 iter
= iter
->GetParent() ;
552 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
554 hh
-= MAC_SCROLLBAR_SIZE
;
560 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
562 ww
-= MAC_SCROLLBAR_SIZE
;
574 // ----------------------------------------------------------------------------
576 // ----------------------------------------------------------------------------
580 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
582 wxWindowBase::DoSetToolTip(tooltip
);
585 m_tooltip
->SetWindow(this);
588 #endif // wxUSE_TOOLTIPS
590 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
594 int former_w
= m_width
;
595 int former_h
= m_height
;
597 int actualWidth
= width
;
598 int actualHeight
= height
;
602 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
603 actualWidth
= m_minWidth
;
604 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
605 actualHeight
= m_minHeight
;
606 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
607 actualWidth
= m_maxWidth
;
608 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
609 actualHeight
= m_maxHeight
;
611 bool doMove
= false ;
612 bool doResize
= false ;
614 if ( actualX
!= former_x
|| actualY
!= former_y
)
618 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
623 if ( doMove
|| doResize
)
625 // erase former position
627 bool partialRepaint
= false ;
629 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
631 wxPoint
oldPos( m_x
, m_y
) ;
632 wxPoint
newPos( actualX
, actualY
) ;
633 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
634 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
635 if ( oldPos
== newPos
)
637 partialRepaint
= true ;
638 RgnHandle oldRgn
,newRgn
,diffRgn
;
642 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
643 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
644 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
645 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
646 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
647 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
650 DisposeRgn(diffRgn
) ;
654 if ( !partialRepaint
)
659 m_width
= actualWidth
;
660 m_height
= actualHeight
;
662 // update any low-level frame-relative positions
664 MacUpdateDimensions() ;
665 // erase new position
667 if ( !partialRepaint
)
670 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
672 MacRepositionScrollBars() ;
675 wxPoint
point(m_x
, m_y
);
676 wxMoveEvent
event(point
, m_windowId
);
677 event
.SetEventObject(this);
678 GetEventHandler()->ProcessEvent(event
) ;
682 MacRepositionScrollBars() ;
683 wxSize
size(m_width
, m_height
);
684 wxSizeEvent
event(size
, m_windowId
);
685 event
.SetEventObject(this);
686 GetEventHandler()->ProcessEvent(event
);
692 // set the size of the window: if the dimensions are positive, just use them,
693 // but if any of them is equal to -1, it means that we must find the value for
694 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
695 // which case -1 is a valid value for x and y)
697 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
698 // the width/height to best suit our contents, otherwise we reuse the current
700 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
702 // get the current size and position...
703 int currentX
, currentY
;
704 GetPosition(¤tX
, ¤tY
);
706 int currentW
,currentH
;
707 GetSize(¤tW
, ¤tH
);
709 // ... and don't do anything (avoiding flicker) if it's already ok
710 if ( x
== currentX
&& y
== currentY
&&
711 width
== currentW
&& height
== currentH
)
713 MacRepositionScrollBars() ; // we might have a real position shift
717 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
719 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
722 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
727 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
729 size
= DoGetBestSize();
734 // just take the current one
741 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
745 size
= DoGetBestSize();
747 //else: already called DoGetBestSize() above
753 // just take the current one
758 DoMoveWindow(x
, y
, width
, height
);
761 // For implementation purposes - sometimes decorations make the client area
764 wxPoint
wxWindowMac::GetClientAreaOrigin() const
766 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
769 void wxWindowMac::SetTitle(const wxString
& title
)
774 wxString
wxWindowMac::GetTitle() const
779 bool wxWindowMac::Show(bool show
)
781 if ( !wxWindowBase::Show(show
) )
785 WindowRef window = (WindowRef) MacGetRootWindow() ;
786 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
787 if ( win == NULL && win->m_isBeingDeleted )
790 MacSuperShown( show
) ;
795 if ( win && !win->m_isBeingDeleted )
806 void wxWindowMac::MacSuperShown( bool show
)
808 wxWindowListNode
*node
= GetChildren().GetFirst();
811 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
812 if ( child
->m_isShown
)
813 child
->MacSuperShown( show
) ;
814 node
= node
->GetNext();
818 void wxWindowMac::MacSuperEnabled( bool enabled
)
822 // to be absolutely correct we'd have to invalidate (with eraseBkground
823 // because unter MacOSX the frames are drawn with an addXXX mode)
826 wxWindowListNode
*node
= GetChildren().GetFirst();
829 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
830 if ( child
->m_isShown
)
831 child
->MacSuperEnabled( enabled
) ;
832 node
= node
->GetNext();
836 bool wxWindowMac::MacIsReallyShown() const
838 if ( m_isShown
&& (m_parent
!= NULL
) ) {
839 return m_parent
->MacIsReallyShown();
843 bool status = m_isShown ;
844 wxWindowMac * win = this ;
845 while ( status && win->m_parent != NULL )
847 win = win->m_parent ;
848 status = win->m_isShown ;
854 int wxWindowMac::GetCharHeight() const
856 wxClientDC
dc ( (wxWindowMac
*)this ) ;
857 return dc
.GetCharHeight() ;
860 int wxWindowMac::GetCharWidth() const
862 wxClientDC
dc ( (wxWindowMac
*)this ) ;
863 return dc
.GetCharWidth() ;
866 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
867 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
869 const wxFont
*fontToUse
= theFont
;
873 wxClientDC
dc( (wxWindowMac
*) this ) ;
875 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
876 if ( externalLeading
)
877 *externalLeading
= le
;
887 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
888 * we always intersect with the entire window, not only with the client area
891 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
893 if ( MacGetTopLevelWindow() == NULL
)
896 wxPoint client
= GetClientAreaOrigin();
899 int x2
= m_width
- client
.x
;
900 int y2
= m_height
- client
.y
;
902 if (IsKindOf( CLASSINFO(wxButton
)))
904 // buttons have an "aura"
911 Rect clientrect
= { y1
, x1
, y2
, x2
};
915 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
916 SectRect( &clientrect
, &r
, &clientrect
) ;
919 if ( !EmptyRect( &clientrect
) )
921 int top
= 0 , left
= 0 ;
923 MacClientToRootWindow( &left
, &top
) ;
924 OffsetRect( &clientrect
, left
, top
) ;
926 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
930 #if wxUSE_CARET && WXWIN_COMPATIBILITY
931 // ---------------------------------------------------------------------------
932 // Caret manipulation
933 // ---------------------------------------------------------------------------
935 void wxWindowMac::CreateCaret(int w
, int h
)
937 SetCaret(new wxCaret(this, w
, h
));
940 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
942 wxFAIL_MSG("not implemented");
945 void wxWindowMac::ShowCaret(bool show
)
947 wxCHECK_RET( m_caret
, "no caret to show" );
952 void wxWindowMac::DestroyCaret()
957 void wxWindowMac::SetCaretPos(int x
, int y
)
959 wxCHECK_RET( m_caret
, "no caret to move" );
964 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
966 wxCHECK_RET( m_caret
, "no caret to get position of" );
968 m_caret
->GetPosition(x
, y
);
970 #endif // wxUSE_CARET
972 wxWindowMac
*wxGetActiveWindow()
974 // actually this is a windows-only concept
978 // Coordinates relative to the window
979 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
981 // We really dont move the mouse programmatically under mac
984 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
986 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
988 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
990 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
992 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
993 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
994 // either a non gray background color or a non control window
996 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
998 wxWindowMac
* parent
= GetParent() ;
1001 if ( parent
->MacGetRootWindow() != window
)
1003 // we are in a different window on the mac system
1009 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1010 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1012 // if we have any other colours in the hierarchy
1013 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1016 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1017 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1019 Rect extent
= { 0 , 0 , 0 , 0 } ;
1022 wxSize size
= parent
->GetSize() ;
1023 parent
->MacClientToRootWindow( &x
, &y
) ;
1027 extent
.right
= x
+ size
.x
;
1028 extent
.bottom
= y
+ size
.y
;
1029 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1033 parent
= parent
->GetParent() ;
1037 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1042 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1045 return m_macBackgroundBrush
;
1049 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1051 event
.GetDC()->Clear() ;
1054 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1056 wxWindowDC
dc(this) ;
1057 wxMacPortSetter
helper(&dc
) ;
1059 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1062 int wxWindowMac::GetScrollPos(int orient
) const
1064 if ( orient
== wxHORIZONTAL
)
1067 return m_hScrollBar
->GetThumbPosition() ;
1072 return m_vScrollBar
->GetThumbPosition() ;
1077 // This now returns the whole range, not just the number
1078 // of positions that we can scroll.
1079 int wxWindowMac::GetScrollRange(int orient
) const
1081 if ( orient
== wxHORIZONTAL
)
1084 return m_hScrollBar
->GetRange() ;
1089 return m_vScrollBar
->GetRange() ;
1094 int wxWindowMac::GetScrollThumb(int orient
) const
1096 if ( orient
== wxHORIZONTAL
)
1099 return m_hScrollBar
->GetThumbSize() ;
1104 return m_vScrollBar
->GetThumbSize() ;
1109 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1111 if ( orient
== wxHORIZONTAL
)
1114 m_hScrollBar
->SetThumbPosition( pos
) ;
1119 m_vScrollBar
->SetThumbPosition( pos
) ;
1123 void wxWindowMac::MacPaintBorders( int left
, int top
)
1128 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1129 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1130 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1131 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1134 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1136 #if wxMAC_USE_THEME_BORDER
1137 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1140 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1141 InsetRect( &rect , border , border );
1142 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1145 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1147 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1148 RGBForeColor( &face
);
1149 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1150 LineTo( left
+ 0 , top
+ 0 );
1151 LineTo( left
+ m_width
- 2 , top
+ 0 );
1153 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1154 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1155 LineTo( left
+ m_width
- 3 , top
+ 2 );
1157 RGBForeColor( sunken
? &face
: &black
);
1158 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1159 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1160 LineTo( left
+ m_width
- 1 , top
+ 0 );
1162 RGBForeColor( sunken
? &shadow
: &white
);
1163 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1164 LineTo( left
+ 1, top
+ 1 );
1165 LineTo( left
+ m_width
- 3 , top
+ 1 );
1167 RGBForeColor( sunken
? &white
: &shadow
);
1168 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1169 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1170 LineTo( left
+ m_width
- 2 , top
+ 1 );
1172 RGBForeColor( sunken
? &black
: &face
);
1173 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1174 LineTo( left
+ 2 , top
+ 2 );
1175 LineTo( left
+ m_width
- 4 , top
+ 2 );
1178 else if (HasFlag(wxSIMPLE_BORDER
))
1180 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1181 RGBForeColor( &black
) ;
1182 FrameRect( &rect
) ;
1186 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1188 if ( child
== m_hScrollBar
)
1189 m_hScrollBar
= NULL
;
1190 if ( child
== m_vScrollBar
)
1191 m_vScrollBar
= NULL
;
1193 wxWindowBase::RemoveChild( child
) ;
1196 // New function that will replace some of the above.
1197 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1198 int range
, bool refresh
)
1200 if ( orient
== wxHORIZONTAL
)
1204 if ( range
== 0 || thumbVisible
>= range
)
1206 if ( m_hScrollBar
->IsShown() )
1207 m_hScrollBar
->Show(false) ;
1211 if ( !m_hScrollBar
->IsShown() )
1212 m_hScrollBar
->Show(true) ;
1213 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1221 if ( range
== 0 || thumbVisible
>= range
)
1223 if ( m_vScrollBar
->IsShown() )
1224 m_vScrollBar
->Show(false) ;
1228 if ( !m_vScrollBar
->IsShown() )
1229 m_vScrollBar
->Show(true) ;
1230 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1234 MacRepositionScrollBars() ;
1237 // Does a physical scroll
1238 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1240 wxClientDC
dc(this) ;
1241 wxMacPortSetter
helper(&dc
) ;
1244 int width
, height
;
1245 GetClientSize( &width
, &height
) ;
1247 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1248 RgnHandle updateRgn
= NewRgn() ;
1249 ClipRect( &scrollrect
) ;
1252 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1253 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1254 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1256 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1257 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1258 DisposeRgn( updateRgn
) ;
1261 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1263 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1264 if (child
== m_vScrollBar
) continue;
1265 if (child
== m_hScrollBar
) continue;
1266 if (child
->IsTopLevel()) continue;
1269 child
->GetPosition( &x
, &y
);
1271 child
->GetSize( &w
, &h
);
1272 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1277 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1279 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1281 wxScrollWinEvent wevent
;
1282 wevent
.SetPosition(event
.GetPosition());
1283 wevent
.SetOrientation(event
.GetOrientation());
1284 wevent
.m_eventObject
= this;
1286 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1287 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1289 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1290 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1292 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1293 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1295 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1296 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1298 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1299 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1301 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1302 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1304 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1305 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1308 GetEventHandler()->ProcessEvent(wevent
);
1312 // Get the window with the focus
1313 wxWindowMac
*wxWindowBase::FindFocus()
1315 return gFocusWindow
;
1318 #if WXWIN_COMPATIBILITY
1319 // If nothing defined for this, try the parent.
1320 // E.g. we may be a button loaded from a resource, with no callback function
1322 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1324 if ( GetEventHandler()->ProcessEvent(event
) )
1327 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1329 #endif // WXWIN_COMPATIBILITY_2
1331 #if WXWIN_COMPATIBILITY
1332 wxObject
* wxWindowMac::GetChild(int number
) const
1334 // Return a pointer to the Nth object in the Panel
1335 wxNode
*node
= GetChildren().GetFirst();
1338 node
= node
->GetNext();
1341 wxObject
*obj
= (wxObject
*)node
->GetData();
1347 #endif // WXWIN_COMPATIBILITY
1349 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1351 // panel wants to track the window which was the last to have focus in it,
1352 // so we want to set ourselves as the window which last had focus
1354 // notice that it's also important to do it upwards the tree becaus
1355 // otherwise when the top level panel gets focus, it won't set it back to
1356 // us, but to some other sibling
1358 // CS:don't know if this is still needed:
1359 //wxChildFocusEvent eventFocus(this);
1360 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1365 void wxWindowMac::Clear()
1367 wxClientDC
dc(this);
1368 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1369 dc
.SetBackground(brush
);
1373 // Setup background and foreground colours correctly
1374 void wxWindowMac::SetupColours()
1377 SetBackgroundColour(GetParent()->GetBackgroundColour());
1380 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1383 // Check if we need to send a LEAVE event
1384 if (m_mouseInWindow)
1387 ::GetCursorPos(&pt);
1388 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1390 // Generate a LEAVE event
1391 m_mouseInWindow = FALSE;
1392 MSWOnMouseLeave(pt.x, pt.y, 0);
1397 // This calls the UI-update mechanism (querying windows for
1398 // menu/toolbar/control state information)
1402 // Raise the window to the top of the Z order
1403 void wxWindowMac::Raise()
1407 // Lower the window to the bottom of the Z order
1408 void wxWindowMac::Lower()
1412 void wxWindowMac::DoSetClientSize(int width
, int height
)
1414 if ( width
!= -1 || height
!= -1 )
1417 if ( width
!= -1 && m_vScrollBar
)
1418 width
+= MAC_SCROLLBAR_SIZE
;
1419 if ( height
!= -1 && m_vScrollBar
)
1420 height
+= MAC_SCROLLBAR_SIZE
;
1422 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1423 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1425 DoSetSize( -1 , -1 , width
, height
) ;
1430 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1432 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1436 if ((point
.x
< 0) || (point
.y
< 0) ||
1437 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1442 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1443 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1447 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1449 wxPoint
newPoint( point
) ;
1451 if ( !IsTopLevel() )
1457 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1459 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1460 // added the m_isShown test --dmazzoni
1461 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1463 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1472 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1476 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1477 if ( ::FindWindow( pt
, &window
) == 3 )
1480 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1483 // No, this yields the CLIENT are, we need the whole frame. RR.
1484 // point = win->ScreenToClient( point ) ;
1487 ::GetPort( &port
) ;
1488 ::SetPort( UMAGetWindowPort( window
) ) ;
1489 ::GlobalToLocal( &pt
) ;
1492 wxPoint
point( pt
.h
, pt
.v
) ;
1494 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1500 static wxWindow
*gs_lastWhich
= NULL
;
1502 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1504 // first trigger a set cursor event
1506 wxPoint clientorigin
= GetClientAreaOrigin() ;
1507 wxSize clientsize
= GetClientSize() ;
1509 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1511 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1513 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1514 if ( processedEvtSetCursor
&& event
.HasCursor() )
1516 cursor
= event
.GetCursor() ;
1521 // the test for processedEvtSetCursor is here to prevent using m_cursor
1522 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1523 // it - this is a way to say that our cursor shouldn't be used for this
1525 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1535 cursor
= *wxSTANDARD_CURSOR
;
1539 cursor
.MacInstall() ;
1541 return cursor
.Ok() ;
1544 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1546 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1547 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1551 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1554 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1562 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1564 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1565 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1567 if (child
->MacDispatchMouseEvent(event
))
1572 wxWindow
* cursorTarget
= this ;
1573 wxPoint
cursorPoint( x
, y
) ;
1575 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1577 cursorTarget
= cursorTarget
->GetParent() ;
1579 cursorPoint
+= cursorTarget
->GetPosition() ;
1583 event
.SetEventObject( this ) ;
1585 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1587 // set focus to this window
1588 if (AcceptsFocus() && FindFocus()!=this)
1593 if ( event
.GetEventType() == wxEVT_MOTION
1594 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1595 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1596 wxToolTip::RelayEvent( this , event
);
1597 #endif // wxUSE_TOOLTIPS
1599 if (gs_lastWhich
!= this)
1601 gs_lastWhich
= this;
1603 // Double clicks must always occur on the same window
1604 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1605 event
.SetEventType( wxEVT_LEFT_DOWN
);
1606 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1607 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1609 // Same for mouse up events
1610 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1612 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1616 GetEventHandler()->ProcessEvent( event
) ;
1621 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1625 return m_tooltip
->GetTip() ;
1630 void wxWindowMac::Update()
1632 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1635 win
->MacUpdate( 0 ) ;
1636 #if TARGET_API_MAC_CARBON
1637 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1639 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1645 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1647 wxTopLevelWindowMac
* win
= NULL
;
1648 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1651 win
= wxFindWinFromMacWindow( window
) ;
1656 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1658 RgnHandle visRgn
= NewRgn() ;
1659 RgnHandle tempRgn
= NewRgn() ;
1660 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1662 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1664 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1665 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1667 int borderTop
= 14 ;
1668 int borderOther
= 4 ;
1670 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1671 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1674 if ( !IsTopLevel() )
1676 wxWindow
* parent
= GetParent() ;
1679 wxSize size
= parent
->GetSize() ;
1682 parent
->MacWindowToRootWindow( &x
, &y
) ;
1683 MacRootWindowToWindow( &x
, &y
) ;
1685 SetRectRgn( tempRgn
,
1686 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1687 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1688 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1690 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1691 if ( parent
->IsTopLevel() )
1693 parent
= parent
->GetParent() ;
1696 if ( respectChildrenAndSiblings
)
1698 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1700 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1702 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1704 if ( !child
->IsTopLevel() && child
->IsShown() )
1706 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1707 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1709 int borderTop
= 14 ;
1710 int borderOther
= 4 ;
1712 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1713 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1715 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1720 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1722 bool thisWindowThrough
= false ;
1723 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1725 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1726 if ( sibling
== this )
1728 thisWindowThrough
= true ;
1731 if( !thisWindowThrough
)
1736 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1738 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
) ;
1739 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1741 int borderTop
= 14 ;
1742 int borderOther
= 4 ;
1744 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
) ;
1745 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1747 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1752 m_macVisibleRegion
= visRgn
;
1753 DisposeRgn( visRgn
) ;
1754 DisposeRgn( tempRgn
) ;
1755 DisposeRgn( tempStaticBoxRgn
) ;
1756 return m_macVisibleRegion
;
1759 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1761 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1762 // updatergn is always already clipped to our boundaries
1763 // it is in window coordinates, not in client coordinates
1765 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1768 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1769 RgnHandle ownUpdateRgn
= NewRgn() ;
1770 CopyRgn( updatergn
, ownUpdateRgn
) ;
1772 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1774 // newupdate is the update region in client coordinates
1775 RgnHandle newupdate
= NewRgn() ;
1776 wxSize point
= GetClientSize() ;
1777 wxPoint origin
= GetClientAreaOrigin() ;
1778 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1779 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1780 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1781 m_updateRegion
= newupdate
;
1782 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1784 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1786 wxWindowDC
dc(this);
1787 if (!EmptyRgn(ownUpdateRgn
))
1788 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1789 wxEraseEvent
eevent( GetId(), &dc
);
1790 eevent
.SetEventObject( this );
1791 GetEventHandler()->ProcessEvent( eevent
);
1793 wxNcPaintEvent
eventNc( GetId() );
1794 eventNc
.SetEventObject( this );
1795 GetEventHandler()->ProcessEvent( eventNc
);
1797 DisposeRgn( ownUpdateRgn
) ;
1798 if ( !m_updateRegion
.Empty() )
1801 event
.m_timeStamp
= time
;
1802 event
.SetEventObject(this);
1803 GetEventHandler()->ProcessEvent(event
);
1807 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1809 RgnHandle childupdate
= NewRgn() ;
1810 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1812 // calculate the update region for the child windows by intersecting the window rectangle with our own
1813 // passed in update region and then offset it to be client-wise window coordinates again
1814 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1815 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1816 SectRgn( childupdate
, updatergn
, childupdate
) ;
1817 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1818 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1820 // because dialogs may also be children
1821 child
->MacRedraw( childupdate
, time
, erase
) ;
1824 DisposeRgn( childupdate
) ;
1825 // eventually a draw grow box here
1829 WXHWND
wxWindowMac::MacGetRootWindow() const
1831 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1835 if ( iter
->IsTopLevel() )
1836 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1838 iter
= iter
->GetParent() ;
1840 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1844 void wxWindowMac::MacCreateScrollBars( long style
)
1846 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1848 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1849 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1851 GetClientSize( &width
, &height
) ;
1853 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1854 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1855 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1856 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1858 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1859 vSize
, wxVERTICAL
);
1861 if ( style
& wxVSCROLL
)
1867 m_vScrollBar
->Show(false) ;
1869 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1870 hSize
, wxHORIZONTAL
);
1871 if ( style
& wxHSCROLL
)
1876 m_hScrollBar
->Show(false) ;
1879 // because the create does not take into account the client area origin
1880 MacRepositionScrollBars() ; // we might have a real position shift
1883 void wxWindowMac::MacRepositionScrollBars()
1885 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1886 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1888 // get real client area
1890 int width
= m_width
;
1891 int height
= m_height
;
1893 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1894 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1896 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1897 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1898 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1899 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1906 MacClientToRootWindow( &x
, &y
) ;
1907 MacClientToRootWindow( &w
, &h
) ;
1909 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1911 int totW
= 10000 , totH
= 10000;
1914 if ( iter
->IsTopLevel() )
1916 totW
= iter
->m_width
;
1917 totH
= iter
->m_height
;
1921 iter
= iter
->GetParent() ;
1949 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1953 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1957 bool wxWindowMac::AcceptsFocus() const
1959 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1962 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1964 return GetParent()->MacGetContainerForEmbedding() ;
1967 void wxWindowMac::MacSuperChangedPosition()
1969 // only window-absolute structures have to be moved i.e. controls
1971 wxWindowListNode
*node
= GetChildren().GetFirst();
1974 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1975 child
->MacSuperChangedPosition() ;
1976 node
= node
->GetNext();
1980 void wxWindowMac::MacTopLevelWindowChangedPosition()
1982 // only screen-absolute structures have to be moved i.e. glcanvas
1984 wxWindowListNode
*node
= GetChildren().GetFirst();
1987 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1988 child
->MacTopLevelWindowChangedPosition() ;
1989 node
= node
->GetNext();
1992 long wxWindowMac::MacGetLeftBorderSize( ) const
1997 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2000 #if wxMAC_USE_THEME_BORDER
2002 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2007 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2010 #if wxMAC_USE_THEME_BORDER
2012 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2017 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2024 long wxWindowMac::MacGetRightBorderSize( ) const
2026 // they are all symmetric in mac themes
2027 return MacGetLeftBorderSize() ;
2030 long wxWindowMac::MacGetTopBorderSize( ) const
2032 // they are all symmetric in mac themes
2033 return MacGetLeftBorderSize() ;
2036 long wxWindowMac::MacGetBottomBorderSize( ) const
2038 // they are all symmetric in mac themes
2039 return MacGetLeftBorderSize() ;
2042 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2044 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2047 // Find the wxWindowMac at the current mouse position, returning the mouse
2049 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2051 pt
= wxGetMousePosition();
2052 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2056 // Get the current mouse position.
2057 wxPoint
wxGetMousePosition()
2060 wxGetMousePosition(& x
, & y
);
2061 return wxPoint(x
, y
);