Adonthell 0.4
win_event.cc
00001 /*
00002    $Id: win_event.cc,v 1.6 2011/02/11 20:50:27 ksterker Exp $
00003 
00004    (C) Copyright 2001 Joel Vennin
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details
00013 */
00014 
00015 
00016 #include "win_event.h"
00017 #include "py_callback.h"
00018 
00019 
00020 void win_event::py_signal_connect (PyObject *pyfunc, int signal, PyObject *args) 
00021 {
00022     // create the callback
00023     py_callback *callback = new py_callback (pyfunc, args);
00024     py_callbacks.push_back (callback);
00025 
00026     // connect the signal
00027     switch (signal)
00028     {
00029         case CLOSE:
00030         {
00031             set_callback_quit (makeFunctor (*callback, &py_callback::callback_func1));
00032             break;
00033         }
00034     
00035         case DESTROY:
00036         {
00037         Functor0wRet<bool> func0ret;
00038             set_callback_destroy (
00039             makeFunctor (&func0ret, *callback, &py_callback::callback_func0ret));
00040             break;
00041         }
00042     
00043         default:
00044         {
00045             set_signal_connect (makeFunctor (*callback, &py_callback::callback_func0), signal);
00046         }
00047     }
00048 }
00049   
00050 
00051 bool win_event::update()
00052 {
00053   if(callback_destroy_ && !callback_destroy_()) return false;
00054   return true;
00055 }
00056 
00057 
00058 win_event::~win_event()
00059 {
00060   //notify that window is closing 
00061   if (callback_quit_) (callback_quit_) (return_code_);
00062   
00063   //delete any python callbacks
00064   for (vector<py_callback *>::iterator i = py_callbacks.begin (); i != py_callbacks.end (); i++)
00065     delete *i;
00066 }
00067 
00068 
00069 
00070 
00071 
00072