[261749]: libs / gtdrag / GTD_Boopsi.c Maximize Restore History

Download this file

GTD_Boopsi.c    185 lines (143 with data), 4.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
/*
* Copyright Š1999-2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the MIT License.
*/
//! BOOPSI gadgets
#include "gtdrag_includes.h"
ULONG PRIVATE DoCustomMethod(struct Gadget *gad,ULONG method,...)
{
return(CallHookPkt((struct Hook *)gad->MutualExclude,gad,&method));
}
ULONG PRIVATE DoRenderMethod(struct DragGadget *rdg,WORD x,WORD y,ULONG mode)
{
struct GadgetInfo gi;
struct RastPort *rp;
struct Gadget *gad = rdg->dg_Gadget;
ULONG rc = 0L;
memset(&gi,0,sizeof(struct GadgetInfo));
gi.gi_Window = rdg->dg_Window;
gi.gi_Screen = gi.gi_Window->WScreen;
gi.gi_RastPort = gi.gi_Window->RPort;
gi.gi_Layer = gi.gi_Window->WLayer;
gi.gi_Domain.Left = rdg->dg_Gadget->LeftEdge;
gi.gi_Domain.Top = rdg->dg_Gadget->TopEdge;
gi.gi_Domain.Width = rdg->dg_Gadget->Width;
gi.gi_Domain.Height = rdg->dg_Gadget->Height;
gi.gi_DrInfo = GetScreenDrawInfo(gi.gi_Screen);
if ((rp = ObtainGIRPort(&gi)) != 0)
{
if (mode != GRENDER_DELETE)
{
x += dg->dg_Window->LeftEdge-rdg->dg_Window->LeftEdge-gad->LeftEdge;
y += dg->dg_Window->TopEdge-rdg->dg_Window->TopEdge-gad->TopEdge;
}
rc = DoCustomMethod(gad,GM_RENDERDRAG,&gi,rp,mode,words(x,y));
ReleaseGIRPort(rp);
}
FreeScreenDrawInfo(gi.gi_Screen,gi.gi_DrInfo);
return(rc);
}
LIB_LH2(ULONG, GTD_HandleInput,
LIB_LHA(struct Gadget *, gad, A0),
LIB_LHA(struct gpInput *, gpi, A1),
struct Library *, library, 24, Gtdrag)
{
LIBFUNC_INIT
struct InputEvent *ie;
long x,y;
if (!gpi || !gad || !gdo || gad != boopsigad || !(ie = gpi->gpi_IEvent))
return(GMR_HANDLEYOURSELF);
x = gpi->gpi_Mouse.X+gad->LeftEdge;
y = gpi->gpi_Mouse.Y+gad->TopEdge;
switch(ie->ie_Class)
{
case IECLASS_RAWMOUSE:
if (ie->ie_Code == IECODE_NOBUTTON)
{
MouseMove(x,y);
return(GMR_MEACTIVE);
}
else
{
if (ie->ie_Code == (IECODE_LBUTTON | IECODE_UP_PREFIX))
MakeDropMessage(GetDragApp(dg->dg_Task),ie->ie_Qualifier,x,y);
FreeDragObj(gdo);
EndDrag();
return(GMR_NOREUSE);
}
case IECLASS_TIMER:
IntuiTick(x,y);
}
return(GMR_MEACTIVE); // catches all input events
LIBFUNC_EXIT
}
LIB_LH2(BOOL, GTD_PrepareDrag,
LIB_LHA(struct Gadget *, gad, A0),
LIB_LHA(struct gpInput *, gpi, A1),
struct Library *, library, 22, Gtdrag)
{
LIBFUNC_INIT
struct DragGadget *dg;
struct Window *win;
if (!gad || !gpi || gdo || !gpi->gpi_IEvent || !(gpi->gpi_IEvent->ie_Qualifier & IEQUALIFIER_LEFTBUTTON) || !gpi->gpi_GInfo)
return(FALSE);
if (FindDragGadget(gad)) // gadget is already registered
return(TRUE);
win = gpi->gpi_GInfo->gi_Window;
if (!GetDragApp(NULL)) // create an drag application for the input.device
{
ULONG tags[] = {GTDA_NewStyle,TRUE,TAG_END};
GTD_AddAppA("intuition",(struct TagItem *)tags);
}
if ((dg = AddDragGadget(gad,win,BOOPSI_KIND)) != 0)
{
struct DragWindow *dw;
foreach(&winlist,dw) // search for the gadget's real application
if (dw->dw_Window == win)
break;
if (dw->dw_Node.mln_Succ) // window found
dg->dg_Task = dw->dw_Task;
else // search gadget list
{
struct DragGadget *sdg;
foreach(&gadlist,sdg)
{
if (sdg != dg && sdg->dg_Window == win)
{
dg->dg_Task = sdg->dg_Task;
break;
}
}
}
return(TRUE);
}
return(FALSE);
LIBFUNC_EXIT
}
LIB_LH2(BOOL, GTD_BeginDrag,
LIB_LHA(struct Gadget *, gad, A0),
LIB_LHA(struct gpInput *, gpi, A1),
struct Library *, library, 23, Gtdrag)
{
AROS_LIBFUNC_INIT
if ((dg = FindDragGadget(gad)) != 0)
{
PrepareDrag(TRUE);
boopsigad = gad;
gdo = CreateDragObj(dg,gpi->gpi_Mouse.X+gad->LeftEdge,gpi->gpi_Mouse.Y+gad->TopEdge);
return(TRUE);
}
return(FALSE);
LIBFUNC_EXIT
}
LIB_LH1(void, GTD_StopDrag,
LIB_LHA(struct Gadget *, gad, A0),
struct Library *, library, 25, Gtdrag)
{
LIBFUNC_INIT
if (gad != boopsigad || !gdo)
return;
FreeDragObj(gdo);
EndDrag();
AROS_LIBFUNC_EXIT
}