Example #1
0
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;
}