[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - include/svx include/vcl svx/source svx/uiconfig vcl/source vcl/unx

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 12 09:32:36 UTC 2021


 include/svx/fontworkgallery.hxx          |    7 +---
 include/vcl/weld.hxx                     |    9 +++++
 svx/source/tbxctrls/fontworkgallery.cxx  |   54 +++++++++----------------------
 svx/uiconfig/ui/fontworkgallerydialog.ui |   37 +++++++++++++--------
 vcl/source/app/salvtables.cxx            |   40 ++++++++++++++++++++++
 vcl/unx/gtk3/gtk3gtkinst.cxx             |   28 ++++++++++++++++
 6 files changed, 119 insertions(+), 56 deletions(-)

New commits:
commit e964ffb3010eace108944a87f8957a34dda9f121
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Jan 8 09:28:38 2021 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Tue Jan 12 10:31:59 2021 +0100

    Fontwork dialog: use iconview
    
    Change-Id: I5bb35407ca83c9b0cda6f6355e6e25c21fecb459
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108960
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/include/svx/fontworkgallery.hxx b/include/svx/fontworkgallery.hxx
index af27c1eb0a5b..b8a3f954eb98 100644
--- a/include/svx/fontworkgallery.hxx
+++ b/include/svx/fontworkgallery.hxx
@@ -52,17 +52,16 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC FontWorkGalleryDialog final : public weld::G
     SdrObject**         mppSdrObject;
     SdrModel*           mpDestModel;
 
-    std::vector<BitmapEx> maFavoritesHorizontal;
+    std::vector<VclPtr< VirtualDevice >> maFavoritesHorizontal;
 
-    SvtValueSet maCtlFavorites;
-    std::unique_ptr<weld::CustomWeld> mxCtlFavorites;
+    std::unique_ptr<weld::IconView> maCtlFavorites;
     std::unique_ptr<weld::Button> mxOKButton;
 
     void            initFavorites(sal_uInt16 nThemeId);
     void            insertSelectedFontwork();
     void            fillFavorites(sal_uInt16 nThemeId);
 
-    DECL_LINK(DoubleClickFavoriteHdl, SvtValueSet*, void);
+    DECL_LINK(DoubleClickFavoriteHdl, weld::IconView&, bool);
     DECL_LINK(ClickOKHdl, weld::Button&, void );
 
 public:
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 3acf96b1fcf7..c07de42a9d2b 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1062,11 +1062,20 @@ public:
                         const OUString* pIconName, TreeIter* pRet)
         = 0;
 
+    virtual void insert(int pos, const OUString* pStr, const OUString* pId,
+                        const VirtualDevice* pIcon, TreeIter* pRet)
+        = 0;
+
     void append(const OUString& rId, const OUString& rStr, const OUString& rImage)
     {
         insert(-1, &rStr, &rId, &rImage, nullptr);
     }
 
+    void append(const OUString& rId, const OUString& rStr, const VirtualDevice* pImage)
+    {
+        insert(-1, &rStr, &rId, pImage, nullptr);
+    }
+
     void connect_selection_changed(const Link<IconView&, void>& rLink)
     {
         m_aSelectionChangeHdl = rLink;
diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx
index 1b2483f11e4e..036060109918 100644
--- a/svx/source/tbxctrls/fontworkgallery.cxx
+++ b/svx/source/tbxctrls/fontworkgallery.cxx
@@ -63,29 +63,21 @@ using namespace ::com::sun::star::beans;
 namespace svx
 {
 
-const int nColCount = 4;
-const int nLineCount = 4;
-
 FontWorkGalleryDialog::FontWorkGalleryDialog(weld::Window* pParent, SdrView& rSdrView)
     : GenericDialogController(pParent, "svx/ui/fontworkgallerydialog.ui", "FontworkGalleryDialog")
     , mnThemeId(0xffff)
     , mrSdrView(rSdrView)
     , mppSdrObject(nullptr)
     , mpDestModel(nullptr)
-    , maCtlFavorites(m_xBuilder->weld_scrolled_window("ctlFavoriteswin"))
-    , mxCtlFavorites(new weld::CustomWeld(*m_xBuilder, "ctlFavorites", maCtlFavorites))
+    , maCtlFavorites(m_xBuilder->weld_icon_view("ctlFavoriteswin"))
     , mxOKButton(m_xBuilder->weld_button("ok"))
 {
-    Size aSize(maCtlFavorites.GetDrawingArea()->get_ref_device().LogicToPixel(Size(200, 200), MapMode(MapUnit::MapAppFont)));
-    mxCtlFavorites->set_size_request(aSize.Width(), aSize.Height());
+    Size aSize(530, 400);
+    maCtlFavorites->set_size_request(aSize.Width(), aSize.Height());
 
-    maCtlFavorites.SetDoubleClickHdl( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) );
+    maCtlFavorites->connect_item_activated( LINK( this, FontWorkGalleryDialog, DoubleClickFavoriteHdl ) );
     mxOKButton->connect_clicked(LINK(this, FontWorkGalleryDialog, ClickOKHdl));
 
-    maCtlFavorites.SetColCount( nColCount );
-    maCtlFavorites.SetLineCount( nLineCount );
-    maCtlFavorites.SetExtraSpacing( 3 );
-
     initFavorites( GALLERY_THEME_FONTWORK );
     fillFavorites( GALLERY_THEME_FONTWORK );
 }
@@ -111,7 +103,7 @@ void FontWorkGalleryDialog::initFavorites(sal_uInt16 nThemeId)
 
         if (GalleryExplorer::GetSdrObj(nThemeId, nModelPos, pModel, &aThumb) && !!aThumb)
         {
-            ScopedVclPtrInstance< VirtualDevice > pVDev;
+            VclPtr< VirtualDevice > pVDev = VclPtr<VirtualDevice>::Create();
             const Point aNull(0, 0);
 
             if (pVDev->GetDPIScaleFactor() > 1)
@@ -128,7 +120,7 @@ void FontWorkGalleryDialog::initFavorites(sal_uInt16 nThemeId)
             pVDev->DrawCheckered(aNull, aSize, nLen, aW, aG);
 
             pVDev->DrawBitmapEx(aNull, aThumb);
-            maFavoritesHorizontal.emplace_back(pVDev->GetBitmapEx(aNull, aSize));
+            maFavoritesHorizontal.emplace_back(pVDev);
         }
     }
 
