]>
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 // 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.
126 NPError
wxPluginApp::NPP_Initialize(void)
128 static int init
= FALSE
;
131 MessageBox(NULL
, "wxPluginApp::NPP_Initialize:\nabout to call wxEntry for 2nd time!!!", "wxPlugin", MB_OK
);
133 wxEntry((WXHINSTANCE
) GetModuleHandle(NULL
));
137 // MessageBox(NULL, "wxPluginApp::NPP_Initialize: have called wxEntry", "wxPlugin", MB_OK);
138 return NPERR_NO_ERROR
;
141 NPError
wxPluginApp::NPP_New(NPMIMEType pluginType
, NPP instance
, uint16 mode
,
142 int16 argc
, char* argn
[], char* argv
[], NPSavedData
* saved
)
144 // MessageBox(NULL, "wxPluginApp::NPP_New", "wxPlugin", MB_OK);
146 // Save values so frame can be created in first NPP_SetWindow
147 if ( m_data
.m_instance
!= 0 )
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
;
153 m_data
.m_instance
= instance
;
154 m_data
.m_type
= pluginType
;
155 m_data
.m_mode
= mode
;
157 SetAttributeValues(argc
, argn
, argv
);
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
);
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
;
170 return NPERR_NO_ERROR
;
173 NPError
wxPluginApp::NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
*stream
,
174 NPBool seekable
, uint16
* stype
)
176 // By default, we want to receive a file instead of a stream.
177 wxPluginFrame
*frame
= FindFrame(instance
);
180 return frame
->OnNPNewStream(type
, stream
, seekable
, stype
);
182 return NPERR_NO_ERROR
;
185 void wxPluginApp::NPP_Print(NPP instance
, NPPrint
* printInfo
)
187 if (instance
== NULL
)
190 wxPluginFrame
*frame
= FindFrame(instance
);
193 frame
->OnNPPrint(printInfo
);
197 NPError
wxPluginApp::NPP_SetWindow(NPP instance
, NPWindow
* window
)
199 // MessageBox(NULL, "wxPluginApp::NPP_SetWindow", "wxPlugin", MB_OK);
202 wxDebugMsg("%d\n", (int) window
->window
);
204 wxPluginFrame
*frame
= FindFrame(instance
);
207 frame
->SetNPWindow(window
);
212 // No such frame: must make it.
213 if ( m_data
.m_instance
== NULL
)
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
;
219 if ( window
->window
== NULL
)
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
;
226 m_data
.m_window
= window
;
227 m_data
.m_instance
= instance
;
229 // wxPluginFrame *frame = OnNewInstance(m_data);
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
;
239 return NPERR_NO_ERROR
;
242 void wxPluginApp::NPP_Shutdown(void)
244 // Clean up wxWindows
248 void wxPluginApp::NPP_StreamAsFile(NPP instance
, NPStream
* stream
, const char *fname
)
250 wxPluginFrame
*frame
= FindFrame(instance
);
254 frame
->OnNPNewFile(stream
, str
);
259 void wxPluginApp::NPP_URLNotify(NPP instance, const char* url, NPReason reason,
265 int32
wxPluginApp::NPP_Write(NPP instance
, NPStream
* stream
, int32 offset
, int32 len
,
268 return len
; // The number of bytes accepted
271 static 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)
275 int32
wxPluginApp::NPP_WriteReady(NPP instance
, NPStream
* stream
)
277 return STREAMBUFSIZE
; // Number of bytes ready to accept in NPP_Write()