expose 32-bit non-alpha modes via the cgfx api
[tangerine.git] / workbench / libs / datatypes / printdtobjecta.c
blobd45cf53e648a7bfa99ab97b16ebad1f850c3311f
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 <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/intuition.h>
13 #include <intuition/intuition.h>
14 #include <intuition/gadgetclass.h>
15 #include <intuition/cghooks.h>
16 #include <datatypes/datatypesclass.h>
17 #include <utility/tagitem.h>
18 #include <clib/boopsistubs.h>
19 #include "datatypes_intern.h"
22 struct PrintMessage
24 struct Message pm_Msg;
25 struct DataTypesBase *pm_dtb;
26 Object *pm_object;
27 struct Window *pm_window;
28 struct Requester *pm_requester;
29 struct dtPrint pm_dtprint;
30 struct GadgetInfo pm_ginfo;
35 void AsyncPrinter(void)
37 struct DataTypesBase *DataTypesBase;
38 struct PrintMessage *pm;
39 struct DTSpecialInfo *dtsi;
40 Object *object;
41 struct MsgPort *ReplyPort;
42 ULONG result = 0;
44 struct Process *MyProc = (struct Process *)FindTask(NULL);
46 WaitPort(&MyProc->pr_MsgPort);
47 pm = (struct PrintMessage *)GetMsg(&MyProc->pr_MsgPort);
49 DataTypesBase = pm->pm_dtb;
51 object = pm->pm_object;
52 dtsi = ((struct Gadget *)object)->SpecialInfo;
54 if((ReplyPort = CreateMsgPort()))
56 struct IORequest *IORequest;
58 if((IORequest = CreateIORequest(ReplyPort, sizeof(union printerIO))))
60 union printerIO *oldPIO;
61 struct Window *window;
63 CopyMem(pm->pm_dtprint.dtp_PIO,IORequest,sizeof(union printerIO));
65 IORequest->io_Message.mn_ReplyPort=ReplyPort;
67 oldPIO = pm->pm_dtprint.dtp_PIO;
68 pm->pm_dtprint.dtp_PIO = (union printerIO *)IORequest;
69 pm->pm_dtprint.dtp_GInfo=NULL;
71 if((window = pm->pm_window))
73 pm->pm_dtprint.dtp_GInfo = &pm->pm_ginfo;
74 pm->pm_ginfo.gi_Screen = window->WScreen;
75 pm->pm_ginfo.gi_Window = window;
76 pm->pm_ginfo.gi_Requester = pm->pm_requester;
77 pm->pm_ginfo.gi_RastPort = window->RPort;
79 if(pm->pm_requester != NULL)
80 pm->pm_ginfo.gi_Layer = pm->pm_requester->ReqLayer;
81 else
82 pm->pm_ginfo.gi_Layer=window->WLayer;
84 pm->pm_ginfo.gi_DrInfo = GetScreenDrawInfo(window->WScreen);
87 result = DoMethodA(object, (Msg)&pm->pm_dtprint);
89 if (pm->pm_ginfo.gi_DrInfo)
90 FreeScreenDrawInfo(window->WScreen, pm->pm_ginfo.gi_DrInfo);
92 pm->pm_dtprint.dtp_PIO = oldPIO;
94 DeleteIORequest(IORequest);
97 DeleteMsgPort(ReplyPort);
100 setattrs((struct Library *)DataTypesBase, object, DTA_PrinterProc, NULL,
101 TAG_DONE);
103 DoGad_OM_NOTIFY((struct Library *)DataTypesBase, object, pm->pm_window,
104 pm->pm_requester, 0, GA_ID,
105 (ULONG)((struct Gadget*)object)->GadgetID,
106 DTA_PrinterStatus, result, TAG_DONE);
108 Delay(50);
110 Forbid();
112 dtsi->si_Flags &= ~DTSIF_PRINTING;
114 FreeVec(pm);
118 /*****************************************************************************
120 NAME */
121 #include <proto/datatypes.h>
124 AROS_LH4(ULONG, PrintDTObjectA,
126 /* SYNOPSIS */
127 AROS_LHA(Object *, object , A0),
128 AROS_LHA(struct Window *, window , A1),
129 AROS_LHA(struct Requester *, requester, A2),
130 AROS_LHA(struct dtPrint *, msg , A3),
132 /* LOCATION */
133 struct Library *, DataTypesBase, 19, DataTypes)
135 /* FUNCTION
137 Perform an object's DTM_PRINT method in an asynchronous manner.
139 INPUTS
141 object -- pointer to the data type object
142 window -- pointer to the window the object has been added to
143 requester -- pointer to the requester the object has been added to
145 RESULT
147 TRUE on success, FALSE otherwise.
149 NOTES
151 When an application has called PrintDTObjectA() it must not touch
152 the printerIO union until a IDCMP_IDCMPUPDATE is received which
153 contains the DTA_PrinterStatus tag.
154 To abort a print, send the DTM_ABORTPRINT method to the object.
155 This will signal the print process with a SIGBREAK_CTRL_C.
157 EXAMPLE
159 BUGS
161 SEE ALSO
163 INTERNALS
165 HISTORY
167 *****************************************************************************/
169 AROS_LIBFUNC_INIT
171 ULONG retval = 0;
172 struct DTSpecialInfo *dtsi = ((struct Gadget *)object)->SpecialInfo;
173 struct PrintMessage *pm;
175 ObtainSemaphore(&(GPB(DataTypesBase)->dtb_Semaphores[SEM_ASYNC]));
177 if(!(dtsi->si_Flags & DTSIF_PRINTING))
179 dtsi->si_Flags |= DTSIF_PRINTING;
181 if((pm = AllocVec(sizeof(struct PrintMessage),
182 MEMF_PUBLIC | MEMF_CLEAR)))
184 struct TagItem Tags[5];
185 struct Process *PrintProcess;
187 pm->pm_Msg.mn_Node.ln_Type = NT_MESSAGE;
188 pm->pm_Msg.mn_Length = sizeof(struct PrintMessage);
189 pm->pm_dtb = (struct DataTypesBase *)DataTypesBase;
190 pm->pm_object = object;
191 pm->pm_window = window;
192 pm->pm_requester = requester;
193 pm->pm_dtprint = *msg;
195 Tags[0].ti_Tag = NP_StackSize;
196 Tags[0].ti_Data = 4096;
197 Tags[1].ti_Tag = NP_Entry;
198 Tags[1].ti_Data = (IPTR)&AsyncPrinter;
199 Tags[2].ti_Tag = NP_Priority;
200 Tags[2].ti_Data = 0;
201 Tags[3].ti_Tag = NP_Name;
202 Tags[3].ti_Data = (IPTR)"AsyncPrintDaemon";
203 Tags[4].ti_Tag = TAG_DONE;
205 if((PrintProcess = CreateNewProc(Tags)))
207 PutMsg(&PrintProcess->pr_MsgPort, &pm->pm_Msg);
209 setattrs(DataTypesBase, object, DTA_PrinterProc, PrintProcess,
210 TAG_DONE);
212 retval = TRUE;
214 else
215 FreeVec(pm);
219 ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_Semaphores[SEM_ASYNC]));
221 return retval;
223 AROS_LIBFUNC_EXIT
224 } /* PrintDTObjectA */