1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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
)
80 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
90 #define wxMAC_USE_THEME_BORDER 0
93 // ===========================================================================
95 // ===========================================================================
98 // ----------------------------------------------------------------------------
99 // constructors and such
100 // ----------------------------------------------------------------------------
102 void wxWindowMac::Init()
107 m_backgroundTransparent
= FALSE
;
109 // as all windows are created with WS_VISIBLE style...
117 m_hScrollBar
= NULL
;
118 m_vScrollBar
= NULL
;
120 m_label
= wxEmptyString
;
124 wxWindowMac::~wxWindowMac()
128 // deleting a window while it is shown invalidates the region
130 wxWindowMac
* iter
= this ;
132 if ( iter
->IsTopLevel() )
137 iter
= iter
->GetParent() ;
142 #ifndef __WXUNIVERSAL__
143 // VS: make sure there's no wxFrame with last focus set to us:
144 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
146 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
149 if ( frame
->GetLastFocus() == this )
151 frame
->SetLastFocus((wxWindow
*)NULL
);
156 #endif // __WXUNIVERSAL__
158 if ( s_lastMouseWindow
== this )
160 s_lastMouseWindow
= NULL
;
163 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
166 if ( frame
->GetLastFocus() == this )
167 frame
->SetLastFocus( NULL
) ;
170 if ( gFocusWindow
== this )
172 gFocusWindow
= NULL
;
175 // CS: copied from MSW :
176 // VS: destroy children first and _then_ detach *this from its parent.
177 // If we'd do it the other way around, children wouldn't be able
178 // find their parent frame (see above).
182 m_parent
->RemoveChild(this);
184 // delete our drop target if we've got one
185 #if wxUSE_DRAG_AND_DROP
186 if ( m_dropTarget
!= NULL
)
191 #endif // wxUSE_DRAG_AND_DROP
195 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
199 const wxString
& name
)
201 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
204 // wxGTK doesn't allow to create controls with static box as the parent so
205 // this will result in a crash when the program is ported to wxGTK - warn
208 // the correct solution is to create the controls as siblings of the
210 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
211 _T("wxStaticBox can't be used as a window parent!") );
212 #endif // wxUSE_STATBOX
214 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
217 parent
->AddChild(this);
221 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
222 m_width
= WidthDefault( size
.x
);
223 m_height
= HeightDefault( size
.y
) ;
224 #ifndef __WXUNIVERSAL__
225 // Don't give scrollbars to wxControls unless they ask for them
226 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
227 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
229 MacCreateScrollBars( style
) ;
235 void wxWindowMac::SetFocus()
237 if ( gFocusWindow
== this )
240 if ( AcceptsFocus() )
246 if ( gFocusWindow
->m_caret
)
248 gFocusWindow
->m_caret
->OnKillFocus();
250 #endif // wxUSE_CARET
251 #ifndef __WXUNIVERSAL__
252 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
253 if ( control
&& control
->GetMacControl() )
255 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
256 control
->MacRedrawControl() ;
259 // Without testing the window id, for some reason
260 // a kill focus event can still be sent to
261 // the control just being focussed.
262 int thisId
= this->m_windowId
;
263 int gFocusWindowId
= gFocusWindow
->m_windowId
;
264 if (gFocusWindowId
!= thisId
)
266 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
267 event
.SetEventObject(gFocusWindow
);
268 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
271 gFocusWindow
= this ;
277 m_caret
->OnSetFocus();
279 #endif // wxUSE_CARET
280 // panel wants to track the window which was the last to have focus in it
281 wxChildFocusEvent
eventFocus(this);
282 GetEventHandler()->ProcessEvent(eventFocus
);
284 #ifndef __WXUNIVERSAL__
285 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
286 if ( control
&& control
->GetMacControl() )
288 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
291 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
292 event
.SetEventObject(this);
293 GetEventHandler()->ProcessEvent(event
) ;
298 bool wxWindowMac::Enable(bool enable
)
300 if ( !wxWindowBase::Enable(enable
) )
303 MacSuperEnabled( enable
) ;
308 void wxWindowMac::DoCaptureMouse()
310 wxTheApp
->s_captureWindow
= this ;
313 wxWindow
* wxWindowBase::GetCapture()
315 return wxTheApp
->s_captureWindow
;
318 void wxWindowMac::DoReleaseMouse()
320 wxTheApp
->s_captureWindow
= NULL
;
323 #if wxUSE_DRAG_AND_DROP
325 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
327 if ( m_dropTarget
!= 0 ) {
331 m_dropTarget
= pDropTarget
;
332 if ( m_dropTarget
!= 0 )
340 // Old style file-manager drag&drop
341 void wxWindowMac::DragAcceptFiles(bool accept
)
347 void wxWindowMac::DoGetSize(int *x
, int *y
) const
350 if(y
) *y
= m_height
;
353 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
359 if ( !IsTopLevel() && GetParent())
361 wxPoint
pt(GetParent()->GetClientAreaOrigin());
370 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
372 menu
->SetInvokingWindow(this);
374 ClientToScreen( &x
, &y
) ;
376 menu
->MacBeforeDisplay( true ) ;
377 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
378 if ( HiWord(menuResult
) != 0 )
381 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
382 wxMenuItem
* item
= NULL
;
384 item
= menu
->FindItem(id
, &realmenu
) ;
385 if (item
->IsCheckable())
387 item
->Check( !item
->IsChecked() ) ;
389 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
391 menu
->MacAfterDisplay( true ) ;
393 menu
->SetInvokingWindow(NULL
);
399 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
401 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
403 Point localwhere
= {0,0} ;
405 if(x
) localwhere
.h
= * x
;
406 if(y
) localwhere
.v
= * y
;
410 ::SetPort( UMAGetWindowPort( window
) ) ;
411 ::GlobalToLocal( &localwhere
) ;
414 if(x
) *x
= localwhere
.h
;
415 if(y
) *y
= localwhere
.v
;
417 MacRootWindowToWindow( x
, y
) ;
419 *x
-= MacGetLeftBorderSize() ;
421 *y
-= MacGetTopBorderSize() ;
424 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
426 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
429 *x
+= MacGetLeftBorderSize() ;
431 *y
+= MacGetTopBorderSize() ;
433 MacWindowToRootWindow( x
, y
) ;
435 Point localwhere
= { 0,0 };
436 if(x
) localwhere
.h
= * x
;
437 if(y
) localwhere
.v
= * y
;
441 ::SetPort( UMAGetWindowPort( window
) ) ;
443 ::LocalToGlobal( &localwhere
) ;
445 if(x
) *x
= localwhere
.h
;
446 if(y
) *y
= localwhere
.v
;
449 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
451 wxPoint origin
= GetClientAreaOrigin() ;
452 if(x
) *x
+= origin
.x
;
453 if(y
) *y
+= origin
.y
;
455 MacWindowToRootWindow( x
, y
) ;
458 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
460 wxPoint origin
= GetClientAreaOrigin() ;
461 MacRootWindowToWindow( x
, y
) ;
462 if(x
) *x
-= origin
.x
;
463 if(y
) *y
-= origin
.y
;
466 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
472 GetParent()->MacWindowToRootWindow( x
, y
) ;
476 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
482 GetParent()->MacRootWindowToWindow( x
, y
) ;
486 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
488 if (m_cursor
== cursor
)
491 if (wxNullCursor
== cursor
)
493 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
498 if ( ! wxWindowBase::SetCursor( cursor
) )
502 wxASSERT_MSG( m_cursor
.Ok(),
503 wxT("cursor must be valid after call to the base version"));
506 wxWindowMac
*mouseWin
;
509 // Change the cursor NOW if we're within the correct window
511 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
513 if ( mouseWin
== this && !wxIsBusy() )
515 m_cursor
.MacInstall() ;
523 // Get size *available for subwindows* i.e. excluding menu bar etc.
524 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
530 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
531 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
533 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
540 MacClientToRootWindow( &x1
, &y1
) ;
541 MacClientToRootWindow( &w
, &h
) ;
543 wxWindowMac
*iter
= (wxWindowMac
*)this ;
545 int totW
= 10000 , totH
= 10000;
548 if ( iter
->IsTopLevel() )
550 totW
= iter
->m_width
;
551 totH
= iter
->m_height
;
555 iter
= iter
->GetParent() ;
558 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
560 hh
-= MAC_SCROLLBAR_SIZE
;
566 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
568 ww
-= MAC_SCROLLBAR_SIZE
;
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
586 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
588 wxWindowBase::DoSetToolTip(tooltip
);
591 m_tooltip
->SetWindow(this);
594 #endif // wxUSE_TOOLTIPS
596 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
600 int former_w
= m_width
;
601 int former_h
= m_height
;
603 int actualWidth
= width
;
604 int actualHeight
= height
;
608 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
609 actualWidth
= m_minWidth
;
610 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
611 actualHeight
= m_minHeight
;
612 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
613 actualWidth
= m_maxWidth
;
614 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
615 actualHeight
= m_maxHeight
;
617 bool doMove
= false ;
618 bool doResize
= false ;
620 if ( actualX
!= former_x
|| actualY
!= former_y
)
624 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
629 if ( doMove
|| doResize
)
631 // erase former position
633 bool partialRepaint
= false ;
635 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
637 wxPoint
oldPos( m_x
, m_y
) ;
638 wxPoint
newPos( actualX
, actualY
) ;
639 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
640 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
641 if ( oldPos
== newPos
)
643 partialRepaint
= true ;
644 RgnHandle oldRgn
,newRgn
,diffRgn
;
648 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
649 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
650 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
651 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
652 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
653 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
656 DisposeRgn(diffRgn
) ;
660 if ( !partialRepaint
)
665 m_width
= actualWidth
;
666 m_height
= actualHeight
;
668 // update any low-level frame-relative positions
670 MacUpdateDimensions() ;
671 // erase new position
673 if ( !partialRepaint
)
676 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
678 MacRepositionScrollBars() ;
681 wxPoint
point(m_x
, m_y
);
682 wxMoveEvent
event(point
, m_windowId
);
683 event
.SetEventObject(this);
684 GetEventHandler()->ProcessEvent(event
) ;
688 MacRepositionScrollBars() ;
689 wxSize
size(m_width
, m_height
);
690 wxSizeEvent
event(size
, m_windowId
);
691 event
.SetEventObject(this);
692 GetEventHandler()->ProcessEvent(event
);
698 // set the size of the window: if the dimensions are positive, just use them,
699 // but if any of them is equal to -1, it means that we must find the value for
700 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
701 // which case -1 is a valid value for x and y)
703 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
704 // the width/height to best suit our contents, otherwise we reuse the current
706 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
708 // get the current size and position...
709 int currentX
, currentY
;
710 GetPosition(¤tX
, ¤tY
);
712 int currentW
,currentH
;
713 GetSize(¤tW
, ¤tH
);
715 // ... and don't do anything (avoiding flicker) if it's already ok
716 if ( x
== currentX
&& y
== currentY
&&
717 width
== currentW
&& height
== currentH
)
719 MacRepositionScrollBars() ; // we might have a real position shift
723 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
725 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
728 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
733 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
735 size
= DoGetBestSize();
740 // just take the current one
747 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
751 size
= DoGetBestSize();
753 //else: already called DoGetBestSize() above
759 // just take the current one
764 DoMoveWindow(x
, y
, width
, height
);
767 // For implementation purposes - sometimes decorations make the client area
770 wxPoint
wxWindowMac::GetClientAreaOrigin() const
772 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
775 void wxWindowMac::SetTitle(const wxString
& title
)
780 wxString
wxWindowMac::GetTitle() const
785 bool wxWindowMac::Show(bool show
)
787 if ( !wxWindowBase::Show(show
) )
790 MacSuperShown( show
) ;
796 void wxWindowMac::MacSuperShown( bool show
)
798 wxWindowListNode
*node
= GetChildren().GetFirst();
801 wxWindowMac
*child
= node
->GetData();
802 if ( child
->m_isShown
)
803 child
->MacSuperShown( show
) ;
804 node
= node
->GetNext();
808 void wxWindowMac::MacSuperEnabled( bool enabled
)
812 // to be absolutely correct we'd have to invalidate (with eraseBkground
813 // because unter MacOSX the frames are drawn with an addXXX mode)
816 wxWindowListNode
*node
= GetChildren().GetFirst();
819 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
820 if ( child
->m_isShown
)
821 child
->MacSuperEnabled( enabled
) ;
822 node
= node
->GetNext();
826 bool wxWindowMac::MacIsReallyShown() const
828 if ( m_isShown
&& (m_parent
!= NULL
) ) {
829 return m_parent
->MacIsReallyShown();
833 bool status = m_isShown ;
834 wxWindowMac * win = this ;
835 while ( status && win->m_parent != NULL )
837 win = win->m_parent ;
838 status = win->m_isShown ;
844 int wxWindowMac::GetCharHeight() const
846 wxClientDC
dc ( (wxWindowMac
*)this ) ;
847 return dc
.GetCharHeight() ;
850 int wxWindowMac::GetCharWidth() const
852 wxClientDC
dc ( (wxWindowMac
*)this ) ;
853 return dc
.GetCharWidth() ;
856 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
857 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
859 const wxFont
*fontToUse
= theFont
;
863 wxClientDC
dc( (wxWindowMac
*) this ) ;
865 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
866 if ( externalLeading
)
867 *externalLeading
= le
;
877 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
878 * we always intersect with the entire window, not only with the client area
881 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
883 if ( MacGetTopLevelWindow() == NULL
)
886 wxPoint client
= GetClientAreaOrigin();
889 int x2
= m_width
- client
.x
;
890 int y2
= m_height
- client
.y
;
892 if (IsKindOf( CLASSINFO(wxButton
)))
894 // buttons have an "aura"
901 Rect clientrect
= { y1
, x1
, y2
, x2
};
905 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
906 SectRect( &clientrect
, &r
, &clientrect
) ;
909 if ( !EmptyRect( &clientrect
) )
911 int top
= 0 , left
= 0 ;
913 MacClientToRootWindow( &left
, &top
) ;
914 OffsetRect( &clientrect
, left
, top
) ;
916 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
920 #if wxUSE_CARET && WXWIN_COMPATIBILITY
921 // ---------------------------------------------------------------------------
922 // Caret manipulation
923 // ---------------------------------------------------------------------------
925 void wxWindowMac::CreateCaret(int w
, int h
)
927 SetCaret(new wxCaret(this, w
, h
));
930 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
932 wxFAIL_MSG("not implemented");
935 void wxWindowMac::ShowCaret(bool show
)
937 wxCHECK_RET( m_caret
, "no caret to show" );
942 void wxWindowMac::DestroyCaret()
947 void wxWindowMac::SetCaretPos(int x
, int y
)
949 wxCHECK_RET( m_caret
, "no caret to move" );
954 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
956 wxCHECK_RET( m_caret
, "no caret to get position of" );
958 m_caret
->GetPosition(x
, y
);
960 #endif // wxUSE_CARET
962 wxWindowMac
*wxGetActiveWindow()
964 // actually this is a windows-only concept
968 // Coordinates relative to the window
969 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
971 // We really don't move the mouse programmatically under Mac.
974 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
976 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
978 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
980 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
982 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
983 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
984 // either a non gray background color or a non control window
986 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
988 wxWindowMac
* parent
= GetParent() ;
991 if ( parent
->MacGetRootWindow() != window
)
993 // we are in a different window on the mac system
999 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1000 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1002 // if we have any other colours in the hierarchy
1003 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1006 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1007 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1009 Rect extent
= { 0 , 0 , 0 , 0 } ;
1012 wxSize size
= parent
->GetSize() ;
1013 parent
->MacClientToRootWindow( &x
, &y
) ;
1017 extent
.right
= x
+ size
.x
;
1018 extent
.bottom
= y
+ size
.y
;
1019 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1023 parent
= parent
->GetParent() ;
1027 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1032 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1035 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
= 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
)
1371 // This calls the UI-update mechanism (querying windows for
1372 // menu/toolbar/control state information)
1376 // Raise the window to the top of the Z order
1377 void wxWindowMac::Raise()
1381 // Lower the window to the bottom of the Z order
1382 void wxWindowMac::Lower()
1386 void wxWindowMac::DoSetClientSize(int width
, int height
)
1388 if ( width
!= -1 || height
!= -1 )
1391 if ( width
!= -1 && m_vScrollBar
)
1392 width
+= MAC_SCROLLBAR_SIZE
;
1393 if ( height
!= -1 && m_vScrollBar
)
1394 height
+= MAC_SCROLLBAR_SIZE
;
1396 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1397 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1399 DoSetSize( -1 , -1 , width
, height
) ;
1404 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1406 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1410 if ((point
.x
< 0) || (point
.y
< 0) ||
1411 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1416 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1417 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1421 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1423 wxPoint
newPoint( point
) ;
1425 if ( !IsTopLevel() )
1431 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1433 wxWindowMac
*child
= node
->GetData();
1434 // added the m_isShown test --dmazzoni
1435 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1437 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1446 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1450 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1451 if ( ::FindWindow( pt
, &window
) == 3 )
1454 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1457 // No, this yields the CLIENT are, we need the whole frame. RR.
1458 // point = win->ScreenToClient( point ) ;
1461 ::GetPort( &port
) ;
1462 ::SetPort( UMAGetWindowPort( window
) ) ;
1463 ::GlobalToLocal( &pt
) ;
1466 wxPoint
point( pt
.h
, pt
.v
) ;
1468 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1474 static wxWindow
*gs_lastWhich
= NULL
;
1476 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1478 // first trigger a set cursor event
1480 wxPoint clientorigin
= GetClientAreaOrigin() ;
1481 wxSize clientsize
= GetClientSize() ;
1483 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1485 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1487 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1488 if ( processedEvtSetCursor
&& event
.HasCursor() )
1490 cursor
= event
.GetCursor() ;
1495 // the test for processedEvtSetCursor is here to prevent using m_cursor
1496 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1497 // it - this is a way to say that our cursor shouldn't be used for this
1499 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1509 cursor
= *wxSTANDARD_CURSOR
;
1513 cursor
.MacInstall() ;
1515 return cursor
.Ok() ;
1518 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1520 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1521 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1525 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1528 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1536 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1538 wxWindowMac
*child
= node
->GetData();
1539 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1541 if (child
->MacDispatchMouseEvent(event
))
1546 wxWindow
* cursorTarget
= this ;
1547 wxPoint
cursorPoint( x
, y
) ;
1549 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1551 cursorTarget
= cursorTarget
->GetParent() ;
1553 cursorPoint
+= cursorTarget
->GetPosition() ;
1557 event
.SetEventObject( this ) ;
1559 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1561 // set focus to this window
1562 if (AcceptsFocus() && FindFocus()!=this)
1567 if ( event
.GetEventType() == wxEVT_MOTION
1568 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1569 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1570 wxToolTip::RelayEvent( this , event
);
1571 #endif // wxUSE_TOOLTIPS
1573 if (gs_lastWhich
!= this)
1575 gs_lastWhich
= this;
1577 // Double clicks must always occur on the same window
1578 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1579 event
.SetEventType( wxEVT_LEFT_DOWN
);
1580 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1581 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1583 // Same for mouse up events
1584 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1586 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1590 GetEventHandler()->ProcessEvent( event
) ;
1595 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1599 return m_tooltip
->GetTip() ;
1601 return wxEmptyString
;
1604 void wxWindowMac::Update()
1606 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1609 win
->MacUpdate( 0 ) ;
1610 #if TARGET_API_MAC_CARBON
1611 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1613 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1619 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1621 wxTopLevelWindowMac
* win
= NULL
;
1622 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1625 win
= wxFindWinFromMacWindow( window
) ;
1630 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1632 RgnHandle visRgn
= NewRgn() ;
1633 RgnHandle tempRgn
= NewRgn() ;
1634 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1636 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1638 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1639 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1641 int borderTop
= 14 ;
1642 int borderOther
= 4 ;
1644 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1645 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1648 if ( !IsTopLevel() )
1650 wxWindow
* parent
= GetParent() ;
1653 wxSize size
= parent
->GetSize() ;
1656 parent
->MacWindowToRootWindow( &x
, &y
) ;
1657 MacRootWindowToWindow( &x
, &y
) ;
1659 SetRectRgn( tempRgn
,
1660 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1661 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1662 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1664 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1665 if ( parent
->IsTopLevel() )
1667 parent
= parent
->GetParent() ;
1670 if ( respectChildrenAndSiblings
)
1672 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1674 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1676 wxWindowMac
*child
= node
->GetData();
1678 if ( !child
->IsTopLevel() && child
->IsShown() )
1680 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1681 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1683 int borderTop
= 14 ;
1684 int borderOther
= 4 ;
1686 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1687 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1689 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1694 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1696 bool thisWindowThrough
= false ;
1697 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1699 wxWindowMac
*sibling
= node
->GetData();
1700 if ( sibling
== this )
1702 thisWindowThrough
= true ;
1705 if( !thisWindowThrough
)
1710 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1712 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
) ;
1713 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1715 int borderTop
= 14 ;
1716 int borderOther
= 4 ;
1718 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
) ;
1719 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1721 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1726 m_macVisibleRegion
= visRgn
;
1727 DisposeRgn( visRgn
) ;
1728 DisposeRgn( tempRgn
) ;
1729 DisposeRgn( tempStaticBoxRgn
) ;
1730 return m_macVisibleRegion
;
1733 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1735 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1736 // updatergn is always already clipped to our boundaries
1737 // it is in window coordinates, not in client coordinates
1739 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1742 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1743 RgnHandle ownUpdateRgn
= NewRgn() ;
1744 CopyRgn( updatergn
, ownUpdateRgn
) ;
1746 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1748 // newupdate is the update region in client coordinates
1749 RgnHandle newupdate
= NewRgn() ;
1750 wxSize point
= GetClientSize() ;
1751 wxPoint origin
= GetClientAreaOrigin() ;
1752 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1753 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1754 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1755 m_updateRegion
= newupdate
;
1756 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1758 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1760 wxWindowDC
dc(this);
1761 if (!EmptyRgn(ownUpdateRgn
))
1762 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1763 wxEraseEvent
eevent( GetId(), &dc
);
1764 eevent
.SetEventObject( this );
1765 GetEventHandler()->ProcessEvent( eevent
);
1767 wxNcPaintEvent
eventNc( GetId() );
1768 eventNc
.SetEventObject( this );
1769 GetEventHandler()->ProcessEvent( eventNc
);
1771 DisposeRgn( ownUpdateRgn
) ;
1772 if ( !m_updateRegion
.Empty() )
1775 event
.m_timeStamp
= time
;
1776 event
.SetEventObject(this);
1777 GetEventHandler()->ProcessEvent(event
);
1781 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1783 RgnHandle childupdate
= NewRgn() ;
1784 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1786 // calculate the update region for the child windows by intersecting the window rectangle with our own
1787 // passed in update region and then offset it to be client-wise window coordinates again
1788 wxWindowMac
*child
= node
->GetData();
1789 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1790 SectRgn( childupdate
, updatergn
, childupdate
) ;
1791 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1792 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1794 // because dialogs may also be children
1795 child
->MacRedraw( childupdate
, time
, erase
) ;
1798 DisposeRgn( childupdate
) ;
1799 // eventually a draw grow box here
1803 WXHWND
wxWindowMac::MacGetRootWindow() const
1805 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1809 if ( iter
->IsTopLevel() )
1810 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1812 iter
= iter
->GetParent() ;
1814 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1818 void wxWindowMac::MacCreateScrollBars( long style
)
1820 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1822 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1823 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1825 GetClientSize( &width
, &height
) ;
1827 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1828 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1829 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1830 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1832 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1833 vSize
, wxVERTICAL
);
1835 if ( style
& wxVSCROLL
)
1841 m_vScrollBar
->Show(false) ;
1843 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1844 hSize
, wxHORIZONTAL
);
1845 if ( style
& wxHSCROLL
)
1850 m_hScrollBar
->Show(false) ;
1853 // because the create does not take into account the client area origin
1854 MacRepositionScrollBars() ; // we might have a real position shift
1857 void wxWindowMac::MacRepositionScrollBars()
1859 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1860 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1862 // get real client area
1864 int width
= m_width
;
1865 int height
= m_height
;
1867 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1868 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1870 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1871 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1872 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1873 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1880 MacClientToRootWindow( &x
, &y
) ;
1881 MacClientToRootWindow( &w
, &h
) ;
1883 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1885 int totW
= 10000 , totH
= 10000;
1888 if ( iter
->IsTopLevel() )
1890 totW
= iter
->m_width
;
1891 totH
= iter
->m_height
;
1895 iter
= iter
->GetParent() ;
1923 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1927 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1931 bool wxWindowMac::AcceptsFocus() const
1933 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1936 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1938 return GetParent()->MacGetContainerForEmbedding() ;
1941 void wxWindowMac::MacSuperChangedPosition()
1943 // only window-absolute structures have to be moved i.e. controls
1945 wxWindowListNode
*node
= GetChildren().GetFirst();
1948 wxWindowMac
*child
= node
->GetData();
1949 child
->MacSuperChangedPosition() ;
1950 node
= node
->GetNext();
1954 void wxWindowMac::MacTopLevelWindowChangedPosition()
1956 // only screen-absolute structures have to be moved i.e. glcanvas
1958 wxWindowListNode
*node
= GetChildren().GetFirst();
1961 wxWindowMac
*child
= node
->GetData();
1962 child
->MacTopLevelWindowChangedPosition() ;
1963 node
= node
->GetNext();
1966 long wxWindowMac::MacGetLeftBorderSize( ) const
1971 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1974 #if wxMAC_USE_THEME_BORDER
1976 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1981 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1984 #if wxMAC_USE_THEME_BORDER
1986 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1991 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1998 long wxWindowMac::MacGetRightBorderSize( ) const
2000 // they are all symmetric in mac themes
2001 return MacGetLeftBorderSize() ;
2004 long wxWindowMac::MacGetTopBorderSize( ) const
2006 // they are all symmetric in mac themes
2007 return MacGetLeftBorderSize() ;
2010 long wxWindowMac::MacGetBottomBorderSize( ) const
2012 // they are all symmetric in mac themes
2013 return MacGetLeftBorderSize() ;
2016 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2018 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2021 // Find the wxWindowMac at the current mouse position, returning the mouse
2023 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2025 pt
= wxGetMousePosition();
2026 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2030 // Get the current mouse position.
2031 wxPoint
wxGetMousePosition()
2034 wxGetMousePosition(& x
, & y
);
2035 return wxPoint(x
, y
);
2038 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2040 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2042 // copied from wxGTK : CS
2043 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2046 // (a) it's a command event and so is propagated to the parent
2047 // (b) under MSW it can be generated from kbd too
2048 // (c) it uses screen coords (because of (a))
2049 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2051 this->ClientToScreen(event
.GetPosition()));
2052 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )