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