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
)
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
89 #define wxMAC_USE_THEME_BORDER 0
92 // ===========================================================================
94 // ===========================================================================
97 // ----------------------------------------------------------------------------
98 // constructors and such
99 // ----------------------------------------------------------------------------
101 void wxWindowMac::Init()
107 m_doubleClickAllowed
= 0;
108 m_winCaptured
= FALSE
;
110 m_isBeingDeleted
= FALSE
;
113 m_mouseInWindow
= FALSE
;
117 m_backgroundTransparent
= FALSE
;
119 // as all windows are created with WS_VISIBLE style...
127 m_hScrollBar
= NULL
;
128 m_vScrollBar
= NULL
;
130 m_label
= wxEmptyString
;
134 wxWindowMac::~wxWindowMac()
138 // deleting a window while it is shown invalidates the region
140 wxWindowMac
* iter
= this ;
142 if ( iter
->IsTopLevel() )
147 iter
= iter
->GetParent() ;
152 m_isBeingDeleted
= TRUE
;
154 #ifndef __WXUNIVERSAL__
155 // VS: make sure there's no wxFrame with last focus set to us:
156 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
158 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
161 if ( frame
->GetLastFocus() == this )
163 frame
->SetLastFocus((wxWindow
*)NULL
);
168 #endif // __WXUNIVERSAL__
170 if ( s_lastMouseWindow
== this )
172 s_lastMouseWindow
= NULL
;
175 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
178 if ( frame
->GetLastFocus() == this )
179 frame
->SetLastFocus( NULL
) ;
182 if ( gFocusWindow
== this )
184 gFocusWindow
= NULL
;
187 // CS: copied from MSW :
188 // VS: destroy children first and _then_ detach *this from its parent.
189 // If we'd do it the other way around, children wouldn't be able
190 // find their parent frame (see above).
194 m_parent
->RemoveChild(this);
196 wxWindowDestroyEvent
event((wxWindow
*)this);
197 (void)GetEventHandler()->ProcessEvent(event
);
199 // delete our drop target if we've got one
200 #if wxUSE_DRAG_AND_DROP
201 if ( m_dropTarget
!= NULL
)
206 #endif // wxUSE_DRAG_AND_DROP
210 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
214 const wxString
& name
)
216 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
219 // wxGTK doesn't allow to create controls with static box as the parent so
220 // this will result in a crash when the program is ported to wxGTK - warn
223 // the correct solution is to create the controls as siblings of the
225 wxASSERT_MSG( !wxDynamicCast(parent
, wxStaticBox
),
226 _T("wxStaticBox can't be used as a window parent!") );
227 #endif // wxUSE_STATBOX
229 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
232 parent
->AddChild(this);
236 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
237 m_width
= WidthDefault( size
.x
);
238 m_height
= HeightDefault( size
.y
) ;
239 #ifndef __WXUNIVERSAL__
240 // Don't give scrollbars to wxControls unless they ask for them
241 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
242 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
244 MacCreateScrollBars( style
) ;
250 void wxWindowMac::SetFocus()
252 if ( gFocusWindow
== this )
255 if ( AcceptsFocus() )
261 if ( gFocusWindow
->m_caret
)
263 gFocusWindow
->m_caret
->OnKillFocus();
265 #endif // wxUSE_CARET
266 #ifndef __WXUNIVERSAL__
267 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
268 if ( control
&& control
->GetMacControl() )
270 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNoPart
) ;
271 control
->MacRedrawControl() ;
274 // Without testing the window id, for some reason
275 // a kill focus event can still be sent to
276 // the control just being focussed.
277 int thisId
= this->m_windowId
;
278 int gFocusWindowId
= gFocusWindow
->m_windowId
;
279 if (gFocusWindowId
!= thisId
)
281 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
282 event
.SetEventObject(gFocusWindow
);
283 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
286 gFocusWindow
= this ;
292 m_caret
->OnSetFocus();
294 #endif // wxUSE_CARET
295 // panel wants to track the window which was the last to have focus in it
296 wxChildFocusEvent
eventFocus(this);
297 GetEventHandler()->ProcessEvent(eventFocus
);
299 #ifndef __WXUNIVERSAL__
300 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
301 if ( control
&& control
->GetMacControl() )
303 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetRootWindow() , (ControlHandle
) control
->GetMacControl() , kControlFocusNextPart
) ;
306 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
307 event
.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(event
) ;
313 bool wxWindowMac::Enable(bool enable
)
315 if ( !wxWindowBase::Enable(enable
) )
318 MacSuperEnabled( enable
) ;
323 void wxWindowMac::DoCaptureMouse()
325 wxTheApp
->s_captureWindow
= this ;
328 wxWindow
* wxWindowBase::GetCapture()
330 return wxTheApp
->s_captureWindow
;
333 void wxWindowMac::DoReleaseMouse()
335 wxTheApp
->s_captureWindow
= NULL
;
338 #if wxUSE_DRAG_AND_DROP
340 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
342 if ( m_dropTarget
!= 0 ) {
346 m_dropTarget
= pDropTarget
;
347 if ( m_dropTarget
!= 0 )
355 // Old style file-manager drag&drop
356 void wxWindowMac::DragAcceptFiles(bool accept
)
362 void wxWindowMac::DoGetSize(int *x
, int *y
) const
365 if(y
) *y
= m_height
;
368 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
374 if ( !IsTopLevel() && GetParent())
376 wxPoint
pt(GetParent()->GetClientAreaOrigin());
385 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
387 menu
->SetInvokingWindow(this);
389 ClientToScreen( &x
, &y
) ;
391 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
392 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
393 if ( HiWord(menuResult
) != 0 )
396 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
398 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
399 event
.m_timeStamp
= TickCount() ;
400 event
.SetEventObject(this->GetEventHandler());
402 GetEventHandler()->ProcessEvent(event
);
404 ::DeleteMenu( menu
->MacGetMenuId() ) ;
405 menu
->SetInvokingWindow(NULL
);
411 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
413 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
415 Point localwhere
= {0,0} ;
417 if(x
) localwhere
.h
= * x
;
418 if(y
) localwhere
.v
= * y
;
422 ::SetPort( UMAGetWindowPort( window
) ) ;
423 ::GlobalToLocal( &localwhere
) ;
426 if(x
) *x
= localwhere
.h
;
427 if(y
) *y
= localwhere
.v
;
429 MacRootWindowToWindow( x
, y
) ;
431 *x
-= MacGetLeftBorderSize() ;
433 *y
-= MacGetTopBorderSize() ;
436 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
438 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
441 *x
+= MacGetLeftBorderSize() ;
443 *y
+= MacGetTopBorderSize() ;
445 MacWindowToRootWindow( x
, y
) ;
447 Point localwhere
= { 0,0 };
448 if(x
) localwhere
.h
= * x
;
449 if(y
) localwhere
.v
= * y
;
453 ::SetPort( UMAGetWindowPort( window
) ) ;
455 ::LocalToGlobal( &localwhere
) ;
457 if(x
) *x
= localwhere
.h
;
458 if(y
) *y
= localwhere
.v
;
461 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
463 wxPoint origin
= GetClientAreaOrigin() ;
464 if(x
) *x
+= origin
.x
;
465 if(y
) *y
+= origin
.y
;
467 MacWindowToRootWindow( x
, y
) ;
470 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
472 wxPoint origin
= GetClientAreaOrigin() ;
473 MacRootWindowToWindow( x
, y
) ;
474 if(x
) *x
-= origin
.x
;
475 if(y
) *y
-= origin
.y
;
478 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
484 GetParent()->MacWindowToRootWindow( x
, y
) ;
488 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
494 GetParent()->MacRootWindowToWindow( x
, y
) ;
498 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
500 if (m_cursor
== cursor
)
503 if (wxNullCursor
== cursor
)
505 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
510 if ( ! wxWindowBase::SetCursor( cursor
) )
514 wxASSERT_MSG( m_cursor
.Ok(),
515 wxT("cursor must be valid after call to the base version"));
518 wxWindowMac
*mouseWin
;
521 // Change the cursor NOW if we're within the correct window
523 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
525 if ( mouseWin
== this && !wxIsBusy() )
527 m_cursor
.MacInstall() ;
535 // Get size *available for subwindows* i.e. excluding menu bar etc.
536 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
542 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
543 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
545 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
552 MacClientToRootWindow( &x1
, &y1
) ;
553 MacClientToRootWindow( &w
, &h
) ;
555 wxWindowMac
*iter
= (wxWindowMac
*)this ;
557 int totW
= 10000 , totH
= 10000;
560 if ( iter
->IsTopLevel() )
562 totW
= iter
->m_width
;
563 totH
= iter
->m_height
;
567 iter
= iter
->GetParent() ;
570 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
572 hh
-= MAC_SCROLLBAR_SIZE
;
578 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
580 ww
-= MAC_SCROLLBAR_SIZE
;
592 // ----------------------------------------------------------------------------
594 // ----------------------------------------------------------------------------
598 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
600 wxWindowBase::DoSetToolTip(tooltip
);
603 m_tooltip
->SetWindow(this);
606 #endif // wxUSE_TOOLTIPS
608 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
612 int former_w
= m_width
;
613 int former_h
= m_height
;
615 int actualWidth
= width
;
616 int actualHeight
= height
;
620 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
621 actualWidth
= m_minWidth
;
622 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
623 actualHeight
= m_minHeight
;
624 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
625 actualWidth
= m_maxWidth
;
626 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
627 actualHeight
= m_maxHeight
;
629 bool doMove
= false ;
630 bool doResize
= false ;
632 if ( actualX
!= former_x
|| actualY
!= former_y
)
636 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
641 if ( doMove
|| doResize
)
643 // erase former position
645 bool partialRepaint
= false ;
647 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
649 wxPoint
oldPos( m_x
, m_y
) ;
650 wxPoint
newPos( actualX
, actualY
) ;
651 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
652 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
653 if ( oldPos
== newPos
)
655 partialRepaint
= true ;
656 RgnHandle oldRgn
,newRgn
,diffRgn
;
660 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
661 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
662 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
663 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
664 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
665 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
668 DisposeRgn(diffRgn
) ;
672 if ( !partialRepaint
)
677 m_width
= actualWidth
;
678 m_height
= actualHeight
;
680 // update any low-level frame-relative positions
682 MacUpdateDimensions() ;
683 // erase new position
685 if ( !partialRepaint
)
688 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
690 MacRepositionScrollBars() ;
693 wxPoint
point(m_x
, m_y
);
694 wxMoveEvent
event(point
, m_windowId
);
695 event
.SetEventObject(this);
696 GetEventHandler()->ProcessEvent(event
) ;
700 MacRepositionScrollBars() ;
701 wxSize
size(m_width
, m_height
);
702 wxSizeEvent
event(size
, m_windowId
);
703 event
.SetEventObject(this);
704 GetEventHandler()->ProcessEvent(event
);
710 // set the size of the window: if the dimensions are positive, just use them,
711 // but if any of them is equal to -1, it means that we must find the value for
712 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
713 // which case -1 is a valid value for x and y)
715 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
716 // the width/height to best suit our contents, otherwise we reuse the current
718 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
720 // get the current size and position...
721 int currentX
, currentY
;
722 GetPosition(¤tX
, ¤tY
);
724 int currentW
,currentH
;
725 GetSize(¤tW
, ¤tH
);
727 // ... and don't do anything (avoiding flicker) if it's already ok
728 if ( x
== currentX
&& y
== currentY
&&
729 width
== currentW
&& height
== currentH
)
731 MacRepositionScrollBars() ; // we might have a real position shift
735 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
737 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
740 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
745 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
747 size
= DoGetBestSize();
752 // just take the current one
759 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
763 size
= DoGetBestSize();
765 //else: already called DoGetBestSize() above
771 // just take the current one
776 DoMoveWindow(x
, y
, width
, height
);
779 // For implementation purposes - sometimes decorations make the client area
782 wxPoint
wxWindowMac::GetClientAreaOrigin() const
784 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
787 void wxWindowMac::SetTitle(const wxString
& title
)
792 wxString
wxWindowMac::GetTitle() const
797 bool wxWindowMac::Show(bool show
)
799 if ( !wxWindowBase::Show(show
) )
803 WindowRef window = (WindowRef) MacGetRootWindow() ;
804 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
805 if ( win == NULL && win->m_isBeingDeleted )
808 MacSuperShown( show
) ;
813 if ( win && !win->m_isBeingDeleted )
824 void wxWindowMac::MacSuperShown( bool show
)
826 wxWindowListNode
*node
= GetChildren().GetFirst();
829 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
830 if ( child
->m_isShown
)
831 child
->MacSuperShown( show
) ;
832 node
= node
->GetNext();
836 void wxWindowMac::MacSuperEnabled( bool enabled
)
840 // to be absolutely correct we'd have to invalidate (with eraseBkground
841 // because unter MacOSX the frames are drawn with an addXXX mode)
844 wxWindowListNode
*node
= GetChildren().GetFirst();
847 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
848 if ( child
->m_isShown
)
849 child
->MacSuperEnabled( enabled
) ;
850 node
= node
->GetNext();
854 bool wxWindowMac::MacIsReallyShown() const
856 if ( m_isShown
&& (m_parent
!= NULL
) ) {
857 return m_parent
->MacIsReallyShown();
861 bool status = m_isShown ;
862 wxWindowMac * win = this ;
863 while ( status && win->m_parent != NULL )
865 win = win->m_parent ;
866 status = win->m_isShown ;
872 int wxWindowMac::GetCharHeight() const
874 wxClientDC
dc ( (wxWindowMac
*)this ) ;
875 return dc
.GetCharHeight() ;
878 int wxWindowMac::GetCharWidth() const
880 wxClientDC
dc ( (wxWindowMac
*)this ) ;
881 return dc
.GetCharWidth() ;
884 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
885 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
887 const wxFont
*fontToUse
= theFont
;
891 wxClientDC
dc( (wxWindowMac
*) this ) ;
893 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
894 if ( externalLeading
)
895 *externalLeading
= le
;
905 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
906 * we always intersect with the entire window, not only with the client area
909 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
911 if ( MacGetTopLevelWindow() == NULL
)
914 wxPoint client
= GetClientAreaOrigin();
917 int x2
= m_width
- client
.x
;
918 int y2
= m_height
- client
.y
;
920 if (IsKindOf( CLASSINFO(wxButton
)))
922 // buttons have an "aura"
929 Rect clientrect
= { y1
, x1
, y2
, x2
};
933 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
934 SectRect( &clientrect
, &r
, &clientrect
) ;
937 if ( !EmptyRect( &clientrect
) )
939 int top
= 0 , left
= 0 ;
941 MacClientToRootWindow( &left
, &top
) ;
942 OffsetRect( &clientrect
, left
, top
) ;
944 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
948 #if wxUSE_CARET && WXWIN_COMPATIBILITY
949 // ---------------------------------------------------------------------------
950 // Caret manipulation
951 // ---------------------------------------------------------------------------
953 void wxWindowMac::CreateCaret(int w
, int h
)
955 SetCaret(new wxCaret(this, w
, h
));
958 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
960 wxFAIL_MSG("not implemented");
963 void wxWindowMac::ShowCaret(bool show
)
965 wxCHECK_RET( m_caret
, "no caret to show" );
970 void wxWindowMac::DestroyCaret()
975 void wxWindowMac::SetCaretPos(int x
, int y
)
977 wxCHECK_RET( m_caret
, "no caret to move" );
982 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
984 wxCHECK_RET( m_caret
, "no caret to get position of" );
986 m_caret
->GetPosition(x
, y
);
988 #endif // wxUSE_CARET
990 wxWindowMac
*wxGetActiveWindow()
992 // actually this is a windows-only concept
996 // Coordinates relative to the window
997 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
999 // We really don't move the mouse programmatically under Mac.
1002 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
1004 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1006 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
1008 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1010 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1011 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1012 // either a non gray background color or a non control window
1014 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1016 wxWindowMac
* parent
= GetParent() ;
1019 if ( parent
->MacGetRootWindow() != window
)
1021 // we are in a different window on the mac system
1027 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1028 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1030 // if we have any other colours in the hierarchy
1031 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1034 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1035 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1037 Rect extent
= { 0 , 0 , 0 , 0 } ;
1040 wxSize size
= parent
->GetSize() ;
1041 parent
->MacClientToRootWindow( &x
, &y
) ;
1045 extent
.right
= x
+ size
.x
;
1046 extent
.bottom
= y
+ size
.y
;
1047 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1051 parent
= parent
->GetParent() ;
1055 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1060 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1063 return m_macBackgroundBrush
;
1066 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1068 event
.GetDC()->Clear() ;
1071 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1073 wxWindowDC
dc(this) ;
1074 wxMacPortSetter
helper(&dc
) ;
1076 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1079 int wxWindowMac::GetScrollPos(int orient
) const
1081 if ( orient
== wxHORIZONTAL
)
1084 return m_hScrollBar
->GetThumbPosition() ;
1089 return m_vScrollBar
->GetThumbPosition() ;
1094 // This now returns the whole range, not just the number
1095 // of positions that we can scroll.
1096 int wxWindowMac::GetScrollRange(int orient
) const
1098 if ( orient
== wxHORIZONTAL
)
1101 return m_hScrollBar
->GetRange() ;
1106 return m_vScrollBar
->GetRange() ;
1111 int wxWindowMac::GetScrollThumb(int orient
) const
1113 if ( orient
== wxHORIZONTAL
)
1116 return m_hScrollBar
->GetThumbSize() ;
1121 return m_vScrollBar
->GetThumbSize() ;
1126 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1128 if ( orient
== wxHORIZONTAL
)
1131 m_hScrollBar
->SetThumbPosition( pos
) ;
1136 m_vScrollBar
->SetThumbPosition( pos
) ;
1140 void wxWindowMac::MacPaintBorders( int left
, int top
)
1145 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1146 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1147 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1148 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1151 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1153 #if wxMAC_USE_THEME_BORDER
1154 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1157 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1158 InsetRect( &rect , border , border );
1159 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1162 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1164 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1165 RGBForeColor( &face
);
1166 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1167 LineTo( left
+ 0 , top
+ 0 );
1168 LineTo( left
+ m_width
- 2 , top
+ 0 );
1170 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1171 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1172 LineTo( left
+ m_width
- 3 , top
+ 2 );
1174 RGBForeColor( sunken
? &face
: &black
);
1175 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1176 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1177 LineTo( left
+ m_width
- 1 , top
+ 0 );
1179 RGBForeColor( sunken
? &shadow
: &white
);
1180 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1181 LineTo( left
+ 1, top
+ 1 );
1182 LineTo( left
+ m_width
- 3 , top
+ 1 );
1184 RGBForeColor( sunken
? &white
: &shadow
);
1185 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1186 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1187 LineTo( left
+ m_width
- 2 , top
+ 1 );
1189 RGBForeColor( sunken
? &black
: &face
);
1190 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1191 LineTo( left
+ 2 , top
+ 2 );
1192 LineTo( left
+ m_width
- 4 , top
+ 2 );
1195 else if (HasFlag(wxSIMPLE_BORDER
))
1197 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1198 RGBForeColor( &black
) ;
1199 FrameRect( &rect
) ;
1203 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1205 if ( child
== m_hScrollBar
)
1206 m_hScrollBar
= NULL
;
1207 if ( child
== m_vScrollBar
)
1208 m_vScrollBar
= NULL
;
1210 wxWindowBase::RemoveChild( child
) ;
1213 // New function that will replace some of the above.
1214 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1215 int range
, bool refresh
)
1217 if ( orient
== wxHORIZONTAL
)
1221 if ( range
== 0 || thumbVisible
>= range
)
1223 if ( m_hScrollBar
->IsShown() )
1224 m_hScrollBar
->Show(false) ;
1228 if ( !m_hScrollBar
->IsShown() )
1229 m_hScrollBar
->Show(true) ;
1230 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1238 if ( range
== 0 || thumbVisible
>= range
)
1240 if ( m_vScrollBar
->IsShown() )
1241 m_vScrollBar
->Show(false) ;
1245 if ( !m_vScrollBar
->IsShown() )
1246 m_vScrollBar
->Show(true) ;
1247 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1251 MacRepositionScrollBars() ;
1254 // Does a physical scroll
1255 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1257 wxClientDC
dc(this) ;
1258 wxMacPortSetter
helper(&dc
) ;
1261 int width
, height
;
1262 GetClientSize( &width
, &height
) ;
1264 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1265 RgnHandle updateRgn
= NewRgn() ;
1266 ClipRect( &scrollrect
) ;
1269 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1270 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1271 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1273 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1274 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1275 DisposeRgn( updateRgn
) ;
1278 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1280 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1281 if (child
== m_vScrollBar
) continue;
1282 if (child
== m_hScrollBar
) continue;
1283 if (child
->IsTopLevel()) continue;
1286 child
->GetPosition( &x
, &y
);
1288 child
->GetSize( &w
, &h
);
1289 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1294 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1296 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1298 wxScrollWinEvent wevent
;
1299 wevent
.SetPosition(event
.GetPosition());
1300 wevent
.SetOrientation(event
.GetOrientation());
1301 wevent
.m_eventObject
= this;
1303 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1304 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1306 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1307 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1309 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1310 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1312 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1313 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1315 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1316 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1318 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1319 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1321 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1322 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1325 GetEventHandler()->ProcessEvent(wevent
);
1329 // Get the window with the focus
1330 wxWindowMac
*wxWindowBase::FindFocus()
1332 return gFocusWindow
;
1335 #if WXWIN_COMPATIBILITY
1336 // If nothing defined for this, try the parent.
1337 // E.g. we may be a button loaded from a resource, with no callback function
1339 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1341 if ( GetEventHandler()->ProcessEvent(event
) )
1344 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1346 #endif // WXWIN_COMPATIBILITY_2
1348 #if WXWIN_COMPATIBILITY
1349 wxObject
* wxWindowMac::GetChild(int number
) const
1351 // Return a pointer to the Nth object in the Panel
1352 wxNode
*node
= GetChildren().GetFirst();
1355 node
= node
->GetNext();
1358 wxObject
*obj
= (wxObject
*)node
->GetData();
1364 #endif // WXWIN_COMPATIBILITY
1366 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1368 // panel wants to track the window which was the last to have focus in it,
1369 // so we want to set ourselves as the window which last had focus
1371 // notice that it's also important to do it upwards the tree becaus
1372 // otherwise when the top level panel gets focus, it won't set it back to
1373 // us, but to some other sibling
1375 // CS:don't know if this is still needed:
1376 //wxChildFocusEvent eventFocus(this);
1377 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1382 void wxWindowMac::Clear()
1384 wxClientDC
dc(this);
1385 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1386 dc
.SetBackground(brush
);
1390 // Setup background and foreground colours correctly
1391 void wxWindowMac::SetupColours()
1394 SetBackgroundColour(GetParent()->GetBackgroundColour());
1397 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1400 // Check if we need to send a LEAVE event
1401 if (m_mouseInWindow)
1404 ::GetCursorPos(&pt);
1405 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1407 // Generate a LEAVE event
1408 m_mouseInWindow = FALSE;
1409 MSWOnMouseLeave(pt.x, pt.y, 0);
1414 // This calls the UI-update mechanism (querying windows for
1415 // menu/toolbar/control state information)
1419 // Raise the window to the top of the Z order
1420 void wxWindowMac::Raise()
1424 // Lower the window to the bottom of the Z order
1425 void wxWindowMac::Lower()
1429 void wxWindowMac::DoSetClientSize(int width
, int height
)
1431 if ( width
!= -1 || height
!= -1 )
1434 if ( width
!= -1 && m_vScrollBar
)
1435 width
+= MAC_SCROLLBAR_SIZE
;
1436 if ( height
!= -1 && m_vScrollBar
)
1437 height
+= MAC_SCROLLBAR_SIZE
;
1439 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1440 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1442 DoSetSize( -1 , -1 , width
, height
) ;
1447 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1449 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1453 if ((point
.x
< 0) || (point
.y
< 0) ||
1454 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1459 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1460 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1464 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1466 wxPoint
newPoint( point
) ;
1468 if ( !IsTopLevel() )
1474 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1476 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1477 // added the m_isShown test --dmazzoni
1478 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1480 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1489 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1493 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1494 if ( ::FindWindow( pt
, &window
) == 3 )
1497 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1500 // No, this yields the CLIENT are, we need the whole frame. RR.
1501 // point = win->ScreenToClient( point ) ;
1504 ::GetPort( &port
) ;
1505 ::SetPort( UMAGetWindowPort( window
) ) ;
1506 ::GlobalToLocal( &pt
) ;
1509 wxPoint
point( pt
.h
, pt
.v
) ;
1511 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1517 static wxWindow
*gs_lastWhich
= NULL
;
1519 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1521 // first trigger a set cursor event
1523 wxPoint clientorigin
= GetClientAreaOrigin() ;
1524 wxSize clientsize
= GetClientSize() ;
1526 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1528 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1530 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1531 if ( processedEvtSetCursor
&& event
.HasCursor() )
1533 cursor
= event
.GetCursor() ;
1538 // the test for processedEvtSetCursor is here to prevent using m_cursor
1539 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1540 // it - this is a way to say that our cursor shouldn't be used for this
1542 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1552 cursor
= *wxSTANDARD_CURSOR
;
1556 cursor
.MacInstall() ;
1558 return cursor
.Ok() ;
1561 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1563 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1564 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1568 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1571 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1579 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1581 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1582 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1584 if (child
->MacDispatchMouseEvent(event
))
1589 wxWindow
* cursorTarget
= this ;
1590 wxPoint
cursorPoint( x
, y
) ;
1592 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1594 cursorTarget
= cursorTarget
->GetParent() ;
1596 cursorPoint
+= cursorTarget
->GetPosition() ;
1600 event
.SetEventObject( this ) ;
1602 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1604 // set focus to this window
1605 if (AcceptsFocus() && FindFocus()!=this)
1610 if ( event
.GetEventType() == wxEVT_MOTION
1611 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1612 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1613 wxToolTip::RelayEvent( this , event
);
1614 #endif // wxUSE_TOOLTIPS
1616 if (gs_lastWhich
!= this)
1618 gs_lastWhich
= this;
1620 // Double clicks must always occur on the same window
1621 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1622 event
.SetEventType( wxEVT_LEFT_DOWN
);
1623 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1624 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1626 // Same for mouse up events
1627 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1629 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1633 GetEventHandler()->ProcessEvent( event
) ;
1638 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1642 return m_tooltip
->GetTip() ;
1647 void wxWindowMac::Update()
1649 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1652 win
->MacUpdate( 0 ) ;
1653 #if TARGET_API_MAC_CARBON
1654 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1656 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1662 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1664 wxTopLevelWindowMac
* win
= NULL
;
1665 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1668 win
= wxFindWinFromMacWindow( window
) ;
1673 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1675 RgnHandle visRgn
= NewRgn() ;
1676 RgnHandle tempRgn
= NewRgn() ;
1677 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1679 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1681 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1682 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1684 int borderTop
= 14 ;
1685 int borderOther
= 4 ;
1687 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1688 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1691 if ( !IsTopLevel() )
1693 wxWindow
* parent
= GetParent() ;
1696 wxSize size
= parent
->GetSize() ;
1699 parent
->MacWindowToRootWindow( &x
, &y
) ;
1700 MacRootWindowToWindow( &x
, &y
) ;
1702 SetRectRgn( tempRgn
,
1703 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1704 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1705 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1707 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1708 if ( parent
->IsTopLevel() )
1710 parent
= parent
->GetParent() ;
1713 if ( respectChildrenAndSiblings
)
1715 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1717 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1719 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1721 if ( !child
->IsTopLevel() && child
->IsShown() )
1723 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1724 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1726 int borderTop
= 14 ;
1727 int borderOther
= 4 ;
1729 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1730 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1732 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1737 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1739 bool thisWindowThrough
= false ;
1740 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1742 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1743 if ( sibling
== this )
1745 thisWindowThrough
= true ;
1748 if( !thisWindowThrough
)
1753 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1755 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
) ;
1756 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1758 int borderTop
= 14 ;
1759 int borderOther
= 4 ;
1761 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
) ;
1762 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1764 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1769 m_macVisibleRegion
= visRgn
;
1770 DisposeRgn( visRgn
) ;
1771 DisposeRgn( tempRgn
) ;
1772 DisposeRgn( tempStaticBoxRgn
) ;
1773 return m_macVisibleRegion
;
1776 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1778 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1779 // updatergn is always already clipped to our boundaries
1780 // it is in window coordinates, not in client coordinates
1782 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1785 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1786 RgnHandle ownUpdateRgn
= NewRgn() ;
1787 CopyRgn( updatergn
, ownUpdateRgn
) ;
1789 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1791 // newupdate is the update region in client coordinates
1792 RgnHandle newupdate
= NewRgn() ;
1793 wxSize point
= GetClientSize() ;
1794 wxPoint origin
= GetClientAreaOrigin() ;
1795 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1796 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1797 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1798 m_updateRegion
= newupdate
;
1799 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1801 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1803 wxWindowDC
dc(this);
1804 if (!EmptyRgn(ownUpdateRgn
))
1805 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1806 wxEraseEvent
eevent( GetId(), &dc
);
1807 eevent
.SetEventObject( this );
1808 GetEventHandler()->ProcessEvent( eevent
);
1810 wxNcPaintEvent
eventNc( GetId() );
1811 eventNc
.SetEventObject( this );
1812 GetEventHandler()->ProcessEvent( eventNc
);
1814 DisposeRgn( ownUpdateRgn
) ;
1815 if ( !m_updateRegion
.Empty() )
1818 event
.m_timeStamp
= time
;
1819 event
.SetEventObject(this);
1820 GetEventHandler()->ProcessEvent(event
);
1824 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1826 RgnHandle childupdate
= NewRgn() ;
1827 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1829 // calculate the update region for the child windows by intersecting the window rectangle with our own
1830 // passed in update region and then offset it to be client-wise window coordinates again
1831 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1832 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1833 SectRgn( childupdate
, updatergn
, childupdate
) ;
1834 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1835 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1837 // because dialogs may also be children
1838 child
->MacRedraw( childupdate
, time
, erase
) ;
1841 DisposeRgn( childupdate
) ;
1842 // eventually a draw grow box here
1846 WXHWND
wxWindowMac::MacGetRootWindow() const
1848 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1852 if ( iter
->IsTopLevel() )
1853 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1855 iter
= iter
->GetParent() ;
1857 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1861 void wxWindowMac::MacCreateScrollBars( long style
)
1863 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1865 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1866 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1868 GetClientSize( &width
, &height
) ;
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
) ;
1875 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1876 vSize
, wxVERTICAL
);
1878 if ( style
& wxVSCROLL
)
1884 m_vScrollBar
->Show(false) ;
1886 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1887 hSize
, wxHORIZONTAL
);
1888 if ( style
& wxHSCROLL
)
1893 m_hScrollBar
->Show(false) ;
1896 // because the create does not take into account the client area origin
1897 MacRepositionScrollBars() ; // we might have a real position shift
1900 void wxWindowMac::MacRepositionScrollBars()
1902 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1903 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1905 // get real client area
1907 int width
= m_width
;
1908 int height
= m_height
;
1910 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1911 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1913 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1914 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1915 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1916 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1923 MacClientToRootWindow( &x
, &y
) ;
1924 MacClientToRootWindow( &w
, &h
) ;
1926 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1928 int totW
= 10000 , totH
= 10000;
1931 if ( iter
->IsTopLevel() )
1933 totW
= iter
->m_width
;
1934 totH
= iter
->m_height
;
1938 iter
= iter
->GetParent() ;
1966 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1970 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1974 bool wxWindowMac::AcceptsFocus() const
1976 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1979 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
1981 return GetParent()->MacGetContainerForEmbedding() ;
1984 void wxWindowMac::MacSuperChangedPosition()
1986 // only window-absolute structures have to be moved i.e. controls
1988 wxWindowListNode
*node
= GetChildren().GetFirst();
1991 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1992 child
->MacSuperChangedPosition() ;
1993 node
= node
->GetNext();
1997 void wxWindowMac::MacTopLevelWindowChangedPosition()
1999 // only screen-absolute structures have to be moved i.e. glcanvas
2001 wxWindowListNode
*node
= GetChildren().GetFirst();
2004 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
2005 child
->MacTopLevelWindowChangedPosition() ;
2006 node
= node
->GetNext();
2009 long wxWindowMac::MacGetLeftBorderSize( ) const
2014 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2017 #if wxMAC_USE_THEME_BORDER
2019 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2024 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2027 #if wxMAC_USE_THEME_BORDER
2029 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2034 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2041 long wxWindowMac::MacGetRightBorderSize( ) const
2043 // they are all symmetric in mac themes
2044 return MacGetLeftBorderSize() ;
2047 long wxWindowMac::MacGetTopBorderSize( ) const
2049 // they are all symmetric in mac themes
2050 return MacGetLeftBorderSize() ;
2053 long wxWindowMac::MacGetBottomBorderSize( ) const
2055 // they are all symmetric in mac themes
2056 return MacGetLeftBorderSize() ;
2059 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2061 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2064 // Find the wxWindowMac at the current mouse position, returning the mouse
2066 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2068 pt
= wxGetMousePosition();
2069 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2073 // Get the current mouse position.
2074 wxPoint
wxGetMousePosition()
2077 wxGetMousePosition(& x
, & y
);
2078 return wxPoint(x
, y
);