subtitles.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:11k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * subtitles.cpp : WinCE gui plugin for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2000-2001 the VideoLAN team
  5.  * $Id: a1067bb910e1262edf1400ecb652a7c79441e458 $
  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.  * Preamble
  26.  *****************************************************************************/
  27. #ifdef HAVE_CONFIG_H
  28. # include "config.h"
  29. #endif
  30. #include <vlc_common.h>
  31. #include <vlc_interface.h>
  32. #include "wince.h"
  33. #include <winuser.h>
  34. #include <windows.h>
  35. #include <windowsx.h>
  36. #include <commctrl.h>
  37. #include <commdlg.h>
  38. /*****************************************************************************
  39.  * Event Table.
  40.  *****************************************************************************/
  41. /*****************************************************************************
  42.  * Constructor.
  43.  *****************************************************************************/
  44. SubsFileDialog::SubsFileDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
  45.                                 HINSTANCE h_inst )
  46.   :  CBaseWindow( p_intf, p_parent, h_inst )
  47. {
  48. }
  49. /***********************************************************************
  50. FUNCTION:
  51.   WndProc
  52. PURPOSE:
  53.   Processes messages sent to the main window.
  54.  
  55. ***********************************************************************/
  56. LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
  57. {
  58.     SHINITDLGINFO shidi;
  59.     SHMENUBARINFO mbi;
  60.     INITCOMMONCONTROLSEX ic;
  61.     RECT rcClient;
  62.     char *psz_subsfile;
  63.     module_config_t *p_item;
  64.     float f_fps;
  65.     int i_delay;
  66.     TCHAR psz_text[256];
  67.     switch( msg )
  68.     {
  69.     case WM_INITDIALOG:
  70.         shidi.dwMask = SHIDIM_FLAGS;
  71.         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
  72.         shidi.hDlg = hwnd;
  73.         SHInitDialog( &shidi );
  74.         //Create the menubar.
  75.         memset (&mbi, 0, sizeof (SHMENUBARINFO));
  76.         mbi.cbSize     = sizeof (SHMENUBARINFO);
  77.         mbi.hwndParent = hwnd;
  78.         mbi.dwFlags    = SHCMBF_EMPTYBAR;
  79.         mbi.hInstRes   = hInst;
  80.         if (!SHCreateMenuBar(&mbi))
  81.         {
  82.             MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
  83.             //return -1;
  84.         }
  85.         hwndCB = mbi.hwndMB;
  86.         // Get the client area rect to put the panels in
  87.         GetClientRect(hwnd, &rcClient);
  88.         /* Create the subtitles file textctrl */
  89.         file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
  90.                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
  91.                                  5, 10, rcClient.right - 2*5, 15,
  92.                                  hwnd, NULL, hInst, NULL );
  93.         psz_subsfile = config_GetPsz( p_intf, "sub-file" );
  94.         if( !psz_subsfile ) psz_subsfile = strdup("");
  95.         file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
  96.             WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
  97.             10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
  98.             hwnd, NULL, hInst, NULL );
  99.         free( psz_subsfile );
  100.         browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
  101.                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  102.                         10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
  103.                         hwnd, NULL, hInst, NULL);
  104.         /* Subtitles encoding */
  105.         encoding_combo = NULL;
  106.         p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
  107.         if( p_item )
  108.         {
  109.             enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
  110.                         WS_CHILD | WS_VISIBLE | SS_LEFT,
  111.                         5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
  112.                         hwnd, NULL, hInst, NULL );
  113.             enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
  114.                 WS_CHILD | WS_VISIBLE | SS_LEFT,
  115.                 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
  116.                 hwnd, NULL, hInst, NULL );
  117.             encoding_combo = CreateWindow( _T("COMBOBOX"),
  118.                 _FROMMB(p_item->value.psz),
  119.                 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
  120.                 LBS_SORT  | WS_VSCROLL,
  121.                 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
  122.                 hwnd, NULL, hInst, NULL );
  123.             /* build a list of available options */
  124.             for( int i_index = 0; p_item->ppsz_list &&
  125.                    p_item->ppsz_list[i_index]; i_index++ )
  126.             {
  127.                 ComboBox_AddString( encoding_combo,
  128.                                     _FROMMB(p_item->ppsz_list[i_index]) );
  129.                 if( p_item->value.psz &&
  130.                     !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
  131.                     ComboBox_SetCurSel( encoding_combo, i_index );
  132.             }
  133.             if( p_item->value.psz )
  134.             {
  135.                 ComboBox_SelectString( encoding_combo, 0,
  136.                                        _FROMMB(p_item->value.psz) );
  137.             }
  138.         }
  139.         /* Misc Subtitles options */
  140.         misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
  141.                                  WS_CHILD | WS_VISIBLE | SS_LEFT,
  142.                                  5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
  143.                                  hwnd, NULL, hInst, NULL );
  144.         delay_label = CreateWindow( _T("STATIC"),
  145.                                     _T("Delay subtitles (in 1/10s)"),
  146.                                     WS_CHILD | WS_VISIBLE | SS_LEFT,
  147.                                     10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
  148.                                     hwnd, NULL, hInst, NULL );
  149.         i_delay = config_GetInt( p_intf, "sub-delay" );
  150.         _stprintf( psz_text, _T("%d"), i_delay );
  151.         delay_edit = CreateWindow( _T("EDIT"), psz_text,
  152.             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
  153.             rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
  154.             hwnd, NULL, hInst, NULL );
  155.         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
  156.         ic.dwICC = ICC_UPDOWN_CLASS;
  157.         InitCommonControlsEx(&ic);
  158.         delay_spinctrl =
  159.             CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
  160.                 UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
  161.                 0, 0, 0, 0, hwnd, 0, hInst,
  162.                 delay_edit, 650000, -650000, i_delay );
  163.         fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
  164.                         WS_CHILD | WS_VISIBLE | SS_LEFT,
  165.                         10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
  166.                         hwnd, NULL, hInst, NULL );
  167.         f_fps = config_GetFloat( p_intf, "sub-fps" );
  168.         _stprintf( psz_text, _T("%f"), f_fps );
  169.         fps_edit = CreateWindow( _T("EDIT"), psz_text,
  170.             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
  171.             rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
  172.             hwnd, NULL, hInst, NULL);
  173.         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
  174.         ic.dwICC = ICC_UPDOWN_CLASS;
  175.         InitCommonControlsEx(&ic);
  176.         fps_spinctrl = CreateUpDownControl(
  177.             WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
  178.             UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
  179.             0, 0, 0, 0, hwnd, 0, hInst, fps_edit, 16000, 0, (int)f_fps );
  180.         break;
  181.     case WM_CLOSE:
  182.         EndDialog( hwnd, LOWORD( wp ) );
  183.         break;
  184.     case WM_SETFOCUS:
  185.         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
  186.         break;
  187.     case WM_COMMAND:
  188.         if ( LOWORD(wp) == IDOK )
  189.         {
  190.             subsfile_mrl.clear();
  191.             string szFileCombo = "sub-file=";
  192.             GetWindowText( file_combo, psz_text, 256 );
  193.             szFileCombo += _TOMB(psz_text);
  194.             subsfile_mrl.push_back( szFileCombo );
  195.             if( GetWindowTextLength( encoding_combo ) != 0 )
  196.             {
  197.                 string szEncoding = "subsdec-encoding=";
  198.                 GetWindowText( encoding_combo, psz_text, 256 );
  199.                 szEncoding += _TOMB(psz_text);
  200.                 subsfile_mrl.push_back( szEncoding );
  201.             }
  202.             string szDelay = "sub-delay=";
  203.             Edit_GetText( delay_edit, psz_text, 256 );
  204.             szDelay += _TOMB(psz_text);
  205.             subsfile_mrl.push_back( szDelay );
  206.             string szFps = "sub-fps=";
  207.             Edit_GetText( fps_edit, psz_text, 256 );
  208.             szFps += _TOMB(psz_text);
  209.             subsfile_mrl.push_back( szFps );
  210.             EndDialog( hwnd, LOWORD( wp ) );
  211.             break;
  212.         }
  213.         if( HIWORD(wp) == BN_CLICKED )
  214.         {
  215.             if ((HWND)lp == browse_button)
  216.             {
  217.                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
  218.                 OnFileBrowse();
  219.             }
  220.         }
  221.         break;
  222.     default:
  223.         break;
  224.     }
  225.     return FALSE;
  226. }
  227. /*****************************************************************************
  228.  * Private methods.
  229.  *****************************************************************************/
  230. /*****************************************************************************
  231.  * Events methods.
  232.  *****************************************************************************/
  233. static void OnOpenCB( intf_dialog_args_t *p_arg )
  234. {
  235.     SubsFileDialog *p_this = (SubsFileDialog *)p_arg->p_arg;
  236.     if( p_arg->i_results && p_arg->psz_results[0] )
  237.     {
  238.         SetWindowText( p_this->file_combo, _FROMMB(p_arg->psz_results[0]) );
  239.         ComboBox_AddString( p_this->file_combo,
  240.                             _FROMMB(p_arg->psz_results[0]) );
  241.         if( ComboBox_GetCount( p_this->file_combo ) > 10 )
  242.             ComboBox_DeleteString( p_this->file_combo, 0 );
  243.     }
  244. }
  245. void SubsFileDialog::OnFileBrowse()
  246. {
  247.     intf_dialog_args_t *p_arg =
  248.         (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
  249.     memset( p_arg, 0, sizeof(intf_dialog_args_t) );
  250.     p_arg->psz_title = strdup( "Open file" );
  251.     p_arg->psz_extensions = strdup( "All|*.*" );
  252.     p_arg->p_arg = this;
  253.     p_arg->pf_callback = OnOpenCB;
  254.     p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
  255. }