]> git.sesse.net Git - vlc/blob - modules/gui/wince/subtitles.cpp
One more time removing of some useless tests.
[vlc] / modules / gui / wince / subtitles.cpp
1 /*****************************************************************************
2  * subtitles.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2001 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc_interface.h>
34
35 #include "wince.h"
36
37 #include <winuser.h>
38 #include <windows.h>
39 #include <windowsx.h>
40 #include <commctrl.h>
41 #include <commdlg.h>
42
43 /*****************************************************************************
44  * Event Table.
45  *****************************************************************************/
46
47 /*****************************************************************************
48  * Constructor.
49  *****************************************************************************/
50 SubsFileDialog::SubsFileDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
51                                 HINSTANCE h_inst )
52   :  CBaseWindow( p_intf, p_parent, h_inst )
53 {
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.dwFlags    = SHCMBF_EMPTYBAR;
92         mbi.hInstRes   = hInst;
93
94         if (!SHCreateMenuBar(&mbi))
95         {
96             MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
97             //return -1;
98         }
99
100         hwndCB = mbi.hwndMB;
101
102         // Get the client area rect to put the panels in
103         GetClientRect(hwnd, &rcClient);
104
105         /* Create the subtitles file textctrl */
106         file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
107                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
108                                  5, 10, rcClient.right - 2*5, 15,
109                                  hwnd, NULL, hInst, NULL );
110
111         psz_subsfile = config_GetPsz( p_intf, "sub-file" );
112         if( !psz_subsfile ) psz_subsfile = strdup("");
113
114         file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
115             WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
116             10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
117             hwnd, NULL, hInst, NULL );
118
119         free( psz_subsfile );
120
121         browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
122                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
123                         10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
124                         hwnd, NULL, hInst, NULL);
125
126         /* Subtitles encoding */
127         encoding_combo = NULL;
128         p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
129         if( p_item )
130         {
131             enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
132                         WS_CHILD | WS_VISIBLE | SS_LEFT,
133                         5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
134                         hwnd, NULL, hInst, NULL );
135
136             enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
137                 WS_CHILD | WS_VISIBLE | SS_LEFT,
138                 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
139                 hwnd, NULL, hInst, NULL );
140
141             encoding_combo = CreateWindow( _T("COMBOBOX"),
142                 _FROMMB(p_item->psz_value),
143                 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
144                 LBS_SORT  | WS_VSCROLL,
145                 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
146                 hwnd, NULL, hInst, NULL );
147
148             /* build a list of available options */
149             for( int i_index = 0; p_item->ppsz_list &&
150                    p_item->ppsz_list[i_index]; i_index++ )
151             {
152                 ComboBox_AddString( encoding_combo,
153                                     _FROMMB(p_item->ppsz_list[i_index]) );
154
155                 if( p_item->psz_value &&
156                     !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
157                     ComboBox_SetCurSel( encoding_combo, i_index );
158             }
159
160             if( p_item->psz_value )
161             {
162                 ComboBox_SelectString( encoding_combo, 0,
163                                        _FROMMB(p_item->psz_value) );
164
165             }
166         }
167
168         /* Misc Subtitles options */
169         misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
170                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
171                                  5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
172                                  hwnd, NULL, hInst, NULL );
173
174         delay_label = CreateWindow( _T("STATIC"),
175                                     _T("Delay subtitles (in 1/10s)"),
176                                     WS_CHILD | WS_VISIBLE | SS_LEFT,
177                                     10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
178                                     hwnd, NULL, hInst, NULL );
179
180         i_delay = config_GetInt( p_intf, "sub-delay" );
181         _stprintf( psz_text, _T("%d"), i_delay );
182
183         delay_edit = CreateWindow( _T("EDIT"), psz_text,
184             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
185             rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
186             hwnd, NULL, hInst, NULL );
187
188         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
189         ic.dwICC = ICC_UPDOWN_CLASS;
190         InitCommonControlsEx(&ic);
191
192         delay_spinctrl =
193             CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
194                 UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
195                 0, 0, 0, 0, hwnd, 0, hInst,
196                 delay_edit, 650000, -650000, i_delay );
197
198         fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
199                         WS_CHILD | WS_VISIBLE | SS_LEFT,
200                         10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
201                         hwnd, NULL, hInst, NULL );
202
203         f_fps = config_GetFloat( p_intf, "sub-fps" );
204         _stprintf( psz_text, _T("%f"), f_fps );
205
206         fps_edit = CreateWindow( _T("EDIT"), psz_text,
207             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
208             rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
209             hwnd, NULL, hInst, NULL);
210
211         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
212         ic.dwICC = ICC_UPDOWN_CLASS;
213         InitCommonControlsEx(&ic);
214
215         fps_spinctrl = CreateUpDownControl(
216             WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
217             UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
218             0, 0, 0, 0, hwnd, 0, hInst, fps_edit, 16000, 0, (int)f_fps );
219
220         break;
221
222     case WM_CLOSE:
223         EndDialog( hwnd, LOWORD( wp ) );
224         break;
225
226     case WM_SETFOCUS:
227         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
228         break;
229
230     case WM_COMMAND:
231         if ( LOWORD(wp) == IDOK )
232         {
233             subsfile_mrl.clear();
234
235             string szFileCombo = "sub-file=";
236             GetWindowText( file_combo, psz_text, 256 );
237             szFileCombo += _TOMB(psz_text);
238             subsfile_mrl.push_back( szFileCombo );
239
240             if( GetWindowTextLength( encoding_combo ) != 0 )
241             {
242                 string szEncoding = "subsdec-encoding=";
243                 GetWindowText( encoding_combo, psz_text, 256 );
244                 szEncoding += _TOMB(psz_text);
245                 subsfile_mrl.push_back( szEncoding );
246             }
247
248             string szDelay = "sub-delay=";
249             Edit_GetText( delay_edit, psz_text, 256 );
250             szDelay += _TOMB(psz_text);
251             subsfile_mrl.push_back( szDelay );
252
253             string szFps = "sub-fps=";
254             Edit_GetText( fps_edit, psz_text, 256 );
255             szFps += _TOMB(psz_text);
256             subsfile_mrl.push_back( szFps );
257
258             EndDialog( hwnd, LOWORD( wp ) );
259             break;
260         }
261         if( HIWORD(wp) == BN_CLICKED )
262         {
263             if ((HWND)lp == browse_button)
264             {
265                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
266                 OnFileBrowse();
267             }
268         }
269         break;
270
271     default:
272         break;
273     }
274
275     return FALSE;
276 }
277
278 /*****************************************************************************
279  * Private methods.
280  *****************************************************************************/
281
282 /*****************************************************************************
283  * Events methods.
284  *****************************************************************************/
285 static void OnOpenCB( intf_dialog_args_t *p_arg )
286 {
287     SubsFileDialog *p_this = (SubsFileDialog *)p_arg->p_arg;
288
289     if( p_arg->i_results && p_arg->psz_results[0] )
290     {
291         SetWindowText( p_this->file_combo, _FROMMB(p_arg->psz_results[0]) );
292         ComboBox_AddString( p_this->file_combo,
293                             _FROMMB(p_arg->psz_results[0]) );
294         if( ComboBox_GetCount( p_this->file_combo ) > 10 )
295             ComboBox_DeleteString( p_this->file_combo, 0 );
296     }
297 }
298
299 void SubsFileDialog::OnFileBrowse()
300 {
301     intf_dialog_args_t *p_arg =
302         (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
303     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
304
305     p_arg->psz_title = strdup( "Open file" );
306     p_arg->psz_extensions = strdup( "All|*.*" );
307     p_arg->p_arg = this;
308     p_arg->pf_callback = OnOpenCB;
309
310     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
311 }