#include "wx/spinctrl.h"
#include "wx/log.h"
#include "wx/geometry.h"
+#include "wx/textctrl.h"
#include "wx/toolbar.h"
#include "wx/dc.h"
#ifndef __DARWIN__
#include <Windows.h>
#include <ToolUtils.h>
+#include <Scrap.h>
+#include <MacTextEditor.h>
#endif
#if TARGET_API_MAC_OSX
{ kEventClassControl , kEventControlEnabledStateChanged } ,
{ kEventClassControl , kEventControlHiliteChanged } ,
{ kEventClassControl , kEventControlSetFocusPart } ,
-// { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
+
+ { kEventClassService , kEventServiceGetTypes },
+ { kEventClassService , kEventServiceCopy },
+ { kEventClassService , kEventServicePaste },
+
+ // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
// { kEventClassControl , kEventControlBoundsChanged } ,
#endif
} ;
wxFocusEvent event(wxEVT_KILL_FOCUS, thisWindow->GetId());
event.SetEventObject(thisWindow);
thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ if (thisWindow->MacIsUserPane())
+ result = noErr;
}
else
{
wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
event.SetEventObject(thisWindow);
thisWindow->GetEventHandler()->ProcessEvent(event) ;
+ if (thisWindow->MacIsUserPane())
+ result = noErr;
}
}
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 )
{
OSStatus result = eventNotHandledErr ;
case kEventClassControl :
result = wxMacWindowControlEventHandler( handler, event, data ) ;
break ;
+ case kEventClassService :
+ result = wxMacWindowServiceEventHandler( handler, event , data ) ;
default :
break ;
}
{
Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
- UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback | kControlHasSpecialBackground |
- kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle;
-
- ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, kControlSupportsEmbedding , (ControlRef*) &m_macControl);
+ UInt32 features = 0
+ | kControlSupportsEmbedding
+// | kControlSupportsLiveFeedback
+// | kControlHasSpecialBackground
+// | kControlSupportsCalcBestRect
+// | kControlHandlesTracking
+ | kControlSupportsFocus
+// | kControlWantsActivate
+// | kControlWantsIdle
+ ;
+
+ ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , (ControlRef*) &m_macControl);
MacPostControlCreate(pos,size) ;
#if !TARGET_API_MAC_OSX
wxSize new_size = size ;
if (!m_macIsUserPane)
- {
- wxSize best_size( DoGetBestSize() );
-
- if (size.x == -1) {
- new_size.x = best_size.x;
- }
- if (size.y == -1) {
- new_size.y = best_size.y;
- }
- SetSize( pos.x, pos.y , new_size.x, new_size.y,wxSIZE_USE_EXISTING );
+ {
+ SetInitialBestSize(size);
}
SetCursor( *wxSTANDARD_CURSOR ) ;
GetRegionBounds( rgn , &content ) ;
DisposeRgn( rgn ) ;
#if !TARGET_API_MAC_OSX
- Rect structure ;
- GetControlBounds( (ControlRef) m_macControl , &structure ) ;
- OffsetRect( &content , -structure.left , -structure.top ) ;
+ // if the content rgn is empty / not supported
+ // don't attempt to correct the coordinates to wxWindow relative ones
+ if (!::EmptyRect( &content ) )
+ {
+ Rect structure ;
+ GetControlBounds( (ControlRef) m_macControl , &structure ) ;
+ OffsetRect( &content , -structure.left , -structure.top ) ;
+ }
#endif
return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
return FALSE;
bool former = MacIsReallyEnabled() ;
+#if TARGET_API_MAC_OSX
if ( enable )
EnableControl( (ControlRef) m_macControl ) ;
else
DisableControl( (ControlRef) m_macControl ) ;
+#else
+ if ( enable )
+ ActivateControl( (ControlRef) m_macControl ) ;
+ else
+ DeactivateControl( (ControlRef) m_macControl ) ;
+#endif
if ( former != MacIsReallyEnabled() )
MacPropagateEnabledStateChanged() ;
bool wxWindowMac::MacIsReallyEnabled()
{
+#if TARGET_API_MAC_OSX
return IsControlEnabled( (ControlRef) m_macControl ) ;
+#else
+ return IsControlActive( (ControlRef) m_macControl ) ;
+#endif
}
bool wxWindowMac::MacIsReallyHilited()