]> git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/src/npshell.cpp
fix for crash on 64 bit platforms (patch 1028942)
[wxWidgets.git] / utils / nplugin / src / npshell.cpp
1 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 //
3 // npshell.cpp
4 //
5 // This file defines a "shell" plugin that plugin developers can use
6 // as the basis for a real plugin. This shell just provides empty
7 // implementations of all functions that the plugin can implement
8 // that will be called by Netscape (the NPP_xxx methods defined in
9 // npapi.h).
10 //
11 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
12
13 #ifndef _NPAPI_H_
14 #include "npapi.h"
15 #endif
16
17 #include <windows.h>
18 #include <string.h>
19 #include <stdio.h>
20
21 #include "NPApp.h"
22
23 //
24 // Instance state information about the plugin.
25 //
26 // *Developers*: Use this struct to hold per-instance
27 // information that you'll need in the
28 // various functions in this file.
29 //
30 typedef struct _PluginInstance
31 {
32 NPWindow* fWindow;
33 uint16 fMode;
34
35 } PluginInstance;
36
37
38
39 //------------------------------------------------------------------------------------
40 // NPP_Initialize:
41 //------------------------------------------------------------------------------------
42 NPError NPP_Initialize(void)
43 {
44 // MessageBox(NULL, "NPP_Initialize", "NPTest", MB_OK);
45 /*
46 wxPluginApp *app = wxGetPluginApp();
47 if ( app )
48 return app->NPP_Initialize();
49 else
50 return NPERR_NO_ERROR;
51 */
52 wxEntry((WXHINSTANCE) GetModuleHandle(NULL));
53
54 return NPERR_NO_ERROR;
55 }
56
57
58 //------------------------------------------------------------------------------------
59 // NPP_Shutdown:
60 //------------------------------------------------------------------------------------
61 void NPP_Shutdown(void)
62 {
63 // MessageBox(NULL, "NPP_Shutdown", "wxPlugin", MB_OK);
64
65 wxPluginApp *app = wxGetPluginApp();
66 if ( app )
67 app->NPP_Shutdown();
68 }
69
70
71 //------------------------------------------------------------------------------------
72 // NPP_New:
73 //------------------------------------------------------------------------------------
74 NPError NP_LOADDS
75 NPP_New(NPMIMEType pluginType,
76 NPP instance,
77 uint16 mode,
78 int16 argc,
79 char* argn[],
80 char* argv[],
81 NPSavedData* saved)
82 {
83 // MessageBox(NULL, "NPP_New", "NPTest", MB_OK);
84
85 if (instance == NULL)
86 return NPERR_INVALID_INSTANCE_ERROR;
87
88 wxPluginApp *app = wxGetPluginApp();
89 if ( app )
90 return app->NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
91 else
92 return NPERR_NO_ERROR;
93 }
94
95 //------------------------------------------------------------------------------------
96 // NPP_Destroy:
97 //------------------------------------------------------------------------------------
98 NPError NP_LOADDS
99 NPP_Destroy(NPP instance, NPSavedData** save)
100 {
101 // MessageBox(NULL, "NPP_Destroy", "NPTest", MB_OK);
102
103 if (instance == NULL)
104 return NPERR_INVALID_INSTANCE_ERROR;
105
106 wxPluginApp *app = wxGetPluginApp();
107 if ( app )
108 return app->NPP_Destroy(instance, save);
109 else
110 return NPERR_NO_ERROR;
111 }
112
113
114 //------------------------------------------------------------------------------------
115 // NPP_SetWindow:
116 //------------------------------------------------------------------------------------
117 NPError NP_LOADDS
118 NPP_SetWindow(NPP instance, NPWindow* window)
119 {
120 // MessageBox(NULL, "NPP_SetWindow", "NPTest", MB_OK);
121
122 if (instance == NULL)
123 return NPERR_INVALID_INSTANCE_ERROR;
124
125 wxPluginApp *app = wxGetPluginApp();
126 if ( app )
127 return app->NPP_SetWindow(instance, window);
128 else
129 return NPERR_NO_ERROR;
130 }
131
132
133 //------------------------------------------------------------------------------------
134 // NPP_NewStream:
135 //------------------------------------------------------------------------------------
136 NPError NP_LOADDS
137 NPP_NewStream(NPP instance,
138 NPMIMEType type,
139 NPStream *stream,
140 NPBool seekable,
141 uint16 *stype)
142 {
143 // MessageBox(NULL, "NPP_NewStream", "NPTest", MB_OK);
144
145 if (instance == NULL)
146 return NPERR_INVALID_INSTANCE_ERROR;
147
148 wxPluginApp *app = wxGetPluginApp();
149 if ( app )
150 return app->NPP_NewStream(instance, type, stream, seekable, stype);
151 else
152 return NPERR_NO_ERROR;
153 }
154
155
156
157 //
158 // *Developers*:
159 // These next 2 functions are directly relevant in a plug-in which handles the
160 // data in a streaming manner. If you want zero bytes because no buffer space
161 // is YET available, return 0. As long as the stream has not been written
162 // to the plugin, Navigator will continue trying to send bytes. If the plugin
163 // doesn't want them, just return some large number from NPP_WriteReady(), and
164 // ignore them in NPP_Write(). For a NP_ASFILE stream, they are still called
165 // but can safely be ignored using this strategy.
166 //
167
168 static int32 STREAMBUFSIZE = 0X0FFFFFFF; // If we are reading from a file in NPAsFile
169 // mode so we can take any size stream in our
170 // write call (since we ignore it)
171
172 //------------------------------------------------------------------------------------
173 // NPP_WriteReady:
174 //------------------------------------------------------------------------------------
175 int32 NP_LOADDS
176 NPP_WriteReady(NPP instance, NPStream *stream)
177 {
178 wxPluginApp *app = wxGetPluginApp();
179 if ( app )
180 return app->NPP_WriteReady(instance, stream);
181 else
182 return STREAMBUFSIZE;
183
184 return STREAMBUFSIZE; // Number of bytes ready to accept in NPP_Write()
185 }
186
187
188
189 //------------------------------------------------------------------------------------
190 // NPP_Write:
191 //------------------------------------------------------------------------------------
192 int32 NP_LOADDS
193 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
194 {
195 wxPluginApp *app = wxGetPluginApp();
196 if ( app )
197 return app->NPP_Write(instance, stream, offset, len, buffer);
198 else
199 return len; // The number of bytes accepted
200 }
201
202
203
204 //------------------------------------------------------------------------------------
205 // NPP_DestroyStream:
206 //------------------------------------------------------------------------------------
207 NPError NP_LOADDS
208 NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
209 {
210 if (instance == NULL)
211 return NPERR_INVALID_INSTANCE_ERROR;
212
213 wxPluginApp *app = wxGetPluginApp();
214 if ( app )
215 return app->NPP_DestroyStream(instance, stream, reason);
216 else
217 return NPERR_NO_ERROR;
218 }
219
220
221 //------------------------------------------------------------------------------------
222 // NPP_StreamAsFile:
223 //------------------------------------------------------------------------------------
224 void NP_LOADDS
225 NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
226 {
227 wxPluginApp *app = wxGetPluginApp();
228 if ( app )
229 app->NPP_StreamAsFile(instance, stream, fname);
230 }
231
232
233
234 //------------------------------------------------------------------------------------
235 // NPP_Print:
236 //------------------------------------------------------------------------------------
237 void NP_LOADDS
238 NPP_Print(NPP instance, NPPrint* printInfo)
239 {
240 if (printInfo == NULL) // trap invalid parm
241 return;
242 if ( instance == NULL )
243 return;
244
245 wxPluginApp *app = wxGetPluginApp();
246 if ( app )
247 app->NPP_Print(instance, printInfo);
248 }
249
250
251 //------------------------------------------------------------------------------------
252 // NPP_HandleEvent:
253 // Mac-only.
254 //------------------------------------------------------------------------------------
255 int16 NPP_HandleEvent(NPP instance, void* event)
256 {
257 NPBool eventHandled = FALSE;
258 if (instance == NULL)
259 return eventHandled;
260
261 PluginInstance* This = (PluginInstance*) instance->pdata;
262
263 //
264 // *Developers*: The "event" passed in is a Macintosh
265 // EventRecord*. The event.what field can be any of the
266 // normal Mac event types, or one of the following additional
267 // types defined in npapi.h: getFocusEvent, loseFocusEvent,
268 // adjustCursorEvent. The focus events inform your plugin
269 // that it will become, or is no longer, the recepient of
270 // key events. If your plugin doesn't want to receive key
271 // events, return false when passed at getFocusEvent. The
272 // adjustCursorEvent is passed repeatedly when the mouse is
273 // over your plugin; if your plugin doesn't want to set the
274 // cursor, return false. Handle the standard Mac events as
275 // normal. The return value for all standard events is currently
276 // ignored except for the key event: for key events, only return
277 // true if your plugin has handled that particular key event.
278 //
279
280 return eventHandled;
281 }
282