include/sfx2/charmapcontainer.hxx | 8 ++++ include/sfx2/charwin.hxx | 11 +---- sfx2/source/control/charmapcontainer.cxx | 57 +++++++++++++++++++++++++------ sfx2/source/control/charwin.cxx | 34 +++--------------- svx/source/dialog/cuicharmap.cxx | 2 - 5 files changed, 65 insertions(+), 47 deletions(-)
New commits: commit b306d5ba956b84c2d6478adcd3f07048e449d81e Author: Michael Weghorn <[email protected]> AuthorDate: Fri Dec 12 19:41:25 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Mon Dec 15 23:50:14 2025 +0100 sfx2, svx: Drop 2 unused includes Qt Creator was showing a warning about those being unused. Change-Id: Ibe80357f52b2cfb0870ab0d860b093243824b206 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195584 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx index 4ba1c56ec73a..a449042edff4 100644 --- a/include/sfx2/charwin.hxx +++ b/include/sfx2/charwin.hxx @@ -23,7 +23,6 @@ #include <vcl/customweld.hxx> #include <vcl/virdev.hxx> #include <vcl/weld.hxx> -#include <deque> class SAL_DLLPUBLIC_RTTI SvxCharView final : public weld::CustomWidgetController { diff --git a/svx/source/dialog/cuicharmap.cxx b/svx/source/dialog/cuicharmap.cxx index ba6fd0c5923a..cc11ee93f608 100644 --- a/svx/source/dialog/cuicharmap.cxx +++ b/svx/source/dialog/cuicharmap.cxx @@ -19,8 +19,6 @@ #include <sal/config.h> -#include <stdio.h> - #include <utility> #include <vcl/svapp.hxx> #include <svl/eitem.hxx> commit e03a1ce190aae23ad98f321a66b103dcbbaa5e1b Author: Michael Weghorn <[email protected]> AuthorDate: Fri Dec 12 19:29:01 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Mon Dec 15 23:50:08 2025 +0100 tdf#168594 Simplify SvxCharView font update SvxCharView::SetFont never gets called with a completely different font than the one already set, but the callers retrieve the currently set font, potentially set a different font family, and pass the font back to SvxCharView::SetFont. Simplify the handling by having a method that takes the font family to set instead, and updates the existing Font object (SvxCharView::maFont) directly. Change-Id: Ifb0e8f648146dcfe5693f62d7601e9646e90e2ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195583 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx index 6e7a21b2e1dd..4ba1c56ec73a 100644 --- a/include/sfx2/charwin.hxx +++ b/include/sfx2/charwin.hxx @@ -52,7 +52,7 @@ public: SvxCharView(const VclPtr<VirtualDevice>& rVirDev); SFX2_DLLPUBLIC virtual ~SvxCharView() override; - void SetFont( const vcl::Font& rFont ); + void UpdateFont(const OUString& rFontFamilyName); vcl::Font const & GetFont() const { return maFont; } void SetText( const OUString& rText ); OUString const & GetText() const { return m_sText; } diff --git a/sfx2/source/control/charmapcontainer.cxx b/sfx2/source/control/charmapcontainer.cxx index 765220fa2a93..953522cba169 100644 --- a/sfx2/source/control/charmapcontainer.cxx +++ b/sfx2/source/control/charmapcontainer.cxx @@ -152,9 +152,7 @@ void SfxCharmapContainer::updateFavCharControl() for (auto it = m_aFavChars.begin(); it != m_aFavChars.end(); ++it, i++) { m_aFavCharView[i].SetText(it->sChar); - vcl::Font rFont = m_aFavCharView[i].GetFont(); - rFont.SetFamilyName(it->sFont); - m_aFavCharView[i].SetFont(rFont); + m_aFavCharView[i].UpdateFont(it->sFont); m_aFavCharView[i].Show(); } @@ -193,9 +191,7 @@ void SfxCharmapContainer::updateRecentCharControl() for (auto it = m_aRecentChars.begin(); it != m_aRecentChars.end(); ++it, i++) { m_aRecentCharView[i].SetText(it->sChar); - vcl::Font rFont = m_aRecentCharView[i].GetFont(); - rFont.SetFamilyName(it->sFont); - m_aRecentCharView[i].SetFont(rFont); + m_aRecentCharView[i].UpdateFont(it->sFont); m_aRecentCharView[i].Show(); } diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx index 4a00dbceeae2..b0673f49ff6b 100644 --- a/sfx2/source/control/charwin.cxx +++ b/sfx2/source/control/charwin.cxx @@ -267,10 +267,10 @@ void SvxCharView::setContextMenuHdl(const Link<const CommandEvent&, void>& rLink maContextMenuHdl = rLink; } -void SvxCharView::SetFont(const vcl::Font& rFont) +void SvxCharView::UpdateFont(const OUString& rFontFamilyName) { tools::Long nWinHeight = GetOutputSizePixel().Height(); - maFont = rFont; + maFont.SetFamilyName(rFontFamilyName); maFont.SetWeight(WEIGHT_NORMAL); maFont.SetAlignment(ALIGN_TOP); maFont.SetFontSize(mxVirDev->PixelToLogic(Size(0, nWinHeight / 2))); @@ -286,7 +286,8 @@ void SvxCharView::SetFont(const vcl::Font& rFont) void SvxCharView::Resize() { - SetFont(GetFont()); //force recalculation of size + // force recalculation of size + UpdateFont(maFont.GetFamilyName()); } void SvxCharView::SetText(const OUString& rText) commit 7bbf805341d3ce839d00067a0d92cae9cb465555 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 11 20:57:21 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Mon Dec 15 23:50:02 2025 +0100 tdf#168594 Move logic to show context menu out of SvxCharView Move the logic to show the context menu for one of the recent or favorite characters in the special characters popup and dialog from the SvxCharView class to the SfxCharmapContainer that manages all of the recent and favorite characters, i.e. which owns the SvxCharView instances. No change in behavior intended or seen in a quick test. This is in preparation of switching away from SvxCharView and using a weld::IconView for the recent and favorite characters instead in an upcoming commit. Change-Id: Id4b5cee8abc68be3dfbdbdb26db5a675be2fd15f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195582 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/include/sfx2/charmapcontainer.hxx b/include/sfx2/charmapcontainer.hxx index b7be9fe237da..65e982a6255e 100644 --- a/include/sfx2/charmapcontainer.hxx +++ b/include/sfx2/charmapcontainer.hxx @@ -56,11 +56,19 @@ class SFX2_DLLPUBLIC SfxCharmapContainer Link<void*, void> m_aUpdateFavHdl; Link<void*, void> m_aUpdateRecentHdl; + DECL_DLLPRIVATE_LINK(RecentContextMenuHdl, const CommandEvent&, void); + DECL_DLLPRIVATE_LINK(FavContextMenuHdl, const CommandEvent&, void); + DECL_DLLPRIVATE_LINK(RecentClearClickHdl, SvxCharView&, void); DECL_DLLPRIVATE_LINK(FavClearClickHdl, SvxCharView&, void); DECL_DLLPRIVATE_LINK(RecentClearAllClickHdl, SvxCharView&, void); DECL_DLLPRIVATE_LINK(FavClearAllClickHdl, SvxCharView&, void); + static void HandleContextMenu(std::span<SvxCharView> aCharViews, + const Link<SvxCharView&, void>& rClearHdl, + const Link<SvxCharView&, void>& rClearAllHdl, + const CommandEvent& rCmdEvent); + public: SfxCharmapContainer(weld::Builder& rBuilder, const VclPtr<VirtualDevice>& rVirDev, bool bLockGridSizes); diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx index e3a5a2bed982..6e7a21b2e1dd 100644 --- a/include/sfx2/charwin.hxx +++ b/include/sfx2/charwin.hxx @@ -36,8 +36,7 @@ private: Link<SvxCharView&, void> maFocusInHdl; Link<SvxCharView&, void> maMouseClickHdl; - Link<SvxCharView&, void> maClearClickHdl; - Link<SvxCharView&, void> maClearAllClickHdl; + Link<const CommandEvent&, void> maContextMenuHdl; virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; virtual void Resize() override; @@ -61,14 +60,11 @@ public: void SetHasInsert( bool bInsert ); void InsertCharToDoc(); - void createContextMenu(const Point& rPosition); - Size get_preferred_size() const { return GetDrawingArea()->get_preferred_size(); } void setFocusInHdl(const Link<SvxCharView&, void>& rLink); void setMouseClickHdl(const Link<SvxCharView&, void>& rLink); - void setClearClickHdl(const Link<SvxCharView&, void>& rLink); - void setClearAllClickHdl(const Link<SvxCharView&, void>& rLink); + void setContextMenuHdl(const Link<const CommandEvent&, void>& rLink); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sfx2/source/control/charmapcontainer.cxx b/sfx2/source/control/charmapcontainer.cxx index f13068eb385b..765220fa2a93 100644 --- a/sfx2/source/control/charmapcontainer.cxx +++ b/sfx2/source/control/charmapcontainer.cxx @@ -24,6 +24,7 @@ #include <sfx2/viewfrm.hxx> #include <sfx2/strings.hrc> #include <sfx2/sfxresid.hxx> +#include <vcl/commandevent.hxx> using namespace css; @@ -121,13 +122,12 @@ void SfxCharmapContainer::init(bool bHasInsert, const Link<SvxCharView&, void>& m_aRecentCharView[i].SetHasInsert(bHasInsert); m_aRecentCharView[i].setFocusInHdl(rFocusInHdl); m_aRecentCharView[i].setMouseClickHdl(rMouseClickHdl); - m_aRecentCharView[i].setClearClickHdl(LINK(this, SfxCharmapContainer, RecentClearClickHdl)); - m_aRecentCharView[i].setClearAllClickHdl(LINK(this, SfxCharmapContainer, RecentClearAllClickHdl)); + m_aRecentCharView[i].setContextMenuHdl( + LINK(this, SfxCharmapContainer, RecentContextMenuHdl)); m_aFavCharView[i].SetHasInsert(bHasInsert); m_aFavCharView[i].setFocusInHdl(rFocusInHdl); m_aFavCharView[i].setMouseClickHdl(rMouseClickHdl); - m_aFavCharView[i].setClearClickHdl(LINK(this, SfxCharmapContainer, FavClearClickHdl)); - m_aFavCharView[i].setClearAllClickHdl(LINK(this, SfxCharmapContainer, FavClearAllClickHdl)); + m_aFavCharView[i].setContextMenuHdl(LINK(this, SfxCharmapContainer, FavContextMenuHdl)); } } @@ -297,6 +297,47 @@ bool SfxCharmapContainer::isFavChar(const OUString& rTitle, const OUString& rFon return std::ranges::find(m_aFavChars, CharAndFont(rTitle, rFont)) != m_aFavChars.end(); } +void SfxCharmapContainer::HandleContextMenu(std::span<SvxCharView> aCharViews, + const Link<SvxCharView&, void>& rClearHdl, + const Link<SvxCharView&, void>& rClearAllHdl, + const CommandEvent& rCmdEvent) +{ + assert(rCmdEvent.GetCommand() == CommandEventId::ContextMenu); + + for (SvxCharView& rView : aCharViews) + { + // the context menu is opened for the currently focused view + if (!rView.HasFocus()) + continue; + + weld::DrawingArea* pDrawingArea = rView.GetDrawingArea(); + std::unique_ptr<weld::Builder> xBuilder( + Application::CreateBuilder(pDrawingArea, u"sfx/ui/charviewmenu.ui"_ustr)); + std::unique_ptr<weld::Menu> xItemMenu(xBuilder->weld_menu(u"charviewmenu"_ustr)); + const OUString sMenuId = xItemMenu->popup_at_rect( + pDrawingArea, tools::Rectangle(rCmdEvent.GetMousePosPixel(), Size(1, 1))); + if (sMenuId == u"clearchar") + rClearHdl.Call(rView); + else if (sMenuId == u"clearallchar") + rClearAllHdl.Call(rView); + + rView.Invalidate(); + return; + } +} + +IMPL_LINK(SfxCharmapContainer, RecentContextMenuHdl, const CommandEvent&, rCmdEvent, void) +{ + HandleContextMenu(m_aRecentCharView, (LINK(this, SfxCharmapContainer, RecentClearClickHdl)), + LINK(this, SfxCharmapContainer, RecentClearAllClickHdl), rCmdEvent); +} + +IMPL_LINK(SfxCharmapContainer, FavContextMenuHdl, const CommandEvent&, rCmdEvent, void) +{ + HandleContextMenu(m_aFavCharView, LINK(this, SfxCharmapContainer, FavClearClickHdl), + LINK(this, SfxCharmapContainer, FavClearAllClickHdl), rCmdEvent); +} + IMPL_LINK(SfxCharmapContainer, RecentClearClickHdl, SvxCharView&, rView, void) { const OUString& sTitle = rView.GetText(); diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx index 2a7c4f77e005..4a00dbceeae2 100644 --- a/sfx2/source/control/charwin.cxx +++ b/sfx2/source/control/charwin.cxx @@ -145,7 +145,7 @@ bool SvxCharView::Command(const CommandEvent& rCommandEvent) { GrabFocus(); Invalidate(); - createContextMenu(rCommandEvent.GetMousePosPixel()); + maContextMenuHdl.Call(rCommandEvent); return true; } @@ -165,22 +165,6 @@ void SvxCharView::InsertCharToDoc() comphelper::dispatchCommand(u".uno:InsertSymbol"_ustr, aArgs); } -void SvxCharView::createContextMenu(const Point& rPosition) -{ - weld::DrawingArea* pDrawingArea = GetDrawingArea(); - std::unique_ptr<weld::Builder> xBuilder( - Application::CreateBuilder(pDrawingArea, u"sfx/ui/charviewmenu.ui"_ustr)); - std::unique_ptr<weld::Menu> xItemMenu(xBuilder->weld_menu(u"charviewmenu"_ustr)); - const OUString sMenuId - = xItemMenu->popup_at_rect(pDrawingArea, tools::Rectangle(rPosition, Size(1, 1))); - if (sMenuId == u"clearchar") - maClearClickHdl.Call(*this); - else if (sMenuId == u"clearallchar") - maClearAllClickHdl.Call(*this); - - Invalidate(); -} - void SvxCharView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) { rRenderContext.SetFont(maFont); @@ -278,14 +262,9 @@ void SvxCharView::setMouseClickHdl(const Link<SvxCharView&, void>& rLink) maMouseClickHdl = rLink; } -void SvxCharView::setClearClickHdl(const Link<SvxCharView&, void>& rLink) -{ - maClearClickHdl = rLink; -} - -void SvxCharView::setClearAllClickHdl(const Link<SvxCharView&, void>& rLink) +void SvxCharView::setContextMenuHdl(const Link<const CommandEvent&, void>& rLink) { - maClearAllClickHdl = rLink; + maContextMenuHdl = rLink; } void SvxCharView::SetFont(const vcl::Font& rFont)
