New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / buildsysrequest_morphos.c
blob66bce1a4a904a673355ebef229cb522d80371fbd
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #define DEBUG_BUILDSYSREQUEST(x) ;
9 /**********************************************************************************************/
11 #include <proto/exec.h>
12 #include <proto/intuition.h>
13 #include <proto/graphics.h>
14 #include <stdio.h>
15 #include <stdarg.h>
16 #include <strings.h>
17 #include <clib/macros.h>
18 #include <exec/memory.h>
19 #include <intuition/gadgetclass.h>
20 #include <intuition/imageclass.h>
21 #include <intuition/screens.h>
22 #include <graphics/rastport.h>
23 #include <graphics/gfxmacros.h>
24 #include <utility/tagitem.h>
25 #include "intuition_intern.h"
26 #include "requesters.h"
28 /**********************************************************************************************
30 NAME */
31 #include <proto/intuition.h>
32 #include <exec/types.h>
33 #include <intuition/intuition.h>
35 AROS_LH7(struct Window *, BuildSysRequest,
37 /* SYNOPSIS */
38 AROS_LHA(struct Window * , window, A0),
39 AROS_LHA(struct IntuiText *, bodytext, A1),
40 AROS_LHA(struct IntuiText *, postext, A2),
41 AROS_LHA(struct IntuiText *, negtext, A3),
42 AROS_LHA(ULONG , IDCMPFlags , D0),
43 AROS_LHA(WORD , width, D2),
44 AROS_LHA(WORD , height, D3),
46 /* LOCATION */
47 struct IntuitionBase *, IntuitionBase, 60, Intuition)
49 /* FUNCTION
51 INPUTS
52 window - The window in which the requester will appear
53 bodytext - The Text to be shown in the body of the requester
54 postext - The Text to be shown in the positive choice gadget
55 negtext - The Text to be shown in the negative choice gadget
56 IDCMPFlags - The IDCMP Flags for this requester
57 width, height - The dimensions of the requester
59 RESULT
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 FreeSysRequest(), DisplayAlert(), ModifyIDCMP(), exec-library/Wait(),
69 Request(), AutoRequest(), EasyRequest(), BuildEasyRequestArgs()
71 INTERNALS
73 HISTORY
75 *****************************************************************************/
77 AROS_LIBFUNC_INIT
78 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
80 struct Screen *scr = NULL, *lockedscr = NULL;
81 struct Window *req;
82 //struct Gadget *gadgets;
83 STRPTR reqtitle;
84 //STRPTR gadgetlabels[3];
85 struct IntRequestUserData *requserdata;
86 int negtextlen;
88 DEBUG_BUILDSYSREQUEST(dprintf("intrequest_buildsysrequest: window 0x%lx body <%s> postext <%s> negtext <%s> IDCMPFlags 0x%lx width %ld height %ld\n",
89 (ULONG) window,
90 bodytext ? (char *) bodytext->IText : "<NULL>",
91 postext->IText ? (char *) postext->IText : "<NULL>",
92 negtext->IText ? (char *) negtext->IText : "<NULL>",
93 IDCMPFlags,
94 (LONG) width,
95 (LONG) height));
97 /* negtext and bodytest must be specified, postext is optional */
98 if (!negtext || !bodytext) return NULL;
100 /* get requester title */
102 reqtitle = NULL;
103 if (window) reqtitle = window->Title;
104 if (!reqtitle) reqtitle = "System Request"; /* stegerg: should be localized */
106 /* get screen and screendrawinfo */
107 if (window)
108 scr = window->WScreen;
109 if (!scr)
111 scr = LockPubScreen(NULL);
112 if (!scr)
113 return NULL;
114 lockedscr = scr;
117 requserdata = AllocVec(sizeof (struct IntRequestUserData),MEMF_PUBLIC|MEMF_CLEAR);
118 if (!requserdata) goto fail;
120 requserdata->ReqScreen = scr;
122 negtextlen = strlen(negtext->IText) + 1;
124 if (postext)
126 int postextlen = strlen(postext->IText) + 1;
128 requserdata->NumGadgets = 2;
129 requserdata->GadgetLabels = AllocVec((requserdata->NumGadgets + 1) * sizeof(STRPTR), MEMF_PUBLIC|MEMF_CLEAR);
130 if (!requserdata->GadgetLabels) goto fail;
131 requserdata->GadgetLabels[0] = AllocVec(postextlen + negtextlen, MEMF_PUBLIC);
132 if (!requserdata->GadgetLabels[0])
134 FreeVec(requserdata->GadgetLabels); goto fail;
136 CopyMem(postext->IText,requserdata->GadgetLabels[0], postextlen);
137 requserdata->GadgetLabels[1] = requserdata->GadgetLabels[0] + postextlen;
138 CopyMem(negtext->IText,requserdata->GadgetLabels[1], negtextlen);
139 } else {
140 requserdata->NumGadgets = 1;
141 requserdata->GadgetLabels = AllocVec((requserdata->NumGadgets + 1) * sizeof(STRPTR), MEMF_PUBLIC|MEMF_CLEAR);
142 if (!requserdata->GadgetLabels) goto fail;
143 requserdata->GadgetLabels[0] = AllocVec(negtextlen, MEMF_PUBLIC);
144 if (!requserdata->GadgetLabels[0])
146 FreeVec(requserdata->GadgetLabels); goto fail;
148 CopyMem(negtext->IText,requserdata->GadgetLabels[0], negtextlen);
151 /* create everything */
153 requserdata->Text = bodytext;
156 struct IntuiText *it = bodytext;
157 while (it)
159 requserdata->NumLines++;
160 it = it->NextText;
164 requserdata->ReqGadgets = AllocVec(requserdata->NumGadgets * (sizeof (struct RequesterGadget)),MEMF_PUBLIC);
165 if (!requserdata->ReqGadgets) goto fail;
167 intrequest_layoutrequester(requserdata,IntuitionBase);
168 if (!requserdata->wwidth) goto fail;
170 if (!(intrequest_creategadgets(requserdata,IntuitionBase))) goto fail;
173 struct TagItem win_tags[] =
175 { WA_Width , requserdata->wwidth },
176 { WA_Height , requserdata->wheight },
177 { WA_Left , (scr->Width/2) - (requserdata->wwidth/2) },
178 { WA_Top , (scr->Height/2) - (requserdata->wheight/2) },
179 { WA_IDCMP , IDCMP_GADGETUP | IDCMP_RAWKEY | (IDCMPFlags & ~IDCMP_VANILLAKEY) | IDCMP_REFRESHWINDOW},
180 { WA_Gadgets , (IPTR)requserdata->Gadgets },
181 { WA_Title , (IPTR)reqtitle },
182 { (lockedscr ? WA_PubScreen : WA_CustomScreen), (IPTR)scr },
183 { WA_Flags , WFLG_DRAGBAR |
184 WFLG_DEPTHGADGET |
185 WFLG_ACTIVATE |
186 WFLG_SIMPLE_REFRESH |
187 WFLG_RMBTRAP },
188 { WA_SkinInfo , NULL },
189 {TAG_DONE }
192 req = OpenWindowTagList(NULL, win_tags);
195 if (req)
198 if (lockedscr) UnlockPubScreen(NULL, lockedscr);
200 req->UserData = (BYTE *)requserdata;
201 requserdata->IDCMP = IDCMPFlags;
202 requserdata->ReqWindow = req;
204 intrequest_drawrequester(requserdata,IntuitionBase);
206 return req;
209 fail:
211 if (requserdata)
213 intrequest_freegadgets(requserdata->Gadgets,IntuitionBase);
214 intrequest_freelabels(requserdata->GadgetLabels, IntuitionBase);
215 if (requserdata->dri) FreeScreenDrawInfo(requserdata->ReqScreen,(struct DrawInfo *)requserdata->dri);
216 if (requserdata->freeitext) intrequest_freeitext(requserdata->Text,IntuitionBase);
217 if (requserdata->ReqGadgets) FreeVec(requserdata->ReqGadgets);
218 FreeVec(requserdata);
221 if (lockedscr) UnlockPubScreen(NULL, lockedscr);
223 return NULL;
225 AROS_LIBFUNC_EXIT
227 } /* BuildSysRequest */
229 /**********************************************************************************************/