grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / icon / iconcontrol.c
blob51fccd38ab044341e7001c7239c50b97de9573a7
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <workbench/icon.h>
8 #include <utility/tagitem.h>
9 #include <proto/icon.h>
11 #include "icon_intern.h"
13 # include <aros/debug.h>
15 /*****************************************************************************
17 NAME */
19 AROS_LH2(ULONG, IconControlA,
21 /* SYNOPSIS */
22 AROS_LHA(struct DiskObject *, icon, A0),
23 AROS_LHA(struct TagItem *, tags, A1),
25 /* LOCATION */
26 struct IconBase *, IconBase, 26, Icon)
28 /* FUNCTION
29 Set and get icon and icon.library options.
31 INPUTS
32 icon - icon to be queried
34 RESULT
35 Number of processed tags.
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct TagItem *tstate = tags;
52 struct TagItem *tag = NULL;
53 ULONG processed = 0;
55 SIPTR *errorCode = NULL;
56 struct TagItem **errorTagItem = NULL;
57 struct NativeIcon *nativeicon = NULL;
58 struct NativeIconImage *image1 = NULL, *image2 = NULL;
60 if (icon)
62 nativeicon = GetNativeIcon(icon, LB(IconBase));
63 if (nativeicon) {
64 image1 = &nativeicon->ni_Image[0];
65 image2 = &nativeicon->ni_Image[1];
69 # define STORE(pointer, value) (pointer != NULL ? *pointer = (value) : (value))
70 # define SET_ERRORCODE(value) do { if (errorCode) STORE(errorCode, (value)); else SetIoErr(value); } while (0)
71 # define SET_ERRORTAGITEM(value) STORE(errorTagItem, (value))
73 /* The following tags need to be setup early ---------------------------*/
74 errorCode = (SIPTR *) GetTagData(ICONA_ErrorCode, 0, tags);
76 errorTagItem = (struct TagItem **) GetTagData(ICONA_ErrorTagItem, 0, tags);
77 SET_ERRORTAGITEM(NULL);
79 /* Parse taglist -------------------------------------------------------*/
80 while ((tag = NextTagItem(&tstate)) != NULL)
82 D(bug("[%s] %s %p, Tag %p Data %p\n", __func__, nativeicon ? "NativeIcon" : "DiskObject", nativeicon ? (APTR)nativeicon : (APTR)icon, tag->ti_Tag, tag->ti_Data));
83 switch (tag->ti_Tag)
85 /* Global tags -------------------------------------------------*/
86 case ICONCTRLA_SetGlobalScreen:
87 if (LB(IconBase)->ib_Screen != (struct Screen *) tag->ti_Data)
89 if ((struct Screen *) tag->ti_Data == NULL)
91 LB(IconBase)->ib_Screen = NULL;
92 /* NOTE: This intentionally does *not* set the error code */
93 processed++;
94 } else if (LB(IconBase)->ib_Screen == NULL)
96 LB(IconBase)->ib_Screen = (struct Screen *) tag->ti_Data;
97 /* NOTE: This intentionally does *not* set the error code */
98 processed++;
101 break;
103 case ICONCTRLA_GetGlobalScreen:
104 STORE((struct Screen **) tag->ti_Data, LB(IconBase)->ib_Screen);
105 processed++;
106 break;
108 case ICONCTRLA_SetGlobalPrecision:
109 case OBP_Precision:
110 LB(IconBase)->ib_Precision = tag->ti_Data;
111 processed++;
112 /* NOTE: This intentionally does *not* set the error code */
113 break;
115 case ICONCTRLA_GetGlobalPrecision:
116 STORE((LONG *) tag->ti_Data, LB(IconBase)->ib_Precision);
117 processed++;
118 break;
120 case ICONCTRLA_SetGlobalEmbossRect:
121 CopyMem((struct Rectangle *)tag->ti_Data, &LB(IconBase)->ib_EmbossRectangle, sizeof(struct Rectangle));
122 processed++;
123 SET_ERRORCODE(0);
124 break;
126 case ICONCTRLA_GetGlobalEmbossRect:
127 CopyMem(&LB(IconBase)->ib_EmbossRectangle, (struct Rectangle *)tag->ti_Data, sizeof(struct Rectangle));
128 processed++;
129 break;
131 case ICONCTRLA_SetGlobalFrameless:
132 LB(IconBase)->ib_Frameless = tag->ti_Data;
133 processed++;
134 SET_ERRORCODE(0);
135 break;
137 case ICONCTRLA_GetGlobalFrameless:
138 STORE((LONG *) tag->ti_Data, LB(IconBase)->ib_Frameless);
139 processed++;
140 break;
142 case ICONCTRLA_SetGlobalIdentifyHook:
143 LB(IconBase)->ib_IdentifyHook = (struct Hook *) tag->ti_Data;
144 processed++;
145 SET_ERRORCODE(0);
146 break;
148 case ICONCTRLA_GetGlobalIdentifyHook:
149 STORE((struct Hook **) tag->ti_Data, LB(IconBase)->ib_IdentifyHook);
150 processed++;
151 break;
153 case ICONCTRLA_SetGlobalMaxNameLength:
154 LB(IconBase)->ib_MaxNameLength = tag->ti_Data;
155 processed++;
156 SET_ERRORCODE(0);
157 break;
159 case ICONCTRLA_GetGlobalMaxNameLength:
160 STORE((LONG *) tag->ti_Data, LB(IconBase)->ib_MaxNameLength);
161 processed++;
162 break;
164 case ICONCTRLA_SetGlobalNewIconsSupport:
165 LB(IconBase)->ib_NewIconsSupport = tag->ti_Data;
166 processed++;
167 SET_ERRORCODE(0);
168 break;
170 case ICONCTRLA_GetGlobalNewIconsSupport:
171 STORE((LONG *) tag->ti_Data, LB(IconBase)->ib_NewIconsSupport);
172 processed++;
173 break;
175 case ICONCTRLA_SetGlobalColorIconSupport:
176 LB(IconBase)->ib_ColorIconSupport = tag->ti_Data;
177 processed++;
178 SET_ERRORCODE(0);
179 break;
181 case ICONCTRLA_GetGlobalColorIconSupport:
182 STORE((LONG *) tag->ti_Data, LB(IconBase)->ib_ColorIconSupport);
183 processed++;
184 break;
186 case ICONCTRLA_SetGlobalScaleBox:
187 LB(IconBase)->ib_ScaleBox = (ULONG)tag->ti_Data;
188 processed++;
189 break;
191 case ICONCTRLA_GetGlobalScaleBox:
192 STORE((ULONG *) tag->ti_Data, LB(IconBase)->ib_ScaleBox);
193 processed++;
194 break;
197 /* Local tags --------------------------------------------------*/
198 case ICONCTRLA_GetImageMask1:
199 if (image1)
201 FetchIconImage(icon, 0);
202 STORE((PLANEPTR *)tag->ti_Data, image1->BitMask);
203 processed++;
205 break;
207 case ICONCTRLA_GetImageMask2:
208 if (image2)
210 FetchIconImage(icon, 1);
211 STORE((PLANEPTR *)tag->ti_Data, image2->BitMask);
212 processed++;
214 break;
216 case ICONCTRLA_SetTransparentColor1:
217 if (image1)
219 image1->TransparentColor = (LONG)tag->ti_Data;
220 /* Mark that the original imagery has been modified */
221 nativeicon->ni_Extra.Size = 0;
222 /* Note: ErrorCode is not modified here */
223 processed++;
225 break;
227 case ICONCTRLA_GetTransparentColor1:
228 if (image1)
230 FetchIconImage(icon, 0);
231 STORE((LONG *)tag->ti_Data, image1->TransparentColor);
233 else
235 STORE((LONG *)tag->ti_Data, -1);
237 processed++;
238 break;
240 case ICONCTRLA_SetTransparentColor2:
241 if (image2)
243 image2->TransparentColor = (LONG)tag->ti_Data;
244 /* Mark that the original imagery has been modified */
245 nativeicon->ni_Extra.Size = 0;
246 /* Note: ErrorCode is not modified here */
247 processed++;
249 break;
251 case ICONCTRLA_GetTransparentColor2:
252 if (image2)
254 FetchIconImage(icon, 1);
255 STORE((LONG *)tag->ti_Data, image2->TransparentColor);
257 else
259 STORE((LONG *)tag->ti_Data, -1);
261 processed++;
262 break;
264 case ICONCTRLA_SetPalette1:
265 if (image1)
267 image1->Palette = (const struct ColorRegister *)tag->ti_Data;
268 /* Mark that the original imagery has been modified */
269 nativeicon->ni_Extra.Size = 0;
270 /* Note: ErrorCode is not modified here */
271 processed++;
273 break;
275 case ICONCTRLA_GetPalette1:
276 if (image1)
278 FetchIconImage(icon, 0);
279 STORE((CONST struct ColorRegister **)tag->ti_Data, image1->Palette);
280 processed++;
282 break;
284 case ICONCTRLA_SetPalette2:
285 if (image2)
287 image2->Palette = (CONST struct ColorRegister *)tag->ti_Data;
288 /* Mark that the original imagery has been modified */
289 nativeicon->ni_Extra.Size = 0;
290 /* Note: ErrorCode is not modified here */
291 processed++;
293 break;
295 case ICONCTRLA_GetPalette2:
296 if (image2)
298 FetchIconImage(icon, 1);
299 STORE((CONST struct ColorRegister **)tag->ti_Data, image2->Palette);
300 processed++;
302 break;
304 case ICONCTRLA_SetPaletteSize1:
305 if (image1)
307 ULONG pens = tag->ti_Data;
308 if (pens >= 1 && pens <= 256) {
309 /* Free any old pens */
310 LayoutIcon(icon, NULL, TAG_END);
311 image1->Pens = pens;
312 /* Mark that the original imagery has been modified */
313 nativeicon->ni_Extra.Size = 0;
314 /* NOTE: Error code is not modified here */
315 processed++;
318 break;
320 case ICONCTRLA_GetPaletteSize1:
321 if (image1)
323 FetchIconImage(icon, 0);
324 STORE((ULONG *)tag->ti_Data, image1->Pens);
326 else
328 STORE((ULONG *)tag->ti_Data, 0);
330 processed++;
331 break;
333 case ICONCTRLA_SetPaletteSize2:
334 if (image2)
336 ULONG pens = tag->ti_Data;
337 if (pens >= 1 && pens <= 256) {
338 /* Free any old pens */
339 LayoutIcon(icon, NULL, TAG_END);
340 image2->Pens = pens;
341 /* Mark that the original imagery has been modified */
342 nativeicon->ni_Extra.Size = 0;
343 /* NOTE: Error code is not modified here */
344 processed++;
347 break;
349 case ICONCTRLA_GetPaletteSize2:
350 if (image2)
352 FetchIconImage(icon, 1);
353 STORE((ULONG *)tag->ti_Data, image2->Pens);
355 else
357 STORE((ULONG *)tag->ti_Data, 0);
359 processed++;
360 break;
362 case ICONCTRLA_SetImageData1:
363 if (image1)
365 image1->ImageData = (APTR)tag->ti_Data;
366 /* Mark that the original imagery has been modified */
367 nativeicon->ni_Extra.Size = 0;
368 processed++;
370 break;
372 case ICONCTRLA_GetImageData1:
373 if (image1)
375 FetchIconImage(icon, 0);
376 STORE((CONST UBYTE **)tag->ti_Data, image1->ImageData);
377 processed++;
379 break;
381 case ICONCTRLA_SetImageData2:
382 if (image2)
384 image2->ImageData = (APTR)tag->ti_Data;
385 /* Mark that the original imagery has been modified */
386 nativeicon->ni_Extra.Size = 0;
387 processed++;
389 break;
391 case ICONCTRLA_GetImageData2:
392 if (image2)
394 FetchIconImage(icon, 1);
395 STORE((CONST UBYTE **)tag->ti_Data, image2->ImageData);
396 processed++;
398 break;
400 case ICONCTRLA_SetFrameless:
401 if (nativeicon)
403 nativeicon->ni_Frameless = (BOOL)tag->ti_Data;
404 /* Mark that the original imagery has been modified */
405 nativeicon->ni_Extra.Size = 0;
406 processed++;
408 break;
410 case ICONCTRLA_GetFrameless:
411 if (nativeicon)
413 STORE((LONG *)tag->ti_Data, nativeicon->ni_Frameless);
414 processed++;
416 break;
418 case ICONCTRLA_SetNewIconsSupport:
419 processed++;
420 break;
422 case ICONCTRLA_GetNewIconsSupport:
423 processed++;
424 break;
426 case ICONCTRLA_SetAspectRatio:
427 if (nativeicon)
429 nativeicon->ni_Face.Aspect = (UBYTE)tag->ti_Data;
430 processed++;
432 break;
434 case ICONCTRLA_GetAspectRatio:
435 if (nativeicon)
437 STORE((UBYTE *)tag->ti_Data, nativeicon->ni_Face.Aspect);
438 } else {
439 STORE((UBYTE *)tag->ti_Data, ICON_ASPECT_RATIO_UNKNOWN);
441 processed++;
442 break;
444 case ICONCTRLA_SetWidth:
445 if (nativeicon)
447 ULONG width = (ULONG)tag->ti_Data;
448 if (width > 0 && width <= 256) {
449 nativeicon->ni_Face.Width = width;
450 /* Mark that the original imagery has been modified */
451 nativeicon->ni_Extra.Size = 0;
452 /* NOTE: Error code is not modified here */
453 processed++;
456 break;
458 case ICONCTRLA_GetWidth:
459 if (nativeicon && nativeicon->ni_Face.Width > 0)
461 STORE((ULONG *)tag->ti_Data, nativeicon->ni_Face.Width);
462 processed++;
464 break;
466 case ICONCTRLA_SetHeight:
467 if (nativeicon)
469 ULONG height = (ULONG)tag->ti_Data;
470 if (height > 0 && height <= 256) {
471 nativeicon->ni_Face.Height = height;
472 /* Mark that the original imagery has been modified */
473 nativeicon->ni_Extra.Size = 0;
474 /* NOTE: Error code is not modified here */
475 processed++;
478 break;
480 case ICONCTRLA_GetHeight:
481 if (nativeicon)
483 STORE((ULONG *)tag->ti_Data, nativeicon->ni_Face.Height);
484 processed++;
486 break;
488 case ICONCTRLA_IsPaletteMapped:
489 if (nativeicon && nativeicon->ni_Image[0].ImageData)
491 STORE((LONG *)tag->ti_Data, 1);
493 else
495 STORE((LONG *)tag->ti_Data, 0);
497 processed++;
498 break;
500 case ICONCTRLA_IsNewIcon:
501 /* NewIcons are not supported */
502 STORE((LONG *)tag->ti_Data, 0);
503 break;
505 case ICONCTRLA_IsNativeIcon:
506 if (nativeicon)
508 STORE((LONG *)tag->ti_Data, 1);
510 else
512 STORE((LONG *)tag->ti_Data, 0);
514 processed++;
515 break;
517 case ICONGETA_IsDefaultIcon:
518 if (nativeicon) {
519 STORE((LONG *)tag->ti_Data, (LONG)nativeicon->ni_IsDefault);
520 } else {
521 STORE((LONG *)tag->ti_Data, 0);
523 processed++;
524 break;
526 case ICONCTRLA_GetScreen:
527 if (nativeicon) {
528 STORE((struct Screen **)tag->ti_Data, nativeicon->ni_Screen);
529 } else {
530 STORE((struct Screen **)tag->ti_Data, NULL);
532 processed++;
533 break;
535 case ICONCTRLA_HasRealImage2:
536 FetchIconImage(icon, 1);
537 if (image2 && image2->ImageData) {
538 STORE((LONG *)tag->ti_Data, TRUE);
539 } else {
540 STORE((LONG *)tag->ti_Data, FALSE);
542 break;
544 case ICONCTRLA_GetARGBImageData1:
545 if (image1)
547 FetchIconARGB(icon, 0);
548 STORE((CONST ULONG **)tag->ti_Data, image1->ARGB);
550 else
552 STORE((CONST ULONG **)tag->ti_Data, NULL);
554 processed++;
555 break;
557 case ICONCTRLA_SetARGBImageData1:
558 if (image1)
560 image1->ARGB = (APTR)tag->ti_Data;
561 /* Disable the from-disk PNG based ARGB imagery */
562 nativeicon->ni_Extra.PNG[0].Size = 0;
563 /* Mark that the original imagery has been modified */
564 nativeicon->ni_Extra.Size = 0;
566 SET_ERRORCODE(0);
567 processed++;
568 break;
571 case ICONCTRLA_GetARGBImageData2:
572 if (image2)
574 FetchIconARGB(icon, 1);
575 STORE((CONST ULONG **)tag->ti_Data, image2->ARGB);
577 else
579 STORE((CONST ULONG **)tag->ti_Data, NULL);
581 processed++;
582 break;
584 case ICONCTRLA_SetARGBImageData2:
585 if (image2)
587 image2->ARGB = (APTR)tag->ti_Data;
588 /* Disable the from-disk PNG based ARGB imagery */
589 nativeicon->ni_Extra.PNG[1].Size = 0;
590 /* Mark that the original imagery has been modified */
591 nativeicon->ni_Extra.Size = 0;
593 SET_ERRORCODE(0);
594 processed++;
595 break;
597 case ICONCTRLA_SetScaleBox:
598 if (nativeicon)
600 nativeicon->ni_ScaleBox = (ULONG)tag->ti_Data;
601 processed++;
603 break;
605 case ICONCTRLA_GetScaleBox:
606 if (nativeicon)
608 STORE((ULONG *)tag->ti_Data, nativeicon->ni_ScaleBox);
609 processed++;
611 break;
613 default:
614 SET_ERRORTAGITEM(tag);
615 break;
619 return processed;
621 AROS_LIBFUNC_EXIT
623 # undef STORE
624 # undef SET_ERRORCODE
625 # undef SET_ERRORTAGITEM
627 } /* IconControlA() */