]> git.sesse.net Git - vlc/blob - modules/gui/wince/video.cpp
Plugins: include vlc_common.h directly instead of vlc/vlc.h
[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 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_vout.h>
34 #include <vlc_interface.h>
35
36 #include "wince.h"
37
38 static void *GetWindow( intf_thread_t *p_intf, vout_thread_t *,
39                         int *pi_x_hint, int *pi_y_hint,
40                         unsigned int *pi_width_hint,
41                         unsigned int *pi_height_hint );
42 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window );
43
44 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
45                           int i_query, va_list args );
46
47 /* IDs for the controls and the menu commands */
48 enum
49 {
50     UpdateSize_Event = 1000 + 1,
51     UpdateHide_Event
52 };
53
54 /* Video Window */
55 class VideoWindow : public CBaseWindow
56 {
57 public:
58     /* Constructor */
59     VideoWindow( intf_thread_t *_p_intf, HWND _p_parent );
60     virtual ~VideoWindow();
61
62     void *GetWindow( vout_thread_t *, int *, int *, unsigned int *,
63                      unsigned int * );
64     void ReleaseWindow( void * );
65     int  ControlWindow( void *, int, va_list );
66  
67     HWND p_child_window; // public because of menu
68
69 private:
70     intf_thread_t *p_intf;
71     vout_thread_t *p_vout;
72     HWND p_parent;
73     vlc_mutex_t lock;
74
75     virtual LRESULT WndProc( HWND, UINT, WPARAM, LPARAM );
76 };
77
78 /*****************************************************************************
79  * Public methods.
80  *****************************************************************************/
81 CBaseWindow *CreateVideoWindow( intf_thread_t *p_intf, HWND p_parent )
82 {
83     return new VideoWindow( p_intf, p_parent );
84 }
85
86 /*****************************************************************************
87  * Constructor.
88  *****************************************************************************/
89 VideoWindow::VideoWindow( intf_thread_t *_p_intf, HWND _p_parent )
90 {
91     RECT rect;
92     WNDCLASS wc;
93
94     /* Initializations */
95     p_intf = _p_intf;
96     p_parent = _p_parent;
97     p_child_window = NULL;
98
99     vlc_mutex_init( &lock );
100
101     p_vout = NULL;
102
103     p_intf->pf_request_window = ::GetWindow;
104     p_intf->pf_release_window = ::ReleaseWindow;
105     p_intf->pf_control_window = ::ControlWindow;
106
107     p_intf->p_sys->p_video_window = this;
108
109     GetClientRect( p_parent, &rect );
110
111     wc.style = CS_HREDRAW | CS_VREDRAW ;
112     wc.lpfnWndProc = (WNDPROC)BaseWndProc;
113     wc.cbClsExtra = 0;
114     wc.cbWndExtra = 0;
115     wc.hIcon = NULL;
116     wc.hInstance = GetModuleHandle(0);
117     wc.hCursor = NULL;
118     wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
119     wc.lpszMenuName = NULL;
120     wc.lpszClassName = _T("VIDEOWINDOW");
121     RegisterClass( &wc );
122
123     p_child_window = CreateWindow (
124         _T("VIDEOWINDOW"), _T(""),
125         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_BORDER,
126         0, 20, rect.right - rect.left,
127         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     UpdateWindow( p_child_window );
132
133     ReleaseWindow( (void*)p_child_window );
134 }
135
136 VideoWindow::~VideoWindow()
137 {
138     vlc_mutex_destroy( &lock );
139 }
140
141 /*****************************************************************************
142  * Private methods.
143  *****************************************************************************/
144 static void *GetWindow( intf_thread_t *p_intf,  vout_thread_t *p_vout,
145                         int *pi_x_hint, int *pi_y_hint,
146                         unsigned int *pi_width_hint,
147                         unsigned int *pi_height_hint )
148 {
149     return p_intf->p_sys->p_video_window->GetWindow( p_vout, pi_x_hint,
150                                     pi_y_hint, pi_width_hint, pi_height_hint );
151 }
152
153 void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
154                               int *pi_x_hint, int *pi_y_hint,
155                               unsigned int *pi_width_hint,
156                               unsigned int *pi_height_hint )
157 {
158     vlc_mutex_lock( &lock );
159
160     if( p_vout )
161     {
162         vlc_mutex_unlock( &lock );
163         msg_Dbg( p_intf, "Video window already in use" );
164         return NULL;
165     }
166
167     p_vout = _p_vout;
168
169     vlc_mutex_unlock( &lock );
170
171     ShowWindow( (HWND)p_child_window, SW_SHOW );
172     return p_child_window;
173 }
174
175 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
176 {
177     p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
178 }
179
180 void VideoWindow::ReleaseWindow( void *p_window )
181 {
182     vlc_mutex_lock( &lock );
183     p_vout = NULL;
184     vlc_mutex_unlock( &lock );
185
186     ShowWindow( (HWND)p_window, SW_HIDE );
187     SetForegroundWindow( p_parent );
188 }
189
190 /***********************************************************************
191
192 FUNCTION:
193   WndProc
194
195 PURPOSE:
196   Processes messages sent to the main window.
197
198 ***********************************************************************/
199 LRESULT VideoWindow::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
200 {
201     switch( msg )
202     {
203     case WM_KILLFOCUS:
204         if( p_vout )
205             vout_Control( p_vout, VOUT_SET_FOCUS, (bool)false );
206         return TRUE;
207
208     case WM_SETFOCUS:
209         if( p_vout )
210             vout_Control( p_vout, VOUT_SET_FOCUS, (bool)true );
211         return TRUE;
212
213     default:
214         return DefWindowProc( hwnd, msg, wp, lp );
215     }
216
217 }
218
219 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
220                           int i_query, va_list args )
221 {
222     return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
223                                                          args );
224 }
225
226 int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
227 {
228     int i_ret = VLC_EGENERIC;
229
230     vlc_mutex_lock( &lock );
231
232     switch( i_query )
233     {
234     case VOUT_SET_STAY_ON_TOP:
235         break;
236
237     default:
238         msg_Dbg( p_intf, "control query not supported" );
239         break;
240     }
241
242     vlc_mutex_unlock( &lock );
243
244     return i_ret;
245 }