Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / usb / trident / CfgListClass.c
bloba86403ab6e253404c413f11eb0d925f98205494d
2 /*****************************************************************************
3 ** This is the CfgList custom class, a sub class of List.mui.
4 ******************************************************************************/
6 #include "debug.h"
8 #define USE_INLINE_STDARG
9 #define __NOLIBBASE__
10 #include <proto/muimaster.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/poseidon.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
16 #include <proto/usbclass.h>
17 #include <proto/icon.h>
18 #include <proto/utility.h>
20 #include "Trident.h"
21 #include "ActionClass.h"
22 #include "IconListClass.h"
23 #include "DevWinClass.h"
24 #include "CfgListClass.h"
25 #include "locale.h"
27 extern struct ExecBase *SysBase;
28 extern struct Library *ps;
29 extern struct IntuitionBase *IntuitionBase;
31 /* /// "CheckDragAccept()" */
32 BOOL CheckDragAccept(Object *obj, LONG targetentry)
34 struct PrefsListEntry *targetplnode = NULL;
35 struct PrefsListEntry *sourceplnode = NULL;
36 ULONG sourceid, targetid;
37 IPTR sourceentry = -1;
39 get(obj, MUIA_List_Active, &sourceentry);
40 if((((LONG) sourceentry) < 0) || (targetentry < 0))
42 return(FALSE);
44 DoMethod(obj, MUIM_List_GetEntry, sourceentry, &sourceplnode);
45 DoMethod(obj, MUIM_List_GetEntry, targetentry, &targetplnode);
46 if((!(sourceplnode && targetplnode)) || (sourceplnode == targetplnode))
48 return(FALSE);
50 sourceid = sourceplnode->chunkid;
51 targetid = targetplnode->chunkid;
53 switch(sourceid)
55 case IFFFORM_DEVICECFG:
56 if(targetid == IFFFORM_DEVICECFG)
58 return(TRUE);
60 break;
62 case IFFFORM_DEVCFGDATA:
63 if((targetid == IFFFORM_DEVICECFG) ||
64 (targetid == IFFFORM_DEVCFGDATA))
66 return(TRUE);
68 break;
70 case IFFFORM_IFCFGDATA:
71 if((targetid == IFFFORM_DEVICECFG) ||
72 (targetid == IFFFORM_IFCFGDATA))
74 return(TRUE);
76 break;
78 case IFFCHNK_FORCEDBIND:
79 if((targetid == IFFFORM_DEVICECFG) ||
80 (targetid == IFFFORM_DEVCFGDATA) ||
81 (targetid == IFFFORM_IFCFGDATA) ||
82 (targetid == IFFCHNK_FORCEDBIND))
84 return(TRUE);
86 break;
88 return(FALSE);
90 /* \\\ */
92 /* /// "ApplyDragAction()" */
93 BOOL ApplyDragAction(Object *obj, LONG targetentry)
95 struct PrefsListEntry *targetplnode = NULL;
96 struct PrefsListEntry *sourceplnode = NULL;
97 ULONG sourceid, targetid;
98 IPTR sourceentry = -1;
99 LONG result;
100 APTR pic, spic, tpic;
101 APTR form;
103 get(obj, MUIA_List_Active, &sourceentry);
104 if((((LONG) sourceentry) < 0) || (targetentry < 0))
106 return(FALSE);
108 DoMethod(obj, MUIM_List_GetEntry, sourceentry, &sourceplnode);
109 DoMethod(obj, MUIM_List_GetEntry, targetentry, &targetplnode);
110 if((!(sourceplnode && targetplnode)) || (sourceplnode == targetplnode))
112 return(FALSE);
114 sourceid = sourceplnode->chunkid;
115 targetid = targetplnode->chunkid;
117 switch(sourceid)
119 case IFFFORM_DEVICECFG:
120 if(targetid == IFFFORM_DEVICECFG)
122 result = MUI_Request(_app(obj), _win(obj), 0, NULL, _(MSG_APPLYDRAGACTION_DEVICECFG),_(MSG_APPLYDRAGACTION_DEVICECFG_HELP), targetplnode->id, sourceplnode->id);
123 if(result < 1)
125 return(FALSE);
127 tpic = NULL;
128 spic = NULL;
129 pic = psdFindCfgForm(NULL, IFFFORM_DEVICECFG);
130 while(pic)
132 if(psdMatchStringChunk(pic, IFFCHNK_DEVID, targetplnode->devid))
134 tpic = pic;
136 if(psdMatchStringChunk(pic, IFFCHNK_DEVID, sourceplnode->devid))
138 spic = pic;
140 pic = psdNextCfgForm(pic);
142 if(!(tpic && spic))
144 return(FALSE);
146 // delete old contents
147 if(result == 1)
149 while((pic = psdFindCfgForm(tpic, IFFFORM_DEVCFGDATA)))
151 psdRemCfgForm(pic);
153 while((pic = psdFindCfgForm(tpic, IFFFORM_IFCFGDATA)))
155 psdRemCfgForm(pic);
159 // copy device cfg data
160 pic = psdFindCfgForm(spic, IFFFORM_DEVCFGDATA);
161 while(pic)
163 form = psdWriteCfg(pic);
164 if(form)
166 psdAddCfgEntry(tpic, form);
167 psdFreeVec(form);
169 pic = psdNextCfgForm(pic);
171 // copy interface cfg data
172 pic = psdFindCfgForm(spic, IFFFORM_IFCFGDATA);
173 while(pic)
175 form = psdWriteCfg(pic);
176 if(form)
178 psdAddCfgEntry(tpic, form);
179 psdFreeVec(form);
181 pic = psdNextCfgForm(pic);
183 return(TRUE);
185 break;
187 case IFFFORM_IFCFGDATA:
188 case IFFFORM_DEVCFGDATA:
189 if((targetid == IFFFORM_DEVCFGDATA) || (targetid == IFFFORM_IFCFGDATA))
191 if(strcmp(sourceplnode->owner, targetplnode->owner))
193 result = MUI_RequestA(_app(obj), _win(obj), 0, NULL, _(MSG_APPLYDRAGACTION_DEVCFGDATA),_(MSG_APPLYDRAGACTION_DEVCFGDATA_HELP), NULL);
194 if(result < 1)
196 return(FALSE);
198 targetid = IFFFORM_DEVICECFG;
199 } else {
200 result = MUI_Request(_app(obj), _win(obj), 0, NULL, _(MSG_APPLYDRAGACTION_DEVCFGDATA_REPLACE),_(MSG_APPLYDRAGACTION_DEVCFGDATA_REPLACE_HELP), targetplnode->id, sourceplnode->id);
202 if(result < 1)
204 return(FALSE);
206 pic = psdGetUsbDevCfg(sourceplnode->owner, sourceplnode->devid, sourceplnode->ifid);
207 if(pic)
209 form = psdWriteCfg(pic);
210 if(form)
212 psdSetUsbDevCfg(sourceplnode->owner, targetplnode->devid, targetplnode->ifid, form);
213 psdFreeVec(form);
216 return(TRUE);
219 if(targetid == IFFFORM_DEVICECFG)
221 pic = psdGetUsbDevCfg(sourceplnode->owner, targetplnode->devid, sourceplnode->ifid);
222 if(pic)
224 result = MUI_Request(_app(obj), _win(obj), 0, NULL, _(MSG_APPLYDRAGACTION_DEVICECFG_REPLACE),_(MSG_APPLYDRAGACTION_DEVICECFG_REPLACE_HELP), targetplnode->id, sourceplnode->id);
225 } else {
226 result = MUI_Request(_app(obj), _win(obj), 0, NULL, _(MSG_APPLYDRAGACTION_DEVICECFG_ADD),_(MSG_APPLYDRAGACTION_DEVICECFG_ADD_HELP), sourceplnode->id, targetplnode->id);
228 if(result < 1)
230 return(FALSE);
232 pic = psdGetUsbDevCfg(sourceplnode->owner, sourceplnode->devid, sourceplnode->ifid);
233 if(pic)
235 form = psdWriteCfg(pic);
236 if(form)
238 psdSetUsbDevCfg(sourceplnode->owner, targetplnode->devid, sourceplnode->ifid, form);
239 psdFreeVec(form);
242 return(TRUE);
244 break;
246 case IFFCHNK_FORCEDBIND:
247 if((targetid == IFFFORM_DEVICECFG) ||
248 (targetid == IFFFORM_DEVCFGDATA) ||
249 (targetid == IFFFORM_IFCFGDATA) ||
250 (targetid == IFFCHNK_FORCEDBIND))
252 psdSetForcedBinding(sourceplnode->owner, targetplnode->devid, targetplnode->ifid);
253 return(TRUE);
255 break;
257 return(FALSE);
259 /* \\\ */
261 /* /// "CfgListDispatcher()" */
262 AROS_UFH3(IPTR, CfgListDispatcher,
263 AROS_UFHA(struct IClass *, cl, A0),
264 AROS_UFHA(Object *, obj, A2),
265 AROS_UFHA(Msg, msg, A1))
267 AROS_USERFUNC_INIT
268 // There should never be an uninitialized pointer, but just in case, try to get an mungwall hit if so.
269 struct CfgListData *data = (struct CfgListData *) 0xABADCAFE;
271 // on OM_NEW the obj pointer will be void, so don't try to get the data base in this case.
272 if(msg->MethodID != OM_NEW) data = INST_DATA(cl,obj);
274 switch(msg->MethodID)
276 case OM_NEW:
277 if(!(obj = (Object *) DoSuperMethodA(cl,obj,msg)))
278 return(0);
279 return((IPTR) obj);
281 case MUIM_DragBegin:
282 data->cl_Dragging = TRUE;
283 break;
285 case MUIM_DragFinish:
286 data->cl_Dragging = FALSE;
287 break;
289 case MUIM_DragQuery:
291 struct MUI_List_TestPos_Result tpr;
292 struct Window *win;
294 win = _window(obj);
295 if(!win)
297 return(MUIV_DragQuery_Refuse);
299 DoMethod(obj, MUIM_List_TestPos, win->MouseX, win->MouseY, &tpr);
300 return((IPTR) (CheckDragAccept(obj, tpr.entry) ? MUIV_DragQuery_Accept : MUIV_DragQuery_Refuse));
303 #ifndef MUI_LPR_FULLDROP
304 #define MUI_LPR_FULLDROP (1<<15)
305 #endif
306 case MUIM_List_TestPos:
308 struct MUIP_List_TestPos *tpmsg = (struct MUIP_List_TestPos *) msg;
309 struct MUI_List_TestPos_Result *res = tpmsg->res;
310 IPTR rc;
311 rc = DoSuperMethodA(cl, obj, msg);
312 if(data->cl_Dragging && (res->entry != -1))
314 if(!CheckDragAccept(obj, res->entry))
316 res->entry = -1; // illegal combination
317 } else {
318 res->flags |= MUI_LPR_FULLDROP;
321 return(rc);
324 case MUIM_DragDrop:
326 //struct MUIP_DragDrop *ddmsg = (struct MUIP_DragDrop *) msg;
327 struct MUI_List_TestPos_Result tpr;
328 struct Window *win;
330 win = _window(obj);
331 if(!win)
333 return(FALSE);
335 DoMethod(obj, MUIM_List_TestPos, win->MouseX, win->MouseY, &tpr);
336 //DoMethod(obj, MUIM_List_TestPos, ddmsg->x, ddmsg->y, &tpr);
337 if(CheckDragAccept(obj, tpr.entry))
339 ApplyDragAction(obj, tpr.entry);
340 } else {
341 MUI_RequestA(_app(obj), _win(obj), 0, NULL, _(MSG_CFGLISTDISPATCHER_OOPS),_(MSG_CFGLISTDISPATCHER_OOPS_HELP), NULL);
342 return(FALSE);
344 return(TRUE);
348 return(DoSuperMethodA(cl,obj,msg));
349 AROS_USERFUNC_EXIT
351 /* \\\ */