-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
inputhandler.c
2964 lines (2510 loc) · 110 KB
/
inputhandler.c
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 © 1995-2017, The AROS Development Team. All rights reserved.
Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
$Id$
*/
/****************************************************************************************/
#include <aros/config.h>
#include <proto/exec.h>
#include <proto/execlock.h>
#include <proto/intuition.h>
#include <proto/alib.h>
#include <proto/layers.h>
#include <proto/graphics.h>
#include <proto/keymap.h>
#include <proto/utility.h>
#include <proto/input.h>
#include <proto/timer.h>
#include <exec/memory.h>
#include <exec/alerts.h>
#include <exec/interrupts.h>
#include <exec/ports.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <intuition/gadgetclass.h>
#include <intuition/pointerclass.h>
#include <intuition/cghooks.h>
#include <intuition/sghooks.h>
#include <devices/inputevent.h>
#include <devices/rawkeycodes.h>
#include <clib/macros.h>
#include "inputhandler.h"
#include "boopsigadgets.h"
#include "boolgadgets.h"
#include "propgadgets.h"
#include "strgadgets.h"
#include "gadgets.h"
#include "intuition_intern.h" /* EWFLG_xxx */
#include "inputhandler_support.h"
#include "inputhandler_actions.h"
#include "menus.h"
#include "monitorclass_private.h"
#ifdef SKINS
# include "smallmenu.h"
# include "intuition_customizesupport.h"
#endif
#undef DEBUG
#define DEBUG 0
#include <aros/debug.h>
#define DEBUG_HANDLER(x) ;
#define DEBUG_KEY(x) ;
#define DEBUG_SCREENKEY(x) ;
#define DEBUG_AUTOSCROLL(x)
#define DEBUG_CLICK(x)
#define DEBUG_DRAG(x)
#define DEBUG_GADGET(x)
#define DEBUG_MONITOR(x)
#define DEBUG_MOUSE(x)
#define DEBUG_WINDOW(x)
/****************************************************************************************/
struct Interrupt *InitIIH(struct IntuitionBase *IntuitionBase)
{
struct Interrupt *iihandler;
D(bug("[Intuition] %s(IntuitionBase=%p)\n", __func__, IntuitionBase));
iihandler = AllocMem(sizeof (struct Interrupt), MEMF_PUBLIC | MEMF_CLEAR);
if (iihandler)
{
struct IIHData *iihdata;
iihdata = AllocMem(sizeof (struct IIHData), MEMF_PUBLIC | MEMF_CLEAR);
if (iihdata)
{
struct MsgPort *port;
port = CreateMsgPort();
if (port)
{
if ((iihdata->InputEventMemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR,
sizeof(struct GeneratedInputEvent) * 10,
sizeof(struct GeneratedInputEvent) * 10)) &&
(iihdata->ActionsMemPool = CreatePool(MEMF_SEM_PROTECTED,
2000, 2000)))
{
const struct TagItem dragtags[] =
{
{GA_SysGadget , TRUE },
{GA_SysGType , GTYP_WDRAGGING},
{TAG_DONE }
};
const struct TagItem sizetags[] =
{
{GA_SysGadget , TRUE },
{GA_SysGType , GTYP_SIZING },
{TAG_DONE }
};
iihdata->MasterDragGadget = (struct Gadget *)NewObjectA(GetPrivIBase(IntuitionBase)->dragbarclass,
NULL,
(struct TagItem *)dragtags);
iihdata->MasterSizeGadget = (struct Gadget *)NewObjectA(GetPrivIBase(IntuitionBase)->sizebuttonclass,
NULL,
(struct TagItem *)sizetags);
if (iihdata->MasterDragGadget && iihdata->MasterSizeGadget)
{
ULONG lock;
/* We do not want to be woken up by message replies.
We are anyway woken up about 10 times a second by
timer events
*/
FreeSignal(port->mp_SigBit);
port->mp_SigBit = -1;
port->mp_Flags = PA_IGNORE;
iihdata->IntuiReplyPort = port;
NEWLIST((struct List*) &iihdata->IntuiActionQueue);
NEWLIST((struct List*)&iihdata->NewAllocatedInputEventList);
NEWLIST((struct List*)&iihdata->AllocatedInputEventList);
iihdata->EndInputEventChain = &iihdata->ReturnInputEvent;
iihdata->FreeInputEvents = NULL;
iihdata->ActQualifier = IEQUALIFIER_RELATIVEMOUSE;
/* Note: there are several routines like CloseWindow, which
expect is_Data to point to the IIHData structure, so don't
change this! */
iihandler->is_Code = (VOID_FUNC)AROS_ASMSYMNAME(IntuiInputHandler);
iihandler->is_Data = iihdata;
iihandler->is_Node.ln_Pri = 50;
iihandler->is_Node.ln_Name = "Intuition InputHandler";
lock = LockIBase(0UL);
iihdata->IntuitionBase = IntuitionBase;
UnlockIBase(lock);
GetPrivIBase(IntuitionBase)->IntuiReplyPort = iihdata->IntuiReplyPort;
GetPrivIBase(IntuitionBase)->IntuiActionQueue = &iihdata->IntuiActionQueue;
ReturnPtr ("InitIIH", struct Interrupt *, iihandler);
} /* f (iihdata->MasterDragGadget && iihdata->MasterSizeGadget) */
DisposeObject((Object *)iihdata->MasterDragGadget);
DisposeObject((Object *)iihdata->MasterSizeGadget);
DeletePool(iihdata->ActionsMemPool);
DeletePool(iihdata->InputEventMemPool);
} /* if (iihdata->InputEventMemPool = ... */
DeleteMsgPort(port);
} /* if (port) */
FreeMem(iihdata, sizeof (struct IIHData));
iihdata->MouseBoundsActiveFlag = FALSE;
} /* if (iihdata) */
FreeMem(iihandler, sizeof (struct Interrupt));
} /* if (iihandler) */
ReturnPtr ("InitIIH", struct Interrupt *, NULL);
}
/****************************************************************************************/
VOID CleanupIIH(struct Interrupt *iihandler, struct IntuitionBase *IntuitionBase)
{
struct IIHData *iihdata = (struct IIHData *)iihandler->is_Data;
D(bug("[Intuition] %s()\n", __func__));
DisposeObject((Object *)iihdata->MasterDragGadget);
DisposeObject((Object *)iihdata->MasterSizeGadget);
FreeGeneratedInputEvents(iihdata);
DeletePool(iihdata->InputEventMemPool);
DeletePool(iihdata->ActionsMemPool);
/* One might think that this port is still in use by the inputhandler.
** However, if intuition is closed for the last time, there should be no
** windows that IntuiMessage can be sent to.
*/
FreeMem(iihdata->IntuiReplyPort, sizeof (struct MsgPort));
FreeMem(iihdata, sizeof (struct IIHData));
FreeMem(iihandler, sizeof (struct Interrupt));
return;
}
/****************************************************************************************/
static void HandleIntuiReplyPort(struct IIHData *iihdata, struct IntuitionBase *IntuitionBase)
{
struct Library *TimerBase = GetPrivIBase(IntuitionBase)->TimerBase;
struct IntuiMessage *im;
D(bug("[Intuition] %s()\n", __func__));
while ((im = (struct IntuiMessage *)GetMsg(iihdata->IntuiReplyPort)))
{
if (im->IDCMPWindow && ResourceExisting(im->IDCMPWindow, RESOURCE_WINDOW, IntuitionBase))
{
struct IntWindow *win = (struct IntWindow *)im->IDCMPWindow;
Forbid();
GetSysTime(&win->lastmsgreplied);
Permit();
switch(im->Class)
{
case IDCMP_MOUSEMOVE:
IW(im->IDCMPWindow)->num_mouseevents--;
break;
case IDCMP_INTUITICKS:
AROS_ATOMIC_AND(im->IDCMPWindow->Flags, ~WFLG_WINDOWTICKED);
break;
#if USE_IDCMPUPDATE_MESSAGECACHE
case IDCMP_IDCMPUPDATE:
IW(im->IDCMPWindow)->num_idcmpupdate--;
if (!(IW(im->IDCMPWindow)->num_idcmpupdate) && IW(im->IDCMPWindow)->messagecache)
{
SendIntuiMessage(im->IDCMPWindow,IW(im->IDCMPWindow)->messagecache);
IW(im->IDCMPWindow)->messagecache = 0;
}
break;
#endif
case IDCMP_MENUVERIFY:
{
struct Window *w = im->IDCMPWindow;
struct IntScreen *scr = 0;
scr = GetPrivScreen(w->WScreen);
if (scr != GetPrivIBase(IntuitionBase)->MenuVerifyScreen ||
scr->MenuVerifySeconds > im->Seconds ||
(scr->MenuVerifySeconds == im->Seconds &&
scr->MenuVerifyMicros > im->Micros))
{
/* The timeout has expired, just ignore. */
}
else
{
--scr->MenuVerifyMsgCount;
if (w == scr->MenuVerifyActiveWindow &&
im->Code == MENUCANCEL)
{
ULONG lock = LockIBase(0);
struct Window *w1;
for (w1 = scr->Screen.FirstWindow; w1; w1 = w1->NextWindow)
{
if (w1->IDCMPFlags & IDCMP_MENUVERIFY && w1 != scr->MenuVerifyActiveWindow)
{
ih_fire_intuimessage(w1,
IDCMP_MOUSEBUTTONS,
MENUUP,
w1,
IntuitionBase);
}
}
UnlockIBase(lock);
scr->MenuVerifyActiveWindow = NULL;
scr->MenuVerifyTimeOut = 0;
scr->MenuVerifyMsgCount = 0;
scr->MenuVerifySeconds = 0;
scr->MenuVerifyMicros = 0;
GetPrivIBase(IntuitionBase)->MenuVerifyScreen = NULL;
}
else if (scr->MenuVerifyMsgCount == 0)
{
struct InputEvent ie;
/* currently we ONLY need the menu open time ! */
ie.ie_TimeStamp.tv_secs = im->Seconds;
ie.ie_TimeStamp.tv_micro = im->Micros;
if (FireMenuMessage(MMCODE_START, scr->MenuVerifyActiveWindow, &ie, IntuitionBase))
{
/* This lock will be released only when the user is
done with menus = when IECLASS_MENU + IESUBCLASS_MENUSTOP
event arrives (generated by MenuHandler task) */
ObtainSemaphore(&GetPrivIBase(IntuitionBase)->MenuLock);
iihdata->MenuWindow = scr->MenuVerifyActiveWindow;
MENUS_ACTIVE = TRUE;
}
scr->MenuVerifyActiveWindow = NULL;
scr->MenuVerifyTimeOut = 0;
scr->MenuVerifyMsgCount = 0;
scr->MenuVerifySeconds = 0;
scr->MenuVerifyMicros = 0;
GetPrivIBase(IntuitionBase)->MenuVerifyScreen = NULL;
}
}
break;
}
case IDCMP_SIZEVERIFY:
{
struct GadgetInfo *gi = &iihdata->GadgetInfo;
struct Window *w = im->IDCMPWindow;
struct Gadget *gadget = im->IAddress;
struct InputEvent ie;
BOOL reuse_event;
PrepareGadgetInfo(gi, IntuitionBase->ActiveScreen, w, NULL);
SetGadgetInfoGadget(gi, gadget, IntuitionBase);
if (IS_BOOPSI_GADGET(gadget))
{
ie.ie_NextEvent = NULL;
ie.ie_Class = IECLASS_RAWMOUSE;
ie.ie_SubClass = 0;
ie.ie_Code = IECODE_LBUTTON;
ie.ie_Qualifier = im->Qualifier;
ie.ie_X = im->MouseX;
ie.ie_Y = im->MouseY;
ie.ie_TimeStamp.tv_secs = IntuitionBase->Seconds;
ie.ie_TimeStamp.tv_micro = IntuitionBase->Micros;
DoGPInput(gi,
gadget,
&ie,
GM_GOACTIVE,
&reuse_event,
IntuitionBase);
/* For compatibility, send a GM_HANDLEINPUT too */
ie.ie_Class = IECLASS_RAWMOUSE;
ie.ie_Code = IECODE_NOBUTTON;
ie.ie_X = 0;
ie.ie_Y = 0;
gadget = DoGPInput(gi,
gadget,
&ie,
GM_HANDLEINPUT,
&reuse_event,
IntuitionBase);
}
/* From now on the master drag/size gadget takes over */
iihdata->ActiveSysGadget = gadget;
gadget = iihdata->MasterSizeGadget;
iihdata->ActiveGadget = gadget;
ie.ie_Class = IECLASS_RAWMOUSE;
ie.ie_Code = IECODE_LBUTTON;
ie.ie_X = im->MouseX;
ie.ie_Y = im->MouseY;
DoGPInput(gi,
gadget,
&ie,
GM_GOACTIVE,
&reuse_event,
IntuitionBase);
break;
}
case IDCMP_REQVERIFY:
{
struct Window *w = im->IDCMPWindow;
EndRequest(w->DMRequest, w);
ih_fire_intuimessage(w,
IDCMP_REQSET,
0,
w,
IntuitionBase);
}
break;
case IDCMP_WBENCHMESSAGE:
DEBUG_WORKBENCH(dprintf("HandleIntuiReplyPort: code 0x%lx\n",
im->Code));
break;
} /* switch(im->Class) */
if (im->Qualifier & IEQUALIFIER_REPEAT)
{
/* IDCMP_IDCMPUPDATE messages can also be sent from app task, therefore
it would be better if there was an ATOMIC_DEC macro or something */
if (IW(im->IDCMPWindow)->num_repeatevents)
{
IW(im->IDCMPWindow)->num_repeatevents--;
}
}
}
FreeIntuiMessage(im);
} /* while ((im = (struct IntuiMessage *)GetMsg(iihdata->IntuiReplyPort))) */
}
/****************************************************************************************/
struct Window *GetToolBoxWindow(struct InputEvent *ie, struct Screen *scr, struct IntuitionBase *IntuitionBase)
{
/* The caller has checked that the input event is a IECLASS_RAWMOUSE, SELECTDOWN event */
/* NOTE: may be called with NULL ie ptr! */
struct LayersBase *LayersBase = GetPrivIBase(IntuitionBase)->LayersBase;
struct Layer *l;
struct Window *new_w = NULL;
D(bug("[Intuition] %s()\n", __func__));
if (scr)
{
D(bug("GetToolBoxWindow: Click at (%d,%d)\n",scr->MouseX,scr->MouseY));
/* What layer ? */
LockLayerInfo(&scr->LayerInfo);
l = WhichLayer(&scr->LayerInfo, scr->MouseX, scr->MouseY);
UnlockLayerInfo(&scr->LayerInfo);
if (NULL == l)
{
new_w = NULL;
D(bug("GetToolBoxWindow: Click not inside layer\n"));
}
else if (l == scr->BarLayer)
{
}
else
{
new_w = (struct Window *)l->Window;
if (new_w)
{
if ((new_w->Flags & WFLG_TOOLBOX) == 0) new_w = NULL;
}
if (!new_w)
{
D(bug("GetToolBoxWindow: Selected layer is not a ToolBox window\n"));
}
else
{
D(bug("GetToolBoxWindow: Found layer %p\n", l));
}
}
}
D(bug("GetToolBoxWindow: New window %p\n", new_w));
return new_w;
}
/****************************************************************************************/
#define KEY_QUALIFIERS (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT | \
IEQUALIFIER_CAPSLOCK | IEQUALIFIER_CONTROL | \
IEQUALIFIER_LALT | IEQUALIFIER_RALT | \
IEQUALIFIER_LCOMMAND | IEQUALIFIER_RCOMMAND | \
IEQUALIFIER_NUMERICPAD)
#define BUTTON_QUALIFIERS (IEQUALIFIER_MIDBUTTON | IEQUALIFIER_RBUTTON | IEQUALIFIER_LEFTBUTTON)
static struct Gadget *Process_RawMouse(struct InputEvent *ie, struct IIHData *iihdata, struct Screen *screen,
struct Window *w, struct Gadget *gadget, struct GadgetInfo *gi,
ULONG stitlebarhit, BOOL new_active_window, BOOL IsToolbox,
struct InputEvent *orig_ie, BOOL *keep_event, BOOL *reuse_event,
#if SINGLE_SETPOINTERPOS_PER_EVENTLOOP
BOOL *call_setpointerpos,
#endif
struct IntuitionBase *IntuitionBase)
{
struct Library *InputBase = GetPrivIBase(IntuitionBase)->InputBase;
struct Requester *req = w ? w->FirstRequest : NULL;
D(bug("[Intuition] %s()\n", __func__));
switch (ie->ie_Code) {
case SELECTDOWN:
{
BOOL new_gadget = FALSE;
BOOL sizeverify = FALSE;
UWORD MetaDrag = GetPrivIBase(IntuitionBase)->IControlPrefs.ic_MetaDrag;
DEBUG_CLICK(bug("[Inputhandler] Screen 0x%p, Window 0x%p, Gadget 0x%p, screen titlebar %d, new active window %d\n", screen, w, gadget, stitlebarhit, new_active_window));
DEBUG_CLICK(if (screen) bug("[Inputhandler] Coordinates: (%d, %d)\n", screen->MouseX, screen->MouseY));
iihdata->ActQualifier |= IEQUALIFIER_LEFTBUTTON;
/* Enter screen dragging mode if LButton + MetaDrag are pressed. */
if (MetaDrag && ((iihdata->ActQualifier & KEY_QUALIFIERS) == MetaDrag)) {
iihdata->ScreenDrag = screen;
iihdata->ScreenDragPointX = screen->MouseX;
iihdata->ScreenDragPointY = screen->MouseY;
*keep_event = FALSE;
break;
}
#ifdef SKINS
iihdata->TitlebarAppearTime = 0;
#endif
if (MENUS_ACTIVE)
{
FireMenuMessage(MMCODE_EVENT, 0, ie, IntuitionBase);
*keep_event = FALSE;
break;
}
#ifdef SKINS
if (!gadget && w)
{
struct Gadget * draggadget = 0;
if ((!(w->FirstRequest)) && (w->Flags & WFLG_DRAGBAR) && MatchHotkey(ie,IA_ACTIVEWINDOWMOVE,IntuitionBase))
{
if (w->MouseX < IW(w)->sizeimage_width || w->MouseX > w->Width - IW(w)->sizeimage_width - 1 || w->MouseY < ((IW(w)->sizeimage_height > w->BorderTop) ? IW(w)->sizeimage_height : w->BorderTop) || w->MouseY > w->Height - IW(w)->sizeimage_height - 1)
{
for (draggadget = w->FirstGadget; draggadget; draggadget = draggadget->NextGadget)
{
if ((draggadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_WDRAGGING)
{
gadget = draggadget;
new_gadget = TRUE;
break;
}
}
}
}
if ((!(w->FirstRequest)) && (w->Flags & WFLG_SIZEGADGET) && MatchHotkey(ie,IA_ACTIVEWINDOWSIZE,IntuitionBase))
{
if (w->MouseX < IW(w)->sizeimage_width || w->MouseX > w->Width - IW(w)->sizeimage_width - 1 || w->MouseY < ((IW(w)->sizeimage_height > w->BorderTop) ? IW(w)->sizeimage_height : w->BorderTop) || w->MouseY > w->Height - IW(w)->sizeimage_height - 1)
{
for (draggadget = w->FirstGadget; draggadget; draggadget = draggadget->NextGadget)
{
if ((draggadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_SIZING)
{
gadget = draggadget;
new_gadget = TRUE;
break;
}
}
}
}
}
#endif
if (!gadget)
{
/* use the *current* screen rather than active one when searching
for sdepth gadget! */
if (screen)
gadget = FindGadget (screen, stitlebarhit ? NULL : w, stitlebarhit ? NULL : req,
screen->MouseX, screen->MouseY, gi, FALSE, IntuitionBase);
DEBUG_CLICK(bug("Click on gadget %p\n", gadget));
new_gadget = TRUE;
} /* if (!gadget) */
/* If we clicked screen titlebar outside of any gadget, enter drag mode */
if ((!gadget) && stitlebarhit) {
DEBUG_CLICK(bug("[Inputhandler] Entering drag state for screen 0x%p\n", screen));
iihdata->ScreenDrag = screen;
iihdata->ScreenDragPointX = screen->MouseX;
iihdata->ScreenDragPointY = screen->MouseY;
*keep_event = FALSE;
break;
}
if (!IsToolbox) {
if (!gadget && stitlebarhit)
{
struct Window *ww = 0;
ww = FindDesktopWindow(screen, IntuitionBase);
DEBUG_CLICK(bug("[Inputhandler] Clicked on backdrop window 0x%p\n", ww));
if (ww) {
ActivateWindow(ww);
w = ww;
}
}
if (!stitlebarhit && !new_active_window && DoubleClick(GetPrivIBase(IntuitionBase)->LastClickSecs,GetPrivIBase(IntuitionBase)->LastClickMicro,
ie->ie_TimeStamp.tv_secs,ie->ie_TimeStamp.tv_micro))
{
if (GetPrivIBase(IntuitionBase)->DoubleClickButton != SELECTDOWN)
{
GetPrivIBase(IntuitionBase)->DoubleClickCounter = 0;
GetPrivIBase(IntuitionBase)->DoubleClickButton = SELECTDOWN;
}
else
{
GetPrivIBase(IntuitionBase)->DoubleClickCounter ++;
}
}
else
{
DEBUG_CLICK(bug("[Inputhandler] Resetting doubleclick counter\n"));
GetPrivIBase(IntuitionBase)->DoubleClickButton = SELECTDOWN;
GetPrivIBase(IntuitionBase)->DoubleClickCounter = 0;
}
/* update last click time for doubleclicktofront */
GetPrivIBase(IntuitionBase)->LastClickSecs = ie->ie_TimeStamp.tv_secs;
GetPrivIBase(IntuitionBase)->LastClickMicro = ie->ie_TimeStamp.tv_micro;
#ifdef SKINS
if (!stitlebarhit)
{
ULONG result;
if (!(gadget && ((gadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_WDEPTH)))
if ((result = RunHotkeys(ie,IntuitionBase)))
{
//gadget = NULL;
if (result == RUNHOTREUSE)
{
*reuse_event = TRUE;
}
else
{
*keep_event = FALSE;
}
}
}
#endif
}
if (gadget && new_gadget)
{
DEBUG_GADGET(bug("[Inputhandler] Activate gadget: 0x%p\n", gadget));
if (w && (w->IDCMPFlags & IDCMP_SIZEVERIFY) &&
(gadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_SIZING /*||
(gadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_WZOOM*/)
{
ih_fire_intuimessage(w,
IDCMP_SIZEVERIFY,
0,
gadget,
IntuitionBase);
gadget = NULL;
sizeverify = TRUE;
}
else
{
BOOL is_draggad, is_sizegad;
UWORD gsystype;
/* Whenever the active gadget changes the gi must be updated
because it is cached in iidata->GadgetInfo!!!! Don't
forget to do this if somewhere else the active
gadget is changed, for example in ActivateGadget!!! */
PrepareGadgetInfo(gi, screen, w, req);
SetGadgetInfoGadget(gi, gadget, IntuitionBase);
gsystype = gadget->GadgetType & GTYP_SYSTYPEMASK;
is_draggad = ((gsystype == GTYP_WDRAGGING)
#ifdef __MORPHOS__
|| (gsystype == GTYP_WDRAGGING2)
#endif
);
is_sizegad = (gsystype == GTYP_SIZING);
/* jDc: intui68k sends IDCMPs for GACT_IMMEDIATE drag&sizegads! */
if (gadget->Activation & GACT_IMMEDIATE)
{
ih_fire_intuimessage(w,
IDCMP_GADGETDOWN,
0,
gadget,
IntuitionBase);
}
if (is_draggad || is_sizegad)
{
if (IS_BOOPSI_GADGET(gadget))
{
DoGPInput(gi,
gadget,
ie,
GM_GOACTIVE,
reuse_event,
IntuitionBase);
/* Ignoring retval of dispatcher above is what
AmigaOS does too for boopsi drag/resize
gadgets */
}
/* From now on the master drag/size gadget takes over */
if ((w->MoreFlags & WMFLG_IAMMUI) && (w->Flags & WFLG_BORDERLESS))
iihdata->ActiveSysGadget = is_draggad ? gadget : 0;
else
iihdata->ActiveSysGadget = gadget;
gadget = is_draggad ? iihdata->MasterDragGadget : iihdata->MasterSizeGadget;
}
}
}
if (gadget)
{
switch (gadget->GadgetType & GTYP_GTYPEMASK)
{
case GTYP_BOOLGADGET:
/* Only set the GFLG_SELECTED flag for RELVERIFY and
* TOGGLESELECT gadget. It's for the user to do it if
* he wants for other GADGIMMEDIATE ones.
* Only RELVERIFY gadgets stay active.
*/
if (gadget->Activation & (GACT_TOGGLESELECT | GACT_RELVERIFY))
{
gadget->Flags ^= GFLG_SELECTED;
RefreshBoolGadgetState(gadget, w, req, IntuitionBase);
}
if (gadget->Activation & GACT_RELVERIFY)
{
gadget->Activation |= GACT_ACTIVEGADGET;
iihdata->MouseWasInsideBoolGadget = TRUE;
}
else
{
gadget = NULL;
}
break;
case GTYP_PROPGADGET:
HandlePropSelectDown(gadget,
w,
req,
w->MouseX - gi->gi_Domain.Left - GetGadgetLeft(gadget, gi->gi_Screen, gi->gi_Window, NULL),
w->MouseY - gi->gi_Domain.Top - GetGadgetTop(gadget, gi->gi_Screen, gi->gi_Window, NULL),
IntuitionBase);
break;
case GTYP_STRGADGET:
/* If the click was inside the active strgad,
** then let it update cursor pos,
** else deactivate stringadget and reuse event.
*/
if (InsideGadget(gi->gi_Screen, gi->gi_Window,
gi->gi_Requester, gadget,
gi->gi_Screen->MouseX, gi->gi_Screen->MouseY))
{
UWORD imsgcode;
HandleStrInput(gadget, gi, ie, &imsgcode,
IntuitionBase);
}
else
{
gadget->Flags &= ~GFLG_SELECTED;
RefreshStrGadget(gadget, w, req, IntuitionBase);
/* Gadget not active anymore */
gadget = NULL;
*reuse_event = TRUE;
}
break;
case GTYP_CUSTOMGADGET:
gadget = DoGPInput(gi,
gadget,
ie,
(new_gadget ? GM_GOACTIVE : GM_HANDLEINPUT),
reuse_event,
IntuitionBase);
D(bug("new_gadget %d, goactive %p\n", new_gadget, gadget));
if (gadget && new_gadget && (!(gadget->GadgetType & GTYP_SIZING)))
{
/* For compatibility, send a GM_HANDLEINPUT too */
struct InputEvent newie;
BOOL reuse_event;
newie.ie_NextEvent = NULL;
newie.ie_Class = IECLASS_RAWMOUSE;
newie.ie_SubClass = 0;
newie.ie_Code = IECODE_NOBUTTON;
newie.ie_Qualifier = ie->ie_Qualifier;
newie.ie_X = 0;
newie.ie_Y = 0;
newie.ie_TimeStamp.tv_secs = IntuitionBase->Seconds;
newie.ie_TimeStamp.tv_micro = IntuitionBase->Micros;
gadget = DoGPInput(gi,
gadget,
&newie,
GM_HANDLEINPUT,
&reuse_event,
IntuitionBase);
D(bug("handleinput %p\n", gadget));
}
break;
case 0: //orig gadtools / some 1.3 gadgets
if (IS_SYS_GADGET(gadget))
{
HandleSysGadgetVerify(gi, gadget, IntuitionBase);
}
else
{
if (gadget->Activation & GACT_RELVERIFY)
{
gadget->Activation |= GACT_ACTIVEGADGET;
iihdata->MouseWasInsideBoolGadget = TRUE;
if (gadget->Flags & GFLG_GADGHIMAGE)
{
gadget->Flags ^= GFLG_SELECTED;
RefreshBoolGadgetState(gadget, w, req, IntuitionBase);
}
}
else
{
/* jDc: this is what original intuition does, before crashing after a while ;)*/
DEBUG_CLICK(bug("[Inputhandler] Sending SELECTDOWN (old gadget), window 0x%p\n", w));
ih_fire_intuimessage(w,
IDCMP_MOUSEBUTTONS,
SELECTDOWN,
w,
IntuitionBase);
}
}
break;
} /* switch (GadgetType) */
} /* if (a gadget is active) */
else if (w && (!req || req->Flags & NOISYREQ) && !sizeverify && !stitlebarhit)
{
DEBUG_CLICK(bug("[Inputhandler] Sending SELECTDOWN, window 0x%p\n", w));
ih_fire_intuimessage(w,
IDCMP_MOUSEBUTTONS,
SELECTDOWN,
w,
IntuitionBase);
}
} /* case SELECTDOWN */
break;
case SELECTUP:
iihdata->ActQualifier &= ~IEQUALIFIER_LEFTBUTTON;
/* Ignore this event if screen drag qualifier is pressed */
if (iihdata->ScreenDrag) {
iihdata->ScreenDrag = NULL;
*keep_event = FALSE;
break;
}
#ifdef SKINS
iihdata->TitlebarAppearTime = 0;
#endif
if (MENUS_ACTIVE)
{
FireMenuMessage(MMCODE_EVENT, 0, ie, IntuitionBase);
*keep_event = FALSE;
break;
}
if (gadget)
{
BOOL inside = InsideGadget(gi->gi_Screen, gi->gi_Window,
gi->gi_Requester, gadget,
gi->gi_Screen->MouseX, gi->gi_Screen->MouseY);
/*int selected = (gadget->Flags & GFLG_SELECTED) != 0;*/
switch (gadget->GadgetType & GTYP_GTYPEMASK)
{
case GTYP_BOOLGADGET:
/* Must be a RELVERIFY gadget */
if (!(gadget->Activation & GACT_TOGGLESELECT) && inside)
{
gadget->Flags ^= GFLG_SELECTED;
RefreshBoolGadgetState(gadget, w, req, IntuitionBase);
}
if (inside)
{
if (IS_SYS_GADGET(gadget))
{
HandleSysGadgetVerify(gi, gadget, IntuitionBase);
}
else
{
if (req && gadget->Activation & GACT_ENDGADGET)
{
EndRequest(req, w);
req = w->FirstRequest;
}
ih_fire_intuimessage(w,
IDCMP_GADGETUP,
0,
gadget,
IntuitionBase);
}
}
else
{
/* RKRM say so */
ih_fire_intuimessage(w,
IDCMP_MOUSEBUTTONS,
SELECTUP,
w,
IntuitionBase);
}
gadget->Activation &= ~GACT_ACTIVEGADGET;
gadget = NULL;
break;
case GTYP_PROPGADGET:
HandlePropSelectUp(gadget, w, req, IntuitionBase);
if (gadget->Activation & GACT_RELVERIFY)
{
ih_fire_intuimessage(w,
IDCMP_GADGETUP,
0,
gadget,
IntuitionBase);
}
gadget = NULL;
break;
/* Intuition string gadgets don't care about SELECTUP */
case GTYP_CUSTOMGADGET:
gadget = DoGPInput(gi, gadget, ie, GM_HANDLEINPUT, reuse_event, IntuitionBase);
break;
case 0: //orig gadtools / some 1.3 gadgets
/* jDc: adding a gadget with gtyp field set to NULL crashes intui68k
** seems we don't need compatibility on this field ;) anyway we should
** handle the case of GTYP_CLOSE, etc, set by some "cod3r"
*/
gadget->Activation &= ~GACT_ACTIVEGADGET;
if (gadget->Activation & GACT_RELVERIFY)
{
if (gadget->Flags & GFLG_GADGHIMAGE)
{
if (inside)
{
gadget->Flags ^= GFLG_SELECTED;
RefreshBoolGadgetState(gadget, w, req, IntuitionBase);
}
}
if (inside)
{
ih_fire_intuimessage(w,
IDCMP_GADGETUP,
0,
gadget,
IntuitionBase);
}
} else {
ih_fire_intuimessage(w,
IDCMP_MOUSEBUTTONS,
SELECTUP,
w,
IntuitionBase);
}
gadget = NULL;
break;
} /* switch GadgetType */
} /* if (a gadget is currently active) */