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 wxArrayPtrVoid submenus
;
390 wxMenuItemList::Node
*node
;
393 for (pos
= 0, node
= menu
->GetMenuItems().GetFirst(); node
; node
= node
->GetNext(), pos
++)
395 item
= (wxMenuItem
*)node
->GetData();
396 wxMenu
* subMenu
= item
->GetSubMenu() ;
399 submenus
.Add(subMenu
) ;
403 ::InsertMenu( (MenuHandle
) menu
->GetHMenu() , -1 ) ;
405 for ( size_t i
= 0 ; i
< submenus
.GetCount() ; ++i
)
407 wxMenu
* submenu
= (wxMenu
*) submenus
[i
] ;
408 wxMenuItemList::Node
*subnode
;
411 for ( subpos
= 0 , subnode
= submenu
->GetMenuItems().GetFirst(); subnode
; subnode
= subnode
->GetNext(), subpos
++)
413 subitem
= (wxMenuItem
*)subnode
->GetData();
414 wxMenu
* itsSubMenu
= subitem
->GetSubMenu() ;
417 submenus
.Add(itsSubMenu
) ;
420 ::InsertMenu( MAC_WXHMENU(submenu
->GetHMenu()) , -1 ) ;
423 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
424 if ( HiWord(menuResult
) != 0 )
427 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
428 wxMenuItem
* item
= NULL
;
430 item
= menu
->FindItem(id
, &realmenu
) ;
431 if (item
->IsCheckable())
433 item
->Check( !item
->IsChecked() ) ;
435 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
437 ::DeleteMenu( menu
->MacGetMenuId() ) ;
438 for ( size_t i
= 0 ; i
< submenus
.GetCount() ; ++i
)
440 wxMenu
* submenu
= (wxMenu
*) submenus
[i
] ;
441 ::DeleteMenu( submenu
->MacGetMenuId() ) ;
444 menu
->SetInvokingWindow(NULL
);
450 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
452 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
454 Point localwhere
= {0,0} ;
456 if(x
) localwhere
.h
= * x
;
457 if(y
) localwhere
.v
= * y
;
461 ::SetPort( UMAGetWindowPort( window
) ) ;
462 ::GlobalToLocal( &localwhere
) ;
465 if(x
) *x
= localwhere
.h
;
466 if(y
) *y
= localwhere
.v
;
468 MacRootWindowToWindow( x
, y
) ;
470 *x
-= MacGetLeftBorderSize() ;
472 *y
-= MacGetTopBorderSize() ;
475 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
477 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
480 *x
+= MacGetLeftBorderSize() ;
482 *y
+= MacGetTopBorderSize() ;
484 MacWindowToRootWindow( x
, y
) ;
486 Point localwhere
= { 0,0 };
487 if(x
) localwhere
.h
= * x
;
488 if(y
) localwhere
.v
= * y
;
492 ::SetPort( UMAGetWindowPort( window
) ) ;
494 ::LocalToGlobal( &localwhere
) ;
496 if(x
) *x
= localwhere
.h
;
497 if(y
) *y
= localwhere
.v
;
500 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
502 wxPoint origin
= GetClientAreaOrigin() ;
503 if(x
) *x
+= origin
.x
;
504 if(y
) *y
+= origin
.y
;
506 MacWindowToRootWindow( x
, y
) ;
509 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
511 wxPoint origin
= GetClientAreaOrigin() ;
512 MacRootWindowToWindow( x
, y
) ;
513 if(x
) *x
-= origin
.x
;
514 if(y
) *y
-= origin
.y
;
517 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
523 GetParent()->MacWindowToRootWindow( x
, y
) ;
527 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
533 GetParent()->MacRootWindowToWindow( x
, y
) ;
537 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
539 if (m_cursor
== cursor
)
542 if (wxNullCursor
== cursor
)
544 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
549 if ( ! wxWindowBase::SetCursor( cursor
) )
553 wxASSERT_MSG( m_cursor
.Ok(),
554 wxT("cursor must be valid after call to the base version"));
557 wxWindowMac
*mouseWin
;
560 // Change the cursor NOW if we're within the correct window
562 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
564 if ( mouseWin
== this && !wxIsBusy() )
566 m_cursor
.MacInstall() ;
574 // Get size *available for subwindows* i.e. excluding menu bar etc.
575 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
581 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
582 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
584 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
591 MacClientToRootWindow( &x1
, &y1
) ;
592 MacClientToRootWindow( &w
, &h
) ;
594 wxWindowMac
*iter
= (wxWindowMac
*)this ;
596 int totW
= 10000 , totH
= 10000;
599 if ( iter
->IsTopLevel() )
601 totW
= iter
->m_width
;
602 totH
= iter
->m_height
;
606 iter
= iter
->GetParent() ;
609 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
611 hh
-= MAC_SCROLLBAR_SIZE
;
617 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
619 ww
-= MAC_SCROLLBAR_SIZE
;
631 // ----------------------------------------------------------------------------
633 // ----------------------------------------------------------------------------
637 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
639 wxWindowBase::DoSetToolTip(tooltip
);
642 m_tooltip
->SetWindow(this);
645 #endif // wxUSE_TOOLTIPS
647 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
651 int former_w
= m_width
;
652 int former_h
= m_height
;
654 int actualWidth
= width
;
655 int actualHeight
= height
;
659 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
660 actualWidth
= m_minWidth
;
661 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
662 actualHeight
= m_minHeight
;
663 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
664 actualWidth
= m_maxWidth
;
665 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
666 actualHeight
= m_maxHeight
;
668 bool doMove
= false ;
669 bool doResize
= false ;
671 if ( actualX
!= former_x
|| actualY
!= former_y
)
675 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
680 if ( doMove
|| doResize
)
682 // erase former position
684 bool partialRepaint
= false ;
686 if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE
) )
688 wxPoint
oldPos( m_x
, m_y
) ;
689 wxPoint
newPos( actualX
, actualY
) ;
690 MacWindowToRootWindow( &oldPos
.x
, &oldPos
.y
) ;
691 MacWindowToRootWindow( &newPos
.x
, &newPos
.y
) ;
692 if ( oldPos
== newPos
)
694 partialRepaint
= true ;
695 RgnHandle oldRgn
,newRgn
,diffRgn
;
699 SetRectRgn(oldRgn
, oldPos
.x
, oldPos
.y
, oldPos
.x
+ m_width
, oldPos
.y
+ m_height
) ;
700 SetRectRgn(newRgn
, newPos
.x
, newPos
.y
, newPos
.x
+ actualWidth
, newPos
.y
+ actualHeight
) ;
701 DiffRgn( newRgn
, oldRgn
, diffRgn
) ;
702 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
703 DiffRgn( oldRgn
, newRgn
, diffRgn
) ;
704 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , diffRgn
) ;
707 DisposeRgn(diffRgn
) ;
711 if ( !partialRepaint
)
716 m_width
= actualWidth
;
717 m_height
= actualHeight
;
719 // update any low-level frame-relative positions
721 MacUpdateDimensions() ;
722 // erase new position
724 if ( !partialRepaint
)
727 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
729 MacRepositionScrollBars() ;
732 wxPoint
point(m_x
, m_y
);
733 wxMoveEvent
event(point
, m_windowId
);
734 event
.SetEventObject(this);
735 GetEventHandler()->ProcessEvent(event
) ;
739 MacRepositionScrollBars() ;
740 wxSize
size(m_width
, m_height
);
741 wxSizeEvent
event(size
, m_windowId
);
742 event
.SetEventObject(this);
743 GetEventHandler()->ProcessEvent(event
);
749 // set the size of the window: if the dimensions are positive, just use them,
750 // but if any of them is equal to -1, it means that we must find the value for
751 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
752 // which case -1 is a valid value for x and y)
754 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
755 // the width/height to best suit our contents, otherwise we reuse the current
757 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
759 // get the current size and position...
760 int currentX
, currentY
;
761 GetPosition(¤tX
, ¤tY
);
763 int currentW
,currentH
;
764 GetSize(¤tW
, ¤tH
);
766 // ... and don't do anything (avoiding flicker) if it's already ok
767 if ( x
== currentX
&& y
== currentY
&&
768 width
== currentW
&& height
== currentH
)
770 MacRepositionScrollBars() ; // we might have a real position shift
774 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
776 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
779 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
784 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
786 size
= DoGetBestSize();
791 // just take the current one
798 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
802 size
= DoGetBestSize();
804 //else: already called DoGetBestSize() above
810 // just take the current one
815 DoMoveWindow(x
, y
, width
, height
);
818 // For implementation purposes - sometimes decorations make the client area
821 wxPoint
wxWindowMac::GetClientAreaOrigin() const
823 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
826 void wxWindowMac::SetTitle(const wxString
& title
)
831 wxString
wxWindowMac::GetTitle() const
836 bool wxWindowMac::Show(bool show
)
838 if ( !wxWindowBase::Show(show
) )
842 WindowRef window = (WindowRef) MacGetRootWindow() ;
843 wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
844 if ( win == NULL && win->m_isBeingDeleted )
847 MacSuperShown( show
) ;
852 if ( win && !win->m_isBeingDeleted )
863 void wxWindowMac::MacSuperShown( bool show
)
865 wxWindowListNode
*node
= GetChildren().GetFirst();
868 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
869 if ( child
->m_isShown
)
870 child
->MacSuperShown( show
) ;
871 node
= node
->GetNext();
875 void wxWindowMac::MacSuperEnabled( bool enabled
)
879 // to be absolutely correct we'd have to invalidate (with eraseBkground
880 // because unter MacOSX the frames are drawn with an addXXX mode)
883 wxWindowListNode
*node
= GetChildren().GetFirst();
886 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
887 if ( child
->m_isShown
)
888 child
->MacSuperEnabled( enabled
) ;
889 node
= node
->GetNext();
893 bool wxWindowMac::MacIsReallyShown() const
895 if ( m_isShown
&& (m_parent
!= NULL
) ) {
896 return m_parent
->MacIsReallyShown();
900 bool status = m_isShown ;
901 wxWindowMac * win = this ;
902 while ( status && win->m_parent != NULL )
904 win = win->m_parent ;
905 status = win->m_isShown ;
911 int wxWindowMac::GetCharHeight() const
913 wxClientDC
dc ( (wxWindowMac
*)this ) ;
914 return dc
.GetCharHeight() ;
917 int wxWindowMac::GetCharWidth() const
919 wxClientDC
dc ( (wxWindowMac
*)this ) ;
920 return dc
.GetCharWidth() ;
923 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
924 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
926 const wxFont
*fontToUse
= theFont
;
930 wxClientDC
dc( (wxWindowMac
*) this ) ;
932 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
933 if ( externalLeading
)
934 *externalLeading
= le
;
944 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
945 * we always intersect with the entire window, not only with the client area
948 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
950 if ( MacGetTopLevelWindow() == NULL
)
953 wxPoint client
= GetClientAreaOrigin();
956 int x2
= m_width
- client
.x
;
957 int y2
= m_height
- client
.y
;
959 if (IsKindOf( CLASSINFO(wxButton
)))
961 // buttons have an "aura"
968 Rect clientrect
= { y1
, x1
, y2
, x2
};
972 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
973 SectRect( &clientrect
, &r
, &clientrect
) ;
976 if ( !EmptyRect( &clientrect
) )
978 int top
= 0 , left
= 0 ;
980 MacClientToRootWindow( &left
, &top
) ;
981 OffsetRect( &clientrect
, left
, top
) ;
983 MacGetTopLevelWindow()->MacInvalidate( &clientrect
, eraseBack
) ;
987 #if wxUSE_CARET && WXWIN_COMPATIBILITY
988 // ---------------------------------------------------------------------------
989 // Caret manipulation
990 // ---------------------------------------------------------------------------
992 void wxWindowMac::CreateCaret(int w
, int h
)
994 SetCaret(new wxCaret(this, w
, h
));
997 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
999 wxFAIL_MSG("not implemented");
1002 void wxWindowMac::ShowCaret(bool show
)
1004 wxCHECK_RET( m_caret
, "no caret to show" );
1006 m_caret
->Show(show
);
1009 void wxWindowMac::DestroyCaret()
1014 void wxWindowMac::SetCaretPos(int x
, int y
)
1016 wxCHECK_RET( m_caret
, "no caret to move" );
1018 m_caret
->Move(x
, y
);
1021 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
1023 wxCHECK_RET( m_caret
, "no caret to get position of" );
1025 m_caret
->GetPosition(x
, y
);
1027 #endif // wxUSE_CARET
1029 wxWindowMac
*wxGetActiveWindow()
1031 // actually this is a windows-only concept
1035 // Coordinates relative to the window
1036 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1038 // We really don't move the mouse programmatically under Mac.
1041 const wxBrush
& wxWindowMac::MacGetBackgroundBrush()
1043 if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1045 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDocumentWindowBackground
) ;
1047 else if ( m_backgroundColour
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1049 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1050 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1051 // either a non gray background color or a non control window
1053 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1055 wxWindowMac
* parent
= GetParent() ;
1058 if ( parent
->MacGetRootWindow() != window
)
1060 // we are in a different window on the mac system
1066 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
)
1067 && parent
->m_backgroundColour
!= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1069 // if we have any other colours in the hierarchy
1070 m_macBackgroundBrush
.SetColour( parent
->m_backgroundColour
) ;
1073 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1074 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1076 Rect extent
= { 0 , 0 , 0 , 0 } ;
1079 wxSize size
= parent
->GetSize() ;
1080 parent
->MacClientToRootWindow( &x
, &y
) ;
1084 extent
.right
= x
+ size
.x
;
1085 extent
.bottom
= y
+ size
.y
;
1086 m_macBackgroundBrush
.SetMacThemeBackground( kThemeBackgroundTabPane
, (WXRECTPTR
) &extent
) ; // todo eventually change for inactive
1090 parent
= parent
->GetParent() ;
1094 m_macBackgroundBrush
.SetMacTheme( kThemeBrushDialogBackgroundActive
) ; // todo eventually change for inactive
1099 m_macBackgroundBrush
.SetColour( m_backgroundColour
) ;
1102 return m_macBackgroundBrush
;
1105 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1107 event
.GetDC()->Clear() ;
1110 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1112 wxWindowDC
dc(this) ;
1113 wxMacPortSetter
helper(&dc
) ;
1115 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1118 int wxWindowMac::GetScrollPos(int orient
) const
1120 if ( orient
== wxHORIZONTAL
)
1123 return m_hScrollBar
->GetThumbPosition() ;
1128 return m_vScrollBar
->GetThumbPosition() ;
1133 // This now returns the whole range, not just the number
1134 // of positions that we can scroll.
1135 int wxWindowMac::GetScrollRange(int orient
) const
1137 if ( orient
== wxHORIZONTAL
)
1140 return m_hScrollBar
->GetRange() ;
1145 return m_vScrollBar
->GetRange() ;
1150 int wxWindowMac::GetScrollThumb(int orient
) const
1152 if ( orient
== wxHORIZONTAL
)
1155 return m_hScrollBar
->GetThumbSize() ;
1160 return m_vScrollBar
->GetThumbSize() ;
1165 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1167 if ( orient
== wxHORIZONTAL
)
1170 m_hScrollBar
->SetThumbPosition( pos
) ;
1175 m_vScrollBar
->SetThumbPosition( pos
) ;
1179 void wxWindowMac::MacPaintBorders( int left
, int top
)
1184 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1185 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1186 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1187 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1190 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1192 #if wxMAC_USE_THEME_BORDER
1193 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1196 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1197 InsetRect( &rect , border , border );
1198 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1201 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1203 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1204 RGBForeColor( &face
);
1205 MoveTo( left
+ 0 , top
+ m_height
- 2 );
1206 LineTo( left
+ 0 , top
+ 0 );
1207 LineTo( left
+ m_width
- 2 , top
+ 0 );
1209 MoveTo( left
+ 2 , top
+ m_height
- 3 );
1210 LineTo( left
+ m_width
- 3 , top
+ m_height
- 3 );
1211 LineTo( left
+ m_width
- 3 , top
+ 2 );
1213 RGBForeColor( sunken
? &face
: &black
);
1214 MoveTo( left
+ 0 , top
+ m_height
- 1 );
1215 LineTo( left
+ m_width
- 1 , top
+ m_height
- 1 );
1216 LineTo( left
+ m_width
- 1 , top
+ 0 );
1218 RGBForeColor( sunken
? &shadow
: &white
);
1219 MoveTo( left
+ 1 , top
+ m_height
- 3 );
1220 LineTo( left
+ 1, top
+ 1 );
1221 LineTo( left
+ m_width
- 3 , top
+ 1 );
1223 RGBForeColor( sunken
? &white
: &shadow
);
1224 MoveTo( left
+ 1 , top
+ m_height
- 2 );
1225 LineTo( left
+ m_width
- 2 , top
+ m_height
- 2 );
1226 LineTo( left
+ m_width
- 2 , top
+ 1 );
1228 RGBForeColor( sunken
? &black
: &face
);
1229 MoveTo( left
+ 2 , top
+ m_height
- 4 );
1230 LineTo( left
+ 2 , top
+ 2 );
1231 LineTo( left
+ m_width
- 4 , top
+ 2 );
1234 else if (HasFlag(wxSIMPLE_BORDER
))
1236 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1237 RGBForeColor( &black
) ;
1238 FrameRect( &rect
) ;
1242 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1244 if ( child
== m_hScrollBar
)
1245 m_hScrollBar
= NULL
;
1246 if ( child
== m_vScrollBar
)
1247 m_vScrollBar
= NULL
;
1249 wxWindowBase::RemoveChild( child
) ;
1252 // New function that will replace some of the above.
1253 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1254 int range
, bool refresh
)
1256 if ( orient
== wxHORIZONTAL
)
1260 if ( range
== 0 || thumbVisible
>= range
)
1262 if ( m_hScrollBar
->IsShown() )
1263 m_hScrollBar
->Show(false) ;
1267 if ( !m_hScrollBar
->IsShown() )
1268 m_hScrollBar
->Show(true) ;
1269 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1277 if ( range
== 0 || thumbVisible
>= range
)
1279 if ( m_vScrollBar
->IsShown() )
1280 m_vScrollBar
->Show(false) ;
1284 if ( !m_vScrollBar
->IsShown() )
1285 m_vScrollBar
->Show(true) ;
1286 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1290 MacRepositionScrollBars() ;
1293 // Does a physical scroll
1294 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1296 wxClientDC
dc(this) ;
1297 wxMacPortSetter
helper(&dc
) ;
1300 int width
, height
;
1301 GetClientSize( &width
, &height
) ;
1303 Rect scrollrect
= { dc
.YLOG2DEVMAC(0) , dc
.XLOG2DEVMAC(0) , dc
.YLOG2DEVMAC(height
) , dc
.XLOG2DEVMAC(width
) } ;
1304 RgnHandle updateRgn
= NewRgn() ;
1305 ClipRect( &scrollrect
) ;
1308 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1309 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1310 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1312 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1313 InvalWindowRgn( (WindowRef
) MacGetRootWindow() , updateRgn
) ;
1314 DisposeRgn( updateRgn
) ;
1317 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1319 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1320 if (child
== m_vScrollBar
) continue;
1321 if (child
== m_hScrollBar
) continue;
1322 if (child
->IsTopLevel()) continue;
1325 child
->GetPosition( &x
, &y
);
1327 child
->GetSize( &w
, &h
);
1328 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1333 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1335 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1337 wxScrollWinEvent wevent
;
1338 wevent
.SetPosition(event
.GetPosition());
1339 wevent
.SetOrientation(event
.GetOrientation());
1340 wevent
.m_eventObject
= this;
1342 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1343 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1345 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1346 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1348 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1349 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1351 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1352 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1354 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1355 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1357 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1358 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1360 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1361 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1364 GetEventHandler()->ProcessEvent(wevent
);
1368 // Get the window with the focus
1369 wxWindowMac
*wxWindowBase::FindFocus()
1371 return gFocusWindow
;
1374 #if WXWIN_COMPATIBILITY
1375 // If nothing defined for this, try the parent.
1376 // E.g. we may be a button loaded from a resource, with no callback function
1378 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1380 if ( GetEventHandler()->ProcessEvent(event
) )
1383 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1385 #endif // WXWIN_COMPATIBILITY_2
1387 #if WXWIN_COMPATIBILITY
1388 wxObject
* wxWindowMac::GetChild(int number
) const
1390 // Return a pointer to the Nth object in the Panel
1391 wxNode
*node
= GetChildren().GetFirst();
1394 node
= node
->GetNext();
1397 wxObject
*obj
= (wxObject
*)node
->GetData();
1403 #endif // WXWIN_COMPATIBILITY
1405 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1407 // panel wants to track the window which was the last to have focus in it,
1408 // so we want to set ourselves as the window which last had focus
1410 // notice that it's also important to do it upwards the tree becaus
1411 // otherwise when the top level panel gets focus, it won't set it back to
1412 // us, but to some other sibling
1414 // CS:don't know if this is still needed:
1415 //wxChildFocusEvent eventFocus(this);
1416 //(void)GetEventHandler()->ProcessEvent(eventFocus);
1421 void wxWindowMac::Clear()
1423 wxClientDC
dc(this);
1424 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1425 dc
.SetBackground(brush
);
1429 // Setup background and foreground colours correctly
1430 void wxWindowMac::SetupColours()
1433 SetBackgroundColour(GetParent()->GetBackgroundColour());
1436 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1439 // Check if we need to send a LEAVE event
1440 if (m_mouseInWindow)
1443 ::GetCursorPos(&pt);
1444 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1446 // Generate a LEAVE event
1447 m_mouseInWindow = FALSE;
1448 MSWOnMouseLeave(pt.x, pt.y, 0);
1453 // This calls the UI-update mechanism (querying windows for
1454 // menu/toolbar/control state information)
1458 // Raise the window to the top of the Z order
1459 void wxWindowMac::Raise()
1463 // Lower the window to the bottom of the Z order
1464 void wxWindowMac::Lower()
1468 void wxWindowMac::DoSetClientSize(int width
, int height
)
1470 if ( width
!= -1 || height
!= -1 )
1473 if ( width
!= -1 && m_vScrollBar
)
1474 width
+= MAC_SCROLLBAR_SIZE
;
1475 if ( height
!= -1 && m_vScrollBar
)
1476 height
+= MAC_SCROLLBAR_SIZE
;
1478 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1479 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1481 DoSetSize( -1 , -1 , width
, height
) ;
1486 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1488 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1492 if ((point
.x
< 0) || (point
.y
< 0) ||
1493 (point
.x
> (m_width
)) || (point
.y
> (m_height
)))
1498 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1499 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1503 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1505 wxPoint
newPoint( point
) ;
1507 if ( !IsTopLevel() )
1513 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1515 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1516 // added the m_isShown test --dmazzoni
1517 if ( child
->MacGetRootWindow() == window
&& child
->m_isShown
)
1519 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1528 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1532 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1533 if ( ::FindWindow( pt
, &window
) == 3 )
1536 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1539 // No, this yields the CLIENT are, we need the whole frame. RR.
1540 // point = win->ScreenToClient( point ) ;
1543 ::GetPort( &port
) ;
1544 ::SetPort( UMAGetWindowPort( window
) ) ;
1545 ::GlobalToLocal( &pt
) ;
1548 wxPoint
point( pt
.h
, pt
.v
) ;
1550 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1556 static wxWindow
*gs_lastWhich
= NULL
;
1558 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1560 // first trigger a set cursor event
1562 wxPoint clientorigin
= GetClientAreaOrigin() ;
1563 wxSize clientsize
= GetClientSize() ;
1565 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1567 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1569 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
1570 if ( processedEvtSetCursor
&& event
.HasCursor() )
1572 cursor
= event
.GetCursor() ;
1577 // the test for processedEvtSetCursor is here to prevent using m_cursor
1578 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1579 // it - this is a way to say that our cursor shouldn't be used for this
1581 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1591 cursor
= *wxSTANDARD_CURSOR
;
1595 cursor
.MacInstall() ;
1597 return cursor
.Ok() ;
1600 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1602 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1603 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1607 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */)
1610 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1618 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1620 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1621 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1623 if (child
->MacDispatchMouseEvent(event
))
1628 wxWindow
* cursorTarget
= this ;
1629 wxPoint
cursorPoint( x
, y
) ;
1631 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1633 cursorTarget
= cursorTarget
->GetParent() ;
1635 cursorPoint
+= cursorTarget
->GetPosition() ;
1639 event
.SetEventObject( this ) ;
1641 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1643 // set focus to this window
1644 if (AcceptsFocus() && FindFocus()!=this)
1649 if ( event
.GetEventType() == wxEVT_MOTION
1650 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1651 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1652 wxToolTip::RelayEvent( this , event
);
1653 #endif // wxUSE_TOOLTIPS
1655 if (gs_lastWhich
!= this)
1657 gs_lastWhich
= this;
1659 // Double clicks must always occur on the same window
1660 if (event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1661 event
.SetEventType( wxEVT_LEFT_DOWN
);
1662 if (event
.GetEventType() == wxEVT_RIGHT_DCLICK
)
1663 event
.SetEventType( wxEVT_RIGHT_DOWN
);
1665 // Same for mouse up events
1666 if (event
.GetEventType() == wxEVT_LEFT_UP
)
1668 if (event
.GetEventType() == wxEVT_RIGHT_UP
)
1672 GetEventHandler()->ProcessEvent( event
) ;
1677 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1681 return m_tooltip
->GetTip() ;
1686 void wxWindowMac::Update()
1688 wxTopLevelWindowMac
* win
= MacGetTopLevelWindow( ) ;
1691 win
->MacUpdate( 0 ) ;
1692 #if TARGET_API_MAC_CARBON
1693 if ( QDIsPortBuffered( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) ) )
1695 QDFlushPortBuffer( GetWindowPort( (WindowRef
) win
->MacGetWindowRef() ) , NULL
) ;
1701 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
1703 wxTopLevelWindowMac
* win
= NULL
;
1704 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1707 win
= wxFindWinFromMacWindow( window
) ;
1712 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings
)
1714 RgnHandle visRgn
= NewRgn() ;
1715 RgnHandle tempRgn
= NewRgn() ;
1716 RgnHandle tempStaticBoxRgn
= NewRgn() ;
1718 SetRectRgn( visRgn
, 0 , 0 , m_width
, m_height
) ;
1720 //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
1721 if ( IsKindOf( CLASSINFO( wxStaticBox
) ) )
1723 int borderTop
= 14 ;
1724 int borderOther
= 4 ;
1726 SetRectRgn( tempStaticBoxRgn
, borderOther
, borderTop
, m_width
- borderOther
, m_height
- borderOther
) ;
1727 DiffRgn( visRgn
, tempStaticBoxRgn
, visRgn
) ;
1730 if ( !IsTopLevel() )
1732 wxWindow
* parent
= GetParent() ;
1735 wxSize size
= parent
->GetSize() ;
1738 parent
->MacWindowToRootWindow( &x
, &y
) ;
1739 MacRootWindowToWindow( &x
, &y
) ;
1741 SetRectRgn( tempRgn
,
1742 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
1743 x
+ size
.x
- parent
->MacGetRightBorderSize(),
1744 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
1746 SectRgn( visRgn
, tempRgn
, visRgn
) ;
1747 if ( parent
->IsTopLevel() )
1749 parent
= parent
->GetParent() ;
1752 if ( respectChildrenAndSiblings
)
1754 if ( GetWindowStyle() & wxCLIP_CHILDREN
)
1756 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1758 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1760 if ( !child
->IsTopLevel() && child
->IsShown() )
1762 SetRectRgn( tempRgn
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1763 if ( child
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1765 int borderTop
= 14 ;
1766 int borderOther
= 4 ;
1768 SetRectRgn( tempStaticBoxRgn
, child
->m_x
+ borderOther
, child
->m_y
+ borderTop
, child
->m_x
+ child
->m_width
- borderOther
, child
->m_y
+ child
->m_height
- borderOther
) ;
1769 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1771 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1776 if ( (GetWindowStyle() & wxCLIP_SIBLINGS
) && GetParent() )
1778 bool thisWindowThrough
= false ;
1779 for (wxWindowListNode
*node
= GetParent()->GetChildren().GetFirst(); node
; node
= node
->GetNext())
1781 wxWindowMac
*sibling
= (wxWindowMac
*)node
->GetData();
1782 if ( sibling
== this )
1784 thisWindowThrough
= true ;
1787 if( !thisWindowThrough
)
1792 if ( !sibling
->IsTopLevel() && sibling
->IsShown() )
1794 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
) ;
1795 if ( sibling
->IsKindOf( CLASSINFO( wxStaticBox
) ) )
1797 int borderTop
= 14 ;
1798 int borderOther
= 4 ;
1800 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
) ;
1801 DiffRgn( tempRgn
, tempStaticBoxRgn
, tempRgn
) ;
1803 DiffRgn( visRgn
, tempRgn
, visRgn
) ;
1808 m_macVisibleRegion
= visRgn
;
1809 DisposeRgn( visRgn
) ;
1810 DisposeRgn( tempRgn
) ;
1811 DisposeRgn( tempStaticBoxRgn
) ;
1812 return m_macVisibleRegion
;
1815 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
1817 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1818 // updatergn is always already clipped to our boundaries
1819 // it is in window coordinates, not in client coordinates
1821 WindowRef window
= (WindowRef
) MacGetRootWindow() ;
1824 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
1825 RgnHandle ownUpdateRgn
= NewRgn() ;
1826 CopyRgn( updatergn
, ownUpdateRgn
) ;
1828 SectRgn( ownUpdateRgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn
) ;
1830 // newupdate is the update region in client coordinates
1831 RgnHandle newupdate
= NewRgn() ;
1832 wxSize point
= GetClientSize() ;
1833 wxPoint origin
= GetClientAreaOrigin() ;
1834 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1835 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1836 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1837 m_updateRegion
= newupdate
;
1838 DisposeRgn( newupdate
) ; // it's been cloned to m_updateRegion
1840 if ( erase
&& !EmptyRgn(ownUpdateRgn
) )
1842 wxWindowDC
dc(this);
1843 if (!EmptyRgn(ownUpdateRgn
))
1844 dc
.SetClippingRegion(wxRegion(ownUpdateRgn
));
1845 wxEraseEvent
eevent( GetId(), &dc
);
1846 eevent
.SetEventObject( this );
1847 GetEventHandler()->ProcessEvent( eevent
);
1849 wxNcPaintEvent
eventNc( GetId() );
1850 eventNc
.SetEventObject( this );
1851 GetEventHandler()->ProcessEvent( eventNc
);
1853 DisposeRgn( ownUpdateRgn
) ;
1854 if ( !m_updateRegion
.Empty() )
1857 event
.m_timeStamp
= time
;
1858 event
.SetEventObject(this);
1859 GetEventHandler()->ProcessEvent(event
);
1863 // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
1865 RgnHandle childupdate
= NewRgn() ;
1866 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1868 // calculate the update region for the child windows by intersecting the window rectangle with our own
1869 // passed in update region and then offset it to be client-wise window coordinates again
1870 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
1871 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1872 SectRgn( childupdate
, updatergn
, childupdate
) ;
1873 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1874 if ( child
->MacGetRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1876 // because dialogs may also be children
1877 child
->MacRedraw( childupdate
, time
, erase
) ;
1880 DisposeRgn( childupdate
) ;
1881 // eventually a draw grow box here
1885 WXHWND
wxWindowMac::MacGetRootWindow() const
1887 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1891 if ( iter
->IsTopLevel() )
1892 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
1894 iter
= iter
->GetParent() ;
1896 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1900 void wxWindowMac::MacCreateScrollBars( long style
)
1902 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1904 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1905 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1907 GetClientSize( &width
, &height
) ;
1909 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1910 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1911 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1912 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1914 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1915 vSize
, wxVERTICAL
);
1917 if ( style
& wxVSCROLL
)
1923 m_vScrollBar
->Show(false) ;
1925 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1926 hSize
, wxHORIZONTAL
);
1927 if ( style
& wxHSCROLL
)
1932 m_hScrollBar
->Show(false) ;
1935 // because the create does not take into account the client area origin
1936 MacRepositionScrollBars() ; // we might have a real position shift
1939 void wxWindowMac::MacRepositionScrollBars()
1941 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1942 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1944 // get real client area
1946 int width
= m_width
;
1947 int height
= m_height
;
1949 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1950 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1952 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1953 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1954 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1955 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1962 MacClientToRootWindow( &x
, &y
) ;
1963 MacClientToRootWindow( &w
, &h
) ;
1965 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1967 int totW
= 10000 , totH
= 10000;
1970 if ( iter
->IsTopLevel() )
1972 totW
= iter
->m_width
;
1973 totH
= iter
->m_height
;
1977 iter
= iter
->GetParent() ;
2005 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2009 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2013 bool wxWindowMac::AcceptsFocus() const
2015 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2018 WXWidget
wxWindowMac::MacGetContainerForEmbedding()
2020 return GetParent()->MacGetContainerForEmbedding() ;
2023 void wxWindowMac::MacSuperChangedPosition()
2025 // only window-absolute structures have to be moved i.e. controls
2027 wxWindowListNode
*node
= GetChildren().GetFirst();
2030 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
2031 child
->MacSuperChangedPosition() ;
2032 node
= node
->GetNext();
2036 void wxWindowMac::MacTopLevelWindowChangedPosition()
2038 // only screen-absolute structures have to be moved i.e. glcanvas
2040 wxWindowListNode
*node
= GetChildren().GetFirst();
2043 wxWindowMac
*child
= (wxWindowMac
*)node
->GetData();
2044 child
->MacTopLevelWindowChangedPosition() ;
2045 node
= node
->GetNext();
2048 long wxWindowMac::MacGetLeftBorderSize( ) const
2053 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2056 #if wxMAC_USE_THEME_BORDER
2058 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2063 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2066 #if wxMAC_USE_THEME_BORDER
2068 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2073 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2080 long wxWindowMac::MacGetRightBorderSize( ) const
2082 // they are all symmetric in mac themes
2083 return MacGetLeftBorderSize() ;
2086 long wxWindowMac::MacGetTopBorderSize( ) const
2088 // they are all symmetric in mac themes
2089 return MacGetLeftBorderSize() ;
2092 long wxWindowMac::MacGetBottomBorderSize( ) const
2094 // they are all symmetric in mac themes
2095 return MacGetLeftBorderSize() ;
2098 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2100 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2103 // Find the wxWindowMac at the current mouse position, returning the mouse
2105 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2107 pt
= wxGetMousePosition();
2108 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2112 // Get the current mouse position.
2113 wxPoint
wxGetMousePosition()
2116 wxGetMousePosition(& x
, & y
);
2117 return wxPoint(x
, y
);
2120 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2122 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2124 // copied from wxGTK : CS
2125 // generate a "context menu" event: this is similar to wxEVT_RIGHT_UP
2128 // (a) it's a command event and so is propagated to the parent
2129 // (b) under MSW it can be generated from kbd too
2130 // (c) it uses screen coords (because of (a))
2131 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2133 this->ClientToScreen(event
.GetPosition()));
2134 this->GetEventHandler()->ProcessEvent(evtCtx
);