Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 2a60ced

Browse files
committed
[[ BrowserWidget ]] Add LCS syntax extensions:
launch url <url> in <widget> - calls OnLaunchUrl(<url>) handler of widget go ( back | forward ) in <widget> - calls OnGoBack, OnGoForward handler of widget do <script> in <widget> - calls OnDo(<script>) handler of widget
1 parent 71219a3 commit 2a60ced

File tree

10 files changed

+232
-5
lines changed

10 files changed

+232
-5
lines changed

engine/engine-sources.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@
343343
'src/exec-interface-scrollbar.cpp',
344344
'src/exec-interface-stack.cpp',
345345
'src/exec-interface-vclip.cpp',
346+
'src/exec-interface-widget.cpp',
346347
'src/exec-keywords.cpp',
347348
'src/exec-legacy.cpp',
348349
'src/exec-logic.cpp',

engine/src/cmds.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ MCDo::~MCDo()
371371
{
372372
delete source;
373373
delete alternatelang;
374+
delete widget;
374375
}
375376

376377
Parse_stat MCDo::parse(MCScriptPoint &sp)
@@ -390,8 +391,12 @@ Parse_stat MCDo::parse(MCScriptPoint &sp)
390391
caller = true;
391392
else
392393
{
393-
MCperror->add(PE_DO_BADENV, sp);
394-
return PS_ERROR;
394+
widget = new MCChunk(False);
395+
if (widget->parse(sp, False) != PS_NORMAL)
396+
{
397+
MCperror->add(PE_DO_BADENV, sp);
398+
return PS_ERROR;
399+
}
395400
}
396401

397402
return PS_NORMAL;
@@ -498,6 +503,20 @@ void MCDo::exec_ctxt(MCExecContext& ctxt)
498503
if (!ctxt . EvalExprAsStringRef(source, EE_DO_BADEXP, &t_script))
499504
return;
500505

506+
if (widget)
507+
{
508+
MCObject *t_object;
509+
uint32_t t_parid;
510+
if (!widget->getobj(ctxt, t_object, t_parid, True))
511+
{
512+
ctxt.LegacyThrow(EE_DO_BADWIDGETEXP);
513+
return;
514+
}
515+
516+
MCInterfaceExecDoInWidget(ctxt, *t_script, (MCWidget*)t_object);
517+
return;
518+
}
519+
501520
if (browser)
502521
{
503522
MCLegacyExecDoInBrowser(ctxt, *t_script);
@@ -536,7 +555,12 @@ void MCDo::compile(MCSyntaxFactoryRef ctxt)
536555

537556
source -> compile(ctxt);
538557

539-
if (browser)
558+
if (widget != nil)
559+
{
560+
widget->compile(ctxt);
561+
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecDoInWidgetMethodInfo);
562+
}
563+
else if (browser)
540564
MCSyntaxFactoryExecMethod(ctxt, kMCLegacyExecDoInBrowserMethodInfo);
541565
else if (alternatelang != nil)
542566
{

engine/src/cmds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class MCDo : public MCStatement
9090
{
9191
MCExpression *source;
9292
MCExpression *alternatelang;
93+
MCChunk *widget;
9394
protected:
9495
bool browser : 1;
9596
Boolean debug : 1;
@@ -102,6 +103,7 @@ class MCDo : public MCStatement
102103
browser = false;
103104
debug = False;
104105
caller = false;
106+
widget = nil;
105107
}
106108
virtual ~MCDo();
107109
virtual Parse_stat parse(MCScriptPoint &);
@@ -688,13 +690,15 @@ class MCLaunch : public MCStatement
688690
{
689691
MCExpression *doc;
690692
MCExpression *app;
693+
MCChunk *widget;
691694
bool as_url;
692695

693696
public:
694697
MCLaunch()
695698
{
696699
doc = app = NULL;
697700
as_url = false;
701+
widget = nil;
698702
}
699703
virtual ~MCLaunch();
700704
virtual Parse_stat parse(MCScriptPoint &);
@@ -1817,6 +1821,9 @@ class MCGo : public MCStatement
18171821
Boolean marked;
18181822
Boolean visible;
18191823
Boolean thisstack;
1824+
1825+
MCChunk *widget;
1826+
Chunk_term direction;
18201827
public:
18211828
MCGo()
18221829
{
@@ -1825,6 +1832,7 @@ class MCGo : public MCStatement
18251832
window = NULL;
18261833
marked = thisstack = False;
18271834
visible = True;
1835+
widget = nil;
18281836
}
18291837
virtual ~MCGo();
18301838
virtual Parse_stat parse(MCScriptPoint &);

engine/src/cmdsc.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,7 @@ MCLaunch::~MCLaunch()
21552155
{
21562156
delete doc;
21572157
delete app;
2158+
delete widget;
21582159
}
21592160

21602161
// Syntax should be:
@@ -2204,6 +2205,15 @@ Parse_stat MCLaunch::parse(MCScriptPoint &sp)
22042205
as_url = t_is_url;
22052206
}
22062207

2208+
if (t_is_url && sp.skip_token(SP_FACTOR, TT_IN) == PS_NORMAL)
2209+
{
2210+
widget = new MCChunk(False);
2211+
if (widget->parse(sp, False) != PS_NORMAL)
2212+
{
2213+
MCperror->add(PE_LAUNCH_BADWIDGETEXP, sp);
2214+
return PS_ERROR;
2215+
}
2216+
}
22072217
return PS_NORMAL;
22082218
}
22092219

