]> git.sesse.net Git - vlc/blob - modules/gui/wince/open.cpp
2f6f6752008ed242f30e2a96fe6e94ab58c3e960
[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., 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 <windowsx.h>
37 #include <commctrl.h>
38 #include <commdlg.h>
39 #include <shlobj.h>
40
41 /*****************************************************************************
42  * Event Table.
43  *****************************************************************************/
44
45 /* IDs for the controls and the menu commands */
46 enum
47 {
48     Notebook_Event = 1000,
49     MRL_Event,
50
51     FileBrowse_Event,
52     FileName_Event,
53
54     DiscType_Event,
55     DiscDevice_Event,
56     DiscTitle_Event,
57     DiscChapter_Event,
58
59     NetType_Event,
60     NetRadio1_Event, NetRadio2_Event, NetRadio3_Event, NetRadio4_Event,
61     NetPort1_Event, NetPort2_Event, NetPort3_Event,
62     NetAddr1_Event, NetAddr2_Event, NetAddr3_Event, NetAddr4_Event,
63
64     SubsFileEnable_Event,
65     SubsFileSettings_Event,
66 };
67
68 /*****************************************************************************
69  * AutoBuiltPanel.
70  *****************************************************************************/
71
72 /*****************************************************************************
73  * Constructor.
74  *****************************************************************************/
75 OpenDialog::OpenDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
76                         HINSTANCE h_inst, int _i_access, int _i_arg )
77   :  CBaseWindow( p_intf, p_parent, h_inst )
78 {
79     /* Initializations */
80     i_access = _i_access;
81     i_open_arg = _i_arg;
82
83     for( int i = 0; i < 4; i++ )
84     {
85         net_radios[i] = 0;
86         net_label[i] = 0;
87         net_port_label[i] = 0;
88         net_ports[i] = 0;
89         hUpdown[i] = 0;
90         i_net_ports[i] = 0;
91         net_addrs_label[i] = 0;
92         net_addrs[i] = 0;
93     }
94
95     CreateWindow( _T("VLC WinCE"), _T("Messages"),
96                   WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX,
97                   0, 0, /*CW_USEDEFAULT*/300, /*CW_USEDEFAULT*/300,
98                   p_parent->GetHandle(), NULL, h_inst, (void *)this );
99 }
100
101 /***********************************************************************
102
103 FUNCTION: 
104   WndProc
105
106 PURPOSE: 
107   Processes messages sent to the main window.
108   
109 ***********************************************************************/
110 LRESULT OpenDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
111 {
112     SHINITDLGINFO shidi;
113     INITCOMMONCONTROLSEX  iccex;  // INITCOMMONCONTROLSEX structure    
114     RECT rcClient;
115     TC_ITEM tcItem;
116
117     switch( msg )
118     {
119     case WM_CREATE:
120         shidi.dwMask = SHIDIM_FLAGS;
121         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_FULLSCREENNOMENUBAR;
122         shidi.hDlg = hwnd;
123         SHInitDialog( &shidi );
124
125         // Get the client area rect to put the panels in
126         GetClientRect( hwnd, &rcClient );
127
128         /* Create MRL combobox */
129         mrl_box = CreateWindow( _T("STATIC"),
130                                 _FROMMB(_("Media Resource Locator (MRL)")),
131                                 WS_CHILD | WS_VISIBLE | SS_LEFT,
132                                 5, 10, rcClient.right, 15, hwnd, 0, hInst, 0 );
133
134         mrl_label = CreateWindow( _T("STATIC"), _FROMMB(_("Open:")),
135                                   WS_CHILD | WS_VISIBLE | SS_LEFT,
136                                   5, 10 + 15 + 10, 40, 15, hwnd, 0, hInst, 0 );
137
138         mrl_combo = CreateWindow( _T("COMBOBOX"), _T(""),
139                                   WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
140                                   CBS_SORT | WS_VSCROLL, 45, 10 + 15 + 10 - 3,
141                                   rcClient.right - 50 - 5, 5*15 + 6, hwnd,
142                                   0, hInst, 0 );
143
144         // No tooltips for ComboBox
145         label = CreateWindow( _T("STATIC"),
146                               _FROMMB(_("Alternatively, you can build an MRL "
147                                        "using one of the following predefined "
148                                        "targets:" )),
149                               WS_CHILD | WS_VISIBLE | SS_LEFT,
150                               5, 10 + 2*(15 + 10), rcClient.right - 2*5, 2*15,
151                               hwnd, 0, hInst, 0 );
152
153         /* Create notebook */
154         iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
155         iccex.dwSize = ICC_TAB_CLASSES;
156         InitCommonControlsEx (&iccex);
157
158         notebook = CreateWindowEx( 0, WC_TABCONTROL, NULL,
159             WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
160             5, 10 + 4*15 + 2*10, rcClient.right - 2*5,
161             rcClient.bottom - MENU_HEIGHT - 15 - 10 - 10 - (10 + 4*15 + 2*10),
162             hwnd, NULL, hInst, NULL );
163
164         tcItem.mask = TCIF_TEXT;
165         tcItem.pszText = _T("File");
166         TabCtrl_InsertItem( notebook, 0, &tcItem );
167         tcItem.pszText = _T("Network");
168         TabCtrl_InsertItem( notebook, 1, &tcItem );
169
170         switch( i_access )
171         {
172         case FILE_ACCESS:
173             TabCtrl_SetCurSel( notebook, 0 );
174             break;
175         case NET_ACCESS:
176             TabCtrl_SetCurSel( notebook, 1 );
177             break;
178         }
179
180         FilePanel( hwnd );
181         NetPanel( hwnd );
182
183         OnPageChange();
184         break;
185
186     case WM_CLOSE:
187         Show( FALSE );
188         return TRUE;
189
190     case WM_SETFOCUS:
191         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
192         SHSipPreference( hwnd, SIP_DOWN ); 
193         break;
194
195     case WM_COMMAND:
196         if( LOWORD(wp) == IDOK )
197         {
198             OnOk();
199             Show( FALSE );
200             break;
201         }
202         if( HIWORD(wp) == BN_CLICKED )
203         {
204             if( (HWND)lp == net_radios[0] )
205             {
206                 OnNetTypeChange( NetRadio1_Event );
207             } else if( (HWND)lp == net_radios[1] )
208             {
209                 OnNetTypeChange( NetRadio2_Event );
210             } else if( (HWND)lp == net_radios[2] )
211             {
212                 OnNetTypeChange( NetRadio3_Event );
213             } else if( (HWND)lp == net_radios[3] )
214             {
215                 OnNetTypeChange( NetRadio4_Event );
216             } else if( (HWND)lp == subsfile_checkbox )
217             {
218                 OnSubsFileEnable();
219             } else if( (HWND)lp == subsfile_button )
220             {
221                 OnSubsFileSettings( hwnd );
222             } else if( (HWND)lp == browse_button )
223             {
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 DefWindowProc( hwnd, msg, wp, lp );
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_access );
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_access = 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_access = 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_access = 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 static void OnOpenCB( intf_dialog_args_t *p_arg )
667 {
668     OpenDialog *p_this = (OpenDialog *)p_arg->p_arg;
669     char psz_tmp[PATH_MAX+2] = "\0";
670
671     if( p_arg->i_results && p_arg->psz_results[0] )
672     {
673         if( strchr( p_arg->psz_results[0], ' ' ) )
674         {
675             strcat( psz_tmp, "\"" );
676             strcat( psz_tmp, p_arg->psz_results[0] );
677             strcat( psz_tmp, "\"" );
678         }
679         else strcat( psz_tmp, p_arg->psz_results[0] );
680
681         SetWindowText( p_this->file_combo, _FROMMB(psz_tmp) );
682         ComboBox_AddString( p_this->file_combo, _FROMMB(psz_tmp) );
683         if( ComboBox_GetCount( p_this->file_combo ) > 10 ) 
684             ComboBox_DeleteString( p_this->file_combo, 0 );
685
686         p_this->UpdateMRL( FILE_ACCESS );
687     }
688 }
689
690 void OpenDialog::OnFileBrowse()
691 {
692     intf_dialog_args_t *p_arg =
693         (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
694     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
695
696     p_arg->psz_title = strdup( "Open file" );
697     p_arg->psz_extensions = strdup( "All (*.*)|*.*" );
698     p_arg->p_arg = this;
699     p_arg->pf_callback = OnOpenCB;
700
701     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
702 }
703
704 /*****************************************************************************
705  * Net panel event methods.
706  *****************************************************************************/
707 void OpenDialog::OnNetPanelChange( int event )
708 {
709     TCHAR psz_text[2048];
710     int port;
711
712     if( event >= NetPort1_Event && event <= NetPort2_Event )
713     {
714         Edit_GetText( net_ports[event - NetPort1_Event], psz_text, 2048 );
715         _stscanf( psz_text, _T("%d"), &port );
716         i_net_ports[event - NetPort1_Event] = port;
717     }
718
719     UpdateMRL( NET_ACCESS );
720 }
721
722 void OpenDialog::OnNetTypeChange( int event )
723 {
724     DisableNETCtrl();
725
726     i_net_type = event - NetRadio1_Event;
727
728     if( event == NetRadio1_Event )
729     {
730         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
731                       SWP_NOMOVE | SWP_NOSIZE );
732         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
733                       SWP_NOMOVE | SWP_NOSIZE );
734         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
735                       SWP_NOMOVE | SWP_NOSIZE );
736     } 
737     else if( event == NetRadio2_Event )
738     {
739         SetWindowPos( net_addrs_label[1], HWND_TOP, 0, 0, 0, 0,
740                       SWP_NOMOVE | SWP_NOSIZE );
741         SetWindowPos( net_addrs[1], HWND_TOP, 0, 0, 0, 0,
742                       SWP_NOMOVE | SWP_NOSIZE );
743         SetWindowPos( net_port_label[1], HWND_TOP, 0, 0, 0, 0,
744                       SWP_NOMOVE | SWP_NOSIZE );
745         SetWindowPos( net_ports[1], HWND_TOP, 0, 0, 0, 0,
746                       SWP_NOMOVE | SWP_NOSIZE );
747         SetWindowPos( hUpdown[1], HWND_TOP, 0, 0, 0, 0,
748                       SWP_NOMOVE | SWP_NOSIZE );
749     } 
750     else if( event == NetRadio3_Event )
751     {
752         SetWindowPos( net_addrs_label[2], HWND_TOP, 0, 0, 0, 0,
753                       SWP_NOMOVE | SWP_NOSIZE );
754         SetWindowPos( net_addrs[2], HWND_TOP, 0, 0, 0, 0,
755                       SWP_NOMOVE | SWP_NOSIZE );
756     } 
757     else if( event == NetRadio4_Event )
758     {
759         SetWindowPos( net_addrs_label[3], HWND_TOP, 0, 0, 0, 0,
760                       SWP_NOMOVE | SWP_NOSIZE );
761         SetWindowPos( net_addrs[3], HWND_TOP, 0, 0, 0, 0,
762                       SWP_NOMOVE | SWP_NOSIZE );
763     }
764         
765     UpdateMRL( NET_ACCESS );
766 }
767
768 void OpenDialog::DisableNETCtrl()
769 {
770     for( int i=0; i<4; i++ )
771     {
772         SetWindowPos( net_port_label[i], HWND_BOTTOM, 0, 0, 0, 0,
773                       SWP_NOMOVE | SWP_NOSIZE );
774         SetWindowPos( net_ports[i], HWND_BOTTOM, 0, 0, 0, 0,
775                       SWP_NOMOVE | SWP_NOSIZE );
776         SetWindowPos( hUpdown[i], HWND_BOTTOM, 0, 0, 0, 0,
777                       SWP_NOMOVE | SWP_NOSIZE );
778         SetWindowPos( net_addrs_label[i], HWND_BOTTOM, 0, 0, 0, 0,
779                       SWP_NOMOVE | SWP_NOSIZE );
780         SetWindowPos( net_addrs[i], HWND_BOTTOM, 0, 0, 0, 0,
781                       SWP_NOMOVE | SWP_NOSIZE );
782     }
783
784     UpdateMRL( FILE_ACCESS );
785 }
786
787 /*****************************************************************************
788  * Subtitles file event methods.
789  *****************************************************************************/
790 void OpenDialog::OnSubsFileEnable()
791 {
792     EnableWindow( subsfile_button, ( SendMessage( subsfile_checkbox,
793                   BM_GETCHECK, 0, 0 ) & BST_CHECKED ) ? TRUE : FALSE );
794 }
795
796 void OpenDialog::OnSubsFileSettings( HWND hwnd )
797 {
798
799     /* Show/hide the open dialog */
800     SubsFileDialog *subsfile_dialog = new SubsFileDialog( p_intf, this, hInst);
801     CreateDialogBox(  hwnd, subsfile_dialog );
802
803     subsfile_mrl.clear();
804
805     for( int i = 0; i < (int)subsfile_dialog->subsfile_mrl.size(); i++ )
806         subsfile_mrl.push_back( subsfile_dialog->subsfile_mrl[i] );
807
808     delete subsfile_dialog;
809 }