@@ -140,33 +132,18 @@ void FontWorkGalleryDialog::fillFavorites(sal_uInt16 nThemeId)
 {
     mnThemeId = nThemeId;
 
-    Size aThumbSize(maCtlFavorites.GetOutputSizePixel());
-    aThumbSize.setWidth( aThumbSize.Width() / nColCount );
-    aThumbSize.setHeight( aThumbSize.Height() / nLineCount );
-    aThumbSize.AdjustWidth( -12 );
-    aThumbSize.AdjustHeight( -12 );
-
     auto nFavCount = maFavoritesHorizontal.size();
 
-    // ValueSet favorites
-    if( nFavCount > (nColCount * nLineCount) )
-    {
-        WinBits nWinBits = maCtlFavorites.GetStyle();
-        nWinBits |= WB_VSCROLL;
-        maCtlFavorites.SetStyle( nWinBits );
-    }
-
-    maCtlFavorites.Clear();
+    maCtlFavorites->clear();
 
     for( size_t nFavorite = 1; nFavorite <= nFavCount; nFavorite++ )
     {
-        OUString aStr = SvxResId(RID_SVXFLOAT3D_FAVORITE) + " " + OUString::number(nFavorite);
-        Image aThumbImage( maFavoritesHorizontal[nFavorite-1] );
-        maCtlFavorites.InsertItem( static_cast<sal_uInt16>(nFavorite), aThumbImage, aStr );
+        OUString sId = OUString::number(static_cast<sal_uInt16>(nFavorite));
+        maCtlFavorites->append(sId, "", maFavoritesHorizontal[nFavorite-1]);
     }
 
-    if (maCtlFavorites.GetItemCount())
-        maCtlFavorites.SelectItem(1);
+    if (maCtlFavorites->n_children())
+        maCtlFavorites->select(0);
 }
 
 void FontWorkGalleryDialog::SetSdrObjectRef( SdrObject** ppSdrObject, SdrModel* pModel )
