2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
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 /*****************************************************************************
19 AROS_LH2(ULONG
, IconControlA
,
22 AROS_LHA(struct DiskObject
*, icon
, A0
),
23 AROS_LHA(struct TagItem
*, tags
, A1
),
26 struct IconBase
*, IconBase
, 26, Icon
)
29 Set and get icon and icon.library options.
32 icon - icon to be queried
35 Number of processed tags.
47 *****************************************************************************/
51 struct TagItem
*tstate
= tags
;
52 struct TagItem
*tag
= NULL
;
55 SIPTR
*errorCode
= NULL
;
56 struct TagItem
**errorTagItem
= NULL
;
57 struct NativeIcon
*nativeicon
= NULL
;
58 struct NativeIconImage
*image1
= NULL
, *image2
= NULL
;
62 nativeicon
= GetNativeIcon(icon
, LB(IconBase
));
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
));
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 */
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 */
103 case ICONCTRLA_GetGlobalScreen
:
104 STORE((struct Screen
**) tag
->ti_Data
, LB(IconBase
)->ib_Screen
);
108 case ICONCTRLA_SetGlobalPrecision
:
110 LB(IconBase
)->ib_Precision
= tag
->ti_Data
;
112 /* NOTE: This intentionally does *not* set the error code */
115 case ICONCTRLA_GetGlobalPrecision
:
116 STORE((LONG
*) tag
->ti_Data
, LB(IconBase
)->ib_Precision
);
120 case ICONCTRLA_SetGlobalEmbossRect
:
121 CopyMem((struct Rectangle
*)tag
->ti_Data
, &LB(IconBase
)->ib_EmbossRectangle
, sizeof(struct Rectangle
));
126 case ICONCTRLA_GetGlobalEmbossRect
:
127 CopyMem(&LB(IconBase
)->ib_EmbossRectangle
, (struct Rectangle
*)tag
->ti_Data
, sizeof(struct Rectangle
));
131 case ICONCTRLA_SetGlobalFrameless
:
132 LB(IconBase
)->ib_Frameless
= tag
->ti_Data
;
137 case ICONCTRLA_GetGlobalFrameless
:
138 STORE((LONG
*) tag
->ti_Data
, LB(IconBase
)->ib_Frameless
);
142 case ICONCTRLA_SetGlobalIdentifyHook
:
143 LB(IconBase
)->ib_IdentifyHook
= (struct Hook
*) tag
->ti_Data
;
148 case ICONCTRLA_GetGlobalIdentifyHook
:
149 STORE((struct Hook
**) tag
->ti_Data
, LB(IconBase
)->ib_IdentifyHook
);
153 case ICONCTRLA_SetGlobalMaxNameLength
:
154 LB(IconBase
)->ib_MaxNameLength
= tag
->ti_Data
;
159 case ICONCTRLA_GetGlobalMaxNameLength
:
160 STORE((LONG
*) tag
->ti_Data
, LB(IconBase
)->ib_MaxNameLength
);
164 case ICONCTRLA_SetGlobalNewIconsSupport
:
165 LB(IconBase
)->ib_NewIconsSupport
= tag
->ti_Data
;
170 case ICONCTRLA_GetGlobalNewIconsSupport
:
171 STORE((LONG
*) tag
->ti_Data
, LB(IconBase
)->ib_NewIconsSupport
);
175 case ICONCTRLA_SetGlobalColorIconSupport
:
176 LB(IconBase
)->ib_ColorIconSupport
= tag
->ti_Data
;
181 case ICONCTRLA_GetGlobalColorIconSupport
:
182 STORE((LONG
*) tag
->ti_Data
, LB(IconBase
)->ib_ColorIconSupport
);
186 case ICONCTRLA_SetGlobalScaleBox
:
187 LB(IconBase
)->ib_ScaleBox
= (ULONG
)tag
->ti_Data
;
191 case ICONCTRLA_GetGlobalScaleBox
:
192 STORE((ULONG
*) tag
->ti_Data
, LB(IconBase
)->ib_ScaleBox
);
197 /* Local tags --------------------------------------------------*/
198 case ICONCTRLA_GetImageMask1
:
201 FetchIconImage(icon
, 0);
202 STORE((PLANEPTR
*)tag
->ti_Data
, image1
->BitMask
);
207 case ICONCTRLA_GetImageMask2
:
210 FetchIconImage(icon
, 1);
211 STORE((PLANEPTR
*)tag
->ti_Data
, image2
->BitMask
);
216 case ICONCTRLA_SetTransparentColor1
:
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 */
227 case ICONCTRLA_GetTransparentColor1
:
230 FetchIconImage(icon
, 0);
231 STORE((LONG
*)tag
->ti_Data
, image1
->TransparentColor
);
235 STORE((LONG
*)tag
->ti_Data
, -1);
240 case ICONCTRLA_SetTransparentColor2
:
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 */
251 case ICONCTRLA_GetTransparentColor2
:
254 FetchIconImage(icon
, 1);
255 STORE((LONG
*)tag
->ti_Data
, image2
->TransparentColor
);
259 STORE((LONG
*)tag
->ti_Data
, -1);
264 case ICONCTRLA_SetPalette1
:
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 */
275 case ICONCTRLA_GetPalette1
:
278 FetchIconImage(icon
, 0);
279 STORE((CONST
struct ColorRegister
**)tag
->ti_Data
, image1
->Palette
);
284 case ICONCTRLA_SetPalette2
:
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 */
295 case ICONCTRLA_GetPalette2
:
298 FetchIconImage(icon
, 1);
299 STORE((CONST
struct ColorRegister
**)tag
->ti_Data
, image2
->Palette
);
304 case ICONCTRLA_SetPaletteSize1
:
307 ULONG pens
= tag
->ti_Data
;
308 if (pens
>= 1 && pens
<= 256) {
309 /* Free any old pens */
310 LayoutIcon(icon
, NULL
, TAG_END
);
312 /* Mark that the original imagery has been modified */
313 nativeicon
->ni_Extra
.Size
= 0;
314 /* NOTE: Error code is not modified here */
320 case ICONCTRLA_GetPaletteSize1
:
323 FetchIconImage(icon
, 0);
324 STORE((ULONG
*)tag
->ti_Data
, image1
->Pens
);
328 STORE((ULONG
*)tag
->ti_Data
, 0);
333 case ICONCTRLA_SetPaletteSize2
:
336 ULONG pens
= tag
->ti_Data
;
337 if (pens
>= 1 && pens
<= 256) {
338 /* Free any old pens */
339 LayoutIcon(icon
, NULL
, TAG_END
);
341 /* Mark that the original imagery has been modified */
342 nativeicon
->ni_Extra
.Size
= 0;
343 /* NOTE: Error code is not modified here */
349 case ICONCTRLA_GetPaletteSize2
:
352 FetchIconImage(icon
, 1);
353 STORE((ULONG
*)tag
->ti_Data
, image2
->Pens
);
357 STORE((ULONG
*)tag
->ti_Data
, 0);
362 case ICONCTRLA_SetImageData1
:
365 image1
->ImageData
= (APTR
)tag
->ti_Data
;
366 /* Mark that the original imagery has been modified */
367 nativeicon
->ni_Extra
.Size
= 0;
372 case ICONCTRLA_GetImageData1
:
375 FetchIconImage(icon
, 0);
376 STORE((CONST UBYTE
**)tag
->ti_Data
, image1
->ImageData
);
381 case ICONCTRLA_SetImageData2
:
384 image2
->ImageData
= (APTR
)tag
->ti_Data
;
385 /* Mark that the original imagery has been modified */
386 nativeicon
->ni_Extra
.Size
= 0;
391 case ICONCTRLA_GetImageData2
:
394 FetchIconImage(icon
, 1);
395 STORE((CONST UBYTE
**)tag
->ti_Data
, image2
->ImageData
);
400 case ICONCTRLA_SetFrameless
:
403 nativeicon
->ni_Frameless
= (BOOL
)tag
->ti_Data
;
404 /* Mark that the original imagery has been modified */
405 nativeicon
->ni_Extra
.Size
= 0;
410 case ICONCTRLA_GetFrameless
:
413 STORE((LONG
*)tag
->ti_Data
, nativeicon
->ni_Frameless
);
418 case ICONCTRLA_SetNewIconsSupport
:
422 case ICONCTRLA_GetNewIconsSupport
:
426 case ICONCTRLA_SetAspectRatio
:
429 nativeicon
->ni_Face
.Aspect
= (UBYTE
)tag
->ti_Data
;
434 case ICONCTRLA_GetAspectRatio
:
437 STORE((UBYTE
*)tag
->ti_Data
, nativeicon
->ni_Face
.Aspect
);
439 STORE((UBYTE
*)tag
->ti_Data
, ICON_ASPECT_RATIO_UNKNOWN
);
444 case ICONCTRLA_SetWidth
:
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 */
458 case ICONCTRLA_GetWidth
:
459 if (nativeicon
&& nativeicon
->ni_Face
.Width
> 0)
461 STORE((ULONG
*)tag
->ti_Data
, nativeicon
->ni_Face
.Width
);
466 case ICONCTRLA_SetHeight
:
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 */
480 case ICONCTRLA_GetHeight
:
483 STORE((ULONG
*)tag
->ti_Data
, nativeicon
->ni_Face
.Height
);
488 case ICONCTRLA_IsPaletteMapped
:
489 if (nativeicon
&& nativeicon
->ni_Image
[0].ImageData
)
491 STORE((LONG
*)tag
->ti_Data
, 1);
495 STORE((LONG
*)tag
->ti_Data
, 0);
500 case ICONCTRLA_IsNewIcon
:
501 /* NewIcons are not supported */
502 STORE((LONG
*)tag
->ti_Data
, 0);
505 case ICONCTRLA_IsNativeIcon
:
508 STORE((LONG
*)tag
->ti_Data
, 1);
512 STORE((LONG
*)tag
->ti_Data
, 0);
517 case ICONGETA_IsDefaultIcon
:
519 STORE((LONG
*)tag
->ti_Data
, (LONG
)nativeicon
->ni_IsDefault
);
521 STORE((LONG
*)tag
->ti_Data
, 0);
526 case ICONCTRLA_GetScreen
:
528 STORE((struct Screen
**)tag
->ti_Data
, nativeicon
->ni_Screen
);
530 STORE((struct Screen
**)tag
->ti_Data
, NULL
);
535 case ICONCTRLA_HasRealImage2
:
536 FetchIconImage(icon
, 1);
537 if (image2
&& image2
->ImageData
) {
538 STORE((LONG
*)tag
->ti_Data
, TRUE
);
540 STORE((LONG
*)tag
->ti_Data
, FALSE
);
544 case ICONCTRLA_GetARGBImageData1
:
547 FetchIconARGB(icon
, 0);
548 STORE((CONST ULONG
**)tag
->ti_Data
, image1
->ARGB
);
552 STORE((CONST ULONG
**)tag
->ti_Data
, NULL
);
557 case ICONCTRLA_SetARGBImageData1
:
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;
571 case ICONCTRLA_GetARGBImageData2
:
574 FetchIconARGB(icon
, 1);
575 STORE((CONST ULONG
**)tag
->ti_Data
, image2
->ARGB
);
579 STORE((CONST ULONG
**)tag
->ti_Data
, NULL
);
584 case ICONCTRLA_SetARGBImageData2
:
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;
597 case ICONCTRLA_SetScaleBox
:
600 nativeicon
->ni_ScaleBox
= (ULONG
)tag
->ti_Data
;
605 case ICONCTRLA_GetScaleBox
:
608 STORE((ULONG
*)tag
->ti_Data
, nativeicon
->ni_ScaleBox
);
614 SET_ERRORTAGITEM(tag
);
624 # undef SET_ERRORCODE
625 # undef SET_ERRORTAGITEM
627 } /* IconControlA() */