21#include <ooo/vba/word/WdCursorType.hpp>
23#include <osl/file.hxx>
30#if !defined WIN32_LEAN_AND_MEAN
31# define WIN32_LEAN_AND_MEAN
50static void lcl_getRegKeyInfo( std::string_view sKeyInfo, HKEY& hBaseKey, OString& sSubKey )
52 std::size_t nBaseKeyIndex = sKeyInfo.find(
'\\');
53 if( nBaseKeyIndex != std::string_view::npos )
55 std::string_view sBaseKey = sKeyInfo.substr( 0, nBaseKeyIndex );
56 sSubKey = OString(sKeyInfo.substr( nBaseKeyIndex + 1 ));
57 if( sBaseKey ==
"HKEY_CURRENT_USER" )
59 hBaseKey = HKEY_CURRENT_USER;
61 else if( sBaseKey ==
"HKEY_LOCAL_MACHINE" )
63 hBaseKey = HKEY_LOCAL_MACHINE;
65 else if( sBaseKey ==
"HKEY_CLASSES_ROOT" )
67 hBaseKey = HKEY_CLASSES_ROOT;
69 else if( sBaseKey ==
"HKEY_USERS" )
71 hBaseKey = HKEY_USERS;
73 else if( sBaseKey ==
"HKEY_CURRENT_CONFIG" )
75 hBaseKey = HKEY_CURRENT_CONFIG;
89 HKEY hBaseKey =
nullptr;
91 lcl_getRegKeyInfo(
maGroupName, hBaseKey, sSubKey );
92 if( hBaseKey !=
nullptr )
95 LPCSTR lpSubKey = sSubKey.getStr();
97 LONG lResult = RegOpenKeyExA( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
98 if( ERROR_SUCCESS == lResult )
100 OUString sUValName = OStringToOUString(
maKey, RTL_TEXTENCODING_DONTKNOW);
101 LPCWSTR lpValueName = o3tl::toW(sUValName.getStr());
102 WCHAR szBuffer[1024];
103 DWORD cbData =
sizeof(szBuffer);
104 lResult = RegQueryValueExW( hKey, lpValueName,
nullptr,
nullptr,
reinterpret_cast<LPBYTE
>(szBuffer), &cbData );
109 sValue = o3tl::toU(szBuffer);
113 throw uno::RuntimeException(
"Only support on Windows" );
120 sValue = OStringToOUString(aCfg.
ReadKey(
maKey), RTL_TEXTENCODING_DONTKNOW);
135 HKEY hBaseKey =
nullptr;
137 lcl_getRegKeyInfo(
maGroupName, hBaseKey, sSubKey );
138 if( hBaseKey !=
nullptr )
141 LPCSTR lpSubKey = sSubKey.getStr();
143 LONG lResult = RegCreateKeyExA( hBaseKey, lpSubKey, 0,
nullptr, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
nullptr, &hKey,
nullptr );
144 if( ERROR_SUCCESS == lResult )
146 DWORD cbData =
sizeof(WCHAR) * (aValue.getLength() + 1);
147 OUString sUValName = OStringToOUString(
maKey, RTL_TEXTENCODING_DONTKNOW);
148 LPCWSTR lpValueName = o3tl::toW(sUValName.getStr());
149 lResult = RegSetValueExW( hKey, lpValueName, 0 , REG_SZ,
reinterpret_cast<BYTE const *
>(aValue.getStr()), cbData );
155 throw uno::RuntimeException(
"Not implemented" );
180 switch( nPointerStyle )
182 case PointerStyle::Arrow:
183 return word::WdCursorType::wdCursorNorthwestArrow;
184 case PointerStyle::Null:
185 return word::WdCursorType::wdCursorNormal;
186 case PointerStyle::Wait:
187 return word::WdCursorType::wdCursorWait;
188 case PointerStyle::Text:
189 return word::WdCursorType::wdCursorIBeam;
191 return word::WdCursorType::wdCursorNormal;
202 case word::WdCursorType::wdCursorNorthwestArrow:
207 case word::WdCursorType::wdCursorWait:
213 case word::WdCursorType::wdCursorIBeam:
219 case word::WdCursorType::wdCursorNormal:
225 throw uno::RuntimeException(
"Unknown value for Cursor pointer" );
230 catch(
const uno::Exception& )
241 if( !rFilename.isEmpty() )
245 bool bIsURL = aObj.
GetProtocol() != INetProtocol::NotValid;
247 sFileUrl = rFilename;
249 osl::FileBase::getFileURLFromSystemPath( rFilename, sFileUrl);
262 return "SwVbaSystem";
265uno::Sequence< OUString >
270 "ooo.vba.word.System"
void SetGroup(const OString &rGroup)
OString ReadKey(const OString &rKey) const
void WriteKey(const OString &rKey, const OString &rValue)
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any getValueEvent() override
virtual void setValueEvent(const css::uno::Any &value) override
virtual ~PrivateProfileStringListener()
void Initialize(const OUString &rFileName, const OString &rGroupName, const OString &rKey)
virtual css::uno::Any SAL_CALL PrivateProfileString(const OUString &rFilename, const OUString &rSection, const OUString &rKey) override
virtual css::uno::Sequence< OUString > getServiceNames() override
SwVbaSystem(css::uno::Reference< css::uno::XComponentContext > const &m_xContext)
virtual ~SwVbaSystem() override
virtual sal_Int32 SAL_CALL getCursor() override
virtual void SAL_CALL setCursor(sal_Int32 _cursor) override
PrivateProfileStringListener maPrivateProfileStringListener
virtual OUString getServiceImplName() override
Sequence< OUString > aServiceNames
#define SAL_N_ELEMENTS(arr)
VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc(const css::uno::Reference< css::uno::XComponentContext > &xContext)
VBAHELPER_DLLPUBLIC PointerStyle getPointerStyle(const css::uno::Reference< css::frame::XModel > &)
VBAHELPER_DLLPUBLIC void setCursorHelper(const css::uno::Reference< css::frame::XModel > &xModel, PointerStyle nPointer, bool bOverWrite)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)