Belarusian
[AROS.git] / rom / intuition / setiprefs_aros.c
blob1893d34703bed934ed068292b7e75ba27197b47b
1 /*
2 Copyright © 1995-2010, 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>
11 #include "intuition_intern.h"
12 #include <proto/intuition.h>
14 /*****************************************************************************
16 NAME */
17 AROS_LH3(ULONG, SetIPrefs,
19 /* SYNOPSIS */
20 AROS_LHA(APTR , data, A0),
21 AROS_LHA(ULONG, length, D0),
22 AROS_LHA(ULONG, type, D1),
24 /* LOCATION */
25 struct IntuitionBase *, IntuitionBase, 96, Intuition)
27 /* FUNCTION
29 INPUTS
31 RESULT
32 Depending on the operation
34 NOTES
35 This function is currently considered private
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 HISTORY
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 ULONG Result = TRUE;
52 ULONG lock = LockIBase(0);
54 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data, length, type));
56 switch (type)
58 case IPREFS_TYPE_ICONTROL:
59 DEBUG_SETIPREFS(bug("SetIPrefs: IPREFS_TYPE_ICONTROL\n"));
60 if (length > sizeof(struct IIControlPrefs))
61 length = sizeof(struct IIControlPrefs);
62 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlPrefs, length);
64 DEBUG_SETIPREFS(bug("SetIPrefs: Drag modes: 0x%04lX\n", GetPrivIBase(IntuitionBase)->IControlPrefs.ic_VDragModes[0]));
66 break;
68 case IPREFS_TYPE_SCREENMODE:
70 struct IScreenModePrefs old_prefs;
72 DEBUG_SETIPREFS(bug("SetIPrefs: IP_SCREENMODE\n"));
73 if (length > sizeof(struct IScreenModePrefs))
74 length = sizeof(struct IScreenModePrefs);
76 if (memcmp(&GetPrivIBase(IntuitionBase)->ScreenModePrefs, data,
77 sizeof(struct IScreenModePrefs)) == 0)
78 break;
80 old_prefs = GetPrivIBase(IntuitionBase)->ScreenModePrefs;
81 GetPrivIBase(IntuitionBase)->ScreenModePrefs = *(struct IScreenModePrefs *)data;
83 if (GetPrivIBase(IntuitionBase)->WorkBench)
85 BOOL try = TRUE, closed;
87 UnlockIBase(lock);
89 while (try && !(closed = CloseWorkBench()))
91 struct EasyStruct es =
93 sizeof(struct EasyStruct),
95 "System Request",
96 "Intuition is attempting to reset the screen,\n"
97 "please close all windows except Wanderer's ones.",
98 "Retry|Cancel"
101 try = EasyRequestArgs(NULL, &es, NULL, NULL) == 1;
104 if (closed)
105 /* FIXME: handle the error condition if OpenWorkBench() fails */
106 /* What to do if OpenWorkBench() fails? Try until it succeeds?
107 Try for a finite amount of times? Don't try and do nothing
108 at all? */
109 OpenWorkBench();
110 else
112 lock = LockIBase(0);
113 GetPrivIBase(IntuitionBase)->ScreenModePrefs = old_prefs;
114 UnlockIBase(lock);
115 Result = FALSE;
118 return Result;
122 break;
125 case IPREFS_TYPE_POINTER:
126 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER\n"));
128 struct IPointerPrefs *fp = data;
129 struct TagItem pointertags[] = {
130 {POINTERA_BitMap , (IPTR)fp->BitMap},
131 {POINTERA_XOffset, fp->XOffset },
132 {POINTERA_YOffset, fp->YOffset },
133 {TAG_DONE , 0 }
136 Object *pointer = NewObjectA(
137 GetPrivIBase(IntuitionBase)->pointerclass,
138 NULL,
139 pointertags);
141 Object **oldptr = fp->Which ?
142 &GetPrivIBase(IntuitionBase)->BusyPointer :
143 &GetPrivIBase(IntuitionBase)->DefaultPointer;
145 InstallPointer(IntuitionBase, fp->Which, oldptr, pointer);
147 break;
149 case IPREFS_TYPE_OLD_PALETTE:
150 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPALETTE\n"));
152 struct ColorSpec *pp = data;
153 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
154 BOOL update_pointer = FALSE;
155 struct Preferences *ActivePrefs = GetPrivIBase(IntuitionBase)->ActivePreferences;
157 DEBUG_SETIPREFS(bug("SetIPrefs: Intuition Color32 Table 0x%p\n", p));
159 while (pp->ColorIndex != -1)
161 DEBUG_SETIPREFS(bug("SetIPrefs: Index %ld Red 0x%04lX Green 0x%04lX Blue 0x%04lX\n",
162 pp->ColorIndex, pp->Red, pp->Green, pp->Blue));
163 if (pp->ColorIndex < COLORTABLEENTRIES)
165 p[pp->ColorIndex].red = (pp->Red<<16)|pp->Red;
166 p[pp->ColorIndex].green = (pp->Green<<16)|pp->Green;
167 p[pp->ColorIndex].blue = (pp->Blue<<16)|pp->Blue;
169 /* Update oldstyle preferences */
170 if (ActivePrefs)
172 UWORD *cols = NULL;
173 UWORD baseindex;
175 if (pp->ColorIndex < 4) {
176 baseindex = 0;
177 cols = &ActivePrefs->color0;
178 } else if (pp->ColorIndex >= 8 && pp->ColorIndex <= 10) {
179 baseindex = 8;
180 cols=&ActivePrefs->color17;
181 update_pointer = TRUE;
184 if (cols)
185 cols[pp->ColorIndex - baseindex] = ((pp->Red >> 4) & 0xf00) | ((pp->Green >> 8) & 0x0f0) | (pp->Blue >> 12);
187 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
188 (LONG) pp->ColorIndex,
189 p[pp->ColorIndex].red,
190 p[pp->ColorIndex].green,
191 p[pp->ColorIndex].blue));
193 pp++;
196 if (update_pointer) {
197 DEBUG_SETIPREFS(bug("[SetIPrefs] Updating pointer colors\n"));
198 SetPointerColors(IntuitionBase);
201 break;
203 case IPREFS_TYPE_POINTER_ALPHA:
204 GetPrivIBase(IntuitionBase)->PointerAlpha = *(UWORD *)data;
205 break;
207 default:
208 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
209 Result = FALSE;
210 break;
213 UnlockIBase(lock);
215 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result));
217 return(Result);
219 AROS_LIBFUNC_EXIT
220 } /* private1 */