@@ -98,7 +98,10 @@ struct MCEvent
9898
9999 struct
100100 {
101- MCObjectHandle *target;
101+ // This shouldn't really be a raw MCObjectProxy* but we can't embed
102+ // the MCObjectHandle RAII class here as it cannot be placed inside
103+ // a union.
104+ MCObjectProxy* target;
102105 union
103106 {
104107 struct
@@ -293,18 +296,16 @@ static void MCEventQueueDispatchEvent(MCEvent *p_event)
293296
294297 case kMCEventTypeUpdateMenu :
295298 {
296- MCObject *t_target;
297- t_target = t_event -> menu . target -> Get ();
298- if (t_target != nil)
299+ MCObjectHandle t_target = t_event->menu .target ;
300+ if (t_target.IsValid ())
299301 t_target->message_with_valueref_args (MCM_mouse_down, kMCEmptyString );
300302 }
301303 break ;
302304
303305 case kMCEventTypeMenuPick :
304306 {
305- MCObject *t_target;
306- t_target = t_event -> menu . target -> Get ();
307- if (t_target != nil)
307+ MCObjectHandle t_target = t_event->menu .target ;
308+ if (t_target.IsValid ())
308309 // SN-2014-06-23: pick updated to StringRef
309310 t_target->message_with_valueref_args (MCM_menu_pick, t_event -> menu . pick . string);
310311 }
@@ -605,12 +606,13 @@ static void MCEventQueueDestroyEvent(MCEvent *p_event)
605606 MCMemoryDeleteArray (p_event -> ime . compose . chars);
606607 else if (p_event -> type == kMCEventTypeUpdateMenu )
607608 {
608- p_event -> menu . target -> Release ();
609+ MCObjectHandle t_handle = p_event->menu .target ;
610+ t_handle.ExternalRelease ();
609611 }
610612 else if (p_event -> type == kMCEventTypeMenuPick )
611613 {
612- p_event -> menu . target -> Release () ;
613- // SN-2014-06-23: pick updated to StringRef
614+ MCObjectHandle t_handle = p_event-> menu . target ;
615+ t_handle. ExternalRelease ();
614616 MCValueRelease (p_event -> menu . pick . string);
615617 }
616618#ifdef _MOBILE
@@ -1076,23 +1078,25 @@ bool MCEventQueuePostResumeApp(void)
10761078 return MCEventQueuePost (kMCEventTypeResumeApp , t_event);
10771079}
10781080
1079- bool MCEventQueuePostUpdateMenu (MCObjectHandle * p_target)
1081+ bool MCEventQueuePostUpdateMenu (MCObjectHandle p_target)
10801082{
10811083 MCEvent *t_event;
10821084 if (!MCEventQueuePost (kMCEventTypeUpdateMenu , t_event))
10831085 return false ;
1084- p_target -> Retain ();
1085- t_event -> menu . target = p_target;
1086+
1087+ t_event -> menu . target = p_target.ExternalRetain ();
1088+
10861089 return true ;
10871090}
10881091
1089- bool MCEventQueuePostMenuPick (MCObjectHandle * p_target, MCStringRef p_string)
1092+ bool MCEventQueuePostMenuPick (MCObjectHandle p_target, MCStringRef p_string)
10901093{
10911094 MCEvent *t_event;
10921095 if (!MCEventQueuePost (kMCEventTypeMenuPick , t_event))
10931096 return false ;
1094- p_target -> Retain ();
1095- t_event -> menu . target = p_target;
1097+
1098+ t_event -> menu . target = p_target.ExternalRetain ();
1099+
10961100 // SN-2014-06-23: pick updated to StringRef
10971101 return MCStringCopy (p_string, t_event -> menu . pick . string);
10981102}
@@ -1138,7 +1142,7 @@ struct MCTouch
11381142 MCTouch *next;
11391143 uint32_t id;
11401144 int32_t x, y;
1141- MCObjectHandle * target;
1145+ MCObjectHandle target;
11421146};
11431147
11441148static MCTouch *s_touches = nil;
@@ -1166,7 +1170,7 @@ static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p
11661170
11671171 if (t_touch != nil)
11681172 {
1169- t_target = t_touch -> target -> Get () ;
1173+ t_target = t_touch -> target;
11701174
11711175 // MW-2011-09-05: [[ Bug 9683 ]] Make sure we remove (and delete the touch) here if
11721176 // it is 'end' or 'cancelled' so that a cleartouches inside an invoked handler
@@ -1178,9 +1182,6 @@ static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p
11781182 else
11791183 t_previous_touch -> next = t_touch -> next;
11801184
1181- // MW-2011-01-28: Looks like a leak to me - make sure we release the object handle!
1182- t_touch -> target -> Release ();
1183-
11841185 delete t_touch;
11851186 }
11861187 }
@@ -1192,7 +1193,7 @@ static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p
11921193 t_touch -> id = p_id;
11931194
11941195 t_target = p_stack -> getcurcard () -> hittest (t_touch_loc.x , t_touch_loc.y );
1195- t_touch -> target = t_target -> gethandle ();
1196+ t_touch -> target = t_target -> GetHandle ();
11961197
11971198 s_touches = t_touch;
11981199 }
@@ -1202,7 +1203,7 @@ static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p
12021203 // Touches on widgets are handled differently
12031204 if (t_target->gettype () == CT_WIDGET )
12041205 {
1205- MCwidgeteventmanager->event_touch (reinterpret_cast <MCWidget* >(t_target),
1206+ MCwidgeteventmanager->event_touch (MCObjectCast <MCWidget>(t_target),
12061207 p_id, p_phase, t_touch_loc.x , t_touch_loc.y );
12071208 }
12081209 else
@@ -1235,8 +1236,6 @@ static void clear_touches(void)
12351236 t_touch = s_touches;
12361237 s_touches = s_touches -> next;
12371238
1238- t_touch -> target -> Release ();
1239-
12401239 delete t_touch;
12411240 }
12421241}
0 commit comments