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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 27 11:02:50 UTC 2020


 include/vcl/svlbitm.hxx         |    3 +++
 include/vcl/vclenum.hxx         |    7 +++++++
 include/vcl/weld.hxx            |    2 ++
 vcl/source/app/salvtables.cxx   |   24 ++++++++++++++++++++++++
 vcl/source/treelist/svlbitm.cxx |   20 +++++++++++++++++++-
 vcl/unx/gtk3/gtk3gtkinst.cxx    |   31 +++++++++++++++++++++++++++++++
 6 files changed, 86 insertions(+), 1 deletion(-)

New commits:
commit 1a7489039e8acbd9499276fdb6e747e11d3ecffe
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Mar 26 15:24:24 2020 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Mar 27 12:02:12 2020 +0100

    add text alignment support to treeview entries
    
    Change-Id: I3ebbaf7b722ad9b6f2b8fadb443053ea816d1643
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91147
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/svlbitm.hxx b/include/vcl/svlbitm.hxx
index b5d00aa95f6b..dc8cde9bcb02 100644
--- a/include/vcl/svlbitm.hxx
+++ b/include/vcl/svlbitm.hxx
@@ -105,6 +105,7 @@ class VCL_DLLPUBLIC SvLBoxString : public SvLBoxItem
 {
 private:
     bool mbEmphasized;
+    double mfAlign;
 protected:
     OUString maText;
 
@@ -120,6 +121,8 @@ public:
 
     virtual int CalcWidth(const SvTreeListBox* pView) const override;
 
+    void Align(double fAlign) { mfAlign = fAlign; }
+
     void Emphasize(bool bEmphasize) { mbEmphasized = bEmphasize; }
     bool IsEmphasized() const { return mbEmphasized; }
 
diff --git a/include/vcl/vclenum.hxx b/include/vcl/vclenum.hxx
index b5423b46e5de..4175c5f37c41 100644
--- a/include/vcl/vclenum.hxx
+++ b/include/vcl/vclenum.hxx
@@ -276,6 +276,13 @@ enum class VclPolicyType
     NEVER
 };
 
+enum class VclTextAlignment
+{
+    LEFT,
+    CENTER,
+    RIGHT
+};
+
 enum class WizardButtonFlags : sal_Int16
 {
     NONE                = 0x0000,
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index b7bf769063c6..35e474ca4a3b 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -854,6 +854,7 @@ public:
         = 0;
     virtual void set_text_emphasis(int row, bool bOn, int col) = 0;
     virtual bool get_text_emphasis(int row, int col) const = 0;
+    virtual void set_text_align(int row, double fAlign, int col) = 0;
     virtual void swap(int pos1, int pos2) = 0;
     virtual std::vector<int> get_selected_rows() const = 0;
     virtual void set_font_color(int pos, const Color& rColor) = 0;
@@ -939,6 +940,7 @@ public:
     virtual void set_sensitive(const TreeIter& rIter, bool bSensitive, int col = -1) = 0;
     virtual void set_text_emphasis(const TreeIter& rIter, bool bOn, int col) = 0;
     virtual bool get_text_emphasis(const TreeIter& rIter, int col) const = 0;
+    virtual void set_text_align(const TreeIter& rIter, double fAlign, int col) = 0;
     virtual void set_toggle(const TreeIter& rIter, TriState bOn, int col) = 0;
     virtual TriState get_toggle(const TreeIter& rIter, int col) const = 0;
     virtual OUString get_text(const TreeIter& rIter, int col = -1) const = 0;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index cf83fa8a0cd9..9d6e20c9a1f5 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -3936,6 +3936,30 @@ public:
         return ::get_text_emphasis(pEntry, col);
     }
 
+    void set_text_align(SvTreeListEntry* pEntry, double fAlign, int col)
+    {
+        ++col; //skip dummy/expander column
+
+        assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
+        SvLBoxItem& rItem = pEntry->GetItem(col);
+        assert(dynamic_cast<SvLBoxString*>(&rItem));
+        static_cast<SvLBoxString&>(rItem).Align(fAlign);
+
+        m_xTreeView->ModelHasEntryInvalidated(pEntry);
+    }
+
+    virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int col) override
+    {
+        const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter);
+        set_text_align(rVclIter.iter, fAlign, col);
+    }
+
+    virtual void set_text_align(int pos, double fAlign, int col) override
+    {
+        SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos);
+        set_text_align(pEntry, fAlign, col);
+    }
+
     virtual void connect_editing(
         const Link<const weld::TreeIter&, bool>& rStartLink,
         const Link<const std::pair<const weld::TreeIter&, OUString>&, bool>& rEndLink) override
