int16_t NpapiPluginWin::HandleEvent(void* event) { PluginWindowlessWin* win = dynamic_cast<PluginWindowlessWin*>(pluginWin); NPEvent* evt(reinterpret_cast<NPEvent*>(event)); if(win != NULL) { LRESULT lRes(0); if (win->HandleEvent(evt->event, evt->wParam, evt->lParam, lRes)) { return boost::numeric_cast<int16_t>(lRes); } } return false; }
int16_t NpapiPluginWin::HandleEvent(void* event) { PluginWindowlessWin* win = dynamic_cast<PluginWindowlessWin*>(pluginWin); NPEvent* evt(reinterpret_cast<NPEvent*>(event)); if(win != NULL) { LRESULT lRes(0); if (evt->event == WM_PAINT) { //special handle drawing, as we need to pass the draw bounds through the layers FB::Rect bounds; if (evt->lParam) { // some browsers pass through bounds in lParam, but Safari does not (as of 5.0.5) RECT *prc = (RECT*) evt->lParam; // not 64-bit safe, but it's how NPAPI works bounds.top = prc->top; bounds.left = prc->left; bounds.bottom = prc->bottom; bounds.right = prc->right; } else { bounds = win->getWindowPosition(); } return win->HandleDraw((HDC)evt->wParam, bounds); } else if (win->HandleEvent(evt->event, static_cast<uint32_t>(evt->wParam), evt->lParam, lRes)) { return boost::numeric_cast<int16_t>(lRes); } } return false; }
NPError NpapiPluginWin::SetWindow(NPWindow* window) { // If window == NULL then our window is gone. Stop drawing. if(window == NULL || window->window == NULL) { // Our window is gone if(pluginMain != NULL) { // Destroy our FireBreath window pluginMain->ClearWindow(); delete pluginWin; pluginWin = NULL; } return NPERR_NO_ERROR; } if (!pluginGuiEnabled()) return NPERR_NO_ERROR; // Code here diverges depending on if // the plugin is windowed or windowless. if(pluginMain->isWindowless()) { assert(window->type == NPWindowTypeDrawable); PluginWindowlessWin* win = dynamic_cast<PluginWindowlessWin*>(pluginWin); if(win == NULL && pluginWin != NULL) { // We've received a window of a different type than the // window we have been using up until now. // This is unlikely/impossible, but it's worth checking for. pluginMain->ClearWindow(); delete pluginWin; pluginWin = NULL; } if(pluginWin == NULL) { // Create new window win = getFactoryInstance()->createPluginWindowless(FB::WindowContextWindowless(NULL)); HWND browserHWND; m_npHost->GetValue(NPNVnetscapeWindow, (void*)&browserHWND); win->setHWND(browserHWND); win->setWindowPosition(window->x, window->y, window->width, window->height); win->setWindowClipping(window->clipRect.top, window->clipRect.left, window->clipRect.bottom, window->clipRect.right); win->setInvalidateWindowFunc(boost::bind(&NpapiPluginWin::invalidateWindow, this, _1, _2, _3, _4)); pluginMain->SetWindow(win); pluginWin = win; } else { win->setWindowPosition(window->x, window->y, window->width, window->height); win->setWindowClipping(window->clipRect.top, window->clipRect.left, window->clipRect.bottom, window->clipRect.right); } } else { assert(window->type == NPWindowTypeWindow); PluginWindowWin* win = dynamic_cast<PluginWindowWin*>(pluginWin); // Check to see if we've received a new HWND (new window) if(win != NULL && win->getHWND() != (HWND)window->window) { pluginMain->ClearWindow(); delete pluginWin; pluginWin = NULL; } else if(win == NULL && pluginWin != NULL) { // We've received a window of a different type than the // window we have been using up until now. // This is unlikely/impossible, but it's worth checking for. pluginMain->ClearWindow(); delete pluginWin; pluginWin = NULL; } if(pluginWin == NULL) { // Sanity check assert(::IsWindow((HWND)window->window)); // Create new window HWND browserHWND; m_npHost->GetValue(NPNVnetscapeWindow, (void*)&browserHWND); win = getFactoryInstance()->createPluginWindowWin(FB::WindowContextWin((HWND)window->window)); win->setBrowserHWND(browserHWND); pluginMain->SetWindow(win); pluginWin = win; } } return NPERR_NO_ERROR; }