vlcplugin_win.cpp 5.03 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
/*****************************************************************************
 * vlcplugin_win.cpp: a VLC plugin for Mozilla (Windows interface)
 *****************************************************************************
 * Copyright (C) 2011 the VideoLAN team
 * $Id$
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *          Damien Fouilleul <damienf@videolan.org>
 *          Jean-Paul Saman <jpsaman@videolan.org>
 *          Cheng Sun <chengsun9@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

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
#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;
};


53 54 55 56 57 58
LRESULT CALLBACK VlcPluginWin::NPWndProcR(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG_PTR ud = GetWindowLongPtr(hWnd, GWLP_USERDATA);
    if( ud ) {
        VlcPluginWin *p_plugin = reinterpret_cast<VlcPluginWin *>(ud);

59
        switch( uMsg ){
60 61 62 63 64
            case WM_ERASEBKGND:
                RECT rect;
                GetClientRect(hWnd, &rect);
                FillRect((HDC)wParam, &rect, (HBRUSH) (COLOR_WINDOW+1));
                return 1;
65 66 67 68 69 70
            case WM_DESTROY:
                // Opera does not call NPP_SetWindow on window destruction...
                p_plugin->destroy_windows();
                break;
        }

71 72 73 74 75 76 77 78
        /* delegate to default handler */
        return CallWindowProc( p_plugin->_NPWndProc, hWnd,
                               uMsg, wParam, lParam);
    }
    else
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

79
VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
80
    VlcPluginBase(instance, mode), _NPWndProc(0),
81 82 83 84 85 86
    _WindowsManager(DllGetModule())
{
}

VlcPluginWin::~VlcPluginWin()
{
87
    destroy_windows();
88 89 90 91
}

void VlcPluginWin::toggle_fullscreen()
{
92
    _WindowsManager.ToggleFullScreen();
93 94 95 96
}

void VlcPluginWin::set_fullscreen(int yes)
{
97 98 99 100 101 102
    if(yes){
        _WindowsManager.StartFullScreen();
    }
    else{
        _WindowsManager.EndFullScreen();
    }
103 104 105 106
}

int  VlcPluginWin::get_fullscreen()
{
107
    return _WindowsManager.IsFullScreen();
108 109
}

110
void VlcPluginWin::set_toolbar_visible(bool)
111 112 113 114
{
    /* TODO */
}

115
bool VlcPluginWin::get_toolbar_visible()
116 117
{
    /* TODO */
118
    return false;
119 120 121 122 123 124 125 126 127 128 129
}

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

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

130 131 132
    if( GetWindowLongPtr(drawable, GWLP_USERDATA) )
        return false;

133
    /* attach our plugin object */
134 135 136 137 138 139 140 141
    SetWindowLongPtr(drawable, GWLP_USERDATA, (LONG_PTR)this);

    /* Some browsers (mainly opera) do not implement NPAPI correctly,
     * so we will need track some events via native window messages,
     * rather than via NPP_SetWindow. */
    _NPWndProc = (WNDPROC) SetWindowLongPtr( drawable,
                                             GWLP_WNDPROC,
                                             (LONG_PTR)NPWndProcR );
142 143 144 145 146 147 148 149 150 151 152 153 154 155

    /* 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()
{
    HWND drawable = (HWND) (getWindow().window);
156 157 158 159 160 161
    RECT rect;
    GetClientRect(drawable, &rect);
    if(!_WindowsManager.IsFullScreen() && _WindowsManager.getHolderWnd()){
        HWND hHolderWnd = _WindowsManager.getHolderWnd()->getHWND();
        MoveWindow(hHolderWnd, 0, 0, rect.right - rect.left, rect.bottom - rect.top, TRUE);
    }
162
    return true;
163 164 165 166
}

bool VlcPluginWin::destroy_windows()
{
167
    _WindowsManager.DestroyWindows();
168 169 170 171 172 173 174 175 176

    HWND hWnd = (HWND)npwindow.window;
    if( hWnd && _NPWndProc){
        /* reset WNDPROC */
        SetWindowLongPtr( hWnd, GWLP_WNDPROC, (LONG_PTR)_NPWndProc );
    }
    _NPWndProc = 0;
    npwindow.window = 0;

177
    SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
178
    return true;
179
}
180 181 182 183 184 185

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

186 187 188 189
void VlcPluginWin::on_media_player_release()
{
    _WindowsManager.LibVlcDetach();
}