@@ -177,14 +154,14 @@ void FontWorkGalleryDialog::SetSdrObjectRef( SdrObject** ppSdrObject, SdrModel*
 
 void FontWorkGalleryDialog::insertSelectedFontwork()
 {
-    sal_uInt16 nItemId = maCtlFavorites.GetSelectedItemId();
+    OUString nItemId = maCtlFavorites->get_selected_id();
 
-    if( nItemId > 0 )
+    if( !nItemId.isEmpty() )
     {
         std::unique_ptr<FmFormModel> pModel(new FmFormModel());
         pModel->GetItemPool().FreezeIdRanges();
 
-        if( GalleryExplorer::GetSdrObj( mnThemeId, nItemId-1, pModel.get() ) )
+        if( GalleryExplorer::GetSdrObj( mnThemeId, nItemId.toInt32()-1, pModel.get() ) )
         {
             SdrPage* pPage = pModel->GetPage(0);
             if( pPage && pPage->GetObjCount() )
@@ -257,10 +234,11 @@ IMPL_LINK_NOARG(FontWorkGalleryDialog, ClickOKHdl, weld::Button&, void)
     m_xDialog->response(RET_OK);
 }
 
-IMPL_LINK_NOARG(FontWorkGalleryDialog, DoubleClickFavoriteHdl, SvtValueSet*, void)
+IMPL_LINK_NOARG(FontWorkGalleryDialog, DoubleClickFavoriteHdl, weld::IconView&, bool)
 {
     insertSelectedFontwork();
     m_xDialog->response(RET_OK);
+    return true;
 }
 
 class FontworkAlignmentWindow : public ToolbarMenu
diff --git a/svx/uiconfig/ui/fontworkgallerydialog.ui b/svx/uiconfig/ui/fontworkgallerydialog.ui
index 1ead11bc1fdd..3d7a81687f1b 100644
--- a/svx/uiconfig/ui/fontworkgallerydialog.ui
+++ b/svx/uiconfig/ui/fontworkgallerydialog.ui
@@ -2,6 +2,16 @@
 <!-- Generated with glade 3.22.1 -->
 <interface domain="svx">
   <requires lib="gtk+" version="3.18"/>
+  <object class="GtkTreeStore" id="liststore1">
+    <columns>
+      <!-- column-name expander -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="FontworkGalleryDialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
@@ -97,25 +107,24 @@
               </packing>
             </child>
             <child>
-              <object class="GtkScrolledWindow" id="ctlFavoriteswin">
+              <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
+                <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
-                <property name="hscrollbar_policy">never</property>
-                <property name="vscrollbar_policy">never</property>
+                <property name="vexpand">True</property>
                 <property name="shadow_type">in</property>
                 <child>
-                  <object class="GtkViewport">
+                  <object class="GtkIconView" id="ctlFavoriteswin">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkDrawingArea" id="ctlFavorites">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
-                        <property name="hexpand">True</property>
-                      </object>
-                    </child>
+                    <property name="can_focus">True</property>
+                    <property name="margin">6</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <property name="model">liststore1</property>
+                    <property name="columns">3</property>
+                    <property name="item_width">100</property>
+                    <property name="pixbuf-column">0</property>
+                    <property name="text-column">1</property>
                   </object>
                 </child>
               </object>
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index ed8f9d57e0cd..77498436bf86 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -4813,6 +4813,46 @@ public:
         enable_notify_events();
     }
 
+    virtual void insert(int pos, const OUString* pStr, const OUString* pId, const VirtualDevice* pIcon, weld::TreeIter* pRet) override
+    {
+        disable_notify_events();
+        auto nInsertPos = pos == -1 ? TREELIST_APPEND : pos;
+        void* pUserData;
+        if (pId)
+        {
+            m_aUserData.emplace_back(std::make_unique<OUString>(*pId));
+            pUserData = m_aUserData.back().get();
+        }
+        else
+            pUserData = nullptr;
+
+        SvTreeListEntry* pEntry = new SvTreeListEntry;
+        if (pIcon)
+        {
+            const Point aNull(0, 0);
+            const Size aSize = pIcon->GetOutputSizePixel();
+            Image aImage(pIcon->GetBitmapEx(aNull, aSize));
+            pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aImage, aImage, false));
+        }
+        else
+        {
+            Image aDummy;
+            pEntry->AddItem(std::make_unique<SvLBoxContextBmp>(aDummy, aDummy, false));
+        }
+        if (pStr)
+            pEntry->AddItem(std::make_unique<SvLBoxString>(*pStr));
+        pEntry->SetUserData(pUserData);
+        m_xIconView->Insert(pEntry, nullptr, nInsertPos);
+
+        if (pRet)
+        {
+            SalInstanceTreeIter* pVclRetIter = static_cast<SalInstanceTreeIter*>(pRet);
+            pVclRetIter->iter = pEntry;
+        }
+
+        enable_notify_events();
+    }
+
     virtual OUString get_selected_id() const override
     {
         assert(m_xIconView->IsUpdateMode() && "don't request selection when frozen");
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index b51534a45cef..25c54899d9eb 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -10590,6 +10590,21 @@ private:
         }
     }
 
+    void insert_item(GtkTreeIter& iter, int pos, const OUString* pId, const OUString* pText, const VirtualDevice* pIcon)
+    {
+        gtk_tree_store_insert_with_values(m_pTreeStore, &iter, nullptr, pos,
+                                          m_nTextCol, !pText ? nullptr : OUStringToOString(*pText, RTL_TEXTENCODING_UTF8).getStr(),
+                                          m_nIdCol, !pId ? nullptr : OUStringToOString(*pId, RTL_TEXTENCODING_UTF8).getStr(),
+                                          -1);
+        if (pIcon)
+        {
+            GdkPixbuf* pixbuf = getPixbuf(*pIcon);
+            gtk_tree_store_set(m_pTreeStore, &iter, m_nImageCol, pixbuf, -1);
+            if (pixbuf)
+                g_object_unref(pixbuf);
+        }
+    }
+
     OUString get(const GtkTreeIter& iter, int col) const
     {
         GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore);
@@ -10650,6 +10665,19 @@ public:
         enable_notify_events();
     }
 
+    virtual void insert(int pos, const OUString* pText, const OUString* pId, const VirtualDevice* pIcon, weld::TreeIter* pRet) override
+    {
+        disable_notify_events();
+        GtkTreeIter iter;
+        insert_item(iter, pos, pId, pText, pIcon);
+        if (pRet)
+        {
+            GtkInstanceTreeIter* pGtkRetIter = static_cast<GtkInstanceTreeIter*>(pRet);
+            pGtkRetIter->iter = iter;
+        }
+        enable_notify_events();
+    }
+
     virtual OUString get_selected_id() const override
     {
         assert(gtk_icon_view_get_model(m_pIconView) && "don't request selection when frozen");


More information about the Libreoffice-commits mailing list