Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / sdk / samples / unixprinting / printplugin.c
blobaf7c681ee7f720d14114a919c5fcfc760177310c
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Dantifer Dang <dantifer.dang@sun.com>.
18 * Portions created by the Initial Developer are Copyright (C) 2004
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Roland Mainz <roland.mainz@nrubsig.org>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* Xlib/Xt stuff */
39 #ifdef MOZ_X11
40 #include <X11/Xlib.h>
41 #include <X11/Intrinsic.h>
42 #include <X11/cursorfont.h>
43 #endif /* MOZ_X11 */
45 #include "npapi.h"
46 #include "printplugin.h"
47 #include "prprf.h"
49 #include <stdlib.h>
50 #include <stdio.h>
52 /* MIMETypeList maintenance routines */
53 NPMIMEType
54 dupMimeType(NPMIMEType type)
56 NPMIMEType mimetype = NPN_MemAlloc(strlen(type)+1);
57 if (mimetype)
58 strcpy(mimetype, type);
59 return mimetype;
62 static void
63 privatePrintScreenMessage(PluginInstance *This)
65 #ifdef MOZ_X11
66 GC gc;
67 unsigned int h,w;
68 int x,y,l;
69 const char *string;
70 gc = XCreateGC(This->display, This->window, 0, NULL);
72 /* draw a rectangle */
73 h = This->height/2;
74 w = 3 * This->width/4;
75 x = (This->width - w)/2; /* center */
76 y = h/2;
77 XDrawRectangle(This->display, This->window, gc, x, y, w, h);
79 /* draw a string */
80 string = This->pluginsPrintMessage;
81 if (string && *string)
83 l = strlen(string);
84 x += This->width/10;
85 XDrawString(This->display, This->window, gc, x, This->height/2, string, l);
87 XFreeGC(This->display, gc);
88 #endif /* MOZ_X11 */
91 static void
92 setCursor (PluginInstance *This)
94 #ifdef MOZ_X11
95 static Cursor nullPluginCursor = None;
96 if (!nullPluginCursor)
98 nullPluginCursor = XCreateFontCursor(This->display, XC_hand2);
100 if (nullPluginCursor)
102 XDefineCursor(This->display, This->window, nullPluginCursor);
104 #endif /* MOZ_X11 */
107 #ifdef MOZ_X11
108 static void
109 xt_event_handler(Widget xt_w, PluginInstance *This, XEvent *xevent, Boolean *b)
111 switch (xevent->type)
113 case Expose:
114 /* get rid of all other exposure events */
115 while(XCheckTypedWindowEvent(This->display, This->window, Expose, xevent))
116 privatePrintScreenMessage(This);
117 break;
118 case ButtonRelease:
119 break;
120 default:
121 break;
124 #endif /* MOZ_X11 */
126 static void
127 addXtEventHandler(PluginInstance *This)
129 #ifdef MOZ_X11
130 Display *dpy = (Display*) This->display;
131 Window xwin = (Window) This->window;
132 Widget xt_w = XtWindowToWidget(dpy, xwin);
133 if (xt_w)
135 long event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;
136 XSelectInput(dpy, xwin, event_mask);
137 XtAddEventHandler(xt_w, event_mask, False, (XtEventHandler)xt_event_handler, This);
139 #endif /* MOZ_X11 */
142 void printScreenMessage(PluginInstance *This)
144 privatePrintScreenMessage(This);
145 setCursor(This);
146 addXtEventHandler(This);
150 void printEPSMessage(PluginInstance *This, FILE *output, NPWindow window)
152 char *string;
153 int x,y,h,w;
155 if (!output)
156 return;
158 fprintf(output, "%%!PS-Adobe-3.0 EPSF-3.0\n");
159 fprintf(output, "%%%%BoundingBox: 0 0 %d %d\n", window.width, window.height);
160 fprintf(output, "%%%%EndComments\n");
161 fprintf(output, "gsave\n");
163 w = 3 * window.width / 4;
164 h = window.height / 2;
165 x = (window.width - w)/2; /* center */
166 y = h/2;
168 /* draw a rectangle */
169 fprintf(output, "newpath\n");
170 fprintf(output, "%d %d moveto 0 %d rlineto %d 0 rlineto 0 %d rlineto\n",
171 x, y, h, w, -h);
172 fprintf(output, "closepath\n");
173 fprintf(output, "stroke\n");
175 /* draw a string */
176 string = This->pluginsPrintMessage;
177 if (string && *string)
179 fprintf(output, "/Times-Roman findfont 300 scalefont setfont\n");
180 fprintf(output, "%d %d moveto\n", x + window.width/10, window.height / 2);
181 fprintf(output, "(%s) show\n",string);
184 fprintf(output,"grestore\n");
185 fprintf(output,"%%%%EOF\n");