Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / ra_gui / gui.c
blob3b670120c4e8b0e1cabaa7202a1ac29192e47c72
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 <intuition/icclass.h>
29 #include <proto/exec.h>
30 #include <proto/dos.h>
31 #include <proto/intuition.h>
32 #include <proto/gadtools.h>
33 #include <proto/diskimage.h>
34 #include <clib/alib_protos.h>
36 #define dbug(x) //Printf x
38 extern struct ClassLibrary *TBIBase;
40 static CONST CONST_STRPTR image_names[IID_MAX] = {
41 "tapeinsert",
42 "tapeeject",
43 "protectdrive",
44 "prefs",
45 "refresh",
46 "list_crypt",
47 "list_checkmark",
48 "list_plugin",
49 "list_disk",
50 "list_cd"
53 #ifdef FALLBACK_IMAGES
54 #include "images/insert.c"
55 #include "images/eject.c"
56 #include "images/writeprotect.c"
57 #include "images/prefs.c"
58 #include "images/refresh.c"
59 #include "images/list_writeprotected.c"
60 #include "images/list_checkmark.c"
61 #include "images/list_plugin.c"
62 #include "images/list_disk.c"
63 #include "images/list_cd.c"
65 static CONST APTR fallback_images[IID_MAX] = {
66 &insert,
67 &eject,
68 &writeprotect,
69 &prefs,
70 &refresh,
71 &list_writeprotected,
72 &list_checkmark,
73 &list_plugin,
74 &list_disk,
75 &list_cd
77 #endif
79 struct GUIElements Gui;
81 static BOOL translate_gui = TRUE;
83 static struct NewMenu main_newmenu[] = {
84 { NM_TITLE, STR_ID(-1), NULL, 0, 0, MENU_ID(0) },
85 { NM_ITEM, STR_ID(MSG_PROJECT_ABOUT), "?", 0, 0, MENU_ID(MID_ABOUT) },
86 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
87 { NM_ITEM, STR_ID(MSG_PROJECT_HIDE), "H", 0, 0, MENU_ID(MID_HIDE) },
88 { NM_ITEM, STR_ID(MSG_PROJECT_ICONIFY), "I", 0, 0, MENU_ID(MID_ICONIFY) },
89 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
90 { NM_ITEM, STR_ID(MSG_PROJECT_QUIT), "Q", 0, 0, MENU_ID(MID_QUIT) },
91 { NM_TITLE, STR_ID(MSG_SETTINGS_MENU), NULL, 0, 0, MENU_ID(0) },
92 { NM_ITEM, STR_ID(MSG_SETTINGS_CHANGETEMPDIR), NULL, 0, 0, MENU_ID(MID_CHANGETEMPDIR) },
93 { NM_ITEM, STR_ID(MSG_SETTINGS_PLUGINS), "P", 0, 0, MENU_ID(MID_PLUGINS) },
94 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
95 { NM_ITEM, STR_ID(MSG_SETTINGS_SAVE), NULL, 0, 0, MENU_ID(MID_SAVESETTINGS) },
96 { NM_END, STR_ID(-1), NULL, 0, 0, MENU_ID(0) }
99 static struct NewMenu main_newmenu_notbiclass[] = {
100 { NM_TITLE, STR_ID(-1), NULL, 0, 0, MENU_ID(0) },
101 { NM_ITEM, STR_ID(MSG_PROJECT_ABOUT), "?", 0, 0, MENU_ID(MID_ABOUT) },
102 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
103 { NM_ITEM, STR_ID(MSG_PROJECT_HIDE), "H", 0, 0, MENU_ID(MID_HIDE) },
104 { NM_ITEM, STR_ID(MSG_PROJECT_ICONIFY), "I", 0, 0, MENU_ID(MID_ICONIFY) },
105 { NM_ITEM, STR_ID(MSG_PROJECT_SNAPSHOT), NULL, 0, 0, MENU_ID(MID_SNAPSHOT) },
106 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
107 { NM_ITEM, STR_ID(MSG_PROJECT_QUIT), "Q", 0, 0, MENU_ID(MID_QUIT) },
108 { NM_TITLE, STR_ID(MSG_SETTINGS_MENU), NULL, 0, 0, MENU_ID(0) },
109 { NM_ITEM, STR_ID(MSG_SETTINGS_CHANGETEMPDIR), NULL, 0, 0, MENU_ID(MID_CHANGETEMPDIR) },
110 { NM_ITEM, STR_ID(MSG_SETTINGS_PLUGINS), "P", 0, 0, MENU_ID(MID_PLUGINS) },
111 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, MENU_ID(0) },
112 { NM_ITEM, STR_ID(MSG_SETTINGS_SAVE), NULL, 0, 0, MENU_ID(MID_SAVESETTINGS) },
113 { NM_END, STR_ID(-1), NULL, 0, 0, MENU_ID(0) }
116 static struct HintInfo main_hintinfo[] = {
117 { GID_SPEEDBAR, SBID_INSERT, STR_ID(MSG_INSERT_GAD), 0 },
118 { GID_SPEEDBAR, SBID_EJECT, STR_ID(MSG_EJECT_GAD), 0 },
119 { GID_SPEEDBAR, SBID_WRITEPROTECT, STR_ID(MSG_WRITEPROTECT_GAD), 0 },
120 { GID_SPEEDBAR, SBID_SETDEVICETYPE, STR_ID(MSG_SETDEVICETYPE_GAD), 0 },
121 { GID_SPEEDBAR, SBID_REFRESH, STR_ID(MSG_REFRESH_GAD), 0 },
122 { -1, -1, NULL, 0 }
125 CONST_STRPTR device_types_array[] = {
126 STR_ID(MSG_DEVICETYPE_DIRECT_ACCESS),
127 STR_ID(MSG_DEVICETYPE_CDROM),
128 NULL
131 struct ColumnInfo drivelist_columns[DRIVE_COL_MAX+1];
132 struct ColumnInfo pluginlist_columns[PLUG_COL_MAX+1];
134 BOOL SetupGUI (void) {
135 ULONG i;
136 struct Node *node;
137 STRPTR popkey;
138 CONST_STRPTR main_window_title;
139 CONST_STRPTR *devtype;
140 static Tag vertproptag = EXTWINDOW_VertProp;
141 static Tag vertobjecttag = EXTWINDOW_VertObject;
143 if (Gui.initialised) {
144 return TRUE;
147 Gui.initialised = TRUE;
149 if (WindowBase->lib_Version >= 50) {
150 vertproptag = WINDOW_VertProp;
151 vertobjecttag = WINDOW_VertObject;
154 Gui.pool = CreatePool(MEMF_ANY, 4096, 1024);
155 if (!Gui.pool) {
156 goto error;
159 if (translate_gui) {
160 translate_gui = FALSE;
161 TranslateMenus(&LocaleInfo, main_newmenu);
162 main_newmenu[0].nm_Label = PROGNAME;
163 TranslateMenus(&LocaleInfo, main_newmenu_notbiclass);
164 main_newmenu_notbiclass[0].nm_Label = PROGNAME;
165 TranslateHints(&LocaleInfo, main_hintinfo);
166 TranslateArray(&LocaleInfo, device_types_array);
169 Gui.userport = CreateMsgPort();
170 Gui.appport = CreateMsgPort();
171 if (!Gui.userport || !Gui.appport) {
172 goto error;
175 Gui.screen = LockPubScreen(WORKBENCHNAME);
176 if (!Gui.screen) {
177 goto error;
180 ClearMem(&drivelist_columns, sizeof(drivelist_columns));
181 drivelist_columns[DRIVE_COL_ICON].ci_Title = "";
182 drivelist_columns[DRIVE_COL_UNIT].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_UNIT_LBL);
183 drivelist_columns[DRIVE_COL_DEVICE].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_DEVICE_LBL);
184 drivelist_columns[DRIVE_COL_WP].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_WRITEPROTECT_LBL);
185 drivelist_columns[DRIVE_COL_DISKIMAGE].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_FILENAME_LBL);
186 drivelist_columns[DRIVE_COL_MAX].ci_Width = -1;
187 ClearMem(&pluginlist_columns, sizeof(pluginlist_columns));
188 pluginlist_columns[PLUG_COL_ICON].ci_Title = "";
189 pluginlist_columns[PLUG_COL_PRI].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_PRIORITY_LBL);
190 pluginlist_columns[PLUG_COL_WRITE].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_WRITESUPPORT_LBL);
191 pluginlist_columns[PLUG_COL_NAME].ci_Title = (STRPTR)GetString(&LocaleInfo, MSG_PLUGIN_LBL);
192 pluginlist_columns[PLUG_COL_MAX].ci_Width = -1;
194 for (i = 0; i < LID_MAX; i++) {
195 Gui.lists[i] = CreateList(FALSE);
196 if (!Gui.lists[i]) {
197 goto error;
201 Gui.images[IID_INSERT] = LoadImage(Gui.screen, image_names[IID_INSERT], TRUE, TRUE);
202 Gui.images[IID_EJECT] = LoadImage(Gui.screen, image_names[IID_EJECT], TRUE, TRUE);
203 Gui.images[IID_WRITEPROTECT] = LoadImage(Gui.screen, image_names[IID_WRITEPROTECT], TRUE, TRUE);
204 Gui.images[IID_PREFS] = LoadImage(Gui.screen, image_names[IID_PREFS], TRUE, TRUE);
205 Gui.images[IID_REFRESH] = LoadImage(Gui.screen, image_names[IID_REFRESH], TRUE, TRUE);
206 Gui.images[IID_LIST_WRITEPROTECTED] = LoadImage(Gui.screen, image_names[IID_LIST_WRITEPROTECTED], FALSE, FALSE);
207 Gui.images[IID_LIST_CHECKMARK] = LoadImage(Gui.screen, image_names[IID_LIST_CHECKMARK], FALSE, FALSE);
208 Gui.images[IID_LIST_PLUGIN] = LoadImage(Gui.screen, image_names[IID_LIST_PLUGIN], FALSE, FALSE);
209 Gui.images[IID_LIST_DISK] = LoadImage(Gui.screen, image_names[IID_LIST_DISK], FALSE, FALSE);
210 Gui.images[IID_LIST_CDROM] = LoadImage(Gui.screen, image_names[IID_LIST_CDROM], FALSE, FALSE);
211 for (i = 0; i < IID_MAX; i++) {
212 if (!Gui.images[i]) {
213 #ifdef FALLBACK_IMAGES
214 Gui.images[i] = fallback_images[i];
215 Gui.fallback_image[i] = TRUE;
216 #else
217 ImageNotFoundRequester(image_names[i]);
218 goto error;
219 #endif
223 node = AllocSpeedButtonNode(SBID_INSERT,
224 SBNA_Disabled, TRUE,
225 SBNA_Image, Gui.images[IID_INSERT],
226 SBNA_Highlight, SBH_IMAGE,
227 TAG_END);
228 if (!node) {
229 goto error;
231 AddTail(Gui.lists[LID_SPEEDBAR], node);
232 node = AllocSpeedButtonNode(SBID_EJECT,
233 SBNA_Disabled, TRUE,
234 SBNA_Image, Gui.images[IID_EJECT],
235 SBNA_Highlight, SBH_IMAGE,
236 TAG_END);
237 if (!node) {
238 goto error;
240 AddTail(Gui.lists[LID_SPEEDBAR], node);
241 node = AllocSpeedButtonNode(SBID_WRITEPROTECT,
242 SBNA_Disabled, TRUE,
243 SBNA_Image, Gui.images[IID_WRITEPROTECT],
244 SBNA_Highlight, SBH_IMAGE,
245 TAG_END);
246 if (!node) {
247 goto error;
249 AddTail(Gui.lists[LID_SPEEDBAR], node);
250 if (CheckLib(DiskImageBase, 52, 23)) {
251 node = AllocSpeedButtonNode(SBID_SETDEVICETYPE,
252 SBNA_Disabled, TRUE,
253 SBNA_Image, Gui.images[IID_PREFS],
254 SBNA_Highlight, SBH_IMAGE,
255 TAG_END);
256 if (!node) {
257 goto error;
259 AddTail(Gui.lists[LID_SPEEDBAR], node);
261 node = AllocSpeedButtonNode(SBID_REFRESH,
262 SBNA_Disabled, FALSE,
263 SBNA_Image, Gui.images[IID_REFRESH],
264 SBNA_Highlight, SBH_IMAGE,
265 TAG_END);
266 if (!node) {
267 goto error;
269 AddTail(Gui.lists[LID_SPEEDBAR], node);
271 node = AllocChooserNode(
272 CNA_Text, GetString(&LocaleInfo, MSG_AUTO_LBL),
273 TAG_END);
274 if (!node) {
275 goto error;
277 AddHead(Gui.lists[LID_PLUGINCHOOSER], node);
279 devtype = device_types_array;
280 while (*devtype) {
281 node = AllocChooserNode(
282 CNA_Text, *devtype++,
283 TAG_END);
284 if (!node) {
285 goto error;
287 AddTail(Gui.lists[LID_DEVICETYPECHOOSER], node);
290 popkey = TTString(Icon, "CX_POPKEY", NULL);
291 if (!popkey || !TrimStr(popkey)[0]) {
292 popkey = "none";
295 main_window_title = ASPrintfPooled(Gui.pool, GetString(&LocaleInfo, MSG_MAIN_WND), PROGNAME, popkey);
296 if (!main_window_title) {
297 goto error;
300 Gui.visualinfo = GetVisualInfoA(Gui.screen, NULL);
301 if (!Gui.visualinfo) {
302 goto error;
304 if (TBIBase) {
305 Gui.menustrip = CreateMenus(main_newmenu, GTMN_FullMenu, TRUE, TAG_END);
306 } else {
307 Gui.menustrip = CreateMenus(main_newmenu_notbiclass, GTMN_FullMenu, TRUE, TAG_END);
309 if (!Gui.menustrip || !LayoutMenus(Gui.menustrip, Gui.visualinfo, GTMN_NewLookMenus, TRUE, TAG_END)) {
310 goto error;
313 Gui.windows[WID_MAIN] = ExtWindowObject,
314 WA_Title, main_window_title,
315 WA_Flags, WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SIZEGADGET
316 |WFLG_NEWLOOKMENUS|WFLG_NOCAREREFRESH|WFLG_ACTIVATE|WFLG_SIZEBRIGHT,
317 WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_GADGETUP|IDCMP_MENUPICK|IDCMP_NEWSIZE,
318 WA_PubScreen, Gui.screen,
319 WINDOW_Position, WPOS_CENTERMOUSE,
320 WINDOW_SharedPort, Gui.userport,
321 WINDOW_AppPort, Gui.appport,
322 WINDOW_IconifyGadget, TRUE,
323 WINDOW_Icon, GetProgramIcon(),
324 WINDOW_IconTitle, PROGNAME,
325 WINDOW_HintInfo, main_hintinfo,
326 WINDOW_GadgetHelp, TRUE,
327 WINDOW_MenuStrip, Gui.menustrip,
328 vertproptag, TRUE,
329 WINDOW_Layout, VLayoutObject,
330 LAYOUT_SpaceOuter, TRUE,
331 LAYOUT_AddChild, Gui.gadgets[GID_SPEEDBAR] = SpeedBarObject,
332 GA_ID, GID_SPEEDBAR,
333 GA_RelVerify, TRUE,
334 SPEEDBAR_Buttons, Gui.lists[LID_SPEEDBAR],
335 End,
336 LAYOUT_AddChild, Gui.gadgets[GID_DRIVELIST] = ListBrowserObject,
337 GA_ID, GID_DRIVELIST,
338 GA_RelVerify, TRUE,
339 LISTBROWSER_ColumnTitles, TRUE,
340 LISTBROWSER_TitleClickable, TRUE,
341 LISTBROWSER_ColumnInfo, drivelist_columns,
342 LISTBROWSER_Labels, Gui.lists[LID_DRIVELIST],
343 LISTBROWSER_ShowSelected, TRUE,
344 LISTBROWSER_AutoFit, TRUE,
345 LISTBROWSER_VerticalProp, FALSE,
346 End,
347 LAYOUT_AddChild, Gui.gadgets[GID_PLUGINCHOOSER] = ChooserObject,
348 GA_ID, GID_PLUGINCHOOSER,
349 CHOOSER_Labels, Gui.lists[LID_PLUGINCHOOSER],
350 End,
351 CHILD_Label, LabelObject,
352 LABEL_Text, GetString(&LocaleInfo, MSG_PLUGIN_GAD),
353 End,
354 End,
355 EXTWINDOW_SnapshotGadget, TRUE,
356 End;
357 Gui.windows[WID_PLUGINS] = ExtWindowObject,
358 WA_Title, GetString(&LocaleInfo, MSG_PLUGINS_WND),
359 WA_Flags, WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SIZEGADGET
360 |WFLG_NOCAREREFRESH|WFLG_ACTIVATE|WFLG_SIZEBRIGHT,
361 WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_GADGETUP|IDCMP_NEWSIZE,
362 WA_PubScreen, Gui.screen,
363 WINDOW_Position, WPOS_CENTERMOUSE,
364 WINDOW_SharedPort, Gui.userport,
365 WINDOW_AppPort, Gui.appport,
366 WINDOW_IconifyGadget, TRUE,
367 WINDOW_Icon, GetProgramIcon(),
368 vertproptag, TRUE,
369 WINDOW_Layout, LayoutObject,
370 LAYOUT_SpaceOuter, TRUE,
371 LAYOUT_AddChild, Gui.gadgets[GID_PLUGINLIST] = ListBrowserObject,
372 GA_ID, GID_PLUGINLIST,
373 GA_RelVerify, TRUE,
374 LISTBROWSER_ColumnTitles, TRUE,
375 LISTBROWSER_TitleClickable, TRUE,
376 LISTBROWSER_ColumnInfo, pluginlist_columns,
377 LISTBROWSER_Labels, Gui.lists[LID_PLUGINLIST],
378 LISTBROWSER_ShowSelected, TRUE,
379 LISTBROWSER_AutoFit, TRUE,
380 LISTBROWSER_VerticalProp, FALSE,
381 End,
382 End,
383 EXTWINDOW_SnapshotGadget, TRUE,
384 End;
385 Gui.windows[WID_SETDEVICETYPE] = WindowObject,
386 WA_Flags, WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_NOCAREREFRESH
387 |WFLG_ACTIVATE,
388 WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_GADGETUP,
389 WA_PubScreen, Gui.screen,
390 WINDOW_Position, WPOS_CENTERMOUSE,
391 WINDOW_SharedPort, Gui.userport,
392 WINDOW_Layout, VLayoutObject,
393 LAYOUT_SpaceOuter, TRUE,
394 LAYOUT_AddChild, Gui.gadgets[GID_DEVICETYPECHOOSER] = ChooserObject,
395 GA_ID, GID_DEVICETYPECHOOSER,
396 CHOOSER_Labels, Gui.lists[LID_DEVICETYPECHOOSER],
397 CHOOSER_Selected, 0,
398 End,
399 CHILD_Label, LabelObject,
400 LABEL_Text, GetString(&LocaleInfo, MSG_DEVICETYPE_GAD),
401 End,
402 LAYOUT_AddChild, HLayoutObject,
403 LAYOUT_BevelStyle, BVS_SBAR_VERT,
404 LAYOUT_AddChild, Gui.gadgets[GID_SETDEVICETYPE_SAVE] = ButtonObject,
405 GA_ID, GID_SETDEVICETYPE_SAVE,
406 GA_RelVerify, TRUE,
407 GA_Text, GetString(&LocaleInfo, MSG_SAVE_GAD),
408 End,
409 LAYOUT_AddChild, Gui.gadgets[GID_SETDEVICETYPE_CANCEL] = ButtonObject,
410 GA_ID, GID_SETDEVICETYPE_CANCEL,
411 GA_RelVerify, TRUE,
412 GA_Text, GetString(&LocaleInfo, MSG_CANCEL_GAD),
413 End,
414 End,
415 End,
416 End;
417 for (i = 0; i < WID_MAX; i++) {
418 if (!Gui.windows[i]) {
419 goto error;
424 static const struct TagItem vprop2lb_map[] = {
425 { PGA_Top, LISTBROWSER_VPropTop },
426 { SCROLLER_Top, LISTBROWSER_VPropTop },
427 { TAG_END, 0 }
429 static const struct TagItem lb2vprop_map[] = {
430 { LISTBROWSER_VPropTotal, SCROLLER_Total },
431 { LISTBROWSER_VPropVisible, SCROLLER_Visible },
432 { LISTBROWSER_VPropTop, SCROLLER_Top },
433 { TAG_END, 0 }
435 GetAttr(vertobjecttag, Gui.windows[WID_MAIN], (Tag *)&Gui.gadgets[GID_DRIVELISTVPROP]);
436 GetAttr(vertobjecttag, Gui.windows[WID_PLUGINS], (Tag *)&Gui.gadgets[GID_PLUGINLISTVPROP]);
437 SetAttrs(Gui.gadgets[GID_DRIVELISTVPROP],
438 ICA_MAP, vprop2lb_map,
439 ICA_TARGET, Gui.gadgets[GID_DRIVELIST],
440 TAG_END);
441 SetAttrs(Gui.gadgets[GID_PLUGINLISTVPROP],
442 ICA_MAP, vprop2lb_map,
443 ICA_TARGET, Gui.gadgets[GID_PLUGINLIST],
444 TAG_END);
445 SetAttrs(Gui.gadgets[GID_DRIVELIST],
446 ICA_MAP, lb2vprop_map,
447 ICA_TARGET, Gui.gadgets[GID_DRIVELISTVPROP],
448 TAG_END);
449 SetAttrs(Gui.gadgets[GID_PLUGINLIST],
450 ICA_MAP, lb2vprop_map,
451 ICA_TARGET, Gui.gadgets[GID_PLUGINLISTVPROP],
452 TAG_END);
455 RestoreWindowSize(Gui.windows[WID_MAIN], "main_window");
456 RestoreWindowSize(Gui.windows[WID_PLUGINS], "plugins_window");
458 ScanUnits();
459 ScanPlugins();
461 return TRUE;
463 error:
464 CleanupGUI();
466 return FALSE;
469 void CleanupGUI (void) {
470 if (Gui.initialised) {
471 ULONG i;
472 struct Node *node, *succ;
474 Gui.initialised = FALSE;
476 for (i = 0; i < GID_MAX; i++) {
477 Gui.gadgets[i] = NULL;
480 HideWindow(WID_MAIN);
481 HideWindow(WID_PLUGINS);
483 for (i = 0; i < WID_MAX; i++) {
484 DisposeObject(Gui.windows[i]);
485 Gui.windows[i] = NULL;
488 FreeMenus(Gui.menustrip);
489 FreeVisualInfo(Gui.visualinfo);
491 while (node = RemHead(Gui.lists[LID_DEVICETYPECHOOSER])) {
492 FreeChooserNode(node);
494 while (node = RemHead(Gui.lists[LID_PLUGINCHOOSER])) {
495 FreeChooserNode(node);
497 FreeListBrowserList(Gui.lists[LID_PLUGINLIST]);
498 FreeListBrowserList(Gui.lists[LID_DRIVELIST]);
500 node = GetHead(Gui.lists[LID_SPEEDBAR]);
501 while (node) {
502 succ = GetSucc(node);
503 FreeSpeedButtonNode(node);
504 node = succ;
507 for (i = 0; i < IID_MAX; i++) {
508 #ifdef FALLBACK_IMAGES
509 if (Gui.fallback_image[i]) {
510 Gui.fallback_image[i] = FALSE;
511 Gui.images[i] = NULL;
512 continue;
514 #endif
515 DisposeObject(Gui.images[i]);
516 Gui.images[i] = NULL;
519 for (i = 0; i < LID_MAX; i++) {
520 DeleteList(Gui.lists[i]);
521 Gui.lists[i] = NULL;
524 UnlockPubScreen(NULL, Gui.screen);
525 Gui.screen = NULL;
527 DeleteMsgPort(Gui.appport);
528 DeleteMsgPort(Gui.userport);
529 Gui.appport = NULL;
530 Gui.userport = NULL;
532 DeletePool(Gui.pool);
533 Gui.pool = NULL;
537 APTR ShowWindow (ULONG window_id) {
538 struct Window *window;
539 if (!Gui.initialised && !SetupGUI()) {
540 return NULL;
542 dbug(("RA_OpenWindow\n"));
543 window = RA_OpenWindow(Gui.windows[window_id]);
544 if (window) {
545 switch (window_id) {
546 case WID_MAIN:
547 UpdateLBVertScroller(WID_MAIN, GID_DRIVELIST, GID_DRIVELISTVPROP);
548 break;
549 case WID_PLUGINS:
550 UpdateLBVertScroller(WID_PLUGINS, GID_PLUGINLIST, GID_PLUGINLISTVPROP);
551 break;
554 return window;
557 void HideWindow (ULONG window_id) {
558 if (Gui.initialised) {
559 switch (window_id) {
560 case WID_MAIN:
561 SaveWindowSize(Gui.windows[WID_MAIN], "main_window", FALSE);
562 break;
563 case WID_PLUGINS:
564 SaveWindowSize(Gui.windows[WID_PLUGINS], "plugins_window", FALSE);
565 break;
567 RA_CloseWindow(Gui.windows[window_id]);
571 void IconifyWindow (ULONG window_id) {
572 if (Gui.initialised) {
573 switch (window_id) {
574 case WID_MAIN:
575 SaveWindowSize(Gui.windows[WID_MAIN], "main_window", FALSE);
576 break;
577 case WID_PLUGINS:
578 SaveWindowSize(Gui.windows[WID_PLUGINS], "plugins_window", FALSE);
579 break;
581 RA_Iconify(Gui.windows[window_id]);
585 void SetWindowBusy (ULONG window_id, ULONG busy) {
586 if (Gui.initialised) {
587 if (window_id == (ULONG)-1) {
588 SetWindowBusy(WID_MAIN, busy);
589 SetWindowBusy(WID_PLUGINS, busy);
590 } else {
591 if (Gui.windows[window_id]) {
592 SetAttrs(Gui.windows[window_id],
593 WA_BusyPointer, busy,
594 TAG_END);
601 ULONG GetGUISignals (void) {
602 ULONG sigs = 0;
603 if (Gui.initialised) {
604 ULONG i;
605 ULONG sigmask;
606 for (i = 0; i < WID_MAX; i++) {
607 sigmask = 0;
608 GetAttr(WINDOW_SigMask, Gui.windows[i], &sigmask);
609 sigs |= sigmask;
612 return sigs;
615 void UpdateLBVertScroller (ULONG wnd_id, ULONG lb_id, ULONG sc_id) {
616 if (Gui.initialised) {
617 struct Window *window;
618 ULONG top, visible, total;
619 window = NULL;
620 GetAttr(WINDOW_Window, Gui.windows[wnd_id], (Tag *)&window);
621 total = top = visible = 0;
622 GetAttrs(Gui.gadgets[lb_id],
623 LISTBROWSER_VPropTotal, &total,
624 LISTBROWSER_VPropVisible, &visible,
625 LISTBROWSER_VPropTop, &top,
626 TAG_END);
627 dbug(("total: %ld\nvisible: %ld\ntop: %ld\n", total, visible, top));
628 SetGadgetAttrs(GA(Gui.gadgets[sc_id]), window, NULL,
629 SCROLLER_Total, total,
630 SCROLLER_Visible, visible,
631 SCROLLER_Top, top,
632 TAG_END);