forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdse.cpp
More file actions
3492 lines (3184 loc) · 83.2 KB
/
cmdse.cpp
File metadata and controls
3492 lines (3184 loc) · 83.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include "prefix.h"
#include "globdefs.h"
#include "objdefs.h"
#include "parsedef.h"
#include "filedefs.h"
#include "mcio.h"
#include "dispatch.h"
#include "object.h"
#include "stack.h"
#include "card.h"
#include "aclip.h"
#include "vclip.h"
#include "player.h"
#include "group.h"
#include "scriptpt.h"
//#include "execpt.h"
#include "handler.h"
#include "cmds.h"
#include "mcerror.h"
#include "chunk.h"
#include "param.h"
#include "util.h"
#include "date.h"
#include "debug.h"
#include "printer.h"
#include "variable.h"
#include "securemode.h"
#include "osspec.h"
#include "image.h"
#include "font.h"
#include "hndlrlst.h"
#include "globals.h"
#include "license.h"
#include "socket.h"
#include "exec.h"
#include "syntax.h"
MCAccept::~MCAccept()
{
delete port;
delete message;
}
Parse_stat MCAccept::parse(MCScriptPoint &sp)
{
initpoint(sp);
if (sp.skip_token(SP_ACCEPT, TT_UNDEFINED, AC_SECURE) == PS_NORMAL)
secure = True;
else if (sp.skip_token(SP_ACCEPT, TT_UNDEFINED, AC_DATAGRAM) == PS_NORMAL)
datagram = True;
sp.skip_token(SP_ACCEPT, TT_UNDEFINED, AC_UNDEFINED); // connections
sp.skip_token(SP_ACCEPT, TT_UNDEFINED, AC_UNDEFINED); // on
sp.skip_token(SP_ACCEPT, TT_UNDEFINED, AC_UNDEFINED); // port
if (sp.parseexp(False, True, &port) != PS_NORMAL)
{
MCperror->add(PE_ACCEPT_BADEXP, sp);
return PS_ERROR;
}
sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH); // with
sp.skip_token(SP_SUGAR, TT_CHUNK, CT_UNDEFINED); // message
if (sp.parseexp(False, True, &message) != PS_NORMAL)
{
MCperror->add(PE_ACCEPT_BADEXP, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL
&& sp.skip_token(SP_SSL, TT_STATEMENT, SSL_VERIFICATION) != PS_NORMAL)
{
//make error
MCperror->add(PE_OPEN_BADMESSAGE, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_SUGAR, TT_PREP, PT_WITHOUT) == PS_NORMAL
&& sp.skip_token(SP_SSL, TT_STATEMENT, SSL_VERIFICATION) == PS_NORMAL)
secureverify = False;
return PS_NORMAL;
}
void MCAccept::exec_ctxt(MCExecContext &ctxt)
{
#ifdef /* MCAccept */ LEGACY_EXEC
// MW-2005-01-28: Fix bug 2412 - accept doesn't clear the result.
MCresult -> clear(False);
if (MCsecuremode & MC_SECUREMODE_NETWORK)
{
MCeerror->add(EE_NETWORK_NOPERM, line, pos);
return ES_ERROR;
}
if (port->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
{
MCeerror->add(EE_ACCEPT_BADEXP, line, pos);
return ES_ERROR;
}
uint2 port = ep.getuint2();
if (message->eval(ep) != ES_NORMAL)
{
MCeerror->add(EE_ACCEPT_BADEXP, line, pos);
return ES_ERROR;
}
MCAutoNameRef t_message_name;
/* UNCHECKED */ ep . copyasnameref(t_message_name);
MCSocket *s = MCS_accept(port, ep.getobj(), t_message_name, datagram, secure, secureverify, NULL);
if (s != NULL)
{
MCU_realloc((char **)&MCsockets, MCnsockets,
MCnsockets + 1, sizeof(MCSocket *));
MCsockets[MCnsockets++] = s;
}
return ES_NORMAL;
#endif /* MCAccept */
uinteger_t t_port;
if (!ctxt . EvalExprAsUInt(port, EE_ACCEPT_BADEXP, t_port))
return;
MCNewAutoNameRef t_message;
if (!ctxt . EvalExprAsNameRef(message, EE_ACCEPT_BADEXP, &t_message))
return;
if (datagram)
MCNetworkExecAcceptDatagramConnectionsOnPort(ctxt, t_port, *t_message);
else if (secure)
MCNetworkExecAcceptSecureConnectionsOnPort(ctxt, t_port, *t_message, secureverify == True);
else
MCNetworkExecAcceptConnectionsOnPort(ctxt, t_port, *t_message);
}
void MCAccept::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
port -> compile(ctxt);
message -> compile(ctxt);
if (datagram)
MCSyntaxFactoryExecMethod(ctxt, kMCNetworkExecAcceptDatagramConnectionsOnPortMethodInfo);
else if (secure)
{
MCSyntaxFactoryEvalConstantBool(ctxt, secureverify == True);
MCSyntaxFactoryExecMethod(ctxt, kMCNetworkExecAcceptSecureConnectionsOnPortMethodInfo);
}
else
MCSyntaxFactoryExecMethod(ctxt, kMCNetworkExecAcceptConnectionsOnPortMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
MCBeep::~MCBeep()
{
delete times;
}
Parse_stat MCBeep::parse(MCScriptPoint &sp)
{
initpoint(sp);
MCScriptPoint oldsp(sp);
MCerrorlock++;
if (sp.parseexp(False, True, ×) != PS_NORMAL)
{
sp = oldsp;
delete times;
times = NULL;
}
MCerrorlock--;
return PS_NORMAL;
}
void MCBeep::exec_ctxt(MCExecContext& ctxt)
{
#ifdef /* MCBeep */ LEGACY_EXEC
uint4 i = 1;
if (times != NULL)
{
if (times->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
{
MCeerror->add(EE_BEEP_BADEXP, line, pos);
return ES_ERROR;
}
i = ep.getuint4();
}
while (i--)
{
MCscreen->beep();
// MW-2010-01-08: [[ Bug 1690 ]] We need a break on all beeps but the last
if (i >= 1)
{
// MW-2008-03-17: [[ Bug 6098 ]] Make sure we check for an abort from wait
if (MCscreen->wait(BEEP_INTERVAL, False, False))
{
MCeerror -> add(EE_WAIT_ABORT, line, pos);
return ES_ERROR;
}
}
}
return ES_NORMAL;
#endif /* MCBeep */
uinteger_t t_count;
if (!ctxt . EvalOptionalExprAsUInt(times, 1, EE_BEEP_BADEXP, t_count))
return;
MCInterfaceExecBeep(ctxt, t_count);
}
void MCBeep::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
if (times != nil)
times -> compile(ctxt);
else
MCSyntaxFactoryEvalConstantUInt(ctxt, 1);
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecBeepMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
void MCBreakPoint::exec_ctxt(MCExecContext& ctxt)
{
#ifdef /* MCBreakPoint */ LEGACY_EXEC
MCB_break(ep, getline(), getpos());
return ES_NORMAL;
#endif /* MCBreakPoint */
MCDebuggingExecBreakpoint(ctxt, line, pos);
}
void MCBreakPoint::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
MCSyntaxFactoryEvalConstantUInt(ctxt, line);
MCSyntaxFactoryEvalConstantUInt(ctxt, pos);
MCSyntaxFactoryExecMethod(ctxt, kMCDebuggingExecBreakpointMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
MCCancel::~MCCancel()
{
delete m_id;
}
Parse_stat MCCancel::parse(MCScriptPoint &sp)
{
initpoint(sp);
if (sp . skip_token(SP_RESET, TT_UNDEFINED, RT_PRINTING) == PS_NORMAL)
{
m_id = NULL;
}
else if (sp.parseexp(False, True, &m_id) != PS_NORMAL)
{
MCperror->add(PE_CANCEL_BADEXP, sp);
return PS_ERROR;
}
return PS_NORMAL;
}
void MCCancel::exec_ctxt(MCExecContext& ctxt)
{
#ifdef /* MCCancel */ LEGACY_EXEC
if (id == NULL)
{
MCprinter -> Cancel();
if (MCprinter != MCsystemprinter)
{
delete MCprinter;
MCprinter = MCsystemprinter;
}
return ES_NORMAL;
}
if (id->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
{
MCeerror->add(EE_CANCEL_IDNAN, line, pos);
return ES_ERROR;
}
if (ep.getuint4() != 0)
MCscreen->cancelmessageid(ep.getuint4());
return ES_NORMAL;
#endif /* MCCancel */
if (m_id == NULL)
MCPrintingExecCancelPrinting(ctxt);
else
{
integer_t t_id;
if (!ctxt . EvalExprAsInt(m_id, EE_CANCEL_IDNAN, t_id))
return;
MCEngineExecCancelMessage(ctxt, t_id);
}
}
void MCCancel::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
if (m_id == nil)
MCSyntaxFactoryExecMethod(ctxt, kMCPrintingExecCancelPrintingMethodInfo);
else
{
m_id -> compile(ctxt);
MCSyntaxFactoryExecMethod(ctxt, kMCEngineExecCancelMessageMethodInfo);
}
MCSyntaxFactoryEndStatement(ctxt);
}
MCClickCmd::~MCClickCmd()
{
delete button;
delete location;
}
Parse_stat MCClickCmd::parse(MCScriptPoint &sp)
{
initpoint(sp);
sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH);
if (sp.skip_token(SP_FACTOR, TT_CHUNK, CT_BUTTON) == PS_NORMAL)
{
if (sp.parseexp(False, True, &button) != PS_NORMAL)
{
MCperror->add(PE_CLICK_BADBUTTONEXP, sp);
return PS_ERROR;
}
}
if (sp.skip_token(SP_FACTOR, TT_PREP, PT_AT) != PS_NORMAL)
{
MCperror->add(PE_CLICK_NOAT, sp);
return PS_ERROR;
}
if (sp.parseexp(False, True, &location) != PS_NORMAL)
{
MCperror->add(PE_CLICK_BADLOCATIONEXP, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
return getmods(sp, mstate);
return PS_NORMAL;
}
void MCClickCmd::exec_ctxt(MCExecContext& ctxt)
{
#ifdef /* MCClickCmd */ LEGACY_EXEC
if (button != NULL)
{
if (button->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
{
MCeerror->add(EE_CLICK_BADBUTTON, line, pos);
return ES_ERROR;
}
which = ep.getuint2();
}
if (location->eval(ep) != ES_NORMAL)
{
MCeerror->add(EE_CLICK_BADLOCATION, line, pos);
return ES_ERROR;
}
MCPoint t_clickloc;
if (!MCU_stoi2x2(ep.getsvalue(), t_clickloc.x, t_clickloc.y))
{
MCeerror->add(EE_CLICK_NAP, line, pos, ep.getsvalue());
return ES_ERROR;
}
if (!MCdefaultstackptr->getopened()
|| !MCdefaultstackptr->haswindow())
{
MCeerror->add(EE_CLICK_STACKNOTOPEN, line, pos, ep.getsvalue());
return ES_ERROR;
}
// IM-2013-09-23: [[ FullscreenMode ]] get / set mouseloc & clickloc in view coords
MCPoint t_view_clickloc;
// IM-2014-01-06: [[ Bug 11624 ]] Use MCStack::stacktowindowloc to account for stack scroll
t_view_clickloc = MCdefaultstackptr->stacktowindowloc(t_clickloc);
uint2 oldmstate = MCmodifierstate;
uint2 oldbstate = MCbuttonstate;
MCStack *t_old_mousestack;
MCPoint t_old_mouseloc;
MCscreen->getmouseloc(t_old_mousestack, t_old_mouseloc);
MCscreen->setmouseloc(MCdefaultstackptr, t_view_clickloc);
MCmodifierstate = mstate;
MCbuttonstate |= 0x1L << (which - 1);
MCdispatcher->wmfocus_stack(MCdefaultstackptr, t_view_clickloc.x, t_view_clickloc.y);
MCmodifierstate = mstate;
MCbuttonstate |= 0x1L << (which - 1);
MCdispatcher->wmdown_stack(MCdefaultstackptr, which);
// **** NULL POINTER FIX
if (MCmousestackptr != NULL)
MCscreen->sync(MCmousestackptr->getw());
Boolean abort = MCscreen->wait(CLICK_INTERVAL, False, False);
MCscreen->setclickloc(MCdefaultstackptr, t_view_clickloc);
MCmodifierstate = mstate;
MCbuttonstate &= ~(0x1L << (which - 1));
MCdispatcher->wmup_stack(MCdefaultstackptr, which);
MCmodifierstate = oldmstate;
MCbuttonstate = oldbstate;
MCControl *mfocused = MCdefaultstackptr->getcard()->getmfocused();
if (mfocused != NULL
&& (mfocused->gettype() == CT_GRAPHIC
&& mfocused->getstate(CS_CREATE_POINTS)
|| (mfocused->gettype() == CT_IMAGE && mfocused->getstate(CS_DRAW)
&& MCdefaultstackptr->gettool(mfocused) == T_POLYGON)))
mfocused->doubleup(1); // cancel polygon create
if (t_old_mousestack == NULL || t_old_mousestack->getmode() != 0)
{
MCscreen->setmouseloc(t_old_mousestack, t_old_mouseloc);
if (t_old_mousestack != NULL)
MCdispatcher->wmfocus_stack(t_old_mousestack, t_old_mouseloc.x, t_old_mouseloc.y);
}
if (abort)
{
MCeerror->add(EE_CLICK_ABORT, line, pos);
return ES_ERROR;
}
return ES_NORMAL;
#endif /* MCClickCmd */
uinteger_t t_which;
if (!ctxt . EvalOptionalExprAsUInt(button, which, EE_CLICK_BADBUTTON, t_which))
return;
which = t_which;
MCPoint t_location;
if (!ctxt . EvalExprAsPoint(location, EE_CLICK_BADLOCATION, t_location))
return;
MCInterfaceExecClickCmd(ctxt, which, t_location, mstate);
}
void MCClickCmd::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
if (button != nil)
button -> compile(ctxt);
else
MCSyntaxFactoryEvalConstantUInt(ctxt, which);
location -> compile(ctxt);
MCSyntaxFactoryEvalConstantUInt(ctxt, mstate);
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecClickCmdMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
MCDrag::~MCDrag()
{
delete button;
delete startloc;
delete endloc;
}
Parse_stat MCDrag::parse(MCScriptPoint &sp)
{
initpoint(sp);
sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH);
if (sp.skip_token(SP_FACTOR, TT_CHUNK, CT_BUTTON) == PS_NORMAL)
{
if (sp.parseexp(False, True, &button) != PS_NORMAL)
{
MCperror->add(PE_DRAG_BADBUTTONEXP, sp);
return PS_ERROR;
}
}
if (sp.skip_token(SP_FACTOR, TT_FROM, PT_FROM) != PS_NORMAL)
{
MCperror->add(PE_DRAG_NOFROM, sp);
return PS_ERROR;
}
if (sp.parseexp(False, True, &startloc) != PS_NORMAL)
{
MCperror->add(PE_DRAG_BADSTARTLOCEXP, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_FACTOR, TT_TO, PT_TO) != PS_NORMAL)
{
MCperror->add(PE_DRAG_NOTO, sp);
return PS_ERROR;
}
if (sp.parseexp(False, True, &endloc) != PS_NORMAL)
{
MCperror->add(PE_DRAG_BADENDLOCEXP, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
return getmods(sp, mstate);
return PS_NORMAL;
}
void MCDrag::exec_ctxt(MCExecContext& ctxt)
{
#ifdef /* MCDrag */ LEGACY_EXEC
if (button != NULL)
{
if (button->eval(ep) != ES_NORMAL || ep.ton() != ES_NORMAL)
{
MCeerror->add(EE_DRAG_BADBUTTON, line, pos);
return ES_ERROR;
}
which = ep.getuint2();
}
if (startloc->eval(ep) != ES_NORMAL)
{
MCeerror->add(EE_DRAG_BADSTARTLOC, line, pos);
return ES_ERROR;
}
int2 sx, sy;
if (!MCU_stoi2x2(ep.getsvalue(), sx, sy))
{
MCeerror->add(EE_DRAG_STARTNAP, line, pos, ep.getsvalue());
return ES_ERROR;
}
if (endloc->eval(ep) != ES_NORMAL)
{
MCeerror->add(EE_DRAG_BADENDLOC, line, pos);
return ES_ERROR;
}
int2 ex, ey;
if (!MCU_stoi2x2(ep.getsvalue(), ex, ey))
{
MCeerror->add(EE_DRAG_ENDNAP, line, pos, ep.getsvalue());
return ES_ERROR;
}
uint2 oldmstate = MCmodifierstate;
uint2 oldbstate = MCbuttonstate;
int2 oldx = MCmousex;
int2 oldy = MCmousey;
MCmodifierstate = mstate;
MCbuttonstate = 0x1 << (which - 1);
MCmousex = sx;
MCmousey = sy;
//MCdragging = True;
MCscreen->setlockmods(True);
MCdefaultstackptr->mfocus(sx, sy);
MCdefaultstackptr->mdown(which);
if (MCdragspeed == 0)
{
MCmousex = ex;
MCmousey = ey;
MCdefaultstackptr->mfocus(ex, ey);
MCdefaultstackptr->mup(which, false);
MCscreen->setlockmods(False);
MCmodifierstate = oldmstate;
MCbuttonstate = oldbstate;
MCmousex = oldx;
MCmousey = oldy;
return ES_NORMAL;
}
MCscreen->sync(MCdefaultstackptr->getw());
real8 dx = MCU_abs(ex - sx);
real8 dy = MCU_abs(ey - sy);
real8 ix = 0.0;
if (dx != 0.0)
ix = dx / (ex - sx);
real8 iy = 0.0;
if (dy != 0.0)
iy = dy / (ey - sy);
real8 starttime = MCS_time();
real8 curtime = starttime;
real8 duration = 0.0;
if (MCdragspeed != 0)
duration = sqrt((double)(dx * dx + dy * dy)) / (real8)MCdragspeed;
real8 endtime = starttime + duration;
Boolean abort = False;
MCdragging = True;
int2 x = sx;
int2 y = sy;
while (x != ex || y != ey)
{
int2 oldx = x;
int2 oldy = y;
x = sx + (int2)(ix * (dx * (curtime - starttime) / duration));
y = sy + (int2)(iy * (dy * (curtime - starttime) / duration));
if (MCscreen->wait((real8)MCsyncrate / 1000.0, False, True))
{
abort = True;
break;
}
curtime = MCS_time();
if (curtime >= endtime)
{
x = ex;
y = ey;
curtime = endtime;
}
if (x != oldx || y != oldy)
MCdefaultstackptr->mfocus(x, y);
}
MCdefaultstackptr->mup(which, false);
MCmodifierstate = oldmstate;
MCbuttonstate = oldbstate;
MCmousex = oldx;
MCmousey = oldy;
MCscreen->setlockmods(False);
MCdragging = False;
if (abort)
{
MCeerror->add(EE_DRAG_ABORT, line, pos);
return ES_ERROR;
}
return ES_NORMAL;
#endif /* MCDrag */
uinteger_t t_which;
if (!ctxt . EvalOptionalExprAsUInt(button, which, EE_DRAG_BADBUTTON, t_which))
return;
which = t_which;
MCPoint t_start;
if (!ctxt . EvalExprAsPoint(startloc, EE_DRAG_BADSTARTLOC, t_start))
return;
MCPoint t_end;
if (!ctxt . EvalExprAsPoint(endloc, EE_DRAG_BADENDLOC, t_end))
return;
MCInterfaceExecDrag(ctxt, which, t_start, t_end, mstate);
}
void MCDrag::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
if (button != nil)
button -> compile(ctxt);
else
MCSyntaxFactoryEvalConstantUInt(ctxt, which);
startloc -> compile(ctxt);
endloc -> compile(ctxt);
MCSyntaxFactoryEvalConstantUInt(ctxt, mstate);
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecDragMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
MCFocus::~MCFocus()
{
delete object;
}
Parse_stat MCFocus::parse(MCScriptPoint &sp)
{
initpoint(sp);
sp.skip_token(SP_FACTOR, TT_OF, PT_ON);
// MW-2008-01-30: [[ Bug 5676 ]] Add "focus on nothing" to allow unfocusing
// all objects on a card.
if (sp.skip_token(SP_SUGAR, TT_UNDEFINED, SG_NOTHING) == PS_NORMAL)
object = NULL;
else
{
object = new MCChunk(False);
if (object->parse(sp, False) != PS_NORMAL)
{
MCperror->add(PE_FOCUS_BADOBJECT, sp);
return PS_ERROR;
}
}
return PS_NORMAL;
}
void MCFocus::exec_ctxt(MCExecContext &ctxt)
{
#ifdef /* MCFocus */ LEGACY_EXEC
MCObject *optr;
uint4 parid;
if (object == NULL)
{
if (MCfocusedstackptr != NULL && MCfocusedstackptr -> getcard() != NULL)
MCfocusedstackptr -> getcard() -> kunfocus();
#ifdef _MOBILE
// Make sure the IME is forced closed if explicitly asked to be.
MCscreen -> closeIME();
#endif
}
else
{
if (object->getobj(ep, optr, parid, True) != ES_NORMAL
|| optr->gettype() < CT_BUTTON || !optr->getflag(F_TRAVERSAL_ON))
{
MCeerror->add(EE_FOCUS_BADOBJECT, line, pos);
return ES_ERROR;
}
optr->getstack()->kfocusset((MCControl *)optr);
}
return ES_NORMAL;
#endif /* MCFocus */
if (object == NULL)
MCInterfaceExecFocusOnNothing(ctxt);
else
{
MCObject *optr;
uint4 parid;
if (!object->getobj(ctxt, optr, parid, True)
|| optr->gettype() < CT_FIRST_CONTROL
|| optr->gettype() > CT_LAST_CONTROL)
{
ctxt . LegacyThrow(EE_FOCUS_BADOBJECT);
return;
}
MCInterfaceExecFocusOn(ctxt, optr);
}
}
void MCFocus::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
if (object == nil)
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecFocusOnNothingMethodInfo);
else
{
object -> compile_object_ptr(ctxt);
MCSyntaxFactoryExecMethod(ctxt, kMCInterfaceExecFocusOnMethodInfo);
}
MCSyntaxFactoryEndStatement(ctxt);
}
MCInsert::~MCInsert()
{
delete target;
}
Parse_stat MCInsert::parse(MCScriptPoint &sp)
{
Symbol_type type;
const LT *te;
initpoint(sp);
sp.skip_token(SP_FACTOR, TT_THE);
if (sp.skip_token(SP_FACTOR, TT_PROPERTY, P_SCRIPT) != PS_NORMAL
|| sp.skip_token(SP_FACTOR, TT_OF) != PS_NORMAL)
{
MCperror->add(PE_INSERT_NOSCRIPT, sp);
return PS_ERROR;
}
target = new MCChunk(False);
if (target->parse(sp, False) != PS_NORMAL)
{
MCperror->add(PE_INSERT_BADOBJECT, sp);
return PS_ERROR;
}
if (sp.skip_token(SP_FACTOR, TT_PREP, PT_INTO) != PS_NORMAL)
{
MCperror->add(PE_INSERT_NOINTO, sp);
return PS_ERROR;
}
if (sp.next(type) != PS_NORMAL
|| sp.lookup(SP_INSERT, te) != PS_NORMAL)
{
MCperror->add(PE_INSERT_NOPLACE, sp);
return PS_ERROR;
}
where = (Insert_point)te->which;
return PS_NORMAL;
}
void MCInsert::exec_ctxt(MCExecContext &ctxt)
{
#ifdef /* MCInsert */ LEGACY_EXEC
MCObject *optr;
uint4 parid;
if (target->getobj(ep, optr, parid, True) != ES_NORMAL
|| !optr->parsescript(True))
{
MCeerror->add(EE_INSERT_BADTARGET, line, pos);
return ES_ERROR;
}
MCObjectList *&listptr = where == IP_FRONT ? MCfrontscripts : MCbackscripts;
optr->removefrom(listptr);
uint4 count = 0;
if (listptr != NULL)
{
MCObjectList *olptr = listptr;
do
{
if (!olptr->getremoved())
count++;
olptr = olptr->next();
}
while (olptr != listptr);
}
if (MClicenseparameters . insert_limit > 0 && count >= MClicenseparameters . insert_limit)
{
MCeerror->add(EE_INSERT_NOTLICENSED, line, pos);
return ES_ERROR;
}
MCObjectList *olptr = new MCObjectList(optr);
olptr->insertto(listptr);
return ES_NORMAL;
#endif /* MCInsert */
MCObject *optr;
uint4 parid;
if (!target->getobj(ctxt, optr, parid, True))
{
ctxt . LegacyThrow(EE_INSERT_BADTARGET);
return;
}
MCEngineExecInsertScriptOfObjectInto(ctxt, optr, where == IP_FRONT);
}
void MCInsert::compile(MCSyntaxFactoryRef ctxt)
{
MCSyntaxFactoryBeginStatement(ctxt, line, pos);
target -> compile_object_ptr(ctxt);
MCSyntaxFactoryEvalConstantBool(ctxt, where == IP_FRONT);
MCSyntaxFactoryExecMethod(ctxt, kMCEngineExecInsertScriptOfObjectIntoMethodInfo);
MCSyntaxFactoryEndStatement(ctxt);
}
// MW-2008-11-05: [[ Dispatch Command ]] Implementation for the dispatch command.
MCDispatchCmd::~MCDispatchCmd(void)
{
while(params != NULL)
{
MCParameter *t_param;
t_param = params;
params = params -> getnext();
delete t_param;
}
delete target;
delete message;
}
// Syntax is:
// dispatch [ command | function ] <message: Expression> [ with <parameters: ParamList> ]
// dispatch [ command | function ] <message: Expression> [ to <target: Chunk> ] [ with <parameters: ParamList> ]
Parse_stat MCDispatchCmd::parse(MCScriptPoint& sp)
{
initpoint(sp);
// MW-2009-09-11: Added support for command/function specification
if (sp . skip_token(SP_HANDLER, TT_HANDLER, HT_FUNCTION) == PS_NORMAL)
is_function = true;
else
sp . skip_token(SP_HANDLER, TT_HANDLER, HT_MESSAGE);
if (sp . parseexp(False, True, &message) != PS_NORMAL)
{
MCperror->add(PE_DISPATCH_BADMESSAGE, sp);
return PS_ERROR;
}
// MW-2008-12-04: Added 'to <target>' form to the syntax
if (sp.skip_token(SP_FACTOR, TT_TO) == PS_NORMAL)
{
target = new MCChunk(False);
if (target -> parse(sp, False) != PS_NORMAL)
{
MCperror->add(PE_DISPATCH_BADTARGET, sp);
return PS_ERROR;
}
}
if (sp . skip_token(SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
{
if (getparams(sp, ¶ms) != PS_NORMAL)
{
MCperror -> add(PE_DISPATCH_BADPARAMS, sp);
return PS_ERROR;
}
}
return PS_NORMAL;
}
// This method follows along the same lines as MCComref::exec
void MCDispatchCmd::exec_ctxt(MCExecContext &ctxt)
{
#ifdef /* MCDispatchCmd */ LEGACY_EXEC
if (MCscreen->abortkey())
{
MCeerror->add(EE_HANDLER_ABORT, line, pos);
return ES_ERROR;
}
if (message -> eval(ep) != ES_NORMAL)
{
MCeerror -> add(EE_DISPATCH_BADMESSAGEEXP, line, pos);
return ES_ERROR;
}
MCAutoNameRef t_message;
/* UNCHECKED */ ep . copyasnameref(t_message);
// Evaluate the target object (if we parsed a 'target' chunk).
MCObject *t_object;
uint4 t_object_part_id;
if (target == NULL)
t_object = ep.getobj();
else if (target->getobj(ep, t_object, t_object_part_id, True) != ES_NORMAL)
{
MCeerror->add(EE_DISPATCH_BADTARGET, line, pos);
return ES_ERROR;
}
// Evaluate the parameter list
Exec_stat stat;
MCParameter *tptr = params;
while (tptr != NULL)
{
// Get the pointer to the variable this parameter maps to or NULL
// if it is an expression.
MCVariable* t_var;
t_var = tptr -> evalvar(ep);
if (t_var == NULL)
{
tptr -> clear_argument();
while ((stat = tptr->eval(ep)) != ES_NORMAL && (MCtrace || MCnbreakpoints) && !MCtrylock && !MClockerrors)
if (!MCB_error(ep, line, pos, EE_STATEMENT_BADPARAM))
break;
if (stat != ES_NORMAL)
{
MCeerror->add(EE_STATEMENT_BADPARAM, line, pos);
return ES_ERROR;
}
tptr->set_argument(ep);
}
else
tptr->set_argument_var(t_var);
tptr = tptr->getnext();
}
// Fetch current default stack and target settings
MCStack *t_old_stack;
t_old_stack = MCdefaultstackptr;
MCObject *t_old_target;
t_old_target = MCtargetptr;
// Cache the current 'this stack' (used to see if we should switch back
// the default stack).
MCStack *t_this_stack;
t_this_stack = t_object -> getstack();
// Retarget this stack and the target to be relative to the target object
MCdefaultstackptr = t_this_stack;
MCtargetptr = t_object;
// MW-2012-10-30: [[ Bug 10478 ]] Turn off lockMessages before dispatch.
Boolean t_old_lock;
t_old_lock = MClockmessages;
MClockmessages = False;
// Add a new entry in the execution contexts