20#include <com/sun/star/frame/XFrame.hpp>
21#include <com/sun/star/frame/status/FontHeight.hpp>
22#include <com/sun/star/frame/XDispatchProvider.hpp>
23#include <com/sun/star/beans/PropertyValue.hpp>
24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/util/XURLTransformer.hpp>
28#include <rtl/math.hxx>
52class SvxFontSizeBox_Base;
53class SvxFontSizeBox_Impl;
55typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, lang::XServiceInfo> FontHeightToolBoxControl_Base;
56class FontHeightToolBoxControl :
public FontHeightToolBoxControl_Base
59 explicit FontHeightToolBoxControl(
60 const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
68 virtual void SAL_CALL
dispose()
override;
71 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& Event )
override;
74 virtual void SAL_CALL execute( sal_Int16 KeyModifier )
override;
75 virtual void SAL_CALL click()
override;
76 virtual void SAL_CALL doubleClick()
override;
77 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow()
override;
78 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow(
const css::uno::Reference< css::awt::XWindow >& Parent )
override;
80 void dispatchCommand(
const css::uno::Sequence< css::beans::PropertyValue >& rArgs );
85 std::unique_ptr<SvxFontSizeBox_Base> m_xWeldBox;
86 SvxFontSizeBox_Base* m_pBox;
89class SvxFontSizeBox_Base
92 SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
93 uno::Reference< frame::XFrame > _xFrame,
94 FontHeightToolBoxControl& rCtrl);
96 virtual ~SvxFontSizeBox_Base()
100 virtual void set_sensitive(
bool bSensitive)
105 void statusChanged_Impl(
tools::Long nHeight,
bool bErase);
109 FontHeightToolBoxControl& m_rCtrl;
112 uno::Reference<frame::XFrame>
m_xFrame;
115 void ReleaseFocus_Impl();
118 virtual bool DoKeyInput(
const KeyEvent& rKEvt);
128 ,
public SvxFontSizeBox_Base
132 const uno::Reference< frame::XFrame >& _xFrame,
133 FontHeightToolBoxControl& rCtrl);
135 virtual void dispose()
override
148 virtual ~SvxFontSizeBox_Impl()
override
153 void SetOptimalSize();
157 virtual void set_sensitive(
bool bSensitive)
override
167 virtual bool DoKeyInput(
const KeyEvent& rKEvt)
override;
170SvxFontSizeBox_Base::SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
171 uno::Reference<frame::XFrame> xFrame,
172 FontHeightToolBoxControl& rCtrl)
182 m_xWidget->connect_changed(
LINK(
this, SvxFontSizeBox_Base, SelectHdl));
183 m_xWidget->connect_key_press(
LINK(
this, SvxFontSizeBox_Base, KeyInputHdl));
184 m_xWidget->connect_entry_activate(
LINK(
this, SvxFontSizeBox_Base, ActivateHdl));
185 m_xWidget->connect_focus_out(
LINK(
this, SvxFontSizeBox_Base, FocusOutHdl));
186 m_xWidget->connect_get_property_tree(
LINK(
this, SvxFontSizeBox_Base, DumpAsPropertyTreeHdl));
189void SvxFontSizeBox_Base::ReleaseFocus_Impl()
198 m_xFrame->getContainerWindow()->setFocus();
203 if (rCombo.changed_by_direct_pick())
213void SvxFontSizeBox_Base::Select()
215 sal_Int64 nSelVal =
m_xWidget->get_value();
216 float fSelVal = float( nSelVal ) / 10;
226 m_rCtrl.dispatchCommand( aArgs );
229void SvxFontSizeBox_Base::statusChanged_Impl(
tools::Long nPoint,
bool bErase )
246 m_aCurText =
m_xWidget->get_active_text();
249void SvxFontSizeBox_Base::UpdateFont()
258 m_aCurText =
m_xWidget->get_active_text();
263 return DoKeyInput(rKEvt);
266bool SvxFontSizeBox_Base::DoKeyInput(
const KeyEvent& rKEvt)
268 bool bHandled =
false;
280 m_xWidget->set_active_or_entry_text(m_aCurText);
281 if (!m_rCtrl.IsInSidebar())
292bool SvxFontSizeBox_Impl::DoKeyInput(
const KeyEvent& rKEvt)
294 return SvxFontSizeBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
300 m_xWidget->set_active_or_entry_text(m_aCurText);
303void SvxFontSizeBox_Impl::SetOptimalSize()
305 SetSizePixel(get_preferred_size());
308SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
vcl::Window* pParent,
309 const uno::Reference<frame::XFrame>& rFrame,
310 FontHeightToolBoxControl& rCtrl)
312 , SvxFontSizeBox_Base(m_xBuilder->weld_combo_box(
"fontsizecombobox"), rFrame, rCtrl)
318 if ( (rDCEvt.
GetType() == DataChangedEventType::SETTINGS) &&
319 (rDCEvt.
GetFlags() & AllSettingsFlags::STYLE) )
328 auto entriesNode = rJsonWriter.startNode(
"entries");
329 for (
int i = 0, nCount =
m_xWidget->get_count(); i < nCount; ++i)
331 auto entryNode = rJsonWriter.startNode(
"");
332 rJsonWriter.put(
"",
m_xWidget->get_text(i));
337 rJsonWriter.put(
"selectedCount",
static_cast<sal_Int32
>(nActive == -1 ? 0 : 1));
339 auto selectedNode = rJsonWriter.startNode(
"selectedEntries");
342 auto node = rJsonWriter.startNode(
"");
343 rJsonWriter.put(
"",
static_cast<sal_Int32
>(nActive));
347 rJsonWriter.put(
"command",
".uno:FontHeight");
350FontHeightToolBoxControl::FontHeightToolBoxControl(
const uno::Reference< uno::XComponentContext >& rxContext )
351 : FontHeightToolBoxControl_Base( rxContext,
356 addStatusListener(
".uno:CharFontName");
360sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService(
const OUString& ServiceName )
365OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
367 return "com.sun.star.svx.FontHeightToolBoxController";
370uno::Sequence< OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
372 return {
"com.sun.star.frame.ToolbarController" };
376void SAL_CALL FontHeightToolBoxControl::dispose()
381 m_xVclBox.disposeAndClear();
387void SAL_CALL FontHeightToolBoxControl::statusChanged(
388 const frame::FeatureStateEvent& rEvent )
394 if (rEvent.FeatureURL.Path ==
"FontHeight")
396 if ( rEvent.IsEnabled )
398 m_pBox->set_sensitive(
true);
399 frame::status::FontHeight aFontHeight;
400 if ( rEvent.State >>= aFontHeight )
403 aFontHeight.Height = rtl::math::round(10. * aFontHeight.Height);
404 m_pBox->statusChanged_Impl(
tools::Long(aFontHeight.Height),
false);
407 m_pBox->statusChanged_Impl(
tools::Long( -1 ),
true );
411 m_pBox->set_sensitive(
false);
412 m_pBox->statusChanged_Impl(
tools::Long( -1 ),
true );
416 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
421 if (getToolboxId(nId, &pToolBox))
425 else if ( rEvent.FeatureURL.Path ==
"CharFontName" )
427 m_pBox->UpdateFont();
432void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 )
436void SAL_CALL FontHeightToolBoxControl::click()
440void SAL_CALL FontHeightToolBoxControl::doubleClick()
444uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
446 return uno::Reference< awt::XWindow >();
449uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
450 const uno::Reference< awt::XWindow >& xParent )
452 uno::Reference< awt::XWindow > xItemWindow;
462 m_xWeldBox.reset(
new SvxFontSizeBox_Base(std::move(xWidget), m_xFrame, *
this));
463 m_pBox = m_xWeldBox.get();
465 m_pBox->UpdateFont();
474 m_pBox = m_xVclBox.get();
476 m_pBox->UpdateFont();
478 m_xVclBox->SetOptimalSize();
486void FontHeightToolBoxControl::dispatchCommand(
487 const uno::Sequence< beans::PropertyValue >& rArgs )
489 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
490 if ( xDispatchProvider.is() )
493 uno::Reference< frame::XDispatch >
xDispatch;
494 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
496 aURL.Complete =
".uno:FontHeight";
497 xURLTransformer->parseStrict( aURL );
498 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
506extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
508 css::uno::XComponentContext *rxContext,
509 css::uno::Sequence<css::uno::Any>
const &)
511 return cppu::acquire(
new FontHeightToolBoxControl(rxContext));
IMPL_LINK(MaskData, PipetteHdl, const OUString &, rId, void)
IMPL_LINK_NOARG(MaskData, ExecHdl, weld::Button &, void)
css::uno::Reference< css::lang::XComponent > m_xFrame
static OutputDevice * GetDefaultDevice()
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
virtual void dispose() override
virtual void GetFocus() override
const vcl::KeyCode & GetKeyCode() const
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static VclPtr< reference_type > Create(Arg &&... arg)
sal_uInt16 GetCode() const
void Disable(bool bChild=true)
void Enable(bool bEnable=true, bool bChild=true)
virtual void DataChanged(const DataChangedEvent &rDCEvt)
virtual std::unique_ptr< ComboBox > weld_combo_box(const OUString &id)=0
Reference< XDispatch > xDispatch
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
constexpr sal_uInt16 KEY_ESCAPE
constexpr sal_uInt16 KEY_TAB
#define LINK(Instance, Class, Member)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference< XFrame > xFrame
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_svx_FontHeightToolBoxController_get_implementation(css::uno::XComponentContext *rxContext, css::uno::Sequence< css::uno::Any > const &)