2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
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>
13 #include "intuition_intern.h"
15 #include "inputhandler_support.h"
17 #include <cybergraphx/cybergraphics.h>
18 #include <ppcinline/cybergraphics.h>
22 #include <aros/debug.h>
29 #define MODENOTAVAILABLE
34 UWORD ip_PointerTicks
;
35 struct timeval ip_DoubleClick
;
36 struct timeval ip_KeyRptDelay
;
37 struct timeval ip_KeyRptSpeed
;
43 struct TextAttr fp_TextAttr
;
51 struct TextAttr fp_TextAttr
;
57 struct IPointerColorPrefs
67 struct IOldPointerPrefs
69 struct BitMap
*BitMap
;
80 struct BitMap
*BitMap
;
95 UWORD PenTable
[NUMDRIPENS
+1];
98 struct IOldOverScanPrefs
103 struct Rectangle Standard
;
106 /*****************************************************************************
109 #include <proto/intuition.h>
111 AROS_LH3(ULONG
, SetIPrefs
,
114 AROS_LHA(APTR
, data
, A0
),
115 AROS_LHA(ULONG
, length
, D0
),
116 AROS_LHA(ULONG
, type
, D1
),
119 struct IntuitionBase
*, IntuitionBase
, 96, Intuition
)
126 Depending on the operation
139 29-10-95 digulla automatically created from
140 intuition_lib.fd and clib/intuition_protos.h
142 *****************************************************************************/
146 ULONG lock
= LockIBase(0);
148 DEBUG_SETIPREFS(bug("SetIPrefs: data %p length %lu type %lu\n", data
, length
, type
));
155 #ifdef MODENOTAVAILABLE
158 ULONG RecalcID
= FALSE
;
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
))
177 if (RecalcID
&& (CyberGfxBase
= OpenLibrary("cybergraphics.library",40)))
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
,
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
,
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
);
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
227 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IEXTENSIONS\n"));
229 if (length
> sizeof(struct IControlExtensions
))
230 length
= sizeof(struct IControlExtensions
);
231 CopyMem(data
, &GetPrivIBase(IntuitionBase
)->IControlExtensions
, length
);
236 DEBUG_SETIPREFS(bug("SetIPrefs: IP_INPUTEXT\n"));
238 if (length
> sizeof(struct InputPrefsExt
))
239 length
= sizeof(struct InputPrefsExt
);
241 CopyMem(data
, &GetPrivIBase(IntuitionBase
)->InputPrefsExt
, length
);
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
;
260 DEBUG_SETIPREFS(bug("SetIPrefs: IP_IACTIONS\n"));
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
);
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
));
297 struct TextFont
**fontptr
;
301 * We can't free graphics defaultfont..it`s shared
303 fontptr
= &GfxBase
->DefaultFont
;
307 fontptr
= &GetPrivIBase(IntuitionBase
)->ScreenFont
;
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
));
325 if (fp
->fp_ScrFont
==0)
328 * We can't free graphics defaultfont..it`s shared
330 fontptr
= &GfxBase
->DefaultFont
;
334 fontptr
= &GetPrivIBase(IntuitionBase
)->ScreenFont
;
343 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPOINTER\n"));
345 struct IOldPointerPrefs
*fp
= data
;
349 DEBUG_SETIPREFS(bug("SetIPrefs: Bitmap 0x%lx XOffset %ld YOffset %ld XResolution %ld YResolution %ld WordWidth %ld Type %ld\n",
353 (LONG
) fp
->XResolution
,
354 (LONG
) fp
->YResolution
,
355 (LONG
) fp
->WordWidth
,
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
},
372 pointer
= NewObjectA(
373 GetPrivIBase(IntuitionBase
)->pointerclass
,
380 &GetPrivIBase(IntuitionBase
)->BusyPointer
:
381 &GetPrivIBase(IntuitionBase
)->DefaultPointer
;
383 InstallPointer(IntuitionBase
, oldptr
, pointer
);
385 * Original iprefs checks for a 0 or -1 return
386 * otherwise it expects a returned bitmap..sigh
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
},
405 Object
*pointer
= NewObjectA(
406 GetPrivIBase(IntuitionBase
)->pointerclass
,
410 Object
**oldptr
= fp
->Which
?
411 &GetPrivIBase(IntuitionBase
)->BusyPointer
:
412 &GetPrivIBase(IntuitionBase
)->DefaultPointer
;
414 InstallPointer(IntuitionBase
, oldptr
, pointer
);
419 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDPENS\n"));
421 struct IOldPenPrefs
*fp
= data
;
424 DEBUG_SETIPREFS(bug("SetIPrefs: Count %ld Type %ld\n",
430 dataptr
= &GetPrivIBase(IntuitionBase
)->DriPens4
[0];
431 DEBUG_SETIPREFS(bug("SetIPrefs: Pens4[]\n"));
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)
445 DEBUG_SETIPREFS(bug("SetIPrefs: PenTable end at entry %ld\n", (LONG
) i
));
450 DEBUG_SETIPREFS(bug("SetIPrefs: Pens[%ld] %ld\n",
452 (LONG
) fp
->PenTable
[i
]));
453 dataptr
[i
] = fp
->PenTable
[i
];
460 DEBUG_SETIPREFS(bug("SetIPrefs: IP_OLDOVERSCAN\n"));
462 struct IOldOverScanPrefs
*fp
= data
;
463 DEBUG_SETIPREFS(bug("SetIPrefs: DisplayID 0x%lx\n",
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",
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
));
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
);
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
,
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
));
546 DEBUG_SETIPREFS(bug("SetIPrefs: ColorIndex %ld > TableSize %ld\n",
547 (LONG
) pp
->ColorIndex
, (LONG
) COLORTABLEENTRIES
));
555 DEBUG_SETIPREFS(bug("SetIPrefs: IP_PALETTE\n"));
557 struct PalettePrefs
*pp
= data
;
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
;
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",
584 DEBUG_SETIPREFS(bug("SetIPrefs: Unknown Prefs Type\n"));
591 DEBUG_SETIPREFS(bug("SetIPrefs: Result 0x%lx\n",Result
));