Main Page Class Hierarchy Compound List File List Compound Members File Members Related Pages Examples

# sdlmessageobject.h

Go to the documentation of this file.

    00001 /*
    00002     ParaGUI - crossplatform widgetset
    00003     Copyright (C) 2000  Alexander Pipelka
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018
    00019     Alexander Pipelka
    00020     pipelka@teleweb.at
    00021
    00022     Last Update:      $Author: pipelka $
    00023     Update Date:      $Date: 2001/01/31 17:23:16 $
    00024     Source File:      $Source: /usr/local/CVSROOT/linux/paragui/doc/html/sdlmessageobject_h-source.html,v $
    00025     CVS/RCS Revision: $Revision: 1.34 $
    00026     Status:           $State: Exp $
    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 //class SDLMessageObject;
    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     // mutexes
    00276
    00277     SDL_mutex* my_mutexSendMessage;
    00278     SDL_mutex* my_mutexReceiveMessage;
    00279
    00280     // callback functions
    00281
    00282     /*
    00283     MSG_CALLBACK my_cbFunc[MSG_TABLE_SIZE];
    00284     void* my_cbData[MSG_TABLE_SIZE];
    00285     */
    00286 };
    00287
    00288
    00289 #ifdef SWIG
    00290
    00291 // Grab a Python function object as a Python object.
    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    /* This function matches the prototype of the normal C callback
    00304       function for our widget. However, we use the clientdata pointer
    00305       for holding a reference to a Python callable object. */
    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;               // Get Python function
    00313    arglist = Py_BuildValue("(ill)",id,widget,data);// Build argument list
    00314    result = PyEval_CallObject(func,arglist);     // Call Python
    00315    Py_DECREF(arglist);                           // Trash arglist
    00316    if (result) {                                 // If no errors, return double
    00317       res = PyInt_AsLong(result);
    00318    }
    00319    Py_XDECREF(result);
    00320    return res;
    00321 }
    00322
    00323 // Attach a new method to our plot widget for adding Python functions
    00324 // Set a Python function object as a callback function
    00325 // Note : PyObject *pyfunc is remapped with a typempap
    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