1 /*****************************************************************************
2 * subtitles.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* strerror() */
42 /*****************************************************************************
44 *****************************************************************************/
46 /*****************************************************************************
48 *****************************************************************************/
49 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
56 /***********************************************************************
62 Processes messages sent to the main window.
64 ***********************************************************************/
65 LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
70 INITCOMMONCONTROLSEX ic;
80 module_config_t *p_item;
82 LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
83 BOOL bWasProcessed = *pbProcessed;
89 shidi.dwMask = SHIDIM_FLAGS;
90 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
92 SHInitDialog( &shidi );
95 memset (&mbi, 0, sizeof (SHMENUBARINFO));
96 mbi.cbSize = sizeof (SHMENUBARINFO);
97 mbi.hwndParent = hwnd;
98 mbi.nToolBarId = IDR_DUMMYMENU;
103 if (!SHCreateMenuBar(&mbi))
105 MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
111 // Get the client area rect to put the panels in
112 GetClientRect(hwnd, &rcClient);
114 /* Create the subtitles file textctrl */
115 file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
116 WS_CHILD | WS_VISIBLE | SS_LEFT,
117 5, 10, rcClient.right - 2*5, 15,
118 hwnd, NULL, hInst, NULL );
120 psz_subsfile = config_GetPsz( p_intf, "sub-file" );
121 if( !psz_subsfile ) psz_subsfile = strdup("");
122 size = MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, NULL, 0 );
123 wUnicode = new WCHAR[size];
124 MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, wUnicode, size );
126 file_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
127 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
128 10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
129 hwnd, NULL, hInst, NULL );
132 if( psz_subsfile ) free( psz_subsfile );
134 browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
135 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
136 10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
137 hwnd, NULL, hInst, NULL);
139 /* Subtitles encoding */
140 encoding_combo = NULL;
142 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
145 enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
146 WS_CHILD | WS_VISIBLE | SS_LEFT,
147 5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
148 hwnd, NULL, hInst, NULL );
150 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, NULL, 0 );
151 wUnicode = new WCHAR[size];
152 MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, wUnicode, size );
154 enc_label = CreateWindow( _T("STATIC"), wUnicode,
155 WS_CHILD | WS_VISIBLE | SS_LEFT,
156 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
157 hwnd, NULL, hInst, NULL );
161 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
162 wUnicode = new WCHAR[size];
163 MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
165 encoding_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
166 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST | LBS_SORT | WS_VSCROLL,
167 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
168 hwnd, NULL, hInst, NULL );
172 /* build a list of available options */
173 for( int i_index = 0; p_item->ppsz_list &&
174 p_item->ppsz_list[i_index]; i_index++ )
176 size = MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, NULL, 0 );
177 wUnicode = new WCHAR[size];
178 MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, wUnicode, size );
180 ComboBox_AddString( encoding_combo, wUnicode );
184 if( p_item->psz_value && !strcmp( p_item->psz_value,
185 p_item->ppsz_list[i_index] ) )
186 ComboBox_SetCurSel( encoding_combo, i_index );
189 if( p_item->psz_value )
191 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
192 wUnicode = new WCHAR[size];
193 MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
195 ComboBox_SelectString( encoding_combo, 0, wUnicode );
201 /* Misc Subtitles options */
202 misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
203 WS_CHILD | WS_VISIBLE | SS_LEFT,
204 5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
205 hwnd, NULL, hInst, NULL );
207 delay_label = CreateWindow( _T("STATIC"), _T("Delay subtitles (in 1/10s)"),
208 WS_CHILD | WS_VISIBLE | SS_LEFT,
209 10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
210 hwnd, NULL, hInst, NULL );
212 i_delay = config_GetInt( p_intf, "sub-delay" );
213 wUnicode = new WCHAR[80];
214 swprintf( wUnicode, _T("%d"), i_delay );
216 delay_edit = CreateWindow( _T("EDIT"), wUnicode,
217 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
218 rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
219 hwnd, NULL, hInst, NULL);
223 ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
224 ic.dwICC = ICC_UPDOWN_CLASS;
225 InitCommonControlsEx(&ic);
227 delay_spinctrl = CreateUpDownControl(
228 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
229 0, 0, 0, 0, hwnd, NULL, hInst,
230 delay_edit, 650000, -650000, i_delay );
232 fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
233 WS_CHILD | WS_VISIBLE | SS_LEFT,
234 10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
235 hwnd, NULL, hInst, NULL );
237 f_fps = config_GetFloat( p_intf, "sub-fps" );
238 wUnicode = new WCHAR[80];
239 swprintf( wUnicode, _T("%d"), (int)f_fps );
241 fps_edit = CreateWindow( _T("EDIT"), wUnicode,
242 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
243 rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
244 hwnd, NULL, hInst, NULL);
248 ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
249 ic.dwICC = ICC_UPDOWN_CLASS;
250 InitCommonControlsEx(&ic);
252 fps_spinctrl = CreateUpDownControl(
253 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
254 0, 0, 0, 0, hwnd, NULL, hInst,
255 fps_edit, 16000, 0, (int)f_fps );
260 if ( LOWORD(wp) == IDOK )
267 subsfile_mrl.clear();
269 string szFileCombo = "sub-file=";
270 size = GetWindowTextLength( file_combo ) + 1;
271 wUnicode = new WCHAR[ size ];
272 GetWindowText( file_combo, wUnicode, size );
273 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
274 szAnsi = new char[size];
275 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
276 szFileCombo += szAnsi;
277 free( wUnicode ); free( szAnsi );
278 subsfile_mrl.push_back( szFileCombo );
280 if( GetWindowTextLength( encoding_combo ) != 0 )
282 string szEncoding = "subsdec-encoding=";
283 size = GetWindowTextLength( encoding_combo ) + 1;
284 wUnicode = new WCHAR[ size ];
285 GetWindowText( encoding_combo, wUnicode, size );
286 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
287 szAnsi = new char[size];
288 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
289 szEncoding += szAnsi;
290 free( wUnicode ); free( szAnsi );
291 subsfile_mrl.push_back( szEncoding );
294 string szDelay = "sub-delay=";
295 size = Edit_GetTextLength( delay_edit );
296 wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
297 Edit_GetText( delay_edit, wUnicode, size + 1);
298 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
299 szAnsi = new char[size];
300 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
302 free( wUnicode ); free( szAnsi );
303 subsfile_mrl.push_back( szDelay );
305 string szFps = "sub-fps=";
306 size = Edit_GetTextLength( fps_edit );
307 wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
308 Edit_GetText( fps_edit, wUnicode, size + 1);
309 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
310 szAnsi = new char[size];
311 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
313 free( wUnicode ); free( szAnsi );
314 subsfile_mrl.push_back( szFps );
316 EndDialog( hwnd, LOWORD( wp ) );
319 if( HIWORD(wp) == BN_CLICKED )
321 if ((HWND)lp == browse_button)
323 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
329 *pbProcessed = bWasProcessed;
334 // the message was not processed
335 // indicate if the base class handled it
336 *pbProcessed = bWasProcessed;
344 /*****************************************************************************
346 *****************************************************************************/
348 /*****************************************************************************
350 *****************************************************************************/
351 void SubsFileDialog::OnFileBrowse()
354 TCHAR DateiName[80+1] = _T("\0");
355 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
357 memset(&ofn, 0, sizeof(OPENFILENAME));
358 ofn.lStructSize = sizeof (OPENFILENAME);
359 ofn.hwndOwner = NULL;
360 ofn.hInstance = hInst;
361 ofn.lpstrFilter = szFilter;
362 ofn.lpstrCustomFilter = NULL;
363 ofn.nMaxCustFilter = 0;
364 ofn.nFilterIndex = 1;
365 ofn.lpstrFile = (LPTSTR) DateiName;
367 ofn.lpstrFileTitle = NULL;
368 ofn.nMaxFileTitle = 40;
369 ofn.lpstrInitialDir = NULL;
370 ofn.lpstrTitle = _T("Open File");
373 ofn.nFileExtension = 0;
374 ofn.lpstrDefExt = NULL;
377 ofn.lpTemplateName = NULL;
378 if( GetOpenFileName((LPOPENFILENAME) &ofn) )
380 SetWindowText( file_combo, ofn.lpstrFile );
381 ComboBox_AddString( file_combo, ofn.lpstrFile );
382 if( ComboBox_GetCount( file_combo ) > 10 )
383 ComboBox_DeleteString( file_combo, 0 );