@@ -2309,7 +2319,23 @@ void MCLaunch::exec_ctxt(MCExecContext& ctxt)
23092319
else if (doc != NULL)
23102320
{
23112321
if (as_url)
2312-
MCFilesExecLaunchUrl(ctxt, *t_document);
2322+
{
2323+
if (widget != nil)
2324+
{
2325+
MCObject *t_object;
2326+
uint32_t t_parid;
2327+
2328+
if (!widget->getobj(ctxt, t_object, t_parid, True) || t_object->gettype() != CT_WIDGET)
2329+
{
2330+
ctxt.LegacyThrow(EE_LAUNCH_BADWIDGETEXP);
2331+
return;
2332+
}
2333+
2334+
MCInterfaceExecLaunchUrlInWidget(ctxt, *t_document, (MCWidget*)t_object);
2335+
}
2336+
else
2337+
MCFilesExecLaunchUrl(ctxt, *t_document);
2338+
}
23132339
else
23142340
MCFilesExecLaunchDocument(ctxt, *t_document);
23152341
}
@@ -2331,7 +2357,15 @@ void MCLaunch::compile(MCSyntaxFactoryRef ctxt)
23312357
doc -> compile(ctxt);
23322358

23332359
if (as_url)
2334-
MCSyntaxFactoryExecMethod(ctxt, kMCFilesExecLaunchUrlMethodInfo);
2360+
{
2361+
if (widget)
2362+
{
2363+
widget->compile(ctxt);
2364+
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecLaunchUrlInWidgetMethodInfo);
2365+
}
2366+
else
2367+
MCSyntaxFactoryExecMethod(ctxt, kMCFilesExecLaunchUrlMethodInfo);
2368+
}
23352369
else
23362370
MCSyntaxFactoryExecMethod(ctxt, kMCFilesExecLaunchDocumentMethodInfo);
23372371
}

engine/src/cmdss.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ MCGo::~MCGo()
129129
delete background;
130130
delete card;
131131
delete window;
132+
delete widget;
132133
}
133134

