00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkEvent_DEFINED
00018 #define SkEvent_DEFINED
00019
00020 #include "SkDOM.h"
00021 #include "SkMetaData.h"
00022 #include "SkString.h"
00023
00024
00025
00031 typedef uint32_t SkEventSinkID;
00032
00039 class SkEvent {
00040 public:
00043 SkEvent();
00046 explicit SkEvent(const SkString& type);
00049 explicit SkEvent(const char type[]);
00052 SkEvent(const SkEvent& src);
00053 ~SkEvent();
00054
00055
00056
00058 void getType(SkString* str) const;
00060 bool isType(const SkString& str) const;
00062 bool isType(const char type[], size_t len = 0) const;
00066 void setType(const SkString&);
00070 void setType(const char type[], size_t len = 0);
00071
00073 uint32_t getFast32() const { return f32; }
00077 void setFast32(uint32_t x) { f32 = x; }
00078
00083 bool findS32(const char name[], int32_t* value = NULL) const { return fMeta.findS32(name, value); }
00088 bool findScalar(const char name[], SkScalar* value = NULL) const { return fMeta.findScalar(name, value); }
00093 const SkScalar* findScalars(const char name[], int* count, SkScalar values[] = NULL) const { return fMeta.findScalars(name, count, values); }
00096 const char* findString(const char name[]) const { return fMeta.findString(name); }
00101 bool findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); }
00102 bool findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); }
00103
00105 bool hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
00107 bool hasScalar(const char name[], SkScalar value) const { return fMeta.hasScalar(name, value); }
00109 bool hasString(const char name[], const char value[]) const { return fMeta.hasString(name, value); }
00111 bool hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); }
00112 bool hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); }
00113
00115 void setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
00117 void setScalar(const char name[], SkScalar value) { fMeta.setScalar(name, value); }
00119 SkScalar* setScalars(const char name[], int count, const SkScalar values[] = NULL) { return fMeta.setScalars(name, count, values); }
00121 void setString(const char name[], const SkString& value) { fMeta.setString(name, value.c_str()); }
00123 void setString(const char name[], const char value[]) { fMeta.setString(name, value); }
00125 void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); }
00126 void setBool(const char name[], bool value) { fMeta.setBool(name, value); }
00127
00129 SkMetaData& getMetaData() { return fMeta; }
00131 const SkMetaData& getMetaData() const { return fMeta; }
00132
00133 void tron() { SkDEBUGCODE(fDebugTrace = true;) }
00134 void troff() { SkDEBUGCODE(fDebugTrace = false;) }
00135 bool isDebugTrace() const
00136 {
00137 #ifdef SK_DEBUG
00138 return fDebugTrace;
00139 #else
00140 return false;
00141 #endif
00142 }
00143
00145 void inflate(const SkDOM&, const SkDOM::Node*);
00146
00147 SkDEBUGCODE(void dump(const char title[] = NULL);)
00148
00154 static bool Post(SkEvent* evt, SkEventSinkID targetID, SkMSec delay = 0);
00160 static bool PostTime(SkEvent* evt, SkEventSinkID targetID, SkMSec time);
00161
00166 bool post(SkEventSinkID sinkID, SkMSec delay = 0)
00167 {
00168 return SkEvent::Post(this, sinkID, delay);
00169 }
00170
00171 void postTime(SkEventSinkID sinkID, SkMSec time)
00172 {
00173 SkEvent::PostTime(this, sinkID, time);
00174 }
00175
00177
00178
00179
00184 static void Init();
00188 static void Term();
00189
00193 static bool ProcessEvent();
00198 static void ServiceQueueTimer();
00199
00201
00202
00203
00207 static void SignalNonEmptyQueue();
00211 static void SignalQueueTimer(SkMSec delay);
00212
00213 #ifndef SK_USE_WXWIDGETS
00214 #ifdef SK_BUILD_FOR_WIN
00215 static bool WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00216 #elif defined(SK_BUILD_FOR_UNIXx)
00217 static uint32_t HandleTimer(uint32_t, void*);
00218 static bool WndProc(Display*, Window, XEvent&);
00219 #endif
00220 #else
00221
00222
00223 #endif
00224
00225 private:
00226 SkMetaData fMeta;
00227 mutable char* fType;
00228 uint32_t f32;
00229 SkDEBUGCODE(bool fDebugTrace;)
00230
00231
00232 SkEventSinkID fTargetID;
00233 SkMSec fTime;
00234 SkEvent* fNextEvent;
00235 void initialize(const char* type, size_t typeLen);
00236
00237 static bool Enqueue(SkEvent* evt);
00238 static SkMSec EnqueueTime(SkEvent* evt, SkMSec time);
00239 static SkEvent* Dequeue(SkEventSinkID* targetID);
00240 static bool QHasEvents();
00241 };
00242
00243 #endif
00244