diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-11-19 11:54:51 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-11-19 18:24:48 +0100 |
commit | f54b1d1e0937cf43d74e34bfd5ae921923527a09 (patch) | |
tree | 59d720cec9ff02bc3f7e55c4770edf57c7f88b17 /svl | |
parent | f39f21d92ec83c3a5062f29dd26214fc83012c06 (diff) |
Clarify DdeData::GetExternalFormat return type
The implementation (in svl/source/svdde/ddedata.cxx) returns any of:
* {CF_TEXT=1, CF_BITMAP=2, CF_METFILEPICT=3} from the Windows API;
* the return value of Windows API's RegisterClipboardFormatW, which is UINT from
the Windows API (i.e., 32-bit unsigned int);
* a enum SotClipboardFormatId value, whose underlying type is sal_uInt32.
So the natural choice is sal_uInt32 here. (Windows API's UINT would also do,
but cannot be used in include/svl/svdde.hxx, which is used on all platforms.)
That in turn shows that DdeService's aFormats and HasCbFormat should also use
sal_uInt32. (And then, simplify some of the std algorithms use in
svl/source/svdde/ddesvr.cxx.)
Change-Id: I593d0a7df78bfdd08ce2de04c3da2078d973e262
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106151
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/svdde/ddedata.cxx | 4 | ||||
-rw-r--r-- | svl/source/svdde/ddesvr.cxx | 23 |
2 files changed, 12 insertions, 15 deletions
diff --git a/svl/source/svdde/ddedata.cxx b/svl/source/svdde/ddedata.cxx index 7cf9c0b1daa6..d8e1e1579226 100644 --- a/svl/source/svdde/ddedata.cxx +++ b/svl/source/svdde/ddedata.cxx @@ -121,7 +121,7 @@ DdeData& DdeData::operator=(DdeData&& rData) noexcept return *this; } -sal_uLong DdeData::GetExternalFormat(SotClipboardFormatId nFmt) +sal_uInt32 DdeData::GetExternalFormat(SotClipboardFormatId nFmt) { switch( nFmt ) { @@ -138,7 +138,7 @@ sal_uLong DdeData::GetExternalFormat(SotClipboardFormatId nFmt) return RegisterClipboardFormatW( o3tl::toW(aName.getStr()) ); } } - return static_cast<sal_uLong>(nFmt); + return static_cast<sal_uInt32>(nFmt); } SotClipboardFormatId DdeData::GetInternalFormat(sal_uLong nFmt) diff --git a/svl/source/svdde/ddesvr.cxx b/svl/source/svdde/ddesvr.cxx index 330e69f2b167..fe0e5c59f41b 100644 --- a/svl/source/svdde/ddesvr.cxx +++ b/svl/source/svdde/ddesvr.cxx @@ -491,31 +491,28 @@ void DdeService::RemoveTopic( const DdeTopic& rTopic ) } } -bool DdeService::HasCbFormat( sal_uInt16 nFmt ) +bool DdeService::HasCbFormat( sal_uInt32 nFmt ) { - return std::any_of(aFormats.begin(), aFormats.end(), - [nFmt](const long nFormat) { return nFormat == nFmt; }); + return std::find(aFormats.begin(), aFormats.end(), nFmt) != aFormats.end(); } bool DdeService::HasFormat(SotClipboardFormatId nFmt) { - return HasCbFormat( static_cast<sal_uInt16>(DdeData::GetExternalFormat( nFmt ))); + return HasCbFormat( DdeData::GetExternalFormat( nFmt )); } void DdeService::AddFormat(SotClipboardFormatId nFmt) { - sal_uLong nExternalFmt = DdeData::GetExternalFormat( nFmt ); - if (std::any_of(aFormats.begin(), aFormats.end(), - [nExternalFmt](const long nFormat) { return static_cast<sal_uLong>(nFormat) == nExternalFmt; })) + sal_uInt32 nExternalFmt = DdeData::GetExternalFormat( nFmt ); + if (HasCbFormat(nExternalFmt)) return; aFormats.push_back( nExternalFmt ); } void DdeService::RemoveFormat(SotClipboardFormatId nFmt) { - sal_uLong nExternalFmt = DdeData::GetExternalFormat( nFmt ); - auto it = std::find_if(aFormats.begin(), aFormats.end(), - [nExternalFmt](const long nFormat) { return static_cast<sal_uLong>(nFormat) == nExternalFmt; }); + sal_uInt32 nExternalFmt = DdeData::GetExternalFormat( nFmt ); + auto it = std::find(aFormats.begin(), aFormats.end(), nExternalFmt); if (it != aFormats.end()) aFormats.erase( it ); } @@ -822,11 +819,11 @@ OUString DdeService::Formats() for (size_t i = 0; i < aFormats.size(); ++i, ++n) { - long f = aFormats[ i ]; + sal_uInt32 f = aFormats[ i ]; if ( n ) s += "\t"; - switch( static_cast<sal_uInt16>(f) ) + switch( f ) { case CF_TEXT: s += "TEXT"; @@ -837,7 +834,7 @@ OUString DdeService::Formats() default: { WCHAR buf[128]; - GetClipboardFormatNameW( static_cast<UINT>(f), buf, SAL_N_ELEMENTS(buf) ); + GetClipboardFormatNameW( f, buf, SAL_N_ELEMENTS(buf) ); s += o3tl::toU(buf); } break; |