Line data Source code
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 : #include <svx/svxids.hrc>
21 : #include <svx/dlgutil.hxx>
22 : #include <svl/itempool.hxx>
23 : #include <svl/aeitem.hxx>
24 :
25 : #include "sdattr.hxx"
26 : #include "View.hxx"
27 : #include "sdresid.hxx"
28 : #include "drawdoc.hxx"
29 : #include "dlgsnap.hxx"
30 :
31 :
32 : /**
33 : * dialog to adjust grid (scarcely ESO!)
34 : */
35 0 : SdSnapLineDlg::SdSnapLineDlg(
36 : ::Window* pWindow,
37 : const SfxItemSet& rInAttrs,
38 : ::sd::View* pView)
39 : : ModalDialog(pWindow, "SnapObjectDialog", "modules/sdraw/ui/dlgsnap.ui")
40 0 : , eUIUnit(pView->GetDoc().GetUIUnit())
41 0 : , aUIScale(pView->GetDoc().GetUIScale())
42 : {
43 0 : get(m_pFtX, "xlabel");
44 0 : get(m_pMtrFldX, "x");
45 0 : get(m_pFtY, "ylabel");
46 0 : get(m_pMtrFldY, "y");
47 0 : get(m_pRadioGroup, "radiogroup");
48 0 : get(m_pRbPoint, "point");
49 0 : get(m_pRbVert, "vert");
50 0 : get(m_pRbHorz, "horz");
51 0 : get(m_pBtnDelete, "delete");
52 :
53 0 : m_pRbHorz->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
54 0 : m_pRbVert->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
55 0 : m_pRbPoint->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
56 :
57 0 : m_pBtnDelete->SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
58 :
59 0 : SetFieldUnit( *m_pMtrFldX, eUIUnit, true );
60 0 : SetFieldUnit( *m_pMtrFldY, eUIUnit, true );
61 :
62 : // get WorkArea
63 0 : Rectangle aWorkArea = pView->GetWorkArea();
64 :
65 : // determine PoolUnit
66 0 : SfxItemPool* pPool = rInAttrs.GetPool();
67 : DBG_ASSERT( pPool, "Where's the Pool?" );
68 0 : SfxMapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
69 :
70 : // #i48497# Consider page origin
71 0 : SdrPageView* pPV = pView->GetSdrPageView();
72 0 : Point aLeftTop(aWorkArea.Left()+1, aWorkArea.Top()+1);
73 0 : pPV->LogicToPagePos(aLeftTop);
74 0 : Point aRightBottom(aWorkArea.Right()-2, aWorkArea.Bottom()-2);
75 0 : pPV->LogicToPagePos(aRightBottom);
76 :
77 : // determine max and min values depending on
78 : // WorkArea, PoolUnit and FieldUnit:
79 0 : SetMetricValue( *m_pMtrFldX, aLeftTop.X(), ePoolUnit );
80 :
81 0 : long nValue = static_cast<long>(m_pMtrFldX->GetValue());
82 0 : nValue = Fraction( nValue ) / aUIScale;
83 0 : m_pMtrFldX->SetMin( nValue );
84 0 : m_pMtrFldX->SetFirst( nValue );
85 :
86 0 : SetMetricValue( *m_pMtrFldX, aRightBottom.X(), ePoolUnit );
87 0 : nValue = static_cast<long>(m_pMtrFldX->GetValue());
88 0 : nValue = Fraction( nValue ) / aUIScale;
89 0 : m_pMtrFldX->SetMax( nValue );
90 0 : m_pMtrFldX->SetLast( nValue );
91 :
92 0 : SetMetricValue( *m_pMtrFldY, aLeftTop.Y(), ePoolUnit );
93 0 : nValue = static_cast<long>(m_pMtrFldY->GetValue());
94 0 : nValue = Fraction( nValue ) / aUIScale;
95 0 : m_pMtrFldY->SetMin( nValue );
96 0 : m_pMtrFldY->SetFirst( nValue );
97 :
98 0 : SetMetricValue( *m_pMtrFldY, aRightBottom.Y(), ePoolUnit );
99 0 : nValue = static_cast<long>(m_pMtrFldY->GetValue());
100 0 : nValue = Fraction( nValue ) / aUIScale;
101 0 : m_pMtrFldY->SetMax( nValue );
102 0 : m_pMtrFldY->SetLast( nValue );
103 :
104 : // set values
105 0 : nXValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
106 0 : nYValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
107 0 : nXValue = Fraction(nXValue) / aUIScale;
108 0 : nYValue = Fraction(nYValue) / aUIScale;
109 0 : SetMetricValue( *m_pMtrFldX, nXValue, SFX_MAPUNIT_100TH_MM);
110 0 : SetMetricValue( *m_pMtrFldY, nYValue, SFX_MAPUNIT_100TH_MM);
111 :
112 0 : m_pRbPoint->Check();
113 0 : }
114 :
115 : /**
116 : * fills provided item sets with dialog box attributes
117 : */
118 0 : IMPL_LINK( SdSnapLineDlg, ClickHdl, Button *, pBtn )
119 : {
120 0 : if ( pBtn == m_pRbPoint ) SetInputFields(sal_True, sal_True);
121 0 : else if ( pBtn == m_pRbHorz ) SetInputFields(sal_False, sal_True);
122 0 : else if ( pBtn == m_pRbVert ) SetInputFields(sal_True, sal_False);
123 0 : else if ( pBtn == m_pBtnDelete ) EndDialog(RET_SNAP_DELETE);
124 :
125 0 : return 0;
126 : }
127 :
128 : /**
129 : * fills provided item sets with dialog box attributes
130 : */
131 0 : void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
132 : {
133 : SnapKind eKind;
134 :
135 0 : if ( m_pRbHorz->IsChecked() ) eKind = SK_HORIZONTAL;
136 0 : else if ( m_pRbVert->IsChecked() ) eKind = SK_VERTICAL;
137 0 : else eKind = SK_POINT;
138 :
139 0 : nXValue = Fraction( GetCoreValue( *m_pMtrFldX, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
140 0 : nYValue = Fraction( GetCoreValue( *m_pMtrFldY, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
141 :
142 0 : rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, (sal_uInt16)eKind));
143 0 : rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_X, nXValue));
144 0 : rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, nYValue));
145 0 : }
146 :
147 0 : void SdSnapLineDlg::HideRadioGroup()
148 : {
149 0 : m_pRadioGroup->Hide();
150 0 : }
151 :
152 : /**
153 : * disable X or Y input fields
154 : */
155 0 : void SdSnapLineDlg::SetInputFields(sal_Bool bEnableX, sal_Bool bEnableY)
156 : {
157 0 : if ( bEnableX )
158 : {
159 0 : if ( !m_pMtrFldX->IsEnabled() )
160 0 : m_pMtrFldX->SetValue(nXValue);
161 0 : m_pMtrFldX->Enable();
162 0 : m_pFtX->Enable();
163 : }
164 0 : else if ( m_pMtrFldX->IsEnabled() )
165 : {
166 0 : nXValue = static_cast<long>(m_pMtrFldX->GetValue());
167 0 : m_pMtrFldX->SetText(OUString());
168 0 : m_pMtrFldX->Disable();
169 0 : m_pFtX->Disable();
170 : }
171 0 : if ( bEnableY )
172 : {
173 0 : if ( !m_pMtrFldY->IsEnabled() )
174 0 : m_pMtrFldY->SetValue(nYValue);
175 0 : m_pMtrFldY->Enable();
176 0 : m_pFtY->Enable();
177 : }
178 0 : else if ( m_pMtrFldY->IsEnabled() )
179 : {
180 0 : nYValue = static_cast<long>(m_pMtrFldY->GetValue());
181 0 : m_pMtrFldY->SetText(OUString());
182 0 : m_pMtrFldY->Disable();
183 0 : m_pFtY->Disable();
184 : }
185 0 : }
186 :
187 :
188 :
189 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|