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