Check if volumes are bootable by checking whether C/Shell is compatible with
[cake.git] / rom / intuition / misc.c
blobb8489e8dc4571b6af58124ca07c2fb39421d4f03
1 /*
2 Copyright © 2002-2003 The MorphOS Development Team, All Rights Reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <exec/memory.h>
8 #include <graphics/rastport.h>
9 #include <intuition/pointerclass.h>
10 #include <proto/exec.h>
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include "intuition_intern.h"
15 #ifdef __MORPHOS__
16 struct RastPort *MyCreateRastPort(struct IntuitionBase *IntuitionBase)
18 struct RastPort *newrp = AllocMem(sizeof(*newrp), MEMF_PUBLIC);
20 if (newrp)
22 InitRastPort(newrp);
25 return newrp;
28 struct RastPort *MyCloneRastPort(struct IntuitionBase *IntuitionBase, struct RastPort *rp)
30 struct RastPort *newrp = NULL;
32 if (rp)
34 newrp = AllocMem(sizeof(*newrp), MEMF_PUBLIC);
35 if (newrp)
37 // *newrp = *rp;
39 memcpy(newrp,rp,sizeof(struct RastPort));
43 return newrp;
46 void MyFreeRastPort(struct IntuitionBase *IntuitionBase, struct RastPort *rp)
48 FreeMem(rp, sizeof(*rp));
52 void MySetPointerPos(struct IntuitionBase *IntuitionBase, int x, int y)
54 struct IntScreen *scr = GetPrivScreen(IntuitionBase->ActiveScreen);
56 IntuitionBase->MouseX = x;
57 IntuitionBase->MouseY = y;
59 if (scr)
61 #if 0
62 dprintf("MoveSprite Viewport 0x%lx %ld %ld\n",&scr->Screen.ViewPort,x + scr->Pointer->xoffset - scr->Screen.LeftEdge,y + scr->Pointer->yoffset - scr->Screen.TopEdge);
63 dprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
64 scr->Pointer->sprite->es_SimpleSprite.posctldata,
65 scr->Pointer->sprite->es_SimpleSprite.height,
66 scr->Pointer->sprite->es_SimpleSprite.x,
67 scr->Pointer->sprite->es_SimpleSprite.y,
68 scr->Pointer->sprite->es_SimpleSprite.num,
69 scr->Pointer->sprite->es_wordwidth,
70 scr->Pointer->sprite->es_flags);
71 #endif
72 MoveSprite(&scr->Screen.ViewPort, &scr->Pointer->sprite->es_SimpleSprite,
73 x + scr->Pointer->xoffset,
74 y + scr->Pointer->yoffset);
75 #if 0
76 dprintf("MoveSprite data 0x%lx, height %ld, x %ld, y %ld, num %ld, wordwidth, 0x%lx, flags 0x%lx\n",
77 scr->Pointer->sprite->es_SimpleSprite.posctldata,
78 scr->Pointer->sprite->es_SimpleSprite.height,
79 scr->Pointer->sprite->es_SimpleSprite.x,
80 scr->Pointer->sprite->es_SimpleSprite.y,
81 scr->Pointer->sprite->es_SimpleSprite.num,
82 scr->Pointer->sprite->es_wordwidth,
83 scr->Pointer->sprite->es_flags);
84 #endif
86 else
88 // dprintf("No Screen for mouseptr\n");
93 LONG IsLayerVisible(struct Layer *layer)
95 return TRUE;
98 BOOL IsLayerHiddenBySibling(struct Layer *layer, BOOL xx)
100 struct Window *win = layer->Window;
102 /* skip requesters attached to the same window. */
103 while (layer->front && layer->front->Window == win)
105 layer = layer->front;
108 /* jDc: we need to care for layers that are on
109 ** front of our layer, but don't cover it*/
111 if (layer->front)
113 struct Layer *lay;
115 for (lay = layer->front; lay; lay = lay->front)
117 struct Window *lwin = lay->Window;
119 if (lwin && win)
121 if (lwin->LeftEdge > win->LeftEdge + win->Width - 1) continue;
122 if (lwin->LeftEdge + lwin->Width - 1 < win->LeftEdge) continue;
123 if (lwin->TopEdge > win->TopEdge + win->Height - 1) continue;
124 if (lwin->TopEdge + lwin->Height - 1 < win->TopEdge) continue;
125 return TRUE;
128 return NULL;
130 } else return NULL;
133 /* Only function needed from libc.a. Oh well. */
134 long atol(const char *str)
136 long value = 0;
137 int neg = 0;
139 while (*str == ' ' || *str == '\t')
140 ++str;
141 if (*str == '-')
143 neg = 1;
144 ++str;
146 while (*str >= '0' && *str <= '9')
148 value *= 10;
149 value += *str - '0';
150 ++str;
152 if (neg)
153 value = -value;
154 return value;
157 #endif
159 struct TextFont *SafeReopenFont(struct IntuitionBase *IntuitionBase,
160 struct TextFont **fontptr)
162 struct TextFont *ret = NULL, *font;
164 /* Atomically lock the font before, so it can't go away
166 Forbid();
168 font = *fontptr;
169 if (font)
171 struct TextAttr ta;
173 font->tf_Accessors++;
174 Permit();
176 /* Now really open it
178 ta.ta_Name = font->tf_Message.mn_Node.ln_Name;
179 ta.ta_YSize = font->tf_YSize;
180 ta.ta_Style = font->tf_Style;
181 ta.ta_Flags = font->tf_Flags;
183 ret = OpenFont(&ta);
185 /* Unlock it
187 Forbid();
188 font->tf_Accessors--;
191 Permit();
193 return ret;
196 Object *MakePointerFromData(struct IntuitionBase *IntuitionBase,
197 UWORD *source, int xOffset, int yOffset, int width, int height)
199 struct BitMap bitmap;
200 Object *retval;
201 UWORD plane0[64], plane1[64];
202 UWORD *p = plane0;
203 UWORD *q = plane1;
204 UWORD *s = source;
205 UWORD mask = ~((1 << (16 - width)) - 1);
206 int k;
208 if (height > 64)
209 height = 64;
211 InitBitMap(&bitmap, 2, 16, height);
212 bitmap.Planes[0] = (PLANEPTR)plane0;
213 bitmap.Planes[1] = (PLANEPTR)plane1;
215 for (k = 0; k < height; ++k)
217 *p++ = *s++ & mask;
218 *q++ = *s++ & mask;
222 struct TagItem pointertags[] =
224 {POINTERA_BitMap , (IPTR)&bitmap },
225 {POINTERA_XOffset , xOffset },
226 {POINTERA_YOffset , yOffset },
227 {TAG_DONE }
230 retval = NewObjectA(GetPrivIBase(IntuitionBase)->pointerclass, NULL, pointertags);
233 return retval;
236 Object *MakePointerFromPrefs(struct IntuitionBase *IntuitionBase, struct Preferences *prefs)
238 SetPointerColors(IntuitionBase);
240 return MakePointerFromData(IntuitionBase,
241 prefs->PointerMatrix + 2, prefs->XOffset, prefs->YOffset, 16, 16);
244 void InstallPointer(struct IntuitionBase *IntuitionBase, Object **old, Object *pointer)
246 struct IntScreen *scr;
247 struct Window *win;
248 struct SharedPointer *oldpointer;
249 struct SharedPointer *newpointer;
251 ULONG lock = LockIBase(0);
253 GetAttr(POINTERA_SharedPointer, *old, (IPTR *)&oldpointer);
254 GetAttr(POINTERA_SharedPointer, pointer, (IPTR *)&newpointer);
256 for (scr = GetPrivScreen(IntuitionBase->FirstScreen); scr; scr = GetPrivScreen(scr->Screen.NextScreen))
258 for (win = scr->Screen.FirstWindow; win; win = win->NextWindow)
260 if (((struct IntWindow *)win)->pointer == *old)
262 win->XOffset = newpointer->xoffset;
263 win->YOffset = newpointer->yoffset;
267 if (scr->Pointer == oldpointer)
269 DEBUG_POINTER(dprintf("InstallPointer: scr 0x%lx pointer 0x%lx sprite 0x%lx\n",
270 scr, pointer, newpointer->sprite));
271 if (ChangeExtSpriteA(&scr->Screen.ViewPort,
272 oldpointer->sprite, newpointer->sprite, NULL))
274 ObtainSharedPointer(newpointer, IntuitionBase);
275 ReleaseSharedPointer(oldpointer, IntuitionBase);
276 scr->Pointer = newpointer;
278 else
280 DEBUG_POINTER(dprintf("InstallPointer: can't change pointer.\n"));
285 DisposeObject(*old);
286 *old = pointer;
288 UnlockIBase(lock);
291 void SetPointerColors(struct IntuitionBase *IntuitionBase)
293 UWORD *p;
294 int k;
295 ULONG lock = LockIBase(0);
296 //struct Screen *scr;
298 DEBUG_POINTER(dprintf("SetPointerColors()\n");)
300 p = &GetPrivIBase(IntuitionBase)->ActivePreferences->color17;
302 DEBUG_POINTER(dprintf("color17 %04lx color18 %04lx color19 %04lx color20 %04lx\n",p[0],p[1],p[2],p[3]);)
304 if (IntuitionBase->ActiveScreen)
306 for (k = 0; k < 3; ++k, ++p)
308 SetRGB4(&IntuitionBase->ActiveScreen->ViewPort,
309 k + 17, *p >> 8, (*p >> 4) & 0xf, *p & 0xf);
313 UnlockIBase(lock);
315 DEBUG_POINTER(dprintf("SetPointerColors() done\n");)
319 struct SharedPointer *CreateSharedPointer(struct ExtSprite *sprite, int x, int y,
320 struct IntuitionBase *IntuitionBase)
322 struct SharedPointer *pointer;
324 pointer = AllocMem(sizeof(*pointer), MEMF_PUBLIC);
325 if (pointer)
327 pointer->sprite = sprite;
328 pointer->xoffset = x;
329 pointer->yoffset = y;
330 pointer->ref_count = 1;
333 return pointer;
336 void ObtainSharedPointer(struct SharedPointer *pointer,
337 struct IntuitionBase *IntuitionBase)
339 ULONG lock = LockIBase(0);
340 ++pointer->ref_count;
341 UnlockIBase(lock);
344 void ReleaseSharedPointer(struct SharedPointer *pointer,
345 struct IntuitionBase *IntuitionBase)
347 ULONG lock = LockIBase(0);
348 if (--pointer->ref_count == 0)
350 FreeSpriteData(pointer->sprite);
351 FreeMem(pointer, sizeof(*pointer));
353 UnlockIBase(lock);