summaryrefslogtreecommitdiff
path: root/cui/source
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-11-07 15:52:53 -0500
committerJustin Luth <justin.luth@collabora.com>2024-12-10 00:07:59 +0100
commita366cd34a85a21210939482d229d6d2dd9c1087c (patch)
treeae5112967ce1b4763c9dc1f4d00b01cb608076b5 /cui/source
parentd97085cc6cd2bdc3b6723d1960d0ec5fa0a48165 (diff)
tdf#125969 cui: add in-use area image to bitmap list
This fixes a five year old (non-)easyhack with 3 duplicates. Note the nice-to-have dependencies in the bug report(s). When the document has a unique background (area) image, it is now added to the list of available images IF/WHEN the user looks in the area tab. This allows the user to switch back after changing, or re-use it in other places in the document. Most of this patch ended up being plumbing to ensure that this added image is ONLY available to the current document, because it MUST NOT be saved to the user profile. This change affects all apps and all types of areas: NICE -tested Writer pages, paragraphs, headers, textbox, sidebar(page) -tested Calc page style -tested Draw page, sidebar(page), textbox Caveats: -the bitmap list is NOT updated at the time of document import, only when area property inspected. (The bug requesting inclusion at the time of import is tdf#100832). make -srj1 UITest_writer_tests8 \ UITEST_TEST_NAME=tdf125969.tdf125969.test_tdf125969 \ SAL_USE_VCLPLUGIN=gen Change-Id: Ic9fea9b199602c4df1376e781d5df019526473d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176253 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'cui/source')
-rw-r--r--cui/source/inc/cuitabarea.hxx2
-rw-r--r--cui/source/tabpages/tpbitmap.cxx50
2 files changed, 38 insertions, 14 deletions
diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index 7021a7aa7847..30feba7fe85f 100644
--- a/cui/source/inc/cuitabarea.hxx
+++ b/cui/source/inc/cuitabarea.hxx
@@ -551,6 +551,8 @@ private:
void CalculateBitmapPresetSize();
sal_Int32 SearchBitmapList(std::u16string_view rBitmapName);
sal_Int32 SearchBitmapList(const GraphicObject& rGraphicObject);
+ tools::Long AddBitmap(const GraphicObject& rGraphicObject, const OUString& rName,
+ bool bOnlyForThisDocument = false);
public:
SvxBitmapTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs);
diff --git a/cui/source/tabpages/tpbitmap.cxx b/cui/source/tabpages/tpbitmap.cxx
index 9e016879b4cb..a4154aa344c8 100644
--- a/cui/source/tabpages/tpbitmap.cxx
+++ b/cui/source/tabpages/tpbitmap.cxx
@@ -37,8 +37,10 @@
#include <dialmgr.hxx>
#include <svx/dlgutil.hxx>
#include <svl/intitem.hxx>
+#include <sfx2/bindings.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/opengrf.hxx>
+#include <sfx2/viewfrm.hxx>
#include <vcl/image.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
@@ -167,9 +169,13 @@ void SvxBitmapTabPage::ActivatePage( const SfxItemSet& rSet )
sal_Int32 nPos( 0 );
if ( !aItem.isPattern() )
{
- nPos = SearchBitmapList( aItem.GetGraphicObject() );
- if (nPos == -1)
+ const GraphicObject& aGraphicObj = aItem.GetGraphicObject();
+ if (aGraphicObj.GetType() != GraphicType::Bitmap)
return;
+
+ nPos = SearchBitmapList(aGraphicObj);
+ if (nPos == -1)
+ nPos = AddBitmap(aGraphicObj, aItem.GetName(), /*OnlyForThisDocument=*/true);
}
else
{
@@ -781,18 +787,7 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickImportHdl, weld::Button&, void)
pDlg.disposeAndClear();
if( !nError )
- {
- m_pBitmapList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName), nCount);
-
- sal_Int32 nId = m_xBitmapLB->GetItemId( nCount - 1 );
- BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview( nCount, m_xBitmapLB->GetIconSize() );
-
- m_xBitmapLB->InsertItem( nId + 1, Image(aBitmap), aName );
- m_xBitmapLB->SelectItem( nId + 1 );
- m_nBitmapListState |= ChangeType::MODIFIED;
-
- ModifyBitmapHdl(m_xBitmapLB.get());
- }
+ AddBitmap(aGraphic, aName);
}
else
{
@@ -836,4 +831,31 @@ sal_Int32 SvxBitmapTabPage::SearchBitmapList(std::u16string_view rBitmapName)
return nPos;
}
+tools::Long SvxBitmapTabPage::AddBitmap(const GraphicObject& rGraphicObject, const OUString& rName,
+ bool bOnlyForThisDocument)
+{
+ const tools::Long nLastPos = m_pBitmapList->Count();
+
+ auto xBitmapEntry = std::make_unique<XBitmapEntry>(rGraphicObject, rName);
+ if (bOnlyForThisDocument)
+ xBitmapEntry->SetSavingAllowed(false);
+ m_pBitmapList->Insert(std::move(xBitmapEntry), nLastPos);
+
+ BitmapEx aBitmap = m_pBitmapList->GetBitmapForPreview(nLastPos, m_xBitmapLB->GetIconSize());
+
+ const sal_uInt16 nHighestId = m_xBitmapLB->GetItemId(nLastPos - 1);
+ m_xBitmapLB->InsertItem(nHighestId + 1, Image(aBitmap), rName);
+ m_xBitmapLB->SelectItem(nHighestId + 1);
+ m_nBitmapListState |= ChangeType::MODIFIED;
+
+ ModifyBitmapHdl(m_xBitmapLB.get());
+
+ // inform sidebar, etc. that the list of images has changed.
+ SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+ if (pViewFrame)
+ pViewFrame->GetBindings().Invalidate(SID_ATTR_PAGE_BITMAP, /*ClearCacheStatus=*/true);
+
+ return nLastPos;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */