Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / zune_gui / pluginlist.c
blob5f321a17186d7351e343f883f5d7b529803e32a1
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "diskimagegui.h"
28 #include <proto/exec.h>
29 #include <proto/intuition.h>
30 #include <proto/muimaster.h>
31 #include <clib/alib_protos.h>
32 #include <SDI_hook.h>
34 #define PLUG_COL_FMT "MINWIDTH=16 BAR,P=\33r BAR,BAR,"
35 enum {
36 PLUG_COL_ICON,
37 PLUG_COL_PRI,
38 PLUG_COL_WRITE,
39 PLUG_COL_NAME,
40 PLUG_COL_MAX
43 enum {
44 PLUG_ICO_PLUGIN,
45 PLUG_ICO_CHECKMARK,
46 PLUG_ICO_MAX
49 struct PluginListData {
50 Object *image[PLUG_ICO_MAX];
51 IPTR handle[PLUG_ICO_MAX];
54 static CONST CONST_STRPTR image_name[PLUG_ICO_MAX] = {
55 "Plugin",
56 "Checkmark"
59 static TEXT image_path[PLUG_ICO_MAX][IMG_PATH_LEN];
61 static TEXT image_str[PLUG_ICO_MAX][16];
63 DISPATCHERPROTO(PluginList_Dispatch);
65 struct MUI_CustomClass *PluginList_CreateClass (void) {
66 return MUI_CreateCustomClass(NULL, MUIC_List, NULL, sizeof(struct PluginListData),
67 ENTRY(PluginList_Dispatch));
70 void PluginList_FreeClass (struct MUI_CustomClass *cl) {
71 MUI_DeleteCustomClass(cl);
74 static IPTR PluginList_New(Class *cl, Object *o, struct opSet *ops);
75 static IPTR PluginList_Setup(Class *cl, Object *o, Msg msg);
76 static IPTR PluginList_Cleanup(Class *cl, Object *o, Msg msg);
78 DISPATCHER(PluginList_Dispatch) {
79 switch (msg->MethodID) {
80 case OM_NEW: return PluginList_New(cl, obj, (struct opSet *)msg);
81 case MUIM_Setup: return PluginList_Setup(cl, obj, msg);
82 case MUIM_Cleanup: return PluginList_Cleanup(cl, obj, msg);
84 return DoSuperMethodA(cl, obj, msg);
87 HOOKPROTO(PluginList_ConstructFunc, IPTR, APTR pool, struct PluginEntry *e);
88 MakeStaticHook(PluginList_ConstructHook, PluginList_ConstructFunc);
89 HOOKPROTO(PluginList_DestructFunc, IPTR, APTR pool, struct PluginEntry *e);
90 MakeStaticHook(PluginList_DestructHook, PluginList_DestructFunc);
91 HOOKPROTO(PluginList_CompareFunc, IPTR, const struct PluginEntry *e2, const struct PluginEntry *e1);
92 MakeStaticHook(PluginList_CompareHook, PluginList_CompareFunc);
93 HOOKPROTO(PluginList_DisplayFunc, IPTR, CONST_STRPTR *array, struct PluginEntry *e);
94 MakeStaticHook(PluginList_DisplayHook, PluginList_DisplayFunc);
96 static IPTR PluginList_New(Class *cl, Object *o, struct opSet *ops) {
97 Object *res;
98 struct TagItem tags[] = {
99 { MUIA_List_Title, TRUE },
100 { MUIA_List_Format, (IPTR)PLUG_COL_FMT },
101 { MUIA_List_ConstructHook, (IPTR)&PluginList_ConstructHook },
102 { MUIA_List_DestructHook, (IPTR)&PluginList_DestructHook },
103 { MUIA_List_CompareHook, (IPTR)&PluginList_CompareHook },
104 { MUIA_List_DisplayHook, (IPTR)&PluginList_DisplayHook },
105 { TAG_MORE, (IPTR)ops->ops_AttrList }
107 ops->ops_AttrList = tags;
108 res = (Object *)DoSuperMethodA(cl, o, (Msg)ops);
109 ops->ops_AttrList = (struct TagItem *)tags[6].ti_Data;
110 return (IPTR)res;
113 static IPTR PluginList_Setup(Class *cl, Object *o, Msg msg) {
114 struct PluginListData *data = INST_DATA(cl, o);
115 int i;
116 if (!DoSuperMethodA(cl, o, msg)) {
117 return FALSE;
119 for (i = 0; i < PLUG_ICO_MAX; i++) {
120 data->image[i] = LoadImage(image_name[i], image_path[i], NULL);
121 if (data->image[i]) {
122 data->handle[i] = DoMethod(o, MUIM_List_CreateImage, data->image[i], 0);
123 } else {
124 data->handle[i] = (IPTR)NULL;
126 SNPrintf(image_str[i], sizeof(image_str[i]), "\33O[%08lx]", data->handle[i]);
128 return TRUE;
131 static IPTR PluginList_Cleanup(Class *cl, Object *o, Msg msg) {
132 struct PluginListData *data = INST_DATA(cl, o);
133 int i;
134 for (i = 0; i < PLUG_ICO_MAX; i++) {
135 DoMethod(o, MUIM_List_DeleteImage, data->handle[i]);
136 MUI_DisposeObject(data->image[i]);
137 image_str[i][0] = 0;
138 data->handle[i] = 0;
139 data->image[i] = NULL;
141 return DoSuperMethodA(cl, o, msg);
144 HOOKPROTO(PluginList_ConstructFunc, IPTR, APTR pool, struct PluginEntry *e) {
145 if (e) {
146 e->priority = ASPrintfPooled(pool, "%ld", (LONG)e->pri_num);
147 e->name = ASPrintfPooled(pool, e->is_builtin ? "%s (builtin)" : "%s", e->name);
149 return (IPTR)e;
152 HOOKPROTO(PluginList_DestructFunc, IPTR, APTR pool, struct PluginEntry *e) {
153 if (e) {
154 FreeVecPooled(pool, e->priority);
155 FreeVecPooled(pool, e->name);
156 FreeVecPooled(pool, e);
158 return 0;
161 HOOKPROTO(PluginList_CompareFunc, IPTR, const struct PluginEntry *e2, const struct PluginEntry *e1) {
162 return ((LONG)e2->pri_num - (LONG)e1->pri_num);
165 HOOKPROTO(PluginList_DisplayFunc, IPTR, CONST_STRPTR *array, struct PluginEntry *e) {
166 if (e) {
167 e->list_pos = (IPTR)array[-1];
168 array[PLUG_COL_ICON] = image_str[PLUG_ICO_PLUGIN];
169 array[PLUG_COL_PRI] = e->priority;
170 array[PLUG_COL_WRITE] = e->has_write ? image_str[PLUG_ICO_CHECKMARK] : (STRPTR)"";
171 array[PLUG_COL_NAME] = e->name;
172 } else {
173 array[PLUG_COL_ICON] = "";
174 array[PLUG_COL_PRI] = GetString(&LocaleInfo, MSG_PRIORITY_LBL);
175 array[PLUG_COL_WRITE] = GetString(&LocaleInfo, MSG_WRITESUPPORT_LBL);
176 array[PLUG_COL_NAME] = GetString(&LocaleInfo, MSG_PLUGIN_LBL);
178 return 0;