23 #include <dialmgr.hxx>
29 #include <rtl/ustring.hxx>
32 #include <svx/svxids.hrc>
33 #include <strings.hrc>
42 #define CM_1_TO_TWIP 567
43 #define TWIP_TO_INCH 1440
56 :
SfxTabPage(pPage, pController,
"cui/ui/croppage.ui",
"CropPage", &rSet)
60 , m_xCropFrame(m_xBuilder->weld_widget(
"cropframe"))
61 , m_xZoomConstRB(m_xBuilder->weld_radio_button(
"keepscale"))
62 , m_xSizeConstRB(m_xBuilder->weld_radio_button(
"keepsize"))
63 , m_xLeftMF(m_xBuilder->weld_metric_spin_button(
"left",
FieldUnit::
CM))
64 , m_xRightMF(m_xBuilder->weld_metric_spin_button(
"right",
FieldUnit::
CM))
65 , m_xTopMF(m_xBuilder->weld_metric_spin_button(
"top",
FieldUnit::
CM))
66 , m_xBottomMF(m_xBuilder->weld_metric_spin_button(
"bottom",
FieldUnit::
CM))
67 , m_xScaleFrame(m_xBuilder->weld_widget(
"scaleframe"))
68 , m_xWidthZoomMF(m_xBuilder->weld_metric_spin_button(
"widthzoom",
FieldUnit::
PERCENT))
69 , m_xHeightZoomMF(m_xBuilder->weld_metric_spin_button(
"heightzoom",
FieldUnit::
PERCENT))
70 , m_xSizeFrame(m_xBuilder->weld_widget(
"sizeframe"))
71 , m_xWidthMF(m_xBuilder->weld_metric_spin_button(
"width",
FieldUnit::
CM))
72 , m_xHeightMF(m_xBuilder->weld_metric_spin_button(
"height",
FieldUnit::
CM))
73 , m_xOrigSizeGrid(m_xBuilder->weld_widget(
"origsizegrid"))
74 , m_xOrigSizeFT(m_xBuilder->weld_label(
"origsizeft"))
75 , m_xOrigSizePB(m_xBuilder->weld_button(
"origsize"))
76 , m_xExampleWN(new
weld::CustomWeld(*m_xBuilder,
"preview", m_aExampleWN))
101 m_xTopMF->connect_value_changed( aLk );
114 return std::make_unique<SvxGrfCropPage>(pPage, pController, *rSet);
123 SID_ATTR_GRAF_KEEP_ZOOM ),
true, &pItem ))
125 if( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
132 sal_uInt16 nW = rPool.
GetWhich( SID_ATTR_GRAF_CROP );
133 if( SfxItemState::SET == rSet->
GetItemState( nW,
true, &pItem))
151 m_xLeftMF->set_value(0, FieldUnit::NONE);
153 m_xTopMF->set_value(0, FieldUnit::NONE);
162 nW = rPool.
GetWhich( SID_ATTR_PAGE_SIZE );
163 if ( SfxItemState::SET == rSet->
GetItemState( nW,
false, &pItem ) )
171 auto nMax =
m_xHeightMF->normalize(aPageSize.Height());
173 nMax =
m_xWidthMF->normalize(aPageSize.Width());
185 if( SfxItemState::SET == rSet->
GetItemState( SID_ATTR_GRAF_GRAPHIC,
false, &pItem ) )
209 if( !static_cast<const SvxBrushItem*>(pItem)->GetGraphicLink().isEmpty() )
222 bool bModified =
false;
223 if(
m_xWidthMF->get_value_changed_from_saved() ||
226 sal_uInt16 nW = rPool.
GetWhich( SID_ATTR_GRAF_FRMSIZE );
229 std::shared_ptr<SvxSizeItem> aSz(std::make_shared<SvxSizeItem>(nW));
234 if( pExSet && SfxItemState::SET ==pExSet->
GetItemState( nW,
false, &pItem ) )
236 aSz.reset(static_cast< SvxSizeItem*>(pItem->
Clone()));
243 Size aTmpSz( aSz->GetSize() );
244 if(
m_xWidthMF->get_value_changed_from_saved() )
248 aSz->SetSize( aTmpSz );
252 bModified |=
nullptr != rSet->
Put( *aSz );
257 SID_ATTR_GRAF_FRMSIZE_PERCENT ),
Size( 0, 0 )) );
260 if(
m_xLeftMF->get_value_changed_from_saved() ||
m_xRightMF->get_value_changed_from_saved() ||
263 sal_uInt16 nW = rPool.
GetWhich( SID_ATTR_GRAF_CROP );
265 std::unique_ptr<SvxGrfCrop> pNew(static_cast<SvxGrfCrop*>(rSet->
Get( nW ).
Clone()));
271 bModified |=
nullptr != rSet->
Put( *pNew );
295 if( SfxItemState::SET == rSet.
GetItemState( SID_ATTR_GRAF_FRMSIZE,
false, &pItem ) )
296 aSize = static_cast<const SvxSizeItem*>(pItem)->GetSize();
304 if (nWidth !=
m_xWidthMF->get_value(FieldUnit::TWIP))
305 m_xWidthMF->set_value(nWidth, FieldUnit::TWIP);
308 if (nHeight !=
m_xHeightMF->get_value(FieldUnit::TWIP))
312 if( SfxItemState::SET == rSet.
GetItemState( SID_ATTR_GRAF_GRAPHIC,
false, &pItem ) )
348 return DeactivateRC::LeavePage;
360 SID_ATTR_GRAF_CROP ) ) );
362 if (&rField == m_xWidthZoomMF.get())
366 m_xWidthMF->set_value( m_xWidthMF->normalize(
367 ((aOrigSize.Width() - nLRBorders) * rField.get_value(FieldUnit::NONE))/100),
374 m_xHeightMF->set_value( m_xHeightMF->normalize(
375 ((aOrigSize.Height() - nULBorders ) * rField.get_value(FieldUnit::NONE))/100) ,
389 SID_ATTR_GRAF_CROP ) ) );
394 if(&rField == m_xWidthMF.get())
401 sal_uInt16 nZoom =
static_cast<sal_uInt16
>( aSize.
Width() * 100 / nWidth);
402 m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE);
411 sal_uInt16 nZoom =
static_cast<sal_uInt16
>( aSize.
Height() * 100 / nHeight);
412 m_xHeightZoomMF->set_value(nZoom, FieldUnit::NONE);
425 SID_ATTR_GRAF_CROP ) ) );
427 bool bZoom = m_xZoomConstRB->get_active();
428 if (&rField == m_xLeftMF.get() || &rField == m_xRightMF.get())
433 if (bZoom && nWidthZoom != 0 && ( ( ( aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom )
434 / 100 >= aPageSize.Width() ) )
436 if (&rField == m_xLeftMF.get())
438 nLeft = aOrigSize.Width() -
439 ( aPageSize.Width() * 100 / nWidthZoom + nRight );
440 m_xLeftMF->set_value( m_xLeftMF->normalize( nLeft ), eUnit );
444 nRight = aOrigSize.Width() -
445 ( aPageSize.Width() * 100 / nWidthZoom + nLeft );
446 m_xRightMF->set_value( m_xRightMF->normalize( nRight ), eUnit );
451 m_aExampleWN.SetLeft(nRight);
452 m_aExampleWN.SetRight(nLeft);
456 m_aExampleWN.SetLeft(nLeft);
457 m_aExampleWN.SetRight(nRight);
462 ZoomHdl(*m_xWidthZoomMF);
470 if(bZoom && ( ( ( aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom)
471 / 100 >= aPageSize.Height()))
473 assert(nHeightZoom &&
"div-by-zero");
474 if(&rField == m_xTopMF.get())
476 nTop = aOrigSize.Height() -
477 ( aPageSize.Height() * 100 / nHeightZoom + nBottom);
478 m_xTopMF->set_value( m_xWidthMF->normalize( nTop ), eUnit );
482 nBottom = aOrigSize.Height() -
483 ( aPageSize.Height() * 100 / nHeightZoom + nTop);
484 m_xBottomMF->set_value( m_xWidthMF->normalize( nBottom ), eUnit );
487 m_aExampleWN.SetTop( nTop );
488 m_aExampleWN.SetBottom( nBottom );
492 ZoomHdl(*m_xHeightZoomMF);
495 m_aExampleWN.Invalidate();
510 SID_ATTR_GRAF_CROP ) ) );
515 m_xWidthMF->set_value( m_xWidthMF->normalize( nWidth ), eUnit );
519 m_xHeightMF->set_value( m_xHeightMF->normalize( nHeight ), eUnit );
520 m_xWidthZoomMF->set_value(100, FieldUnit::NONE);
521 m_xHeightZoomMF->set_value(100, FieldUnit::NONE);
533 SID_ATTR_GRAF_CROP ) ) );
541 sal_uInt16 nZoom = 0;
544 nZoom =
static_cast<sal_uInt16
>((( nWidth * 1000 / nDen )+5)/10);
547 nZoom =
static_cast<sal_uInt16
>((( nHeight * 1000 / nDen )+5)/10);
562 SID_ATTR_GRAF_CROP ) ) );
569 nMin = nMinWidth - (nL >= 0 ? nL : 0);
574 nMin = nMinHeight - (nUp >= 0 ? nUp : 0);
578 nMin = nMinHeight - (nLow >= 0 ? nLow : 0);
593 SID_ATTR_GRAF_CROP ) ));
621 m_xLeftMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
622 m_xRightMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
626 m_xTopMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
627 m_xBottomMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE);
635 std::unique_ptr<weld::MetricSpinButton> xFld(xBuilder->weld_metric_spin_button(
"spin", FieldUnit::CM));
638 xFld->set_max(INT_MAX - 1, FieldUnit::NONE);
641 sTemp = xFld->get_text();
644 sTemp +=
u"\u00D7" + xFld->get_text();
652 sTemp +=
" " +
CuiResId( RID_SVXSTR_PPI );
653 OUString sPPI = OUString::number(ax);
654 if (
abs(ax - ay) > 1) {
655 sPPI +=
u"\u00D7" + OUString::number(ay);
657 sTemp = sTemp.replaceAll(
"%1", sPPI);
671 const MapMode aMapTwip( MapUnit::MapTwip );
685 , m_aBottomRight(0, 0)
691 CustomWidgetController::SetDrawingArea(pDrawingArea);
704 rRenderContext.
Push(PushFlags::MAPMODE);
720 m_aGrf.
Draw(&rRenderContext, aRect.TopLeft(), aRect.GetSize());
732 const double fLogicDashLength(aDashVector.getX());
744 std::vector< double >(2, fLogicDashLength),
755 2.0 * fLogicDashLength);
757 rRenderContext.
Pop();
776 if( aYScale < aXScale )
Color GetStripeColorA() const
basegfx::B2DHomMatrix GetInverseViewTransformation() const
#define LINK(Instance, Class, Member)
void SetRight(tools::Long nVal)
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
void SetAntialiasing(AntialiasingFlags nMode)
void setWidth(tools::Long nWidth)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetTop(tools::Long nVal)
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
virtual void ActivatePage(const SfxItemSet &rSet) override
IMPL_LINK(SvxGrfCropPage, ZoomHdl, weld::MetricSpinButton &, rField, void)
const StyleSettings & GetStyleSettings() const
constexpr OUStringLiteral PERCENT(u"Percent")
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
void DrawPolyLine(const tools::Polygon &rPoly)
std::unique_ptr< weld::MetricSpinButton > m_xLeftMF
virtual void Paint(vcl::RenderContext &rRenderContext, const ::tools::Rectangle &rRect) override
const MapMode & GetMapMode() const
void SetLeft(tools::Long nVal)
Color GetStripeColorB() const
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
std::unique_ptr< weld::MetricSpinButton > m_xTopMF
std::unique_ptr< weld::Widget > m_xScaleFrame
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
static OutputDevice * GetDefaultDevice()
SvxGrfCropPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
std::unique_ptr< weld::Widget > m_xCropFrame
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static Size GetGrfOrigSize(const Graphic &)
std::unique_ptr< weld::MetricSpinButton > m_xBottomMF
virtual bool FillItemSet(SfxItemSet *rSet) override
void SetExchangeSupport()
std::unique_ptr< weld::MetricSpinButton > m_xRightMF
const Graphic * GetGraphic(OUString const &referer=OUString()) const
virtual OutputDevice & get_ref_device()=0
virtual ~SvxGrfCropPage() override
std::unique_ptr< weld::MetricSpinButton > m_xHeightZoomMF
void DrawRect(const tools::Rectangle &rRect)
const SfxItemSet & GetItemSet() const
std::unique_ptr< weld::CustomWeld > m_xExampleWN
void applyLineDashing(const B2DPolygon &rCandidate, const std::vector< double > &rDotDashArray, B2DPolyPolygon *pLineTarget, B2DPolyPolygon *pGapTarget, double fDotDashLength)
void SetScaleX(const Fraction &rScaleX)
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
GraphicType GetType() const
std::unique_ptr< weld::Button > m_xOrigSizePB
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
const OUString & GetValue() const
tools::Long Width() const
static bool GetLayoutRTL()
void SetScaleY(const Fraction &rScaleY)
const AllSettings & GetSettings() const
MapUnit GetMapUnit() const
SfxItemPool * GetPool() const
const SfxItemSet * GetDialogExampleSet() const
OUString CuiResId(const char *pKey)
void SetFrameSize(const Size &rSz)
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
std::unique_ptr< weld::MetricSpinButton > m_xHeightMF
std::unique_ptr< weld::Widget > m_xSizeFrame
const OUString & GetGraphicLink() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
weld::Window * GetFrameWeld() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
static int lcl_GetValue(const weld::MetricSpinButton &rMetric, FieldUnit eUnit)
std::unique_ptr< weld::MetricSpinButton > m_xWidthZoomMF
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
MapMode GetPrefMapMode() const
std::unique_ptr< weld::RadioButton > m_xSizeConstRB
SvxCropExample m_aExampleWN
virtual void Resize() override
tools::Long Height() const
const Color & GetWindowColor() const
std::unique_ptr< weld::RadioButton > m_xZoomConstRB
basegfx::BColor getBColor() const
void setHeight(tools::Long nHeight)
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
FieldUnit MapToFieldUnit(const MapUnit eUnit)
virtual void Reset(const SfxItemSet *rSet) override
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
std::unique_ptr< weld::MetricSpinButton > m_xWidthMF
Degree100 abs(Degree100 x)
void SetBottom(tools::Long nVal)
std::unique_ptr< weld::Label > m_xOrigSizeFT
sal_uInt16 GetStripeLength() const
void GraphicHasChanged(bool bFound)
void SetGraphic(const Graphic &rGrf)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
void Push(PushFlags nFlags=PushFlags::ALL)
std::unique_ptr< weld::Widget > m_xOrigSizeGrid
IMPL_LINK_NOARG(SvxGrfCropPage, OrigSizeHdl, weld::Button &, void)