win32_fullscreen.h 9.36 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
struct VLCViewResources
{
    VLCViewResources()
36
        :hNewMessageBitmap(0), hFullscreenBitmap(0), hDeFullscreenBitmap(0), hPauseBitmap(0),
37 38 39
         hPlayBitmap(0), hVolumeBitmap(0), hVolumeMutedBitmap(0),
         hBackgroundIcon(0)
    {};
Sergey Radionov's avatar
Sergey Radionov committed
40 41 42 43 44 45 46 47 48 49 50
    ~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 );
    }
51 52 53 54 55 56 57 58 59 60 61

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

62 63 64 65 66 67 68 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
////////////////////////////////////////////////////////////////////////////////
//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();

    //libvlc events arrives from separate thread
    void OnLibVlcEvent(const libvlc_event_t* event);

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

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

    void SyncVolumeSliderWithVLCVolume();
    void SetVLCVolumeBySliderPos(int CurScrollPos);
    void SetVideoPosScrollPosByVideoPos(libvlc_time_t CurScrollPos);
    void UpdateButtons();

    void NeedHideControls();

    void handle_position_changed_event(const libvlc_event_t* event);
    void handle_input_state_event(const libvlc_event_t* event);

    bool IsPlaying()
    {
116 117
        if( VP() )
            return VP()->is_playing();
118 119 120 121 122 123 124 125
        return false;
    }

private:
    VLCWindowsManager* _wm;

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

    void CreateToolTip();

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

    int VideoPosShiftBits;
};

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

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

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

public:
164 165
    void DestroyWindow();

166
    void LibVlcAttach();
167
    void LibVlcDetach();
168

169 170 171
    void NeedShowControls()
        { if(_CtrlsWnd) _CtrlsWnd->NeedShowControls(); }

172 173 174
    //libvlc events arrives from separate thread
    void OnLibVlcEvent(const libvlc_event_t* event);

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

178 179
    HWND FindMP_hWnd();

180
    HHOOK _hMouseHook;
181
    DWORD _MouseHookThreadId;
182
    void MouseHook(bool SetHook);
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 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
public:
233
    //libvlc events arrives from separate thread
234
    void OnLibVlcEvent(const libvlc_event_t* ) {};
235 236

private:
237
    void NeedHideControls();
238 239

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

private:
    VLCWindowsManager* _WindowsManager;

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

private:
    HWND _hWnd;

    int VideoPosShiftBits;
};

///////////////////////
//VLCWindowsManager
///////////////////////
class VLCWindowsManager
{
public:
260 261
    VLCWindowsManager(HMODULE hModule, const VLCViewResources& rc,
                      const vlc_player_options* = 0);
262 263 264 265 266
    ~VLCWindowsManager();

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

267
    void LibVlcAttach(vlc_player*);
268 269 270 271 272 273 274 275 276 277
    void LibVlcDetach();

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

    HMODULE getHModule() const {return _hModule;};
    VLCHolderWnd* getHolderWnd() const {return _HolderWnd;}
    VLCFullScreenWnd* getFullScreenWnd() const {return _FSWnd;}
278
    vlc_player* VP() const {return _vp;}
279
    const VLCViewResources& RC() const {return _rc;}
280
    const vlc_player_options* PO() const {return _po;}
281 282 283 284 285 286

public:
    void setNewMessageFlag(bool Yes)
        {_b_new_messages_flag = Yes;};
    bool getNewMessageFlag() const
        {return _b_new_messages_flag;};
287 288
public:
    void OnMouseEvent(UINT uMouseMsg);
289

290 291 292 293 294 295
private:
    void VlcEvents(bool Attach);
    //libvlc events arrives from separate thread
    static void OnLibVlcEvent_proxy(const libvlc_event_t* event, void *param);
    void OnLibVlcEvent(const libvlc_event_t* event);

296
private:
297
    const VLCViewResources& _rc;
298
    HMODULE _hModule;
299 300
    const vlc_player_options *const _po;

301 302
    HWND _hWindowedParentWnd;

303
    vlc_player* _vp;
304

305 306 307 308
    VLCHolderWnd* _HolderWnd;
    VLCFullScreenWnd* _FSWnd;

    bool _b_new_messages_flag;
309 310 311

private:
    DWORD Last_WM_MOUSEMOVE_Pos;
312 313
};

314 315 316
////////////////////////////
//inlines
////////////////////////////
317
inline vlc_player* VLCControlsWnd::VP() const
318
{
319
    return _wm->VP();
320 321 322 323 324 325 326
}

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

327 328 329 330 331
inline const vlc_player_options* VLCControlsWnd::PO() const
{
    return _wm->PO();
}

332
inline vlc_player* VLCHolderWnd::VP() const
333
{
334
    return _wm->VP();
335 336 337 338
}

inline const VLCViewResources& VLCHolderWnd::RC() const
{
339 340 341 342 343 344
    return _wm->RC();
}

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

347
inline vlc_player* VLCFullScreenWnd::VP() const
348
{
349
    return _WindowsManager->VP();
350 351 352 353 354 355 356
}

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

357 358 359
#endif //_WIN32

#endif //VLC_FULLSCREEN_H