LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbasystem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 75 0.0 %
Date: 2015-06-13 12:38:46 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 OUString& rFileName, const OString& rGroupName, const 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 OString& sKeyInfo, HKEY& hBaseKey, OString& sSubKey )
      54             : {
      55             :     sal_Int32 nBaseKeyIndex = sKeyInfo.indexOf('\\');
      56             :     if( nBaseKeyIndex > 0 )
      57             :     {
      58             :         OString sBaseKey = sKeyInfo.copy( 0, nBaseKeyIndex );
      59             :         sSubKey = sKeyInfo.copy( nBaseKeyIndex + 1 );
      60             :         if( sBaseKey == "HKEY_CURRENT_USER" )
      61             :         {
      62             :             hBaseKey = HKEY_CURRENT_USER;
      63             :         }
      64             :         else if( sBaseKey == "HKEY_LOCAL_MACHINE" )
      65             :         {
      66             :             hBaseKey = HKEY_LOCAL_MACHINE;
      67             :         }
      68             :         else if( sBaseKey == "HKEY_CLASSES_ROOT" )
      69             :         {
      70             :             hBaseKey = HKEY_CLASSES_ROOT;
      71             :         }
      72             :         else if( sBaseKey == "HKEY_USERS" )
      73             :         {
      74             :             hBaseKey = HKEY_USERS;
      75             :         }
      76             :         else if( sBaseKey == "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 :     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 = 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             :         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 = OUString::createFromAscii(szBuffer);
     116             :             }
     117             :         }
     118             : 
     119             :         return uno::makeAny( sValue );
     120             : #else
     121           0 :         throw uno::RuntimeException("Only support on Windows" );
     122             : #endif
     123             :     }
     124             : 
     125           0 :     return uno::makeAny( sValue );
     126             : }
     127             : 
     128           0 : void PrivateProfileStringListener::setValueEvent( const css::uno::Any& value )
     129             : {
     130             :     // set the private profile string
     131           0 :     OUString aValue;
     132           0 :     value >>= aValue;
     133           0 :     if(!maFileName.isEmpty())
     134             :     {
     135             :         // set value into a file
     136           0 :         Config aCfg( maFileName );
     137           0 :         aCfg.SetGroup( maGroupName );
     138           0 :         aCfg.WriteKey( maKey, OUStringToOString(aValue, RTL_TEXTENCODING_DONTKNOW) );
     139             :     }
     140             :     else
     141             :     {
     142             :         //set value into windows register
     143             : #ifdef WNT
     144             :         HKEY hBaseKey = NULL;
     145             :         OString sSubKey;
     146             :         lcl_getRegKeyInfo( maGroupName, hBaseKey, sSubKey );
     147             :         if( hBaseKey != NULL )
     148             :         {
     149             :             HKEY hKey = NULL;
     150             :             LONG lResult;
     151             :             LPCTSTR lpSubKey = TEXT( sSubKey.getStr());
     152             :             lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
     153             :             if( ERROR_SUCCESS == lResult )
     154             :             {
     155             :                 OString aUTF8Value = OUStringToOString( aValue, RTL_TEXTENCODING_UTF8 );
     156             :                 DWORD cbData = sizeof(TCHAR) * (_tcslen(aUTF8Value.getStr()) + 1);
     157             :                 LPCTSTR lpValueName = TEXT(maKey.getStr());
     158             :                 lResult = RegSetValueEx( hKey, lpValueName, 0 /* Reserved */, REG_SZ, (LPBYTE)aUTF8Value.getStr(), cbData );
     159             :                 RegCloseKey( hKey );
     160             :             }
     161             :         }
     162             :         return;
     163             : #else
     164           0 :         throw uno::RuntimeException("Not implemented" );
     165             : #endif
     166           0 :     }
     167             : 
     168           0 : }
     169             : 
     170           0 : SwVbaSystem::SwVbaSystem( uno::Reference<uno::XComponentContext >& xContext ): SwVbaSystem_BASE( uno::Reference< XHelperInterface >(), xContext )
     171             : {
     172           0 : }
     173             : 
     174           0 : SwVbaSystem::~SwVbaSystem()
     175             : {
     176           0 : }
     177             : 
     178             : sal_Int32 SAL_CALL
     179           0 : SwVbaSystem::getCursor() throw (uno::RuntimeException, std::exception)
     180             : {
     181           0 :     PointerStyle nPointerStyle = getPointerStyle( getCurrentWordDoc(mxContext) );
     182             : 
     183           0 :     switch( nPointerStyle )
     184             :     {
     185             :         case PointerStyle::Arrow:
     186           0 :             return word::WdCursorType::wdCursorNorthwestArrow;
     187             :         case PointerStyle::Null:
     188           0 :             return word::WdCursorType::wdCursorNormal;
     189             :         case PointerStyle::Wait:
     190           0 :             return word::WdCursorType::wdCursorWait;
     191             :         case PointerStyle::Text:
     192           0 :             return word::WdCursorType::wdCursorIBeam;
     193             :         default:
     194           0 :             return word::WdCursorType::wdCursorNormal;
     195             :     }
     196             : }
     197             : 
     198             : void SAL_CALL
     199           0 : SwVbaSystem::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException, std::exception)
     200             : {
     201             :     try
     202             :     {
     203           0 :         switch( _cursor )
     204             :         {
     205             :             case word::WdCursorType::wdCursorNorthwestArrow:
     206             :             {
     207           0 :                 const Pointer& rPointer( PointerStyle::Arrow );
     208           0 :                 setCursorHelper( getCurrentWordDoc(mxContext), rPointer, false );
     209           0 :                 break;
     210             :             }
     211             :             case word::WdCursorType::wdCursorWait:
     212             :             {
     213           0 :                 const Pointer& rPointer( static_cast< PointerStyle >( PointerStyle::Wait ) );
     214             :                 //It will set the edit window, toobar and statusbar's mouse pointer.
     215           0 :                 setCursorHelper( getCurrentWordDoc(mxContext), rPointer, true );
     216           0 :                 break;
     217             :             }
     218             :             case word::WdCursorType::wdCursorIBeam:
     219             :             {
     220           0 :                 const Pointer& rPointer( static_cast< PointerStyle >( PointerStyle::Text ) );
     221             :                 //It will set the edit window, toobar and statusbar's mouse pointer.
     222           0 :                 setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, true );
     223           0 :                 break;
     224             :             }
     225             :             case word::WdCursorType::wdCursorNormal:
     226             :             {
     227           0 :                 const Pointer& rPointer( PointerStyle::Null );
     228           0 :                 setCursorHelper( getCurrentWordDoc( mxContext ), rPointer, false );
     229           0 :                 break;
     230             :             }
     231             :             default:
     232           0 :                 throw uno::RuntimeException("Unknown value for Cursor pointer" );
     233             :                 // TODO: isn't this a flaw in the API? It should be allowed to throw an
     234             :                 // IllegalArgumentException, or so
     235             :         }
     236             :     }
     237           0 :     catch( const uno::Exception& )
     238             :     {
     239             :     }
     240           0 : }
     241             : 
     242             : uno::Any SAL_CALL
     243           0 : SwVbaSystem::PrivateProfileString( const OUString& rFilename, const OUString& rSection, const OUString& rKey ) throw ( uno::RuntimeException, std::exception )
     244             : {
     245             :     // FIXME: need to detect whether it is a relative file path
     246             :     // we need to detect if this is a URL, if not then assume it's a file path
     247           0 :     OUString sFileUrl;
     248           0 :     if( !rFilename.isEmpty() )
     249             :     {
     250           0 :         INetURLObject aObj;
     251           0 :         aObj.SetURL( rFilename );
     252           0 :         bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
     253           0 :         if ( bIsURL )
     254           0 :             sFileUrl = rFilename;
     255             :         else
     256           0 :             osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl);
     257             :     }
     258             : 
     259           0 :     OString aGroupName(OUStringToOString(rSection, RTL_TEXTENCODING_DONTKNOW));
     260           0 :     OString aKey(OUStringToOString(rKey, RTL_TEXTENCODING_DONTKNOW));
     261           0 :     maPrivateProfileStringListener.Initialize( sFileUrl, aGroupName, aKey );
     262             : 
     263           0 :     return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( &maPrivateProfileStringListener ) ) );
     264             : }
     265             : 
     266             : OUString
     267           0 : SwVbaSystem::getServiceImplName()
     268             : {
     269           0 :     return OUString("SwVbaSystem");
     270             : }
     271             : 
     272             : uno::Sequence< OUString >
     273           0 : SwVbaSystem::getServiceNames()
     274             : {
     275           0 :     static uno::Sequence< OUString > aServiceNames;
     276           0 :     if ( aServiceNames.getLength() == 0 )
     277             :     {
     278           0 :         aServiceNames.realloc( 1 );
     279           0 :         aServiceNames[ 0 ] = "ooo.vba.word.System";
     280             :     }
     281           0 :     return aServiceNames;
     282             : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11