bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / dlg / dlgsnap.cxx
blob9540be122a3e1896b1cea072872a361181e8c9c3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svxids.hrc>
21 #include <svx/dlgutil.hxx>
22 #include <svl/itempool.hxx>
23 #include <svl/aeitem.hxx>
25 #include "sdattr.hxx"
26 #include "View.hxx"
27 #include "sdresid.hxx"
28 #include "drawdoc.hxx"
29 #include "dlgsnap.hxx"
32 /**
33 * dialog to adjust grid (scarcely ESO!)
35 SdSnapLineDlg::SdSnapLineDlg(
36 ::Window* pWindow,
37 const SfxItemSet& rInAttrs,
38 ::sd::View* pView)
39 : ModalDialog(pWindow, "SnapObjectDialog", "modules/sdraw/ui/dlgsnap.ui")
40 , eUIUnit(pView->GetDoc().GetUIUnit())
41 , aUIScale(pView->GetDoc().GetUIScale())
43 get(m_pFtX, "xlabel");
44 get(m_pMtrFldX, "x");
45 get(m_pFtY, "ylabel");
46 get(m_pMtrFldY, "y");
47 get(m_pRadioGroup, "radiogroup");
48 get(m_pRbPoint, "point");
49 get(m_pRbVert, "vert");
50 get(m_pRbHorz, "horz");
51 get(m_pBtnDelete, "delete");
53 m_pRbHorz->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
54 m_pRbVert->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
55 m_pRbPoint->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
57 m_pBtnDelete->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
59 SetFieldUnit( *m_pMtrFldX, eUIUnit, sal_True );
60 SetFieldUnit( *m_pMtrFldY, eUIUnit, sal_True );
62 // get WorkArea
63 Rectangle aWorkArea = pView->GetWorkArea();
65 // determine PoolUnit
66 SfxItemPool* pPool = rInAttrs.GetPool();
67 DBG_ASSERT( pPool, "Where's the Pool?" );
68 SfxMapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
70 // #i48497# Consider page origin
71 SdrPageView* pPV = pView->GetSdrPageView();
72 Point aLeftTop(aWorkArea.Left()+1, aWorkArea.Top()+1);
73 pPV->LogicToPagePos(aLeftTop);
74 Point aRightBottom(aWorkArea.Right()-2, aWorkArea.Bottom()-2);
75 pPV->LogicToPagePos(aRightBottom);
77 // determine max and min values depending on
78 // WorkArea, PoolUnit and FieldUnit:
79 SetMetricValue( *m_pMtrFldX, aLeftTop.X(), ePoolUnit );
81 long nValue = static_cast<long>(m_pMtrFldX->GetValue());
82 nValue = Fraction( nValue ) / aUIScale;
83 m_pMtrFldX->SetMin( nValue );
84 m_pMtrFldX->SetFirst( nValue );
86 SetMetricValue( *m_pMtrFldX, aRightBottom.X(), ePoolUnit );
87 nValue = static_cast<long>(m_pMtrFldX->GetValue());
88 nValue = Fraction( nValue ) / aUIScale;
89 m_pMtrFldX->SetMax( nValue );
90 m_pMtrFldX->SetLast( nValue );
92 SetMetricValue( *m_pMtrFldY, aLeftTop.Y(), ePoolUnit );
93 nValue = static_cast<long>(m_pMtrFldY->GetValue());
94 nValue = Fraction( nValue ) / aUIScale;
95 m_pMtrFldY->SetMin( nValue );
96 m_pMtrFldY->SetFirst( nValue );
98 SetMetricValue( *m_pMtrFldY, aRightBottom.Y(), ePoolUnit );
99 nValue = static_cast<long>(m_pMtrFldY->GetValue());
100 nValue = Fraction( nValue ) / aUIScale;
101 m_pMtrFldY->SetMax( nValue );
102 m_pMtrFldY->SetLast( nValue );
104 // set values
105 nXValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
106 nYValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
107 nXValue = Fraction(nXValue) / aUIScale;
108 nYValue = Fraction(nYValue) / aUIScale;
109 SetMetricValue( *m_pMtrFldX, nXValue, SFX_MAPUNIT_100TH_MM);
110 SetMetricValue( *m_pMtrFldY, nYValue, SFX_MAPUNIT_100TH_MM);
112 m_pRbPoint->Check();
116 * fills provided item sets with dialog box attributes
118 IMPL_LINK( SdSnapLineDlg, ClickHdl, Button *, pBtn )
120 if ( pBtn == m_pRbPoint ) SetInputFields(sal_True, sal_True);
121 else if ( pBtn == m_pRbHorz ) SetInputFields(sal_False, sal_True);
122 else if ( pBtn == m_pRbVert ) SetInputFields(sal_True, sal_False);
123 else if ( pBtn == m_pBtnDelete ) EndDialog(RET_SNAP_DELETE);
125 return 0;
129 * fills provided item sets with dialog box attributes
131 void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
133 SnapKind eKind;
135 if ( m_pRbHorz->IsChecked() ) eKind = SK_HORIZONTAL;
136 else if ( m_pRbVert->IsChecked() ) eKind = SK_VERTICAL;
137 else eKind = SK_POINT;
139 nXValue = Fraction( GetCoreValue( *m_pMtrFldX, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
140 nYValue = Fraction( GetCoreValue( *m_pMtrFldY, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
142 rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, (sal_uInt16)eKind));
143 rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_X, nXValue));
144 rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, nYValue));
147 void SdSnapLineDlg::HideRadioGroup()
149 m_pRadioGroup->Hide();
153 * disable X or Y input fields
155 void SdSnapLineDlg::SetInputFields(sal_Bool bEnableX, sal_Bool bEnableY)
157 if ( bEnableX )
159 if ( !m_pMtrFldX->IsEnabled() )
160 m_pMtrFldX->SetValue(nXValue);
161 m_pMtrFldX->Enable();
162 m_pFtX->Enable();
164 else if ( m_pMtrFldX->IsEnabled() )
166 nXValue = static_cast<long>(m_pMtrFldX->GetValue());
167 m_pMtrFldX->SetText(String());
168 m_pMtrFldX->Disable();
169 m_pFtX->Disable();
171 if ( bEnableY )
173 if ( !m_pMtrFldY->IsEnabled() )
174 m_pMtrFldY->SetValue(nYValue);
175 m_pMtrFldY->Enable();
176 m_pFtY->Enable();
178 else if ( m_pMtrFldY->IsEnabled() )
180 nYValue = static_cast<long>(m_pMtrFldY->GetValue());
181 m_pMtrFldY->SetText(String());
182 m_pMtrFldY->Disable();
183 m_pFtY->Disable();
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */