+#define wxMAC_USE_THEME_BORDER 1
+
+// ---------------------------------------------------------------------------
+// Utility Routines to move between different coordinate systems
+// ---------------------------------------------------------------------------
+
+/*
+ * Right now we have the following setup :
+ * a border that is not part of the native control is always outside the
+ * control's border (otherwise we loose all native intelligence, future ways
+ * may be to have a second embedding control responsible for drawing borders
+ * and backgrounds eventually)
+ * so all this border calculations have to be taken into account when calling
+ * native methods or getting native oriented data
+ * so we have three coordinate systems here
+ * wx client coordinates
+ * wx window coordinates (including window frames)
+ * native coordinates
+ */
+
+//
+// originating from native control
+//
+
+
+void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
+{
+ OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
+}
+
+void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
+{
+ OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
+}
+
+//
+// directed towards native control
+//
+
+void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
+{
+ OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
+}
+
+void wxMacWindowToNative( const wxWindow* window , Rect *rect )
+{
+ OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
+}
+
+
+// ---------------------------------------------------------------------------
+// Carbon Events
+// ---------------------------------------------------------------------------
+
+extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
+pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
+
+#if TARGET_API_MAC_OSX
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
+enum {
+ kEventControlVisibilityChanged = 157
+};
+#endif
+
+#endif
+
+static const EventTypeSpec eventList[] =
+{
+ { kEventClassControl , kEventControlHit } ,
+#if TARGET_API_MAC_OSX
+ { kEventClassControl , kEventControlDraw } ,
+ { kEventClassControl , kEventControlVisibilityChanged } ,
+ { kEventClassControl , kEventControlEnabledStateChanged } ,
+ { kEventClassControl , kEventControlHiliteChanged } ,
+ { kEventClassControl , kEventControlSetFocusPart } ,
+
+ { kEventClassService , kEventServiceGetTypes },
+ { kEventClassService , kEventServiceCopy },
+ { kEventClassService , kEventServicePaste },
+
+ // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
+// { kEventClassControl , kEventControlBoundsChanged } ,
+#endif
+} ;
+
+static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ ControlRef controlRef ;
+ wxWindowMac* thisWindow = (wxWindowMac*) data ;
+
+ cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
+
+ switch( GetEventKind( event ) )
+ {
+#if TARGET_API_MAC_OSX
+ case kEventControlDraw :
+ {
+ RgnHandle updateRgn = NULL ;
+ RgnHandle allocatedRgn = NULL ;
+ wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
+ if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
+ {
+ updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
+ }
+ else
+ {
+ if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
+ {
+ allocatedRgn = NewRgn() ;
+ CopyRgn( updateRgn , allocatedRgn ) ;
+ // hide the given region by the new region that must be shifted
+ wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
+ updateRgn = allocatedRgn ;
+ }
+ }
+
+#if 0
+ // in case we would need a coregraphics compliant background erase first
+ // now usable to track redraws
+ CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
+ if ( thisWindow->MacIsUserPane() )
+ {
+ static float color = 0.5 ;
+ static channel = 0 ;
+ HIRect bounds;
+ HIViewGetBounds( controlRef, &bounds );
+ CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 ,
+ channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 );
+ CGContextFillRect( cgContext, bounds );
+ color += 0.1 ;
+ if ( color > 0.9 )
+ {
+ color = 0.5 ;
+ channel++ ;
+ if ( channel == 3 )
+ channel = 0 ;
+ }
+ }
+#endif
+ if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
+ result = noErr ;
+ if ( allocatedRgn )
+ DisposeRgn( allocatedRgn ) ;
+ }
+ break ;
+ case kEventControlVisibilityChanged :
+ thisWindow->MacVisibilityChanged() ;
+ break ;
+ case kEventControlEnabledStateChanged :
+ thisWindow->MacEnabledStateChanged() ;
+ break ;
+ case kEventControlHiliteChanged :
+ thisWindow->MacHiliteChanged() ;
+ break ;
+ case kEventControlSetFocusPart :
+ {
+ Boolean focusEverything = false ;
+ ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+ if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
+ {
+ }
+ if ( controlPart == kControlFocusNoPart )
+ {
+ #if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ {
+ thisWindow->GetCaret()->OnKillFocus();
+ }
+ #endif // wxUSE_CARET
+ wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ }
+ else
+ {
+ // panel wants to track the window which was the last to have focus in it
+ wxChildFocusEvent eventFocus(thisWindow);
+ thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
+
+ #if wxUSE_CARET
+ if ( thisWindow->GetCaret() )
+ {
+ thisWindow->GetCaret()->OnSetFocus();
+ }
+ #endif // wxUSE_CARET
+
+ wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+ event.SetEventObject(thisWindow);
+ thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ }
+ if ( thisWindow->MacIsUserPane() )
+ result = noErr ;
+ }
+ break ;
+#endif
+ case kEventControlHit :
+ {
+ result = thisWindow->MacControlHit( handler , event ) ;
+ }
+ break ;
+ default :
+ break ;
+ }
+ return result ;
+}
+
+static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ OSStatus result = eventNotHandledErr ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+
+ ControlRef controlRef ;
+ wxWindowMac* thisWindow = (wxWindowMac*) data ;
+ wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
+ cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
+
+ switch( GetEventKind( event ) )
+ {
+ case kEventServiceGetTypes :
+ if( textCtrl )
+ {
+ long from, to ;
+ textCtrl->GetSelection( &from , &to ) ;
+
+ CFMutableArrayRef copyTypes = 0 , pasteTypes = 0;
+ if( from != to )
+ copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ;
+ if ( textCtrl->IsEditable() )
+ pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ;
+
+ static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
+ for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i )
+ {
+ CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]);
+ if ( typestring )
+ {
+ if ( copyTypes )
+ CFArrayAppendValue (copyTypes, typestring) ;
+ if ( pasteTypes )
+ CFArrayAppendValue (pasteTypes, typestring) ;
+ CFRelease( typestring ) ;
+ }
+ }
+ result = noErr ;
+ }
+ break ;
+ case kEventServiceCopy :
+ if ( textCtrl )
+ {
+ long from, to ;
+ textCtrl->GetSelection( &from , &to ) ;
+ wxString val = textCtrl->GetValue() ;
+ val = val.Mid( from , to - from ) ;
+ ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
+ verify_noerr( ClearScrap( &scrapRef ) ) ;
+ verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ;
+ result = noErr ;
+ }
+ break ;
+ case kEventServicePaste :
+ if ( textCtrl )
+ {
+ ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
+ Size textSize, pastedSize ;
+ verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ;
+ textSize++ ;
+ char *content = new char[textSize] ;
+ GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content );
+ content[textSize-1] = 0 ;
+#if wxUSE_UNICODE
+ textCtrl->WriteText( wxString( content , wxConvLocal ) );
+#else
+ textCtrl->WriteText( wxString( content ) ) ;
+#endif
+ delete[] content ;
+ result = noErr ;
+ }
+ break ;
+ }
+
+ return result ;
+}
+
+pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+{
+ EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
+ EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
+ wxTheApp->MacSetCurrentEvent( event , handler ) ;
+ OSStatus result = eventNotHandledErr ;
+
+ switch ( GetEventClass( event ) )
+ {
+ case kEventClassControl :
+ result = wxMacWindowControlEventHandler( handler, event, data ) ;
+ break ;
+ case kEventClassService :
+ result = wxMacWindowServiceEventHandler( handler, event , data ) ;
+ default :
+ break ;
+ }
+ wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
+ return result ;
+}
+
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
+
+// ---------------------------------------------------------------------------
+// UserPane events for non OSX builds
+// ---------------------------------------------------------------------------
+
+static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneDrawProc(part) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
+}
+
+static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneIdleProc() ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
+}
+
+static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneActivateProc(activating) ;
+}
+
+static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
+ return win->MacControlUserPaneFocusProc(action) ;
+}
+
+static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
+{
+ wxWindow * win = wxFindControlFromMacControl(control) ;
+ wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
+ win->MacControlUserPaneBackgroundProc(info) ;
+}
+
+void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
+{
+ RgnHandle rgn = NewRgn() ;
+ GetClip( rgn ) ;
+ wxMacWindowStateSaver sv( this ) ;
+ SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
+ MacDoRedraw( rgn , 0 ) ;
+ DisposeRgn( rgn ) ;
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
+{
+ return kControlNoPart ;
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneIdleProc()
+{
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
+{
+}
+
+wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
+{
+ return kControlNoPart ;
+}
+
+void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
+{
+}
+
+ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ;
+ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ;
+ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ;
+ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ;
+ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ;
+ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ;
+ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ;
+ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ;
+
+// ===========================================================================
+// implementation
+// ===========================================================================
+
+wxList wxWinMacControlList(wxKEY_INTEGER);
+
+wxWindow *wxFindControlFromMacControl(ControlRef inControl )
+{
+ wxNode *node = wxWinMacControlList.Find((long)inControl);
+ if (!node)
+ return NULL;
+ return (wxControl *)node->GetData();
+}
+
+void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
+{
+ // adding NULL ControlRef is (first) surely a result of an error and
+ // (secondly) breaks native event processing
+ wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
+
+ if ( !wxWinMacControlList.Find((long)inControl) )
+ wxWinMacControlList.Append((long)inControl, control);
+}
+
+void wxRemoveMacControlAssociation(wxWindow *control)
+{
+ wxWinMacControlList.DeleteObject(control);
+}
+
+// UPP functions
+ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
+
+ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
+
+// we have to setup the brush in the current port and return noErr
+// or return an error code so that the control manager walks further up the
+// hierarchy to find a correct background
+
+pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
+{
+ OSStatus status = paramErr ;
+ switch( iMessage )
+ {
+ case kControlMsgApplyTextColor :
+ break ;
+ case kControlMsgSetUpBackground :
+ {
+ wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ;
+ if ( wx != NULL )
+ {
+ /*
+ const wxBrush &brush = wx->MacGetBackgroundBrush() ;
+ if ( brush.Ok() )
+ {
+ wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
+ */
+ // this clipping is only needed for non HIView
+
+ RgnHandle clip = NewRgn() ;
+ int x = 0 , y = 0;
+
+ wx->MacWindowToRootWindow( &x,&y ) ;
+ CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ;
+ OffsetRgn( clip , x , y ) ;
+ SetClip( clip ) ;
+ DisposeRgn( clip ) ;
+
+ status = noErr ;
+ /*
+ }
+ else if ( wx->MacIsUserPane() )
+ {
+ // if we don't have a valid brush for such a control, we have to call the
+ // setup of our parent ourselves
+ status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
+ }
+ */
+ }
+ }
+ break ;
+ default :
+ break ;
+ }
+ return status ;
+}
+
+
+pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
+pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
+{
+ if ( partCode != 0)
+ {
+ wxWindow* wx = wxFindControlFromMacControl( control ) ;
+ if ( wx )
+ {
+ wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
+ }
+ }
+}
+
+// ----------------------------------------------------------------------------
+ // constructors and such
+// ----------------------------------------------------------------------------
+
+wxWindowMac::wxWindowMac()
+{
+ Init();
+}
+
+wxWindowMac::wxWindowMac(wxWindowMac *parent,
+ wxWindowID id,
+ const wxPoint& pos ,
+ const wxSize& size ,
+ long style ,
+ const wxString& name )
+{
+ Init();
+ Create(parent, id, pos, size, style, name);
+}
+
+void wxWindowMac::Init()
+{
+ m_peer = NULL ;
+ m_frozenness = 0 ;
+#if WXWIN_COMPATIBILITY_2_4
+ m_backgroundTransparent = FALSE;
+#endif
+
+ // as all windows are created with WS_VISIBLE style...
+ m_isShown = TRUE;
+
+ m_hScrollBar = NULL ;
+ m_vScrollBar = NULL ;
+ m_macBackgroundBrush = wxNullBrush ;
+
+ m_macIsUserPane = TRUE;
+
+ // make sure all proc ptrs are available
+
+ if ( gControlUserPaneDrawUPP == NULL )
+ {
+ gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ;
+ gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ;
+ gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ;
+ gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ;
+ gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ;
+ gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ;
+ gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ;
+ gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ;
+ }
+ if ( wxMacLiveScrollbarActionUPP == NULL )
+ {
+ wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
+ }
+
+ if ( wxMacSetupControlBackgroundUPP == NULL )
+ {
+ wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
+ }
+
+ // we need a valid font for the encodings
+ wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
+}
+
+// Destructor
+wxWindowMac::~wxWindowMac()
+{
+ SendDestroyEvent();
+
+ m_isBeingDeleted = TRUE;
+
+ if ( m_peer )
+ {
+ // deleting a window while it is shown invalidates the region occupied by border or
+ // focus
+ int outerBorder = MacGetLeftBorderSize() ;
+ if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
+ outerBorder += 4 ;
+
+ if ( IsShown() && ( outerBorder > 0 ) )
+ {
+ // as the borders are drawn on the parent we have to properly invalidate all these areas
+ RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
+
+ Rect rect ;
+
+ m_peer->GetRect( &rect ) ;
+ RectRgn( updateInner , &rect ) ;
+ InsetRect( &rect , -outerBorder , -outerBorder ) ;
+ RectRgn( updateOuter , &rect ) ;
+ DiffRgn( updateOuter , updateInner ,updateOuter ) ;
+ wxPoint parent(0,0);
+ GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
+ parent -= GetParent()->GetClientAreaOrigin() ;
+ OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
+ CopyRgn( updateOuter , updateTotal ) ;
+
+ GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
+ DisposeRgn(updateOuter) ;
+ DisposeRgn(updateInner) ;
+ DisposeRgn(updateTotal) ;
+ }
+ }
+
+#ifndef __WXUNIVERSAL__
+ // VS: make sure there's no wxFrame with last focus set to us:
+ for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
+ {
+ wxFrame *frame = wxDynamicCast(win, wxFrame);
+ if ( frame )
+ {
+ if ( frame->GetLastFocus() == this )
+ {
+ frame->SetLastFocus((wxWindow*)NULL);
+ }
+ break;
+ }
+ }
+#endif // __WXUNIVERSAL__
+
+ // destroy children before destroying this window itself
+ DestroyChildren();
+
+ // wxRemoveMacControlAssociation( this ) ;
+ // If we delete an item, we should initialize the parent panel,
+ // because it could now be invalid.
+ wxWindow *parent = GetParent() ;
+ if ( parent )
+ {
+ if (parent->GetDefaultItem() == (wxButton*) this)
+ parent->SetDefaultItem(NULL);
+ }
+ if ( m_peer && m_peer->Ok() )
+ {
+ // in case the callback might be called during destruction
+ wxRemoveMacControlAssociation( this) ;
+ // we currently are not using this hook
+ // ::SetControlColorProc( *m_peer , NULL ) ;
+ m_peer->Dispose() ;
+ }
+
+ if ( g_MacLastWindow == this )
+ {
+ g_MacLastWindow = NULL ;
+ }
+
+ wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
+ if ( frame )
+ {
+ if ( frame->GetLastFocus() == this )
+ frame->SetLastFocus( NULL ) ;
+ }
+
+ // delete our drop target if we've got one
+#if wxUSE_DRAG_AND_DROP
+ if ( m_dropTarget != NULL )
+ {
+ delete m_dropTarget;
+ m_dropTarget = NULL;
+ }
+#endif // wxUSE_DRAG_AND_DROP
+ delete m_peer ;
+}
+
+WXWidget wxWindowMac::GetHandle() const
+{
+ return (WXWidget) m_peer->GetControlRef() ;
+}
+
+
+void wxWindowMac::MacInstallEventHandler( WXWidget control )
+{
+ wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
+ InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(),
+ GetEventTypeCount(eventList), eventList, this,
+ (EventHandlerRef *)&m_macControlEventHandler);
+
+}
+
+// Constructor
+bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxString& name)
+{
+ wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
+
+ if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
+ return FALSE;
+
+ parent->AddChild(this);
+
+ m_windowVariant = parent->GetWindowVariant() ;
+
+ if ( m_macIsUserPane )
+ {
+ Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
+
+ UInt32 features = 0
+ | kControlSupportsEmbedding
+// | kControlSupportsLiveFeedback
+// | kControlHasSpecialBackground
+// | kControlSupportsCalcBestRect
+// | kControlHandlesTracking
+ | kControlSupportsFocus
+// | kControlWantsActivate
+// | kControlWantsIdle
+ ;
+
+ m_peer = new wxMacControl() ;
+ ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
+
+
+ MacPostControlCreate(pos,size) ;
+#if !TARGET_API_MAC_OSX
+ m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ;
+ m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ;
+ m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ;
+ m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ;
+ m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ;
+ m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ;
+ m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ;
+ m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ;
+#endif
+ }
+#ifndef __WXUNIVERSAL__
+ // Don't give scrollbars to wxControls unless they ask for them
+ if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
+ (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
+ {
+ MacCreateScrollBars( style ) ;
+ }
+#endif
+
+ wxWindowCreateEvent event(this);
+ GetEventHandler()->AddPendingEvent(event);
+
+ return TRUE;
+}
+
+void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
+{
+ wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
+
+ m_peer->SetReference( (long) this ) ;
+
+ MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
+
+ ControlRef container = (ControlRef) GetParent()->GetHandle() ;
+ wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
+ ::EmbedControl( m_peer->GetControlRef() , container ) ;
+
+ // adjust font, controlsize etc
+ DoSetWindowVariant( m_windowVariant ) ;
+
+#if !TARGET_API_MAC_OSX
+ // eventually we can fix some clipping issues be reactivating this hook
+ //if ( m_macIsUserPane )
+ // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
+#endif
+ m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
+
+ if (!m_macIsUserPane)
+ {
+ SetInitialBestSize(size);
+ }
+
+ SetCursor( *wxSTANDARD_CURSOR ) ;
+}