summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-05-23 18:50:55 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-05-23 18:55:40 +0900
commitef934abf7d222035e4261474c322de603bd001da (patch)
treea84b2295ebbc97ccc0a8c0a2d273f31366afa1c8 /vcl
parent60ef5920d3ad89e0839f26488481ded8157ebbe9 (diff)
support linking a Slider with a NumericField
Change-Id: I5cfd28d278cc21884eb9bf1b0e5a619c871f6bd2
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/slider.cxx43
1 files changed, 41 insertions, 2 deletions
diff --git a/vcl/source/control/slider.cxx b/vcl/source/control/slider.cxx
index fb566e892cd9..4aa94ad8b427 100644
--- a/vcl/source/control/slider.cxx
+++ b/vcl/source/control/slider.cxx
@@ -68,6 +68,8 @@ void Slider::ImplInit( vcl::Window* pParent, WinBits nStyle )
mbCalcSize = true;
mbFullDrag = true;
+ mpLinkedField = nullptr;
+
Control::ImplInit( pParent, nStyle, NULL );
ImplInitSettings();
@@ -75,7 +77,7 @@ void Slider::ImplInit( vcl::Window* pParent, WinBits nStyle )
}
Slider::Slider( vcl::Window* pParent, WinBits nStyle ) :
- Control( WINDOW_SLIDER )
+ Control(WINDOW_SLIDER)
{
ImplInit( pParent, nStyle );
}
@@ -211,6 +213,34 @@ void Slider::ImplUpdateRects( bool bUpdate )
}
}
+void Slider::ImplSetFieldLink(const Link<>& rLink)
+{
+ if (mpLinkedField != nullptr)
+ {
+ mpLinkedField->SetModifyHdl(rLink);
+ mpLinkedField->SetUpHdl(rLink);
+ mpLinkedField->SetDownHdl(rLink);
+ mpLinkedField->SetFirstHdl(rLink);
+ mpLinkedField->SetLastHdl(rLink);
+ mpLinkedField->SetLoseFocusHdl(rLink);
+ }
+}
+
+void Slider::ImplUpdateLinkedField()
+{
+ if (mpLinkedField)
+ mpLinkedField->SetValue(mnThumbPos);
+}
+
+IMPL_LINK(Slider, LinkedFieldModifyHdl, NumericField*, pField)
+{
+ if (pField)
+ {
+ SetThumbPos(pField->GetValue());
+ }
+ return 0;
+}
+
long Slider::ImplCalcThumbPos( long nPixPos )
{
// calculate position
@@ -762,6 +792,7 @@ void Slider::Tracking( const TrackingEvent& rTEvt )
{
ImplUpdateRects();
Update();
+ ImplUpdateLinkedField();
if ( mbFullDrag && (nOldPos != mnThumbPos) )
{
mnDelta = mnThumbPos-nOldPos;
@@ -839,6 +870,13 @@ void Slider::Resize()
Invalidate();
}
+void Slider::SetLinkedField(NumericField* pField)
+{
+ ImplSetFieldLink(Link<>());
+ mpLinkedField = pField;
+ ImplSetFieldLink(LINK(this, Slider, LinkedFieldModifyHdl));
+}
+
void Slider::RequestHelp( const HelpEvent& rHEvt )
{
Control::RequestHelp( rHEvt );
@@ -947,7 +985,7 @@ void Slider::SetRange( const Range& rRange )
mnThumbPos = mnMaxRange;
if ( mnThumbPos < mnMinRange )
mnThumbPos = mnMinRange;
-
+ ImplUpdateLinkedField();
StateChanged( StateChangedType::Data );
}
}
@@ -962,6 +1000,7 @@ void Slider::SetThumbPos( long nNewThumbPos )
if ( mnThumbPos != nNewThumbPos )
{
mnThumbPos = nNewThumbPos;
+ ImplUpdateLinkedField();
StateChanged( StateChangedType::Data );
}
}