vlcplugin_win.cpp 6.41 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlcplugin_win.cpp: a VLC plugin for Mozilla (Windows interface)
 *****************************************************************************
4
 * Copyright (C) 2011-2012 VLC authors and VideoLAN
5 6
 * $Id$
 *
7 8
 * Authors: Cheng Sun <chengsun9@gmail.com>
 *          Sergey Radionov <RSATom@gmail.com>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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.
 *****************************************************************************/

25 26 27 28
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

29 30 31 32 33 34 35 36 37 38 39 40 41 42
#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 )
{
43
    (void)lpReserved;
44 45 46 47 48 49 50 51 52 53 54 55
    switch( fdwReason )
    {
        case DLL_PROCESS_ATTACH:
            hDllModule = (HMODULE)hModule;
            break;
        default:
            break;
    }
    return TRUE;
};


56 57 58 59 60 61
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);

62
        switch( uMsg ){
63 64 65 66 67
            case WM_ERASEBKGND:
                RECT rect;
                GetClientRect(hWnd, &rect);
                FillRect((HDC)wParam, &rect, (HBRUSH) (COLOR_WINDOW+1));
                return 1;
68 69 70 71 72 73 74 75 76
            case WM_LBUTTONDBLCLK:
                /*if we get WM_LBUTTONDBLCLK here,
                * it mean that fullscreen mode is on,
                * and fullscreen window is on another display.
                * So user can see browser window and
                * plugin drawable (i.e. this) window,
                * and might want switch fullscreen off*/
                p_plugin->set_fullscreen(false);
                return 0;
77 78 79 80 81 82
            case WM_DESTROY:
                // Opera does not call NPP_SetWindow on window destruction...
                p_plugin->destroy_windows();
                break;
        }

83 84 85 86 87 88 89 90
        /* delegate to default handler */
        return CallWindowProc( p_plugin->_NPWndProc, hWnd,
                               uMsg, wParam, lParam);
    }
    else
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

91
VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
92
    VlcPluginBase(instance, mode), _NPWndProc(0),
93
    _WindowsManager(DllGetModule(), _ViewRC, &m_player, &get_options())
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
    _ViewRC.hDeFullscreenBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(3),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hPlayBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(4),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hPauseBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(5),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hVolumeBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(6),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hVolumeMutedBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(7),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

    _ViewRC.hBackgroundIcon =
        (HICON) LoadImage(DllGetModule(), MAKEINTRESOURCE(8),
                          IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);

    _ViewRC.hFullscreenBitmap =
        LoadImage(DllGetModule(), MAKEINTRESOURCE(9),
                  IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
122 123 124 125
}

VlcPluginWin::~VlcPluginWin()
{
126
    destroy_windows();
127 128 129 130
}

void VlcPluginWin::toggle_fullscreen()
{
131
    _WindowsManager.ToggleFullScreen();
132 133 134 135
}

void VlcPluginWin::set_fullscreen(int yes)
{
136 137 138 139 140 141
    if(yes){
        _WindowsManager.StartFullScreen();
    }
    else{
        _WindowsManager.EndFullScreen();
    }
142 143
}

144
bool VlcPluginWin::get_fullscreen()
145
{
146
    return _WindowsManager.IsFullScreen();
147 148
}

149
void VlcPluginWin::set_toolbar_visible(bool)
150 151 152 153
{
    /* TODO */
}

154
bool VlcPluginWin::get_toolbar_visible()
155 156
{
    /* TODO */
157
    return false;
158 159 160 161 162 163 164 165 166 167 168
}

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

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

169 170 171
    if( GetWindowLongPtr(drawable, GWLP_USERDATA) )
        return false;

172
    /* attach our plugin object */
173 174 175 176 177 178 179 180
    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 );
181 182 183 184 185 186 187 188 189 190 191 192 193 194

    /* 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);
195 196 197
    RECT rect;
    GetClientRect(drawable, &rect);
    if(!_WindowsManager.IsFullScreen() && _WindowsManager.getHolderWnd()){
198
        HWND hHolderWnd = _WindowsManager.getHolderWnd()->hWnd();
199 200
        MoveWindow(hHolderWnd, 0, 0, rect.right - rect.left, rect.bottom - rect.top, TRUE);
    }
201
    return true;
202 203 204 205
}

bool VlcPluginWin::destroy_windows()
{
206
    _WindowsManager.DestroyWindows();
207 208 209 210 211 212 213 214 215

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

216
    SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
217
    return true;
218
}
219

220
void VlcPluginWin::set_player_window()
221
{
222
    player().get_mp().setHwnd(_WindowsManager.getHolderWnd()->hWnd());
223
}