Adonthell  0.4
win_event.h
1 /*
2  (C) Copyright 2000, 2001 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef _WIN_EVENT_H_
20 #define _WIN_EVENT_H_
21 
22 #include <locale>
23 #include "Python.h"
24 #include <vector>
25 
26 class py_callback;
27 
28 
29 #include "types.h"
30 #include "callback.h"
31 
32 
33 using namespace std;
34 
35 class win_event
36 {
37  public:
38 
39  win_event(){return_code_=0;}
40 
41  //Use this function to set a callback function
42  void set_return_code (int rc)
43  { return_code_ = rc; }
44 
45 #ifndef SWIG
46  void set_signal_connect (const Functor0 &func, u_int8 signal)
47  { callback_[signal] = func; }
48  void set_callback_destroy (const Functor0wRet<bool> &func)
49  { callback_destroy_ = func; }
50  void set_callback_quit (const Functor1<int> &func)
51  { callback_quit_ = func;}
52 #endif
53 
54  bool update();
55 
56  void py_signal_connect (PyObject *pyfunc, int signal, PyObject *args = NULL);
57 
58  const static u_int8 ACTIVATE =1 ;
59  const static u_int8 UNACTIVATE = 2;
60  const static u_int8 UPDATE = 3;
61  const static u_int8 DRAW = 4;
62  const static u_int8 DRAW_ON_VISIBLE = 5;
63  const static u_int8 ACTIVATE_KEY = 6;
64  const static u_int8 SELECT = 7;
65  const static u_int8 UNSELECT = 8;
66  const static u_int8 KEYBOARD = 9;
67  const static u_int8 SCROLL_UP = 10;
68  const static u_int8 SCROLL_DOWN = 11;
69  const static u_int8 NEXT = 12;
70  const static u_int8 PREVIOUS = 13;
71  const static u_int8 CLOSE = 14;
72  const static u_int8 DESTROY = 15;
73 
74  /*****************************************************/
75  /*****************************************************/
76  //DESTRUCTOR
77  virtual ~win_event();
78 
79  protected:
80  // the python callbacks connected to the window
81  vector<py_callback *> py_callbacks;
82 
83 
84  Functor0 callback_[20];
85  Functor0wRet<bool> callback_destroy_;
86  Functor1<int> callback_quit_;
87 
88 
89  int return_code_;
90 
91  //execute the callback function
92  virtual void on_activate(){ if(callback_[ACTIVATE]) (callback_[ACTIVATE])();}
93  virtual void on_unactivate(){ if(callback_[UNACTIVATE]) (callback_[UNACTIVATE])();}
94 
95  virtual void on_update() { if(callback_[UPDATE]) (callback_[UPDATE])();}
96 
97  virtual void on_draw_visible(){ if(callback_[DRAW_ON_VISIBLE]) (callback_[DRAW_ON_VISIBLE])();}
98  virtual void on_draw(){ if(callback_[DRAW]) (callback_[DRAW])();}
99 
100  virtual void on_activate_key(){ if(callback_[ACTIVATE_KEY]) (callback_[ACTIVATE_KEY])();}
101  virtual void on_select(){ if(callback_[SELECT]) (callback_[SELECT])();}
102  virtual void on_unselect(){ if(callback_[UNSELECT]) (callback_[UNSELECT])();}
103 
104  virtual void on_up(){if(callback_[SCROLL_UP]) (callback_[SCROLL_UP])();}
105  virtual void on_down(){if(callback_[SCROLL_DOWN]) (callback_[SCROLL_DOWN])();}
106 
107  virtual void on_next(){if(callback_[NEXT]) (callback_[NEXT])();}
108  virtual void on_previous(){if(callback_[PREVIOUS]) (callback_[PREVIOUS])();}
109 };
110 
111 
112 
113 #endif
114 
115 
Declares some basic types.
Definition: str_hash.h:71
#define u_int8
8 bits long unsigned integer
Definition: types.h:35
Stores the C++ <-> Python callback binding.
Definition: py_callback.h:41