video.cpp 7 KB
Newer Older
1 2 3
/*****************************************************************************
 * video.cpp : WinCE gui plugin for VLC
 *****************************************************************************
4
 * Copyright (C) 2000-2004, 2003 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * $Id$
 *
 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
 *          Gildas Bazin <gbazin@videolan.org>
 *
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <vlc/vlc.h>
Clément Stenac's avatar
Clément Stenac committed
33 34
#include <vlc_vout.h>
#include <vlc_interface.h>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

#include "wince.h"

static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *,
                        int *pi_x_hint, int *pi_y_hint,
                        unsigned int *pi_width_hint,
                        unsigned int *pi_height_hint );
static void ReleaseWindow( intf_thread_t *p_intf, void *p_window );

static int ControlWindow( intf_thread_t *p_intf, void *p_window,
                          int i_query, va_list args );

/* IDs for the controls and the menu commands */
enum
{
    UpdateSize_Event = 1000 + 1,
    UpdateHide_Event
};

/* Video Window */
class VideoWindow : public CBaseWindow
{
public:
    /* Constructor */
59
    VideoWindow( intf_thread_t *_p_intf, HWND _p_parent );
60 61 62 63 64 65
    virtual ~VideoWindow();

    void *GetWindow( vout_thread_t *, int *, int *, unsigned int *,
                     unsigned int * );
    void ReleaseWindow( void * );
    int  ControlWindow( void *, int, va_list );
66
 
67 68 69 70 71 72 73 74
    HWND p_child_window; // public because of menu

private:
    intf_thread_t *p_intf;
    vout_thread_t *p_vout;
    HWND p_parent;
    vlc_mutex_t lock;

75
    virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
76 77 78 79 80
};

/*****************************************************************************
 * Public methods.
 *****************************************************************************/
81
CBaseWindow *CreateVideoWindow( intf_thread_t *p_intf, HWND p_parent )
82
{
83
    return new VideoWindow( p_intf, p_parent );
84 85 86 87 88
}

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
89
VideoWindow::VideoWindow( intf_thread_t *_p_intf, HWND _p_parent )
90 91 92 93 94 95 96 97 98
{
    RECT rect;
    WNDCLASS wc;

    /* Initializations */
    p_intf = _p_intf;
    p_parent = _p_parent;
    p_child_window = NULL;

99
    vlc_mutex_init( &lock );
100 101 102 103 104

    p_vout = NULL;

    p_intf->pf_request_window = ::GetWindow;
    p_intf->pf_release_window = ::ReleaseWindow;
105
    p_intf->pf_control_window = ::ControlWindow;
106 107 108 109 110 111 112 113 114 115

    p_intf->p_sys->p_video_window = this;

    GetClientRect( p_parent, &rect );

    wc.style = CS_HREDRAW | CS_VREDRAW ;
    wc.lpfnWndProc = (WNDPROC)BaseWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = NULL;
116
    wc.hInstance = GetModuleHandle(0);
117 118 119 120 121 122 123
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = _T("VIDEOWINDOW");
    RegisterClass( &wc );

    p_child_window = CreateWindow (
124 125
        _T("VIDEOWINDOW"), _T(""),
        WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_BORDER,
126 127
        0, 20, rect.right - rect.left,
        rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT - 20,
128
        p_parent, NULL, GetModuleHandle(0), (void *)this );
129

130
    ShowWindow( p_child_window, SW_SHOW );
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    UpdateWindow( p_child_window );

    ReleaseWindow( (void*)p_child_window );
}

VideoWindow::~VideoWindow()
{
    vlc_mutex_destroy( &lock );
}

/*****************************************************************************
 * Private methods.
 *****************************************************************************/
static void *GetWindow( intf_thread_t *p_intf,  vout_thread_t *p_vout,
                        int *pi_x_hint, int *pi_y_hint,
                        unsigned int *pi_width_hint,
                        unsigned int *pi_height_hint )
{
    return p_intf->p_sys->p_video_window->GetWindow( p_vout, pi_x_hint,
                                    pi_y_hint, pi_width_hint, pi_height_hint );
}

void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
                              int *pi_x_hint, int *pi_y_hint,
                              unsigned int *pi_width_hint,
                              unsigned int *pi_height_hint )
{
    vlc_mutex_lock( &lock );

    if( p_vout )
    {
        vlc_mutex_unlock( &lock );
        msg_Dbg( p_intf, "Video window already in use" );
        return NULL;
    }

    p_vout = _p_vout;

    vlc_mutex_unlock( &lock );

171
    ShowWindow( (HWND)p_child_window, SW_SHOW );
172 173 174 175 176 177 178 179 180 181 182 183 184
    return p_child_window;
}

static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
{
    p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
}

void VideoWindow::ReleaseWindow( void *p_window )
{
    vlc_mutex_lock( &lock );
    p_vout = NULL;
    vlc_mutex_unlock( &lock );
185 186 187

    ShowWindow( (HWND)p_window, SW_HIDE );
    SetForegroundWindow( p_parent );
188 189 190 191 192 193 194
}

/***********************************************************************

FUNCTION:
  WndProc

195
PURPOSE:
196 197 198
  Processes messages sent to the main window.

***********************************************************************/
199
LRESULT VideoWindow::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
200
{
201 202 203 204
    switch( msg )
    {
    case WM_KILLFOCUS:
        if( p_vout )
205
            vout_Control( p_vout, VOUT_SET_FOCUS, (bool)false );
206 207 208 209
        return TRUE;

    case WM_SETFOCUS:
        if( p_vout )
210
            vout_Control( p_vout, VOUT_SET_FOCUS, (bool)true );
211 212 213 214 215 216
        return TRUE;

    default:
        return DefWindowProc( hwnd, msg, wp, lp );
    }

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
}

static int ControlWindow( intf_thread_t *p_intf, void *p_window,
                          int i_query, va_list args )
{
    return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
                                                         args );
}

int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
{
    int i_ret = VLC_EGENERIC;

    vlc_mutex_lock( &lock );

    switch( i_query )
    {
234
    case VOUT_SET_STAY_ON_TOP:
235 236
        break;

237 238 239
    default:
        msg_Dbg( p_intf, "control query not supported" );
        break;
240 241 242 243 244 245
    }

    vlc_mutex_unlock( &lock );

    return i_ret;
}