2 Copyright 1995-2010, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
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>
28 # include "intuition_customize.h"
29 # include "intuition_extend.h"
33 #include "intuition_preferences.h"
34 #include "intuition_intern.h"
36 #include "boopsigadgets.h"
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
;
55 static CONST UWORD DriPens2
[NUMDRIPENS
] = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1 , 1 , 0};
56 static CONST UWORD DriPens4
[NUMDRIPENS
] = { 1, 0, 1, 2, 1, 3, 1, 0, 2, 1, 2, 1 , 2 , 1};
58 static CONST UWORD DriPens2
[NUMDRIPENS
] = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1};
59 static CONST UWORD DriPens4
[NUMDRIPENS
] = { 1, 0, 1, 2, 1, 3, 1, 0, 2, 1, 2, 1};
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
|
80 ICF_AVOIDWINBORDERERASE
|
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';
94 GetPrivIBase(IntuitionBase
)->DefaultPreferences
->PointerTicks
= 2;
96 /* FIXME: Try to load preferences from a file! */
99 /*******************************************************************
100 DOSBase = OpenLibrary("dos.library",0);
103 if (NULL != (pref_file = Open("envarc:",MODE_OLDFILE)))
106 ** Read it and check whether the file was valid.
109 if (sizeof(struct Preferences) ==
111 GetPrivIBase(IntuitionBase)->DefaultPreferences,
112 sizeof(struct Preferences)))
113 read_preferences = TRUE;
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
),
141 CopyMem(GetPrivIBase(IntuitionBase
)->DefaultPreferences
,
142 GetPrivIBase(IntuitionBase
)->ActivePreferences
,
143 sizeof(struct Preferences
));
145 SetPrefs(GetPrivIBase(IntuitionBase
)->DefaultPreferences
,
146 sizeof(struct Preferences
),
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
)
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
, (IPTR
)buffer
},
186 im
= NewObjectA(NULL
, SYSICLASS
, image_tags
);
189 struct TagItem size_tags
[] =
192 {IA_Height
, preferred_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
);
208 /**********************************************************************************/
210 BOOL
CreateWinSysGadgets(struct Window
*w
, struct IntuitionBase
*IntuitionBase
)
213 struct DrawInfo
*dri
;
216 EnterFunc(bug("CreateWinSysGadgets(w=%p)\n", w
));
218 is_gzz
= (w
->Flags
& WFLG_GIMMEZEROZERO
) ? TRUE
: FALSE
;
220 dri
= GetScreenDrawInfo(w
->WScreen
);
223 LONG db_left
, db_width
, relright
,ewidth
; /* dragbar sizes */
224 BOOL sysgads_ok
= TRUE
;
228 db_width
= 0; /* Georg Steger: was w->Width; */
230 /* Relright of rightmost button */
231 //relright = - (TITLEBAR_HEIGHT - 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
[] =
246 {GA_RelRight
, -width
+ 1 },
247 {GA_RelBottom
, -height
+ 1 },
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
},
258 struct TagItem image_tags
[] =
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
},
270 im
= NewObjectA(NULL
, SYSICLASS
, image_tags
);
277 size_tags
[0].ti_Data
= (IPTR
)im
;
279 SYSGAD(w
, SIZEGAD
) = NewObjectA(NULL
, BUTTONGCLASS
, size_tags
);
281 if (!SYSGAD(w
, SIZEGAD
))
289 if (w
->Flags
& WFLG_DEPTHGADGET
)
291 struct TagItem depth_tags
[] =
294 //{GA_RelRight , relright },
296 #if SQUARE_WIN_GADGETS
297 {GA_Width
, TITLEBAR_HEIGHT
},
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
},
309 im
= CreateStdSysImage(DEPTHIMAGE
, TITLEBAR_HEIGHT
, w
->WScreen
, (APTR
)((struct IntWindow
*)(w
))->DecorUserBuffer
, dri
, IntuitionBase
);
316 depth_tags
[0].ti_Data
= (IPTR
)im
;
318 SYSGAD(w
, DEPTHGAD
) = NewObjectA(NULL
, BUTTONGCLASS
, depth_tags
);
320 if (!SYSGAD(w
, DEPTHGAD
))
328 GetAttr(GA_Width
, SYSGAD(w
, DEPTHGAD
), &width
);
336 struct TagItem gadtags
[] =
338 {GA_RelRight
, relright
},
339 /* {GA_Width , width }, */
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
[] =
359 //{GA_RelRight , relright },
361 #if SQUARE_WIN_GADGETS
362 {GA_Width
, TITLEBAR_HEIGHT
},
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
},
375 im
= CreateStdSysImage(ZOOMIMAGE
, TITLEBAR_HEIGHT
, w
->WScreen
, (APTR
)((struct IntWindow
*)(w
))->DecorUserBuffer
, dri
, IntuitionBase
);
382 zoom_tags
[0].ti_Data
= (IPTR
)im
;
384 SYSGAD(w
, ZOOMGAD
) = NewObjectA(NULL
, BUTTONGCLASS
, zoom_tags
);
386 if (!SYSGAD(w
, ZOOMGAD
))
394 GetAttr(GA_Width
, SYSGAD(w
, ZOOMGAD
), &width
);
400 struct TagItem gadtags
[] =
402 {GA_RelRight
, relright
},
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
);
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
);
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
);
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
);
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
);
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
);
455 if (w
->Flags
& WFLG_CLOSEGADGET
)
457 struct TagItem close_tags
[] =
462 #if SQUARE_WIN_GADGETS
463 {GA_Width
, TITLEBAR_HEIGHT
},
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
},
475 im
= CreateStdSysImage(CLOSEIMAGE
, TITLEBAR_HEIGHT
, w
->WScreen
, (APTR
)((struct IntWindow
*)(w
))->DecorUserBuffer
, dri
,IntuitionBase
);
482 close_tags
[0].ti_Data
= (IPTR
)im
;
484 SYSGAD(w
, CLOSEGAD
) = NewObjectA(NULL
, BUTTONGCLASS
, close_tags
);
486 if (!SYSGAD(w
, CLOSEGAD
))
494 GetAttr(GA_Width
, SYSGAD(w
, CLOSEGAD
), &width
);
502 if (w
->Flags
& WFLG_DRAGBAR
)
505 struct TagItem dragbar_tags
[] =
507 {GA_Left
, 0/*db_left*/ },
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
},
517 SYSGAD(w
, DRAGBAR
) = NewObjectA(NULL
, BUTTONGCLASS
, dragbar_tags
);
519 if (!SYSGAD(w
, DRAGBAR
))
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
);
539 D(bug("Adding gadgets\n"));
540 for (i
= NUM_SYSGADS
; --i
>= 0; )
544 struct wdpLayoutBorderGadgets msg
;
546 msg
.MethodID
= WDM_LAYOUT_BORDERGADGETS
;
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
);
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 */
580 for (i
= 0; i
< NUM_SYSGADS
; 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
)
596 ULONG backdrop
= LAYERBACKDROP
;
599 D(bug("[intuition] CreateScreenBar()\n"));
602 if (scr
->Flags
& SCREENQUIET
|| (GetPrivScreen(scr
)->SpecialFlags
& SF_InvisibleBar
))
605 if (GetPrivScreen(scr
)->SpecialFlags
& SF_AppearingBar
)
608 ypos
= - (scr
->BarHeight
+ 1);
611 if (scr
->Flags
& SCREENQUIET
) front
= FALSE
;
613 D(bug("[intuition] CreateScreenBar: Got initial flags\n"));
617 D(bug("[intuition] CreateScreenBar: No current BarLayer\n"));
620 scr
->BarLayer
= CreateUpfrontHookLayer(&scr
->LayerInfo
,
621 scr
->RastPort
.BitMap
,
625 scr
->BarHeight
+ ypos
, /* 1 pixel heigher than scr->BarHeight */
626 LAYERSIMPLE
| backdrop
,
632 scr
->BarLayer
= CreateBehindHookLayer(&scr
->LayerInfo
,
633 scr
->RastPort
.BitMap
,
637 scr
->BarHeight
+ ypos
, /* 1 pixel heigher than scr->BarHeight */
638 LAYERSIMPLE
| backdrop
,
645 D(bug("[intuition] CreateScreenBar: Adding BarLayer @ %p\n", scr
->BarLayer
));
646 D(bug("[intuition] CreateScreenBar: Rastport @ %p, Font @ %p\n", scr
->BarLayer
->rp
, ((struct IntScreen
*)scr
)->DInfo
.dri
.dri_Font
));
647 SetFont(scr
->BarLayer
->rp
, ((struct IntScreen
*)scr
)->DInfo
.dri
.dri_Font
);
648 if (!(scr
->Flags
& SCREENQUIET
)) {
649 D(bug("[intuition] CreateScreenBar: Rendering Bar ...\n"));
650 RenderScreenBar(scr
, FALSE
, IntuitionBase
);
652 D(bug("[intuition] CreateScreenBar: ... done\n"));
656 D(bug("[intuition] CreateScreenBar: Failed to create BarLayer!!\n"));
661 D(bug("[intuition] CreateScreenBar: Screen already has BarLayer\n"));
665 /**********************************************************************************/
667 void KillScreenBar(struct Screen
*scr
, struct IntuitionBase
*IntuitionBase
)
671 DeleteLayer(0, scr
->BarLayer
);
672 scr
->BarLayer
= FALSE
;
677 /**********************************************************************************/
680 //RenderScreenBar moved to morphos/mosmisc.c
685 void RenderScreenBar(struct Screen
*scr
, BOOL refresh
, struct IntuitionBase
*IntuitionBase
)
688 struct DrawInfo
*dri
= &((struct IntScreen
*)scr
)->DInfo
.dri
;
691 D(bug("[intuition] RenderScreenBar()\n"));
695 #if USE_NEWDISPLAYBEEP
701 D(bug("[intuition] RenderScreenBar: BarLayer @ %p\n", scr
->BarLayer
));
703 rp
= scr
->BarLayer
->rp
;
705 D(bug("[intuition] RenderScreenBar: RastPort @ %p\n", rp
));
706 /* must lock GadgetLock to avoid deadlocks with ObtainGIRPort
707 when calling refreshgadget inside layer update state */
708 LockLayerInfo(scr
->BarLayer
->LayerInfo
);
710 LockLayer(0, scr
->BarLayer
);
712 D(bug("[intuition] RenderScreenBar: Layer locked\n"));
713 #if USE_NEWDISPLAYBEEP
714 beeping
= (scr
->Flags
& BEEPING
) && GetBitMapAttr(rp
->BitMap
, BMA_DEPTH
) > 8;
717 if (refresh
) BeginUpdate(scr
->BarLayer
);
720 struct sdpDrawScreenBar msg
;
722 D(bug("[intuition] RenderScreenBar: Begin Refresh .. \n"));
724 msg
.MethodID
= SDM_DRAW_SCREENBAR
;
725 msg
.sdp_Layer
= scr
->BarLayer
;
728 msg
.sdp_Screen
= scr
;
730 msg
.sdp_UserBuffer
= ((struct IntScreen
*)(scr
))->DecorUserBuffer
;
731 msg
.sdp_TrueColor
= (((struct IntScreen
*)(scr
))->DInfo
.dri
.dri_Flags
& DRIF_DIRECTCOLOR
);
733 D(bug("[intuition] RenderScreenBar: ScrDecorObj @ %p, DecorUserBuffer @ %p\n", ((struct IntScreen
*)(scr
))->ScrDecorObj
, ((struct IntScreen
*)(scr
))->DecorUserBuffer
));
734 DoMethodA(((struct IntScreen
*)(scr
))->ScrDecorObj
, (Msg
)&msg
);
737 D(bug("[intuition] RenderScreenBar: Update gadgets .. \n"));
739 if (scr
->FirstGadget
)
741 RefreshBoopsiGadget(scr
->FirstGadget
, (struct Window
*)scr
, NULL
, IntuitionBase
);
746 D(bug("[intuition] RenderScreenBar: End Refresh .. \n"));
747 scr
->BarLayer
->Flags
&= ~LAYERREFRESH
;
748 EndUpdate(scr
->BarLayer
, TRUE
);
751 D(bug("[intuition] RenderScreenBar: Unlock Layer ..\n"));
753 UnlockLayer(scr
->BarLayer
);
755 UnlockLayerInfo(scr
->BarLayer
->LayerInfo
);
757 } /* if (scr->BarLayer) */
758 D(bug("[intuition] RenderScreenBar: Done \n"));
763 /**********************************************************************************/
765 void UpdateMouseCoords(struct Window
*win
)
767 WORD scrmousex
= win
->WScreen
->MouseX
;
768 WORD scrmousey
= win
->WScreen
->MouseY
;
770 win
->MouseX
= scrmousex
- win
->LeftEdge
;
771 win
->MouseY
= scrmousey
- win
->TopEdge
;
773 /* stegerg: AmigaOS sets this even if window is not GZZ
774 so we do the same as they are handy also for non-GZZ
777 win
->GZZMouseX
= scrmousex
- (win
->LeftEdge
+ win
->BorderLeft
);
778 win
->GZZMouseY
= scrmousey
- (win
->TopEdge
+ win
->BorderTop
);
781 /**********************************************************************************/
783 /* subtract rectangle b from rectangle b. resulting rectangles will be put into
784 destrectarray which must have place for at least 4 rectangles. Returns number
785 of resulting rectangles */
787 #if 0 /* use <clib/macros.h> MAX/MIN macros */
789 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
792 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
795 WORD
SubtractRectFromRect(struct Rectangle
*a
, struct Rectangle
*b
, struct Rectangle
*destrectarray
)
797 struct Rectangle intersect
;
798 BOOL intersecting
= FALSE
;
801 /* calc. intersection between a and b */
803 if (a
->MinX
<= b
->MaxX
)
805 if (a
->MinY
<= b
->MaxY
)
807 if (a
->MaxX
>= b
->MinX
)
809 if (a
->MaxY
>= b
->MinY
)
811 intersect
.MinX
= MAX(a
->MinX
, b
->MinX
);
812 intersect
.MinY
= MAX(a
->MinY
, b
->MinY
);
813 intersect
.MaxX
= MIN(a
->MaxX
, b
->MaxX
);
814 intersect
.MaxY
= MIN(a
->MaxY
, b
->MaxY
);
824 destrectarray
[numrects
++] = *a
;
826 } /* not intersecting */
829 if (intersect
.MinY
> a
->MinY
) /* upper */
831 destrectarray
->MinX
= a
->MinX
;
832 destrectarray
->MinY
= a
->MinY
;
833 destrectarray
->MaxX
= a
->MaxX
;
834 destrectarray
->MaxY
= intersect
.MinY
- 1;
840 if (intersect
.MaxY
< a
->MaxY
) /* lower */
842 destrectarray
->MinX
= a
->MinX
;
843 destrectarray
->MinY
= intersect
.MaxY
+ 1;
844 destrectarray
->MaxX
= a
->MaxX
;
845 destrectarray
->MaxY
= a
->MaxY
;
851 if (intersect
.MinX
> a
->MinX
) /* left */
853 destrectarray
->MinX
= a
->MinX
;
854 destrectarray
->MinY
= intersect
.MinY
;
855 destrectarray
->MaxX
= intersect
.MinX
- 1;
856 destrectarray
->MaxY
= intersect
.MaxY
;
862 if (intersect
.MaxX
< a
->MaxX
) /* right */
864 destrectarray
->MinX
= intersect
.MaxX
+ 1;
865 destrectarray
->MinY
= intersect
.MinY
;
866 destrectarray
->MaxX
= a
->MaxX
;
867 destrectarray
->MaxY
= intersect
.MaxY
;
879 ULONG
addextragadget(struct Window
*w
,BOOL is_gzz
,struct DrawInfo
*dri
,LONG relright
,ULONG imagetype
,ULONG gadgetid
,ULONG gadgettype
,struct IntuitionBase
*IntuitionBase
)
881 struct TagItem gadget_tags
[] =
884 {GA_ToggleSelect
, FALSE
},
886 {GA_Height
, TITLEBAR_HEIGHT
},
887 {GA_TopBorder
, TRUE
},
888 {GA_GZZGadget
, is_gzz
},
890 {GA_RelVerify
, TRUE
},
893 struct TagItem image_tags
[] =
900 {IA_Height
, TITLEBAR_HEIGHT
},
901 {SYSIA_Which
, imagetype
},
902 {SYSIA_DrawInfo
, (IPTR
)dri
},
903 {SYSIA_Size
, w
->WScreen
->Flags
& SCREENHIRES
?
904 SYSISIZE_MEDRES
: SYSISIZE_LOWRES
},
905 {SYSIA_UserBuffer
, ((struct IntWindow
*)(w
))->DecorUserBuffer
},
911 if (gadgettype
== LOCKGAD
)
912 gadget_tags
[1].ti_Data
= TRUE
;
914 im
= NewObjectA(NULL
, SYSICLASS
, image_tags
);
917 gadget_tags
[0].ti_Data
= (IPTR
)im
;
919 SYSGAD(w
, gadgettype
) = NewObjectA(NULL
, BUTTONGCLASS
, gadget_tags
);
921 if (!SYSGAD(w
, gadgettype
))
928 GetAttr(GA_Width
, SYSGAD(w
, gadgettype
), &width
);
933 struct TagItem gadtags
[] =
935 {GA_RelRight
, relright
- width
},
939 SetAttrsA(SYSGAD(w
, gadgettype
), gadtags
);
950 /**********************************************************************************/
952 /* FIXME: Probably sucks. I have no clue about this hash stuff */
953 LONG
CalcResourceHash(APTR resource
)
955 LONG l1
, l2
, l3
, l4
, hash
;
959 l5
= (((IPTR
)resource
) >> 32) & 0xFF;
960 l6
= (((IPTR
)resource
) >> 40) & 0xFF;
961 l7
= (((IPTR
)resource
) >> 48) & 0xFF;
962 l8
= (((IPTR
)resource
) >> 56) & 0xFF;
965 l1
= ((IPTR
)resource
) & 0xFF;
966 l2
= (((IPTR
)resource
) >> 8) & 0xFF;
967 l3
= (((IPTR
)resource
) >> 16) & 0xFF;
968 l4
= (((IPTR
)resource
) >> 24) & 0xFF;
970 hash
= (l1
+ l2
+ l3
+ l4
974 ) % RESOURCELIST_HASHSIZE
;
978 /**********************************************************************************/
980 void AddResourceToList(APTR resource
, UWORD resourcetype
, struct IntuitionBase
*IntuitionBase
)
982 struct HashNode
*hn
= NULL
;
988 case RESOURCE_WINDOW
:
989 hn
= &((struct IntWindow
*)resource
)->hashnode
;
990 hn
->type
= RESOURCE_WINDOW
;
993 case RESOURCE_SCREEN
:
994 hn
= &((struct IntScreen
*)resource
)->hashnode
;
995 hn
->type
= RESOURCE_SCREEN
;
999 D(bug("AddResourceToList: Unknown resource type!!!\n"));
1003 hash
= CalcResourceHash(resource
);
1005 hn
->resource
= resource
;
1007 ilock
= LockIBase(0);
1008 AddTail((struct List
*)&GetPrivIBase(IntuitionBase
)->ResourceList
[hash
], (struct Node
*)hn
);
1012 /**********************************************************************************/
1014 void RemoveResourceFromList(APTR resource
, UWORD resourcetype
, struct IntuitionBase
*IntuitionBase
)
1016 struct HashNode
*hn
= NULL
;
1019 switch(resourcetype
)
1021 case RESOURCE_WINDOW
:
1022 hn
= &((struct IntWindow
*)resource
)->hashnode
;
1025 case RESOURCE_SCREEN
:
1026 hn
= &((struct IntScreen
*)resource
)->hashnode
;
1030 D(bug("RemoveResourceFromList: Unknown resource type!!!\n"));
1034 if (hn
->type
!= resourcetype
)
1036 D(bug("RemoveResourceFromList: Panic. Resource Type mismatch!!!\n"));
1039 ilock
= LockIBase(0);
1040 Remove((struct Node
*)hn
);
1044 /**********************************************************************************/
1046 BOOL
ResourceExisting(APTR resource
, UWORD resourcetype
, struct IntuitionBase
*IntuitionBase
)
1048 struct HashNode
*hn
= NULL
;
1051 BOOL exists
= FALSE
;
1053 hash
= CalcResourceHash(resource
);
1055 ilock
= LockIBase(0);
1056 ForeachNode((struct List
*)&GetPrivIBase(IntuitionBase
)->ResourceList
[hash
], hn
)
1058 if ((hn
->resource
== resource
) && (hn
->type
== resourcetype
))
1069 void FireScreenNotifyMessageCode(IPTR data
, ULONG flag
, ULONG code
, struct IntuitionBase
*IntuitionBase
)
1071 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase
)->ScreenNotificationListLock
);
1073 struct ScreenNotifyMessage
*msg
;
1074 struct ReplyPort
*reply
;
1076 struct IntScreenNotify
*sn
;
1079 if (!IsListEmpty(&GetPrivIBase(IntuitionBase
)->ScreenNotificationList
))
1081 node
= GetPrivIBase(IntuitionBase
)->ScreenNotificationList
.lh_Head
;
1082 for (; node
->ln_Succ
; node
= node
->ln_Succ
)
1084 sn
= (struct IntScreenNotify
*) node
;
1085 BOOL leavescreen
= FALSE
;
1086 if (flag
& (SNOTIFY_AFTER_OPENSCREEN
| SNOTIFY_BEFORE_OPENSCREEN
| SNOTIFY_AFTER_CLOSESCREEN
| SNOTIFY_BEFORE_CLOSESCREEN
| SNOTIFY_LOCKPUBSCREEN
| SNOTIFY_UNLOCKPUBSCREEN
))
1089 if ((sn
->flags
& flag
) && !leavescreen
)
1093 msg
= AllocMem(sizeof(struct ScreenNotifyMessage
), MEMF_CLEAR
);
1096 msg
->snm_Message
.mn_Magic
= MAGIC_SCREENNOTIFY
;
1097 msg
->snm_Message
.mn_Version
= SCREENNOTIFY_VERSION
;
1098 msg
->snm_Object
= data
;
1099 msg
->snm_Class
= flag
;
1100 msg
->snm_Code
= code
;
1101 msg
->snm_UserData
= sn
->userdata
;
1102 msg
->snm_Message
.mn_Length
= sizeof(struct ScreenNotifyMessage
);
1103 if (sn
->flags
& SNOTIFY_WAIT_REPLY
)
1105 reply
= (struct ReplyPort
*)CreateMsgPort();
1108 msg
->snm_Message
.mn_ReplyPort
= (struct MsgPort
*)reply
;
1110 PutMsg((struct MsgPort
*)sn
->port
, (struct Message
*) msg
);
1111 WaitPort((struct MsgPort
*)reply
);
1112 GetMsg((struct MsgPort
*)reply
);
1113 FreeMem((APTR
) msg
, sizeof(struct ScreenNotifyMessage
));
1114 DeleteMsgPort((struct MsgPort
*)reply
);
1115 } else FreeMem((APTR
) msg
, sizeof(struct ScreenNotifyMessage
));
1119 msg
->snm_Message
.mn_ReplyPort
= GetPrivIBase(IntuitionBase
)->ScreenNotifyReplyPort
;
1121 PutMsg(sn
->port
, (struct Message
*) msg
);
1126 else if (sn
->sigtask
)
1128 Signal(sn
->sigtask
, 1 << sn
->sigbit
);
1132 struct ScreenNotifyMessage msg
;
1133 msg
.snm_Message
.mn_Magic
= MAGIC_SCREENNOTIFY
;
1134 msg
.snm_Message
.mn_Version
= SCREENNOTIFY_VERSION
;
1135 msg
.snm_Object
= data
;
1136 msg
.snm_Class
= flag
;
1137 msg
.snm_UserData
= sn
->userdata
;
1138 msg
.snm_Message
.mn_Length
= sizeof(struct ScreenNotifyMessage
);
1140 CallHook(sn
->hook
, NULL
, (Msg
) &msg
);
1145 ReleaseSemaphore(&GetPrivIBase(IntuitionBase
)->ScreenNotificationListLock
);
1148 void FireScreenNotifyMessage(IPTR data
, ULONG flag
, struct IntuitionBase
*IntuitionBase
)
1150 FireScreenNotifyMessageCode(data
, flag
, 0, IntuitionBase
);
1153 /**********************************************************************************/
1155 AROS_UFH3(struct Region
*, DefaultWindowShapeFunc
,
1156 AROS_UFHA(struct Hook
*, hook
, A0
),
1157 AROS_UFHA(struct Layer
*, lay
, A2
),
1158 AROS_UFHA(struct ShapeHookMsg
*, msg
, A1
))
1162 struct IntuitionBase
*IntuitionBase
= (struct IntuitionBase
*)hook
->h_Data
;
1163 struct Window
*win
= (struct Window
*)hook
->h_SubEntry
;
1164 struct Region
*shape
;
1165 struct wdpWindowShape shapemsg
;
1167 shapemsg
.MethodID
= WDM_WINDOWSHAPE
;
1168 shapemsg
.wdp_TrueColor
= (GetPrivScreen(win
->WScreen
)->DInfo
.dri
.dri_Flags
& DRIF_DIRECTCOLOR
) ? TRUE
: FALSE
;
1169 shapemsg
.wdp_Width
= msg
->NewBounds
.MaxX
- msg
->NewBounds
.MinX
+ 1;
1170 shapemsg
.wdp_Height
= msg
->NewBounds
.MaxY
- msg
->NewBounds
.MinY
+ 1;
1171 shapemsg
.wdp_Window
= win
;
1172 shapemsg
.wdp_UserBuffer
= IW(win
)->DecorUserBuffer
;
1174 shape
= (struct Region
*)DoMethodA(GetPrivScreen(win
->WScreen
)->WinDecorObj
, (Msg
)&shapemsg
);
1176 if (IW(win
)->OutlineShape
) DisposeRegion(IW(win
)->OutlineShape
);
1177 IW(win
)->OutlineShape
= shape
;
1178 IW(win
)->CustomShape
= FALSE
;
1185 /**********************************************************************************/