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_SET_FOCUS(wxWindowMac::OnSetFocus
)
79 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
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()
103 m_backgroundTransparent
= FALSE
;
105 // as all windows are created with WS_VISIBLE style...
113 m_hScrollBar
= NULL
;
114 m_vScrollBar
= NULL
;
118 wxWindowMac::~wxWindowMac()
122 // deleting a window while it is shown invalidates the region
124 wxWindowMac
* iter
= this ;
126 if ( iter
->IsTopLevel() )
131 iter
= iter
->GetParent() ;
136 m_isBeingDeleted
= TRUE
;
138 #ifndef __WXUNIVERSAL__
139 // VS: make sure there's no wxFrame with last focus set to us:
140 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
142 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
145 if ( frame
->GetLastFocus() == this )
147 frame
->SetLastFocus((wxWindow
*)NULL
);
152 #endif // __WXUNIVERSAL__
154 if ( s_lastMouseWindow
== this )
156 s_lastMouseWindow
= NULL
;
159 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
162 if ( frame
->GetLastFocus() == this )
163 frame
->SetLastFocus( NULL
) ;
166 if ( gFocusWindow
== this )
168 gFocusWindow
= NULL
;
173 // delete our drop target if we've got one
174 #if wxUSE_DRAG_AND_DROP
175 if ( m_dropTarget
!= NULL
)
180 #endif // wxUSE_DRAG_AND_DROP
184 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
188 const wxString
& name
)
190 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
193 // wxGTK doesn't allow to create controls with static box as the parent so
194 // this will result in a crash when the program is ported to wxGTK - warn
197 // the correct solution is to create the controls as siblings of the
199 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
200 _T("wxStaticBox can't be used as a window parent!") );
201 #endif // wxUSE_STATBOX
203 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
206 parent
->AddChild(this);
210 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
211 m_width
= WidthDefault( size
.x
);
212 m_height
= HeightDefault( size
.y
) ;
213 #ifndef __WXUNIVERSAL__
214 // Don't give scrollbars to wxControls unless they ask for them
215 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
216 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
218 MacCreateScrollBars( style
) ;
224 void wxWindowMac::SetFocus()
226 if ( gFocusWindow
== this )
229 if ( AcceptsFocus() )
235 if ( gFocusWindow
->m_caret
)
237 gFocusWindow
->m_caret
->OnKillFocus();
239 #endif // wxUSE_CARET
240 #ifndef __WXUNIVERSAL__
241 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
242 if ( control
&& control
->GetMacControl() )
244 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
245 control
->MacRedrawControl() ;
248 // Without testing the window id, for some reason
249 // a kill focus event can still be sent to
250 // the control just being focussed.
251 int thisId
= this->m_windowId
;
252 int gFocusWindowId
= gFocusWindow
->m_windowId
;
253 if (gFocusWindowId
!= thisId
)
255 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
256 event
.SetEventObject(gFocusWindow
);
257 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
260 gFocusWindow
= this ;
266 m_caret
->OnSetFocus();
268 #endif // wxUSE_CARET
269 // panel wants to track the window which was the last to have focus in it
270 wxChildFocusEvent
eventFocus(this);
271 GetEventHandler()->ProcessEvent(eventFocus
);
273 #ifndef __WXUNIVERSAL__
274 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
275 if ( control
&& control
->GetMacControl() )
277 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
280 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
281 event
.SetEventObject(this);
282 GetEventHandler()->ProcessEvent(event
) ;
287 bool wxWindowMac::Enable(bool enable
)
289 if ( !wxWindowBase::Enable(enable
) )
292 MacSuperEnabled( enable
) ;
297 void wxWindowMac::DoCaptureMouse()
299 wxTheApp
->s_captureWindow
= this ;
302 wxWindow
* wxWindowBase::GetCapture()
304 return wxTheApp
->s_captureWindow
;
307 void wxWindowMac::DoReleaseMouse()
309 wxTheApp
->s_captureWindow
= NULL
;
312 #if wxUSE_DRAG_AND_DROP
314 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
316 if ( m_dropTarget
!= 0 ) {
320 m_dropTarget
= pDropTarget
;
321 if ( m_dropTarget
!= 0 )
329 // Old style file-manager drag&drop
330 void wxWindowMac::DragAcceptFiles(bool accept
)
336 void wxWindowMac::DoGetSize(int *x
, int *y
) const
339 if(y
) *y
= m_height
;
342 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
348 if ( !IsTopLevel() && GetParent())
350 wxPoint
pt(GetParent()->GetClientAreaOrigin());
359 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
361 menu
->SetInvokingWindow(this);
363 ClientToScreen( &x
, &y
) ;
365 menu
->MacBeforeDisplay( true ) ;
366 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
367 if ( HiWord(menuResult
) != 0 )
370 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
371 wxMenuItem
* item
= NULL
;
373 item
= menu
->FindItem(id
, &realmenu
) ;
374 if (item
->IsCheckable())
376 item
->Check( !item
->IsChecked() ) ;
378 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
380 menu
->MacAfterDisplay( true ) ;
382 menu
->SetInvokingWindow(NULL
);
388 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
390 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
392 Point localwhere
= {0,0} ;
394 if(x
) localwhere
.h
= * x
;
395 if(y
) localwhere
.v
= * y
;
399 ::SetPort( UMAGetWindowPort( window
) ) ;
400 ::GlobalToLocal( &localwhere
) ;
403 if(x
) *x
= localwhere
.h
;
404 if(y
) *y
= localwhere
.v
;
406 MacRootWindowToWindow( x
, y
) ;
408 *x
-= MacGetLeftBorderSize() ;
410 *y
-= MacGetTopBorderSize() ;
413 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
415 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
418 *x
+= MacGetLeftBorderSize() ;
420 *y
+= MacGetTopBorderSize() ;
422 MacWindowToRootWindow( x
, y
) ;
424 Point localwhere
= { 0,0 };
425 if(x
) localwhere
.h
= * x
;
426 if(y
) localwhere
.v
= * y
;
430 ::SetPort( UMAGetWindowPort( window
) ) ;
432 ::LocalToGlobal( &localwhere
) ;
434 if(x
) *x
= localwhere
.h
;
435 if(y
) *y
= localwhere
.v
;
438 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
440 wxPoint origin
= GetClientAreaOrigin() ;
441 if(x
) *x
+= origin
.x
;
442 if(y
) *y
+= origin
.y
;
444 MacWindowToRootWindow( x
, y
) ;
447 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
449 wxPoint origin
= GetClientAreaOrigin() ;
450 MacRootWindowToWindow( x
, y
) ;
451 if(x
) *x
-= origin
.x
;
452 if(y
) *y
-= origin
.y
;
455 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
461 GetParent()->MacWindowToRootWindow( x
, y
) ;
465 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
471 GetParent()->MacRootWindowToWindow( x
, y
) ;
475 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
477 if (m_cursor
== cursor
)
480 if (wxNullCursor
== cursor
)
482 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
487 if ( ! wxWindowBase::SetCursor( cursor
) )
491 wxASSERT_MSG( m_cursor
.Ok(),
492 wxT("cursor must be valid after call to the base version"));
495 wxWindowMac
*mouseWin
;
498 // Change the cursor NOW if we're within the correct window
500 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
502 if ( mouseWin
== this && !wxIsBusy() )
504 m_cursor
.MacInstall() ;
512 // Get size *available for subwindows* i.e. excluding menu bar etc.
513 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
519 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
520 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
522 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
529 MacClientToRootWindow( &x1
, &y1
) ;
530 MacClientToRootWindow( &w
, &h
) ;
532 wxWindowMac
*iter
= (wxWindowMac
*)this ;
534 int totW
= 10000 , totH
= 10000;
537 if ( iter
->IsTopLevel() )
539 totW
= iter
->m_width
;
540 totH
= iter
->m_height
;
544 iter
= iter
->GetParent() ;
547 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
549 hh
-= MAC_SCROLLBAR_SIZE
;
555 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
557 ww
-= MAC_SCROLLBAR_SIZE
;
569 // ----------------------------------------------------------------------------
571 // ----------------------------------------------------------------------------
575 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
577 wxWindowBase::DoSetToolTip(tooltip
);
580 m_tooltip
->SetWindow(this);
583 #endif // wxUSE_TOOLTIPS
585 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
589 int former_w
= m_width
;
590 int former_h
= m_height
;
592 int actualWidth
= width
;
593 int actualHeight
= height
;
597 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
598 actualWidth
= m_minWidth
;
599 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
600 actualHeight
= m_minHeight
;
601 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
602 actualWidth
= m_maxWidth
;
603 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
604 actualHeight
= m_maxHeight
;
606 bool doMove
= false ;
607 bool doResize
= false ;
609 if ( actualX
!= former_x
|| actualY
!= former_y
)
613 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
618 if ( doMove
|| doResize
)
620 // erase former position
622 bool partialRepaint
= false ;
624 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
626 wxPoint
oldPos( m_x
, m_y
) ;
627 wxPoint
newPos( actualX
, actualY
) ;
628 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
629 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
630 if ( oldPos
== newPos
)
632 partialRepaint
= true ;
633 RgnHandle oldRgn
,newRgn
,diffRgn
;
637 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
638 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
639 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
640 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
641 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
642 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
645 DisposeRgn(diffRgn
) ;
649 if ( !partialRepaint
)
654 m_width
= actualWidth
;
655 m_height
= actualHeight
;
657 // update any low-level frame-relative positions
659 MacUpdateDimensions() ;
660 // erase new position
662 if ( !partialRepaint
)
665 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
667 MacRepositionScrollBars() ;
670 wxPoint
point(m_x
, m_y
);
671 wxMoveEvent
event(point
, m_windowId
);
672 event
.SetEventObject(this);
673 GetEventHandler()->ProcessEvent(event
) ;
677 MacRepositionScrollBars() ;
678 wxSize
size(m_width
, m_height
);
679 wxSizeEvent
event(size
, m_windowId
);
680 event
.SetEventObject(this);
681 GetEventHandler()->ProcessEvent(event
);
687 // set the size of the window: if the dimensions are positive, just use them,
688 // but if any of them is equal to -1, it means that we must find the value for
689 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
690 // which case -1 is a valid value for x and y)
692 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
693 // the width/height to best suit our contents, otherwise we reuse the current
695 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
697 // get the current size and position...
698 int currentX
, currentY
;
699 GetPosition(¤tX
, ¤tY
);
701 int currentW
,currentH
;
702 GetSize(¤tW
, ¤tH
);
704 // ... and don't do anything (avoiding flicker) if it's already ok
705 if ( x
== currentX
&& y
== currentY
&&
706 width
== currentW
&& height
== currentH
)
708 MacRepositionScrollBars() ; // we might have a real position shift
712 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
714 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
717 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
722 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
724 size
= DoGetBestSize();
729 // just take the current one
736 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
740 size
= DoGetBestSize();
742 //else: already called DoGetBestSize() above
748 // just take the current one
753 DoMoveWindow(x
, y
, width
, height
);
756 // For implementation purposes - sometimes decorations make the client area
759 wxPoint
wxWindowMac::GetClientAreaOrigin() const
761 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
764 void wxWindowMac::SetTitle(const wxString
& title
)
769 wxString
wxWindowMac::GetTitle() const
774 bool wxWindowMac::Show(bool show
)
776 if ( !wxWindowBase::Show(show
) )
779 MacSuperShown( show
) ;
785 void wxWindowMac::MacSuperShown( bool show
)
787 wxWindowListNode
*node
= GetChildren().GetFirst();
790 wxWindowMac
*child
= node
->GetData();
791 if ( child
->m_isShown
)
792 child
->MacSuperShown( show
) ;
793 node
= node
->GetNext();
797 void wxWindowMac::MacSuperEnabled( bool enabled
)
801 // to be absolutely correct we'd have to invalidate (with eraseBkground
802 // because unter MacOSX the frames are drawn with an addXXX mode)
805 wxWindowListNode
*node
= GetChildren().GetFirst();
808 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
809 if ( child
->m_isShown
)
810 child
->MacSuperEnabled( enabled
) ;
811 node
= node
->GetNext();
815 bool wxWindowMac::MacIsReallyShown() const
817 if ( m_isShown
&& (m_parent
!= NULL
) ) {
818 return m_parent
->MacIsReallyShown();
822 bool status = m_isShown ;
823 wxWindowMac * win = this ;
824 while ( status && win->m_parent != NULL )
826 win = win->m_parent ;
827 status = win->m_isShown ;
833 int wxWindowMac::GetCharHeight() const
835 wxClientDC
dc ( (wxWindowMac
*)this ) ;
836 return dc
.GetCharHeight() ;
839 int wxWindowMac::GetCharWidth() const
841 wxClientDC
dc ( (wxWindowMac
*)this ) ;
842 return dc
.GetCharWidth() ;
845 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
846 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
848 const wxFont
*fontToUse
= theFont
;
852 wxClientDC
dc( (wxWindowMac
*) this ) ;
854 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
855 if ( externalLeading
)
856 *externalLeading
= le
;
866 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
867 * we always intersect with the entire window, not only with the client area
870 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
872 if ( MacGetTopLevelWindow() == NULL
)
875 if ( !MacIsReallyShown() )
878 wxPoint client
= GetClientAreaOrigin();
881 int x2
= m_width
- client
.x
;
882 int y2
= m_height
- client
.y
;
884 if (IsKindOf( CLASSINFO(wxButton
)))
886 // buttons have an "aura"
893 Rect clientrect
= { y1
, x1
, y2
, x2
};
897 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
898 SectRect( &clientrect
, &r
, &clientrect
) ;
901 if ( !EmptyRect( &clientrect
) )
903 int top
= 0 , left
= 0 ;
905 MacClientToRootWindow( &left
, &top
) ;
906 OffsetRect( &clientrect
, left
, top
) ;
908 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
912 wxWindowMac
*wxGetActiveWindow()
914 // actually this is a windows-only concept
918 // Coordinates relative to the window
919 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
921 // We really don't move the mouse programmatically under Mac.
924 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
926 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
928 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
930 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
932 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
933 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
934 // either a non gray background color or a non control window
936 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
938 wxWindowMac
* parent
= GetParent() ;
941 if ( parent
->MacGetRootWindow() != window
)
943 // we are in a different window on the mac system
949 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
950 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
952 // if we have any other colours in the hierarchy
953 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
956 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
957 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
959 Rect extent
= { 0 , 0 , 0 , 0 } ;
962 wxSize size
= parent
->GetSize() ;
963 parent
->MacClientToRootWindow( &x
, &y
) ;
967 extent
.right
= x
+ size
.x
;
968 extent
.bottom
= y
+ size
.y
;
969 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
973 parent
= parent
->GetParent() ;
977 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
982 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
985 return m_macBackgroundBrush
;
988 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
990 event
.GetDC()->Clear() ;
993 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
995 wxWindowDC
dc(this) ;
996 wxMacPortSetter
helper(&dc
) ;
998 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1001 int wxWindowMac::GetScrollPos(int orient
) const
1003 if ( orient
== wxHORIZONTAL
)
1006 return m_hScrollBar
->GetThumbPosition() ;
1011 return m_vScrollBar
->GetThumbPosition() ;
1016 // This now returns the whole range, not just the number
1017 // of positions that we can scroll.
1018 int wxWindowMac::GetScrollRange(int orient
) const
1020 if ( orient
== wxHORIZONTAL
)
1023 return m_hScrollBar
->GetRange() ;
1028 return m_vScrollBar
->GetRange() ;
1033 int wxWindowMac::GetScrollThumb(int orient
) const
1035 if ( orient
== wxHORIZONTAL
)
1038 return m_hScrollBar
->GetThumbSize() ;
1043 return m_vScrollBar
->GetThumbSize() ;
1048 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1050 if ( orient
== wxHORIZONTAL
)
1053 m_hScrollBar
->SetThumbPosition( pos
) ;
1058 m_vScrollBar
->SetThumbPosition( pos
) ;
1062 void wxWindowMac::MacPaintBorders( int left
, int top
)
1067 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1068 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1069 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1070 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1073 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1075 #if wxMAC_USE_THEME_BORDER
1076 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1079 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1080 InsetRect( &rect , border , border );
1081 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1084 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1086 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1087 RGBForeColor( &face
);
1088 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1089 LineTo( left
+ 0 , top
+ 0 );
1090 LineTo( left
+ m_width
- 2 , top
+ 0 );
1092 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1093 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1094 LineTo( left
+ m_width
- 3 , top
+ 2 );
1096 RGBForeColor( sunken
? &face
: &black
);
1097 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1098 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1099 LineTo( left
+ m_width
- 1 , top
+ 0 );
1101 RGBForeColor( sunken
? &shadow
: &white
);
1102 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1103 LineTo( left
+ 1, top
+ 1 );
1104 LineTo( left
+ m_width
- 3 , top
+ 1 );
1106 RGBForeColor( sunken
? &white
: &shadow
);
1107 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1108 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1109 LineTo( left
+ m_width
- 2 , top
+ 1 );
1111 RGBForeColor( sunken
? &black
: &face
);
1112 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1113 LineTo( left
+ 2 , top
+ 2 );
1114 LineTo( left
+ m_width
- 4 , top
+ 2 );
1117 else if (HasFlag(wxSIMPLE_BORDER
))
1119 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1120 RGBForeColor( &black
) ;
1121 FrameRect( &rect
) ;
1125 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1127 if ( child
== m_hScrollBar
)
1128 m_hScrollBar
= NULL
;
1129 if ( child
== m_vScrollBar
)
1130 m_vScrollBar
= NULL
;
1132 wxWindowBase::RemoveChild( child
) ;
1135 // New function that will replace some of the above.
1136 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1137 int range
, bool refresh
)
1139 if ( orient
== wxHORIZONTAL
)
1143 if ( range
== 0 || thumbVisible
>= range
)
1145 if ( m_hScrollBar
->IsShown() )
1146 m_hScrollBar
->Show(false) ;
1150 if ( !m_hScrollBar
->IsShown() )
1151 m_hScrollBar
->Show(true) ;
1152 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1160 if ( range
== 0 || thumbVisible
>= range
)
1162 if ( m_vScrollBar
->IsShown() )
1163 m_vScrollBar
->Show(false) ;
1167 if ( !m_vScrollBar
->IsShown() )
1168 m_vScrollBar
->Show(true) ;
1169 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1173 MacRepositionScrollBars() ;
1176 // Does a physical scroll
1177 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1179 if( dx
== 0 && dy
==0 )
1184 wxClientDC
dc(this) ;
1185 wxMacPortSetter
helper(&dc
) ;
1187 int width
, height
;
1188 GetClientSize( &width
, &height
) ;
1190 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1191 RgnHandle updateRgn
= NewRgn() ;
1192 ClipRect( &scrollrect
) ;
1195 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1196 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1197 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1199 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1200 // we also have to scroll the update rgn in this rectangle
1201 // in order not to loose updates
1202 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1203 RgnHandle formerUpdateRgn
= NewRgn() ;
1204 RgnHandle scrollRgn
= NewRgn() ;
1205 RectRgn( scrollRgn
, &scrollrect
) ;
1206 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1208 LocalToGlobal( &pt
) ;
1209 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1210 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1211 if ( !EmptyRgn( formerUpdateRgn
) )
1213 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1214 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1215 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1217 InvalWindowRgn(rootWindow
, updateRgn
) ;
1218 DisposeRgn( updateRgn
) ;
1219 DisposeRgn( formerUpdateRgn
) ;
1220 DisposeRgn( scrollRgn
) ;
1223 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1225 wxWindowMac
*child
= node
->GetData();
1226 if (child
== m_vScrollBar
) continue;
1227 if (child
== m_hScrollBar
) continue;
1228 if (child
->IsTopLevel()) continue;
1231 child
->GetPosition( &x
, &y
);
1233 child
->GetSize( &w
, &h
);
1234 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1241 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1243 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1245 wxScrollWinEvent wevent
;
1246 wevent
.SetPosition(event
.GetPosition());
1247 wevent
.SetOrientation(event
.GetOrientation());
1248 wevent
.m_eventObject
= this;
1250 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
1251 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1252 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
1253 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1254 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
1255 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1256 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
1257 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1258 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
1259 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1260 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
1261 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1262 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
1263 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1264 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
1265 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1267 GetEventHandler()->ProcessEvent(wevent
);
1271 // Get the window with the focus
1272 wxWindowMac
*wxWindowBase::FindFocus()
1274 return gFocusWindow
;
1277 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1279 // panel wants to track the window which was the last to have focus in it,
1280 // so we want to set ourselves as the window which last had focus
1282 // notice that it's also important to do it upwards the tree becaus
1283 // otherwise when the top level panel gets focus, it won't set it back to
1284 // us, but to some other sibling
1286 // CS:don't know if this is still needed:
1287 //wxChildFocusEvent eventFocus(this);
1288 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1293 // Setup background and foreground colours correctly
1294 void wxWindowMac::SetupColours()
1297 SetBackgroundColour(GetParent()->GetBackgroundColour());
1300 void wxWindowMac::OnInternalIdle()
1302 // This calls the UI-update mechanism (querying windows for
1303 // menu/toolbar/control state information)
1304 if (wxUpdateUIEvent::CanUpdate(this))
1305 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1308 // Raise the window to the top of the Z order
1309 void wxWindowMac::Raise()
1313 // Lower the window to the bottom of the Z order
1314 void wxWindowMac::Lower()
1318 void wxWindowMac::DoSetClientSize(int width
, int height
)
1320 if ( width
!= -1 || height
!= -1 )
1323 if ( width
!= -1 && m_vScrollBar
)
1324 width
+= MAC_SCROLLBAR_SIZE
;
1325 if ( height
!= -1 && m_vScrollBar
)
1326 height
+= MAC_SCROLLBAR_SIZE
;
1328 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1329 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1331 DoSetSize( -1 , -1 , width
, height
) ;
1336 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1338 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1342 if ((point
.x
< 0) || (point
.y
< 0) ||
1343 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1348 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1349 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1353 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1355 wxPoint
newPoint( point
) ;
1357 if ( !IsTopLevel() )
1363 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1365 wxWindowMac
*child
= node
->GetData();
1366 // added the m_isShown test --dmazzoni
1367 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1369 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1378 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1382 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1383 if ( ::FindWindow( pt
, &window
) == 3 )
1386 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1389 // No, this yields the CLIENT are, we need the whole frame. RR.
1390 // point = win->ScreenToClient( point ) ;
1393 ::GetPort( &port
) ;
1394 ::SetPort( UMAGetWindowPort( window
) ) ;
1395 ::GlobalToLocal( &pt
) ;
1398 wxPoint
point( pt
.h
, pt
.v
) ;
1400 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1406 static wxWindow
*gs_lastWhich
= NULL
;
1408 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1410 // first trigger a set cursor event
1412 wxPoint clientorigin
= GetClientAreaOrigin() ;
1413 wxSize clientsize
= GetClientSize() ;
1415 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1417 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1419 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1420 if ( processedEvtSetCursor
&& event
.HasCursor() )
1422 cursor
= event
.GetCursor() ;
1427 // the test for processedEvtSetCursor is here to prevent using m_cursor
1428 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1429 // it - this is a way to say that our cursor shouldn't be used for this
1431 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1441 cursor
= *wxSTANDARD_CURSOR
;
1445 cursor
.MacInstall() ;
1447 return cursor
.Ok() ;
1450 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1452 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1453 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1457 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1460 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1468 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1470 wxWindowMac
*child
= node
->GetData();
1471 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1473 if (child
->MacDispatchMouseEvent(event
))
1478 wxWindow
* cursorTarget
= this ;
1479 wxPoint
cursorPoint( x
, y
) ;
1481 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1483 cursorTarget
= cursorTarget
->GetParent() ;
1485 cursorPoint
+= cursorTarget
->GetPosition() ;
1489 event
.SetEventObject( this ) ;
1491 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1493 // set focus to this window
1494 if (AcceptsFocus() && FindFocus()!=this)
1499 if ( event
.GetEventType() == wxEVT_MOTION
1500 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1501 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1502 wxToolTip::RelayEvent( this , event
);
1503 #endif // wxUSE_TOOLTIPS
1505 if (gs_lastWhich
!= this)
1507 gs_lastWhich
= this;
1509 // Double clicks must always occur on the same window
1510 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1511 event
.SetEventType( wxEVT_LEFT_DOWN
);
1512 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1513 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1515 // Same for mouse up events
1516 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1518 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1522 GetEventHandler()->ProcessEvent( event
) ;
1527 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1531 return m_tooltip
->GetTip() ;
1533 return wxEmptyString
;
1536 void wxWindowMac::Update()
1538 wxRegion visRgn
= MacGetVisibleRegion( false ) ;
1539 int top
= 0 , left
= 0 ;
1540 MacWindowToRootWindow( &left
, &top
) ;
1541 WindowRef rootWindow
= (WindowRef
) MacGetRootWindow() ;
1542 RgnHandle updateRgn
= NewRgn() ;
1543 // getting the update region in macos local coordinates
1544 GetWindowUpdateRgn( rootWindow
, updateRgn
) ;
1546 ::GetPort( &port
) ;
1547 ::SetPort( UMAGetWindowPort( rootWindow
) ) ;
1549 LocalToGlobal( &pt
) ;
1551 OffsetRgn( updateRgn
, -pt
.h
, -pt
.v
) ;
1552 // translate to window local coordinates
1553 OffsetRgn( updateRgn
, -left
, -top
) ;
1554 SectRgn( updateRgn
, (RgnHandle
) visRgn
.GetWXHRGN() , updateRgn
) ;
1555 MacRedraw( updateRgn
, 0 , true ) ;
1556 // for flushing and validating we need macos-local coordinates again
1557 OffsetRgn( updateRgn
, left
, top
) ;
1558 #if TARGET_API_MAC_CARBON
1559 if ( QDIsPortBuffered( GetWindowPort( rootWindow
) ) )
1561 QDFlushPortBuffer( GetWindowPort( rootWindow
) , updateRgn
) ;
1564 ValidWindowRgn( rootWindow
, updateRgn
) ;
1565 DisposeRgn( updateRgn
) ;
1568 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1570 wxTopLevelWindowMac
* win
= NULL
;
1571 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1574 win
= wxFindWinFromMacWindow( window
) ;
1579 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1581 RgnHandle visRgn
= NewRgn() ;
1582 RgnHandle tempRgn
= NewRgn() ;
1583 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1585 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1587 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1588 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1590 int borderTop
= 14 ;
1591 int borderOther
= 4 ;
1593 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1594 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1597 if ( !IsTopLevel() )
1599 wxWindow
* parent
= GetParent() ;
1602 wxSize size
= parent
->GetSize() ;
1605 parent
->MacWindowToRootWindow( &x
, &y
) ;
1606 MacRootWindowToWindow( &x
, &y
) ;
1608 SetRectRgn( tempRgn
,
1609 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1610 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1611 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1613 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1614 if ( parent
->IsTopLevel() )
1616 parent
= parent
->GetParent() ;
1619 if ( respectChildrenAndSiblings
)
1621 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1623 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1625 wxWindowMac
*child
= node
->GetData();
1627 if ( !child
->IsTopLevel() && child
->IsShown() )
1629 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1630 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1632 int borderTop
= 14 ;
1633 int borderOther
= 4 ;
1635 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1636 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1638 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1643 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1645 bool thisWindowThrough
= false ;
1646 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1648 wxWindowMac
*sibling
= node
->GetData();
1649 if ( sibling
== this )
1651 thisWindowThrough
= true ;
1654 if( !thisWindowThrough
)
1659 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1661 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
) ;
1662 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1664 int borderTop
= 14 ;
1665 int borderOther
= 4 ;
1667 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
) ;
1668 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1670 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1675 m_macVisibleRegion
= visRgn
;
1676 DisposeRgn( visRgn
) ;
1677 DisposeRgn( tempRgn
) ;
1678 DisposeRgn( tempStaticBoxRgn
) ;
1679 return m_macVisibleRegion
;
1682 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1684 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1685 // updatergn is always already clipped to our boundaries
1686 // it is in window coordinates, not in client coordinates
1688 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1691 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1692 RgnHandle ownUpdateRgn
= NewRgn() ;
1693 CopyRgn( updatergn
, ownUpdateRgn
) ;
1695 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1697 // newupdate is the update region in client coordinates
1698 RgnHandle newupdate
= NewRgn() ;
1699 wxSize point
= GetClientSize() ;
1700 wxPoint origin
= GetClientAreaOrigin() ;
1701 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1702 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1703 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1704 m_updateRegion
= newupdate
;
1705 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1707 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1709 wxWindowDC
dc(this);
1710 if (!EmptyRgn(ownUpdateRgn
))
1711 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1712 wxEraseEvent
eevent( GetId(), &dc
);
1713 eevent
.SetEventObject( this );
1714 GetEventHandler()->ProcessEvent( eevent
);
1716 wxNcPaintEvent
eventNc( GetId() );
1717 eventNc
.SetEventObject( this );
1718 GetEventHandler()->ProcessEvent( eventNc
);
1720 DisposeRgn( ownUpdateRgn
) ;
1721 if ( !m_updateRegion
.Empty() )
1723 wxWindowList hiddenWindows
;
1724 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1726 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1728 if ( child
&& child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->GetMacControl() )
1730 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , false , false ) ;
1731 hiddenWindows
.Append( child
) ;
1736 event
.m_timeStamp
= time
;
1737 event
.SetEventObject(this);
1738 GetEventHandler()->ProcessEvent(event
);
1740 for (wxWindowListNode
*node
= hiddenWindows
.GetFirst(); node
; node
= node
->GetNext())
1742 wxControl
*child
= wxDynamicCast( ( wxWindow
*)node
->GetData() , wxControl
) ;
1744 if ( child
&& child
->GetMacControl() )
1746 SetControlVisibility( (ControlHandle
) child
->GetMacControl() , true , false ) ;
1752 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1754 RgnHandle childupdate
= NewRgn() ;
1755 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1757 // calculate the update region for the child windows by intersecting the window rectangle with our own
1758 // passed in update region and then offset it to be client-wise window coordinates again
1759 wxWindowMac
*child
= node
->GetData();
1760 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1761 SectRgn( childupdate
, updatergn
, childupdate
) ;
1762 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1763 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1765 // because dialogs may also be children
1766 child
->MacRedraw( childupdate
, time
, erase
) ;
1769 DisposeRgn( childupdate
) ;
1770 // eventually a draw grow box here
1774 WXHWND
wxWindowMac::MacGetRootWindow() const
1776 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1780 if ( iter
->IsTopLevel() )
1781 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1783 iter
= iter
->GetParent() ;
1785 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
1789 void wxWindowMac::MacCreateScrollBars( long style
)
1791 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1793 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1794 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1796 GetClientSize( &width
, &height
) ;
1798 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1799 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1800 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1801 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1803 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1804 vSize
, wxVERTICAL
);
1806 if ( style
& wxVSCROLL
)
1812 m_vScrollBar
->Show(false) ;
1814 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1815 hSize
, wxHORIZONTAL
);
1816 if ( style
& wxHSCROLL
)
1821 m_hScrollBar
->Show(false) ;
1824 // because the create does not take into account the client area origin
1825 MacRepositionScrollBars() ; // we might have a real position shift
1828 void wxWindowMac::MacRepositionScrollBars()
1830 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1831 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1833 // get real client area
1835 int width
= m_width
;
1836 int height
= m_height
;
1838 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1839 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1841 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1842 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1843 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1844 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1851 MacClientToRootWindow( &x
, &y
) ;
1852 MacClientToRootWindow( &w
, &h
) ;
1854 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1856 int totW
= 10000 , totH
= 10000;
1859 if ( iter
->IsTopLevel() )
1861 totW
= iter
->m_width
;
1862 totH
= iter
->m_height
;
1866 iter
= iter
->GetParent() ;
1894 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1898 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1902 bool wxWindowMac::AcceptsFocus() const
1904 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1907 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1909 return GetParent()->MacGetContainerForEmbedding() ;
1912 void wxWindowMac::MacSuperChangedPosition()
1914 // only window-absolute structures have to be moved i.e. controls
1916 wxWindowListNode
*node
= GetChildren().GetFirst();
1919 wxWindowMac
*child
= node
->GetData();
1920 child
->MacSuperChangedPosition() ;
1921 node
= node
->GetNext();
1925 void wxWindowMac::MacTopLevelWindowChangedPosition()
1927 // only screen-absolute structures have to be moved i.e. glcanvas
1929 wxWindowListNode
*node
= GetChildren().GetFirst();
1932 wxWindowMac
*child
= node
->GetData();
1933 child
->MacTopLevelWindowChangedPosition() ;
1934 node
= node
->GetNext();
1937 long wxWindowMac::MacGetLeftBorderSize( ) const
1942 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
1945 #if wxMAC_USE_THEME_BORDER
1947 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1952 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
1955 #if wxMAC_USE_THEME_BORDER
1957 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
1962 else if (m_windowStyle
&wxSIMPLE_BORDER
)
1969 long wxWindowMac::MacGetRightBorderSize( ) const
1971 // they are all symmetric in mac themes
1972 return MacGetLeftBorderSize() ;
1975 long wxWindowMac::MacGetTopBorderSize( ) const
1977 // they are all symmetric in mac themes
1978 return MacGetLeftBorderSize() ;
1981 long wxWindowMac::MacGetBottomBorderSize( ) const
1983 // they are all symmetric in mac themes
1984 return MacGetLeftBorderSize() ;
1987 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
1989 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
1992 // Find the wxWindowMac at the current mouse position, returning the mouse
1994 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
1996 pt
= wxGetMousePosition();
1997 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2001 // Get the current mouse position.
2002 wxPoint
wxGetMousePosition()
2005 wxGetMousePosition(& x
, & y
);
2006 return wxPoint(x
, y
);
2009 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2011 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2013 // copied from wxGTK : CS
2014 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2017 // (a) it's a command event and so is propagated to the parent
2018 // (b) under MSW it can be generated from kbd too
2019 // (c) it uses screen coords (because of (a))
2020 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2022 this->ClientToScreen(event
.GetPosition()));
2023 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )