diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-06 10:59:19 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-06 18:17:02 +0100 |
commit | 97a5da96159f28de0b846de7dd94d2880251e8b3 (patch) | |
tree | 091f4334ff184047376240a4deb5bfb9b0da5b1e | |
parent | bf2f1adfd2e4725518147657c6b57eb5697a29d5 (diff) |
weld SvxMetricField
split off SdPagesField as its not really a MetricSpinButton and can
be a SpinButton with a custom output function.
while I'm at it use ngettext to provide better plurals for the output.
Change-Id: Idc9ce0513c9fce60c8713c7361fd40f0dbd01f64
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88100
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/svx/InterimItemWindow.hxx (renamed from svx/source/inc/InterimItemWindow.hxx) | 4 | ||||
-rw-r--r-- | include/svx/itemwin.hxx | 23 | ||||
-rw-r--r-- | sd/UIConfig_simpress.mk | 1 | ||||
-rw-r--r-- | sd/inc/sdresid.hxx | 1 | ||||
-rw-r--r-- | sd/inc/strings.hrc | 7 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/dlg/diactrl.cxx | 112 | ||||
-rw-r--r-- | sd/source/ui/inc/diactrl.hxx | 21 | ||||
-rw-r--r-- | sd/uiconfig/simpress/ui/pagesfieldbox.ui | 30 | ||||
-rw-r--r-- | solenv/sanitizers/ui/modules/simpress.suppr | 1 | ||||
-rw-r--r-- | solenv/sanitizers/ui/svx.suppr | 1 | ||||
-rw-r--r-- | svx/UIConfig_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/sidebar/paragraph/ParaSpacingWindow.hxx | 2 | ||||
-rw-r--r-- | svx/source/tbxctrls/itemwin.cxx | 118 | ||||
-rw-r--r-- | svx/source/tbxctrls/linewidthctrl.cxx | 13 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbunocontroller.cxx | 2 | ||||
-rw-r--r-- | svx/uiconfig/ui/metricfieldbox.ui | 30 |
17 files changed, 243 insertions, 129 deletions
diff --git a/svx/source/inc/InterimItemWindow.hxx b/include/svx/InterimItemWindow.hxx index 715cf41fc020..58430a2a9c17 100644 --- a/svx/source/inc/InterimItemWindow.hxx +++ b/include/svx/InterimItemWindow.hxx @@ -10,8 +10,10 @@ #pragma once #include <vcl/layout.hxx> +#include <vcl/weld.hxx> +#include <svx/svxdllapi.h> -class InterimItemWindow : public Control +class SVX_DLLPUBLIC InterimItemWindow : public Control { public: virtual ~InterimItemWindow() override; diff --git a/include/svx/itemwin.hxx b/include/svx/itemwin.hxx index a304405523ce..ee2e82ecbdc6 100644 --- a/include/svx/itemwin.hxx +++ b/include/svx/itemwin.hxx @@ -23,6 +23,7 @@ #include <vcl/lstbox.hxx> #include <svtools/toolbarmenu.hxx> #include <svx/dlgctrl.hxx> +#include <svx/InterimItemWindow.hxx> #include <svx/svxdllapi.h> class XLineWidthItem; @@ -48,32 +49,34 @@ public: virtual ~SvxLineBox() override; }; -class SVX_DLLPUBLIC SvxMetricField : public MetricField +class SVX_DLLPUBLIC SvxMetricField final : public InterimItemWindow { - using Window::Update; - - OUString aCurTxt; +private: + std::unique_ptr<weld::MetricSpinButton> m_xWidget; + int nCurValue; MapUnit ePoolUnit; FieldUnit eDlgUnit; - Size aLogicalSize; css::uno::Reference< css::frame::XFrame > mxFrame; - static void ReleaseFocus_Impl(); + DECL_LINK(ModifyHdl, weld::MetricSpinButton&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_LINK(FocusInHdl, weld::Widget&, void); -protected: - virtual void Modify() override; + static void ReleaseFocus_Impl(); - virtual bool PreNotify( NotifyEvent& rNEvt ) override; - virtual bool EventNotify( NotifyEvent& rNEvt ) override; virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; public: SvxMetricField( vcl::Window* pParent, const css::uno::Reference< css::frame::XFrame >& rFrame ); + virtual void dispose() override; + virtual ~SvxMetricField() override; void Update( const XLineWidthItem* pItem ); void SetCoreUnit( MapUnit eUnit ); void RefreshDlgUnit(); + + void set_sensitive(bool bSensitive); }; class SVX_DLLPUBLIC SvxFillTypeBox final : public ListBox diff --git a/sd/UIConfig_simpress.mk b/sd/UIConfig_simpress.mk index b6fcfc484042..3b12fc536374 100644 --- a/sd/UIConfig_simpress.mk +++ b/sd/UIConfig_simpress.mk @@ -141,6 +141,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/simpress,\ sd/uiconfig/simpress/ui/notebookbar_groupedbar_full \ sd/uiconfig/simpress/ui/notebookbar_groupedbar_compact \ sd/uiconfig/simpress/ui/optimpressgeneralpage \ + sd/uiconfig/simpress/ui/pagesfieldbox \ sd/uiconfig/simpress/ui/photoalbum \ sd/uiconfig/simpress/ui/presentationdialog \ sd/uiconfig/simpress/ui/prntopts \ diff --git a/sd/inc/sdresid.hxx b/sd/inc/sdresid.hxx index 20254c0979fb..8c4e80b90e03 100644 --- a/sd/inc/sdresid.hxx +++ b/sd/inc/sdresid.hxx @@ -23,5 +23,6 @@ #include "sddllapi.h" SD_DLLPUBLIC OUString SdResId(const char* pId); +SD_DLLPUBLIC OUString SdResId(const char* pId, int nCardinality); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/inc/strings.hrc b/sd/inc/strings.hrc index 0f188c5b1227..a72d47e7d937 100644 --- a/sd/inc/strings.hrc +++ b/sd/inc/strings.hrc @@ -21,6 +21,7 @@ #define INCLUDED_SD_INC_STRINGS_HRC #define NC_(Context, String) reinterpret_cast<char const *>(Context "\004" u8##String) +#define NNC_(Context, StringSingular, StringPlural) reinterpret_cast<char const *>(Context "\004" u8##StringSingular "\004" u8##StringPlural) #define STR_NULL NC_("STR_NULL", "None") #define STR_INSERTPAGE NC_("STR_INSERTPAGE", "Insert Slide") @@ -149,10 +150,12 @@ #define STR_EFFECTDLG_PROGRAM NC_("STR_EFFECTDLG_PROGRAM", "Program") #define STR_EFFECTDLG_MACRO NC_("STR_EFFECTDLG_MACRO", "Macro") #define STR_FULLSCREEN_SLIDESHOW NC_("STR_FULLSCREEN_SLIDESHOW", "Presenting: %s") + +// To translators: this is the spinbutton in the slidesorter toolbar to set the number of slides to show per row +#define STR_SLIDES NNC_("STR_SLIDES", "%1 slide", "%1 slides") + // Strings for animation effects #define STR_INSERT_TEXT NC_("STR_INSERT_TEXT", "Insert Text") -#define STR_SLIDE_SINGULAR NC_("STR_SLIDE_SINGULAR", " Slide") -#define STR_SLIDE_PLURAL NC_("STR_SLIDE_PLURAL", " Slides") #define STR_LOAD_PRESENTATION_LAYOUT NC_("STR_LOAD_PRESENTATION_LAYOUT", "Load Master Slide") #define STR_DRAGTYPE_URL NC_("STR_DRAGTYPE_URL", "Insert as Hyperlink") #define STR_DRAGTYPE_EMBEDDED NC_("STR_DRAGTYPE_EMBEDDED", "Insert as Copy") diff --git a/sd/source/ui/app/sdmod.cxx b/sd/source/ui/app/sdmod.cxx index 0a10c237501f..077ab4b259bd 100644 --- a/sd/source/ui/app/sdmod.cxx +++ b/sd/source/ui/app/sdmod.cxx @@ -85,6 +85,11 @@ OUString SdResId(const char* pId) return Translate::get(pId, SD_MOD()->GetResLocale()); } +OUString SdResId(const char* pId, int nCardinality) +{ + return Translate::nget(pId, nCardinality, SD_MOD()->GetResLocale()); +} + // Dtor SdModule::~SdModule() { diff --git a/sd/source/ui/dlg/diactrl.cxx b/sd/source/ui/dlg/diactrl.cxx index d05f4f1f16a0..37507c3b4e5b 100644 --- a/sd/source/ui/dlg/diactrl.cxx +++ b/sd/source/ui/dlg/diactrl.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <vcl/field.hxx> #include <svl/intitem.hxx> #include <vcl/toolbox.hxx> @@ -34,54 +35,95 @@ using namespace ::com::sun::star; SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlDiaPages, SfxUInt16Item ) +namespace +{ + OUString format_number(int nSlides) + { + OUString aSlides(SdResId(STR_SLIDES, nSlides)); + return aSlides.replaceFirst("%1", OUString::number(nSlides)); + } +} + // SdPagesField SdPagesField::SdPagesField( vcl::Window* pParent, - const uno::Reference< frame::XFrame >& rFrame ) : - SvxMetricField ( pParent, rFrame ), - m_xFrame ( rFrame ) + const uno::Reference< frame::XFrame >& rFrame ) + : InterimItemWindow(pParent, "modules/simpress/ui/pagesfieldbox.ui", "PagesFieldBox") + , m_xWidget(m_xBuilder->weld_spin_button("pagesfield")) + , m_xFrame(rFrame) { - OUString aStr( SdResId( STR_SLIDE_PLURAL ) ); - SetCustomUnitText( aStr ); - - // set size - aStr += "XXX"; - Size aSize( GetTextWidth( aStr )+20, GetTextHeight()+6 ); + // set parameter of MetricFields + m_xWidget->set_digits(0); + m_xWidget->set_range(1, 15); + m_xWidget->set_increments(1, 5); + m_xWidget->connect_value_changed(LINK(this, SdPagesField, ModifyHdl)); + m_xWidget->connect_output(LINK(this, SdPagesField, OutputHdl)); + m_xWidget->connect_input(LINK(this, SdPagesField, spin_button_input)); + m_xWidget->connect_key_press(LINK(this, SdPagesField, KeyInputHdl)); + + auto width = std::max(m_xWidget->get_pixel_size(format_number(1)).Width(), + m_xWidget->get_pixel_size(format_number(15)).Width()); + int chars = ceil(width / m_xWidget->get_approximate_digit_width()); + m_xWidget->set_width_chars(chars); + + SetSizePixel(m_xWidget->get_preferred_size()); +} - SetSizePixel( aSize ); +IMPL_LINK(SdPagesField, KeyInputHdl, const KeyEvent&, rKEvt, bool) +{ + return ChildKeyInput(rKEvt); +} - // set parameter of MetricFields - SetUnit( FieldUnit::CUSTOM ); - SetMin( 1 ); - SetFirst( 1 ); - SetMax( 15 ); - SetLast( 15 ); - SetSpinSize( 1 ); - SetDecimalDigits( 0 ); - Show(); +void SdPagesField::dispose() +{ + m_xWidget.reset(); + InterimItemWindow::dispose(); } SdPagesField::~SdPagesField() { + disposeOnce(); +} + +void SdPagesField::set_sensitive(bool bSensitive) +{ + Enable(bSensitive); + m_xWidget->set_sensitive(bSensitive); + if (!bSensitive) + m_xWidget->set_text(""); } void SdPagesField::UpdatePagesField( const SfxUInt16Item* pItem ) { - if( pItem ) + if (pItem) + m_xWidget->set_value(pItem->GetValue()); + else + m_xWidget->set_text(OUString()); +} + +IMPL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton&, rSpinButton, void) +{ + rSpinButton.set_text(format_number(rSpinButton.get_value())); +} + +IMPL_LINK(SdPagesField, spin_button_input, int*, result, bool) +{ + const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper(); + double fResult(0.0); + bool bRet = MetricFormatter::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE); + if (bRet) { - long nValue = static_cast<long>(pItem->GetValue()); - SetValue( nValue ); - if( nValue == 1 ) - SetCustomUnitText( SdResId( STR_SLIDE_SINGULAR ) ); - else - SetCustomUnitText( SdResId( STR_SLIDE_PLURAL ) ); + if (fResult > SAL_MAX_INT32) + fResult = SAL_MAX_INT32; + else if (fResult < SAL_MIN_INT32) + fResult = SAL_MIN_INT32; + *result = fResult; } - else - SetText( OUString() ); + return bRet; } -void SdPagesField::Modify() +IMPL_LINK_NOARG(SdPagesField, ModifyHdl, weld::SpinButton&, void) { - SfxUInt16Item aItem( SID_PAGES_PER_ROW, static_cast<sal_uInt16>(GetValue()) ); + SfxUInt16Item aItem(SID_PAGES_PER_ROW, m_xWidget->get_value()); ::uno::Any a; ::uno::Sequence< ::beans::PropertyValue > aArgs( 1 ); @@ -110,12 +152,11 @@ void SdTbxCtlDiaPages::StateChanged( sal_uInt16, if ( eState == SfxItemState::DISABLED ) { - pFld->Disable(); - pFld->SetText( OUString() ); + pFld->set_sensitive(false); } else { - pFld->Enable(); + pFld->set_sensitive(true); const SfxUInt16Item* pItem = nullptr; if ( eState == SfxItemState::DEFAULT ) @@ -130,7 +171,10 @@ void SdTbxCtlDiaPages::StateChanged( sal_uInt16, VclPtr<vcl::Window> SdTbxCtlDiaPages::CreateItemWindow( vcl::Window* pParent ) { - return VclPtrInstance<SdPagesField>( pParent, m_xFrame ).get(); + VclPtr<SdPagesField> pWindow = VclPtr<SdPagesField>::Create(pParent, m_xFrame); + pWindow->Show(); + + return pWindow; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/inc/diactrl.hxx b/sd/source/ui/inc/diactrl.hxx index 908731a80fb1..f9260ef4303a 100644 --- a/sd/source/ui/inc/diactrl.hxx +++ b/sd/source/ui/inc/diactrl.hxx @@ -20,7 +20,7 @@ #ifndef INCLUDED_SD_SOURCE_UI_INC_DIACTRL_HXX #define INCLUDED_SD_SOURCE_UI_INC_DIACTRL_HXX -#include <svx/itemwin.hxx> +#include <svx/InterimItemWindow.hxx> #include <sfx2/tbxctrl.hxx> namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } } @@ -28,17 +28,22 @@ class SfxUInt16Item; // SdPagesField: -class SdPagesField : public SvxMetricField +class SdPagesField final : public InterimItemWindow { private: - css::uno::Reference< css::frame::XFrame > m_xFrame; -protected: - virtual void Modify() override; + std::unique_ptr<weld::SpinButton> m_xWidget; + css::uno::Reference<css::frame::XFrame> m_xFrame; + + DECL_LINK(ModifyHdl, weld::SpinButton&, void); + DECL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton&, void); + DECL_LINK(spin_button_input, int* result, bool); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); public: - SdPagesField( vcl::Window* pParent, - const css::uno::Reference< css::frame::XFrame >& rFrame ); - virtual ~SdPagesField() override; + SdPagesField(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rFrame); + virtual void dispose() override; + void set_sensitive(bool bSensitive); + virtual ~SdPagesField() override; void UpdatePagesField( const SfxUInt16Item* pItem ); }; diff --git a/sd/uiconfig/simpress/ui/pagesfieldbox.ui b/sd/uiconfig/simpress/ui/pagesfieldbox.ui new file mode 100644 index 000000000000..59bf4457ec4b --- /dev/null +++ b/sd/uiconfig/simpress/ui/pagesfieldbox.ui @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface domain="svx"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkAdjustment" id="adjustment1"> + <property name="upper">100</property> + <property name="step_increment">1</property> + <property name="page_increment">10</property> + </object> + <object class="GtkBox" id="PagesFieldBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkSpinButton" id="pagesfield"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="adjustment">adjustment1</property> + <property name="digits">2</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> diff --git a/solenv/sanitizers/ui/modules/simpress.suppr b/solenv/sanitizers/ui/modules/simpress.suppr index 637da5821bce..6e3de94645c0 100644 --- a/solenv/sanitizers/ui/modules/simpress.suppr +++ b/solenv/sanitizers/ui/modules/simpress.suppr @@ -23,6 +23,7 @@ sd/uiconfig/simpress/ui/notebookbar_groups.ui://GtkLabel[@id='formatgrouplabel'] sd/uiconfig/simpress/ui/notebookbar_groups.ui://GtkLabel[@id='slidegrouplabel'] orphan-label sd/uiconfig/simpress/ui/notebookbar_groups.ui://GtkLabel[@id='insertgrouplabel'] orphan-label sd/uiconfig/simpress/ui/notebookbar_groups.ui://GtkLabel[@id='imagegrouplabel'] orphan-label +sd/uiconfig/simpress/ui/pagesfieldbox.ui://GtkSpinButton[@id='pagesfield'] no-labelled-by sd/uiconfig/simpress/ui/presentationdialog.ui://GtkLabel[@id='externalmonitor_str'] orphan-label sd/uiconfig/simpress/ui/presentationdialog.ui://GtkLabel[@id='monitor_str'] orphan-label sd/uiconfig/simpress/ui/presentationdialog.ui://GtkLabel[@id='allmonitors_str'] orphan-label diff --git a/solenv/sanitizers/ui/svx.suppr b/solenv/sanitizers/ui/svx.suppr index fec4f1c6f10f..0c4cd85cf614 100644 --- a/solenv/sanitizers/ui/svx.suppr +++ b/solenv/sanitizers/ui/svx.suppr @@ -54,6 +54,7 @@ svx/uiconfig/ui/mediawindow.ui://GtkEntry[@id='timeedit'] no-labelled-by svx/uiconfig/ui/mediawindow.ui://GtkLabel[@id='url'] orphan-label svx/uiconfig/ui/mediawindow.ui://GtkScale[@id='timeslider'] no-labelled-by svx/uiconfig/ui/mediawindow.ui://GtkScale[@id='volumeslider'] no-labelled-by +svx/uiconfig/ui/metricfieldbox.ui://GtkSpinButton[@id='metricfield'] no-labelled-by svx/uiconfig/ui/numberingwindow.ui://GtkButton[@id='more'] button-no-label svx/uiconfig/ui/oldcolorwindow.ui://GtkButton[@id='auto_color_button'] button-no-label svx/uiconfig/ui/oldcolorwindow.ui://GtkComboBox[@id='palette_listbox'] no-labelled-by diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk index 15f4bb7f7326..f3be7c4967ef 100644 --- a/svx/UIConfig_svx.mk +++ b/svx/UIConfig_svx.mk @@ -79,6 +79,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\ svx/uiconfig/ui/medialine \ svx/uiconfig/ui/mediaplayback \ svx/uiconfig/ui/mediawindow \ + svx/uiconfig/ui/metricfieldbox \ svx/uiconfig/ui/namespacedialog \ svx/uiconfig/ui/numberingwindow \ svx/uiconfig/ui/oldcolorwindow \ diff --git a/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx b/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx index af103d5d1f8a..b09f5addf8c6 100644 --- a/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx +++ b/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx @@ -21,8 +21,8 @@ #include <editeng/ulspitem.hxx> #include <vcl/EnumContext.hxx> +#include <svx/InterimItemWindow.hxx> #include <svx/relfld.hxx> -#include <InterimItemWindow.hxx> using namespace com::sun::star; diff --git a/svx/source/tbxctrls/itemwin.cxx b/svx/source/tbxctrls/itemwin.cxx index 0baf9407b01e..e0ac4cdbfb8d 100644 --- a/svx/source/tbxctrls/itemwin.cxx +++ b/svx/source/tbxctrls/itemwin.cxx @@ -58,41 +58,56 @@ using namespace ::com::sun::star::beans; SvxMetricField::SvxMetricField( vcl::Window* pParent, const Reference< XFrame >& rFrame ) - : MetricField(pParent, WB_BORDER | WB_SPIN | WB_REPEAT) - , aCurTxt() + : InterimItemWindow(pParent, "svx/ui/metricfieldbox.ui", "MetricFieldBox") + , m_xWidget(m_xBuilder->weld_metric_spin_button("metricfield", FieldUnit::MM)) + , nCurValue(0) , ePoolUnit(MapUnit::MapCM) + , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame)) , mxFrame(rFrame) { - Size aSize( CalcMinimumSize() ); - SetSizePixel( aSize ); - aLogicalSize = PixelToLogic(aSize, MapMode(MapUnit::MapAppFont)); - SetUnit( FieldUnit::MM ); - SetDecimalDigits( 2 ); - SetMax( 5000 ); - SetMin( 0 ); - SetLast( 5000 ); - SetFirst( 0 ); - - eDlgUnit = SfxModule::GetModuleFieldUnit( mxFrame ); - SetFieldUnit( *this, eDlgUnit ); - Show(); + m_xWidget->set_range(0, 5000, FieldUnit::NONE); + m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl)); + m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl)); + m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl)); + + SetFieldUnit(*m_xWidget, eDlgUnit); + + SetSizePixel(m_xWidget->get_preferred_size()); +} + +void SvxMetricField::dispose() +{ + m_xWidget.reset(); + InterimItemWindow::dispose(); +} + +SvxMetricField::~SvxMetricField() +{ + disposeOnce(); +} + +void SvxMetricField::set_sensitive(bool bSensitive) +{ + Enable(bSensitive); + m_xWidget->set_sensitive(bSensitive); + if (!bSensitive) + m_xWidget->set_text(""); } void SvxMetricField::Update( const XLineWidthItem* pItem ) { if ( pItem ) { - if ( pItem->GetValue() != GetCoreValue( *this, ePoolUnit ) ) - SetMetricValue( *this, pItem->GetValue(), ePoolUnit ); + if (pItem->GetValue() != GetCoreValue(*m_xWidget, ePoolUnit)) + SetMetricValue(*m_xWidget, pItem->GetValue(), ePoolUnit); } else - SetText( "" ); + m_xWidget->set_text(""); } -void SvxMetricField::Modify() +IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton&, void) { - MetricField::Modify(); - long nTmp = GetCoreValue( *this, ePoolUnit ); + auto nTmp = GetCoreValue(*m_xWidget, ePoolUnit); XLineWidthItem aLineWidthItem( nTmp ); Any a; @@ -126,59 +141,30 @@ void SvxMetricField::RefreshDlgUnit() if ( eDlgUnit != eTmpUnit ) { eDlgUnit = eTmpUnit; - SetFieldUnit( *this, eDlgUnit ); + SetFieldUnit(*m_xWidget, eDlgUnit); } } -bool SvxMetricField::PreNotify( NotifyEvent& rNEvt ) +IMPL_LINK_NOARG(SvxMetricField, FocusInHdl, weld::Widget&, void) { - MouseNotifyEvent nType = rNEvt.GetType(); - - if ( MouseNotifyEvent::MOUSEBUTTONDOWN == nType || MouseNotifyEvent::GETFOCUS == nType ) - aCurTxt = GetText(); - - return MetricField::PreNotify( rNEvt ); + nCurValue = m_xWidget->get_value(FieldUnit::NONE); } - -bool SvxMetricField::EventNotify( NotifyEvent& rNEvt ) +IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool) { - bool bHandled = MetricField::EventNotify( rNEvt ); + bool bHandled = false; - if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) - { - const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); - const vcl::KeyCode& rKey = pKEvt->GetKeyCode(); - SfxViewShell* pSh = SfxViewShell::Current(); - - if ( rKey.GetModifier() && rKey.GetGroup() != KEYGROUP_CURSOR && pSh ) - (void)pSh->KeyInput( *pKEvt ); - else - { - bool bHandledInside = false; - - switch ( rKey.GetCode() ) - { - case KEY_RETURN: - Reformat(); - bHandledInside = true; - break; - - case KEY_ESCAPE: - SetText( aCurTxt ); - bHandled = true; - break; - } + sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); - if ( bHandledInside ) - { - bHandled = true; - Modify(); - ReleaseFocus_Impl(); - } - } + if (nCode == KEY_ESCAPE) + { + m_xWidget->set_value(nCurValue, FieldUnit::NONE); + ModifyHdl(*m_xWidget); + ReleaseFocus_Impl(); + bHandled = true; } - return bHandled; + + return bHandled || ChildKeyInput(rKEvt); } void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt ) @@ -186,10 +172,10 @@ void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt ) if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) { - SetSizePixel(LogicToPixel(aLogicalSize, MapMode(MapUnit::MapAppFont))); + SetSizePixel(m_xWidget->get_preferred_size()); } - MetricField::DataChanged( rDCEvt ); + InterimItemWindow::DataChanged( rDCEvt ); } SvxFillTypeBox::SvxFillTypeBox( vcl::Window* pParent ) : diff --git a/svx/source/tbxctrls/linewidthctrl.cxx b/svx/source/tbxctrls/linewidthctrl.cxx index 0a6d75446819..61f48a0293e5 100644 --- a/svx/source/tbxctrls/linewidthctrl.cxx +++ b/svx/source/tbxctrls/linewidthctrl.cxx @@ -83,12 +83,11 @@ void SvxLineWidthToolBoxControl::StateChanged( { if ( eState == SfxItemState::DISABLED ) { - pFld->Disable(); - pFld->SetText( "" ); + pFld->set_sensitive(false); } else { - pFld->Enable(); + pFld->set_sensitive(true); if ( eState == SfxItemState::DEFAULT ) { @@ -107,10 +106,12 @@ void SvxLineWidthToolBoxControl::StateChanged( } } - -VclPtr<vcl::Window> SvxLineWidthToolBoxControl::CreateItemWindow( vcl::Window *pParent ) +VclPtr<vcl::Window> SvxLineWidthToolBoxControl::CreateItemWindow(vcl::Window *pParent) { - return VclPtr<SvxMetricField>::Create( pParent, m_xFrame ).get(); + VclPtr<SvxMetricField> pWindow = VclPtr<SvxMetricField>::Create(pParent, m_xFrame); + pWindow->Show(); + + return pWindow; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/tbxctrls/tbunocontroller.cxx b/svx/source/tbxctrls/tbunocontroller.cxx index 125543a55e88..fda45184209f 100644 --- a/svx/source/tbxctrls/tbunocontroller.cxx +++ b/svx/source/tbxctrls/tbunocontroller.cxx @@ -41,7 +41,7 @@ #include <sfx2/sidebar/SidebarToolBox.hxx> #include <boost/property_tree/ptree.hpp> -#include <InterimItemWindow.hxx> +#include <svx/InterimItemWindow.hxx> using namespace ::com::sun::star; diff --git a/svx/uiconfig/ui/metricfieldbox.ui b/svx/uiconfig/ui/metricfieldbox.ui new file mode 100644 index 000000000000..1eda510a2304 --- /dev/null +++ b/svx/uiconfig/ui/metricfieldbox.ui @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> +<interface domain="svx"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkAdjustment" id="adjustment1"> + <property name="upper">100</property> + <property name="step_increment">1</property> + <property name="page_increment">10</property> + </object> + <object class="GtkBox" id="MetricFieldBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkSpinButton" id="metricfield"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="adjustment">adjustment1</property> + <property name="digits">2</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> |