summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svx/dialcontrol.hxx66
-rw-r--r--svx/source/dialog/dialcontrol.cxx232
2 files changed, 1 insertions, 297 deletions
diff --git a/include/svx/dialcontrol.hxx b/include/svx/dialcontrol.hxx
index 07f95bb04420..b17b39cf5615 100644
--- a/include/svx/dialcontrol.hxx
+++ b/include/svx/dialcontrol.hxx
@@ -21,9 +21,7 @@
#define INCLUDED_SVX_DIALCONTROL_HXX
#include <memory>
-#include <vcl/ctrl.hxx>
#include <vcl/customweld.hxx>
-#include <vcl/field.hxx>
#include <vcl/virdev.hxx>
#include <svx/svxdllapi.h>
@@ -68,74 +66,12 @@ private:
state of the control.
It is possible to link a numeric field to this control using the function
- SetLinkedField(). The DialControl will take full control of this numeric
+ SetLinkedField(). The SvxDialControl will take full control of this numeric
field:
- Sets the rotation angle to the numeric field in mouse operations.
- Shows the value entered/modified in the numeric field.
- Enables/disables/shows/hides the field according to own state changes.
*/
-class SAL_WARN_UNUSED DialControl : public Control
-{
-public:
- explicit DialControl( vcl::Window* pParent, WinBits nBits );
-
- virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
-
- virtual void StateChanged( StateChangedType nStateChange ) override;
- virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
-
- virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
- virtual void MouseMove( const MouseEvent& rMEvt ) override;
- virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
- virtual void KeyInput( const KeyEvent& rKEvt ) override;
- virtual void LoseFocus() override;
-
- virtual Size GetOptimalSize() const override;
- virtual void Resize() override;
-
- /** Returns the current rotation angle in 1/100 degrees. */
- sal_Int32 GetRotation() const;
- /** Sets the rotation to the passed value (in 1/100 degrees). */
- void SetRotation( sal_Int32 nAngle );
-
- /** The passed handler is called whenever the rotation value changes. */
- void SetModifyHdl( const Link<DialControl*,void>& rLink );
-
-protected:
- struct DialControl_Impl
- {
- ScopedVclPtr<DialControlBmp> mxBmpEnabled;
- ScopedVclPtr<DialControlBmp> mxBmpDisabled;
- ScopedVclPtr<DialControlBmp> mxBmpBuffered;
- Link<DialControl*,void> maModifyHdl;
- VclPtr<NumericField> mpLinkField;
- sal_Int32 mnLinkedFieldValueMultiplyer;
- Size maWinSize;
- vcl::Font maWinFont;
- sal_Int32 mnAngle;
- sal_Int32 mnOldAngle;
- long mnCenterX;
- long mnCenterY;
- bool mbNoRot;
-
- explicit DialControl_Impl( vcl::Window& rParent );
- void Init( const Size& rWinSize, const vcl::Font& rWinFont );
- void SetSize( const Size& rWinSize );
- };
- std::unique_ptr< DialControl_Impl > mpImpl;
-
- virtual void HandleMouseEvent( const Point& rPos, bool bInitial );
- void HandleEscapeEvent();
-
- void SetRotation( sal_Int32 nAngle, bool bBroadcast );
-
- void Init( const Size& rWinSize, const vcl::Font& rWinFont );
- void Init( const Size& rWinSize );
-
-private:
- void InvalidateControl();
-};
-
class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxDialControl final : public weld::CustomWidgetController
{
public:
diff --git a/svx/source/dialog/dialcontrol.cxx b/svx/source/dialog/dialcontrol.cxx
index 35eae0a707ed..47bef93b3992 100644
--- a/svx/source/dialog/dialcontrol.cxx
+++ b/svx/source/dialog/dialcontrol.cxx
@@ -215,238 +215,6 @@ void DialControlBmp::DrawBackground()
DrawEllipse( aEllipseRect );
}
-
-DialControl::DialControl_Impl::DialControl_Impl ( vcl::Window& rParent ) :
- mxBmpEnabled(VclPtr<DialControlBmp>::Create(rParent)),
- mxBmpDisabled(VclPtr<DialControlBmp>::Create(rParent)),
- mxBmpBuffered(VclPtr<DialControlBmp>::Create(rParent)),
- mpLinkField( nullptr ),
- mnLinkedFieldValueMultiplyer( 0 ),
- mnAngle( 0 ),
- mnOldAngle( 0 ),
- mnCenterX( 0 ),
- mnCenterY( 0 ),
- mbNoRot( false )
-{
-}
-
-void DialControl::DialControl_Impl::Init( const Size& rWinSize, const vcl::Font& rWinFont )
-{
- maWinFont = rWinFont;
- maWinFont.SetTransparent(true);
- mxBmpBuffered->InitBitmap(maWinFont);
- SetSize(rWinSize);
-}
-
-void DialControl::DialControl_Impl::SetSize( const Size& rWinSize )
-{
- // make the control squared, and adjusted so that we have a well-defined
- // center ["(x - 1) | 1" creates odd value <= x]
- long nMin = (std::min(rWinSize.Width(), rWinSize.Height()) - 1) | 1;
-
- maWinSize = Size( nMin, nMin );
-
- mnCenterX = maWinSize.Width() / 2;
- mnCenterY = maWinSize.Height() / 2;
-
- mxBmpEnabled->DrawBackground( maWinSize, true );
- mxBmpDisabled->DrawBackground( maWinSize, false );
- mxBmpBuffered->SetSize( maWinSize );
-}
-
-
-DialControl::DialControl( vcl::Window* pParent, WinBits nBits ) :
- Control( pParent, nBits ),
- mpImpl( new DialControl_Impl( *this ) )
-{
- Init( GetOutputSizePixel() );
-}
-
-void DialControl::Resize()
-{
- mpImpl->SetSize(GetOutputSizePixel());
- InvalidateControl();
-}
-
-void DialControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
-{
- Point aPos;
- rRenderContext.DrawBitmapEx(aPos, mpImpl->mxBmpBuffered->GetBitmapEx(aPos, mpImpl->maWinSize));
-}
-
-void DialControl::StateChanged( StateChangedType nStateChange )
-{
- if( nStateChange == StateChangedType::Enable )
- InvalidateControl();
-
- // update the linked edit field
- if( mpImpl->mpLinkField )
- {
- NumericField& rField = *mpImpl->mpLinkField;
- switch( nStateChange )
- {
- case StateChangedType::Visible: rField.Show( IsVisible() ); break;
- case StateChangedType::Enable: rField.Enable( IsEnabled() ); break;
- default:;
- }
- }
-
- Control::StateChanged( nStateChange );
-}
-
-void DialControl::DataChanged( const DataChangedEvent& rDCEvt )
-{
- if( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
- {
- Init( mpImpl->maWinSize, mpImpl->maWinFont );
- InvalidateControl();
- }
- Control::DataChanged( rDCEvt );
-}
-
-void DialControl::MouseButtonDown( const MouseEvent& rMEvt )
-{
- if( rMEvt.IsLeft() )
- {
- GrabFocus();
- CaptureMouse();
- mpImpl->mnOldAngle = mpImpl->mnAngle;
- HandleMouseEvent( rMEvt.GetPosPixel(), true );
- }
- Control::MouseButtonDown( rMEvt );
-}
-
-void DialControl::MouseMove( const MouseEvent& rMEvt )
-{
- if( IsMouseCaptured() && rMEvt.IsLeft() )
- HandleMouseEvent( rMEvt.GetPosPixel(), false );
- Control::MouseMove(rMEvt );
-}
-
-void DialControl::MouseButtonUp( const MouseEvent& rMEvt )
-{
- if( IsMouseCaptured() )
- {
- ReleaseMouse();
- if( mpImpl->mpLinkField )
- mpImpl->mpLinkField->GrabFocus();
- }
- Control::MouseButtonUp( rMEvt );
-}
-
-void DialControl::KeyInput( const KeyEvent& rKEvt )
-{
- const vcl::KeyCode& rKCode = rKEvt.GetKeyCode();
- if( !rKCode.GetModifier() && (rKCode.GetCode() == KEY_ESCAPE) )
- HandleEscapeEvent();
- else
- Control::KeyInput( rKEvt );
-}
-
-void DialControl::LoseFocus()
-{
- // release captured mouse
- HandleEscapeEvent();
- Control::LoseFocus();
-}
-
-sal_Int32 DialControl::GetRotation() const
-{
- return mpImpl->mnAngle;
-}
-
-Size DialControl::GetOptimalSize() const
-{
- return LogicToPixel(Size(42, 43), MapMode(MapUnit::MapAppFont));
-}
-
-void DialControl::SetRotation( sal_Int32 nAngle )
-{
- SetRotation( nAngle, false );
-}
-
-void DialControl::SetModifyHdl( const Link<DialControl*,void>& rLink )
-{
- mpImpl->maModifyHdl = rLink;
-}
-
-void DialControl::Init( const Size& rWinSize, const vcl::Font& rWinFont )
-{
- mpImpl->Init( rWinSize, rWinFont );
- EnableRTL( false ); // don't mirror mouse handling
- SetOutputSizePixel( mpImpl->maWinSize );
- SetBackground();
-}
-
-void DialControl::Init( const Size& rWinSize )
-{
- //hidpi TODO: GetDefaultFont() picks a font size too small, so fix it here.
- vcl::Font aDefaultSize = GetFont();
-
- vcl::Font aFont( OutputDevice::GetDefaultFont(
- DefaultFontType::UI_SANS, Application::GetSettings().GetUILanguageTag().getLanguageType(), GetDefaultFontFlags::OnlyOne ) );
-
- aFont.SetFontHeight(aDefaultSize.GetFontHeight());
- Init( rWinSize, aFont );
-}
-
-void DialControl::InvalidateControl()
-{
- mpImpl->mxBmpBuffered->CopyBackground( IsEnabled() ? *mpImpl->mxBmpEnabled : *mpImpl->mxBmpDisabled );
- if( !mpImpl->mbNoRot )
- mpImpl->mxBmpBuffered->DrawElements( GetText(), mpImpl->mnAngle );
- Invalidate();
-}
-
-void DialControl::SetRotation( sal_Int32 nAngle, bool bBroadcast )
-{
- bool bOldSel = mpImpl->mbNoRot;
- mpImpl->mbNoRot = false;
-
- while( nAngle < 0 )
- nAngle += 36000;
-
- if( !bOldSel || (mpImpl->mnAngle != nAngle) )
- {
- mpImpl->mnAngle = nAngle;
- InvalidateControl();
- if( mpImpl->mpLinkField )
- mpImpl->mpLinkField->SetValue( static_cast< long >( GetRotation() / mpImpl->mnLinkedFieldValueMultiplyer ) );
- if( bBroadcast )
- mpImpl->maModifyHdl.Call( this );
- }
-}
-
-void DialControl::HandleMouseEvent( const Point& rPos, bool bInitial )
-{
- long nX = rPos.X() - mpImpl->mnCenterX;
- long nY = mpImpl->mnCenterY - rPos.Y();
- double fH = sqrt( static_cast< double >( nX ) * nX + static_cast< double >( nY ) * nY );
- if( fH != 0.0 )
- {
- double fAngle = acos( nX / fH );
- sal_Int32 nAngle = static_cast<sal_Int32>(basegfx::rad2deg(fAngle) * 100.0);
- if( nY < 0 )
- nAngle = 36000 - nAngle;
- if( bInitial ) // round to entire 15 degrees
- nAngle = ((nAngle + 750) / 1500) * 1500;
- // Round up to 1 degree
- nAngle = (((nAngle + 50) / 100) * 100) % 36000;
- SetRotation( nAngle, true );
- }
-}
-
-void DialControl::HandleEscapeEvent()
-{
- if( IsMouseCaptured() )
- {
- ReleaseMouse();
- SetRotation( mpImpl->mnOldAngle, true );
- if( mpImpl->mpLinkField )
- mpImpl->mpLinkField->GrabFocus();
- }
-}
-
SvxDialControl::DialControl_Impl::DialControl_Impl(OutputDevice& rReference) :
mxBmpEnabled(VclPtr<DialControlBmp>::Create(rReference)),
mxBmpDisabled(VclPtr<DialControlBmp>::Create(rReference)),