diff options
-rw-r--r-- | extensions/source/ole/unoconversionutilities.hxx | 3 | ||||
-rw-r--r-- | extensions/source/ole/unoobjw.cxx | 9 | ||||
-rw-r--r-- | include/systools/win32/oleauto.hxx | 23 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccActionBase.cxx | 5 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccImage.cxx | 3 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccTable.cxx | 5 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/AccTextBase.cxx | 14 | ||||
-rw-r--r-- | winaccessibility/source/UAccCOM/MAccessible.cxx | 23 |
8 files changed, 45 insertions, 40 deletions
diff --git a/extensions/source/ole/unoconversionutilities.hxx b/extensions/source/ole/unoconversionutilities.hxx index a73a714abe55..e2d68dbe5359 100644 --- a/extensions/source/ole/unoconversionutilities.hxx +++ b/extensions/source/ole/unoconversionutilities.hxx @@ -36,6 +36,7 @@ #include <o3tl/char16_t2wchar_t.hxx> #include "ole2uno.hxx" #include <cppuhelper/weakref.hxx> +#include <systools/win32/oleauto.hxx> #include "unotypewrapper.hxx" #include <unordered_map> @@ -849,7 +850,7 @@ void UnoConversionUtilities<T>::anyToVariant(VARIANT* pVariant, const Any& rAny) if (rAny >>= value) { pVariant->vt = VT_BSTR; - pVariant->bstrVal = SysAllocString(o3tl::toW(value.getStr())); + pVariant->bstrVal = sal::systools::BStr::newBSTR(value); } else { diff --git a/extensions/source/ole/unoobjw.cxx b/extensions/source/ole/unoobjw.cxx index 5a3151d07b44..cd84c0c6b91b 100644 --- a/extensions/source/ole/unoobjw.cxx +++ b/extensions/source/ole/unoobjw.cxx @@ -87,6 +87,7 @@ #include <comphelper/windowserrorstring.hxx> #include <o3tl/char16_t2wchar_t.hxx> #include <o3tl/safeint.hxx> +#include <systools/win32/oleauto.hxx> #include "comifaces.hxx" #include "jscriptclasses.hxx" @@ -119,7 +120,7 @@ static void writeExcepinfo(EXCEPINFO * pInfo, const OUString& message) { pInfo->wCode = UNO_2_OLE_EXCEPTIONCODE; pInfo->bstrSource = SysAllocString(L"[automation bridge] "); - pInfo->bstrDescription = SysAllocString(o3tl::toW(message.getStr())); + pInfo->bstrDescription = sal::systools::BStr::newBSTR(message); } } @@ -811,7 +812,7 @@ HRESULT STDMETHODCALLTYPE CXTypeInfo::GetNames(MEMBERID memid, return E_INVALIDARG; SAL_INFO("extensions.olebridge", "..." << this << "@CXTypeInfo::GetNames(" << memid << "): " << aMethods[memid + 2]->getName()); - rgBstrNames[0] = SysAllocString(reinterpret_cast<LPOLESTR>(aMethods[memid + 2]->getName().pData->buffer)); + rgBstrNames[0] = sal::systools::BStr::newBSTR(aMethods[memid + 2]->getName()); *pcNames = 1; return S_OK; @@ -887,7 +888,7 @@ HRESULT STDMETHODCALLTYPE CXTypeInfo::GetDocumentation(MEMBERID memid, { if (memid == MEMBERID_NIL) { - *pBstrName = SysAllocString(o3tl::toW(msImplementationName.getStr())); + *pBstrName = sal::systools::BStr::newBSTR(msImplementationName); } else if (memid == DISPID_VALUE) { @@ -897,7 +898,7 @@ HRESULT STDMETHODCALLTYPE CXTypeInfo::GetDocumentation(MEMBERID memid, else { // FIXME: Shouldn't we be able to know the names of the members of UNO interfaces? - *pBstrName = SysAllocString(o3tl::toW(OUString("UnknownNameOfMember#" + OUString::number(memid)).getStr())); + *pBstrName = sal::systools::BStr::newBSTR(Concat2View("UnknownNameOfMember#" + OUString::number(memid))); } } if (pBstrDocString) diff --git a/include/systools/win32/oleauto.hxx b/include/systools/win32/oleauto.hxx index c01ac1225f73..60383a6c26a3 100644 --- a/include/systools/win32/oleauto.hxx +++ b/include/systools/win32/oleauto.hxx @@ -35,24 +35,23 @@ namespace sal::systools class BStr { public: - BStr() = default; - BStr(std::u16string_view sv) - : m_Str(::SysAllocStringLen(o3tl::toW(sv.data()), sv.length())) + static BSTR newBSTR(std::u16string_view sv) { + return ::SysAllocStringLen(o3tl::toW(sv.data()), sv.size()); } - BStr(const BStr& src) - : BStr(std::u16string_view(src)) + BStr() = default; + BStr(std::u16string_view sv) + : m_Str(newBSTR(sv)) { } - BStr(BStr&& src) - : m_Str(std::exchange(src.m_Str, nullptr)) + BStr(BStr&& src) noexcept + : m_Str(src.release()) { } ~BStr() { ::SysFreeString(m_Str); } BStr& operator=(std::u16string_view sv) { - ::SysFreeString( - std::exchange(m_Str, ::SysAllocStringLen(o3tl::toW(sv.data()), sv.length()))); + ::SysFreeString(std::exchange(m_Str, newBSTR(sv))); return *this; } BStr& operator=(const BStr& src) @@ -61,9 +60,9 @@ public: operator=(std::u16string_view(src)); return *this; } - BStr& operator=(BStr&& src) + BStr& operator=(BStr&& src) noexcept { - ::SysFreeString(std::exchange(m_Str, std::exchange(src.m_Str, nullptr))); + ::SysFreeString(std::exchange(m_Str, src.release())); return *this; } operator std::u16string_view() const { return { o3tl::toU(m_Str), length() }; } @@ -74,6 +73,8 @@ public: return &m_Str; } UINT length() const { return ::SysStringLen(m_Str); } + // similar to std::unique_ptr::release + BSTR release() { return std::exchange(m_Str, nullptr); } private: BSTR m_Str = nullptr; diff --git a/winaccessibility/source/UAccCOM/AccActionBase.cxx b/winaccessibility/source/UAccCOM/AccActionBase.cxx index aa5f63b55c61..391623f07034 100644 --- a/winaccessibility/source/UAccCOM/AccActionBase.cxx +++ b/winaccessibility/source/UAccCOM/AccActionBase.cxx @@ -31,6 +31,7 @@ #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> #include <comphelper/AccessibleImplementationHelper.hxx> +#include <systools/win32/oleauto.hxx> #include "acccommon.h" @@ -116,7 +117,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_description(long actionInd OUString ouStr = pRXAct->getAccessibleActionDescription(actionIndex); SysFreeString(*description); - *description = SysAllocString(o3tl::toW(ouStr.getStr())); + *description = sal::systools::BStr::newBSTR(ouStr); return S_OK; @@ -176,7 +177,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_keyBinding( auto const wString = comphelper::GetkeyBindingStrByXkeyBinding( binding->getAccessibleKeyBinding(index)); - (*keyBinding)[index] = SysAllocString(o3tl::toW(wString.getStr())); + (*keyBinding)[index] = sal::systools::BStr::newBSTR(wString); } *nBinding = nCount; diff --git a/winaccessibility/source/UAccCOM/AccImage.cxx b/winaccessibility/source/UAccCOM/AccImage.cxx index 7dbfcc339cc3..faabffe331e4 100644 --- a/winaccessibility/source/UAccCOM/AccImage.cxx +++ b/winaccessibility/source/UAccCOM/AccImage.cxx @@ -23,6 +23,7 @@ #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/oleauto.hxx> #include <com/sun/star/accessibility/XAccessible.hpp> #include <com/sun/star/accessibility/XAccessibleContext.hpp> @@ -48,7 +49,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccImage::get_description(BSTR* description) OUString ouStr = GetXInterface()->getAccessibleImageDescription(); SysFreeString(*description); - *description = SysAllocString(o3tl::toW(ouStr.getStr())); + *description = sal::systools::BStr::newBSTR(ouStr); return S_OK; } diff --git a/winaccessibility/source/UAccCOM/AccTable.cxx b/winaccessibility/source/UAccCOM/AccTable.cxx index bf0cc9563515..b142b525bb32 100644 --- a/winaccessibility/source/UAccCOM/AccTable.cxx +++ b/winaccessibility/source/UAccCOM/AccTable.cxx @@ -27,6 +27,7 @@ #include <sal/log.hxx> #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/oleauto.hxx> #include <com/sun/star/accessibility/XAccessible.hpp> #include "MAccessible.h" @@ -125,7 +126,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_columnDescription(long column, const OUString& ouStr = pRXTable->getAccessibleColumnDescription(column); SysFreeString(*description); - *description = SysAllocString(o3tl::toW(ouStr.getStr())); + *description = sal::systools::BStr::newBSTR(ouStr); if (*description==nullptr) return E_FAIL; return S_OK; @@ -323,7 +324,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTable::get_rowDescription(long row, BSTR * const OUString& ouStr = pRXTable->getAccessibleRowDescription(row); SysFreeString(*description); - *description = SysAllocString(o3tl::toW(ouStr.getStr())); + *description = sal::systools::BStr::newBSTR(ouStr); if (*description==nullptr) return E_FAIL; return S_OK; diff --git a/winaccessibility/source/UAccCOM/AccTextBase.cxx b/winaccessibility/source/UAccCOM/AccTextBase.cxx index 857b52f2f53f..620fa18b6925 100644 --- a/winaccessibility/source/UAccCOM/AccTextBase.cxx +++ b/winaccessibility/source/UAccCOM/AccTextBase.cxx @@ -29,6 +29,7 @@ #include <vcl/accessibility/AccessibleTextAttributeHelper.hxx> #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> +#include <systools/win32/oleauto.hxx> #include <com/sun/star/accessibility/AccessibleScrollType.hpp> #include <com/sun/star/accessibility/AccessibleTextType.hpp> @@ -148,7 +149,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_attributes(long offset, long if(*textAttributes) SysFreeString(*textAttributes); - *textAttributes = SysAllocString(o3tl::toW(sAttrs.getStr())); + *textAttributes = sal::systools::BStr::newBSTR(sAttrs); return S_OK; @@ -446,7 +447,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_text(long startOffset, long const OUString ouStr = pRXText->getTextRange(startOffset, endOffset); SysFreeString(*text); - *text = SysAllocString(o3tl::toW(ouStr.getStr())); + *text = sal::systools::BStr::newBSTR(ouStr); return S_OK; } catch(...) { return E_FAIL; } @@ -487,9 +488,8 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textBeforeOffset(long offset return E_FAIL; TextSegment segment = pRXText->getTextBeforeIndex(offset, nUnoBoundaryType); - OUString ouStr = segment.SegmentText; SysFreeString(*text); - *text = SysAllocString(o3tl::toW(ouStr.getStr())); + *text = sal::systools::BStr::newBSTR(segment.SegmentText); *startOffset = segment.SegmentStart; *endOffset = segment.SegmentEnd; @@ -533,9 +533,8 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textAfterOffset(long offset, return E_FAIL; TextSegment segment = pRXText->getTextBehindIndex(offset, nUnoBoundaryType); - OUString ouStr = segment.SegmentText; SysFreeString(*text); - *text = SysAllocString(o3tl::toW(ouStr.getStr())); + *text = sal::systools::BStr::newBSTR(segment.SegmentText); *startOffset = segment.SegmentStart; *endOffset = segment.SegmentEnd; @@ -579,9 +578,8 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textAtOffset(long offset, IA return E_FAIL; TextSegment segment = pRXText->getTextAtIndex(offset, nUnoBoundaryType); - OUString ouStr = segment.SegmentText; SysFreeString(*text); - *text = SysAllocString(o3tl::toW(ouStr.getStr())); + *text = sal::systools::BStr::newBSTR(segment.SegmentText); *startOffset = segment.SegmentStart; *endOffset = segment.SegmentEnd; diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx b/winaccessibility/source/UAccCOM/MAccessible.cxx index cc08094eb1b1..b131782120cb 100644 --- a/winaccessibility/source/UAccCOM/MAccessible.cxx +++ b/winaccessibility/source/UAccCOM/MAccessible.cxx @@ -42,6 +42,7 @@ #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> #include <comphelper/AccessibleImplementationHelper.hxx> +#include <systools/win32/oleauto.hxx> #include <com/sun/star/accessibility/AccessibleRelationType.hpp> #include <com/sun/star/accessibility/XAccessibleText.hpp> @@ -378,7 +379,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_accName(VARIANT varChild, BS const OUString sName = xContext->getAccessibleName(); SysFreeString(*pszName); - *pszName = SysAllocString(o3tl::toW(sName.getStr())); + *pszName = sal::systools::BStr::newBSTR(sName); return S_OK; } @@ -470,7 +471,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_accDescription(VARIANT varCh const OUString sDescription = xContext->getAccessibleDescription(); SysFreeString(*pszDescription); - *pszDescription = SysAllocString(o3tl::toW(sDescription.getStr())); + *pszDescription = sal::systools::BStr::newBSTR(sDescription); return S_OK; } @@ -763,7 +764,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_accKeyboardShortcut(VARIANT } SysFreeString(*pszKeyboardShortcut); - *pszKeyboardShortcut = SysAllocString(o3tl::toW(wString.getStr())); + *pszKeyboardShortcut = sal::systools::BStr::newBSTR(wString); return S_OK; } @@ -2488,7 +2489,7 @@ void CMAccessible::ConvertAnyToVariant(const css::uno::Any &rAnyVal, VARIANT *pv pvData->vt = VT_BSTR; OUString val; rAnyVal >>= val; - pvData->bstrVal = SysAllocString(o3tl::toW(val.getStr())); + pvData->bstrVal = sal::systools::BStr::newBSTR(val); break; } @@ -2540,7 +2541,7 @@ void CMAccessible::ConvertAnyToVariant(const css::uno::Any &rAnyVal, VARIANT *pv case TypeClass::TypeClass_MAKE_FIXED_SIZE: // Output the type string, if there is other uno value type. pvData->vt = VT_BSTR; - pvData->bstrVal = SysAllocString(o3tl::toW(rAnyVal.getValueTypeName().getStr())); + pvData->bstrVal = sal::systools::BStr::newBSTR(rAnyVal.getValueTypeName()); break; default: @@ -2638,9 +2639,9 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_locale( IA2Locale __RPC_FAR return E_FAIL; css::lang::Locale unoLoc = m_xContext->getLocale(); - locale->language = SysAllocString(o3tl::toW(unoLoc.Language.getStr())); - locale->country = SysAllocString(o3tl::toW(unoLoc.Country.getStr())); - locale->variant = SysAllocString(o3tl::toW(unoLoc.Variant.getStr())); + locale->language = sal::systools::BStr::newBSTR(unoLoc.Language); + locale->country = sal::systools::BStr::newBSTR(unoLoc.Country); + locale->variant = sal::systools::BStr::newBSTR(unoLoc.Variant); return S_OK; @@ -2657,7 +2658,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_appName(BSTR __RPC_FAR *name return E_INVALIDARG; static const OUString sAppName = utl::ConfigManager::getProductName(); - *name = SysAllocString(o3tl::toW(sAppName.getStr())); + *name = sal::systools::BStr::newBSTR(sAppName); return S_OK; } catch(...) { return E_FAIL; } } @@ -2670,7 +2671,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_appVersion(BSTR __RPC_FAR *v if(version == nullptr) return E_INVALIDARG; static const OUString sVersion = utl::ConfigManager::getProductVersion(); - *version=SysAllocString(o3tl::toW(sVersion.getStr())); + *version = sal::systools::BStr::newBSTR(sVersion); return S_OK; } catch(...) { return E_FAIL; } } @@ -2734,7 +2735,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CMAccessible::get_attributes(/*[out]*/ BSTR *p if (*pAttr) SysFreeString(*pAttr); - *pAttr = SysAllocString(o3tl::toW(sAttributes.getStr())); + *pAttr = sal::systools::BStr::newBSTR(sAttributes); return S_OK; } catch(...) { return E_FAIL; } |