Nonsense removed: upper case and lower case the same time.
[AROS.git] / rom / intuition / setiprefs_morphos.c
blob5a36c93db01b6b4cb43184396d105c50171d600d
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 <proto/graphics.h>
9 #include <prefs/palette.h>
10 #include <intuition/pointerclass.h>
11 #include <devices/input.h>
12 #include <exec/io.h>
13 #include "intuition_intern.h"
14 #include "menus.h"
15 #include "inputhandler_support.h"
16 #ifdef __MORPHOS__
17 #include <cybergraphx/cybergraphics.h>
18 #include <ppcinline/cybergraphics.h>
19 #endif
20 #undef DEBUG
21 #define DEBUG 1
22 #include <aros/debug.h>
24 #ifdef IP_ICONTROL
25 #undef IP_ICONTROL
26 #endif
27 #define IP_ICONTROL 4
29 #define MODENOTAVAILABLE
30 #if 0
31 struct InputPrefs
33 char ip_Keymap[16];
34 UWORD ip_PointerTicks;
35 struct timeval ip_DoubleClick;
36 struct timeval ip_KeyRptDelay;
37 struct timeval ip_KeyRptSpeed;
38 WORD ip_MouseAccel;
40 #endif
41 struct IOldFontPrefs
43 struct TextAttr fp_TextAttr;
44 UBYTE fp_Name[32];
45 ULONG fp_NotUsed;
46 WORD fp_Type;
49 struct IFontPrefs
51 struct TextAttr fp_TextAttr;
52 UBYTE fp_Name[32];
53 ULONG fp_xxx;
54 BOOL fp_ScrFont;
57 struct IPointerColorPrefs
59 UWORD Num;
60 UWORD Red;
61 UWORD Green;
62 UWORD Blue;
63 UWORD NotZero;
64 UWORD Pad[3];
67 struct IOldPointerPrefs
69 struct BitMap *BitMap;
70 WORD XOffset;
71 WORD YOffset;
72 UWORD WordWidth;
73 UWORD XResolution;
74 UWORD YResolution;
75 UWORD Type;
78 struct IPointerPrefs
80 struct BitMap *BitMap;
81 WORD XOffset;
82 WORD YOffset;
83 UWORD BytesPerRow;
84 UWORD Size;
85 UWORD YSize;
86 UWORD Which;
87 ULONG Zero;
90 struct IOldPenPrefs
92 UWORD Count;
93 UWORD Type;
94 ULONG Pad;
95 UWORD PenTable[NUMDRIPENS+1];
98 struct IOldOverScanPrefs
100 ULONG DisplayID;
101 Point ViewPos;
102 Point Text;
103 struct Rectangle Standard;
106 /*****************************************************************************
108 NAME */
109 #include <proto/intuition.h>
111 AROS_LH3(ULONG, SetIPrefs,
113 /* SYNOPSIS */
114 AROS_LHA(APTR , data, A0),
115 AROS_LHA(ULONG, length, D0),
116 AROS_LHA(ULONG, type, D1),
118 /* LOCATION */
119 struct IntuitionBase *, IntuitionBase, 96, Intuition)
121 /* FUNCTION
123 INPUTS
125 RESULT
126 Depending on the operation
128 NOTES
130 EXAMPLE
132 BUGS
134 SEE ALSO
136 INTERNALS
138 HISTORY
139 29-10-95 digulla automatically created from
140 intuition_lib.fd and clib/intuition_protos.h
142 *****************************************************************************/
144 AROS_LIBFUNC_INIT
145 ULONG Result=TRUE;
146 ULONG lock = LockIBase(0);
148 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data, length, type));
150 switch (type)
152 case IP_SCREENMODE:
153 #ifndef USEGETIPREFS
155 #ifdef MODENOTAVAILABLE
156 ULONG modeid;
157 long width,height;
158 ULONG RecalcID = FALSE;
159 #endif
161 DEBUG_SETIPREFS(bug("SetIPrefs: IP_SCREENMODE\n"));
162 if (length > sizeof(struct IScreenModePrefs))
163 length = sizeof(struct IScreenModePrefs);
164 CopyMem(data, &GetPrivIBase(IntuitionBase)->ScreenModePrefs, length);
166 #ifdef MODENOTAVAILABLE
167 modeid = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID;
168 width = (WORD)GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Width;
169 height = (WORD)GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Height;
171 if (ModeNotAvailable(modeid))
173 RecalcID = TRUE;
177 if (RecalcID && (CyberGfxBase = OpenLibrary("cybergraphics.library",40)))
179 //ULONG ID;
181 // mode specified is not available
183 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Depth = 8;
185 DEBUG_SETIPREFS(bug("WB ModeID %08lx not available (w %ld h %ld)\n",modeid,width,height));
187 // try to find a 800x600x16bit mode first
188 modeid=BestCModeIDTags( CYBRBIDTG_NominalWidth, (width == -1) ? 800 : width,
189 CYBRBIDTG_NominalHeight, (height == -1) ? 600 : height,
190 CYBRBIDTG_Depth, 16,
191 TAG_DONE );
193 if(modeid == INVALID_ID)
195 // find a 640x480x8bit fallback mode if there is no 16bit one
197 modeid=BestCModeIDTags( CYBRBIDTG_NominalWidth, (width == -1) ? 640 : width,
198 CYBRBIDTG_NominalHeight, (height == -1) ? 480 : height,
199 CYBRBIDTG_Depth, 8,
200 TAG_DONE );
204 if (modeid != INVALID_ID)
206 DEBUG_SETIPREFS(bug(" Using replacement ID %08lx\n",modeid));
208 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID = modeid;
211 CloseLibrary(CyberGfxBase);
213 #endif
215 #endif
216 break;
218 case IP_OLDICONTROL:
219 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDICONTROL\n"));
220 if (length > sizeof(struct IIControlPrefs))
221 length = sizeof(struct IIControlPrefs);
222 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlPrefs, length);
223 FireMenuMessage(MMCODE_STARTCLOCK,NULL,NULL,IntuitionBase);//test if we need to restart clock
224 break;
226 case IP_IEXTENSIONS:
227 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IEXTENSIONS\n"));
228 #ifdef SKINS
229 if (length > sizeof(struct IControlExtensions))
230 length = sizeof(struct IControlExtensions);
231 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlExtensions, length);
232 #endif
233 break;
235 case IP_INPUTEXT:
236 DEBUG_SETIPREFS(bug("SetIPrefs: IP_INPUTEXT\n"));
237 #ifdef SKINS
238 if (length > sizeof(struct InputPrefsExt))
239 length = sizeof(struct InputPrefsExt);
241 CopyMem(data, &GetPrivIBase(IntuitionBase)->InputPrefsExt, length);
244 struct IOStdReq req;
246 memclr(&req,sizeof (struct IOStdReq));
248 req.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
249 req.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
250 req.io_Command = IND_SETMOUSETYPE;
251 req.io_Data = &GetPrivIBase(IntuitionBase)->InputPrefsExt.ip_MouseMode;
252 DoIO(&req);
255 #endif
256 break;
259 case IP_IACTIONS:
260 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IACTIONS\n"));
261 #ifdef SKINS
263 ULONG mem;
265 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->InputHandlerLock);
267 mem = GetPrivIBase(IntuitionBase)->NumIControlActions * (sizeof (struct IAction));
269 GetPrivIBase(IntuitionBase)->NumIControlActions = 0;
271 FreeMem(GetPrivIBase(IntuitionBase)->IControlActions,mem);
273 mem = (length/(sizeof (struct IAction)) * (sizeof (struct IAction)));
275 if ((GetPrivIBase(IntuitionBase)->IControlActions = AllocMem(mem,MEMF_ANY)))
278 GetPrivIBase(IntuitionBase)->NumIControlActions = mem / (sizeof (struct IAction));
279 CopyMem(data, GetPrivIBase(IntuitionBase)->IControlActions, mem);
282 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->InputHandlerLock);
284 #endif
285 break;
287 case IP_OLDFONT:
288 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDFONT\n"));
290 struct IOldFontPrefs *fp = data;
291 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
293 DEBUG_SETIPREFS(bug("SetIPrefs: Type %d Name <%s> Size %d Font %p\n", fp->fp_Type, fp->fp_Name, fp->fp_TextAttr.ta_YSize, font));
295 if (font)
297 struct TextFont **fontptr;
298 if (fp->fp_Type==0)
301 * We can't free graphics defaultfont..it`s shared
303 fontptr = &GfxBase->DefaultFont;
305 else
307 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
308 CloseFont(*fontptr);
310 *fontptr = font;
313 break;
314 case IP_FONT:
315 DEBUG_SETIPREFS(bug("SetIPrefs: IP_FONT\n"));
317 struct IFontPrefs *fp = data;
318 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
319 struct TextFont **fontptr;
321 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));
323 if (font)
325 if (fp->fp_ScrFont==0)
328 * We can't free graphics defaultfont..it`s shared
330 fontptr = &GfxBase->DefaultFont;
332 else
334 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
335 CloseFont(*fontptr);
337 *fontptr = font;
340 break;
342 case IP_OLDPOINTER:
343 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPOINTER\n"));
345 struct IOldPointerPrefs *fp = data;
346 Object *pointer;
347 Object **oldptr;
349 DEBUG_SETIPREFS(bug("SetIPrefs: Bitmap 0x%lx XOffset %ld YOffset %ld XResolution %ld YResolution %ld WordWidth %ld Type %ld\n",
350 (ULONG) fp->BitMap,
351 (LONG) fp->XOffset,
352 (LONG) fp->YOffset,
353 (LONG) fp->XResolution,
354 (LONG) fp->YResolution,
355 (LONG) fp->WordWidth,
356 (LONG) fp->Type));
359 struct TagItem pointertags[] =
362 POINTERA_BitMap , (ULONG) fp->BitMap
364 {POINTERA_XOffset , fp->XOffset },
365 {POINTERA_YOffset , fp->YOffset },
366 {POINTERA_XResolution , fp->XResolution },
367 {POINTERA_YResolution , fp->YResolution },
368 {POINTERA_WordWidth , fp->WordWidth },
369 {TAG_DONE }
372 pointer = NewObjectA(
373 GetPrivIBase(IntuitionBase)->pointerclass,
374 NULL,
375 pointertags);
379 oldptr = fp->Type ?
380 &GetPrivIBase(IntuitionBase)->BusyPointer :
381 &GetPrivIBase(IntuitionBase)->DefaultPointer;
383 InstallPointer(IntuitionBase, fp->Type, oldptr, pointer);
385 * Original iprefs checks for a 0 or -1 return
386 * otherwise it expects a returned bitmap..sigh
388 Result = -1;
390 break;
391 case IP_POINTER:
392 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER\n"));
394 struct IPointerPrefs *fp = data;
395 struct TagItem pointertags[] =
398 POINTERA_BitMap , (ULONG) fp->BitMap
400 {POINTERA_XOffset , fp->XOffset },
401 {POINTERA_YOffset , fp->YOffset },
402 {TAG_DONE }
405 Object *pointer = NewObjectA(
406 GetPrivIBase(IntuitionBase)->pointerclass,
407 NULL,
408 pointertags);
410 Object **oldptr = fp->Which ?
411 &GetPrivIBase(IntuitionBase)->BusyPointer :
412 &GetPrivIBase(IntuitionBase)->DefaultPointer;
414 InstallPointer(IntuitionBase, oldptr, pointer);
416 break;
418 case IP_OLDPENS:
419 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPENS\n"));
421 struct IOldPenPrefs *fp = data;
422 UWORD *dataptr;
423 int i;
424 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
425 (LONG) fp->Count,
426 (LONG) fp->Type));
428 if (fp->Type==0)
430 dataptr = &GetPrivIBase(IntuitionBase)->DriPens4[0];
431 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
433 else
435 dataptr = &GetPrivIBase(IntuitionBase)->DriPens8[0];
436 DEBUG_SETIPREFS(bug("SetIPrefs: Pens8[]\n"));
438 for (i=0;i<NUMDRIPENS;i++)
440 if (fp->PenTable[i]==(UWORD)~0UL)
443 * end of the array
445 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG) i));
446 break;
448 else
450 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
451 (LONG) i,
452 (LONG) fp->PenTable[i]));
453 dataptr[i] = fp->PenTable[i];
457 break;
459 case IP_OLDOVERSCAN:
460 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDOVERSCAN\n"));
462 struct IOldOverScanPrefs *fp = data;
463 DEBUG_SETIPREFS(bug("SetIPrefs: DisplayID 0x%lx\n",
464 fp->DisplayID));
466 DEBUG_SETIPREFS(bug("SetIPrefs: ViewPos.x %ld ViewPos.y %ld\n",
467 (LONG) fp->ViewPos.x,
468 (LONG) fp->ViewPos.y));
470 DEBUG_SETIPREFS(bug("SetIPrefs: Text.x %ld Text.y %ld\n",
471 (LONG) fp->Text.x,
472 (LONG) fp->Text.y));
474 DEBUG_SETIPREFS(bug("SetIPrefs: MinX %ld MinY %ld MaxX %ld MaxY %ld\n",
475 (LONG) fp->Standard.MinX,
476 (LONG) fp->Standard.MinY,
477 (LONG) fp->Standard.MaxX,
478 (LONG) fp->Standard.MaxY));
480 break;
482 case IP_PTRCOLOR:
483 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PTRCOLOR\n"));
484 if (IntuitionBase->ActiveScreen)
486 struct IPointerColorPrefs *fp = data;
487 if (fp->Num >= 8 && fp->Num <= 10)
489 (&GetPrivIBase(IntuitionBase)->ActivePreferences->color17)[fp->Num - 8] =
490 ((fp->Red << 4) & 0xf00) | (fp->Green & 0x0f0) | (fp->Blue >> 4);
491 SetPointerColors(IntuitionBase);
494 break;
496 case IP_OLDPALETTE:
497 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPALETTE\n"));
499 struct ColorSpec *pp = data;
500 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
502 // COLORTABLEENTRIES == 32
504 DEBUG_SETIPREFS(bug("SetIPrefs: Intuition Color32 Table 0x%lx\n", (ULONG) p));
506 while (pp->ColorIndex != ~0x0)
508 DEBUG_SETIPREFS(bug("SetIPrefs: Index %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
509 (LONG) pp->ColorIndex,
510 (ULONG) pp->Red,
511 (ULONG) pp->Green,
512 (ULONG) pp->Blue));
513 if (pp->ColorIndex < COLORTABLEENTRIES)
515 struct Preferences *ActivePrefs;
517 p[pp->ColorIndex].red = (pp->Red<<16)|pp->Red;
518 p[pp->ColorIndex].green = (pp->Green<<16)|pp->Green;
519 p[pp->ColorIndex].blue = (pp->Blue<<16)|pp->Blue;
521 // check for pointer colors
522 if ((ActivePrefs = GetPrivIBase(IntuitionBase)->ActivePreferences))
524 if (pp->ColorIndex >= 8 && pp->ColorIndex <= 10)
526 UWORD *ptrcols=&ActivePrefs->color17;
528 ptrcols[pp->ColorIndex - 8] =
529 ((pp->Red >> 4) & 0xf00) | ((pp->Green >> 8) & 0x0f0) | (pp->Blue >> 12);
532 if (IntuitionBase->ActiveScreen)
534 SetPointerColors(IntuitionBase);
538 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
539 (LONG) pp->ColorIndex,
540 p[pp->ColorIndex].red,
541 p[pp->ColorIndex].green,
542 p[pp->ColorIndex].blue));
544 else
546 DEBUG_SETIPREFS(bug("SetIPrefs: ColorIndex %ld > TableSize %ld\n",
547 (LONG) pp->ColorIndex, (LONG) COLORTABLEENTRIES));
549 pp++;
552 break;
554 case IP_PALETTE:
555 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PALETTE\n"));
557 struct PalettePrefs *pp = data;
558 int k;
559 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
561 CopyMem(pp->pap_4ColorPens, GetPrivIBase(IntuitionBase)->DriPens4, NUMDRIPENS * sizeof(UWORD));
562 CopyMem(pp->pap_8ColorPens, GetPrivIBase(IntuitionBase)->DriPens8, NUMDRIPENS * sizeof(UWORD));
563 for (k = 0; k < COLORTABLEENTRIES; ++k)
565 int n = pp->pap_Colors[k].ColorIndex;
566 if (n == -1)
567 break;
568 else if (n >= 0 && n < 8)
570 p[n].red = pp->pap_Colors[k].Red * 0x10001;
571 p[n].green = pp->pap_Colors[k].Green * 0x10001;
572 p[n].blue = pp->pap_Colors[k].Blue * 0x10001;
574 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
575 (LONG) n,
576 p[n].red,
577 p[n].green,
578 p[n].blue));
581 break;
583 default:
584 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
585 Result = FALSE;
586 break;
589 UnlockIBase(lock);
591 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result));
592 return(Result);
593 AROS_LIBFUNC_EXIT
594 } /* private1 */