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