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