fix function to take the hook param
[AROS.git] / workbench / libs / datatypes / doasynclayout.c
blob6230e9b251babc0df1f87f2dab1b7851b98cb503
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #define USE_BOOPSI_STUBS
10 #include <utility/tagitem.h>
11 #include <dos/dostags.h>
12 #include <dos/dosextens.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
15 #include <intuition/intuition.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/cghooks.h>
18 #include <clib/boopsistubs.h>
19 #include "datatypes_intern.h"
21 struct LayoutMessage
23 struct Message lm_Msg;
24 struct DataTypesBase *lm_dtb;
25 Object *lm_object;
26 struct Window *lm_window;
27 struct gpLayout lm_gplayout;
28 struct GadgetInfo lm_ginfo;
32 void AsyncLayouter(void)
34 struct DataTypesBase *dtb;
35 struct LayoutMessage *lm;
36 struct DTSpecialInfo *dtsi;
37 Object *object;
39 struct Process *MyProc = (struct Process *)FindTask(NULL);
41 WaitPort(&MyProc->pr_MsgPort);
42 lm = (struct LayoutMessage *)GetMsg(&MyProc->pr_MsgPort);
44 dtb = lm->lm_dtb;
46 object = lm->lm_object;
47 dtsi = ((struct Gadget *)object)->SpecialInfo;
49 ObtainSemaphore(&dtsi->si_Lock);
51 lm->lm_gplayout.MethodID = DTM_ASYNCLAYOUT;
55 dtsi->si_Flags &= ~DTSIF_NEWSIZE;
57 DoMethodA(object, (Msg)&lm->lm_gplayout);
59 } while(dtsi->si_Flags & DTSIF_NEWSIZE);
61 setattrs((struct Library *)dtb, object, DTA_LayoutProc, NULL, TAG_DONE);
63 dtsi->si_Flags &= ~(DTSIF_LAYOUT | DTSIF_NEWSIZE);
65 ReleaseSemaphore(&dtsi->si_Lock);
67 DoGad_OM_NOTIFY((struct Library *)dtb, object, lm->lm_window, NULL, 0,
68 GA_ID, (ULONG)((struct Gadget *)object)->GadgetID,
69 DTA_Data, object,
70 DTA_TopVert, dtsi->si_TopVert,
71 DTA_VisibleVert, dtsi->si_VisVert,
72 DTA_TotalVert, dtsi->si_TotVert,
73 DTA_TopHoriz, dtsi->si_TopHoriz,
74 DTA_VisibleHoriz, dtsi->si_VisHoriz,
75 DTA_TotalHoriz, dtsi->si_TotHoriz,
76 DTA_Sync, TRUE,
77 DTA_Busy, FALSE,
78 TAG_DONE);
80 Forbid();
82 dtsi->si_Flags &= ~DTSIF_LAYOUTPROC;
84 FreeVec(lm);
88 /*****************************************************************************
90 NAME */
91 #include <proto/datatypes.h>
93 AROS_LH2(ULONG, DoAsyncLayout,
95 /* SYNOPSIS */
96 AROS_LHA(Object * , object, A0),
97 AROS_LHA(struct gpLayout *, gpl , A1),
99 /* LOCATION */
100 struct Library *, DataTypesBase, 14, DataTypes)
102 /* FUNCTION
104 Perform an object's DTM_ASYNCLAYOUT method -- doing it asynchronously
105 off loads the input.device. The method should exit when a SIGBREAK_CTRL_C
106 is received; this signal means that the data is obsolete and the the
107 method will be called again.
109 INPUTS
111 object -- pointer to data type object
112 gpl -- gpLayout message pointer
114 RESULT
116 NOTES
118 EXAMPLE
120 BUGS
122 SEE ALSO
124 INTERNALS
126 HISTORY
128 *****************************************************************************/
130 AROS_LIBFUNC_INIT
132 ULONG retval = FALSE;
133 struct DTSpecialInfo *dtsi=((struct Gadget *)object)->SpecialInfo;
134 struct Process *LayoutProc;
136 ObtainSemaphore(&(GPB(DataTypesBase)->dtb_Semaphores[SEM_ASYNC]));
138 if(dtsi->si_Flags & DTSIF_LAYOUT)
140 dtsi->si_Flags |= DTSIF_NEWSIZE;
142 if(GetAttr(DTA_LayoutProc, object, (IPTR *)&LayoutProc))
144 if(LayoutProc != NULL)
145 Signal((struct Task *)LayoutProc, SIGBREAKF_CTRL_C);
148 retval = TRUE;
150 else
152 struct LayoutMessage *lm;
154 dtsi->si_Flags |= (DTSIF_LAYOUT | DTSIF_LAYOUTPROC);
156 Do_OM_NOTIFY(DataTypesBase, object, gpl->gpl_GInfo, 0, DTA_Data, NULL,
157 TAG_DONE);
159 if((lm = AllocVec(sizeof(struct LayoutMessage),
160 MEMF_PUBLIC | MEMF_CLEAR)))
162 struct TagItem Tags[5];
164 lm->lm_Msg.mn_Node.ln_Type = NT_MESSAGE;
165 lm->lm_Msg.mn_Length = sizeof(struct LayoutMessage);
166 lm->lm_dtb = (struct DataTypesBase *)DataTypesBase;
167 lm->lm_object = object;
168 lm->lm_window = gpl->gpl_GInfo->gi_Window;
169 lm->lm_gplayout = *gpl;
170 lm->lm_ginfo= *gpl->gpl_GInfo;
171 lm->lm_gplayout.gpl_GInfo= &lm->lm_ginfo;
173 Tags[0].ti_Tag = NP_StackSize;
174 Tags[0].ti_Data = AROS_STACKSIZE;
175 Tags[1].ti_Tag = NP_Entry;
176 Tags[1].ti_Data = (IPTR)&AsyncLayouter;
177 Tags[2].ti_Tag = NP_Priority;
178 Tags[2].ti_Data = 0;
179 Tags[3].ti_Tag = NP_Name;
180 Tags[3].ti_Data = (IPTR)"AsyncLayoutDaemon";
181 Tags[4].ti_Tag = TAG_DONE;
183 if((LayoutProc = CreateNewProc(Tags)))
185 PutMsg(&LayoutProc->pr_MsgPort, &lm->lm_Msg);
187 setattrs(DataTypesBase, object, DTA_LayoutProc, LayoutProc, TAG_DONE);
188 retval = TRUE;
190 else
191 FreeVec(lm);
194 if (!retval) dtsi->si_Flags &= ~(DTSIF_LAYOUT | DTSIF_LAYOUTPROC);
197 ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_Semaphores[SEM_ASYNC]));
199 return retval;
201 AROS_LIBFUNC_EXIT
203 } /* DoAsyncLayout */