134135
Parse_stat MCGo::parse(MCScriptPoint &sp)
@@ -292,6 +293,19 @@ Parse_stat MCGo::parse(MCScriptPoint &sp)
292293
case CT_BACKWARD:
293294
case CT_FORWARD:
294295
{
296+
if (sp.skip_token(SP_FACTOR, TT_IN) == PS_NORMAL)
297+
{
298+
widget = new MCChunk(False);
299+
if (widget->parse(sp, False) != PS_NORMAL)
300+
{
301+
MCperror->add(PE_GO_BADWIDGETEXP, sp);
302+
return PS_ERROR;
303+
}
304+
direction = nterm;
305+
306+
break;
307+
}
308+
295309
card = new MCCRef;
296310
card->etype = nterm;
297311
MCScriptPoint oldsp(sp);
@@ -988,6 +1002,26 @@ void MCGo::exec_ctxt(MCExecContext &ctxt)
9881002

9891003
ctxt . SetTheResultToEmpty();
9901004

1005+
// go ( forward | backward ) in widget ...
1006+
if (widget != nil)
1007+
{
1008+
MCObject *t_object;
1009+
uint32_t t_parid;
1010+
1011+
if (!widget->getobj(ctxt, t_object, t_parid, True) || t_object->gettype() != CT_WIDGET)
1012+
{
1013+
ctxt.LegacyThrow(EE_GO_BADWIDGETEXP);
1014+
return;
1015+
}
1016+
1017+
if (direction == CT_BACKWARD)
1018+
MCInterfaceExecGoBackInWidget(ctxt, (MCWidget*)t_object);
1019+
else
1020+
MCInterfaceExecGoForwardInWidget(ctxt, (MCWidget*)t_object);
1021+
1022+
return;
1023+
}
1024+
9911025
if (stack == NULL && background == NULL && card == NULL)
9921026
{
9931027
ctxt . LegacyThrow(EE_GO_NODEST);
@@ -1216,6 +1250,16 @@ void MCGo::exec_ctxt(MCExecContext &ctxt)
12161250

12171251
void MCGo::compile(MCSyntaxFactoryRef ctxt)
12181252
{
1253+
if (widget != nil)
1254+
{
1255+
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
1256+
widget->compile(ctxt);
1257+
MCSyntaxFactoryExecMethod(ctxt, direction == CT_BACKWARD ? kMCInterfaceExecGoBackInWidgetMethodInfo : kMCInterfaceExecGoForwardInWidgetMethodInfo);
1258+
MCSyntaxFactoryEndStatement(ctxt);
1259+
1260+
return;
1261+
}
1262+
12191263
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
12201264

12211265
bool t_is_home, t_is_relative;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Copyright (C) 2015 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include "prefix.h"
18+
19+
#include "widget.h"
20+
#include "widget-ref.h"
21+
22+
#include "exec.h"
23+
24+
#include "exec-interface.h"
25+
26+
MC_EXEC_DEFINE_EXEC_METHOD(Interface, GoBackInWidget, 1)
27+
MC_EXEC_DEFINE_EXEC_METHOD(Interface, GoForwardInWidget, 1)
28+
MC_EXEC_DEFINE_EXEC_METHOD(Interface, LaunchUrlInWidget, 2)
29+
MC_EXEC_DEFINE_EXEC_METHOD(Interface, DoInWidget, 2);
30+
31+
void MCInterfaceExecGoBackInWidget(MCExecContext& ctxt, MCWidget *p_widget)
32+
{
33+
MCWidgetPost(p_widget->getwidget(), MCNAME("OnGoBack"), kMCEmptyProperList);
34+
}
35+
36+
void MCInterfaceExecGoForwardInWidget(MCExecContext& ctxt, MCWidget *p_widget)
37+
{
38+
MCWidgetPost(p_widget->getwidget(), MCNAME("OnGoForward"), kMCEmptyProperList);
39+
}
40+
41+
void MCInterfaceExecLaunchUrlInWidget(MCExecContext& ctxt, MCStringRef p_url, MCWidget *p_widget)
42+
{
43+
MCAutoProperListRef t_list;
44+
45+
/* UNCHECKED */ MCProperListCreate((MCValueRef*)&p_url, 1, &t_list);
46+
MCWidgetPost(p_widget->getwidget(), MCNAME("OnLaunchUrl"), *t_list);
47+
}
48+
49+
void MCInterfaceExecDoInWidget(MCExecContext& ctxt, MCStringRef p_script, MCWidget *p_widget)
50+
{
51+
MCAutoProperListRef t_list;
52+
53+
/* UNCHECKED */ MCProperListCreate((MCValueRef*)&p_script, 1, &t_list);
54+
MCWidgetPost(p_widget->getwidget(), MCNAME("OnDo"), *t_list);
55+
}

engine/src/exec.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,10 @@ extern MCExecMethodInfo *kMCInterfaceGetUsePixelScalingMethodInfo;
28602860
extern MCExecMethodInfo *kMCInterfaceGetScreenPixelScaleMethodInfo;
28612861
extern MCExecMethodInfo *kMCInterfaceGetScreenPixelScalesMethodInfo;
28622862

2863+
extern MCExecMethodInfo *kMCInterfaceExecGoBackInWidgetMethodInfo;
2864+
extern MCExecMethodInfo *kMCInterfaceExecGoForwardInWidgetMethodInfo;
2865+
extern MCExecMethodInfo *kMCInterfaceExecLaunchUrlInWidgetMethodInfo;
2866+
extern MCExecMethodInfo *kMCInterfaceExecDoInWidgetMethodInfo;
28632867

28642868
void MCInterfaceInitialize(MCExecContext& ctxt);
28652869
void MCInterfaceFinalize(MCExecContext& ctxt);
@@ -3427,6 +3431,11 @@ void MCInterfaceGetUsePixelScaling(MCExecContext& ctxt, bool &r_setting);
34273431
void MCInterfaceGetScreenPixelScale(MCExecContext& ctxt, double& r_scale);
34283432
void MCInterfaceGetScreenPixelScales(MCExecContext& ctxt, uindex_t& r_count, double*& r_scale);
34293433

3434+
void MCInterfaceExecGoBackInWidget(MCExecContext& ctxt, MCWidget *p_widget);
3435+
void MCInterfaceExecGoForwardInWidget(MCExecContext& ctxt, MCWidget *p_widget);
3436+
void MCInterfaceExecLaunchUrlInWidget(MCExecContext& ctxt, MCStringRef p_url, MCWidget *p_widget);
3437+
void MCInterfaceExecDoInWidget(MCExecContext& ctxt, MCStringRef p_script, MCWidget *p_widget);
3438+
34303439
///////////
34313440

34323441
struct MCInterfaceLayer;

engine/src/executionerrors.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,15 @@ enum Exec_errors
26592659

26602660
// {EE-0869} System error: message
26612661
EE_SYSTEM_MESSAGE,
2662+
2663+
// {EE-0870} go: error in widget expression
2664+
EE_GO_BADWIDGETEXP,
2665+
2666+
// {EE-0871} launch: error in widget expression
2667+
EE_LAUNCH_BADWIDGETEXP,
2668+
2669+
// {EE-0872} do: error in widget expression
2670+
EE_DO_BADWIDGETEXP,
26622671
};
26632672

26642673
extern const char *MCexecutionerrors;

engine/src/parseerrors.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,12 @@ enum Parse_errors
17241724

17251725
// {PE-0560} load: missing 'from'
17261726
PE_LOAD_NOFROM,
1727+
1728+
// {PE-0561} go: error in widget expression
1729+
PE_GO_BADWIDGETEXP,
1730+
1731+
// {PE-0562} launch: error in widget expression
1732+
PE_LAUNCH_BADWIDGETEXP,
17271733
};
17281734

17291735
extern const char *MCparsingerrors;

0 commit comments

Comments
 (0)