Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

subtitles.cpp

00001 /*****************************************************************************
00002  * subtitles.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2001 the VideoLAN team
00005  * $Id: subtitles.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/intf.h>
00033 
00034 #include "wince.h"
00035 
00036 #include <winuser.h>
00037 #include <windows.h>
00038 #include <windowsx.h>
00039 #include <commctrl.h>
00040 #include <commdlg.h>
00041 
00042 /*****************************************************************************
00043  * Event Table.
00044  *****************************************************************************/
00045 
00046 /*****************************************************************************
00047  * Constructor.
00048  *****************************************************************************/
00049 SubsFileDialog::SubsFileDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
00050                                 HINSTANCE h_inst )
00051   :  CBaseWindow( p_intf, p_parent, h_inst )
00052 {
00053 }
00054 
00055 /***********************************************************************
00056 
00057 FUNCTION: 
00058   WndProc
00059 
00060 PURPOSE: 
00061   Processes messages sent to the main window.
00062   
00063 ***********************************************************************/
00064 LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
00065 {
00066     SHINITDLGINFO shidi;
00067     SHMENUBARINFO mbi;
00068     INITCOMMONCONTROLSEX ic;
00069     RECT rcClient;
00070 
00071     char *psz_subsfile;
00072     module_config_t *p_item;
00073     float f_fps;
00074     int i_delay;
00075 
00076     TCHAR psz_text[256];
00077 
00078     switch( msg )
00079     {
00080     case WM_INITDIALOG:
00081         shidi.dwMask = SHIDIM_FLAGS;
00082         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
00083         shidi.hDlg = hwnd;
00084         SHInitDialog( &shidi );
00085 
00086         //Create the menubar.
00087         memset (&mbi, 0, sizeof (SHMENUBARINFO));
00088         mbi.cbSize     = sizeof (SHMENUBARINFO);
00089         mbi.hwndParent = hwnd;
00090         mbi.dwFlags    = SHCMBF_EMPTYBAR;
00091         mbi.hInstRes   = hInst;
00092 
00093         if (!SHCreateMenuBar(&mbi))
00094         {
00095             MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
00096             //return -1;
00097         }
00098 
00099         hwndCB = mbi.hwndMB;
00100 
00101         // Get the client area rect to put the panels in
00102         GetClientRect(hwnd, &rcClient);
00103 
00104         /* Create the subtitles file textctrl */
00105         file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
00106                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
00107                                  5, 10, rcClient.right - 2*5, 15,
00108                                  hwnd, NULL, hInst, NULL );
00109 
00110         psz_subsfile = config_GetPsz( p_intf, "sub-file" );
00111         if( !psz_subsfile ) psz_subsfile = strdup("");
00112 
00113         file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
00114             WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
00115             10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
00116             hwnd, NULL, hInst, NULL );
00117 
00118         if( psz_subsfile ) free( psz_subsfile );
00119 
00120         browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
00121                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
00122                         10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
00123                         hwnd, NULL, hInst, NULL);
00124 
00125         /* Subtitles encoding */
00126         encoding_combo = NULL;
00127         p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
00128         if( p_item )
00129         {
00130             enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
00131                         WS_CHILD | WS_VISIBLE | SS_LEFT,
00132                         5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
00133                         hwnd, NULL, hInst, NULL );
00134 
00135             enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00136                 WS_CHILD | WS_VISIBLE | SS_LEFT,
00137                 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
00138                 hwnd, NULL, hInst, NULL );
00139 
00140             encoding_combo = CreateWindow( _T("COMBOBOX"),
00141                 _FROMMB(p_item->psz_value),
00142                 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
00143                 LBS_SORT  | WS_VSCROLL,
00144                 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
00145                 hwnd, NULL, hInst, NULL );
00146 
00147             /* build a list of available options */
00148             for( int i_index = 0; p_item->ppsz_list &&
00149                    p_item->ppsz_list[i_index]; i_index++ )
00150             {
00151                 ComboBox_AddString( encoding_combo,
00152                                     _FROMMB(p_item->ppsz_list[i_index]) );
00153 
00154                 if( p_item->psz_value &&
00155                     !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
00156                     ComboBox_SetCurSel( encoding_combo, i_index );
00157             }
00158 
00159             if( p_item->psz_value )
00160             {
00161                 ComboBox_SelectString( encoding_combo, 0,
00162                                        _FROMMB(p_item->psz_value) );
00163 
00164             }
00165         }
00166 
00167         /* Misc Subtitles options */
00168         misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
00169                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
00170                                  5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
00171                                  hwnd, NULL, hInst, NULL );
00172 
00173         delay_label = CreateWindow( _T("STATIC"),
00174                                     _T("Delay subtitles (in 1/10s)"),
00175                                     WS_CHILD | WS_VISIBLE | SS_LEFT,
00176                                     10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
00177                                     hwnd, NULL, hInst, NULL );
00178 
00179         i_delay = config_GetInt( p_intf, "sub-delay" );
00180         _stprintf( psz_text, _T("%d"), i_delay );
00181 
00182         delay_edit = CreateWindow( _T("EDIT"), psz_text,
00183             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
00184             rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
00185             hwnd, NULL, hInst, NULL );
00186 
00187         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
00188         ic.dwICC = ICC_UPDOWN_CLASS;
00189         InitCommonControlsEx(&ic);
00190 
00191         delay_spinctrl =
00192             CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
00193                 UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
00194                 0, 0, 0, 0, hwnd, 0, hInst,
00195                 delay_edit, 650000, -650000, i_delay );
00196 
00197         fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
00198                         WS_CHILD | WS_VISIBLE | SS_LEFT,
00199                         10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
00200                         hwnd, NULL, hInst, NULL );
00201 
00202         f_fps = config_GetFloat( p_intf, "sub-fps" );
00203         _stprintf( psz_text, _T("%f"), f_fps );
00204 
00205         fps_edit = CreateWindow( _T("EDIT"), psz_text,
00206             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
00207             rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
00208             hwnd, NULL, hInst, NULL);
00209 
00210         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
00211         ic.dwICC = ICC_UPDOWN_CLASS;
00212         InitCommonControlsEx(&ic);
00213 
00214         fps_spinctrl = CreateUpDownControl(
00215             WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
00216             UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
00217             0, 0, 0, 0, hwnd, 0, hInst, fps_edit, 16000, 0, (int)f_fps );
00218 
00219         break;
00220 
00221     case WM_CLOSE:
00222         EndDialog( hwnd, LOWORD( wp ) );
00223         break;
00224 
00225     case WM_SETFOCUS:
00226         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
00227         break;
00228 
00229     case WM_COMMAND:
00230         if ( LOWORD(wp) == IDOK )
00231         {
00232             subsfile_mrl.clear();
00233 
00234             string szFileCombo = "sub-file=";
00235             GetWindowText( file_combo, psz_text, 256 );
00236             szFileCombo += _TOMB(psz_text);
00237             subsfile_mrl.push_back( szFileCombo );
00238 
00239             if( GetWindowTextLength( encoding_combo ) != 0 )
00240             {
00241                 string szEncoding = "subsdec-encoding=";
00242                 GetWindowText( encoding_combo, psz_text, 256 );
00243                 szEncoding += _TOMB(psz_text);
00244                 subsfile_mrl.push_back( szEncoding );
00245             }
00246 
00247             string szDelay = "sub-delay=";
00248             Edit_GetText( delay_edit, psz_text, 256 );
00249             szDelay += _TOMB(psz_text);
00250             subsfile_mrl.push_back( szDelay );
00251 
00252             string szFps = "sub-fps=";
00253             Edit_GetText( fps_edit, psz_text, 256 );
00254             szFps += _TOMB(psz_text);
00255             subsfile_mrl.push_back( szFps );
00256 
00257             EndDialog( hwnd, LOWORD( wp ) );
00258             break;
00259         }
00260         if( HIWORD(wp) == BN_CLICKED )
00261         {
00262             if ((HWND)lp == browse_button)
00263             {
00264                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
00265                 OnFileBrowse();
00266             } 
00267         }
00268         break;
00269 
00270     default:
00271         break;
00272     }
00273 
00274     return FALSE;
00275 }
00276 
00277 /*****************************************************************************
00278  * Private methods.
00279  *****************************************************************************/
00280 
00281 /*****************************************************************************
00282  * Events methods.
00283  *****************************************************************************/
00284 static void OnOpenCB( intf_dialog_args_t *p_arg )
00285 {
00286     SubsFileDialog *p_this = (SubsFileDialog *)p_arg->p_arg;
00287 
00288     if( p_arg->i_results && p_arg->psz_results[0] )
00289     {
00290         SetWindowText( p_this->file_combo, _FROMMB(p_arg->psz_results[0]) );
00291         ComboBox_AddString( p_this->file_combo,
00292                             _FROMMB(p_arg->psz_results[0]) );
00293         if( ComboBox_GetCount( p_this->file_combo ) > 10 )
00294             ComboBox_DeleteString( p_this->file_combo, 0 );
00295     }
00296 }
00297 
00298 void SubsFileDialog::OnFileBrowse()
00299 {
00300     intf_dialog_args_t *p_arg =
00301         (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
00302     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
00303 
00304     p_arg->psz_title = strdup( "Open file" );
00305     p_arg->psz_extensions = strdup( "All|*.*" );
00306     p_arg->p_arg = this;
00307     p_arg->pf_callback = OnOpenCB;
00308 
00309     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
00310 }

Generated on Tue Dec 20 10:14:46 2005 for vlc-0.8.4a by  doxygen 1.4.2