Kaydet (Commit) 39aa91cf authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: tdf#121341 weld TrendlineTabPage

Change-Id: I8ecc1901388986bd6a3822e8d0055e48d873586c
Reviewed-on: https://gerrit.libreoffice.org/63387
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 21c41659
...@@ -19,12 +19,9 @@ ...@@ -19,12 +19,9 @@
#ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_RES_TRENDLINE_HXX #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_RES_TRENDLINE_HXX
#define INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_RES_TRENDLINE_HXX #define INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_RES_TRENDLINE_HXX
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <svl/itemset.hxx> #include <svl/itemset.hxx>
#include <svx/chrtitem.hxx> #include <svx/chrtitem.hxx>
#include <vcl/field.hxx> #include <vcl/weld.hxx>
#include <vcl/fmtfield.hxx>
class SvNumberFormatter; class SvNumberFormatter;
...@@ -34,7 +31,7 @@ namespace chart ...@@ -34,7 +31,7 @@ namespace chart
class TrendlineResources final class TrendlineResources final
{ {
public: public:
TrendlineResources( vcl::Window* pParent, const SfxItemSet& rInAttrs ); TrendlineResources(weld::Builder& rParent, const SfxItemSet& rInAttrs);
~TrendlineResources(); ~TrendlineResources();
void Reset(const SfxItemSet& rInAttrs); void Reset(const SfxItemSet& rInAttrs);
...@@ -46,32 +43,6 @@ public: ...@@ -46,32 +43,6 @@ public:
void SetNbPoints( sal_Int32 nNbPoints ); void SetNbPoints( sal_Int32 nNbPoints );
private: private:
VclPtr<RadioButton> m_pRB_Linear;
VclPtr<RadioButton> m_pRB_Logarithmic;
VclPtr<RadioButton> m_pRB_Exponential;
VclPtr<RadioButton> m_pRB_Power;
VclPtr<RadioButton> m_pRB_Polynomial;
VclPtr<RadioButton> m_pRB_MovingAverage;
VclPtr<FixedImage> m_pFI_Linear;
VclPtr<FixedImage> m_pFI_Logarithmic;
VclPtr<FixedImage> m_pFI_Exponential;
VclPtr<FixedImage> m_pFI_Power;
VclPtr<FixedImage> m_pFI_Polynomial;
VclPtr<FixedImage> m_pFI_MovingAverage;
VclPtr<NumericField> m_pNF_Degree;
VclPtr<NumericField> m_pNF_Period;
VclPtr<Edit> m_pEE_Name;
VclPtr<FormattedField> m_pFmtFld_ExtrapolateForward;
VclPtr<FormattedField> m_pFmtFld_ExtrapolateBackward;
VclPtr<CheckBox> m_pCB_SetIntercept;
VclPtr<FormattedField> m_pFmtFld_InterceptValue;
VclPtr<CheckBox> m_pCB_ShowEquation;
VclPtr<Edit> m_pEE_XName;
VclPtr<Edit> m_pEE_YName;
VclPtr<CheckBox> m_pCB_ShowCorrelationCoeff;
SvxChartRegress m_eTrendLineType; SvxChartRegress m_eTrendLineType;
bool m_bTrendLineUnique; bool m_bTrendLineUnique;
...@@ -79,10 +50,37 @@ private: ...@@ -79,10 +50,37 @@ private:
SvNumberFormatter* m_pNumFormatter; SvNumberFormatter* m_pNumFormatter;
sal_Int32 m_nNbPoints; sal_Int32 m_nNbPoints;
std::unique_ptr<weld::RadioButton> m_xRB_Linear;
std::unique_ptr<weld::RadioButton> m_xRB_Logarithmic;
std::unique_ptr<weld::RadioButton> m_xRB_Exponential;
std::unique_ptr<weld::RadioButton> m_xRB_Power;
std::unique_ptr<weld::RadioButton> m_xRB_Polynomial;
std::unique_ptr<weld::RadioButton> m_xRB_MovingAverage;
std::unique_ptr<weld::Image> m_xFI_Linear;
std::unique_ptr<weld::Image> m_xFI_Logarithmic;
std::unique_ptr<weld::Image> m_xFI_Exponential;
std::unique_ptr<weld::Image> m_xFI_Power;
std::unique_ptr<weld::Image> m_xFI_Polynomial;
std::unique_ptr<weld::Image> m_xFI_MovingAverage;
std::unique_ptr<weld::SpinButton> m_xNF_Degree;
std::unique_ptr<weld::SpinButton> m_xNF_Period;
std::unique_ptr<weld::Entry> m_xEE_Name;
std::unique_ptr<weld::FormattedSpinButton> m_xFmtFld_ExtrapolateForward;
std::unique_ptr<weld::FormattedSpinButton> m_xFmtFld_ExtrapolateBackward;
std::unique_ptr<weld::CheckButton> m_xCB_SetIntercept;
std::unique_ptr<weld::FormattedSpinButton> m_xFmtFld_InterceptValue;
std::unique_ptr<weld::CheckButton> m_xCB_ShowEquation;
std::unique_ptr<weld::Entry> m_xEE_XName;
std::unique_ptr<weld::Entry> m_xEE_YName;
std::unique_ptr<weld::CheckButton> m_xCB_ShowCorrelationCoeff;
void UpdateControlStates(); void UpdateControlStates();
DECL_LINK( SelectTrendLine, Button*, void ); DECL_LINK(SelectTrendLine, weld::ToggleButton&, void);
DECL_LINK( ChangeValue, Edit&, void); DECL_LINK(ChangeSpinValue, weld::SpinButton&, void);
DECL_LINK( ShowEquation, CheckBox&, void); DECL_LINK(ChangeFormattedValue, weld::FormattedSpinButton&, void);
DECL_LINK(ShowEquation, weld::ToggleButton&, void);
}; };
} // namespace chart } // namespace chart
......
...@@ -24,16 +24,15 @@ ...@@ -24,16 +24,15 @@
namespace chart namespace chart
{ {
TrendlineTabPage::TrendlineTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ) : TrendlineTabPage::TrendlineTabPage(TabPageParent pParent, const SfxItemSet& rInAttrs)
SfxTabPage( pParent, "TP_TRENDLINE", "modules/schart/ui/tp_Trendline.ui", &rInAttrs ), : SfxTabPage(pParent, "modules/schart/ui/tp_Trendline.ui", "TP_TRENDLINE", &rInAttrs)
m_aTrendlineResources( this, rInAttrs ) , m_aTrendlineResources(*m_xBuilder, rInAttrs)
{ {
} }
VclPtr<SfxTabPage> TrendlineTabPage::Create( VclPtr<SfxTabPage> TrendlineTabPage::Create(TabPageParent pParent, const SfxItemSet* rOutAttrs)
TabPageParent pParent, const SfxItemSet* rOutAttrs )
{ {
return VclPtr<TrendlineTabPage>::Create( pParent.pParent, *rOutAttrs ); return VclPtr<TrendlineTabPage>::Create(pParent, *rOutAttrs);
} }
bool TrendlineTabPage::FillItemSet( SfxItemSet* rOutAttrs ) bool TrendlineTabPage::FillItemSet( SfxItemSet* rOutAttrs )
......
...@@ -29,7 +29,7 @@ namespace chart ...@@ -29,7 +29,7 @@ namespace chart
class TrendlineTabPage : public SfxTabPage class TrendlineTabPage : public SfxTabPage
{ {
public: public:
TrendlineTabPage ( vcl::Window* pParent, const SfxItemSet& rInAttrs ); TrendlineTabPage(TabPageParent pParent, const SfxItemSet& rInAttrs);
static VclPtr<SfxTabPage> Create( TabPageParent pParent, const SfxItemSet* rInAttrs ); static VclPtr<SfxTabPage> Create( TabPageParent pParent, const SfxItemSet* rInAttrs );
virtual bool FillItemSet( SfxItemSet* rOutAttrs ) override; virtual bool FillItemSet( SfxItemSet* rOutAttrs ) override;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
typedef css::uno::Reference<css::accessibility::XAccessible> a11yref; typedef css::uno::Reference<css::accessibility::XAccessible> a11yref;
typedef css::uno::Reference<css::accessibility::XAccessibleRelationSet> a11yrelationset; typedef css::uno::Reference<css::accessibility::XAccessibleRelationSet> a11yrelationset;
class SvNumberFormatter;
namespace vcl namespace vcl
{ {
class ILibreOfficeKitNotifier; class ILibreOfficeKitNotifier;
...@@ -692,6 +694,34 @@ public: ...@@ -692,6 +694,34 @@ public:
static unsigned int Power10(unsigned int n); static unsigned int Power10(unsigned int n);
}; };
class VCL_DLLPUBLIC FormattedSpinButton : virtual public Entry
{
protected:
Link<FormattedSpinButton&, void> m_aValueChangedHdl;
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;
void set_max(double max)
{
double min, dummy;
get_range(min, dummy);
set_range(min, max);
}
virtual void set_formatter(SvNumberFormatter* pFormatter) = 0;
void connect_value_changed(const Link<FormattedSpinButton&, void>& rLink)
{
m_aValueChangedHdl = rLink;
}
};
class VCL_DLLPUBLIC Image : virtual public Widget class VCL_DLLPUBLIC Image : virtual public Widget
{ {
public: public:
...@@ -1200,6 +1230,8 @@ public: ...@@ -1200,6 +1230,8 @@ public:
= 0; = 0;
virtual std::unique_ptr<MetricSpinButton> virtual std::unique_ptr<MetricSpinButton>
weld_metric_spin_button(const OString& id, FieldUnit eUnit, bool bTakeOwnership = false) = 0; weld_metric_spin_button(const OString& id, FieldUnit eUnit, bool bTakeOwnership = false) = 0;
virtual std::unique_ptr<FormattedSpinButton>
weld_formatted_spin_button(const OString& id, bool bTakeOwnership = false) = 0;
virtual std::unique_ptr<TimeSpinButton> virtual std::unique_ptr<TimeSpinButton>
weld_time_spin_button(const OString& id, TimeFieldFormat eFormat, bool bTakeOwnership = false) weld_time_spin_button(const OString& id, TimeFieldFormat eFormat, bool bTakeOwnership = false)
= 0; = 0;
......
...@@ -58,6 +58,7 @@ $(eval $(call gb_Library_add_libs,vclplug_gtk3,\ ...@@ -58,6 +58,7 @@ $(eval $(call gb_Library_add_libs,vclplug_gtk3,\
$(eval $(call gb_Library_use_libraries,vclplug_gtk3,\ $(eval $(call gb_Library_use_libraries,vclplug_gtk3,\
vcl \ vcl \
svl \
tl \ tl \
utl \ utl \
sot \ sot \
......
...@@ -2083,6 +2083,46 @@ IMPL_LINK(SalInstanceSpinButton, InputHdl, sal_Int64*, pResult, TriState) ...@@ -2083,6 +2083,46 @@ IMPL_LINK(SalInstanceSpinButton, InputHdl, sal_Int64*, pResult, TriState)
return eRet; return eRet;
} }
class SalInstanceFormattedSpinButton : public SalInstanceEntry, public virtual weld::FormattedSpinButton
{
private:
VclPtr<FormattedField> m_xButton;
public:
SalInstanceFormattedSpinButton(FormattedField* pButton, bool bTakeOwnership)
: SalInstanceEntry(pButton, bTakeOwnership)
, m_xButton(pButton)
{
}
virtual double get_value() const override
{
return m_xButton->GetValue();
}
virtual void set_value(double value) override
{
m_xButton->SetValue(value);
}
virtual void set_range(double min, double max) override
{
m_xButton->SetMinValue(min);
m_xButton->SetMaxValue(max);
}
virtual void get_range(double& min, double& max) const override
{
min = m_xButton->GetMinValue();
max = m_xButton->GetMaxValue();
}
virtual void set_formatter(SvNumberFormatter* pFormatter) override
{
m_xButton->SetFormatter(pFormatter);
}
};
class SalInstanceLabel : public SalInstanceWidget, public virtual weld::Label class SalInstanceLabel : public SalInstanceWidget, public virtual weld::Label
{ {
private: private:
...@@ -2940,6 +2980,13 @@ public: ...@@ -2940,6 +2980,13 @@ public:
return o3tl::make_unique<weld::MetricSpinButton>(std::move(xButton), eUnit); return o3tl::make_unique<weld::MetricSpinButton>(std::move(xButton), eUnit);
} }
virtual std::unique_ptr<weld::FormattedSpinButton> weld_formatted_spin_button(const OString& id,
bool bTakeOwnership) override
{
FormattedField* pSpinButton = m_xBuilder->get<FormattedField>(id);
return pSpinButton ? o3tl::make_unique<SalInstanceFormattedSpinButton>(pSpinButton, bTakeOwnership) : nullptr;
}
virtual std::unique_ptr<weld::TimeSpinButton> weld_time_spin_button(const OString& id, TimeFieldFormat eFormat, virtual std::unique_ptr<weld::TimeSpinButton> weld_time_spin_button(const OString& id, TimeFieldFormat eFormat,
bool bTakeOwnership) override bool bTakeOwnership) override
{ {
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <rtl/bootstrap.hxx> #include <rtl/bootstrap.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
#include <tools/fract.hxx> #include <tools/fract.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <unotools/resmgr.hxx> #include <unotools/resmgr.hxx>
...@@ -4401,18 +4403,18 @@ private: ...@@ -4401,18 +4403,18 @@ private:
return pThis->signal_output(); return pThis->signal_output();
} }
static gboolean signalInput(GtkSpinButton*, gdouble* new_value, gpointer widget) static gint signalInput(GtkSpinButton*, gdouble* new_value, gpointer widget)
{ {
GtkInstanceSpinButton* pThis = static_cast<GtkInstanceSpinButton*>(widget); GtkInstanceSpinButton* pThis = static_cast<GtkInstanceSpinButton*>(widget);
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
int result; int result;
TriState eHandled = pThis->signal_input(&result); TriState eHandled = pThis->signal_input(&result);
if (eHandled == TRISTATE_INDET) if (eHandled == TRISTATE_INDET)
return false; return 0;
if (eHandled == TRISTATE_TRUE) if (eHandled == TRISTATE_TRUE)
{ {
*new_value = pThis->toGtk(result); *new_value = pThis->toGtk(result);
return true; return 1;
} }
return GTK_INPUT_ERROR; return GTK_INPUT_ERROR;
} }
...@@ -4511,6 +4513,159 @@ public: ...@@ -4511,6 +4513,159 @@ public:
} }
}; };
class GtkInstanceFormattedSpinButton : public GtkInstanceEntry, public virtual weld::FormattedSpinButton
{
private:
GtkSpinButton* m_pButton;
SvNumberFormatter* m_pFormatter;
Color* m_pLastOutputColor;
sal_uInt32 m_nFormatKey;
gulong m_nValueChangedSignalId;
gulong m_nOutputSignalId;
gulong m_nInputSignalId;
bool signal_output()
{
if (!m_pFormatter)
return false;
double dVal = get_value();
OUString sNewText;
if (m_pFormatter->IsTextFormat(m_nFormatKey))
{
// first convert the number as string in standard format
OUString sTemp;
m_pFormatter->GetOutputString(dVal, 0, sTemp, &m_pLastOutputColor);
// then encode the string in the corresponding text format
m_pFormatter->GetOutputString(sTemp, m_nFormatKey, sNewText, &m_pLastOutputColor);
}
else
{
m_pFormatter->GetOutputString(dVal, m_nFormatKey, sNewText, &m_pLastOutputColor);
}
set_text(sNewText);
return true;
}
static gboolean signalOutput(GtkSpinButton*, gpointer widget)
{
GtkInstanceFormattedSpinButton* pThis = static_cast<GtkInstanceFormattedSpinButton*>(widget);
SolarMutexGuard aGuard;
return pThis->signal_output();
}
gint signal_input(double* value)
{
if (!m_pFormatter)
return 0;
sal_uInt32 nFormatKey = m_nFormatKey; // IsNumberFormat changes the FormatKey!
if (m_pFormatter->IsTextFormat(nFormatKey))
// for detection of values like "1,1" in fields that are formatted as text
nFormatKey = 0;
OUString sText(get_text());
// special treatment for percentage formatting
if (m_pFormatter->GetType(m_nFormatKey) == SvNumFormatType::PERCENT)
{
// the language of our format
LanguageType eLanguage = m_pFormatter->GetEntry(m_nFormatKey)->GetLanguage();
// the default number format for this language
sal_uLong nStandardNumericFormat = m_pFormatter->GetStandardFormat(SvNumFormatType::NUMBER, eLanguage);
sal_uInt32 nTempFormat = nStandardNumericFormat;
double dTemp;
if (m_pFormatter->IsNumberFormat(sText, nTempFormat, dTemp) &&
SvNumFormatType::NUMBER == m_pFormatter->GetType(nTempFormat))
// the string is equivalent to a number formatted one (has no % sign) -> append it
sText += "%";
// (with this, a input of '3' becomes '3%', which then by the formatter is translated
// into 0.03. Without this, the formatter would give us the double 3 for an input '3',
// which equals 300 percent.
}
if (!m_pFormatter->IsNumberFormat(sText, nFormatKey, *value))
return GTK_INPUT_ERROR;
return 1;
}
static gint signalInput(GtkSpinButton*, gdouble* new_value, gpointer widget)
{
GtkInstanceFormattedSpinButton* pThis = static_cast<GtkInstanceFormattedSpinButton*>(widget);
SolarMutexGuard aGuard;
return pThis->signal_input(new_value);
}
static void signalValueChanged(GtkSpinButton*, gpointer widget)
{
GtkInstanceFormattedSpinButton* pThis = static_cast<GtkInstanceFormattedSpinButton*>(widget);
SolarMutexGuard aGuard;
pThis->signal_value_changed();
}
public:
GtkInstanceFormattedSpinButton(GtkSpinButton* pButton, bool bTakeOwnership)
: GtkInstanceEntry(GTK_ENTRY(pButton), bTakeOwnership)
, m_pButton(pButton)
, m_pFormatter(nullptr)
, m_pLastOutputColor(nullptr)
, m_nFormatKey(0)
, m_nValueChangedSignalId(g_signal_connect(pButton, "value-changed", G_CALLBACK(signalValueChanged), this))
, m_nOutputSignalId(g_signal_connect(pButton, "output", G_CALLBACK(signalOutput), this))
, m_nInputSignalId(g_signal_connect(pButton, "input", G_CALLBACK(signalInput), this))
{
}
virtual double get_value() const override
{
return gtk_spin_button_get_value(m_pButton);
}
virtual void set_value(double value) override
{
disable_notify_events();
gtk_spin_button_set_value(m_pButton, value);
enable_notify_events();
}
virtual void set_range(double min, double max) override
{
disable_notify_events();
gtk_spin_button_set_range(m_pButton, min, max);
enable_notify_events();
}
virtual void get_range(double& min, double& max) const override
{
gtk_spin_button_get_range(m_pButton, &min, &max);
}
virtual void set_formatter(SvNumberFormatter* pFormatter) override
{
m_pFormatter = pFormatter;
// calc the default format key from the Office's UI locale
if (m_pFormatter)
{
// get the Office's locale and translate
LanguageType eSysLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType( false);
// get the standard numeric format for this language
m_nFormatKey = m_pFormatter->GetStandardFormat( SvNumFormatType::NUMBER, eSysLanguage );
}
else
m_nFormatKey = 0;
signal_output();
}
virtual ~GtkInstanceFormattedSpinButton() override
{
g_signal_handler_disconnect(m_pButton, m_nInputSignalId);
g_signal_handler_disconnect(m_pButton, m_nOutputSignalId);
g_signal_handler_disconnect(m_pButton, m_nValueChangedSignalId);
}
};
class GtkInstanceLabel : public GtkInstanceWidget, public virtual weld::Label class GtkInstanceLabel : public GtkInstanceWidget, public virtual weld::Label
{ {
private: private:
...@@ -6224,6 +6379,15 @@ public: ...@@ -6224,6 +6379,15 @@ public:
return o3tl::make_unique<weld::MetricSpinButton>(weld_spin_button(id, bTakeOwnership), eUnit); return o3tl::make_unique<weld::MetricSpinButton>(weld_spin_button(id, bTakeOwnership), eUnit);
} }
virtual std::unique_ptr<weld::FormattedSpinButton> weld_formatted_spin_button(const OString &id, bool bTakeOwnership) override
{
GtkSpinButton* pSpinButton = GTK_SPIN_BUTTON(gtk_builder_get_object(m_pBuilder, id.getStr()));
if (!pSpinButton)
return nullptr;
auto_add_parentless_widgets_to_container(GTK_WIDGET(pSpinButton));
return o3tl::make_unique<GtkInstanceFormattedSpinButton>(pSpinButton, bTakeOwnership);
}
virtual std::unique_ptr<weld::TimeSpinButton> weld_time_spin_button(const OString& id, TimeFieldFormat eFormat, virtual std::unique_ptr<weld::TimeSpinButton> weld_time_spin_button(const OString& id, TimeFieldFormat eFormat,
bool bTakeOwnership) override bool bTakeOwnership) override
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment