1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10*5b190011SAndrew Rist *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19*5b190011SAndrew Rist *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <svx/svxids.hrc>
33cdf0e10cSrcweir #include <svx/dlgutil.hxx>
34cdf0e10cSrcweir #include <svl/itempool.hxx>
35cdf0e10cSrcweir #include <svl/aeitem.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "dlgsnap.hrc"
38cdf0e10cSrcweir #include "sdattr.hxx"
39cdf0e10cSrcweir #include "View.hxx"
40cdf0e10cSrcweir #include "sdresid.hxx"
41cdf0e10cSrcweir #include "drawdoc.hxx"
42cdf0e10cSrcweir #include "dlgsnap.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir /*************************************************************************
46cdf0e10cSrcweir |*
47cdf0e10cSrcweir |* Dialog zum Einstellen des Rasters (wohl kaum ESO!)
48cdf0e10cSrcweir |*
49cdf0e10cSrcweir \************************************************************************/
50cdf0e10cSrcweir
SdSnapLineDlg(::Window * pWindow,const SfxItemSet & rInAttrs,::sd::View * pView)51cdf0e10cSrcweir SdSnapLineDlg::SdSnapLineDlg(
52cdf0e10cSrcweir ::Window* pWindow,
53cdf0e10cSrcweir const SfxItemSet& rInAttrs,
54cdf0e10cSrcweir ::sd::View* pView)
55cdf0e10cSrcweir : ModalDialog (pWindow, SdResId(DLG_SNAPLINE)),
56cdf0e10cSrcweir aFlPos (this, SdResId(FL_POSITION)),
57cdf0e10cSrcweir aFtX (this, SdResId(FT_X)),
58cdf0e10cSrcweir aMtrFldX (this, SdResId(MTR_FLD_X)),
59cdf0e10cSrcweir aFtY (this, SdResId(FT_Y)),
60cdf0e10cSrcweir aMtrFldY (this, SdResId(MTR_FLD_Y)),
61cdf0e10cSrcweir aFlDir (this, SdResId(FL_DIRECTION)),
62cdf0e10cSrcweir aRbPoint (this, SdResId(RB_POINT)),
63cdf0e10cSrcweir aRbVert (this, SdResId(RB_VERTICAL)),
64cdf0e10cSrcweir aRbHorz (this, SdResId(RB_HORIZONTAL)),
65cdf0e10cSrcweir aBtnOK (this, SdResId(BTN_OK)),
66cdf0e10cSrcweir aBtnCancel (this, SdResId(BTN_CANCEL)),
67cdf0e10cSrcweir aBtnHelp (this, SdResId(BTN_HELP)),
68cdf0e10cSrcweir aBtnDelete (this, SdResId(BTN_DELETE)),
69cdf0e10cSrcweir eUIUnit(pView->GetDoc()->GetUIUnit()),
70cdf0e10cSrcweir aUIScale(pView->GetDoc()->GetUIScale())
71cdf0e10cSrcweir {
72cdf0e10cSrcweir aRbPoint.SetModeRadioImage( Image( SdResId( BMP_POINT_H ) ), BMP_COLOR_HIGHCONTRAST );
73cdf0e10cSrcweir aRbVert.SetModeRadioImage( Image( SdResId( BMP_VERTICAL_H ) ), BMP_COLOR_HIGHCONTRAST );
74cdf0e10cSrcweir aRbHorz.SetModeRadioImage( Image( SdResId( BMP_HORIZONTAL_H ) ), BMP_COLOR_HIGHCONTRAST );
75cdf0e10cSrcweir
76cdf0e10cSrcweir FreeResource();
77cdf0e10cSrcweir
78cdf0e10cSrcweir aRbHorz.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
79cdf0e10cSrcweir aRbVert.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
80cdf0e10cSrcweir aRbPoint.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
81cdf0e10cSrcweir
82cdf0e10cSrcweir aBtnDelete.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
83cdf0e10cSrcweir
84cdf0e10cSrcweir SetFieldUnit( aMtrFldX, eUIUnit, sal_True );
85cdf0e10cSrcweir SetFieldUnit( aMtrFldY, eUIUnit, sal_True );
86cdf0e10cSrcweir
87cdf0e10cSrcweir // WorkArea holen
88cdf0e10cSrcweir Rectangle aWorkArea = pView->GetWorkArea();
89cdf0e10cSrcweir
90cdf0e10cSrcweir // PoolUnit ermitteln
91cdf0e10cSrcweir SfxItemPool* pPool = rInAttrs.GetPool();
92cdf0e10cSrcweir DBG_ASSERT( pPool, "Wo ist der Pool?" );
93cdf0e10cSrcweir SfxMapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
94cdf0e10cSrcweir
95cdf0e10cSrcweir // #i48497# Consider page origin
96cdf0e10cSrcweir SdrPageView* pPV = pView->GetSdrPageView();
97cdf0e10cSrcweir Point aLeftTop(aWorkArea.Left()+1, aWorkArea.Top()+1);
98cdf0e10cSrcweir pPV->LogicToPagePos(aLeftTop);
99cdf0e10cSrcweir Point aRightBottom(aWorkArea.Right()-2, aWorkArea.Bottom()-2);
100cdf0e10cSrcweir pPV->LogicToPagePos(aRightBottom);
101cdf0e10cSrcweir
102cdf0e10cSrcweir // Hier werden die Max- und MinWerte in Abhaengigkeit von der
103cdf0e10cSrcweir // WorkArea, PoolUnit und der FieldUnit:
104cdf0e10cSrcweir SetMetricValue( aMtrFldX, aLeftTop.X(), ePoolUnit );
105cdf0e10cSrcweir
106cdf0e10cSrcweir long nValue = static_cast<long>(aMtrFldX.GetValue());
107cdf0e10cSrcweir nValue = Fraction( nValue ) / aUIScale;
108cdf0e10cSrcweir aMtrFldX.SetMin( nValue );
109cdf0e10cSrcweir aMtrFldX.SetFirst( nValue );
110cdf0e10cSrcweir
111cdf0e10cSrcweir SetMetricValue( aMtrFldX, aRightBottom.X(), ePoolUnit );
112cdf0e10cSrcweir nValue = static_cast<long>(aMtrFldX.GetValue());
113cdf0e10cSrcweir nValue = Fraction( nValue ) / aUIScale;
114cdf0e10cSrcweir aMtrFldX.SetMax( nValue );
115cdf0e10cSrcweir aMtrFldX.SetLast( nValue );
116cdf0e10cSrcweir
117cdf0e10cSrcweir SetMetricValue( aMtrFldY, aLeftTop.Y(), ePoolUnit );
118cdf0e10cSrcweir nValue = static_cast<long>(aMtrFldY.GetValue());
119cdf0e10cSrcweir nValue = Fraction( nValue ) / aUIScale;
120cdf0e10cSrcweir aMtrFldY.SetMin( nValue );
121cdf0e10cSrcweir aMtrFldY.SetFirst( nValue );
122cdf0e10cSrcweir
123cdf0e10cSrcweir SetMetricValue( aMtrFldY, aRightBottom.Y(), ePoolUnit );
124cdf0e10cSrcweir nValue = static_cast<long>(aMtrFldY.GetValue());
125cdf0e10cSrcweir nValue = Fraction( nValue ) / aUIScale;
126cdf0e10cSrcweir aMtrFldY.SetMax( nValue );
127cdf0e10cSrcweir aMtrFldY.SetLast( nValue );
128cdf0e10cSrcweir
129cdf0e10cSrcweir // Setzen der Werte
130cdf0e10cSrcweir nXValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
131cdf0e10cSrcweir nYValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
132cdf0e10cSrcweir nXValue = Fraction(nXValue) / aUIScale;
133cdf0e10cSrcweir nYValue = Fraction(nYValue) / aUIScale;
134cdf0e10cSrcweir SetMetricValue( aMtrFldX, nXValue, SFX_MAPUNIT_100TH_MM);
135cdf0e10cSrcweir SetMetricValue( aMtrFldY, nYValue, SFX_MAPUNIT_100TH_MM);
136cdf0e10cSrcweir
137cdf0e10cSrcweir aRbPoint.Check();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir /*************************************************************************
141cdf0e10cSrcweir |*
142cdf0e10cSrcweir |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
143cdf0e10cSrcweir |*
144cdf0e10cSrcweir \************************************************************************/
145cdf0e10cSrcweir
IMPL_LINK(SdSnapLineDlg,ClickHdl,Button *,pBtn)146cdf0e10cSrcweir IMPL_LINK( SdSnapLineDlg, ClickHdl, Button *, pBtn )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir if ( pBtn == &aRbPoint ) SetInputFields(sal_True, sal_True);
149cdf0e10cSrcweir else if ( pBtn == &aRbHorz ) SetInputFields(sal_False, sal_True);
150cdf0e10cSrcweir else if ( pBtn == &aRbVert ) SetInputFields(sal_True, sal_False);
151cdf0e10cSrcweir else if ( pBtn == &aBtnDelete ) EndDialog(RET_SNAP_DELETE);
152cdf0e10cSrcweir
153cdf0e10cSrcweir return 0;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir /*************************************************************************
157cdf0e10cSrcweir |*
158cdf0e10cSrcweir |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
159cdf0e10cSrcweir |*
160cdf0e10cSrcweir \************************************************************************/
161cdf0e10cSrcweir
GetAttr(SfxItemSet & rOutAttrs)162cdf0e10cSrcweir void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir SnapKind eKind;
165cdf0e10cSrcweir
166cdf0e10cSrcweir if ( aRbHorz.IsChecked() ) eKind = SK_HORIZONTAL;
167cdf0e10cSrcweir else if ( aRbVert.IsChecked() ) eKind = SK_VERTICAL;
168cdf0e10cSrcweir else eKind = SK_POINT;
169cdf0e10cSrcweir
170cdf0e10cSrcweir nXValue = Fraction( GetCoreValue( aMtrFldX, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
171cdf0e10cSrcweir nYValue = Fraction( GetCoreValue( aMtrFldY, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
172cdf0e10cSrcweir
173cdf0e10cSrcweir rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, (sal_uInt16)eKind));
174cdf0e10cSrcweir rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_X, nXValue));
175cdf0e10cSrcweir rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, nYValue));
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir /*************************************************************************
179cdf0e10cSrcweir |*
180cdf0e10cSrcweir |* Gruppe mit Radiobutton verstecken
181cdf0e10cSrcweir |*
182cdf0e10cSrcweir \************************************************************************/
183cdf0e10cSrcweir
HideRadioGroup()184cdf0e10cSrcweir void SdSnapLineDlg::HideRadioGroup()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir aFlDir.Hide();
187cdf0e10cSrcweir aRbHorz.Hide();
188cdf0e10cSrcweir aRbVert.Hide();
189cdf0e10cSrcweir aRbPoint.Hide();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir /*************************************************************************
193cdf0e10cSrcweir |*
194cdf0e10cSrcweir |* X- bzw. Y-Inputfeld disablen
195cdf0e10cSrcweir |*
196cdf0e10cSrcweir \************************************************************************/
197cdf0e10cSrcweir
SetInputFields(sal_Bool bEnableX,sal_Bool bEnableY)198cdf0e10cSrcweir void SdSnapLineDlg::SetInputFields(sal_Bool bEnableX, sal_Bool bEnableY)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir if ( bEnableX )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir if ( !aMtrFldX.IsEnabled() )
203cdf0e10cSrcweir aMtrFldX.SetValue(nXValue);
204cdf0e10cSrcweir aMtrFldX.Enable();
205cdf0e10cSrcweir aFtX.Enable();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir else if ( aMtrFldX.IsEnabled() )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir nXValue = static_cast<long>(aMtrFldX.GetValue());
210cdf0e10cSrcweir aMtrFldX.SetText(String());
211cdf0e10cSrcweir aMtrFldX.Disable();
212cdf0e10cSrcweir aFtX.Disable();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir if ( bEnableY )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir if ( !aMtrFldY.IsEnabled() )
217cdf0e10cSrcweir aMtrFldY.SetValue(nYValue);
218cdf0e10cSrcweir aMtrFldY.Enable();
219cdf0e10cSrcweir aFtY.Enable();
220cdf0e10cSrcweir }
221cdf0e10cSrcweir else if ( aMtrFldY.IsEnabled() )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir nYValue = static_cast<long>(aMtrFldY.GetValue());
224cdf0e10cSrcweir aMtrFldY.SetText(String());
225cdf0e10cSrcweir aMtrFldY.Disable();
226cdf0e10cSrcweir aFtY.Disable();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir
231cdf0e10cSrcweir
232