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