Don't get OOPBase in this ugly way.
[tangerine.git] / rom / intuition / setiprefs_morphos.c
blob55f1fc1d718c7363e82797391d38eb78e39dfeb0
1 /*
2 Copyright © 1995-2003, 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 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
146 ULONG Result=TRUE;
147 ULONG lock = LockIBase(0);
149 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data, length, type));
151 switch (type)
153 case IP_SCREENMODE:
154 #ifndef USEGETIPREFS
156 #ifdef MODENOTAVAILABLE
157 ULONG modeid;
158 long width,height;
159 ULONG RecalcID = FALSE;
160 #endif
162 DEBUG_SETIPREFS(bug("SetIPrefs: IP_SCREENMODE\n"));
163 if (length > sizeof(struct IScreenModePrefs))
164 length = sizeof(struct IScreenModePrefs);
165 CopyMem(data, &GetPrivIBase(IntuitionBase)->ScreenModePrefs, length);
167 #ifdef MODENOTAVAILABLE
168 modeid = GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID;
169 width = (WORD)GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Width;
170 height = (WORD)GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Height;
172 if (ModeNotAvailable(modeid))
174 RecalcID = TRUE;
178 if ((RecalcID == TRUE) && (CyberGfxBase = OpenLibrary("cybergraphics.library",40)))
180 //ULONG ID;
182 // mode specified is not available
184 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Depth = 8;
186 DEBUG_SETIPREFS(bug("WB ModeID %08lx not available (w %ld h %ld)\n",modeid,width,height));
188 // try to find a 800x600x16bit mode first
189 modeid=BestCModeIDTags( CYBRBIDTG_NominalWidth, (width == -1) ? 800 : width,
190 CYBRBIDTG_NominalHeight, (height == -1) ? 600 : height,
191 CYBRBIDTG_Depth, 16,
192 TAG_DONE );
194 if(modeid == INVALID_ID)
196 // find a 640x480x8bit fallback mode if there is no 16bit one
198 modeid=BestCModeIDTags( CYBRBIDTG_NominalWidth, (width == -1) ? 640 : width,
199 CYBRBIDTG_NominalHeight, (height == -1) ? 480 : height,
200 CYBRBIDTG_Depth, 8,
201 TAG_DONE );
205 if (modeid != INVALID_ID)
207 DEBUG_SETIPREFS(bug(" Using replacement ID %08lx\n",modeid));
209 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID = modeid;
212 CloseLibrary(CyberGfxBase);
214 #endif
216 #endif
217 break;
219 case IP_OLDICONTROL:
220 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDICONTROL\n"));
221 if (length > sizeof(struct IIControlPrefs))
222 length = sizeof(struct IIControlPrefs);
223 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlPrefs, length);
224 FireMenuMessage(MMCODE_STARTCLOCK,NULL,NULL,IntuitionBase);//test if we need to restart clock
225 break;
227 case IP_IEXTENSIONS:
228 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IEXTENSIONS\n"));
229 #ifdef SKINS
230 if (length > sizeof(struct IControlExtensions))
231 length = sizeof(struct IControlExtensions);
232 CopyMem(data, &GetPrivIBase(IntuitionBase)->IControlExtensions, length);
233 #endif
234 break;
236 case IP_INPUTEXT:
237 DEBUG_SETIPREFS(bug("SetIPrefs: IP_INPUTEXT\n"));
238 #ifdef SKINS
239 if (length > sizeof(struct InputPrefsExt))
240 length = sizeof(struct InputPrefsExt);
242 CopyMem(data, &GetPrivIBase(IntuitionBase)->InputPrefsExt, length);
245 struct IOStdReq req;
247 memclr(&req,sizeof (struct IOStdReq));
249 req.io_Device = GetPrivIBase(IntuitionBase)->InputIO->io_Device;
250 req.io_Unit = GetPrivIBase(IntuitionBase)->InputIO->io_Unit;
251 req.io_Command = IND_SETMOUSETYPE;
252 req.io_Data = &GetPrivIBase(IntuitionBase)->InputPrefsExt.ip_MouseMode;
253 DoIO(&req);
256 #endif
257 break;
260 case IP_IACTIONS:
261 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IACTIONS\n"));
262 #ifdef SKINS
264 ULONG mem;
266 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->InputHandlerLock);
268 mem = GetPrivIBase(IntuitionBase)->NumIControlActions * (sizeof (struct IAction));
270 GetPrivIBase(IntuitionBase)->NumIControlActions = 0;
272 FreeMem(GetPrivIBase(IntuitionBase)->IControlActions,mem);
274 mem = (length/(sizeof (struct IAction)) * (sizeof (struct IAction)));
276 if ((GetPrivIBase(IntuitionBase)->IControlActions = AllocMem(mem,MEMF_ANY)))
279 GetPrivIBase(IntuitionBase)->NumIControlActions = mem / (sizeof (struct IAction));
280 CopyMem(data, GetPrivIBase(IntuitionBase)->IControlActions, mem);
283 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->InputHandlerLock);
285 #endif
286 break;
288 case IP_OLDFONT:
289 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDFONT\n"));
291 struct IOldFontPrefs *fp = data;
292 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
294 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));
296 if (font)
298 struct TextFont **fontptr;
299 if (fp->fp_Type==0)
302 * We can't free graphics defaultfont..it`s shared
304 fontptr = &GfxBase->DefaultFont;
306 else
308 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
309 CloseFont(*fontptr);
311 *fontptr = font;
314 break;
315 case IP_FONT:
316 DEBUG_SETIPREFS(bug("SetIPrefs: IP_FONT\n"));
318 struct IFontPrefs *fp = data;
319 struct TextFont *font = OpenFont(&fp->fp_TextAttr);
320 struct TextFont **fontptr;
322 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));
324 if (font)
326 if (fp->fp_ScrFont==0)
329 * We can't free graphics defaultfont..it`s shared
331 fontptr = &GfxBase->DefaultFont;
333 else
335 fontptr = &GetPrivIBase(IntuitionBase)->ScreenFont;
336 CloseFont(*fontptr);
338 *fontptr = font;
341 break;
343 case IP_OLDPOINTER:
344 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPOINTER\n"));
346 struct IOldPointerPrefs *fp = data;
347 Object *pointer;
348 Object **oldptr;
350 DEBUG_SETIPREFS(bug("SetIPrefs: Bitmap 0x%lx XOffset %ld YOffset %ld XResolution %ld YResolution %ld WordWidth %ld Type %ld\n",
351 (ULONG) fp->BitMap,
352 (LONG) fp->XOffset,
353 (LONG) fp->YOffset,
354 (LONG) fp->XResolution,
355 (LONG) fp->YResolution,
356 (LONG) fp->WordWidth,
357 (LONG) fp->Type));
360 struct TagItem pointertags[] =
363 POINTERA_BitMap , (ULONG) fp->BitMap
365 {POINTERA_XOffset , fp->XOffset },
366 {POINTERA_YOffset , fp->YOffset },
367 {POINTERA_XResolution , fp->XResolution },
368 {POINTERA_YResolution , fp->YResolution },
369 {POINTERA_WordWidth , fp->WordWidth },
370 {TAG_DONE }
373 pointer = NewObjectA(
374 GetPrivIBase(IntuitionBase)->pointerclass,
375 NULL,
376 pointertags);
380 oldptr = fp->Type ?
381 &GetPrivIBase(IntuitionBase)->BusyPointer :
382 &GetPrivIBase(IntuitionBase)->DefaultPointer;
384 InstallPointer(IntuitionBase, oldptr, pointer);
386 * Original iprefs checks for a 0 or -1 return
387 * otherwise it expects a returned bitmap..sigh
389 Result = -1;
391 break;
392 case IP_POINTER:
393 DEBUG_SETIPREFS(bug("SetIPrefs: IP_POINTER\n"));
395 struct IPointerPrefs *fp = data;
396 struct TagItem pointertags[] =
399 POINTERA_BitMap , (ULONG) fp->BitMap
401 {POINTERA_XOffset , fp->XOffset },
402 {POINTERA_YOffset , fp->YOffset },
403 {TAG_DONE }
406 Object *pointer = NewObjectA(
407 GetPrivIBase(IntuitionBase)->pointerclass,
408 NULL,
409 pointertags);
411 Object **oldptr = fp->Which ?
412 &GetPrivIBase(IntuitionBase)->BusyPointer :
413 &GetPrivIBase(IntuitionBase)->DefaultPointer;
415 InstallPointer(IntuitionBase, oldptr, pointer);
417 break;
419 case IP_OLDPENS:
420 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPENS\n"));
422 struct IOldPenPrefs *fp = data;
423 UWORD *dataptr;
424 int i;
425 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
426 (LONG) fp->Count,
427 (LONG) fp->Type));
429 if (fp->Type==0)
431 dataptr = &GetPrivIBase(IntuitionBase)->DriPens4[0];
432 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
434 else
436 dataptr = &GetPrivIBase(IntuitionBase)->DriPens8[0];
437 DEBUG_SETIPREFS(bug("SetIPrefs: Pens8[]\n"));
439 for (i=0;i<NUMDRIPENS;i++)
441 if (fp->PenTable[i]==(UWORD)~0UL)
444 * end of the array
446 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG) i));
447 break;
449 else
451 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
452 (LONG) i,
453 (LONG) fp->PenTable[i]));
454 dataptr[i] = fp->PenTable[i];
458 break;
460 case IP_OLDOVERSCAN:
461 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDOVERSCAN\n"));
463 struct IOldOverScanPrefs *fp = data;
464 DEBUG_SETIPREFS(bug("SetIPrefs: DisplayID 0x%lx\n",
465 fp->DisplayID));
467 DEBUG_SETIPREFS(bug("SetIPrefs: ViewPos.x %ld ViewPos.y %ld\n",
468 (LONG) fp->ViewPos.x,
469 (LONG) fp->ViewPos.y));
471 DEBUG_SETIPREFS(bug("SetIPrefs: Text.x %ld Text.y %ld\n",
472 (LONG) fp->Text.x,
473 (LONG) fp->Text.y));
475 DEBUG_SETIPREFS(bug("SetIPrefs: MinX %ld MinY %ld MaxX %ld MaxY %ld\n",
476 (LONG) fp->Standard.MinX,
477 (LONG) fp->Standard.MinY,
478 (LONG) fp->Standard.MaxX,
479 (LONG) fp->Standard.MaxY));
481 break;
483 case IP_PTRCOLOR:
484 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PTRCOLOR\n"));
485 if (IntuitionBase->ActiveScreen)
487 struct IPointerColorPrefs *fp = data;
488 if (fp->Num >= 8 && fp->Num <= 10)
490 (&GetPrivIBase(IntuitionBase)->ActivePreferences->color17)[fp->Num - 8] =
491 ((fp->Red << 4) & 0xf00) | (fp->Green & 0x0f0) | (fp->Blue >> 4);
492 SetPointerColors(IntuitionBase);
495 break;
497 case IP_OLDPALETTE:
498 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPALETTE\n"));
500 struct ColorSpec *pp = data;
501 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
503 // COLORTABLEENTRIES == 32
505 DEBUG_SETIPREFS(bug("SetIPrefs: Intuition Color32 Table 0x%lx\n", (ULONG) p));
507 while (pp->ColorIndex != ~0x0)
509 DEBUG_SETIPREFS(bug("SetIPrefs: Index %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
510 (LONG) pp->ColorIndex,
511 (ULONG) pp->Red,
512 (ULONG) pp->Green,
513 (ULONG) pp->Blue));
514 if (pp->ColorIndex < COLORTABLEENTRIES)
516 struct Preferences *ActivePrefs;
518 p[pp->ColorIndex].red = (pp->Red<<16)|pp->Red;
519 p[pp->ColorIndex].green = (pp->Green<<16)|pp->Green;
520 p[pp->ColorIndex].blue = (pp->Blue<<16)|pp->Blue;
522 // check for pointer colors
523 if ((ActivePrefs = GetPrivIBase(IntuitionBase)->ActivePreferences))
525 if (pp->ColorIndex >= 8 && pp->ColorIndex <= 10)
527 UWORD *ptrcols=&ActivePrefs->color17;
529 ptrcols[pp->ColorIndex - 8] =
530 ((pp->Red >> 4) & 0xf00) | ((pp->Green >> 8) & 0x0f0) | (pp->Blue >> 12);
533 if (IntuitionBase->ActiveScreen)
535 SetPointerColors(IntuitionBase);
539 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
540 (LONG) pp->ColorIndex,
541 p[pp->ColorIndex].red,
542 p[pp->ColorIndex].green,
543 p[pp->ColorIndex].blue));
545 else
547 DEBUG_SETIPREFS(bug("SetIPrefs: ColorIndex %ld > TableSize %ld\n",
548 (LONG) pp->ColorIndex, (LONG) COLORTABLEENTRIES));
550 pp++;
553 break;
555 case IP_PALETTE:
556 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PALETTE\n"));
558 struct PalettePrefs *pp = data;
559 int k;
560 struct Color32 *p = GetPrivIBase(IntuitionBase)->Colors;
562 CopyMem(pp->pap_4ColorPens, GetPrivIBase(IntuitionBase)->DriPens4, NUMDRIPENS * sizeof(UWORD));
563 CopyMem(pp->pap_8ColorPens, GetPrivIBase(IntuitionBase)->DriPens8, NUMDRIPENS * sizeof(UWORD));
564 for (k = 0; k < COLORTABLEENTRIES; ++k)
566 int n = pp->pap_Colors[k].ColorIndex;
567 if (n == -1)
568 break;
569 else if (n >= 0 && n < 8)
571 p[n].red = pp->pap_Colors[k].Red * 0x10001;
572 p[n].green = pp->pap_Colors[k].Green * 0x10001;
573 p[n].blue = pp->pap_Colors[k].Blue * 0x10001;
575 DEBUG_SETIPREFS(bug("SetIPrefs: Set Color32 %ld Red 0x%lx Green 0x%lx Blue 0x%lx\n",
576 (LONG) n,
577 p[n].red,
578 p[n].green,
579 p[n].blue));
582 break;
584 default:
585 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
586 Result = FALSE;
587 break;
590 UnlockIBase(lock);
592 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result));
593 return(Result);
594 AROS_LIBFUNC_EXIT
595 } /* private1 */