]> git.sesse.net Git - vlc/blob - modules/gui/wince/subtitles.cpp
* modules/gui/wince: WinCE build fixes.
[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 <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33
34 #include "wince.h"
35
36 #include <winuser.h>
37 #include <windows.h>
38 #include <windowsx.h>
39 #include <commctrl.h>
40 #include <commdlg.h>
41
42 /*****************************************************************************
43  * Event Table.
44  *****************************************************************************/
45
46 /*****************************************************************************
47  * Constructor.
48  *****************************************************************************/
49 SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
50 {
51     /* Initializations */
52     p_intf = _p_intf;
53     hInst = _hInst;
54 }
55
56 /***********************************************************************
57
58 FUNCTION: 
59   WndProc
60
61 PURPOSE: 
62   Processes messages sent to the main window.
63   
64 ***********************************************************************/
65 LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
66                                  PBOOL pbProcessed  )
67 {
68     SHINITDLGINFO shidi;
69     SHMENUBARINFO mbi;
70     INITCOMMONCONTROLSEX ic;
71     RECT rcClient;
72
73     int size;
74     LPWSTR wUnicode;
75
76     char *psz_subsfile;
77
78     float f_fps;
79     int i_delay;
80     module_config_t *p_item;
81
82     LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
83     BOOL bWasProcessed = *pbProcessed;
84     *pbProcessed = TRUE;
85
86     switch( msg )
87     {
88     case WM_INITDIALOG:
89         shidi.dwMask = SHIDIM_FLAGS;
90         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
91         shidi.hDlg = hwnd;
92         SHInitDialog( &shidi );
93
94         //Create the menubar.
95         memset (&mbi, 0, sizeof (SHMENUBARINFO));
96         mbi.cbSize     = sizeof (SHMENUBARINFO);
97         mbi.hwndParent = hwnd;
98         mbi.nToolBarId = IDR_DUMMYMENU;
99         mbi.hInstRes   = hInst;
100         mbi.nBmpId     = 0;
101         mbi.cBmpImages = 0;
102
103         if (!SHCreateMenuBar(&mbi))
104         {
105             MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
106             //return -1;
107         }
108
109         hwndCB = mbi.hwndMB;
110
111         // Get the client area rect to put the panels in
112         GetClientRect(hwnd, &rcClient);
113
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 );
119
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 );
125
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 );
130
131         free( wUnicode );
132         if( psz_subsfile ) free( psz_subsfile );
133
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);
138
139         /* Subtitles encoding */
140         encoding_combo = NULL;
141         p_item =
142             config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
143         if( p_item )
144          {
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 );
149
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 );
153
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 );
158
159              free( wUnicode );
160
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 );
164
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 );
169
170              free( wUnicode );
171
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++ )
175              {
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 );
179
180                  ComboBox_AddString( encoding_combo, wUnicode );
181
182                  free( wUnicode );
183
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 );
187              }
188
189              if( p_item->psz_value )
190              {
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 );
194
195                  ComboBox_SelectString( encoding_combo, 0, wUnicode );
196
197                  free( wUnicode );
198              }
199          }
200
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 );
206
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 );
211
212         i_delay = config_GetInt( p_intf, "sub-delay" );
213         wUnicode = new WCHAR[80];
214         swprintf( wUnicode, _T("%d"), i_delay );
215
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);
220
221         free( wUnicode );
222
223         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
224         ic.dwICC = ICC_UPDOWN_CLASS;
225         InitCommonControlsEx(&ic);
226
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 );
231
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 );
236
237         f_fps = config_GetFloat( p_intf, "sub-fps" );
238         wUnicode = new WCHAR[80];
239         swprintf( wUnicode, _T("%d"), (int)f_fps );
240
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);
245
246         free( wUnicode );
247
248         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
249         ic.dwICC = ICC_UPDOWN_CLASS;
250         InitCommonControlsEx(&ic);
251
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 );
256
257         return lResult;
258
259     case WM_COMMAND:
260         if ( LOWORD(wp) == IDOK )
261         {
262             int size;
263             BOOL bTemp;
264             LPSTR szAnsi;
265             LPWSTR wUnicode;
266
267             subsfile_mrl.clear();
268
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 );
279
280             if( GetWindowTextLength( encoding_combo ) != 0 )
281             {
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 );
292             }
293
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 );
301             szDelay += szAnsi;
302             free( wUnicode ); free( szAnsi );
303             subsfile_mrl.push_back( szDelay );
304
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 );
312             szFps += szAnsi;
313             free( wUnicode ); free( szAnsi );
314             subsfile_mrl.push_back( szFps );
315
316             EndDialog( hwnd, LOWORD( wp ) );
317             return TRUE;
318         }
319         if( HIWORD(wp) == BN_CLICKED )
320         {
321             if ((HWND)lp == browse_button)
322             {
323                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
324                 OnFileBrowse();
325                 return TRUE;
326             } 
327         }
328
329         *pbProcessed = bWasProcessed;
330         lResult = FALSE;
331         return lResult;
332
333     default:
334         // the message was not processed
335         // indicate if the base class handled it
336         *pbProcessed = bWasProcessed;
337         lResult = FALSE;
338         return lResult;
339     }
340
341     return lResult;
342 }
343
344 /*****************************************************************************
345  * Private methods.
346  *****************************************************************************/
347
348 /*****************************************************************************
349  * Events methods.
350  *****************************************************************************/
351 void SubsFileDialog::OnFileBrowse()
352 {
353     OPENFILENAME ofn;
354     TCHAR DateiName[80+1] = _T("\0");
355     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
356
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;
366     ofn.nMaxFile = 80;
367     ofn.lpstrFileTitle = NULL;
368     ofn.nMaxFileTitle = 40;
369     ofn.lpstrInitialDir = NULL;
370     ofn.lpstrTitle = _T("Open File");
371     ofn.Flags = NULL;
372     ofn.nFileOffset = 0;
373     ofn.nFileExtension = 0;
374     ofn.lpstrDefExt = NULL;
375     ofn.lCustData = 0L;
376     ofn.lpfnHook = NULL;
377     ofn.lpTemplateName = NULL;
378     if( GetOpenFileName((LPOPENFILENAME) &ofn) )
379     {
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 );
384     }
385 }