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