OS/2 Differences, Steps, Files
Differences in a OS/2 Plug-In
The OS/2 interface to plug-ins differs from the Windows documentation in
the following ways:
- Coordinates passed in
NPP_SetWindow
and
NPP_Print
are based on origin
being bottom-left with height extending upwards and width extending to the right.
- The window passed by
NPP_SetWindow
is of class "Netscape Plugin Window" and has
a class style of CS_MOVENOTIFY.
- The platformPrint field in the
NPFullPrint
and
NPEmbedPrint
data structures passed by
NPP_Print
is an HPS.
-
Netscape methods
(NPN_*) must only be made from thread 1.
- Returning FALSE from
NPP_Print
with a full-page embed will allow Navigator to print the plug-in on your behalf.
The plug-in data is reloaded for the display window as a result of this.
- There is no support for the Java interface (JRI) interface to plug-ins.
- To get keystrokes that the Navigator uses for accelerator keys like
CTRL, SHIFT, and ESC, in your subclass window procedure, respond FALSE to WM_TRANSLATEACCEL
messages. This will prevent any translation of WM_CHAR messages by Navigator's
accelerator table while the "Netscape Plugin Window" has the focus.
The plug-in might also inspect the parameters for each WM_TRANSLATEACCL message
and pass some messages on to Navigator. Things like F5 (reload page), TAB,
ALT-F4, etc. should behave as the user expects. This can be done by calling
the original window procedure for the "Netscape Plugin Window" with the WM_TRANSLATEACCL message.
- Plug-ins should always pass system control keys, like ALT-F4, on to Navigator.
Never close the "Netscape Plugin Window" in response to a user keystroke.
Navigator manages the plug-in window construction and destruction.
- Setting the height and width of a plug-in to 1x1 is not supported and will cause
errors in page handling. Use HIDDEN=TRUE on the
EMBED tag if you want to hide a plug-in.
- DDE between plug-ins and Navigator will work on OS/2. This is currently not
supported on other platforms.
Creating a OS/2 Plug-In
In order to create a OS/2 plug-in you need a C++ complier, such as
IBM's Visual Age C++ version 3.0 compiler.
- Create a directory on your hard drive for the plug-in project. For
example, you might call this directory OS2PLUG.
- Download the OS/2 Sample Source Code. Note that the file is
compressed.
- Use the resulting dialog boxes to save the file in the directory
you created for the plug-in project (for example, in C:\OS2PLUG). The
compressed file is saved in the directory you specified.
- Decompress the file. If you are using pkunzip to decompress the
file, use the -d flag to maintain the directory structure stored in
the zip file. A readme file is placed in the directory. The following
directory structure is created:
-
\common
contains common build files NPOS2.CPP
-
\doc
contains this documentation
-
\include
contains header files NPAPI.H and NPUPP.H
-
\sample\npclock
directory contains a plug-in that displays a clock. The clock plug-in responds
to an additional attributes in the
EMBED
tag named TRANSPARENCY. The two valid values are ON and OFF.
-
\sample\npdraw
directory contains a plug-in that streams a drawing. A random draw data file
can be generated by building and running the GENDATA.EXE program.
-
\sample\npshell
directory contains a template of the files you use to create a new plug-in
-
\test
contains test HTML files for the plug-in samples
- Create a new subdirectory to work in. For example,
C:\OS2PLUG\SAMPLES\MYPLUG.
- Copy all the directories and files in the \sample\npshell directory into
your new working directory. In addition, copy into this directory any
auxiliary plug-in specific files you have created. For example, you
may have written code to implement window handling functionality.
- Using your compiler, open the existing makefile in your working
directory.
- Edit the resource file NPSHELL.RC
to include the correct information. You must change the MIME type and
the file extension values. For example, if you were creating an AVI
plug-in, your resource file would look like this:
#include "npapi.h"
RCDATA NP_INFO_ProductVersion { 1,0,0,1, }
RCDATA NP_INFO_MIMEType {"Sample/Draw"}
RCDATA NP_INFO_FileExtents {"drw"}
RCDATA NP_INFO_FileOpenName {"OS/2 Streaming Draw Plugin"}
NOTE: There is a problem in the OS/2 resource compiler that causes an error if the '}'
is appended to the first RCDATA type (NP_INFO_ProductVersion in the above example) without
the extra comma. You can also move the last brace to the next line to avoid the compile error.
- To include multiple MIME types in the plug-in, use a vertical bar to
delimit each value in the MIME type. For example, VALUE "MIMEType",
"sample/bmp|sample/gif". MIME types must be paired with file extensions and descriptions.
For the previous example, the extensions should be "bmp|gif" and the file descriptions would be
"bitmap files|gif files".
- Save the resource file. The resource file allows Netscape to query
the plug-in without having to load it in memory.
- Open the file npshell.cpp. This is a compilable shell file that
provides the framework for creating a plug-in. By working in
npshell.cpp, you simply fill in the necessary code for basic plug-in
functionality.
- In npshell.cpp, write the code for the functions needed for your
plug-in. The Plug-In Application Programming Interface provides a
detailed description of each function. You may want to take a look at
the other samples.
- Save the npshell.cpp file.
- Using your compiler, build the project. The file npshell.dll is created.
In the samples, you can get a debug version by specifying
OPT=DEBUG
on the command line and a dynamically-linked DLL by specifying
CRT=DYNAMIC.
- Copy the dll file (npshell.dll) into the PLUGINS
subdirectory of Navigator. If this directory doesn't exist, create it
in the same location as netscape.exe. If the plug-in has associated
files, create a separate subdirectory and places the files there.
- Restart Navigator. When Netscape Navigator starts up, it locates the path to the
NETSCAPE.EXE and looks for a PLUGINS subdirectory there (not necessarily the current directory)
Navigator then looks for plug-in modules in that directory and any subdirectories.
- From the Help menu of Navigator, choose About Plug-ins. A list of
all plug-ins in the directory is displayed. You should see your Mime
type listed.
- Test your plug-in by creating an HTML document.
- Navigator will only accept plug-in dlls with file names begining with 'np'.
OS/2 Files
When you unzip the OS/2 sample source code, several subdirectories
are automatically created in your working directory.
The contents of each directory include:
\common Directory
- npos2.cpp - Passes plug-in function pointers to Netscape for
communication and contains shell functions for Navigator entry
points. This file also implements version checking. You should not
need to change this file.
\include Directory
- npapi.h - Plug-in header file for plug-in entry points and callback to
Netscape.
- npupp.h - Function pointer tables and DLL entry point definitions.
\sample\npclock Directory
- npclock.cpp - main line for plug-in
- clock.h - constants for resource
- clock.hpp - class header for Clock class
- clock.cpp - class implementation for Clock class
- npclock.rc - resources
- npclock.def - def file
- makefile - A IBM VisualAge C++ 3.0 make file for plug-ins.
\sample\npdraw Directory
- npdraw.cpp - main line for plug-in
- draw.h - constants
- npdraw.rc - resources
- npdraw.def - def file
- makefile - A IBM VisualAge C++ 3.0 make file for plug-ins.
- gendata.cpp - source to generate random data
- gendata.def - def file for GENDATA.EXE
- gendata.mak - Makefile for GENDATA.EXE
\samples\npshell Directory
- npshell.cpp - Shell implementation of all plug-in methods. This
file also includes suggestions (as comments) on plug-in development
as applicable to a specific method. You use this file to create your
own plug-in.
- npshell.def - Used by the linker to resolve export symbols for
plug-in entry points. You should not need to change this file.
- npshell.rc - Contains boiler-plate symbols for plug-ins.
- makefile - A IBM VisualAge C++ 3.0 make file for plug-ins.
\test Directory
- clock.clk - data file for clock plug-in
- clock.htm - HTML to display clock plug-in
- draw.lst - data file for draw plug-in
- draw.htm - HTML to display draw plug-in
- npshell.htm - HTML for shell plug-in
- npshell.smp - data file for shell plug-in