revert between 56095 -> 55830 in arch
[AROS.git] / external / openurl / prefs / applist.c
blobad669b35ce6c44551ec80ab0fccce9b4faf744f4
1 /***************************************************************************
3 openurl.library - universal URL display and browser launcher library
4 Copyright (C) 1998-2005 by Troels Walsted Hansen, et al.
5 Copyright (C) 2005-2013 by openurl.library Open Source Team
7 This library is free software; it has been placed in the public domain
8 and you can freely redistribute it and/or modify it. Please note, however,
9 that some components may be under the LGPL or GPL license.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 openurl.library project: http://sourceforge.net/projects/openurllib/
17 $Id$
19 ***************************************************************************/
21 #include "openurl.h"
23 #define CATCOMP_NUMBERS
24 #include "locale.h"
25 #include "macros.h"
27 #include <libraries/openurl.h>
28 #include <stdio.h>
30 #include "SDI_hook.h"
32 #include "debug.h"
34 /**************************************************************************/
36 ** Little lamp class for enabled/disabled
39 static struct MUI_CustomClass *lampClass = NULL;
40 #define lampObject NewObject(lampClass->mcc_Class,NULL
42 struct lampData
44 LONG enabled;
45 LONG disabled;
46 LONG detail;
47 WORD delta;
49 ULONG flags;
52 enum
54 FLG_LampSetup = 1<<0,
55 FLG_LampDisabled = 1<<1,
58 /***********************************************************************/
60 static IPTR mLampNew(struct IClass *cl, Object *obj, struct opSet *msg)
62 return (IPTR)DoSuperNew(cl,obj,
63 MUIA_Font, MUIV_Font_List,
64 TAG_MORE, msg->ops_AttrList);
67 /**************************************************************************/
69 static IPTR mLampSets(struct IClass *cl, Object *obj, struct opSet *msg)
71 struct lampData *data = INST_DATA(cl,obj);
72 struct TagItem *tag;
74 if((tag = FindTagItem(MUIA_Lamp_Disabled,msg->ops_AttrList)))
76 if (tag->ti_Data)
77 SET_FLAG(data->flags, FLG_LampDisabled);
78 else
79 CLEAR_FLAG(data->flags, FLG_LampDisabled);
81 /* Of course, we don't redraw here */
84 return DoSuperMethodA(cl,obj,(Msg)msg);
87 /***********************************************************************/
89 static IPTR mLampSetup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
91 struct lampData *data = INST_DATA(cl,obj);
92 if (!DoSuperMethodA(cl,obj,(APTR)msg)) return FALSE;
94 if (MUIMasterBase->lib_Version<20)
96 data->enabled = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"r00000000,ffffffff,00000000",0);
97 data->disabled = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"rffffffff,00000000,00000000",0);
98 data->detail = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"r00000000,00000000,00000000",0);
100 else
102 data->enabled = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"r02ff00",0);
103 data->disabled = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"rff0000",0);
104 data->detail = MUI_ObtainPen(muiRenderInfo(obj),(APTR)"r000000",0);
107 SET_FLAG(data->flags, FLG_LampSetup);
109 return TRUE;
112 /***********************************************************************/
114 static IPTR mLampCleanup(struct IClass *cl,Object *obj,struct MUIP_Setup *msg)
116 struct lampData *data = INST_DATA(cl,obj);
118 if(isFlagSet(data->flags, FLG_LampSetup))
120 MUI_ReleasePen(muiRenderInfo(obj),data->enabled);
121 MUI_ReleasePen(muiRenderInfo(obj),data->disabled);
122 MUI_ReleasePen(muiRenderInfo(obj),data->detail);
124 CLEAR_FLAG(data->flags, FLG_LampSetup);
127 return DoSuperMethodA(cl,obj,(APTR)msg);
130 /***********************************************************************/
132 static IPTR mLampAskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
134 struct lampData *data = INST_DATA(cl,obj);
135 struct RastPort rp;
136 struct TextExtent te;
137 UWORD w, h, d;
139 DoSuperMethodA(cl,obj,(APTR)msg);
141 CopyMem(&_screen(obj)->RastPort,&rp,sizeof(rp));
143 /* Don't ask or modify ! */
145 SetFont(&rp,_font(obj));
146 TextExtent(&rp," ",2,&te);
148 w = te.te_Width;
149 h = te.te_Height;
151 if (w>=h) d = w;
152 else d = h;
154 data->delta = te.te_Extent.MinY;
156 msg->MinMaxInfo->MinWidth += d;
157 msg->MinMaxInfo->MinHeight += h;
158 msg->MinMaxInfo->DefWidth += d;
159 msg->MinMaxInfo->DefHeight += h;
160 msg->MinMaxInfo->MaxWidth += d;
161 msg->MinMaxInfo->MaxHeight += h;
163 return 0;
166 /***********************************************************************/
168 static IPTR mLampDraw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
170 struct lampData *data = INST_DATA(cl,obj);
171 IPTR res;
173 res = DoSuperMethodA(cl,obj,(APTR)msg);
175 if(hasFlag(msg->flags, (MADF_DRAWOBJECT|MADF_DRAWUPDATE)))
177 WORD l, t, r, b;
179 /* Don't ask or modify ! */
181 l = _mleft(obj);
182 r = _mright(obj);
183 t = _mtop(obj)+(_mheight(obj)+data->delta)/2-1;
184 b = t-data->delta;
186 if (r-l>2)
188 l += 1;
189 r -= 1;
192 if (b-t>2)
194 t += 1;
195 b -= 1;
198 SetAPen(_rp(obj), MUIPEN(isFlagSet(data->flags, FLG_LampDisabled) ? data->disabled : data->enabled));
199 RectFill(_rp(obj),l,t,r,b);
201 SetAPen(_rp(obj),MUIPEN(data->detail));
202 Move(_rp(obj),l,t);
203 Draw(_rp(obj),r,t);
204 Draw(_rp(obj),r,b);
205 Draw(_rp(obj),l,b);
206 Draw(_rp(obj),l,t);
209 return res;
212 /***********************************************************************/
214 SDISPATCHER(lampDispatcher)
216 switch(msg->MethodID)
218 case OM_NEW: return mLampNew(cl,obj,(APTR)msg);
219 case OM_SET: return mLampSets(cl,obj,(APTR)msg);
221 case MUIM_Setup: return mLampSetup(cl,obj,(APTR)msg);
222 case MUIM_Cleanup: return mLampCleanup(cl,obj,(APTR)msg);
223 case MUIM_AskMinMax: return mLampAskMinMax(cl,obj,(APTR)msg);
224 case MUIM_Draw: return mLampDraw(cl,obj,(APTR)msg);
226 default: return DoSuperMethodA(cl,obj,msg);
230 /***********************************************************************/
232 static BOOL initLampClass(void)
234 BOOL success = FALSE;
236 ENTER();
238 if((lampClass = MUI_CreateCustomClass(NULL, MUIC_Rectangle, NULL, sizeof(struct lampData), ENTRY(lampDispatcher))) != NULL)
239 success = TRUE;
241 RETURN(success);
242 return success;
245 /**************************************************************************/
247 static void disposeLampClass(void)
249 if(lampClass != NULL)
250 MUI_DeleteCustomClass(lampClass);
253 /**************************************************************************/
255 ** List of clients with lamps
258 static struct MUI_CustomClass *listClass = NULL;
259 #define listObject NewObject(listClass->mcc_Class,NULL
261 struct listData
263 Object *olamp;
264 APTR lamp;
265 TEXT col0buf[NAME_LEN+16];
267 ULONG nameOfs;
268 ULONG pathOfs;
269 ULONG nodeSize;
271 TEXT format[64];
273 ULONG flags;
275 struct Hook conHook;
276 struct Hook desHook;
277 struct Hook dispHook;
280 enum
282 FLG_ListSetup = 1<<0,
285 /* Used for Import/Export */
286 struct listIO
288 ULONG len;
289 TEXT format[64];
292 /**************************************************************************/
294 HOOKPROTO(conFunc, struct URL_Node *, APTR pool, struct URL_Node *node)
296 struct listData *data = hook->h_Data;
297 struct URL_Node *new;
299 if(isFlagSet(node->Flags, UNF_NTALLOC))
301 new = node;
302 CLEAR_FLAG(node->Flags, UNF_NTALLOC);
304 else if((new = AllocPooled(pool,data->nodeSize)) != NULL)
305 CopyMem(node, new, data->nodeSize);
307 return new;
309 MakeStaticHook(conHook, conFunc);
311 /**************************************************************************/
313 HOOKPROTO(desFunc, void, APTR pool, struct URL_Node *node)
315 struct listData *data = hook->h_Data;
317 FreePooled(pool,node,data->nodeSize);
319 MakeStaticHook(desHook, desFunc);
321 /**************************************************************************/
323 HOOKPROTO(dispFunc, void, STRPTR *array, struct URL_Node *node)
325 struct listData *data = hook->h_Data;
327 if (node)
329 if (data->lamp)
331 set(data->olamp, MUIA_Lamp_Disabled, isFlagSet(node->Flags, UNF_DISABLED));
332 #if defined(__LP64__)
333 sprintf(data->col0buf,"\33O[%016lx]", (IPTR)data->lamp);
334 #else
335 sprintf(data->col0buf,"\33O[%08lx]", (IPTR)data->lamp);
336 #endif
337 *array++ = data->col0buf;
339 else
340 *array++ = (STRPTR)(isFlagSet(node->Flags, UNF_DISABLED) ? " " : ">");
342 *array++ = (STRPTR)node+data->nameOfs;
343 *array = (STRPTR)node+data->pathOfs;
345 else
347 *array++ = (STRPTR)" ";
348 *array++ = getString(MSG_Edit_ListName);
349 *array = getString(MSG_Edit_ListPath);
352 MakeStaticHook(dispHook, dispFunc);
354 /**************************************************************************/
356 static IPTR mListNew(struct IClass *cl, Object *obj, struct opSet *msg)
358 if((obj = (Object *)DoSuperNew(cl,obj,
359 InputListFrame,
360 MUIA_List_Title, TRUE,
361 MUIA_List_Format, "C=0,C=1,C=2",
362 MUIA_List_DragSortable, TRUE,
363 MUIA_List_Pool, g_pool,
364 MUIA_List_DragSortable, TRUE,
365 MUIA_List_ShowDropMarks, TRUE,
366 TAG_MORE, msg->ops_AttrList)) != NULL)
368 struct listData *data = INST_DATA(cl,obj);
370 // the hooks make use of the instance data and hence must not
371 // put the data pointer into the global hook definitions
372 InitHook(&data->conHook, conHook, data);
373 InitHook(&data->desHook, desHook, data);
374 InitHook(&data->dispHook, dispHook, data);
376 // now tell the list object to use the local hooks
377 set(obj, MUIA_List_ConstructHook, &data->conHook);
378 set(obj, MUIA_List_DestructHook, &data->desHook);
379 set(obj, MUIA_List_DisplayHook, &data->dispHook);
381 data->nameOfs = GetTagData(MUIA_AppList_NodeNameOffset,0,msg->ops_AttrList);
382 data->pathOfs = GetTagData(MUIA_AppList_NodePathOffset,0,msg->ops_AttrList);
383 data->nodeSize = GetTagData(MUIA_AppList_NodeSize,0,msg->ops_AttrList);
385 strlcpy(data->format,"C=0,C=1,C=2", sizeof(data->format));
387 if (lampClass) data->olamp = lampObject, End;
391 return (IPTR)obj;
394 /**************************************************************************/
396 static IPTR mListDispose(struct IClass *cl, Object *obj, Msg msg)
398 struct listData *data = INST_DATA(cl,obj);
400 if (data->olamp) MUI_DisposeObject(data->olamp);
402 return DoSuperMethodA(cl,obj,msg);
405 /**************************************************************************/
407 static IPTR mListSetup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
409 IPTR result = FALSE;
411 ENTER();
413 if(DoSuperMethodA(cl, obj, (APTR)msg))
415 struct listData *data = INST_DATA(cl, obj);
417 if(isFlagClear(data->flags, FLG_ListSetup))
419 /* After thinking about that hard, I decided to use the lamp in >=8 color screen */
420 if(data->olamp != NULL && GetBitMapAttr(_screen(obj)->RastPort.BitMap, BMA_DEPTH) > 3)
421 data->lamp = (APTR)DoSuperMethod(cl, obj, MUIM_List_CreateImage, (IPTR)data->olamp, 0);
423 SET_FLAG(data->flags, FLG_ListSetup);
425 result = TRUE;
429 RETURN(result);
430 return result;
433 /***********************************************************************/
435 static IPTR mListCleanup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
437 IPTR result;
438 struct listData *data = INST_DATA(cl, obj);
440 ENTER();
442 if(isFlagSet(data->flags, FLG_ListSetup))
444 if(data->lamp != NULL)
446 DoSuperMethod(cl, obj, MUIM_List_DeleteImage, (IPTR)data->lamp);
447 data->lamp = NULL;
450 CLEAR_FLAG(data->flags, FLG_ListSetup);
453 result = DoSuperMethodA(cl, obj, (APTR)msg);
455 RETURN(result);
456 return(result);
459 /***********************************************************************/
461 ** Import format
464 static IPTR mListImport(struct IClass *cl, Object *obj, struct MUIP_Import *msg)
466 ULONG id;
468 if(MUIMasterBase->lib_Version < 20)
469 return 0;
471 if((id = (muiNotifyData(obj)->mnd_ObjectID)) != 0)
473 struct listIO *io;
475 if((io = (struct listIO *)DoMethod(msg->dataspace,MUIM_Dataspace_Find, id)) != NULL)
477 struct listData *data = INST_DATA(cl,obj);
479 strlcpy(data->format, io->format, sizeof(data->format));
480 set(obj,MUIA_List_Format,data->format);
484 return 0;
487 /***********************************************************************/
489 ** Export format
492 static IPTR mListExport(UNUSED struct IClass *cl, Object *obj, struct MUIP_Import *msg)
494 ULONG id;
496 if(MUIMasterBase->lib_Version < 20)
497 return 0;
499 if((id = (muiNotifyData(obj)->mnd_ObjectID)) != 0)
501 struct listIO io;
502 STRPTR f;
504 if((f = (STRPTR)xget(obj, MUIA_List_Format)) != NULL)
506 io.len = strlen(f)+1;
507 strlcpy(io.format, f, sizeof(io.format));
509 DoMethod(msg->dataspace,MUIM_Dataspace_Add,(IPTR)&io,sizeof(ULONG)+io.len,id);
513 return 0;
516 /**************************************************************************/
518 ** Check if format changed
521 static IPTR mListCheckSave(struct IClass *cl, Object *obj, UNUSED Msg msg)
523 struct listData *data = INST_DATA(cl,obj);
524 STRPTR f;
526 if((f = (STRPTR)xget(obj, MUIA_List_Format)) != NULL)
527 return (IPTR)strcmp(f,(STRPTR)&data->format);
528 else
529 return 0;
532 /**************************************************************************/
534 SDISPATCHER(listDispatcher)
536 switch (msg->MethodID)
538 case OM_NEW: return mListNew(cl,obj,(APTR)msg);
539 case OM_DISPOSE: return mListDispose(cl,obj,(APTR)msg);
541 case MUIM_Setup: return mListSetup(cl,obj,(APTR)msg);
542 case MUIM_Cleanup: return mListCleanup(cl,obj,(APTR)msg);
543 case MUIM_Import: return mListImport(cl,obj,(APTR)msg);
544 case MUIM_Export: return mListExport(cl,obj,(APTR)msg);
546 case MUIM_App_CheckSave: return mListCheckSave(cl,obj,(APTR)msg);
548 default: return DoSuperMethodA(cl,obj,msg);
552 /**************************************************************************/
554 static BOOL initListClass(void)
556 BOOL success = FALSE;
558 ENTER();
560 if((listClass = MUI_CreateCustomClass(NULL, MUIC_List, NULL, sizeof(struct listData), ENTRY(listDispatcher))) != NULL)
561 success = TRUE;
563 RETURN(success);
564 return success;
567 /**************************************************************************/
569 static void disposeListClass(void)
571 if(listClass != NULL)
572 MUI_DeleteCustomClass(listClass);
575 /**************************************************************************/
577 struct data
579 Object *appList;
580 Object *add;
581 Object *edit;
582 Object *clone;
583 Object *delete;
584 Object *disable;
585 Object *up;
586 Object *down;
588 ULONG nameOfs;
589 ULONG pathOfs;
590 ULONG nodeSize;
591 struct IClass *editClass;
592 ULONG editAttr;
593 ULONG listAttr;
595 STRPTR newNodeName;
598 /**************************************************************************/
600 static IPTR mNew(struct IClass *cl, Object *obj, struct opSet *msg)
602 Object *appl, *addb, *editb, *cloneb, *deleteb, *disableb, *upb, *downb;
603 struct IClass *editWinClass;
604 STRPTR nodeName;
605 CONST_STRPTR helpNode;
606 ULONG nameOfs, pathOfs, nodeSize, editWinAttr, listAttr, help, id;
608 /* What we are */
609 switch (GetTagData(MUIA_AppList_Type,0,msg->ops_AttrList))
611 case MUIV_AppList_Type_Browser:
612 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
613 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
614 nodeSize = sizeof(struct URL_BrowserNode);
615 editWinClass = g_browserEditWinClass->mcc_Class;
616 editWinAttr = MUIA_BrowserEditWin_Browser;
617 listAttr = MUIA_BrowserEditWin_ListObj;
618 nodeName = getString(MSG_Browser_NewBrowser);
619 helpNode = "BROWSER";
620 help = MSG_Browser_List_Help;
621 id = MAKE_ID('B','L','S','T');
622 break;
624 case MUIV_AppList_Type_Mailer:
625 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
626 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
627 nodeSize = sizeof(struct URL_MailerNode);
628 editWinClass = g_mailerEditWinClass->mcc_Class;
629 editWinAttr = MUIA_MailerEditWin_Mailer;
630 listAttr = MUIA_MailerEditWin_ListObj;
631 nodeName = getString(MSG_Mailer_NewMailer);
632 helpNode = "MAILERS";
633 help = MSG_Mailer_List_Help;
634 id = MAKE_ID('M','L','S','T');
635 break;
637 case MUIV_AppList_Type_FTP:
638 nameOfs = sizeof(struct MinNode) + sizeof(ULONG);
639 pathOfs = sizeof(struct MinNode) + sizeof(ULONG) + NAME_LEN;
640 nodeSize = sizeof(struct URL_FTPNode);
641 editWinClass = g_FTPEditWinClass->mcc_Class;
642 editWinAttr = MUIA_FTPEditWin_FTP;
643 listAttr = MUIA_FTPEditWin_ListObj;
644 nodeName = getString(MSG_FTP_NewFTP);
645 helpNode = "FTPS";
646 help = MSG_FTP_List_Help;
647 id = MAKE_ID('F','L','S','T');
648 break;
650 default:
651 return 0;
654 if((obj = (Object *)DoSuperNew(cl,obj,
655 MUIA_HelpNode, helpNode,
656 MUIA_ShortHelp, getString(help),
657 MUIA_Group_Horiz, TRUE,
658 MUIA_Group_HorizSpacing, 2,
660 Child, ListviewObject,
661 MUIA_CycleChain, TRUE,
662 MUIA_Listview_DefClickColumn, 1,
663 MUIA_Listview_DragType, MUIV_Listview_DragType_Immediate,
664 MUIA_Listview_List, appl = listObject,
665 MUIA_ObjectID, id,
666 MUIA_AppList_NodeNameOffset, nameOfs,
667 MUIA_AppList_NodePathOffset, pathOfs,
668 MUIA_AppList_NodeSize, nodeSize,
669 End,
670 End,
672 Child, VGroup,
673 //VirtualFrame,
674 //MUIA_Background, MUII_GroupBack,
675 MUIA_Group_VertSpacing, 2,
676 MUIA_Weight, 0,
678 Child, addb = obutton(MSG_AppList_Add,MSG_AppList_Add_Help),
679 Child, editb = obutton(MSG_AppList_Edit,MSG_AppList_Edit_Help),
680 Child, cloneb = obutton(MSG_AppList_Clone,MSG_AppList_Clone_Help),
681 Child, deleteb = obutton(MSG_AppList_Delete,MSG_AppList_Delete_Help),
682 Child, HGroup,
683 MUIA_Group_HorizSpacing, 1,
684 Child, upb = oibutton(IBT_Up,MSG_AppList_MoveUp_Help),
685 Child, downb = oibutton(IBT_Down,MSG_AppList_MoveDown_Help),
686 Child, disableb = otbutton(MSG_AppList_Disable,MSG_AppList_Disable_Help),
687 End,
688 Child, VSpace(0),
689 End,
691 TAG_MORE, msg->ops_AttrList)) != NULL)
693 struct data *data = INST_DATA(cl,obj);
695 /* init instance data */
696 data->appList = appl;
697 data->add = addb;
698 data->edit = editb;
699 data->clone = cloneb;
700 data->delete = deleteb;
701 data->disable = disableb;
702 data->up = upb;
703 data->down = downb;
705 data->nameOfs = nameOfs;
706 data->pathOfs = pathOfs;
707 data->nodeSize = nodeSize;
709 data->editClass = editWinClass;
710 data->editAttr = editWinAttr;
711 data->listAttr = listAttr;
712 data->newNodeName = nodeName;
714 /* listview */
715 DoMethod(appl,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,(IPTR)obj,1,MUIM_AppList_ActiveChanged);
716 DoMethod(appl,MUIM_Notify,MUIA_Listview_DoubleClick,MUIV_EveryTime,(IPTR)obj,2,MUIM_AppList_Edit,TRUE);
718 /* buttons */
719 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,TRUE,
720 (IPTR)editb,
721 (IPTR)cloneb,
722 (IPTR)deleteb,
723 (IPTR)disableb,
724 (IPTR)upb,
725 (IPTR)downb,
726 NULL);
728 /* list buttons */
729 DoMethod(addb,MUIM_Notify,MUIA_Pressed,FALSE,(IPTR)obj,1,MUIM_AppList_Add);
730 DoMethod(editb,MUIM_Notify,MUIA_Pressed,FALSE,(IPTR)obj,1,MUIM_AppList_Edit,FALSE);
731 DoMethod(cloneb,MUIM_Notify,MUIA_Pressed,FALSE,(IPTR)obj,1,MUIM_AppList_Clone);
732 DoMethod(deleteb,MUIM_Notify,MUIA_Pressed,FALSE,(IPTR)obj,1,MUIM_AppList_Delete);
733 DoMethod(disableb,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,(IPTR)obj,2,MUIM_AppList_Disable,MUIV_TriggerValue);
734 DoMethod(upb,MUIM_Notify,MUIA_Timer,MUIV_EveryTime,(IPTR)obj,2,MUIM_AppList_Move,TRUE);
735 DoMethod(downb,MUIM_Notify,MUIA_Timer,MUIV_EveryTime,(IPTR)obj,2,MUIM_AppList_Move,FALSE);
738 return (IPTR)obj;
741 /**************************************************************************/
743 ** I hate this: it will be removed asap!
746 static IPTR mGet(struct IClass *cl, Object *obj, struct opGet *msg)
748 struct data *data = INST_DATA(cl,obj);
750 switch (msg->opg_AttrID)
752 case MUIA_AppList_ListObj: *msg->opg_Storage = (IPTR)data->appList; return TRUE;
753 default: return DoSuperMethodA(cl,obj,(Msg)msg);
757 /**************************************************************************/
759 static IPTR mAdd(struct IClass *cl, Object *obj, UNUSED Msg msg)
761 struct data *data = INST_DATA(cl,obj);
762 struct URL_Node *node;
764 if (!(node = AllocPooled(g_pool,data->nodeSize))) return FALSE;
766 memset(node,0,data->nodeSize);
767 strcpy((STRPTR)node+data->nameOfs,data->newNodeName);
769 node->Flags = UNF_NEW|UNF_NTALLOC;
771 DoMethod(data->appList,MUIM_List_InsertSingle,(IPTR)node,MUIV_List_Insert_Bottom);
773 set(data->appList,MUIA_List_Active,xget(data->appList,MUIA_List_InsertPosition));
775 DoMethod(obj,MUIM_AppList_Edit,FALSE);
777 return TRUE;
780 /**************************************************************************/
782 static IPTR mEdit(struct IClass *cl, Object *obj, struct MUIP_AppList_Edit *msg)
784 struct data *data = INST_DATA(cl,obj);
785 struct URL_Node *node;
787 DoMethod(data->appList,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(IPTR)&node);
788 if (node)
790 if (msg->check && (xget(data->appList,MUIA_Listview_ClickColumn)==0))
792 set(data->appList,MUIA_Listview_ClickColumn,1);
794 if(isFlagSet(node->Flags, UNF_DISABLED))
795 CLEAR_FLAG(node->Flags, UNF_DISABLED);
796 else
797 SET_FLAG(node->Flags, UNF_DISABLED);
799 DoMethod(data->appList, MUIM_List_Redraw, xget(data->appList, MUIA_List_Active));
800 set(data->disable, MUIA_Selected, isFlagSet(node->Flags, UNF_DISABLED));
802 else
803 DoMethod(_app(obj),MUIM_App_OpenWin,(IPTR)data->editClass,data->editAttr,(IPTR)node,data->listAttr,(IPTR)data->appList,TAG_END);
806 return TRUE;
809 /**************************************************************************/
811 static IPTR mClone(struct IClass *cl, Object *obj, UNUSED Msg msg)
813 ULONG success = FALSE;
814 struct data *data = INST_DATA(cl,obj);
815 struct URL_Node *node;
816 ULONG active;
818 active = xget(data->appList, MUIA_List_Active);
819 DoMethod(data->appList, MUIM_List_GetEntry, active, (IPTR)&node);
820 if(node != NULL)
822 struct URL_Node *new;
824 if((new = AllocPooled(g_pool, data->nodeSize)) != NULL)
826 CopyMem(node, new, data->nodeSize);
827 new->Flags = UNF_NEW|UNF_NTALLOC;
829 DoMethod(data->appList, MUIM_List_InsertSingle, (IPTR)new, MUIV_List_Insert_Bottom);
830 set(data->appList, MUIA_List_Active, MUIV_List_Active_Bottom);
832 DoMethod(obj, MUIM_AppList_Edit, FALSE);
834 success = TRUE;
838 return success;
841 /**************************************************************************/
843 static IPTR mDelete(struct IClass *cl, Object *obj, UNUSED Msg msg)
845 struct data *data = INST_DATA(cl,obj);
846 UBYTE *node;
847 ULONG active;
849 active = xget(data->appList,MUIA_List_Active);
850 DoMethod(data->appList,MUIM_List_GetEntry,active,(IPTR)&node);
851 if (node)
853 DoMethod(_app(obj),MUIM_App_CloseWin,data->editAttr,(IPTR)node);
854 DoMethod(data->appList,MUIM_List_Remove,active);
857 return TRUE;
860 /**************************************************************************/
862 static IPTR mActiveChanged(struct IClass *cl, Object *obj, UNUSED Msg msg)
864 struct data *data = INST_DATA(cl,obj);
865 LONG a;
867 a = (LONG)xget(data->appList,MUIA_List_Active);
868 if (a>=0)
870 struct URL_Node *node;
871 LONG n;
873 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,FALSE,
874 (IPTR)data->edit,
875 (IPTR)data->clone,
876 (IPTR)data->delete,
877 (IPTR)data->disable,
878 NULL);
880 DoMethod(data->appList,MUIM_List_GetEntry,a,(IPTR)&node);
881 set(data->disable, MUIA_Selected, isFlagSet(node->Flags, UNF_DISABLED));
883 if (a==0) SetAttrs(data->up,MUIA_Selected,FALSE,MUIA_Disabled,TRUE,TAG_DONE);
884 else set(data->up,MUIA_Disabled,FALSE);
886 n = xget(data->appList,MUIA_List_Entries);
887 if (n-1<=a) SetAttrs(data->down,MUIA_Selected,FALSE,MUIA_Disabled,TRUE,TAG_DONE);
888 else set(data->down,MUIA_Disabled,FALSE);
890 else
892 set(data->disable,MUIA_Selected,FALSE);
894 DoMethod(obj,MUIM_MultiSet,MUIA_Disabled,TRUE,
895 (IPTR)data->edit,
896 (IPTR)data->clone,
897 (IPTR)data->delete,
898 (IPTR)data->disable,
899 (IPTR)data->up,
900 (IPTR)data->down,
901 NULL);
904 return TRUE;
907 /**************************************************************************/
909 static IPTR mDisable(struct IClass *cl, Object *obj, struct MUIP_AppList_Disable *msg)
911 struct data *data = INST_DATA(cl,obj);
912 struct URL_Node *node;
914 DoMethod(data->appList,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(IPTR)&node);
915 if (node)
917 if (!BOOLSAME(msg->disable, isFlagSet(node->Flags, UNF_DISABLED)))
919 if(msg->disable)
920 SET_FLAG(node->Flags, UNF_DISABLED);
921 else
922 CLEAR_FLAG(node->Flags, UNF_DISABLED);
924 DoMethod(data->appList,MUIM_List_Redraw,xget(data->appList,MUIA_List_Active));
928 return TRUE;
931 /**************************************************************************/
933 static IPTR mMove(struct IClass *cl, Object *obj, struct MUIP_AppList_Move *msg)
935 struct data *data = INST_DATA(cl,obj);
937 DoMethod(data->appList,MUIM_List_Exchange,MUIV_List_Exchange_Active,msg->up ? MUIV_List_Exchange_Previous : MUIV_List_Exchange_Next);
938 set(data->appList,MUIA_List_Active,msg->up ? MUIV_List_Active_Up : MUIV_List_Active_Down);
940 return 0;
943 /**************************************************************************/
945 ** Forward to the list
948 static IPTR mCheckSave(struct IClass *cl, Object *obj, UNUSED Msg msg)
950 struct data *data = INST_DATA(cl,obj);
952 return DoMethod(data->appList,MUIM_App_CheckSave);
955 /**************************************************************************/
957 SDISPATCHER(dispatcher)
959 switch (msg->MethodID)
961 case OM_NEW: return mNew(cl,obj,(APTR)msg);
962 case OM_GET: return mGet(cl,obj,(APTR)msg);
964 case MUIM_AppList_Add: return mAdd(cl,obj,(APTR)msg);
965 case MUIM_AppList_Edit: return mEdit(cl,obj,(APTR)msg);
966 case MUIM_AppList_Clone: return mClone(cl,obj,(APTR)msg);
967 case MUIM_AppList_Delete: return mDelete(cl,obj,(APTR)msg);
968 case MUIM_AppList_ActiveChanged: return mActiveChanged(cl,obj,(APTR)msg);
969 case MUIM_AppList_Disable: return mDisable(cl,obj,(APTR)msg);
970 case MUIM_AppList_Move: return mMove(cl,obj,(APTR)msg);
971 case MUIM_App_CheckSave: return mCheckSave(cl,obj,(APTR)msg);
973 default: return DoSuperMethodA(cl,obj,msg);
977 /**************************************************************************/
979 BOOL initAppListClass(void)
981 BOOL success = FALSE;
983 ENTER();
985 if(initListClass() == TRUE)
987 if((g_appListClass = MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct data), ENTRY(dispatcher))) != NULL)
989 initLampClass();
990 success = TRUE;
992 else
993 disposeListClass();
996 RETURN(success);
997 return success;
1000 /**************************************************************************/
1002 void disposeAppListClass(void)
1004 ENTER();
1006 disposeLampClass();
1007 disposeListClass();
1008 if(g_appListClass != NULL)
1009 MUI_DeleteCustomClass(g_appListClass);
1011 LEAVE();
1014 /**************************************************************************/