WinCE: update the interface module
[vlc.git] / 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     // Changeset 138da19...
104     //p_intf->pf_request_window = ::GetWindow;
105     //p_intf->pf_release_window = ::ReleaseWindow;
106     //p_intf->pf_control_window = ::ControlWindow;
107
108     p_intf->p_sys->p_video_window = this;
109
110     GetClientRect( p_parent, &rect );
111
112     wc.style = CS_HREDRAW | CS_VREDRAW ;
113     wc.lpfnWndProc = (WNDPROC)BaseWndProc;
114     wc.cbClsExtra = 0;
115     wc.cbWndExtra = 0;
116     wc.hIcon = NULL;
117     wc.hInstance = GetModuleHandle(0);
118     wc.hCursor = NULL;
119     wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
120     wc.lpszMenuName = NULL;
121     wc.lpszClassName = _T("VIDEOWINDOW");
122     RegisterClass( &wc );
123
124     p_child_window = CreateWindow (
125         _T("VIDEOWINDOW"), _T(""),
126         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_BORDER,
127         0, 20, rect.right - rect.left,
128         rect.bottom - rect.top - 2*(MENU_HEIGHT-1) - SLIDER_HEIGHT - 20,
129         p_parent, NULL, GetModuleHandle(0), (void *)this );
130
131     ShowWindow( p_child_window, SW_SHOW );
132     UpdateWindow( p_child_window );
133
134     ReleaseWindow( (void*)p_child_window );
135 }
136
137 VideoWindow::~VideoWindow()
138 {
139     vlc_mutex_destroy( &lock );
140 }
141
142 /*****************************************************************************
143  * Private methods.
144  *****************************************************************************/
145 static void *GetWindow( intf_thread_t *p_intf,  vout_thread_t *p_vout,
146                         int *pi_x_hint, int *pi_y_hint,
147                         unsigned int *pi_width_hint,
148                         unsigned int *pi_height_hint )
149 {
150     return p_intf->p_sys->p_video_window->GetWindow( p_vout, pi_x_hint,
151                                     pi_y_hint, pi_width_hint, pi_height_hint );
152 }
153
154 void *VideoWindow::GetWindow( vout_thread_t *_p_vout,
155                               int *pi_x_hint, int *pi_y_hint,
156                               unsigned int *pi_width_hint,
157                               unsigned int *pi_height_hint )
158 {
159     vlc_mutex_lock( &lock );
160
161     if( p_vout )
162     {
163         vlc_mutex_unlock( &lock );
164         msg_Dbg( p_intf, "Video window already in use" );
165         return NULL;
166     }
167
168     p_vout = _p_vout;
169
170     vlc_mutex_unlock( &lock );
171
172     ShowWindow( (HWND)p_child_window, SW_SHOW );
173     return p_child_window;
174 }
175
176 static void ReleaseWindow( intf_thread_t *p_intf, void *p_window )
177 {
178     p_intf->p_sys->p_video_window->ReleaseWindow( p_window );
179 }
180
181 void VideoWindow::ReleaseWindow( void *p_window )
182 {
183     vlc_mutex_lock( &lock );
184     p_vout = NULL;
185     vlc_mutex_unlock( &lock );
186
187     ShowWindow( (HWND)p_window, SW_HIDE );
188     SetForegroundWindow( p_parent );
189 }
190
191 /***********************************************************************
192
193 FUNCTION:
194   WndProc
195
196 PURPOSE:
197   Processes messages sent to the main window.
198
199 ***********************************************************************/
200 LRESULT VideoWindow::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
201 {
202     switch( msg )
203     {
204     case WM_KILLFOCUS:
205         if( p_vout )
206             vout_Control( p_vout, VOUT_SET_FOCUS, (bool)false );
207         return TRUE;
208
209     case WM_SETFOCUS:
210         if( p_vout )
211             vout_Control( p_vout, VOUT_SET_FOCUS, (bool)true );
212         return TRUE;
213
214     default:
215         return DefWindowProc( hwnd, msg, wp, lp );
216     }
217
218 }
219
220 static int ControlWindow( intf_thread_t *p_intf, void *p_window,
221                           int i_query, va_list args )
222 {
223     return p_intf->p_sys->p_video_window->ControlWindow( p_window, i_query,
224                                                          args );
225 }
226
227 int VideoWindow::ControlWindow( void *p_window, int i_query, va_list args )
228 {
229     int i_ret = VLC_EGENERIC;
230
231     vlc_mutex_lock( &lock );
232
233     switch( i_query )
234     {
235     case VOUT_SET_STAY_ON_TOP:
236         break;
237
238     default:
239         msg_Dbg( p_intf, "control query not supported" );
240         break;
241     }
242
243     vlc_mutex_unlock( &lock );
244
245     return i_ret;
246 }