diff --git a/vcl/source/treelist/svlbitm.cxx b/vcl/source/treelist/svlbitm.cxx
index 6e4c2d14be2d..cd7fbae06b97 100644
--- a/vcl/source/treelist/svlbitm.cxx
+++ b/vcl/source/treelist/svlbitm.cxx
@@ -174,12 +174,14 @@ bool SvLBoxButtonData::IsRadio() const {
 
 SvLBoxString::SvLBoxString(const OUString& rStr)
     : mbEmphasized(false)
+    , mfAlign(0.0)
     , maText(rStr)
 {
 }
 
 SvLBoxString::SvLBoxString()
     : mbEmphasized(false)
+    , mfAlign(0.0)
 {
 }
 
@@ -206,7 +208,23 @@ void SvLBoxString::Paint(
         aSize.setWidth( rDev.GetEntryWidth() );
     }
     else
-        aSize.setWidth(GetWidth(&rDev, &rEntry));
+    {
+        if (mfAlign < 0.5 )
+        {
+            nStyle |= DrawTextFlags::Left;
+            aSize.setWidth(GetWidth(&rDev, &rEntry));
+        }
+        else if (mfAlign == 0.5)
+        {
+            nStyle |= DrawTextFlags::Center;
+            aSize.setWidth(rDev.GetBoundingRect(&rEntry).getWidth());
+        }
+        else if (mfAlign > 0.5)
+        {
+            nStyle |= DrawTextFlags::Right;
+            aSize.setWidth(rDev.GetBoundingRect(&rEntry).getWidth());
+        }
+    }
     aSize.setHeight(GetHeight(&rDev, &rEntry));
 
     if (mbEmphasized)
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 6436c23d71ab..03386b798f17 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -8631,6 +8631,8 @@ private:
     std::map<int, int> m_aSensitiveMap;
     // map from text column to indent column
     std::map<int, int> m_aIndentMap;
+    // map from text column to text align column
+    std::map<int, int> m_aAlignMap;
     // currently expanding parent that logically, but not currently physically,
     // contain placeholders
     o3tl::sorted_vector<GtkTreePath*, CompareGtkTreePath> m_aExpandingPlaceHolderParents;
@@ -8841,6 +8843,19 @@ private:
             set(iter, col, bInt);
     }
 
+    void set(const GtkTreeIter& iter, int col, double fValue)
+    {
+        gtk_tree_store_set(m_pTreeStore, const_cast<GtkTreeIter*>(&iter), col, fValue, -1);
+    }
+
+    void set(int pos, int col, double fValue)
+    {
+        GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore);
+        GtkTreeIter iter;
+        if (gtk_tree_model_iter_nth_child(pModel, &iter, nullptr, pos))
+            set(iter, col, fValue);
+    }
+
     static gboolean signalTestExpandRow(GtkTreeView*, GtkTreeIter* iter, GtkTreePath*, gpointer widget)
     {
         GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget);
@@ -9274,6 +9289,7 @@ public:
                     m_aWeightMap[nIndex] = -1;
                     m_aSensitiveMap[nIndex] = -1;
                     m_aIndentMap[nIndex] = -1;
+                    m_aAlignMap[nIndex] = -1;
                     g_signal_connect(G_OBJECT(pCellRenderer), "editing-started", G_CALLBACK(signalCellEditingStarted), this);
                     g_signal_connect(G_OBJECT(pCellRenderer), "editing-canceled", G_CALLBACK(signalCellEditingCanceled), this);
                     g_signal_connect(G_OBJECT(pCellRenderer), "edited", G_CALLBACK(signalCellEdited), this);
@@ -9311,6 +9327,8 @@ public:
             a.second = nIndex++;
         for (auto& a : m_aIndentMap)
             a.second = nIndex++;
+        for (auto& a : m_aAlignMap)
+            a.second = nIndex++;
 
         ensure_drag_begin_end();
 
@@ -9862,6 +9880,19 @@ public:
         return get_int(pos, m_aWeightMap.find(col)->second) == PANGO_WEIGHT_BOLD;
     }
 
+    virtual void set_text_align(const weld::TreeIter& rIter, double fAlign, int col) override
+    {
+        const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter);
+        col = get_model_col(col);
+        set(rGtkIter.iter, m_aAlignMap[col], fAlign);
+    }
+
+    virtual void set_text_align(int pos, double fAlign, int col) override
+    {
+        col = get_model_col(col);
+        set(pos, m_aAlignMap[col], fAlign);
+    }
+
     using GtkInstanceWidget::set_sensitive;
 
     virtual void set_sensitive(int pos, bool bSensitive, int col) override


More information about the Libreoffice-commits mailing list