]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/subtitles.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / wince / subtitles.cpp
index ee166a1fe9bcd777d71a915c883900edacb33264..7a38c56b2d8ae31e7064945bfe652151e71a81a0 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * subtitles.cpp : WinCE gui plugin for VLC
  *****************************************************************************
- * Copyright (C) 2000-2001 VideoLAN
+ * Copyright (C) 2000-2001 the VideoLAN team
  * $Id$
  *
  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
  *
  * 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
-#include <string.h>
+#include <vlc_interface.h>
 
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string>
-#include <stdio.h>
-using namespace std;
+#include "wince.h"
 
 #include <winuser.h>
 #include <windows.h>
 #include <windowsx.h>
 #include <commctrl.h>
-#include <aygshell.h>
-
 #include <commdlg.h>
 
-#include "wince.h"
-
 /*****************************************************************************
  * Event Table.
  *****************************************************************************/
@@ -51,42 +43,34 @@ using namespace std;
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-SubsFileDialog::SubsFileDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
+SubsFileDialog::SubsFileDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
+                                HINSTANCE h_inst )
+  :  CBaseWindow( p_intf, p_parent, h_inst )
 {
-    /* Initializations */
-    p_intf = _p_intf;
-    hInst = _hInst;
 }
 
 /***********************************************************************
 
-FUNCTION: 
+FUNCTION:
   WndProc
 
-PURPOSE: 
+PURPOSE:
   Processes messages sent to the main window.
-  
 ***********************************************************************/
-LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
-                                 PBOOL pbProcessed  )
+LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
 {
     SHINITDLGINFO shidi;
     SHMENUBARINFO mbi;
     INITCOMMONCONTROLSEX ic;
     RECT rcClient;
 
-    int size;
-    LPWSTR wUnicode;
-
     char *psz_subsfile;
-
+    module_config_t *p_item;
     float f_fps;
     int i_delay;
-    module_config_t *p_item;
 
-    LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
-    BOOL bWasProcessed = *pbProcessed;
-    *pbProcessed = TRUE;
+    TCHAR psz_text[256];
 
     switch( msg )
     {
@@ -100,14 +84,12 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
         memset (&mbi, 0, sizeof (SHMENUBARINFO));
         mbi.cbSize     = sizeof (SHMENUBARINFO);
         mbi.hwndParent = hwnd;
-        mbi.nToolBarId = IDR_DUMMYMENU;
+        mbi.dwFlags    = SHCMBF_EMPTYBAR;
         mbi.hInstRes   = hInst;
-        mbi.nBmpId     = 0;
-        mbi.cBmpImages = 0;
 
         if (!SHCreateMenuBar(&mbi))
         {
-            MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
+            MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
             //return -1;
         }
 
@@ -124,16 +106,12 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
 
         psz_subsfile = config_GetPsz( p_intf, "sub-file" );
         if( !psz_subsfile ) psz_subsfile = strdup("");
-        size = MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, NULL, 0 );
-        wUnicode = new WCHAR[size];
-        MultiByteToWideChar( CP_ACP, 0, psz_subsfile, -1, wUnicode, size );
 
-        file_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
+        file_combo = CreateWindow( _T("COMBOBOX"), _FROMMB(psz_subsfile),
             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 );
 
-        free( wUnicode );
         if( psz_subsfile ) free( psz_subsfile );
 
         browse_button = CreateWindow( _T("BUTTON"), _T("Browse..."),
@@ -143,65 +121,45 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
 
         /* Subtitles encoding */
         encoding_combo = NULL;
-        p_item =
-            config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
+        p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
         if( p_item )
-         {
-             enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
+        {
+            enc_box = CreateWindow( _T("STATIC"), _T("Subtitles encoding"),
                         WS_CHILD | WS_VISIBLE | SS_LEFT,
                         5, 10 + 3*(15 + 10), rcClient.right - 2*5, 15,
                         hwnd, NULL, hInst, NULL );
 
-             size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, NULL, 0 );
-             wUnicode = new WCHAR[size];
-             MultiByteToWideChar( CP_ACP, 0, p_item->psz_text, -1, wUnicode, size );
-
-             enc_label = CreateWindow( _T("STATIC"), wUnicode,
+            enc_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
                 WS_CHILD | WS_VISIBLE | SS_LEFT,
                 10, 10 + 4*(15 + 10), rcClient.right - 2*10, 15,
                 hwnd, NULL, hInst, NULL );
 
-             free( wUnicode );
-
-             size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
-             wUnicode = new WCHAR[size];
-             MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
-
-             encoding_combo = CreateWindow( _T("COMBOBOX"), wUnicode,
-                WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST | LBS_SORT  | WS_VSCROLL,
+            encoding_combo = CreateWindow( _T("COMBOBOX"),
+                _FROMMB(p_item->psz_value),
+                WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
+                LBS_SORT  | WS_VSCROLL,
                 rcClient.right - 150 - 10, 10 + 5*(15 + 10) - 3, 150, 5*15 + 6,
                 hwnd, NULL, hInst, NULL );
 
-             free( wUnicode );
-
-             /* build a list of available options */
-             for( int i_index = 0; p_item->ppsz_list &&
-                    p_item->ppsz_list[i_index]; i_index++ )
-             {
-                 size = MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, NULL, 0 );
-                 wUnicode = new WCHAR[size];
-                 MultiByteToWideChar( CP_ACP, 0, p_item->ppsz_list[i_index], -1, wUnicode, size );
-
-                 ComboBox_AddString( encoding_combo, wUnicode );
-
-                 free( wUnicode );
-
-                 if( p_item->psz_value && !strcmp( p_item->psz_value,
-                                                   p_item->ppsz_list[i_index] ) )
-                   ComboBox_SetCurSel( encoding_combo, i_index );
-             }
+            /* 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]) );
 
-             if( p_item->psz_value )
-             {
-                 size = MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, NULL, 0 );
-                 wUnicode = new WCHAR[size];
-                 MultiByteToWideChar( CP_ACP, 0, p_item->psz_value, -1, wUnicode, size );
+                if( p_item->psz_value &&
+                    !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
+                    ComboBox_SetCurSel( encoding_combo, i_index );
+            }
 
-                 ComboBox_SelectString( encoding_combo, 0, wUnicode );
+            if( p_item->psz_value )
+            {
+                ComboBox_SelectString( encoding_combo, 0,
+                                       _FROMMB(p_item->psz_value) );
 
-                 free( wUnicode );
-             }
-         }
+            }
+        }
 
         /* Misc Subtitles options */
         misc_box = CreateWindow( _T("STATIC"), _T("Subtitles options"),
@@ -209,30 +167,29 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
                                  5, 10 + 6*(15 + 10), rcClient.right - 2*5, 15,
                                  hwnd, NULL, hInst, NULL );
 
-        delay_label = CreateWindow( _T("STATIC"), _T("Delay subtitles (in 1/10s)"),
+        delay_label = CreateWindow( _T("STATIC"),
+                                    _T("Delay subtitles (in 1/10s)"),
                                     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" );
-        wUnicode = new WCHAR[80];
-        swprintf( wUnicode, _T("%d"), i_delay );
-
-        delay_edit = CreateWindow( _T("EDIT"), wUnicode,
-                        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);
+        _stprintf( psz_text, _T("%d"), i_delay );
 
-        free( wUnicode );
+        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 );
 
         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
         ic.dwICC = ICC_UPDOWN_CLASS;
         InitCommonControlsEx(&ic);
 
-        delay_spinctrl = CreateUpDownControl(
-                        WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
-                        0, 0, 0, 0,     hwnd, NULL,     hInst,
-                        delay_edit, 650000, -650000, i_delay );
+        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 );
 
         fps_label = CreateWindow( _T("STATIC"), _T("Frames per second"),
                         WS_CHILD | WS_VISIBLE | SS_LEFT,
@@ -240,86 +197,62 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
                         hwnd, NULL, hInst, NULL );
 
         f_fps = config_GetFloat( p_intf, "sub-fps" );
-        wUnicode = new WCHAR[80];
-        swprintf( wUnicode, _T("%d"), (int)f_fps );
-
-        fps_edit = CreateWindow( _T("EDIT"), wUnicode,
-                        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);
+        _stprintf( psz_text, _T("%f"), f_fps );
 
-        free( wUnicode );
+        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);
 
         ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
         ic.dwICC = ICC_UPDOWN_CLASS;
         InitCommonControlsEx(&ic);
 
         fps_spinctrl = CreateUpDownControl(
-                        WS_CHILD | WS_VISIBLE | WS_BORDER | UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_NOTHOUSANDS,
-                        0, 0, 0, 0,     hwnd, NULL,     hInst,
-                        fps_edit, 16000, 0, (int)f_fps );
+            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 );
+
+        break;
+
+    case WM_CLOSE:
+        EndDialog( hwnd, LOWORD( wp ) );
+        break;
 
-        return lResult;
+    case WM_SETFOCUS:
+        SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
+        break;
 
     case WM_COMMAND:
         if ( LOWORD(wp) == IDOK )
         {
-            int size;
-            BOOL bTemp;
-            LPSTR szAnsi;
-            LPWSTR wUnicode;
-
             subsfile_mrl.clear();
 
             string szFileCombo = "sub-file=";
-            size = GetWindowTextLength( file_combo ) + 1;
-            wUnicode = new WCHAR[ size ];
-            GetWindowText( file_combo, wUnicode, size );
-            size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
-            szAnsi = new char[size];
-            WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
-            szFileCombo += szAnsi;
-            free( wUnicode ); free( szAnsi );
+            GetWindowText( file_combo, psz_text, 256 );
+            szFileCombo += _TOMB(psz_text);
             subsfile_mrl.push_back( szFileCombo );
 
             if( GetWindowTextLength( encoding_combo ) != 0 )
             {
                 string szEncoding = "subsdec-encoding=";
-                size = GetWindowTextLength( encoding_combo ) + 1;
-                wUnicode = new WCHAR[ size ];
-                GetWindowText( encoding_combo, wUnicode, size );
-                size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
-                szAnsi = new char[size];
-                WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
-                szEncoding += szAnsi;
-                free( wUnicode ); free( szAnsi );
+                GetWindowText( encoding_combo, psz_text, 256 );
+                szEncoding += _TOMB(psz_text);
                 subsfile_mrl.push_back( szEncoding );
             }
 
             string szDelay = "sub-delay=";
-            size = Edit_GetTextLength( delay_edit );
-            wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
-            Edit_GetText( delay_edit, wUnicode, size + 1);
-            size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
-            szAnsi = new char[size];
-            WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
-            szDelay += szAnsi;
-            free( wUnicode ); free( szAnsi );
+            Edit_GetText( delay_edit, psz_text, 256 );
+            szDelay += _TOMB(psz_text);
             subsfile_mrl.push_back( szDelay );
 
             string szFps = "sub-fps=";
-            size = Edit_GetTextLength( fps_edit );
-            wUnicode = new WCHAR[size + 1]; //Add 1 for the NULL
-            Edit_GetText( fps_edit, wUnicode, size + 1);
-            size = WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, NULL, 0, NULL, &bTemp );
-            szAnsi = new char[size];
-            WideCharToMultiByte( CP_ACP, 0, wUnicode, -1, szAnsi, size, NULL, &bTemp );
-            szFps += szAnsi;
-            free( wUnicode ); free( szAnsi );
+            Edit_GetText( fps_edit, psz_text, 256 );
+            szFps += _TOMB(psz_text);
             subsfile_mrl.push_back( szFps );
 
             EndDialog( hwnd, LOWORD( wp ) );
-            return TRUE;
+            break;
         }
         if( HIWORD(wp) == BN_CLICKED )
         {
@@ -327,23 +260,15 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
             {
                 SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
                 OnFileBrowse();
-                return TRUE;
-            } 
+            }
         }
