include/svx/svdpage.hxx              |    2 ++
 sd/inc/sdpage.hxx                    |    1 -
 sd/source/core/sdpage.cxx            |    5 -----
 sd/source/ui/unoidl/unomodel.cxx     |    9 ++++-----
 svx/source/annotation/Annotation.cxx |    4 ++--
 svx/source/svdraw/svdpage.cxx        |    9 +++++++++
 6 files changed, 17 insertions(+), 13 deletions(-)

New commits:
commit 5779dc944c5427d84c23a3a9c466a0caafb46689
Author:     Gökay Şatır <gokaysa...@collabora.com>
AuthorDate: Thu Jun 27 20:45:26 2024 +0300
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Jun 27 21:22:31 2024 +0200

    Update getPartHash function.
    
    Current hash uses this pointer so it gives different values for another 
pointer.
    
    Signed-off-by: Gökay Şatır <gokaysa...@collabora.com>
    Change-Id: I1a687a56ed90d01821a97f3d350759a0dd2621e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169660
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index 32bd6903501a..2aea6f585e31 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -433,6 +433,7 @@ private:
     sal_Int32 mnBorderUpper; // top page margin
     sal_Int32 mnBorderRight; // right page margin
     sal_Int32 mnBorderLower; // bottom page margin
+    sal_Int64 nRandomHash; // Unique value for the page.
     bool mbBackgroundFullSize = false; ///< Background object to represent the 
whole page.
 
     std::unique_ptr<SdrLayerAdmin> mpLayerAdmin;
@@ -504,6 +505,7 @@ public:
     sal_Int32 GetUpperBorder() const;
     sal_Int32 GetRightBorder() const;
     sal_Int32 GetLowerBorder() const;
+    sal_Int64 GetPageRandomHash() const { return this->nRandomHash; }
     void    SetBackgroundFullSize(bool bIn);
     bool    IsBackgroundFullSize() const;
 
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx
index ebc4a2b5abba..5de35a9fb3a9 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -171,7 +171,6 @@ public:
     OUString        GetPresObjText(PresObjKind eObjKind) const;
     SfxStyleSheet* GetStyleSheetForMasterPageBackground() const;
     SfxStyleSheet*  GetStyleSheetForPresObj(PresObjKind eObjKind) const;
-    sal_Int64       GetHashCode() const;
     bool            RestoreDefaultText( SdrObject* pObj );
 
     /** @return true if the given SdrObject is inside the presentation object 
list */
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index 10b4f34b761f..07df2efa4b1d 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -2696,11 +2696,6 @@ SdPage* SdPage::getImplementation( const 
css::uno::Reference< css::drawing::XDra
     return nullptr;
 }
 
-sal_Int64 SdPage::GetHashCode() const
-{
-    return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
-}
-
 void SdPage::SetName (const OUString& rName)
 {
     OUString aOldName( GetName() );
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 1f4777ed7dfc..84f9a36b5e44 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2597,8 +2597,7 @@ OUString SdXImpressDocument::getPartHash(int nPart)
         return OUString();
     }
 
-    uno::Reference<drawing::XDrawPage> xDrawPage(pPage->getUnoPage(), 
uno::UNO_QUERY);
-    return OUString::fromUtf8(GetInterfaceHash(xDrawPage));
+    return OUString::number(pPage->GetPageRandomHash());
 }
 
 bool SdXImpressDocument::isMasterViewMode()
@@ -2694,10 +2693,10 @@ void 
SdXImpressDocument::getPostIts(::tools::JsonWriter& rJsonWriter)
     auto commentsNode = rJsonWriter.startNode("comments");
     // Return annotations on master pages too ?
     const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
-    SdPage* pPage;
+    SdrPage* pPage;
     for (sal_uInt16 nPage = 0; nPage < nMaxPages; ++nPage)
     {
-        pPage = static_cast<SdPage*>(mpDoc->GetPage(nPage));
+        pPage = mpDoc->GetPage(nPage);
 
         for (auto const& xAnnotation : pPage->getAnnotations())
         {
@@ -2709,7 +2708,7 @@ void SdXImpressDocument::getPostIts(::tools::JsonWriter& 
rJsonWriter)
             rJsonWriter.put("dateTime", 
utl::toISO8601(xAnnotation->getDateTime()));
             uno::Reference<text::XText> xText(xAnnotation->getTextRange());
             rJsonWriter.put("text", xText->getString());
-            rJsonWriter.put("parthash", pPage->GetHashCode());
+            rJsonWriter.put("parthash", pPage->GetPageRandomHash());
             geometry::RealPoint2D const & rPoint = xAnnotation->getPosition();
             geometry::RealSize2D const & rSize = xAnnotation->getSize();
             ::tools::Rectangle aRectangle(Point(rPoint.X * 100.0, rPoint.Y * 
100.0), Size(rSize.Width * 100.0, rSize.Height * 100.0));
diff --git a/svx/source/annotation/Annotation.cxx 
b/svx/source/annotation/Annotation.cxx
index 512280d29b4f..2efca7d9bbcf 100644
--- a/svx/source/annotation/Annotation.cxx
+++ b/svx/source/annotation/Annotation.cxx
@@ -44,8 +44,8 @@ OString lcl_LOKGetCommentPayload(CommentNotificationType 
nType, Annotation& rAnn
             aJsonWriter.put("dateTime", 
utl::toISO8601(rAnnotation.GetDateTime()));
             aJsonWriter.put("text", rAnnotation.GetText());
             SdrPage const* pPage = rAnnotation.getPage();
-            sal_Int64 nHash = 
sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pPage));
-            aJsonWriter.put("parthash", pPage ? OString::number(nHash) : 
OString());
+            aJsonWriter.put("parthash",
+                            pPage ? 
OString::number(pPage->GetPageRandomHash()) : OString());
             geometry::RealPoint2D const& rPoint = rAnnotation.GetPosition();
             geometry::RealSize2D const& rSize = rAnnotation.GetSize();
             tools::Rectangle aRectangle(
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 9da7c5a63978..4022a99b0685 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -58,6 +58,7 @@
 #include <svl/hint.hxx>
 #include <rtl/strbuf.hxx>
 #include <libxml/xmlwriter.h>
+#include <rtl/random.h>
 #include <docmodel/theme/Theme.hxx>
 
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
@@ -1324,6 +1325,14 @@ SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage)
     mbPageBorderOnlyLeftRight(false)
 {
     mpSdrPageProperties.reset(new SdrPageProperties(*this));
+
+    sal_Int8 random1;
+    (void)rtl_random_getBytes(nullptr, &random1, 1);
+
+    sal_Int8 random2;
+    (void)rtl_random_getBytes(nullptr, &random2, 1);
+
+    this->nRandomHash = random1 * random2;
 }
 
 SdrPage::~SdrPage()

Reply via email to