vlcplugin_win.cpp 4.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
#include "vlcplugin_win.h"

#include "../common/win32_fullscreen.h"

static HMODULE hDllModule= 0;

HMODULE DllGetModule()
{
    return hDllModule;
};

extern "C"
BOOL WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
{
    switch( fdwReason )
    {
        case DLL_PROCESS_ATTACH:
            hDllModule = (HMODULE)hModule;
            break;
        default:
            break;
    }
    return TRUE;
};


static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
{
    VlcPluginWin *p_plugin = reinterpret_cast<VlcPluginWin *>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));

    switch( i_msg )
    {
        case WM_ERASEBKGND:
            return 1L;

        case WM_PAINT:
        {
            PAINTSTRUCT paintstruct;
            HDC hdc;
            RECT rect;

            hdc = BeginPaint( p_hwnd, &paintstruct );

            GetClientRect( p_hwnd, &rect );

            FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
            SetTextColor(hdc, RGB(255, 255, 255));
            SetBkColor(hdc, RGB(0, 0, 0));
            if( p_plugin->psz_text )
                DrawText( hdc, p_plugin->psz_text, strlen(p_plugin->psz_text), &rect,
                          DT_CENTER|DT_VCENTER|DT_SINGLELINE);

            EndPaint( p_hwnd, &paintstruct );
            return 0L;
        }
        case WM_SIZE:{
            int new_client_width = LOWORD(lpar);
            int new_client_height = HIWORD(lpar);
            //first child will be resized to client area
            HWND hChildWnd = GetWindow(p_hwnd, GW_CHILD);
            if(hChildWnd){
                MoveWindow(hChildWnd, 0, 0, new_client_width, new_client_height, FALSE);
            }
            return 0L;
        }
        case WM_LBUTTONDBLCLK:{
            p_plugin->toggle_fullscreen();
            return 0L;
        }
        default:
            /* delegate to default handler */
            return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
                                   i_msg, wpar, lpar );
    }
}

VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
    VlcPluginBase(instance, mode),
    pf_wndproc(NULL),
    _WindowsManager(DllGetModule())
{
}

VlcPluginWin::~VlcPluginWin()
{
    HWND win = (HWND)getWindow().window;
    WNDPROC winproc = getWindowProc();
    if( winproc )
    {
        /* reset WNDPROC */
        SetWindowLongPtr( win, GWLP_WNDPROC, (LONG_PTR)winproc );
    }

    _WindowsManager.DestroyWindows();
}

void VlcPluginWin::set_player_window()
{
    _WindowsManager.LibVlcAttach(libvlc_media_player);
}

void VlcPluginWin::toggle_fullscreen()
{
    if (playlist_isplaying())
        libvlc_toggle_fullscreen(libvlc_media_player);
}

void VlcPluginWin::set_fullscreen(int yes)
{
    if (playlist_isplaying())
        libvlc_set_fullscreen(libvlc_media_player,yes);
}

int  VlcPluginWin::get_fullscreen()
{
    int r = 0;
    if (playlist_isplaying())
        r = libvlc_get_fullscreen(libvlc_media_player);
    return r;
}

void VlcPluginWin::show_toolbar()
{
    /* TODO */
}

void VlcPluginWin::hide_toolbar()
{
    /* TODO */
}

void VlcPluginWin::update_controls()
{
    /* TODO */
}

bool VlcPluginWin::create_windows()
{
    HWND drawable = (HWND) (getWindow().window);

    /* attach our plugin object */
    SetWindowLongPtr(drawable, GWLP_USERDATA,
                     (LONG_PTR)this);

    /* install our WNDPROC */
    setWindowProc( (WNDPROC)SetWindowLongPtr( drawable,
                                     GWLP_WNDPROC, (LONG_PTR)Manage ) );

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

    _WindowsManager.CreateWindows(drawable);

    return true;
}

bool VlcPluginWin::resize_windows()
{
    /* TODO */
    HWND drawable = (HWND) (getWindow().window);
    /* Redraw window */
    InvalidateRect( drawable, NULL, TRUE );
    UpdateWindow( drawable );
166
    return true;
167 168 169 170 171 172 173 174 175 176
}

bool VlcPluginWin::destroy_windows()
{
    /* reset WNDPROC */
    HWND oldwin = (HWND)npwindow.window;
    SetWindowLongPtr( oldwin, GWLP_WNDPROC, (LONG_PTR)(getWindowProc()) );
    setWindowProc(NULL);

    npwindow.window = NULL;
177
    return true;
178
}