merge the formfield patch from ooo-build
[ooovba.git] / np_sdk / mozsrc / npwin.cpp
blob1fb4d3e68e140ebe31edf23ee123c6a7442b88a2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
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 NPL, 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 NPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef _NPAPI_H_
39 #include "npapi.h"
40 #endif
41 #ifndef _NPUPP_H_
42 #include "npupp.h"
43 #endif
45 //\\// DEFINE
46 #define NP_EXPORT
48 #ifdef OS2
49 #define WINAPI _System
50 #define HIBYTE(a) (a>>8)
51 #define LOBYTE(a) (a&0xFF)
52 #endif
54 //\\// GLOBAL DATA
55 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
57 extern "C"
59 #ifdef OJI
60 JRIGlobalRef Private_GetJavaClass(void);
62 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
63 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
64 // Private_GetJavaClass (global function)
66 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
67 // of this class existence
69 JRIGlobalRef
70 Private_GetJavaClass(void)
72 jref clazz = NPP_GetJavaClass();
73 if (clazz) {
74 JRIEnv* env = NPN_GetJavaEnv();
75 return JRI_NewGlobalRef(env, clazz);
77 return NULL;
79 #endif /* OJI */
81 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
82 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
83 // PLUGIN DLL entry points
85 // These are the Windows specific DLL entry points. They must be exoprted
88 // we need these to be global since we have to fill one of its field
89 // with a data (class) which requires knowlwdge of the navigator
90 // jump-table. This jump table is known at Initialize time (NP_Initialize)
91 // which is called after NP_GetEntryPoint
92 static NPPluginFuncs* g_pluginFuncs;
94 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
95 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
96 // NP_GetEntryPoints
98 // fills in the func table used by Navigator to call entry points in
99 // plugin DLL. Note that these entry points ensure that DS is loaded
100 // by using the NP_LOADDS macro, when compiling for Win16
102 NPError WINAPI NP_EXPORT
103 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
105 // trap a NULL ptr
106 if(pFuncs == NULL)
107 return NPERR_INVALID_FUNCTABLE_ERROR;
109 // if the plugin's function table is smaller than the plugin expects,
110 // then they are incompatible, and should return an error
112 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
113 pFuncs->newp = NPP_New;
114 pFuncs->destroy = NPP_Destroy;
115 pFuncs->setwindow = NPP_SetWindow;
116 pFuncs->newstream = NPP_NewStream;
117 pFuncs->destroystream = NPP_DestroyStream;
118 pFuncs->asfile = NPP_StreamAsFile;
119 pFuncs->writeready = NPP_WriteReady;
120 pFuncs->write = NPP_Write;
121 pFuncs->print = NPP_Print;
122 pFuncs->event = 0; /// reserved
124 g_pluginFuncs = pFuncs;
126 return NPERR_NO_ERROR;
129 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
130 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
131 // NP_Initialize
133 // called immediately after the plugin DLL is loaded
135 NPError WINAPI NP_EXPORT
136 NP_Initialize(NPNetscapeFuncs* pFuncs)
138 // trap a NULL ptr
139 if(pFuncs == NULL)
140 return NPERR_INVALID_FUNCTABLE_ERROR;
142 g_pNavigatorFuncs = pFuncs; // save it for future reference
144 // if the plugin's major ver level is lower than the Navigator's,
145 // then they are incompatible, and should return an error
146 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
147 return NPERR_INCOMPATIBLE_VERSION_ERROR;
149 // We have to defer these assignments until g_pNavigatorFuncs is set
150 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
152 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
153 g_pluginFuncs->urlnotify = NPP_URLNotify;
156 #ifdef OJI
157 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
158 g_pluginFuncs->javaClass = Private_GetJavaClass();
160 #endif
162 // NPP_Initialize is a standard (cross-platform) initialize function.
163 return NPP_Initialize();
166 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
167 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
168 // NP_Shutdown
170 // called immediately before the plugin DLL is unloaded.
171 // This functio shuold check for some ref count on the dll to see if it is
172 // unloadable or it needs to stay in memory.
174 NPError WINAPI NP_EXPORT
175 NP_Shutdown()
177 NPP_Shutdown();
178 g_pNavigatorFuncs = NULL;
179 return NPERR_NO_ERROR;
182 char * NP_GetMIMEDescription()
184 return NPP_GetMIMEDescription();
187 // END - PLUGIN DLL entry points
188 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
189 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
191 /* NAVIGATOR Entry points */
193 /* These entry points expect to be called from within the plugin. The
194 noteworthy assumption is that DS has already been set to point to the
195 plugin's DLL data segment. Don't call these functions from outside
196 the plugin without ensuring DS is set to the DLLs data segment first,
197 typically using the NP_LOADDS macro
200 /* returns the major/minor version numbers of the Plugin API for the plugin
201 and the Navigator
203 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
205 *plugin_major = NP_VERSION_MAJOR;
206 *plugin_minor = NP_VERSION_MINOR;
207 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
208 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
211 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
213 return g_pNavigatorFuncs->getvalue(instance, variable, result);
217 /* causes the specified URL to be fetched and streamed in
219 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
222 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
223 NPError err;
224 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
225 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
227 else {
228 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
230 return err;
234 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
236 return g_pNavigatorFuncs->geturl(instance, url, target);
239 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
241 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
242 NPError err;
243 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
244 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
246 else {
247 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
249 return err;
253 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
255 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
258 /* Requests that a number of bytes be provided on a stream. Typically
259 this would be used if a stream was in "pull" mode. An optional
260 position can be provided for streams which are seekable.
262 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
264 return g_pNavigatorFuncs->requestread(stream, rangeList);
267 /* Creates a new stream of data from the plug-in to be interpreted
268 by Netscape in the current window.
270 NPError NPN_NewStream(NPP instance, NPMIMEType type,
271 const char* target, NPStream** stream)
273 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
274 NPError err;
276 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
277 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
279 else {
280 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
282 return err;
285 /* Provides len bytes of data.
287 int32 NPN_Write(NPP instance, NPStream *stream,
288 int32 len, void *buffer)
290 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
291 int32 result;
293 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
294 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
296 else {
297 result = -1;
299 return result;
302 /* Closes a stream object.
303 reason indicates why the stream was closed.
305 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
307 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
308 NPError err;
310 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
311 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
313 else {
314 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
316 return err;
319 /* Provides a text status message in the Netscape client user interface
321 void NPN_Status(NPP instance, const char *message)
323 g_pNavigatorFuncs->status(instance, message);
326 /* returns the user agent string of Navigator, which contains version info
328 const char* NPN_UserAgent(NPP instance)
330 return g_pNavigatorFuncs->uagent(instance);
333 /* allocates memory from the Navigator's memory space. Necessary so that
334 saved instance data may be freed by Navigator when exiting.
338 void* NPN_MemAlloc(uint32 size)
340 return g_pNavigatorFuncs->memalloc(size);
343 /* reciprocal of MemAlloc() above
345 void NPN_MemFree(void* ptr)
347 g_pNavigatorFuncs->memfree(ptr);
350 #ifdef OJI
351 /* private function to Netscape. do not use!
353 void NPN_ReloadPlugins(NPBool reloadPages)
355 g_pNavigatorFuncs->reloadplugins(reloadPages);
358 JRIEnv* NPN_GetJavaEnv(void)
360 return g_pNavigatorFuncs->getJavaEnv();
363 jref NPN_GetJavaPeer(NPP instance)
365 return g_pNavigatorFuncs->getJavaPeer(instance);
367 #endif
368 } //end of extern "C"