⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xprint.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $XConsortium: xprint.c /main/3 1996/11/23 17:11:55 rws $ *//*(c) Copyright 1996 Hewlett-Packard Company(c) Copyright 1996 International Business Machines Corp.(c) Copyright 1996 Sun Microsystems, Inc.(c) Copyright 1996 Novell, Inc.(c) Copyright 1996 Digital Equipment Corp.(c) Copyright 1996 Fujitsu Limited(c) Copyright 1996 Hitachi, Ltd.Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THECOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHERIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the names of the copyright holders shallnot be used in advertising or otherwise to promote the sale, use or otherdealings in this Software without prior written authorization from saidcopyright holders.*//***********************************************************************    ***********************************************************    ***    *  File:          xprint.c**    ***    *  Copyright:     Copyright 1993, 1995 Hewlett-Packard Company**    ***    *		Copyright 1989 by The Massachusetts Institute of Technology**    ***    *		Permission to use, copy, modify, and distribute this**    *		software and its documentation for any purpose and without**    *		fee is hereby granted, provided that the above copyright**    *		notice appear in all copies and that both that copyright**    *		notice and this permission notice appear in supporting**    *		documentation, and that the name of MIT not be used in**    *		advertising or publicity pertaining to distribution of the**    *		software without specific prior written permission.**    *		M.I.T. makes no representation about the suitability of**    *		this software for any purpose. It is provided "as is"**    *		without any express or implied warranty.**    ***    *		MIT DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,**    *		INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-**    *		NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MIT BE  LI-**    *		ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR**    *		ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR**    *		PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR**    *		OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH**    *		THE USE OR PERFORMANCE OF THIS SOFTWARE.**    ***    *******************************************************************************************************************************//* $XFree86: xc/programs/Xserver/Xext/xprint.c,v 1.4 1997/01/02 04:05:05 dawes Exp $ */#include "X.h"#define NEED_EVENTS#include "Xproto.h"#undef NEED_EVENTS#include "misc.h"#include "windowstr.h"#include "scrnintstr.h"#include "pixmapstr.h"#include "extnsionst.h"#include "dixstruct.h"#include "Xatom.h"#define _XP_PRINT_SERVER_#include "Print.h"#include "Printstr.h"#undef _XP_PRINT_SERVER_#include "../Xprint/DiPrint.h"extern WindowPtr *WindowTable; /* declared in dix:globals.c */extern WindowPtr XpDiValidatePrinter();extern char *XpDiGetDriverName();extern char *XpGetAttributes();extern char *XpGetOneAttribute();extern int XpRehashPrinterList();extern void XpSetFontResFunc();static void XpResetProc();static int ProcXpDispatch();static int ProcXpSwappedDispatch();static int ProcXpQueryVersion();static int ProcXpGetPrinterList();static int ProcXpCreateContext();static int ProcXpSetContext();static int ProcXpGetContext();static int ProcXpDestroyContext();static int ProcXpGetContextScreen();static int ProcXpStartJob();static int ProcXpEndJob();static int ProcXpStartDoc();static int ProcXpEndDoc();static int ProcXpStartPage();static int ProcXpEndPage();static int ProcXpSelectInput();static int ProcXpInputSelected();static int ProcXpPutDocumentData();static int ProcXpGetDocumentData();static int ProcXpGetAttributes();static int ProcXpGetOneAttribute();static int ProcXpSetAttributes();static int ProcXpRehashPrinterList();static int ProcXpQueryScreens();static int ProcXpGetPageDimensions();static int ProcXpSetImageResolution();static int ProcXpGetImageResolution();static void SwapXpNotifyEvent();static void SwapXpAttributeEvent();static int SProcXpGetPrinterList();static int SProcXpCreateContext();static int SProcXpSetContext();static int SProcXpGetContext();static int SProcXpDestroyContext();static int SProcXpGetContextScreen();static int SProcXpStartJob();static int SProcXpEndJob();static int SProcXpStartDoc();static int SProcXpEndDoc();static int SProcXpStartPage();static int SProcXpEndPage();static int SProcXpSelectInput();static int SProcXpInputSelected();static int SProcXpPutDocumentData();static int SProcXpGetDocumentData();static int SProcXpGetAttributes();static int SProcXpGetOneAttribute();static int SProcXpSetAttributes();static int SProcXpRehashPrinterList();static int SProcXpGetPageDimensions();static int SProcXpSetImageResolution();static int SProcXpGetImageResolution();static void SendXpNotify();static void SendAttributeNotify();static int XpFreeClient();static int XpFreeContext();static int XpFreePage();static int XpFreeEvents();static Bool XpCloseScreen();static CARD32 GetAllEventMasks();static struct _XpEvent *AddEventRec();static void DeleteEventRec();static struct _XpEvent *FindEventRec();static struct _XpClient *CreateXpClient();static void FreeXpClient();static void InitContextPrivates();static void ResetContextPrivates();static struct _XpClient *FindClient();static struct _XpClient *AcquireClient();typedef struct _driver {    struct _driver *next;    char *name;    int (* CreateContext)();} XpDriverRec, *XpDriverPtr;typedef struct  _xpScreen {    Bool (* CloseScreen)();    struct _driver *drivers;} XpScreenRec, *XpScreenPtr;/* * Each context has a list of XpClients indicating which clients have * associated this context with their connection. * Each such client has a RTclient resource allocated for it, * and this per-client * resource is used to delete the XpClientRec if/when the client closes * its connection. * The list of XpClients is also walked if/when the context is destroyed * so that the ContextPtr can be removed from the client's devPrivates. */typedef struct _XpClient {	struct _XpClient *pNext;	ClientPtr	client;	XpContextPtr	context;	CARD32		eventMask;	XID		contextClientID; /* unneeded sanity check? */} XpClientRec, *XpClientPtr;/* * Each StartPage request specifies a window which forms the top level * window of the page.  One of the following structs is created as a * RTpage resource with the same ID as the window itself.  This enables  * us to clean up when/if the window is destroyed, and to prevent the * same window from being simultaneously referenced in multiple contexts. * The page resource is created at the first StartPage on a given window, * and is only destroyed when/if the window is destroyed.  When the * EndPage is recieved (or an EndDoc or EndJob) the context field is * set to NULL, but the resource remains alive. */typedef struct _XpPage {	XpContextPtr	context;} XpPageRec, *XpPagePtr;typedef struct _XpStPageRec {    XpContextPtr pContext;    Bool slept;    XpPagePtr pPage;    WindowPtr pWin;} XpStPageRec, *XpStPagePtr;typedef struct _XpStDocRec {    XpContextPtr pContext;    Bool slept;    CARD8 type;} XpStDocRec, *XpStDocPtr;#define QUADPAD(x) ((((x)+3)>>2)<<2)/* * Possible bit-mask values in the "state" field of a XpContextRec. */#define JOB_STARTED (1 << 0)#define DOC_RAW_STARTED (1 << 1)#define DOC_COOKED_STARTED (1 << 2)#define PAGE_STARTED (1 << 3)#define GET_DOC_DATA_STARTED (1 << 4)#define JOB_GET_DATA (1 << 5)    static XpScreenPtr XpScreens[MAXSCREENS];static unsigned char XpReqCode;static int XpEventBase;static int XpErrorBase;static int XpGeneration = 0;static int XpWindowPrivateIndex;static int XpClientPrivateIndex;/* Variables for the context private machinery.  * These must be initialized at compile time because * main() calls InitOutput before InitExtensions, and the * output drivers are likely to call AllocateContextPrivate. * These variables are reset at CloseScreen time.  CloseScreen * is used because it occurs after FreeAllResources, and before * the next InitOutput cycle. */static int  contextPrivateCount = 0;static int contextPrivateLen = 0;static unsigned *contextPrivateSizes = (unsigned *)NULL;static unsigned totalContextSize = sizeof(XpContextRec);/* * There are three types of resources involved.  One is the resource associated * with the context itself, with an ID specified by a printing client.  The * next is a resource created by us on the client's behalf (and unknown to * the client) when a client inits or sets a context which allows us to  * track each client's interest in events * on a particular context, and also allows us to clean up this interest * record when/if the client's connection is closed.  Finally, there is * a resource created for each window that's specified in a StartPage.  This * resource carries the same ID as the window itself, and enables us to * easily prevent the same window being referenced in multiple contexts * simultaneously, and enables us to clean up if the window is destroyed * before the EndPage. */static RESTYPE RTclient, RTcontext, RTpage;/* * allEvents is the OR of all the legal event mask bits. */static CARD32 allEvents = XPPrintMask | XPAttributeMask;/******************************************************************************* * * ExtensionInit, Driver Init functions, QueryVersion, and Dispatch procs * ******************************************************************************//* * XpExtensionInit * * Called from InitExtensions in main() usually through miinitextension * */voidXpExtensionInit(){    ExtensionEntry *extEntry, *AddExtension();    int i;    RTclient = CreateNewResourceType(XpFreeClient);    RTcontext = CreateNewResourceType(XpFreeContext);    RTpage = CreateNewResourceType(XpFreePage);    if (RTclient && RTcontext && RTpage &&        (extEntry = AddExtension(XP_PRINTNAME, XP_EVENTS, XP_ERRORS,                               ProcXpDispatch, ProcXpSwappedDispatch,                               XpResetProc, StandardMinorOpcode)))    {        XpReqCode = (unsigned char)extEntry->base;        XpEventBase = extEntry->eventBase;        XpErrorBase = extEntry->errorBase;        EventSwapVector[XpEventBase] = SwapXpNotifyEvent;        EventSwapVector[XpEventBase+1] = SwapXpAttributeEvent;    }    if(XpGeneration != serverGeneration)    {	XpClientPrivateIndex = AllocateClientPrivateIndex();	/*	 * We allocate 0 length & simply stuff a pointer to the	 * ContextRec in the DevUnion.	 */	if(AllocateClientPrivate(XpClientPrivateIndex, 0) != TRUE)	{		/* we can't alloc a client private, should we bail??? XXX */	}	XpGeneration = serverGeneration;    }    for(i = 0; i < MAXSCREENS; i++)    {	/*	 * If a screen has registered with our extension, then we	 * wrap the screen's CloseScreen function to allow us to	 * reset our ContextPrivate stuff.  Note that this	 * requires a printing DDX to call XpRegisterInitFunc	 * _before_ this extension is initialized - i.e. at screen init	 * time, _not_ at root window creation time.	 */	if(XpScreens[i] != (XpScreenPtr)NULL)	{	    XpScreens[i]->CloseScreen = screenInfo.screens[i]->CloseScreen;	    screenInfo.screens[i]->CloseScreen = XpCloseScreen;	}    }    DeclareExtensionSecurity(XP_PRINTNAME, TRUE);}static voidXpResetProc(extEntry)    ExtensionEntry extEntry;{    int i;    /*     * We can't free up the XpScreens recs here, because extensions are     * closed before screens, and our CloseScreen function uses the XpScreens     * recs.    for(i = 0; i < MAXSCREENS; i++)    {	if(XpScreens[i] != (XpScreenPtr)NULL)	    Xfree(XpScreens[i]);	XpScreens[i] = (XpScreenPtr)NULL;    }    */}static BoolXpCloseScreen(index, pScreen)    int index;    ScreenPtr pScreen;{    Bool (* CloseScreen)();    CloseScreen = XpScreens[index]->CloseScreen;    if(XpScreens[index] != (XpScreenPtr)NULL)    {	XpDriverPtr pDriv, nextDriv;	pDriv = XpScreens[index]->drivers;	while(pDriv != (XpDriverPtr)NULL)	{	    nextDriv = pDriv->next;            Xfree(pDriv);	    pDriv = nextDriv;	}	Xfree(XpScreens[index]);    }    XpScreens[index] = (XpScreenPtr)NULL;    /*     * It's wasteful to call ResetContextPrivates() at every CloseScreen,      * but it's the best we know how to do for now.  We do this because we     * have to wait until after all resources have been freed (so we know     * how to free the ContextRecs), and before the next InitOutput cycle.     * See dix/main.c for the order of initialization and reset.     */    ResetContextPrivates();    return (*CloseScreen)(index, pScreen);}static voidFreeScreenEntry(pScreenEntry)    XpScreenPtr pScreenEntry;{    XpDriverPtr pDriver;    pDriver = pScreenEntry->drivers;     while(pDriver != (XpDriverPtr)NULL)    {	XpDriverPtr tmp;	tmp = pDriver->next;	xfree(pDriver);	pDriver = tmp;    }    xfree(pScreenEntry);}/* * XpRegisterInitFunc tells the print extension which screens * are printers as opposed to displays, and what drivers are * supported on each screen.  This eliminates the need of * allocating print-related private structures on windows on _all_ screens. * It also hands the extension a pointer to the routine to be called * whenever a context gets created for a particular driver on this screen. */voidXpRegisterInitFunc(pScreen, driverName, initContext)    ScreenPtr pScreen;    char *driverName;    int (*initContext)();{    XpDriverPtr pDriver;    if(XpScreens[pScreen->myNum] == (XpScreenPtr)NULL)    {        if((XpScreens[pScreen->myNum] =           (XpScreenPtr) Xalloc(sizeof(XpScreenRec))) == (XpScreenPtr)NULL)            return;	XpScreens[pScreen->myNum]->CloseScreen = (Bool(*)())NULL;	XpScreens[pScreen->myNum]->drivers = (XpDriverPtr)NULL;    }    if((pDriver = (XpDriverPtr)Xalloc(sizeof(XpDriverRec))) ==        (XpDriverPtr)NULL)	return;    pDriver->next = XpScreens[pScreen->myNum]->drivers;    pDriver->name = driverName;    pDriver->CreateContext = initContext;    XpScreens[pScreen->myNum]->drivers = pDriver;}static int ProcXpDispatch(client)    ClientPtr client;{    REQUEST(xReq);    switch(stuff->data)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -