comparison include/mb_observer.h @ 1067:7b4e80ab671a openvg

merge from default branch
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Dec 2010 12:25:56 +0800
parents e415c55b4a0d
children 1993e5ae60aa
comparison
equal deleted inserted replaced
630:bd18951b51d5 1067:7b4e80ab671a
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4
1 #ifndef __OBSERVER_H_ 3 #ifndef __OBSERVER_H_
2 #define __OBSERVER_H_ 4 #define __OBSERVER_H_
3 5
4 #include "mb_tools.h" 6 #include "mb_tools.h"
5 7
6 typedef struct _event event_t; 8 typedef struct _event event_t;
7 typedef struct _observer observer_t; 9 typedef struct _observer observer_t;
8 typedef struct _subject subject_t; 10 typedef struct _subject subject_t;
9 typedef struct _mouse_event mouse_event_t; 11 typedef struct _mouse_event mouse_event_t;
10 typedef struct _monitor_event monitor_event_t; 12 typedef struct _monitor_event monitor_event_t;
11 typedef struct _ob_factory ob_factory_t; 13 typedef struct _observer_factory observer_factory_t;
12 typedef void (*evt_handler)(event_t *event, void *arg); 14 typedef void (*evt_handler)(event_t *event, void *arg);
13 15
14 struct _event { 16 struct _event {
15 int type; /*!< event type (a.k.a. EVT_*) */ 17 int type; /*!< event type (a.k.a. EVT_*) */
16 subject_t *tgt, *cur_tgt; 18 subject_t *tgt, *cur_tgt;
51 int obj_type; /*!< \brief type of object (a.k.a. OBJT_*). */ 53 int obj_type; /*!< \brief type of object (a.k.a. OBJT_*). */
52 void *obj; /*!< \brief the object this subject for. */ 54 void *obj; /*!< \brief the object this subject for. */
53 int flags; 55 int flags;
54 subject_t *monitor_sub; /*!< \brief Monitor adding/removing 56 subject_t *monitor_sub; /*!< \brief Monitor adding/removing
55 * obervers on this subject. */ 57 * obervers on this subject. */
56 ob_factory_t *factory; 58 observer_factory_t *factory;
57 STAILQ(observer_t) observers; 59 STAILQ(observer_t) observers;
58 }; 60 };
59 /*! \brief Flag that make a subject to stop propagate events to parents. */ 61 /*! \brief Flag that make a subject to stop propagate events to parents. */
60 #define SUBF_STOP_PROPAGATE 0x1 62 #define SUBF_STOP_PROPAGATE 0x1
61 #define SUBF_BUSY 0x2 /*!< \brief in subject_notify() */ 63 #define SUBF_BUSY 0x2 /*!< \brief in subject_notify() */
83 /*! \brief Observer factory. 85 /*! \brief Observer factory.
84 * 86 *
85 * It provides functions for allocation of subject and observer objects, 87 * It provides functions for allocation of subject and observer objects,
86 * and strategy function for getting the subject of parent coord object. 88 * and strategy function for getting the subject of parent coord object.
87 */ 89 */
88 struct _ob_factory { 90 struct _observer_factory {
89 subject_t *(*subject_alloc)(ob_factory_t *factory); 91 subject_t *(*subject_alloc)(observer_factory_t *factory);
90 void (*subject_free)(ob_factory_t *factory, subject_t *subject); 92 void (*subject_free)(observer_factory_t *factory, subject_t *subject);
91 observer_t *(*observer_alloc)(ob_factory_t *factory); 93 observer_t *(*observer_alloc)(observer_factory_t *factory);
92 void (*observer_free)(ob_factory_t *factory, observer_t *observer); 94 void (*observer_free)(observer_factory_t *factory, observer_t *observer);
93 /*! This is a strategy function to get subjects of parents. */ 95 /*! This is a strategy function to get subjects of parents. */
94 subject_t *(*get_parent_subject)(ob_factory_t *factory, 96 subject_t *(*get_parent_subject)(observer_factory_t *factory,
95 subject_t *cur_subject); 97 subject_t *cur_subject);
96 }; 98 };
97 99
98 enum {EVT_ANY,EVT_MOUSE_OVER, EVT_MOUSE_OUT, EVT_MOUSE_MOVE, 100 enum {EVT_ANY,EVT_MOUSE_OVER, EVT_MOUSE_OUT, EVT_MOUSE_MOVE,
99 EVT_MOUSE_BUT_PRESS, EVT_MOUSE_BUT_RELEASE, 101 EVT_MOUSE_BUT_PRESS, EVT_MOUSE_BUT_RELEASE,
101 EVT_RDMAN_REDRAW, 103 EVT_RDMAN_REDRAW,
102 EVT_MONITOR_ADD, EVT_MONITOR_REMOVE, EVT_MONITOR_FREE, 104 EVT_MONITOR_ADD, EVT_MONITOR_REMOVE, EVT_MONITOR_FREE,
103 EVT_MOUSE_MOVE_RAW 105 EVT_MOUSE_MOVE_RAW
104 }; 106 };
105 107
106 extern subject_t *subject_new(ob_factory_t *factory, 108 extern subject_t *subject_new(observer_factory_t *factory,
107 void *obj, int obj_type); 109 void *obj, int obj_type);
108 extern void subject_free(subject_t *subject); 110 extern void subject_free(subject_t *subject);
109 extern void subject_notify(subject_t *subject, event_t *evt); 111 extern void subject_notify(subject_t *subject, event_t *evt);
110 extern observer_t *subject_add_event_observer(subject_t *subject, int type, 112 extern observer_t *subject_add_event_observer(subject_t *subject, int type,
111 evt_handler hdr, void *arg); 113 evt_handler hdr, void *arg);