2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 #include <proto/exec.h>
8 #include <intuition/iprefs.h>
9 #include <intuition/pointerclass.h>
10 #include <prefs/pointer.h>
11 #include <prefs/palette.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
16 #include "intuition_intern.h"
18 /*****************************************************************************
21 AROS_LH3(ULONG
, SetIPrefs
,
24 AROS_LHA(APTR
, data
, A0
),
25 AROS_LHA(ULONG
, length
, D0
),
26 AROS_LHA(ULONG
, type
, D1
),
29 struct IntuitionBase
*, IntuitionBase
, 96, Intuition
)
36 Depending on the operation.
39 This function is currently considered private.
49 *****************************************************************************/
53 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
55 ULONG lock
= LockIBase(0);
57 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data
, length
, type
));
61 case IPREFS_TYPE_ICONTROL_V37
:
62 DEBUG_SETIPREFS(bug("SetIPrefs: IP_ICONTROL_V37\n"));
63 if (length
> sizeof(struct IIControlPrefs
))
64 length
= sizeof(struct IIControlPrefs
);
65 CopyMem(data
, &GetPrivIBase(IntuitionBase
)->IControlPrefs
, length
);
67 DEBUG_SETIPREFS(bug("SetIPrefs: Drag modes: 0x%04lX\n", GetPrivIBase(IntuitionBase
)->IControlPrefs
.ic_VDragModes
[0]));
71 case IPREFS_TYPE_SCREENMODE_V37
:
73 struct IScreenModePrefs old_prefs
;
75 DEBUG_SETIPREFS(bug("SetIPrefs: IP_SCREENMODE_V37\n"));
76 if (length
> sizeof(struct IScreenModePrefs
))
77 length
= sizeof(struct IScreenModePrefs
);
79 if (memcmp(&GetPrivIBase(IntuitionBase
)->ScreenModePrefs
, data
,
80 sizeof(struct IScreenModePrefs
)) == 0)
83 old_prefs
= GetPrivIBase(IntuitionBase
)->ScreenModePrefs
;
84 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
= *(struct IScreenModePrefs
*)data
;
86 if (GetPrivIBase(IntuitionBase
)->WorkBench
)
88 BOOL
try = TRUE
, closed
;
92 while (try && !(closed
= CloseWorkBench()))
94 struct EasyStruct es
=
96 sizeof(struct EasyStruct
),
99 "Intuition is attempting to reset the screen,\n"
100 "please close all windows except Wanderer's ones.",
104 try = EasyRequestArgs(NULL
, &es
, NULL
, NULL
) == 1;
108 /* FIXME: handle the error condition if OpenWorkBench() fails */
109 /* What to do if OpenWorkBench() fails? Try until it succeeds?
110 Try for a finite amount of times? Don't try and do nothing
116 GetPrivIBase(IntuitionBase
)->ScreenModePrefs
= old_prefs
;
128 case IPREFS_TYPE_POINTER_V39
:
129 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER_V39\n"));
131 struct IPointerPrefs
*fp
= data
;
132 struct TagItem pointertags
[] = {
133 {POINTERA_BitMap
, (IPTR
)fp
->BitMap
},
134 {POINTERA_XOffset
, fp
->XOffset
},
135 {POINTERA_YOffset
, fp
->YOffset
},
139 Object
*pointer
= NewObjectA(
140 GetPrivIBase(IntuitionBase
)->pointerclass
,
144 Object
**oldptr
= fp
->Which
?
145 &GetPrivIBase(IntuitionBase
)->BusyPointer
:
146 &GetPrivIBase(IntuitionBase
)->DefaultPointer
;
148 InstallPointer(IntuitionBase
, fp
->Which
, oldptr
, pointer
);
149 /* return -1 so that WB3.x C:IPrefs is happy */
154 case IPREFS_TYPE_POINTER_V37
:
155 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER_V37\n"));
157 struct Preferences
*ActivePrefs
= &GetPrivIBase(IntuitionBase
)->ActivePreferences
;
158 struct IPointerPrefsV37
*fp
= data
;
159 UWORD size
= fp
->YSize
* 2;
162 if (size
> POINTERSIZE
)
164 memset(ActivePrefs
->PointerMatrix
, 0, POINTERSIZE
* sizeof (UWORD
));
165 CopyMem(fp
->data
, ActivePrefs
->PointerMatrix
, size
* sizeof (UWORD
));
166 ActivePrefs
->XOffset
= fp
->XOffset
;
167 ActivePrefs
->YOffset
= fp
->YOffset
;
169 pointer
= MakePointerFromPrefs(IntuitionBase
, ActivePrefs
);
171 InstallPointer(IntuitionBase
, WBP_NORMAL
, &GetPrivIBase(IntuitionBase
)->DefaultPointer
, pointer
);
172 /* return -1 so that WB2.x C:IPrefs is happy */
177 case IPREFS_TYPE_PALETTE_V39
:
178 case IPREFS_TYPE_PALETTE_V37
:
179 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PALETTE_V%d %p %d\n", type
== IPREFS_TYPE_PALETTE_V39
? 39 : 37, data
, length
));
181 struct ColorSpec
*pp
= data
;
182 struct Color32
*p
= GetPrivIBase(IntuitionBase
)->Colors
;
183 BOOL update_pointer
= FALSE
;
184 struct Preferences
*ActivePrefs
= &GetPrivIBase(IntuitionBase
)->ActivePreferences
;
186 DEBUG_SETIPREFS(bug("SetIPrefs: Intuition Color32 Table 0x%p\n", p
));
188 while (pp
->ColorIndex
!= -1)
192 idx
= pp
->ColorIndex
;
193 DEBUG_SETIPREFS(bug("SetIPrefs: Index %ld R 0x%04lX G 0x%04lX B 0x%04lX\n",
194 idx
, pp
->Red
, pp
->Green
, pp
->Blue
));
195 if (type
== IPREFS_TYPE_PALETTE_V37
) {
196 /* v37 cursor colors are 17 to 19 */
202 if (idx
>= 0 && idx
< COLORTABLEENTRIES
)
204 UWORD red
, green
, blue
;
205 if (type
== IPREFS_TYPE_PALETTE_V37
) {
206 /* 4-bit color components */
207 red
= (pp
->Red
<< 4) | pp
->Red
;
208 green
= (pp
->Green
<< 4) | pp
->Green
;
209 blue
= (pp
->Blue
<< 4) | pp
->Blue
;
210 red
= (red
<< 8) | red
;
211 green
= (green
<< 8) | green
;
212 blue
= (blue
<< 8) | blue
;
214 /* 8-bit color components */
220 p
[idx
].red
= (red
<< 16) | red
;
221 p
[idx
].green
= (green
<< 16) | green
;
222 p
[idx
].blue
= (blue
<< 16) | blue
;
224 /* Update oldstyle preferences */
232 cols
= &ActivePrefs
->color0
;
233 } else if (idx
>= 8 && idx
<= 10) {
235 cols
=&ActivePrefs
->color17
;
236 update_pointer
= TRUE
;
240 cols
[idx
- baseindex
] = ((red
>> 4) & 0xf00) | ((green
>> 8) & 0x0f0) | ((blue
>> 12));
242 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld R 0x%08lx G 0x%08lx B 0x%08lx\n",
251 if (update_pointer
) {
252 DEBUG_SETIPREFS(bug("[SetIPrefs] Updating pointer colors\n"));
253 SetPointerColors(IntuitionBase
);
258 case IPREFS_TYPE_PENS_V39
:
259 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PENS_V39\n"));
261 struct IOldPenPrefs
*fp
= data
;
264 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
270 dataptr
= &GetPrivIBase(IntuitionBase
)->DriPens4
[0];
271 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
275 dataptr
= &GetPrivIBase(IntuitionBase
)->DriPens8
[0];
276 DEBUG_SETIPREFS(bug("SetIPrefs: Pens8[]\n"));
278 for (i
=0;i
<NUMDRIPENS
;i
++)
280 if (fp
->PenTable
[i
]==(UWORD
)~0UL)
285 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG
) i
));
290 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
292 (LONG
) fp
->PenTable
[i
]));
293 dataptr
[i
] = fp
->PenTable
[i
];
300 case IPREFS_TYPE_POINTER_ALPHA
:
301 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_POINTER_ALPHA\n"));
302 GetPrivIBase(IntuitionBase
)->PointerAlpha
= *(UWORD
*)data
;
305 case IPREFS_TYPE_OVERSCAN_V37
:
306 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_OVERSCAN_V37\n"));
309 case IPREFS_TYPE_FONT_V37
:
310 DEBUG_SETIPREFS(bug("SetIPrefs: IP_FONT_V37\n"));
312 struct IFontPrefs
*fp
= data
;
313 struct TextFont
*font
= OpenFont(&fp
->fp_TextAttr
);
314 struct TextFont
**fontptr
;
316 DEBUG_SETIPREFS(bug("SetIPrefs: Type %d Name <%s> Size %d Font %p\n", fp
->fp_ScrFont
, fp
->fp_Name
, fp
->fp_TextAttr
.ta_YSize
, font
));
320 if (fp
->fp_ScrFont
==0)
323 * We can't free graphics defaultfont..it`s shared
325 fontptr
= &GfxBase
->DefaultFont
;
329 fontptr
= &GetPrivIBase(IntuitionBase
)->ScreenFont
;
338 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
345 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result
));