Skip to content

Commit 85759f5

Browse files
committed
[[ Hooks ]] Move global handlers and native controls into hook system.
1 parent a60915d commit 85759f5

9 files changed

Lines changed: 66 additions & 75 deletions

File tree

engine/src/dispatch.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ Boolean MCDispatch::cut(Boolean home)
275275
return MCnoui || (flags & F_WAS_LICENSED) != 0;
276276
}
277277

278-
//extern Exec_stat MCHandlePlatformMessage(Handler_type htype, const MCString& mess, MCParameter *params);
279278
Exec_stat MCDispatch::handle(Handler_type htype, MCNameRef mess, MCParameter *params, MCObject *pass_from)
280279
{
281280
Exec_stat stat = ES_NOT_HANDLED;
@@ -342,29 +341,6 @@ Exec_stat MCDispatch::handle(Handler_type htype, MCNameRef mess, MCParameter *pa
342341
stat = ES_PASS;
343342
}
344343

345-
//#ifdef TARGET_SUBPLATFORM_IPHONE
346-
// extern Exec_stat MCIPhoneHandleMessage(MCNameRef message, MCParameter *params);
347-
// if (stat == ES_NOT_HANDLED || stat == ES_PASS)
348-
// {
349-
// stat = MCIPhoneHandleMessage(mess, params);
350-
//
351-
// if (stat != ES_NOT_HANDLED && stat != ES_PASS)
352-
// return stat;
353-
// }
354-
//#endif
355-
//
356-
//#ifdef _MOBILE
357-
// if (stat == ES_NOT_HANDLED || stat == ES_PASS)
358-
// {
359-
// stat = MCHandlePlatformMessage(htype, MCNameGetOldString(mess), params);
360-
//
361-
// // MW-2011-08-22: [[ Bug 9686 ]] Make sure we exit as soon as the
362-
// // message is handled.
363-
// if (stat != ES_NOT_HANDLED && stat != ES_PASS)
364-
// return stat;
365-
// }
366-
//#endif
367-
368344
if (MCmessagemessages && stat != ES_PASS)
369345
MCtargetptr->sendmessage(htype, mess, False);
370346

engine/src/exec-keywords.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
#include "globals.h"
4040

41-
#ifdef _MOBILE
42-
extern bool MCIsPlatformMessage(MCNameRef handler_name);
43-
extern Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters);
44-
#endif
45-
4641
////////////////////////////////////////////////////////////////////////////////
4742

4843
static Exec_stat MCKeywordsExecuteStatements(MCExecContext& ctxt, MCStatement *p_statements, Exec_errors p_error)
@@ -110,7 +105,7 @@ static Exec_stat MCKeywordsExecuteStatements(MCExecContext& ctxt, MCStatement *p
110105
return stat;
111106
}
112107

