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 #ifndef SDLMESSAGEOBJECT_H
00030 #define SDLMESSAGEOBJECT_H
00031
00032 #ifdef SWIG
00033 %include "swigcommon.h"
00034 %module sdlmessageobject
00035 %{
00036 #include "sdlmessageobject.h"
00037 %}
00038 #endif
00039
00040 #include "paragui.h"
00041
00042
00043 class SDLWidget;
00044
00053 class DECLSPEC SDLMessageObject {
00054
00055 public:
00062 SDLMessageObject();
00063
00067 virtual ~SDLMessageObject();
00068
00076 void EnableReceiver(bool enable);
00077
00082 SDLMessageObject* SetCapture();
00083
00087 void ReleaseCapture();
00088
00090 SDLMessageObject* SetInputFocus();
00091
00093 void ReleaseInputFocus();
00094
00098 int RunEventLoop(void* data);
00099
00103 bool IsEnabled();
00104
00106 bool SendMessage(SDLMessageObject* target, MSG_TYPE type, MSG_ID id, MSG_DATA data);
00107
00109 void SetEventCallback(MSG_TYPE type, MSG_CALLBACK cbfunc, void *clientdata = NULL);
00110
00119 static int PumpIntoEventQueue(const SDL_Event* event);
00120
00122 SDL_Event WaitEvent(Uint32 delay=0);
00123
00124 protected:
00125
00134 virtual bool eventActive(const SDL_ActiveEvent* active);
00135
00145 virtual bool eventKeyDown(const SDL_KeyboardEvent* key);
00146
00156 virtual bool eventKeyUp(const SDL_KeyboardEvent* key);
00157
00167 virtual bool eventMouseMotion(const SDL_MouseMotionEvent* motion);
00168
00178 virtual bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
00179
00189 virtual bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
00190
00199 virtual bool eventQuit(int id, SDLWidget* widget, unsigned long data);
00200
00209 virtual bool eventSysWM(const SDL_SysWMEvent* syswm);
00210
00219 virtual bool eventMessage(MSG_MESSAGE* msg);
00220
00222 virtual bool eventButtonClick(int id, SDLWidget* widget);
00223
00225 virtual bool eventScrollPos(int id, SDLWidget* widget, unsigned long data);
00226
00228 virtual bool eventScrollTrack(int id, SDLWidget* widget, unsigned long data);
00229
00231 virtual void eventInputFocusLost(SDLMessageObject* newfocus);
00232
00234 virtual void eventIdle();
00235
00244 virtual bool AcceptEvent(const SDL_Event* event);
00245
00253 virtual bool ProcessEvent(const SDL_Event* event);
00254
00255 bool my_quitEventLoop;
00256
00257 private:
00258
00259 SDLMessageObject(const SDLMessageObject&);
00260 SDLMessageObject& operator=(const SDLMessageObject&);
00261
00262 static void SetObjectList(SDLMessageObject* list);
00263 void RemoveObject(SDLMessageObject* obj);
00264
00265 static SDLMessageObject* objectList;
00266 static SDLMessageObject* captureObject;
00267 static SDLMessageObject* inputFocusObject;
00268
00269 SDLMessageObject* my_oldCapture;
00270 SDLMessageObject* my_oldFocus;
00271 SDLMessageObject* my_objectNext;
00272
00273 bool my_canReceiveMessages;
00274
00275
00276
00277 SDL_mutex* my_mutexSendMessage;
00278 SDL_mutex* my_mutexReceiveMessage;
00279
00280
00281
00282
00283
00284
00285
00286 };
00287
00288
00289 #ifdef SWIG
00290
00291
00292 %typemap(python,in) PyObject *pyfunc {
00293 if (!PyCallable_Check($source)) {
00294 PyErr_SetString(PyExc_TypeError, "Need a callable object!");
00295 return NULL;
00296 }
00297 $target = $source;
00298 }
00299
00300
00301 %{
00302
00303
00304
00305
00306 static bool PythonCallBack(int id, SDLWidget *widget, unsigned long data, void *clientdata)
00307 {
00308 PyObject *func, *arglist;
00309 PyObject *result;
00310 bool res = 0;
00311
00312 func = (PyObject *) clientdata;
00313 arglist = Py_BuildValue("(ill)",id,widget,data);
00314 result = PyEval_CallObject(func,arglist);
00315 Py_DECREF(arglist);
00316 if (result) {
00317 res = PyInt_AsLong(result);
00318 }
00319 Py_XDECREF(result);
00320 return res;
00321 }
00322
00323
00324
00325
00326 %}
00327
00328 %addmethods SDLMessageObject {
00329 void set_pymethod(MSG_TYPE type, PyObject *pyfunc) {
00330 self->SetEventCallback(type, PythonCallBack, (void *) pyfunc);
00331 Py_INCREF(pyfunc);
00332 }
00333 }
00334 #endif
00335
00336 #endif // SDLMESSAGEOBJECT_H