include/svtools/toolboxcontroller.hxx | 2 svx/source/tbxctrls/tbunocontroller.cxx | 249 ++++++++++++++++++++------------ 2 files changed, 160 insertions(+), 91 deletions(-)
New commits: commit 96808b8422e94e9db73d582e6846d7423bd1d3db Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Apr 20 12:16:17 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Mon Apr 20 19:44:32 2020 +0200 weld SvxFontSizeBox_Impl Change-Id: Ied8ef61226a720acac74db78ae5852cd4e624d14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92562 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/svtools/toolboxcontroller.hxx b/include/svtools/toolboxcontroller.hxx index bcf688ded0c6..bf8e2b6b2864 100644 --- a/include/svtools/toolboxcontroller.hxx +++ b/include/svtools/toolboxcontroller.hxx @@ -129,6 +129,8 @@ class SVT_DLLPUBLIC ToolboxController : void enable( bool bEnable ); + bool IsInSidebar() const { return m_bSidebar; } + protected: bool getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox ); struct Listener diff --git a/svx/source/tbxctrls/tbunocontroller.cxx b/svx/source/tbxctrls/tbunocontroller.cxx index 33cf5c4ed6c8..3e3d9ce2751b 100644 --- a/svx/source/tbxctrls/tbunocontroller.cxx +++ b/svx/source/tbxctrls/tbunocontroller.cxx @@ -27,6 +27,7 @@ #include <vcl/event.hxx> #include <vcl/svapp.hxx> +#include <vcl/weldutils.hxx> #include <vcl/window.hxx> #include <vcl/settings.hxx> #include <toolkit/helper/vclunohelper.hxx> @@ -46,7 +47,9 @@ using namespace ::com::sun::star; namespace { +class SvxFontSizeBox_Base; class SvxFontSizeBox_Impl; + class FontHeightToolBoxControl : public svt::ToolboxController, public lang::XServiceInfo { @@ -81,40 +84,43 @@ class FontHeightToolBoxControl : public svt::ToolboxController, using svt::ToolboxController::dispatchCommand; private: - VclPtr<SvxFontSizeBox_Impl> m_pBox; + VclPtr<SvxFontSizeBox_Impl> m_xVclBox; + std::unique_ptr<SvxFontSizeBox_Base> m_xWeldBox; + SvxFontSizeBox_Base* m_pBox; css::awt::FontDescriptor m_aCurrentFont; }; -class SvxFontSizeBox_Impl final : public InterimItemWindow +class SvxFontSizeBox_Base { public: - SvxFontSizeBox_Impl( vcl::Window* pParent, - const uno::Reference< frame::XFrame >& _xFrame, - FontHeightToolBoxControl& rCtrl ); + SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget, + const uno::Reference< frame::XFrame >& _xFrame, + FontHeightToolBoxControl& rCtrl); - virtual void dispose() override; - virtual ~SvxFontSizeBox_Impl() override; - void statusChanged_Impl( long nHeight, bool bErase ); - void UpdateFont( const css::awt::FontDescriptor& rCurrentFont ); - void SetOptimalSize(); + virtual ~SvxFontSizeBox_Base() + { + } - virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; - virtual void GetFocus() override; + virtual void set_sensitive(bool bSensitive) + { + m_xWidget->set_sensitive(bSensitive); + } - void Enable() {m_xWidget->set_sensitive(true); InterimItemWindow::Enable();} - void Disable() {m_xWidget->set_sensitive(false); InterimItemWindow::Disable();} + void statusChanged_Impl(long nHeight, bool bErase); + void UpdateFont(const css::awt::FontDescriptor& rCurrentFont); -private: - FontHeightToolBoxControl& m_rCtrl; - OUString m_aCurText; - bool m_bRelease; - uno::Reference< frame::XFrame > m_xFrame; - std::unique_ptr<FontSizeBox> m_xWidget; +protected: + FontHeightToolBoxControl& m_rCtrl; + OUString m_aCurText; + bool m_bRelease; + uno::Reference<frame::XFrame> m_xFrame; + std::unique_ptr<FontSizeBox> m_xWidget; void ReleaseFocus_Impl(); - void Select(); + virtual bool DoKeyInput(const KeyEvent& rKEvt); + DECL_LINK(SelectHdl, weld::ComboBox&, void); DECL_LINK(KeyInputHdl, const KeyEvent&, bool); DECL_LINK(ActivateHdl, weld::ComboBox&, bool); @@ -122,48 +128,69 @@ private: DECL_LINK(DumpAsPropertyTreeHdl, boost::property_tree::ptree&, void); }; -SvxFontSizeBox_Impl::SvxFontSizeBox_Impl( - vcl::Window* _pParent, - const uno::Reference< frame::XFrame >& _xFrame, - FontHeightToolBoxControl& _rCtrl ) : +class SvxFontSizeBox_Impl final : public InterimItemWindow + , public SvxFontSizeBox_Base +{ +public: + SvxFontSizeBox_Impl(vcl::Window* pParent, + const uno::Reference< frame::XFrame >& _xFrame, + FontHeightToolBoxControl& rCtrl); - InterimItemWindow(_pParent, "svx/ui/fontsizebox.ui", "FontSizeBox"), + virtual void dispose() override + { + m_xWidget.reset(); + InterimItemWindow::dispose(); + } - m_rCtrl ( _rCtrl ), - m_bRelease ( true ), - m_xFrame ( _xFrame ), - m_xWidget(new FontSizeBox(m_xBuilder->weld_combo_box("fontsizecombobox"))) -{ - m_xWidget->set_value(0); - m_xWidget->set_entry_text(""); - m_xWidget->disable_entry_completion(); + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } - m_xWidget->connect_changed(LINK(this, SvxFontSizeBox_Impl, SelectHdl)); - m_xWidget->connect_key_press(LINK(this, SvxFontSizeBox_Impl, KeyInputHdl)); - m_xWidget->connect_entry_activate(LINK(this, SvxFontSizeBox_Impl, ActivateHdl)); - m_xWidget->connect_focus_out(LINK(this, SvxFontSizeBox_Impl, FocusOutHdl)); - m_xWidget->connect_get_property_tree(LINK(this, SvxFontSizeBox_Impl, DumpAsPropertyTreeHdl)); -} + virtual ~SvxFontSizeBox_Impl() override + { + disposeOnce(); + } -void SvxFontSizeBox_Impl::dispose() -{ - m_xWidget.reset(); - InterimItemWindow::dispose(); -} + void SetOptimalSize(); -SvxFontSizeBox_Impl::~SvxFontSizeBox_Impl() -{ - disposeOnce(); -} + virtual void DataChanged(const DataChangedEvent& rDCEvt) override; + + virtual void set_sensitive(bool bSensitive) override + { + m_xWidget->set_sensitive(bSensitive); + if (bSensitive) + InterimItemWindow::Enable(); + else + InterimItemWindow::Disable(); + } -void SvxFontSizeBox_Impl::GetFocus() +private: + virtual bool DoKeyInput(const KeyEvent& rKEvt) override; +}; + +SvxFontSizeBox_Base::SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget, + const uno::Reference< frame::XFrame >& rFrame, + FontHeightToolBoxControl& rCtrl) + : m_rCtrl(rCtrl) + , m_bRelease(true) + , m_xFrame(rFrame) + , m_xWidget(new FontSizeBox(std::move(xWidget))) { - if (m_xWidget) - m_xWidget->grab_focus(); - InterimItemWindow::GetFocus(); + m_xWidget->set_value(0); + m_xWidget->set_entry_text(""); + m_xWidget->disable_entry_completion(); + + m_xWidget->connect_changed(LINK(this, SvxFontSizeBox_Base, SelectHdl)); + m_xWidget->connect_key_press(LINK(this, SvxFontSizeBox_Base, KeyInputHdl)); + m_xWidget->connect_entry_activate(LINK(this, SvxFontSizeBox_Base, ActivateHdl)); + m_xWidget->connect_focus_out(LINK(this, SvxFontSizeBox_Base, FocusOutHdl)); + m_xWidget->connect_get_property_tree(LINK(this, SvxFontSizeBox_Base, DumpAsPropertyTreeHdl)); } -void SvxFontSizeBox_Impl::ReleaseFocus_Impl() +void SvxFontSizeBox_Base::ReleaseFocus_Impl() { if ( !m_bRelease ) { @@ -175,19 +202,19 @@ void SvxFontSizeBox_Impl::ReleaseFocus_Impl() m_xFrame->getContainerWindow()->setFocus(); } -IMPL_LINK(SvxFontSizeBox_Impl, SelectHdl, weld::ComboBox&, rCombo, void) +IMPL_LINK(SvxFontSizeBox_Base, SelectHdl, weld::ComboBox&, rCombo, void) { if (rCombo.changed_by_direct_pick()) // only when picked from the list Select(); } -IMPL_LINK_NOARG(SvxFontSizeBox_Impl, ActivateHdl, weld::ComboBox&, bool) +IMPL_LINK_NOARG(SvxFontSizeBox_Base, ActivateHdl, weld::ComboBox&, bool) { Select(); return true; } -void SvxFontSizeBox_Impl::Select() +void SvxFontSizeBox_Base::Select() { sal_Int64 nSelVal = m_xWidget->get_value(); float fSelVal = float( nSelVal ) / 10; @@ -204,7 +231,7 @@ void SvxFontSizeBox_Impl::Select() m_rCtrl.dispatchCommand( aArgs ); } -void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase ) +void SvxFontSizeBox_Base::statusChanged_Impl( long nPoint, bool bErase ) { if ( !bErase ) { @@ -224,31 +251,34 @@ void SvxFontSizeBox_Impl::statusChanged_Impl( long nPoint, bool bErase ) m_aCurText = m_xWidget->get_active_text(); } -void SvxFontSizeBox_Impl::UpdateFont( const css::awt::FontDescriptor& rCurrentFont ) +void SvxFontSizeBox_Base::UpdateFont(const css::awt::FontDescriptor& rCurrentFont) { // filling up the sizes list auto nOldVal = m_xWidget->get_value(); // memorize old value - const FontList* _pFontList = nullptr; - std::unique_ptr<FontList> aHold( new FontList( this )); - _pFontList = aHold.get(); + std::unique_ptr<FontList> xFontList(new FontList(Application::GetDefaultDevice())); - if ( !rCurrentFont.Name.isEmpty() ) + if (!rCurrentFont.Name.isEmpty()) { - FontMetric _aFontMetric; - _aFontMetric.SetFamilyName( rCurrentFont.Name ); - _aFontMetric.SetStyleName( rCurrentFont.StyleName ); - _aFontMetric.SetFontHeight( rCurrentFont.Height ); - m_xWidget->Fill(&_aFontMetric, _pFontList); + FontMetric aFontMetric; + aFontMetric.SetFamilyName(rCurrentFont.Name); + aFontMetric.SetStyleName(rCurrentFont.StyleName); + aFontMetric.SetFontHeight(rCurrentFont.Height); + m_xWidget->Fill(&aFontMetric, xFontList.get()); } else { - m_xWidget->Fill(nullptr, _pFontList); + m_xWidget->Fill(nullptr, xFontList.get()); } m_xWidget->set_value(nOldVal); // restore old value m_aCurText = m_xWidget->get_active_text(); // memorize to reset at ESC } -IMPL_LINK(SvxFontSizeBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool) +IMPL_LINK(SvxFontSizeBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool) +{ + return DoKeyInput(rKEvt); +} + +bool SvxFontSizeBox_Base::DoKeyInput(const KeyEvent& rKEvt) { bool bHandled = false; @@ -263,16 +293,23 @@ IMPL_LINK(SvxFontSizeBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool) case KEY_ESCAPE: m_xWidget->set_entry_text(m_aCurText); - if ( typeid( *GetParent() ) != typeid( sfx2::sidebar::SidebarToolBox ) ) + if (!m_rCtrl.IsInSidebar()) + { ReleaseFocus_Impl(); - bHandled = true; + bHandled = true; + } break; } - return bHandled || ChildKeyInput(rKEvt); + return bHandled; +} + +bool SvxFontSizeBox_Impl::DoKeyInput(const KeyEvent& rKEvt) +{ + return SvxFontSizeBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt); } -IMPL_LINK_NOARG(SvxFontSizeBox_Impl, FocusOutHdl, weld::Widget&, void) +IMPL_LINK_NOARG(SvxFontSizeBox_Base, FocusOutHdl, weld::Widget&, void) { if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus m_xWidget->set_entry_text(m_aCurText); @@ -283,6 +320,14 @@ void SvxFontSizeBox_Impl::SetOptimalSize() SetSizePixel(get_preferred_size()); } +SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(vcl::Window* pParent, + const uno::Reference<frame::XFrame>& rFrame, + FontHeightToolBoxControl& rCtrl) + : InterimItemWindow(pParent, "svx/ui/fontsizebox.ui", "FontSizeBox") + , SvxFontSizeBox_Base(m_xBuilder->weld_combo_box("fontsizecombobox"), rFrame, rCtrl) +{ +} + void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt ) { if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && @@ -292,7 +337,7 @@ void SvxFontSizeBox_Impl::DataChanged( const DataChangedEvent& rDCEvt ) } } -IMPL_LINK(SvxFontSizeBox_Impl, DumpAsPropertyTreeHdl, boost::property_tree::ptree&, rTree, void) +IMPL_LINK(SvxFontSizeBox_Base, DumpAsPropertyTreeHdl, boost::property_tree::ptree&, rTree, void) { boost::property_tree::ptree aEntries; @@ -372,7 +417,9 @@ void SAL_CALL FontHeightToolBoxControl::dispose() svt::ToolboxController::dispose(); SolarMutexGuard aSolarMutexGuard; - m_pBox.disposeAndClear(); + m_xVclBox.disposeAndClear(); + m_xWeldBox.reset(); + m_pBox = nullptr; } // XStatusListener @@ -382,16 +429,11 @@ void SAL_CALL FontHeightToolBoxControl::statusChanged( if ( m_pBox ) { SolarMutexGuard aSolarMutexGuard; - if ( rEvent.FeatureURL.Path == "FontHeight" ) + if (rEvent.FeatureURL.Path == "FontHeight") { - ToolBox* pToolBox = nullptr; - sal_uInt16 nId = 0; - if ( !getToolboxId( nId, &pToolBox ) ) - return; - if ( rEvent.IsEnabled ) { - m_pBox->Enable(); + m_pBox->set_sensitive(true); frame::status::FontHeight aFontHeight; if ( rEvent.State >>= aFontHeight ) m_pBox->statusChanged_Impl( long( 10. * aFontHeight.Height ), false ); @@ -400,11 +442,19 @@ void SAL_CALL FontHeightToolBoxControl::statusChanged( } else { - m_pBox->Disable(); + m_pBox->set_sensitive(false); m_pBox->statusChanged_Impl( long( -1 ), true ); } - pToolBox->EnableItem( nId, rEvent.IsEnabled ); + if (m_pToolbar) + m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled); + else + { + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox)) + pToolBox->EnableItem(nId, rEvent.IsEnabled); + } } else if ( rEvent.FeatureURL.Path == "CharFontName" ) { @@ -437,16 +487,33 @@ uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWind { uno::Reference< awt::XWindow > xItemWindow; - VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent ); - if ( pParent ) + if (m_pBuilder) { SolarMutexGuard aSolarMutexGuard; - m_pBox = VclPtr<SvxFontSizeBox_Impl>::Create( pParent, m_xFrame, *this ); + + std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("fontsizecombobox")); + + xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get())); + + m_xWeldBox.reset(new SvxFontSizeBox_Base(std::move(xWidget), m_xFrame, *this)); + m_pBox = m_xWeldBox.get(); //Get the box to fill itself with all its sizes m_pBox->UpdateFont(m_aCurrentFont); - //Make it size itself to its optimal size re above sizes - m_pBox->SetOptimalSize(); - xItemWindow = VCLUnoHelper::GetInterface( m_pBox ); + } + else + { + VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent ); + if ( pParent ) + { + SolarMutexGuard aSolarMutexGuard; + m_xVclBox = VclPtr<SvxFontSizeBox_Impl>::Create( pParent, m_xFrame, *this ); + m_pBox = m_xVclBox.get(); + //Get the box to fill itself with all its sizes + m_pBox->UpdateFont(m_aCurrentFont); + //Make it size itself to its optimal size re above sizes + m_xVclBox->SetOptimalSize(); + xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox); + } } return xItemWindow; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits