00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
#ifndef TCarbonEvent_H_
00045
#define TCarbonEvent_H_
00046
00047
#include <Carbon/Carbon.h>
00048
00049 struct InvalidEventParameterType {};
00050
00051 template <
class T> EventParamType
EventDataType() throw(
InvalidEventParameterType )
00052 {
throw InvalidEventParameterType();
return 0; }
00053
00054
template <>
inline EventParamType EventDataType<WindowRef>() {
return typeWindowRef; }
00055
template <>
inline EventParamType EventDataType<ControlRef>() {
return typeControlRef; }
00056
template <>
inline EventParamType EventDataType<MenuRef>() {
return typeMenuRef; }
00057
template <>
inline EventParamType EventDataType<DragRef>() {
return typeDragRef; }
00058
00059
template <>
inline EventParamType EventDataType<HIPoint>() {
return typeHIPoint; }
00060
template <>
inline EventParamType EventDataType<HISize>() {
return typeHISize; }
00061
template <>
inline EventParamType EventDataType<HIRect>() {
return typeHIRect; }
00062
template <>
inline EventParamType EventDataType<Point>() {
return typeQDPoint; }
00063
template <>
inline EventParamType EventDataType<Rect>() {
return typeQDRectangle; }
00064
template <>
inline EventParamType EventDataType<RgnHandle>() {
return typeQDRgnHandle; }
00065
00066
template <>
inline EventParamType EventDataType<Boolean>() {
return typeBoolean; }
00067
template <>
inline EventParamType EventDataType<UInt32>() {
return typeUInt32; }
00068
00069
template <>
inline EventParamType EventDataType<HICommand>() {
return typeHICommand; }
00070
00071 class TCarbonEvent
00072 {
00073
public:
00074
00075
TCarbonEvent(
00076 UInt32 inClass,
00077 UInt32 inKind );
00078
TCarbonEvent(
00079 EventRef inEvent );
00080
virtual ~TCarbonEvent();
00081
00082 UInt32
GetClass()
const
00083
{ return ::GetEventClass( fEvent ); }
00084 UInt32
GetKind()
const
00085
{ return ::GetEventKind( fEvent ); };
00086
00087
00088 void SetTime(
00089 EventTime inTime )
00090 { ::SetEventTime( fEvent, inTime ); }
00091 EventTime
GetTime()
const
00092
{ return ::GetEventTime( fEvent ); }
00093 UInt32
GetTimeAsTicks()
const
00094
{
return EventTimeToTicks(
GetTime() ); }
00095
00096
00097 void Retain()
00098 { ::RetainEvent( fEvent ); }
00099 void Release()
00100 { ::ReleaseEvent( fEvent ); }
00101
00102
00103 operator EventRef&()
00104 {
return fEvent; };
00105 EventRef
GetEventRef()
00106 {
return fEvent; }
00107
00108
00109 OSStatus PostToQueue(
00110 EventQueueRef inQueue,
00111 EventPriority inPriority = kEventPriorityStandard );
00112
00113
00114 OSStatus SetParameter(
00115 EventParamName inName,
00116 EventParamType inType,
00117 UInt32 inSize,
00118
const void* inData );
00119 OSStatus GetParameter(
00120 EventParamName inName,
00121 EventParamType inType,
00122 UInt32 inBufferSize,
00123
void* outData );
00124
00125 OSStatus GetParameterType(
00126 EventParamName inName,
00127 EventParamType* outType );
00128 OSStatus GetParameterSize(
00129 EventParamName inName,
00130 UInt32* outSize );
00131
00132
00133 OSStatus SetParameter(
00134 EventParamName inName,
00135 Boolean inValue );
00136 OSStatus GetParameter(
00137 EventParamName inName,
00138 Boolean* outValue );
00139
00140 OSStatus SetParameter(
00141 EventParamName inName,
00142
bool inValue );
00143 OSStatus GetParameter(
00144 EventParamName inName,
00145
bool* outValue );
00146
00147 OSStatus SetParameter(
00148 EventParamName inName,
00149 Point inPt );
00150 OSStatus GetParameter(
00151 EventParamName inName,
00152 Point* outPt );
00153
00154 OSStatus SetParameter(
00155 EventParamName inName,
00156
const HIPoint& inPt );
00157
00158 OSStatus GetParameter(
00159 EventParamName inName,
00160 HIPoint* outPt );
00161
00162 OSStatus SetParameter(
00163 EventParamName inName,
00164
const Rect& inRect );
00165 OSStatus GetParameter(
00166 EventParamName inName,
00167 Rect* outRect );
00168
00169 OSStatus SetParameter(
00170 EventParamName inName,
00171
const HIRect& inRect );
00172 OSStatus GetParameter(
00173 EventParamName inName,
00174 HIRect* outRect );
00175
00176 OSStatus SetParameter(
00177 EventParamName inName,
00178
const HISize& inSize );
00179 OSStatus GetParameter(
00180 EventParamName inName,
00181 HISize* outSize );
00182
00183 OSStatus SetParameter(
00184 EventParamName inName,
00185 RgnHandle inRegion );
00186 OSStatus GetParameter(
00187 EventParamName inName,
00188 RgnHandle* outRegion );
00189
00190 OSStatus SetParameter(
00191 EventParamName inName,
00192 WindowRef inWindow );
00193 OSStatus GetParameter(
00194 EventParamName inName,
00195 WindowRef* outWindow );
00196
00197 OSStatus SetParameter(
00198 EventParamName inName,
00199 ControlRef inControl );
00200 OSStatus GetParameter(
00201 EventParamName inName,
00202 ControlRef* outControl );
00203
00204 OSStatus SetParameter(
00205 EventParamName inName,
00206 MenuRef inMenu );
00207 OSStatus GetParameter(
00208 EventParamName inName,
00209 MenuRef* outMenu );
00210
00211 OSStatus SetParameter(
00212 EventParamName inName,
00213 DragRef inDrag );
00214 OSStatus GetParameter(
00215 EventParamName inName,
00216 DragRef* outDrag );
00217
00218 OSStatus SetParameter(
00219 EventParamName inName,
00220 UInt32 inValue );
00221 OSStatus GetParameter(
00222 EventParamName inName,
00223 UInt32* outValue );
00224
00225 OSStatus SetParameter(
00226 EventParamName inName,
00227
const HICommand& inValue );
00228 OSStatus GetParameter(
00229 EventParamName inName,
00230 HICommand* outValue );
00231
00232 OSStatus SetParameter(
00233 EventParamName inName,
00234
const ControlPartCode& inValue );
00235 OSStatus GetParameter(
00236 EventParamName inName,
00237 ControlPartCode* outValue );
00238
00239
00240 template <
class T> OSStatus SetParameter(
00241 EventParamName inName,
00242 EventParamType inType,
00243
const T& inValue )
00244 {
00245
return SetParameter( inName, inType,
sizeof( T ), &inValue );
00246 }
00247
00248 template <
class T> OSStatus GetParameter(
00249 EventParamName inName,
00250 EventParamType inType,
00251 T* outValue )
00252 {
00253
return GetParameter( inName, inType,
sizeof( T ), outValue );
00254 }
00255
00256 template <
class T> T GetParameter(
00257 EventParamName inName )
00258 {
00259 T outValue;
00260
00261 verify_noerr( GetParameter( inName, EventDataType<T>(),
sizeof( T ), &outValue ) );
00262
00263
return outValue;
00264 }
00265
00266 template <
class T>
void SetParameter(
00267 EventParamName inName,
00268
const T& inValue )
00269 {
00270 verify_noerr( SetParameter( inName, EventDataType<T>(),
sizeof( T ), &inValue ) );
00271 }
00272
00273 template <
class T> T GetParameter(
00274 EventParamName inName, EventParamType inType )
00275 {
00276 T outValue;
00277
00278 verify_noerr( GetParameter( inName, inType,
sizeof( T ), &outValue ) );
00279
00280
return outValue;
00281 }
00282
00283
private:
00284 EventRef fEvent;
00285 };
00286
00287
#endif // TCarbonEvent_H_