LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/vba - vbasystem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-12-27 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10