44 #include "npfunctions.h"
45 #include "BasePlugin.h"
46 #include "dllFreeWRL.h"
74 m_pNPInstance(pNPInstance),
76 m_bInitialized(FALSE),
77 m_pScriptableObject(NULL)
82 m_pfreeWRLPlayer = NULL;
86 assert(m_pfreeWRLPlayer);
92 NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj);
97 if (m_pScriptableObject)
98 NPN_ReleaseObject(m_pScriptableObject);
101 NPN_ReleaseObject(sWindowObj);
107 static LRESULT CALLBACK PluginWinProc(HWND, UINT, WPARAM, LPARAM);
108 static WNDPROC lpOldProc = NULL;
111 NPBool CPlugin::init(
NPWindow* pNPWindow)
113 if(pNPWindow == NULL)
116 m_Window = pNPWindow;
119 m_hWnd = (HWND)pNPWindow->window;
125 lpOldProc = SubclassWindow(m_hWnd, (WNDPROC)PluginWinProc);
129 SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)
this);
131 m_hWnd = (
long int*) pNPWindow->window;
136 bool frontend_handles_display_thread =
false;
137 m_pfreeWRLPlayer->onInit(pNPWindow->width,pNPWindow->height, pNPWindow->window, m_EAIflag, frontend_handles_display_thread);
140 m_pfreeWRLPlayer->onLoad(m_sceneUrl);
143 m_bInitialized = TRUE;
149 m_pfreeWRLPlayer->onClose();
154 SubclassWindow(m_hWnd, lpOldProc);
162 delete m_pfreeWRLPlayer;
164 m_bInitialized = FALSE;
167 NPBool CPlugin::isInitialized()
169 return m_bInitialized;
172 int16_t CPlugin::handleEvent(
void* event)
175 NPEvent* ev = (NPEvent*)event;
177 Rect box = { m_Window->y, m_Window->x,
178 m_Window->y + m_Window->height, m_Window->x + m_Window->width };
179 if (ev->what == updateEvt) {
180 ::TETextBox(m_String, strlen(m_String), &box, teJustCenter);
188 void CPlugin::showVersion()
190 const char *ua = NPN_UserAgent(m_pNPInstance);
191 strcpy_s(m_String, ua);
194 InvalidateRect(m_hWnd, NULL, TRUE);
195 UpdateWindow(m_hWnd);
211 void CPlugin::clear()
213 strcpy_s(m_String,
"");
216 InvalidateRect(m_hWnd, NULL, TRUE);
217 UpdateWindow(m_hWnd);
221 void CPlugin::getVersion(
char* *aVersion)
223 const char *ua = NPN_UserAgent(m_pNPInstance);
224 char*& version = *aVersion;
225 version = (
char*)NPN_MemAlloc(1 + strlen(ua));
227 strcpy_s(version,
sizeof(version), ua);
231 CPlugin::GetScriptableObject()
233 if (!m_pScriptableObject) {
234 m_pScriptableObject =
235 NPN_CreateObject(m_pNPInstance,
239 if (m_pScriptableObject) {
240 NPN_RetainObject(m_pScriptableObject);
243 return m_pScriptableObject;
248 static HCURSOR hSensor, hArrow;
249 static HCURSOR cursor;
252 hSensor = LoadCursor(NULL,IDC_HAND);
253 hArrow = LoadCursor( NULL, IDC_ARROW );
255 void updateCursorStyle0(
int cstyle)
257 if(!hSensor) loadCursors();
260 SetCursor(hSensor);
break;
262 SetCursor(hArrow);
break;
264 SetCursor(NULL);
break;
269 LRESULT CPlugin::handleWindowEvents(HWND hWnd, UINT eventmsg, WPARAM wParam, LPARAM lParam)
290 cursorStyle = m_pfreeWRLPlayer->onMouse(4, 1,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
291 updateCursorStyle0(cursorStyle);
296 cursorStyle = m_pfreeWRLPlayer->onMouse(5, 1,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
297 updateCursorStyle0(cursorStyle);
302 cursorStyle = m_pfreeWRLPlayer->onMouse(4, 2,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
303 updateCursorStyle0(cursorStyle);
308 cursorStyle = m_pfreeWRLPlayer->onMouse(5, 2,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
309 updateCursorStyle0(cursorStyle);
314 cursorStyle = m_pfreeWRLPlayer->onMouse(4, 3,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
315 updateCursorStyle0(cursorStyle);
320 cursorStyle = m_pfreeWRLPlayer->onMouse(5, 3,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
321 updateCursorStyle0(cursorStyle);
322 updateCursorStyle0(cursorStyle);
327 cursorStyle = m_pfreeWRLPlayer->onMouse(6, 0,GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam));
328 updateCursorStyle0(cursorStyle);
333 m_pfreeWRLPlayer->onKey(CdllFreeWRL::KEYDOWN,wParam);
338 m_pfreeWRLPlayer->onKey(CdllFreeWRL::KEYUP,wParam);
343 m_pfreeWRLPlayer->onKey(CdllFreeWRL::KEYPRESS,wParam);
359 void CPlugin::setSceneUrl(
char* sceneUrl)
362 size_t buffersize = strlen(sceneUrl)+1;
364 char* buf = (
char*) calloc(buffersize,
sizeof(
char));
366 strcpy_s(buf,buffersize,sceneUrl);
371 void CPlugin::setEAIFlag()
378 static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
380 CPlugin *plugin = (
CPlugin *)(LONG_PTR) GetWindowLong(hWnd, GWL_USERDATA);
386 std::string errormsg(
"Instance Error: Plugin has not been initialized");
390 HDC hdc = BeginPaint(hWnd, &ps);
392 GetClientRect(hWnd, &rc);
393 FrameRect(hdc, &rc, GetStockBrush(BLACK_BRUSH));
394 DrawText(hdc, (LPCTSTR) errormsg.c_str(), errormsg.length(), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
404 plugin->handleWindowEvents(hWnd,msg,wParam,lParam);
406 return DefWindowProc(hWnd, msg, wParam, lParam);
CPlugin(NPP pNPInstance)
CPlugin class.constructor.