Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / openurl / prefs / applist.c
blob96936c466e4a60671b7b5fbc6425fc52b598f4e7
1 /*
2 ** OpenURL - MUI preferences for openurl.library
3 **
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
6 **
7 ** Developed by:
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** A clients page
16 #include "OpenURL.h"
17 #define CATCOMP_NUMBERS
18 #include "loc.h"
19 #include "libraries/openurl.h"
21 /**************************************************************************/
23 ** Little lamp class for enabled/disabled
26 static struct MUI_CustomClass *lampClass = NULL;
27 #ifdef __AROS__
28 #define lampObject BOOPSIOBJMACRO_START(lampClass->mcc_Class)
29 #else
30 #define lampObject NewObject(lampClass->mcc_Class,NULL
31 #endif
33 struct lampData
35 struct MUI_PenSpec **specs; /* We don't need to save them, because of Pens window is always valid */
37 LONG enabled;
38 LONG disabled;
39 LONG detail;
40 WORD delta;
42 ULONG flags;
45 enum
47 FLG_LampSetup = 1<<0,
48 FLG_LampDisabled = 1<<1,
51 /***********************************************************************/
53 static ULONG
54 mLampNew(struct IClass *cl,Object *obj,struct opSet *msg)
56 return (ULONG)DoSuperNew(cl,obj,
57 MUIA_Font, MUIV_Font_List,
58 TAG_MORE, msg->ops_AttrList);
61 /**************************************************************************/
63 static ULONG
64 mLampSets(struct IClass *cl,Object *obj,struct opSet *msg)
66 struct lampData *data = INST_DATA(cl,obj);
67 struct TagItem *tag;
69 if (tag = FindTagItem(MUIA_Lamp_Disabled,msg->ops_AttrList))
71 if (tag->ti_Data) data->flags |= FLG_LampDisabled;
72 else data->flags &= ~FLG_LampDisabled;
74 /* Of course, we don't redraw here */
77 if (tag = FindTagItem(MUIA_App_Pens,msg->ops_AttrList))
79 struct MUI_PenSpec **specs = (struct MUI_PenSpec **)tag->ti_Data;
81 data->specs = specs;
83 if (data->flags & FLG_LampSetup)
85 MUI_ReleasePen(muiRenderInfo(obj),data->enabled);
86 MUI_ReleasePen(muiRenderInfo(obj),data->disabled);
87 MUI_ReleasePen(muiRenderInfo(obj),data->detail);
88 data->enabled = MUI_ObtainPen(muiRenderInfo(obj),specs[0],0);
89 data->disabled = MUI_ObtainPen(muiRenderInfo(obj),specs[1],0);
90 data->detail = MUI_ObtainPen(muiRenderInfo(obj),specs[2],0);
92 /* Of course, we don't redraw here */
93 data->flags |= FLG_LampSetup;
97 return DoSuperMethodA(cl,obj,(Msg)msg);
100 /***********************************************************************/
102 static ULONG
103 mLampSetup(struct IClass *cl,Object *obj,struct MUIP_Setup *msg)
105 struct lampData *data = INST_DATA(cl,obj);
106 if (!DoSuperMethodA(cl,obj,(APTR)msg)) return FALSE;
107 data->enabled = MUI_ObtainPen(muiRenderInfo(obj),data->specs[0],0);
108 data->disabled = MUI_ObtainPen(muiRenderInfo(obj),data->specs[1],0);
109 data->detail = MUI_ObtainPen(muiRenderInfo(obj),data->specs[2],0);
111 data->flags |= FLG_LampSetup;
113 return TRUE;
116 /***********************************************************************/
118 static ULONG
119 mLampCleanup(struct IClass *cl,Object *obj,struct MUIP_Setup *msg)
121 struct lampData *data = INST_DATA(cl,obj);
123 if (data->flags & FLG_LampSetup)
125 MUI_ReleasePen(muiRenderInfo(obj),data->enabled);
126 MUI_ReleasePen(muiRenderInfo(obj),data->disabled);
127 MUI_ReleasePen(muiRenderInfo(obj),data->detail);
129 data->flags &= ~FLG_LampSetup;
132 return DoSuperMethodA(cl,obj,(APTR)msg);
135 /***********************************************************************/
137 static ULONG
138 mLampAskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
140 struct lampData *data = INST_DATA(cl,obj);
141 struct RastPort rp;
142 struct TextExtent te;
143 UWORD w, h, d;
145 DoSuperMethodA(cl,obj,(APTR)msg);
147 CopyMem(&_screen(obj)->RastPort,&rp,sizeof(rp));
149 /* Don't ask or modify ! */
151 SetFont(&rp,_font(obj));
152 TextExtent(&rp," ",2,&te);
154 w = te.te_Width;
155 h = te.te_Height;
157 if (w>=h) d = w;
158 else d = h;
160 data->delta = te.te_Extent.MinY;
162 msg->MinMaxInfo->MinWidth += d;
163 msg->MinMaxInfo->MinHeight += h;
164 msg->MinMaxInfo->DefWidth += d;
165 msg->MinMaxInfo->DefHeight += h;
166 msg->MinMaxInfo->MaxWidth += d;
167 msg->MinMaxInfo->MaxHeight += h;
169 return 0;
172 /***********************************************************************/
174 static ULONG
175 mLampDraw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
177 struct lampData *data = INST_DATA(cl,obj);
178 ULONG res;
180 res = DoSuperMethodA(cl,obj,(APTR)msg);
182 if (msg->flags & (MADF_DRAWOBJECT|MADF_DRAWUPDATE))
184 WORD l, t, r, b;
186 /* Don't ask or modify ! */
188 l = _mleft(obj);
189 r = _mright(obj);
190 t = _mtop(obj)+(_mheight(obj)+data->delta)/2-1;
191 b = t-data->delta;
193 if (r-l>2)
195 l += 1;
196 r -= 1;
199 if (b-t>2)
201 t += 1;
202 b -= 1;
205 SetAPen(_rp(obj),MUIPEN((data->flags & FLG_LampDisabled) ? data->disabled : data->enabled));
206 RectFill(_rp(obj),l,t,r,b);
208 SetAPen(_rp(obj),MUIPEN(data->detail));
209 Move(_rp(obj),l,t);
210 Draw(_rp(obj),r,t);
211 Draw(_rp(obj),r,b);
212 Draw(_rp(obj),l,b);
213 Draw(_rp(obj),l,t);
216 return res;
219 /***********************************************************************/
221 M_DISP(lampDispatcher)
223 M_DISPSTART
225 switch(msg->MethodID)
227 case OM_NEW: return mLampNew(cl,obj,(APTR)msg);
228 case OM_SET: return mLampSets(cl,obj,(APTR)msg);
230 case MUIM_Setup: return mLampSetup(cl,obj,(APTR)msg);
231 case MUIM_Cleanup: return mLampCleanup(cl,obj,(APTR)msg);
232 case MUIM_AskMinMax: return mLampAskMinMax(cl,obj,(APTR)msg);
233 case MUIM_Draw: return mLampDraw(cl,obj,(APTR)msg);
235 default: return DoSuperMethodA(cl,obj,msg);
239 M_DISPEND(lampDispatcher)
241 /***********************************************************************/
243 static ULONG
244 initLampClass(void)
246 return (ULONG)(lampClass = MUI_CreateCustomClass(NULL,MUIC_Rectangle,NULL,sizeof(struct lampData),DISP(lampDispatcher)));
249 /**************************************************************************/
251 static void
252 disposeLampClass(void)
254 if (lampClass) MUI_DeleteCustomClass(lampClass);
257 /**************************************************************************/
259 ** List of clients with lamps
262 static struct MUI_CustomClass *listClass = NULL;
263 #ifdef __AROS__
264 #define listObject BOOPSIOBJMACRO_START(listClass->mcc_Class)
265 #else
266 #define listObject NewObject(listClass->mcc_Class,NULL
267 #endif
269 struct listData
271 Object *olamp;
272 APTR lamp;
273 TEXT col0buf[NAME_LEN+16];
275 ULONG nameOfs;
276 ULONG pathOfs;
277 ULONG nodeSize;
279 TEXT format[64];
281 ULONG flags;
284 enum
286 FLG_ListSetup = 1<<0,
289 /* Used for Import/Export */
290 struct listIO
292 ULONG len;
293 TEXT format[64];
296 /**************************************************************************/
298 #ifdef __MORPHOS__
299 static struct URL_Node *
300 conFun(void)
302 struct Hook *hook = (struct Hook *)REG_a0;
303 APTR pool = (APTR)REG_A2;
304 struct URL_Node *node = (struct URL_Node *)REG_A1;
305 #elif defined(__AROS__)
306 AROS_UFH3S(struct URL_Node *, conFun,
307 AROS_UFHA(struct Hook * , hook, A0),
308 AROS_UFHA(APTR , pool, A2),
309 AROS_UFHA(struct URL_Node *, node, A1))
311 AROS_USERFUNC_INIT
312 #else
313 static struct URL_Node * SAVEDS ASM
314 conFun(REG(a0,struct Hook *hook),REG(a2,APTR pool),REG(a1,struct URL_Node *node))
316 #endif
317 struct listData *data = hook->h_Data;
318 struct URL_Node *new;
320 if (node->Flags & UNF_NTALLOC)
322 new = node;
323 node->Flags &= ~UNF_NTALLOC;
325 else if (new = AllocPooled(pool,data->nodeSize)) CopyMem(node,new,data->nodeSize);
327 return new;
328 #ifdef __AROS__
329 AROS_USERFUNC_EXIT
330 #endif
333 #ifdef __MORPHOS__
334 static struct EmulLibEntry conTrap = {TRAP_LIB,0,(void (*)(void))conFun};
335 static struct Hook conHook = {0,0,(HOOKFUNC)&conTrap};
336 #else
337 static struct Hook conHook = {0,0,(HOOKFUNC)conFun};
338 #endif
340 /**************************************************************************/
342 #ifdef __MORPHOS__
343 static void
344 destFun(void)
346 struct Hook *hook = (struct Hook *)REG_a0;
347 APTR pool = (APTR)REG_A2;
348 struct URL_Node *node = (struct URL_Node *)REG_A1;
349 #elif defined(__AROS__)
350 AROS_UFH3S(void, destFun,
351 AROS_UFHA(struct Hook * , hook, A0),
352 AROS_UFHA(APTR , pool, A2),
353 AROS_UFHA(struct URL_Node *, node, A1))
355 AROS_USERFUNC_INIT
356 #else
357 static void SAVEDS ASM
358 destFun(REG(a0,struct Hook *hook),REG(a2,APTR pool),REG(a1,struct URL_Node *node))
360 #endif
361 struct listData *data = hook->h_Data;
363 FreePooled(pool,node,data->nodeSize);
364 #ifdef __AROS__
365 AROS_USERFUNC_EXIT
366 #endif
369 #ifdef __MORPHOS__
370 static struct EmulLibEntry destTrap = {TRAP_LIBNR,0,(void (*)(void))destFun};
371 static struct Hook destHook = {0,0,(HOOKFUNC)&destTrap};
372 #else
373 static struct Hook destHook = {0,0,(HOOKFUNC)destFun};
374 #endif
376 /**************************************************************************/
378 #ifdef __MORPHOS__
379 static void
380 dispFun(void)
382 struct Hook *hook = (struct Hook *)REG_a0;
383 STRPTR *array = (STRPTR *)REG_A2;
384 struct URL_Node *node = (struct URL_Node *)REG_A1;
385 #elif defined(__AROS__)
386 AROS_UFH3S(void, dispFun,
387 AROS_UFHA(struct Hook * , hook , A0),
388 AROS_UFHA(STRPTR * , array, A2),
389 AROS_UFHA(struct URL_Node *, node , A1))
391 AROS_USERFUNC_INIT
392 #else
393 static void SAVEDS ASM
394 dispFun(REG(a0,struct Hook *hook),REG(a2,STRPTR *array),REG(a1,struct URL_Node *node))
396 #endif
397 struct listData *data = hook->h_Data;
399 if (node)
401 if (data->lamp && data->olamp)
403 set(data->olamp,MUIA_Lamp_Disabled,node->Flags & UNF_DISABLED);
404 //msprintf(data->col0buf,"\33O[%08lx] %s",(ULONG)data->lamp,(ULONG)((UBYTE *)node+data->nameOfs));
405 msprintf(data->col0buf,"\33O[%08lx]",(ULONG)data->lamp);
406 *array++ = data->col0buf;
408 else
409 *array++ = "+";
410 //msprintf(data->col0buf,"%s %s",(ULONG)((node->Flags & UNF_DISABLED) ? " " : ">"),(ULONG)
412 *array++ = (STRPTR)node+data->nameOfs;
413 *array = (STRPTR)node+data->pathOfs;
415 else
417 *array++ = " ";
418 *array++ = getString(MSG_Edit_ListName);
419 *array = getString(MSG_Edit_ListPath);
421 #ifdef __AROS__
422 AROS_USERFUNC_EXIT
423 #endif
426 #ifdef __MORPHOS__
427 static struct EmulLibEntry dispTrap = {TRAP_LIBNR,0,(void (*)(void))dispFun};
428 static struct Hook dispHook = {0,0,(HOOKFUNC)&dispTrap};
429 #else
430 static struct Hook dispHook = {0,0,(HOOKFUNC)dispFun};
431 #endif
433 /**************************************************************************/
435 static ULONG
436 mListNew(struct IClass *cl,Object *obj,struct opSet *msg)
438 if (obj = (Object *)DoSuperNew(cl,obj,
439 InputListFrame,
440 MUIA_List_Title, TRUE,
441 MUIA_List_Format, "C=0,C=1,C=2",
442 MUIA_List_DragSortable, TRUE,
443 MUIA_List_Pool, g_pool,
444 MUIA_List_ConstructHook, &conHook,
445 MUIA_List_DestructHook, &destHook,
446 MUIA_List_DisplayHook, &dispHook,
447 MUIA_List_DragSortable, TRUE,
448 MUIA_List_ShowDropMarks, TRUE,
449 0x8042bc08, 1, /* MUI4 Auto Line Height: put the real name if you know it :P */
450 TAG_MORE, msg->ops_AttrList))
452 struct listData *data = INST_DATA(cl,obj);
454 data->nameOfs = GetTagData(MUIA_AppList_NodeNameOffset,0,msg->ops_AttrList);
455 data->pathOfs = GetTagData(MUIA_AppList_NodePathOffset,0,msg->ops_AttrList);
456 data->nodeSize = GetTagData(MUIA_AppList_NodeSize,0,msg->ops_AttrList);
458 strcpy(data->format,"C=0,C=1,C=2");
460 if (lampClass) data->olamp = lampObject, End;
462 conHook.h_Data = data;
463 destHook.h_Data = data;
464 dispHook.h_Data = data;
467 return (ULONG)obj;
470 /**************************************************************************/
472 static ULONG
473 mListDispose(struct IClass *cl,Object *obj,Msg msg)
475 struct listData *data = INST_DATA(cl,obj);
477 if (data->olamp) MUI_DisposeObject(data->olamp);
479 return DoSuperMethodA(cl,obj,msg);
482 /**************************************************************************/
484 static ULONG
485 mListSets(struct IClass *cl,Object *obj,struct opSet *msg)
487 struct TagItem *tag;
489 if (tag = FindTagItem(MUIA_App_Pens,msg->ops_AttrList))
491 struct listData *data = INST_DATA(cl,obj);
492 if (data->olamp)
494 struct MUI_PenSpec **specs = (struct MUI_PenSpec **)tag->ti_Data;
495 set(data->olamp,MUIA_App_Pens,specs);
496 tag->ti_Tag = TAG_IGNORE;
498 /* Don't want even know why a push is needed here! */
499 if (data->flags & FLG_ListSetup)
500 DoMethod(_app(obj),MUIM_Application_PushMethod,(ULONG)obj,2,MUIM_List_Redraw,MUIV_List_Redraw_All);
504 return DoSuperMethodA(cl,obj,(Msg)msg);
507 /***********************************************************************/
509 static ULONG
510 mListSetup(struct IClass *cl,Object *obj,struct MUIP_Setup *msg)
512 struct listData *data = INST_DATA(cl,obj);
514 if (!DoSuperMethodA(cl,obj,(APTR)msg)) return FALSE;
516 /* After thinking about that hard, I decided to use the lamp in >=8 color screen */
517 if (data->olamp && (GetBitMapAttr(_screen(obj)->RastPort.BitMap,BMA_DEPTH)>3))
518 data->lamp = (APTR)DoSuperMethod(cl,obj,MUIM_List_CreateImage,(ULONG)data->olamp,0);
520 data->flags |= FLG_ListSetup;
522 return TRUE;
525 /***********************************************************************/
527 static ULONG
528 mListCleanup(struct IClass *cl,Object *obj,struct MUIP_Setup *msg)
530 struct listData *data = INST_DATA(cl,obj);
532 if (data->flags & FLG_ListSetup)
534 if (data->lamp)
536 DoSuperMethod(cl,obj,MUIM_List_DeleteImage,(ULONG)data->lamp);
537 data->lamp = NULL;
540 data->flags &= ~FLG_ListSetup;
543 return DoSuperMethodA(cl,obj,(APTR)msg);
546 /***********************************************************************/
548 ** Import format
551 static ULONG
552 mListImport(struct IClass *cl,Object *obj,struct MUIP_Import *msg)
554 register ULONG id;
556 if (id = (muiNotifyData(obj)->mnd_ObjectID))
558 register struct listIO *io;
560 if (io = (struct listIO *)DoMethod(msg->dataspace,MUIM_Dataspace_Find,id))
562 struct listData *data = INST_DATA(cl,obj);
564 stccpy(data->format,io->format,sizeof(data->format));
565 set(obj,MUIA_List_Format,data->format);
569 return 0;
572 /***********************************************************************/
574 ** Export format
577 static ULONG
578 mListExport(struct IClass *cl,Object *obj,struct MUIP_Import *msg)
580 register ULONG id;
582 if (id = (muiNotifyData(obj)->mnd_ObjectID))
584 struct listIO io;
585 STRPTR f;
587 get(obj,MUIA_List_Format,&f);
588 io.len = strlen(f)+1;
589 stccpy(io.format,f,sizeof(io.format));
591 DoMethod(msg->dataspace,MUIM_Dataspace_Add,(ULONG)&io,sizeof(ULONG)+io.len,id);
594 return 0;
597 /**************************************************************************/
599 ** Check if format changed
602 static ULONG
603 mListCheckSave(struct IClass *cl,Object *obj,Msg msg)
605 struct listData *data = INST_DATA(cl,obj);
606 #ifdef __AROS__
607 // Zune doesn't have MUIA_List_Format
608 return 1;
609 #else
610 UBYTE *f;
612 get(obj,MUIA_List_Format,&f);
614 return (ULONG)strcmp((STRPTR)f,(STRPTR)&data->format);
615 #endif
618 /**************************************************************************/
620 M_DISP(listDispatcher)
622 M_DISPSTART
624 switch (msg->MethodID)
626 case OM_NEW: return mListNew(cl,obj,(APTR)msg);
627 case OM_DISPOSE: return mListDispose(cl,obj,(APTR)msg);
628 case OM_SET: return mListSets(cl,obj,(APTR)msg);
630 case MUIM_Setup: return mListSetup(cl,obj,(APTR)msg);
631 case MUIM_Cleanup: return mListCleanup(cl,obj,(APTR)msg);
632 case MUIM_Import: return mListImport(cl,obj,(APTR)msg);
633 case MUIM_Export: return mListExport(cl,obj,(APTR)msg);
635 case MUIM_App_CheckSave: return mListCheckSave(cl,obj,(APTR)msg);
637 default: return DoSuperMethodA(cl,obj,msg);
641 M_DISPEND(listDispatcher)
643 /**************************************************************************/
645 static ULONG
646 initListClass(void)
648 return (ULONG)(listClass = MUI_CreateCustomClass(NULL,MUIC_List,NULL,sizeof(struct listData),DISP(listDispatcher)));
651 /**************************************************************************/
653 static void
654 disposeListClass(void)
656 if (listClass) MUI_DeleteCustomClass(listClass);
659 /**************************************************************************/
661 struct data
663 Object *appList;
664 Object *add;
665 Object *edit;
666 Object *clone;
667 Object *delete;
668 Object *disable;
669 Object *up;
670 Object *down;
672 ULONG nameOfs;
673 ULONG pathOfs;
674 ULONG nodeSize;
675 struct IClass *editClass;
676 ULONG editAttr;
677 ULONG listAttr;
679 STRPTR newNodeName;
682 /**************************************************************************/
684 static ULONG
685 mNew(struct IClass *cl,Object *obj,struct opSet *msg)
687 Object *appl, *addb, *editb, *cloneb, *deleteb, *disableb, *upb, *downb;
688 struct IClass *editWinClass;
689 STRPTR nodeName, helpNode;
690 ULONG nameOfs, pathOfs, nodeSize, editWinAttr, listAttr, help, id;
692 /* What we are */
693 switch (GetTagData(MUIA_AppList_Type,0,msg->ops_AttrList))
695 case MUIV_AppList_Type_Browser:
696 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
697 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
698 nodeSize = sizeof(struct URL_BrowserNode);
699 editWinClass = g_browserEditWinClass->mcc_Class;
700 editWinAttr = MUIA_BrowserEditWin_Browser;
701 listAttr = MUIA_BrowserEditWin_ListObj;
702 nodeName = getString(MSG_Browser_NewBrowser);
703 helpNode = "BROWSER";
704 help = MSG_Browser_List_Help;
705 id = MAKE_ID('B','L','S','T');
706 break;
708 case MUIV_AppList_Type_Mailer:
709 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
710 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
711 nodeSize = sizeof(struct URL_MailerNode);
712 editWinClass = g_mailerEditWinClass->mcc_Class;
713 editWinAttr = MUIA_MailerEditWin_Mailer;
714 listAttr = MUIA_MailerEditWin_ListObj;
715 nodeName = getString(MSG_Mailer_NewMailer);
716 helpNode = "MAILERS";
717 help = MSG_Mailer_List_Help;
718 id = MAKE_ID('M','L','S','T');
719 break;
721 case MUIV_AppList_Type_FTP:
722 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
723 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
724 nodeSize = sizeof(struct URL_FTPNode);
725 editWinClass = g_FTPEditWinClass->mcc_Class;
726 editWinAttr = MUIA_FTPEditWin_FTP;
727 listAttr = MUIA_FTPEditWin_ListObj;
728 nodeName = getString(MSG_FTP_NewFTP);
729 helpNode = "FTPS";
730 help = MSG_FTP_List_Help;
731 id = MAKE_ID('F','L','S','T');
732 break;
734 default:
735 return 0;
738 if (obj = (Object *)DoSuperNew(cl,obj,
739 MUIA_HelpNode, helpNode,
740 MUIA_ShortHelp, getString(help),
741 MUIA_Group_Horiz, TRUE,
742 MUIA_Group_HorizSpacing, 2,
744 Child, ListviewObject,
745 MUIA_CycleChain, TRUE,
746 MUIA_Listview_DefClickColumn, 1,
747 MUIA_Listview_DragType, MUIV_Listview_DragType_Immediate,
748 MUIA_Listview_List, appl = listObject,
749 MUIA_ObjectID, id,
750 MUIA_AppList_NodeNameOffset, nameOfs,
751 MUIA_AppList_NodePathOffset, pathOfs,
752 MUIA_AppList_NodeSize, nodeSize,
753 End,
754 End,
756 Child, VGroup,
757 VirtualFrame,
758 MUIA_Background, MUII_GroupBack,
759 MUIA_Weight, 10,
761 Child, addb = obutton(MSG_AppList_Add,MSG_AppList_Add_Help),
762 Child, editb = obutton(MSG_AppList_Edit,MSG_AppList_Edit_Help),
763 Child, cloneb = obutton(MSG_AppList_Clone,MSG_AppList_Clone_Help),
764 Child, HGroup,
765 MUIA_Group_HorizSpacing, 1,
766 Child, upb = oibutton(IBT_Up,MSG_AppList_MoveUp_Help),
767 Child, downb = oibutton(IBT_Down,MSG_AppList_MoveDown_Help),
768 Child, disableb = otbutton(MSG_AppList_Disable,MSG_AppList_Disable_Help),
769 End,
770 Child, VSpace(0),
771 Child, deleteb = obutton(MSG_AppList_Delete,MSG_AppList_Delete_Help),
772 End,
774 TAG_MORE, msg->ops_AttrList))
776 struct data *data = INST_DATA(cl,obj);
778 /* init instance data */
779 data->appList = appl;
780 data->add = addb;
781 data->edit = editb;
782 data->clone = cloneb;
783 data->delete = deleteb;
784 data->disable = disableb;
785 data->up = upb;
786 data->down = downb;
788 data->nameOfs = nameOfs;
789 data->pathOfs = pathOfs;
790 data->nodeSize = nodeSize;
792 data->editClass = editWinClass;
793 data->editAttr = editWinAttr;
794 data->listAttr = listAttr;
795 data->newNodeName = nodeName;
797 /* listview */
798 DoMethod(appl,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,(ULONG)obj,1,MUIM_AppList_ActiveChanged);
799 DoMethod(appl,MUIM_Notify,MUIA_Listview_DoubleClick,MUIV_EveryTime,(ULONG)obj,2,MUIM_AppList_Edit,TRUE);
801 /* buttons */
802 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,TRUE,
803 (ULONG)editb,
804 (ULONG)cloneb,
805 (ULONG)deleteb,
806 (ULONG)disableb,
807 (ULONG)upb,
808 (ULONG)downb,
809 NULL);
811 /* list buttons */
812 DoMethod(addb,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_AppList_Add);
813 DoMethod(editb,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_AppList_Edit,FALSE);
814 DoMethod(cloneb,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_AppList_Clone);
815 DoMethod(deleteb,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_AppList_Delete);
816 DoMethod(disableb,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,(ULONG)obj,2,MUIM_AppList_Disable,MUIV_TriggerValue);
817 DoMethod(upb,MUIM_Notify,MUIA_Timer,MUIV_EveryTime,(ULONG)obj,2,MUIM_AppList_Move,TRUE);
818 DoMethod(downb,MUIM_Notify,MUIA_Timer,MUIV_EveryTime,(ULONG)obj,2,MUIM_AppList_Move,FALSE);
821 return (ULONG)obj;
824 /**************************************************************************/
826 ** I hate this: it will be removed asap!
829 static ULONG
830 mGet(struct IClass *cl,Object *obj,struct opGet *msg)
832 struct data *data = INST_DATA(cl,obj);
834 switch (msg->opg_AttrID)
836 case MUIA_AppList_ListObj: *msg->opg_Storage = (ULONG)data->appList; return TRUE;
837 default: return DoSuperMethodA(cl,obj,(Msg)msg);
841 /**************************************************************************/
843 static ULONG
844 mAdd(struct IClass *cl,Object *obj,Msg msg)
846 struct data *data = INST_DATA(cl,obj);
847 struct URL_Node *node;
849 if (!(node = AllocPooled(g_pool,data->nodeSize))) return FALSE;
851 memset(node,0,data->nodeSize);
852 strcpy((STRPTR)node+data->nameOfs,data->newNodeName);
854 node->Flags = UNF_NEW|UNF_NTALLOC;
856 DoMethod(data->appList,MUIM_List_InsertSingle,(ULONG)node,MUIV_List_Insert_Bottom);
858 set(data->appList,MUIA_List_Active,xget(data->appList,MUIA_List_InsertPosition));
860 DoMethod(obj,MUIM_AppList_Edit,FALSE);
862 return TRUE;
865 /**************************************************************************/
867 static ULONG
868 mEdit(struct IClass *cl,Object *obj,struct MUIP_AppList_Edit *msg)
870 struct data *data = INST_DATA(cl,obj);
871 struct URL_Node *node;
873 DoMethod(data->appList,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(ULONG)&node);
874 if (node)
876 if (msg->check && (xget(data->appList,MUIA_Listview_ClickColumn)==0))
878 set(data->appList,MUIA_Listview_ClickColumn,1);
880 if (node->Flags & UNF_DISABLED) node->Flags &= ~UNF_DISABLED;
881 else node->Flags |= UNF_DISABLED;
883 DoMethod(data->appList,MUIM_List_Redraw,xget(data->appList,MUIA_List_Active));
884 set(data->disable,MUIA_Selected,node->Flags & UNF_DISABLED);
886 else DoMethod(_app(obj),MUIM_App_OpenWin,(ULONG)data->editClass,data->editAttr,(ULONG)node,data->listAttr,(ULONG)data->appList,TAG_END);
889 return TRUE;
892 /**************************************************************************/
894 static ULONG
895 mClone(struct IClass *cl,Object *obj,Msg msg)
897 struct data *data = INST_DATA(cl,obj);
898 struct URL_Node *node;
899 ULONG active;
901 get(data->appList,MUIA_List_Active,&active);
902 DoMethod(data->appList,MUIM_List_GetEntry,active,(ULONG)&node);
903 if (node)
905 struct URL_Node *new;
907 if (!(new = AllocPooled(g_pool,data->nodeSize))) return FALSE;
908 CopyMem(node,new,data->nodeSize);
909 new->Flags |= UNF_NEW|UNF_NTALLOC;
911 DoMethod(data->appList,MUIM_List_InsertSingle,(ULONG)new,MUIV_List_Insert_Bottom);
912 set(data->appList,MUIA_List_Active,MUIV_List_Active_Bottom);
914 DoMethod(obj,MUIM_AppList_Edit,FALSE);
917 return TRUE;
920 /**************************************************************************/
922 static ULONG
923 mDelete(struct IClass *cl,Object *obj,Msg msg)
925 struct data *data = INST_DATA(cl,obj);
926 UBYTE *node;
927 ULONG active;
929 get(data->appList,MUIA_List_Active,&active);
930 DoMethod(data->appList,MUIM_List_GetEntry,active,(ULONG)&node);
931 if (node)
933 DoMethod(_app(obj),MUIM_App_CloseWin,data->editAttr,(ULONG)node);
934 DoMethod(data->appList,MUIM_List_Remove,active);
937 return TRUE;
940 /**************************************************************************/
942 static ULONG
943 mActiveChanged(struct IClass *cl,Object *obj,Msg msg)
945 struct data *data = INST_DATA(cl,obj);
946 LONG a;
948 a = (LONG)xget(data->appList,MUIA_List_Active);
949 if (a>=0)
951 struct URL_Node *node;
952 ULONG n;
954 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,FALSE,
955 (ULONG)data->edit,
956 (ULONG)data->clone,
957 (ULONG)data->delete,
958 (ULONG)data->disable,
959 NULL);
961 DoMethod(data->appList,MUIM_List_GetEntry,a,(ULONG)&node);
962 set(data->disable,MUIA_Selected,node->Flags & UNF_DISABLED);
964 if (a==0) SetAttrs(data->up,MUIA_Selected,FALSE,MUIA_Disabled,TRUE,TAG_DONE);
965 else set(data->up,MUIA_Disabled,FALSE);
967 n = xget(data->appList,MUIA_List_Entries);
968 if (n-1<=a) SetAttrs(data->down,MUIA_Selected,FALSE,MUIA_Disabled,TRUE,TAG_DONE);
969 else set(data->down,MUIA_Disabled,FALSE);
971 else
973 set(data->disable,MUIA_Selected,FALSE);
975 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,TRUE,
976 (ULONG)data->edit,
977 (ULONG)data->clone,
978 (ULONG)data->delete,
979 (ULONG)data->disable,
980 (ULONG)data->up,
981 (ULONG)data->down,
982 NULL);
985 return TRUE;
988 /**************************************************************************/
990 static ULONG
991 mDisable(struct IClass *cl,Object *obj,struct MUIP_AppList_Disable *msg)
993 struct data *data = INST_DATA(cl,obj);
994 struct URL_Node *node;
996 DoMethod(data->appList,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(ULONG)&node);
997 if (node)
999 if (!BOOLSAME(msg->disable,node->Flags & UNF_DISABLED))
1001 if (msg->disable) node->Flags |= UNF_DISABLED;
1002 else node->Flags &= ~UNF_DISABLED;
1004 DoMethod(data->appList,MUIM_List_Redraw,xget(data->appList,MUIA_List_Active));
1008 return TRUE;
1011 /**************************************************************************/
1013 static ULONG
1014 mMove(struct IClass *cl,Object *obj,struct MUIP_AppList_Move *msg)
1016 struct data *data = INST_DATA(cl,obj);
1018 DoMethod(data->appList,MUIM_List_Exchange,MUIV_List_Exchange_Active,msg->up ? MUIV_List_Exchange_Previous : MUIV_List_Exchange_Next);
1019 set(data->appList,MUIA_List_Active,msg->up ? MUIV_List_Active_Up : MUIV_List_Active_Down);
1021 return 0;
1024 /**************************************************************************/
1026 ** Forward to the list
1029 static ULONG
1030 mCheckSave(struct IClass *cl,Object *obj,Msg msg)
1032 struct data *data = INST_DATA(cl,obj);
1034 return DoMethod(data->appList,MUIM_App_CheckSave);
1037 /**************************************************************************/
1039 M_DISP(dispatcher)
1041 M_DISPSTART
1043 switch (msg->MethodID)
1045 case OM_NEW: return mNew(cl,obj,(APTR)msg);
1046 case OM_GET: return mGet(cl,obj,(APTR)msg);
1048 case MUIM_AppList_Add: return mAdd(cl,obj,(APTR)msg);
1049 case MUIM_AppList_Edit: return mEdit(cl,obj,(APTR)msg);
1050 case MUIM_AppList_Clone: return mClone(cl,obj,(APTR)msg);
1051 case MUIM_AppList_Delete: return mDelete(cl,obj,(APTR)msg);
1052 case MUIM_AppList_ActiveChanged: return mActiveChanged(cl,obj,(APTR)msg);
1053 case MUIM_AppList_Disable: return mDisable(cl,obj,(APTR)msg);
1054 case MUIM_AppList_Move: return mMove(cl,obj,(APTR)msg);
1055 case MUIM_App_CheckSave: return mCheckSave(cl,obj,(APTR)msg);
1057 default: return DoSuperMethodA(cl,obj,msg);
1061 M_DISPEND(dispatcher)
1063 /**************************************************************************/
1065 ULONG
1066 initAppListClass(void)
1068 if (initListClass())
1070 if (g_appListClass = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct data),DISP(dispatcher)))
1072 initLampClass();
1074 return TRUE;
1077 disposeListClass();
1080 return FALSE;
1083 /**************************************************************************/
1085 void
1086 disposeAppListClass(void)
1088 disposeLampClass();
1089 disposeListClass();
1090 if (g_appListClass) MUI_DeleteCustomClass(g_appListClass);
1093 /**************************************************************************/