forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventqueue.cpp
More file actions
1419 lines (1167 loc) · 34.8 KB
/
eventqueue.cpp
File metadata and controls
1419 lines (1167 loc) · 34.8 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-2013 Runtime Revolution 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 "filedefs.h"
#include "objdefs.h"
#include "parsedef.h"
#include "globals.h"
#include "stack.h"
#include "card.h"
#include "field.h"
#include "mode.h"
#include "dispatch.h"
#include "eventqueue.h"
#include "debug.h"
#include "group.h"
#include "widget-events.h"
#include "resolution.h"
#include "graphics_util.h"
////////////////////////////////////////////////////////////////////////////////
extern Boolean tripleclick;
#ifdef _MOBILE
static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p_id, uint32_t p_taps, int32_t x, int32_t y);
#endif
////////////////////////////////////////////////////////////////////////////////
enum MCEventType
{
kMCEventTypeNotify,
kMCEventTypeQuitApp,
kMCEventTypeSuspendApp,
kMCEventTypeResumeApp,
kMCEventTypeUpdateMenu,
kMCEventTypeMenuPick,
kMCEventTypeWindowReshape,
kMCEventTypeMouseFocus,
kMCEventTypeMousePress,
kMCEventTypeMouseWheel,
kMCEventTypeMousePosition,
kMCEventTypeKeyFocus,
kMCEventTypeKeyPress,
kMCEventTypeImeCompose,
kMCEventTypeTouch,
kMCEventTypeMotion,
kMCEventTypeAcceleration,
kMCEventTypeOrientation,
kMCEventTypeLocation,
kMCEventTypeHeading,
kMCEventTypeCustom,
};
struct MCEvent
{
MCEvent *next;
MCEventType type;
union
{
struct
{
MCEventQueueNotifyCallback callback;
void *state;
} notify;
struct
{
MCStack *stack;
MCGFloat scale;
} window;
struct
{
MCObjectHandle *target;
union
{
struct
{
// SN-2014-06-23: pick updated to StringRef
MCStringRef string;
} pick;
};
} menu;
struct
{
uint32_t time;
MCStack *stack;
union
{
struct
{
bool inside;
} focus;
struct
{
uint32_t modifiers;
MCMousePressState state;
int32_t button;
} press;
struct
{
uint32_t modifiers;
int32_t dh, dv;
} wheel;
struct
{
uint32_t modifiers;
int32_t x, y;
} position;
};
} mouse;
struct
{
MCStack *stack;
union
{
struct
{
bool owner;
} focus;
struct
{
uint32_t modifiers;
uint32_t key_code;
uint32_t char_code;
} press;
};
} key;
struct
{
MCStack *stack;
union
{
struct
{
bool enabled;
uint32_t offset;
uint32_t char_count;
uint16_t *chars;
} compose;
};
} ime;
struct
{
MCStack *stack;
MCEventTouchPhase phase;
uint32_t id;
uint32_t taps;
int32_t x;
int32_t y;
} touch;
struct
{
MCStack *stack;
MCEventMotionType type;
} motion;
struct
{
double x, y, z, t;
} acceleration;
struct
{
const char *error;
} location;
struct
{
MCCustomEvent *event;
} custom;
};
};
typedef bool (*MCEventQueueFilterCallback)(void *context, MCEvent *event);
static MCEvent *s_first_event = nil;
static MCEvent *s_last_event = nil;
static uint32_t s_click_time = 0;
static uint32_t s_click_count = 0;
////////////////////////////////////////////////////////////////////////////////
bool MCEventQueueInitialize(void)
{
s_first_event = nil;
s_last_event = nil;
return true;
}
void MCEventQueueFinalize(void)
{
while(s_first_event != nil)
{
MCEvent *t_event;
t_event = s_first_event;
s_first_event = s_first_event -> next;
switch(t_event -> type)
{
case kMCEventTypeNotify:
t_event -> notify . callback(t_event -> notify . state, false);
break;
}
if (t_event -> type == kMCEventTypeImeCompose)
MCMemoryDeleteArray(t_event -> ime . compose . chars);
MCMemoryDelete(t_event);
}
s_first_event = nil;
s_last_event = nil;
}
////////////////////////////////////////////////////////////////////////////////
static void MCEventQueueDispatchEvent(MCEvent *p_event)
{
MCEvent *t_event;
t_event = p_event;
MCObject *t_menu;
t_menu = MCdispatcher -> getmenu();
switch(t_event -> type)
{
case kMCEventTypeNotify:
t_event -> notify . callback(t_event -> notify . state, true);
break;
case kMCEventTypeQuitApp:
{
switch(MCdefaultstackptr->getcard()->message(MCM_shut_down_request))
{
case ES_PASS:
case ES_NOT_HANDLED:
MCdefaultstackptr->getcard()->message(MCM_shut_down);
MCquit = True;
MCexitall = True;
MCtracestackptr = NULL;
MCtraceabort = True;
MCtracereturn = True;
break;
default:
break;
}
}
break;
case kMCEventTypeSuspendApp:
MCdefaultstackptr->getcard()->message(MCM_suspend);
break;
case kMCEventTypeResumeApp:
MCdefaultstackptr->getcard()->message(MCM_resume);
break;
case kMCEventTypeUpdateMenu:
{
MCObject *t_target;
t_target = t_event -> menu . target -> Get();
if (t_target != nil)
t_target->message_with_valueref_args(MCM_mouse_down, kMCEmptyString);
}
break;
case kMCEventTypeMenuPick:
{
MCObject *t_target;
t_target = t_event -> menu . target -> Get();
if (t_target != nil)
// SN-2014-06-23: pick updated to StringRef
t_target->message_with_valueref_args(MCM_menu_pick, t_event -> menu . pick . string);
}
break;
case kMCEventTypeWindowReshape:
// IM-2014-02-14: [[ HiDPI ]] update view backing scale
t_event -> window . stack -> view_setbackingscale(t_event->window.scale);
t_event -> window . stack -> view_configure(true);
break;
case kMCEventTypeMouseFocus:
if (t_event -> mouse . focus . inside)
{
if (MCmousestackptr != t_event -> mouse . stack)
{
MCmousestackptr = t_event -> mouse . stack;
MCmousestackptr -> enter();
}
if (t_menu == nil)
MCmousestackptr -> mfocus(MCmousex, MCmousey);
else
t_menu -> mfocus(MCmousex, MCmousey);
}
else if (MCmousestackptr == t_event -> mouse . stack)
{
MCmousestackptr -> munfocus();
MCmousestackptr = nil;
}
break;
case kMCEventTypeMousePress:
if (MCmousestackptr == t_event -> mouse . stack || t_menu != nil)
{
if (t_event -> mouse . press . state == kMCMousePressStateDown)
MCbuttonstate |= (1 << t_event -> mouse . press . button);
else
MCbuttonstate &= ~(1 << t_event -> mouse . press . button);
if (t_event -> mouse . press . state == kMCMousePressStateDown)
{
if (t_event -> mouse . time - s_click_time < MCdoubletime &&
MCU_abs(MCclicklocx - MCmousex) < MCdoubledelta &&
MCU_abs(MCclicklocy - MCmousey) < MCdoubledelta)
s_click_count += 1;
else
s_click_count = 0;
}
else
s_click_time = t_event -> mouse . time;
MCeventtime = t_event -> mouse . time;
MCmodifierstate = t_event -> mouse . press . modifiers;
MCclicklocx = MCmousex;
MCclicklocy = MCmousey;
MCclickstackptr = MCmousestackptr;
MCObject *t_target;
t_target = t_menu != nil ? t_menu : MCclickstackptr;
if (t_event -> mouse . press . state == kMCMousePressStateDown)
{
tripleclick = s_click_count == 2;
if (s_click_count != 1)
t_target -> mdown(t_event -> mouse . press . button + 1);
else
t_target -> doubledown(t_event -> mouse . press . button + 1);
}
else if (t_event -> mouse . press . state == kMCMousePressStateUp)
{
if (s_click_count != 1)
t_target -> mup(t_event -> mouse . press . button + 1, false);
else
t_target -> doubleup(t_event -> mouse . press . button + 1);
}
else
{
s_click_count = 0;
tripleclick = False;
// If the press was 'released' i.e. cancelled then we stop messages, mup then
// dispatch a mouseRelease message ourselves.
// FG-2013-10-09 [[ Bugfix 11208 ]]
// CS_NO_MESSAGES only applies to the target and not the controls it contains
// so the mouse up message (on mouseUp) sets sent when it isn't desired
// Hopefully nobody depends on the old behaviour...
//t_target -> setstate(True, CS_NO_MESSAGES);
//t_target -> mup(t_event -> mouse . press . button + 1);
//t_target -> setstate(False, CS_NO_MESSAGES);
bool old_lock = MClockmessages;
MClockmessages = true;
t_target -> mup(t_event -> mouse . press . button + 1, false);
MClockmessages = old_lock;
t_target -> message_with_args(MCM_mouse_release, t_event -> mouse . press . button + 1);
}
}
break;
case kMCEventTypeMouseWheel:
// Notice that we recompute mfocused twice - this is because calling the key handler
// could invalidate mfocused in between.
if (MCmousestackptr == t_event -> mouse . stack)
{
MCObject *mfocused;
mfocused = MCmousestackptr->getcard()->getmfocused();
if (mfocused == NULL)
mfocused = MCmousestackptr -> getcard();
if (mfocused == NULL)
mfocused = MCmousestackptr;
MCeventtime = t_event -> mouse . time;
MCmodifierstate = t_event -> mouse . wheel . modifiers;
if (t_event -> mouse . wheel . dv != 0)
mfocused -> kdown(kMCEmptyString, t_event -> mouse . wheel . dv < 0 ? XK_WheelUp : XK_WheelDown);
mfocused = MCmousestackptr->getcard()->getmfocused();
if (mfocused == NULL)
mfocused = MCmousestackptr -> getcard();
if (mfocused == NULL)
mfocused = MCmousestackptr;
if (t_event -> mouse . wheel . dh != 0)
mfocused -> kdown(kMCEmptyString, t_event -> mouse . wheel . dh < 0 ? XK_WheelLeft : XK_WheelRight);
}
break;
case kMCEventTypeMousePosition:
if (MCmousestackptr == t_event -> mouse . stack || t_menu != nil)
{
MCeventtime = t_event -> mouse . time;
MCmodifierstate = t_event -> mouse . position . modifiers;
MCObject *t_target;
t_target = t_menu != nil ? t_menu : MCmousestackptr;
// IM-2013-09-30: [[ FullscreenMode ]] Translate mouse location to stack coords
MCPoint t_mouseloc;
t_mouseloc = MCPointMake(t_event->mouse.position.x, t_event->mouse.position.y);
// IM-2013-10-03: [[ FullscreenMode ]] Transform mouseloc based on the mousestack
t_mouseloc = MCmousestackptr->windowtostackloc(t_mouseloc);
MCmousex = t_mouseloc.x;
MCmousey = t_mouseloc.y;
t_target -> mfocus(t_mouseloc . x, t_mouseloc . y);
}
break;
case kMCEventTypeKeyFocus:
if (t_event -> key . focus . owner)
t_event -> key . stack -> kfocus();
else
t_event -> key . stack -> kunfocus();
break;
case kMCEventTypeKeyPress:
{
MCObject *t_target;
t_target = t_menu != nil ? t_menu : t_event -> key . stack;
MCmodifierstate = t_event -> key . press . modifiers;
// If 'char_code' is 0, then this key press has not generated a
// character.
if (t_event -> key . press . char_code == 0)
{
t_target -> kdown(kMCEmptyString, t_event -> key . press . key_code);
t_target -> kup(kMCEmptyString, t_event -> key . press . key_code);
break;
}
// Otherwise 'char_code' is the unicode codepoint, so first map to
// UTF-16 (not done properly yet...)
unichar_t t_unichar;
t_unichar = (unichar_t)t_event -> key . press . char_code;
// Now the string is created with the appropriate unicode-capable function
MCAutoStringRef t_buffer;
MCStringCreateWithChars(&t_unichar, 1, &t_buffer);
t_target -> kdown(*t_buffer, t_event -> key . press . key_code);
t_target -> kup(*t_buffer, t_event -> key . press . key_code);
}
break;
case kMCEventTypeImeCompose:
{
if (!MCactivefield)
break;
if (t_event -> ime . compose . enabled)
MCactivefield -> startcomposition();
else
MCactivefield -> stopcomposition(True, False);
MCactivefield -> setcompositioncursoroffset(t_event -> ime . compose . offset * 2);
MCAutoStringRef t_unichars;
MCStringCreateWithChars((const unichar_t *)t_event->ime.compose.chars, t_event->ime.compose.char_count, &t_unichars);
// MW-2012-02-13: [[ Block Unicode ]] Use the new 'finsert' method in
// unicode mode.
MCactivefield -> finsertnew(FT_IMEINSERT, *t_unichars, LCH_UNICODE);
if (t_event -> ime . compose . enabled)
{
MCRectangle r;
MCactivefield -> getcompositionrect(r, -1);
MCModeConfigureIme(MCactivefield -> getstack(), true, r . x, r . y + r . height);
}
}
break;
case kMCEventTypeCustom:
t_event -> custom . event -> Dispatch();
break;
#ifdef _MOBILE
case kMCEventTypeTouch:
handle_touch(t_event -> touch . stack, t_event -> touch . phase, t_event -> touch . id, t_event -> touch . taps, t_event -> touch . x, t_event -> touch . y);
break;
case kMCEventTypeMotion:
{
MCNameRef t_message;
MCStringRef t_motion;
switch(t_event -> motion . type)
{
case kMCEventMotionShakeBegan:
t_motion = MCSTR("shake");
t_message = MCM_motion_start;
break;
case kMCEventMotionShakeEnded:
t_motion = MCSTR("shake");
t_message = MCM_motion_end;
break;
case kMCEventMotionShakeCancelled:
t_motion = MCSTR("shake");
t_message = MCM_motion_release;
break;
}
MCdefaultstackptr -> getcurcard() -> message_with_valueref_args(t_message, t_motion);
}
break;
case kMCEventTypeAcceleration:
{
MCAutoStringRef t_value;
/* UNCHECKED */ MCStringFormat(&t_value, "%.6f,%.6f,%.6f,%f", t_event -> acceleration . x, t_event -> acceleration . y, t_event -> acceleration . z, t_event -> acceleration . t);
MCdefaultstackptr -> getcurcard() -> message_with_valueref_args(MCM_acceleration_changed, *t_value);
}
break;
case kMCEventTypeOrientation:
MCdefaultstackptr -> getcurcard() -> message(MCM_orientation_changed);
break;
case kMCEventTypeLocation:
MCdefaultstackptr -> getcurcard() -> message(t_event -> location . error == nil ? MCM_location_changed : MCM_location_error);
break;
case kMCEventTypeHeading:
MCdefaultstackptr -> getcurcard() -> message(t_event -> location . error == nil ? MCM_heading_changed : MCM_heading_error);
break;
#endif
}
}
static void MCEventQueueRemoveEvent(MCEvent *p_event)
{
if (s_first_event == p_event)
{
s_first_event = p_event -> next;
if (s_first_event == nil)
s_last_event = nil;
}
else
{
MCEvent *t_previous;
for(t_previous = s_first_event; t_previous -> next != p_event; t_previous = t_previous -> next)
;
t_previous -> next = p_event -> next;
if (s_last_event == p_event)
s_last_event = t_previous;
}
}
static void MCEventQueueDestroyEvent(MCEvent *p_event)
{
if (p_event -> type == kMCEventTypeImeCompose)
MCMemoryDeleteArray(p_event -> ime . compose . chars);
else if (p_event -> type == kMCEventTypeUpdateMenu)
{
p_event -> menu . target -> Release();
}
else if (p_event -> type == kMCEventTypeMenuPick)
{
p_event -> menu . target -> Release();
// SN-2014-06-23: pick updated to StringRef
MCValueRelease(p_event -> menu . pick . string);
}
#ifdef _MOBILE
else if (p_event -> type == kMCEventTypeCustom)
p_event -> custom . event -> Destroy();
#endif
MCMemoryDelete(p_event);
}
static MCStack *MCEventQueueGetEventStack(MCEvent *p_event)
{
switch(p_event -> type)
{
case kMCEventTypeWindowReshape:
return p_event -> window . stack;
case kMCEventTypeMouseFocus:
case kMCEventTypeMousePress:
case kMCEventTypeMouseWheel:
case kMCEventTypeMousePosition:
return p_event -> mouse . stack;
case kMCEventTypeKeyFocus:
case kMCEventTypeKeyPress:
return p_event -> key . stack;
case kMCEventTypeImeCompose:
return p_event -> ime . stack;
default:
break;
}
return nil;
}
bool MCEventQueueDispatch(void)
{
if (s_first_event == nil)
return false;
MCEvent *t_event;
t_event = s_first_event;
if (t_event -> next == nil)
s_first_event = s_last_event = nil;
else
s_first_event = s_first_event -> next;
MCEventQueueDispatchEvent(t_event);
MCEventQueueDestroyEvent(t_event);
return true;
}
void MCEventQueueFlush(MCStack *p_stack)
{
bool t_changed;
do
{
t_changed = false;
for(MCEvent *t_event = s_first_event; t_event != nil; t_event = t_event -> next)
if (MCEventQueueGetEventStack(t_event) == p_stack)
{
MCEventQueueRemoveEvent(t_event);
MCEventQueueDestroyEvent(t_event);
t_changed = true;
break;
}
}
while(t_changed);
}
void MCEventQueueFilter(MCEventQueueFilterCallback p_callback, void *p_context)
{
MCEvent *t_new_first_event, *t_new_last_event;
t_new_first_event = nil;
t_new_last_event = nil;
MCEvent *t_event;
t_event = s_first_event;
while(t_event != nil)
{
MCEvent *t_next_event;
t_next_event = t_event -> next;
if (p_callback(p_context, t_event))
{
if (t_new_last_event == nil)
t_new_first_event = t_event;
else
t_new_last_event -> next = t_event;
t_new_last_event = t_event;
}
else
MCEventQueueDestroyEvent(t_event);
t_event = t_next_event;
}
s_first_event = t_new_first_event;
s_last_event = t_new_last_event;
if (s_last_event != nil)
s_last_event -> next = nil;
}
// Search through the eventqueue for a mouse click (mousedown followed by mouseup)
// and remove it from the queue. This will also remove all but the last mousemove.
bool MCEventQueueGetMouseClick(uint32_t p_button)
{
// Look for the first mouse down event in the queue
MCEvent *t_mouse_down, *t_mouse_move;
t_mouse_down = nil;
t_mouse_move = nil;
for(MCEvent *t_event = s_first_event; t_event != nil; t_event = t_event -> next)
{
if (t_event -> type == kMCEventTypeMousePosition)
t_mouse_move = t_event;
if (t_event -> type == kMCEventTypeMousePress &&
t_event -> mouse . press . state == kMCMousePressStateDown &&
(p_button == 0 || (uint32_t) t_event -> mouse . press . button == p_button))
{
t_mouse_down = t_event;
break;
}
}
if (t_mouse_down == nil)
return false;
// Look for a subsequent mouse up event in the queue
MCEvent *t_mouse_up;
t_mouse_up = nil;
for(MCEvent *t_event = t_mouse_down -> next; t_event != nil; t_event = t_event -> next)
if (t_event -> type == kMCEventTypeMousePress &&
t_event -> mouse . press . state == kMCMousePressStateUp &&
(p_button == 0 || (uint32_t) t_event -> mouse . press . button == p_button))
{
t_mouse_up = t_event;
break;
}
if (t_mouse_up == nil)
return false;
MCmodifierstate = t_mouse_up -> mouse . press . modifiers;
MCclickstackptr = MCmousestackptr;
// If there is a mouse-move event then update the clickloc with that position
// otherwise use MCmousex/y.
if (t_mouse_move != nil)
{
// Take into account fullscreenmode.
MCPoint t_mouseloc;
t_mouseloc = MCPointMake(t_mouse_move->mouse.position.x, t_mouse_move->mouse.position.y);
t_mouseloc = MCmousestackptr->windowtostackloc(t_mouseloc);
MCclicklocx = t_mouseloc . x;
MCclicklocy = t_mouseloc . y;
}
else
{
MCclicklocx = MCmousex;
MCclicklocy = MCmousey;
}
// Now remove *all* mouse events from the queue up to and including the
// mouse up.
MCEvent *t_event;
t_event = s_first_event;
for(;;)
{
MCEvent *t_next;
t_next = t_event -> next;
if (t_event -> type == kMCEventTypeMouseFocus ||
t_event -> type == kMCEventTypeMousePosition ||
t_event -> type == kMCEventTypeMousePress ||
t_event -> type == kMCEventTypeMouseWheel)
{
MCEventQueueRemoveEvent(t_event);
MCEventQueueDestroyEvent(t_event);
}
if (t_event == t_mouse_up)
break;
t_event = t_next;
}
return true;
}
static bool MCEventQueueEventIsMouse(MCEvent *p_event)
{
return p_event -> type == kMCEventTypeMouseFocus ||
p_event -> type == kMCEventTypeMousePosition ||
p_event -> type == kMCEventTypeMousePress ||
p_event -> type == kMCEventTypeMouseWheel;
}
////////////////////////////////////////////////////////////////////////////////
static bool MCEventQueuePost(MCEventType p_type, MCEvent*& r_event)
{
MCEvent *t_event;
if (!MCMemoryNew(t_event))
return false;
if (s_last_event == nil)
s_first_event = s_last_event = t_event;
else
{
s_last_event -> next = t_event;
s_last_event = t_event;
}
t_event -> type = p_type;
// MW-2011-08-16: [[ Wait ]] Ping any running wait loop to make sure it
// picks up the new event if it wants to.
MCscreen -> pingwait();
r_event = t_event;
return true;
}
static bool MCEventQueuePostAtFront(MCEventType p_type, MCEvent*& r_event)
{
MCEvent *t_event;
if (!MCMemoryNew(t_event))
return false;
if (s_first_event == nil)
s_first_event = s_last_event = t_event;
else
{
t_event -> next = s_first_event;
s_first_event = t_event;
}
t_event -> type = p_type;
// MW-2011-08-16: [[ Wait ]] Ping any running wait loop to make sure it
// picks up the new event if it wants to.
MCscreen -> pingwait();
r_event = t_event;
return true;
}
//////////
bool MCEventQueuePostNotify(MCEventQueueNotifyCallback p_callback, void *p_state)
{
MCEvent *t_event;
if (!MCEventQueuePost(kMCEventTypeNotify, t_event))
return false;
t_event -> notify . callback = p_callback;
t_event -> notify . state = p_state;
return true;
}
//////////
// IM-2014-02-14: [[ HiDPI ]] Post backing scale changes with window reshape message
bool MCEventQueuePostWindowReshape(MCStack *p_stack, MCGFloat p_backing_scale)
{
// We look through the current event queue, looking for the last window
// reshape event for this stack and coalesce the event.
MCEvent *t_event;
t_event = nil;
for(MCEvent *t_new_event = s_first_event; t_new_event != nil; t_new_event = t_new_event -> next)
if (t_new_event -> type == kMCEventTypeWindowReshape &&
t_new_event -> window . stack == p_stack)
t_event = t_new_event;
// If we found an event, remove it since we are about to replace it
// with a more recent mouse position event.
if (t_event != nil)
{
MCEventQueueRemoveEvent(t_event);
MCEventQueueDestroyEvent(t_event);
}
if (!MCEventQueuePost(kMCEventTypeWindowReshape, t_event))
return false;
t_event -> window . stack = p_stack;
t_event -> window . scale = p_backing_scale;
return true;
}
//////////
static bool MCEventQueuePostMouse(MCEventType p_type, MCStack *p_stack, uint32_t p_time, MCEvent*& r_event)
{
if (!MCEventQueuePost(p_type, r_event))
return false;
r_event -> mouse . stack = p_stack;
r_event -> mouse . time = p_time;
return true;
}
bool MCEventQueuePostMouseFocus(MCStack *p_stack, uint32_t p_time, bool p_inside)
{
MCEvent *t_event;
if (!MCEventQueuePostMouse(kMCEventTypeMouseFocus, p_stack, p_time, t_event))
return false;
t_event -> mouse . focus . inside = p_inside;
//MCLog("MouseFocus(%p, %d, %d)", p_stack, p_time, p_inside);
return true;
}
bool MCEventQueuePostMousePress(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, MCMousePressState p_state, int32_t p_button)
{
MCEvent *t_event;
if (!MCEventQueuePostMouse(kMCEventTypeMousePress, p_stack, p_time, t_event))
return false;
t_event -> mouse . press . modifiers = p_modifiers;
t_event -> mouse . press . state = p_state;
t_event -> mouse . press . button = p_button;
//MCLog("MousePress(%p, %d, %d, %d, %d)", p_stack, p_time, p_modifiers, p_state, p_button);
return true;
}
bool MCEventQueuePostMouseWheel(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, int32_t p_dh, int32_t p_dv)
{
MCEvent *t_event;
if (!MCEventQueuePostMouse(kMCEventTypeMouseWheel, p_stack, p_time, t_event))
return false;
t_event -> mouse . wheel . modifiers = p_modifiers;
t_event -> mouse . wheel . dh = p_dh;
t_event -> mouse . wheel . dv = p_dv;
return true;
}
bool MCEventQueuePostMousePosition(MCStack *p_stack, uint32_t p_time, uint32_t p_modifiers, int32_t p_x, int32_t p_y)
{
// We look through the current event queue, looking for the last mouse
// position event for this stack. If we encounter a press, wheel or focus
// event, we reset our search.
MCEvent *t_event;
t_event = nil;
for(MCEvent *t_new_event = s_first_event; t_new_event != nil; t_new_event = t_new_event -> next)
if (MCEventQueueEventIsMouse(t_new_event) &&
t_new_event -> mouse . stack == p_stack)
{
if (t_new_event -> type == kMCEventTypeMousePosition)
t_event = t_new_event;
else
t_event = nil;
}
// If we found an event, remove it since we are about to replace it
// with a more recent mouse position event.
if (t_event != nil)
{
MCEventQueueRemoveEvent(t_event);
MCEventQueueDestroyEvent(t_event);
}
if (!MCEventQueuePostMouse(kMCEventTypeMousePosition, p_stack, p_time, t_event))
return false;
t_event -> mouse . position . modifiers = p_modifiers;
t_event -> mouse . position . x = p_x;
t_event -> mouse . position . y = p_y;
//MCLog("MousePosition(%p, %d, %d, %d, %d)", p_stack, p_time, p_modifiers, p_x, p_y);
return true;