[Libreoffice-commits] core.git: include/svl svl/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Thu Nov 19 17:25:29 UTC 2020


 include/svl/svdde.hxx        |    6 +++---
 svl/source/svdde/ddedata.cxx |    4 ++--
 svl/source/svdde/ddesvr.cxx  |   23 ++++++++++-------------
 3 files changed, 15 insertions(+), 18 deletions(-)

New commits:
commit f54b1d1e0937cf43d74e34bfd5ae921923527a09
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Nov 19 11:54:51 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Thu Nov 19 18:24:48 2020 +0100

    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 at redhat.com>

diff --git a/include/svl/svdde.hxx b/include/svl/svdde.hxx
index beea2ef5e53d..e8b808ea1159 100644
--- a/include/svl/svdde.hxx
+++ b/include/svl/svdde.hxx
@@ -71,7 +71,7 @@ public:
     DdeData&        operator=(const DdeData&);
     DdeData&        operator=(DdeData&&) noexcept;
 
-    static sal_uLong GetExternalFormat(SotClipboardFormatId nFmt);
+    static sal_uInt32 GetExternalFormat(SotClipboardFormatId nFmt);
     static SotClipboardFormatId GetInternalFormat(sal_uLong nFmt);
 };
 
@@ -286,14 +286,14 @@ protected:
     const DdeTopic* GetSysTopic() const { return pSysTopic; }
 private:
     std::vector<DdeTopic*> aTopics;
-    std::vector< tools::Long >    aFormats;
+    std::vector< sal_uInt32 > aFormats;
     DdeTopic*       pSysTopic;
     DdeString*      pName;
     std::vector<std::unique_ptr<Conversation>>
                     m_vConv;
     short           nStatus;
 
-    SVL_DLLPRIVATE bool HasCbFormat( sal_uInt16 );
+    SVL_DLLPRIVATE bool HasCbFormat( sal_uInt32 );
 
 public:
                     DdeService( SAL_UNUSED_PARAMETER const OUString& );
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;


More information about the Libreoffice-commits mailing list