-
-        *pbProcessed = bWasProcessed;
-        lResult = FALSE;
-        return lResult;
+        break;
 
     default:
-        // the message was not processed
-        // indicate if the base class handled it
-        *pbProcessed = bWasProcessed;
-        lResult = FALSE;
-        return lResult;
+        break;
     }
 
-    return lResult;
+    return FALSE;
 }
 
 /*****************************************************************************
@@ -353,38 +278,30 @@ LRESULT SubsFileDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
 /*****************************************************************************
  * Events methods.
  *****************************************************************************/
-void SubsFileDialog::OnFileBrowse()
+static void OnOpenCB( intf_dialog_args_t *p_arg )
 {
-    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");
-    ofn.Flags = NULL;
-    ofn.nFileOffset = 0;
-    ofn.nFileExtension = 0;
-    ofn.lpstrDefExt = NULL;
-    ofn.lCustData = 0L;
-    ofn.lpfnHook = NULL;
-    ofn.lpTemplateName = NULL;
-    if( GetOpenFileName((LPOPENFILENAME) &ofn) )
+    SubsFileDialog *p_this = (SubsFileDialog *)p_arg->p_arg;
+
+    if( p_arg->i_results && p_arg->psz_results[0] )
     {
-        SetWindowText( file_combo, ofn.lpstrFile );
-        ComboBox_AddString( file_combo, ofn.lpstrFile );
-        if( ComboBox_GetCount( file_combo ) > 10 )
-            ComboBox_DeleteString( file_combo, 0 );
+        SetWindowText( p_this->file_combo, _FROMMB(p_arg->psz_results[0]) );
+        ComboBox_AddString( p_this->file_combo,
+                            _FROMMB(p_arg->psz_results[0]) );
+        if( ComboBox_GetCount( p_this->file_combo ) > 10 )
+            ComboBox_DeleteString( p_this->file_combo, 0 );
     }
 }
+
+void SubsFileDialog::OnFileBrowse()
+{
+    intf_dialog_args_t *p_arg =
+        (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
+    memset( p_arg, 0, sizeof(intf_dialog_args_t) );
+
+    p_arg->psz_title = strdup( "Open file" );
+    p_arg->psz_extensions = strdup( "All|*.*" );
+    p_arg->p_arg = this;
+    p_arg->pf_callback = OnOpenCB;
+
+    p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_GENERIC, 0, p_arg);
+}