Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / ra_gui / extwindowclass.c
blobdacbe786489cb5a6b65a22f9153f810e5feac9d8
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 <intuition/icclass.h>
28 #include <classes/extwindow.h>
29 #include <gadgets/extscroller.h>
30 #include <images/titlebar.h>
31 #include <proto/utility.h>
32 #include <proto/intuition.h>
33 #include <proto/window.h>
34 #include <clib/alib_protos.h>
35 #include <SDI_compiler.h>
37 #define GA(o) ((struct Gadget *)(o))
39 struct ExtWindow {
40 struct Window *window;
41 ULONG flags;
42 APTR drawinfo;
43 Object *snapshotimg;
44 Object *snapshotgad;
45 Object *vertpropgad;
46 Object *uparrowimg;
47 Object *uparrowgad;
48 Object *downarrowimg;
49 Object *downarrowgad;
52 #define GID_SNAPSHOT 0x7FFE
53 #define GID_VERTPROP 0x7FFD
54 #define GID_HORIZPROP 0x7FFC
55 #define EWFLG_SNAPSHOTGADGET 0x00000001
56 #define EWFLG_VERTPROPGADGET 0x00000002
58 static ULONG EXTWINDOW_Dispatch (REG(a0, Class *cl), REG(a2, Object *o), REG(a1, Msg msg));
60 Class *ExtWindowClass;
62 Class *InitExtWindowClass (void) {
63 ExtWindowClass = MakeClass("extwindow.class", NULL, WINDOW_GetClass(),
64 sizeof(struct ExtWindow), 0);
65 if (ExtWindowClass) {
66 ExtWindowClass->cl_Dispatcher.h_Entry = EXTWINDOW_Dispatch;
68 return ExtWindowClass;
71 static ULONG EXTWINDOW_New (Class *cl, Object *o, struct opSet *ops);
72 static ULONG EXTWINDOW_Get (Class *cl, Object *o, struct opGet *opg);
73 static ULONG EXTWINDOW_Open (Class *cl, Object *o, Msg msg);
74 static ULONG EXTWINDOW_Close (Class *cl, Object *o, Msg msg);
75 static ULONG EXTWINDOW_Dispose (Class *cl, Object *o, Msg msg);
76 static ULONG EXTWINDOW_HandleInput (Class *cl, Object *o, Msg msg);
77 static void ParseTagList (const struct TagItem *src_tags,
78 struct TagItem *win_tags, struct TagItem *extwin_tags);
79 static struct Gadget *FindSysGadget (struct Window *window, ULONG type);
80 static BOOL AddSnapshotGadget (struct ExtWindow *extwin);
81 static void RemSnapshotGadget (struct ExtWindow *extwin);
82 static BOOL AddVertPropGadget (struct ExtWindow *extwin);
83 static void RemVertPropGadget (struct ExtWindow *extwin);
85 static ULONG EXTWINDOW_Dispatch (REG(a0, Class *cl), REG(a2, Object *o), REG(a1, Msg msg)) {
86 switch (msg->MethodID) {
87 case OM_NEW: return EXTWINDOW_New(cl, o, (struct opSet *)msg);
88 case OM_GET: return EXTWINDOW_Get(cl, o, (struct opGet *)msg);
89 case WM_OPEN: return EXTWINDOW_Open(cl, o, msg);
90 case WM_CLOSE:
91 case WM_ICONIFY: return EXTWINDOW_Close(cl, o, msg);
92 case OM_DISPOSE: return EXTWINDOW_Dispose(cl, o, msg);
93 case WM_HANDLEINPUT: return EXTWINDOW_HandleInput(cl, o, msg);
95 return DoSuperMethodA(cl, o, msg);
98 static const struct TagItem up2vprop_map[] = {
99 { GA_ID, EXTSCROLLER_GoUp },
100 { TAG_END, 0 },
102 static const struct TagItem down2vprop_map[] = {
103 { GA_ID, EXTSCROLLER_GoDown },
104 { TAG_END, 0 },
107 static ULONG EXTWINDOW_New (Class *cl, Object *o, struct opSet *ops) {
108 Object *res;
109 res = (Object *)DoSuperMethodA(cl, o, (Msg)ops);
110 if (res) {
111 struct TagItem *tags = ops->ops_AttrList;
112 struct ExtWindow *extwin = INST_DATA(cl, res);
113 LONG error_count = 0;
114 if (GetTagData(EXTWINDOW_VertProp, FALSE, tags)) {
115 extwin->flags |= EWFLG_VERTPROPGADGET;
116 extwin->vertpropgad = ExtScrollerObject,
117 GA_ID, GID_VERTPROP,
118 PGA_Borderless, TRUE,
119 PGA_NewLook, TRUE,
120 End;
121 if (!extwin->vertpropgad) error_count++;
122 extwin->uparrowgad = NewObject(NULL, "buttongclass",
123 GA_ID, 1,
124 GA_RelVerify, FALSE,
125 ICA_MAP, up2vprop_map,
126 ICA_TARGET, extwin->vertpropgad,
127 TAG_END);
128 if (!extwin->uparrowgad) error_count++;
129 extwin->downarrowgad = NewObject(NULL, "buttongclass",
130 GA_ID, 1,
131 GA_RelVerify, FALSE,
132 ICA_MAP, down2vprop_map,
133 ICA_TARGET, extwin->vertpropgad,
134 TAG_END);
135 if (!extwin->downarrowgad) error_count++;
137 if (GetTagData(EXTWINDOW_SnapshotGadget, FALSE, tags)) {
138 extwin->flags |= EWFLG_SNAPSHOTGADGET;
139 extwin->snapshotgad = NewObject(NULL, "buttongclass",
140 GA_ID, GID_SNAPSHOT,
141 GA_RelVerify, TRUE,
142 TAG_END);
143 if (!extwin->snapshotgad) error_count++;
145 if (error_count) {
146 CoerceMethod(cl, res, OM_DISPOSE);
147 return (ULONG)NULL;
150 return (ULONG)res;
153 static ULONG EXTWINDOW_Get (Class *cl, Object *o, struct opGet *opg) {
154 struct ExtWindow *extwin = INST_DATA(cl, o);
155 switch (opg->opg_AttrID) {
156 case EXTWINDOW_VertObject:
157 *opg->opg_Storage = (ULONG)extwin->vertpropgad;
158 break;
159 default:
160 return DoSuperMethodA(cl, o, (Msg)opg);
162 return TRUE;
165 static ULONG EXTWINDOW_Open (Class *cl, Object *o, Msg msg) {
166 struct ExtWindow *extwin = INST_DATA(cl, o);
167 struct Window *res;
168 res = (struct Window *)DoSuperMethodA(cl, o, msg);
169 if (!extwin->window && res) {
170 extwin->window = res;
171 extwin->drawinfo = GetScreenDrawInfo(res->WScreen);
172 if (extwin->flags & EWFLG_VERTPROPGADGET) {
173 AddVertPropGadget(extwin);
175 if (extwin->flags & EWFLG_SNAPSHOTGADGET) {
176 AddSnapshotGadget(extwin);
179 return (ULONG)res;
182 static ULONG EXTWINDOW_Close (Class *cl, Object *o, Msg msg) {
183 struct ExtWindow *extwin = INST_DATA(cl, o);
184 if (extwin->window) {
185 RemSnapshotGadget(extwin);
186 RemVertPropGadget(extwin);
187 FreeScreenDrawInfo(extwin->window->WScreen, extwin->drawinfo);
188 extwin->drawinfo = NULL;
189 extwin->window = NULL;
191 return DoSuperMethodA(cl, o, msg);
194 static ULONG EXTWINDOW_Dispose (Class *cl, Object *o, Msg msg) {
195 struct ExtWindow *extwin = INST_DATA(cl, o);
196 if (extwin->window) {
197 RemSnapshotGadget(extwin);
198 RemVertPropGadget(extwin);
199 FreeScreenDrawInfo(extwin->window->WScreen, extwin->drawinfo);
200 extwin->drawinfo = NULL;
201 extwin->window = NULL;
203 DisposeObject(extwin->snapshotgad);
204 extwin->snapshotgad = NULL;
205 DisposeObject(extwin->downarrowgad);
206 extwin->downarrowgad = NULL;
207 DisposeObject(extwin->uparrowgad);
208 extwin->uparrowgad = NULL;
209 DisposeObject(extwin->vertpropgad);
210 extwin->vertpropgad = NULL;
211 return DoSuperMethodA(cl, o, msg);
214 static ULONG EXTWINDOW_HandleInput (Class *cl, Object *o, Msg msg) {
215 ULONG res;
216 res = DoSuperMethodA(cl, o, msg);
217 if ((res & WMHI_CLASSMASK) == WMHI_GADGETUP) {
218 switch (res & WMHI_GADGETMASK) {
219 case GID_SNAPSHOT:
220 res = WMHI_SNAPSHOT;
221 break;
224 return res;
227 static struct Gadget *FindSysGadget (struct Window *window, ULONG type) {
228 if (window) {
229 struct Gadget *gad;
230 gad = window->FirstGadget;
231 while (gad) {
232 if ((gad->GadgetType & (GTYP_SYSGADGET|GTYP_SYSTYPEMASK)) == (GTYP_SYSGADGET|type)) {
233 return gad;
235 gad = gad->NextGadget;
238 return NULL;
241 static BOOL AddSnapshotGadget (struct ExtWindow *extwin) {
242 struct Window *window = extwin->window;
243 struct Gadget *zoomgad;
244 zoomgad = FindSysGadget(window, GTYP_WZOOM);
245 if (!zoomgad) {
246 return FALSE;
248 extwin->snapshotimg = NewObject(NULL, "tbiclass",
249 SYSIA_DrawInfo, extwin->drawinfo,
250 SYSIA_Which, SNAPSHOTIMAGE,
251 TAG_END);
252 if (!extwin->snapshotimg) {
253 return FALSE;
255 SetAttrs(extwin->snapshotgad,
256 GA_Image, extwin->snapshotimg,
257 GA_RelRight, TBI_RELPOS(zoomgad, 3),
258 GA_Top, 0,
259 GA_Width, zoomgad->Width,
260 GA_Height, zoomgad->Height,
261 GA_TopBorder, TRUE,
262 TAG_END);
263 AddGadget(window, GA(extwin->snapshotgad), 0);
264 RefreshGList(GA(extwin->snapshotgad), window, NULL, 1);
265 return TRUE;
268 static void RemSnapshotGadget (struct ExtWindow *extwin) {
269 if (extwin->snapshotgad) {
270 RemoveGadget(extwin->window, GA(extwin->snapshotgad));
271 SetAttrs(extwin->snapshotgad,
272 GA_Image, NULL,
273 TAG_END);
274 DisposeObject(extwin->snapshotimg);
275 extwin->snapshotimg = NULL;
279 static BOOL AddVertPropGadget (struct ExtWindow *extwin) {
280 struct Window *window = extwin->window;
281 struct Gadget *sizegad;
282 sizegad = FindSysGadget(window, GTYP_SIZING);
283 if (!sizegad) {
284 return FALSE;
286 extwin->uparrowimg = NewObject(NULL, "sysiclass",
287 SYSIA_DrawInfo, extwin->drawinfo,
288 SYSIA_Which, UPIMAGE,
289 TAG_END);
290 if (!extwin->uparrowimg) {
291 return FALSE;
293 extwin->downarrowimg = NewObject(NULL, "sysiclass",
294 SYSIA_DrawInfo, extwin->drawinfo,
295 SYSIA_Which, DOWNIMAGE,
296 TAG_END);
297 if (!extwin->downarrowimg) {
298 DisposeObject(extwin->uparrowimg);
299 extwin->uparrowimg = NULL;
300 return FALSE;
302 SetAttrs(extwin->vertpropgad,
303 GA_RelRight, -(window->BorderRight - 5),
304 GA_Top, window->BorderTop + 1,
305 GA_Width, window->BorderRight - 8,
306 GA_RelHeight, -(window->BorderTop + sizegad->Height + 4 + 2*sizegad->Height),
307 GA_RightBorder, TRUE,
308 TAG_END);
309 SetAttrs(extwin->uparrowgad,
310 GA_Image, extwin->uparrowimg,
311 GA_RelRight, -(window->BorderRight - 1),
312 GA_RelBottom, -(3*sizegad->Height + 1),
313 GA_Width, window->BorderRight,
314 GA_Height, sizegad->Height,
315 TAG_END);
316 SetAttrs(extwin->downarrowgad,
317 GA_Image, extwin->downarrowimg,
318 GA_RelRight, -(window->BorderRight - 1),
319 GA_RelBottom, -(2*sizegad->Height),
320 GA_Width, window->BorderRight,
321 GA_Height, sizegad->Height,
322 TAG_END);
323 AddGadget(window, GA(extwin->vertpropgad), 0);
324 AddGadget(window, GA(extwin->uparrowgad), 0);
325 AddGadget(window, GA(extwin->downarrowgad), 0);
326 RefreshGList(GA(extwin->vertpropgad), window, NULL, 1);
327 RefreshGList(GA(extwin->uparrowgad), window, NULL, 1);
328 RefreshGList(GA(extwin->downarrowgad), window, NULL, 1);
329 return TRUE;
332 static void RemVertPropGadget (struct ExtWindow *extwin) {
333 if (extwin->vertpropgad) {
334 RemoveGadget(extwin->window, GA(extwin->vertpropgad));
335 RemoveGadget(extwin->window, GA(extwin->uparrowgad));
336 RemoveGadget(extwin->window, GA(extwin->downarrowgad));
337 SetAttrs(extwin->uparrowgad,
338 GA_Image, NULL,
339 TAG_END);
340 SetAttrs(extwin->downarrowgad,
341 GA_Image, NULL,
342 TAG_END);
343 DisposeObject(extwin->uparrowimg);
344 extwin->uparrowimg = NULL;
345 DisposeObject(extwin->downarrowimg);
346 extwin->downarrowimg = NULL;