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