]> git.saurik.com Git - wxWidgets.git/blame - utils/nplugin/src/npapp.cpp
libjpeg not used by default (it didn't even link)
[wxWidgets.git] / utils / nplugin / src / npapp.cpp
CommitLineData
bbf1f0e5
KB
1/*
2 * File: NPApp.cc
3 * Purpose: wxPluginApp implementation
4 * Author: Julian Smart
5 * Created: 1997
6 * Updated:
7 * Copyright: (c) Julian Smart
8 */
9
10// For compilers that support precompilation, includes "wx/wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14#pragma hdrstop
15#endif
16
17#include "NPApp.h"
18#include "NPFrame.h"
19
20#include <windows.h>
21
22IMPLEMENT_ABSTRACT_CLASS(wxPluginApp, wxApp)
23
24wxPluginApp *wxGetPluginApp(void)
25{
26 if ( wxTheApp && wxTheApp->IsKindOf(CLASSINFO(wxPluginApp)))
27 return (wxPluginApp *)wxTheApp;
28 else
29 return NULL;
30}
31
32wxPluginApp::wxPluginApp(void)
33{
34 m_data.m_argc = NULL;
35 m_data.m_argn = NULL;
36 m_data.m_argv = NULL;
37 m_data.m_type = 0;
38 m_data.m_instance = 0;
39 m_data.m_mode = 0;
40 m_data.m_window = 0;
41}
42
43wxPluginApp::~wxPluginApp(void)
44{
45 if ( m_data.m_argn )
46 delete[] m_data.m_argn;
47 if ( m_data.m_argv )
48 delete[] m_data.m_argv;
49}
50
51// Add a frame
52void wxPluginApp::AddFrame(wxPluginFrame *frame)
53{
54 m_frames.Append(frame);
55}
56
57// Remove a frame
58void wxPluginApp::RemoveFrame(wxPluginFrame *frame)
59{
60 m_frames.DeleteObject(frame);
61}
62
63// Find a frame given a NP instance
64wxPluginFrame *wxPluginApp::FindFrame(NPP instance)
65{
66 wxNode *node = m_frames.First();
67 while ( node )
68 {
69 wxPluginFrame *frame = (wxPluginFrame *)node->Data();
70 if ( frame->GetInstance() == instance )
71 {
72 return frame;
73 }
74 node = node->Next();
75 }
76 return NULL;
77}
78
79void wxPluginApp::SetAttributeValues(const int n, char *argn[], char *argv[])
80{
81 if ( m_data.m_argn )
82 delete[] m_data.m_argn;
83 if ( m_data.m_argv )
84 delete[] m_data.m_argv;
85
86 m_data.m_argc = n;
87
88 m_data.m_argn = new wxString[n];
89 m_data.m_argv = new wxString[n];
90 int i;
91 for ( i = 0; i < n ; i ++)
92 {
93 m_data.m_argn[i] = argn[i];
94 m_data.m_argv[i] = argv[i];
95 }
96}
97
98///////////////////////////////////////////////////////////////
99// Netscape Plugin API calls routed via wxPluginApp
100
101NPError wxPluginApp::NPP_Destroy(NPP instance, NPSavedData** save)
102{
103 wxPluginFrame *frame = FindFrame(instance);
104 if ( frame )
105 {
106 frame->OnClose();
107 delete frame;
108 }
109 return NPERR_NO_ERROR;
110}
111
112NPError wxPluginApp::NPP_DestroyStream(NPP instance, NPStream* stream, NPError reason)
113{
114 return NPERR_NO_ERROR;
115}
116
117/*
118jref wxPluginApp::NPP_GetJavaClass(void)
119{
120 return 0;
121}
122*/
123
5de76427
JS
124// This can't work now because we don't have a global app until wxEntry is called.
125// We'll put the wxEntry call in npshell.cpp instead.
bbf1f0e5
KB
126NPError wxPluginApp::NPP_Initialize(void)
127{
128 static int init = FALSE;
129
130 if ( init == TRUE )
131 MessageBox(NULL, "wxPluginApp::NPP_Initialize:\nabout to call wxEntry for 2nd time!!!", "wxPlugin", MB_OK);
132
133 wxEntry((WXHINSTANCE) GetModuleHandle(NULL));
134
135 init = TRUE;
136
137// MessageBox(NULL, "wxPluginApp::NPP_Initialize: have called wxEntry", "wxPlugin", MB_OK);
138 return NPERR_NO_ERROR;
139}
140
141NPError wxPluginApp::NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,
142 int16 argc, char* argn[], char* argv[], NPSavedData* saved)
143{
144// MessageBox(NULL, "wxPluginApp::NPP_New", "wxPlugin", MB_OK);
145
146 // Save values so frame can be created in first NPP_SetWindow
147 if ( m_data.m_instance != 0 )
148 {
149 MessageBox(NULL, "wxPluginApp::NPP_New: whoops, 2 NPP_New calls in succession without NPP_SetWindow.\n Need to modify my code!", "wxPlugin", MB_OK);
150 return NPERR_NO_ERROR;
151 }
152
153 m_data.m_instance = instance;
154 m_data.m_type = pluginType;
155 m_data.m_mode = mode;
156
157 SetAttributeValues(argc, argn, argv);
158
159 // Unfortunately, we may get a stream event before we've got a valid window
160 // handle, so we just have to go ahead and create a new instance.
161 wxPluginFrame *frame = OnNewInstance(m_data);
162
163 m_data.m_instance = NULL;
164 m_data.m_window = NULL;
165 delete[] m_data.m_argv;
166 delete[] m_data.m_argn;
167 m_data.m_argv = NULL;
168 m_data.m_argn = NULL;
169
170 return NPERR_NO_ERROR;
171}
172
173NPError wxPluginApp::NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream,
174 NPBool seekable, uint16* stype)
175{
176 // By default, we want to receive a file instead of a stream.
177 wxPluginFrame *frame = FindFrame(instance);
178 if ( frame )
179 {
180 return frame->OnNPNewStream(type, stream, seekable, stype);
181 }
182 return NPERR_NO_ERROR;
183}
184
185void wxPluginApp::NPP_Print(NPP instance, NPPrint* printInfo)
186{
187 if (instance == NULL)
188 return;
189
190 wxPluginFrame *frame = FindFrame(instance);
191 if ( frame )
192 {
193 frame->OnNPPrint(printInfo);
194 }
195}
196
197NPError wxPluginApp::NPP_SetWindow(NPP instance, NPWindow* window)
198{
199// MessageBox(NULL, "wxPluginApp::NPP_SetWindow", "wxPlugin", MB_OK);
200
201 if ( window )
202 wxDebugMsg("%d\n", (int) window->window);
203
204 wxPluginFrame *frame = FindFrame(instance);
205 if ( frame )
206 {
207 frame->SetNPWindow(window);
208 }
209 else
210 {
211#if 0
212 // No such frame: must make it.
213 if ( m_data.m_instance == NULL )
214 {
215 MessageBox(NULL, "wxPluginApp::NPP_SetWindow: whoops, no data to create window. SetWindow called in funny order?", "wxPlugin", MB_OK);
216 return NPERR_NO_ERROR;
217 }
218
219 if ( window->window == NULL )
220 {
221 // We're receiving a NULL window before we've even received
222 // a valid window. Ignore this silly thing.
223 return NPERR_NO_ERROR;
224 }
225
226 m_data.m_window = window;
227 m_data.m_instance = instance;
228
229// wxPluginFrame *frame = OnNewInstance(m_data);
230
231 m_data.m_instance = NULL;
232 m_data.m_window = NULL;
233 delete[] m_data.m_argv;
234 delete[] m_data.m_argn;
235 m_data.m_argv = NULL;
236 m_data.m_argn = NULL;
237#endif
238 }
239 return NPERR_NO_ERROR;
240}
241
242void wxPluginApp::NPP_Shutdown(void)
243{
244 // Clean up wxWindows
245 CleanUp();
246}
247
248void wxPluginApp::NPP_StreamAsFile(NPP instance, NPStream* stream, const char *fname)
249{
250 wxPluginFrame *frame = FindFrame(instance);
251 if ( frame )
252 {
253 wxString str(fname);
254 frame->OnNPNewFile(stream, str);
255 }
256}
257
258/*
259void wxPluginApp::NPP_URLNotify(NPP instance, const char* url, NPReason reason,
260 void* notifyData)
261{
262}
263*/
264
265int32 wxPluginApp::NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
266 void* buf)
267{
268 return len; // The number of bytes accepted
269}
270
271static int32 STREAMBUFSIZE = 0X0FFFFFFF; // If we are reading from a file in NPAsFile
272 // mode so we can take any size stream in our
273 // write call (since we ignore it)
274
275int32 wxPluginApp::NPP_WriteReady(NPP instance, NPStream* stream)
276{
277 return STREAMBUFSIZE; // Number of bytes ready to accept in NPP_Write()
278}
279