]> git.sesse.net Git - vlc/blob - modules/gui/wince/subtitles.cpp
* modules/gui/wince: some more code cleanup + 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 {
67     SHINITDLGINFO shidi;
68     SHMENUBARINFO mbi;
69     INITCOMMONCONTROLSEX ic;
70     RECT rcClient;
71
72     char *psz_subsfile;
73     module_config_t *p_item;
74     float f_fps;
75     int i_delay;
76
77     TCHAR psz_text[256];
78
79     switch( msg )
80     {
81     case WM_INITDIALOG:
82         shidi.dwMask = SHIDIM_FLAGS;
83         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
84         shidi.hDlg = hwnd;
85         SHInitDialog( &shidi );
86
87         //Create the menubar.
88         memset (&mbi, 0, sizeof (SHMENUBARINFO));
89         mbi.cbSize     = sizeof (SHMENUBARINFO);
90         mbi.hwndParent = hwnd;
91         mbi.nToolBarId = IDR_DUMMYMENU;
92         mbi.hInstRes   = hInst;
93         mbi.nBmpId     = 0;
94         mbi.cBmpImages = 0;
95
96         if (!SHCreateMenuBar(&mbi))
97         {
98             MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
99             //return -1;
100         }
101
102         hwndCB = mbi.hwndMB;
103
104         // Get the client area rect to put the panels in
105         GetClientRect(hwnd, &rcClient);
106
107         /* Create the subtitles file textctrl */
108         file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
109                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
110                                  5, 10, rcClient.right - 2*5, 15,
111                                  hwnd, NULL, hInst, NULL );
112
113         psz_subsfile = config_GetPsz( p_intf, "sub-file" );
114         if( !psz_subsfile ) psz_subsfile = strdup("");
115
116         file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
117             WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
118             10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
119             hwnd, NULL, hInst, NULL );
120
121         if( psz_subsfile ) free( psz_subsfile );
122
123         browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
124                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
125                         10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
126                         hwnd, NULL, hInst, NULL);
127
128         /* Subtitles encoding */
129         encoding_combo = NULL;
130         p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
131         if( p_item )
132         {
133             enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
134                         WS_CHILD | WS_VISIBLE | SS_LEFT,
135                         5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
136                         hwnd, NULL, hInst, NULL );
137
138             enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
139                 WS_CHILD | WS_VISIBLE | SS_LEFT,
140                 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
141                 hwnd, NULL, hInst, NULL );
142
143             encoding_combo = CreateWindow( _T("COMBOBOX"),
144                 _FROMMB(p_item->psz_value),
145                 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
146                 LBS_SORT  | WS_VSCROLL,
147                 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
148                 hwnd, NULL, hInst, NULL );
149
150             /* build a list of available options */
151             for( int i_index = 0; p_item->ppsz_list &&
152                    p_item->ppsz_list[i_index]; i_index++ )
153             {
154                 ComboBox_AddString( encoding_combo,
155                                     _FROMMB(p_item->ppsz_list[i_index]) );
156
157                 if( p_item->psz_value &&
158                     !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
159                     ComboBox_SetCurSel( encoding_combo, i_index );
160             }
161
162             if( p_item->psz_value )
163             {
164                 ComboBox_SelectString( encoding_combo, 0,
165                                        _FROMMB(p_item->psz_value) );
166
167             }
168         }
169
170         /* Misc Subtitles options */
171         misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
172                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
173                                  5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
174                                  hwnd, NULL, hInst, NULL );
175
176         delay_label = CreateWindow( _T("STATIC"),
177                                     _T("Delay subtitles (in 1/10s)"),
178                                     WS_CHILD | WS_VISIBLE | SS_LEFT,
179                                     10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
180                                     hwnd, NULL, hInst, NULL );
181
182         i_delay = config_GetInt( p_intf, "sub-delay" );
183         _stprintf( psz_text, _T("%d"), i_delay );
184
185         delay_edit = CreateWindow( _T("EDIT"), psz_text,
186             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
187             rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
188             hwnd, NULL, hInst, NULL );
189
190         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
191         ic.dwICC = ICC_UPDOWN_CLASS;
192         InitCommonControlsEx(&ic);
193
194         delay_spinctrl =
195             CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
196                 UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
197                 0, 0, 0, 0, hwnd, 0, hInst,
198                 delay_edit, 650000, -650000, i_delay );
199
200         fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
201                         WS_CHILD | WS_VISIBLE | SS_LEFT,
202                         10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
203                         hwnd, NULL, hInst, NULL );
204
205         f_fps = config_GetFloat( p_intf, "sub-fps" );
206         _stprintf( psz_text, _T("%f"), f_fps );
207
208         fps_edit = CreateWindow( _T("EDIT"), psz_text,
209             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
210             rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
211             hwnd, NULL, hInst, NULL);
212
213         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
214         ic.dwICC = ICC_UPDOWN_CLASS;
215         InitCommonControlsEx(&ic);
216
217         fps_spinctrl = CreateUpDownControl(
218             WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
219             UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
220             0, 0, 0, 0, hwnd, 0, hInst, fps_edit, 16000, 0, (int)f_fps );
221
222         break;
223
224     case WM_CLOSE:
225         EndDialog( hwnd, LOWORD( wp ) );
226         break;
227
228     case WM_COMMAND:
229         if ( LOWORD(wp) == IDOK )
230         {
231             subsfile_mrl.clear();
232
233             string szFileCombo = "sub-file=";
234             GetWindowText( file_combo, psz_text, 256 );
235             szFileCombo += _TOMB(psz_text);
236             subsfile_mrl.push_back( szFileCombo );
237
238             if( GetWindowTextLength( encoding_combo ) != 0 )
239             {
240                 string szEncoding = "subsdec-encoding=";
241                 GetWindowText( encoding_combo, psz_text, 256 );
242                 szEncoding += _TOMB(psz_text);
243                 subsfile_mrl.push_back( szEncoding );
244             }
245
246             string szDelay = "sub-delay=";
247             Edit_GetText( delay_edit, psz_text, 256 );
248             szDelay += _TOMB(psz_text);
249             subsfile_mrl.push_back( szDelay );
250
251             string szFps = "sub-fps=";
252             Edit_GetText( fps_edit, psz_text, 256 );
253             szFps += _TOMB(psz_text);
254             subsfile_mrl.push_back( szFps );
255
256             EndDialog( hwnd, LOWORD( wp ) );
257             break;
258         }
259         if( HIWORD(wp) == BN_CLICKED )
260         {
261             if ((HWND)lp == browse_button)
262             {
263                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
264                 OnFileBrowse();
265             } 
266         }
267         break;
268
269     default:
270         break;
271     }
272
273     return FALSE;
274 }
275
276 /*****************************************************************************
277  * Private methods.
278  *****************************************************************************/
279
280 /*****************************************************************************
281  * Events methods.
282  *****************************************************************************/
283 void SubsFileDialog::OnFileBrowse()
284 {
285     OPENFILENAME ofn;
286     TCHAR DateiName[80+1] = _T("\0");
287     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
288
289     memset(&ofn, 0, sizeof(OPENFILENAME));
290     ofn.lStructSize = sizeof (OPENFILENAME);
291     ofn.hwndOwner = NULL;
292     ofn.hInstance = hInst;
293     ofn.lpstrFilter = szFilter;
294     ofn.lpstrCustomFilter = NULL;
295     ofn.nMaxCustFilter = 0;
296     ofn.nFilterIndex = 1;
297     ofn.lpstrFile = (LPTSTR) DateiName;
298     ofn.nMaxFile = 80;
299     ofn.lpstrFileTitle = NULL;
300     ofn.nMaxFileTitle = 40;
301     ofn.lpstrInitialDir = NULL;
302     ofn.lpstrTitle = _T("Open File");
303     ofn.Flags = 0;
304     ofn.nFileOffset = 0;
305     ofn.nFileExtension = 0;
306     ofn.lpstrDefExt = NULL;
307     ofn.lCustData = 0L;
308     ofn.lpfnHook = NULL;
309     ofn.lpTemplateName = NULL;
310     if( GetOpenFileName((LPOPENFILENAME) &ofn) )
311     {
312         SetWindowText( file_combo, ofn.lpstrFile );
313         ComboBox_AddString( file_combo, ofn.lpstrFile );
314         if( ComboBox_GetCount( file_combo ) > 10 )
315             ComboBox_DeleteString( file_combo, 0 );
316     }
317 }