]> git.sesse.net Git - vlc/blob - modules/gui/wince/open.cpp
* modules/gui/wince: cleanup + ported to win32 (but not tried yet ;).
[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     TCHAR psz_text[256];
344
345     struct net_type
346     {
347         TCHAR *psz_text;
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].psz_text,
364                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
365                 rc.left + 5, rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
366
367     net_label[0] = CreateWindow( _T("STATIC"), net_type_array[0].psz_text,
368                 WS_CHILD | WS_VISIBLE | SS_LEFT,
369                 rc.left + 5 + 15 + 5, rc.top + 10, net_type_array[0].length,
370                 15, hwnd, NULL, hInst, NULL );
371
372     i_net_ports[0] = config_GetInt( p_intf, "server-port" );
373
374     net_port_label[0] = CreateWindow( _T("STATIC"), _T("Port"),
375                 WS_CHILD | WS_VISIBLE | SS_LEFT,
376                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
377                 hwnd, NULL, hInst, NULL );
378
379     _stprintf( psz_text, _T("%d"), i_net_ports[0] );
380     net_ports[0] = CreateWindow( _T("EDIT"), psz_text,
381         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
382         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
383         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6, hwnd, NULL, hInst, NULL );
384
385     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
386     ic.dwICC = ICC_UPDOWN_CLASS;
387     InitCommonControlsEx(&ic);
388
389     hUpdown[0] = CreateUpDownControl(
390                 WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
391                 UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
392                 0, 0, 0, 0, hwnd, 0, hInst,
393                 net_ports[0], 16000, 0, i_net_ports[0]);
394
395     /* UDP/RTP Multicast row */
396     net_radios[1] = CreateWindow( _T("BUTTON"), net_type_array[1].psz_text,
397                 WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
398                 rc.left + 5, rc.top + 10 + 15 + 10, 15, 15,
399                 hwnd, NULL, hInst, NULL);
400
401     net_label[1] = CreateWindow( _T("STATIC"), net_type_array[1].psz_text,
402                 WS_CHILD | WS_VISIBLE | SS_LEFT,
403                 rc.left + 5 + 15 + 5, rc.top + 10 + 15 + 10,
404                 net_type_array[1].length, 15, hwnd, NULL, hInst, NULL );
405
406     net_addrs_label[1] = CreateWindow( _T("STATIC"), _T("Address"),
407                 WS_CHILD | WS_VISIBLE | SS_LEFT,
408                 rc.left + 5 , rc.top + 10 + 2*(15 + 10), 50, 15,
409                 hwnd, NULL, hInst, NULL);
410
411     net_addrs[1] = CreateWindow( _T("EDIT"), _T(""),
412                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
413                 rc.left + 5 + 50 + 5, rc.top + 10 + 2*(15 + 10) - 3,
414                 rc.right - 5 - (rc.left + 5 + 50 + 5), 15 + 6,
415                 hwnd, NULL, hInst, NULL);
416
417     net_port_label[1] = CreateWindow( _T("STATIC"), _T("Port"),
418                 WS_CHILD | WS_VISIBLE | SS_LEFT,
419                 rc.left + 5 , rc.top + 10 + 3*(15 + 10), 30, 15,
420                 hwnd, NULL, hInst, NULL);
421
422     i_net_ports[1] = i_net_ports[0];
423
424     _stprintf( psz_text, _T("%d"), i_net_ports[1] );
425     net_ports[1] = CreateWindow( _T("EDIT"), psz_text,
426                 WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
427                 rc.left + 5 + 30 + 5, rc.top + 10 + 3*(15 + 10) - 3,
428                 rc.right - 5 -(rc.left + 5 + 30 + 5), 15 + 6,
429                 hwnd, NULL, hInst, NULL );
430
431     ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
432     ic.dwICC = ICC_UPDOWN_CLASS;
433     InitCommonControlsEx(&ic);
434
435     hUpdown[1] = CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
436         UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
437         0, 0, 0, 0, hwnd, 0, hInst,
438         net_ports[1], 16000, 0, i_net_ports[1] );
439
440     /* HTTP and RTSP rows */
441     net_radios[2] = CreateWindow( _T("BUTTON"), net_type_array[2].psz_text,
442         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
443         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5,
444         rc.top + 10, 15, 15, hwnd, NULL, hInst, NULL );
445         
446     net_label[2] = CreateWindow( _T("STATIC"), net_type_array[2].psz_text,
447         WS_CHILD | WS_VISIBLE | SS_LEFT,
448         rc.left + 5 + 15 + 5 + net_type_array[0].length + 5 + 15 + 5,
449         rc.top + 10, net_type_array[2].length, 15,
450         hwnd, NULL, hInst, NULL );
451
452     net_addrs_label[2] = CreateWindow( _T("STATIC"), _T("URL"),
453         WS_CHILD | WS_VISIBLE | SS_LEFT,
454         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
455         hwnd, NULL, hInst, NULL );
456
457     net_addrs[2] = CreateWindow( _T("EDIT"), _T(""),
458         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
459         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
460         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
461         hwnd, NULL, hInst, NULL);
462
463     net_radios[3] = CreateWindow( _T("BUTTON"), net_type_array[3].psz_text,
464         WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
465         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5,
466         rc.top + 10 + 15 + 10, 15, 15, hwnd, NULL, hInst, NULL );
467
468     net_label[3] = CreateWindow( _T("STATIC"), net_type_array[3].psz_text,
469         WS_CHILD | WS_VISIBLE | SS_LEFT,
470         rc.left + 5 + 15 + 5 + net_type_array[1].length + 5 + 15 + 5,
471         rc.top + 10 + 15 + 10, net_type_array[3].length, 15,
472         hwnd, NULL, hInst, NULL );
473
474     net_addrs_label[3] = CreateWindow( _T("STATIC"), _T("URL"),
475         WS_CHILD | WS_VISIBLE | SS_LEFT,
476         rc.left + 5 , rc.top + 10 + 2*(15 + 10), 30, 15,
477         hwnd, NULL, hInst, NULL );
478
479     net_addrs[3] = CreateWindow( _T("EDIT"), _T("rtsp://"),
480         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
481         rc.left + 5 + 30 + 5, rc.top + 10 + 2*(15 + 10) - 3,
482         rc.right - 5 - (rc.left + 5 + 30 + 5), 15 + 6,
483         hwnd, NULL, hInst, NULL );
484
485     SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
486 }
487
488 void OpenDialog::UpdateMRL()
489 {
490     UpdateMRL( i_current_access_method );
491 }
492
493 void OpenDialog::UpdateMRL( int i_access_method )
494 {
495     string demux, mrltemp;
496     TCHAR psz_text[2048];
497     char psz_tmp[256];
498
499     i_current_access_method = i_access_method;
500
501     switch( i_access_method )
502     {
503     case FILE_ACCESS:
504         GetWindowText( file_combo, psz_text, 2048 );
505         mrltemp = _TOMB(psz_text);
506         break;
507     case NET_ACCESS:
508         switch( i_net_type )
509         {
510         case 0:
511             mrltemp = "udp" + demux + "://";
512             if( i_net_ports[0] !=
513                 config_GetInt( p_intf, "server-port" ) )
514             {
515                 sprintf( psz_tmp, "@:%d", i_net_ports[0] );
516                 mrltemp += psz_tmp;
517             }
518             break;
519
520         case 1:
521             mrltemp = "udp" + demux + "://@";
522             Edit_GetText( net_addrs[1], psz_text, 2048 );
523             mrltemp += _TOMB(psz_text);
524             if( i_net_ports[1] != config_GetInt( p_intf, "server-port" ) )
525             {
526                 sprintf( psz_tmp, ":%d", i_net_ports[1] );
527                 mrltemp += psz_tmp;
528             }
529             break;
530
531         case 2:
532             /* http access */
533             Edit_GetText( net_addrs[2], psz_text, 2048 );
534             if( !strstr( _TOMB(psz_text), "http://" ) )
535             {
536                 mrltemp = "http" + demux + "://";
537             }
538             mrltemp += _TOMB(psz_text);
539             break;
540
541         case 3:
542             /* RTSP access */
543             Edit_GetText( net_addrs[3], psz_text, 2048 );
544             if( !strstr( _TOMB(psz_text), "rtsp://" ) )
545             {
546                 mrltemp = "rtsp" + demux + "://";
547             }
548             mrltemp += _TOMB(psz_text);
549             break;
550         }
551         break;
552     default:
553         break;
554     }
555
556     SetWindowText( mrl_combo, _FROMMB(mrltemp.c_str()) );
557 }
558
559 void OpenDialog::OnPageChange()
560 {
561     if( TabCtrl_GetCurSel( notebook ) == 0 )
562     {
563         for( int i=0; i<4; i++ )
564         {
565             SetWindowPos( net_radios[i], HWND_BOTTOM, 0, 0, 0, 0,
566                           SWP_NOMOVE | SWP_NOSIZE );
567             SetWindowPos( net_label[i], HWND_BOTTOM, 0, 0, 0, 0,
568                           SWP_NOMOVE | SWP_NOSIZE );
569         }
570         DisableNETCtrl();
571
572         SetWindowPos( file_combo, HWND_TOP, 0, 0, 0, 0,
573                       SWP_NOMOVE | SWP_NOSIZE );
574         SetWindowPos( browse_button, HWND_TOP, 0, 0, 0, 0,
575                       SWP_NOMOVE | SWP_NOSIZE );
576         SetWindowPos( subsfile_checkbox, HWND_TOP, 0, 0, 0, 0,
577                       SWP_NOMOVE | SWP_NOSIZE );
578         SetWindowPos( subsfile_label, HWND_TOP, 0, 0, 0, 0,
579                       SWP_NOMOVE | SWP_NOSIZE );
580         SetWindowPos( subsfile_button, HWND_TOP, 0, 0, 0, 0,
581                       SWP_NOMOVE | SWP_NOSIZE );
582
583         i_current_access_method = FILE_ACCESS;
584     }
585     else if ( TabCtrl_GetCurSel( notebook ) == 1 )
586     {
587         SetWindowPos( file_combo, HWND_BOTTOM, 0, 0, 0, 0,
588                       SWP_NOMOVE | SWP_NOSIZE );
589         SetWindowPos( browse_button, HWND_BOTTOM, 0, 0, 0, 0,
590                       SWP_NOMOVE | SWP_NOSIZE );
591         SetWindowPos( subsfile_checkbox, HWND_BOTTOM, 0, 0, 0, 0,
592                       SWP_NOMOVE | SWP_NOSIZE );
593         SetWindowPos( subsfile_label, HWND_BOTTOM, 0, 0, 0, 0,
594                       SWP_NOMOVE | SWP_NOSIZE );
595         SetWindowPos( subsfile_button, HWND_BOTTOM, 0, 0, 0, 0,
596                       SWP_NOMOVE | SWP_NOSIZE );
597
598         for( int i=0; i<4; i++ )
599         {
600             SetWindowPos( net_radios[i], HWND_TOP, 0, 0, 0, 0,
601                           SWP_NOMOVE | SWP_NOSIZE );
602             SendMessage( net_radios[i], BM_SETCHECK, BST_UNCHECKED, 0 );
603             SetWindowPos( net_label[i], HWND_TOP, 0, 0, 0, 0,
604                           SWP_NOMOVE | SWP_NOSIZE );
605         }
606         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
607                       SWP_NOMOVE | SWP_NOSIZE );
608         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
609                       SWP_NOMOVE | SWP_NOSIZE );
610         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
611                       SWP_NOMOVE | SWP_NOSIZE );
612
613         SendMessage( net_radios[0], BM_SETCHECK, BST_CHECKED, 0 );
614
615         i_current_access_method = NET_ACCESS;
616     }
617
618     UpdateMRL();
619 }
620
621 void OpenDialog::OnOk()
622 {
623     TCHAR psz_text[2048];
624
625     GetWindowText( mrl_combo, psz_text, 2048 ); // replace by ComboBox_GetText( mrl_combo, wUnicode, size )
626     mrl = SeparateEntries( psz_text );
627     ComboBox_AddString( mrl_combo, psz_text );
628     if( ComboBox_GetCount( mrl_combo ) > 10 ) 
629         ComboBox_DeleteString( mrl_combo, 0 );
630     ComboBox_SetCurSel( mrl_combo, ComboBox_GetCount( mrl_combo ) - 1 );
631
632     /* Update the playlist */
633     playlist_t *p_playlist =
634         (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
635                                        FIND_ANYWHERE );
636     if( p_playlist == NULL ) return;
637
638     for( int i = 0; i < (int)mrl.size(); i++ )
639     {
640         vlc_bool_t b_start = !i && i_open_arg;
641         playlist_item_t *p_item =
642             playlist_ItemNew( p_intf, (const char*)mrl[i].c_str(),
643                               (const char *)mrl[i].c_str() );
644
645         /* Insert options */
646         while( i + 1 < (int)mrl.size() &&
647                ((const char *)mrl[i + 1].c_str())[0] == ':' )
648         {
649             playlist_ItemAddOption( p_item, mrl[i + 1].c_str() );
650             i++;
651         }
652
653         /* Get the options from the subtitles dialog */
654         if( (SendMessage( subsfile_checkbox, BM_GETCHECK, 0, 0 ) & BST_CHECKED)
655             && subsfile_mrl.size() )
656         {
657             for( int j = 0; j < (int)subsfile_mrl.size(); j++ )
658             {
659                 playlist_ItemAddOption( p_item, subsfile_mrl[j].c_str() );
660             }
661         }
662
663         playlist_AddItem( p_playlist, p_item,
664                           PLAYLIST_APPEND, PLAYLIST_END );
665
666         if( b_start )
667         {
668             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY , p_item );
669         }
670     }
671
672     //TogglePlayButton( PLAYING_S );
673
674     vlc_object_release( p_playlist );
675 }
676
677 /*****************************************************************************
678  * File panel event methods.
679  *****************************************************************************/
680 void OpenDialog::OnFilePanelChange()
681 {
682     UpdateMRL( FILE_ACCESS );
683 }
684
685 void OpenDialog::OnFileBrowse()
686 {       
687     OPENFILENAME ofn;
688     static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");
689     TCHAR psz_file[PATH_MAX] = _T("\0");
690     TCHAR psz_tmp[PATH_MAX+2] = _T("\0");
691
692     memset(&ofn, 0, sizeof(OPENFILENAME));
693     ofn.lStructSize = sizeof (OPENFILENAME);
694     ofn.hwndOwner = NULL;
695     ofn.hInstance = hInst;
696     ofn.lpstrFilter = szFilter;
697     ofn.lpstrCustomFilter = NULL;
698     ofn.nMaxCustFilter = 0;
699     ofn.nFilterIndex = 1;     
700     ofn.lpstrFile = psz_file; 
701     ofn.nMaxFile = PATH_MAX;
702     ofn.lpstrFileTitle = NULL; 
703     ofn.nMaxFileTitle = 40;
704     ofn.lpstrInitialDir = NULL;
705     ofn.lpstrTitle = _T("Open File");
706     ofn.Flags = 0;
707     ofn.nFileOffset = 0;
708     ofn.nFileExtension = 0;
709     ofn.lpstrDefExt = NULL;
710     ofn.lCustData = 0L;
711     ofn.lpfnHook = NULL;
712     ofn.lpTemplateName = NULL;
713     if( GetOpenFileName((LPOPENFILENAME) &ofn) )
714     {
715         if( _tcschr( ofn.lpstrFile, _T(' ') ) )
716         {
717             _tcscat( psz_tmp, _T("\"") );
718             _tcscat( psz_tmp, ofn.lpstrFile );
719             _tcscat( psz_tmp, _T("\"") );
720         }
721         else _tcscat( psz_tmp, ofn.lpstrFile );
722
723         SetWindowText( file_combo, psz_tmp );
724         ComboBox_AddString( file_combo, psz_tmp );
725         if( ComboBox_GetCount( file_combo ) > 10 ) 
726             ComboBox_DeleteString( file_combo, 0 );
727
728         UpdateMRL( FILE_ACCESS );
729     }
730 }
731
732 /*****************************************************************************
733  * Net panel event methods.
734  *****************************************************************************/
735 void OpenDialog::OnNetPanelChange( int event )
736 {
737     TCHAR psz_text[2048];
738     int port;
739
740     if( event >= NetPort1_Event && event <= NetPort2_Event )
741     {
742         Edit_GetText( net_ports[event - NetPort1_Event], psz_text, 2048 );
743         _stscanf( psz_text, _T("%d"), &port );
744         i_net_ports[event - NetPort1_Event] = port;
745     }
746
747     UpdateMRL( NET_ACCESS );
748 }
749
750 void OpenDialog::OnNetTypeChange( int event )
751 {
752     DisableNETCtrl();
753
754     i_net_type = event - NetRadio1_Event;
755
756     if( event == NetRadio1_Event )
757     {
758         SetWindowPos( net_port_label[0], HWND_TOP, 0, 0, 0, 0,
759                       SWP_NOMOVE | SWP_NOSIZE );
760         SetWindowPos( net_ports[0], HWND_TOP, 0, 0, 0, 0,
761                       SWP_NOMOVE | SWP_NOSIZE );
762         SetWindowPos( hUpdown[0], HWND_TOP, 0, 0, 0, 0,
763                       SWP_NOMOVE | SWP_NOSIZE );
764     } 
765     else if( event == NetRadio2_Event )
766     {
767         SetWindowPos( net_addrs_label[1], HWND_TOP, 0, 0, 0, 0,
768                       SWP_NOMOVE | SWP_NOSIZE );
769         SetWindowPos( net_addrs[1], HWND_TOP, 0, 0, 0, 0,
770                       SWP_NOMOVE | SWP_NOSIZE );
771         SetWindowPos( net_port_label[1], HWND_TOP, 0, 0, 0, 0,
772                       SWP_NOMOVE | SWP_NOSIZE );
773         SetWindowPos( net_ports[1], HWND_TOP, 0, 0, 0, 0,
774                       SWP_NOMOVE | SWP_NOSIZE );
775         SetWindowPos( hUpdown[1], HWND_TOP, 0, 0, 0, 0,
776                       SWP_NOMOVE | SWP_NOSIZE );
777     } 
778     else if( event == NetRadio3_Event )
779     {
780         SetWindowPos( net_addrs_label[2], HWND_TOP, 0, 0, 0, 0,
781                       SWP_NOMOVE | SWP_NOSIZE );
782         SetWindowPos( net_addrs[2], HWND_TOP, 0, 0, 0, 0,
783                       SWP_NOMOVE | SWP_NOSIZE );
784     } 
785     else if( event == NetRadio4_Event )
786     {
787         SetWindowPos( net_addrs_label[3], HWND_TOP, 0, 0, 0, 0,
788                       SWP_NOMOVE | SWP_NOSIZE );
789         SetWindowPos( net_addrs[3], HWND_TOP, 0, 0, 0, 0,
790                       SWP_NOMOVE | SWP_NOSIZE );
791     }
792         
793     UpdateMRL( NET_ACCESS );
794 }
795
796 void OpenDialog::DisableNETCtrl()
797 {
798     for( int i=0; i<4; i++ )
799     {
800         SetWindowPos( net_port_label[i], HWND_BOTTOM, 0, 0, 0, 0,
801                       SWP_NOMOVE | SWP_NOSIZE );
802         SetWindowPos( net_ports[i], HWND_BOTTOM, 0, 0, 0, 0,
803                       SWP_NOMOVE | SWP_NOSIZE );
804         SetWindowPos( hUpdown[i], HWND_BOTTOM, 0, 0, 0, 0,
805                       SWP_NOMOVE | SWP_NOSIZE );
806         SetWindowPos( net_addrs_label[i], HWND_BOTTOM, 0, 0, 0, 0,
807                       SWP_NOMOVE | SWP_NOSIZE );
808         SetWindowPos( net_addrs[i], HWND_BOTTOM, 0, 0, 0, 0,
809                       SWP_NOMOVE | SWP_NOSIZE );
810     }
811
812     UpdateMRL( FILE_ACCESS );
813 }
814
815 /*****************************************************************************
816  * Subtitles file event methods.
817  *****************************************************************************/
818 void OpenDialog::OnSubsFileEnable()
819 {
820     EnableWindow( subsfile_button, ( SendMessage( subsfile_checkbox,
821                   BM_GETCHECK, 0, 0 ) & BST_CHECKED ) ? TRUE : FALSE );
822 }
823
824 void OpenDialog::OnSubsFileSettings( HWND hwnd )
825 {
826
827     /* Show/hide the open dialog */
828     SubsFileDialog *subsfile_dialog = new SubsFileDialog( p_intf, hInst );
829     DialogBoxParam( hInst, (LPCTSTR)IDD_DUMMY, hwnd,
830                     (DLGPROC)subsfile_dialog->BaseWndProc,
831                     (long)subsfile_dialog );
832
833     subsfile_mrl.clear();
834
835     for( int i = 0; i < (int)subsfile_dialog->subsfile_mrl.size(); i++ )
836         subsfile_mrl.push_back( subsfile_dialog->subsfile_mrl[i] );
837
838     delete subsfile_dialog;
839 }
840
841 /*****************************************************************************
842  * Utility functions.
843  *****************************************************************************/
844 vector<string> SeparateEntries( TCHAR *entries )
845 {
846     vlc_bool_t b_quotes_mode = VLC_FALSE;
847     vector<string> entries_array;
848     TCHAR *entry = new TCHAR[ _tcslen(entries) + 1 ];
849     TCHAR *strToken = entries;
850     int length = _tcscspn( strToken, _T(" \t\r\n\"") );
851     *entry = 0;
852
853     while( strToken - entries < _tcslen(entries) )
854     { 
855         _tcsncat( entry, strToken, length );
856
857         _tcsncat( entry, strToken + length, 1 );
858
859         if( !b_quotes_mode && strToken[length] == _T('\"') )
860         {
861             /* Enters quotes mode */
862             entry[ _tcslen(entry) - 1 ] = 0;
863             b_quotes_mode = VLC_TRUE;
864         }
865         else if( b_quotes_mode && strToken[length] == _T('\"') )
866         {
867             /* Finished the quotes mode */
868             entry[ _tcslen(entry) - 1 ] = 0;
869             if( _tcscmp( entry, _T("") ) != 0 )
870             {
871                 entries_array.push_back( _TOMB(entry) );
872             }
873             *entry = 0;
874             b_quotes_mode = VLC_FALSE;
875         }
876         else if( !b_quotes_mode && strToken[length] != _T('\"') )
877         {
878             /* we found a non-quoted standalone string */
879             if( strToken + length - entries < _tcslen(entries) ||/*token.HasMoreTokens() ||*/ //FIX ME IF YOU CAN
880                 strToken[length] == _T(' ') ||
881                 strToken[length] == _T('\t') ||
882                 strToken[length] == _T('\r') ||
883                 strToken[length] == _T('\n') )
884               entry[ _tcslen(entry) - 1 ]/*strToken[length]*/ = 0;
885             if( _tcscmp( entry, _T("") ) != 0 )
886             {
887                 entries_array.push_back( _TOMB(entry) );
888             }
889             *entry = 0;
890         }
891         else
892         {;}
893
894         strToken += length + 1;
895         length = _tcscspn( strToken, _T(" \t\r\n\"") );
896     }
897
898     if( _tcscmp( entry, _T("") ) != 0 )
899     {
900         entries_array.push_back( _TOMB(entry) );
901     }
902
903     delete [] entry;
904     return entries_array;
905 }