xref: /AOO41X/main/sd/source/ui/dlg/dlgsnap.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <svx/svxids.hrc>
37*cdf0e10cSrcweir #include <svx/dlgutil.hxx>
38*cdf0e10cSrcweir #include <svl/itempool.hxx>
39*cdf0e10cSrcweir #include <svl/aeitem.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include "dlgsnap.hrc"
42*cdf0e10cSrcweir #include "sdattr.hxx"
43*cdf0e10cSrcweir #include "View.hxx"
44*cdf0e10cSrcweir #include "sdresid.hxx"
45*cdf0e10cSrcweir #include "drawdoc.hxx"
46*cdf0e10cSrcweir #include "dlgsnap.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir /*************************************************************************
50*cdf0e10cSrcweir |*
51*cdf0e10cSrcweir |* Dialog zum Einstellen des Rasters (wohl kaum ESO!)
52*cdf0e10cSrcweir |*
53*cdf0e10cSrcweir \************************************************************************/
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir SdSnapLineDlg::SdSnapLineDlg(
56*cdf0e10cSrcweir     ::Window* pWindow,
57*cdf0e10cSrcweir     const SfxItemSet& rInAttrs,
58*cdf0e10cSrcweir     ::sd::View* pView)
59*cdf0e10cSrcweir     : ModalDialog (pWindow, SdResId(DLG_SNAPLINE)),
60*cdf0e10cSrcweir       aFlPos      (this, SdResId(FL_POSITION)),
61*cdf0e10cSrcweir       aFtX        (this, SdResId(FT_X)),
62*cdf0e10cSrcweir       aMtrFldX    (this, SdResId(MTR_FLD_X)),
63*cdf0e10cSrcweir       aFtY        (this, SdResId(FT_Y)),
64*cdf0e10cSrcweir       aMtrFldY    (this, SdResId(MTR_FLD_Y)),
65*cdf0e10cSrcweir       aFlDir      (this, SdResId(FL_DIRECTION)),
66*cdf0e10cSrcweir       aRbPoint    (this, SdResId(RB_POINT)),
67*cdf0e10cSrcweir       aRbVert     (this, SdResId(RB_VERTICAL)),
68*cdf0e10cSrcweir 	  aRbHorz     (this, SdResId(RB_HORIZONTAL)),
69*cdf0e10cSrcweir 	  aBtnOK      (this, SdResId(BTN_OK)),
70*cdf0e10cSrcweir       aBtnCancel  (this, SdResId(BTN_CANCEL)),
71*cdf0e10cSrcweir       aBtnHelp    (this, SdResId(BTN_HELP)),
72*cdf0e10cSrcweir       aBtnDelete  (this, SdResId(BTN_DELETE)),
73*cdf0e10cSrcweir 	  eUIUnit(pView->GetDoc()->GetUIUnit()),
74*cdf0e10cSrcweir       aUIScale(pView->GetDoc()->GetUIScale())
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	aRbPoint.SetModeRadioImage( Image( SdResId( BMP_POINT_H ) ), BMP_COLOR_HIGHCONTRAST );
77*cdf0e10cSrcweir 	aRbVert.SetModeRadioImage( Image( SdResId( BMP_VERTICAL_H ) ), BMP_COLOR_HIGHCONTRAST );
78*cdf0e10cSrcweir 	aRbHorz.SetModeRadioImage( Image( SdResId( BMP_HORIZONTAL_H ) ), BMP_COLOR_HIGHCONTRAST );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	FreeResource();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	aRbHorz.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
83*cdf0e10cSrcweir 	aRbVert.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
84*cdf0e10cSrcweir 	aRbPoint.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	aBtnDelete.SetClickHdl(LINK(this, SdSnapLineDlg, ClickHdl));
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	SetFieldUnit( aMtrFldX, eUIUnit, sal_True );
89*cdf0e10cSrcweir 	SetFieldUnit( aMtrFldY, eUIUnit, sal_True );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	// WorkArea holen
92*cdf0e10cSrcweir 	Rectangle aWorkArea = pView->GetWorkArea();
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	// PoolUnit ermitteln
95*cdf0e10cSrcweir 	SfxItemPool* pPool = rInAttrs.GetPool();
96*cdf0e10cSrcweir 	DBG_ASSERT( pPool, "Wo ist der Pool?" );
97*cdf0e10cSrcweir 	SfxMapUnit ePoolUnit = pPool->GetMetric( SID_ATTR_FILL_HATCH );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	// #i48497# Consider page origin
100*cdf0e10cSrcweir     SdrPageView* pPV = pView->GetSdrPageView();
101*cdf0e10cSrcweir     Point aLeftTop(aWorkArea.Left()+1, aWorkArea.Top()+1);
102*cdf0e10cSrcweir     pPV->LogicToPagePos(aLeftTop);
103*cdf0e10cSrcweir     Point aRightBottom(aWorkArea.Right()-2, aWorkArea.Bottom()-2);
104*cdf0e10cSrcweir     pPV->LogicToPagePos(aRightBottom);
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     // Hier werden die Max- und MinWerte in Abhaengigkeit von der
107*cdf0e10cSrcweir     // WorkArea, PoolUnit und der FieldUnit:
108*cdf0e10cSrcweir     SetMetricValue( aMtrFldX, aLeftTop.X(), ePoolUnit );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	long nValue = static_cast<long>(aMtrFldX.GetValue());
111*cdf0e10cSrcweir 	nValue = Fraction( nValue ) / aUIScale;
112*cdf0e10cSrcweir 	aMtrFldX.SetMin( nValue );
113*cdf0e10cSrcweir 	aMtrFldX.SetFirst( nValue );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	SetMetricValue( aMtrFldX, aRightBottom.X(), ePoolUnit );
116*cdf0e10cSrcweir 	nValue = static_cast<long>(aMtrFldX.GetValue());
117*cdf0e10cSrcweir 	nValue = Fraction( nValue ) / aUIScale;
118*cdf0e10cSrcweir 	aMtrFldX.SetMax( nValue );
119*cdf0e10cSrcweir 	aMtrFldX.SetLast( nValue );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	SetMetricValue( aMtrFldY, aLeftTop.Y(), ePoolUnit );
122*cdf0e10cSrcweir 	nValue = static_cast<long>(aMtrFldY.GetValue());
123*cdf0e10cSrcweir 	nValue = Fraction( nValue ) / aUIScale;
124*cdf0e10cSrcweir 	aMtrFldY.SetMin( nValue );
125*cdf0e10cSrcweir 	aMtrFldY.SetFirst( nValue );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	SetMetricValue( aMtrFldY, aRightBottom.Y(), ePoolUnit );
128*cdf0e10cSrcweir 	nValue = static_cast<long>(aMtrFldY.GetValue());
129*cdf0e10cSrcweir 	nValue = Fraction( nValue ) / aUIScale;
130*cdf0e10cSrcweir 	aMtrFldY.SetMax( nValue );
131*cdf0e10cSrcweir 	aMtrFldY.SetLast( nValue );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	// Setzen der Werte
134*cdf0e10cSrcweir 	nXValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
135*cdf0e10cSrcweir 	nYValue = ((const SfxUInt32Item&) rInAttrs.Get(ATTR_SNAPLINE_Y)).GetValue();
136*cdf0e10cSrcweir 	nXValue = Fraction(nXValue) / aUIScale;
137*cdf0e10cSrcweir 	nYValue = Fraction(nYValue) / aUIScale;
138*cdf0e10cSrcweir 	SetMetricValue( aMtrFldX, nXValue, SFX_MAPUNIT_100TH_MM);
139*cdf0e10cSrcweir 	SetMetricValue( aMtrFldY, nYValue, SFX_MAPUNIT_100TH_MM);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	aRbPoint.Check();
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir /*************************************************************************
145*cdf0e10cSrcweir |*
146*cdf0e10cSrcweir |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
147*cdf0e10cSrcweir |*
148*cdf0e10cSrcweir \************************************************************************/
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir IMPL_LINK( SdSnapLineDlg, ClickHdl, Button *, pBtn )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	if ( pBtn == &aRbPoint )		SetInputFields(sal_True, sal_True);
153*cdf0e10cSrcweir 	else if ( pBtn == &aRbHorz )	SetInputFields(sal_False, sal_True);
154*cdf0e10cSrcweir 	else if ( pBtn == &aRbVert )	SetInputFields(sal_True, sal_False);
155*cdf0e10cSrcweir 	else if ( pBtn == &aBtnDelete ) EndDialog(RET_SNAP_DELETE);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	return 0;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir /*************************************************************************
161*cdf0e10cSrcweir |*
162*cdf0e10cSrcweir |* Fuellt uebergebenes Item-Set mit Dialogbox-Attributen
163*cdf0e10cSrcweir |*
164*cdf0e10cSrcweir \************************************************************************/
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir void SdSnapLineDlg::GetAttr(SfxItemSet& rOutAttrs)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	SnapKind eKind;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	if ( aRbHorz.IsChecked() )		eKind = SK_HORIZONTAL;
171*cdf0e10cSrcweir 	else if ( aRbVert.IsChecked() ) eKind = SK_VERTICAL;
172*cdf0e10cSrcweir 	else							eKind = SK_POINT;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	nXValue = Fraction( GetCoreValue( aMtrFldX, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
175*cdf0e10cSrcweir 	nYValue = Fraction( GetCoreValue( aMtrFldY, SFX_MAPUNIT_100TH_MM) ) * aUIScale;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	rOutAttrs.Put(SfxAllEnumItem(ATTR_SNAPLINE_KIND, (sal_uInt16)eKind));
178*cdf0e10cSrcweir 	rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_X, nXValue));
179*cdf0e10cSrcweir 	rOutAttrs.Put(SfxUInt32Item(ATTR_SNAPLINE_Y, nYValue));
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir /*************************************************************************
183*cdf0e10cSrcweir |*
184*cdf0e10cSrcweir |* Gruppe mit Radiobutton verstecken
185*cdf0e10cSrcweir |*
186*cdf0e10cSrcweir \************************************************************************/
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir void SdSnapLineDlg::HideRadioGroup()
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	aFlDir.Hide();
191*cdf0e10cSrcweir 	aRbHorz.Hide();
192*cdf0e10cSrcweir 	aRbVert.Hide();
193*cdf0e10cSrcweir 	aRbPoint.Hide();
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir /*************************************************************************
197*cdf0e10cSrcweir |*
198*cdf0e10cSrcweir |* X- bzw. Y-Inputfeld disablen
199*cdf0e10cSrcweir |*
200*cdf0e10cSrcweir \************************************************************************/
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir void SdSnapLineDlg::SetInputFields(sal_Bool bEnableX, sal_Bool bEnableY)
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	if ( bEnableX )
205*cdf0e10cSrcweir 	{
206*cdf0e10cSrcweir 		if ( !aMtrFldX.IsEnabled() )
207*cdf0e10cSrcweir 			aMtrFldX.SetValue(nXValue);
208*cdf0e10cSrcweir 		aMtrFldX.Enable();
209*cdf0e10cSrcweir 		aFtX.Enable();
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir 	else if ( aMtrFldX.IsEnabled() )
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		nXValue = static_cast<long>(aMtrFldX.GetValue());
214*cdf0e10cSrcweir 		aMtrFldX.SetText(String());
215*cdf0e10cSrcweir 		aMtrFldX.Disable();
216*cdf0e10cSrcweir 		aFtX.Disable();
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir 	if ( bEnableY )
219*cdf0e10cSrcweir 	{
220*cdf0e10cSrcweir 		if ( !aMtrFldY.IsEnabled() )
221*cdf0e10cSrcweir 			aMtrFldY.SetValue(nYValue);
222*cdf0e10cSrcweir 		aMtrFldY.Enable();
223*cdf0e10cSrcweir 		aFtY.Enable();
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir 	else if ( aMtrFldY.IsEnabled() )
226*cdf0e10cSrcweir 	{
227*cdf0e10cSrcweir 		nYValue = static_cast<long>(aMtrFldY.GetValue());
228*cdf0e10cSrcweir 		aMtrFldY.SetText(String());
229*cdf0e10cSrcweir 		aMtrFldY.Disable();
230*cdf0e10cSrcweir 		aFtY.Disable();
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236