summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-02-06 10:59:19 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-02-06 18:17:02 +0100
commit97a5da96159f28de0b846de7dd94d2880251e8b3 (patch)
tree091f4334ff184047376240a4deb5bfb9b0da5b1e /sd
parentbf2f1adfd2e4725518147657c6b57eb5697a29d5 (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>
Diffstat (limited to 'sd')
-rw-r--r--sd/UIConfig_simpress.mk1
-rw-r--r--sd/inc/sdresid.hxx1
-rw-r--r--sd/inc/strings.hrc7
-rw-r--r--sd/source/ui/app/sdmod.cxx5
-rw-r--r--sd/source/ui/dlg/diactrl.cxx112
-rw-r--r--sd/source/ui/inc/diactrl.hxx21
-rw-r--r--sd/uiconfig/simpress/ui/pagesfieldbox.ui30
7 files changed, 133 insertions, 44 deletions
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>