From 0bf31b7f4cd7909c87f84909f34137d406ac5e76 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 6 Oct 2026 15:01:52 +0200 Subject: [PATCH] svx: Port ExtrusionLightingWindow from ValueSet to weld::IconView Port the widget to select the lighting from using a ValueSet widget to using weld::IconView. This helps to be more consistent with other platform/toolkit widgets and reduces custom widget logic. Adjust indices used to account for the fact that weld::IconView indices are 0-based while the ValueSet ones are 1-based. The popup can be triggered like this: * open attachment 175894 from tdf#145296 * make sure the "3D-Settings" toolbar is enabled in "View" -> "Toolbars" -> "3D-Settings" * select the extruded shape * press the "Lighting" button in the "3D-Settings" toolbar Change-Id: I28d86251b70149574535dc7b583660dbe42e9a0d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211903 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- svx/source/tbxctrls/extrusioncontrols.cxx | 76 ++++++++++------------- svx/source/tbxctrls/extrusioncontrols.hxx | 13 ++-- svx/uiconfig/ui/lightingwindow.ui | 41 ++++++------ 3 files changed, 61 insertions(+), 69 deletions(-) diff --git a/svx/source/tbxctrls/extrusioncontrols.cxx b/svx/source/tbxctrls/extrusioncontrols.cxx index c3845119d7ae..1d7cbc64f994 100644 --- a/svx/source/tbxctrls/extrusioncontrols.cxx +++ b/svx/source/tbxctrls/extrusioncontrols.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -594,44 +595,38 @@ ExtrusionLightingWindow::ExtrusionLightingWindow(svt::PopupWindowController* pCo weld::Widget* pParent) : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/lightingwindow.ui"_ustr, u"LightingWindow"_ustr) , mxControl(pControl) - , mxLightingSet(new ValueSet(nullptr)) - , mxLightingSetWin(new weld::CustomWeld(*m_xBuilder, u"valueset"_ustr, *mxLightingSet)) + , mxLightingIconView(m_xBuilder->weld_icon_view(u"iconview"_ustr)) , mxBright(m_xBuilder->weld_radio_button(u"bright"_ustr)) , mxNormal(m_xBuilder->weld_radio_button(u"normal"_ustr)) , mxDim(m_xBuilder->weld_radio_button(u"dim"_ustr)) { - mxLightingSet->SetStyle(WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NOBORDER | WB_NO_DIRECTSELECT); - for (sal_uInt16 i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i) { if( i != FROM_FRONT ) { - maImgLightingOff[i] = Image(StockImage::Yes, aLightOffBmps[i]); - maImgLightingOn[i] = Image(StockImage::Yes, aLightOnBmps[i]); + maImgLightingOff[i] = Image(StockImage::Yes, aLightOffBmps[i]).GetBitmap(); + maImgLightingOn[i] = Image(StockImage::Yes, aLightOnBmps[i]).GetBitmap(); } - maImgLightingPreview[i] = Image(StockImage::Yes, aLightPreviewBmps[i]); + maImgLightingPreview[i] = Image(StockImage::Yes, aLightPreviewBmps[i]).GetBitmap(); } - mxLightingSet->SetHelpId( HID_VALUESET_EXTRUSION_LIGHTING ); + mxLightingIconView->set_help_id(HID_VALUESET_EXTRUSION_LIGHTING); - mxLightingSet->SetSelectHdl( LINK( this, ExtrusionLightingWindow, SelectValueSetHdl ) ); - mxLightingSet->SetColCount( 3 ); - mxLightingSet->EnableFullItemMode( false ); + mxLightingIconView->connect_item_activated( + LINK(this, ExtrusionLightingWindow, IconViewItemActivatedHdl)); - for (sal_uInt16 i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i) + for (int i = FROM_TOP_LEFT; i <= FROM_BOTTOM_RIGHT; ++i) { if( i != FROM_FRONT ) { - mxLightingSet->InsertItem( i+1, maImgLightingOff[i] ); + mxLightingIconView->insert(i, nullptr, nullptr, &maImgLightingOff[i], nullptr); } else { - mxLightingSet->InsertItem( 5, maImgLightingPreview[FROM_FRONT] ); + mxLightingIconView->insert(4, nullptr, nullptr, &maImgLightingPreview[FROM_FRONT], + nullptr); } } - Size aSize(72, 72); - mxLightingSet->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height()); - mxLightingSet->SetOutputSizePixel(aSize); mxBright->connect_toggled(LINK(this, ExtrusionLightingWindow, SelectToolbarMenuHdl)); mxNormal->connect_toggled(LINK(this, ExtrusionLightingWindow, SelectToolbarMenuHdl)); @@ -641,10 +636,7 @@ ExtrusionLightingWindow::ExtrusionLightingWindow(svt::PopupWindowController* pCo AddStatusListener( g_sExtrusionLightingIntensity ); } -void ExtrusionLightingWindow::GrabFocus() -{ - mxLightingSet->GrabFocus(); -} +void ExtrusionLightingWindow::GrabFocus() { mxLightingIconView->grab_focus(); } ExtrusionLightingWindow::~ExtrusionLightingWindow() { @@ -665,26 +657,28 @@ void ExtrusionLightingWindow::implSetDirection( int nDirection, bool bEnabled ) if( !bEnabled ) nDirection = FROM_FRONT; - sal_uInt16 nItemId; - for( nItemId = FROM_TOP_LEFT; nItemId <= FROM_BOTTOM_RIGHT; nItemId++ ) + for (int nItemIndex = FROM_TOP_LEFT; nItemIndex <= FROM_BOTTOM_RIGHT; nItemIndex++) { - if( nItemId == FROM_FRONT ) + ScopedVclPtr pDev = VclPtr::Create(); + if (nItemIndex == FROM_FRONT) { - mxLightingSet->SetItemImage( nItemId + 1, maImgLightingPreview[ nDirection ] ); + pDev->SetOutputSizePixel(maImgLightingPreview[nDirection].GetSizePixel()); + pDev->DrawBitmap(Point(), maImgLightingPreview[nDirection]); } else { - mxLightingSet->SetItemImage( - nItemId + 1, - static_cast(nDirection) == nItemId ? maImgLightingOn[nItemId] : maImgLightingOff[nItemId] - ); + const Bitmap& rBitmap = nDirection == nItemIndex ? maImgLightingOn[nItemIndex] + : maImgLightingOff[nItemIndex]; + pDev->SetOutputSizePixel(rBitmap.GetSizePixel()); + pDev->DrawBitmap(Point(), rBitmap); } + mxLightingIconView->set_image(nItemIndex, *pDev); } if (bEnabled) - mxLightingSet->Enable(); + mxLightingIconView->set_sensitive(true); else - mxLightingSet->Disable(); + mxLightingIconView->set_sensitive(false); } void ExtrusionLightingWindow::statusChanged( @@ -719,23 +713,21 @@ void ExtrusionLightingWindow::statusChanged( } } -IMPL_LINK_NOARG(ExtrusionLightingWindow, SelectValueSetHdl, ValueSet*, void) +IMPL_LINK(ExtrusionLightingWindow, IconViewItemActivatedHdl, const weld::TreeIter&, rIter, bool) { - sal_Int32 nDirection = mxLightingSet->GetSelectedItemId(); + sal_Int32 nDirection = mxLightingIconView->get_iter_index_in_parent(rIter); + assert(nDirection >= 0 && nDirection < 9 && "Invalid index"); - if( (nDirection > 0) && (nDirection < 10) ) - { - nDirection--; + Sequence aArgs{ comphelper::makePropertyValue( + g_sExtrusionLightingDirection.copy(5), nDirection) }; - Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue( - g_sExtrusionLightingDirection.copy(5), nDirection) }; + mxControl->dispatchCommand(g_sExtrusionLightingDirection, aArgs); - mxControl->dispatchCommand( g_sExtrusionLightingDirection, aArgs ); - - implSetDirection( nDirection, true ); - } + implSetDirection(nDirection, true); mxControl->EndPopupMode(); + + return true; } IMPL_LINK(ExtrusionLightingWindow, SelectToolbarMenuHdl, weld::Toggleable&, rButton, void) diff --git a/svx/source/tbxctrls/extrusioncontrols.hxx b/svx/source/tbxctrls/extrusioncontrols.hxx index 60cfc0663b97..760469bab569 100644 --- a/svx/source/tbxctrls/extrusioncontrols.hxx +++ b/svx/source/tbxctrls/extrusioncontrols.hxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -143,21 +144,21 @@ class ExtrusionLightingWindow final : public WeldToolbarPopup { private: rtl::Reference mxControl; - std::unique_ptr mxLightingSet; - std::unique_ptr mxLightingSetWin; + std::unique_ptr mxLightingIconView; std::unique_ptr mxBright; std::unique_ptr mxNormal; std::unique_ptr mxDim; - Image maImgLightingOff[9]; - Image maImgLightingOn[9]; - Image maImgLightingPreview[9]; + Bitmap maImgLightingOff[9]; + Bitmap maImgLightingOn[9]; + Bitmap maImgLightingPreview[9]; void implSetIntensity( int nLevel, bool bEnabled ); void implSetDirection( int nDirection, bool bEnabled ); DECL_LINK( SelectToolbarMenuHdl, weld::Toggleable&, void ); - DECL_LINK( SelectValueSetHdl, ValueSet*, void ); + DECL_LINK(IconViewItemActivatedHdl, const weld::TreeIter&, bool); + public: ExtrusionLightingWindow(svt::PopupWindowController* pControl, weld::Widget* pParentWindow); virtual void GrabFocus() override; diff --git a/svx/uiconfig/ui/lightingwindow.ui b/svx/uiconfig/ui/lightingwindow.ui index 5daa97319d0e..20e46eb11ab3 100644 --- a/svx/uiconfig/ui/lightingwindow.ui +++ b/svx/uiconfig/ui/lightingwindow.ui @@ -2,6 +2,16 @@ + + + + + + + + + + True False @@ -29,29 +39,18 @@ vertical 6 - + True True - True - True - never - never - in - - - True - False - - - True - True - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK - True - True - - - - + 6 + iconview_model + 3 + 0 + 0 + 0 + 2 + 3 + True False