summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-05-25 16:54:30 +0100
committerCaolán McNamara <caolanm@redhat.com>2018-05-29 12:34:29 +0200
commit94762fbc8dcb3b7fe6d535374915db7e7ab95937 (patch)
treed32a6b25794ba87f8dca29ea5765d4596a4f757c /svx
parent096692d397b086775d68a29a905d8883184b70a4 (diff)
weld SvxAngleTabPage
Change-Id: I03bd0a6a0805d549570ce44030a0f58ca2b98d05 Reviewed-on: https://gerrit.libreoffice.org/54987 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/dialog/charmap.cxx4
-rw-r--r--svx/source/dialog/dialcontrol.cxx277
2 files changed, 272 insertions, 9 deletions
diff --git a/svx/source/dialog/charmap.cxx b/svx/source/dialog/charmap.cxx
index 0288524a6466..8b568d80269a 100644
--- a/svx/source/dialog/charmap.cxx
+++ b/svx/source/dialog/charmap.cxx
@@ -124,7 +124,7 @@ void SvxShowCharSet::MouseButtonDown(const MouseEvent& rMEvt)
{
GrabFocus();
bDrag = true;
- grab_add();
+ CaptureMouse();
int nIndex = PixelToMapIndex( rMEvt.GetPosPixel() );
// Fire the focus event
@@ -153,7 +153,7 @@ void SvxShowCharSet::MouseButtonUp(const MouseEvent& rMEvt)
// released mouse over character map
if ( tools::Rectangle(Point(), GetOutputSizePixel()).IsInside(rMEvt.GetPosPixel()))
aSelectHdl.Call( this );
- grab_remove();
+ ReleaseMouse();
bDrag = false;
}
}
diff --git a/svx/source/dialog/dialcontrol.cxx b/svx/source/dialog/dialcontrol.cxx
index 874d280abefb..e62fe137dcbf 100644
--- a/svx/source/dialog/dialcontrol.cxx
+++ b/svx/source/dialog/dialcontrol.cxx
@@ -31,12 +31,12 @@ namespace svx {
const long DIAL_OUTER_WIDTH = 8;
-DialControlBmp::DialControlBmp(vcl::Window& rParent) :
- VirtualDevice(rParent, DeviceFormat::DEFAULT, DeviceFormat::DEFAULT),
- mbEnabled(true),
- mrParent(rParent),
- mnCenterX(0),
- mnCenterY(0)
+DialControlBmp::DialControlBmp(OutputDevice& rReference)
+ : VirtualDevice(rReference, DeviceFormat::DEFAULT, DeviceFormat::DEFAULT)
+ , mbEnabled(true)
+ , mrParent(rReference)
+ , mnCenterX(0)
+ , mnCenterY(0)
{
EnableRTL(false);
}
@@ -507,6 +507,270 @@ void DialControl::HandleEscapeEvent()
}
}
+SvxDialControl::DialControl_Impl::DialControl_Impl(OutputDevice& rReference) :
+ mxBmpEnabled(VclPtr<DialControlBmp>::Create(rReference)),
+ mxBmpDisabled(VclPtr<DialControlBmp>::Create(rReference)),
+ mxBmpBuffered(VclPtr<DialControlBmp>::Create(rReference)),
+ mpLinkField( nullptr ),
+ mnLinkedFieldValueMultiplyer( 0 ),
+ mnAngle( 0 ),
+ mnInitialAngle( 0 ),
+ mnOldAngle( 0 ),
+ mnCenterX( 0 ),
+ mnCenterY( 0 ),
+ mbNoRot( false )
+{
+}
+
+void SvxDialControl::DialControl_Impl::Init( const Size& rWinSize, const vcl::Font& rWinFont )
+{
+ maWinFont = rWinFont;
+ maWinFont.SetTransparent(true);
+ mxBmpBuffered->InitBitmap(maWinFont);
+ SetSize(rWinSize);
+}
+
+void SvxDialControl::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 );
+}
+
+void SvxDialControl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
+{
+ //use same logic as DialControl_Impl::SetSize
+ int nDim = (std::min<int>(pDrawingArea->get_approximate_digit_width() * 12,
+ pDrawingArea->get_text_height() * 6) - 1) | 1;
+ pDrawingArea->set_size_request(nDim, nDim);
+ CustomWidgetController::SetDrawingArea(pDrawingArea);
+ mpImpl.reset(new DialControl_Impl(pDrawingArea->get_ref_device()));
+ //set size and use that
+ Init(GetOutputSizePixel());
+}
+
+void SvxDialControl::Resize()
+{
+ mpImpl->SetSize(GetOutputSizePixel());
+ InvalidateControl();
+}
+
+void SvxDialControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
+{
+ Point aPos;
+ rRenderContext.SetBackground();
+ rRenderContext.Erase();
+ rRenderContext.DrawBitmapEx(aPos, mpImpl->mxBmpBuffered->GetBitmapEx(aPos, mpImpl->maWinSize));
+}
+
+void SvxDialControl::StyleUpdated()
+{
+ CustomWidgetController::StyleUpdated();
+ Init( mpImpl->maWinSize, mpImpl->maWinFont );
+ InvalidateControl();
+}
+
+void SvxDialControl::MouseButtonDown(const MouseEvent& rMEvt)
+{
+ if( rMEvt.IsLeft() )
+ {
+ GrabFocus();
+ CaptureMouse();
+ mpImpl->mnOldAngle = mpImpl->mnAngle;
+ HandleMouseEvent( rMEvt.GetPosPixel(), true );
+ }
+}
+
+void SvxDialControl::MouseMove( const MouseEvent& rMEvt )
+{
+ if( IsMouseCaptured() && rMEvt.IsLeft() )
+ HandleMouseEvent( rMEvt.GetPosPixel(), false );
+}
+
+void SvxDialControl::MouseButtonUp(const MouseEvent&)
+{
+ if( IsMouseCaptured() )
+ {
+ ReleaseMouse();
+ if( mpImpl->mpLinkField )
+ mpImpl->mpLinkField->grab_focus();
+ }
+}
+
+bool SvxDialControl::KeyInput( const KeyEvent& rKEvt )
+{
+ const vcl::KeyCode& rKCode = rKEvt.GetKeyCode();
+ if( !rKCode.GetModifier() && (rKCode.GetCode() == KEY_ESCAPE) )
+ {
+ HandleEscapeEvent();
+ return true;
+ }
+ return CustomWidgetController::KeyInput(rKEvt);
+}
+
+void SvxDialControl::LoseFocus()
+{
+ // release captured mouse
+ HandleEscapeEvent();
+}
+
+bool SvxDialControl::HasRotation() const
+{
+ return !mpImpl->mbNoRot;
+}
+
+void SvxDialControl::SetNoRotation()
+{
+ if( !mpImpl->mbNoRot )
+ {
+ mpImpl->mbNoRot = true;
+ InvalidateControl();
+ if( mpImpl->mpLinkField )
+ mpImpl->mpLinkField->set_text("");
+ }
+}
+
+sal_Int32 SvxDialControl::GetRotation() const
+{
+ return mpImpl->mnAngle;
+}
+
+void SvxDialControl::SetRotation( sal_Int32 nAngle )
+{
+ SetRotation( nAngle, false );
+}
+
+void SvxDialControl::SetLinkedField(weld::SpinButton* pField, sal_Int32 nDecimalPlaces)
+{
+ mpImpl->mnLinkedFieldValueMultiplyer = 100 / std::pow(10.0, double(nDecimalPlaces));
+
+ // remove modify handler from old linked field
+ if( mpImpl->mpLinkField )
+ {
+ weld::SpinButton& rField = *mpImpl->mpLinkField;
+ rField.connect_value_changed(Link<weld::SpinButton&,void>());
+ }
+ // remember the new linked field
+ mpImpl->mpLinkField = pField;
+ // set modify handler at new linked field
+ if( mpImpl->mpLinkField )
+ {
+ weld::SpinButton& rField = *mpImpl->mpLinkField;
+ rField.connect_value_changed(LINK(this, SvxDialControl, LinkedFieldModifyHdl));
+ }
+}
+
+IMPL_LINK_NOARG(SvxDialControl, LinkedFieldModifyHdl, weld::SpinButton&, void)
+{
+ LinkedFieldModifyHdl();
+}
+
+void SvxDialControl::LinkedFieldModifyHdl()
+{
+ if( mpImpl->mpLinkField )
+ SetRotation(mpImpl->mpLinkField->get_value() * mpImpl->mnLinkedFieldValueMultiplyer, false);
+}
+
+
+void SvxDialControl::SaveValue()
+{
+ mpImpl->mnInitialAngle = mpImpl->mnAngle;
+}
+
+bool SvxDialControl::IsValueModified()
+{
+ return mpImpl->mnInitialAngle != mpImpl->mnAngle;
+}
+
+void SvxDialControl::SetModifyHdl( const Link<SvxDialControl*,void>& rLink )
+{
+ mpImpl->maModifyHdl = rLink;
+}
+
+void SvxDialControl::Init( const Size& rWinSize, const vcl::Font& rWinFont )
+{
+ mpImpl->Init( rWinSize, rWinFont );
+ EnableRTL( false ); // don't mirror mouse handling
+ SetOutputSizePixel( mpImpl->maWinSize );
+}
+
+void SvxDialControl::Init( const Size& rWinSize )
+{
+ //hidpi TODO: GetDefaultFont() picks a font size too small, so fix it here.
+ vcl::Font aDefaultSize = Application::GetSettings().GetStyleSettings().GetLabelFont();
+
+ vcl::Font aFont( OutputDevice::GetDefaultFont(
+ DefaultFontType::UI_SANS, Application::GetSettings().GetUILanguageTag().getLanguageType(), GetDefaultFontFlags::OnlyOne ) );
+
+ aFont.SetFontHeight(aDefaultSize.GetFontHeight());
+ Init( rWinSize, aFont );
+}
+
+void SvxDialControl::InvalidateControl()
+{
+ mpImpl->mxBmpBuffered->CopyBackground( IsEnabled() ? *mpImpl->mxBmpEnabled : *mpImpl->mxBmpDisabled );
+ if( !mpImpl->mbNoRot )
+ mpImpl->mxBmpBuffered->DrawElements( GetText(), mpImpl->mnAngle );
+ Invalidate();
+}
+
+void SvxDialControl::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->set_value(GetRotation() / mpImpl->mnLinkedFieldValueMultiplyer);
+ if( bBroadcast )
+ mpImpl->maModifyHdl.Call( this );
+ }
+}
+
+void SvxDialControl::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 >( fAngle / F_PI180 * 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 SvxDialControl::HandleEscapeEvent()
+{
+ if( IsMouseCaptured() )
+ {
+ ReleaseMouse();
+ SetRotation( mpImpl->mnOldAngle, true );
+ if( mpImpl->mpLinkField )
+ mpImpl->mpLinkField->grab_focus();
+ }
+}
DialControlWrapper::DialControlWrapper( DialControl& rDial ) :
SingleControlWrapperType( rDial )
@@ -534,7 +798,6 @@ void DialControlWrapper::SetControlValue( sal_Int32 nValue )
GetControl().SetRotation( nValue );
}
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */