include/svtools/ctrlbox.hxx | 3 +++ svtools/source/control/ctrlbox.cxx | 1 + svx/source/tbxctrls/tbcontrl.cxx | 31 ++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-)
New commits: commit 30d3a5743961274d360e683eccd2756257ed5e7a Author: Caolán McNamara <[email protected]> AuthorDate: Tue Dec 12 10:22:32 2023 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Tue Dec 12 13:59:33 2023 +0100 tdf#158320 restore Live Preview for font hovering a) announce Preview when a 'selected' font preview is requested b) move EndPreview to when the dropdown popups down, rather than listen to ESC Change-Id: I68916769150c23c0ec18aae084cdf3cafb7352a4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160609 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx index 39863b171b0e..ddd8eabc8f32 100644 --- a/include/svtools/ctrlbox.hxx +++ b/include/svtools/ctrlbox.hxx @@ -329,6 +329,7 @@ private: bool mbWYSIWYG; OUString maFontMRUEntriesFile; Idle maUpdateIdle; + Link<const FontMetric&, void> m_aLivePreviewHdl; SVT_DLLPRIVATE void ImplDestroyFontList(); @@ -356,6 +357,8 @@ public: void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_in(rLink); } void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_out(rLink); } void connect_key_press(const Link<const KeyEvent&, bool>& rLink) { m_xComboBox->connect_key_press(rLink); } + void connect_popup_toggled(const Link<weld::ComboBox&, void>& rLink){ m_xComboBox->connect_popup_toggled(rLink); } + void connect_live_preview(const Link<const FontMetric&, void>& rLink) { m_aLivePreviewHdl = rLink; } int get_active() const { return m_xComboBox->get_active(); } OUString get_active_text() const { return m_xComboBox->get_active_text(); } void set_active_or_entry_text(const OUString& rText); diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index 3d4ce47b0814..5b06c7540090 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -873,6 +873,7 @@ IMPL_LINK(FontNameBox, CustomRenderHdl, weld::ComboBox::render_args, aPayload, v { const FontMetric& rFontMetric = (*mpFontList)[nIndex]; DrawPreview(rFontMetric, aDestPoint, rRenderContext, true); + m_aLivePreviewHdl.Call(rFontMetric); } else { diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 6253d4f4b0d4..9a3669aac56a 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -341,6 +341,7 @@ protected: bool bRelease; Reference< XFrame > m_xFrame; bool mbCheckingUnknownFont; + bool mbDropDownActive; void ReleaseFocus_Impl(); @@ -394,6 +395,8 @@ public: DECL_LINK(ActivateHdl, weld::ComboBox&, bool); DECL_LINK(FocusInHdl, weld::Widget&, void); DECL_LINK(FocusOutHdl, weld::Widget&, void); + DECL_LINK(PopupToggledHdl, weld::ComboBox&, void); + DECL_LINK(LivePreviewHdl, const FontMetric&, void); DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void); }; @@ -1726,6 +1729,7 @@ SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget , bRelease(true) , m_xFrame(rFrame) , mbCheckingUnknownFont(false) + , mbDropDownActive(false) { EnableControls(); @@ -1734,6 +1738,8 @@ SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget m_xWidget->connect_entry_activate(LINK(this, SvxFontNameBox_Base, ActivateHdl)); m_xWidget->connect_focus_in(LINK(this, SvxFontNameBox_Base, FocusInHdl)); m_xWidget->connect_focus_out(LINK(this, SvxFontNameBox_Base, FocusOutHdl)); + m_xWidget->connect_popup_toggled(LINK(this, SvxFontNameBox_Base, PopupToggledHdl)); + m_xWidget->connect_live_preview(LINK(this, SvxFontNameBox_Base, LivePreviewHdl)); m_xWidget->connect_get_property_tree(LINK(this, SvxFontNameBox_Base, DumpAsPropertyTreeHdl)); m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 5); @@ -1849,7 +1855,6 @@ bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt) ReleaseFocus_Impl(); bHandled = true; } - EndPreview(); break; } @@ -1871,6 +1876,30 @@ IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusOutHdl, weld::Widget&, void) } } +IMPL_LINK(SvxFontNameBox_Base, LivePreviewHdl, const FontMetric&, rFontMetric, void) +{ + Sequence<PropertyValue> aArgs(1); + + SvxFontItem aFontItem(rFontMetric.GetFamilyType(), + rFontMetric.GetFamilyName(), + rFontMetric.GetStyleName(), + rFontMetric.GetPitch(), + rFontMetric.GetCharSet(), + SID_ATTR_CHAR_FONT); + PropertyValue* pArgs = aArgs.getArray(); + aFontItem.QueryValue(pArgs[0].Value); + pArgs[0].Name = "CharPreviewFontName"; + const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY); + SfxToolBoxControl::Dispatch(xProvider, ".uno:CharPreviewFontName", aArgs); +} + +IMPL_LINK_NOARG(SvxFontNameBox_Base, PopupToggledHdl, weld::ComboBox&, void) +{ + mbDropDownActive = !mbDropDownActive; + if (!mbDropDownActive) + EndPreview(); +} + void SvxFontNameBox_Impl::SetOptimalSize() { // set width in chars low so the size request will not be overridden
