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
345 if(y
) *y
= m_height
;
348 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
356 wxPoint
pt(GetParent()->GetClientAreaOrigin());
365 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
367 menu
->SetInvokingWindow(this);
369 ClientToScreen( &x
, &y
) ;
371 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
372 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
373 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
374 ::DeleteMenu( menu
->MacGetMenuId() ) ;
375 menu
->SetInvokingWindow(NULL
);
381 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
383 WindowRef window
= GetMacRootWindow() ;
385 Point localwhere
= {0,0} ;
387 if(x
) localwhere
.h
= * x
;
388 if(y
) localwhere
.v
= * y
;
392 ::SetPort( UMAGetWindowPort( window
) ) ;
393 ::GlobalToLocal( &localwhere
) ;
396 if(x
) *x
= localwhere
.h
;
397 if(y
) *y
= localwhere
.v
;
399 MacRootWindowToClient( x
, y
) ;
402 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
404 WindowRef window
= GetMacRootWindow() ;
406 MacClientToRootWindow( x
, y
) ;
408 Point localwhere
= { 0,0 };
409 if(x
) localwhere
.h
= * x
;
410 if(y
) localwhere
.v
= * y
;
414 ::SetPort( UMAGetWindowPort( window
) ) ;
415 ::SetOrigin( 0 , 0 ) ;
416 ::LocalToGlobal( &localwhere
) ;
418 if(x
) *x
= localwhere
.h
;
419 if(y
) *y
= localwhere
.v
;
422 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
424 if ( m_macWindowData
== NULL
)
428 GetParent()->MacClientToRootWindow( x
, y
) ;
432 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
434 if ( m_macWindowData
== NULL
)
438 GetParent()->MacRootWindowToClient( x
, y
) ;
442 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
444 if (m_cursor
== cursor
)
447 if (wxNullCursor
== cursor
)
449 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
454 if ( ! wxWindowBase::SetCursor( cursor
) )
458 wxASSERT_MSG( m_cursor
.Ok(),
459 wxT("cursor must be valid after call to the base version"));
462 wxWindowMac
*mouseWin
;
465 // Change the cursor NOW if we're within the correct window
467 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
469 if ( mouseWin
== this && !wxIsBusy() )
471 m_cursor
.MacInstall() ;
479 // Get size *available for subwindows* i.e. excluding menu bar etc.
480 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
486 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
487 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
489 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
496 MacClientToRootWindow( &x1
, &y1
) ;
497 MacClientToRootWindow( &w
, &h
) ;
499 wxWindowMac
*iter
= (wxWindowMac
*)this ;
501 int totW
= 10000 , totH
= 10000;
504 if ( iter
->m_macWindowData
)
506 totW
= iter
->m_width
;
507 totH
= iter
->m_height
;
511 iter
= iter
->GetParent() ;
514 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
516 hh
-= MAC_SCROLLBAR_SIZE
;
522 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
524 ww
-= MAC_SCROLLBAR_SIZE
;
536 // ----------------------------------------------------------------------------
538 // ----------------------------------------------------------------------------
542 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
544 wxWindowBase::DoSetToolTip(tooltip
);
547 m_tooltip
->SetWindow(this);
550 #endif // wxUSE_TOOLTIPS
552 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
554 DoSetSize( x
,y
, width
, height
) ;
557 // set the size of the window: if the dimensions are positive, just use them,
558 // but if any of them is equal to -1, it means that we must find the value for
559 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
560 // which case -1 is a valid value for x and y)
562 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
563 // the width/height to best suit our contents, otherwise we reuse the current
565 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
570 int former_w
= m_width
;
571 int former_h
= m_height
;
573 int currentX
, currentY
;
574 GetPosition(¤tX
, ¤tY
);
575 int currentW
,currentH
;
576 GetSize(¤tW
, ¤tH
);
578 int actualWidth
= width
;
579 int actualHeight
= height
;
582 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
584 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
587 wxSize
size( -1 , -1 ) ;
589 if (width
== -1 || height
== -1 )
591 size
= DoGetBestSize() ;
596 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
598 actualWidth
= size
.x
;
599 if ( actualWidth
== -1 )
604 actualWidth
= currentW
;
609 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
611 actualHeight
= size
.y
;
612 if ( actualHeight
== -1 )
617 actualHeight
= currentH
;
621 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
622 actualWidth
= m_minWidth
;
623 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
624 actualHeight
= m_minHeight
;
625 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
626 actualWidth
= m_maxWidth
;
627 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
628 actualHeight
= m_maxHeight
;
629 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
631 MacRepositionScrollBars() ; // we might have a real position shift
635 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
638 bool doMove
= false ;
639 bool doResize
= false ;
641 if ( actualX
!= former_x
|| actualY
!= former_y
)
645 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
650 if ( doMove
|| doResize
)
652 if ( m_macWindowData
)
657 // erase former position
658 wxMacDrawingHelper
focus( this ) ;
661 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
662 // ClipRect( &clientrect ) ;
663 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
668 m_width
= actualWidth
;
669 m_height
= actualHeight
;
670 if ( m_macWindowData
)
673 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
676 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
678 // the OS takes care of invalidating and erasing the new area
679 // we have erased the old one
681 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
683 wxFrame
* frame
= (wxFrame
*) this ;
684 frame
->PositionStatusBar();
685 frame
->PositionToolBar();
690 // erase new position
693 wxMacDrawingHelper
focus( this ) ;
696 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
697 // ClipRect( &clientrect ) ;
698 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
703 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
705 MacRepositionScrollBars() ;
708 wxPoint
point(m_x
, m_y
);
709 wxMoveEvent
event(point
, m_windowId
);
710 event
.SetEventObject(this);
711 GetEventHandler()->ProcessEvent(event
) ;
715 MacRepositionScrollBars() ;
716 wxSize
size(m_width
, m_height
);
717 wxSizeEvent
event(size
, m_windowId
);
718 event
.SetEventObject(this);
719 GetEventHandler()->ProcessEvent(event
);
723 // For implementation purposes - sometimes decorations make the client area
726 wxPoint
wxWindowMac::GetClientAreaOrigin() const
728 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
731 // Makes an adjustment to the window position (for example, a frame that has
732 // a toolbar that it manages itself).
733 void wxWindowMac::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
735 if( !m_macWindowData
)
737 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
739 wxPoint
pt(GetParent()->GetClientAreaOrigin());
740 x
+= pt
.x
; y
+= pt
.y
;
745 void wxWindowMac::SetTitle(const wxString
& title
)
751 if( wxApp::s_macDefaultEncodingIsPC
)
752 label
= wxMacMakeMacStringFromPC( title
) ;
756 if ( m_macWindowData
)
757 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
760 wxString
wxWindowMac::GetTitle() const
765 bool wxWindowMac::Show(bool show
)
767 if ( !wxWindowBase::Show(show
) )
770 if ( m_macWindowData
)
774 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
775 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
776 // no need to generate events here, they will get them triggered by macos
777 // actually they should be , but apparently they are not
778 wxSize
size(m_width
, m_height
);
779 wxSizeEvent
event(size
, m_windowId
);
780 event
.SetEventObject(this);
781 GetEventHandler()->ProcessEvent(event
);
785 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
788 MacSuperShown( show
) ;
791 WindowRef window
= GetMacRootWindow() ;
792 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
793 if ( win
&& !win
->m_isBeingDeleted
)
804 void wxWindowMac::MacSuperShown( bool show
)
806 wxNode
*node
= GetChildren().First();
809 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
810 if ( child
->m_isShown
)
811 child
->MacSuperShown( show
) ;
816 bool wxWindowMac::MacIsReallyShown() const
818 if ( m_isShown
&& (m_parent
!= NULL
) ) {
819 return m_parent
->MacIsReallyShown();
823 bool status = m_isShown ;
824 wxWindowMac * win = this ;
825 while ( status && win->m_parent != NULL )
827 win = win->m_parent ;
828 status = win->m_isShown ;
834 int wxWindowMac::GetCharHeight() const
836 wxClientDC
dc ( (wxWindowMac
*)this ) ;
837 return dc
.GetCharHeight() ;
840 int wxWindowMac::GetCharWidth() const
842 wxClientDC
dc ( (wxWindowMac
*)this ) ;
843 return dc
.GetCharWidth() ;
846 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
847 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
849 const wxFont
*fontToUse
= theFont
;
853 wxClientDC
dc( (wxWindowMac
*) this ) ;
855 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
856 if ( externalLeading
)
857 *externalLeading
= le
;
866 void wxWindowMac::MacEraseBackground( Rect
*rect
)
869 WindowRef window = GetMacRootWindow() ;
870 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
872 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
874 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
876 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
877 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
878 // either a non gray background color or a non control window
880 wxWindowMac* parent = GetParent() ;
883 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
885 // if we have any other colours in the hierarchy
886 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
889 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
891 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
892 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
894 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
900 // we have arrived at a non control item
904 parent = parent->GetParent() ;
908 // if there is nothing special -> use default
909 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
914 RGBBackColor( &m_backgroundColour.GetPixel()) ;
919 for (wxNode *node = GetChildren().First(); node; node = node->Next())
921 wxWindowMac *child = (wxWindowMac*)node->Data();
923 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
924 SectRect( &clientrect , rect , &clientrect ) ;
926 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
927 if ( child->GetMacRootWindow() == window && child->IsShown() )
929 wxMacDrawingClientHelper focus( this ) ;
932 child->MacEraseBackground( &clientrect ) ;
939 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
944 wxMacDrawingClientHelper
focus( this ) ;
948 client
= GetClientAreaOrigin( ) ;
949 Rect clientrect
= { -client
.y
, -client
.x
, m_height
- client
.y
, m_width
- client
.x
} ;
950 // ClipRect( &clientrect ) ;
954 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
955 SectRect( &clientrect
, &r
, &clientrect
) ;
957 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
960 m_macEraseOnRedraw
= false ;
962 m_macEraseOnRedraw
= true ;
965 // Responds to colour changes: passes event on to children.
966 void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent
& event
)
968 wxNode
*node
= GetChildren().First();
971 // Only propagate to non-top-level windows
972 wxWindowMac
*win
= (wxWindowMac
*)node
->Data();
973 if ( win
->GetParent() )
975 wxSysColourChangedEvent event2
;
976 event
.m_eventObject
= win
;
977 win
->GetEventHandler()->ProcessEvent(event2
);
984 #if wxUSE_CARET && WXWIN_COMPATIBILITY
985 // ---------------------------------------------------------------------------
986 // Caret manipulation
987 // ---------------------------------------------------------------------------
989 void wxWindowMac::CreateCaret(int w
, int h
)
991 SetCaret(new wxCaret(this, w
, h
));
994 void wxWindowMac::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
996 wxFAIL_MSG("not implemented");
999 void wxWindowMac::ShowCaret(bool show
)
1001 wxCHECK_RET( m_caret
, "no caret to show" );
1003 m_caret
->Show(show
);
1006 void wxWindowMac::DestroyCaret()
1011 void wxWindowMac::SetCaretPos(int x
, int y
)
1013 wxCHECK_RET( m_caret
, "no caret to move" );
1015 m_caret
->Move(x
, y
);
1018 void wxWindowMac::GetCaretPos(int *x
, int *y
) const
1020 wxCHECK_RET( m_caret
, "no caret to get position of" );
1022 m_caret
->GetPosition(x
, y
);
1024 #endif // wxUSE_CARET
1026 wxWindowMac
*wxGetActiveWindow()
1028 // actually this is a windows-only concept
1032 // Coordinates relative to the window
1033 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1035 // We really dont move the mouse programmatically under mac
1038 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1040 // TODO : probably we would adopt the EraseEvent structure
1043 int wxWindowMac::GetScrollPos(int orient
) const
1045 if ( orient
== wxHORIZONTAL
)
1048 return m_hScrollBar
->GetThumbPosition() ;
1053 return m_vScrollBar
->GetThumbPosition() ;
1058 // This now returns the whole range, not just the number
1059 // of positions that we can scroll.
1060 int wxWindowMac::GetScrollRange(int orient
) const
1062 if ( orient
== wxHORIZONTAL
)
1065 return m_hScrollBar
->GetRange() ;
1070 return m_vScrollBar
->GetRange() ;
1075 int wxWindowMac::GetScrollThumb(int orient
) const
1077 if ( orient
== wxHORIZONTAL
)
1080 return m_hScrollBar
->GetThumbSize() ;
1085 return m_vScrollBar
->GetThumbSize() ;
1090 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1092 if ( orient
== wxHORIZONTAL
)
1095 m_hScrollBar
->SetThumbPosition( pos
) ;
1100 m_vScrollBar
->SetThumbPosition( pos
) ;
1104 void wxWindowMac::MacCreateRealWindow( const wxString
& title
,
1108 const wxString
& name
)
1111 m_windowStyle
= style
;
1132 m_macWindowData
= new MacWindowData() ;
1134 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1136 // translate the window attributes in the appropriate window class and attributes
1138 WindowClass wclass
= 0;
1139 WindowAttributes attr
= kWindowNoAttributes
;
1141 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1143 wclass
= kFloatingWindowClass
;
1144 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1146 attr
|= kWindowSideTitlebarAttribute
;
1149 else if ( HasFlag( wxCAPTION
) )
1151 if ( HasFlag( wxDIALOG_MODAL
) )
1153 wclass
= kMovableModalWindowClass
;
1157 wclass
= kDocumentWindowClass
;
1162 wclass
= kModalWindowClass
;
1165 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1167 attr
|= kWindowFullZoomAttribute
;
1168 attr
|= kWindowCollapseBoxAttribute
;
1170 if ( HasFlag( wxRESIZE_BORDER
) )
1172 attr
|= kWindowResizableAttribute
;
1174 if ( HasFlag( wxSYSTEM_MENU
) )
1176 attr
|= kWindowCloseBoxAttribute
;
1179 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1180 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1182 if( wxApp::s_macDefaultEncodingIsPC
)
1183 label
= wxMacMakeMacStringFromPC( title
) ;
1186 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1187 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1189 m_macWindowData
->m_macFocus
= NULL
;
1190 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1193 void wxWindowMac::MacPaint( wxPaintEvent
&event
)
1197 void wxWindowMac::MacPaintBorders( )
1199 if( m_macWindowData
)
1202 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1203 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1204 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1205 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1208 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1210 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1211 RGBColor pen1
= sunken
? white
: black
;
1212 RGBColor pen2
= sunken
? shadow
: face
;
1213 RGBColor pen3
= sunken
? face
: shadow
;
1214 RGBColor pen4
= sunken
? black
: white
;
1216 RGBForeColor( &pen1
) ;
1218 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1219 FrameRect( &rect
) ;
1221 RGBForeColor( &pen2
) ;
1223 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1224 FrameRect( &rect
) ;
1226 RGBForeColor( &pen3
) ;
1228 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1229 FrameRect( &rect
) ;
1231 RGBForeColor( &pen4
) ;
1234 LineTo( m_width
- 3 , 0 ) ;
1236 LineTo( 0 , m_height
- 3 ) ;
1239 else if (HasFlag(wxSIMPLE_BORDER
))
1241 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1242 RGBForeColor( &black
) ;
1243 FrameRect( &rect
) ;
1246 if ( this->GetParent() )
1248 wxPaintDC dc(GetParent());
1249 GetParent()->PrepareDC(dc);
1251 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1253 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1255 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1256 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1258 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1259 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1260 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1261 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1264 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1267 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1270 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1273 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1274 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1276 else if (HasFlag(wxDOUBLE_BORDER))
1278 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1280 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1281 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1283 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1284 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1285 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1286 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1289 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1292 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1295 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1298 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1299 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1301 else if (HasFlag(wxSIMPLE_BORDER))
1303 dc.SetPen(*wxBLACK_PEN);
1304 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1310 // New function that will replace some of the above.
1311 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1312 int range
, bool refresh
)
1314 if ( orient
== wxHORIZONTAL
)
1318 if ( range
== 0 || thumbVisible
>= range
)
1320 if ( m_hScrollBar
->IsShown() )
1321 m_hScrollBar
->Show(false) ;
1325 if ( !m_hScrollBar
->IsShown() )
1326 m_hScrollBar
->Show(true) ;
1327 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1335 if ( range
== 0 || thumbVisible
>= range
)
1337 if ( m_vScrollBar
->IsShown() )
1338 m_vScrollBar
->Show(false) ;
1342 if ( !m_vScrollBar
->IsShown() )
1343 m_vScrollBar
->Show(true) ;
1344 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1348 MacRepositionScrollBars() ;
1351 // Does a physical scroll
1352 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1354 wxMacDrawingClientHelper
focus( this ) ;
1357 int width
, height
;
1358 GetClientSize( &width
, &height
) ;
1360 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1362 RgnHandle updateRgn
= NewRgn() ;
1363 ClipRect( &scrollrect
) ;
1366 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1367 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1369 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1370 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1371 DisposeRgn( updateRgn
) ;
1374 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1376 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1377 if (child
== m_vScrollBar
) continue;
1378 if (child
== m_hScrollBar
) continue;
1379 if (child
->IsTopLevel()) continue;
1381 child
->GetPosition( &x
, &y
);
1383 child
->GetSize( &w
, &h
);
1384 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1389 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
1391 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1393 wxScrollWinEvent wevent
;
1394 wevent
.SetPosition(event
.GetPosition());
1395 wevent
.SetOrientation(event
.GetOrientation());
1396 wevent
.m_eventObject
= this;
1398 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1399 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1401 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1402 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1404 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1405 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1407 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1408 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1410 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1411 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1413 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1414 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1416 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1417 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1420 GetEventHandler()->ProcessEvent(wevent
);
1424 bool wxWindowMac::SetFont(const wxFont
& font
)
1426 if ( !wxWindowBase::SetFont(font
) )
1435 // Get the window with the focus
1436 wxWindowMac
*wxWindowBase::FindFocus()
1438 return gFocusWindow
;
1441 #if WXWIN_COMPATIBILITY
1442 // If nothing defined for this, try the parent.
1443 // E.g. we may be a button loaded from a resource, with no callback function
1445 void wxWindowMac::OnCommand(wxWindowMac
& win
, wxCommandEvent
& event
)
1447 if ( GetEventHandler()->ProcessEvent(event
) )
1450 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1452 #endif // WXWIN_COMPATIBILITY_2
1454 #if WXWIN_COMPATIBILITY
1455 wxObject
* wxWindowMac::GetChild(int number
) const
1457 // Return a pointer to the Nth object in the Panel
1458 wxNode
*node
= GetChildren().First();
1461 node
= node
->Next();
1464 wxObject
*obj
= (wxObject
*)node
->Data();
1470 #endif // WXWIN_COMPATIBILITY
1472 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
1474 // panel wants to track the window which was the last to have focus in it,
1475 // so we want to set ourselves as the window which last had focus
1477 // notice that it's also important to do it upwards the tree becaus
1478 // otherwise when the top level panel gets focus, it won't set it back to
1479 // us, but to some other sibling
1480 wxWindowMac
*win
= this;
1483 wxWindowMac
*parent
= win
->GetParent();
1484 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1487 panel
->SetLastFocus(win
);
1496 void wxWindowMac::Clear()
1498 if ( m_macWindowData
)
1500 wxMacDrawingClientHelper
helper ( this ) ;
1502 wxPoint origin
= GetClientAreaOrigin() ;
1503 GetClientSize( &w
, &h
) ;
1504 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1505 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1510 wxClientDC
dc(this);
1511 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1512 dc
.SetBackground(brush
);
1517 // Setup background and foreground colours correctly
1518 void wxWindowMac::SetupColours()
1521 SetBackgroundColour(GetParent()->GetBackgroundColour());
1524 void wxWindowMac::OnIdle(wxIdleEvent
& event
)
1527 // Check if we need to send a LEAVE event
1528 if (m_mouseInWindow)
1531 ::GetCursorPos(&pt);
1532 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1534 // Generate a LEAVE event
1535 m_mouseInWindow = FALSE;
1536 MSWOnMouseLeave(pt.x, pt.y, 0);
1541 // This calls the UI-update mechanism (querying windows for
1542 // menu/toolbar/control state information)
1546 // Raise the window to the top of the Z order
1547 void wxWindowMac::Raise()
1549 if ( m_macWindowData
)
1551 UMABringToFront( m_macWindowData
->m_macWindow
) ;
1555 // Lower the window to the bottom of the Z order
1556 void wxWindowMac::Lower()
1558 if ( m_macWindowData
)
1560 UMASendBehind( m_macWindowData
->m_macWindow
, NULL
) ;
1564 void wxWindowMac::DoSetClientSize(int width
, int height
)
1566 if ( width
!= -1 || height
!= -1 )
1569 if ( width
!= -1 && m_vScrollBar
)
1570 width
+= MAC_SCROLLBAR_SIZE
;
1571 if ( height
!= -1 && m_vScrollBar
)
1572 height
+= MAC_SCROLLBAR_SIZE
;
1574 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1575 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1577 DoSetSize( -1 , -1 , width
, height
) ;
1582 wxWindowMac
* wxWindowMac::s_lastMouseWindow
= NULL
;
1584 bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindowMac
** outWin
)
1586 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1587 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1590 WindowRef window
= GetMacRootWindow() ;
1592 wxPoint
newPoint( point
) ;
1597 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1599 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1600 // added the m_isShown test --dmazzoni
1601 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1603 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1612 bool wxWindowMac::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindowMac
** outWin
)
1615 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1616 if ( ::FindWindow( pt
, &window
) == 3 )
1618 wxPoint
point( screenpoint
) ;
1619 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1622 win
->ScreenToClient( point
) ;
1623 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1629 extern int wxBusyCursorCount
;
1631 bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent
& event
)
1633 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1634 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1638 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1641 WindowRef window
= GetMacRootWindow() ;
1649 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1651 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1652 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1654 if (child
->MacDispatchMouseEvent(event
))
1662 if ( wxBusyCursorCount
== 0 )
1664 m_cursor
.MacInstall() ;
1667 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1669 // set focus to this window
1670 if (AcceptsFocus() && FindFocus()!=this)
1675 if ( event
.GetEventType() == wxEVT_MOTION
1676 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1677 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1678 wxToolTip::RelayEvent( this , event
);
1679 #endif // wxUSE_TOOLTIPS
1680 GetEventHandler()->ProcessEvent( event
) ;
1687 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
1691 return m_tooltip
->GetTip() ;
1695 void wxWindowMac::MacFireMouseEvent( EventRecord
*ev
)
1697 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1698 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1699 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1701 event
.m_leftDown
= isDown
&& !controlDown
;
1702 event
.m_middleDown
= FALSE
;
1703 event
.m_rightDown
= isDown
&& controlDown
;
1705 if ( ev
->what
== mouseDown
)
1708 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1710 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1712 else if ( ev
->what
== mouseUp
)
1715 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1717 event
.SetEventType(wxEVT_LEFT_UP
) ;
1721 event
.SetEventType(wxEVT_MOTION
) ;
1724 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1725 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1726 event
.m_altDown
= ev
->modifiers
& optionKey
;
1727 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1729 Point localwhere
= ev
->where
;
1732 ::GetPort( &port
) ;
1733 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1734 ::GlobalToLocal( &localwhere
) ;
1737 if ( ev
->what
== mouseDown
)
1739 if ( ev
->when
- lastWhen
<= GetDblTime() )
1741 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1744 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1746 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1752 lastWhen
= ev
->when
;
1754 lastWhere
= localwhere
;
1757 event
.m_x
= localwhere
.h
;
1758 event
.m_y
= localwhere
.v
;
1763 wxPoint origin = GetClientAreaOrigin() ;
1765 event.m_x += origin.x ;
1766 event.m_y += origin.y ;
1769 event
.m_timeStamp
= ev
->when
;
1770 event
.SetEventObject(this);
1771 if ( wxTheApp
->s_captureWindow
)
1775 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1778 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1779 if ( ev
->what
== mouseUp
)
1781 wxTheApp
->s_captureWindow
= NULL
;
1782 if ( wxBusyCursorCount
== 0 )
1784 m_cursor
.MacInstall() ;
1790 MacDispatchMouseEvent( event
) ;
1794 void wxWindowMac::MacMouseDown( EventRecord
*ev
, short part
)
1796 MacFireMouseEvent( ev
) ;
1799 void wxWindowMac::MacMouseUp( EventRecord
*ev
, short part
)
1805 MacFireMouseEvent( ev
) ;
1811 void wxWindowMac::MacMouseMoved( EventRecord
*ev
, short part
)
1817 MacFireMouseEvent( ev
) ;
1822 void wxWindowMac::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1824 if ( !m_macWindowData
->m_macHasReceivedFirstActivate
)
1825 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1827 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1828 event
.m_timeStamp
= ev
->when
;
1829 event
.SetEventObject(this);
1831 GetEventHandler()->ProcessEvent(event
);
1834 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1835 // MacUpdateImmediately() ;
1838 void wxWindowMac::MacRedraw( RgnHandle updatergn
, long time
)
1840 // updatergn is always already clipped to our boundaries
1841 WindowRef window
= GetMacRootWindow() ;
1842 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1843 RgnHandle ownUpdateRgn
= NewRgn() ;
1844 CopyRgn( updatergn
, ownUpdateRgn
) ;
1847 wxMacDrawingHelper
focus( this ) ; // was client
1850 WindowRef window
= GetMacRootWindow() ;
1851 bool eraseBackground
= false ;
1852 if ( m_macWindowData
)
1853 eraseBackground
= true ;
1854 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1856 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1858 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1860 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1861 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1862 // either a non gray background color or a non control window
1865 wxWindowMac
* parent
= GetParent() ;
1868 if ( parent
->GetMacRootWindow() != window
)
1870 // we are in a different window on the mac system
1875 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1877 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1879 // if we have any other colours in the hierarchy
1880 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1883 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1884 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1887 GetRegionBounds( updatergn
, &box
) ;
1888 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1897 parent
= parent
->GetParent() ;
1901 // if there is nothing special -> use default
1902 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1907 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1909 // subtract all non transparent children from updatergn
1911 RgnHandle childarea
= NewRgn() ;
1912 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1914 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1915 // eventually test for transparent windows
1916 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1918 if ( child
->GetBackgroundColour() != m_backgroundColour
&& !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1920 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1921 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1925 DisposeRgn( childarea
) ;
1927 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1928 eraseBackground
= true ;
1929 SetClip( ownUpdateRgn
) ;
1930 if ( m_macEraseOnRedraw
) {
1931 if ( eraseBackground
)
1933 EraseRgn( ownUpdateRgn
) ;
1937 m_macEraseOnRedraw
= true ;
1942 RgnHandle newupdate
= NewRgn() ;
1943 wxSize point
= GetClientSize() ;
1944 wxPoint origin
= GetClientAreaOrigin() ;
1946 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1947 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1948 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1949 m_updateRegion
= newupdate
;
1950 DisposeRgn( newupdate
) ;
1955 event
.m_timeStamp
= time
;
1956 event
.SetEventObject(this);
1957 GetEventHandler()->ProcessEvent(event
);
1961 RgnHandle childupdate
= NewRgn() ;
1963 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1965 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
1966 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1967 SectRgn( childupdate
, updatergn
, childupdate
) ;
1968 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1969 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1971 // because dialogs may also be children
1972 child
->MacRedraw( childupdate
, time
) ;
1975 DisposeRgn( childupdate
) ;
1976 // eventually a draw grow box here
1979 void wxWindowMac::MacUpdateImmediately()
1981 WindowRef window
= GetMacRootWindow() ;
1984 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1986 AGAPortHelper
help( GetWindowPort(window
) ) ;
1988 AGAPortHelper
help( (window
) ) ;
1990 SetOrigin( 0 , 0 ) ;
1991 BeginUpdate( window
) ;
1994 RgnHandle region
= NewRgn();
1998 GetPortVisibleRegion( GetWindowPort( window
), region
);
2000 // if windowshade gives incompatibility , take the follwing out
2001 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2003 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
2005 DisposeRgn( region
);
2008 EndUpdate( window
) ;
2012 void wxWindowMac::MacUpdate( EventRecord
*ev
)
2014 WindowRef window
= (WindowRef
) ev
->message
;
2015 wxWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2017 AGAPortHelper
help( GetWindowPort(window
) ) ;
2019 AGAPortHelper
help( (window
) ) ;
2021 SetOrigin( 0 , 0 ) ;
2022 BeginUpdate( window
) ;
2025 RgnHandle region
= NewRgn();
2029 GetPortVisibleRegion( GetWindowPort( window
), region
);
2031 // if windowshade gives incompatibility , take the follwing out
2032 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2034 MacRedraw( region
, ev
->when
) ;
2036 DisposeRgn( region
);
2039 EndUpdate( window
) ;
2042 WindowRef
wxWindowMac::GetMacRootWindow() const
2044 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2048 if ( iter
->m_macWindowData
)
2049 return iter
->m_macWindowData
->m_macWindow
;
2051 iter
= iter
->GetParent() ;
2053 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2057 void wxWindowMac::MacCreateScrollBars( long style
)
2059 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2061 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2062 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2064 GetClientSize( &width
, &height
) ;
2066 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2067 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2068 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2069 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2071 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2072 vSize
, wxVERTICAL
);
2074 if ( style
& wxVSCROLL
)
2080 m_vScrollBar
->Show(false) ;
2082 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2083 hSize
, wxHORIZONTAL
);
2084 if ( style
& wxHSCROLL
)
2089 m_hScrollBar
->Show(false) ;
2092 // because the create does not take into account the client area origin
2093 MacRepositionScrollBars() ; // we might have a real position shift
2096 void wxWindowMac::MacRepositionScrollBars()
2098 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2099 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2101 // get real client area
2103 int width
= m_width
;
2104 int height
= m_height
;
2106 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2107 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2109 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2110 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2111 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2112 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2119 MacClientToRootWindow( &x
, &y
) ;
2120 MacClientToRootWindow( &w
, &h
) ;
2122 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2124 int totW
= 10000 , totH
= 10000;
2127 if ( iter
->m_macWindowData
)
2129 totW
= iter
->m_width
;
2130 totH
= iter
->m_height
;
2134 iter
= iter
->GetParent() ;
2162 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2166 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2170 void wxWindowMac::MacKeyDown( EventRecord
*ev
)
2176 bool wxWindowMac::AcceptsFocus() const
2178 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2181 ControlHandle
wxWindowMac::MacGetContainerForEmbedding()
2183 if ( m_macWindowData
)
2184 return m_macWindowData
->m_macRootControl
;
2186 return GetParent()->MacGetContainerForEmbedding() ;
2189 void wxWindowMac::MacSuperChangedPosition()
2191 // only window-absolute structures have to be moved i.e. controls
2193 wxNode
*node
= GetChildren().First();
2196 wxWindowMac
*child
= (wxWindowMac
*)node
->Data();
2197 child
->MacSuperChangedPosition() ;
2198 node
= node
->Next();
2202 bool wxWindowMac::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2204 if ( window
== NULL
)
2210 ::GetPort(&currPort
);
2211 port
= UMAGetWindowPort( window
) ;
2212 if (currPort
!= port
)
2215 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2216 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2220 bool wxWindowMac::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindowMac
* win
)
2222 if ( window
== NULL
)
2227 ::GetPort(&currPort
);
2228 port
= UMAGetWindowPort( window
) ;
2229 if (currPort
!= port
)
2231 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2232 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2233 ::ClipRect(&clipRect
);
2236 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2237 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2238 Pattern whiteColor
;
2240 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2241 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2245 void wxWindowMac::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2247 if ( m_macWindowData
)
2253 clipRect
->right
= m_width
;
2254 clipRect
->bottom
= m_height
;
2255 *window
= m_macWindowData
->m_macWindow
;
2260 wxASSERT( GetParent() != NULL
) ;
2261 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2262 localOrigin
->h
+= m_x
;
2263 localOrigin
->v
+= m_y
;
2264 OffsetRect(clipRect
, -m_x
, -m_y
);
2269 myClip
.right
= m_width
;
2270 myClip
.bottom
= m_height
;
2271 SectRect(clipRect
, &myClip
, clipRect
);
2275 void wxWindowMac::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2277 // int width , height ;
2278 // GetClientSize( &width , &height ) ;
2280 if ( m_macWindowData
)
2286 clipRect
->right
= m_width
;//width;
2287 clipRect
->bottom
= m_height
;// height;
2288 *window
= m_macWindowData
->m_macWindow
;
2293 wxASSERT( GetParent() != NULL
) ;
2295 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2297 localOrigin
->h
+= m_x
;
2298 localOrigin
->v
+= m_y
;
2299 OffsetRect(clipRect
, -m_x
, -m_y
);
2304 myClip
.right
= m_width
;//width;
2305 myClip
.bottom
= m_height
;// height;
2306 SectRect(clipRect
, &myClip
, clipRect
);
2310 void wxWindowMac::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindowMac
** rootwin
)
2312 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2314 int width
, height
;
2315 GetClientSize( &width
, &height
) ;
2317 client
= GetClientAreaOrigin( ) ;
2319 localOrigin
->h
+= client
.x
;
2320 localOrigin
->v
+= client
.y
;
2321 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2326 myClip
.right
= width
;
2327 myClip
.bottom
= height
;
2328 SectRect(clipRect
, &myClip
, clipRect
);
2331 long wxWindowMac::MacGetLeftBorderSize( ) const
2333 if( m_macWindowData
)
2336 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2340 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2344 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2351 long wxWindowMac::MacGetRightBorderSize( ) const
2353 if( m_macWindowData
)
2356 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2360 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2364 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2371 long wxWindowMac::MacGetTopBorderSize( ) const
2373 if( m_macWindowData
)
2376 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2380 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2384 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2391 long wxWindowMac::MacGetBottomBorderSize( ) const
2393 if( m_macWindowData
)
2396 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2400 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2404 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2411 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2413 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2417 wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac
* theWindow
)
2423 wxWindowMac
*rootwin
;
2424 m_currentPort
= NULL
;
2426 GetPort( &m_formerPort
) ;
2429 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2430 m_currentPort
= UMAGetWindowPort( window
) ;
2431 if ( m_formerPort
!= m_currentPort
)
2432 SetPort( m_currentPort
) ;
2433 GetPenState( &m_savedPenState
) ;
2434 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2439 wxMacDrawingHelper::~wxMacDrawingHelper()
2443 SetPort( m_currentPort
) ;
2444 SetPenState( &m_savedPenState
) ;
2445 SetOrigin( 0 , 0 ) ;
2447 GetPortBounds( m_currentPort
, &portRect
) ;
2448 ClipRect( &portRect
) ;
2451 if ( m_formerPort
!= m_currentPort
)
2452 SetPort( m_formerPort
) ;
2455 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac
* theWindow
)
2461 wxWindowMac
*rootwin
;
2462 m_currentPort
= NULL
;
2464 GetPort( &m_formerPort
) ;
2468 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2469 m_currentPort
= UMAGetWindowPort( window
) ;
2470 if ( m_formerPort
!= m_currentPort
)
2471 SetPort( m_currentPort
) ;
2472 GetPenState( &m_savedPenState
) ;
2473 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2478 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2482 SetPort( m_currentPort
) ;
2483 SetPenState( &m_savedPenState
) ;
2484 SetOrigin( 0 , 0 ) ;
2486 GetPortBounds( m_currentPort
, &portRect
) ;
2487 ClipRect( &portRect
) ;
2490 if ( m_formerPort
!= m_currentPort
)
2491 SetPort( m_formerPort
) ;
2494 // Find the wxWindowMac at the current mouse position, returning the mouse
2496 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2498 pt
= wxGetMousePosition();
2499 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2503 // Get the current mouse position.
2504 wxPoint
wxGetMousePosition()
2507 wxGetMousePosition(& x
, & y
);
2508 return wxPoint(x
, y
);