corrections to scren bar rendering offsets
[AROS.git] / rom / intuition / setprefs.c
blob42a6da27499c29282b9cdfe246954b03b54ab052
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2013, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include "intuition_intern.h"
10 #include <intuition/preferences.h>
11 #include <devices/input.h>
12 #include <devices/inputevent.h>
13 #include <prefs/pointer.h>
15 #include <stddef.h>
17 /* Palette update is AROS addition. Keep while backporting. */
18 static void SetColors(UWORD *p, UBYTE first, UBYTE cnt, struct IntuitionBase *IntuitionBase)
20 struct Color32 *q = GetPrivIBase(IntuitionBase)->Colors;
21 UBYTE i;
23 for (i = 0; i < cnt; i++) {
24 q[i + first].red = ((p[i] >> 8) & 0x0F) * 0x11111111;
25 q[i + first].green = ((p[i] >> 4) & 0x0F) * 0x11111111;
26 q[i + first].blue = (p[i] & 0x0F) * 0x11111111;
30 /*****************************************************************************
32 NAME */
33 #include <proto/intuition.h>
35 AROS_LH3(struct Preferences *, SetPrefs,
37 /* SYNOPSIS */
38 AROS_LHA(struct Preferences * , prefbuffer, A0),
39 AROS_LHA(LONG , size, D0),
40 AROS_LHA(BOOL , inform, D1),
42 /* LOCATION */
43 struct IntuitionBase *, IntuitionBase, 54, Intuition)
45 /* FUNCTION
46 Sets the current Preferences structure.
48 INPUTS
49 prefbuffer - The buffer which contains your settings for the
50 preferences.
51 size - The number of bytes of the buffer you want to be copied.
52 inform - If TRUE, all windows with IDCMP_NEWPREFS IDCMPFlags set
53 get an IDCMP_NEWPREFS message.
55 RESULT
56 Returns your parameter buffer.
58 NOTES
60 EXAMPLE
62 BUGS
64 SEE ALSO
65 GetDefPrefs(), GetPrefs()
67 INTERNALS
69 HISTORY
71 *****************************************************************************/
73 AROS_LIBFUNC_INIT
75 DEBUG_SETPREFS(dprintf("SetPrefs: Buffer 0x%p Size 0x%d Inform %d\n", prefbuffer, size, inform));
76 if (size > 0 && NULL != prefbuffer)
78 ULONG lock = LockIBase(0);
79 BOOL changepointer = FALSE;
81 if (size > offsetof(struct Preferences, PointerMatrix))
83 if (memcmp(&prefbuffer->PointerMatrix,&GetPrivIBase(IntuitionBase)->ActivePreferences.PointerMatrix,POINTERSIZE) != 0)
84 changepointer = TRUE;
87 if (size > offsetof(struct Preferences, color17))
89 if (memcmp(&prefbuffer->color17, &GetPrivIBase(IntuitionBase)->ActivePreferences.color17, sizeof(UWORD) * 3) != 0)
90 changepointer = TRUE;
93 CopyMem(prefbuffer,
94 &GetPrivIBase(IntuitionBase)->ActivePreferences,
95 size <= sizeof(struct Preferences) ? size : sizeof(struct Preferences));
97 UnlockIBase(lock);
99 DEBUG_SETPREFS(dprintf("SetPrefs: DoubleClick %ld.%ld\n",
100 GetPrivIBase(IntuitionBase)->ActivePreferences.DoubleClick.tv_secs,
101 GetPrivIBase(IntuitionBase)->ActivePreferences.DoubleClick.tv_micro));
103 if (GetPrivIBase(IntuitionBase)->InputIO)
105 struct timerequest req =
107 {{{0}, 0}, 0},
108 {{0}}
111 if (size > offsetof(struct Preferences, KeyRptDelay))
113 #ifdef __MORPHOS__
114 /* No need to setup a reply port, this command is guaranteed to support
115 * quick I/O.
117 #else
118 struct MsgPort *port = CreateMsgPort();
120 if (port)
122 req.tr_node.io_Message.mn_ReplyPort = port;
124 #endif
125 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptDelay %ld secs micros %ld\n",
126 GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptDelay.tv_secs,
127 GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptDelay.tv_micro));
128 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
129 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
130 req.tr_node.io_Command = IND_SETTHRESH;
131 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptDelay;
132 DoIO(&req.tr_node);
134 #ifndef __MORPHOS__
135 DeleteMsgPort(port);
137 #endif
140 if (size > offsetof(struct Preferences, KeyRptSpeed))
142 #ifdef __MORPHOS__
143 /* No need to setup a reply port, this command is guaranteed to support
144 * quick I/O.
145 * TODO: Implement the same for AROS, useful.
147 #else
148 struct MsgPort *port = CreateMsgPort();
150 if (port)
152 req.tr_node.io_Message.mn_ReplyPort = port;
153 #endif
155 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptSpeed secs %ld micros %ld\n",
156 GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptSpeed.tv_secs,
157 GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptSpeed.tv_micro));
159 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
160 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
161 req.tr_node.io_Command = IND_SETPERIOD;
162 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences.KeyRptSpeed;
163 DoIO(&req.tr_node);
165 #ifndef __MORPHOS__
166 DeleteMsgPort(port);
168 #endif
171 else
173 DEBUG_SETPREFS(dprintf("SetPrefs: no InputIO..don't set Key prefs\n"));
176 if (changepointer)
178 Object *pointer;
180 SetColors(&GetPrivIBase(IntuitionBase)->ActivePreferences.color17, 8, 3, IntuitionBase);
181 pointer = MakePointerFromPrefs(IntuitionBase, &GetPrivIBase(IntuitionBase)->ActivePreferences);
182 if (pointer)
184 InstallPointer(IntuitionBase, WBP_NORMAL, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
187 if (size > offsetof(struct Preferences, color3))
188 SetColors(&GetPrivIBase(IntuitionBase)->ActivePreferences.color0, 0, 4, IntuitionBase);
191 ** If inform == TRUE then notify all windows that want to know about
192 ** an update on the preferences.
193 ** Do that by creating an inputevent, that will be handled by our
194 ** handler and converted to idcmp messages, as well as by all other
195 ** input handlers (not sure it should be that way, but that shouldn't
196 ** do any harm).
199 if (inform)
201 struct MsgPort *port = CreateMsgPort();
203 DEBUG_SETPREFS(dprintf("SetPrefs: Send NEWPREFS event\n"));
205 if (port)
207 struct InputEvent ie;
208 struct IOStdReq req;
210 ie.ie_NextEvent = NULL;
211 ie.ie_Class = IECLASS_NEWPREFS;
212 ie.ie_SubClass = 0;
213 ie.ie_Code = 0;
214 ie.ie_Qualifier = 0;
215 ie.ie_EventAddress = NULL;
217 req.io_Message.mn_ReplyPort = port;
218 req.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
219 req.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
220 req.io_Command = IND_WRITEEVENT;
221 req.io_Length = sizeof(ie);
222 req.io_Data = &ie;
224 DoIO((struct IORequest *)&req);
226 DeleteMsgPort(port);
231 /* TODO: Is there any further immediate action to be taken when the prefences are updated? */
233 return prefbuffer;
235 AROS_LIBFUNC_EXIT
236 } /* SetPrefs() */