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 *****************************************************************************/
32 #include <stdlib.h> /* malloc(), free() */
47 /*****************************************************************************
49 *****************************************************************************/
51 /*****************************************************************************
53 *****************************************************************************/
54 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
61 /***********************************************************************
67 Processes messages sent to the main window.
69 ***********************************************************************/
70 LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
75 INITCOMMONCONTROLSEX ic;
85 module_config_t *p_item;
87 LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
88 BOOL bWasProcessed = *pbProcessed;
94 shidi.dwMask = SHIDIM_FLAGS;
95 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
97 SHInitDialog( &shidi );
100 memset (&mbi, 0, sizeof (SHMENUBARINFO));
101 mbi.cbSize = sizeof (SHMENUBARINFO);
102 mbi.hwndParent = hwnd;
103 mbi.nToolBarId = IDR_DUMMYMENU;
104 mbi.hInstRes = hInst;
108 if (!SHCreateMenuBar(&mbi))
110 MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
116 // Get the client area rect to put the panels in
117 GetClientRect(hwnd, &rcClient);
119 /* Create the subtitles file textctrl */
120 file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
121 WS_CHILD | WS_VISIBLE | SS_LEFT,
122 5, 10, rcClient.right - 2*5, 15,
123 hwnd, NULL, hInst, NULL );
125 psz_subsfile = config_GetPsz( p_intf, "sub-file" );
126 if( !psz_subsfile ) psz_subsfile = strdup("");
127 size = MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, NULL, 0 );
128 wUnicode = new WCHAR[size];
129 MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, wUnicode, size );
131 file_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
132 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
133 10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
134 hwnd, NULL, hInst, NULL );
137 if( psz_subsfile ) free( psz_subsfile );
139 browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
140 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
141 10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
142 hwnd, NULL, hInst, NULL);
144 /* Subtitles encoding */
145 encoding_combo = NULL;
147 config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
150 enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
151 WS_CHILD | WS_VISIBLE | SS_LEFT,
152 5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
153 hwnd, NULL, hInst, NULL );
155 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, NULL, 0 );
156 wUnicode = new WCHAR[size];
157 MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, wUnicode, size );
159 enc_label = CreateWindow( _T("STATIC"), wUnicode,
160 WS_CHILD | WS_VISIBLE | SS_LEFT,
161 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
162 hwnd, NULL, hInst, NULL );
166 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
167 wUnicode = new WCHAR[size];
168 MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
170 encoding_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
171 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST | LBS_SORT | WS_VSCROLL,
172 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
173 hwnd, NULL, hInst, NULL );
177 /* build a list of available options */
178 for( int i_index = 0; p_item->ppsz_list &&
179 p_item->ppsz_list[i_index]; i_index++ )
181 size = MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, NULL, 0 );
182 wUnicode = new WCHAR[size];
183 MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, wUnicode, size );
185 ComboBox_AddString( encoding_combo, wUnicode );
189 if( p_item->psz_value && !strcmp( p_item->psz_value,
190 p_item->ppsz_list[i_index] ) )
191 ComboBox_SetCurSel( encoding_combo, i_index );
194 if( p_item->psz_value )
196 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
197 wUnicode = new WCHAR[size];
198 MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
200 ComboBox_SelectString( encoding_combo, 0, wUnicode );
206 /* Misc Subtitles options */
207 misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
208 WS_CHILD | WS_VISIBLE | SS_LEFT,
209 5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
210 hwnd, NULL, hInst, NULL );
212 delay_label = CreateWindow( _T("STATIC"), _T("Delay subtitles (in 1/10s)"),
213 WS_CHILD | WS_VISIBLE | SS_LEFT,
214 10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
215 hwnd, NULL, hInst, NULL );
217 i_delay = config_GetInt( p_intf, "sub-delay" );
218 wUnicode = new WCHAR[80];
219 swprintf( wUnicode, _T("%d"), i_delay );
221 delay_edit = CreateWindow( _T("EDIT"), wUnicode,
222 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
223 rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
224 hwnd, NULL, hInst, NULL);
228 ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
229 ic.dwICC = ICC_UPDOWN_CLASS;
230 InitCommonControlsEx(&ic);
232 delay_spinctrl = CreateUpDownControl(
233 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
234 0, 0, 0, 0, hwnd, NULL, hInst,
235 delay_edit, 650000, -650000, i_delay );
237 fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
238 WS_CHILD | WS_VISIBLE | SS_LEFT,
239 10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
240 hwnd, NULL, hInst, NULL );
242 f_fps = config_GetFloat( p_intf, "sub-fps" );
243 wUnicode = new WCHAR[80];
244 swprintf( wUnicode, _T("%d"), (int)f_fps );
246 fps_edit = CreateWindow( _T("EDIT"), wUnicode,
247 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
248 rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
249 hwnd, NULL, hInst, NULL);
253 ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
254 ic.dwICC = ICC_UPDOWN_CLASS;
255 InitCommonControlsEx(&ic);
257 fps_spinctrl = CreateUpDownControl(
258 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
259 0, 0, 0, 0, hwnd, NULL, hInst,
260 fps_edit, 16000, 0, (int)f_fps );
265 if ( LOWORD(wp) == IDOK )
272 subsfile_mrl.clear();
274 string szFileCombo = "sub-file=";
275 size = GetWindowTextLength( file_combo ) + 1;
276 wUnicode = new WCHAR[ size ];
277 GetWindowText( file_combo, wUnicode, size );
278 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
279 szAnsi = new char[size];
280 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
281 szFileCombo += szAnsi;
282 free( wUnicode ); free( szAnsi );
283 subsfile_mrl.push_back( szFileCombo );
285 if( GetWindowTextLength( encoding_combo ) != 0 )
287 string szEncoding = "subsdec-encoding=";
288 size = GetWindowTextLength( encoding_combo ) + 1;
289 wUnicode = new WCHAR[ size ];
290 GetWindowText( encoding_combo, wUnicode, size );
291 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
292 szAnsi = new char[size];
293 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
294 szEncoding += szAnsi;
295 free( wUnicode ); free( szAnsi );
296 subsfile_mrl.push_back( szEncoding );
299 string szDelay = "sub-delay=";
300 size = Edit_GetTextLength( delay_edit );
301 wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
302 Edit_GetText( delay_edit, wUnicode, size + 1);
303 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
304 szAnsi = new char[size];
305 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
307 free( wUnicode ); free( szAnsi );
308 subsfile_mrl.push_back( szDelay );
310 string szFps = "sub-fps=";
311 size = Edit_GetTextLength( fps_edit );
312 wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
313 Edit_GetText( fps_edit, wUnicode, size + 1);
314 size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
315 szAnsi = new char[size];
316 WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
318 free( wUnicode ); free( szAnsi );
319 subsfile_mrl.push_back( szFps );
321 EndDialog( hwnd, LOWORD( wp ) );
324 if( HIWORD(wp) == BN_CLICKED )
326 if ((HWND)lp == browse_button)
328 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
334 *pbProcessed = bWasProcessed;
339 // the message was not processed
340 // indicate if the base class handled it
341 *pbProcessed = bWasProcessed;
349 /*****************************************************************************
351 *****************************************************************************/
353 /*****************************************************************************
355 *****************************************************************************/
356 void SubsFileDialog::OnFileBrowse()
359 TCHAR DateiName[80+1] = _T("\0");
360 static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
362 memset(&ofn, 0, sizeof(OPENFILENAME));
363 ofn.lStructSize = sizeof (OPENFILENAME);
364 ofn.hwndOwner = NULL;
365 ofn.hInstance = hInst;
366 ofn.lpstrFilter = szFilter;
367 ofn.lpstrCustomFilter = NULL;
368 ofn.nMaxCustFilter = 0;
369 ofn.nFilterIndex = 1;
370 ofn.lpstrFile = (LPTSTR) DateiName;
372 ofn.lpstrFileTitle = NULL;
373 ofn.nMaxFileTitle = 40;
374 ofn.lpstrInitialDir = NULL;
375 ofn.lpstrTitle = _T("Open File");
378 ofn.nFileExtension = 0;
379 ofn.lpstrDefExt = NULL;
382 ofn.lpTemplateName = NULL;
383 if( GetOpenFileName((LPOPENFILENAME) &ofn) )
385 SetWindowText( file_combo, ofn.lpstrFile );
386 ComboBox_AddString( file_combo, ofn.lpstrFile );
387 if( ComboBox_GetCount( file_combo ) > 10 )
388 ComboBox_DeleteString( file_combo, 0 );