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