comparison nodejs/mbfly_njs.cc @ 676:f264b50c469c

Bind subject of mouse_event to JS object of coord
author Thinker K.F. Li <thinker@branda.to>
date Fri, 06 Aug 2010 13:33:47 +0800
parents c643af2095c5
children 799c852b9065
comparison
equal deleted inserted replaced
675:c643af2095c5 676:f264b50c469c
24 24
25 return coord; 25 return coord;
26 } 26 }
27 27
28 static void 28 static void
29 xnjsmb_coord_mod(Handle<Object> mbrt, Handle<Value> ret) { 29 xnjsmb_coord_new_mod(Handle<Object> mbrt, Handle<Value> ret) {
30 Handle<Object> ret_obj = ret->ToObject(); 30 Handle<Object> ret_obj = ret->ToObject();
31 Persistent<Object> *ret_obj_hdl; 31 Persistent<Object> *ret_obj_hdl;
32 coord_t *coord; 32 coord_t *coord;
33 subject_t *subject;
34 Handle<Value> subject_o;
33 35
34 SET(ret_obj, "mbrt", mbrt); 36 SET(ret_obj, "mbrt", mbrt);
35 coord = (coord_t *)UNWRAP(ret_obj); 37 coord = (coord_t *)UNWRAP(ret_obj);
36 /* Keep associated js object in property store for retrieving, 38 /* Keep associated js object in property store for retrieving,
37 * later, without create new js object. 39 * later, without create new js object.
38 */ 40 */
39 ret_obj_hdl = new Persistent<Object>(ret_obj); 41 ret_obj_hdl = new Persistent<Object>(ret_obj);
40 mb_prop_set(&coord->obj.props, PROP_JSOBJ, ret_obj_hdl); 42 mb_prop_set(&coord->obj.props, PROP_JSOBJ, ret_obj_hdl);
43
44 subject = coord->mouse_event;
45 subject_o = export_xnjsmb_auto_subject_new(subject);
46 SET(ret_obj, "subject", subject_o);
41 } 47 }
42 48
43 #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new 49 #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new
44 50
45 static void 51 static void
60 66
61 static njs_runtime_t * 67 static njs_runtime_t *
62 _X_njs_MB_new(Handle<Object> self, char *display_name, 68 _X_njs_MB_new(Handle<Object> self, char *display_name,
63 int width, int height) { 69 int width, int height) {
64 njs_runtime_t *obj; 70 njs_runtime_t *obj;
71 coord_t *root;
72 subject_t *subject;
73 Handle<Object> root_o;
74 Handle<Value> subject_o;
65 75
66 obj = X_njs_MB_new(display_name, width, height); 76 obj = X_njs_MB_new(display_name, width, height);
67 WRAP(self, obj); /* mkroot need a wrapped object, but 77 WRAP(self, obj); /* mkroot need a wrapped object, but
68 * it is wrapped after returning of 78 * it is wrapped after returning of
69 * this function. So, we wrap it 79 * this function. So, we wrap it
70 * here. */ 80 * here. */
71 X_njs_MB_init_handle_connection(obj); 81 X_njs_MB_init_handle_connection(obj);
72 xnjsmb_coord_mkroot(self); 82 xnjsmb_coord_mkroot(self);
83
84 root_o = GET(self, "root")->ToObject();
85 root = (coord_t *)UNWRAP(root_o);
86 subject = root->mouse_event;
87 subject_o = export_xnjsmb_auto_subject_new(subject);
88 SET(root_o, "subject", subject_o);
73 89
74 return obj; 90 return obj;
75 } 91 }
76 92
77 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. 93 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs.
123 */ 139 */
124 xnjsmb_shapes_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); 140 xnjsmb_shapes_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
125 xnjsmb_paints_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); 141 xnjsmb_paints_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
126 xnjsmb_font_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); 142 xnjsmb_font_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
127 xnjsmb_img_ldr_init_mb_rt_temp(target); 143 xnjsmb_img_ldr_init_mb_rt_temp(target);
144 xnjsmb_observer_init();
128 145
129 target->Set(String::New("mb_rt"), 146 target->Set(String::New("mb_rt"),
130 xnjsmb_auto_mb_rt_temp->GetFunction()); 147 xnjsmb_auto_mb_rt_temp->GetFunction());
131 } 148 }