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
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.
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 ***** */
41 #include <X11/Intrinsic.h>
42 #include <X11/cursorfont.h>
46 #include "printplugin.h"
52 /* MIMETypeList maintenance routines */
54 dupMimeType(NPMIMEType type
)
56 NPMIMEType mimetype
= NPN_MemAlloc(strlen(type
)+1);
58 strcpy(mimetype
, type
);
63 privatePrintScreenMessage(PluginInstance
*This
)
70 gc
= XCreateGC(This
->display
, This
->window
, 0, NULL
);
72 /* draw a rectangle */
74 w
= 3 * This
->width
/4;
75 x
= (This
->width
- w
)/2; /* center */
77 XDrawRectangle(This
->display
, This
->window
, gc
, x
, y
, w
, h
);
80 string
= This
->pluginsPrintMessage
;
81 if (string
&& *string
)
85 XDrawString(This
->display
, This
->window
, gc
, x
, This
->height
/2, string
, l
);
87 XFreeGC(This
->display
, gc
);
92 setCursor (PluginInstance
*This
)
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
);
109 xt_event_handler(Widget xt_w
, PluginInstance
*This
, XEvent
*xevent
, Boolean
*b
)
111 switch (xevent
->type
)
114 /* get rid of all other exposure events */
115 while(XCheckTypedWindowEvent(This
->display
, This
->window
, Expose
, xevent
))
116 privatePrintScreenMessage(This
);
127 addXtEventHandler(PluginInstance
*This
)
130 Display
*dpy
= (Display
*) This
->display
;
131 Window xwin
= (Window
) This
->window
;
132 Widget xt_w
= XtWindowToWidget(dpy
, xwin
);
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
);
142 void printScreenMessage(PluginInstance
*This
)
144 privatePrintScreenMessage(This
);
146 addXtEventHandler(This
);
150 void printEPSMessage(PluginInstance
*This
, FILE *output
, NPWindow window
)
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 */
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",
172 fprintf(output
, "closepath\n");
173 fprintf(output
, "stroke\n");
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");