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