Bug 238704 RFE: Need sample plugin for plugin printing

patch by roland.mainz@nrubsig.org and dantifer.dang@sun.com
r=dantifer.dang@sun.com sr=jst
This commit is contained in:
timeless%mozdev.org 2004-04-23 02:47:33 +00:00
Родитель 0575217798
Коммит 5f66ee7437
9 изменённых файлов: 1364 добавлений и 0 удалений

Просмотреть файл

@ -46,6 +46,10 @@ MODULE = plugin
DIRS = base/public base/src
ifneq (,$(filter gtk gtk2 xlib ,$(MOZ_WIDGET_TOOLKIT)))
DIRS += samples/unixprinting
endif
# These subdirs rely on GTK libraries and header files, it is not
# buildable on other non-GTK unix builds

Просмотреть файл

@ -0,0 +1,91 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Initial Developer of the Original Code is
# Dantifer Dang <dantifer.dang@sun.com>.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Roland Mainz <roland.mainz@nrubsig.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = plugin
LIBRARY_NAME = unixprintplugin
GRE_MODULE = 1
PACKAGE_FILE = npprint.pkg
REQUIRES = java \
plugin \
$(NULL)
CSRCS = \
npshell.c \
printplugin.c \
npunix.c \
$(NULL)
# plugins should always be shared, even in the "static" build
FORCE_SHARED_LIB = 1
# Force use of PIC
FORCE_USE_PIC = 1
NO_DIST_INSTALL = 1
NO_INSTALL = 1
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) $(XT_LIBS) \
$(NULL)
EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS)
ifeq ($(OS_ARCH), OpenVMS)
DEFINES += -DGENERIC_MOTIF_REDEFINES
OS_CXXFLAGS += -Wc,warn=disa=NOSIMPINT
endif
install-plugin: $(SHARED_LIBRARY)
ifdef SHARED_LIBRARY
$(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins
endif
libs:: install-plugin
ifdef SHARED_LIBRARY
install:: $(SHARED_LIBRARY)
$(SYSINSTALL) $(IFLAGS2) $< $(DESTDIR)$(mozappdir)/plugins
endif

Просмотреть файл

@ -0,0 +1,39 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Initial Developer of the Original Code is
# Dantifer Dang <dantifer.dang@sun.com>.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Roland Mainz <roland.mainz@nrubsig.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#
# the print plugin goes in gecko-support because we search for plugins
# in the application, not the GRE
[gecko-support]
dist/bin/plugins/@SHARED_LIBRARY@

Просмотреть файл

@ -0,0 +1,385 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stephen Mak <smak@sun.com>
*/
/*
* npshell.c
*
* Netscape Client Plugin API
* - Function that need to be implemented by plugin developers
*
* This file defines a "shell" plugin that plugin developers can use
* as the basis for a real plugin. This shell just provides empty
* implementations of all functions that the plugin can implement
* that will be called by Netscape (the NPP_xxx methods defined in
* npapi.h).
*
* dp Suresh <dp@netscape.com>
* updated 5/1998 <pollmann@netscape.com>
* updated 9/2000 <smak@sun.com>
* updated 3/2004 <dantifer.dang@sun.com>
*
*/
#include <stdio.h>
#include <string.h>
#include "npapi.h"
#include "printplugin.h"
#include "strings.h"
#include "plstr.h"
/***********************************************************************
*
* Implementations of plugin API functions
*
***********************************************************************/
char*
NPP_GetMIMEDescription(void)
{
return(MIME_TYPES_HANDLED);
}
NPError
NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
NPError err = NPERR_NO_ERROR;
switch (variable) {
case NPPVpluginNameString:
*((char **)value) = PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char **)value) = PLUGIN_DESCRIPTION;
break;
default:
err = NPERR_GENERIC_ERROR;
}
return err;
}
NPError
NPP_Initialize(void)
{
return NPERR_NO_ERROR;
}
#ifdef OJI
jref
NPP_GetJavaClass()
{
return NULL;
}
#endif
void
NPP_Shutdown(void)
{
}
NPError
NPP_New(NPMIMEType pluginType,
NPP instance,
uint16 mode,
int16 argc,
char* argn[],
char* argv[],
NPSavedData* saved)
{
PluginInstance* This;
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
This = (PluginInstance*) instance->pdata;
if (This == NULL)
{
return NPERR_OUT_OF_MEMORY_ERROR;
}
memset(This, 0, sizeof(PluginInstance));
/* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
This->mode = mode;
This->type = dupMimeType(pluginType);
This->instance = instance;
This->pluginsPrintMessage = NULL;
This->exists = FALSE;
/* Parse argument list passed to plugin instance */
/* We are interested in these arguments
* PLUGINSPAGE = <url>
*/
while (argc > 0)
{
argc --;
if (argv[argc] != NULL)
{
if (!PL_strcasecmp(argn[argc], "PRINTMSG"))
This->pluginsPrintMessage = strdup(argv[argc]);
else if (!PL_strcasecmp(argn[argc], "HIDDEN"))
This->pluginsHidden = (!PL_strcasecmp(argv[argc],
"TRUE"));
}
}
return NPERR_NO_ERROR;
}
NPError
NPP_Destroy(NPP instance, NPSavedData** save)
{
PluginInstance* This;
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
This = (PluginInstance*) instance->pdata;
if (This != NULL) {
if (This->type)
NPN_MemFree(This->type);
if (This->pluginsPrintMessage)
NPN_MemFree(This->pluginsPrintMessage);
NPN_MemFree(instance->pdata);
instance->pdata = NULL;
}
return NPERR_NO_ERROR;
}
NPError
NPP_SetWindow(NPP instance, NPWindow* window)
{
PluginInstance* This;
NPSetWindowCallbackStruct *ws_info;
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
This = (PluginInstance*) instance->pdata;
if (This == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
#ifdef MOZ_X11
if (This->window == (Window) window->window) {
/* The page with the plugin is being resized.
Save any UI information because the next time
around expect a SetWindow with a new window
id.
*/
#ifdef DEBUG
fprintf(stderr, "Printplugin: plugin received window resize.\n");
fprintf(stderr, "Window=(%i)\n", (int)window);
if (window) {
fprintf(stderr, "W=(%i) H=(%i)\n",
(int)window->width, (int)window->height);
}
#endif
return NPERR_NO_ERROR;
} else {
This->window = (Window) window->window;
This->x = window->x;
This->y = window->y;
This->width = window->width;
This->height = window->height;
This->display = ws_info->display;
This->visual = ws_info->visual;
This->depth = ws_info->depth;
This->colormap = ws_info->colormap;
printScreenMessage(This);
}
#endif /* #ifdef MOZ_X11 */
return NPERR_NO_ERROR;
}
NPError
NPP_NewStream(NPP instance,
NPMIMEType type,
NPStream *stream,
NPBool seekable,
uint16 *stype)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
return NPERR_NO_ERROR;
}
int32
NPP_WriteReady(NPP instance, NPStream *stream)
{
/***** Insert NPP_WriteReady code here *****\
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
\*******************************************/
/* Number of bytes ready to accept in NPP_Write() */
return -1L; /* don't accept any bytes in NPP_Write() */
}
int32
NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
{
/***** Insert NPP_Write code here *****\
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
\**************************************/
return -1; /* tell the browser to abort the stream, don't need it */
}
NPError
NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
/***** Insert NPP_DestroyStream code here *****\
PluginInstance* This;
This = (PluginInstance*) instance->pdata;
\**********************************************/
return NPERR_NO_ERROR;
}
void
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
{
/***** Insert NPP_StreamAsFile code here *****\
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
\*********************************************/
}
void
NPP_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData)
{
/***** Insert NPP_URLNotify code here *****\
PluginInstance* This;
if (instance != NULL)
This = (PluginInstance*) instance->pdata;
\*********************************************/
}
void
NPP_Print(NPP instance, NPPrint* printInfo)
{
if(printInfo == NULL)
return;
if (instance != NULL) {
/***** Insert NPP_Print code here *****\
PluginInstance* This = (PluginInstance*) instance->pdata;
\**************************************/
if (printInfo->mode == NP_FULL) {
/*
* PLUGIN DEVELOPERS:
* If your plugin would like to take over
* printing completely when it is in full-screen mode,
* set printInfo->pluginPrinted to TRUE and print your
* plugin as you see fit. If your plugin wants Netscape
* to handle printing in this case, set
* printInfo->pluginPrinted to FALSE (the default) and
* do nothing. If you do want to handle printing
* yourself, printOne is true if the print button
* (as opposed to the print menu) was clicked.
* On the Macintosh, platformPrint is a THPrint; on
* Windows, platformPrint is a structure
* (defined in npapi.h) containing the printer name, port,
* etc.
*/
/***** Insert NPP_Print code here *****\
void* platformPrint =
printInfo->print.fullPrint.platformPrint;
NPBool printOne =
printInfo->print.fullPrint.printOne;
\**************************************/
/* Do the default*/
printInfo->print.fullPrint.pluginPrinted = FALSE;
}
else { /* If not fullscreen, we must be embedded */
/*
* PLUGIN DEVELOPERS:
* If your plugin is embedded, or is full-screen
* but you returned false in pluginPrinted above, NPP_Print
* will be called with mode == NP_EMBED. The NPWindow
* in the printInfo gives the location and dimensions of
* the embedded plugin on the printed page. On the
* Macintosh, platformPrint is the printer port; on
* Windows, platformPrint is the handle to the printing
* device context.
*/
/***** Insert NPP_Print code here *****\
NPWindow* printWindow =
&(printInfo->print.embedPrint.window);
void* platformPrint =
printInfo->print.embedPrint.platformPrint;
\**************************************/
PluginInstance* This;
NPPrintCallbackStruct* platformPrint;
FILE *output;
platformPrint =
(NPPrintCallbackStruct *)(printInfo->print.embedPrint.platformPrint);
output = (FILE*)(platformPrint->fp);
if (output == NULL)
return;
This = (PluginInstance*) instance->pdata;
if (This == NULL)
return;
printEPSMessage(This, output, printInfo->print.embedPrint.window);
}
}
}

