]>
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
);
108 return NPERR_NO_ERROR
;
111 NPError
wxPluginApp::NPP_DestroyStream(NPP instance
, NPStream
* stream
, NPError reason
)
113 return NPERR_NO_ERROR
;
117 jref wxPluginApp::NPP_GetJavaClass(void)
123 // This can't work now because we don't have a global app until wxEntry is called.
124 // We'll put the wxEntry call in npshell.cpp instead.
125 NPError
wxPluginApp::NPP_Initialize(void)
127 static int init
= FALSE
;
130 MessageBox(NULL
, "wxPluginApp::NPP_Initialize:\nabout to call wxEntry for 2nd time!!!", "wxPlugin", MB_OK
);
132 wxEntry((WXHINSTANCE
) GetModuleHandle(NULL
));
136 // MessageBox(NULL, "wxPluginApp::NPP_Initialize: have called wxEntry", "wxPlugin", MB_OK);
137 return NPERR_NO_ERROR
;
140 NPError
wxPluginApp::NPP_New(NPMIMEType pluginType
, NPP instance
, uint16 mode
,
141 int16 argc
, char* argn
[], char* argv
[], NPSavedData
* saved
)
143 // MessageBox(NULL, "wxPluginApp::NPP_New", "wxPlugin", MB_OK);
145 // Save values so frame can be created in first NPP_SetWindow
146 if ( m_data
.m_instance
!= 0 )
148 MessageBox(NULL
, "wxPluginApp::NPP_New: whoops, 2 NPP_New calls in succession without NPP_SetWindow.\n Need to modify my code!", "wxPlugin", MB_OK
);
149 return NPERR_NO_ERROR
;
152 m_data
.m_instance
= instance
;
153 m_data
.m_type
= pluginType
;
154 m_data
.m_mode
= mode
;
156 SetAttributeValues(argc
, argn
, argv
);
158 // Unfortunately, we may get a stream event before we've got a valid window
159 // handle, so we just have to go ahead and create a new instance.
160 wxPluginFrame
*frame
= OnNewInstance(m_data
);
162 m_data
.m_instance
= NULL
;
163 m_data
.m_window
= NULL
;
164 delete[] m_data
.m_argv
;
165 delete[] m_data
.m_argn
;
166 m_data
.m_argv
= NULL
;
167 m_data
.m_argn
= NULL
;
169 return NPERR_NO_ERROR
;
172 NPError
wxPluginApp::NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
*stream
,
173 NPBool seekable
, uint16
* stype
)
175 // By default, we want to receive a file instead of a stream.
176 wxPluginFrame
*frame
= FindFrame(instance
);
179 return frame
->OnNPNewStream(type
, stream
, seekable
, stype
);
181 return NPERR_NO_ERROR
;
184 void wxPluginApp::NPP_Print(NPP instance
, NPPrint
* printInfo
)
186 if (instance
== NULL
)
189 wxPluginFrame
*frame
= FindFrame(instance
);
192 frame
->OnNPPrint(printInfo
);
196 NPError
wxPluginApp::NPP_SetWindow(NPP instance
, NPWindow
* window
)
198 // MessageBox(NULL, "wxPluginApp::NPP_SetWindow", "wxPlugin", MB_OK);
201 wxDebugMsg("%d\n", (int) window
->window
);
203 wxPluginFrame
*frame
= FindFrame(instance
);
206 frame
->SetNPWindow(window
);
211 // No such frame: must make it.
212 if ( m_data
.m_instance
== NULL
)
214 MessageBox(NULL
, "wxPluginApp::NPP_SetWindow: whoops, no data to create window. SetWindow called in funny order?", "wxPlugin", MB_OK
);
215 return NPERR_NO_ERROR
;
218 if ( window
->window
== NULL
)
220 // We're receiving a NULL window before we've even received
221 // a valid window. Ignore this silly thing.
222 return NPERR_NO_ERROR
;
225 m_data
.m_window
= window
;
226 m_data
.m_instance
= instance
;
228 // wxPluginFrame *frame = OnNewInstance(m_data);
230 m_data
.m_instance
= NULL
;
231 m_data
.m_window
= NULL
;
232 delete[] m_data
.m_argv
;
233 delete[] m_data
.m_argn
;
234 m_data
.m_argv
= NULL
;
235 m_data
.m_argn
= NULL
;
238 return NPERR_NO_ERROR
;
241 void wxPluginApp::NPP_Shutdown(void)
243 // Clean up wxWindows
247 void wxPluginApp::NPP_StreamAsFile(NPP instance
, NPStream
* stream
, const char *fname
)
249 wxPluginFrame
*frame
= FindFrame(instance
);
253 frame
->OnNPNewFile(stream
, str
);
258 void wxPluginApp::NPP_URLNotify(NPP instance, const char* url, NPReason reason,
264 int32
wxPluginApp::NPP_Write(NPP instance
, NPStream
* stream
, int32 offset
, int32 len
,
267 return len
; // The number of bytes accepted
270 static int32 STREAMBUFSIZE
= 0X0FFFFFFF; // If we are reading from a file in NPAsFile
271 // mode so we can take any size stream in our
272 // write call (since we ignore it)
274 int32
wxPluginApp::NPP_WriteReady(NPP instance
, NPStream
* stream
)
276 return STREAMBUFSIZE
; // Number of bytes ready to accept in NPP_Write()