113-
void MCKeywordsExecCommandOrFunction(MCExecContext& ctxt, bool resolved, MCHandler *handler, MCParameter *params, MCNameRef name, uint2 line, uint2 pos, bool platform_message, bool is_function)
108+
void MCKeywordsExecCommandOrFunction(MCExecContext& ctxt, bool resolved, MCHandler *handler, MCParameter *params, MCNameRef name, uint2 line, uint2 pos, bool global_handler, bool is_function)
114109
{
115110
if (MCscreen->abortkey())
116111
{
@@ -181,17 +176,12 @@ void MCKeywordsExecCommandOrFunction(MCExecContext& ctxt, bool resolved, MCHandl
181176
added = True;
182177
}
183178

184-
if (platform_message)
179+
if (global_handler)
185180
{
186-
#ifdef _MOBILE
187-
extern Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters);
188-
189181
// AL-2014-03-14: Currently no mobile handler's execution is halted when ES_ERROR
190182
// is returned. Error info is returned via the result.
191-
stat = MCHandlePlatformMessage(name, params);
192-
if (stat != ES_NOT_HANDLED)
193-
stat = ES_NORMAL;
194-
#endif
183+
if (!MCRunGlobalHandler(name, params, stat))
184+
stat = ES_NOT_HANDLED;
195185
}
196186
else if (handler != nil)
197187
{

engine/src/exec-nativecontrol.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,12 @@ void MCNativeControlExecCreateControl(MCExecContext& ctxt, MCStringRef p_type_na
613613
}
614614

615615
MCNativeControlType t_type;
616-
if (!MCNativeControl::LookupType(p_type_name, t_type))
616+
if (!MCLookupNativeControlType(p_type_name, (intenum_t&)t_type))
617617
return;
618618

619619
MCNativeControl *t_new_control;
620620
t_new_control = nil;
621-
if (MCNativeControl::CreateWithType(t_type, t_new_control))
621+
if (MCCreateNativeControl((intenum_t)t_type, (void*&)t_new_control))
622622
{
623623
extern MCExecContext *MCECptr;
624624
t_new_control -> SetOwner(MCECptr -> GetObject());
@@ -701,7 +701,7 @@ void MCNativeControlExecGet(MCExecContext& ctxt, MCStringRef p_control_name, MCS
701701
return;
702702

703703
Properties t_property;
704-
if (!MCNativeControl::LookupProperty(p_property_name, t_property))
704+
if (!MCLookupNativeControlProperty(p_property_name, (intenum_t&)t_property))
705705
return;
706706

707707
MCPropertyInfo *t_info;
@@ -731,7 +731,7 @@ void MCNativeControlExecSet(MCExecContext& ctxt, MCStringRef p_control_name, MCS
731731
return;
732732

733733
Properties t_property;
734-
if (!MCNativeControl::LookupProperty(p_property_name, t_property))
734+
if (!MCLookupNativeControlProperty(p_property_name, (intenum_t&)t_property))
735735
return;
736736

737737
MCPropertyInfo *t_info;
@@ -775,7 +775,7 @@ void MCNativeControlExecDo(MCExecContext& ctxt, MCStringRef p_control_name, MCSt
775775
return;
776776

777777
MCNativeControlAction t_action;
778-
if (!MCNativeControl::LookupAction(p_action_name, t_action))
778+
if (!MCLookupNativeControlAction(p_action_name, (intenum_t&)t_action))
779779
return;
780780

781781
MCNativeControlActionInfo *t_info;
@@ -881,6 +881,8 @@ void MCNativeControlExecDo(MCExecContext& ctxt, MCStringRef p_control_name, MCSt
881881

882882
case kMCNativeControlActionUnknown:
883883
default:
884+
if (MCPerformNativeControlAction((intenum_t)t_info -> action, &t_control, p_arguments, p_argument_count))
885+
return;
884886
break;
885887
}
886888
ctxt . Throw();

engine/src/express.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,18 +646,13 @@ void MCExpression::compile_out(MCSyntaxFactoryRef ctxt)
646646

647647
////////////////////////////////////////////////////////////////////////////////
648648

649-
#ifdef _MOBILE
650-
extern bool MCIsPlatformMessage(MCNameRef handler_name);
651-
extern Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters);
652-
#endif
653-
654649
MCFuncref::MCFuncref(MCNameRef inname)
655650
{
656651
/* UNCHECKED */ MCNameClone(inname, name);
657652
handler = nil;
658653
params = NULL;
659654
resolved = false;
660-
platform_message = false;
655+
global_handler = false;
661656
}
662657

663658
MCFuncref::~MCFuncref()
@@ -680,13 +675,12 @@ Parse_stat MCFuncref::parse(MCScriptPoint &sp, Boolean the)
680675
MCperror->add(PE_FUNCTION_BADPARAMS, sp);
681676
return PS_ERROR;
682677
}
683-
#ifdef _MOBILE
684-
if (MCIsPlatformMessage(name))
678+
679+
if (MCIsGlobalHandler(name))
685680
{
686-
platform_message = true;
681+
global_handler = true;
687682
resolved = true;
688683
}
689-
#endif
690684

691685
return PS_NORMAL;
692686
}
@@ -845,7 +839,7 @@ Exec_stat MCFuncref::eval(MCExecPoint &ep)
845839

846840
void MCFuncref::eval_ctxt(MCExecContext& ctxt, MCExecValue& r_value)
847841
{
848-
MCKeywordsExecCommandOrFunction(ctxt, resolved, handler, params, name, line, pos, platform_message, true);
842+
MCKeywordsExecCommandOrFunction(ctxt, resolved, handler, params, name, line, pos, global_handler, true);
849843

850844
Exec_stat stat = ctxt . GetExecStat();
851845

engine/src/express.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class MCFuncref : public MCExpression
164164
MCObject *parent;
165165
MCParameter *params;
166166
bool resolved : 1;
167-
bool platform_message : 1;
167+
bool global_handler : 1;
168168
public:
169169
MCFuncref(MCNameRef);
170170
virtual ~MCFuncref();

engine/src/mblhandlers.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7099,7 +7099,7 @@ static void invoke_platform(void *p_context)
70997099

71007100
extern void MCIPhoneCallOnMainFiber(void (*)(void *), void *);
71017101

7102-
Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters)
7102+
bool MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters, Exec_stat& r_result)
71037103
{
71047104
for(uint32_t i = 0; s_platform_messages[i] . message != nil; i++)
71057105
if (MCNameIsEqualToCString(p_message, s_platform_messages[i] . message, kMCCompareCaseless))
@@ -7113,25 +7113,32 @@ Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters
71137113
ctxt . context = s_platform_messages[i] . context;
71147114
ctxt . parameters = p_parameters;
71157115
MCIPhoneCallOnMainFiber(invoke_platform, &ctxt);
7116-
return ctxt . result;
7116+
r_result = ctxt . result;
7117+
return true;
71177118
}
71187119

71197120
// Execute the method as normal, in this case the method will have to jump
71207121
// to the main fiber to do any system stuff.
7121-
return s_platform_messages[i] . handler(s_platform_messages[i] . context, p_parameters);
7122+
r_result = s_platform_messages[i] . handler(s_platform_messages[i] . context, p_parameters);
7123+
return true;
71227124
}
71237125

7124-
return ES_NOT_HANDLED;
7126+
r_result = ES_NOT_HANDLED;
7127+
return false;
71257128
}
71267129
#else // Android
7127-
Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters)
7130+
bool MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters, Exec_stat& r_result)
71287131
{
71297132
for(uint32_t i = 0; s_platform_messages[i] . message != nil; i++)
71307133
{
71317134
if (MCNameIsEqualToCString(p_message, s_platform_messages[i] . message, kMCCompareCaseless))
7132-
return s_platform_messages[i] . handler(s_platform_messages[i] . context, p_parameters);
7135+
{
7136+
r_result = s_platform_messages[i] . handler(s_platform_messages[i] . context, p_parameters);
7137+
return true;
7138+
}
71337139
}
71347140

7135-
return ES_NOT_HANDLED;
7141+
r_result = ES_NOT_HANDLED;
7142+
return false;
71367143
}
71377144
#endif

