LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbasystem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 110 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #include "vbasystem.hxx"
      29                 :            : 
      30                 :            : #include <ooo/vba/word/WdCursorType.hpp>
      31                 :            : #include <tools/diagnose_ex.h>
      32                 :            : #include <tools/config.hxx>
      33                 :            : #include <osl/file.hxx>
      34                 :            : #include <tools/urlobj.hxx>
      35                 :            : 
      36                 :            : #ifdef WNT
      37                 :            : #include <windows.h>
      38                 :            : #include <tchar.h>
      39                 :            : #endif
      40                 :            : 
      41                 :            : using namespace ::ooo::vba;
      42                 :            : using namespace ::com::sun::star;
      43                 :            : 
      44                 :          0 : PrivateProfileStringListener::~PrivateProfileStringListener()
      45                 :            : {
      46         [ #  # ]:          0 : }
      47                 :            : 
      48                 :          0 : void PrivateProfileStringListener::Initialize( const rtl::OUString& rFileName, const rtl::OString& rGroupName, const rtl::OString& rKey )
      49                 :            : {
      50                 :          0 :     maFileName = rFileName;
      51                 :          0 :     maGroupName = rGroupName;
      52                 :          0 :     maKey = rKey;
      53                 :          0 : }
      54                 :            : #ifdef WNT
      55                 :            : void lcl_getRegKeyInfo( const rtl::OString& sKeyInfo, HKEY& hBaseKey, rtl::OString& sSubKey )
      56                 :            : {
      57                 :            :     sal_Int32 nBaseKeyIndex = sKeyInfo.indexOf('\\');
      58                 :            :     if( nBaseKeyIndex > 0 )
      59                 :            :     {
      60                 :            :         rtl::OString sBaseKey = sKeyInfo.copy( 0, nBaseKeyIndex );
      61                 :            :         sSubKey = sKeyInfo.copy( nBaseKeyIndex + 1 );
      62                 :            :         if( sBaseKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HKEY_CURRENT_USER")) )
      63                 :            :         {
      64                 :            :             hBaseKey = HKEY_CURRENT_USER;
      65                 :            :         }
      66                 :            :         else if( sBaseKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HKEY_LOCAL_MACHINE")) )
      67                 :            :         {
      68                 :            :             hBaseKey = HKEY_LOCAL_MACHINE;
      69                 :            :         }
      70                 :            :         else if( sBaseKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HKEY_CLASSES_ROOT")) )
      71                 :            :         {
      72                 :            :             hBaseKey = HKEY_CLASSES_ROOT;
      73                 :            :         }
      74                 :            :         else if( sBaseKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HKEY_USERS")) )
      75                 :            :         {
      76                 :            :             hBaseKey = HKEY_USERS;
      77                 :            :         }
      78                 :            :         else if( sBaseKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HKEY_CURRENT_CONFIG")) )
      79                 :            :         {
      80                 :            :             hBaseKey = HKEY_CURRENT_CONFIG;
      81                 :            :         }
      82                 :            :     }
      83                 :            : }
      84                 :            : #endif
      85                 :            : 
      86                 :          0 : uno::Any PrivateProfileStringListener::getValueEvent()
      87                 :            : {
      88                 :            :     // get the private profile string
      89                 :          0 :     rtl::OUString sValue;
      90         [ #  # ]:          0 :     if(!maFileName.isEmpty())
      91                 :            :     {
      92                 :            :         // get key/value from a file
      93         [ #  # ]:          0 :         Config aCfg( maFileName );
      94         [ #  # ]:          0 :         aCfg.SetGroup( maGroupName );
      95 [ #  # ][ #  # ]:          0 :         sValue = rtl::OStringToOUString(aCfg.ReadKey(maKey), RTL_TEXTENCODING_DONTKNOW);
                 [ #  # ]
      96                 :            :     }
      97                 :            :     else
      98                 :            :     {
      99                 :            :         // get key/value from windows register
     100                 :            : #ifdef WNT
     101                 :            :         HKEY hBaseKey = NULL;
     102                 :            :         rtl::OString sSubKey;
     103                 :            :         lcl_getRegKeyInfo( maGroupName, hBaseKey, sSubKey );
     104                 :            :         if( hBaseKey != NULL )
     105                 :            :         {
     106                 :            :             HKEY hKey = NULL;
     107                 :            :             LONG lResult;
     108                 :            :             LPCTSTR lpSubKey = TEXT( sSubKey.getStr());
     109                 :            :             TCHAR szBuffer[1024];
     110                 :            :             DWORD cbData = sizeof( szBuffer );
     111                 :            :             lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
     112                 :            :             if( ERROR_SUCCESS == lResult )
     113                 :            :             {
     114                 :            :                 LPCTSTR lpValueName = TEXT(maKey.getStr());
     115                 :            :                 lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)szBuffer, &cbData );
     116                 :            :                 RegCloseKey( hKey );
     117                 :            :                 sValue = rtl::OUString::createFromAscii(szBuffer);
     118                 :            :             }
     119                 :            :         }
     120                 :            : 
     121                 :            :         return uno::makeAny( sValue );
     122                 :            : #else
     123                 :            :         throw uno::RuntimeException( rtl::OUString(
     124 [ #  # ][ #  # ]:          0 :                         RTL_CONSTASCII_USTRINGPARAM("Only support on Windows")), uno::Reference< uno::XInterface >() );
     125                 :            : #endif
     126                 :            :     }
     127                 :            : 
     128         [ #  # ]:          0 :     return uno::makeAny( sValue );
     129                 :            : }
     130                 :            : 
     131                 :          0 : void PrivateProfileStringListener::setValueEvent( const css::uno::Any& value )
     132                 :            : {
     133                 :            :     // set the private profile string
     134                 :          0 :     rtl::OUString aValue;
     135                 :          0 :     value >>= aValue;
     136         [ #  # ]:          0 :     if(!maFileName.isEmpty())
     137                 :            :     {
     138                 :            :         // set value into a file
     139         [ #  # ]:          0 :         Config aCfg( maFileName );
     140         [ #  # ]:          0 :         aCfg.SetGroup( maGroupName );
     141 [ #  # ][ #  # ]:          0 :         aCfg.WriteKey( maKey, rtl::OUStringToOString(aValue, RTL_TEXTENCODING_DONTKNOW) );
                 [ #  # ]
     142                 :            :     }
     143                 :            :     else
     144                 :            :     {
     145                 :            :         //set value into windows register
     146                 :            : #ifdef WNT
     147                 :            :         HKEY hBaseKey = NULL;
     148                 :            :         rtl::OString sSubKey;
     149                 :            :         lcl_getRegKeyInfo( maGroupName, hBaseKey, sSubKey );
     150                 :            :         if( hBaseKey != NULL )
     151                 :            :         {
     152                 :            :             HKEY hKey = NULL;
     153                 :            :             LONG lResult;
     154                 :            :             LPCTSTR lpSubKey = TEXT( sSubKey.getStr());
     155                 :            :             lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
     156                 :            :             if( ERROR_SUCCESS == lResult )
     157                 :            :             {
     158                 :            :                 LPCTSTR szValue = TEXT( rtl::OUStringToOString( aValue, RTL_TEXTENCODING_UTF8 ).getStr() );
     159                 :            :                 DWORD cbData = sizeof(TCHAR) * (_tcslen(szValue) + 1);
     160                 :            :                 LPCTSTR lpValueName = TEXT(maKey.getStr());
     161                 :            :                 lResult = RegSetValueEx( hKey, lpValueName, 0 /* Reserved */, REG_SZ, (LPBYTE)szValue, cbData );
     162                 :            :                 RegCloseKey( hKey );
     163                 :            :             }
     164                 :            :         }
     165                 :            :         return;
     166                 :            : #else
     167                 :            :         throw uno::RuntimeException( rtl::OUString(
     168 [ #  # ][ #  # ]:          0 :                         RTL_CONSTASCII_USTRINGPARAM("Not implemented")), uno::Reference< uno::XInterface >() );
     169                 :            : #endif
     170                 :          0 :     }
     171                 :            : 
     172                 :          0 : }
     173                 :            : 
     174         [ #  # ]:          0 : SwVbaSystem::SwVbaSystem( uno::Reference<uno::XComponentContext >& xContext ): SwVbaSystem_BASE( uno::Reference< XHelperInterface >(), xContext )
     175                 :            : {
     176                 :          0 : }
     177                 :            : 
     178                 :          0 : SwVbaSystem::~SwVbaSystem()
     179                 :            : {
     180         [ #  # ]:          0 : }
     181                 :            : 
     182                 :            : sal_Int32 SAL_CALL
     183                 :          0 : SwVbaSystem::getCursor() throw (uno::RuntimeException)
     184                 :            : {
     185         [ #  # ]:          0 :     sal_Int32 nPointerStyle =  getPointerStyle( getCurrentWordDoc(mxContext) );
     186                 :            : 
     187   [ #  #  #  #  :          0 :     switch( nPointerStyle )
                      # ]
     188                 :            :     {
     189                 :            :         case POINTER_ARROW:
     190                 :          0 :             return word::WdCursorType::wdCursorNorthwestArrow;
     191                 :            :         case POINTER_NULL:
     192                 :          0 :             return word::WdCursorType::wdCursorNormal;
     193                 :            :         case POINTER_WAIT:
     194                 :          0 :             return word::WdCursorType::wdCursorWait;
     195                 :            :         case POINTER_TEXT:
     196                 :          0 :             return word::WdCursorType::wdCursorIBeam;
     197                 :            :         default:
     198                 :          0 :             return word::WdCursorType::wdCursorNormal;
     199                 :            :     }
     200                 :            : }
     201                 :            : 
     202                 :            : void SAL_CALL
     203                 :          0 : SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException)
     204                 :            : {
     205                 :            :     try
     206                 :            :     {
     207   [ #  #  #  #  :          0 :         switch( _cursor )
                      # ]
     208                 :            :         {
     209                 :            :             case word::WdCursorType::wdCursorNorthwestArrow:
     210                 :            :             {
     211                 :          0 :                 const Pointer& rPointer( POINTER_ARROW );
     212 [ #  # ][ #  # ]:          0 :                 setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_False );
     213                 :          0 :                 break;
     214                 :            :             }
     215                 :            :             case word::WdCursorType::wdCursorWait:
     216                 :            :             {
     217                 :          0 :                 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_WAIT ) );
     218                 :            :                 //It will set the edit window, toobar and statusbar's mouse pointer.
     219 [ #  # ][ #  # ]:          0 :                 setCursorHelper( getCurrentWordDoc(mxContext), rPointer, sal_True );
     220                 :          0 :                 break;
     221                 :            :             }
     222                 :            :             case word::WdCursorType::wdCursorIBeam:
     223                 :            :             {
     224                 :          0 :                 const Pointer& rPointer( static_cast< PointerStyle >( POINTER_TEXT ) );
     225                 :            :                 //It will set the edit window, toobar and statusbar's mouse pointer.
     226 [ #  # ][ #  # ]:          0 :                 setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_True );
     227                 :          0 :                 break;
     228                 :            :             }
     229                 :            :             case word::WdCursorType::wdCursorNormal:
     230                 :            :             {
     231                 :          0 :                 const Pointer& rPointer( POINTER_NULL );
     232 [ #  # ][ #  # ]:          0 :                 setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, sal_False );
     233                 :          0 :                 break;
     234                 :            :             }
     235                 :            :             default:
     236                 :            :                 throw uno::RuntimeException( rtl::OUString(
     237 [ #  # ][ #  # ]:          0 :                         RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() );
                 [ #  # ]
     238                 :            :                 // TODO: isn't this a flaw in the API? It should be allowed to throw an
     239                 :            :                 // IllegalArgumentException, or so
     240                 :            :         }
     241                 :            :     }
     242                 :          0 :     catch( const uno::Exception& )
     243                 :            :     {
     244                 :            :         DBG_UNHANDLED_EXCEPTION();
     245                 :            :     }
     246                 :          0 : }
     247                 :            : 
     248                 :            : uno::Any SAL_CALL
     249                 :          0 : SwVbaSystem::PrivateProfileString( const rtl::OUString& rFilename, const rtl::OUString& rSection, const rtl::OUString& rKey ) throw ( uno::RuntimeException )
     250                 :            : {
     251                 :            :     // FIXME: need to detect whether it is a relative file path
     252                 :            :     // we need to detect if this is a URL, if not then assume its a file path
     253                 :          0 :     rtl::OUString sFileUrl;
     254         [ #  # ]:          0 :     if( !rFilename.isEmpty() )
     255                 :            :     {
     256         [ #  # ]:          0 :         INetURLObject aObj;
     257         [ #  # ]:          0 :         aObj.SetURL( rFilename );
     258                 :          0 :         bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
     259         [ #  # ]:          0 :         if ( bIsURL )
     260                 :          0 :             sFileUrl = rFilename;
     261                 :            :         else
     262 [ #  # ][ #  # ]:          0 :             osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl);
     263                 :            :     }
     264                 :            : 
     265         [ #  # ]:          0 :     rtl::OString aGroupName(rtl::OUStringToOString(rSection, RTL_TEXTENCODING_DONTKNOW));
     266         [ #  # ]:          0 :     rtl::OString aKey(rtl::OUStringToOString(rKey, RTL_TEXTENCODING_DONTKNOW));
     267                 :          0 :     maPrivateProfileStringListener.Initialize( sFileUrl, aGroupName, aKey );
     268                 :            : 
     269 [ #  # ][ #  # ]:          0 :     return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( &maPrivateProfileStringListener ) ) );
         [ #  # ][ #  # ]
     270                 :            : }
     271                 :            : 
     272                 :            : rtl::OUString
     273                 :          0 : SwVbaSystem::getServiceImplName()
     274                 :            : {
     275                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaSystem"));
     276                 :            : }
     277                 :            : 
     278                 :            : uno::Sequence< rtl::OUString >
     279                 :          0 : SwVbaSystem::getServiceNames()
     280                 :            : {
     281 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     282         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
     283                 :            :     {
     284                 :          0 :         aServiceNames.realloc( 1 );
     285         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.System" ) );
     286                 :            :     }
     287                 :          0 :     return aServiceNames;
     288                 :            : }
     289                 :            : 
     290                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10