added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / intuition_misc.c
blobd3b3b28ba6324cb1768c5b7b33f339f633d34d61
1 /*
2 Copyright 1995-2004, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <exec/types.h>
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/layers.h>
12 #include <proto/intuition.h>
13 #include <proto/cybergraphics.h>
14 #include <clib/macros.h>
15 #include <intuition/intuitionbase.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/windecorclass.h>
19 #include <intuition/scrdecorclass.h>
20 #include <intuition/preferences.h>
21 #include <intuition/extensions.h>
22 #include <graphics/layers.h>
23 #include <graphics/rpattr.h>
24 #include <graphics/gfxmacros.h>
25 #include <cybergraphx/cybergraphics.h>
27 #ifdef SKINS
28 # include "intuition_customize.h"
29 # include "intuition_extend.h"
30 # include "mosmisc.h"
31 #endif
33 #include "intuition_preferences.h"
34 #include "intuition_intern.h"
36 #include "boopsigadgets.h"
37 #include "showhide.h"
39 #include <string.h>
42 #undef DEBUG
43 #define DEBUG 0
44 # include <aros/debug.h>
46 ULONG addextragadget(struct Window *w,BOOL is_gzz,struct DrawInfo *dri,LONG relright,ULONG imagetype,ULONG gadgetid,ULONG gadgettype,struct IntuitionBase *IntuitionBase);
47 extern IPTR HookEntry();
49 /**********************************************************************************/
51 void LoadDefaultPreferences(struct IntuitionBase * IntuitionBase)
53 BYTE read_preferences = FALSE;
54 # ifdef SKINS
55 static UWORD DriPens2[NUMDRIPENS] = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 , 1 , 0};
56 static UWORD DriPens4[NUMDRIPENS] = { 1, 0, 1, 2, 1, 3, 1, 0, 2, 1, 2, 1 , 2 , 1};
57 # else
58 static UWORD DriPens2[NUMDRIPENS] = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1};
59 static UWORD DriPens4[NUMDRIPENS] = { 1, 0, 1, 2, 1, 3, 1, 0, 2, 1, 2, 1};
60 # endif /* SKINS */
63 ** Load the intuition preferences from a file on the disk
64 ** Allocate storage for the preferences, even if it's just a copy
65 ** of the default preferences.
67 GetPrivIBase(IntuitionBase)->DefaultPreferences =
68 AllocMem(sizeof(struct Preferences), MEMF_CLEAR);
70 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_DisplayID = INVALID_ID;
71 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Width = AROS_DEFAULT_WBWIDTH;
72 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Height = AROS_DEFAULT_WBHEIGHT;
73 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Depth = AROS_DEFAULT_WBDEPTH;
74 GetPrivIBase(IntuitionBase)->ScreenModePrefs.smp_Control = 0;
76 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_TimeOut = 50;
77 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_MetaDrag = IEQUALIFIER_LCOMMAND;
78 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_Flags = ICF_3DMENUS |
79 ICF_OFFSCREENLAYERS |
80 ICF_AVOIDWINBORDERERASE |
81 ICF_MODEPROMOTE |
82 ICF_MENUSNAP |
83 ICF_STRGAD_FILTER |
84 ICF_COERCE_LACE;
85 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_WBtoFront = 'N';
86 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_FrontToBack = 'M';
87 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_ReqTrue = 'V';
88 GetPrivIBase(IntuitionBase)->IControlPrefs.ic_ReqFalse = 'B';
92 * Mouse default.
94 GetPrivIBase(IntuitionBase)->DefaultPreferences->PointerTicks = 2;
96 #warning FIXME: Try to load preferences from a file!
99 /*******************************************************************
100 DOSBase = OpenLibrary("dos.library",0);
101 if (NULL != DOSBase)
103 if (NULL != (pref_file = Open("envarc:",MODE_OLDFILE)))
106 ** Read it and check whether the file was valid.
109 if (sizeof(struct Preferences) ==
110 Read(pref_file,
111 GetPrivIBase(IntuitionBase)->DefaultPreferences,
112 sizeof(struct Preferences)))
113 read_preferences = TRUE;
115 Close(pref_file);
117 CloseLibrary(DOSBase)
119 ****************************************************************/
121 if (FALSE == read_preferences)
124 ** no (valid) preferences file is available.
126 CopyMem(&IntuitionDefaultPreferences,
127 GetPrivIBase(IntuitionBase)->DefaultPreferences,
128 sizeof(struct Preferences));
133 ** Activate the preferences...
136 GetPrivIBase(IntuitionBase)->ActivePreferences =
137 AllocMem(sizeof(struct Preferences),
138 MEMF_CLEAR);
140 #if 1
141 CopyMem(GetPrivIBase(IntuitionBase)->DefaultPreferences,
142 GetPrivIBase(IntuitionBase)->ActivePreferences,
143 sizeof(struct Preferences));
144 #else
145 SetPrefs(GetPrivIBase(IntuitionBase)->DefaultPreferences,
146 sizeof(struct Preferences),
147 FALSE/*TRUE*/);
148 #endif
150 CopyMem(DriPens2, GetPrivIBase(IntuitionBase)->DriPens2, sizeof(DriPens2));
151 CopyMem(DriPens4, GetPrivIBase(IntuitionBase)->DriPens4, sizeof(DriPens4));
152 CopyMem(DriPens4, GetPrivIBase(IntuitionBase)->DriPens8, sizeof(DriPens4));
155 /**********************************************************************************/
157 void CheckRectFill(struct RastPort *rp, WORD x1, WORD y1, WORD x2, WORD y2,
158 struct IntuitionBase * IntuitionBase)
161 if ((x2 >= x1) && (y2 >= y1))
163 RectFill(rp, x1, y1, x2, y2);
167 /**********************************************************************************/
169 #define TITLEBAR_HEIGHT (w->BorderTop)
171 Object* CreateStdSysImage(WORD which, WORD preferred_height, struct Screen *scr, APTR buffer,
172 struct DrawInfo *dri, struct IntuitionBase *IntuitionBase)
174 Object *im;
176 struct TagItem image_tags[] =
178 {SYSIA_Which , which },
179 {SYSIA_DrawInfo , (IPTR)dri },
180 {SYSIA_Size , scr->Flags & SCREENHIRES ?
181 SYSISIZE_MEDRES : SYSISIZE_LOWRES },
182 {SYSIA_UserBuffer , buffer },
183 {TAG_DONE }
186 im = NewObjectA(NULL, SYSICLASS, image_tags);
187 if (im)
189 struct TagItem size_tags[] =
191 {IA_Width , 0 },
192 {IA_Height , preferred_height },
193 {TAG_DONE }
195 IPTR width, height;
197 GetAttr(IA_Width, im, &width);
198 GetAttr(IA_Height, im, &height);
200 size_tags[0].ti_Data = preferred_height * width / height;
202 SetAttrsA(im, size_tags);
205 return im;
208 /**********************************************************************************/
210 BOOL CreateWinSysGadgets(struct Window *w, struct IntuitionBase *IntuitionBase)
213 struct DrawInfo *dri;
214 BOOL is_gzz;
216 EnterFunc(bug("CreateWinSysGadgets(w=%p)\n", w));
218 is_gzz = (w->Flags & WFLG_GIMMEZEROZERO) ? TRUE : FALSE;
220 dri = GetScreenDrawInfo(w->WScreen);
221 if (dri)
223 LONG db_left, db_width, relright,ewidth; /* dragbar sizes */
224 BOOL sysgads_ok = TRUE;
227 db_left = 0;
228 db_width = 0; /* Georg Steger: was w->Width; */
230 /* Relright of rightmost button */
231 //relright = - (TITLEBAR_HEIGHT - 1);
233 relright = 1;
235 /* Now try to create the various gadgets */
237 if (w->Flags & WFLG_SIZEGADGET)
239 /* this code must not change the 'relright' variable */
240 WORD width = ((struct IntWindow *)w)->sizeimage_width;
241 WORD height = ((struct IntWindow *)w)->sizeimage_height;
243 struct TagItem size_tags[] =
245 {GA_Image , 0 },
246 {GA_RelRight , -width + 1 },
247 {GA_RelBottom , -height + 1 },
248 {GA_Width , width },
249 {GA_Height , height },
250 {GA_SysGadget , TRUE },
251 {GA_SysGType , GTYP_SIZING },
252 {GA_BottomBorder, TRUE },
253 {GA_RightBorder , TRUE },
254 {GA_GZZGadget , is_gzz },
255 {TAG_DONE }
258 struct TagItem image_tags[] =
260 {IA_Width , width },
261 {IA_Height , height },
262 {SYSIA_Which , SIZEIMAGE },
263 {SYSIA_DrawInfo , (IPTR)dri },
264 {SYSIA_UserBuffer, ((struct IntWindow *)(w))->DecorUserBuffer },
265 {SYSIA_Size , w->WScreen->Flags & SCREENHIRES ? SYSISIZE_MEDRES : SYSISIZE_LOWRES},
266 {TAG_DONE }
268 Object *im;
270 im = NewObjectA(NULL, SYSICLASS, image_tags);
271 if (!im)
273 sysgads_ok = FALSE;
275 else
277 size_tags[0].ti_Data = (IPTR)im;
279 SYSGAD(w, SIZEGAD) = NewObjectA(NULL, BUTTONGCLASS, size_tags);
281 if (!SYSGAD(w, SIZEGAD))
283 DisposeObject(im);
284 sysgads_ok = FALSE;
289 if (w->Flags & WFLG_DEPTHGADGET)
291 struct TagItem depth_tags[] =
293 {GA_Image , 0 },
294 //{GA_RelRight , relright },
295 {GA_Top , 0 },
296 #if SQUARE_WIN_GADGETS
297 {GA_Width , TITLEBAR_HEIGHT },
298 #endif
299 {GA_Height , TITLEBAR_HEIGHT },
300 {GA_SysGadget , TRUE },
301 {GA_SysGType , GTYP_WDEPTH },
302 {GA_TopBorder , TRUE },
303 {GA_GZZGadget , is_gzz },
304 {GA_RelVerify , TRUE },
305 {TAG_DONE }
307 Object *im;
309 im = CreateStdSysImage(DEPTHIMAGE, TITLEBAR_HEIGHT, w->WScreen, ((struct IntWindow *)(w))->DecorUserBuffer, dri, IntuitionBase);
310 if (!im)
312 sysgads_ok = FALSE;
314 else
316 depth_tags[0].ti_Data = (IPTR)im;
318 SYSGAD(w, DEPTHGAD) = NewObjectA(NULL, BUTTONGCLASS, depth_tags);
320 if (!SYSGAD(w, DEPTHGAD))
322 DisposeObject(im);
323 sysgads_ok = FALSE;
325 else
327 IPTR width;
328 GetAttr(GA_Width, SYSGAD(w, DEPTHGAD), &width);
330 /*****/
332 relright -= width;
333 db_width -= width;
336 struct TagItem gadtags[] =
338 {GA_RelRight, relright },
339 /* {GA_Width , width }, */
340 {TAG_DONE }
343 SetAttrsA(SYSGAD(w, DEPTHGAD), gadtags);
350 /* RKRMs: window gets zoom gadget if WA_Zoom tag was used,
351 or if window has both a sizegadget and a depthgadget */
353 if ((w->Flags & WFLG_HASZOOM) ||
354 ((w->Flags & WFLG_SIZEGADGET) && (w->Flags & WFLG_DEPTHGADGET)))
356 struct TagItem zoom_tags[] =
358 {GA_Image , 0 },
359 //{GA_RelRight , relright },
360 {GA_Top , 0 },
361 #if SQUARE_WIN_GADGETS
362 {GA_Width , TITLEBAR_HEIGHT },
363 #endif
364 {GA_Height , TITLEBAR_HEIGHT },
365 {GA_SysGadget , TRUE },
366 {GA_SysGType , GTYP_WZOOM },
367 {GA_TopBorder , TRUE },
368 {GA_GZZGadget , is_gzz },
369 {GA_RelVerify , TRUE },
370 {TAG_DONE }
373 Object *im;
375 im = CreateStdSysImage(ZOOMIMAGE, TITLEBAR_HEIGHT, w->WScreen, ((struct IntWindow *)(w))->DecorUserBuffer, dri, IntuitionBase);
376 if (!im)
378 sysgads_ok = FALSE;
380 else
382 zoom_tags[0].ti_Data = (IPTR)im;
384 SYSGAD(w, ZOOMGAD) = NewObjectA(NULL, BUTTONGCLASS, zoom_tags);
386 if (!SYSGAD(w, ZOOMGAD))
388 DisposeObject(im);
389 sysgads_ok = FALSE;
391 else
393 IPTR width;
394 GetAttr(GA_Width, SYSGAD(w, ZOOMGAD), &width);
396 relright -= width;
397 db_width -= width;
400 struct TagItem gadtags[] =
402 {GA_RelRight, relright},
403 {TAG_DONE }
407 SetAttrsA(SYSGAD(w, ZOOMGAD), gadtags);
413 if (((struct IntWindow *)(w))->extrabuttons & ETG_LOCK)
415 ewidth = addextragadget(w,is_gzz,dri,relright,LOCKIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_Lock,LOCKGAD,IntuitionBase);
416 relright -= ewidth;
417 db_width -= ewidth;
420 if (((struct IntWindow *)(w))->extrabuttons & ETG_ICONIFY)
422 ewidth = addextragadget(w,is_gzz,dri,relright,ICONIFYIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_Iconify,ICONIFYGAD,IntuitionBase);
423 relright -= ewidth;
424 db_width -= ewidth;
427 if (((struct IntWindow *)(w))->extrabuttons & ETG_JUMP)
429 ewidth = addextragadget(w,is_gzz,dri,relright,JUMPIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_Jump,JUMPGAD,IntuitionBase);
430 relright -= ewidth;
431 db_width -= ewidth;
434 if (((struct IntWindow *)(w))->extrabuttons & ETG_SNAPSHOT)
436 ewidth = addextragadget(w,is_gzz,dri,relright,SNAPSHOTIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_Snapshot,SNAPSHOTGAD,IntuitionBase);
437 relright -= ewidth;
438 db_width -= ewidth;
441 if (((struct IntWindow *)(w))->extrabuttons & ETG_MUI)
443 ewidth = addextragadget(w,is_gzz,dri,relright,MUIIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_MUI,MUIGAD,IntuitionBase);
444 relright -= ewidth;
445 db_width -= ewidth;
448 if (((struct IntWindow *)(w))->extrabuttons & ETG_POPUP)
450 ewidth = addextragadget(w,is_gzz,dri,relright,POPUPIMAGE,((struct IntWindow *)w)->extrabuttonsid + ETD_PopUp,POPUPGAD,IntuitionBase);
451 relright -= ewidth;
452 db_width -= ewidth;
455 if (w->Flags & WFLG_CLOSEGADGET)
457 struct TagItem close_tags[] =
459 {GA_Image , 0 },
460 {GA_Left , 0 },
461 {GA_Top , 0 },
462 #if SQUARE_WIN_GADGETS
463 {GA_Width , TITLEBAR_HEIGHT },
464 #endif
465 {GA_Height , TITLEBAR_HEIGHT },
466 {GA_SysGadget , TRUE },
467 {GA_SysGType , GTYP_CLOSE },
468 {GA_TopBorder , TRUE },
469 {GA_GZZGadget , is_gzz },
470 {GA_RelVerify , TRUE },
471 {TAG_DONE }
473 Object *im;
475 im = CreateStdSysImage(CLOSEIMAGE, TITLEBAR_HEIGHT, w->WScreen, ((struct IntWindow *)(w))->DecorUserBuffer, dri,IntuitionBase);
476 if (!im)
478 sysgads_ok = FALSE;
480 else
482 close_tags[0].ti_Data = (IPTR)im;
484 SYSGAD(w, CLOSEGAD) = NewObjectA(NULL, BUTTONGCLASS, close_tags);
486 if (!SYSGAD(w, CLOSEGAD))
488 DisposeObject(im);
489 sysgads_ok = FALSE;
491 else
493 IPTR width;
494 GetAttr(GA_Width, SYSGAD(w, CLOSEGAD), &width);
496 db_left += width;
497 db_width -= width;
502 if (w->Flags & WFLG_DRAGBAR)
505 struct TagItem dragbar_tags[] =
507 {GA_Left , 0/*db_left*/ },
508 {GA_Top , 0 },
509 {GA_RelWidth , 0/*db_width*/ },
510 {GA_Height , TITLEBAR_HEIGHT },
511 {GA_SysGadget , TRUE },
512 {GA_SysGType , GTYP_WDRAGGING },
513 {GA_TopBorder , TRUE },
514 {GA_GZZGadget , is_gzz },
515 {TAG_DONE }
517 SYSGAD(w, DRAGBAR) = NewObjectA(NULL, BUTTONGCLASS, dragbar_tags);
519 if (!SYSGAD(w, DRAGBAR))
520 sysgads_ok = FALSE;
525 D(bug("Dragbar: %p\n", SYSGAD(w, DRAGBAR ) ));
526 D(bug("Depthgad: %p\n", SYSGAD(w, DEPTHGAD) ));
527 D(bug("Zoomgad: %p\n", SYSGAD(w, ZOOMGAD ) ));
528 D(bug("Closegad: %p\n", SYSGAD(w, CLOSEGAD) ));
529 D(bug("Sizegad: %p\n", SYSGAD(w, SIZEGAD ) ));
531 /* Don't need drawinfo anymore */
532 FreeScreenDrawInfo(w->WScreen, dri);
534 if (sysgads_ok)
536 int i;
539 D(bug("Adding gadgets\n"));
540 for (i = NUM_SYSGADS; --i >= 0; )
542 if (SYSGAD(w, i))
544 struct wdpLayoutBorderGadgets msg;
546 msg.MethodID = WDM_LAYOUT_BORDERGADGETS;
547 msg.wdp_Window = w;
548 msg.wdp_Gadgets = (struct Gadget *)SYSGAD(w, i);
549 msg.wdp_Flags = WDF_LBG_SYSTEMGADGET | WDF_LBG_INITIAL;
550 msg.wdp_UserBuffer = ((struct IntWindow *)(w))->DecorUserBuffer;
551 msg.wdp_ExtraButtons = ((struct IntWindow *)w)->extrabuttons;
553 msg.wdp_TrueColor = (((struct IntScreen *)w->WScreen)->DInfo.dri.dri_Flags & DRIF_DIRECTCOLOR);
554 msg.wdp_Dri = dri;
556 DoMethodA(((struct IntScreen *)(w->WScreen))->WinDecorObj, (Msg)&msg);
558 AddGadget(w, (struct Gadget *)SYSGAD(w, i), 0);
562 ReturnBool("CreateWinSysGadgets", TRUE);
564 } /* if (sysgads created) */
566 KillWinSysGadgets(w, IntuitionBase);
568 } /* if (got DrawInfo) */
569 ReturnBool("CreateWinSysGadgets", FALSE);
573 /**********************************************************************************/
575 VOID KillWinSysGadgets(struct Window *w, struct IntuitionBase *IntuitionBase)
577 /* Free system gadgets */
578 UWORD i;
580 for (i = 0; i < NUM_SYSGADS; i ++)
582 if (SYSGAD(w, i))
584 RemoveGadget( w, (struct Gadget *)SYSGAD(w, i));
585 DisposeObject((Object *)((struct Gadget *)SYSGAD(w, i))->GadgetRender);
586 DisposeObject( SYSGAD(w, i) );
591 /**********************************************************************************/
593 void CreateScreenBar(struct Screen *scr, struct IntuitionBase *IntuitionBase)
595 BOOL front = TRUE;
596 ULONG backdrop = LAYERBACKDROP;
597 WORD ypos = 0;
599 #ifdef SKINS
600 if (scr->Flags & SCREENQUIET || (GetPrivScreen(scr)->SpecialFlags & SF_InvisibleBar)) front = FALSE;
601 if (GetPrivScreen(scr)->SpecialFlags & SF_AppearingBar)
603 backdrop = 0;
604 ypos = - (scr->BarHeight + 1);
606 #else
607 if (scr->Flags & SCREENQUIET) front = FALSE;
608 #endif
610 if (!scr->BarLayer)
612 if (front)
614 scr->BarLayer = CreateUpfrontHookLayer(&scr->LayerInfo,
615 scr->RastPort.BitMap,
617 ypos,
618 scr->Width - 1,
619 scr->BarHeight + ypos, /* 1 pixel heigher than scr->BarHeight */
620 LAYERSIMPLE | backdrop,
621 LAYERS_NOBACKFILL,
622 NULL);
624 else
626 scr->BarLayer = CreateBehindHookLayer(&scr->LayerInfo,
627 scr->RastPort.BitMap,
629 ypos,
630 scr->Width - 1,
631 scr->BarHeight + ypos, /* 1 pixel heigher than scr->BarHeight */
632 LAYERSIMPLE | backdrop,
633 LAYERS_NOBACKFILL,
634 NULL);
637 if (scr->BarLayer)
639 SetFont(scr->BarLayer->rp, ((struct IntScreen *)scr)->DInfo.dri.dri_Font);
640 RenderScreenBar(scr, FALSE, IntuitionBase);
646 /**********************************************************************************/
648 void KillScreenBar(struct Screen *scr, struct IntuitionBase *IntuitionBase)
650 if (scr->BarLayer)
652 DeleteLayer(0, scr->BarLayer);
653 scr->BarLayer = FALSE;
658 /**********************************************************************************/
660 #ifdef SKINS
661 //RenderScreenBar moved to morphos/mosmisc.c
662 #endif
664 #ifndef SKINS
666 void RenderScreenBar(struct Screen *scr, BOOL refresh, struct IntuitionBase *IntuitionBase)
669 struct DrawInfo *dri = &((struct IntScreen *)scr)->DInfo.dri;
670 struct RastPort *rp;
672 if (scr->BarLayer)
674 #if USE_NEWDISPLAYBEEP
675 BOOL beeping;
676 #else
677 #define beeping 0
678 #endif
680 rp = scr->BarLayer->rp;
682 /* must lock GadgetLock to avoid deadlocks with ObtainGIRPort
683 when calling refreshgadget inside layer update state */
684 LockLayerInfo(scr->BarLayer->LayerInfo);
685 LOCKGADGET
686 LockLayer(0, scr->BarLayer);
688 #if USE_NEWDISPLAYBEEP
689 beeping = (scr->Flags & BEEPING) && GetBitMapAttr(rp->BitMap, BMA_DEPTH) > 8;
690 #endif
692 if (refresh) BeginUpdate(scr->BarLayer);
695 struct sdpDrawScreenBar msg;
697 msg.MethodID = SDM_DRAW_SCREENBAR;
698 msg.sdp_Layer = scr->BarLayer;
699 msg.sdp_RPort = rp;
700 msg.sdp_Flags = 0;
701 msg.sdp_Screen = scr;
702 msg.sdp_Dri = dri;
703 msg.sdp_UserBuffer = ((struct IntScreen *)(scr))->DecorUserBuffer;
704 msg.sdp_TrueColor = (((struct IntScreen *)scr)->DInfo.dri.dri_Flags & DRIF_DIRECTCOLOR);
706 DoMethodA(((struct IntScreen *)(scr))->ScrDecorObj, (Msg)&msg);
709 if (scr->FirstGadget)
711 RefreshBoopsiGadget(scr->FirstGadget, (struct Window *)scr, NULL, IntuitionBase);
714 if (refresh)
716 scr->BarLayer->Flags &= ~LAYERREFRESH;
717 EndUpdate(scr->BarLayer, TRUE);
722 UnlockLayer(scr->BarLayer);
723 UNLOCKGADGET
724 UnlockLayerInfo(scr->BarLayer->LayerInfo);
726 } /* if (scr->BarLayer) */
730 #endif
732 /**********************************************************************************/
734 void UpdateMouseCoords(struct Window *win)
736 WORD scrmousex = win->WScreen->MouseX;
737 WORD scrmousey = win->WScreen->MouseY;
739 win->MouseX = scrmousex - win->LeftEdge;
740 win->MouseY = scrmousey - win->TopEdge;
742 /* stegerg: AmigaOS sets this even if window is not GZZ
743 so we do the same as they are handy also for non-GZZ
744 windows */
746 win->GZZMouseX = scrmousex - (win->LeftEdge + win->BorderLeft);
747 win->GZZMouseY = scrmousey - (win->TopEdge + win->BorderTop);
750 /**********************************************************************************/
752 /* subtract rectangle b from rectangle b. resulting rectangles will be put into
753 destrectarray which must have place for at least 4 rectangles. Returns number
754 of resulting rectangles */
756 #if 0 /* use <clib/macros.h> MAX/MIN macros */
757 #undef MAX
758 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
760 #undef MIN
761 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
762 #endif
764 WORD SubtractRectFromRect(struct Rectangle *a, struct Rectangle *b, struct Rectangle *destrectarray)
766 struct Rectangle intersect;
767 BOOL intersecting = FALSE;
768 WORD numrects = 0;
770 /* calc. intersection between a and b */
772 if (a->MinX <= b->MaxX)
774 if (a->MinY <= b->MaxY)
776 if (a->MaxX >= b->MinX)
778 if (a->MaxY >= b->MinY)
780 intersect.MinX = MAX(a->MinX, b->MinX);
781 intersect.MinY = MAX(a->MinY, b->MinY);
782 intersect.MaxX = MIN(a->MaxX, b->MaxX);
783 intersect.MaxY = MIN(a->MaxY, b->MaxY);
785 intersecting = TRUE;
791 if (!intersecting)
793 destrectarray[numrects++] = *a;
795 } /* not intersecting */
796 else
798 if (intersect.MinY > a->MinY) /* upper */
800 destrectarray->MinX = a->MinX;
801 destrectarray->MinY = a->MinY;
802 destrectarray->MaxX = a->MaxX;
803 destrectarray->MaxY = intersect.MinY - 1;
805 numrects++;
806 destrectarray++;
809 if (intersect.MaxY < a->MaxY) /* lower */
811 destrectarray->MinX = a->MinX;
812 destrectarray->MinY = intersect.MaxY + 1;
813 destrectarray->MaxX = a->MaxX;
814 destrectarray->MaxY = a->MaxY;
816 numrects++;
817 destrectarray++;
820 if (intersect.MinX > a->MinX) /* left */
822 destrectarray->MinX = a->MinX;
823 destrectarray->MinY = intersect.MinY;
824 destrectarray->MaxX = intersect.MinX - 1;
825 destrectarray->MaxY = intersect.MaxY;
827 numrects++;
828 destrectarray++;
831 if (intersect.MaxX < a->MaxX) /* right */
833 destrectarray->MinX = intersect.MaxX + 1;
834 destrectarray->MinY = intersect.MinY;
835 destrectarray->MaxX = a->MaxX;
836 destrectarray->MaxY = intersect.MaxY;
838 numrects++;
839 destrectarray++;
842 } /* intersecting */
844 return numrects;
848 ULONG addextragadget(struct Window *w,BOOL is_gzz,struct DrawInfo *dri,LONG relright,ULONG imagetype,ULONG gadgetid,ULONG gadgettype,struct IntuitionBase *IntuitionBase)
850 struct TagItem gadget_tags[] =
852 {GA_Image , 0 },
853 {GA_ToggleSelect, FALSE },
854 {GA_Top , 0 },
855 {GA_Height , TITLEBAR_HEIGHT },
856 {GA_TopBorder , TRUE },
857 {GA_GZZGadget , is_gzz },
858 {GA_ID , gadgetid },
859 {GA_RelVerify , TRUE },
860 {TAG_DONE }
862 struct TagItem image_tags[] =
864 #ifdef SKINS
865 {TAG_IGNORE , 0 },
866 #else
867 {IA_Left , -1 },
868 #endif
869 {IA_Height , TITLEBAR_HEIGHT },
870 {SYSIA_Which , imagetype },
871 {SYSIA_DrawInfo , (IPTR)dri },
872 {SYSIA_Size , w->WScreen->Flags & SCREENHIRES ?
873 SYSISIZE_MEDRES : SYSISIZE_LOWRES },
874 {SYSIA_UserBuffer, ((struct IntWindow *)(w))->DecorUserBuffer },
876 {TAG_DONE }
878 Object *im;
880 if (gadgettype == LOCKGAD)
881 gadget_tags[1].ti_Data = TRUE;
883 im = NewObjectA(NULL, SYSICLASS, image_tags);
884 if (im)
886 gadget_tags[0].ti_Data = (IPTR)im;
888 SYSGAD(w, gadgettype) = NewObjectA(NULL, BUTTONGCLASS, gadget_tags);
890 if (!SYSGAD(w, gadgettype))
892 DisposeObject(im);
894 else
896 IPTR width;
897 GetAttr(GA_Width, SYSGAD(w, gadgettype), &width);
899 --width;
902 struct TagItem gadtags[] =
904 {GA_RelRight, relright - width },
905 {TAG_DONE }
908 SetAttrsA(SYSGAD(w, gadgettype), gadtags);
911 return width;
915 return 0;
919 /**********************************************************************************/
921 LONG CalcResourceHash(APTR resource)
923 LONG l1, l2, l3, l4, hash;
925 /* FIXME: Probably sucks. I have no clue about this hash stuff */
927 l1 = ((LONG)resource) & 0xFF;
928 l2 = (((LONG)resource) >> 8) & 0xFF;
929 l3 = (((LONG)resource) >> 16) & 0xFF;
930 l4 = (((LONG)resource) >> 24) & 0xFF;
932 hash = (l1 + l2 + l3 + l4) % RESOURCELIST_HASHSIZE;
934 return hash;
936 /**********************************************************************************/
938 void AddResourceToList(APTR resource, UWORD resourcetype, struct IntuitionBase *IntuitionBase)
940 struct HashNode *hn = NULL;
941 LONG hash;
942 ULONG ilock;
944 switch(resourcetype)
946 case RESOURCE_WINDOW:
947 hn = &((struct IntWindow *)resource)->hashnode;
948 hn->type = RESOURCE_WINDOW;
949 break;
951 case RESOURCE_SCREEN:
952 hn = &((struct IntScreen *)resource)->hashnode;
953 hn->type = RESOURCE_SCREEN;
954 break;
956 default:
957 D(bug("AddResourceToList: Unknown resource type!!!\n"));
958 return;
961 hash = CalcResourceHash(resource);
963 hn->resource = resource;
965 ilock = LockIBase(0);
966 AddTail((struct List *)&GetPrivIBase(IntuitionBase)->ResourceList[hash], (struct Node *)hn);
967 UnlockIBase(ilock);
970 /**********************************************************************************/
972 void RemoveResourceFromList(APTR resource, UWORD resourcetype, struct IntuitionBase *IntuitionBase)
974 struct HashNode *hn = NULL;
975 ULONG ilock;
977 switch(resourcetype)
979 case RESOURCE_WINDOW:
980 hn = &((struct IntWindow *)resource)->hashnode;
981 break;
983 case RESOURCE_SCREEN:
984 hn = &((struct IntScreen *)resource)->hashnode;
985 break;
987 default:
988 D(bug("RemoveResourceFromList: Unknown resource type!!!\n"));
989 return;
992 if (hn->type != resourcetype)
994 D(bug("RemoveResourceFromList: Panic. Resource Type mismatch!!!\n"));
997 ilock = LockIBase(0);
998 Remove((struct Node *)hn);
999 UnlockIBase(ilock);
1002 /**********************************************************************************/
1004 BOOL ResourceExisting(APTR resource, UWORD resourcetype, struct IntuitionBase *IntuitionBase)
1006 struct HashNode *hn = NULL;
1007 LONG hash;
1008 ULONG ilock;
1009 BOOL exists = FALSE;
1011 hash = CalcResourceHash(resource);
1013 ilock = LockIBase(0);
1014 ForeachNode((struct List *)&GetPrivIBase(IntuitionBase)->ResourceList[hash], hn)
1016 if ((hn->resource == resource) && (hn->type == resourcetype))
1018 exists = TRUE;
1019 break;
1022 UnlockIBase(ilock);
1024 return exists;
1027 void FireScreenNotifyMessageCode(IPTR data, ULONG flag, ULONG code, struct IntuitionBase *IntuitionBase)
1029 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase)->ScreenNotificationListLock);
1031 struct ScreenNotifyMessage *msg;
1032 struct ReplyPort *reply;
1034 struct IntScreenNotify *sn;
1035 struct Node *node;
1037 if (!IsListEmpty(&GetPrivIBase(IntuitionBase)->ScreenNotificationList))
1039 node = GetPrivIBase(IntuitionBase)->ScreenNotificationList.lh_Head;
1040 for (; node->ln_Succ; node = node->ln_Succ)
1042 sn = (struct IntScreenNotify *) node;
1043 BOOL leavescreen = FALSE;
1044 if (flag & (SNOTIFY_AFTER_OPENSCREEN | SNOTIFY_BEFORE_OPENSCREEN | SNOTIFY_AFTER_CLOSESCREEN | SNOTIFY_BEFORE_CLOSESCREEN | SNOTIFY_LOCKPUBSCREEN | SNOTIFY_UNLOCKPUBSCREEN))
1047 if ((sn->flags & flag) && !leavescreen)
1049 if (sn->port)
1051 msg = AllocMem(sizeof(struct ScreenNotifyMessage), MEMF_CLEAR);
1052 if (msg)
1054 msg->snm_Message.mn_Magic = MAGIC_SCREENNOTIFY;
1055 msg->snm_Message.mn_Version = SCREENNOTIFY_VERSION;
1056 msg->snm_Object = data;
1057 msg->snm_Class = flag;
1058 msg->snm_UserData = sn->userdata;
1059 msg->snm_Message.mn_Length = sizeof(struct ScreenNotifyMessage);
1060 if (sn->flags & SNOTIFY_WAIT_REPLY)
1062 reply = CreateMsgPort();
1063 if (reply)
1065 msg->snm_Message.mn_ReplyPort = reply;
1067 PutMsg(sn->port, (struct Message *) msg);
1068 WaitPort(reply);
1069 GetMsg(reply);
1070 FreeMem((APTR) msg, sizeof(struct ScreenNotifyMessage));
1071 DeleteMsgPort(reply);
1072 } else FreeMem((APTR) msg, sizeof(struct ScreenNotifyMessage));
1074 else
1076 msg->snm_Message.mn_ReplyPort = GetPrivIBase(IntuitionBase)->ScreenNotifyReplyPort;
1078 PutMsg(sn->port, (struct Message *) msg);
1083 else if (sn->sigtask)
1085 Signal(sn->sigtask, 1 << sn->sigbit);
1087 else if (sn->hook)
1089 struct ScreenNotifyMessage msg;
1090 msg.snm_Message.mn_Magic = MAGIC_SCREENNOTIFY;
1091 msg.snm_Message.mn_Version = SCREENNOTIFY_VERSION;
1092 msg.snm_Object = data;
1093 msg.snm_Class = flag;
1094 msg.snm_UserData = sn->userdata;
1095 msg.snm_Message.mn_Length = sizeof(struct ScreenNotifyMessage);
1097 CallHook(sn->hook, NULL, (Msg) &msg);
1102 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->ScreenNotificationListLock);
1105 void FireScreenNotifyMessage(IPTR data, ULONG flag, struct IntuitionBase *IntuitionBase)
1107 FireScreenNotifyMessageCode(data, flag, 0, IntuitionBase);
1110 /**********************************************************************************/
1112 AROS_UFH3(struct Region *, DefaultWindowShapeFunc,
1113 AROS_UFHA(struct Hook *, hook, A0),
1114 AROS_UFHA(struct Layer *, lay, A2),
1115 AROS_UFHA(struct ShapeHookMsg *, msg, A1))
1117 AROS_USERFUNC_INIT
1119 struct IntuitionBase *IntuitionBase = (struct IntuitionBase *)hook->h_Data;
1120 struct Window *win = (struct Window *)hook->h_SubEntry;
1121 struct Region *shape;
1122 struct wdpWindowShape shapemsg;
1124 shapemsg.MethodID = WDM_WINDOWSHAPE;
1125 shapemsg.wdp_TrueColor = (GetPrivScreen(win->WScreen)->DInfo.dri.dri_Flags & DRIF_DIRECTCOLOR) ? TRUE : FALSE;
1126 shapemsg.wdp_Width = msg->NewBounds.MaxX - msg->NewBounds.MinX + 1;
1127 shapemsg.wdp_Height = msg->NewBounds.MaxY - msg->NewBounds.MinY + 1;
1128 shapemsg.wdp_Window = win;
1129 shapemsg.wdp_UserBuffer = IW(win)->DecorUserBuffer;
1131 shape = (struct Region *)DoMethodA(GetPrivScreen(win->WScreen)->WinDecorObj, (Msg)&shapemsg);
1133 if (IW(win)->OutlineShape) DisposeRegion(IW(win)->OutlineShape);
1134 IW(win)->OutlineShape = shape;
1135 IW(win)->CustomShape = FALSE;
1137 return shape;
1139 AROS_USERFUNC_EXIT
1142 /**********************************************************************************/