summaryrefslogtreecommitdiff
path: root/include/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-07-03 12:08:02 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-07-05 16:44:09 +0200
commit95cfa85395f983df3ba044192b29ce0bbc5e6085 (patch)
tree24388695e580fab69539bc4d9304e8a5535ef6bf /include/vcl
parent7b6549811a929e004266a6ead26b69d499c73e0c (diff)
adjust FormattedSpinButton to be driven by an EntryFormatter
so we can have the same backend driving the FormattedSpinButtons as a FormattedEntry Change-Id: I07a472315a04787eb5fcf992cde8f758af742156 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97860 Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/vcl')
-rw-r--r--include/vcl/fmtfield.hxx1
-rw-r--r--include/vcl/formatter.hxx12
-rw-r--r--include/vcl/weld.hxx46
-rw-r--r--include/vcl/weldutils.hxx23
4 files changed, 43 insertions, 39 deletions
diff --git a/include/vcl/fmtfield.hxx b/include/vcl/fmtfield.hxx
index 26715e687218..1d92a1b957b4 100644
--- a/include/vcl/fmtfield.hxx
+++ b/include/vcl/fmtfield.hxx
@@ -48,6 +48,7 @@ public:
virtual FactoryFunction GetUITestFactory() const override;
Formatter* GetFormatter();
+ void SetFormatter(Formatter* pFormatter);
protected:
std::unique_ptr<Formatter> m_xFormatter;
diff --git a/include/vcl/formatter.hxx b/include/vcl/formatter.hxx
index f54d59ca4600..4f9a016cc6da 100644
--- a/include/vcl/formatter.hxx
+++ b/include/vcl/formatter.hxx
@@ -156,13 +156,13 @@ public:
// Min-/Max-management
bool HasMinValue() const { return m_bHasMin; }
- void ClearMinValue() { m_bHasMin = false; }
- void SetMinValue(double dMin);
+ virtual void ClearMinValue() { m_bHasMin = false; }
+ virtual void SetMinValue(double dMin);
double GetMinValue() const { return m_dMinValue; }
bool HasMaxValue() const { return m_bHasMax; }
- void ClearMaxValue() { m_bHasMax = false; }
- void SetMaxValue(double dMax);
+ virtual void ClearMaxValue() { m_bHasMax = false; }
+ virtual void SetMaxValue(double dMax);
double GetMaxValue() const { return m_dMaxValue; }
// Current value
@@ -219,7 +219,7 @@ public:
void SetStrictFormat(bool bEnable) { m_bStrictFormat = bEnable; }
// Check format during input
- void SetSpinSize(double dStep) { m_dSpinSize = dStep; }
+ virtual void SetSpinSize(double dStep) { m_dSpinSize = dStep; }
double GetSpinSize() const { return m_dSpinSize; }
void SetSpinFirst(double dFirst) { m_dSpinFirst = dFirst; }
@@ -304,6 +304,8 @@ protected:
SvNumberFormatter* CreateFormatter() { SetFormatter(StandardFormatter()); return m_pFormatter; }
+ virtual void UpdateCurrentValue(double dCurrentValue) { m_dCurrentValue = dCurrentValue; }
+
void ReFormat();
};
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index ee110a049888..88dbcf0dad5f 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -62,6 +62,7 @@ typedef css::uno::Reference<css::accessibility::XAccessibleRelationSet> a11yrela
enum class PointerStyle;
class CommandEvent;
class KeyEvent;
+class Formatter;
class MouseEvent;
class SvNumberFormatter;
class TransferDataContainer;
@@ -1506,7 +1507,7 @@ public:
*/
virtual void set_font_color(const Color& rColor) = 0;
- void connect_changed(const Link<Entry&, void>& rLink) { m_aChangeHdl = rLink; }
+ virtual void connect_changed(const Link<Entry&, void>& rLink) { m_aChangeHdl = rLink; }
void connect_insert_text(const Link<OUString&, bool>& rLink) { m_aInsertTextHdl = rLink; }
// callback returns true to indicated no further processing of activate wanted
void connect_activate(const Link<Entry&, bool>& rLink) { m_aActivateHdl = rLink; }
@@ -1596,52 +1597,31 @@ public:
static unsigned int Power10(unsigned int n);
};
+class EntryFormatter;
+
+// Similar to a SpinButton, but input and output formatting and range/value
+// are managed by a more complex Formatter which can support doubles.
class VCL_DLLPUBLIC FormattedSpinButton : virtual public Entry
{
protected:
Link<FormattedSpinButton&, void> m_aValueChangedHdl;
- Link<FormattedSpinButton&, void> m_aOutputHdl;
- Link<double*, bool> m_aInputHdl;
void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
public:
- virtual void set_value(double value) = 0;
- virtual double get_value() const = 0;
- virtual void set_range(double min, double max) = 0;
- virtual void get_range(double& min, double& max) const = 0;
- virtual void set_increments(double step, double page) = 0;
-
- void set_min(double min)
- {
- double max, dummy;
- get_range(dummy, max);
- set_range(min, max);
- }
-
- void set_max(double max)
- {
- double min, dummy;
- get_range(min, dummy);
- set_range(min, max);
- }
-
- virtual void set_formatter(SvNumberFormatter* pFormatter) = 0;
- virtual SvNumberFormatter* get_formatter() = 0;
- virtual sal_Int32 get_format_key() const = 0;
- virtual void set_format_key(sal_Int32 nFormatKey) = 0;
-
- virtual void set_digits(unsigned int digits) = 0;
-
- virtual void treat_as_number(bool bSet) = 0;
+ virtual Formatter& GetFormatter() = 0;
+ virtual void SetFormatter(weld::EntryFormatter* pFormatter) = 0;
void connect_value_changed(const Link<FormattedSpinButton&, void>& rLink)
{
m_aValueChangedHdl = rLink;
}
- void connect_output(const Link<FormattedSpinButton&, void>& rLink) { m_aOutputHdl = rLink; }
- void connect_input(const Link<double*, bool>& rLink) { m_aInputHdl = rLink; }
+private:
+ friend class EntryFormatter;
+ virtual void sync_range_from_formatter() = 0;
+ virtual void sync_value_from_formatter() = 0;
+ virtual void sync_increments_from_formatter() = 0;
};
class VCL_DLLPUBLIC Image : virtual public Widget
diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx
index 299d3ee3135b..757303fdcabf 100644
--- a/include/vcl/weldutils.hxx
+++ b/include/vcl/weldutils.hxx
@@ -158,12 +158,17 @@ class VCL_DLLPUBLIC EntryFormatter : public Formatter
{
public:
EntryFormatter(weld::Entry& rEntry);
+ EntryFormatter(weld::FormattedSpinButton& rSpinButton);
+ // EntryFormatter will set listeners to "changed" and "focus-out" of the
+ // entry so users that want to add their own listeners to those must set
+ // them through this formatter and not directly on the entry
void connect_changed(const Link<weld::Entry&, void>& rLink) { m_aModifyHdl = rLink; }
+ void connect_focus_out(const Link<weld::Widget&, void>& rLink) { m_aFocusOutHdl = rLink; }
weld::Entry& get_widget() { return m_rEntry; }
- // Formatter overrides
+ // public Formatter overrides, drives interactions with the Entry
virtual Selection GetEntrySelection() const override;
virtual OUString GetEntryText() const override;
virtual void SetEntryText(const OUString& rText, const Selection& rSel) override;
@@ -171,14 +176,30 @@ public:
virtual SelectionOptions GetEntrySelectionOptions() const override;
virtual void FieldModified() override;
+ // public Formatter overrides, drives optional SpinButton settings
+ virtual void ClearMinValue() override;
+ virtual void SetMinValue(double dMin) override;
+ virtual void ClearMaxValue() override;
+ virtual void SetMaxValue(double dMin) override;
+
+ virtual void SetSpinSize(double dStep) override;
+
void SetEntrySelectionOptions(SelectionOptions eOptions) { m_eOptions = eOptions; }
+ virtual ~EntryFormatter() override;
+
private:
weld::Entry& m_rEntry;
+ weld::FormattedSpinButton* m_pSpinButton;
Link<weld::Entry&, void> m_aModifyHdl;
+ Link<weld::Widget&, void> m_aFocusOutHdl;
SelectionOptions m_eOptions;
DECL_DLLPRIVATE_LINK(ModifyHdl, weld::Entry&, void);
DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
+ void Init();
+
+ // private Formatter overrides
+ virtual void UpdateCurrentValue(double dCurrentValue) override;
};
// get the row the iterator is on