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