win32_fullscreen.h 8.68 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlc_win32_fullscreen.h: a VLC plugin for Mozilla
 *****************************************************************************
4
 * Copyright © 2002-2011 VideoLAN and VLC authors
5 6 7 8
 * $Id$
 *
 * Authors: Sergey Radionov <rsatom@gmail.com>
 *
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15 16
 * (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
17
 * GNU Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20 21 22 23 24 25 26 27 28
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef VLC_FULLSCREEN_H
#define VLC_FULLSCREEN_H

#ifdef _WIN32

29
#include "win32_vlcwnd.h"
30
#include "vlc_player_options.h"
31
#include "vlc_player.h"
32

33 34 35
enum{
    WM_MOUSE_EVENT_NOTIFY = WM_APP + 1,
    WM_MOUSE_EVENT_REPOST,
36
    WM_SET_MOUSE_HOOK,
37 38 39 40
    WM_MOUSE_EVENT_NOTIFY_SUCCESS = 0xFF
};


41 42 43
struct VLCViewResources
{
    VLCViewResources()
44
        :hNewMessageBitmap(0), hFullscreenBitmap(0), hDeFullscreenBitmap(0), hPauseBitmap(0),
45 46
         hPlayBitmap(0), hVolumeBitmap(0), hVolumeMutedBitmap(0),
         hBackgroundIcon(0)
47
    {}
Sergey Radionov's avatar
Sergey Radionov committed
48 49 50 51 52 53 54 55 56 57 58
    ~VLCViewResources()
    {
        if( hNewMessageBitmap )   DeleteObject( hNewMessageBitmap );
        if( hFullscreenBitmap )   DeleteObject( hFullscreenBitmap );
        if( hDeFullscreenBitmap ) DeleteObject( hDeFullscreenBitmap );
        if( hPauseBitmap )        DeleteObject( hPauseBitmap );
        if( hPlayBitmap )         DeleteObject( hPlayBitmap );
        if( hVolumeBitmap )       DeleteObject( hVolumeBitmap );
        if( hVolumeMutedBitmap )  DeleteObject( hVolumeMutedBitmap );
        if( hBackgroundIcon )     DestroyIcon ( hBackgroundIcon );
    }
59 60 61 62 63 64 65 66 67 68 69

    HANDLE hNewMessageBitmap;
    HANDLE hFullscreenBitmap;
    HANDLE hDeFullscreenBitmap;
    HANDLE hPauseBitmap;
    HANDLE hPlayBitmap;
    HANDLE hVolumeBitmap;
    HANDLE hVolumeMutedBitmap;
    HICON  hBackgroundIcon;
};

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
////////////////////////////////////////////////////////////////////////////////
//class VLCControlsWnd
////////////////////////////////////////////////////////////////////////////////
class VLCWindowsManager;
class VLCControlsWnd: public VLCWnd
{
    enum{
        xControlsSpace = 5
    };

    enum{
        ID_FS_SWITCH_FS = 1,
        ID_FS_PLAY_PAUSE = 2,
        ID_FS_VIDEO_POS_SCROLL = 3,
        ID_FS_MUTE = 4,
        ID_FS_VOLUME = 5,
    };

protected:
    VLCControlsWnd(HINSTANCE hInstance, VLCWindowsManager* WM);
    bool Create(HWND hWndParent);

public:
    static VLCControlsWnd*
        CreateControlsWindow(HINSTANCE hInstance,
                             VLCWindowsManager* wm, HWND hWndParent);
    ~VLCControlsWnd();

    void NeedShowControls();

100

101
    //libvlc events arrives from separate thread
102
    void UpdateFullscreenButton(bool fullscreen);
103 104 105 106 107 108 109 110

protected:
    virtual void PreRegisterWindowClass(WNDCLASS* wc);
    virtual LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
    void SetVideoPos(float Pos); //0-start, 1-end

111 112
    void UpdateVolumeSlider(unsigned int vol);
    void UpdateMuteButton(bool muted);
113
    void RegisterToVLCEvents();
114 115 116 117 118

    void NeedHideControls();

    bool IsPlaying()
    {
119
        if( VP() )
120
            return VP()->mlp().isPlaying();
121 122 123 124 125 126 127 128
        return false;
    }

private:
    VLCWindowsManager* _wm;

    VLCWindowsManager& WM() {return *_wm;}
    inline const VLCViewResources& RC();
129
    inline vlc_player* VP() const;
130
    inline const vlc_player_options* PO() const;
131 132 133 134 135 136 137 138 139 140 141 142

    void CreateToolTip();

private:
    HWND hToolTipWnd;
    HWND hFSButton;
    HWND hPlayPauseButton;
    HWND hVideoPosScroll;
    HWND hMuteButton;
    HWND hVolumeSlider;
};

143 144 145
////////////////////////////////////////////////////////////////////////////////
//class VLCHolderWnd
////////////////////////////////////////////////////////////////////////////////
146
class VLCWindowsManager;
147
class VLCHolderWnd: public VLCWnd
148 149
{
public:
150 151 152 153 154 155 156 157
    static VLCHolderWnd*
        CreateHolderWindow(HINSTANCE hInstance,
                           HWND hParentWnd, VLCWindowsManager* WM);
    ~VLCHolderWnd();

protected:
    VLCHolderWnd(HINSTANCE hInstance, VLCWindowsManager* WM)
        : VLCWnd(hInstance), _hMouseHook(NULL), _MouseHookThreadId(0),
158
        _wm(WM), _hBgBrush(0), _CtrlsWnd(0), _oldMouseCoords() {}
159 160 161 162 163 164
    bool Create(HWND hWndParent);

    virtual void PreRegisterWindowClass(WNDCLASS* wc);
    virtual LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);

public:
165 166
    void DestroyWindow();

167 168 169 170
    VLCControlsWnd* ControlWindow()
    {
        return _CtrlsWnd;
    }
171

172
private:
173
    static LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam);