Просмотреть файл

@ -0,0 +1,507 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stephen Mak <smak@sun.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* npunix.c
*
* Netscape Client Plugin API
* - Wrapper function to interface with the Netscape Navigator
*
* dp Suresh <dp@netscape.com>
*
*----------------------------------------------------------------------
* PLUGIN DEVELOPERS:
* YOU WILL NOT NEED TO EDIT THIS FILE.
*----------------------------------------------------------------------
*/
#define XP_UNIX 1
#include <stdio.h>
#include "npapi.h"
#include "npupp.h"
/*
* Define PLUGIN_TRACE to have the wrapper functions print
* messages to stderr whenever they are called.
*/
#ifdef PLUGIN_TRACE
#include <stdio.h>
#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
#else
#define PLUGINDEBUGSTR(msg)
#endif
/***********************************************************************
*
* Globals
*
***********************************************************************/
static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
/***********************************************************************
*
* Wrapper functions : plugin calling Netscape Navigator
*
* These functions let the plugin developer just call the APIs
* as documented and defined in npapi.h, without needing to know
* about the function table and call macros in npupp.h.
*
***********************************************************************/
void
NPN_Version(int* plugin_major, int* plugin_minor,
int* netscape_major, int* netscape_minor)
{
*plugin_major = NP_VERSION_MAJOR;
*plugin_minor = NP_VERSION_MINOR;
/* Major version is in high byte */
*netscape_major = gNetscapeFuncs.version >> 8;
/* Minor version is in low byte */
*netscape_minor = gNetscapeFuncs.version & 0xFF;
}
NPError
NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
{
return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
instance, variable, r_value);
}
NPError
NPN_SetValue(NPP instance, NPPVariable variable, void *value)
{
return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
instance, variable, value);
}
NPError
NPN_GetURL(NPP instance, const char* url, const char* window)
{
return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
}
NPError
NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
{
return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
}
NPError
NPN_PostURL(NPP instance, const char* url, const char* window,
uint32 len, const char* buf, NPBool file)
{
return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
url, window, len, buf, file);
}
NPError
NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
const char* buf, NPBool file, void* notifyData)
{
return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
instance, url, window, len, buf, file, notifyData);
}
NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{
return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
stream, rangeList);
}
NPError
NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
NPStream** stream_ptr)
{
return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
type, window, stream_ptr);
}
int32
NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
{
return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
stream, len, buffer);
}
NPError
NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
instance, stream, reason);
}
void
NPN_Status(NPP instance, const char* message)
{
CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
}
const char*
NPN_UserAgent(NPP instance)
{
return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
}
void*
NPN_MemAlloc(uint32 size)
{
return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
}
void NPN_MemFree(void* ptr)
{
CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
}
uint32 NPN_MemFlush(uint32 size)
{
return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
}
void NPN_ReloadPlugins(NPBool reloadPages)
{
CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
}
#ifdef OJI
JRIEnv* NPN_GetJavaEnv()
{
return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
}
jref NPN_GetJavaPeer(NPP instance)
{
return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
instance);
}
#endif
void
NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
{
CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
invalidRect);
}
void
NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
{
CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
invalidRegion);
}
void
NPN_ForceRedraw(NPP instance)
{
CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
}
/***********************************************************************
*
* Wrapper functions : Netscape Navigator -> plugin
*
* These functions let the plugin developer just create the APIs
* as documented and defined in npapi.h, without needing to
* install those functions in the function table or worry about
* setting up globals for 68K plugins.
*
***********************************************************************/
NPError
Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
int16 argc, char* argn[], char* argv[], NPSavedData* saved)
{
NPError ret;
PLUGINDEBUGSTR("New");
ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
return ret;
}
NPError
Private_Destroy(NPP instance, NPSavedData** save)
{
PLUGINDEBUGSTR("Destroy");
return NPP_Destroy(instance, save);
}
NPError
Private_SetWindow(NPP instance, NPWindow* window)
{
NPError err;
PLUGINDEBUGSTR("SetWindow");
err = NPP_SetWindow(instance, window);
return err;
}
NPError
Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
NPBool seekable, uint16* stype)
{
NPError err;
PLUGINDEBUGSTR("NewStream");
err = NPP_NewStream(instance, type, stream, seekable, stype);
return err;
}
int32
Private_WriteReady(NPP instance, NPStream* stream)
{
unsigned int result;
PLUGINDEBUGSTR("WriteReady");
result = NPP_WriteReady(instance, stream);
return result;
}
int32
Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
void* buffer)
{
unsigned int result;
PLUGINDEBUGSTR("Write");
result = NPP_Write(instance, stream, offset, len, buffer);
return result;
}
void
Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{
PLUGINDEBUGSTR("StreamAsFile");
NPP_StreamAsFile(instance, stream, fname);
}
NPError
Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
NPError err;
PLUGINDEBUGSTR("DestroyStream");
err = NPP_DestroyStream(instance, stream, reason);
return err;
}
void
Private_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData)
{
PLUGINDEBUGSTR("URLNotify");
NPP_URLNotify(instance, url, reason, notifyData);
}
void
Private_Print(NPP instance, NPPrint* platformPrint)
{
PLUGINDEBUGSTR("Print");
NPP_Print(instance, platformPrint);
}
#ifdef OJI
JRIGlobalRef
Private_GetJavaClass(void)
{
jref clazz = NPP_GetJavaClass();
if (clazz) {
JRIEnv* env = NPN_GetJavaEnv();
return JRI_NewGlobalRef(env, clazz);
}
return NULL;
}
#endif
/***********************************************************************
*
* These functions are located automagically by netscape.
*
***********************************************************************/
/*
* NP_GetMIMEDescription
* - Netscape needs to know about this symbol
* - Netscape uses the return value to identify when an object instance
* of this plugin should be created.
*/
char *
NP_GetMIMEDescription(void)
{
return NPP_GetMIMEDescription();
}
/*
* NP_GetValue [optional]
* - Netscape needs to know about this symbol.
* - Interfaces with plugin to get values for predefined variables
* that the navigator needs.
*/
NPError
NP_GetValue(void* future, NPPVariable variable, void *value)
{
return NPP_GetValue(future, variable, value);
}
/*
* NP_Initialize
* - Netscape needs to know about this symbol.
* - It calls this function after looking up its symbol before it
* is about to create the first ever object of this kind.
*
* PARAMETERS
* nsTable - The netscape function table. If developers just use these
* wrappers, they dont need to worry about all these function
* tables.
* RETURN
* pluginFuncs
* - This functions needs to fill the plugin function table
* pluginFuncs and return it. Netscape Navigator plugin
* library will use this function table to call the plugin.
*
*/
NPError
NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
{
NPError err = NPERR_NO_ERROR;
PLUGINDEBUGSTR("NP_Initialize");
/* validate input parameters */
if ((nsTable == NULL) || (pluginFuncs == NULL))
err = NPERR_INVALID_FUNCTABLE_ERROR;
/*
* Check the major version passed in Netscape's function table.
* We won't load if the major version is newer than what we expect.
* Also check that the function tables passed in are big enough for
* all the functions we need (they could be bigger, if Netscape added
* new APIs, but that's OK with us -- we'll just ignore them).
*
*/
if (err == NPERR_NO_ERROR) {
if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
err = NPERR_INCOMPATIBLE_VERSION_ERROR;
if (nsTable->size < sizeof(NPNetscapeFuncs))
err = NPERR_INVALID_FUNCTABLE_ERROR;
if (pluginFuncs->size < sizeof(NPPluginFuncs))
err = NPERR_INVALID_FUNCTABLE_ERROR;
}
if (err == NPERR_NO_ERROR) {
/*
* Copy all the fields of Netscape function table into our
* copy so we can call back into Netscape later. Note that
* we need to copy the fields one by one, rather than assigning
* the whole structure, because the Netscape function table
* could actually be bigger than what we expect.
*/
gNetscapeFuncs.version = nsTable->version;
gNetscapeFuncs.size = nsTable->size;
gNetscapeFuncs.posturl = nsTable->posturl;
gNetscapeFuncs.geturl = nsTable->geturl;
gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
gNetscapeFuncs.requestread = nsTable->requestread;
gNetscapeFuncs.newstream = nsTable->newstream;
gNetscapeFuncs.write = nsTable->write;
gNetscapeFuncs.destroystream = nsTable->destroystream;
gNetscapeFuncs.status = nsTable->status;
gNetscapeFuncs.uagent = nsTable->uagent;
gNetscapeFuncs.memalloc = nsTable->memalloc;
gNetscapeFuncs.memfree = nsTable->memfree;
gNetscapeFuncs.memflush = nsTable->memflush;
gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
#ifdef OJI
gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
#endif
gNetscapeFuncs.getvalue = nsTable->getvalue;
/*
* Set up the plugin function table that Netscape will use to
* call us. Netscape needs to know about our version and size
* and have a UniversalProcPointer for every function we
* implement.
*/
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
pluginFuncs->size = sizeof(NPPluginFuncs);
pluginFuncs->newp = NewNPP_NewProc(Private_New);
pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
pluginFuncs->write = NewNPP_WriteProc(Private_Write);
pluginFuncs->print = NewNPP_PrintProc(Private_Print);
pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
pluginFuncs->event = NULL;
#ifdef OJI
pluginFuncs->javaClass = Private_GetJavaClass();
#endif
err = NPP_Initialize();
}
return err;
}
/*
* NP_Shutdown [optional]
* - Netscape needs to know about this symbol.
* - It calls this function after looking up its symbol after
* the last object of this kind has been destroyed.
*
*/
NPError
NP_Shutdown(void)
{
PLUGINDEBUGSTR("NP_Shutdown");
NPP_Shutdown();
return NPERR_NO_ERROR;
}

