]> git.sesse.net Git - vlc/blob - modules/gui/wince/open.cpp
* modules/gui/wince: some more code cleanup + fixes.
[vlc] / modules / gui / wince / open.cpp
1 /*****************************************************************************
2  * open.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2004 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 /* IDs for the controls and the menu commands */
47 enum
48 {
49     Notebook_Event = 1000,
50     MRL_Event,
51
52     FileBrowse_Event,
53     FileName_Event,
54
55     DiscType_Event,
56     DiscDevice_Event,
57     DiscTitle_Event,
58     DiscChapter_Event,
59
60     NetType_Event,
61     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
62     NetPort1_Event, NetPort2_Event, NetPort3_Event,
63     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
64
65     SubsFileEnable_Event,
66     SubsFileSettings_Event,
67 };
68
69 /*****************************************************************************
70  * AutoBuiltPanel.
71  *****************************************************************************/
72
73 /*****************************************************************************
74  * Constructor.
75  *****************************************************************************/
76 OpenDialog::OpenDialog( intf_thread_t *_p_intf, HINSTANCE _hInst,
77                         int _i_access_method, int _i_arg, int _i_method )
78 {
79     /* Initializations */
80     p_intf = _p_intf;
81     hInst = _hInst;
82     i_current_access_method = _i_access_method;
83     i_open_arg = _i_arg;
84     i_method = _i_method;
85 }
86
87 /***********************************************************************
88
89 FUNCTION: 
90   WndProc
91
92 PURPOSE: 
93   Processes messages sent to the main window.
94   
95 ***********************************************************************/
96 LRESULT OpenDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
97 {
98     SHINITDLGINFO shidi;
99     SHMENUBARINFO mbi;
100     INITCOMMONCONTROLSEX  iccex;  // INITCOMMONCONTROLSEX structure    
101     RECT rcClient;
102     TC_ITEM tcItem;
103
104     switch( msg )
105     {
106     case WM_INITDIALOG: 
107         shidi.dwMask = SHIDIM_FLAGS;
108         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
109             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
110         shidi.hDlg = hwnd;
111         SHInitDialog( &shidi );
112
113         //Create the menubar.
114         memset( &mbi, 0, sizeof(SHMENUBARINFO) );
115         mbi.cbSize     = sizeof(SHMENUBARINFO);
116         mbi.hwndParent = hwnd;
117         mbi.nToolBarId = IDR_DUMMYMENU;
118         mbi.hInstRes   = hInst;
119         mbi.nBmpId     = 0;
120         mbi.cBmpImages = 0;  
121
122         if( !SHCreateMenuBar( &mbi ) )
123         {
124             MessageBox( hwnd, _T("SHCreateMenuBar failed"),
125                         _T("Error"), MB_OK );
126             //return -1;
127         }
128
129         hwndCB = mbi.hwndMB;
130
131         // Get the client area rect to put the panels in
132         GetClientRect( hwnd, &rcClient );
133
134         /* Create MRL combobox */
135         mrl_box = CreateWindow( _T("STATIC"),
136                                 _FROMMB(_("Media Resource Locator (MRL)")),
137                                 WS_CHILD | WS_VISIBLE | SS_LEFT,
138                                 5, 10, rcClient.right, 15, hwnd, 0, hInst, 0 );
139
140         mrl_label = CreateWindow( _T("STATIC"), _FROMMB(_("Open:")),
141                                   WS_CHILD | WS_VISIBLE | SS_LEFT,
142                                   5, 10 + 15 + 10, 40, 15, hwnd, 0, hInst, 0 );
143
144         mrl_combo = CreateWindow( _T("COMBOBOX"), _T(""),
145                                   WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
146                                   CBS_SORT | WS_VSCROLL, 45, 10 + 15 + 10 - 3,
147                                   rcClient.right - 50 - 5, 5*15 + 6, hwnd,
148                                   0, hInst, 0 );
149
150         // No tooltips for ComboBox
151         label = CreateWindow( _T("STATIC"),
152                               _FROMMB(_("Alternatively, you can build an MRL "
153                                        "using one of the following predefined "
154                                        "targets:" )),
155                               WS_CHILD | WS_VISIBLE | SS_LEFT,
156                               5, 10 + 2*(15 + 10), rcClient.right - 2*5, 2*15,
157                               hwnd, 0, hInst, 0 );
158
159         /* Create notebook */
160         iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
161         iccex.dwSize = ICC_TAB_CLASSES;
162         InitCommonControlsEx (&iccex);
163
164         notebook = CreateWindowEx( 0, WC_TABCONTROL, NULL,
165             WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
166             5, 10 + 4*15 + 2*10, rcClient.right - 2*5,
167             rcClient.bottom - MENU_HEIGHT - 15 - 10 - 10 - (10 + 4*15 + 2*10),
168             hwnd, NULL, hInst, NULL );
169
170         tcItem.mask = TCIF_TEXT;
171         tcItem.pszText = _T("File");
172         TabCtrl_InsertItem( notebook, 0, &tcItem );
173         tcItem.pszText = _T("Network");
174         TabCtrl_InsertItem( notebook, 1, &tcItem );
175
176         switch( i_current_access_method )
177         {
178         case FILE_ACCESS:
179             TabCtrl_SetCurSel( notebook, 0 );
180             break;
181         case NET_ACCESS:
182             TabCtrl_SetCurSel( notebook, 1 );
183             break;
184         }
185
186         FilePanel( hwnd );
187         NetPanel( hwnd );
188
189         OnPageChange();
190         break;
191
192     case WM_CLOSE:
193         EndDialog( hwnd, LOWORD( wp ) );
194         break;
195
196     case WM_COMMAND:
197         if( LOWORD(wp) == IDOK )
198         {
199             OnOk();
200             EndDialog( hwnd, LOWORD( wp ) );
201             break;
202         }
203         if( HIWORD(wp) == BN_CLICKED )
204         {
205             if( (HWND)lp == net_radios[0] )
206             {
207                 OnNetTypeChange( NetRadio1_Event );
208             } else if( (HWND)lp == net_radios[1] )
209             {
210                 OnNetTypeChange( NetRadio2_Event );
211             } else if( (HWND)lp == net_radios[2] )
212             {
213                 OnNetTypeChange( NetRadio3_Event );
214             } else if( (HWND)lp == net_radios[3] )
215             {
216                 OnNetTypeChange( NetRadio4_Event );
217             } else if( (HWND)lp == subsfile_checkbox )
218             {
219                 OnSubsFileEnable();
220             } else if( (HWND)lp == subsfile_button )
221             {
222                 OnSubsFileSettings( hwnd );
223             } else if( (HWND)lp == browse_button )
224             {
225                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
226                 OnFileBrowse();
227             } 
228             break;
229         }
230         if( HIWORD(wp) == EN_CHANGE )
231         {
232             if( (HWND)lp == net_addrs[1] )
233             {
234                 OnNetPanelChange( NetAddr2_Event );
235             } else if( (HWND)lp == net_addrs[2] )
236             {
237                 OnNetPanelChange( NetAddr3_Event );
238             } else if( (HWND)lp == net_addrs[3] )
239             {
240                 OnNetPanelChange( NetAddr4_Event );
241             } else if( (HWND)lp == net_ports[0] )
242             {
243                 OnNetPanelChange( NetPort1_Event );
244             } else if( (HWND)lp == net_ports[1] )
245             {
246                 OnNetPanelChange( NetPort2_Event );
247             }
248         }
249         if( HIWORD(wp) == CBN_EDITUPDATE )
250         {
251             if ((HWND)lp == file_combo)
252             {
253                 OnFilePanelChange();
254             }
255         }
256         break;
257
258     case WM_NOTIFY:
259         if( (((NMHDR *)lp)->code) == TCN_SELCHANGE ) OnPageChange();
260         break;
261
262     default:
263         break;
264     }
265
266     return FALSE;
267 }
268
269 /*****************************************************************************
270  * Private methods.
271  *****************************************************************************/
272 void OpenDialog::FilePanel( HWND hwnd )
273 {
274     RECT rc;    
275     GetWindowRect( notebook, &rc);
276
277     /* Create browse file line */
278     file_combo = CreateWindow( _T("COMBOBOX"), _T(""),
279         WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
280         rc.left + 10, rc.top + 10 - 3, rc.right - 10 - (rc.left + 10),
281         5*15 + 6, hwnd, NULL, hInst, NULL );
282
283     browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
284         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
285         rc.left + 10, rc.top + 10 + 15 + 10 - 3, 80, 15 + 6,
286         hwnd, NULL, hInst, NULL );
287
288     /* Create Subtitles File checkox */
289     subsfile_checkbox = CreateWindow( _T("BUTTON"), _T("Subtitle options"),
290         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
291         rc.left + 10, rc.top + 10 + 2*(15 + 10), 15, 15,
292         hwnd, NULL, hInst, NULL );
293     SendMessage( subsfile_checkbox, BM_SETCHECK, BST_UNCHECKED, 0 );
294
295     subsfile_label = CreateWindow( _T("STATIC"), _T("Subtitle options"),
296                 WS_CHILD | WS_VISIBLE | SS_LEFT,
297                 rc.left + 10 + 15 + 10, rc.top + 10 + 2*(15 + 10), 100, 15,
298                 hwnd, NULL, hInst, NULL);
299
300     subsfile_button = CreateWindow( _T("BUTTON"), _T("Settings..."),
301                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_DISABLED,
302                 rc.right - 80 - 10, rc.top + 10 + 2*(15 + 10) - 3, 80, 15 + 6,
303                 hwnd, NULL, hInst, NULL );
304
305     char *psz_subsfile = config_GetPsz( p_intf, "sub-file" );
306     if( psz_subsfile && *psz_subsfile )
307     {
308         SendMessage( subsfile_checkbox, BM_SETCHECK, BST_CHECKED, 0 );
309         EnableWindow( subsfile_button, TRUE );
310         string sz_subsfile = "sub-file=";
311         sz_subsfile += psz_subsfile;
312         subsfile_mrl.push_back( sz_subsfile );
313     }
314     if( psz_subsfile ) free( psz_subsfile );
315 }
316
317 void OpenDialog::NetPanel( HWND hwnd )
318 {  
319     INITCOMMONCONTROLSEX ic;
320     TCHAR psz_text[256];
321
322     struct net_type
323     {
324         TCHAR *psz_text;
325         int length;
326     };
327
328     static struct net_type net_type_array[] =
329     {
330         { _T("UDP/RTP"), 82 },
331         { _T("UDP/RTP Multicast"), 140 },
332         { _T("HTTP/FTP/MMS"), 90 },
333         { _T("RTSP"), 30 }
334     };
335
336     RECT rc;    
337     GetWindowRect( notebook, &rc);
338
339     /* UDP/RTP row */
340     net_radios[0] = CreateWindow( _T("BUTTON"), net_type_array[0].psz_text,
341                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
342                 rc.left + 5, rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
343
344     net_label[0] = CreateWindow( _T("STATIC"), net_type_array[0].psz_text,
345                 WS_CHILD | WS_VISIBLE | SS_LEFT,
346                 rc.left + 5 + 15 + 5, rc.top + 10, net_type_array[0].length,
347                 15, hwnd, NULL, hInst, NULL );
348
349     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
350
351     net_port_label[0] = CreateWindow( _T("STATIC"), _T("Port"),
352                 WS_CHILD | WS_VISIBLE | SS_LEFT,
353                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
354                 hwnd, NULL, hInst, NULL );
355
356     _stprintf( psz_text, _T("%d"), i_net_ports[0] );
357     net_ports[0] = CreateWindow( _T("EDIT"), psz_text,
358         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
359         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
360         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6, hwnd, NULL, hInst, NULL );
361
362     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
363     ic.dwICC = ICC_UPDOWN_CLASS;
364     InitCommonControlsEx(&ic);
365
366     hUpdown[0] = CreateUpDownControl(
367                 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
368                 UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
369                 0, 0, 0, 0, hwnd, 0, hInst,
370                 net_ports[0], 16000, 0, i_net_ports[0]);
371
372     /* UDP/RTP Multicast row */
373     net_radios[1] = CreateWindow( _T("BUTTON"), net_type_array[1].psz_text,
374                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
375                 rc.left + 5, rc.top + 10 + 15 + 10, 15, 15,
376                 hwnd, NULL, hInst, NULL);
377
378     net_label[1] = CreateWindow( _T("STATIC"), net_type_array[1].psz_text,
379                 WS_CHILD | WS_VISIBLE | SS_LEFT,
380                 rc.left + 5 + 15 + 5, rc.top + 10 + 15 + 10,
381                 net_type_array[1].length, 15, hwnd, NULL, hInst, NULL );
382
383     net_addrs_label[1] = CreateWindow( _T("STATIC"), _T("Address"),
384                 WS_CHILD | WS_VISIBLE | SS_LEFT,
385                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 50, 15,
386                 hwnd, NULL, hInst, NULL);
387
388     net_addrs[1] = CreateWindow( _T("EDIT"), _T(""),
389                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
390                 rc.left + 5 + 50 + 5, rc.top + 10 + 2*(15 + 10) - 3,
391                 rc.right - 5 - (rc.left + 5 + 50 + 5), 15 + 6,
392                 hwnd, NULL, hInst, NULL);
393
394     net_port_label[1] = CreateWindow( _T("STATIC"), _T("Port"),
395                 WS_CHILD | WS_VISIBLE | SS_LEFT,
396                 rc.left + 5 , rc.top + 10 + 3*(15 + 10), 30, 15,
397                 hwnd, NULL, hInst, NULL);
398
399     i_net_ports[1] = i_net_ports[0];
400
401     _stprintf( psz_text, _T("%d"), i_net_ports[1] );
402     net_ports[1] = CreateWindow( _T("EDIT"), psz_text,
403                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
404                 rc.left + 5 + 30 + 5, rc.top + 10 + 3*(15 + 10) - 3,
405                 rc.right - 5 -(rc.left + 5 + 30 + 5), 15 + 6,
406                 hwnd, NULL, hInst, NULL );
407
408     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
409     ic.dwICC = ICC_UPDOWN_CLASS;
410     InitCommonControlsEx(&ic);
411
412     hUpdown[1] = CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
413         UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
414         0, 0, 0, 0, hwnd, 0, hInst,
415         net_ports[1], 16000, 0, i_net_ports[1] );
416
417     /* HTTP and RTSP rows */
418     net_radios[2] = CreateWindow( _T("BUTTON"), net_type_array[2].psz_text,
419         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
420         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5,
421         rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
422         
423     net_label[2] = CreateWindow( _T("STATIC"), net_type_array[2].psz_text,
424         WS_CHILD | WS_VISIBLE | SS_LEFT,
425         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5 + 15 + 5,
426         rc.top + 10, net_type_array[2].length, 15,
427         hwnd, NULL, hInst, NULL );
428
429     net_addrs_label[2] = CreateWindow( _T("STATIC"), _T("URL"),
430         WS_CHILD | WS_VISIBLE | SS_LEFT,
431         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
432         hwnd, NULL, hInst, NULL );
433
434     net_addrs[2] = CreateWindow( _T("EDIT"), _T(""),
435         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
436         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
437         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
438         hwnd, NULL, hInst, NULL);
439
440     net_radios[3] = CreateWindow( _T("BUTTON"), net_type_array[3].psz_text,
441         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
442         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5,
443         rc.top + 10 + 15 + 10, 15, 15, hwnd, NULL, hInst, NULL );
444
445     net_label[3] = CreateWindow( _T("STATIC"), net_type_array[3].psz_text,
446         WS_CHILD | WS_VISIBLE | SS_LEFT,
447         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5 + 15 + 5,
448         rc.top + 10 + 15 + 10, net_type_array[3].length, 15,
449         hwnd, NULL, hInst, NULL );
450
451     net_addrs_label[3] = CreateWindow( _T("STATIC"), _T("URL"),
452         WS_CHILD | WS_VISIBLE | SS_LEFT,
453         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
454         hwnd, NULL, hInst, NULL );
455
456     net_addrs[3] = CreateWindow( _T("EDIT"), _T("rtsp://"),
457         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
458         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
459         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
460         hwnd, NULL, hInst, NULL );
461
462     SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
463 }
464
465 void OpenDialog::UpdateMRL()
466 {
467     UpdateMRL( i_current_access_method );
468 }
469
470 void OpenDialog::UpdateMRL( int i_access_method )
471 {
472     string demux, mrltemp;
473     TCHAR psz_text[2048];
474     char psz_tmp[256];
475
476     i_current_access_method = i_access_method;
477
478     switch( i_access_method )
479     {
480     case FILE_ACCESS:
481         GetWindowText( file_combo, psz_text, 2048 );
482         mrltemp = _TOMB(psz_text);
483         break;
484     case NET_ACCESS:
485         switch( i_net_type )
486         {
487         case 0:
488             mrltemp = "udp" + demux + "://";
489             if( i_net_ports[0] !=
490                 config_GetInt( p_intf, "server-port" ) )
491             {
492                 sprintf( psz_tmp, "@:%d", i_net_ports[0] );
493                 mrltemp += psz_tmp;
494             }
495             break;
496
497         case 1:
498             mrltemp = "udp" + demux + "://@";
499             Edit_GetText( net_addrs[1], psz_text, 2048 );
500             mrltemp += _TOMB(psz_text);
501             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
502             {
503                 sprintf( psz_tmp, ":%d", i_net_ports[1] );
504                 mrltemp += psz_tmp;
505             }
506             break;
507
508         case 2:
509             /* http access */
510             Edit_GetText( net_addrs[2], psz_text, 2048 );
511             if( !strstr( _TOMB(psz_text), "http://" ) )
512             {
513                 mrltemp = "http" + demux + "://";
514             }
515             mrltemp += _TOMB(psz_text);
516             break;
517
518         case 3:
519             /* RTSP access */
520             Edit_GetText( net_addrs[3], psz_text, 2048 );
521             if( !strstr( _TOMB(psz_text), "rtsp://" ) )
522             {
523                 mrltemp = "rtsp" + demux + "://";
524             }
525             mrltemp += _TOMB(psz_text);
526             break;
527         }
528         break;
529     default:
530         break;
531     }
532
533     SetWindowText( mrl_combo, _FROMMB(mrltemp.c_str()) );
534 }
535
536 void OpenDialog::OnPageChange()
537 {
538     if( TabCtrl_GetCurSel( notebook ) == 0 )
539     {
540         for( int i=0; i<4; i++ )
541         {
542             SetWindowPos( net_radios[i], HWND_BOTTOM, 0, 0, 0, 0,
543                           SWP_NOMOVE | SWP_NOSIZE );
544             SetWindowPos( net_label[i], HWND_BOTTOM, 0, 0, 0, 0,
545                           SWP_NOMOVE | SWP_NOSIZE );
546         }
547         DisableNETCtrl();
548
549         SetWindowPos( file_combo, HWND_TOP, 0, 0, 0, 0,
550                       SWP_NOMOVE | SWP_NOSIZE );
551         SetWindowPos( browse_button, HWND_TOP, 0, 0, 0, 0,
552                       SWP_NOMOVE | SWP_NOSIZE );
553         SetWindowPos( subsfile_checkbox, HWND_TOP, 0, 0, 0, 0,
554                       SWP_NOMOVE | SWP_NOSIZE );
555         SetWindowPos( subsfile_label, HWND_TOP, 0, 0, 0, 0,
556                       SWP_NOMOVE | SWP_NOSIZE );
557         SetWindowPos( subsfile_button, HWND_TOP, 0, 0, 0, 0,
558                       SWP_NOMOVE | SWP_NOSIZE );
559
560         i_current_access_method = FILE_ACCESS;
561     }
562     else if ( TabCtrl_GetCurSel( notebook ) == 1 )
563     {
564         SetWindowPos( file_combo, HWND_BOTTOM, 0, 0, 0, 0,
565                       SWP_NOMOVE | SWP_NOSIZE );
566         SetWindowPos( browse_button, HWND_BOTTOM, 0, 0, 0, 0,
567                       SWP_NOMOVE | SWP_NOSIZE );
568         SetWindowPos( subsfile_checkbox, HWND_BOTTOM, 0, 0, 0, 0,
569                       SWP_NOMOVE | SWP_NOSIZE );
570         SetWindowPos( subsfile_label, HWND_BOTTOM, 0, 0, 0, 0,
571                       SWP_NOMOVE | SWP_NOSIZE );
572         SetWindowPos( subsfile_button, HWND_BOTTOM, 0, 0, 0, 0,
573                       SWP_NOMOVE | SWP_NOSIZE );
574
575         for( int i=0; i<4; i++ )
576         {
577             SetWindowPos( net_radios[i], HWND_TOP, 0, 0, 0, 0,
578                           SWP_NOMOVE | SWP_NOSIZE );
579             SendMessage( net_radios[i], BM_SETCHECK, BST_UNCHECKED, 0 );
580             SetWindowPos( net_label[i], HWND_TOP, 0, 0, 0, 0,
581                           SWP_NOMOVE | SWP_NOSIZE );
582         }
583         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
584                       SWP_NOMOVE | SWP_NOSIZE );
585         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
586                       SWP_NOMOVE | SWP_NOSIZE );
587         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
588                       SWP_NOMOVE | SWP_NOSIZE );
589
590         SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
591
592         i_current_access_method = NET_ACCESS;
593     }
594
595     UpdateMRL();
596 }
597
598 void OpenDialog::OnOk()
599 {
600     TCHAR psz_text[2048];
601
602     GetWindowText( mrl_combo, psz_text, 2048 ); // replace by ComboBox_GetText( mrl_combo, wUnicode, size )
603     mrl = SeparateEntries( psz_text );
604     ComboBox_AddString( mrl_combo, psz_text );
605     if( ComboBox_GetCount( mrl_combo ) > 10 ) 
606         ComboBox_DeleteString( mrl_combo, 0 );
607     ComboBox_SetCurSel( mrl_combo, ComboBox_GetCount( mrl_combo ) - 1 );
608
609     /* Update the playlist */
610     playlist_t *p_playlist =
611         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
612                                        FIND_ANYWHERE );
613     if( p_playlist == NULL ) return;
614
615     for( int i = 0; i < (int)mrl.size(); i++ )
616     {
617         vlc_bool_t b_start = !i && i_open_arg;
618         playlist_item_t *p_item =
619             playlist_ItemNew( p_intf, (const char*)mrl[i].c_str(),
620                               (const char *)mrl[i].c_str() );
621
622         /* Insert options */
623         while( i + 1 < (int)mrl.size() &&
624                ((const char *)mrl[i + 1].c_str())[0] == ':' )
625         {
626             playlist_ItemAddOption( p_item, mrl[i + 1].c_str() );
627             i++;
628         }
629
630         /* Get the options from the subtitles dialog */
631         if( (SendMessage( subsfile_checkbox, BM_GETCHECK, 0, 0 ) & BST_CHECKED)
632             && subsfile_mrl.size() )
633         {
634             for( int j = 0; j < (int)subsfile_mrl.size(); j++ )
635             {
636                 playlist_ItemAddOption( p_item, subsfile_mrl[j].c_str() );
637             }
638         }
639
640         playlist_AddItem( p_playlist, p_item,
641                           PLAYLIST_APPEND, PLAYLIST_END );
642
643         if( b_start )
644         {
645             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY , p_item );
646         }
647     }
648
649     //TogglePlayButton( PLAYING_S );
650
651     vlc_object_release( p_playlist );
652 }
653
654 /*****************************************************************************
655  * File panel event methods.
656  *****************************************************************************/
657 void OpenDialog::OnFilePanelChange()
658 {
659     UpdateMRL( FILE_ACCESS );
660 }
661
662 void OpenDialog::OnFileBrowse()
663 {       
664     OPENFILENAME ofn;
665     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
666     TCHAR psz_file[PATH_MAX] = _T("\0");
667     TCHAR psz_tmp[PATH_MAX+2] = _T("\0");
668
669     memset(&ofn, 0, sizeof(OPENFILENAME));
670     ofn.lStructSize = sizeof (OPENFILENAME);
671     ofn.hwndOwner = NULL;
672     ofn.hInstance = hInst;
673     ofn.lpstrFilter = szFilter;
674     ofn.lpstrCustomFilter = NULL;
675     ofn.nMaxCustFilter = 0;
676     ofn.nFilterIndex = 1;     
677     ofn.lpstrFile = psz_file; 
678     ofn.nMaxFile = PATH_MAX;
679     ofn.lpstrFileTitle = NULL; 
680     ofn.nMaxFileTitle = 40;
681     ofn.lpstrInitialDir = NULL;
682     ofn.lpstrTitle = _T("Open File");
683     ofn.Flags = 0;
684     ofn.nFileOffset = 0;
685     ofn.nFileExtension = 0;
686     ofn.lpstrDefExt = NULL;
687     ofn.lCustData = 0L;
688     ofn.lpfnHook = NULL;
689     ofn.lpTemplateName = NULL;
690     if( GetOpenFileName((LPOPENFILENAME) &ofn) )
691     {
692         if( _tcschr( ofn.lpstrFile, _T(' ') ) )
693         {
694             _tcscat( psz_tmp, _T("\"") );
695             _tcscat( psz_tmp, ofn.lpstrFile );
696             _tcscat( psz_tmp, _T("\"") );
697         }
698         else _tcscat( psz_tmp, ofn.lpstrFile );
699
700         SetWindowText( file_combo, psz_tmp );
701         ComboBox_AddString( file_combo, psz_tmp );
702         if( ComboBox_GetCount( file_combo ) > 10 ) 
703             ComboBox_DeleteString( file_combo, 0 );
704
705         UpdateMRL( FILE_ACCESS );
706     }
707 }
708
709 /*****************************************************************************
710  * Net panel event methods.
711  *****************************************************************************/
712 void OpenDialog::OnNetPanelChange( int event )
713 {
714     TCHAR psz_text[2048];
715     int port;
716
717     if( event >= NetPort1_Event && event <= NetPort2_Event )
718     {
719         Edit_GetText( net_ports[event - NetPort1_Event], psz_text, 2048 );
720         _stscanf( psz_text, _T("%d"), &port );
721         i_net_ports[event - NetPort1_Event] = port;
722     }
723
724     UpdateMRL( NET_ACCESS );
725 }
726
727 void OpenDialog::OnNetTypeChange( int event )
728 {
729     DisableNETCtrl();
730
731     i_net_type = event - NetRadio1_Event;
732
733     if( event == NetRadio1_Event )
734     {
735         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
736                       SWP_NOMOVE | SWP_NOSIZE );
737         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
738                       SWP_NOMOVE | SWP_NOSIZE );
739         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
740                       SWP_NOMOVE | SWP_NOSIZE );
741     } 
742     else if( event == NetRadio2_Event )
743     {
744         SetWindowPos( net_addrs_label[1], HWND_TOP, 0, 0, 0, 0,
745                       SWP_NOMOVE | SWP_NOSIZE );
746         SetWindowPos( net_addrs[1], HWND_TOP, 0, 0, 0, 0,
747                       SWP_NOMOVE | SWP_NOSIZE );
748         SetWindowPos( net_port_label[1], HWND_TOP, 0, 0, 0, 0,
749                       SWP_NOMOVE | SWP_NOSIZE );
750         SetWindowPos( net_ports[1], HWND_TOP, 0, 0, 0, 0,
751                       SWP_NOMOVE | SWP_NOSIZE );
752         SetWindowPos( hUpdown[1], HWND_TOP, 0, 0, 0, 0,
753                       SWP_NOMOVE | SWP_NOSIZE );
754     } 
755     else if( event == NetRadio3_Event )
756     {
757         SetWindowPos( net_addrs_label[2], HWND_TOP, 0, 0, 0, 0,
758                       SWP_NOMOVE | SWP_NOSIZE );
759         SetWindowPos( net_addrs[2], HWND_TOP, 0, 0, 0, 0,
760                       SWP_NOMOVE | SWP_NOSIZE );
761     } 
762     else if( event == NetRadio4_Event )
763     {
764         SetWindowPos( net_addrs_label[3], HWND_TOP, 0, 0, 0, 0,
765                       SWP_NOMOVE | SWP_NOSIZE );
766         SetWindowPos( net_addrs[3], HWND_TOP, 0, 0, 0, 0,
767                       SWP_NOMOVE | SWP_NOSIZE );
768     }
769         
770     UpdateMRL( NET_ACCESS );
771 }
772
773 void OpenDialog::DisableNETCtrl()
774 {
775     for( int i=0; i<4; i++ )
776     {
777         SetWindowPos( net_port_label[i], HWND_BOTTOM, 0, 0, 0, 0,
778                       SWP_NOMOVE | SWP_NOSIZE );
779         SetWindowPos( net_ports[i], HWND_BOTTOM, 0, 0, 0, 0,
780                       SWP_NOMOVE | SWP_NOSIZE );
781         SetWindowPos( hUpdown[i], HWND_BOTTOM, 0, 0, 0, 0,
782                       SWP_NOMOVE | SWP_NOSIZE );
783         SetWindowPos( net_addrs_label[i], HWND_BOTTOM, 0, 0, 0, 0,
784                       SWP_NOMOVE | SWP_NOSIZE );
785         SetWindowPos( net_addrs[i], HWND_BOTTOM, 0, 0, 0, 0,
786                       SWP_NOMOVE | SWP_NOSIZE );
787     }
788
789     UpdateMRL( FILE_ACCESS );
790 }
791
792 /*****************************************************************************
793  * Subtitles file event methods.
794  *****************************************************************************/
795 void OpenDialog::OnSubsFileEnable()
796 {
797     EnableWindow( subsfile_button, ( SendMessage( subsfile_checkbox,
798                   BM_GETCHECK, 0, 0 ) & BST_CHECKED ) ? TRUE : FALSE );
799 }
800
801 void OpenDialog::OnSubsFileSettings( HWND hwnd )
802 {
803
804     /* Show/hide the open dialog */
805     SubsFileDialog *subsfile_dialog = new SubsFileDialog( p_intf, hInst );
806     CreateDialogBox(  hwnd, subsfile_dialog );
807
808     subsfile_mrl.clear();
809
810     for( int i = 0; i < (int)subsfile_dialog->subsfile_mrl.size(); i++ )
811         subsfile_mrl.push_back( subsfile_dialog->subsfile_mrl[i] );
812
813     delete subsfile_dialog;
814 }
815
816 /*****************************************************************************
817  * Utility functions.
818  *****************************************************************************/
819 vector<string> SeparateEntries( TCHAR *entries )
820 {
821     vlc_bool_t b_quotes_mode = VLC_FALSE;
822     vector<string> entries_array;
823     TCHAR *entry = new TCHAR[ _tcslen(entries) + 1 ];
824     TCHAR *strToken = entries;
825     int length = _tcscspn( strToken, _T(" \t\r\n\"") );
826     *entry = 0;
827
828     while( strToken - entries < _tcslen(entries) )
829     { 
830         _tcsncat( entry, strToken, length );
831
832         _tcsncat( entry, strToken + length, 1 );
833
834         if( !b_quotes_mode && strToken[length] == _T('\"') )
835         {
836             /* Enters quotes mode */
837             entry[ _tcslen(entry) - 1 ] = 0;
838             b_quotes_mode = VLC_TRUE;
839         }
840         else if( b_quotes_mode && strToken[length] == _T('\"') )
841         {
842             /* Finished the quotes mode */
843             entry[ _tcslen(entry) - 1 ] = 0;
844             if( _tcscmp( entry, _T("") ) != 0 )
845             {
846                 entries_array.push_back( _TOMB(entry) );
847             }
848             *entry = 0;
849             b_quotes_mode = VLC_FALSE;
850         }
851         else if( !b_quotes_mode && strToken[length] != _T('\"') )
852         {
853             /* we found a non-quoted standalone string */
854             if( strToken + length - entries < _tcslen(entries) ||/*token.HasMoreTokens() ||*/ //FIX ME IF YOU CAN
855                 strToken[length] == _T(' ') ||
856                 strToken[length] == _T('\t') ||
857                 strToken[length] == _T('\r') ||
858                 strToken[length] == _T('\n') )
859               entry[ _tcslen(entry) - 1 ]/*strToken[length]*/ = 0;
860             if( _tcscmp( entry, _T("") ) != 0 )
861             {
862                 entries_array.push_back( _TOMB(entry) );
863             }
864             *entry = 0;
865         }
866         else
867         {;}
868
869         strToken += length + 1;
870         length = _tcscspn( strToken, _T(" \t\r\n\"") );
871     }
872
873     if( _tcscmp( entry, _T("") ) != 0 )
874     {
875         entries_array.push_back( _TOMB(entry) );
876     }
877
878     delete [] entry;
879     return entries_array;
880 }