comparison src/graphics.cc @ 7367:600808df131c

[project @ 2008-01-14 08:58:02 by jwe]
author jwe
date Mon, 14 Jan 2008 08:58:02 +0000
parents 2a2115742cb5
children 74d64ead0cd7
comparison
equal deleted inserted replaced
7366:2a2115742cb5 7367:600808df131c
133 133
134 retval(0) = 0; 134 retval(0) = 0;
135 retval(1) = 1; 135 retval(1) = 1;
136 136
137 return retval; 137 return retval;
138 }
139
140 // NOTE: "cb" is passed by value, because "function_value" method
141 // is non-const; passing "cb" by const-reference is not
142 // possible
143
144 static void
145 execute_callback (octave_value cb, const graphics_handle& h,
146 const octave_value& data)
147 {
148 octave_value_list args;
149 octave_function *fcn = 0;
150
151 args(0) = h.as_octave_value ();
152 args(1) = data;
153
154 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
155
156 if (cb.is_function_handle ())
157 fcn = cb.function_value ();
158 else if (cb.is_string ())
159 {
160 std::string s = cb.string_value ();
161 octave_value f = symbol_table::find_function (s);
162 int status;
163
164 if (f.is_defined ())
165 fcn = f.function_value ();
166 else
167 {
168 eval_string (s, false, status);
169 return;
170 }
171 }
172 else if (cb.is_cell () && cb.length () > 0
173 && (cb.rows () == 1 || cb.columns () == 1)
174 && cb.cell_value ()(0).is_function_handle ())
175 {
176 Cell c = cb.cell_value ();
177
178 fcn = c(0).function_value ();
179 if (! error_state)
180 {
181 for (int i = 0; i < c.length () ; i++)
182 args(2+i) = c(i);
183 }
184 }
185 else
186 error ("trying to execute non-executable object (class = %s)",
187 cb.class_name ());
188
189 if (! error_state)
190 feval (fcn, args);
191
192 END_INTERRUPT_WITH_EXCEPTIONS;
138 } 193 }
139 194
140 // --------------------------------------------------------------------- 195 // ---------------------------------------------------------------------
141 196
142 radio_values::radio_values (const std::string& opt_string) 197 radio_values::radio_values (const std::string& opt_string)
333 error ("set: invalid graphics handle for property \"%s\"", 388 error ("set: invalid graphics handle for property \"%s\"",
334 get_name ().c_str ()); 389 get_name ().c_str ());
335 } 390 }
336 391
337 bool 392 bool
338 callback_property::validate (const octave_value&) const 393 callback_property::validate (const octave_value& v) const
339 { 394 {
340 // FIXME: implement this 395 // case 1: function handle
341 return true; 396 // case 2: cell array with first element being a function handle
342 } 397 // case 3: string corresponding to known function name
343 398 // case 4: evaluatable string
344 void 399 // case 5: empty matrix
345 callback_property::execute (void) 400
346 { 401 if (v.is_function_handle ())
347 // FIXME: define correct signature and implement this 402 return true;
403 else if (v.is_string ())
404 // complete validation will be done at execution-time
405 return true;
406 else if (v.is_cell () && v.length () > 0
407 && (v.rows() == 1 || v.columns () == 1)
408 && v.cell_value ()(0).is_function_handle ())
409 return true;
410 else if (v.is_empty ())
411 return true;
412
413 return false;
414 }
415
416 void
417 callback_property::execute (const octave_value& data) const
418 {
419 if (callback.is_defined () && ! callback.is_empty ())
420 execute_callback (callback, get_parent (), data);
348 } 421 }
349 422
350 // --------------------------------------------------------------------- 423 // ---------------------------------------------------------------------
351 424
352 void 425 void
604 { 677 {
605 iterator p = handle_map.find (h); 678 iterator p = handle_map.find (h);
606 679
607 if (p != handle_map.end ()) 680 if (p != handle_map.end ())
608 { 681 {
682 p->second.get_properties ().execute_deletefcn ();
683
609 handle_map.erase (p); 684 handle_map.erase (p);
610 685
611 if (h.value () < 0) 686 if (h.value () < 0)
612 handle_free_list.insert (h); 687 handle_free_list.insert (h);
613 } 688 }
2063 2138
2064 graphics_handle parent_h = obj.get_parent (); 2139 graphics_handle parent_h = obj.get_parent ();
2065 2140
2066 graphics_object parent_obj = gh_manager::get_object (parent_h); 2141 graphics_object parent_obj = gh_manager::get_object (parent_h);
2067 2142
2143 // NOTE: free the handle before removing it from its parent's
2144 // children, such that the object's state is correct when
2145 // the deletefcn callback is executed
2146
2147 gh_manager::free (h);
2148
2068 parent_obj.remove_child (h); 2149 parent_obj.remove_child (h);
2069
2070 gh_manager::free (h);
2071 } 2150 }
2072 else 2151 else
2073 error ("delete: invalid graphics object (= %g)", val); 2152 error ("delete: invalid graphics object (= %g)", val);
2074 } 2153 }
2075 else 2154 else