forcing device into host mode requires a full config - which we will do in opendevice...
[AROS.git] / rom / intuition / setiprefs.c
blob932e66e03c50ba84dee9fced0af626cbc55b0f7b
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
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 /*****************************************************************************
20 NAME */
21 AROS_LH3(ULONG, SetIPrefs,
23 /* SYNOPSIS */
24 AROS_LHA(APTR , data, A0),
25 AROS_LHA(ULONG, length, D0),
26 AROS_LHA(ULONG, type, D1),
28 /* LOCATION */
29 struct IntuitionBase *, IntuitionBase, 96, Intuition)
31 /* FUNCTION
33 INPUTS
35 RESULT
36 Depending on the operation
38 NOTES
39 This function is currently considered private
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
49 HISTORY
51 *****************************************************************************/
53 AROS_LIBFUNC_INIT
55 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
56 ULONG Result = TRUE;
57 ULONG lock = LockIBase(0);
59 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data, length, type));
61 switch (type)
63 case IPREFS_TYPE_ICONTROL_V37:
64 DEBUG_SETIPREFS(bug("SetIPrefs: IP_ICONTROL_V37\n"));
65 if (length > sizeof(struct IIControlPrefs))
66 length = sizeof(struct IIControlPrefs);
67 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlPrefs, length);
69 DEBUG_SETIPREFS(bug("SetIPrefs: Drag modes: 0x%04lX\n", GetPrivIBase(IntuitionBase)->IControlPrefs.ic_VDragModes[0]));
71 break;
73 case IPREFS_TYPE_SCREENMODE_V37:
75 struct IScreenModePrefs old_prefs;
77 DEBUG_SETIPREFS(bug("SetIPrefs: IP_SCREENMODE_V37\n"));
78 if (length > sizeof(struct IScreenModePrefs))
79 length = sizeof(struct IScreenModePrefs);
81 if (memcmp(&GetPrivIBase(IntuitionBase)->ScreenModePrefs, data,
82 sizeof(struct IScreenModePrefs)) == 0)
83 break;
85 old_prefs = GetPrivIBase(IntuitionBase)->ScreenModePrefs;
86 GetPrivIBase(IntuitionBase)->ScreenModePrefs = *(struct IScreenModePrefs *)data;
88 if (GetPrivIBase(IntuitionBase)->WorkBench)
90 BOOL try = TRUE, closed;
92 UnlockIBase(lock);
94 while (try && !(closed = CloseWorkBench()))
96 struct EasyStruct es =
98 sizeof(struct EasyStruct),
100 "System Request",
101 "Intuition is attempting to reset the screen,\n"
102 "please close all windows except Wanderer's ones.",
103 "Retry|Cancel"
106 try = EasyRequestArgs(NULL, &es, NULL, NULL) == 1;
109 if (closed)
110 /* FIXME: handle the error condition if OpenWorkBench() fails */
111 /* What to do if OpenWorkBench() fails? Try until it succeeds?
112 Try for a finite amount of times? Don't try and do nothing
113 at all? */
114 OpenWorkBench();
115 else
117 lock = LockIBase(0);
118 GetPrivIBase(IntuitionBase)->ScreenModePrefs = old_prefs;
119 UnlockIBase(lock);
120 Result = FALSE;
123 return Result;
127 break;
130 case IPREFS_TYPE_POINTER_V39:
131 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER_V39\n"));
133 struct IPointerPrefs *fp = data;
134 struct TagItem pointertags[] = {
135 {POINTERA_BitMap , (IPTR)fp->BitMap},
136 {POINTERA_XOffset, fp->XOffset },
137 {POINTERA_YOffset, fp->YOffset },
138 {TAG_DONE , 0 }
141 Object *pointer = NewObjectA(
142 GetPrivIBase(IntuitionBase)->pointerclass,
143 NULL,
144 pointertags);
146 Object **oldptr = fp->Which ?
147 &GetPrivIBase(IntuitionBase)->BusyPointer :
148 &GetPrivIBase(IntuitionBase)->DefaultPointer;
150 InstallPointer(IntuitionBase, fp->Which, oldptr, pointer);
151 /* return -1 so that WB3.x C:IPrefs is happy */
152 Result = -1;
154 break;
156 case IPREFS_TYPE_POINTER_V37:
157 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER_V37\n"));
159 struct Preferences *ActivePrefs = GetPrivIBase(IntuitionBase)->ActivePreferences;
160 struct IPointerPrefsV37 *fp = data;
161 UWORD size = fp->YSize * 2;
162 Object *pointer;
164 if (size > POINTERSIZE)
165 size = POINTERSIZE;
166 memset(ActivePrefs->PointerMatrix, 0, POINTERSIZE * sizeof (UWORD));
167 CopyMem(fp->data, ActivePrefs->PointerMatrix, size * sizeof (UWORD));
168 ActivePrefs->XOffset = fp->XOffset;
169 ActivePrefs->YOffset = fp->YOffset;
171 pointer = MakePointerFromPrefs(IntuitionBase, ActivePrefs);
172 if (pointer)
173 InstallPointer(IntuitionBase, WBP_NORMAL, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
174 /* return -1 so that WB2.x C:IPrefs is happy */
175 Result = -1;
177 break;
179 case IPREFS_TYPE_PALETTE_V39:
180 case IPREFS_TYPE_PALETTE_V37:
181 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PALETTE_V%d %p %d\n", type == IPREFS_TYPE_PALETTE_V39 ? 39 : 37, data, length));
183 struct ColorSpec *pp = data;
184 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
185 BOOL update_pointer = FALSE;
186 struct Preferences *ActivePrefs = GetPrivIBase(IntuitionBase)->ActivePreferences;
188 DEBUG_SETIPREFS(bug("SetIPrefs: Intuition Color32 Table 0x%p\n", p));
190 while (pp->ColorIndex != -1)
192 WORD idx;
194 idx = pp->ColorIndex;
195 DEBUG_SETIPREFS(bug("SetIPrefs: Index %ld R 0x%04lX G 0x%04lX B 0x%04lX\n",
196 idx, pp->Red, pp->Green, pp->Blue));
197 if (type == IPREFS_TYPE_PALETTE_V37) {
198 /* v37 cursor colors are 17 to 19 */
199 if (idx >= 17)
200 idx = idx - 17 + 8;
201 else if (idx >= 8)
202 idx = -1;
204 if (idx >= 0 && idx < COLORTABLEENTRIES)
206 UWORD red, green, blue;
207 if (type == IPREFS_TYPE_PALETTE_V37) {
208 /* 4-bit color components */
209 red = (pp->Red << 4) | pp->Red;
210 green = (pp->Green << 4) | pp->Green;
211 blue = (pp->Blue << 4) | pp->Blue;
212 red = (red << 8) | red;
213 green = (green << 8) | green;
214 blue = (blue << 8) | blue;
215 } else {
216 /* 8-bit color components */
217 red = pp->Red;
218 green = pp->Green;
219 blue = pp->Blue;
222 p[idx].red = (red << 16) | red;
223 p[idx].green = (green << 16) | green;
224 p[idx].blue = (blue << 16) | blue;
226 /* Update oldstyle preferences */
227 if (ActivePrefs)
229 UWORD *cols = NULL;
230 UWORD baseindex;
232 if (idx < 4) {
233 baseindex = 0;
234 cols = &ActivePrefs->color0;
235 } else if (idx >= 8 && idx <= 10) {
236 baseindex = 8;
237 cols=&ActivePrefs->color17;
238 update_pointer = TRUE;
241 if (cols)
242 cols[idx - baseindex] = ((red >> 4) & 0xf00) | ((green >> 8) & 0x0f0) | ((blue >> 12));
244 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld R 0x%08lx G 0x%08lx B 0x%08lx\n",
245 (LONG) idx,
246 p[idx].red,
247 p[idx].green,
248 p[idx].blue));
250 pp++;
253 if (update_pointer) {
254 DEBUG_SETIPREFS(bug("[SetIPrefs] Updating pointer colors\n"));
255 SetPointerColors(IntuitionBase);
258 break;
260 case IPREFS_TYPE_PENS_V39:
261 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PENS_V39\n"));
263 struct IOldPenPrefs *fp = data;
264 UWORD *dataptr;
265 int i;
266 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
267 (LONG) fp->Count,
268 (LONG) fp->Type));
270 if (fp->Type==0)
272 dataptr = &GetPrivIBase(IntuitionBase)->DriPens4[0];
273 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
275 else
277 dataptr = &GetPrivIBase(IntuitionBase)->DriPens8[0];
278 DEBUG_SETIPREFS(bug("SetIPrefs: Pens8[]\n"));
280 for (i=0;i<NUMDRIPENS;i++)
282 if (fp->PenTable[i]==(UWORD)~0UL)
285 * end of the array
287 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG) i));
288 break;
290 else
292 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
293 (LONG) i,
294 (LONG) fp->PenTable[i]));
295 dataptr[i] = fp->PenTable[i];
299 break;
302 case IPREFS_TYPE_POINTER_ALPHA:
303 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_POINTER_ALPHA\n"));
304 GetPrivIBase(IntuitionBase)->PointerAlpha = *(UWORD *)data;
305 break;
307 case IPREFS_TYPE_OVERSCAN_V37:
308 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_OVERSCAN_V37\n"));
309 break;
311 case IPREFS_TYPE_FONT_V37:
312 DEBUG_SETIPREFS(bug("SetIPrefs: IP_FONT_V37\n"));
314 struct IFontPrefs *fp = data;
315 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
316 struct TextFont **fontptr;
318 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 (font)
322 if (fp->fp_ScrFont==0)
325 * We can't free graphics defaultfont..it`s shared
327 fontptr = &GfxBase->DefaultFont;
329 else
331 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
332 CloseFont(*fontptr);
334 *fontptr = font;
337 break;
339 default:
340 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
341 Result = FALSE;
342 break;
345 UnlockIBase(lock);
347 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result));
349 return(Result);
351 AROS_LIBFUNC_EXIT
352 } /* private1 */