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()
138 // deleting a window while it is shown invalidates the region
140 wxWindowMac
* iter
= this ;
142 if ( iter
->IsTopLevel() )
147 iter
= iter
->GetParent() ;
152 m_isBeingDeleted
= TRUE
;
154 #ifndef __WXUNIVERSAL__
155 // VS: make sure there's no wxFrame with last focus set to us:
156 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
158 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
161 if ( frame
->GetLastFocus() == this )
163 frame
->SetLastFocus((wxWindow
*)NULL
);
168 #endif // __WXUNIVERSAL__
170 if ( s_lastMouseWindow
== this )
172 s_lastMouseWindow
= NULL
;
175 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
178 if ( frame
->GetLastFocus() == this )
179 frame
->SetLastFocus( NULL
) ;
182 if ( gFocusWindow
== this )
184 gFocusWindow
= NULL
;
188 m_parent
->RemoveChild(this);
194 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
198 const wxString
& name
)
200 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
203 // wxGTK doesn't allow to create controls with static box as the parent so
204 // this will result in a crash when the program is ported to wxGTK - warn
207 // the correct solution is to create the controls as siblings of the
209 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
210 _T("wxStaticBox can't be used as a window parent!") );
211 #endif // wxUSE_STATBOX
213 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
216 parent
->AddChild(this);
220 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
221 m_width
= WidthDefault( size
.x
);
222 m_height
= HeightDefault( size
.y
) ;
223 #ifndef __WXUNIVERSAL__
224 // Don't give scrollbars to wxControls unless they ask for them
225 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
226 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
228 MacCreateScrollBars( style
) ;
234 void wxWindowMac::SetFocus()
236 if ( gFocusWindow
== this )
239 if ( AcceptsFocus() )
245 if ( gFocusWindow
->m_caret
)
247 gFocusWindow
->m_caret
->OnKillFocus();
249 #endif // wxUSE_CARET
250 #ifndef __WXUNIVERSAL__
251 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
252 if ( control
&& control
->GetMacControl() )
254 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
255 control
->MacRedrawControl() ;
258 // Without testing the window id, for some reason
259 // a kill focus event can still be sent to
260 // the control just being focussed.
261 int thisId
= this->m_windowId
;
262 int gFocusWindowId
= gFocusWindow
->m_windowId
;
263 if (gFocusWindowId
!= thisId
)
265 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
266 event
.SetEventObject(gFocusWindow
);
267 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
270 gFocusWindow
= this ;
276 m_caret
->OnSetFocus();
278 #endif // wxUSE_CARET
279 // panel wants to track the window which was the last to have focus in it
280 wxChildFocusEvent
eventFocus(this);
281 GetEventHandler()->ProcessEvent(eventFocus
);
283 #ifndef __WXUNIVERSAL__
284 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
285 if ( control
&& control
->GetMacControl() )
287 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
290 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
291 event
.SetEventObject(this);
292 GetEventHandler()->ProcessEvent(event
) ;
297 bool wxWindowMac::Enable(bool enable
)
299 if ( !wxWindowBase::Enable(enable
) )
302 MacSuperEnabled( enable
) ;
307 void wxWindowMac::DoCaptureMouse()
309 wxTheApp
->s_captureWindow
= this ;
312 wxWindow
* wxWindowBase::GetCapture()
314 return wxTheApp
->s_captureWindow
;
317 void wxWindowMac::DoReleaseMouse()
319 wxTheApp
->s_captureWindow
= NULL
;
322 #if wxUSE_DRAG_AND_DROP
324 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
326 if ( m_dropTarget
!= 0 ) {
330 m_dropTarget
= pDropTarget
;
331 if ( m_dropTarget
!= 0 )
339 // Old style file-manager drag&drop
340 void wxWindowMac::DragAcceptFiles(bool accept
)
346 void wxWindowMac::DoGetSize(int *x
, int *y
) const
349 if(y
) *y
= m_height
;
352 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
358 if ( !IsTopLevel() && GetParent())
360 wxPoint
pt(GetParent()->GetClientAreaOrigin());
369 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
371 menu
->SetInvokingWindow(this);
373 ClientToScreen( &x
, &y
) ;
375 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
376 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
377 if ( HiWord(menuResult
) != 0 )
380 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
382 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
383 event
.m_timeStamp
= TickCount() ;
384 event
.SetEventObject(this->GetEventHandler());
386 GetEventHandler()->ProcessEvent(event
);
388 ::DeleteMenu( menu
->MacGetMenuId() ) ;
389 menu
->SetInvokingWindow(NULL
);
395 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
397 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
399 Point localwhere
= {0,0} ;
401 if(x
) localwhere
.h
= * x
;
402 if(y
) localwhere
.v
= * y
;
406 ::SetPort( UMAGetWindowPort( window
) ) ;
407 ::GlobalToLocal( &localwhere
) ;
410 if(x
) *x
= localwhere
.h
;
411 if(y
) *y
= localwhere
.v
;
413 MacRootWindowToWindow( x
, y
) ;
415 *x
-= MacGetLeftBorderSize() ;
417 *y
-= MacGetTopBorderSize() ;
420 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
422 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
425 *x
+= MacGetLeftBorderSize() ;
427 *y
+= MacGetTopBorderSize() ;
429 MacWindowToRootWindow( x
, y
) ;
431 Point localwhere
= { 0,0 };
432 if(x
) localwhere
.h
= * x
;
433 if(y
) localwhere
.v
= * y
;
437 ::SetPort( UMAGetWindowPort( window
) ) ;
439 ::LocalToGlobal( &localwhere
) ;
441 if(x
) *x
= localwhere
.h
;
442 if(y
) *y
= localwhere
.v
;
445 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
447 wxPoint origin
= GetClientAreaOrigin() ;
448 if(x
) *x
+= origin
.x
;
449 if(y
) *y
+= origin
.y
;
451 MacWindowToRootWindow( x
, y
) ;
454 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
456 wxPoint origin
= GetClientAreaOrigin() ;
457 MacRootWindowToWindow( x
, y
) ;
458 if(x
) *x
-= origin
.x
;
459 if(y
) *y
-= origin
.y
;
462 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
468 GetParent()->MacWindowToRootWindow( x
, y
) ;
472 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
478 GetParent()->MacRootWindowToWindow( x
, y
) ;
482 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
484 if (m_cursor
== cursor
)
487 if (wxNullCursor
== cursor
)
489 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
494 if ( ! wxWindowBase::SetCursor( cursor
) )
498 wxASSERT_MSG( m_cursor
.Ok(),
499 wxT("cursor must be valid after call to the base version"));
502 wxWindowMac
*mouseWin
;
505 // Change the cursor NOW if we're within the correct window
507 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
509 if ( mouseWin
== this && !wxIsBusy() )
511 m_cursor
.MacInstall() ;
519 // Get size *available for subwindows* i.e. excluding menu bar etc.
520 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
526 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
527 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
529 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
536 MacClientToRootWindow( &x1
, &y1
) ;
537 MacClientToRootWindow( &w
, &h
) ;
539 wxWindowMac
*iter
= (wxWindowMac
*)this ;
541 int totW
= 10000 , totH
= 10000;
544 if ( iter
->IsTopLevel() )
546 totW
= iter
->m_width
;
547 totH
= iter
->m_height
;
551 iter
= iter
->GetParent() ;
554 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
556 hh
-= MAC_SCROLLBAR_SIZE
;
562 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
564 ww
-= MAC_SCROLLBAR_SIZE
;
576 // ----------------------------------------------------------------------------
578 // ----------------------------------------------------------------------------
582 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
584 wxWindowBase::DoSetToolTip(tooltip
);
587 m_tooltip
->SetWindow(this);
590 #endif // wxUSE_TOOLTIPS
592 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
596 int former_w
= m_width
;
597 int former_h
= m_height
;
599 int actualWidth
= width
;
600 int actualHeight
= height
;
604 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
605 actualWidth
= m_minWidth
;
606 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
607 actualHeight
= m_minHeight
;
608 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
609 actualWidth
= m_maxWidth
;
610 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
611 actualHeight
= m_maxHeight
;
613 bool doMove
= false ;
614 bool doResize
= false ;
616 if ( actualX
!= former_x
|| actualY
!= former_y
)
620 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
625 if ( doMove
|| doResize
)
627 // erase former position
629 bool partialRepaint
= false ;
631 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
633 wxPoint
oldPos( m_x
, m_y
) ;
634 wxPoint
newPos( actualX
, actualY
) ;
635 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
636 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
637 if ( oldPos
== newPos
)
639 partialRepaint
= true ;
640 RgnHandle oldRgn
,newRgn
,diffRgn
;
644 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
645 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
646 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
647 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
648 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
649 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
652 DisposeRgn(diffRgn
) ;
656 if ( !partialRepaint
)
661 m_width
= actualWidth
;
662 m_height
= actualHeight
;
664 // update any low-level frame-relative positions
666 MacUpdateDimensions() ;
667 // erase new position
669 if ( !partialRepaint
)
672 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
674 MacRepositionScrollBars() ;
677 wxPoint
point(m_x
, m_y
);
678 wxMoveEvent
event(point
, m_windowId
);
679 event
.SetEventObject(this);
680 GetEventHandler()->ProcessEvent(event
) ;
684 MacRepositionScrollBars() ;
685 wxSize
size(m_width
, m_height
);
686 wxSizeEvent
event(size
, m_windowId
);
687 event
.SetEventObject(this);
688 GetEventHandler()->ProcessEvent(event
);
694 // set the size of the window: if the dimensions are positive, just use them,
695 // but if any of them is equal to -1, it means that we must find the value for
696 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
697 // which case -1 is a valid value for x and y)
699 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
700 // the width/height to best suit our contents, otherwise we reuse the current
702 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
704 // get the current size and position...
705 int currentX
, currentY
;
706 GetPosition(¤tX
, ¤tY
);
708 int currentW
,currentH
;
709 GetSize(¤tW
, ¤tH
);
711 // ... and don't do anything (avoiding flicker) if it's already ok
712 if ( x
== currentX
&& y
== currentY
&&
713 width
== currentW
&& height
== currentH
)
715 MacRepositionScrollBars() ; // we might have a real position shift
719 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
721 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
724 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
729 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
731 size
= DoGetBestSize();
736 // just take the current one
743 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
747 size
= DoGetBestSize();
749 //else: already called DoGetBestSize() above
755 // just take the current one
760 DoMoveWindow(x
, y
, width
, height
);
763 // For implementation purposes - sometimes decorations make the client area
766 wxPoint
wxWindowMac::GetClientAreaOrigin() const
768 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
771 void wxWindowMac::SetTitle(const wxString
& title
)
776 wxString
wxWindowMac::GetTitle() const
781 bool wxWindowMac::Show(bool show
)
783 if ( !wxWindowBase::Show(show
) )
787 WindowRef window = (WindowRef) MacGetRootWindow() ;
788 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
789 if ( win == NULL && win->m_isBeingDeleted )
792 MacSuperShown( show
) ;
797 if ( win && !win->m_isBeingDeleted )
808 void wxWindowMac::MacSuperShown( bool show
)
810 wxWindowListNode
*node
= GetChildren().GetFirst();
813 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
814 if ( child
->m_isShown
)
815 child
->MacSuperShown( show
) ;
816 node
= node
->GetNext();
820 void wxWindowMac::MacSuperEnabled( bool enabled
)
824 // to be absolutely correct we'd have to invalidate (with eraseBkground
825 // because unter MacOSX the frames are drawn with an addXXX mode)
828 wxWindowListNode
*node
= GetChildren().GetFirst();
831 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
832 if ( child
->m_isShown
)
833 child
->MacSuperEnabled( enabled
) ;
834 node
= node
->GetNext();
838 bool wxWindowMac::MacIsReallyShown() const
840 if ( m_isShown
&& (m_parent
!= NULL
) ) {
841 return m_parent
->MacIsReallyShown();
845 bool status = m_isShown ;
846 wxWindowMac * win = this ;
847 while ( status && win->m_parent != NULL )
849 win = win->m_parent ;
850 status = win->m_isShown ;
856 int wxWindowMac::GetCharHeight() const
858 wxClientDC
dc ( (wxWindowMac
*)this ) ;
859 return dc
.GetCharHeight() ;
862 int wxWindowMac::GetCharWidth() const
864 wxClientDC
dc ( (wxWindowMac
*)this ) ;
865 return dc
.GetCharWidth() ;
868 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
869 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
871 const wxFont
*fontToUse
= theFont
;
875 wxClientDC
dc( (wxWindowMac
*) this ) ;
877 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
878 if ( externalLeading
)
879 *externalLeading
= le
;
889 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
890 * we always intersect with the entire window, not only with the client area
893 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
895 if ( MacGetTopLevelWindow() == NULL
)
898 wxPoint client
= GetClientAreaOrigin();
901 int x2
= m_width
- client
.x
;
902 int y2
= m_height
- client
.y
;
904 if (IsKindOf( CLASSINFO(wxButton
)))
906 // buttons have an "aura"
913 Rect clientrect
= { y1
, x1
, y2
, x2
};
917 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
918 SectRect( &clientrect
, &r
, &clientrect
) ;
921 if ( !EmptyRect( &clientrect
) )
923 int top
= 0 , left
= 0 ;
925 MacClientToRootWindow( &left
, &top
) ;
926 OffsetRect( &clientrect
, left
, top
) ;
928 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
932 #if wxUSE_CARET && WXWIN_COMPATIBILITY
933 // ---------------------------------------------------------------------------
934 // Caret manipulation
935 // ---------------------------------------------------------------------------
937 void wxWindowMac::CreateCaret(int w
, int h
)
939 SetCaret(new wxCaret(this, w
, h
));
942 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
944 wxFAIL_MSG("not implemented");
947 void wxWindowMac::ShowCaret(bool show
)
949 wxCHECK_RET( m_caret
, "no caret to show" );
954 void wxWindowMac::DestroyCaret()
959 void wxWindowMac::SetCaretPos(int x
, int y
)
961 wxCHECK_RET( m_caret
, "no caret to move" );
966 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
968 wxCHECK_RET( m_caret
, "no caret to get position of" );
970 m_caret
->GetPosition(x
, y
);
972 #endif // wxUSE_CARET
974 wxWindowMac
*wxGetActiveWindow()
976 // actually this is a windows-only concept
980 // Coordinates relative to the window
981 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
983 // We really dont move the mouse programmatically under mac
986 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
988 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
990 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
992 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
994 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
995 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
996 // either a non gray background color or a non control window
998 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1000 wxWindowMac
* parent
= GetParent() ;
1003 if ( parent
->MacGetRootWindow() != window
)
1005 // we are in a different window on the mac system
1011 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1012 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1014 // if we have any other colours in the hierarchy
1015 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1018 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1019 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1021 Rect extent
= { 0 , 0 , 0 , 0 } ;
1024 wxSize size
= parent
->GetSize() ;
1025 parent
->MacClientToRootWindow( &x
, &y
) ;
1029 extent
.right
= x
+ size
.x
;
1030 extent
.bottom
= y
+ size
.y
;
1031 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1035 parent
= parent
->GetParent() ;
1039 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1044 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1047 return m_macBackgroundBrush
;
1051 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1053 event
.GetDC()->Clear() ;
1056 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1058 wxWindowDC
dc(this) ;
1059 wxMacPortSetter
helper(&dc
) ;
1061 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1064 int wxWindowMac::GetScrollPos(int orient
) const
1066 if ( orient
== wxHORIZONTAL
)
1069 return m_hScrollBar
->GetThumbPosition() ;
1074 return m_vScrollBar
->GetThumbPosition() ;
1079 // This now returns the whole range, not just the number
1080 // of positions that we can scroll.
1081 int wxWindowMac::GetScrollRange(int orient
) const
1083 if ( orient
== wxHORIZONTAL
)
1086 return m_hScrollBar
->GetRange() ;
1091 return m_vScrollBar
->GetRange() ;
1096 int wxWindowMac::GetScrollThumb(int orient
) const
1098 if ( orient
== wxHORIZONTAL
)
1101 return m_hScrollBar
->GetThumbSize() ;
1106 return m_vScrollBar
->GetThumbSize() ;
1111 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1113 if ( orient
== wxHORIZONTAL
)
1116 m_hScrollBar
->SetThumbPosition( pos
) ;
1121 m_vScrollBar
->SetThumbPosition( pos
) ;
1125 void wxWindowMac::MacPaintBorders( int left
, int top
)
1130 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1131 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1132 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1133 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1136 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1138 #if wxMAC_USE_THEME_BORDER
1139 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1142 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1143 InsetRect( &rect , border , border );
1144 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1147 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1149 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1150 RGBForeColor( &face
);
1151 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1152 LineTo( left
+ 0 , top
+ 0 );
1153 LineTo( left
+ m_width
- 2 , top
+ 0 );
1155 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1156 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1157 LineTo( left
+ m_width
- 3 , top
+ 2 );
1159 RGBForeColor( sunken
? &face
: &black
);
1160 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1161 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1162 LineTo( left
+ m_width
- 1 , top
+ 0 );
1164 RGBForeColor( sunken
? &shadow
: &white
);
1165 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1166 LineTo( left
+ 1, top
+ 1 );
1167 LineTo( left
+ m_width
- 3 , top
+ 1 );
1169 RGBForeColor( sunken
? &white
: &shadow
);
1170 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1171 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1172 LineTo( left
+ m_width
- 2 , top
+ 1 );
1174 RGBForeColor( sunken
? &black
: &face
);
1175 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1176 LineTo( left
+ 2 , top
+ 2 );
1177 LineTo( left
+ m_width
- 4 , top
+ 2 );
1180 else if (HasFlag(wxSIMPLE_BORDER
))
1182 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1183 RGBForeColor( &black
) ;
1184 FrameRect( &rect
) ;
1188 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1190 if ( child
== m_hScrollBar
)
1191 m_hScrollBar
= NULL
;
1192 if ( child
== m_vScrollBar
)
1193 m_vScrollBar
= NULL
;
1195 wxWindowBase::RemoveChild( child
) ;
1198 // New function that will replace some of the above.
1199 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1200 int range
, bool refresh
)
1202 if ( orient
== wxHORIZONTAL
)
1206 if ( range
== 0 || thumbVisible
>= range
)
1208 if ( m_hScrollBar
->IsShown() )
1209 m_hScrollBar
->Show(false) ;
1213 if ( !m_hScrollBar
->IsShown() )
1214 m_hScrollBar
->Show(true) ;
1215 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1223 if ( range
== 0 || thumbVisible
>= range
)
1225 if ( m_vScrollBar
->IsShown() )
1226 m_vScrollBar
->Show(false) ;
1230 if ( !m_vScrollBar
->IsShown() )
1231 m_vScrollBar
->Show(true) ;
1232 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1236 MacRepositionScrollBars() ;
1239 // Does a physical scroll
1240 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1242 wxClientDC
dc(this) ;
1243 wxMacPortSetter
helper(&dc
) ;
1246 int width
, height
;
1247 GetClientSize( &width
, &height
) ;
1249 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1250 RgnHandle updateRgn
= NewRgn() ;
1251 ClipRect( &scrollrect
) ;
1254 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1255 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1256 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1258 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1259 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1260 DisposeRgn( updateRgn
) ;
1263 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1265 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1266 if (child
== m_vScrollBar
) continue;
1267 if (child
== m_hScrollBar
) continue;
1268 if (child
->IsTopLevel()) continue;
1271 child
->GetPosition( &x
, &y
);
1273 child
->GetSize( &w
, &h
);
1274 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1279 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1281 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1283 wxScrollWinEvent wevent
;
1284 wevent
.SetPosition(event
.GetPosition());
1285 wevent
.SetOrientation(event
.GetOrientation());
1286 wevent
.m_eventObject
= this;
1288 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1289 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1291 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1292 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1294 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1295 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1297 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1298 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1300 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1301 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1303 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1304 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1306 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1307 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1310 GetEventHandler()->ProcessEvent(wevent
);
1314 // Get the window with the focus
1315 wxWindowMac
*wxWindowBase::FindFocus()
1317 return gFocusWindow
;
1320 #if WXWIN_COMPATIBILITY
1321 // If nothing defined for this, try the parent.
1322 // E.g. we may be a button loaded from a resource, with no callback function
1324 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1326 if ( GetEventHandler()->ProcessEvent(event
) )
1329 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1331 #endif // WXWIN_COMPATIBILITY_2
1333 #if WXWIN_COMPATIBILITY
1334 wxObject
* wxWindowMac::GetChild(int number
) const
1336 // Return a pointer to the Nth object in the Panel
1337 wxNode
*node
= GetChildren().GetFirst();
1340 node
= node
->GetNext();
1343 wxObject
*obj
= (wxObject
*)node
->GetData();
1349 #endif // WXWIN_COMPATIBILITY
1351 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1353 // panel wants to track the window which was the last to have focus in it,
1354 // so we want to set ourselves as the window which last had focus
1356 // notice that it's also important to do it upwards the tree becaus
1357 // otherwise when the top level panel gets focus, it won't set it back to
1358 // us, but to some other sibling
1360 // CS:don't know if this is still needed:
1361 //wxChildFocusEvent eventFocus(this);
1362 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1367 void wxWindowMac::Clear()
1369 wxClientDC
dc(this);
1370 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1371 dc
.SetBackground(brush
);
1375 // Setup background and foreground colours correctly
1376 void wxWindowMac::SetupColours()
1379 SetBackgroundColour(GetParent()->GetBackgroundColour());
1382 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1385 // Check if we need to send a LEAVE event
1386 if (m_mouseInWindow)
1389 ::GetCursorPos(&pt);
1390 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1392 // Generate a LEAVE event
1393 m_mouseInWindow = FALSE;
1394 MSWOnMouseLeave(pt.x, pt.y, 0);
1399 // This calls the UI-update mechanism (querying windows for
1400 // menu/toolbar/control state information)
1404 // Raise the window to the top of the Z order
1405 void wxWindowMac::Raise()
1409 // Lower the window to the bottom of the Z order
1410 void wxWindowMac::Lower()
1414 void wxWindowMac::DoSetClientSize(int width
, int height
)
1416 if ( width
!= -1 || height
!= -1 )
1419 if ( width
!= -1 && m_vScrollBar
)
1420 width
+= MAC_SCROLLBAR_SIZE
;
1421 if ( height
!= -1 && m_vScrollBar
)
1422 height
+= MAC_SCROLLBAR_SIZE
;
1424 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1425 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1427 DoSetSize( -1 , -1 , width
, height
) ;
1432 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1434 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1438 if ((point
.x
< 0) || (point
.y
< 0) ||
1439 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1444 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1445 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1449 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1451 wxPoint
newPoint( point
) ;
1453 if ( !IsTopLevel() )
1459 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1461 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1462 // added the m_isShown test --dmazzoni
1463 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1465 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1474 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1478 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1479 if ( ::FindWindow( pt
, &window
) == 3 )
1482 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1485 // No, this yields the CLIENT are, we need the whole frame. RR.
1486 // point = win->ScreenToClient( point ) ;
1489 ::GetPort( &port
) ;
1490 ::SetPort( UMAGetWindowPort( window
) ) ;
1491 ::GlobalToLocal( &pt
) ;
1494 wxPoint
point( pt
.h
, pt
.v
) ;
1496 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1502 static wxWindow
*gs_lastWhich
= NULL
;
1504 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1506 // first trigger a set cursor event
1508 wxPoint clientorigin
= GetClientAreaOrigin() ;
1509 wxSize clientsize
= GetClientSize() ;
1511 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1513 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1515 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1516 if ( processedEvtSetCursor
&& event
.HasCursor() )
1518 cursor
= event
.GetCursor() ;
1523 // the test for processedEvtSetCursor is here to prevent using m_cursor
1524 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1525 // it - this is a way to say that our cursor shouldn't be used for this
1527 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1537 cursor
= *wxSTANDARD_CURSOR
;
1541 cursor
.MacInstall() ;
1543 return cursor
.Ok() ;
1546 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1548 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1549 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1553 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1556 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1564 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1566 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1567 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1569 if (child
->MacDispatchMouseEvent(event
))
1574 wxWindow
* cursorTarget
= this ;
1575 wxPoint
cursorPoint( x
, y
) ;
1577 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1579 cursorTarget
= cursorTarget
->GetParent() ;
1581 cursorPoint
+= cursorTarget
->GetPosition() ;
1585 event
.SetEventObject( this ) ;
1587 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1589 // set focus to this window
1590 if (AcceptsFocus() && FindFocus()!=this)
1595 if ( event
.GetEventType() == wxEVT_MOTION
1596 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1597 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1598 wxToolTip::RelayEvent( this , event
);
1599 #endif // wxUSE_TOOLTIPS
1601 if (gs_lastWhich
!= this)
1603 gs_lastWhich
= this;
1605 // Double clicks must always occur on the same window
1606 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1607 event
.SetEventType( wxEVT_LEFT_DOWN
);
1608 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1609 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1611 // Same for mouse up events
1612 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1614 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1618 GetEventHandler()->ProcessEvent( event
) ;
1623 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1627 return m_tooltip
->GetTip() ;
1632 void wxWindowMac::Update()
1634 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1637 win
->MacUpdate( 0 ) ;
1638 #if TARGET_API_MAC_CARBON
1639 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1641 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1647 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1649 wxTopLevelWindowMac
* win
= NULL
;
1650 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1653 win
= wxFindWinFromMacWindow( window
) ;
1658 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1660 RgnHandle visRgn
= NewRgn() ;
1661 RgnHandle tempRgn
= NewRgn() ;
1662 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1664 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1666 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1667 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1669 int borderTop
= 14 ;
1670 int borderOther
= 4 ;
1672 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1673 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1676 if ( !IsTopLevel() )
1678 wxWindow
* parent
= GetParent() ;
1681 wxSize size
= parent
->GetSize() ;
1684 parent
->MacWindowToRootWindow( &x
, &y
) ;
1685 MacRootWindowToWindow( &x
, &y
) ;
1687 SetRectRgn( tempRgn
,
1688 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1689 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1690 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1692 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1693 if ( parent
->IsTopLevel() )
1695 parent
= parent
->GetParent() ;
1698 if ( respectChildrenAndSiblings
)
1700 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1702 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1704 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1706 if ( !child
->IsTopLevel() && child
->IsShown() )
1708 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1709 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1711 int borderTop
= 14 ;
1712 int borderOther
= 4 ;
1714 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1715 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1717 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1722 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1724 bool thisWindowThrough
= false ;
1725 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1727 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1728 if ( sibling
== this )
1730 thisWindowThrough
= true ;
1733 if( !thisWindowThrough
)
1738 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1740 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
) ;
1741 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1743 int borderTop
= 14 ;
1744 int borderOther
= 4 ;
1746 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
) ;
1747 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1749 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1754 m_macVisibleRegion
= visRgn
;
1755 DisposeRgn( visRgn
) ;
1756 DisposeRgn( tempRgn
) ;
1757 DisposeRgn( tempStaticBoxRgn
) ;
1758 return m_macVisibleRegion
;
1761 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1763 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1764 // updatergn is always already clipped to our boundaries
1765 // it is in window coordinates, not in client coordinates
1767 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1770 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1771 RgnHandle ownUpdateRgn
= NewRgn() ;
1772 CopyRgn( updatergn
, ownUpdateRgn
) ;
1774 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1776 // newupdate is the update region in client coordinates
1777 RgnHandle newupdate
= NewRgn() ;
1778 wxSize point
= GetClientSize() ;
1779 wxPoint origin
= GetClientAreaOrigin() ;
1780 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1781 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1782 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1783 m_updateRegion
= newupdate
;
1784 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1786 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1788 wxWindowDC
dc(this);
1789 if (!EmptyRgn(ownUpdateRgn
))
1790 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1791 wxEraseEvent
eevent( GetId(), &dc
);
1792 eevent
.SetEventObject( this );
1793 GetEventHandler()->ProcessEvent( eevent
);
1795 wxNcPaintEvent
eventNc( GetId() );
1796 eventNc
.SetEventObject( this );
1797 GetEventHandler()->ProcessEvent( eventNc
);
1799 DisposeRgn( ownUpdateRgn
) ;
1800 if ( !m_updateRegion
.Empty() )
1803 event
.m_timeStamp
= time
;
1804 event
.SetEventObject(this);
1805 GetEventHandler()->ProcessEvent(event
);
1809 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1811 RgnHandle childupdate
= NewRgn() ;
1812 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1814 // calculate the update region for the child windows by intersecting the window rectangle with our own
1815 // passed in update region and then offset it to be client-wise window coordinates again
1816 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1817 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1818 SectRgn( childupdate
, updatergn
, childupdate
) ;
1819 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1820 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1822 // because dialogs may also be children
1823 child
->MacRedraw( childupdate
, time
, erase
) ;
1826 DisposeRgn( childupdate
) ;
1827 // eventually a draw grow box here
1831 WXHWND
wxWindowMac::MacGetRootWindow() const
1833 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1837 if ( iter
->IsTopLevel() )
1838 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1840 iter
= iter
->GetParent() ;
1842 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1846 void wxWindowMac::MacCreateScrollBars( long style
)
1848 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1850 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1851 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1853 GetClientSize( &width
, &height
) ;
1855 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1856 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1857 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1858 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1860 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1861 vSize
, wxVERTICAL
);
1863 if ( style
& wxVSCROLL
)
1869 m_vScrollBar
->Show(false) ;
1871 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1872 hSize
, wxHORIZONTAL
);
1873 if ( style
& wxHSCROLL
)
1878 m_hScrollBar
->Show(false) ;
1881 // because the create does not take into account the client area origin
1882 MacRepositionScrollBars() ; // we might have a real position shift
1885 void wxWindowMac::MacRepositionScrollBars()
1887 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1888 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1890 // get real client area
1892 int width
= m_width
;
1893 int height
= m_height
;
1895 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1896 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1898 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1899 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1900 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1901 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1908 MacClientToRootWindow( &x
, &y
) ;
1909 MacClientToRootWindow( &w
, &h
) ;
1911 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1913 int totW
= 10000 , totH
= 10000;
1916 if ( iter
->IsTopLevel() )
1918 totW
= iter
->m_width
;
1919 totH
= iter
->m_height
;
1923 iter
= iter
->GetParent() ;
1951 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1955 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1959 bool wxWindowMac::AcceptsFocus() const
1961 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1964 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1966 return GetParent()->MacGetContainerForEmbedding() ;
1969 void wxWindowMac::MacSuperChangedPosition()
1971 // only window-absolute structures have to be moved i.e. controls
1973 wxWindowListNode
*node
= GetChildren().GetFirst();
1976 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1977 child
->MacSuperChangedPosition() ;
1978 node
= node
->GetNext();
1982 void wxWindowMac::MacTopLevelWindowChangedPosition()
1984 // only screen-absolute structures have to be moved i.e. glcanvas
1986 wxWindowListNode
*node
= GetChildren().GetFirst();
1989 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1990 child
->MacTopLevelWindowChangedPosition() ;
1991 node
= node
->GetNext();
1994 long wxWindowMac::MacGetLeftBorderSize( ) const
1999 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2002 #if wxMAC_USE_THEME_BORDER
2004 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2009 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2012 #if wxMAC_USE_THEME_BORDER
2014 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2019 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2026 long wxWindowMac::MacGetRightBorderSize( ) const
2028 // they are all symmetric in mac themes
2029 return MacGetLeftBorderSize() ;
2032 long wxWindowMac::MacGetTopBorderSize( ) const
2034 // they are all symmetric in mac themes
2035 return MacGetLeftBorderSize() ;
2038 long wxWindowMac::MacGetBottomBorderSize( ) const
2040 // they are all symmetric in mac themes
2041 return MacGetLeftBorderSize() ;
2044 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2046 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2049 // Find the wxWindowMac at the current mouse position, returning the mouse
2051 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2053 pt
= wxGetMousePosition();
2054 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2058 // Get the current mouse position.
2059 wxPoint
wxGetMousePosition()
2062 wxGetMousePosition(& x
, & y
);
2063 return wxPoint(x
, y
);