NListtree.mcc: fix sorted insert
[AROS.git] / rom / intuition / setiprefs.c
blobb891f3d1c9d8fff640947da5a69c6ef78f5ddd76
1 /*
2 Copyright © 1995-2013, 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 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
54 ULONG Result = TRUE;
55 ULONG lock = LockIBase(0);
57 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data, length, type));
59 switch (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]));
69 break;
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)
81 break;
83 old_prefs = GetPrivIBase(IntuitionBase)->ScreenModePrefs;
84 GetPrivIBase(IntuitionBase)->ScreenModePrefs = *(struct IScreenModePrefs *)data;
86 if (GetPrivIBase(IntuitionBase)->WorkBench)
88 BOOL try = TRUE, closed;
90 UnlockIBase(lock);
92 while (try && !(closed = CloseWorkBench()))
94 struct EasyStruct es =
96 sizeof(struct EasyStruct),
98 "System Request",
99 "Intuition is attempting to reset the screen,\n"
100 "please close all windows except Wanderer's ones.",
101 "Retry|Cancel"
104 try = EasyRequestArgs(NULL, &es, NULL, NULL) == 1;
107 if (closed)
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
111 at all? */
112 OpenWorkBench();
113 else
115 lock = LockIBase(0);
116 GetPrivIBase(IntuitionBase)->ScreenModePrefs = old_prefs;
117 UnlockIBase(lock);
118 Result = FALSE;
121 return Result;
125 break;
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 },
136 {TAG_DONE , 0 }
139 Object *pointer = NewObjectA(
140 GetPrivIBase(IntuitionBase)->pointerclass,
141 NULL,
142 pointertags);
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 */
150 Result = -1;
152 break;
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;
160 Object *pointer;
162 if (size > POINTERSIZE)
163 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);
170 if (pointer)
171 InstallPointer(IntuitionBase, WBP_NORMAL, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
172 /* return -1 so that WB2.x C:IPrefs is happy */
173 Result = -1;
175 break;
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)
190 WORD idx;
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 */
197 if (idx >= 17)
198 idx = idx - 17 + 8;
199 else if (idx >= 8)
200 idx = -1;
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;
213 } else {
214 /* 8-bit color components */
215 red = pp->Red;
216 green = pp->Green;
217 blue = pp->Blue;
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 */
225 if (ActivePrefs)
227 UWORD *cols = NULL;
228 UWORD baseindex;
230 if (idx < 4) {
231 baseindex = 0;
232 cols = &ActivePrefs->color0;
233 } else if (idx >= 8 && idx <= 10) {
234 baseindex = 8;
235 cols=&ActivePrefs->color17;
236 update_pointer = TRUE;
239 if (cols)
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",
243 (LONG) idx,
244 p[idx].red,
245 p[idx].green,
246 p[idx].blue));
248 pp++;
251 if (update_pointer) {
252 DEBUG_SETIPREFS(bug("[SetIPrefs] Updating pointer colors\n"));
253 SetPointerColors(IntuitionBase);
256 break;
258 case IPREFS_TYPE_PENS_V39:
259 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PENS_V39\n"));
261 struct IOldPenPrefs *fp = data;
262 UWORD *dataptr;
263 int i;
264 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
265 (LONG) fp->Count,
266 (LONG) fp->Type));
268 if (fp->Type==0)
270 dataptr = &GetPrivIBase(IntuitionBase)->DriPens4[0];
271 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
273 else
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)
283 * end of the array
285 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG) i));
286 break;
288 else
290 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
291 (LONG) i,
292 (LONG) fp->PenTable[i]));
293 dataptr[i] = fp->PenTable[i];
297 break;
300 case IPREFS_TYPE_POINTER_ALPHA:
301 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_POINTER_ALPHA\n"));
302 GetPrivIBase(IntuitionBase)->PointerAlpha = *(UWORD *)data;
303 break;
305 case IPREFS_TYPE_OVERSCAN_V37:
306 DEBUG_SETIPREFS(bug("[SetIPrefs]: IP_OVERSCAN_V37\n"));
307 break;
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));
318 if (font)
320 if (fp->fp_ScrFont==0)
323 * We can't free graphics defaultfont..it`s shared
325 fontptr = &GfxBase->DefaultFont;
327 else
329 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
330 CloseFont(*fontptr);
332 *fontptr = font;
335 break;
337 default:
338 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
339 Result = FALSE;
340 break;
343 UnlockIBase(lock);
345 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result));
347 return(Result);
349 AROS_LIBFUNC_EXIT
350 } /* private1 */