Просмотреть файл

@ -0,0 +1,185 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
* Dantifer Dang <dantifer.dang@sun.com>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@nrubsig.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* Xlib/Xt stuff */
#ifdef MOZ_X11
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/cursorfont.h>
#endif /* MOZ_X11 */
#include "npapi.h"
#include "printplugin.h"
#include "prprf.h"
#include <stdlib.h>
#include <stdio.h>
/* MIMETypeList maintenance routines */
NPMIMEType
dupMimeType(NPMIMEType type)
{
NPMIMEType mimetype = NPN_MemAlloc(strlen(type)+1);
if (mimetype)
strcpy(mimetype, type);
return mimetype;
}
static void
privatePrintScreenMessage(PluginInstance *This)
{
#ifdef MOZ_X11
GC gc;
unsigned int h,w;
int x,y,l;
const char *string;
gc = XCreateGC(This->display, This->window, 0, NULL);
/* draw a rectangle */
h = This->height/2;
w = 3 * This->width/4;
x = (This->width - w)/2; /* center */
y = h/2;
XDrawRectangle(This->display, This->window, gc, x, y, w, h);
/* draw a string */
string = This->pluginsPrintMessage;
if (string && *string)
{
l = strlen(string);
x += This->width/10;
XDrawString(This->display, This->window, gc, x, This->height/2, string, l);
}
XFreeGC(This->display, gc);
#endif /* MOZ_X11 */
}
static void
setCursor (PluginInstance *This)
{
#ifdef MOZ_X11
static Cursor nullPluginCursor = None;
if (!nullPluginCursor)
{
nullPluginCursor = XCreateFontCursor(This->display, XC_hand2);
}
if (nullPluginCursor)
{
XDefineCursor(This->display, This->window, nullPluginCursor);
}
#endif /* MOZ_X11 */
}
#ifdef MOZ_X11
static void
xt_event_handler(Widget xt_w, PluginInstance *This, XEvent *xevent, Boolean *b)
{
switch (xevent->type)
{
case Expose:
/* get rid of all other exposure events */
while(XCheckTypedWindowEvent(This->display, This->window, Expose, xevent));
privatePrintScreenMessage(This);
break;
case ButtonRelease:
break;
default:
break;
}
}
#endif /* MOZ_X11 */
static void
addXtEventHandler(PluginInstance *This)
{
#ifdef MOZ_X11
Display *dpy = (Display*) This->display;
Window xwin = (Window) This->window;
Widget xt_w = XtWindowToWidget(dpy, xwin);
if (xt_w)
{
long event_mask = ExposureMask | ButtonReleaseMask | ButtonPressMask;
XSelectInput(dpy, xwin, event_mask);
XtAddEventHandler(xt_w, event_mask, False, (XtEventHandler)xt_event_handler, This);
}
#endif /* MOZ_X11 */
}
void printScreenMessage(PluginInstance *This)
{
privatePrintScreenMessage(This);
setCursor(This);
addXtEventHandler(This);
}
void printEPSMessage(PluginInstance *This, FILE *output, NPWindow window)
{
char *string;
int x,y,h,w;
if (!output)
return;
fprintf(output, "%%!PS-Adobe-3.0 EPSF-3.0\n");
fprintf(output, "%%%%BoundingBox: 0 0 %d %d\n", window.width, window.height);
fprintf(output, "%%%%EndComments\n");
fprintf(output, "gsave\n");
w = 3 * window.width / 4;
h = window.height / 2;
x = (window.width - w)/2; /* center */
y = h/2;
/* draw a rectangle */
fprintf(output, "newpath\n");
fprintf(output, "%d %d moveto 0 %d rlineto %d 0 rlineto 0 %d rlineto\n",
x, y, h, w, -h);
fprintf(output, "closepath\n");
fprintf(output, "stroke\n");
/* draw a string */
string = This->pluginsPrintMessage;
if (string && *string)
{
fprintf(output, "/Times-Roman findfont 300 scalefont setfont\n");
fprintf(output, "%d %d moveto\n", x + window.width/10, window.height / 2);
fprintf(output, "(%s) show\n",string);
}
fprintf(output,"grestore\n");
fprintf(output,"%%%%EOF\n");
}

