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