fix the sam440 build - rename to prevent ambiguity. (NicJA)
[AROS.git] / rom / intuition / decoration.c
blob34a117eb1c3c365ce34ea87d4f030ceb6eeaec87
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Decoration support code
6 */
8 #include <intuition/screens.h>
9 #include <intuition/intuition.h>
10 #include <intuition/windecorclass.h>
11 #include <intuition/scrdecorclass.h>
12 #include <intuition/gadgetclass.h>
13 #include <intuition/extensions.h>
14 #include <proto/exec.h>
15 #include <proto/intuition.h>
16 #include <proto/dos.h>
18 #include "intuition_intern.h"
19 #include "intuition_customize.h"
20 #include "inputhandler_actions.h"
22 BOOL int_LoadDecorator(const char *name, struct IntScreen *screen, struct IntuitionBase *IntuitionBase)
24 IPTR userbuffersize;
25 struct NewDecorator *nd = NULL;
27 ObtainSemaphore(&((struct IntIntuitionBase *)(IntuitionBase))->ScrDecorSem);
29 if (name)
31 nd = (struct NewDecorator *)FindName(&GetPrivIBase(IntuitionBase)->Decorations, name);
33 else
35 struct DosLibrary *DOSBase = GetPrivIBase(IntuitionBase)->DOSBase;
37 /* Open dos.library only once, when first needed */
38 if (!DOSBase)
39 GetPrivIBase(IntuitionBase)->DOSBase = DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 36);
41 if (DOSBase)
43 struct Node *node;
45 if (!IsListEmpty(&GetPrivIBase(IntuitionBase)->Decorations))
47 node = GetPrivIBase(IntuitionBase)->Decorations.lh_Head;
48 for (; node->ln_Succ; node = node->ln_Succ)
50 struct NewDecorator *d = (struct NewDecorator *) node;
52 if ((d->nd_IntPattern != NULL) && (screen->Screen.Title != NULL))
54 if (MatchPattern(d->nd_IntPattern, screen->Screen.Title))
55 nd = d;
62 if (!nd)
63 nd = ((struct IntIntuitionBase *)(IntuitionBase))->Decorator;
65 if (nd)
66 nd->nd_cnt++;
68 ReleaseSemaphore(&((struct IntIntuitionBase *)(IntuitionBase))->ScrDecorSem);
70 screen->Decorator = nd;
71 if (nd != NULL)
73 screen->ScrDecorObj = NewObjectA(nd->nd_ScreenClass, NULL, nd->nd_ScreenTags);
74 screen->MenuDecorObj = NewObjectA(nd->nd_MenuClass, NULL, nd->nd_MenuTags);
75 screen->WinDecorObj = NewObjectA(nd->nd_WindowClass, NULL, nd->nd_WindowTags);
77 else
79 screen->ScrDecorObj = NewObjectA(GetPrivIBase(IntuitionBase)->ScrDecorClass, NULL, GetPrivIBase(IntuitionBase)->ScrDecorTags);
80 screen->MenuDecorObj = NewObjectA(GetPrivIBase(IntuitionBase)->MenuDecorClass, NULL, GetPrivIBase(IntuitionBase)->MenuDecorTags);
81 screen->WinDecorObj = NewObjectA(GetPrivIBase(IntuitionBase)->WinDecorClass, NULL, GetPrivIBase(IntuitionBase)->WinDecorTags);
84 GetAttr(SDA_UserBuffer, screen->ScrDecorObj, &userbuffersize);
85 screen->DecorUserBufferSize = userbuffersize;
86 if (userbuffersize)
88 screen->DecorUserBuffer = (IPTR)AllocMem(userbuffersize, MEMF_ANY | MEMF_CLEAR);
89 if (!screen->DecorUserBuffer)
90 return FALSE;
93 return TRUE;
96 struct RemoveDecoratorMsg
98 struct IntuiActionMsg msg;
99 struct NewDecorator *nd;
102 /* This is called on the input.device's context */
104 static VOID int_removedecorator(struct RemoveDecoratorMsg *m,
105 struct IntuitionBase *IntuitionBase)
107 struct DecoratorMessage msg;
108 struct MsgPort *port = CreateMsgPort();
110 if (port)
112 Remove((struct Node *)m->nd);
113 FreeVec(m->nd->nd_IntPattern);
115 msg.dm_Message.mn_ReplyPort = port;
116 msg.dm_Message.mn_Magic = MAGIC_DECORATOR;
117 msg.dm_Message.mn_Version = DECORATOR_VERSION;
118 msg.dm_Class = DM_CLASS_DESTROYDECORATOR;
119 msg.dm_Code = 0;
120 msg.dm_Flags = 0;
121 msg.dm_Object = (IPTR)m->nd;
123 PutMsg(m->nd->nd_Port, (struct Message *)&msg);
124 WaitPort(port);
125 GetMsg(port);
126 DeleteMsgPort(port);
130 /* !!! ScrDecorSem must be obtained and released by the caller !!! */
131 void int_UnloadDecorator(struct NewDecorator *tnd, struct IntuitionBase *IntuitionBase)
133 if ((tnd->nd_cnt == 0) && (tnd->nd_Port != NULL))
135 struct RemoveDecoratorMsg msg;
137 msg.nd = tnd;
138 DoASyncAction((APTR)int_removedecorator, &msg.msg, sizeof(msg), IntuitionBase);
142 BOOL int_InitDecorator(struct Screen *screen)
144 BOOL ok;
145 struct sdpInitScreen msg;
147 msg.MethodID = SDM_INITSCREEN;
148 msg.sdp_Screen = screen;
149 msg.sdp_TrueColor = (GetPrivScreen(screen)->DInfo.dri_Flags & DRIF_DIRECTCOLOR) ? TRUE : FALSE;
150 msg.sdp_FontHeight = GetPrivScreen(screen)->DInfo.dri_Font->tf_YSize;
151 msg.sdp_BarVBorder = screen->BarVBorder;
152 msg.sdp_BarHBorder = screen->BarHBorder;
153 msg.sdp_MenuVBorder = screen->MenuVBorder;
154 msg.spd_MenuHBorder = screen->MenuHBorder;
155 msg.sdp_WBorTop = screen->WBorTop;
156 msg.sdp_WBorLeft = screen->WBorLeft;
157 msg.sdp_WBorRight = screen->WBorRight;
158 msg.sdp_WBorBottom = screen->WBorBottom;
159 msg.sdp_TitleHack = 0;
160 msg.sdp_BarHeight = screen->BarHeight;
161 msg.sdp_UserBuffer = ((struct IntScreen *)screen)->DecorUserBuffer;
163 ok = DoMethodA(GetPrivScreen(screen)->ScrDecorObj, &msg.MethodID);
164 if (ok)
166 screen->BarHeight = msg.sdp_BarHeight;
167 screen->BarVBorder = msg.sdp_BarVBorder;
168 screen->BarHBorder = msg.sdp_BarHBorder;
169 screen->MenuVBorder = msg.sdp_MenuVBorder;
170 screen->MenuHBorder = msg.spd_MenuHBorder;
171 screen->WBorTop = msg.sdp_WBorTop;
172 screen->WBorLeft = msg.sdp_WBorLeft;
173 screen->WBorRight = msg.sdp_WBorRight;
174 screen->WBorBottom = msg.sdp_WBorBottom;
177 return ok;
180 void int_CalcSkinInfo(struct Screen *screen, struct IntuitionBase *IntuitionBase)
182 if (screen->FirstGadget)
184 struct sdpLayoutScreenGadgets lmsg;
186 lmsg.MethodID = SDM_LAYOUT_SCREENGADGETS;
187 lmsg.sdp_TrueColor = (GetPrivScreen(screen)->DInfo.dri_Flags & DRIF_DIRECTCOLOR) ? TRUE : FALSE;
188 lmsg.sdp_Layer = screen->BarLayer;
189 lmsg.sdp_Gadgets = screen->FirstGadget;
190 lmsg.sdp_Flags = SDF_LSG_INITIAL | SDF_LSG_MULTIPLE;
191 lmsg.sdp_UserBuffer = ((struct IntScreen *)screen)->DecorUserBuffer;
193 DoMethodA(((struct IntScreen *)(screen))->ScrDecorObj, &lmsg.MethodID);