revert between 56095 -> 55830 in arch
[AROS.git] / workbench / system / Workbook / workbook.c
blob782565280df72ccebc584ac455abfd392d398d8d
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Workbook Main
6 Lang: english
7 */
9 #include <stdio.h>
11 #include <proto/dos.h>
12 #include <proto/intuition.h>
13 #include <proto/exec.h>
14 #include <proto/icon.h>
15 #include <proto/workbench.h>
16 #include <proto/arossupport.h>
18 #include "workbook_intern.h"
19 #include "classes.h"
21 /* Allocate classes and run the main app */
22 static int WB_Main(struct WorkbookBase *wb)
24 int rc = RETURN_OK;
26 wb->wb_WBApp = WBApp_MakeClass(wb);
27 if (!wb->wb_WBApp)
28 goto exit;
30 wb->wb_WBWindow = WBWindow_MakeClass(wb);
31 if (!wb->wb_WBWindow)
32 goto exit;
34 wb->wb_WBVirtual = WBVirtual_MakeClass(wb);
35 if (!wb->wb_WBVirtual)
36 goto exit;
38 wb->wb_WBSet = WBSet_MakeClass(wb);
39 if (!wb->wb_WBSet)
40 goto exit;
42 wb->wb_WBIcon = WBIcon_MakeClass(wb);
43 if (!wb->wb_WBIcon)
44 goto exit;
46 wb->wb_App = NewObject(WBApp, NULL, TAG_END);
47 if (wb->wb_App) {
48 DoMethod(wb->wb_App, WBAM_WORKBENCH, 0);
49 DisposeObject(wb->wb_App);
50 rc = 0;
53 exit:
54 if (wb->wb_WBIcon)
55 FreeClass(wb->wb_WBIcon);
56 if (wb->wb_WBSet)
57 FreeClass(wb->wb_WBSet);
58 if (wb->wb_WBVirtual)
59 FreeClass(wb->wb_WBVirtual);
60 if (wb->wb_WBWindow)
61 FreeClass(wb->wb_WBWindow);
62 if (wb->wb_WBApp)
63 FreeClass(wb->wb_WBApp);
65 return rc;
68 #undef WorkbenchBase
69 #undef DOSBase
71 /* This wrapper is needed, so that we can start
72 * workbench items from an Input handler
74 AROS_PROCH(wbOpener, argstr, argsize, SysBase)
76 AROS_PROCFUNC_INIT
78 APTR WorkbenchBase = OpenLibrary("workbench.library", 0);
79 APTR DOSBase = OpenLibrary("dos.library", 0);
81 if (WorkbenchBase && DOSBase) {
82 /* 'argstr' is already an absolute path */
83 OpenWorkbenchObject(argstr, TAG_END);
86 CloseLibrary(DOSBase);
87 CloseLibrary(WorkbenchBase);
89 return 0;
91 AROS_PROCFUNC_EXIT
95 ULONG WorkbookMain(void)
97 struct WorkbookBase *wb;
98 APTR DOSBase;
99 int rc = RETURN_ERROR;
101 wb = NULL;
103 wb = AllocVec(sizeof(*wb), MEMF_ANY | MEMF_CLEAR);
104 if (!wb)
105 goto error;
107 wb->wb_DOSBase = OpenLibrary("dos.library", 0);
108 if (wb->wb_DOSBase == NULL)
109 goto error;
111 DOSBase = wb->wb_DOSBase;
113 wb->wb_IntuitionBase = OpenLibrary("intuition.library",0);
114 if (wb->wb_IntuitionBase == NULL)
115 goto error;
117 wb->wb_UtilityBase = OpenLibrary("utility.library",0);
118 if (wb->wb_UtilityBase == NULL)
119 goto error;
121 wb->wb_GadToolsBase = OpenLibrary("gadtools.library",0);
122 if (wb->wb_GadToolsBase == NULL)
123 goto error;
125 /* Version 44 or later for DrawIconStateA */
126 wb->wb_IconBase = OpenLibrary("icon.library",44);
127 if (wb->wb_IconBase == NULL)
128 goto error;
130 /* Version 44 or later for OpenWorkbenchObject */
131 wb->wb_WorkbenchBase = OpenLibrary("workbench.library",44);
132 if (wb->wb_WorkbenchBase == NULL)
133 goto error;
135 wb->wb_GfxBase = OpenLibrary("graphics.library",0);
136 if (wb->wb_GfxBase == NULL)
137 goto error;
139 wb->wb_LayersBase = OpenLibrary("layers.library", 0);
140 if (wb->wb_LayersBase == NULL)
141 goto error;
143 wb->wb_OpenerSegList = CreateSegList(wbOpener);
144 if (wb->wb_OpenerSegList == BNULL)
145 goto error;
147 SetConsoleTask(NULL);
148 rc = WB_Main(wb);
150 UnLoadSeg(wb->wb_OpenerSegList);
152 error:
153 if (wb) {
154 if (wb->wb_LayersBase)
155 CloseLibrary(wb->wb_LayersBase);
157 if (wb->wb_GfxBase)
158 CloseLibrary(wb->wb_GfxBase);
160 if (wb->wb_WorkbenchBase)
161 CloseLibrary(wb->wb_WorkbenchBase);
163 if (wb->wb_IconBase)
164 CloseLibrary(wb->wb_IconBase);
166 if (wb->wb_GadToolsBase)
167 CloseLibrary(wb->wb_GadToolsBase);
169 if (wb->wb_IntuitionBase)
170 CloseLibrary(wb->wb_GadToolsBase);
172 if (wb->wb_DOSBase)
173 CloseLibrary(wb->wb_DOSBase);
175 FreeVec(wb);
178 return rc;