sw/source/uibase/sidebar/PageSizeControl.cxx | 46 ++++++++++------------- sw/source/uibase/sidebar/PageSizeControl.hxx | 12 +----- sw/uiconfig/swriter/ui/pagesizecontrol.ui | 53 ++++++++++++++++++--------- 3 files changed, 59 insertions(+), 52 deletions(-)
New commits: commit 44de0093b28b6090bcac989e18a1d34c888403fe Author: Michael Weghorn <[email protected]> AuthorDate: Thu Nov 27 22:30:19 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Nov 28 08:14:08 2025 +0100 sw: Use #pragma once Change-Id: Ia6a4027fa1234b18ae386ba613163f0edfbc0443 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194742 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/sw/source/uibase/sidebar/PageSizeControl.hxx b/sw/source/uibase/sidebar/PageSizeControl.hxx index ef5c3653f601..481783195f64 100644 --- a/sw/source/uibase/sidebar/PageSizeControl.hxx +++ b/sw/source/uibase/sidebar/PageSizeControl.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX -#define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX +#pragma once #include <i18nutil/paper.hxx> @@ -55,6 +54,4 @@ private: } // end of namespace sw::sidebar -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 85dc059a3990b41f93be6e163c2c8d2138f9e0e9 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Nov 27 22:29:52 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Nov 28 08:14:01 2025 +0100 tdf#136905 tdf#169710 Use TreeView in PageSizeControl So far, the custom ValueSetWithTextControl was used in the "Page Size" dropdown (used in the "Layout" tab of the Tabbed interface in Writer) to show what is effectively a table with two columns (page size and dimensions). Stop using that custom control, and instead use a weld::TreeView for the job, which avoids having to do manual rendering and ensures it takes into account the style, etc. Use automatic size for the columns and give the tree view its preferred height, which makes sure that all entries are visible without scrolling. Enable the GtkTreeView properties activate-on-single-click and hover-selection to keep highlighting the entry that the mouse hovers over and activating an entry when its clicked once. Change-Id: I21038e65c2bf0d7b931f38c49a7da9a596983f36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194741 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/sw/source/uibase/sidebar/PageSizeControl.cxx b/sw/source/uibase/sidebar/PageSizeControl.cxx index ebac8aac3ca3..5b83943fc230 100644 --- a/sw/source/uibase/sidebar/PageSizeControl.cxx +++ b/sw/source/uibase/sidebar/PageSizeControl.cxx @@ -19,7 +19,6 @@ #include <memory> #include "PageSizeControl.hxx" -#include "ValueSetWithTextControl.hxx" #include <cmdid.h> #include <svx/pageitem.hxx> @@ -69,10 +68,9 @@ namespace sw::sidebar { PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"modules/swriter/ui/pagesizecontrol.ui"_ustr, u"PageSizeControl"_ustr) + , mxPageSizeTreeView(m_xBuilder->weld_tree_view(u"pagesizetreeview"_ustr)) , mxMoreButton(m_xBuilder->weld_button(u"moreoptions"_ustr)) , mxWidthHeightField(m_xBuilder->weld_metric_spin_button(u"metric"_ustr, FieldUnit::CM)) - , mxSizeValueSet(new ValueSetWithTextControl) - , mxSizeValueSetWin(new weld::CustomWeld(*m_xBuilder, u"pagesizevalueset"_ustr, *mxSizeValueSet)) , mxControl(pControl) { mxWidthHeightField->set_unit(FieldUnit::CM); @@ -90,9 +88,6 @@ PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) maPaperList.push_back( PAPER_LETTER ); maPaperList.push_back( PAPER_LEGAL ); - mxSizeValueSet->SetStyle( mxSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_FLATVALUESET ); - - sal_uInt16 nSelectedItem = 0; OUString aMetricStr; const OUString aText = mxWidthHeightField->get_text(); for (short i = aText.getLength() - 1; i >= 0; i--) @@ -141,25 +136,21 @@ PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) true ); const OUString aItemText2 = aWidthStr + " x " + aHeightStr + " " + aMetricStr; - - mxSizeValueSet->AddItem( - SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ), - aItemText2 ); + const int nPos = mxPageSizeTreeView->n_children(); + mxPageSizeTreeView->append(); + mxPageSizeTreeView->set_text(nPos, SvxPaperInfo::GetName(maPaperList[nPaperIdx]), 0); + mxPageSizeTreeView->set_text(nPos, aItemText2, 1); if ( pSize && aPaperSize == pSize->GetSize() ) - { - nSelectedItem = nPaperIdx + 1; - } + mxPageSizeTreeView->select(nPaperIdx); } - mxSizeValueSet->SetNoSelection(); - mxSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl, ImplSizeHdl ) ); - mxSizeValueSet->Show(); - mxSizeValueSet->Resize(); + mxPageSizeTreeView->columns_autosize(); + const int nHeight = mxPageSizeTreeView->get_preferred_size().Height(); + mxPageSizeTreeView->set_size_request(-1, nHeight); + mxPageSizeTreeView->queue_resize(); - mxSizeValueSet->SelectItem( nSelectedItem ); - mxSizeValueSet->SetFormat(); - mxSizeValueSet->Invalidate(); + mxPageSizeTreeView->connect_row_activated(LINK(this, PageSizeControl, ImplSizeHdl)); mxMoreButton->connect_clicked( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) ); mxMoreButton->grab_focus(); @@ -167,7 +158,7 @@ PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent) void PageSizeControl::GrabFocus() { - mxSizeValueSet->GrabFocus(); + mxPageSizeTreeView->grab_focus(); } PageSizeControl::~PageSizeControl() @@ -199,15 +190,18 @@ void PageSizeControl::ExecuteSizeChange( const Paper ePaper ) SfxCallMode::RECORD, { &aPageSizeItem }); } - -IMPL_LINK_NOARG(PageSizeControl, ImplSizeHdl, ValueSet*, void) +IMPL_LINK_NOARG(PageSizeControl, ImplSizeHdl, weld::TreeView&, bool) { - mxSizeValueSet->SetNoSelection(); - const sal_uInt16 nSelectedPaper = mxSizeValueSet->GetSelectedItemId(); - const Paper ePaper = maPaperList[nSelectedPaper - 1]; + const int nIndex = mxPageSizeTreeView->get_selected_index(); + if (nIndex < 0) + return false; + + const Paper ePaper = maPaperList.at(nIndex); ExecuteSizeChange( ePaper ); mxControl->EndPopupMode(); + + return true; } IMPL_LINK_NOARG(PageSizeControl, MoreButtonClickHdl_Impl, weld::Button&, void) diff --git a/sw/source/uibase/sidebar/PageSizeControl.hxx b/sw/source/uibase/sidebar/PageSizeControl.hxx index f1adaad49c61..ef5c3653f601 100644 --- a/sw/source/uibase/sidebar/PageSizeControl.hxx +++ b/sw/source/uibase/sidebar/PageSizeControl.hxx @@ -19,8 +19,6 @@ #ifndef INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX #define INCLUDED_SW_SOURCE_UIBASE_SIDEBAR_PAGESIZECONTROL_HXX -#include "ValueSetWithTextControl.hxx" - #include <i18nutil/paper.hxx> #include <svtools/toolbarmenu.hxx> @@ -41,18 +39,17 @@ public: virtual ~PageSizeControl() override; private: + std::unique_ptr<weld::TreeView> mxPageSizeTreeView; std::unique_ptr<weld::Button> mxMoreButton; // hidden metric field std::unique_ptr<weld::MetricSpinButton> mxWidthHeightField; - std::unique_ptr<ValueSetWithTextControl> mxSizeValueSet; - std::unique_ptr<weld::CustomWeld> mxSizeValueSetWin; rtl::Reference<PageSizePopup> mxControl; std::vector<Paper> maPaperList; static void ExecuteSizeChange(const Paper ePaper); - DECL_LINK(ImplSizeHdl, ValueSet*, void); + DECL_LINK(ImplSizeHdl, weld::TreeView&, bool); DECL_LINK(MoreButtonClickHdl_Impl, weld::Button&, void); }; diff --git a/sw/uiconfig/swriter/ui/pagesizecontrol.ui b/sw/uiconfig/swriter/ui/pagesizecontrol.ui index bc5372cc9aea..a6a773fda0d1 100644 --- a/sw/uiconfig/swriter/ui/pagesizecontrol.ui +++ b/sw/uiconfig/swriter/ui/pagesizecontrol.ui @@ -12,6 +12,16 @@ <property name="can-focus">False</property> <property name="icon-name">cmd/lc_attributepagesize.png</property> </object> + <object class="GtkTreeStore" id="pagesizemodel"> + <columns> + <!-- column-name pagename --> + <column type="gchararray"/> + <!-- column-name dimensions --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkPopover" id="PageSizeControl"> <property name="can-focus">False</property> <property name="no-show-all">True</property> @@ -33,32 +43,41 @@ <property name="vexpand">True</property> <property name="orientation">vertical</property> <child> - <object class="GtkScrolledWindow" id="valuesetwin"> + <object class="GtkTreeView" id="pagesizetreeview"> <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> + <property name="model">pagesizemodel</property> + <property name="headers-visible">False</property> + <property name="enable-search">False</property> + <property name="hover-selection">True</property> + <property name="show-expanders">False</property> + <property name="activate-on-single-click">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="papersize"> + <child> + <object class="GtkCellRendererText"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> <child> - <object class="GtkViewport"> - <property name="visible">True</property> - <property name="can-focus">False</property> + <object class="GtkTreeViewColumn" id="dimensions"> <child> - <object class="GtkDrawingArea" id="pagesizevalueset"> - <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> - <property name="vexpand">True</property> - </object> + <object class="GtkCellRendererText"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> </child> </object> </child> </object> <packing> - <property name="expand">True</property> + <property name="expand">False</property> <property name="fill">True</property> <property name="position">0</property> </packing>
