+template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
+template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
+template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
+template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
+template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
+template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
+template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
+template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
+template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
+#if TARGET_API_MAC_OSX
+template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand ; }
+template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
+template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
+template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
+template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
+#endif
+template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
+template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
+/*
+ These are ambiguous
+ template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
+ template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
+ template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
+ template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
+ */
+
+class wxMacCarbonEvent
+{
+
+public :
+ wxMacCarbonEvent()
+ {
+ m_eventRef = 0 ;
+ m_release = false ;
+ }
+
+ wxMacCarbonEvent( EventRef event , bool release = false )
+ {
+ m_eventRef = event ;
+ m_release = release ;
+ }
+
+ wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
+ {
+ m_eventRef = NULL ;
+ verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
+ m_release = true ;
+ }
+
+ ~wxMacCarbonEvent()
+ {
+ if ( m_release )
+ ReleaseEvent( m_eventRef ) ;
+ }
+
+ OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
+ {
+ verify( (m_eventRef == NULL) || m_release ) ;
+ if ( m_eventRef && m_release )
+ {
+ ReleaseEvent( m_eventRef ) ;
+ m_release = false ;
+ m_eventRef = NULL ;
+
+ }
+ OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ;
+ if ( err == noErr )
+ m_release = true ;
+ return err ;
+ }
+
+ OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
+
+ template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
+ {
+ return GetParameter( inName, type , sizeof( T ) , data ) ;
+ }
+ template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
+ {
+ return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
+ }
+
+ template <typename T> T GetParameter( EventParamName inName )
+ {
+ T value ;
+ verify_noerr( GetParameter<T>( inName, &value ) ) ;
+ return value ;
+ }
+ template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
+ {
+ T value ;
+ verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
+ return value ;
+ }
+
+ OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData) ;
+ template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
+ {
+ return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
+ }
+ template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
+ {
+ return SetParameter<T>( inName, inDesiredType , &data ) ;
+ }
+ template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
+ {
+ return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
+ }
+ template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
+ {
+ return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
+ }
+ UInt32 GetClass()
+ {
+ return ::GetEventClass( m_eventRef ) ;
+ }
+ UInt32 GetKind()
+ {
+ return ::GetEventKind( m_eventRef ) ;
+ }
+ EventTime GetTime()
+ {
+ return ::GetEventTime( m_eventRef ) ;
+ }
+ UInt32 GetTicks()
+ {
+ return EventTimeToTicks( GetTime() ) ;
+ }
+ OSStatus SetTime( EventTime inWhen = 0 /*now*/ )
+ {
+ return ::SetEventTime( m_eventRef , inWhen ? inWhen : GetCurrentEventTime() ) ;
+ }
+ operator EventRef () { return m_eventRef; }
+
+ bool IsValid() { return m_eventRef != 0 ; }
+protected :
+ EventRef m_eventRef ;
+ bool m_release ;
+} ;
+
+//
+// helper class for allocating and deallocating Universal Proc Ptrs
+//
+
+template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
+{
+public :
+ wxMacUPP( procType proc )
+ {
+ m_upp = NULL ;
+ m_upp = (*newUPP)( NULL ) ;
+ }
+ ~wxMacUPP()
+ {
+ if ( m_upp )
+ disposeUPP( m_upp ) ;
+ }
+ operator uppType() { return m_upp ; }
+private :
+ uppType m_upp ;
+} ;