win32_fullscreen.h 9 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

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);
112
    void RegisterToVLCEvents();
113 114 115 116 117

    void NeedHideControls();

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

private:
    VLCWindowsManager* _wm;

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

    void CreateToolTip();

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

    int VideoPosShiftBits;
};

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

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

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

public:
166 167
    void DestroyWindow();

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

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

176 177
    HWND FindMP_hWnd();

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

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

private:
    static HINSTANCE _hinstance;
    static ATOM _holder_wndclass_atom;

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

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

224
    ~VLCFullScreenWnd(){};
225 226

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

private:
233
    void NeedHideControls();
234 235

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

private:
    VLCWindowsManager* _WindowsManager;

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

private:
    HWND _hWnd;

    int VideoPosShiftBits;
};

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

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

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

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

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

295 296
    HWND _hWindowedParentWnd;

297
    vlc_player* _vp;
298

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

    bool _b_new_messages_flag;
303 304 305

private:
    DWORD Last_WM_MOUSEMOVE_Pos;
306 307
};

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

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

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

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

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

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

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

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

351 352 353
#endif //_WIN32

#endif //VLC_FULLSCREEN_H