174

175 176
    HWND FindMP_hWnd();

177
    HHOOK _hMouseHook;
178
    DWORD _MouseHookThreadId;
179
    void MouseHook(bool SetHook);
180

181 182
    VLCWindowsManager& WM()
        {return *_wm;}
183
    inline vlc_player* VP() const;
184
    inline const VLCViewResources& RC() const;
185
    inline const vlc_player_options* PO() const;
186 187

private:
188
    VLCWindowsManager* _wm;
189
    HBRUSH _hBgBrush;
190
    VLCControlsWnd*    _CtrlsWnd;
191
    POINTS _oldMouseCoords;
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
};

///////////////////////
//VLCFullScreenWnd
///////////////////////
class VLCFullScreenWnd
{
public:
    static void RegisterWndClassName(HINSTANCE hInstance);
    static void UnRegisterWndClassName();
    static VLCFullScreenWnd* CreateFSWindow(VLCWindowsManager* WM);
    void DestroyWindow()
        {::DestroyWindow(_hWnd);};

private:
    static LPCTSTR getClassName(void) { return TEXT("VLC ActiveX Fullscreen Class"); };
    static LRESULT CALLBACK FSWndWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
    static HINSTANCE _hinstance;
    static ATOM _fullscreen_wndclass_atom;

private:
    VLCFullScreenWnd(HWND hWnd, VLCWindowsManager* WM)
216
        :_WindowsManager(WM), _hWnd(hWnd) {};
217

218
    ~VLCFullScreenWnd(){};
219 220

private:
221 222
     VLCWindowsManager& WM()
        {return *_WindowsManager;}
223
    inline vlc_player* VP() const;
224
    inline const VLCViewResources& RC() const;
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

private:
    VLCWindowsManager* _WindowsManager;

public:
    HWND getHWND() const {return _hWnd;}

private:
    HWND _hWnd;
};

///////////////////////
//VLCWindowsManager
///////////////////////
class VLCWindowsManager
{
public:
242
    VLCWindowsManager(HMODULE hModule, const VLCViewResources& rc,
243
                    vlc_player* player, const vlc_player_options* = 0);
244
    ~VLCWindowsManager();
245 246
    VLCWindowsManager(const VLCWindowsManager&) = delete;
    VLCWindowsManager& operator=(const VLCWindowsManager&) = delete;
247 248 249 250 251 252 253 254 255 256 257 258

    void CreateWindows(HWND hWindowedParentWnd);
    void DestroyWindows();

    void StartFullScreen();
    void EndFullScreen();
    void ToggleFullScreen();
    bool IsFullScreen();

    HMODULE getHModule() const {return _hModule;};
    VLCHolderWnd* getHolderWnd() const {return _HolderWnd;}
    VLCFullScreenWnd* getFullScreenWnd() const {return _FSWnd;}
259
    vlc_player* VP() const {return _vp;}
260
    const VLCViewResources& RC() const {return _rc;}
261
    const vlc_player_options* PO() const {return _po;}
262 263 264 265 266 267

public:
    void setNewMessageFlag(bool Yes)
        {_b_new_messages_flag = Yes;};
    bool getNewMessageFlag() const
        {return _b_new_messages_flag;};
268
public:
269
    void OnKeyDownEvent(UINT uKeyMsg);
270
    void OnMouseEvent(UINT uMouseMsg);
271 272

private:
273
    const VLCViewResources& _rc;
274
    HMODULE _hModule;
275 276
    const vlc_player_options *const _po;

277 278
    HWND _hWindowedParentWnd;

279
    vlc_player* _vp;
280

281 282 283 284
    VLCHolderWnd* _HolderWnd;
    VLCFullScreenWnd* _FSWnd;

    bool _b_new_messages_flag;
285 286 287

private:
    DWORD Last_WM_MOUSEMOVE_Pos;
288 289
};

290 291 292
////////////////////////////
//inlines
////////////////////////////
293
inline vlc_player* VLCControlsWnd::VP() const
294
{
295
    return _wm->VP();
296 297 298 299 300 301 302
}

inline const VLCViewResources& VLCControlsWnd::RC()
{
    return _wm->RC();
}

303 304 305 306 307
inline const vlc_player_options* VLCControlsWnd::PO() const
{
    return _wm->PO();
}

308
inline vlc_player* VLCHolderWnd::VP() const
309
{
310
    return _wm->VP();
311 312 313 314
}

inline const VLCViewResources& VLCHolderWnd::RC() const
{
315 316 317 318 319 320
    return _wm->RC();
}

inline const vlc_player_options* VLCHolderWnd::PO() const
{
    return _wm->PO();
321 322
}

323
inline vlc_player* VLCFullScreenWnd::VP() const
324
{
325
    return _WindowsManager->VP();
326 327 328 329 330 331 332
}

inline const VLCViewResources& VLCFullScreenWnd::RC() const
{
    return _WindowsManager->RC();
}

333 334 335
#endif //_WIN32

#endif //VLC_FULLSCREEN_H