]> git.sesse.net Git - vlc/blob - modules/gui/wince/subtitles.cpp
* modules/gui/wince/*: New Windows CE interface by Cedric Marodon <cedric_marodon...
[vlc] / modules / gui / wince / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30 #include <string.h>
31
32 #include <stdlib.h>                                      /* malloc(), free() */
33 #include <string>
34 #include <stdio.h>
35 using namespace std;
36
37 #include <winuser.h>
38 #include <windows.h>
39 #include <windowsx.h>
40 #include <commctrl.h>
41 #include <aygshell.h>
42
43 #include <commdlg.h>
44
45 #include "wince.h"
46
47 /*****************************************************************************
48  * Event Table.
49  *****************************************************************************/
50
51 /*****************************************************************************
52  * Constructor.
53  *****************************************************************************/
54 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
55 {
56     /* Initializations */
57     p_intf = _p_intf;
58     hInst = _hInst;
59 }
60
61 /***********************************************************************
62
63 FUNCTION: 
64   WndProc
65
66 PURPOSE: 
67   Processes messages sent to the main window.
68   
69 ***********************************************************************/
70 LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
71                                  PBOOL pbProcessed  )
72 {
73     SHINITDLGINFO shidi;
74     SHMENUBARINFO mbi;
75     INITCOMMONCONTROLSEX ic;
76     RECT rcClient;
77
78     int size;
79     LPWSTR wUnicode;
80
81     char *psz_subsfile;
82
83     float f_fps;
84     int i_delay;
85     module_config_t *p_item;
86
87     LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
88     BOOL bWasProcessed = *pbProcessed;
89     *pbProcessed = TRUE;
90
91     switch( msg )
92     {
93     case WM_INITDIALOG:
94         shidi.dwMask = SHIDIM_FLAGS;
95         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
96         shidi.hDlg = hwnd;
97         SHInitDialog( &shidi );
98
99         //Create the menubar.
100         memset (&mbi, 0, sizeof (SHMENUBARINFO));
101         mbi.cbSize     = sizeof (SHMENUBARINFO);
102         mbi.hwndParent = hwnd;
103         mbi.nToolBarId = IDR_DUMMYMENU;
104         mbi.hInstRes   = hInst;
105         mbi.nBmpId     = 0;
106         mbi.cBmpImages = 0;
107
108         if (!SHCreateMenuBar(&mbi))
109         {
110             MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
111             //return -1;
112         }
113
114         hwndCB = mbi.hwndMB;
115
116         // Get the client area rect to put the panels in
117         GetClientRect(hwnd, &rcClient);
118
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 );
124
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 );
130
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 );
135
136         free( wUnicode );
137         if( psz_subsfile ) free( psz_subsfile );
138
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);
143
144         /* Subtitles encoding */
145         encoding_combo = NULL;
146         p_item =
147             config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
148         if( p_item )
149          {
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 );
154
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 );
158
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 );
163
164              free( wUnicode );
165
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 );
169
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 );
174
175              free( wUnicode );
176
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++ )
180              {
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 );
184
185                  ComboBox_AddString( encoding_combo, wUnicode );
186
187                  free( wUnicode );
188
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 );
192              }
193
194              if( p_item->psz_value )
195              {
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 );
199
200                  ComboBox_SelectString( encoding_combo, 0, wUnicode );
201
202                  free( wUnicode );
203              }
204          }
205
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 );
211
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 );
216
217         i_delay = config_GetInt( p_intf, "sub-delay" );
218         wUnicode = new WCHAR[80];
219         swprintf( wUnicode, _T("%d"), i_delay );
220
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);
225
226         free( wUnicode );
227
228         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
229         ic.dwICC = ICC_UPDOWN_CLASS;
230         InitCommonControlsEx(&ic);
231
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 );
236
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 );
241
242         f_fps = config_GetFloat( p_intf, "sub-fps" );
243         wUnicode = new WCHAR[80];
244         swprintf( wUnicode, _T("%d"), (int)f_fps );
245
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);
250
251         free( wUnicode );
252
253         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
254         ic.dwICC = ICC_UPDOWN_CLASS;
255         InitCommonControlsEx(&ic);
256
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 );
261
262         return lResult;
263
264     case WM_COMMAND:
265         if ( LOWORD(wp) == IDOK )
266         {
267             int size;
268             BOOL bTemp;
269             LPSTR szAnsi;
270             LPWSTR wUnicode;
271
272             subsfile_mrl.clear();
273
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 );
284
285             if( GetWindowTextLength( encoding_combo ) != 0 )
286             {
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 );
297             }
298
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 );
306             szDelay += szAnsi;
307             free( wUnicode ); free( szAnsi );
308             subsfile_mrl.push_back( szDelay );
309
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 );
317             szFps += szAnsi;
318             free( wUnicode ); free( szAnsi );
319             subsfile_mrl.push_back( szFps );
320
321             EndDialog( hwnd, LOWORD( wp ) );
322             return TRUE;
323         }
324         if( HIWORD(wp) == BN_CLICKED )
325         {
326             if ((HWND)lp == browse_button)
327             {
328                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
329                 OnFileBrowse();
330                 return TRUE;
331             } 
332         }
333
334         *pbProcessed = bWasProcessed;
335         lResult = FALSE;
336         return lResult;
337
338     default:
339         // the message was not processed
340         // indicate if the base class handled it
341         *pbProcessed = bWasProcessed;
342         lResult = FALSE;
343         return lResult;
344     }
345
346     return lResult;
347 }
348
349 /*****************************************************************************
350  * Private methods.
351  *****************************************************************************/
352
353 /*****************************************************************************
354  * Events methods.
355  *****************************************************************************/
356 void SubsFileDialog::OnFileBrowse()
357 {
358     OPENFILENAME ofn;
359     TCHAR DateiName[80+1] = _T("\0");
360     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
361
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;
371     ofn.nMaxFile = 80;
372     ofn.lpstrFileTitle = NULL;
373     ofn.nMaxFileTitle = 40;
374     ofn.lpstrInitialDir = NULL;
375     ofn.lpstrTitle = _T("Open File");
376     ofn.Flags = NULL;
377     ofn.nFileOffset = 0;
378     ofn.nFileExtension = 0;
379     ofn.lpstrDefExt = NULL;
380     ofn.lCustData = 0L;
381     ofn.lpfnHook = NULL;
382     ofn.lpTemplateName = NULL;
383     if( GetOpenFileName((LPOPENFILENAME) &ofn) )
384     {
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 );
389     }
390 }