diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-30 10:03:30 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-09-28 08:48:42 +0100 |
commit | eb0a623d058a7d9d09c3b663a425930e1531be56 (patch) | |
tree | 3bb835b5c4555df269dc6eaf23b456884afb0ecc /vcl | |
parent | 6ab899e7cc8dee550fbbeeb009bd1524eb9df2d1 (diff) |
Get optimal size of spinbuttons from min/max values, not current val
Change-Id: I2af72a1d88d2d411924110c6ead03bc8ed8b5dde
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/edit.hxx | 1 | ||||
-rw-r--r-- | vcl/inc/vcl/field.hxx | 12 | ||||
-rw-r--r-- | vcl/inc/vcl/spinfld.hxx | 1 | ||||
-rw-r--r-- | vcl/source/control/edit.cxx | 11 | ||||
-rw-r--r-- | vcl/source/control/field.cxx | 34 | ||||
-rw-r--r-- | vcl/source/control/spinfld.cxx | 12 |
6 files changed, 58 insertions, 13 deletions
diff --git a/vcl/inc/vcl/edit.hxx b/vcl/inc/vcl/edit.hxx index a382bc83f82b..947aeca5de13 100644 --- a/vcl/inc/vcl/edit.hxx +++ b/vcl/inc/vcl/edit.hxx @@ -230,6 +230,7 @@ public: AutocompleteAction GetAutocompleteAction() const { return meAutocompleteAction; } virtual Size CalcMinimumSize() const; + virtual Size CalcMinimumSizeForText(const rtl::OUString &rString) const; virtual Size GetOptimalSize(WindowSizeType eType) const; virtual Size CalcSize( sal_uInt16 nChars ) const; virtual xub_StrLen GetMaxVisChars() const; diff --git a/vcl/inc/vcl/field.hxx b/vcl/inc/vcl/field.hxx index 1461046742d8..fc418df89e12 100644 --- a/vcl/inc/vcl/field.hxx +++ b/vcl/inc/vcl/field.hxx @@ -171,8 +171,6 @@ protected: protected: NumericFormatter(); - virtual XubString CreateFieldText( sal_Int64 nValue ) const; - void FieldUp(); void FieldDown(); void FieldFirst(); @@ -213,6 +211,7 @@ public: void SetUserValue( sal_Int64 nNewValue ); virtual void SetValue( sal_Int64 nNewValue ); virtual sal_Int64 GetValue() const; + virtual XubString CreateFieldText( sal_Int64 nValue ) const; sal_Bool IsValueModified() const; sal_Int64 GetCorrectedValue() const { return mnCorrectedValue; } @@ -241,8 +240,6 @@ protected: protected: MetricFormatter(); - virtual XubString CreateFieldText( sal_Int64 nValue ) const; - SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); SAL_DLLPRIVATE sal_Bool ImplMetricReformat( const XubString& rStr, double& rValue, XubString& rOutStr ); @@ -275,6 +272,7 @@ public: void SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit ); virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const; virtual sal_Int64 GetValue() const; + virtual XubString CreateFieldText( sal_Int64 nValue ) const; using NumericFormatter::GetCorrectedValue; sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const; @@ -296,7 +294,6 @@ private: protected: CurrencyFormatter(); - virtual XubString CreateFieldText( sal_Int64 nValue ) const; SAL_DLLPRIVATE sal_Bool ImplCurrencyReformat( const XubString& rStr, XubString& rOutStr ); public: @@ -308,6 +305,7 @@ public: virtual void SetValue( sal_Int64 nNewValue ); virtual sal_Int64 GetValue() const; + virtual XubString CreateFieldText( sal_Int64 nValue ) const; }; @@ -523,6 +521,8 @@ public: virtual long Notify( NotifyEvent& rNEvt ); virtual void DataChanged( const DataChangedEvent& rDCEvt ); + virtual Size CalcMinimumSize() const; + virtual void Modify(); virtual void Up(); @@ -550,6 +550,8 @@ public: virtual long Notify( NotifyEvent& rNEvt ); virtual void DataChanged( const DataChangedEvent& rDCEvt ); + virtual Size CalcMinimumSize() const; + virtual void Modify(); virtual void Up(); diff --git a/vcl/inc/vcl/spinfld.hxx b/vcl/inc/vcl/spinfld.hxx index fbe2fb451e19..f773baa90680 100644 --- a/vcl/inc/vcl/spinfld.hxx +++ b/vcl/inc/vcl/spinfld.hxx @@ -101,6 +101,7 @@ public: const Link& GetLastHdl() const { return maLastHdlLink; } virtual Size CalcMinimumSize() const; + virtual Size CalcMinimumSizeForText(const rtl::OUString &rString) const; virtual Size GetOptimalSize(WindowSizeType eType) const; virtual Size CalcSize( sal_uInt16 nChars ) const; virtual void take_properties(Window &rOther); diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index 479d6cb45e24..019cca649e95 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -2868,11 +2868,9 @@ void Edit::SetSubEdit( Edit* pEdit ) } } -// ----------------------------------------------------------------------- - -Size Edit::CalcMinimumSize() const +Size Edit::CalcMinimumSizeForText(const rtl::OUString &rString) const { - Size aSize ( GetTextWidth( GetText() ), GetTextHeight() ); + Size aSize ( GetTextWidth( rString ), GetTextHeight() ); // do not create edit fields in which one cannot enter anything // a default minimum width should exist for at least 3 characters Size aMinSize ( CalcSize( 3 ) ); @@ -2897,6 +2895,11 @@ Size Edit::CalcMinimumSize() const return aSize; } +Size Edit::CalcMinimumSize() const +{ + return CalcMinimumSizeForText(GetText()); +} + Size Edit::GetMinimumEditSize() { Window* pDefWin = ImplGetDefaultWindow(); diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index 5fa5480de59e..fdb74f6dc7b7 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -933,6 +933,35 @@ void NumericField::Last() SpinField::Last(); } +namespace +{ + Size calcMinimumSize(const SpinField &rSpinField, const NumericFormatter &rFormatter) + { + rtl::OUStringBuffer aBuf; + sal_Int32 nTextLen; + + nTextLen = rtl::OUString::valueOf(rFormatter.GetMin()).getLength(); + comphelper::string::padToLength(aBuf, nTextLen, '9'); + Size aMinTextSize = rSpinField.CalcMinimumSizeForText( + rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64())); + + nTextLen = rtl::OUString::valueOf(rFormatter.GetMax()).getLength(); + comphelper::string::padToLength(aBuf, nTextLen, '9'); + Size aMaxTextSize = rSpinField.CalcMinimumSizeForText( + rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64())); + + Size aRet(std::max(aMinTextSize.Width(), aMaxTextSize.Width()), + std::max(aMinTextSize.Height(), aMaxTextSize.Height())); + + return aRet; + } +} + +Size NumericField::CalcMinimumSize() const +{ + return calcMinimumSize(*this, *this); +} + // ----------------------------------------------------------------------- NumericBox::NumericBox( Window* pParent, WinBits nWinStyle ) : @@ -1688,6 +1717,11 @@ MetricField::MetricField( Window* pParent, const ResId& rResId ) : Show(); } +Size MetricField::CalcMinimumSize() const +{ + return calcMinimumSize(*this, *this); +} + void MetricFormatter::take_properties(MetricFormatter &rOtherField) { maCustomUnitText = rOtherField.maCustomUnitText; diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx index ae6b00453326..dcd5233002fc 100644 --- a/vcl/source/control/spinfld.cxx +++ b/vcl/source/control/spinfld.cxx @@ -990,11 +990,9 @@ sal_Bool SpinField::ShowDropDown( sal_Bool ) return sal_False; } -// ----------------------------------------------------------------------- - -Size SpinField::CalcMinimumSize() const +Size SpinField::CalcMinimumSizeForText(const rtl::OUString &rString) const { - Size aSz = Edit::CalcMinimumSize(); + Size aSz = Edit::CalcMinimumSizeForText(rString); if ( GetStyle() & WB_DROPDOWN ) aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize(); @@ -1004,6 +1002,12 @@ Size SpinField::CalcMinimumSize() const return aSz; } +Size SpinField::CalcMinimumSize() const +{ + fprintf(stderr, "SpinField::CalcMinimumSize\n"); + return CalcMinimumSizeForText(GetText()); +} + // ----------------------------------------------------------------------- Size SpinField::GetOptimalSize(WindowSizeType eType) const |