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>
51 class SvxFontSizeBox_Base;
52 class SvxFontSizeBox_Impl;
55 public lang::XServiceInfo
58 explicit FontHeightToolBoxControl(
59 const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
62 virtual css::uno::Any SAL_CALL
queryInterface(
const css::uno::Type& aType )
override;
63 virtual void SAL_CALL
acquire() noexcept override;
64 virtual
void SAL_CALL release() noexcept override;
67 virtual OUString SAL_CALL getImplementationName() override;
68 virtual
sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
69 virtual
css::
uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
72 virtual
void SAL_CALL dispose() override;
75 virtual
void SAL_CALL statusChanged( const
css::frame::FeatureStateEvent& Event ) override;
78 virtual
void SAL_CALL execute( sal_Int16 KeyModifier ) override;
79 virtual
void SAL_CALL click() override;
80 virtual
void SAL_CALL doubleClick() override;
81 virtual
css::
uno::Reference<
css::awt::XWindow > SAL_CALL createPopupWindow() override;
82 virtual
css::
uno::Reference<
css::awt::XWindow > SAL_CALL createItemWindow( const
css::
uno::Reference<
css::awt::XWindow >& Parent ) override;
84 void dispatchCommand( const
css::
uno::Sequence<
css::beans::PropertyValue >& rArgs );
85 using
svt::ToolboxController::dispatchCommand;
88 VclPtr<SvxFontSizeBox_Impl> m_xVclBox;
89 std::unique_ptr<SvxFontSizeBox_Base> m_xWeldBox;
90 SvxFontSizeBox_Base* m_pBox;
93 class SvxFontSizeBox_Base
96 SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
97 const uno::Reference< frame::XFrame >& _xFrame,
98 FontHeightToolBoxControl& rCtrl);
100 virtual ~SvxFontSizeBox_Base()
104 virtual void set_sensitive(
bool bSensitive)
109 void statusChanged_Impl(
tools::Long nHeight,
bool bErase);
113 FontHeightToolBoxControl& m_rCtrl;
116 uno::Reference<frame::XFrame>
m_xFrame;
119 void ReleaseFocus_Impl();
122 virtual bool DoKeyInput(
const KeyEvent& rKEvt);
132 ,
public SvxFontSizeBox_Base
136 const uno::Reference< frame::XFrame >& _xFrame,
137 FontHeightToolBoxControl& rCtrl);
139 virtual void dispose()
override
152 virtual ~SvxFontSizeBox_Impl()
override
157 void SetOptimalSize();
161 virtual void set_sensitive(
bool bSensitive)
override
171 virtual bool DoKeyInput(
const KeyEvent& rKEvt)
override;
174 SvxFontSizeBox_Base::SvxFontSizeBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
175 const uno::Reference<frame::XFrame>& rFrame,
176 FontHeightToolBoxControl& rCtrl)
186 m_xWidget->connect_changed(
LINK(
this, SvxFontSizeBox_Base, SelectHdl));
187 m_xWidget->connect_key_press(
LINK(
this, SvxFontSizeBox_Base, KeyInputHdl));
188 m_xWidget->connect_entry_activate(
LINK(
this, SvxFontSizeBox_Base, ActivateHdl));
189 m_xWidget->connect_focus_out(
LINK(
this, SvxFontSizeBox_Base, FocusOutHdl));
190 m_xWidget->connect_get_property_tree(
LINK(
this, SvxFontSizeBox_Base, DumpAsPropertyTreeHdl));
193 void SvxFontSizeBox_Base::ReleaseFocus_Impl()
202 m_xFrame->getContainerWindow()->setFocus();
207 if (rCombo.changed_by_direct_pick())
217 void SvxFontSizeBox_Base::Select()
219 sal_Int64 nSelVal =
m_xWidget->get_value();
220 float fSelVal = float( nSelVal ) / 10;
230 m_rCtrl.dispatchCommand( aArgs );
233 void SvxFontSizeBox_Base::statusChanged_Impl(
tools::Long nPoint,
bool bErase )
250 m_aCurText =
m_xWidget->get_active_text();
253 void SvxFontSizeBox_Base::UpdateFont()
262 m_aCurText =
m_xWidget->get_active_text();
267 return DoKeyInput(rKEvt);
270 bool SvxFontSizeBox_Base::DoKeyInput(
const KeyEvent& rKEvt)
272 bool bHandled =
false;
284 m_xWidget->set_active_or_entry_text(m_aCurText);
285 if (!m_rCtrl.IsInSidebar())
296 bool SvxFontSizeBox_Impl::DoKeyInput(
const KeyEvent& rKEvt)
298 return SvxFontSizeBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
304 m_xWidget->set_active_or_entry_text(m_aCurText);
307 void SvxFontSizeBox_Impl::SetOptimalSize()
309 SetSizePixel(get_preferred_size());
312 SvxFontSizeBox_Impl::SvxFontSizeBox_Impl(
vcl::Window* pParent,
313 const uno::Reference<frame::XFrame>& rFrame,
314 FontHeightToolBoxControl& rCtrl)
316 , SvxFontSizeBox_Base(m_xBuilder->weld_combo_box(
"fontsizecombobox"), rFrame, rCtrl)
322 if ( (rDCEvt.
GetType() == DataChangedEventType::SETTINGS) &&
323 (rDCEvt.
GetFlags() & AllSettingsFlags::STYLE) )
332 auto entriesNode = rJsonWriter.startNode(
"entries");
335 auto entryNode = rJsonWriter.startNode(
"");
336 rJsonWriter.put(
"",
m_xWidget->get_text(i));
341 rJsonWriter.put(
"selectedCount", static_cast<sal_Int32>(nActive == -1 ? 0 : 1));
343 auto selectedNode = rJsonWriter.startNode(
"selectedEntries");
346 auto node = rJsonWriter.startNode(
"");
347 rJsonWriter.put(
"", static_cast<sal_Int32>(nActive));
351 rJsonWriter.put(
"command",
".uno:FontHeight");
354 FontHeightToolBoxControl::FontHeightToolBoxControl(
const uno::Reference< uno::XComponentContext >& rxContext )
355 :
svt::ToolboxController( rxContext,
360 addStatusListener(
".uno:CharFontName");
364 css::uno::Any SAL_CALL FontHeightToolBoxControl::queryInterface(
const css::uno::Type& aType )
366 uno::Any a = ToolboxController::queryInterface( aType );
370 return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >(
this ));
373 void SAL_CALL FontHeightToolBoxControl::acquire() noexcept
375 ToolboxController::acquire();
378 void SAL_CALL FontHeightToolBoxControl::release() noexcept
380 ToolboxController::release();
384 sal_Bool SAL_CALL FontHeightToolBoxControl::supportsService(
const OUString& ServiceName )
389 OUString SAL_CALL FontHeightToolBoxControl::getImplementationName()
391 return "com.sun.star.svx.FontHeightToolBoxController";
394 uno::Sequence< OUString > SAL_CALL FontHeightToolBoxControl::getSupportedServiceNames( )
396 return {
"com.sun.star.frame.ToolbarController" };
400 void SAL_CALL FontHeightToolBoxControl::dispose()
405 m_xVclBox.disposeAndClear();
411 void SAL_CALL FontHeightToolBoxControl::statusChanged(
412 const frame::FeatureStateEvent& rEvent )
418 if (rEvent.FeatureURL.Path ==
"FontHeight")
420 if ( rEvent.IsEnabled )
422 m_pBox->set_sensitive(
true);
423 frame::status::FontHeight aFontHeight;
424 if ( rEvent.State >>= aFontHeight )
427 aFontHeight.Height = rtl::math::round(10. * aFontHeight.Height);
428 m_pBox->statusChanged_Impl(
tools::Long(aFontHeight.Height),
false);
431 m_pBox->statusChanged_Impl(
tools::Long( -1 ),
true );
435 m_pBox->set_sensitive(
false);
436 m_pBox->statusChanged_Impl(
tools::Long( -1 ),
true );
440 m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
445 if (getToolboxId(nId, &pToolBox))
449 else if ( rEvent.FeatureURL.Path ==
"CharFontName" )
451 m_pBox->UpdateFont();
456 void SAL_CALL FontHeightToolBoxControl::execute( sal_Int16 )
460 void SAL_CALL FontHeightToolBoxControl::click()
464 void SAL_CALL FontHeightToolBoxControl::doubleClick()
468 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createPopupWindow()
470 return uno::Reference< awt::XWindow >();
473 uno::Reference< awt::XWindow > SAL_CALL FontHeightToolBoxControl::createItemWindow(
474 const uno::Reference< awt::XWindow >& xParent )
476 uno::Reference< awt::XWindow > xItemWindow;
486 m_xWeldBox.reset(
new SvxFontSizeBox_Base(std::move(xWidget), m_xFrame, *
this));
487 m_pBox = m_xWeldBox.get();
489 m_pBox->UpdateFont();
498 m_pBox = m_xVclBox.get();
500 m_pBox->UpdateFont();
502 m_xVclBox->SetOptimalSize();
510 void FontHeightToolBoxControl::dispatchCommand(
511 const uno::Sequence< beans::PropertyValue >& rArgs )
513 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
514 if ( xDispatchProvider.is() )
517 uno::Reference< frame::XDispatch >
xDispatch;
518 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
520 aURL.Complete =
".uno:FontHeight";
521 xURLTransformer->parseStrict( aURL );
522 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
523 if ( xDispatch.is() )
524 xDispatch->dispatch( aURL, rArgs );
530 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
532 css::uno::XComponentContext *rxContext,
533 css::uno::Sequence<css::uno::Any>
const &)
535 return cppu::acquire(
new FontHeightToolBoxControl(rxContext));
#define LINK(Instance, Class, Member)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
IMPL_LINK(MaskData, PipetteHdl, const OString &, rId, void)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
virtual std::unique_ptr< ComboBox > weld_combo_box(const OString &id)=0
css::uno::Reference< css::lang::XComponent > m_xFrame
sal_uInt16 GetCode() const
DataChangedEventType GetType() const
IMPL_LINK_NOARG(MaskData, ExecHdl, weld::Button &, void)
static OutputDevice * GetDefaultDevice()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_svx_FontHeightToolBoxController_get_implementation(css::uno::XComponentContext *rxContext, css::uno::Sequence< css::uno::Any > const &)
void Enable(bool bEnable=true, bool bChild=true)
exports com.sun.star. frame
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual void GetFocus() override
AllSettingsFlags GetFlags() const
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void Disable(bool bChild=true)
const vcl::KeyCode & GetKeyCode() const
Reference< XDispatch > xDispatch
constexpr sal_uInt16 KEY_ESCAPE
virtual void dispose() override
static VclPtr< reference_type > Create(Arg &&...arg)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
constexpr sal_uInt16 KEY_TAB