Add:Core:Made it possible to drag the bitmap instead of the vectors (based on code...
[navit-package] / navit / callback.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef NAVIT_CALLBACK_H
21 #define NAVIT_CALLBACK_H
22
23 #include "item.h"
24 #include "attr.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 /* prototypes */
30 enum attr_type;
31 struct callback;
32 struct callback_list;
33 struct callback_list *callback_list_new(void);
34 struct callback *callback_new_attr(void (*func)(void), enum attr_type type, int pcount, void **p);
35 struct callback *callback_new(void (*func)(void), int pcount, void **p);
36 void callback_destroy(struct callback *cb);
37 void callback_set_arg(struct callback *cb, int arg, void *p);
38 void callback_list_add(struct callback_list *l, struct callback *cb);
39 struct callback *callback_list_add_new(struct callback_list *l, void (*func)(void), int pcount, void **p);
40 void callback_list_remove(struct callback_list *l, struct callback *cb);
41 void callback_list_remove_destroy(struct callback_list *l, struct callback *cb);
42 void callback_call(struct callback *cb, int pcount, void **p);
43 void callback_list_call_attr(struct callback_list *l, enum attr_type type, int pcount, void **p);
44 void callback_list_call(struct callback_list *l, int pcount, void **p);
45 void callback_list_destroy(struct callback_list *l);
46 /* end of prototypes */
47
48 static inline struct callback *callback_new_attr_0(void (*func)(void), enum attr_type type)
49 {
50         return callback_new_attr(func, type, 0, NULL);
51 }
52
53 static inline struct callback *callback_new_0(void (*func)(void))
54 {
55         return callback_new(func, 0, NULL);
56 }
57
58 static inline struct callback *callback_new_attr_1(void (*func)(void), enum attr_type type, void *p1)
59 {
60         void *p[1];
61         p[0]=p1;
62         return callback_new_attr(func, type, 1, p);
63 }
64
65 static inline struct callback *callback_new_1(void (*func)(void), void *p1)
66 {
67         void *p[1];
68         p[0]=p1;
69         return callback_new(func, 1, p);
70 }
71
72 static inline struct callback *callback_new_attr_2(void (*func)(void), enum attr_type type, void *p1, void *p2)
73 {
74         void *p[2];
75         p[0]=p1;
76         p[1]=p2;
77         return callback_new_attr(func, type, 2, p);
78 }
79
80 static inline struct callback *callback_new_2(void (*func)(void), void *p1, void *p2)
81 {
82         void *p[2];
83         p[0]=p1;
84         p[1]=p2;
85         return callback_new(func, 2, p);
86 }
87
88 static inline struct callback *callback_new_3(void (*func)(void), void *p1, void *p2, void *p3)
89 {
90         void *p[3];
91         p[0]=p1;
92         p[1]=p2;
93         p[2]=p3;
94         return callback_new(func, 3, p);
95 }
96
97 static inline void callback_call_0(struct callback *cb)
98 {
99         callback_call(cb, 0, NULL);
100 }
101
102 static inline void callback_call_1(struct callback *cb, void *p1)
103 {
104         void *p[1];
105         p[0]=p1;
106         callback_call(cb, 1, p);
107 }
108
109 static inline void callback_list_call_0(struct callback_list *l)
110 {
111         callback_list_call(l, 0, NULL);
112 }
113
114 static inline void callback_list_call_attr_0(struct callback_list *l, enum attr_type type)
115 {
116         callback_list_call_attr(l, type, 0, NULL);
117 }
118
119 static inline void callback_list_call_attr_1(struct callback_list *l, enum attr_type type, void *p1)
120 {
121         void *p[1];
122         p[0]=p1;
123         callback_list_call_attr(l, type, 1, p);
124 }
125
126 static inline void callback_list_call_1(struct callback_list *l, void *p1)
127 {
128         void *p[1];
129         p[0]=p1;
130         callback_list_call(l, 1, p);
131 }
132
133 static inline void callback_list_call_attr_2(struct callback_list *l, enum attr_type type, void *p1, void *p2)
134 {
135         void *p[2];
136         p[0]=p1;
137         p[1]=p2;
138         callback_list_call_attr(l, type, 2, p);
139 }
140
141 static inline void callback_list_call_2(struct callback_list *l, void *p1, void *p2)
142 {
143         void *p[2];
144         p[0]=p1;
145         p[1]=p2;
146         callback_list_call(l, 2, p);
147 }
148
149 static inline void callback_list_call_attr_3(struct callback_list *l, enum attr_type type, void *p1, void *p2, void *p3)
150 {
151         void *p[3];
152         p[0]=p1;
153         p[1]=p2;
154         p[2]=p3;
155         callback_list_call_attr(l, type, 3, p);
156 }
157
158 static inline void callback_list_call_attr_4(struct callback_list *l, enum attr_type type, void *p1, void *p2, void *p3, void *p4)
159 {
160         void *p[4];
161         p[0]=p1;
162         p[1]=p2;
163         p[2]=p3;
164         p[3]=p4;
165         callback_list_call_attr(l, type, 4, p);
166 }
167
168
169 #define callback_cast(x) (void (*)(void))(x)
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif
175