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()
108 m_doubleClickAllowed
= 0;
109 m_winCaptured
= FALSE
;
111 m_isBeingDeleted
= FALSE
;
114 m_mouseInWindow
= FALSE
;
118 m_backgroundTransparent
= FALSE
;
120 // as all windows are created with WS_VISIBLE style...
128 m_hScrollBar
= NULL
;
129 m_vScrollBar
= NULL
;
131 m_label
= wxEmptyString
;
135 wxWindowMac::~wxWindowMac()
139 // deleting a window while it is shown invalidates the region
141 wxWindowMac
* iter
= this ;
143 if ( iter
->IsTopLevel() )
148 iter
= iter
->GetParent() ;
153 m_isBeingDeleted
= TRUE
;
155 #ifndef __WXUNIVERSAL__
156 // VS: make sure there's no wxFrame with last focus set to us:
157 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
159 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
162 if ( frame
->GetLastFocus() == this )
164 frame
->SetLastFocus((wxWindow
*)NULL
);
169 #endif // __WXUNIVERSAL__
171 if ( s_lastMouseWindow
== this )
173 s_lastMouseWindow
= NULL
;
176 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
179 if ( frame
->GetLastFocus() == this )
180 frame
->SetLastFocus( NULL
) ;
183 if ( gFocusWindow
== this )
185 gFocusWindow
= NULL
;
188 // CS: copied from MSW :
189 // VS: destroy children first and _then_ detach *this from its parent.
190 // If we'd do it the other way around, children wouldn't be able
191 // find their parent frame (see above).
195 m_parent
->RemoveChild(this);
197 // delete our drop target if we've got one
198 #if wxUSE_DRAG_AND_DROP
199 if ( m_dropTarget
!= NULL
)
204 #endif // wxUSE_DRAG_AND_DROP
208 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
212 const wxString
& name
)
214 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
217 // wxGTK doesn't allow to create controls with static box as the parent so
218 // this will result in a crash when the program is ported to wxGTK - warn
221 // the correct solution is to create the controls as siblings of the
223 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
224 _T("wxStaticBox can't be used as a window parent!") );
225 #endif // wxUSE_STATBOX
227 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
230 parent
->AddChild(this);
234 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
235 m_width
= WidthDefault( size
.x
);
236 m_height
= HeightDefault( size
.y
) ;
237 #ifndef __WXUNIVERSAL__
238 // Don't give scrollbars to wxControls unless they ask for them
239 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
240 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
242 MacCreateScrollBars( style
) ;
248 void wxWindowMac::SetFocus()
250 if ( gFocusWindow
== this )
253 if ( AcceptsFocus() )
259 if ( gFocusWindow
->m_caret
)
261 gFocusWindow
->m_caret
->OnKillFocus();
263 #endif // wxUSE_CARET
264 #ifndef __WXUNIVERSAL__
265 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
266 if ( control
&& control
->GetMacControl() )
268 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
269 control
->MacRedrawControl() ;
272 // Without testing the window id, for some reason
273 // a kill focus event can still be sent to
274 // the control just being focussed.
275 int thisId
= this->m_windowId
;
276 int gFocusWindowId
= gFocusWindow
->m_windowId
;
277 if (gFocusWindowId
!= thisId
)
279 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
280 event
.SetEventObject(gFocusWindow
);
281 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
284 gFocusWindow
= this ;
290 m_caret
->OnSetFocus();
292 #endif // wxUSE_CARET
293 // panel wants to track the window which was the last to have focus in it
294 wxChildFocusEvent
eventFocus(this);
295 GetEventHandler()->ProcessEvent(eventFocus
);
297 #ifndef __WXUNIVERSAL__
298 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
299 if ( control
&& control
->GetMacControl() )
301 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
304 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
305 event
.SetEventObject(this);
306 GetEventHandler()->ProcessEvent(event
) ;
311 bool wxWindowMac::Enable(bool enable
)
313 if ( !wxWindowBase::Enable(enable
) )
316 MacSuperEnabled( enable
) ;
321 void wxWindowMac::DoCaptureMouse()
323 wxTheApp
->s_captureWindow
= this ;
326 wxWindow
* wxWindowBase::GetCapture()
328 return wxTheApp
->s_captureWindow
;
331 void wxWindowMac::DoReleaseMouse()
333 wxTheApp
->s_captureWindow
= NULL
;
336 #if wxUSE_DRAG_AND_DROP
338 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
340 if ( m_dropTarget
!= 0 ) {
344 m_dropTarget
= pDropTarget
;
345 if ( m_dropTarget
!= 0 )
353 // Old style file-manager drag&drop
354 void wxWindowMac::DragAcceptFiles(bool accept
)
360 void wxWindowMac::DoGetSize(int *x
, int *y
) const
363 if(y
) *y
= m_height
;
366 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
372 if ( !IsTopLevel() && GetParent())
374 wxPoint
pt(GetParent()->GetClientAreaOrigin());
383 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
385 menu
->SetInvokingWindow(this);
387 ClientToScreen( &x
, &y
) ;
389 menu
->MacBeforeDisplay( true ) ;
390 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
391 if ( HiWord(menuResult
) != 0 )
394 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
395 wxMenuItem
* item
= NULL
;
397 item
= menu
->FindItem(id
, &realmenu
) ;
398 if (item
->IsCheckable())
400 item
->Check( !item
->IsChecked() ) ;
402 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
404 menu
->MacAfterDisplay( true ) ;
406 menu
->SetInvokingWindow(NULL
);
412 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
414 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
416 Point localwhere
= {0,0} ;
418 if(x
) localwhere
.h
= * x
;
419 if(y
) localwhere
.v
= * y
;
423 ::SetPort( UMAGetWindowPort( window
) ) ;
424 ::GlobalToLocal( &localwhere
) ;
427 if(x
) *x
= localwhere
.h
;
428 if(y
) *y
= localwhere
.v
;
430 MacRootWindowToWindow( x
, y
) ;
432 *x
-= MacGetLeftBorderSize() ;
434 *y
-= MacGetTopBorderSize() ;
437 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
439 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
442 *x
+= MacGetLeftBorderSize() ;
444 *y
+= MacGetTopBorderSize() ;
446 MacWindowToRootWindow( x
, y
) ;
448 Point localwhere
= { 0,0 };
449 if(x
) localwhere
.h
= * x
;
450 if(y
) localwhere
.v
= * y
;
454 ::SetPort( UMAGetWindowPort( window
) ) ;
456 ::LocalToGlobal( &localwhere
) ;
458 if(x
) *x
= localwhere
.h
;
459 if(y
) *y
= localwhere
.v
;
462 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
464 wxPoint origin
= GetClientAreaOrigin() ;
465 if(x
) *x
+= origin
.x
;
466 if(y
) *y
+= origin
.y
;
468 MacWindowToRootWindow( x
, y
) ;
471 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
473 wxPoint origin
= GetClientAreaOrigin() ;
474 MacRootWindowToWindow( x
, y
) ;
475 if(x
) *x
-= origin
.x
;
476 if(y
) *y
-= origin
.y
;
479 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
485 GetParent()->MacWindowToRootWindow( x
, y
) ;
489 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
495 GetParent()->MacRootWindowToWindow( x
, y
) ;
499 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
501 if (m_cursor
== cursor
)
504 if (wxNullCursor
== cursor
)
506 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
511 if ( ! wxWindowBase::SetCursor( cursor
) )
515 wxASSERT_MSG( m_cursor
.Ok(),
516 wxT("cursor must be valid after call to the base version"));
519 wxWindowMac
*mouseWin
;
522 // Change the cursor NOW if we're within the correct window
524 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
526 if ( mouseWin
== this && !wxIsBusy() )
528 m_cursor
.MacInstall() ;
536 // Get size *available for subwindows* i.e. excluding menu bar etc.
537 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
543 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
544 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
546 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
553 MacClientToRootWindow( &x1
, &y1
) ;
554 MacClientToRootWindow( &w
, &h
) ;
556 wxWindowMac
*iter
= (wxWindowMac
*)this ;
558 int totW
= 10000 , totH
= 10000;
561 if ( iter
->IsTopLevel() )
563 totW
= iter
->m_width
;
564 totH
= iter
->m_height
;
568 iter
= iter
->GetParent() ;
571 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
573 hh
-= MAC_SCROLLBAR_SIZE
;
579 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
581 ww
-= MAC_SCROLLBAR_SIZE
;
593 // ----------------------------------------------------------------------------
595 // ----------------------------------------------------------------------------
599 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
601 wxWindowBase::DoSetToolTip(tooltip
);
604 m_tooltip
->SetWindow(this);
607 #endif // wxUSE_TOOLTIPS
609 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
613 int former_w
= m_width
;
614 int former_h
= m_height
;
616 int actualWidth
= width
;
617 int actualHeight
= height
;
621 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
622 actualWidth
= m_minWidth
;
623 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
624 actualHeight
= m_minHeight
;
625 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
626 actualWidth
= m_maxWidth
;
627 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
628 actualHeight
= m_maxHeight
;
630 bool doMove
= false ;
631 bool doResize
= false ;
633 if ( actualX
!= former_x
|| actualY
!= former_y
)
637 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
642 if ( doMove
|| doResize
)
644 // erase former position
646 bool partialRepaint
= false ;
648 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
650 wxPoint
oldPos( m_x
, m_y
) ;
651 wxPoint
newPos( actualX
, actualY
) ;
652 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
653 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
654 if ( oldPos
== newPos
)
656 partialRepaint
= true ;
657 RgnHandle oldRgn
,newRgn
,diffRgn
;
661 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
662 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
663 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
664 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
665 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
666 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
669 DisposeRgn(diffRgn
) ;
673 if ( !partialRepaint
)
678 m_width
= actualWidth
;
679 m_height
= actualHeight
;
681 // update any low-level frame-relative positions
683 MacUpdateDimensions() ;
684 // erase new position
686 if ( !partialRepaint
)
689 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
691 MacRepositionScrollBars() ;
694 wxPoint
point(m_x
, m_y
);
695 wxMoveEvent
event(point
, m_windowId
);
696 event
.SetEventObject(this);
697 GetEventHandler()->ProcessEvent(event
) ;
701 MacRepositionScrollBars() ;
702 wxSize
size(m_width
, m_height
);
703 wxSizeEvent
event(size
, m_windowId
);
704 event
.SetEventObject(this);
705 GetEventHandler()->ProcessEvent(event
);
711 // set the size of the window: if the dimensions are positive, just use them,
712 // but if any of them is equal to -1, it means that we must find the value for
713 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
714 // which case -1 is a valid value for x and y)
716 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
717 // the width/height to best suit our contents, otherwise we reuse the current
719 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
721 // get the current size and position...
722 int currentX
, currentY
;
723 GetPosition(¤tX
, ¤tY
);
725 int currentW
,currentH
;
726 GetSize(¤tW
, ¤tH
);
728 // ... and don't do anything (avoiding flicker) if it's already ok
729 if ( x
== currentX
&& y
== currentY
&&
730 width
== currentW
&& height
== currentH
)
732 MacRepositionScrollBars() ; // we might have a real position shift
736 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
738 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
741 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
746 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
748 size
= DoGetBestSize();
753 // just take the current one
760 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
764 size
= DoGetBestSize();
766 //else: already called DoGetBestSize() above
772 // just take the current one
777 DoMoveWindow(x
, y
, width
, height
);
780 // For implementation purposes - sometimes decorations make the client area
783 wxPoint
wxWindowMac::GetClientAreaOrigin() const
785 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
788 void wxWindowMac::SetTitle(const wxString
& title
)
793 wxString
wxWindowMac::GetTitle() const
798 bool wxWindowMac::Show(bool show
)
800 if ( !wxWindowBase::Show(show
) )
804 WindowRef window = (WindowRef) MacGetRootWindow() ;
805 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
806 if ( win == NULL && win->m_isBeingDeleted )
809 MacSuperShown( show
) ;
814 if ( win && !win->m_isBeingDeleted )
825 void wxWindowMac::MacSuperShown( bool show
)
827 wxWindowListNode
*node
= GetChildren().GetFirst();
830 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
831 if ( child
->m_isShown
)
832 child
->MacSuperShown( show
) ;
833 node
= node
->GetNext();
837 void wxWindowMac::MacSuperEnabled( bool enabled
)
841 // to be absolutely correct we'd have to invalidate (with eraseBkground
842 // because unter MacOSX the frames are drawn with an addXXX mode)
845 wxWindowListNode
*node
= GetChildren().GetFirst();
848 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
849 if ( child
->m_isShown
)
850 child
->MacSuperEnabled( enabled
) ;
851 node
= node
->GetNext();
855 bool wxWindowMac::MacIsReallyShown() const
857 if ( m_isShown
&& (m_parent
!= NULL
) ) {
858 return m_parent
->MacIsReallyShown();
862 bool status = m_isShown ;
863 wxWindowMac * win = this ;
864 while ( status && win->m_parent != NULL )
866 win = win->m_parent ;
867 status = win->m_isShown ;
873 int wxWindowMac::GetCharHeight() const
875 wxClientDC
dc ( (wxWindowMac
*)this ) ;
876 return dc
.GetCharHeight() ;
879 int wxWindowMac::GetCharWidth() const
881 wxClientDC
dc ( (wxWindowMac
*)this ) ;
882 return dc
.GetCharWidth() ;
885 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
886 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
888 const wxFont
*fontToUse
= theFont
;
892 wxClientDC
dc( (wxWindowMac
*) this ) ;
894 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
895 if ( externalLeading
)
896 *externalLeading
= le
;
906 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
907 * we always intersect with the entire window, not only with the client area
910 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
912 if ( MacGetTopLevelWindow() == NULL
)
915 wxPoint client
= GetClientAreaOrigin();
918 int x2
= m_width
- client
.x
;
919 int y2
= m_height
- client
.y
;
921 if (IsKindOf( CLASSINFO(wxButton
)))
923 // buttons have an "aura"
930 Rect clientrect
= { y1
, x1
, y2
, x2
};
934 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
935 SectRect( &clientrect
, &r
, &clientrect
) ;
938 if ( !EmptyRect( &clientrect
) )
940 int top
= 0 , left
= 0 ;
942 MacClientToRootWindow( &left
, &top
) ;
943 OffsetRect( &clientrect
, left
, top
) ;
945 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
949 #if wxUSE_CARET && WXWIN_COMPATIBILITY
950 // ---------------------------------------------------------------------------
951 // Caret manipulation
952 // ---------------------------------------------------------------------------
954 void wxWindowMac::CreateCaret(int w
, int h
)
956 SetCaret(new wxCaret(this, w
, h
));
959 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
961 wxFAIL_MSG("not implemented");
964 void wxWindowMac::ShowCaret(bool show
)
966 wxCHECK_RET( m_caret
, "no caret to show" );
971 void wxWindowMac::DestroyCaret()
976 void wxWindowMac::SetCaretPos(int x
, int y
)
978 wxCHECK_RET( m_caret
, "no caret to move" );
983 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
985 wxCHECK_RET( m_caret
, "no caret to get position of" );
987 m_caret
->GetPosition(x
, y
);
989 #endif // wxUSE_CARET
991 wxWindowMac
*wxGetActiveWindow()
993 // actually this is a windows-only concept
997 // Coordinates relative to the window
998 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1000 // We really don't move the mouse programmatically under Mac.
1003 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
1005 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1007 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
1009 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1011 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1012 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1013 // either a non gray background color or a non control window
1015 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1017 wxWindowMac
* parent
= GetParent() ;
1020 if ( parent
->MacGetRootWindow() != window
)
1022 // we are in a different window on the mac system
1028 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1029 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1031 // if we have any other colours in the hierarchy
1032 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1035 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1036 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1038 Rect extent
= { 0 , 0 , 0 , 0 } ;
1041 wxSize size
= parent
->GetSize() ;
1042 parent
->MacClientToRootWindow( &x
, &y
) ;
1046 extent
.right
= x
+ size
.x
;
1047 extent
.bottom
= y
+ size
.y
;
1048 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1052 parent
= parent
->GetParent() ;
1056 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1061 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1064 return m_macBackgroundBrush
;
1067 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1069 event
.GetDC()->Clear() ;
1072 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1074 wxWindowDC
dc(this) ;
1075 wxMacPortSetter
helper(&dc
) ;
1077 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1080 int wxWindowMac::GetScrollPos(int orient
) const
1082 if ( orient
== wxHORIZONTAL
)
1085 return m_hScrollBar
->GetThumbPosition() ;
1090 return m_vScrollBar
->GetThumbPosition() ;
1095 // This now returns the whole range, not just the number
1096 // of positions that we can scroll.
1097 int wxWindowMac::GetScrollRange(int orient
) const
1099 if ( orient
== wxHORIZONTAL
)
1102 return m_hScrollBar
->GetRange() ;
1107 return m_vScrollBar
->GetRange() ;
1112 int wxWindowMac::GetScrollThumb(int orient
) const
1114 if ( orient
== wxHORIZONTAL
)
1117 return m_hScrollBar
->GetThumbSize() ;
1122 return m_vScrollBar
->GetThumbSize() ;
1127 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1129 if ( orient
== wxHORIZONTAL
)
1132 m_hScrollBar
->SetThumbPosition( pos
) ;
1137 m_vScrollBar
->SetThumbPosition( pos
) ;
1141 void wxWindowMac::MacPaintBorders( int left
, int top
)
1146 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1147 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1148 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1149 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1152 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1154 #if wxMAC_USE_THEME_BORDER
1155 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1158 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1159 InsetRect( &rect , border , border );
1160 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1163 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1165 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1166 RGBForeColor( &face
);
1167 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1168 LineTo( left
+ 0 , top
+ 0 );
1169 LineTo( left
+ m_width
- 2 , top
+ 0 );
1171 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1172 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1173 LineTo( left
+ m_width
- 3 , top
+ 2 );
1175 RGBForeColor( sunken
? &face
: &black
);
1176 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1177 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1178 LineTo( left
+ m_width
- 1 , top
+ 0 );
1180 RGBForeColor( sunken
? &shadow
: &white
);
1181 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1182 LineTo( left
+ 1, top
+ 1 );
1183 LineTo( left
+ m_width
- 3 , top
+ 1 );
1185 RGBForeColor( sunken
? &white
: &shadow
);
1186 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1187 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1188 LineTo( left
+ m_width
- 2 , top
+ 1 );
1190 RGBForeColor( sunken
? &black
: &face
);
1191 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1192 LineTo( left
+ 2 , top
+ 2 );
1193 LineTo( left
+ m_width
- 4 , top
+ 2 );
1196 else if (HasFlag(wxSIMPLE_BORDER
))
1198 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1199 RGBForeColor( &black
) ;
1200 FrameRect( &rect
) ;
1204 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1206 if ( child
== m_hScrollBar
)
1207 m_hScrollBar
= NULL
;
1208 if ( child
== m_vScrollBar
)
1209 m_vScrollBar
= NULL
;
1211 wxWindowBase::RemoveChild( child
) ;
1214 // New function that will replace some of the above.
1215 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1216 int range
, bool refresh
)
1218 if ( orient
== wxHORIZONTAL
)
1222 if ( range
== 0 || thumbVisible
>= range
)
1224 if ( m_hScrollBar
->IsShown() )
1225 m_hScrollBar
->Show(false) ;
1229 if ( !m_hScrollBar
->IsShown() )
1230 m_hScrollBar
->Show(true) ;
1231 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1239 if ( range
== 0 || thumbVisible
>= range
)
1241 if ( m_vScrollBar
->IsShown() )
1242 m_vScrollBar
->Show(false) ;
1246 if ( !m_vScrollBar
->IsShown() )
1247 m_vScrollBar
->Show(true) ;
1248 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1252 MacRepositionScrollBars() ;
1255 // Does a physical scroll
1256 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1258 wxClientDC
dc(this) ;
1259 wxMacPortSetter
helper(&dc
) ;
1262 int width
, height
;
1263 GetClientSize( &width
, &height
) ;
1265 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1266 RgnHandle updateRgn
= NewRgn() ;
1267 ClipRect( &scrollrect
) ;
1270 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1271 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1272 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1274 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1275 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1276 DisposeRgn( updateRgn
) ;
1279 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1281 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1282 if (child
== m_vScrollBar
) continue;
1283 if (child
== m_hScrollBar
) continue;
1284 if (child
->IsTopLevel()) continue;
1287 child
->GetPosition( &x
, &y
);
1289 child
->GetSize( &w
, &h
);
1290 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1295 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1297 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1299 wxScrollWinEvent wevent
;
1300 wevent
.SetPosition(event
.GetPosition());
1301 wevent
.SetOrientation(event
.GetOrientation());
1302 wevent
.m_eventObject
= this;
1304 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1305 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1307 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1308 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1310 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1311 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1313 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1314 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1316 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1317 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1319 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1320 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1322 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1323 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1326 GetEventHandler()->ProcessEvent(wevent
);
1330 // Get the window with the focus
1331 wxWindowMac
*wxWindowBase::FindFocus()
1333 return gFocusWindow
;
1336 #if WXWIN_COMPATIBILITY
1337 // If nothing defined for this, try the parent.
1338 // E.g. we may be a button loaded from a resource, with no callback function
1340 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1342 if ( GetEventHandler()->ProcessEvent(event
) )
1345 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1347 #endif // WXWIN_COMPATIBILITY_2
1349 #if WXWIN_COMPATIBILITY
1350 wxObject
* wxWindowMac::GetChild(int number
) const
1352 // Return a pointer to the Nth object in the Panel
1353 wxNode
*node
= GetChildren().GetFirst();
1356 node
= node
->GetNext();
1359 wxObject
*obj
= (wxObject
*)node
->GetData();
1365 #endif // WXWIN_COMPATIBILITY
1367 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1369 // panel wants to track the window which was the last to have focus in it,
1370 // so we want to set ourselves as the window which last had focus
1372 // notice that it's also important to do it upwards the tree becaus
1373 // otherwise when the top level panel gets focus, it won't set it back to
1374 // us, but to some other sibling
1376 // CS:don't know if this is still needed:
1377 //wxChildFocusEvent eventFocus(this);
1378 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1383 void wxWindowMac::Clear()
1385 wxClientDC
dc(this);
1386 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1387 dc
.SetBackground(brush
);
1391 // Setup background and foreground colours correctly
1392 void wxWindowMac::SetupColours()
1395 SetBackgroundColour(GetParent()->GetBackgroundColour());
1398 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1401 // Check if we need to send a LEAVE event
1402 if (m_mouseInWindow)
1405 ::GetCursorPos(&pt);
1406 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1408 // Generate a LEAVE event
1409 m_mouseInWindow = FALSE;
1410 MSWOnMouseLeave(pt.x, pt.y, 0);
1415 // This calls the UI-update mechanism (querying windows for
1416 // menu/toolbar/control state information)
1420 // Raise the window to the top of the Z order
1421 void wxWindowMac::Raise()
1425 // Lower the window to the bottom of the Z order
1426 void wxWindowMac::Lower()
1430 void wxWindowMac::DoSetClientSize(int width
, int height
)
1432 if ( width
!= -1 || height
!= -1 )
1435 if ( width
!= -1 && m_vScrollBar
)
1436 width
+= MAC_SCROLLBAR_SIZE
;
1437 if ( height
!= -1 && m_vScrollBar
)
1438 height
+= MAC_SCROLLBAR_SIZE
;
1440 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1441 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1443 DoSetSize( -1 , -1 , width
, height
) ;
1448 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1450 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1454 if ((point
.x
< 0) || (point
.y
< 0) ||
1455 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1460 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1461 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1465 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1467 wxPoint
newPoint( point
) ;
1469 if ( !IsTopLevel() )
1475 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1477 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1478 // added the m_isShown test --dmazzoni
1479 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1481 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1490 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1494 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1495 if ( ::FindWindow( pt
, &window
) == 3 )
1498 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1501 // No, this yields the CLIENT are, we need the whole frame. RR.
1502 // point = win->ScreenToClient( point ) ;
1505 ::GetPort( &port
) ;
1506 ::SetPort( UMAGetWindowPort( window
) ) ;
1507 ::GlobalToLocal( &pt
) ;
1510 wxPoint
point( pt
.h
, pt
.v
) ;
1512 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1518 static wxWindow
*gs_lastWhich
= NULL
;
1520 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1522 // first trigger a set cursor event
1524 wxPoint clientorigin
= GetClientAreaOrigin() ;
1525 wxSize clientsize
= GetClientSize() ;
1527 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1529 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1531 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1532 if ( processedEvtSetCursor
&& event
.HasCursor() )
1534 cursor
= event
.GetCursor() ;
1539 // the test for processedEvtSetCursor is here to prevent using m_cursor
1540 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1541 // it - this is a way to say that our cursor shouldn't be used for this
1543 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1553 cursor
= *wxSTANDARD_CURSOR
;
1557 cursor
.MacInstall() ;
1559 return cursor
.Ok() ;
1562 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1564 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1565 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1569 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1572 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1580 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1582 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1583 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1585 if (child
->MacDispatchMouseEvent(event
))
1590 wxWindow
* cursorTarget
= this ;
1591 wxPoint
cursorPoint( x
, y
) ;
1593 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1595 cursorTarget
= cursorTarget
->GetParent() ;
1597 cursorPoint
+= cursorTarget
->GetPosition() ;
1601 event
.SetEventObject( this ) ;
1603 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1605 // set focus to this window
1606 if (AcceptsFocus() && FindFocus()!=this)
1611 if ( event
.GetEventType() == wxEVT_MOTION
1612 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1613 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1614 wxToolTip::RelayEvent( this , event
);
1615 #endif // wxUSE_TOOLTIPS
1617 if (gs_lastWhich
!= this)
1619 gs_lastWhich
= this;
1621 // Double clicks must always occur on the same window
1622 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1623 event
.SetEventType( wxEVT_LEFT_DOWN
);
1624 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1625 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1627 // Same for mouse up events
1628 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1630 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1634 GetEventHandler()->ProcessEvent( event
) ;
1639 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1643 return m_tooltip
->GetTip() ;
1648 void wxWindowMac::Update()
1650 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1653 win
->MacUpdate( 0 ) ;
1654 #if TARGET_API_MAC_CARBON
1655 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1657 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1663 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1665 wxTopLevelWindowMac
* win
= NULL
;
1666 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1669 win
= wxFindWinFromMacWindow( window
) ;
1674 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1676 RgnHandle visRgn
= NewRgn() ;
1677 RgnHandle tempRgn
= NewRgn() ;
1678 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1680 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1682 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1683 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1685 int borderTop
= 14 ;
1686 int borderOther
= 4 ;
1688 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1689 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1692 if ( !IsTopLevel() )
1694 wxWindow
* parent
= GetParent() ;
1697 wxSize size
= parent
->GetSize() ;
1700 parent
->MacWindowToRootWindow( &x
, &y
) ;
1701 MacRootWindowToWindow( &x
, &y
) ;
1703 SetRectRgn( tempRgn
,
1704 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1705 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1706 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1708 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1709 if ( parent
->IsTopLevel() )
1711 parent
= parent
->GetParent() ;
1714 if ( respectChildrenAndSiblings
)
1716 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1718 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1720 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1722 if ( !child
->IsTopLevel() && child
->IsShown() )
1724 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1725 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1727 int borderTop
= 14 ;
1728 int borderOther
= 4 ;
1730 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1731 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1733 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1738 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1740 bool thisWindowThrough
= false ;
1741 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1743 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1744 if ( sibling
== this )
1746 thisWindowThrough
= true ;
1749 if( !thisWindowThrough
)
1754 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1756 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
) ;
1757 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1759 int borderTop
= 14 ;
1760 int borderOther
= 4 ;
1762 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
) ;
1763 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1765 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1770 m_macVisibleRegion
= visRgn
;
1771 DisposeRgn( visRgn
) ;
1772 DisposeRgn( tempRgn
) ;
1773 DisposeRgn( tempStaticBoxRgn
) ;
1774 return m_macVisibleRegion
;
1777 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1779 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1780 // updatergn is always already clipped to our boundaries
1781 // it is in window coordinates, not in client coordinates
1783 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1786 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1787 RgnHandle ownUpdateRgn
= NewRgn() ;
1788 CopyRgn( updatergn
, ownUpdateRgn
) ;
1790 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1792 // newupdate is the update region in client coordinates
1793 RgnHandle newupdate
= NewRgn() ;
1794 wxSize point
= GetClientSize() ;
1795 wxPoint origin
= GetClientAreaOrigin() ;
1796 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1797 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1798 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1799 m_updateRegion
= newupdate
;
1800 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1802 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1804 wxWindowDC
dc(this);
1805 if (!EmptyRgn(ownUpdateRgn
))
1806 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1807 wxEraseEvent
eevent( GetId(), &dc
);
1808 eevent
.SetEventObject( this );
1809 GetEventHandler()->ProcessEvent( eevent
);
1811 wxNcPaintEvent
eventNc( GetId() );
1812 eventNc
.SetEventObject( this );
1813 GetEventHandler()->ProcessEvent( eventNc
);
1815 DisposeRgn( ownUpdateRgn
) ;
1816 if ( !m_updateRegion
.Empty() )
1819 event
.m_timeStamp
= time
;
1820 event
.SetEventObject(this);
1821 GetEventHandler()->ProcessEvent(event
);
1825 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1827 RgnHandle childupdate
= NewRgn() ;
1828 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1830 // calculate the update region for the child windows by intersecting the window rectangle with our own
1831 // passed in update region and then offset it to be client-wise window coordinates again
1832 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1833 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1834 SectRgn( childupdate
, updatergn
, childupdate
) ;
1835 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1836 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1838 // because dialogs may also be children
1839 child
->MacRedraw( childupdate
, time
, erase
) ;
1842 DisposeRgn( childupdate
) ;
1843 // eventually a draw grow box here
1847 WXHWND
wxWindowMac::MacGetRootWindow() const
1849 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1853 if ( iter
->IsTopLevel() )
1854 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1856 iter
= iter
->GetParent() ;
1858 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1862 void wxWindowMac::MacCreateScrollBars( long style
)
1864 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1866 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1867 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1869 GetClientSize( &width
, &height
) ;
1871 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1872 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1873 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1874 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1876 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1877 vSize
, wxVERTICAL
);
1879 if ( style
& wxVSCROLL
)
1885 m_vScrollBar
->Show(false) ;
1887 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1888 hSize
, wxHORIZONTAL
);
1889 if ( style
& wxHSCROLL
)
1894 m_hScrollBar
->Show(false) ;
1897 // because the create does not take into account the client area origin
1898 MacRepositionScrollBars() ; // we might have a real position shift
1901 void wxWindowMac::MacRepositionScrollBars()
1903 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1904 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1906 // get real client area
1908 int width
= m_width
;
1909 int height
= m_height
;
1911 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1912 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1914 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1915 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1916 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1917 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1924 MacClientToRootWindow( &x
, &y
) ;
1925 MacClientToRootWindow( &w
, &h
) ;
1927 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1929 int totW
= 10000 , totH
= 10000;
1932 if ( iter
->IsTopLevel() )
1934 totW
= iter
->m_width
;
1935 totH
= iter
->m_height
;
1939 iter
= iter
->GetParent() ;
1967 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1971 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1975 bool wxWindowMac::AcceptsFocus() const
1977 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1980 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1982 return GetParent()->MacGetContainerForEmbedding() ;
1985 void wxWindowMac::MacSuperChangedPosition()
1987 // only window-absolute structures have to be moved i.e. controls
1989 wxWindowListNode
*node
= GetChildren().GetFirst();
1992 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1993 child
->MacSuperChangedPosition() ;
1994 node
= node
->GetNext();
1998 void wxWindowMac::MacTopLevelWindowChangedPosition()
2000 // only screen-absolute structures have to be moved i.e. glcanvas
2002 wxWindowListNode
*node
= GetChildren().GetFirst();
2005 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
2006 child
->MacTopLevelWindowChangedPosition() ;
2007 node
= node
->GetNext();
2010 long wxWindowMac::MacGetLeftBorderSize( ) const
2015 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2018 #if wxMAC_USE_THEME_BORDER
2020 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2025 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2028 #if wxMAC_USE_THEME_BORDER
2030 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2035 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2042 long wxWindowMac::MacGetRightBorderSize( ) const
2044 // they are all symmetric in mac themes
2045 return MacGetLeftBorderSize() ;
2048 long wxWindowMac::MacGetTopBorderSize( ) const
2050 // they are all symmetric in mac themes
2051 return MacGetLeftBorderSize() ;
2054 long wxWindowMac::MacGetBottomBorderSize( ) const
2056 // they are all symmetric in mac themes
2057 return MacGetLeftBorderSize() ;
2060 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2062 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2065 // Find the wxWindowMac at the current mouse position, returning the mouse
2067 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2069 pt
= wxGetMousePosition();
2070 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2074 // Get the current mouse position.
2075 wxPoint
wxGetMousePosition()
2078 wxGetMousePosition(& x
, & y
);
2079 return wxPoint(x
, y
);
2082 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2084 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2086 // copied from wxGTK : CS
2087 // generate a "context menu" event: this is similar to wxEVT_RIGHT_UP
2090 // (a) it's a command event and so is propagated to the parent
2091 // (b) under MSW it can be generated from kbd too
2092 // (c) it uses screen coords (because of (a))
2093 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2095 this->ClientToScreen(event
.GetPosition()));
2096 this->GetEventHandler()->ProcessEvent(evtCtx
);