Просмотреть файл

@ -0,0 +1,77 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
* Dantifer Dang <dantifer.dang@sun.com>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@nrubsig.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef UNIXPRINTING_SAMPLEPLUGIN_H
#define UNIXPRINTING_SAMPLEPLUGIN_H 1
#define MIME_TYPES_HANDLED "application/x-print-unix-nsplugin:.pnt:Demo Print Plugin for Unix/Linux"
#define PLUGIN_NAME "Demo Print Plugin for unix/linux"
#define PLUGIN_DESCRIPTION "The demo print plugin for unix."
typedef struct _PluginInstance
{
uint16 mode;
#ifdef MOZ_X11
Window window;
Display *display;
#endif /* MOZ_X11 */
uint32 x,
y;
uint32 width,
height;
NPMIMEType type;
char *message;
NPP instance;
char *pluginsPrintMessage;
NPBool pluginsHidden;
#ifdef MOZ_X11
Visual *visual;
Colormap colormap;
#endif /* MOZ_X11 */
unsigned int depth;
NPBool exists; /* Does the widget already exist? */
} PluginInstance;
/* Extern functions */
extern NPMIMEType dupMimeType(NPMIMEType type);
extern void printScreenMessage(PluginInstance *This);
extern void printEPSMessage(PluginInstance *This, FILE *output, NPWindow window);
#endif /* !UNIXPRINTING_SAMPLEPLUGIN_H */

