weld SwTOXStylesTabPage
Change-Id: I1e7056ef8293ddc7072e95ee248e45b2785d1234
Reviewed-on: https://gerrit.libreoffice.org/62347
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index ebf796a..7fcd7b8 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -429,6 +429,7 @@ public:
void unselect_all() { select(-1); }
virtual int n_children() const = 0;
virtual void make_sorted() = 0;
virtual void clear() = 0;
virtual int get_height_rows(int nRows) const = 0;
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index ca883f1..6764592 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -3609,44 +3609,31 @@ sal_uInt32 SwTokenWindow::GetControlIndex(FormTokenType eType) const
return nIndex;
}
SwTOXStylesTabPage::SwTOXStylesTabPage(vcl::Window* pParent, const SfxItemSet& rAttrSet )
: SfxTabPage(pParent, "TocStylesPage",
"modules/swriter/ui/tocstylespage.ui", &rAttrSet)
SwTOXStylesTabPage::SwTOXStylesTabPage(TabPageParent pParent, const SfxItemSet& rAttrSet)
: SfxTabPage(pParent, "modules/swriter/ui/tocstylespage.ui", "TocStylesPage", &rAttrSet)
, m_xLevelLB(m_xBuilder->weld_tree_view("levels"))
, m_xAssignBT(m_xBuilder->weld_button("assign"))
, m_xParaLayLB(m_xBuilder->weld_tree_view("styles"))
, m_xStdBT(m_xBuilder->weld_button("default"))
, m_xEditStyleBT(m_xBuilder->weld_button("edit"))
{
get(m_pLevelLB, "levels");
get(m_pAssignBT, "assign");
get(m_pParaLayLB, "styles");
m_pParaLayLB->SetStyle(m_pParaLayLB->GetStyle() | WB_SORT);
get(m_pStdBT, "default");
get(m_pEditStyleBT, "edit");
long nHeight = m_pLevelLB->GetTextHeight() * 16;
m_pLevelLB->set_height_request(nHeight);
m_pParaLayLB->set_height_request(nHeight);
m_xParaLayLB->make_sorted();
auto nHeight = m_xLevelLB->get_height_rows(16);
m_xLevelLB->set_size_request(-1, nHeight);
m_xParaLayLB->set_size_request(-1, nHeight);
SetExchangeSupport();
m_pEditStyleBT->SetClickHdl (LINK( this, SwTOXStylesTabPage, EditStyleHdl));
m_pAssignBT->SetClickHdl (LINK( this, SwTOXStylesTabPage, AssignHdl));
m_pStdBT->SetClickHdl (LINK( this, SwTOXStylesTabPage, StdHdl));
m_pParaLayLB->SetSelectHdl (LINK( this, SwTOXStylesTabPage, EnableSelectHdl));
m_pLevelLB->SetSelectHdl(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
m_pParaLayLB->SetDoubleClickHdl(LINK( this, SwTOXStylesTabPage, DoubleClickHdl));
m_xEditStyleBT->connect_clicked(LINK(this, SwTOXStylesTabPage, EditStyleHdl));
m_xAssignBT->connect_clicked(LINK(this, SwTOXStylesTabPage, AssignHdl));
m_xStdBT->connect_clicked(LINK(this, SwTOXStylesTabPage, StdHdl));
m_xParaLayLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
m_xLevelLB->connect_changed(LINK(this, SwTOXStylesTabPage, EnableSelectHdl));
m_xParaLayLB->connect_row_activated(LINK(this, SwTOXStylesTabPage, DoubleClickHdl));
}
SwTOXStylesTabPage::~SwTOXStylesTabPage()
{
disposeOnce();
}
void SwTOXStylesTabPage::dispose()
{
m_pCurrentForm.reset();
m_pLevelLB.clear();
m_pAssignBT.clear();
m_pParaLayLB.clear();
m_pStdBT.clear();
m_pEditStyleBT.clear();
SfxTabPage::dispose();
}
bool SwTOXStylesTabPage::FillItemSet( SfxItemSet* )
@@ -3662,15 +3649,14 @@ void SwTOXStylesTabPage::Reset( const SfxItemSet* rSet )
void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
{
m_pCurrentForm.reset(new SwForm(GetForm()));
m_pParaLayLB->Clear();
m_pLevelLB->Clear();
// not hyperlink for user directories
const sal_uInt16 nSize = m_pCurrentForm->GetFormMax();
// display form pattern without title
m_xLevelLB->freeze();
m_xLevelLB->clear();
// display 1st TemplateEntry
OUString aStr( SwResId( STR_TITLE ));
if( !m_pCurrentForm->GetTemplate( 0 ).isEmpty() )
@@ -3679,7 +3665,7 @@ void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
+ m_pCurrentForm->GetTemplate( 0 )
+ OUStringLiteral1(aDeliEnd);
}
m_pLevelLB->InsertEntry(aStr);
m_xLevelLB->append_text(aStr);
for( sal_uInt16 i=1; i < nSize; ++i )
{
@@ -3699,30 +3685,33 @@ void SwTOXStylesTabPage::ActivatePage( const SfxItemSet& )
+ m_pCurrentForm->GetTemplate( i )
+ OUStringLiteral1(aDeliEnd);
}
m_pLevelLB->InsertEntry( aStr );
m_xLevelLB->append_text(aStr);
}
m_xLevelLB->thaw();
// initialise templates
SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetTabDialog())->GetWrtShell();
const sal_uInt16 nSz = rSh.GetTextFormatCollCount();
m_xParaLayLB->freeze();
m_xParaLayLB->clear();
for( sal_uInt16 i = 0; i < nSz; ++i )
{
const SwTextFormatColl *pColl = &rSh.GetTextFormatColl( i );
if( !pColl->IsDefault() )
m_pParaLayLB->InsertEntry( pColl->GetName() );
m_xParaLayLB->append_text( pColl->GetName() );
}
// query pool collections and set them for the directory
for( sal_uInt16 i = 0; i < m_pCurrentForm->GetFormMax(); ++i )
{
aStr = m_pCurrentForm->GetTemplate( i );
if( !aStr.isEmpty() &&
LISTBOX_ENTRY_NOTFOUND == m_pParaLayLB->GetEntryPos( aStr ))
m_pParaLayLB->InsertEntry( aStr );
if (!aStr.isEmpty() && m_xParaLayLB->find_text(aStr) == -1)
m_xParaLayLB->append_text(aStr);
}
m_xParaLayLB->thaw();
EnableSelectHdl(*m_pParaLayLB);
EnableSelectHdl(*m_xParaLayLB);
}
DeactivateRC SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/ )
@@ -3731,17 +3720,17 @@ DeactivateRC SwTOXStylesTabPage::DeactivatePage( SfxItemSet* /*pSet*/ )
return DeactivateRC::LeavePage;
}
VclPtr<SfxTabPage> SwTOXStylesTabPage::Create( TabPageParent pParent,
const SfxItemSet* rAttrSet)
VclPtr<SfxTabPage> SwTOXStylesTabPage::Create(TabPageParent pParent,
const SfxItemSet* rAttrSet)
{
return VclPtr<SwTOXStylesTabPage>::Create(pParent.pParent, *rAttrSet);
return VclPtr<SwTOXStylesTabPage>::Create(pParent, *rAttrSet);
}
IMPL_LINK_NOARG(SwTOXStylesTabPage, EditStyleHdl, Button *, void)
IMPL_LINK_NOARG(SwTOXStylesTabPage, EditStyleHdl, weld::Button&, void)
{
if( LISTBOX_ENTRY_NOTFOUND != m_pParaLayLB->GetSelectedEntryPos())
if (m_xParaLayLB->get_selected_index() != -1)
{
SfxStringItem aStyle(SID_STYLE_EDIT, m_pParaLayLB->GetSelectedEntry());
SfxStringItem aStyle(SID_STYLE_EDIT, m_xParaLayLB->get_selected_text());
SfxUInt16Item aFamily(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para));
SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetTabDialog())->GetWrtShell();
rSh.GetView().GetViewFrame()->GetDispatcher()->ExecuteList(SID_STYLE_EDIT,
@@ -3751,62 +3740,61 @@ IMPL_LINK_NOARG(SwTOXStylesTabPage, EditStyleHdl, Button *, void)
}
// allocate templates
IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl, Button*, void)
IMPL_LINK_NOARG(SwTOXStylesTabPage, AssignHdl, weld::Button&, void)
{
sal_Int32 nLevPos = m_pLevelLB->GetSelectedEntryPos();
sal_Int32 nTemplPos = m_pParaLayLB->GetSelectedEntryPos();
if(nLevPos != LISTBOX_ENTRY_NOTFOUND &&
nTemplPos != LISTBOX_ENTRY_NOTFOUND)
auto nLevPos = m_xLevelLB->get_selected_index();
auto nTemplPos = m_xParaLayLB->get_selected_index();
if (nLevPos != -1 && nTemplPos != -1)
{
const OUString aStr(m_pLevelLB->GetEntry(nLevPos).getToken(0, aDeliStart)
const OUString aStr(m_xLevelLB->get_text(nLevPos).getToken(0, aDeliStart)
+ OUStringLiteral1(aDeliStart)
+ m_pParaLayLB->GetSelectedEntry()
+ m_xParaLayLB->get_selected_text()
+ OUStringLiteral1(aDeliEnd));
m_pCurrentForm->SetTemplate(nLevPos, m_pParaLayLB->GetSelectedEntry());
m_pCurrentForm->SetTemplate(nLevPos, m_xParaLayLB->get_selected_text());
m_pLevelLB->RemoveEntry(nLevPos);
m_pLevelLB->InsertEntry(aStr, nLevPos);
m_pLevelLB->SelectEntry(aStr);
m_xLevelLB->remove(nLevPos);
m_xLevelLB->insert_text(nLevPos, aStr);
m_xLevelLB->select_text(aStr);
Modify();
}
}
IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl, Button*, void)
IMPL_LINK_NOARG(SwTOXStylesTabPage, StdHdl, weld::Button&, void)
{
const sal_Int32 nPos = m_pLevelLB->GetSelectedEntryPos();
if(nPos != LISTBOX_ENTRY_NOTFOUND)
const auto nPos = m_xLevelLB->get_selected_index();
if (nPos != -1)
{
const OUString aStr(m_pLevelLB->GetEntry(nPos).getToken(0, aDeliStart));
m_pLevelLB->RemoveEntry(nPos);
m_pLevelLB->InsertEntry(aStr, nPos);
m_pLevelLB->SelectEntry(aStr);
const OUString aStr(m_xLevelLB->get_text(nPos).getToken(0, aDeliStart));
m_xLevelLB->remove(nPos);
m_xLevelLB->insert_text(nPos, aStr);
m_xLevelLB->select_text(aStr);
m_pCurrentForm->SetTemplate(nPos, aEmptyOUStr);
Modify();
}
}
IMPL_LINK_NOARG(SwTOXStylesTabPage, DoubleClickHdl, ListBox&, void)
IMPL_LINK_NOARG(SwTOXStylesTabPage, DoubleClickHdl, weld::TreeView&, void)
{
const OUString aTmpName( m_pParaLayLB->GetSelectedEntry() );
const OUString aTmpName(m_xParaLayLB->get_selected_text());
SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetTabDialog())->GetWrtShell();
if(m_pParaLayLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
(m_pLevelLB->GetSelectedEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
AssignHdl(m_pAssignBT);
if(m_xParaLayLB->get_selected_index() != -1 &&
(m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)))
AssignHdl(*m_xAssignBT);
}
// enable only when selected
IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl, ListBox&, void)
IMPL_LINK_NOARG(SwTOXStylesTabPage, EnableSelectHdl, weld::TreeView&, void)
{
m_pStdBT->Enable(m_pLevelLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND);
m_xStdBT->set_sensitive(m_xLevelLB->get_selected_index() != -1);
SwWrtShell& rSh = static_cast<SwMultiTOXTabDialog*>(GetTabDialog())->GetWrtShell();
const OUString aTmpName(m_pParaLayLB->GetSelectedEntry());
m_pAssignBT->Enable(m_pParaLayLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND &&
LISTBOX_ENTRY_NOTFOUND != m_pLevelLB->GetSelectedEntryPos() &&
(m_pLevelLB->GetSelectedEntryPos() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
m_pEditStyleBT->Enable(m_pParaLayLB->GetSelectedEntryPos() != LISTBOX_ENTRY_NOTFOUND );
const OUString aTmpName(m_xParaLayLB->get_selected_text());
m_xAssignBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1 &&
m_xLevelLB->get_selected_index() != -1 &&
(m_xLevelLB->get_selected_index() == 0 || SwMultiTOXTabDialog::IsNoNum(rSh, aTmpName)));
m_xEditStyleBT->set_sensitive(m_xParaLayLB->get_selected_index() != -1);
}
void SwTOXStylesTabPage::Modify()
diff --git a/sw/source/uibase/inc/swuicnttab.hxx b/sw/source/uibase/inc/swuicnttab.hxx
index 88d7c90..2c14d57 100644
--- a/sw/source/uibase/inc/swuicnttab.hxx
+++ b/sw/source/uibase/inc/swuicnttab.hxx
@@ -447,34 +447,33 @@ public:
class SwTOXStylesTabPage : public SfxTabPage
{
VclPtr<ListBox> m_pLevelLB;
VclPtr<PushButton> m_pAssignBT;
VclPtr<ListBox> m_pParaLayLB;
VclPtr<PushButton> m_pStdBT;
VclPtr<PushButton> m_pEditStyleBT;
std::unique_ptr<SwForm> m_pCurrentForm;
DECL_LINK( EditStyleHdl, Button *, void );
DECL_LINK( StdHdl, Button*, void );
DECL_LINK(EnableSelectHdl, ListBox&, void);
DECL_LINK( DoubleClickHdl, ListBox&, void );
DECL_LINK( AssignHdl, Button*, void );
std::unique_ptr<weld::TreeView> m_xLevelLB;
std::unique_ptr<weld::Button> m_xAssignBT;
std::unique_ptr<weld::TreeView> m_xParaLayLB;
std::unique_ptr<weld::Button> m_xStdBT;
std::unique_ptr<weld::Button> m_xEditStyleBT;
DECL_LINK(EditStyleHdl, weld::Button&, void);
DECL_LINK(StdHdl, weld::Button&, void);
DECL_LINK(EnableSelectHdl, weld::TreeView&, void);
DECL_LINK(DoubleClickHdl, weld::TreeView&, void);
DECL_LINK(AssignHdl, weld::Button&, void);
void Modify();
SwForm& GetForm()
{
SwMultiTOXTabDialog* pDlg = static_cast<SwMultiTOXTabDialog*>(GetTabDialog());
return *pDlg->GetForm(pDlg->GetCurrentTOXType());
}
{
SwMultiTOXTabDialog* pDlg = static_cast<SwMultiTOXTabDialog*>(GetTabDialog());
return *pDlg->GetForm(pDlg->GetCurrentTOXType());
}
using SfxTabPage::ActivatePage;
using SfxTabPage::DeactivatePage;
public:
SwTOXStylesTabPage(vcl::Window* pParent, const SfxItemSet& rAttrSet);
SwTOXStylesTabPage(TabPageParent pParent, const SfxItemSet& rAttrSet);
virtual ~SwTOXStylesTabPage() override;
virtual void dispose() override;
virtual bool FillItemSet( SfxItemSet* ) override;
virtual void Reset( const SfxItemSet* ) override;
diff --git a/sw/uiconfig/swriter/ui/tocstylespage.ui b/sw/uiconfig/swriter/ui/tocstylespage.ui
index 71aad33..95decc9 100644
--- a/sw/uiconfig/swriter/ui/tocstylespage.ui
+++ b/sw/uiconfig/swriter/ui/tocstylespage.ui
@@ -1,6 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="sw">
<!-- interface-requires gtk+ 3.0 -->
<requires lib="gtk+" version="3.18"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">sw/res/one_left.png</property>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="liststore2">
<columns>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkBox" id="TocStylesPage">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -35,81 +57,106 @@
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="tocstylespage|label1">_Levels</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">levels:border</property>
<property name="mnemonic_widget">levels</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes" context="tocstylespage|label2">Paragraph _Styles</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">styles:border</property>
<property name="mnemonic_widget">styles</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="levels:border">
<object class="GtkTreeView" id="levels">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="search_column">0</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="styles:border">
<object class="GtkTreeView" id="styles">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore2</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="search_column">0</property>
<property name="show_expanders">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
@@ -125,8 +172,6 @@
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
@@ -142,8 +187,6 @@
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
@@ -158,8 +201,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
@@ -190,11 +231,6 @@
</packing>
</child>
</object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">sw/res/one_left.png</property>
</object>
<object class="GtkSizeGroup" id="sizegroup1">
<widgets>
<widget name="default"/>
@@ -203,8 +239,8 @@
</object>
<object class="GtkSizeGroup" id="sizegroup2">
<widgets>
<widget name="levels:border"/>
<widget name="styles:border"/>
<widget name="levels"/>
<widget name="styles"/>
</widgets>
</object>
</interface>
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 972e23d..485b404a 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1860,6 +1860,11 @@ public:
return m_xTreeView->CalcWindowSizePixel(nRows);
}
virtual void make_sorted() override
{
m_xTreeView->SetStyle(m_xTreeView->GetStyle() | WB_SORT);
}
ListBox& getTreeView()
{
return *m_xTreeView;
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 90f1045..0959438 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -3912,11 +3912,29 @@ namespace
}
}
namespace
{
gint sort_func(GtkTreeModel* pModel, GtkTreeIter* a, GtkTreeIter* b, gpointer data)
{
comphelper::string::NaturalStringSorter* pSorter = static_cast<comphelper::string::NaturalStringSorter*>(data);
gchar* pName1;
gchar* pName2;
gtk_tree_model_get(pModel, a, 0, &pName1, -1);
gtk_tree_model_get(pModel, b, 0, &pName2, -1);
gint ret = pSorter->compare(OUString(pName1, strlen(pName1), RTL_TEXTENCODING_UTF8),
OUString(pName2, strlen(pName2), RTL_TEXTENCODING_UTF8));
g_free(pName1);
g_free(pName2);
return ret;
}
}
class GtkInstanceTreeView : public GtkInstanceContainer, public virtual weld::TreeView
{
private:
GtkTreeView* m_pTreeView;
GtkListStore* m_pListStore;
std::unique_ptr<comphelper::string::NaturalStringSorter> m_xSorter;
gulong m_nChangedSignalId;
gulong m_nRowActivatedSignalId;
@@ -4036,6 +4054,16 @@ public:
enable_notify_events();
}
virtual void make_sorted() override
{
m_xSorter.reset(new comphelper::string::NaturalStringSorter(
::comphelper::getProcessComponentContext(),
Application::GetSettings().GetUILanguageTag().getLocale()));
GtkTreeSortable* pSortable = GTK_TREE_SORTABLE(m_pListStore);
gtk_tree_sortable_set_sort_func(pSortable, 0, sort_func, m_xSorter.get(), nullptr);
gtk_tree_sortable_set_sort_column_id(pSortable, 0, GTK_SORT_ASCENDING);
}
virtual int n_children() const override
{
return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_pListStore), nullptr);
@@ -4122,12 +4150,22 @@ public:
g_object_ref(m_pListStore);
GtkInstanceContainer::freeze();
gtk_tree_view_set_model(m_pTreeView, nullptr);
if (m_xSorter)
{
GtkTreeSortable* pSortable = GTK_TREE_SORTABLE(m_pListStore);
gtk_tree_sortable_set_sort_column_id(pSortable, GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
}
enable_notify_events();
}
virtual void thaw() override
{
disable_notify_events();
if (m_xSorter)
{
GtkTreeSortable* pSortable = GTK_TREE_SORTABLE(m_pListStore);
gtk_tree_sortable_set_sort_column_id(pSortable, 0, GTK_SORT_ASCENDING);
}
gtk_tree_view_set_model(m_pTreeView, GTK_TREE_MODEL(m_pListStore));
GtkInstanceContainer::thaw();
g_object_unref(m_pListStore);
@@ -4853,23 +4891,6 @@ public:
}
};
namespace
{
gint sort_func(GtkTreeModel* pModel, GtkTreeIter* a, GtkTreeIter* b, gpointer data)
{
comphelper::string::NaturalStringSorter* pSorter = static_cast<comphelper::string::NaturalStringSorter*>(data);
gchar* pName1;
gchar* pName2;
gtk_tree_model_get(pModel, a, 0, &pName1, -1);
gtk_tree_model_get(pModel, b, 0, &pName2, -1);
gint ret = pSorter->compare(OUString(pName1, strlen(pName1), RTL_TEXTENCODING_UTF8),
OUString(pName2, strlen(pName2), RTL_TEXTENCODING_UTF8));
g_free(pName1);
g_free(pName2);
return ret;
}
}
class GtkInstanceComboBox : public GtkInstanceContainer, public vcl::ISearchableStringList, public virtual weld::ComboBox
{
private: