示例#1
0
bool VlcPluginMac::resize_windows()
{
    /* as MacOS X video output is windowless, set viewport */
    libvlc_rectangle_t view, clip;

    /* browser sets port origin to top-left location of plugin
     * relative to GrafPort window origin is set relative to document,
     * which of little use for drawing
     */
    view.top	= 0; // ((NP_Port*) (npwindow.window))->porty;
    view.left	= 0; // ((NP_Port*) (npwindow.window))->portx;
    view.bottom  = npwindow.height+view.top;
    view.right   = npwindow.width+view.left;

    /* clipRect coordinates are also relative to GrafPort */
    clip.top     = npwindow.clipRect.top;
    clip.left    = npwindow.clipRect.left;
    clip.bottom  = npwindow.clipRect.bottom;
    clip.right   = npwindow.clipRect.right;

#ifdef NOT_WORKING
    libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
#else
#warning disabled code
#endif
}
示例#2
0
文件: vlcshell.cpp 项目: paa/vlc
NPError NPP_SetWindow( NPP instance, NPWindow* window )
{
#if defined(XP_UNIX)
    Window control;
    unsigned int i_control_height = 0, i_control_width = 0;
#endif

    if( ! instance )
    {
        return NPERR_INVALID_INSTANCE_ERROR;
    }

    /* NPP_SetWindow may be called before NPP_New (Opera) */
    VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
    if( NULL == p_plugin )
    {
        /* we should probably show a splash screen here */
        return NPERR_NO_ERROR;
    }

#if defined(XP_UNIX)
    control = p_plugin->getControlWindow();
#endif

    libvlc_instance_t *p_vlc = p_plugin->getVLC();

    /*
     * PLUGIN DEVELOPERS:
     *  Before setting window to point to the
     *  new window, you may wish to compare the new window
     *  info to the previous window (if any) to note window
     *  size changes, etc.
     */

    /* retrieve current window */
    NPWindow& curwin = p_plugin->getWindow();

#ifdef XP_MACOSX
    if( window && window->window )
    {
        /* check if plugin has a new parent window */
        CGrafPtr drawable = (((NP_Port*) (window->window))->port);

        /* as MacOS X video output is windowless, set viewport */
        libvlc_rectangle_t view, clip;

        /*
        ** browser sets port origin to top-left location of plugin
        ** relative to GrafPort window origin is set relative to document,
        ** which of little use for drawing
        */
        view.top     = ((NP_Port*) (window->window))->porty;
        view.left    = ((NP_Port*) (window->window))->portx;
        view.bottom  = window->height+view.top;
        view.right   = window->width+view.left;

        /* clipRect coordinates are also relative to GrafPort */
        clip.top     = window->clipRect.top;
        clip.left    = window->clipRect.left;
        clip.bottom  = window->clipRect.bottom;
        clip.right   = window->clipRect.right;
#ifdef NOT_WORKING
        libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
#else
#warning disabled code
#endif
        /* remember new window */
        p_plugin->setWindow(*window);
    }
    else if( curwin.window )
    {
        /* change/set parent */
        curwin.window = NULL;
    }
#endif /* XP_MACOSX */

#ifdef XP_WIN
    if( window && window->window )
    {
        /* check if plugin has a new parent window */
        HWND drawable = (HWND) (window->window);
        if( !curwin.window || drawable != curwin.window )
        {
            /* reset previous window settings */
            HWND oldwin = (HWND)p_plugin->getWindow().window;
            WNDPROC oldproc = p_plugin->getWindowProc();
            if( oldproc )
            {
                /* reset WNDPROC */
                SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
            }
            /* attach our plugin object */
            SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
                             reinterpret_cast<LONG_PTR>(p_plugin));

            /* install our WNDPROC */
            p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
                                             GWL_WNDPROC, (LONG)Manage ) );

            /* change window style to our liking */
            LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
            style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
            SetWindowLong((HWND)drawable, GWL_STYLE, style);

            /* remember new window */
            p_plugin->setWindow(*window);

            /* Redraw window */
            InvalidateRect( (HWND)drawable, NULL, TRUE );
            UpdateWindow( (HWND)drawable );
        }
    }
    else if( curwin.window )
    {
        /* reset WNDPROC */
        HWND oldwin = (HWND)curwin.window;
        SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
        p_plugin->setWindowProc(NULL);

        curwin.window = NULL;
    }
#endif /* XP_WIN */

#if defined(XP_UNIX)
    /* default to hidden toolbar, shown at the end of this method if asked *
     * developers note : getToolbarSize need to wait the end of this method
     */
    i_control_height = 0;
    i_control_width = window->width;

    if( window && window->window )
    {
        Window  parent  = (Window) window->window;
        if( !curwin.window || (parent != (Window)curwin.window) )
        {
            Display *p_display = ( (NPSetWindowCallbackStruct *)
                                   window->ws_info )->display;

            XResizeWindow( p_display, parent, window->width, window->height );

            int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));

            /* create windows */
            Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
                           window->width, window->height - i_control_height,
                           0, i_blackColor, i_blackColor );
            Window controls = (Window) NULL;
            controls = XCreateSimpleWindow( p_display, parent,
                            0, window->height - i_control_height-1,
                            window->width, i_control_height-1,
                            0, i_blackColor, i_blackColor );

            XMapWindow( p_display, parent );
            XMapWindow( p_display, video );
            if( controls ) { XMapWindow( p_display, controls ); }

            XFlush(p_display);

            /* bind events */
            Widget w = XtWindowToWidget( p_display, parent );

            XtAddEventHandler( w, ExposureMask, FALSE,
                               (XtEventHandler)Redraw, p_plugin );
            XtAddEventHandler( w, StructureNotifyMask, FALSE,
                               (XtEventHandler)Resize, p_plugin );
            XtAddEventHandler( w, ButtonReleaseMask, FALSE,
                               (XtEventHandler)ControlHandler, p_plugin );

            /* remember window */
            p_plugin->setWindow( *window );
            p_plugin->setVideoWindow( video );

            if( controls )
            {
                p_plugin->setControlWindow( controls );
            }

            Redraw( w, (XtPointer)p_plugin, NULL );

            /* now display toolbar if asked through parameters */
            if( p_plugin->b_toolbar )
            {
                p_plugin->showToolbar();
            }
        }
    }
    else if( curwin.window )
    {
        curwin.window = NULL;
    }
#endif /* XP_UNIX */

    if( !p_plugin->b_stream )
    {
        if( p_plugin->psz_target )
        {
            if( p_plugin->playlist_add( p_plugin->psz_target ) != -1 )
            {
                if( p_plugin->b_autoplay )
                {
                    p_plugin->playlist_play();
                }
            }
            p_plugin->b_stream = true;
        }
    }
    return NPERR_NO_ERROR;
}