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