1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
8 // Copyright: (c) AUTHOR
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"
44 #define wxWINDOW_HSCROLL 5998
45 #define wxWINDOW_VSCROLL 5997
46 #define MAC_SCROLLBAR_SIZE 16
48 #include <wx/mac/uma.h>
50 #if wxUSE_DRAG_AND_DROP
56 extern wxList wxPendingDelete
;
57 wxWindowMac
* gFocusWindow
= NULL
;
59 #ifdef __WXUNIVERSAL__
60 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
62 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
63 #endif // __WXUNIVERSAL__/__WXMAC__
65 #if !USE_SHARED_LIBRARY
67 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
68 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
69 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
70 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
71 EVT_IDLE(wxWindowMac::OnIdle
)
72 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
79 // ===========================================================================
81 // ===========================================================================
83 // ---------------------------------------------------------------------------
84 // wxWindowMac utility functions
85 // ---------------------------------------------------------------------------
87 // Find an item given the Macintosh Window Reference
89 wxList
*wxWinMacWindowList
= NULL
;
90 wxWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
92 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
95 return (wxWindowMac
*)node
->Data();
98 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindowMac
*win
)
100 // adding NULL WindowRef is (first) surely a result of an error and
101 // (secondly) breaks menu command processing
102 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
104 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
105 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
108 void wxRemoveMacWindowAssociation(wxWindowMac
*win
)
110 wxWinMacWindowList
->DeleteObject(win
);
113 // ----------------------------------------------------------------------------
114 // constructors and such
115 // ----------------------------------------------------------------------------
117 WindowRef
wxWindowMac::s_macWindowInUpdate
= NULL
;
119 void wxWindowMac::Init()
124 m_macEraseOnRedraw
= true ;
127 m_doubleClickAllowed
= 0;
128 m_winCaptured
= FALSE
;
130 m_isBeingDeleted
= FALSE
;
133 m_mouseInWindow
= FALSE
;
137 m_backgroundTransparent
= FALSE
;
139 // as all windows are created with WS_VISIBLE style...
142 m_macWindowData
= NULL
;
143 m_macEraseOnRedraw
= true ;
150 m_hScrollBar
= NULL
;
151 m_vScrollBar
= NULL
;
153 #if wxUSE_DRAG_AND_DROP
154 m_pDropTarget
= NULL
;
159 wxWindowMac::~wxWindowMac()
161 // deleting a window while it is shown invalidates the region
163 wxWindowMac
* iter
= this ;
165 if ( iter
->m_macWindowData
)
170 iter
= iter
->GetParent() ;
175 m_isBeingDeleted
= TRUE
;
177 if ( s_lastMouseWindow
== this )
179 s_lastMouseWindow
= NULL
;
182 if ( gFocusWindow
== this )
184 gFocusWindow
= NULL
;
188 m_parent
->RemoveChild(this);
192 if ( m_macWindowData
)
194 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
195 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
196 delete m_macWindowData
;
197 wxRemoveMacWindowAssociation( this ) ;
202 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
206 const wxString
& name
)
208 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
210 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
213 parent
->AddChild(this);
217 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
218 m_width
= WidthDefault( size
.x
);
219 m_height
= HeightDefault( size
.y
) ;
220 #ifndef __WXUNIVERSAL__
221 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
223 MacCreateScrollBars( style
) ;
229 void wxWindowMac::SetFocus()
231 if ( gFocusWindow
== this )
234 if ( AcceptsFocus() )
240 if ( gFocusWindow
->m_caret
)
242 gFocusWindow
->m_caret
->OnKillFocus();
244 #endif // wxUSE_CARET
245 #ifndef __WXUNIVERSAL__
246 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
247 if ( control
&& control
->GetMacControl() )
249 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
250 control
->MacRedrawControl() ;
253 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
254 event
.SetEventObject(gFocusWindow
);
255 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
257 gFocusWindow
= this ;
263 m_caret
->OnSetFocus();
265 #endif // wxUSE_CARET
266 // panel wants to track the window which was the last to have focus in it
267 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
270 panel
->SetLastFocus((wxWindow
*)this);
272 #ifndef __WXUNIVERSAL__
273 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
274 if ( control
&& control
->GetMacControl() )
276 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
279 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
280 event
.SetEventObject(this);
281 GetEventHandler()->ProcessEvent(event
) ;
286 bool wxWindowMac::Enable(bool enable
)
288 if ( !wxWindowBase::Enable(enable
) )
291 wxWindowList::Node
*node
= GetChildren().GetFirst();
294 wxWindowMac
*child
= node
->GetData();
295 child
->Enable(enable
);
297 node
= node
->GetNext();
303 void wxWindowMac::CaptureMouse()
305 wxTheApp
->s_captureWindow
= this ;
308 wxWindow
* wxWindowBase::GetCapture()
310 return wxTheApp
->s_captureWindow
;
313 void wxWindowMac::ReleaseMouse()
315 wxTheApp
->s_captureWindow
= NULL
;
318 #if wxUSE_DRAG_AND_DROP
320 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
322 if ( m_pDropTarget
!= 0 ) {
323 delete m_pDropTarget
;
326 m_pDropTarget
= pDropTarget
;
327 if ( m_pDropTarget
!= 0 )
335 // Old style file-manager drag&drop
336 void wxWindowMac::DragAcceptFiles(bool accept
)
342 void wxWindowMac::DoGetSize(int *x
, int *y
) const
348 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
354 wxPoint
pt(GetParent()->GetClientAreaOrigin());
361 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
363 menu
->SetInvokingWindow(this);
365 ClientToScreen( &x
, &y
) ;
367 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
368 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
369 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
370 ::DeleteMenu( menu
->MacGetMenuId() ) ;
371 menu
->SetInvokingWindow(NULL
);
377 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
379 WindowRef window
= GetMacRootWindow() ;
387 ::SetPort( UMAGetWindowPort( window
) ) ;
388 ::GlobalToLocal( &localwhere
) ;
394 MacRootWindowToClient( x
, y
) ;
397 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
399 WindowRef window
= GetMacRootWindow() ;
401 MacClientToRootWindow( x
, y
) ;
409 ::SetPort( UMAGetWindowPort( window
) ) ;
410 ::SetOrigin( 0 , 0 ) ;
411 ::LocalToGlobal( &localwhere
) ;
417 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
419 if ( m_macWindowData
)
426 GetParent()->MacClientToRootWindow( x
, y
) ;
430 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
432 if ( m_macWindowData
)
439 GetParent()->MacRootWindowToClient( x
, y
) ;
443 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
445 if (m_cursor
== cursor
)
448 if (wxNullCursor
== cursor
)
450 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
455 if ( ! wxWindowBase::SetCursor( cursor
) )
459 wxASSERT_MSG( m_cursor
.Ok(),
460 wxT("cursor must be valid after call to the base version"));
463 wxWindowMac
*mouseWin
;
466 // Change the cursor NOW if we're within the correct window
468 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
470 if ( mouseWin
== this && !wxIsBusy() )
472 m_cursor
.MacInstall() ;
480 // Get size *available for subwindows* i.e. excluding menu bar etc.
481 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
486 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
487 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
489 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
496 MacClientToRootWindow( &x1
, &y1
) ;
497 MacClientToRootWindow( &w
, &h
) ;
499 WindowRef window
= NULL
;
500 wxWindowMac
*iter
= (wxWindowMac
*)this ;
502 int totW
= 10000 , totH
= 10000;
505 if ( iter
->m_macWindowData
)
507 totW
= iter
->m_width
;
508 totH
= iter
->m_height
;
512 iter
= iter
->GetParent() ;
515 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
517 (*y
) -= MAC_SCROLLBAR_SIZE
;
523 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
525 (*x
) -= MAC_SCROLLBAR_SIZE
;
535 // ----------------------------------------------------------------------------
537 // ----------------------------------------------------------------------------
541 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
543 wxWindowBase::DoSetToolTip(tooltip
);
546 m_tooltip
->SetWindow(this);
549 #endif // wxUSE_TOOLTIPS
551 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
553 DoSetSize( x
,y
, width
, height
) ;
556 // set the size of the window: if the dimensions are positive, just use them,
557 // but if any of them is equal to -1, it means that we must find the value for
558 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
559 // which case -1 is a valid value for x and y)
561 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
562 // the width/height to best suit our contents, otherwise we reuse the current
564 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
569 int former_w
= m_width
;
570 int former_h
= m_height
;
572 int currentX
, currentY
;
573 GetPosition(¤tX
, ¤tY
);
574 int currentW
,currentH
;
575 GetSize(¤tW
, ¤tH
);
577 int actualWidth
= width
;
578 int actualHeight
= height
;
581 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
583 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
586 wxSize
size( -1 , -1 ) ;
588 if (width
== -1 || height
== -1 )
590 size
= DoGetBestSize() ;
595 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
597 actualWidth
= size
.x
;
598 if ( actualWidth
== -1 )
603 actualWidth
= currentW
;
608 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
610 actualHeight
= size
.y
;
611 if ( actualHeight
== -1 )
616 actualHeight
= currentH
;
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
;
628 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
630 MacRepositionScrollBars() ; // we might have a real position shift
634 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
637 bool doMove
= false ;
638 bool doResize
= false ;
640 if ( actualX
!= former_x
|| actualY
!= former_y
)
644 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
649 if ( doMove
|| doResize
)
651 if ( m_macWindowData
)
656 // erase former position
657 wxMacDrawingHelper
focus( this ) ;
660 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
661 // ClipRect( &clientrect ) ;
662 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
667 m_width
= actualWidth
;
668 m_height
= actualHeight
;
669 if ( m_macWindowData
)
672 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
675 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
677 // the OS takes care of invalidating and erasing the new area
678 // we have erased the old one
680 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
682 wxFrame
* frame
= (wxFrame
*) this ;
683 frame
->PositionStatusBar();
684 frame
->PositionToolBar();
689 // erase new position
692 wxMacDrawingHelper
focus( this ) ;
695 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
696 // ClipRect( &clientrect ) ;
697 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
702 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
704 MacRepositionScrollBars() ;
707 wxPoint
point(m_x
, m_y
);
708 wxMoveEvent
event(point
, m_windowId
);
709 event
.SetEventObject(this);
710 GetEventHandler()->ProcessEvent(event
) ;
714 MacRepositionScrollBars() ;
715 wxSize
size(m_width
, m_height
);
716 wxSizeEvent
event(size
, m_windowId
);
717 event
.SetEventObject(this);
718 GetEventHandler()->ProcessEvent(event
);
722 // For implementation purposes - sometimes decorations make the client area
725 wxPoint
wxWindowMac::GetClientAreaOrigin() const
727 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
730 // Makes an adjustment to the window position (for example, a frame that has
731 // a toolbar that it manages itself).
732 void wxWindowMac::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
734 if( !m_macWindowData
)
736 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
738 wxPoint
pt(GetParent()->GetClientAreaOrigin());
739 x
+= pt
.x
; y
+= pt
.y
;
744 void wxWindowMac::SetTitle(const wxString
& title
)
750 if( wxApp::s_macDefaultEncodingIsPC
)
751 label
= wxMacMakeMacStringFromPC( title
) ;
755 if ( m_macWindowData
)
756 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
759 wxString
wxWindowMac::GetTitle() const
764 bool wxWindowMac::Show(bool show
)
766 if ( !wxWindowBase::Show(show
) )
769 if ( m_macWindowData
)
773 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
774 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
775 // no need to generate events here, they will get them triggered by macos
776 // actually they should be , but apparently they are not
777 wxSize
size(m_width
, m_height
);
778 wxSizeEvent
event(size
, m_windowId
);
779 event
.SetEventObject(this);
780 GetEventHandler()->ProcessEvent(event
);
784 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
787 MacSuperShown( show
) ;
790 WindowRef window
= GetMacRootWindow() ;
791 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
792 if ( !win
->m_isBeingDeleted
)
803 void wxWindowMac::MacSuperShown( bool show
)
805 wxNode
*node
= GetChildren().First();
808 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
809 if ( child
->m_isShown
)
810 child
->MacSuperShown( show
) ;
815 bool wxWindowMac::MacIsReallyShown() const
817 if ( m_isShown
&& (m_parent
!= NULL
) ) {
818 return m_parent
->MacIsReallyShown();
822 bool status = m_isShown ;
823 wxWindowMac * win = this ;
824 while ( status && win->m_parent != NULL )
826 win = win->m_parent ;
827 status = win->m_isShown ;
833 int wxWindowMac::GetCharHeight() const
835 wxClientDC
dc ( (wxWindowMac
*)this ) ;
836 return dc
.GetCharHeight() ;
839 int wxWindowMac::GetCharWidth() const
841 wxClientDC
dc ( (wxWindowMac
*)this ) ;
842 return dc
.GetCharWidth() ;
845 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
846 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
848 const wxFont
*fontToUse
= theFont
;
852 wxClientDC
dc( (wxWindowMac
*) this ) ;
854 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
855 if ( externalLeading
)
856 *externalLeading
= le
;
865 void wxWindowMac::MacEraseBackground( Rect
*rect
)
868 WindowRef window = GetMacRootWindow() ;
869 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
871 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
873 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
875 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
876 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
877 // either a non gray background color or a non control window
879 wxWindowMac* parent = GetParent() ;
882 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
884 // if we have any other colours in the hierarchy
885 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
888 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
890 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
891 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
893 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
899 // we have arrived at a non control item
903 parent = parent->GetParent() ;
907 // if there is nothing special -> use default
908 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
913 RGBBackColor( &m_backgroundColour.GetPixel()) ;
918 for (wxNode *node = GetChildren().First(); node; node = node->Next())
920 wxWindowMac *child = (wxWindowMac*)node->Data();
922 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
923 SectRect( &clientrect , rect , &clientrect ) ;
925 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
926 if ( child->GetMacRootWindow() == window && child->IsShown() )
928 wxMacDrawingClientHelper focus( this ) ;
931 child->MacEraseBackground( &clientrect ) ;
938 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
943 wxMacDrawingClientHelper
focus( this ) ;
947 client
= GetClientAreaOrigin( ) ;
948 Rect clientrect
= { -client
.y
, -client
.x
, m_height
- client
.y
, m_width
- client
.x
} ;
949 // ClipRect( &clientrect ) ;
953 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
954 SectRect( &clientrect
, &r
, &clientrect
) ;
956 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
959 m_macEraseOnRedraw
= false ;
961 m_macEraseOnRedraw
= true ;
964 // Responds to colour changes: passes event on to children.
965 void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
967 wxNode
*node
= GetChildren().First();
970 // Only propagate to non-top-level windows
971 wxWindowMac
*win
= (wxWindowMac
*)node
->Data();
972 if ( win
->GetParent() )
974 wxSysColourChangedEvent event2
;
975 event
.m_eventObject
= win
;
976 win
->GetEventHandler()->ProcessEvent(event2
);
983 #if wxUSE_CARET && WXWIN_COMPATIBILITY
984 // ---------------------------------------------------------------------------
985 // Caret manipulation
986 // ---------------------------------------------------------------------------
988 void wxWindowMac::CreateCaret(int w
, int h
)
990 SetCaret(new wxCaret(this, w
, h
));
993 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
995 wxFAIL_MSG("not implemented");
998 void wxWindowMac::ShowCaret(bool show
)
1000 wxCHECK_RET( m_caret
, "no caret to show" );
1002 m_caret
->Show(show
);
1005 void wxWindowMac::DestroyCaret()
1010 void wxWindowMac::SetCaretPos(int x
, int y
)
1012 wxCHECK_RET( m_caret
, "no caret to move" );
1014 m_caret
->Move(x
, y
);
1017 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
1019 wxCHECK_RET( m_caret
, "no caret to get position of" );
1021 m_caret
->GetPosition(x
, y
);
1023 #endif // wxUSE_CARET
1025 wxWindowMac
*wxGetActiveWindow()
1027 // actually this is a windows-only concept
1031 // Coordinates relative to the window
1032 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1034 // We really dont move the mouse programmatically under mac
1037 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1039 // TODO : probably we would adopt the EraseEvent structure
1042 int wxWindowMac::GetScrollPos(int orient
) const
1044 if ( orient
== wxHORIZONTAL
)
1047 return m_hScrollBar
->GetThumbPosition() ;
1052 return m_vScrollBar
->GetThumbPosition() ;
1057 // This now returns the whole range, not just the number
1058 // of positions that we can scroll.
1059 int wxWindowMac::GetScrollRange(int orient
) const
1061 if ( orient
== wxHORIZONTAL
)
1064 return m_hScrollBar
->GetRange() ;
1069 return m_vScrollBar
->GetRange() ;
1074 int wxWindowMac::GetScrollThumb(int orient
) const
1076 if ( orient
== wxHORIZONTAL
)
1079 return m_hScrollBar
->GetThumbSize() ;
1084 return m_vScrollBar
->GetThumbSize() ;
1089 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1091 if ( orient
== wxHORIZONTAL
)
1094 m_hScrollBar
->SetThumbPosition( pos
) ;
1099 m_vScrollBar
->SetThumbPosition( pos
) ;
1103 void wxWindowMac::MacCreateRealWindow( const wxString
& title
,
1107 const wxString
& name
)
1110 m_windowStyle
= style
;
1131 m_macWindowData
= new MacWindowData() ;
1133 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1135 // translate the window attributes in the appropriate window class and attributes
1137 WindowClass wclass
= 0;
1138 WindowAttributes attr
= kWindowNoAttributes
;
1140 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1142 wclass
= kFloatingWindowClass
;
1143 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1145 attr
|= kWindowSideTitlebarAttribute
;
1148 else if ( HasFlag( wxCAPTION
) )
1150 if ( HasFlag( wxDIALOG_MODAL
) )
1152 wclass
= kMovableModalWindowClass
;
1156 wclass
= kDocumentWindowClass
;
1161 wclass
= kModalWindowClass
;
1164 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1166 attr
|= kWindowFullZoomAttribute
;
1167 attr
|= kWindowCollapseBoxAttribute
;
1169 if ( HasFlag( wxRESIZE_BORDER
) )
1171 attr
|= kWindowResizableAttribute
;
1173 if ( HasFlag( wxSYSTEM_MENU
) )
1175 attr
|= kWindowCloseBoxAttribute
;
1178 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1179 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1181 if( wxApp::s_macDefaultEncodingIsPC
)
1182 label
= wxMacMakeMacStringFromPC( title
) ;
1185 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1186 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1188 m_macWindowData
->m_macFocus
= NULL
;
1189 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1192 void wxWindowMac::MacPaint( wxPaintEvent
&event
)
1196 void wxWindowMac::MacPaintBorders( )
1198 if( m_macWindowData
)
1201 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1202 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1203 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1204 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1207 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1209 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1210 RGBColor pen1
= sunken
? white
: black
;
1211 RGBColor pen2
= sunken
? shadow
: face
;
1212 RGBColor pen3
= sunken
? face
: shadow
;
1213 RGBColor pen4
= sunken
? black
: white
;
1215 RGBForeColor( &pen1
) ;
1217 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1218 FrameRect( &rect
) ;
1220 RGBForeColor( &pen2
) ;
1222 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1223 FrameRect( &rect
) ;
1225 RGBForeColor( &pen3
) ;
1227 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1228 FrameRect( &rect
) ;
1230 RGBForeColor( &pen4
) ;
1233 LineTo( m_width
- 3 , 0 ) ;
1235 LineTo( 0 , m_height
- 3 ) ;
1238 else if (HasFlag(wxSIMPLE_BORDER
))
1240 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1241 RGBForeColor( &black
) ;
1242 FrameRect( &rect
) ;
1245 if ( this->GetParent() )
1247 wxPaintDC dc(GetParent());
1248 GetParent()->PrepareDC(dc);
1250 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1252 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1254 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1255 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1257 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1258 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1259 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1260 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1263 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1266 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1269 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1272 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1273 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1275 else if (HasFlag(wxDOUBLE_BORDER))
1277 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1279 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1280 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1282 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1283 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1284 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1285 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1288 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1291 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1294 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1297 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1298 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1300 else if (HasFlag(wxSIMPLE_BORDER))
1302 dc.SetPen(*wxBLACK_PEN);
1303 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1309 // New function that will replace some of the above.
1310 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1311 int range
, bool refresh
)
1313 if ( orient
== wxHORIZONTAL
)
1317 if ( range
== 0 || thumbVisible
>= range
)
1319 if ( m_hScrollBar
->IsShown() )
1320 m_hScrollBar
->Show(false) ;
1324 if ( !m_hScrollBar
->IsShown() )
1325 m_hScrollBar
->Show(true) ;
1326 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1334 if ( range
== 0 || thumbVisible
>= range
)
1336 if ( m_vScrollBar
->IsShown() )
1337 m_vScrollBar
->Show(false) ;
1341 if ( !m_vScrollBar
->IsShown() )
1342 m_vScrollBar
->Show(true) ;
1343 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1347 MacRepositionScrollBars() ;
1350 // Does a physical scroll
1351 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1353 wxMacDrawingClientHelper
focus( this ) ;
1356 int width
, height
;
1357 GetClientSize( &width
, &height
) ;
1359 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1361 RgnHandle updateRgn
= NewRgn() ;
1362 ClipRect( &scrollrect
) ;
1365 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1366 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1368 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1369 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1370 DisposeRgn( updateRgn
) ;
1373 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1375 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1376 if (child
== m_vScrollBar
) continue;
1377 if (child
== m_hScrollBar
) continue;
1378 if (child
->IsTopLevel()) continue;
1380 child
->GetPosition( &x
, &y
);
1382 child
->GetSize( &w
, &h
);
1383 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1388 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1390 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1392 wxScrollWinEvent wevent
;
1393 wevent
.SetPosition(event
.GetPosition());
1394 wevent
.SetOrientation(event
.GetOrientation());
1395 wevent
.m_eventObject
= this;
1397 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1398 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1400 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1401 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1403 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1404 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1406 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1407 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1409 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1410 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1412 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1413 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1415 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1416 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1419 GetEventHandler()->ProcessEvent(wevent
);
1423 bool wxWindowMac::SetFont(const wxFont
& font
)
1425 if ( !wxWindowBase::SetFont(font
) )
1434 // Get the window with the focus
1435 wxWindowMac
*wxWindowBase::FindFocus()
1437 return gFocusWindow
;
1440 #if WXWIN_COMPATIBILITY
1441 // If nothing defined for this, try the parent.
1442 // E.g. we may be a button loaded from a resource, with no callback function
1444 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1446 if ( GetEventHandler()->ProcessEvent(event
) )
1449 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1451 #endif // WXWIN_COMPATIBILITY_2
1453 #if WXWIN_COMPATIBILITY
1454 wxObject
* wxWindowMac::GetChild(int number
) const
1456 // Return a pointer to the Nth object in the Panel
1457 wxNode
*node
= GetChildren().First();
1460 node
= node
->Next();
1463 wxObject
*obj
= (wxObject
*)node
->Data();
1469 #endif // WXWIN_COMPATIBILITY
1471 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1473 // panel wants to track the window which was the last to have focus in it,
1474 // so we want to set ourselves as the window which last had focus
1476 // notice that it's also important to do it upwards the tree becaus
1477 // otherwise when the top level panel gets focus, it won't set it back to
1478 // us, but to some other sibling
1479 wxWindowMac
*win
= this;
1482 wxWindowMac
*parent
= win
->GetParent();
1483 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1486 panel
->SetLastFocus(win
);
1495 void wxWindowMac::Clear()
1497 if ( m_macWindowData
)
1499 wxMacDrawingClientHelper
helper ( this ) ;
1501 wxPoint origin
= GetClientAreaOrigin() ;
1502 GetClientSize( &w
, &h
) ;
1503 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1504 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1509 wxClientDC
dc(this);
1510 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1511 dc
.SetBackground(brush
);
1516 // Setup background and foreground colours correctly
1517 void wxWindowMac::SetupColours()
1520 SetBackgroundColour(GetParent()->GetBackgroundColour());
1523 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1526 // Check if we need to send a LEAVE event
1527 if (m_mouseInWindow)
1530 ::GetCursorPos(&pt);
1531 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1533 // Generate a LEAVE event
1534 m_mouseInWindow = FALSE;
1535 MSWOnMouseLeave(pt.x, pt.y, 0);
1540 // This calls the UI-update mechanism (querying windows for
1541 // menu/toolbar/control state information)
1545 // Raise the window to the top of the Z order
1546 void wxWindowMac::Raise()
1548 if ( m_macWindowData
)
1550 UMABringToFront( m_macWindowData
->m_macWindow
) ;
1554 // Lower the window to the bottom of the Z order
1555 void wxWindowMac::Lower()
1557 if ( m_macWindowData
)
1559 UMASendBehind( m_macWindowData
->m_macWindow
, NULL
) ;
1563 void wxWindowMac::DoSetClientSize(int width
, int height
)
1565 if ( width
!= -1 || height
!= -1 )
1568 if ( width
!= -1 && m_vScrollBar
)
1569 width
+= MAC_SCROLLBAR_SIZE
;
1570 if ( height
!= -1 && m_vScrollBar
)
1571 height
+= MAC_SCROLLBAR_SIZE
;
1573 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1574 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1576 DoSetSize( -1 , -1 , width
, height
) ;
1581 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1583 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1585 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1586 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1589 WindowRef window
= GetMacRootWindow() ;
1591 wxPoint
newPoint( point
) ;
1596 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1598 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1599 // added the m_isShown test --dmazzoni
1600 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1602 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1611 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1614 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1615 if ( ::FindWindow( pt
, &window
) == 3 )
1617 wxPoint
point( screenpoint
) ;
1618 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1621 win
->ScreenToClient( point
) ;
1622 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1628 extern int wxBusyCursorCount
;
1630 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1632 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1633 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1637 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1640 WindowRef window
= GetMacRootWindow() ;
1648 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1650 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1651 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1653 if (child
->MacDispatchMouseEvent(event
))
1661 if ( wxBusyCursorCount
== 0 )
1663 m_cursor
.MacInstall() ;
1666 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1668 // set focus to this window
1669 if (AcceptsFocus() && FindFocus()!=this)
1674 if ( event
.GetEventType() == wxEVT_MOTION
1675 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1676 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1677 wxToolTip::RelayEvent( this , event
);
1678 #endif // wxUSE_TOOLTIPS
1679 GetEventHandler()->ProcessEvent( event
) ;
1686 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1690 return m_tooltip
->GetTip() ;
1694 void wxWindowMac::MacFireMouseEvent( EventRecord
*ev
)
1696 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1697 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1698 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1700 event
.m_leftDown
= isDown
&& !controlDown
;
1701 event
.m_middleDown
= FALSE
;
1702 event
.m_rightDown
= isDown
&& controlDown
;
1704 if ( ev
->what
== mouseDown
)
1707 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1709 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1711 else if ( ev
->what
== mouseUp
)
1714 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1716 event
.SetEventType(wxEVT_LEFT_UP
) ;
1720 event
.SetEventType(wxEVT_MOTION
) ;
1723 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1724 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1725 event
.m_altDown
= ev
->modifiers
& optionKey
;
1726 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1728 Point localwhere
= ev
->where
;
1731 ::GetPort( &port
) ;
1732 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1733 ::GlobalToLocal( &localwhere
) ;
1736 if ( ev
->what
== mouseDown
)
1738 if ( ev
->when
- lastWhen
<= GetDblTime() )
1740 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1743 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1745 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1751 lastWhen
= ev
->when
;
1753 lastWhere
= localwhere
;
1756 event
.m_x
= localwhere
.h
;
1757 event
.m_y
= localwhere
.v
;
1762 wxPoint origin = GetClientAreaOrigin() ;
1764 event.m_x += origin.x ;
1765 event.m_y += origin.y ;
1768 event
.m_timeStamp
= ev
->when
;
1769 event
.SetEventObject(this);
1770 if ( wxTheApp
->s_captureWindow
)
1774 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1777 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1778 if ( ev
->what
== mouseUp
)
1780 wxTheApp
->s_captureWindow
= NULL
;
1781 if ( wxBusyCursorCount
== 0 )
1783 m_cursor
.MacInstall() ;
1789 MacDispatchMouseEvent( event
) ;
1793 void wxWindowMac::MacMouseDown( EventRecord
*ev
, short part
)
1795 MacFireMouseEvent( ev
) ;
1798 void wxWindowMac::MacMouseUp( EventRecord
*ev
, short part
)
1800 WindowPtr frontWindow
;
1805 MacFireMouseEvent( ev
) ;
1811 void wxWindowMac::MacMouseMoved( EventRecord
*ev
, short part
)
1813 WindowPtr frontWindow
;
1818 MacFireMouseEvent( ev
) ;
1823 void wxWindowMac::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1825 if ( !m_macWindowData
->m_macHasReceivedFirstActivate
)
1826 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1828 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1829 event
.m_timeStamp
= ev
->when
;
1830 event
.SetEventObject(this);
1832 GetEventHandler()->ProcessEvent(event
);
1835 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1836 // MacUpdateImmediately() ;
1839 void wxWindowMac::MacRedraw( RgnHandle updatergn
, long time
)
1841 // updatergn is always already clipped to our boundaries
1842 WindowRef window
= GetMacRootWindow() ;
1843 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1844 RgnHandle ownUpdateRgn
= NewRgn() ;
1845 CopyRgn( updatergn
, ownUpdateRgn
) ;
1846 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1848 wxMacDrawingHelper
focus( this ) ; // was client
1851 WindowRef window
= GetMacRootWindow() ;
1852 bool eraseBackground
= false ;
1853 if ( m_macWindowData
)
1854 eraseBackground
= true ;
1855 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1857 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1859 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1861 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1862 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1863 // either a non gray background color or a non control window
1866 wxWindowMac
* parent
= GetParent() ;
1869 if ( parent
->GetMacRootWindow() != window
)
1871 // we are in a different window on the mac system
1876 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1878 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1880 // if we have any other colours in the hierarchy
1881 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1884 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1885 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1888 GetRegionBounds( updatergn
, &box
) ;
1889 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1898 parent
= parent
->GetParent() ;
1902 // if there is nothing special -> use default
1903 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1908 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1910 // subtract all non transparent children from updatergn
1912 RgnHandle childarea
= NewRgn() ;
1913 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1915 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1916 // eventually test for transparent windows
1917 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1919 if ( child
->GetBackgroundColour() != m_backgroundColour
&& !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1921 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1922 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1926 DisposeRgn( childarea
) ;
1928 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1929 eraseBackground
= true ;
1930 SetClip( ownUpdateRgn
) ;
1931 if ( m_macEraseOnRedraw
) {
1932 if ( eraseBackground
)
1934 EraseRgn( ownUpdateRgn
) ;
1938 m_macEraseOnRedraw
= true ;
1943 RgnHandle newupdate
= NewRgn() ;
1944 wxSize point
= GetClientSize() ;
1945 wxPoint origin
= GetClientAreaOrigin() ;
1947 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1948 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1949 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1950 m_updateRegion
= newupdate
;
1951 DisposeRgn( newupdate
) ;
1956 event
.m_timeStamp
= time
;
1957 event
.SetEventObject(this);
1958 GetEventHandler()->ProcessEvent(event
);
1962 RgnHandle childupdate
= NewRgn() ;
1964 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1966 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1967 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1968 SectRgn( childupdate
, updatergn
, childupdate
) ;
1969 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1970 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1972 // because dialogs may also be children
1973 child
->MacRedraw( childupdate
, time
) ;
1976 DisposeRgn( childupdate
) ;
1977 // eventually a draw grow box here
1980 void wxWindowMac::MacUpdateImmediately()
1982 WindowRef window
= GetMacRootWindow() ;
1985 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1987 AGAPortHelper
help( GetWindowPort(window
) ) ;
1989 AGAPortHelper
help( (window
) ) ;
1991 SetOrigin( 0 , 0 ) ;
1992 BeginUpdate( window
) ;
1995 RgnHandle region
= NewRgn();
1999 GetPortVisibleRegion( GetWindowPort( window
), region
);
2001 // if windowshade gives incompatibility , take the follwing out
2002 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2004 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
2006 DisposeRgn( region
);
2009 EndUpdate( window
) ;
2013 void wxWindowMac::MacUpdate( EventRecord
*ev
)
2015 WindowRef window
= (WindowRef
) ev
->message
;
2016 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2018 AGAPortHelper
help( GetWindowPort(window
) ) ;
2020 AGAPortHelper
help( (window
) ) ;
2022 SetOrigin( 0 , 0 ) ;
2023 BeginUpdate( window
) ;
2026 RgnHandle region
= NewRgn();
2030 GetPortVisibleRegion( GetWindowPort( window
), region
);
2032 // if windowshade gives incompatibility , take the follwing out
2033 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2035 MacRedraw( region
, ev
->when
) ;
2037 DisposeRgn( region
);
2040 EndUpdate( window
) ;
2043 WindowRef
wxWindowMac::GetMacRootWindow() const
2045 WindowRef window
= NULL
;
2046 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2050 if ( iter
->m_macWindowData
)
2051 return iter
->m_macWindowData
->m_macWindow
;
2053 iter
= iter
->GetParent() ;
2055 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2059 void wxWindowMac::MacCreateScrollBars( long style
)
2061 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2063 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2064 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2066 GetClientSize( &width
, &height
) ;
2068 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2069 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2070 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2071 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2073 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2074 vSize
, wxVERTICAL
);
2076 if ( style
& wxVSCROLL
)
2082 m_vScrollBar
->Show(false) ;
2084 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2085 hSize
, wxHORIZONTAL
);
2086 if ( style
& wxHSCROLL
)
2091 m_hScrollBar
->Show(false) ;
2094 // because the create does not take into account the client area origin
2095 MacRepositionScrollBars() ; // we might have a real position shift
2098 void wxWindowMac::MacRepositionScrollBars()
2100 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2101 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2103 // get real client area
2105 int width
= m_width
;
2106 int height
= m_height
;
2108 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2109 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2111 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2112 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2113 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2114 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2121 MacClientToRootWindow( &x
, &y
) ;
2122 MacClientToRootWindow( &w
, &h
) ;
2124 WindowRef window
= NULL
;
2125 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2127 int totW
= 10000 , totH
= 10000;
2130 if ( iter
->m_macWindowData
)
2132 totW
= iter
->m_width
;
2133 totH
= iter
->m_height
;
2137 iter
= iter
->GetParent() ;
2165 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2169 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2173 void wxWindowMac::MacKeyDown( EventRecord
*ev
)
2179 bool wxWindowMac::AcceptsFocus() const
2181 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2184 ControlHandle
wxWindowMac::MacGetContainerForEmbedding()
2186 if ( m_macWindowData
)
2187 return m_macWindowData
->m_macRootControl
;
2189 return GetParent()->MacGetContainerForEmbedding() ;
2192 void wxWindowMac::MacSuperChangedPosition()
2194 // only window-absolute structures have to be moved i.e. controls
2196 wxNode
*node
= GetChildren().First();
2199 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
2200 child
->MacSuperChangedPosition() ;
2201 node
= node
->Next();
2205 bool wxWindowMac::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2207 if ( window
== NULL
)
2213 ::GetPort(&currPort
);
2214 port
= UMAGetWindowPort( window
) ;
2215 if (currPort
!= port
)
2218 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2219 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2223 bool wxWindowMac::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2225 if ( window
== NULL
)
2230 ::GetPort(&currPort
);
2231 port
= UMAGetWindowPort( window
) ;
2232 if (currPort
!= port
)
2234 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2235 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2236 ::ClipRect(&clipRect
);
2239 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2240 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2241 Pattern whiteColor
;
2243 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2244 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2248 void wxWindowMac::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2250 if ( m_macWindowData
)
2256 clipRect
->right
= m_width
;
2257 clipRect
->bottom
= m_height
;
2258 *window
= m_macWindowData
->m_macWindow
;
2263 wxASSERT( GetParent() != NULL
) ;
2264 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2265 localOrigin
->h
+= m_x
;
2266 localOrigin
->v
+= m_y
;
2267 OffsetRect(clipRect
, -m_x
, -m_y
);
2272 myClip
.right
= m_width
;
2273 myClip
.bottom
= m_height
;
2274 SectRect(clipRect
, &myClip
, clipRect
);
2278 void wxWindowMac::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2280 // int width , height ;
2281 // GetClientSize( &width , &height ) ;
2283 if ( m_macWindowData
)
2289 clipRect
->right
= m_width
;//width;
2290 clipRect
->bottom
= m_height
;// height;
2291 *window
= m_macWindowData
->m_macWindow
;
2296 wxASSERT( GetParent() != NULL
) ;
2298 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2300 localOrigin
->h
+= m_x
;
2301 localOrigin
->v
+= m_y
;
2302 OffsetRect(clipRect
, -m_x
, -m_y
);
2307 myClip
.right
= m_width
;//width;
2308 myClip
.bottom
= m_height
;// height;
2309 SectRect(clipRect
, &myClip
, clipRect
);
2313 void wxWindowMac::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2315 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2317 int width
, height
;
2318 GetClientSize( &width
, &height
) ;
2320 client
= GetClientAreaOrigin( ) ;
2322 localOrigin
->h
+= client
.x
;
2323 localOrigin
->v
+= client
.y
;
2324 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2329 myClip
.right
= width
;
2330 myClip
.bottom
= height
;
2331 SectRect(clipRect
, &myClip
, clipRect
);
2334 long wxWindowMac::MacGetLeftBorderSize( ) const
2336 if( m_macWindowData
)
2339 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2343 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2347 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2354 long wxWindowMac::MacGetRightBorderSize( ) const
2356 if( m_macWindowData
)
2359 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2363 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2367 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2374 long wxWindowMac::MacGetTopBorderSize( ) const
2376 if( m_macWindowData
)
2379 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2383 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2387 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2394 long wxWindowMac::MacGetBottomBorderSize( ) const
2396 if( m_macWindowData
)
2399 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2403 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2407 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2414 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2416 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2420 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac
* theWindow
)
2426 wxWindowMac
*rootwin
;
2427 m_currentPort
= NULL
;
2429 GetPort( &m_formerPort
) ;
2432 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2433 m_currentPort
= UMAGetWindowPort( window
) ;
2434 if ( m_formerPort
!= m_currentPort
)
2435 SetPort( m_currentPort
) ;
2436 GetPenState( &m_savedPenState
) ;
2437 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2442 wxMacDrawingHelper::~wxMacDrawingHelper()
2446 SetPort( m_currentPort
) ;
2447 SetPenState( &m_savedPenState
) ;
2448 SetOrigin( 0 , 0 ) ;
2450 GetPortBounds( m_currentPort
, &portRect
) ;
2451 ClipRect( &portRect
) ;
2454 if ( m_formerPort
!= m_currentPort
)
2455 SetPort( m_formerPort
) ;
2458 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac
* theWindow
)
2464 wxWindowMac
*rootwin
;
2465 m_currentPort
= NULL
;
2467 GetPort( &m_formerPort
) ;
2471 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2472 m_currentPort
= UMAGetWindowPort( window
) ;
2473 if ( m_formerPort
!= m_currentPort
)
2474 SetPort( m_currentPort
) ;
2475 GetPenState( &m_savedPenState
) ;
2476 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2481 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2485 SetPort( m_currentPort
) ;
2486 SetPenState( &m_savedPenState
) ;
2487 SetOrigin( 0 , 0 ) ;
2489 GetPortBounds( m_currentPort
, &portRect
) ;
2490 ClipRect( &portRect
) ;
2493 if ( m_formerPort
!= m_currentPort
)
2494 SetPort( m_formerPort
) ;
2497 // Find the wxWindowMac at the current mouse position, returning the mouse
2499 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2501 pt
= wxGetMousePosition();
2502 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2506 // Get the current mouse position.
2507 wxPoint
wxGetMousePosition()
2510 wxGetMousePosition(& x
, & y
);
2511 return wxPoint(x
, y
);