1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
50 #define MAC_SCROLLBAR_SIZE 15
51 #define MAC_SMALL_SCROLLBAR_SIZE 11
53 #include "wx/mac/uma.h"
56 #include <ToolUtils.h>
58 #include <MacTextEditor.h>
61 #if TARGET_API_MAC_OSX
63 #include <HIToolbox/HIView.h>
67 #if wxUSE_DRAG_AND_DROP
73 extern wxList wxPendingDelete
;
75 #ifdef __WXUNIVERSAL__
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
79 #endif // __WXUNIVERSAL__/__WXMAC__
81 #if !USE_SHARED_LIBRARY
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
85 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
86 // TODO EVT_PAINT(wxWindowMac::OnPaint)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
224 if ( thisWindow
->MacIsUserPane() )
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
243 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
246 DisposeRgn( allocatedRgn
) ;
249 case kEventControlVisibilityChanged
:
250 thisWindow
->MacVisibilityChanged() ;
252 case kEventControlEnabledStateChanged
:
253 thisWindow
->MacEnabledStateChanged() ;
255 case kEventControlHiliteChanged
:
256 thisWindow
->MacHiliteChanged() ;
258 case kEventControlSetFocusPart
:
260 Boolean focusEverything
= false ;
261 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
262 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
265 if ( controlPart
== kControlFocusNoPart
)
268 if ( thisWindow
->GetCaret() )
270 thisWindow
->GetCaret()->OnKillFocus();
272 #endif // wxUSE_CARET
273 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
274 event
.SetEventObject(thisWindow
);
275 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
279 // panel wants to track the window which was the last to have focus in it
280 wxChildFocusEvent
eventFocus(thisWindow
);
281 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
284 if ( thisWindow
->GetCaret() )
286 thisWindow
->GetCaret()->OnSetFocus();
288 #endif // wxUSE_CARET
290 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
291 event
.SetEventObject(thisWindow
);
292 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
294 if ( thisWindow
->MacIsUserPane() )
299 case kEventControlHit
:
301 result
= thisWindow
->MacControlHit( handler
, event
) ;
310 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
312 OSStatus result
= eventNotHandledErr
;
314 wxMacCarbonEvent
cEvent( event
) ;
316 ControlRef controlRef
;
317 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
318 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
319 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
321 switch( GetEventKind( event
) )
323 case kEventServiceGetTypes
:
327 textCtrl
->GetSelection( &from
, &to
) ;
329 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
331 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
332 if ( textCtrl
->IsEditable() )
333 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
335 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
336 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
338 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
342 CFArrayAppendValue (copyTypes
, typestring
) ;
344 CFArrayAppendValue (pasteTypes
, typestring
) ;
345 CFRelease( typestring
) ;
351 case kEventServiceCopy
:
355 textCtrl
->GetSelection( &from
, &to
) ;
356 wxString val
= textCtrl
->GetValue() ;
357 val
= val
.Mid( from
, to
- from
) ;
358 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
359 verify_noerr( ClearScrap( &scrapRef
) ) ;
360 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
364 case kEventServicePaste
:
367 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
368 Size textSize
, pastedSize
;
369 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
371 char *content
= new char[textSize
] ;
372 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
373 content
[textSize
-1] = 0 ;
375 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
377 textCtrl
->WriteText( wxString( content
) ) ;
388 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
390 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
391 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
392 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
393 OSStatus result
= eventNotHandledErr
;
395 switch ( GetEventClass( event
) )
397 case kEventClassControl
:
398 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
400 case kEventClassService
:
401 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
405 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
409 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
411 // ---------------------------------------------------------------------------
412 // UserPane events for non OSX builds
413 // ---------------------------------------------------------------------------
415 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
417 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
418 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
419 win
->MacControlUserPaneDrawProc(part
) ;
422 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
424 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
425 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
426 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
429 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
431 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
432 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
433 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
436 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
438 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
439 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
440 win
->MacControlUserPaneIdleProc() ;
443 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
445 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
446 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
447 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
450 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
452 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
453 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
454 win
->MacControlUserPaneActivateProc(activating
) ;
457 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
459 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
460 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
461 return win
->MacControlUserPaneFocusProc(action
) ;
464 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
466 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
467 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
468 win
->MacControlUserPaneBackgroundProc(info
) ;
471 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
473 RgnHandle rgn
= NewRgn() ;
475 wxMacWindowStateSaver
sv( this ) ;
476 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
477 MacDoRedraw( rgn
, 0 ) ;
481 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
483 return kControlNoPart
;
486 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
488 return kControlNoPart
;
491 void wxWindowMac::MacControlUserPaneIdleProc()
495 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
497 return kControlNoPart
;
500 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
504 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
506 return kControlNoPart
;
509 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
513 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
514 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
515 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
516 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
517 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
518 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
519 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
520 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
522 // ===========================================================================
524 // ===========================================================================
526 wxList
wxWinMacControlList(wxKEY_INTEGER
);
528 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
530 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
533 return (wxControl
*)node
->GetData();
536 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
538 // adding NULL ControlRef is (first) surely a result of an error and
539 // (secondly) breaks native event processing
540 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
542 if ( !wxWinMacControlList
.Find((long)inControl
) )
543 wxWinMacControlList
.Append((long)inControl
, control
);
546 void wxRemoveMacControlAssociation(wxWindow
*control
)
548 wxWinMacControlList
.DeleteObject(control
);
552 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
554 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
556 // we have to setup the brush in the current port and return noErr
557 // or return an error code so that the control manager walks further up the
558 // hierarchy to find a correct background
560 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
562 OSStatus status
= paramErr
;
565 case kControlMsgApplyTextColor
:
567 case kControlMsgSetUpBackground
:
569 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
573 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
576 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
578 // this clipping is only needed for non HIView
580 RgnHandle clip
= NewRgn() ;
583 wx
->MacWindowToRootWindow( &x
,&y
) ;
584 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
585 OffsetRgn( clip
, x
, y
) ;
592 else if ( wx->MacIsUserPane() )
594 // if we don't have a valid brush for such a control, we have to call the
595 // setup of our parent ourselves
596 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
609 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
610 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
614 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
617 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
622 // ----------------------------------------------------------------------------
623 // constructors and such
624 // ----------------------------------------------------------------------------
626 wxWindowMac::wxWindowMac()
631 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
636 const wxString
& name
)
639 Create(parent
, id
, pos
, size
, style
, name
);
642 void wxWindowMac::Init()
646 #if WXWIN_COMPATIBILITY_2_4
647 m_backgroundTransparent
= FALSE
;
650 // as all windows are created with WS_VISIBLE style...
653 m_hScrollBar
= NULL
;
654 m_vScrollBar
= NULL
;
655 m_macBackgroundBrush
= wxNullBrush
;
657 m_macIsUserPane
= TRUE
;
659 // make sure all proc ptrs are available
661 if ( gControlUserPaneDrawUPP
== NULL
)
663 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
664 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
665 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
666 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
667 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
668 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
669 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
670 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
672 if ( wxMacLiveScrollbarActionUPP
== NULL
)
674 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
677 if ( wxMacSetupControlBackgroundUPP
== NULL
)
679 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
682 // we need a valid font for the encodings
683 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
687 wxWindowMac::~wxWindowMac()
691 m_isBeingDeleted
= TRUE
;
693 #ifndef __WXUNIVERSAL__
694 // VS: make sure there's no wxFrame with last focus set to us:
695 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
697 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
700 if ( frame
->GetLastFocus() == this )
702 frame
->SetLastFocus((wxWindow
*)NULL
);
707 #endif // __WXUNIVERSAL__
709 // wxRemoveMacControlAssociation( this ) ;
710 // If we delete an item, we should initialize the parent panel,
711 // because it could now be invalid.
712 wxWindow
*parent
= GetParent() ;
715 if (parent
->GetDefaultItem() == (wxButton
*) this)
716 parent
->SetDefaultItem(NULL
);
718 if ( m_peer
&& m_peer
->Ok() )
720 // in case the callback might be called during destruction
721 wxRemoveMacControlAssociation( this) ;
722 // we currently are not using this hook
723 // ::SetControlColorProc( *m_peer , NULL ) ;
727 if ( g_MacLastWindow
== this )
729 g_MacLastWindow
= NULL
;
732 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
735 if ( frame
->GetLastFocus() == this )
736 frame
->SetLastFocus( NULL
) ;
741 // delete our drop target if we've got one
742 #if wxUSE_DRAG_AND_DROP
743 if ( m_dropTarget
!= NULL
)
748 #endif // wxUSE_DRAG_AND_DROP
752 WXWidget
wxWindowMac::GetHandle() const
754 return (WXWidget
) m_peer
->GetControlRef() ;
758 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
760 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
761 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
762 GetEventTypeCount(eventList
), eventList
, this,
763 (EventHandlerRef
*)&m_macControlEventHandler
);
768 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
772 const wxString
& name
)
774 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
776 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
779 parent
->AddChild(this);
781 m_windowVariant
= parent
->GetWindowVariant() ;
783 if ( m_macIsUserPane
)
785 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
788 | kControlSupportsEmbedding
789 // | kControlSupportsLiveFeedback
790 // | kControlHasSpecialBackground
791 // | kControlSupportsCalcBestRect
792 // | kControlHandlesTracking
793 | kControlSupportsFocus
794 // | kControlWantsActivate
795 // | kControlWantsIdle
798 m_peer
= new wxMacControl() ;
799 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
802 MacPostControlCreate(pos
,size
) ;
803 #if !TARGET_API_MAC_OSX
804 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
805 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
806 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
807 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
808 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
809 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
810 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
811 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
814 #ifndef __WXUNIVERSAL__
815 // Don't give scrollbars to wxControls unless they ask for them
816 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
817 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
819 MacCreateScrollBars( style
) ;
823 wxWindowCreateEvent
event(this);
824 GetEventHandler()->AddPendingEvent(event
);
829 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
831 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
833 m_peer
->SetReference( (long) this ) ;
835 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
837 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
838 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
839 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
841 // adjust font, controlsize etc
842 DoSetWindowVariant( m_windowVariant
) ;
844 #if !TARGET_API_MAC_OSX
845 // eventually we can fix some clipping issues be reactivating this hook
846 //if ( m_macIsUserPane )
847 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
849 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
851 if (!m_macIsUserPane
)
853 SetInitialBestSize(size
);
856 SetCursor( *wxSTANDARD_CURSOR
) ;
859 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
861 // Don't assert, in case we set the window variant before
862 // the window is created
863 // wxASSERT( m_peer->Ok() ) ;
865 m_windowVariant
= variant
;
867 if (m_peer
== NULL
|| !m_peer
->Ok())
871 ThemeFontID themeFont
= kThemeSystemFont
;
873 // we will get that from the settings later
874 // and make this NORMAL later, but first
875 // we have a few calculations that we must fix
879 case wxWINDOW_VARIANT_NORMAL
:
880 size
= kControlSizeNormal
;
881 themeFont
= kThemeSystemFont
;
883 case wxWINDOW_VARIANT_SMALL
:
884 size
= kControlSizeSmall
;
885 themeFont
= kThemeSmallSystemFont
;
887 case wxWINDOW_VARIANT_MINI
:
888 if (UMAGetSystemVersion() >= 0x1030 )
890 // not always defined in the headers
896 size
= kControlSizeSmall
;
897 themeFont
= kThemeSmallSystemFont
;
900 case wxWINDOW_VARIANT_LARGE
:
901 size
= kControlSizeLarge
;
902 themeFont
= kThemeSystemFont
;
905 wxFAIL_MSG(_T("unexpected window variant"));
908 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
911 font
.MacCreateThemeFont( themeFont
) ;
915 void wxWindowMac::MacUpdateControlFont()
917 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
921 bool wxWindowMac::SetFont(const wxFont
& font
)
923 bool retval
= !wxWindowBase::SetFont( font
) ;
925 MacUpdateControlFont() ;
930 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
932 if ( !wxWindowBase::SetForegroundColour(col
) )
935 MacUpdateControlFont() ;
940 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
942 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
946 wxColour
newCol(GetBackgroundColour());
947 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
949 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
951 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
953 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
957 brush
.SetColour( newCol
) ;
959 MacSetBackgroundBrush( brush
) ;
961 MacUpdateControlFont() ;
966 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
968 m_macBackgroundBrush
= brush
;
969 m_peer
->SetBackground( brush
) ;
972 bool wxWindowMac::MacCanFocus() const
974 // there is currently no way to determine whether the window is running in full keyboard
975 // access mode, therefore we cannot rely on these features, yet the only other way would be
976 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
977 // in event handlers...
978 UInt32 features
= 0 ;
979 m_peer
->GetFeatures( & features
) ;
980 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
984 void wxWindowMac::SetFocus()
986 if ( AcceptsFocus() )
988 #if !TARGET_API_MAC_OSX
989 wxWindow
* former
= FindFocus() ;
991 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
992 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
993 // leave in case of an error
994 if ( err
== errCouldntSetFocus
)
997 #if !TARGET_API_MAC_OSX
998 // emulate carbon events when running under carbonlib where they are not natively available
1001 EventRef evRef
= NULL
;
1002 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1005 wxMacCarbonEvent
cEvent( evRef
) ;
1006 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1007 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1009 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1010 ReleaseEvent(evRef
) ;
1012 // send new focus event
1014 EventRef evRef
= NULL
;
1015 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1018 wxMacCarbonEvent
cEvent( evRef
) ;
1019 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1020 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1022 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1023 ReleaseEvent(evRef
) ;
1030 void wxWindowMac::DoCaptureMouse()
1032 wxTheApp
->s_captureWindow
= this ;
1035 wxWindow
* wxWindowBase::GetCapture()
1037 return wxTheApp
->s_captureWindow
;
1040 void wxWindowMac::DoReleaseMouse()
1042 wxTheApp
->s_captureWindow
= NULL
;
1045 #if wxUSE_DRAG_AND_DROP
1047 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1049 if ( m_dropTarget
!= 0 ) {
1050 delete m_dropTarget
;
1053 m_dropTarget
= pDropTarget
;
1054 if ( m_dropTarget
!= 0 )
1062 // Old style file-manager drag&drop
1063 void wxWindowMac::DragAcceptFiles(bool accept
)
1068 // Returns the size of the native control. In the case of the toplevel window
1069 // this is the content area root control
1071 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1072 int& w
, int& h
) const
1075 m_peer
->GetRect( &bounds
) ;
1080 w
= bounds
.right
- bounds
.left
;
1081 h
= bounds
.bottom
- bounds
.top
;
1084 // From a wx position / size calculate the appropriate size of the native control
1086 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1089 int& w
, int& h
, bool adjustOrigin
) const
1091 // the desired size, minus the border pixels gives the correct size of the control
1095 // todo the default calls may be used as soon as PostCreateControl Is moved here
1096 w
= size
.x
; // WidthDefault( size.x );
1097 h
= size
.y
; // HeightDefault( size.y ) ;
1098 #if !TARGET_API_MAC_OSX
1099 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1102 x
+= MacGetLeftBorderSize() ;
1103 y
+= MacGetTopBorderSize() ;
1104 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1105 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1108 AdjustForParentClientOrigin( x
, y
) ;
1112 // Get window size (not client size)
1113 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1115 // take the size of the control and add the borders that have to be drawn outside
1116 int x1
, y1
, w1
, h1
;
1118 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1120 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1121 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1127 // get the position of the bounds of this window in client coordinates of its parent
1128 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1130 int x1
, y1
, w1
,h1
;
1131 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1132 x1
-= MacGetLeftBorderSize() ;
1133 y1
-= MacGetTopBorderSize() ;
1135 #if !TARGET_API_MAC_OSX
1136 if ( !GetParent()->IsTopLevel() )
1139 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1144 if ( !IsTopLevel() )
1146 wxWindow
*parent
= GetParent();
1149 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1150 x1
+= parent
->MacGetLeftBorderSize() ;
1151 y1
+= parent
->MacGetTopBorderSize() ;
1152 // and now to client coordinates
1153 wxPoint
pt(parent
->GetClientAreaOrigin());
1162 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1164 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1166 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1169 Point localwhere
= {0,0} ;
1171 if(x
) localwhere
.h
= * x
;
1172 if(y
) localwhere
.v
= * y
;
1174 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1175 if(x
) *x
= localwhere
.h
;
1176 if(y
) *y
= localwhere
.v
;
1179 MacRootWindowToWindow( x
, y
) ;
1181 wxPoint origin
= GetClientAreaOrigin() ;
1182 if(x
) *x
-= origin
.x
;
1183 if(y
) *y
-= origin
.y
;
1186 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1188 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1189 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1191 wxPoint origin
= GetClientAreaOrigin() ;
1192 if(x
) *x
+= origin
.x
;
1193 if(y
) *y
+= origin
.y
;
1195 MacWindowToRootWindow( x
, y
) ;
1198 Point localwhere
= { 0,0 };
1199 if(x
) localwhere
.h
= * x
;
1200 if(y
) localwhere
.v
= * y
;
1201 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1202 if(x
) *x
= localwhere
.h
;
1203 if(y
) *y
= localwhere
.v
;
1207 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1209 wxPoint origin
= GetClientAreaOrigin() ;
1210 if(x
) *x
+= origin
.x
;
1211 if(y
) *y
+= origin
.y
;
1213 MacWindowToRootWindow( x
, y
) ;
1216 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1218 MacRootWindowToWindow( x
, y
) ;
1220 wxPoint origin
= GetClientAreaOrigin() ;
1221 if(x
) *x
-= origin
.x
;
1222 if(y
) *y
-= origin
.y
;
1225 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1227 #if TARGET_API_MAC_OSX
1229 if ( x
) pt
.x
= *x
;
1230 if ( y
) pt
.y
= *y
;
1232 if ( !IsTopLevel() )
1234 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1237 pt
.x
-= MacGetLeftBorderSize() ;
1238 pt
.y
-= MacGetTopBorderSize() ;
1239 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1243 if ( x
) *x
= (int) pt
.x
;
1244 if ( y
) *y
= (int) pt
.y
;
1246 if ( !IsTopLevel() )
1249 m_peer
->GetRect( &bounds
) ;
1250 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1251 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1256 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1261 MacWindowToRootWindow( &x1
, &y1
) ;
1266 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1268 #if TARGET_API_MAC_OSX
1270 if ( x
) pt
.x
= *x
;
1271 if ( y
) pt
.y
= *y
;
1273 if ( !IsTopLevel() )
1275 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1276 pt
.x
+= MacGetLeftBorderSize() ;
1277 pt
.y
+= MacGetTopBorderSize() ;
1280 if ( x
) *x
= (int) pt
.x
;
1281 if ( y
) *y
= (int) pt
.y
;
1283 if ( !IsTopLevel() )
1286 m_peer
->GetRect( &bounds
) ;
1287 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1288 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1293 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1298 MacRootWindowToWindow( &x1
, &y1
) ;
1303 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1305 RgnHandle rgn
= NewRgn() ;
1307 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1309 GetRegionBounds( rgn
, &content
) ;
1314 m_peer
->GetRect( &content
) ;
1317 m_peer
->GetRect( &structure
) ;
1318 #if !TARGET_API_MAC_OSX
1319 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1321 left
= content
.left
- structure
.left
;
1322 top
= content
.top
- structure
.top
;
1323 right
= structure
.right
- content
.right
;
1324 bottom
= structure
.bottom
- content
.bottom
;
1327 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1329 wxSize sizeTotal
= size
;
1331 RgnHandle rgn
= NewRgn() ;
1335 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1337 GetRegionBounds( rgn
, &content
) ;
1342 m_peer
->GetRect( &content
) ;
1345 m_peer
->GetRect( &structure
) ;
1346 #if !TARGET_API_MAC_OSX
1347 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1350 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1351 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1353 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1354 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1360 // Get size *available for subwindows* i.e. excluding menu bar etc.
1361 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1365 RgnHandle rgn
= NewRgn() ;
1367 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1369 GetRegionBounds( rgn
, &content
) ;
1374 m_peer
->GetRect( &content
) ;
1376 #if !TARGET_API_MAC_OSX
1378 m_peer
->GetRect( &structure
) ;
1379 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1381 ww
= content
.right
- content
.left
;
1382 hh
= content
.bottom
- content
.top
;
1384 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1385 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1388 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1394 GetSize( &w , &h ) ;
1396 MacClientToRootWindow( &x1 , &y1 ) ;
1397 MacClientToRootWindow( &w , &h ) ;
1399 wxWindowMac *iter = (wxWindowMac*)this ;
1401 int totW = 10000 , totH = 10000;
1404 if ( iter->IsTopLevel() )
1406 iter->GetSize( &totW , &totH ) ;
1410 iter = iter->GetParent() ;
1413 if (m_hScrollBar && m_hScrollBar->IsShown() )
1415 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1421 if (m_vScrollBar && m_vScrollBar->IsShown() )
1423 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1431 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1433 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1435 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1437 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1444 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1446 if (m_cursor
== cursor
)
1449 if (wxNullCursor
== cursor
)
1451 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1456 if ( ! wxWindowBase::SetCursor( cursor
) )
1460 wxASSERT_MSG( m_cursor
.Ok(),
1461 wxT("cursor must be valid after call to the base version"));
1464 wxWindowMac
*mouseWin
= 0 ;
1466 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1468 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1470 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1471 // position, use it...
1475 ControlPartCode part
;
1476 ControlRef control
;
1477 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1479 mouseWin
= wxFindControlFromMacControl( control
) ;
1482 QDSwapPort( savePort
, NULL
) ;
1485 if ( mouseWin
== this && !wxIsBusy() )
1487 m_cursor
.MacInstall() ;
1494 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1496 menu
->SetInvokingWindow(this);
1499 if ( x
== -1 && y
== -1 )
1501 wxPoint mouse
= wxGetMousePosition();
1502 x
= mouse
.x
; y
= mouse
.y
;
1506 ClientToScreen( &x
, &y
) ;
1509 menu
->MacBeforeDisplay( true ) ;
1510 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1511 if ( HiWord(menuResult
) != 0 )
1514 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1515 wxMenuItem
* item
= NULL
;
1517 item
= menu
->FindItem(id
, &realmenu
) ;
1518 if (item
->IsCheckable())
1520 item
->Check( !item
->IsChecked() ) ;
1522 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1524 menu
->MacAfterDisplay( true ) ;
1526 menu
->SetInvokingWindow(NULL
);
1532 // ----------------------------------------------------------------------------
1534 // ----------------------------------------------------------------------------
1538 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1540 wxWindowBase::DoSetToolTip(tooltip
);
1543 m_tooltip
->SetWindow(this);
1546 #endif // wxUSE_TOOLTIPS
1548 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1550 // this is never called for a toplevel window, so we know we have a parent
1551 int former_x
, former_y
, former_w
, former_h
;
1553 // Get true coordinates of former position
1554 DoGetPosition( &former_x
, &former_y
) ;
1555 DoGetSize( &former_w
, &former_h
) ;
1557 wxWindow
*parent
= GetParent();
1560 wxPoint
pt(parent
->GetClientAreaOrigin());
1565 int actualWidth
= width
;
1566 int actualHeight
= height
;
1570 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1571 actualWidth
= m_minWidth
;
1572 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1573 actualHeight
= m_minHeight
;
1574 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1575 actualWidth
= m_maxWidth
;
1576 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1577 actualHeight
= m_maxHeight
;
1579 bool doMove
= false ;
1580 bool doResize
= false ;
1582 if ( actualX
!= former_x
|| actualY
!= former_y
)
1586 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1591 if ( doMove
|| doResize
)
1593 // we don't adjust twice for the origin
1594 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1595 #if TARGET_API_MAC_OSX
1596 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1597 if ( ! GetParent()->IsTopLevel() )
1599 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1600 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1601 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1602 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1605 bool vis
= m_peer
->IsVisible();
1607 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1609 m_peer
->SetVisibility( false , true ) ;
1610 m_peer
->SetRect( &r
) ;
1612 m_peer
->SetVisibility( true , true ) ;
1614 MacRepositionScrollBars() ;
1617 wxPoint
point(actualX
,actualY
);
1618 wxMoveEvent
event(point
, m_windowId
);
1619 event
.SetEventObject(this);
1620 GetEventHandler()->ProcessEvent(event
) ;
1624 MacRepositionScrollBars() ;
1625 wxSize
size(actualWidth
, actualHeight
);
1626 wxSizeEvent
event(size
, m_windowId
);
1627 event
.SetEventObject(this);
1628 GetEventHandler()->ProcessEvent(event
);
1634 wxSize
wxWindowMac::DoGetBestSize() const
1636 if ( m_macIsUserPane
|| IsTopLevel() )
1637 return wxWindowBase::DoGetBestSize() ;
1639 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1640 int bestWidth
, bestHeight
;
1641 m_peer
->GetBestRect( &bestsize
) ;
1643 if ( EmptyRect( &bestsize
) )
1645 bestsize
.left
= bestsize
.top
= 0 ;
1646 bestsize
.right
= 16 ;
1647 bestsize
.bottom
= 16 ;
1648 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1650 bestsize
.bottom
= 16 ;
1652 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1654 bestsize
.bottom
= 24 ;
1658 // return wxWindowBase::DoGetBestSize() ;
1662 bestWidth
= bestsize
.right
- bestsize
.left
;
1663 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1664 if ( bestHeight
< 10 )
1667 return wxSize(bestWidth
, bestHeight
);
1671 // set the size of the window: if the dimensions are positive, just use them,
1672 // but if any of them is equal to -1, it means that we must find the value for
1673 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1674 // which case -1 is a valid value for x and y)
1676 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1677 // the width/height to best suit our contents, otherwise we reuse the current
1679 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1681 // get the current size and position...
1682 int currentX
, currentY
;
1683 GetPosition(¤tX
, ¤tY
);
1685 int currentW
,currentH
;
1686 GetSize(¤tW
, ¤tH
);
1688 // ... and don't do anything (avoiding flicker) if it's already ok
1689 if ( x
== currentX
&& y
== currentY
&&
1690 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1693 MacRepositionScrollBars() ; // we might have a real position shift
1697 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1699 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1702 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1704 wxSize
size(-1, -1);
1707 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1709 size
= DoGetBestSize();
1714 // just take the current one
1721 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1725 size
= DoGetBestSize();
1727 //else: already called DoGetBestSize() above
1733 // just take the current one
1738 DoMoveWindow(x
, y
, width
, height
);
1742 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1744 RgnHandle rgn
= NewRgn() ;
1746 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1747 GetRegionBounds( rgn
, &content
) ;
1749 #if !TARGET_API_MAC_OSX
1750 // if the content rgn is empty / not supported
1751 // don't attempt to correct the coordinates to wxWindow relative ones
1752 if (!::EmptyRect( &content
) )
1755 m_peer
->GetRect( &structure
) ;
1756 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1760 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1763 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1765 if ( clientheight
!= -1 || clientheight
!= -1 )
1767 int currentclientwidth
, currentclientheight
;
1768 int currentwidth
, currentheight
;
1770 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1771 GetSize( ¤twidth
, ¤theight
) ;
1773 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1774 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1778 void wxWindowMac::SetTitle(const wxString
& title
)
1780 m_label
= wxStripMenuCodes(title
) ;
1782 if ( m_peer
&& m_peer
->Ok() )
1784 m_peer
->SetTitle( m_label
) ;
1789 wxString
wxWindowMac::GetTitle() const
1794 bool wxWindowMac::Show(bool show
)
1796 if ( !wxWindowBase::Show(show
) )
1799 // TODO use visibilityChanged Carbon Event for OSX
1800 bool former
= MacIsReallyShown() ;
1802 m_peer
->SetVisibility( show
, true ) ;
1803 if ( former
!= MacIsReallyShown() )
1804 MacPropagateVisibilityChanged() ;
1808 bool wxWindowMac::Enable(bool enable
)
1810 wxASSERT( m_peer
->Ok() ) ;
1811 if ( !wxWindowBase::Enable(enable
) )
1814 bool former
= MacIsReallyEnabled() ;
1815 m_peer
->Enable( enable
) ;
1817 if ( former
!= MacIsReallyEnabled() )
1818 MacPropagateEnabledStateChanged() ;
1823 // status change propagations (will be not necessary for OSX later )
1826 void wxWindowMac::MacPropagateVisibilityChanged()
1828 #if !TARGET_API_MAC_OSX
1829 MacVisibilityChanged() ;
1831 wxWindowListNode
*node
= GetChildren().GetFirst();
1834 wxWindowMac
*child
= node
->GetData();
1835 if ( child
->IsShown() )
1836 child
->MacPropagateVisibilityChanged( ) ;
1837 node
= node
->GetNext();
1842 void wxWindowMac::MacPropagateEnabledStateChanged( )
1844 #if !TARGET_API_MAC_OSX
1845 MacEnabledStateChanged() ;
1847 wxWindowListNode
*node
= GetChildren().GetFirst();
1850 wxWindowMac
*child
= node
->GetData();
1851 if ( child
->IsEnabled() )
1852 child
->MacPropagateEnabledStateChanged() ;
1853 node
= node
->GetNext();
1858 void wxWindowMac::MacPropagateHiliteChanged( )
1860 #if !TARGET_API_MAC_OSX
1861 MacHiliteChanged() ;
1863 wxWindowListNode
*node
= GetChildren().GetFirst();
1866 wxWindowMac
*child
= node
->GetData();
1867 // if ( child->IsEnabled() )
1868 child
->MacPropagateHiliteChanged() ;
1869 node
= node
->GetNext();
1875 // status change notifications
1878 void wxWindowMac::MacVisibilityChanged()
1882 void wxWindowMac::MacHiliteChanged()
1886 void wxWindowMac::MacEnabledStateChanged()
1891 // status queries on the inherited window's state
1894 bool wxWindowMac::MacIsReallyShown()
1896 // only under OSX the visibility of the TLW is taken into account
1897 #if TARGET_API_MAC_OSX
1898 if ( m_peer
&& m_peer
->Ok() )
1899 return m_peer
->IsVisible();
1901 wxWindow
* win
= this ;
1902 while( win
->IsShown() )
1904 if ( win
->IsTopLevel() )
1907 win
= win
->GetParent() ;
1915 bool wxWindowMac::MacIsReallyEnabled()
1917 return m_peer
->IsEnabled() ;
1920 bool wxWindowMac::MacIsReallyHilited()
1922 return m_peer
->IsActive();
1925 void wxWindowMac::MacFlashInvalidAreas()
1927 #if TARGET_API_MAC_OSX
1928 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1936 int wxWindowMac::GetCharHeight() const
1938 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1939 return dc
.GetCharHeight() ;
1942 int wxWindowMac::GetCharWidth() const
1944 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1945 return dc
.GetCharWidth() ;
1948 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1949 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1951 const wxFont
*fontToUse
= theFont
;
1953 fontToUse
= &m_font
;
1955 wxClientDC
dc( (wxWindowMac
*) this ) ;
1957 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1958 if ( externalLeading
)
1959 *externalLeading
= le
;
1969 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1970 * we always intersect with the entire window, not only with the client area
1973 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1975 if ( m_peer
== NULL
)
1978 #if TARGET_API_MAC_OSX
1980 m_peer
->SetNeedsDisplay( true ) ;
1983 RgnHandle update
= NewRgn() ;
1984 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1985 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1986 wxPoint origin
= GetClientAreaOrigin() ;
1987 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1988 // right now this is wx' window coordinates, as our native peer does not have borders, this is
1990 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1991 m_peer
->SetNeedsDisplay( true , update
) ;
1992 DisposeRgn( update
) ;
1996 RgnHandle updateRgn = NewRgn() ;
1999 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2003 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2004 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2006 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2007 DisposeRgn(updateRgn) ;
2009 if ( m_peer
->IsVisible())
2011 m_peer
->SetVisibility( false , false ) ;
2012 m_peer
->SetVisibility( true , true ) ;
2015 if ( MacGetTopLevelWindow() == NULL )
2018 if ( !m_peer->IsVisible())
2021 wxPoint client = GetClientAreaOrigin();
2024 int x2 = m_width - client.x;
2025 int y2 = m_height - client.y;
2027 if (IsKindOf( CLASSINFO(wxButton)))
2029 // buttons have an "aura"
2036 Rect clientrect = { y1, x1, y2, x2 };
2040 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2041 SectRect( &clientrect , &r , &clientrect ) ;
2044 if ( !EmptyRect( &clientrect ) )
2046 int top = 0 , left = 0 ;
2048 MacClientToRootWindow( &left , &top ) ;
2049 OffsetRect( &clientrect , left , top ) ;
2051 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2057 void wxWindowMac::Freeze()
2059 #if TARGET_API_MAC_OSX
2060 if ( !m_frozenness
++ )
2062 m_peer
->SetDrawingEnabled( false ) ;
2068 void wxWindowMac::Thaw()
2070 #if TARGET_API_MAC_OSX
2071 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2073 if ( !--m_frozenness
)
2075 m_peer
->SetDrawingEnabled( true ) ;
2076 m_peer
->InvalidateWithChildren() ;
2081 void wxWindowMac::MacRedrawControl()
2084 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2086 #if TARGET_API_MAC_CARBON
2089 wxClientDC dc(this) ;
2090 wxMacPortSetter helper(&dc) ;
2091 wxMacWindowClipper clipper(this) ;
2092 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2093 UMADrawControl( *m_peer ) ;
2100 void wxWindowMac::OnPaint(wxPaintEvent& event)
2102 // why don't we skip that here ?
2106 wxWindowMac
*wxGetActiveWindow()
2108 // actually this is a windows-only concept
2112 // Coordinates relative to the window
2113 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2115 // We really don't move the mouse programmatically under Mac.
2118 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2120 #if TARGET_API_MAC_OSX
2121 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2127 event
.GetDC()->Clear() ;
2130 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2135 int wxWindowMac::GetScrollPos(int orient
) const
2137 if ( orient
== wxHORIZONTAL
)
2140 return m_hScrollBar
->GetThumbPosition() ;
2145 return m_vScrollBar
->GetThumbPosition() ;
2150 // This now returns the whole range, not just the number
2151 // of positions that we can scroll.
2152 int wxWindowMac::GetScrollRange(int orient
) const
2154 if ( orient
== wxHORIZONTAL
)
2157 return m_hScrollBar
->GetRange() ;
2162 return m_vScrollBar
->GetRange() ;
2167 int wxWindowMac::GetScrollThumb(int orient
) const
2169 if ( orient
== wxHORIZONTAL
)
2172 return m_hScrollBar
->GetThumbSize() ;
2177 return m_vScrollBar
->GetThumbSize() ;
2182 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2184 if ( orient
== wxHORIZONTAL
)
2187 m_hScrollBar
->SetThumbPosition( pos
) ;
2192 m_vScrollBar
->SetThumbPosition( pos
) ;
2196 void wxWindowMac::MacPaintBorders( int left
, int top
)
2202 GetSize( &w
, &h
) ;
2203 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2204 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2208 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2209 InsetRect( &srect
, border
, border
);
2210 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2212 else if (HasFlag(wxSIMPLE_BORDER
))
2216 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2217 InsetRect( &srect
, border
, border
);
2218 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2222 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2224 if ( child
== m_hScrollBar
)
2225 m_hScrollBar
= NULL
;
2226 if ( child
== m_vScrollBar
)
2227 m_vScrollBar
= NULL
;
2229 wxWindowBase::RemoveChild( child
) ;
2232 // New function that will replace some of the above.
2233 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2234 int range
, bool refresh
)
2236 if ( orient
== wxHORIZONTAL
)
2240 if ( range
== 0 || thumbVisible
>= range
)
2242 if ( m_hScrollBar
->IsShown() )
2243 m_hScrollBar
->Show(false) ;
2247 if ( !m_hScrollBar
->IsShown() )
2248 m_hScrollBar
->Show(true) ;
2249 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2257 if ( range
== 0 || thumbVisible
>= range
)
2259 if ( m_vScrollBar
->IsShown() )
2260 m_vScrollBar
->Show(false) ;
2264 if ( !m_vScrollBar
->IsShown() )
2265 m_vScrollBar
->Show(true) ;
2266 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2270 MacRepositionScrollBars() ;
2273 // Does a physical scroll
2274 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2276 if( dx
== 0 && dy
==0 )
2282 int width
, height
;
2283 GetClientSize( &width
, &height
) ;
2284 #if TARGET_API_MAC_OSX
2285 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2286 // area is scrolled, this does not occur if width and height are 2 pixels less,
2287 // TODO write optimal workaround
2288 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2291 scrollrect
.Intersect( *rect
) ;
2293 if ( m_peer
->GetNeedsDisplay() )
2295 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2296 // either immediate redraw or full invalidate
2298 // is the better overall solution, as it does not slow down scrolling
2299 m_peer
->SetNeedsDisplay( true ) ;
2301 // this would be the preferred version for fast drawing controls
2302 if( UMAGetSystemVersion() < 0x1030 )
2305 HIViewRender(m_peer
->GetControlRef()) ;
2308 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2309 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2310 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2317 RgnHandle updateRgn
= NewRgn() ;
2320 wxClientDC
dc(this) ;
2321 wxMacPortSetter
helper(&dc
) ;
2323 m_peer
->GetRect( &scrollrect
) ;
2324 scrollrect
.top
+= MacGetTopBorderSize() ;
2325 scrollrect
.left
+= MacGetLeftBorderSize() ;
2326 scrollrect
.bottom
= scrollrect
.top
+ height
;
2327 scrollrect
.right
= scrollrect
.left
+ width
;
2331 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2332 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2333 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2335 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2337 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2341 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2343 wxWindowMac
*child
= node
->GetData();
2344 if (child
== m_vScrollBar
) continue;
2345 if (child
== m_hScrollBar
) continue;
2346 if (child
->IsTopLevel()) continue;
2349 child
->GetPosition( &x
, &y
);
2351 child
->GetSize( &w
, &h
);
2355 if (rect
->Intersects(rc
))
2356 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2360 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2365 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2367 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2369 wxScrollWinEvent wevent
;
2370 wevent
.SetPosition(event
.GetPosition());
2371 wevent
.SetOrientation(event
.GetOrientation());
2372 wevent
.m_eventObject
= this;
2374 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2375 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2376 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2377 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2378 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2379 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2380 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2381 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2382 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2383 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2384 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2385 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2386 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2387 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2388 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2389 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2391 GetEventHandler()->ProcessEvent(wevent
);
2395 // Get the window with the focus
2396 wxWindowMac
*wxWindowBase::FindFocus()
2398 ControlRef control
;
2399 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2400 return wxFindControlFromMacControl( control
) ;
2403 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2405 // panel wants to track the window which was the last to have focus in it,
2406 // so we want to set ourselves as the window which last had focus
2408 // notice that it's also important to do it upwards the tree becaus
2409 // otherwise when the top level panel gets focus, it won't set it back to
2410 // us, but to some other sibling
2412 // CS:don't know if this is still needed:
2413 //wxChildFocusEvent eventFocus(this);
2414 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2416 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2418 wxMacWindowStateSaver
sv( this ) ;
2423 MacWindowToRootWindow( &x
, &y
) ;
2424 GetSize( &w
, &h
) ;
2425 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2427 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2428 DrawThemeFocusRect( &rect
, true ) ;
2431 DrawThemeFocusRect( &rect
, false ) ;
2432 // as this erases part of the frame we have to redraw borders
2433 MacPaintBorders( x
, y
) ;
2440 void wxWindowMac::OnInternalIdle()
2442 // This calls the UI-update mechanism (querying windows for
2443 // menu/toolbar/control state information)
2444 if (wxUpdateUIEvent::CanUpdate(this))
2445 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2448 // Raise the window to the top of the Z order
2449 void wxWindowMac::Raise()
2451 m_peer
->SetZOrder( true , NULL
) ;
2454 // Lower the window to the bottom of the Z order
2455 void wxWindowMac::Lower()
2457 m_peer
->SetZOrder( false , NULL
) ;
2461 // static wxWindow *gs_lastWhich = NULL;
2463 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2465 // first trigger a set cursor event
2467 wxPoint clientorigin
= GetClientAreaOrigin() ;
2468 wxSize clientsize
= GetClientSize() ;
2470 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2472 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2474 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2475 if ( processedEvtSetCursor
&& event
.HasCursor() )
2477 cursor
= event
.GetCursor() ;
2482 // the test for processedEvtSetCursor is here to prevent using m_cursor
2483 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2484 // it - this is a way to say that our cursor shouldn't be used for this
2486 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2496 cursor
= *wxSTANDARD_CURSOR
;
2500 cursor
.MacInstall() ;
2502 return cursor
.Ok() ;
2505 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2509 return m_tooltip
->GetTip() ;
2511 return wxEmptyString
;
2514 void wxWindowMac::Update()
2516 #if TARGET_API_MAC_OSX
2517 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2518 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2519 // for composited windows this also triggers a redraw of all
2520 // invalid views in the window
2521 if( UMAGetSystemVersion() >= 0x1030 )
2522 HIWindowFlush(window
) ;
2526 // the only way to trigger the redrawing on earlier systems is to call
2529 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2530 UInt32 currentEventClass
= 0 ;
2531 UInt32 currentEventKind
= 0 ;
2532 if ( currentEvent
!= NULL
)
2534 currentEventClass
= ::GetEventClass( currentEvent
) ;
2535 currentEventKind
= ::GetEventKind( currentEvent
) ;
2537 if ( currentEventClass
!= kEventClassMenu
)
2539 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2542 OSStatus status
= noErr
;
2543 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2546 m_peer
->SetNeedsDisplay( true ) ;
2549 ::Draw1Control( m_peer
->GetControlRef() ) ;
2553 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2555 wxTopLevelWindowMac
* win
= NULL
;
2556 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2559 win
= wxFindWinFromMacWindow( window
) ;
2563 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2567 RgnHandle visRgn
= NewRgn() ;
2568 RgnHandle tempRgn
= NewRgn() ;
2569 if ( m_peer
->IsVisible())
2571 m_peer
->GetRect( &r
) ;
2572 r
.left
-= MacGetLeftBorderSize() ;
2573 r
.top
-= MacGetTopBorderSize() ;
2574 r
.bottom
+= MacGetBottomBorderSize() ;
2575 r
.right
+= MacGetRightBorderSize() ;
2577 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2579 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2580 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2589 if ( includeOuterStructures
)
2590 InsetRect( &r
, -4 , -4 ) ;
2591 RectRgn( visRgn
, &r
) ;
2593 if ( !IsTopLevel() )
2595 wxWindow
* child
= this ;
2596 wxWindow
* parent
= child
->GetParent() ;
2601 // we have to find a better clipping algorithm here, in order not to clip things
2602 // positioned like status and toolbar
2603 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2605 size
= parent
->GetSize() ;
2610 size
= parent
->GetClientSize() ;
2611 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2615 parent
->MacWindowToRootWindow( &x
, &y
) ;
2616 MacRootWindowToWindow( &x
, &y
) ;
2618 SetRectRgn( tempRgn
,
2619 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2620 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2621 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2623 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2624 if ( parent
->IsTopLevel() )
2627 parent
= child
->GetParent() ;
2632 wxRegion vis
= visRgn
;
2633 DisposeRgn( visRgn
) ;
2634 DisposeRgn( tempRgn
) ;
2639 This function must not change the updatergn !
2641 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2643 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2644 bool handled
= false ;
2646 GetRegionBounds( updatergn
, &updatebounds
) ;
2647 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2648 if ( !EmptyRgn(updatergn
) )
2650 RgnHandle newupdate
= NewRgn() ;
2651 wxSize point
= GetClientSize() ;
2652 wxPoint origin
= GetClientAreaOrigin() ;
2653 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2654 SectRgn( newupdate
, updatergn
, newupdate
) ;
2656 // first send an erase event to the entire update area
2658 wxWindowDC
dc(this);
2659 dc
.SetClippingRegion(wxRegion(updatergn
));
2660 wxEraseEvent
eevent( GetId(), &dc
);
2661 eevent
.SetEventObject( this );
2662 GetEventHandler()->ProcessEvent( eevent
);
2665 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2666 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2667 m_updateRegion
= newupdate
;
2668 DisposeRgn( newupdate
) ;
2670 if ( !m_updateRegion
.Empty() )
2672 // paint the window itself
2674 event
.m_timeStamp
= time
;
2675 event
.SetEventObject(this);
2676 handled
= GetEventHandler()->ProcessEvent(event
);
2678 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2681 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2683 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2690 // now we cannot rely on having its borders drawn by a window itself, as it does not
2691 // get the updateRgn wide enough to always do so, so we do it from the parent
2692 // this would also be the place to draw any custom backgrounds for native controls
2693 // in Composited windowing
2694 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2696 wxWindowMac
*child
= node
->GetData();
2697 if (child
== m_vScrollBar
) continue;
2698 if (child
== m_hScrollBar
) continue;
2699 if (child
->IsTopLevel()) continue;
2700 if (!child
->IsShown()) continue;
2703 child
->GetPosition( &x
, &y
);
2705 child
->GetSize( &w
, &h
);
2706 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2707 if ( child
->MacGetTopBorderSize() )
2709 OffsetRect( &childRect
, MacGetLeftBorderSize() , MacGetTopBorderSize() ) ;
2710 if ( RectInRgn( &childRect
, updatergn
) )
2712 // paint custom borders
2713 wxNcPaintEvent
eventNc( child
->GetId() );
2714 eventNc
.SetEventObject( child
);
2715 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2717 wxWindowDC
dc(this) ;
2718 dc
.SetClippingRegion(wxRegion(updatergn
));
2719 wxMacPortSetter
helper(&dc
) ;
2720 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ x
, dc
.m_macLocalOrigin
.y
+ y
) ;
2724 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2726 wxWindowDC
dc(this) ;
2727 dc
.SetClippingRegion(wxRegion(updatergn
));
2728 wxMacPortSetter
helper(&dc
) ;
2729 DrawThemeFocusRect( &childRect
, true ) ;
2736 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2738 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2739 // updatergn is always already clipped to our boundaries
2740 // if we are in compositing mode then it is in relative to the upper left of the control
2741 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2742 // of the toplevel window
2743 // it is in window coordinates, not in client coordinates
2745 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2746 RgnHandle ownUpdateRgn
= NewRgn() ;
2747 CopyRgn( updatergn
, ownUpdateRgn
) ;
2749 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2752 m_peer
->GetRectInWindowCoords( &bounds
);
2753 RgnHandle controlRgn
= NewRgn();
2754 RectRgn( controlRgn
, &bounds
);
2755 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2756 // the window update region
2757 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2758 DisposeRgn( controlRgn
);
2760 //KO: convert ownUpdateRgn to local coordinates
2761 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2764 MacDoRedraw( ownUpdateRgn
, time
) ;
2765 DisposeRgn( ownUpdateRgn
) ;
2769 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2771 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2775 if ( iter
->IsTopLevel() )
2776 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2778 iter
= iter
->GetParent() ;
2780 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2784 void wxWindowMac::MacCreateScrollBars( long style
)
2786 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2788 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2790 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2791 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2792 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2793 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2795 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2796 variant
= wxWINDOW_VARIANT_SMALL
;
2799 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2801 GetClientSize( &width
, &height
) ;
2803 wxPoint
vPoint(width
-scrlsize
, 0) ;
2804 wxSize
vSize(scrlsize
, height
- adjust
) ;
2805 wxPoint
hPoint(0 , height
-scrlsize
) ;
2806 wxSize
hSize( width
- adjust
, scrlsize
) ;
2809 if ( style
& wxVSCROLL
)
2811 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2812 vSize
, wxVERTICAL
);
2815 if ( style
& wxHSCROLL
)
2817 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2818 hSize
, wxHORIZONTAL
);
2823 // because the create does not take into account the client area origin
2824 MacRepositionScrollBars() ; // we might have a real position shift
2827 void wxWindowMac::MacRepositionScrollBars()
2829 if ( !m_hScrollBar
&& !m_vScrollBar
)
2832 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2833 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2834 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2836 // get real client area
2840 GetSize( &width
, &height
) ;
2842 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2843 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2845 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2846 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2847 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2848 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2854 GetSize( &w , &h ) ;
2856 MacClientToRootWindow( &x , &y ) ;
2857 MacClientToRootWindow( &w , &h ) ;
2859 wxWindowMac *iter = (wxWindowMac*)this ;
2861 int totW = 10000 , totH = 10000;
2864 if ( iter->IsTopLevel() )
2866 iter->GetSize( &totW , &totH ) ;
2870 iter = iter->GetParent() ;
2898 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2902 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2906 bool wxWindowMac::AcceptsFocus() const
2908 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2911 void wxWindowMac::MacSuperChangedPosition()
2913 // only window-absolute structures have to be moved i.e. controls
2915 wxWindowListNode
*node
= GetChildren().GetFirst();
2918 wxWindowMac
*child
= node
->GetData();
2919 child
->MacSuperChangedPosition() ;
2920 node
= node
->GetNext();
2924 void wxWindowMac::MacTopLevelWindowChangedPosition()
2926 // only screen-absolute structures have to be moved i.e. glcanvas
2928 wxWindowListNode
*node
= GetChildren().GetFirst();
2931 wxWindowMac
*child
= node
->GetData();
2932 child
->MacTopLevelWindowChangedPosition() ;
2933 node
= node
->GetNext();
2937 long wxWindowMac::MacGetLeftBorderSize( ) const
2942 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2947 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2952 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2959 long wxWindowMac::MacGetRightBorderSize( ) const
2961 // they are all symmetric in mac themes
2962 return MacGetLeftBorderSize() ;
2965 long wxWindowMac::MacGetTopBorderSize( ) const
2967 // they are all symmetric in mac themes
2968 return MacGetLeftBorderSize() ;
2971 long wxWindowMac::MacGetBottomBorderSize( ) const
2973 // they are all symmetric in mac themes
2974 return MacGetLeftBorderSize() ;
2977 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2979 return style
& ~wxBORDER_MASK
;
2982 // Find the wxWindowMac at the current mouse position, returning the mouse
2984 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2986 pt
= wxGetMousePosition();
2987 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2991 // Get the current mouse position.
2992 wxPoint
wxGetMousePosition()
2995 wxGetMousePosition(& x
, & y
);
2996 return wxPoint(x
, y
);
2999 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3001 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3003 // copied from wxGTK : CS
3004 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3007 // (a) it's a command event and so is propagated to the parent
3008 // (b) under MSW it can be generated from kbd too
3009 // (c) it uses screen coords (because of (a))
3010 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3012 this->ClientToScreen(event
.GetPosition()));
3013 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3022 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3026 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3030 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3031 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3035 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3037 return eventNotHandledErr
;