1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <vcl/customweld.hxx>
23 #include <vcl/graph.hxx>
24 #include <sfx2/tabdlg.hxx>
25 
26 class SvxCropExample : public weld::CustomWidgetController
27 {
28     MapMode     m_aMapMode;
29     Size        m_aFrameSize;
30     Point       m_aTopLeft, m_aBottomRight;
31     Graphic     m_aGrf;
32 
33 public:
34     SvxCropExample();
35 
36     virtual void Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) override;
37     virtual void Resize() override;
38     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
39 
SetTop(tools::Long nVal)40     void SetTop( tools::Long nVal )                { m_aTopLeft.setX(nVal); }
SetBottom(tools::Long nVal)41     void SetBottom( tools::Long nVal )             { m_aBottomRight.setX(nVal); }
SetLeft(tools::Long nVal)42     void SetLeft( tools::Long nVal )               { m_aTopLeft.setY(nVal); }
SetRight(tools::Long nVal)43     void SetRight( tools::Long nVal)               { m_aBottomRight.setY(nVal); }
44     void SetFrameSize( const Size& rSz );
SetGraphic(const Graphic & rGrf)45     void SetGraphic( const Graphic& rGrf )  { m_aGrf = rGrf; }
46 };
47 
48 class SvxGrfCropPage : public SfxTabPage
49 {
50     friend class VclPtr<SvxGrfCropPage>;
51 
52     OUString        aGraphicName;
53     Size            aOrigSize;
54     Size            aOrigPixelSize;
55     Size            aPageSize;
56     tools::Long            nOldWidth;
57     tools::Long            nOldHeight;
58     bool            bSetOrigSize;
59 
60     SvxCropExample m_aExampleWN;
61 
62     std::unique_ptr<weld::Widget> m_xCropFrame;
63     std::unique_ptr<weld::RadioButton> m_xZoomConstRB;
64     std::unique_ptr<weld::RadioButton> m_xSizeConstRB;
65     std::unique_ptr<weld::MetricSpinButton> m_xLeftMF;
66     std::unique_ptr<weld::MetricSpinButton> m_xRightMF;
67     std::unique_ptr<weld::MetricSpinButton> m_xTopMF;
68     std::unique_ptr<weld::MetricSpinButton> m_xBottomMF;
69 
70     std::unique_ptr<weld::Widget> m_xScaleFrame;
71     std::unique_ptr<weld::MetricSpinButton> m_xWidthZoomMF;
72     std::unique_ptr<weld::MetricSpinButton> m_xHeightZoomMF;
73 
74     std::unique_ptr<weld::Widget> m_xSizeFrame;
75     std::unique_ptr<weld::MetricSpinButton> m_xWidthMF;
76     std::unique_ptr<weld::MetricSpinButton> m_xHeightMF;
77 
78     std::unique_ptr<weld::Widget> m_xOrigSizeGrid;
79     std::unique_ptr<weld::Label> m_xOrigSizeFT;
80     std::unique_ptr<weld::Button> m_xOrigSizePB;
81 
82     // Example
83     std::unique_ptr<weld::CustomWeld> m_xExampleWN;
84 
85     DECL_LINK(ZoomHdl, weld::MetricSpinButton&, void);
86     DECL_LINK(SizeHdl, weld::MetricSpinButton&, void);
87     DECL_LINK(CropModifyHdl, weld::MetricSpinButton&, void);
88     DECL_LINK(OrigSizeHdl, weld::Button&, void);
89 
90     void            CalcZoom();
91     void            CalcMinMaxBorder();
92     void            GraphicHasChanged(bool bFound);
93     virtual void    ActivatePage(const SfxItemSet& rSet) override;
94 
95     static Size     GetGrfOrigSize(const Graphic&);
96 public:
97     SvxGrfCropPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet);
98     static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet );
99     virtual ~SvxGrfCropPage() override;
100 
101     virtual bool FillItemSet( SfxItemSet *rSet ) override;
102     virtual void Reset( const SfxItemSet *rSet ) override;
103     virtual DeactivateRC DeactivatePage( SfxItemSet *pSet ) override;
104 };
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
107