]>
git.saurik.com Git - wxWidgets.git/blob - utils/nplugin/src/npapp.cpp
3 * Purpose: wxPluginApp implementation
7 * Copyright: (c) Julian Smart
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
22 IMPLEMENT_ABSTRACT_CLASS(wxPluginApp
, wxApp
)
24 wxPluginApp
*wxGetPluginApp(void)
26 if ( wxTheApp
&& wxTheApp
->IsKindOf(CLASSINFO(wxPluginApp
)))
27 return (wxPluginApp
*)wxTheApp
;
32 wxPluginApp::wxPluginApp(void)
38 m_data
.m_instance
= 0;
43 wxPluginApp::~wxPluginApp(void)
46 delete[] m_data
.m_argn
;
48 delete[] m_data
.m_argv
;
52 void wxPluginApp::AddFrame(wxPluginFrame
*frame
)
54 m_frames
.Append(frame
);
58 void wxPluginApp::RemoveFrame(wxPluginFrame
*frame
)
60 m_frames
.DeleteObject(frame
);
63 // Find a frame given a NP instance
64 wxPluginFrame
*wxPluginApp::FindFrame(NPP instance
)
66 wxNode
*node
= m_frames
.First();
69 wxPluginFrame
*frame
= (wxPluginFrame
*)node
->Data();
70 if ( frame
->GetInstance() == instance
)
79 void wxPluginApp::SetAttributeValues(const int n
, char *argn
[], char *argv
[])
82 delete[] m_data
.m_argn
;
84 delete[] m_data
.m_argv
;
88 m_data
.m_argn
= new wxString
[n
];
89 m_data
.m_argv
= new wxString
[n
];
91 for ( i
= 0; i
< n
; i
++)
93 m_data
.m_argn
[i
] = argn
[i
];
94 m_data
.m_argv
[i
] = argv
[i
];
98 ///////////////////////////////////////////////////////////////
99 // Netscape Plugin API calls routed via wxPluginApp
101 NPError
wxPluginApp::NPP_Destroy(NPP instance
, NPSavedData
** save
)
103 wxPluginFrame
*frame
= FindFrame(instance
);
109 return NPERR_NO_ERROR
;
112 NPError
wxPluginApp::NPP_DestroyStream(NPP instance
, NPStream
* stream
, NPError reason
)
114 return NPERR_NO_ERROR
;
118 jref wxPluginApp::NPP_GetJavaClass(void)
124 NPError
wxPluginApp::NPP_Initialize(void)
126 static int init
= FALSE
;
129 MessageBox(NULL
, "wxPluginApp::NPP_Initialize:\nabout to call wxEntry for 2nd time!!!", "wxPlugin", MB_OK
);
131 wxEntry((WXHINSTANCE
) GetModuleHandle(NULL
));
135 // MessageBox(NULL, "wxPluginApp::NPP_Initialize: have called wxEntry", "wxPlugin", MB_OK);
136 return NPERR_NO_ERROR
;
139 NPError
wxPluginApp::NPP_New(NPMIMEType pluginType
, NPP instance
, uint16 mode
,
140 int16 argc
, char* argn
[], char* argv
[], NPSavedData
* saved
)
142 // MessageBox(NULL, "wxPluginApp::NPP_New", "wxPlugin", MB_OK);
144 // Save values so frame can be created in first NPP_SetWindow
145 if ( m_data
.m_instance
!= 0 )
147 MessageBox(NULL
, "wxPluginApp::NPP_New: whoops, 2 NPP_New calls in succession without NPP_SetWindow.\n Need to modify my code!", "wxPlugin", MB_OK
);
148 return NPERR_NO_ERROR
;
151 m_data
.m_instance
= instance
;
152 m_data
.m_type
= pluginType
;
153 m_data
.m_mode
= mode
;
155 SetAttributeValues(argc
, argn
, argv
);
157 // Unfortunately, we may get a stream event before we've got a valid window
158 // handle, so we just have to go ahead and create a new instance.
159 wxPluginFrame
*frame
= OnNewInstance(m_data
);
161 m_data
.m_instance
= NULL
;
162 m_data
.m_window
= NULL
;
163 delete[] m_data
.m_argv
;
164 delete[] m_data
.m_argn
;
165 m_data
.m_argv
= NULL
;
166 m_data
.m_argn
= NULL
;
168 return NPERR_NO_ERROR
;
171 NPError
wxPluginApp::NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
*stream
,
172 NPBool seekable
, uint16
* stype
)
174 // By default, we want to receive a file instead of a stream.
175 wxPluginFrame
*frame
= FindFrame(instance
);
178 return frame
->OnNPNewStream(type
, stream
, seekable
, stype
);
180 return NPERR_NO_ERROR
;
183 void wxPluginApp::NPP_Print(NPP instance
, NPPrint
* printInfo
)
185 if (instance
== NULL
)
188 wxPluginFrame
*frame
= FindFrame(instance
);
191 frame
->OnNPPrint(printInfo
);
195 NPError
wxPluginApp::NPP_SetWindow(NPP instance
, NPWindow
* window
)
197 // MessageBox(NULL, "wxPluginApp::NPP_SetWindow", "wxPlugin", MB_OK);
200 wxDebugMsg("%d\n", (int) window
->window
);
202 wxPluginFrame
*frame
= FindFrame(instance
);
205 frame
->SetNPWindow(window
);
210 // No such frame: must make it.
211 if ( m_data
.m_instance
== NULL
)
213 MessageBox(NULL
, "wxPluginApp::NPP_SetWindow: whoops, no data to create window. SetWindow called in funny order?", "wxPlugin", MB_OK
);
214 return NPERR_NO_ERROR
;
217 if ( window
->window
== NULL
)
219 // We're receiving a NULL window before we've even received
220 // a valid window. Ignore this silly thing.
221 return NPERR_NO_ERROR
;
224 m_data
.m_window
= window
;
225 m_data
.m_instance
= instance
;
227 // wxPluginFrame *frame = OnNewInstance(m_data);
229 m_data
.m_instance
= NULL
;
230 m_data
.m_window
= NULL
;
231 delete[] m_data
.m_argv
;
232 delete[] m_data
.m_argn
;
233 m_data
.m_argv
= NULL
;
234 m_data
.m_argn
= NULL
;
237 return NPERR_NO_ERROR
;
240 void wxPluginApp::NPP_Shutdown(void)
242 // Clean up wxWindows
246 void wxPluginApp::NPP_StreamAsFile(NPP instance
, NPStream
* stream
, const char *fname
)
248 wxPluginFrame
*frame
= FindFrame(instance
);
252 frame
->OnNPNewFile(stream
, str
);
257 void wxPluginApp::NPP_URLNotify(NPP instance, const char* url, NPReason reason,
263 int32
wxPluginApp::NPP_Write(NPP instance
, NPStream
* stream
, int32 offset
, int32 len
,
266 return len
; // The number of bytes accepted
269 static int32 STREAMBUFSIZE
= 0X0FFFFFFF; // If we are reading from a file in NPAsFile
270 // mode so we can take any size stream in our
271 // write call (since we ignore it)
273 int32
wxPluginApp::NPP_WriteReady(NPP instance
, NPStream
* stream
)
275 return STREAMBUFSIZE
; // Number of bytes ready to accept in NPP_Write()