engine/src/statemnt.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,13 @@ void MCStatement::compile(MCSyntaxFactoryRef ctxt)
353353

354354
////////////////////////////////////////////////////////////////////////////////
355355

356-
#ifdef _MOBILE
357-
extern bool MCIsPlatformMessage(MCNameRef handler_name);
358-
extern Exec_stat MCHandlePlatformMessage(MCNameRef p_message, MCParameter *p_parameters);
359-
#endif
360-
361356
MCComref::MCComref(MCNameRef n)
362357
{
363358
/* UNCHECKED */ MCNameClone(n, name);
364359
handler = nil;
365360
params = NULL;
366361
resolved = false;
367-
platform_message = false;
362+
global_handler = false;
368363
}
369364

370365
MCComref::~MCComref()
@@ -386,13 +381,12 @@ Parse_stat MCComref::parse(MCScriptPoint &sp)
386381
MCperror->add(PE_STATEMENT_BADPARAMS, sp);
387382
return PS_ERROR;
388383
}
389-
#ifdef _MOBILE
390-
if (MCIsPlatformMessage(name))
384+
385+
if (MCIsGlobalHandler(name))
391386
{
392-
platform_message = true;
387+
global_handler = true;
393388
resolved = true;
394389
}
395-
#endif
396390

397391
return PS_NORMAL;
398392
}
@@ -536,7 +530,7 @@ Exec_stat MCComref::exec(MCExecPoint &ep)
536530

537531
void MCComref::exec_ctxt(MCExecContext& ctxt)
538532
{
539-
MCKeywordsExecCommandOrFunction(ctxt, resolved, handler, params, name, line, pos, platform_message, false);
533+
MCKeywordsExecCommandOrFunction(ctxt, resolved, handler, params, name, line, pos, global_handler, false);
540534
}
541535

542536
////////////////////////////////////////////////////////////////////////////////

engine/src/statemnt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class MCComref : public MCStatement
7878
MCHandler *handler;
7979
MCParameter *params;
8080
bool resolved : 1;
81-
bool platform_message : 1;
81+
bool global_handler : 1;
8282
public:
8383
MCComref(MCNameRef n);
8484
virtual ~MCComref();

engine/src/sysspec.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040

4141
#include "foundation.h"
4242

43+
#if defined(_IOS_MOBILE) || defined(_ANDROID_MOBILE)
44+
#include "mblcontrol.h"
45+
#endif
46+
4347
#include <signal.h>
4448
#ifdef _WIN32
4549
#include <float.h> // _isnan()
@@ -208,6 +212,25 @@ static void handle_signal(int p_signal)
208212
#endif
209213
#endif
210214

215+
#if defined(_IOS_MOBILE) || defined(_ANDROID_MOBILE)
216+
extern bool MCIsPlatformMessage(MCNameRef name);
217+
extern bool MCHandlePlatformMessage(MCNameRef name, MCParameter *parameters, Exec_stat& r_result);
218+
static MCHookGlobalHandlersDescriptor s_global_handlers_desc =
219+
{
220+
MCIsPlatformMessage,
221+
MCHandlePlatformMessage,
222+
};
223+
224+
static MCHookNativeControlsDescriptor s_native_control_desc =
225+
{
226+
(bool(*)(MCStringRef,intenum_t&))MCNativeControl::LookupType,
227+
(bool(*)(MCStringRef,intenum_t&))MCNativeControl::LookupProperty,
228+
(bool(*)(MCStringRef,intenum_t&))MCNativeControl::LookupAction,
229+
(bool(*)(intenum_t,void*&))MCNativeControl::CreateWithType,
230+
nil,
231+
};
232+
#endif
233+
211234
void MCS_common_init(void)
212235
{
213236
MCsystem -> Initialize();
@@ -226,7 +249,12 @@ void MCS_common_init(void)
226249
for(uint4 i = 0; i < 256; ++i)
227250
MClowercasingtable[i] = (uint1)tolower((uint1)i);
228251
#endif
229-
252+
253+
#if defined(_IOS_MOBILE) || defined(_ANDROID_MOBILE)
254+
MCHookRegister(kMCHookGlobalHandlers, &s_global_handlers_desc);
255+
MCHookRegister(kMCHookNativeControls, &s_native_control_desc);
256+
#endif
257+
230258
MCStackSecurityInit();
231259
}
232260

0 commit comments

Comments
 (0)