subtitles.cpp 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*****************************************************************************
 * subtitles.cpp : WinCE gui plugin for VLC
 *****************************************************************************
 * Copyright (C) 2000-2001 VideoLAN
 * $Id$
 *
 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
 *          Gildas Bazin <gbazin@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
28 29 30
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>                                            /* strerror() */
#include <stdio.h>
31 32 33
#include <vlc/vlc.h>
#include <vlc/intf.h>

34
#include "wince.h"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

#include <winuser.h>
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <commdlg.h>

/*****************************************************************************
 * Event Table.
 *****************************************************************************/

/*****************************************************************************
 * Constructor.
 *****************************************************************************/
SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
{
    /* Initializations */
    p_intf = _p_intf;
    hInst = _hInst;
}

/***********************************************************************

FUNCTION: 
  WndProc

PURPOSE: 
  Processes messages sent to the main window.
  
***********************************************************************/
65
LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
66 67 68 69 70 71 72
{
    SHINITDLGINFO shidi;
    SHMENUBARINFO mbi;
    INITCOMMONCONTROLSEX ic;
    RECT rcClient;

    char *psz_subsfile;
73
    module_config_t *p_item;
74 75
    float f_fps;
    int i_delay;
76 77

    TCHAR psz_text[256];
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    switch( msg )
    {
    case WM_INITDIALOG:
        shidi.dwMask = SHIDIM_FLAGS;
        shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
        shidi.hDlg = hwnd;
        SHInitDialog( &shidi );

        //Create the menubar.
        memset (&mbi, 0, sizeof (SHMENUBARINFO));
        mbi.cbSize     = sizeof (SHMENUBARINFO);
        mbi.hwndParent = hwnd;
        mbi.nToolBarId = IDR_DUMMYMENU;
        mbi.hInstRes   = hInst;
        mbi.nBmpId     = 0;
        mbi.cBmpImages = 0;

        if (!SHCreateMenuBar(&mbi))
        {
98
            MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
            //return -1;
        }

        hwndCB = mbi.hwndMB;

        // Get the client area rect to put the panels in
        GetClientRect(hwnd, &rcClient);

        /* Create the subtitles file textctrl */
        file_box = CreateWindow( _T("STATIC"), _T("Subtitles file"),
                                 WS_CHILD | WS_VISIBLE | SS_LEFT,
                                 5, 10, rcClient.right - 2*5, 15,
                                 hwnd, NULL, hInst, NULL );

        psz_subsfile = config_GetPsz( p_intf, "sub-file" );
        if( !psz_subsfile ) psz_subsfile = strdup("");

116
        file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
117 118 119 120 121 122 123 124 125 126 127 128 129
            WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL,
            10, 10 + 15 + 10 - 3, rcClient.right - 2*10, 5*15 + 6,
            hwnd, NULL, hInst, NULL );

        if( psz_subsfile ) free( psz_subsfile );

        browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
                        WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                        10, 10 + 2*(15 + 10) - 3, 80, 15 + 6,
                        hwnd, NULL, hInst, NULL);

        /* Subtitles encoding */
        encoding_combo = NULL;
130
        p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
131
        if( p_item )
132 133
        {
            enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
134 135 136 137
                        WS_CHILD | WS_VISIBLE | SS_LEFT,
                        5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
                        hwnd, NULL, hInst, NULL );

138
            enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
139 140 141 142
                WS_CHILD | WS_VISIBLE | SS_LEFT,
                10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
                hwnd, NULL, hInst, NULL );

143 144 145 146
            encoding_combo = CreateWindow( _T("COMBOBOX"),
                _FROMMB(p_item->psz_value),
                WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
                LBS_SORT  | WS_VSCROLL,
147 148 149
                rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
                hwnd, NULL, hInst, NULL );

150 151 152 153 154 155
            /* build a list of available options */
            for( int i_index = 0; p_item->ppsz_list &&
                   p_item->ppsz_list[i_index]; i_index++ )
            {
                ComboBox_AddString( encoding_combo,
                                    _FROMMB(p_item->ppsz_list[i_index]) );
156

157 158 159 160
                if( p_item->psz_value &&
                    !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
                    ComboBox_SetCurSel( encoding_combo, i_index );
            }
161

162 163 164 165
            if( p_item->psz_value )
            {
                ComboBox_SelectString( encoding_combo, 0,
                                       _FROMMB(p_item->psz_value) );
166

167 168
            }
        }
169 170 171 172 173 174 175

        /* Misc Subtitles options */
        misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
                                 WS_CHILD | WS_VISIBLE | SS_LEFT,
                                 5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
                                 hwnd, NULL, hInst, NULL );

176 177
        delay_label = CreateWindow( _T("STATIC"),
                                    _T("Delay subtitles (in 1/10s)"),
178 179 180 181 182
                                    WS_CHILD | WS_VISIBLE | SS_LEFT,
                                    10, 10 + 7*(15 + 10), rcClient.right - 70 - 2*10, 15,
                                    hwnd, NULL, hInst, NULL );

        i_delay = config_GetInt( p_intf, "sub-delay" );