Просмотреть файл

@ -0,0 +1,28 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Print plugin Embed Test #1</title>
</head>
<body>
<center>
<h1>Demo Print Plugin for Unix/Linux #1</h1>
<table align="center" border="1">
<tbody>
<tr><td>Sample test (above plugin)</td></tr>
<tr>
<td align="center">
<embed
type="application/x-print-unix-nsplugin"
printmsg="printable demo plugin" height="500" width="500">
<br>
</td>
</tr>
<tr><td>Sample test (below plugin)</td></tr>
</tbody>
</table>
<br>
for test purpose only
<br>
</center>
</body>
</html>

Просмотреть файл

@ -0,0 +1,48 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Print plugin Embed Test #2</title>
</head>
<body>
<center>
<h1>Demo Print Plugin for Unix/Linux #2</h1>
<table align="center" border="1">
<tbody>
<tr><td>Sample test (above plugins)</td></tr>
<tr>
<td align="center">
<embed
type="application/x-print-unix-nsplugin"
printmsg="printable demo plugin 1" height="220" width="220">
<br>
</td>
<td align="center">
<embed
type="application/x-print-unix-nsplugin"
printmsg="printable demo plugin 2" height="220" width="220">
<br>
</td>
</tr>
<tr>
<td align="center">
<embed
type="application/x-print-unix-nsplugin"
printmsg="printable demo plugin 3" height="220" width="220">
<br>
</td>
<td align="center">
<embed
type="application/x-print-unix-nsplugin"
printmsg="printable demo plugin 4" height="220" width="220">
<br>
</td>
</tr>
<tr><td>Sample test (below plugins)</td></tr>
</tbody>
</table>
<br>
for test purpose only
<br>
</center>
</body>
</html>