]> git.sesse.net Git - vlc/blob - modules/gui/wince/video.cpp
c918ab96ac459bb25639581a77bbb8a86922243f
[vlc] / modules / gui / wince / video.cpp
1 /*****************************************************************************
2  * video.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2004, 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc_vout.h>
30 #include <vlc_interface.h>
31
32 #include "wince.h"
33
34 static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *,
35                         int *pi_x_hint, int *pi_y_hint,
36                         unsigned int *pi_width_hint,
37                         unsigned int *pi_height_hint );
38 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window );
39
40 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
41                           int i_query, va_list args );
42
43 /* IDs for the controls and the menu commands */
44 enum
45 {
46     UpdateSize_Event = 1000 + 1,
47     UpdateHide_Event
48 };
49
50 /* Video Window */
51 class VideoWindow : public CBaseWindow
52 {
53 public:
54     /* Constructor */
55     VideoWindow( intf_thread_t *_p_intf, HWND _p_parent );
56     virtual ~VideoWindow();
57
58     void *GetWindow( vout_thread_t *, int *, int *, unsigned int *,
59                      unsigned int * );
60     void ReleaseWindow( void * );
61     int  ControlWindow( void *, int, va_list );
62         
63     HWND p_child_window; // public because of menu
64
65 private:
66     intf_thread_t *p_intf;
67     vout_thread_t *p_vout;
68     HWND p_parent;
69     vlc_mutex_t lock;
70
71     virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
72 };
73
74 /*****************************************************************************
75  * Public methods.
76  *****************************************************************************/
77 CBaseWindow *CreateVideoWindow( intf_thread_t *p_intf, HWND p_parent )
78 {
79     return new VideoWindow( p_intf, p_parent );
80 }
81
82 /*****************************************************************************
83  * Constructor.
84  *****************************************************************************/
85 VideoWindow::VideoWindow( intf_thread_t *_p_intf, HWND _p_parent )
86 {
87     RECT rect;
88     WNDCLASS wc;
89
90     /* Initializations */
91     p_intf = _p_intf;
92     p_parent = _p_parent;
93     p_child_window = NULL;
94
95     vlc_mutex_init( p_intf, &lock );
96
97     p_vout = NULL;
98
99     p_intf->pf_request_window = ::GetWindow;
100     p_intf->pf_release_window = ::ReleaseWindow;
101     p_intf->pf_control_window = ::ControlWindow;
102
103     p_intf->p_sys->p_video_window = this;
104
105     GetClientRect( p_parent, &rect );
106
107     wc.style = CS_HREDRAW | CS_VREDRAW ;
108     wc.lpfnWndProc = (WNDPROC)BaseWndProc;
109     wc.cbClsExtra = 0;
110     wc.cbWndExtra = 0;
111     wc.hIcon = NULL;
112     wc.hInstance = GetModuleHandle(0);
113     wc.hCursor = NULL;
114     wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
115     wc.lpszMenuName = NULL;
116     wc.lpszClassName = _T("VIDEOWINDOW");
117     RegisterClass( &wc );
118
119     p_child_window = CreateWindow (
120         _T("VIDEOWINDOW"), _T(""),
121         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_BORDER,
122         0, 20, rect.right - rect.left,
123         rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT - 20,
124         p_parent, NULL, GetModuleHandle(0), (void *)this );
125
126     ShowWindow( p_child_window, SW_SHOW );
127     UpdateWindow( p_child_window );
128
129     ReleaseWindow( (void*)p_child_window );
130 }
131
132 VideoWindow::~VideoWindow()
133 {
134     vlc_mutex_destroy( &lock );
135 }
136
137 /*****************************************************************************
138  * Private methods.
139  *****************************************************************************/
140 static void *GetWindow( intf_thread_t *p_intf,  vout_thread_t *p_vout,
141                         int *pi_x_hint, int *pi_y_hint,
142                         unsigned int *pi_width_hint,
143                         unsigned int *pi_height_hint )
144 {
145     return p_intf->p_sys->p_video_window->GetWindow( p_vout, pi_x_hint,
146                                     pi_y_hint, pi_width_hint, pi_height_hint );
147 }
148
149 void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
150                               int *pi_x_hint, int *pi_y_hint,
151                               unsigned int *pi_width_hint,
152                               unsigned int *pi_height_hint )
153 {
154     vlc_mutex_lock( &lock );
155
156     if( p_vout )
157     {
158         vlc_mutex_unlock( &lock );
159         msg_Dbg( p_intf, "Video window already in use" );
160         return NULL;
161     }
162
163     p_vout = _p_vout;
164
165     vlc_mutex_unlock( &lock );
166
167     ShowWindow( (HWND)p_child_window, SW_SHOW );
168     return p_child_window;
169 }
170
171 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
172 {
173     p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
174 }
175
176 void VideoWindow::ReleaseWindow( void *p_window )
177 {
178     vlc_mutex_lock( &lock );
179     p_vout = NULL;
180     vlc_mutex_unlock( &lock );
181
182     ShowWindow( (HWND)p_window, SW_HIDE );
183     SetForegroundWindow( p_parent );
184 }
185
186 /***********************************************************************
187
188 FUNCTION:
189   WndProc
190
191 PURPOSE: 
192   Processes messages sent to the main window.
193
194 ***********************************************************************/
195 LRESULT VideoWindow::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
196 {
197     switch( msg )
198     {
199     case WM_KILLFOCUS:
200         if( p_vout )
201             vout_Control( p_vout, VOUT_SET_FOCUS, (vlc_bool_t)VLC_FALSE );
202         return TRUE;
203
204     case WM_SETFOCUS:
205         if( p_vout )
206             vout_Control( p_vout, VOUT_SET_FOCUS, (vlc_bool_t)VLC_TRUE );
207         return TRUE;
208
209     default:
210         return DefWindowProc( hwnd, msg, wp, lp );
211     }
212
213 }
214
215 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
216                           int i_query, va_list args )
217 {
218     return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
219                                                          args );
220 }
221
222 int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
223 {
224     int i_ret = VLC_EGENERIC;
225
226     vlc_mutex_lock( &lock );
227
228     switch( i_query )
229     {
230     case VOUT_SET_STAY_ON_TOP:
231         break;
232
233     default:
234         msg_Dbg( p_intf, "control query not supported" );
235         break;
236     }
237
238     vlc_mutex_unlock( &lock );
239
240     return i_ret;
241 }