183
        _stprintf( psz_text, _T("%d"), i_delay );
184

185 186 187 188
        delay_edit = CreateWindow( _T("EDIT"), psz_text,
            WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
            rcClient.right - 70 - 10, 10 + 7*(15 + 10) - 3, 70, 15 + 6,
            hwnd, NULL, hInst, NULL );
189 190 191 192 193

        ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
        ic.dwICC = ICC_UPDOWN_CLASS;
        InitCommonControlsEx(&ic);

194 195 196 197 198
        delay_spinctrl =
            CreateUpDownControl( WS_CHILD | WS_VISIBLE | WS_BORDER |
                UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
                0, 0, 0, 0, hwnd, 0, hInst,
                delay_edit, 650000, -650000, i_delay );
199 200 201 202 203 204 205

        fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
                        WS_CHILD | WS_VISIBLE | SS_LEFT,
                        10, 10 + 8*(15 + 10), rcClient.right - 70 - 2*10, 15,
                        hwnd, NULL, hInst, NULL );

        f_fps = config_GetFloat( p_intf, "sub-fps" );
206
        _stprintf( psz_text, _T("%f"), f_fps );
207

208 209 210 211
        fps_edit = CreateWindow( _T("EDIT"), psz_text,
            WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
            rcClient.right - 70 - 10, 10 + 8*(15 + 10) - 3, 70, 15 + 6,
            hwnd, NULL, hInst, NULL);
212 213 214 215 216 217

        ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
        ic.dwICC = ICC_UPDOWN_CLASS;
        InitCommonControlsEx(&ic);

        fps_spinctrl = CreateUpDownControl(
218 219 220
            WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT |
            UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
            0, 0, 0, 0, hwnd, 0, hInst, fps_edit, 16000, 0, (int)f_fps );
221

222 223 224 225 226
        break;

    case WM_CLOSE:
        EndDialog( hwnd, LOWORD( wp ) );
        break;
227 228 229 230 231 232 233

    case WM_COMMAND:
        if ( LOWORD(wp) == IDOK )
        {
            subsfile_mrl.clear();

            string szFileCombo = "sub-file=";
234 235
            GetWindowText( file_combo, psz_text, 256 );
            szFileCombo += _TOMB(psz_text);
236 237 238 239 240
            subsfile_mrl.push_back( szFileCombo );

            if( GetWindowTextLength( encoding_combo ) != 0 )
            {
                string szEncoding = "subsdec-encoding=";
241 242
                GetWindowText( encoding_combo, psz_text, 256 );
                szEncoding += _TOMB(psz_text);
243 244 245 246
                subsfile_mrl.push_back( szEncoding );
            }

            string szDelay = "sub-delay=";
247 248
            Edit_GetText( delay_edit, psz_text, 256 );
            szDelay += _TOMB(psz_text);
249 250 251
            subsfile_mrl.push_back( szDelay );

            string szFps = "sub-fps=";
252 253
            Edit_GetText( fps_edit, psz_text, 256 );
            szFps += _TOMB(psz_text);
254 255 256
            subsfile_mrl.push_back( szFps );

            EndDialog( hwnd, LOWORD( wp ) );
257
            break;
258 259 260 261 262 263 264 265 266
        }
        if( HIWORD(wp) == BN_CLICKED )
        {
            if ((HWND)lp == browse_button)
            {
                SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
                OnFileBrowse();
            } 
        }
267
        break;
268 269

    default:
270
        break;
271 272
    }

273
    return FALSE;
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
}

/*****************************************************************************
 * Private methods.
 *****************************************************************************/

/*****************************************************************************
 * Events methods.
 *****************************************************************************/
void SubsFileDialog::OnFileBrowse()
{
    OPENFILENAME ofn;
    TCHAR DateiName[80+1] = _T("\0");
    static TCHAR szFilter[] = _T("All (*.*)\0*.*\0");

    memset(&ofn, 0, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof (OPENFILENAME);
    ofn.hwndOwner = NULL;
    ofn.hInstance = hInst;
    ofn.lpstrFilter = szFilter;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter = 0;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = (LPTSTR) DateiName;
    ofn.nMaxFile = 80;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 40;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = _T("Open File");
303
    ofn.Flags = 0;
304 305 306 307 308 309 310 311 312 313 314 315 316 317
    ofn.nFileOffset = 0;
    ofn.nFileExtension = 0;
    ofn.lpstrDefExt = NULL;
    ofn.lCustData = 0L;
    ofn.lpfnHook = NULL;
    ofn.lpTemplateName = NULL;
    if( GetOpenFileName((LPOPENFILENAME) &ofn) )
    {
        SetWindowText( file_combo, ofn.lpstrFile );
        ComboBox_AddString( file_combo, ofn.lpstrFile );
        if( ComboBox_GetCount( file_combo ) > 10 )
            ComboBox_DeleteString( file_combo, 0 );
    }
}