_screen is only valid between show/hide.
[AROS.git] / rom / intuition / setiprefs.c
blob226ae09e4156e2967e915b05790966da3d5aecd2
1 /*
2 Copyright © 1995-2019, 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("[Intuition] %s: data %p length %lu type %lu\n", __func__, data, length, type));
59 switch (type)
61 case IPREFS_TYPE_ICONTROL_V37:
62 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_ICONTROL_V37\n", __func__));
63 if (length > sizeof(struct IIControlPrefs))
64 length = sizeof(struct IIControlPrefs);
65 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlPrefs, length);
67 DEBUG_SETIPREFS(bug("[Intuition] %s: Drag modes: 0x%04lX\n", __func__, GetPrivIBase(IntuitionBase)->IControlPrefs.ic_VDragModes[0]));
69 break;
71 case IPREFS_TYPE_SCREENMODE_V37:
73 BOOL reopen = FALSE, closed = (GetPrivIBase(IntuitionBase)->WorkBench) ? FALSE : TRUE;
75 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_SCREENMODE_V37\n", __func__));
76 if (length > sizeof(struct IScreenModePrefs))
77 length = sizeof(struct IScreenModePrefs);
79 if (!GetPrivIBase(IntuitionBase)->ScreenModePrefs)
80 GetPrivIBase(IntuitionBase)->ScreenModePrefs = AllocMem(sizeof(struct IScreenModePrefs), MEMF_ANY);
82 if (memcmp(GetPrivIBase(IntuitionBase)->ScreenModePrefs, data,
83 sizeof(struct IScreenModePrefs)) == 0)
84 break;
86 if (!closed)
88 BOOL try = TRUE;
90 reopen = TRUE;
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;
110 if (closed)
111 CopyMem(data, GetPrivIBase(IntuitionBase)->ScreenModePrefs, sizeof(struct IScreenModePrefs));
113 if (reopen)
115 if (closed)
117 if (!OpenWorkBench())
119 /* FIXME: handle the error condition if OpenWorkBench() fails */
120 /* What to do if OpenWorkBench() fails? Try until it succeeds?
121 Try for a finite amount of times? Don't try and do nothing
122 at all? */
125 else
126 Result = FALSE;
127 return Result;
130 break;
133 case IPREFS_TYPE_POINTER_V39:
134 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_POINTER_V39\n", __func__));
136 struct IPointerPrefs *fp = data;
137 struct TagItem pointertags[] = {
138 {POINTERA_BitMap , (IPTR)fp->BitMap},
139 {POINTERA_XOffset, fp->XOffset },
140 {POINTERA_YOffset, fp->YOffset },
141 {TAG_DONE , 0 }
144 Object *pointer = NewObjectA(
145 GetPrivIBase(IntuitionBase)->pointerclass,
146 NULL,
147 pointertags);
149 Object **oldptr = fp->Which ?
150 &GetPrivIBase(IntuitionBase)->BusyPointer :
151 &GetPrivIBase(IntuitionBase)->DefaultPointer;
153 InstallPointer(IntuitionBase, fp->Which, oldptr, pointer);
154 /* return -1 so that WB3.x C:IPrefs is happy */
155 Result = -1;
157 break;
159 case IPREFS_TYPE_POINTER_V37:
160 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_POINTER_V37\n", __func__));
162 struct Preferences *ActivePrefs = &GetPrivIBase(IntuitionBase)->ActivePreferences;
163 struct IPointerPrefsV37 *fp = data;
164 UWORD size = fp->YSize * 2;
165 Object *pointer;
167 if (size > POINTERSIZE)
168 size = POINTERSIZE;
169 memset(ActivePrefs->PointerMatrix, 0, POINTERSIZE * sizeof (UWORD));
170 CopyMem(fp->data, ActivePrefs->PointerMatrix, size * sizeof (UWORD));
171 ActivePrefs->XOffset = fp->XOffset;
172 ActivePrefs->YOffset = fp->YOffset;
174 pointer = MakePointerFromPrefs(IntuitionBase, ActivePrefs);
175 if (pointer)
176 InstallPointer(IntuitionBase, WBP_NORMAL, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
177 /* return -1 so that WB2.x C:IPrefs is happy */
178 Result = -1;
180 break;
182 case IPREFS_TYPE_PALETTE_V39:
183 case IPREFS_TYPE_PALETTE_V37:
184 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_PALETTE_V%d %p %d\n", __func__, type == IPREFS_TYPE_PALETTE_V39 ? 39 : 37, data, length));
186 struct ColorSpec *pp = data;
187 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
188 BOOL update_pointer = FALSE;
189 struct Preferences *ActivePrefs = &GetPrivIBase(IntuitionBase)->ActivePreferences;
191 DEBUG_SETIPREFS(bug("[Intuition] %s: Intuition Color32 Table 0x%p\n", __func__, p));
193 while (pp->ColorIndex != -1)
195 WORD idx;
197 idx = pp->ColorIndex;
198 DEBUG_SETIPREFS(bug("[Intuition] %s: Index %ld R 0x%04lX G 0x%04lX B 0x%04lX\n",
199 __func__, idx, pp->Red, pp->Green, pp->Blue));
200 if (type == IPREFS_TYPE_PALETTE_V37) {
201 /* v37 cursor colors are 17 to 19 */
202 if (idx >= 17)
203 idx = idx - 17 + 8;
204 else if (idx >= 8)
205 idx = -1;
207 if (idx >= 0 && idx < COLORTABLEENTRIES)
209 UWORD red, green, blue;
210 if (type == IPREFS_TYPE_PALETTE_V37) {
211 /* 4-bit color components */
212 red = (pp->Red << 4) | pp->Red;
213 green = (pp->Green << 4) | pp->Green;
214 blue = (pp->Blue << 4) | pp->Blue;
215 red = (red << 8) | red;
216 green = (green << 8) | green;
217 blue = (blue << 8) | blue;
218 } else {
219 /* 8-bit color components */
220 red = pp->Red;
221 green = pp->Green;
222 blue = pp->Blue;
225 p[idx].red = (red << 16) | red;
226 p[idx].green = (green << 16) | green;
227 p[idx].blue = (blue << 16) | blue;
229 /* Update oldstyle preferences */
230 if (ActivePrefs)
232 UWORD *cols = NULL;
233 UWORD baseindex;
235 if (idx < 4) {
236 baseindex = 0;
237 cols = &ActivePrefs->color0;
238 } else if (idx >= 8 && idx <= 10) {
239 baseindex = 8;
240 cols=&ActivePrefs->color17;
241 update_pointer = TRUE;
244 if (cols)
245 cols[idx - baseindex] = ((red >> 4) & 0xf00) | ((green >> 8) & 0x0f0) | ((blue >> 12));
247 DEBUG_SETIPREFS(bug("[Intuition] %s: Set Color32 %ld R 0x%08lx G 0x%08lx B 0x%08lx\n",
248 __func__,
249 (LONG) idx,
250 p[idx].red,
251 p[idx].green,
252 p[idx].blue));
254 pp++;
257 if (update_pointer) {
258 DEBUG_SETIPREFS(bug("[SetIPrefs] Updating pointer colors\n", __func__));
259 SetPointerColors(IntuitionBase);
262 break;
264 case IPREFS_TYPE_PENS_V39:
265 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_PENS_V39\n", __func__));
267 struct IOldPenPrefs *fp = data;
268 UWORD *dataptr;
269 int i;
270 DEBUG_SETIPREFS(bug("[Intuition] %s: Count %ld Type %ld\n",
271 __func__,
272 (LONG) fp->Count,
273 (LONG) fp->Type));
275 if (fp->Type==0)
277 dataptr = &GetPrivIBase(IntuitionBase)->DriPens4[0];
278 DEBUG_SETIPREFS(bug("[Intuition] %s: Pens4[]\n", __func__));
280 else
282 dataptr = &GetPrivIBase(IntuitionBase)->DriPens8[0];
283 DEBUG_SETIPREFS(bug("[Intuition] %s: Pens8[]\n", __func__));
285 for (i=0;i<NUMDRIPENS;i++)
287 if (fp->PenTable[i]==(UWORD)~0UL)
290 * end of the array
292 DEBUG_SETIPREFS(bug("[Intuition] %s: PenTable end at entry %ld\n", __func__, (LONG) i));
293 break;
295 else
297 DEBUG_SETIPREFS(bug("[Intuition] %s: Pens[%ld] %ld\n",
298 __func__,
299 (LONG) i,
300 (LONG) fp->PenTable[i]));
301 dataptr[i] = fp->PenTable[i];
305 break;
308 case IPREFS_TYPE_POINTER_ALPHA:
309 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_POINTER_ALPHA\n", __func__));
310 GetPrivIBase(IntuitionBase)->PointerAlpha = *(UWORD *)data;
311 break;
313 case IPREFS_TYPE_OVERSCAN_V37:
314 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_OVERSCAN_V37\n", __func__));
315 break;
317 case IPREFS_TYPE_FONT_V37:
318 DEBUG_SETIPREFS(bug("[Intuition] %s: IP_FONT_V37\n", __func__));
320 struct IFontPrefs *fp = data;
321 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
322 struct TextFont **fontptr;
324 DEBUG_SETIPREFS(bug("[Intuition] %s: Type %d Name <%s> Size %d Font %p\n", __func__, fp->fp_ScrFont, fp->fp_Name, fp->fp_TextAttr.ta_YSize, font));
326 if (font)
328 if (fp->fp_ScrFont==0)
331 * We can't free graphics defaultfont..it`s shared
333 fontptr = &GfxBase->DefaultFont;
335 else
337 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
338 CloseFont(*fontptr);
340 *fontptr = font;
343 break;
345 default:
346 DEBUG_SETIPREFS(bug("[Intuition] %s: Unknown Prefs Type\n", __func__));
347 Result = FALSE;
348 break;
351 UnlockIBase(lock);
353 DEBUG_SETIPREFS(bug("[Intuition] %s: Result 0x%lx\n", __func__, Result));
355 return(Result);
357 AROS_LIBFUNC_EXIT
358 } /* private1 */