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