tdf#168120 sc: Switch to weld::TreeView in CellLineStyleControl
Similar to how
commit 85dc059a39
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Thu Nov 27 22:29:52 2025 +0100
tdf#136905 tdf#169710 Use TreeView in PageSizeControl
did elswhere, also switch from using a (different)
custom control to using a weld::TreeView in the dropdown
to select from a list of border styles in the Calc sidebar.
The logic for creating the images for the single border
styles in CellLineStylePopup::CreateImage is based on
the existing logic in CellLineStyleValueSet::UserDraw
(which was used so far).
Indexes change because weld::TreeView indexes are
0-based while the ValueSet ones are 1-based
(and use 0 as a special value).
It will also no longer apply when switching from using
CellLineStyleValueSet to using a weld::TreeView in an
upcoming commit, because CellLineStyleValueSet uses
a 1-based index while weld::TreeView uses a 0-based one.
This reduces custom widget logic and custom drawing
and makes this more consistent with other widgets
used elsewhere.
This also addresses the issue of a font inconsistent
with what gets used elsewhere being used
previously, as mentioned in tdf#168120.
To trigger the dropdown:
* start Calc
* select a cell
* open the "Properties" deck in the sidebar
* in the "Cell Appearance" section, click on
the "Specify the borders of the selected cell"
control and select "Outer Border"
* click on the "Select the line style of your borders"
control (second control from the top on
the right hand side in the "Cell Appearance" section).
CellLineStyleValueSet is now unused and will be
dropped in an upcoming commit.
Change-Id: I05c1e5f8f3689af02b4337c65b4aaba481c67e86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194776
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
#include "CellLineStyleControl.hxx"
|
||||
#include "CellLineStyleValueSet.hxx"
|
||||
#include <vcl/i18nhelp.hxx>
|
||||
#include <vcl/settings.hxx>
|
||||
#include <vcl/svapp.hxx>
|
||||
@@ -37,14 +36,11 @@ CellLineStylePopup::CellLineStylePopup(weld::Toolbar* pParent, const OUString& r
|
||||
: WeldToolbarPopup(nullptr, pParent, u"modules/scalc/ui/floatinglinestyle.ui"_ustr, u"FloatingLineStyle"_ustr)
|
||||
, maToolButton(pParent, rId)
|
||||
, mpDispatcher(pDispatcher)
|
||||
, mxCellLineStyleValueSet(new sc::sidebar::CellLineStyleValueSet)
|
||||
, mxCellLineStyleValueSetWin(new weld::CustomWeld(*m_xBuilder, u"linestylevalueset"_ustr, *mxCellLineStyleValueSet))
|
||||
, mxCellLineStyleTreeView(m_xBuilder->weld_tree_view(u"linestyletreeview"_ustr))
|
||||
, mxPushButtonMoreOptions(m_xBuilder->weld_button(u"more"_ustr))
|
||||
{
|
||||
mxPushButtonMoreOptions->connect_clicked(LINK(this, CellLineStylePopup, PBClickHdl));
|
||||
|
||||
mxCellLineStyleValueSet->SetStyle(mxCellLineStyleValueSet->GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT);
|
||||
|
||||
const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetLocaleI18nHelper();
|
||||
const std::vector<OUString> aStrings = {
|
||||
ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", rI18nHelper.GetNum(5, 2)),
|
||||
@@ -60,38 +56,85 @@ CellLineStylePopup::CellLineStylePopup(weld::Toolbar* pParent, const OUString& r
|
||||
ScResId(STR_BORDER_DOUBLE_3).replaceFirst("%s", rI18nHelper.GetNum(305, 2)),
|
||||
ScResId(STR_BORDER_DOUBLE_4).replaceFirst("%s", rI18nHelper.GetNum(450, 2))
|
||||
};
|
||||
mxCellLineStyleValueSet->SetUnit(aStrings);
|
||||
|
||||
for (size_t i = 1; i <= aStrings.size(); ++i)
|
||||
for (size_t i = 0; i < aStrings.size(); ++i)
|
||||
{
|
||||
mxCellLineStyleValueSet->InsertItem(i);
|
||||
mxCellLineStyleValueSet->SetItemText(i, aStrings.at(i-1));
|
||||
}
|
||||
mxCellLineStyleTreeView->append();
|
||||
mxCellLineStyleTreeView->set_text(i, aStrings.at(i), 1);
|
||||
|
||||
SetAllNoSel();
|
||||
mxCellLineStyleValueSet->SetSelectHdl(LINK(this, CellLineStylePopup, VSSelectHdl));
|
||||
ScopedVclPtr<VirtualDevice> pDev = CreateImage(i);
|
||||
mxCellLineStyleTreeView->set_image(i, *pDev, 0);
|
||||
}
|
||||
mxCellLineStyleTreeView->columns_autosize();
|
||||
const int nHeight = mxCellLineStyleTreeView->get_preferred_size().Height();
|
||||
mxCellLineStyleTreeView->set_size_request(-1, nHeight);
|
||||
mxCellLineStyleTreeView->queue_resize();
|
||||
|
||||
mxCellLineStyleTreeView->connect_row_activated(LINK(this, CellLineStylePopup, StyleSelectHdl));
|
||||
}
|
||||
|
||||
CellLineStylePopup::~CellLineStylePopup()
|
||||
{
|
||||
}
|
||||
|
||||
VclPtr<VirtualDevice> CellLineStylePopup::CreateImage(int nIndex)
|
||||
{
|
||||
VclPtr<VirtualDevice> pDev = mxCellLineStyleTreeView->create_virtual_device();
|
||||
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
|
||||
pDev->SetBackground(rStyleSettings.GetFieldColor());
|
||||
pDev->SetLineColor(rStyleSettings.GetFieldTextColor());
|
||||
pDev->SetFillColor(pDev->GetLineColor());;
|
||||
pDev->SetOutputSizePixel(Size(50, 26));
|
||||
|
||||
constexpr tools::Long nX = 5;
|
||||
constexpr tools::Long nY = 10;
|
||||
constexpr tools::Long nTRX = 40;
|
||||
switch(nIndex)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + nIndex * 2 + 1 ));
|
||||
break;
|
||||
case 6:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + 1 ));
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY + 3 , nTRX, nY + 4 ));
|
||||
break;
|
||||
case 7:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + 1 ));
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY + 5 , nTRX, nY + 6 ));
|
||||
break;
|
||||
case 8:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + 1 ));
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY + 3 , nTRX, nY + 6 ));
|
||||
break;
|
||||
case 9:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + 3 ));
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY + 5 , nTRX, nY + 6 ));
|
||||
break;
|
||||
case 10:
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY , nTRX, nY + 3 ));
|
||||
pDev->DrawRect(tools::Rectangle(nX, nY + 5 , nTRX, nY + 8 ));
|
||||
break;
|
||||
}
|
||||
|
||||
return pDev;
|
||||
}
|
||||
|
||||
void CellLineStylePopup::GrabFocus()
|
||||
{
|
||||
mxCellLineStyleValueSet->GrabFocus();
|
||||
mxCellLineStyleTreeView->grab_focus();
|
||||
}
|
||||
|
||||
void CellLineStylePopup::SetAllNoSel()
|
||||
IMPL_LINK_NOARG(CellLineStylePopup, StyleSelectHdl, weld::TreeView&, bool)
|
||||
{
|
||||
mxCellLineStyleValueSet->SelectItem(0);
|
||||
mxCellLineStyleValueSet->SetNoSelection();
|
||||
mxCellLineStyleValueSet->SetFormat();
|
||||
mxCellLineStyleValueSet->Invalidate();
|
||||
}
|
||||
const int nIndex = mxCellLineStyleTreeView->get_selected_index();
|
||||
if (nIndex < 0)
|
||||
return false;
|
||||
|
||||
IMPL_LINK_NOARG(CellLineStylePopup, VSSelectHdl, ValueSet*, void)
|
||||
{
|
||||
const sal_uInt16 iPos(mxCellLineStyleValueSet->GetSelectedItemId());
|
||||
SvxLineItem aLineItem(SID_FRAME_LINESTYLE);
|
||||
SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
|
||||
sal_uInt16 n1 = 0;
|
||||
@@ -100,51 +143,51 @@ IMPL_LINK_NOARG(CellLineStylePopup, VSSelectHdl, ValueSet*, void)
|
||||
|
||||
//FIXME: fully for new border line possibilities
|
||||
|
||||
switch(iPos)
|
||||
switch(nIndex)
|
||||
{
|
||||
case 1:
|
||||
case 0:
|
||||
n1 = SvxBorderLineWidth::Hairline;
|
||||
break;
|
||||
case 2:
|
||||
case 1:
|
||||
n1 = SvxBorderLineWidth::VeryThin;
|
||||
break;
|
||||
case 3:
|
||||
case 2:
|
||||
n1 = SvxBorderLineWidth::Thin;
|
||||
break;
|
||||
case 4:
|
||||
case 3:
|
||||
n1 = SvxBorderLineWidth::Medium;
|
||||
break;
|
||||
case 5:
|
||||
case 4:
|
||||
n1 = SvxBorderLineWidth::Thick;
|
||||
break;
|
||||
case 6:
|
||||
case 5:
|
||||
n1 = SvxBorderLineWidth::ExtraThick;
|
||||
break;
|
||||
case 7:
|
||||
case 6:
|
||||
n1 = SvxBorderLineWidth::Hairline;
|
||||
n2 = SvxBorderLineWidth::Hairline;
|
||||
n3 = SvxBorderLineWidth::Medium;
|
||||
nStyle = SvxBorderLineStyle::DOUBLE;
|
||||
break;
|
||||
case 8:
|
||||
case 7:
|
||||
n1 = SvxBorderLineWidth::Hairline;
|
||||
n2 = SvxBorderLineWidth::Hairline;
|
||||
n3 = SvxBorderLineWidth::Thick;
|
||||
nStyle = SvxBorderLineStyle::DOUBLE;
|
||||
break;
|
||||
case 9:
|
||||
case 8:
|
||||
n1 = SvxBorderLineWidth::Thin;
|
||||
n2 = SvxBorderLineWidth::Medium;
|
||||
n3 = SvxBorderLineWidth::Thin;
|
||||
nStyle = SvxBorderLineStyle::DOUBLE;
|
||||
break;
|
||||
case 10:
|
||||
case 9:
|
||||
n1 = SvxBorderLineWidth::Medium;
|
||||
n2 = SvxBorderLineWidth::Hairline;
|
||||
n3 = SvxBorderLineWidth::Medium;
|
||||
nStyle = SvxBorderLineStyle::DOUBLE;
|
||||
break;
|
||||
case 11:
|
||||
case 10:
|
||||
n1 = SvxBorderLineWidth::Medium;
|
||||
n2 = SvxBorderLineWidth::Medium;
|
||||
n3 = SvxBorderLineWidth::Medium;
|
||||
@@ -159,9 +202,10 @@ IMPL_LINK_NOARG(CellLineStylePopup, VSSelectHdl, ValueSet*, void)
|
||||
aLineItem.SetLine( &aTmp );
|
||||
mpDispatcher->ExecuteList(
|
||||
SID_FRAME_LINESTYLE, SfxCallMode::RECORD, { &aLineItem });
|
||||
SetAllNoSel();
|
||||
mxCellLineStyleTreeView->unselect_all();
|
||||
|
||||
maToolButton.set_inactive();
|
||||
return true;
|
||||
}
|
||||
|
||||
IMPL_LINK_NOARG(CellLineStylePopup, PBClickHdl, weld::Button&, void)
|
||||
@@ -172,68 +216,64 @@ IMPL_LINK_NOARG(CellLineStylePopup, PBClickHdl, weld::Button&, void)
|
||||
|
||||
void CellLineStylePopup::SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis)
|
||||
{
|
||||
mxCellLineStyleValueSet->GrabFocus();
|
||||
SetAllNoSel();
|
||||
mxCellLineStyleTreeView->grab_focus();
|
||||
|
||||
//FIXME: fully for new border line possibilities
|
||||
|
||||
if (out == SvxBorderLineWidth::Hairline && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(1);
|
||||
mxCellLineStyleTreeView->select(0);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::VeryThin && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(2);
|
||||
mxCellLineStyleTreeView->select(1);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Thin && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(3);
|
||||
mxCellLineStyleTreeView->select(2);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Medium && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(4);
|
||||
mxCellLineStyleTreeView->select(3);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Thick && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(5);
|
||||
mxCellLineStyleTreeView->select(4);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::ExtraThick && in == 0 && dis == 0)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(6);
|
||||
mxCellLineStyleTreeView->select(5);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Hairline && in == SvxBorderLineWidth::Hairline
|
||||
&& dis == SvxBorderLineWidth::Thin)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(7);
|
||||
mxCellLineStyleTreeView->select(6);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Hairline && in == SvxBorderLineWidth::Hairline
|
||||
&& dis == SvxBorderLineWidth::Medium)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(8);
|
||||
mxCellLineStyleTreeView->select(7);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Thin && in == SvxBorderLineWidth::Medium
|
||||
&& dis == SvxBorderLineWidth::Thin)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(9);
|
||||
mxCellLineStyleTreeView->select(8);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Medium && in == SvxBorderLineWidth::Hairline
|
||||
&& dis == SvxBorderLineWidth::Medium)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(10);
|
||||
mxCellLineStyleTreeView->select(9);
|
||||
}
|
||||
else if (out == SvxBorderLineWidth::Medium && in == SvxBorderLineWidth::Medium
|
||||
&& dis == SvxBorderLineWidth::Medium)
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(11);
|
||||
mxCellLineStyleTreeView->select(10);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mxCellLineStyleValueSet->SetSelItem(0);
|
||||
mxCellLineStyleTreeView->unselect_all();
|
||||
mxPushButtonMoreOptions->grab_focus();
|
||||
}
|
||||
mxCellLineStyleValueSet->SetFormat();
|
||||
mxCellLineStyleValueSet->Invalidate();
|
||||
}
|
||||
|
||||
} // end of namespace sc::sidebar
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include <svtools/toolbarmenu.hxx>
|
||||
#include <svx/colorwindow.hxx>
|
||||
#include "CellLineStyleValueSet.hxx"
|
||||
#include <vcl/virdev.hxx>
|
||||
#include <vcl/vclptr.hxx>
|
||||
|
||||
class SfxDispatcher;
|
||||
|
||||
@@ -31,15 +32,14 @@ class CellLineStylePopup : public WeldToolbarPopup
|
||||
private:
|
||||
MenuOrToolMenuButton maToolButton;
|
||||
SfxDispatcher* mpDispatcher;
|
||||
std::unique_ptr<CellLineStyleValueSet> mxCellLineStyleValueSet;
|
||||
std::unique_ptr<weld::CustomWeld> mxCellLineStyleValueSetWin;
|
||||
std::unique_ptr<weld::TreeView> mxCellLineStyleTreeView;
|
||||
std::unique_ptr<weld::Button> mxPushButtonMoreOptions;
|
||||
|
||||
void SetAllNoSel();
|
||||
|
||||
DECL_LINK(VSSelectHdl, ValueSet*, void);
|
||||
DECL_LINK(StyleSelectHdl, weld::TreeView&, bool);
|
||||
DECL_LINK(PBClickHdl, weld::Button&, void);
|
||||
|
||||
VclPtr<VirtualDevice> CreateImage(int nIndex);
|
||||
|
||||
public:
|
||||
CellLineStylePopup(weld::Toolbar* pParent, const OUString& rId, SfxDispatcher* pDispatcher);
|
||||
void SetLineStyleSelect(sal_uInt16 out, sal_uInt16 in, sal_uInt16 dis);
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface domain="sc">
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<object class="GtkListStore" id="liststore1">
|
||||
<columns>
|
||||
<!-- column-name image -->
|
||||
<column type="GdkPixbuf"/>
|
||||
<!-- column-name text -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name id -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkPopover" id="FloatingLineStyle">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="no-show-all">True</property>
|
||||
@@ -22,6 +32,41 @@
|
||||
<property name="vexpand">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="row-spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="linestyletreeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="model">liststore1</property>
|
||||
<property name="headers-visible">False</property>
|
||||
<property name="enable-search">False</property>
|
||||
<property name="show-expanders">False</property>
|
||||
<property name="activate-on-single-click">True</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf"/>
|
||||
<attributes>
|
||||
<attribute name="pixbuf">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="more">
|
||||
<property name="label" translatable="yes" context="floatinglinestyle|more">_More Options...</property>
|
||||
@@ -35,37 +80,6 @@
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="valuesetwin">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="hscrollbar-policy">never</property>
|
||||
<property name="vscrollbar-policy">never</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkDrawingArea" id="linestylevalueset">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="has-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>
|
||||
<property name="vexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
||||
Reference in New Issue
Block a user