win32_fullscreen.h 9.07 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 36 37 38 39
enum{
    WM_MOUSE_EVENT_NOTIFY = WM_APP + 1,
    WM_MOUSE_EVENT_REPOST,
    WM_MOUSE_EVENT_NOTIFY_SUCCESS = 0xFF
};


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

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

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
////////////////////////////////////////////////////////////////////////////////
//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();

99

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

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

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

    void SyncVolumeSliderWithVLCVolume();
    void SetVLCVolumeBySliderPos(int CurScrollPos);
    void SetVideoPosScrollPosByVideoPos(libvlc_time_t CurScrollPos);
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 143 144

    void CreateToolTip();

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

    int VideoPosShiftBits;
};

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

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

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

public:
167 168
    void DestroyWindow();

169 170 171 172
    VLCControlsWnd* ControlWindow()
    {
        return _CtrlsWnd;
    }
173

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

177 178
    HWND FindMP_hWnd();

179
    HHOOK _hMouseHook;
180
    DWORD _MouseHookThreadId;
181
    void MouseHook(bool SetHook);
182
    void TrackMouse();
183

184 185
    VLCWindowsManager& WM()
        {return *_wm;}
186
    inline vlc_player* VP() const;
187
    inline const VLCViewResources& RC() const;
188
    inline const vlc_player_options* PO() const;
189 190 191 192 193 194

private:
    static HINSTANCE _hinstance;
    static ATOM _holder_wndclass_atom;

private:
195
    VLCWindowsManager* _wm;
196
    HBRUSH _hBgBrush;
197
    VLCControlsWnd*    _CtrlsWnd;
198
    POINTS _oldMouseCoords;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
};

///////////////////////
//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)
223
        :_WindowsManager(WM), _hWnd(hWnd) {};
224

225
    ~VLCFullScreenWnd(){};
226 227

private:
228 229
     VLCWindowsManager& WM()
        {return *_WindowsManager;}
230
    inline vlc_player* VP() const;
231
    inline const VLCViewResources& RC() const;
232 233

private:
234
    void NeedHideControls();
235 236

private:
237
    void CreateToolTip();
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

private:
    VLCWindowsManager* _WindowsManager;

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

private:
    HWND _hWnd;

    int VideoPosShiftBits;
};

///////////////////////
//VLCWindowsManager
///////////////////////
class VLCWindowsManager
{
public:
257
    VLCWindowsManager(HMODULE hModule, const VLCViewResources& rc,
258
                    vlc_player* player, const vlc_player_options* = 0);
259
    ~VLCWindowsManager();
260 261
    VLCWindowsManager(const VLCWindowsManager&) = delete;
    VLCWindowsManager& operator=(const VLCWindowsManager&) = delete;
262 263 264 265 266 267 268 269 270 271 272 273

    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;}
274
    vlc_player* VP() const {return _vp;}
275
    const VLCViewResources& RC() const {return _rc;}
276
    const vlc_player_options* PO() const {return _po;}
277 278 279 280 281 282

public:
    void setNewMessageFlag(bool Yes)
        {_b_new_messages_flag = Yes;};
    bool getNewMessageFlag() const
        {return _b_new_messages_flag;};
283
public:
284
    void OnKeyDownEvent(UINT uKeyMsg);
285
    void OnMouseEvent(UINT uMouseMsg);
286

287 288 289 290
private:
    //libvlc events arrives from separate thread
    void OnLibVlcEvent(const libvlc_event_t* event);

291
private:
292
    const VLCViewResources& _rc;
293
    HMODULE _hModule;
294 295
    const vlc_player_options *const _po;

296 297
    HWND _hWindowedParentWnd;

298
    vlc_player* _vp;
299

300 301 302 303
    VLCHolderWnd* _HolderWnd;
    VLCFullScreenWnd* _FSWnd;

    bool _b_new_messages_flag;
304 305 306

private:
    DWORD Last_WM_MOUSEMOVE_Pos;
307 308
};

309 310 311
////////////////////////////
//inlines
////////////////////////////
312
inline vlc_player* VLCControlsWnd::VP() const
313
{
314
    return _wm->VP();
315 316 317 318 319 320 321
}

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

322 323 324 325 326
inline const vlc_player_options* VLCControlsWnd::PO() const
{
    return _wm->PO();
}

327
inline vlc_player* VLCHolderWnd::VP() const
328
{
329
    return _wm->VP();
330 331 332 333
}

inline const VLCViewResources& VLCHolderWnd::RC() const
{
334 335 336 337 338 339
    return _wm->RC();
}

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

342
inline vlc_player* VLCFullScreenWnd::VP() const
343
{
344
    return _WindowsManager->VP();
345 346 347 348 349 350 351
}

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

352 353 354
#endif //_WIN32

#endif //VLC_FULLSCREEN_H