HUNKF_FAST | HUNKF_CHIP = next long is memory flag. HUNKF_ADVISORY = ignore following...
[AROS.git] / rom / intuition / setprefs.c
blob8fc0cac77ede7cb26afc77b7de18530ba7ec695d
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 <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 static void SetColors(UWORD *p, UBYTE first, UBYTE cnt, struct IntuitionBase *IntuitionBase)
19 struct Color32 *q = GetPrivIBase(IntuitionBase)->Colors;
20 UBYTE i;
22 for (i = 0; i < cnt; i++) {
23 q[i + first].red = ((p[i] >> 8) & 0x0F) * 0x11111111;
24 q[i + first].green = ((p[i] >> 4) & 0x0F) * 0x11111111;
25 q[i + first].blue = (p[i] & 0x0F) * 0x11111111;
29 /*****************************************************************************
31 NAME */
32 #include <proto/intuition.h>
34 AROS_LH3(struct Preferences *, SetPrefs,
36 /* SYNOPSIS */
37 AROS_LHA(struct Preferences * , prefbuffer, A0),
38 AROS_LHA(LONG , size, D0),
39 AROS_LHA(BOOL , inform, D1),
41 /* LOCATION */
42 struct IntuitionBase *, IntuitionBase, 54, Intuition)
44 /* FUNCTION
45 Sets the current Preferences structure.
47 INPUTS
48 prefbuffer - The buffer which contains your settings for the
49 preferences.
50 size - The number of bytes of the buffer you want to be copied.
51 inform - If TRUE, all windows with IDCMP_NEWPREFS IDCMPFlags set
52 get an IDCMP_NEWPREFS message.
54 RESULT
55 Returns your parameter buffer.
57 NOTES
59 EXAMPLE
61 BUGS
63 SEE ALSO
64 GetDefPrefs(), GetPrefs()
66 INTERNALS
68 HISTORY
70 *****************************************************************************/
72 AROS_LIBFUNC_INIT
74 DEBUG_SETPREFS(dprintf("SetPrefs: Buffer 0x%p Size 0x%d Inform %d\n", prefbuffer, size, inform));
75 if (size > 0 && NULL != prefbuffer)
77 ULONG lock = LockIBase(0);
78 BOOL changepointer = FALSE;
80 if (size > offsetof(struct Preferences, PointerMatrix))
82 if (memcmp(&prefbuffer->PointerMatrix,&GetPrivIBase(IntuitionBase)->ActivePreferences->PointerMatrix,POINTERSIZE) != 0)
83 changepointer = TRUE;
86 if (size > offsetof(struct Preferences, color17))
88 if (memcmp(&prefbuffer->color17, &GetPrivIBase(IntuitionBase)->ActivePreferences->color17, sizeof(UWORD) * 3) != 0)
89 changepointer = TRUE;
92 CopyMem(prefbuffer,
93 GetPrivIBase(IntuitionBase)->ActivePreferences,
94 size <= sizeof(struct Preferences) ? size : sizeof(struct Preferences));
96 UnlockIBase(lock);
98 DEBUG_SETPREFS(dprintf("SetPrefs: DoubleClick %ld.%ld\n",
99 GetPrivIBase(IntuitionBase)->ActivePreferences->DoubleClick.tv_secs,
100 GetPrivIBase(IntuitionBase)->ActivePreferences->DoubleClick.tv_micro));
102 if (GetPrivIBase(IntuitionBase)->InputIO)
104 struct timerequest req =
106 {{{0}, 0}, 0},
107 {{0}}
110 if (size > offsetof(struct Preferences, KeyRptDelay))
112 #ifdef __MORPHOS__
113 /* No need to setup a reply port, this command is guaranteed to support
114 * quick I/O.
116 #else
117 struct MsgPort *port = CreateMsgPort();
119 if (port)
121 req.tr_node.io_Message.mn_ReplyPort = port;
123 #endif
124 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptDelay %ld secs micros %ld\n",
125 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay.tv_secs,
126 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay.tv_micro));
127 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
128 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
129 req.tr_node.io_Command = IND_SETTHRESH;
130 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptDelay;
131 DoIO(&req.tr_node);
133 #ifndef __MORPHOS__
134 DeleteMsgPort(port);
136 #endif
139 if (size > offsetof(struct Preferences, KeyRptSpeed))
141 #ifdef __MORPHOS__
142 /* No need to setup a reply port, this command is guaranteed to support
143 * quick I/O.
145 #else
146 struct MsgPort *port = CreateMsgPort();
148 if (port)
150 req.tr_node.io_Message.mn_ReplyPort = port;
151 #endif
153 DEBUG_SETPREFS(dprintf("SetPrefs: KeyRptSpeed secs %ld micros %ld\n",
154 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed.tv_secs,
155 GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed.tv_micro));
157 req.tr_node.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
158 req.tr_node.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
159 req.tr_node.io_Command = IND_SETPERIOD;
160 req.tr_time = GetPrivIBase(IntuitionBase)->ActivePreferences->KeyRptSpeed;
161 DoIO(&req.tr_node);
163 #ifndef __MORPHOS__
164 DeleteMsgPort(port);
166 #endif
169 else
171 DEBUG_SETPREFS(dprintf("SetPrefs: no InputIO..don't set Key prefs\n"));
174 if (changepointer)
176 Object *pointer;
178 SetColors(&GetPrivIBase(IntuitionBase)->ActivePreferences->color17, 8, 3, IntuitionBase);
179 pointer = MakePointerFromPrefs(IntuitionBase, GetPrivIBase(IntuitionBase)->ActivePreferences);
180 if (pointer)
182 InstallPointer(IntuitionBase, WBP_NORMAL, &GetPrivIBase(IntuitionBase)->DefaultPointer, pointer);
185 if (size > offsetof(struct Preferences, color3))
186 SetColors(&GetPrivIBase(IntuitionBase)->ActivePreferences->color0, 0, 4, IntuitionBase);
189 ** If inform == TRUE then notify all windows that want to know about
190 ** an update on the preferences.
191 ** Do that by creating an inputevent, that will be handled by our
192 ** handler and converted to idcmp messages, as well as by all other
193 ** input handlers (not sure it should be that way, but that shouldn't
194 ** do any harm).
197 if (inform)
199 struct MsgPort *port = CreateMsgPort();
201 DEBUG_SETPREFS(dprintf("SetPrefs: Send NEWPREFS event\n"));
203 if (port)
205 struct InputEvent ie;
206 struct IOStdReq req;
208 ie.ie_NextEvent = NULL;
209 ie.ie_Class = IECLASS_NEWPREFS;
210 ie.ie_SubClass = 0;
211 ie.ie_Code = 0;
212 ie.ie_Qualifier = 0;
213 ie.ie_EventAddress = NULL;
215 req.io_Message.mn_ReplyPort = port;
216 req.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
217 req.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
218 req.io_Command = IND_WRITEEVENT;
219 req.io_Length = sizeof(ie);
220 req.io_Data = &ie;
222 DoIO((struct IORequest *)&req);
224 DeleteMsgPort(port);
229 /* TODO: Is there any further immediate action to be taken when the prefences are updated? */
231 return (struct Preferences *) prefbuffer;
233 AROS_LIBFUNC_EXIT
234 } /* SetPrefs() */