xref: /trunk/main/svx/source/dialog/optgrid.cxx (revision f6e50924)
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_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/shl.hxx>
29 #include <sfx2/app.hxx>
30 #include <sfx2/module.hxx>
31 #include <svl/intitem.hxx>
32 
33 #define _SVX_OPTGRID_CXX
34 
35 #include <svx/svxids.hrc>
36 #include <svx/dialmgr.hxx>
37 #include "svx/optgrid.hxx"
38 #include <svx/dialogs.hrc>
39 #include "optgrid.hrc"
40 #include "svx/dlgutil.hxx"
41 
42 /* -----------------18.08.98 17:41-------------------
43  * local functions
44  * --------------------------------------------------*/
lcl_GetMinMax(MetricField & rField,long & nFirst,long & nLast,long & nMin,long & nMax)45 void	lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
46 {
47 	nFirst	= static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
48 	nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
49 	nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
50 	nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
51 }
52 
lcl_SetMinMax(MetricField & rField,long nFirst,long nLast,long nMin,long nMax)53 void	lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
54 {
55 	rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
56 	rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
57 	rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
58 	rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
59 }
60 
61 /*--------------------------------------------------------------------
62 	Beschreibung: Rastereinstellungen Ctor
63  --------------------------------------------------------------------*/
64 
SvxOptionsGrid()65 SvxOptionsGrid::SvxOptionsGrid() :
66 	nFldDrawX		( 100 ),
67 	nFldDivisionX	( 0 ),
68 	nFldDrawY		( 100 ),
69 	nFldDivisionY	( 0 ),
70 	nFldSnapX		( 100 ),
71 	nFldSnapY		( 100 ),
72 	bUseGridsnap	( 0 ),
73 	bSynchronize	( 1 ),
74 	bGridVisible	( 0 ),
75 	bEqualGrid		( 1 )
76 {
77 }
78 
79 /*--------------------------------------------------------------------
80 	Beschreibung: Rastereinstellungen Dtor
81  --------------------------------------------------------------------*/
82 
~SvxOptionsGrid()83 SvxOptionsGrid::~SvxOptionsGrid()
84 {
85 }
86 
87 /*--------------------------------------------------------------------
88 	Beschreibung: Item fuer Rastereinstellungen
89  --------------------------------------------------------------------*/
90 
SvxGridItem(const SvxGridItem & rItem)91 SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
92 :	SvxOptionsGrid()
93 ,	SfxPoolItem(rItem)
94 {
95 	bUseGridsnap = rItem.bUseGridsnap ;
96 	bSynchronize = rItem.bSynchronize ;
97 	bGridVisible = rItem.bGridVisible ;
98 	bEqualGrid	 = rItem.bEqualGrid	  ;
99 	nFldDrawX    = rItem.nFldDrawX    ;
100 	nFldDivisionX= rItem.nFldDivisionX;
101 	nFldDrawY    = rItem.nFldDrawY    ;
102 	nFldDivisionY= rItem.nFldDivisionY;
103 	nFldSnapX    = rItem.nFldSnapX    ;
104 	nFldSnapY    = rItem.nFldSnapY    ;
105 
106 };
107 
108 /*--------------------------------------------------------------------
109 	Beschreibung:
110  --------------------------------------------------------------------*/
111 
Clone(SfxItemPool *) const112 SfxPoolItem*  SvxGridItem::Clone( SfxItemPool* ) const
113 {
114 	return new SvxGridItem( *this );
115 }
116 
117 /*--------------------------------------------------------------------
118 	Beschreibung:
119  --------------------------------------------------------------------*/
120 
operator ==(const SfxPoolItem & rAttr) const121 int SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
122 {
123 	DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" );
124 
125 	const SvxGridItem& rItem = (const SvxGridItem&) rAttr;
126 
127 	return ( 	bUseGridsnap == rItem.bUseGridsnap &&
128 				bSynchronize == rItem.bSynchronize &&
129 				bGridVisible == rItem.bGridVisible &&
130 				bEqualGrid	 == rItem.bEqualGrid   &&
131 				nFldDrawX    == rItem.nFldDrawX    &&
132 				nFldDivisionX== rItem.nFldDivisionX&&
133 				nFldDrawY    == rItem.nFldDrawY    &&
134 				nFldDivisionY== rItem.nFldDivisionY&&
135 				nFldSnapX    == rItem.nFldSnapX    &&
136 				nFldSnapY    == rItem.nFldSnapY		);
137 }
138 
139 /*--------------------------------------------------------------------
140 	Beschreibung:
141  --------------------------------------------------------------------*/
142 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,String & rText,const IntlWrapper *) const143 SfxItemPresentation  SvxGridItem::GetPresentation
144 (
145 	SfxItemPresentation ePres,
146 	SfxMapUnit			/*eCoreUnit*/,
147 	SfxMapUnit			/*ePresUnit*/,
148     String&             rText, const IntlWrapper *
149 )	const
150 {
151 	switch ( ePres )
152 	{
153 		case SFX_ITEM_PRESENTATION_NONE:
154 			rText.Erase();
155 			return SFX_ITEM_PRESENTATION_NONE;
156 		case SFX_ITEM_PRESENTATION_NAMELESS:
157 		case SFX_ITEM_PRESENTATION_COMPLETE:
158 			rText = String::CreateFromAscii("SvxGridItem");
159 			return ePres;
160 		default:
161 			return SFX_ITEM_PRESENTATION_NONE;
162 	}
163 }
164 
165 
166 /*----------------- OS 23.02.95  -----------------------
167  TabPage Rastereinstellungen
168 -------------------------------------------------------*/
169 
SvxGridTabPage(Window * pParent,const SfxItemSet & rCoreSet)170 SvxGridTabPage::SvxGridTabPage( Window* pParent, const SfxItemSet& rCoreSet) :
171 
172 	SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_GRID ), rCoreSet ),
173 
174 	aCbxUseGridsnap	( this, SVX_RES( CBX_USE_GRIDSNAP ) ),
175 	aCbxGridVisible	( this, SVX_RES( CBX_GRID_VISIBLE ) ),
176 
177     aFlResolution   ( this, SVX_RES( FL_RESOLUTION ) ),
178     aFtDrawX        ( this, SVX_RES( FT_DRAW_X ) ),
179 	aMtrFldDrawX	( this, SVX_RES( MTR_FLD_DRAW_X ) ),
180     aFtDrawY        ( this, SVX_RES( FT_DRAW_Y ) ),
181 	aMtrFldDrawY	( this, SVX_RES( MTR_FLD_DRAW_Y ) ),
182 
183     aFlDivision     ( this, SVX_RES( FL_DIVISION ) ),
184     aFtDivisionX(     this, SVX_RES( FT_DIVISION_X) ),
185     aNumFldDivisionX( this, SVX_RES( NUM_FLD_DIVISION_X ) ),
186     aDivisionPointX(  this, SVX_RES( FT_HORZ_POINTS) ),
187 
188     aFtDivisionY(     this, SVX_RES( FT_DIVISION_Y) ),
189     aNumFldDivisionY( this, SVX_RES( NUM_FLD_DIVISION_Y ) ),
190     aDivisionPointY(  this, SVX_RES( FT_VERT_POINTS) ),
191 
192 	aCbxSynchronize	( this, SVX_RES( CBX_SYNCHRONIZE ) ),
193     aGrpDrawGrid    ( this, SVX_RES( GRP_DRAWGRID ) ),
194 
195     aGrpSnap            ( this, SVX_RES( GRP_SNAP ) ),
196 	aCbxSnapHelplines   ( this, SVX_RES( CBX_SNAP_HELPLINES ) ),
197 	aCbxSnapBorder      ( this, SVX_RES( CBX_SNAP_BORDER ) ),
198     aCbxSnapFrame       ( this, SVX_RES( CBX_SNAP_FRAME ) ),
199     aCbxSnapPoints      ( this, SVX_RES( CBX_SNAP_POINTS ) ),
200 	aFtSnapArea         ( this, SVX_RES( FT_SNAP_AREA ) ),
201     aMtrFldSnapArea     ( this, SVX_RES( MTR_FLD_SNAP_AREA ) ),
202 
203 	aSeparatorFL        ( this, SVX_RES( FL_SEPARATOR ) ),
204 
205 	aGrpOrtho           ( this, SVX_RES( GRP_ORTHO ) ),
206     aCbxOrtho           ( this, SVX_RES( CBX_ORTHO ) ),
207     aCbxBigOrtho        ( this, SVX_RES( CBX_BIGORTHO ) ),
208     aCbxRotate          ( this, SVX_RES( CBX_ROTATE ) ),
209     aMtrFldAngle        ( this, SVX_RES( MTR_FLD_ANGLE ) ),
210     aFtBezAngle         ( this, SVX_RES( FT_BEZ_ANGLE ) ),
211     aMtrFldBezAngle     ( this, SVX_RES( MTR_FLD_BEZ_ANGLE ) ),
212 
213     bAttrModified( sal_False )
214 {
215 	// diese Page braucht ExchangeSupport
216 	SetExchangeSupport();
217 
218 	FreeResource();
219 
220     aDivisionPointY.SetText(aDivisionPointX.GetText());
221 	// Metrik einstellen
222 	FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
223 	long nFirst, nLast, nMin, nMax;
224 
225 	lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
226 	SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
227 	lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
228 
229 	lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
230 	SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
231 	lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
232 
233 
234     aCbxRotate.SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
235     Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
236 	aCbxUseGridsnap.SetClickHdl( aLink );
237 	aCbxSynchronize.SetClickHdl( aLink );
238 	aCbxGridVisible.SetClickHdl( aLink );
239 	aMtrFldDrawX.SetModifyHdl(
240         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
241 	aMtrFldDrawY.SetModifyHdl(
242         LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
243     aNumFldDivisionX.SetModifyHdl(
244         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
245     aNumFldDivisionY.SetModifyHdl(
246         LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
247 
248 	::rtl::OUString sFlResolution( aFlResolution.GetDisplayText() );
249 	::rtl::OUString sFtDrawX(aFtDrawX.GetDisplayText());
250 	::rtl::OUString sFtDrawY(aFtDrawY.GetDisplayText());
251     aMtrFldDrawX.SetAccessibleName( sFtDrawX + sFlResolution   );
252     aMtrFldDrawY.SetAccessibleName( sFtDrawY + sFlResolution   );
253 	::rtl::OUString sFlDivision( aFlDivision.GetDisplayText() );
254 	::rtl::OUString sFtDivisionX(aFtDivisionX.GetDisplayText());
255 	::rtl::OUString sFtDivisionY(aFtDivisionY.GetDisplayText());
256     aNumFldDivisionX.SetAccessibleName(  sFtDivisionX + sFlDivision );
257     aNumFldDivisionY.SetAccessibleName(  sFtDivisionY + sFlDivision );
258 }
259 
260 //------------------------------------------------------------------------
261 
Create(Window * pParent,const SfxItemSet & rAttrSet)262 SfxTabPage* SvxGridTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
263 {
264 	return ( new SvxGridTabPage( pParent, rAttrSet ) );
265 }
266 
267 //------------------------------------------------------------------------
268 
FillItemSet(SfxItemSet & rCoreSet)269 sal_Bool SvxGridTabPage::FillItemSet( SfxItemSet& rCoreSet )
270 {
271 	if ( bAttrModified )
272 	{
273 		SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
274 
275 		aGridItem.bUseGridsnap	= aCbxUseGridsnap.IsChecked();
276 		aGridItem.bSynchronize	= aCbxSynchronize.IsChecked();
277 		aGridItem.bGridVisible	= aCbxGridVisible.IsChecked();
278 
279 		SfxMapUnit eUnit =
280 			rCoreSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
281 		long nX =GetCoreValue(	aMtrFldDrawX, eUnit );
282 		long nY = GetCoreValue(	aMtrFldDrawY, eUnit );
283 
284 		aGridItem.nFldDrawX    = (sal_uInt32) nX;
285 		aGridItem.nFldDrawY    = (sal_uInt32) nY;
286         aGridItem.nFldDivisionX = static_cast<long>(aNumFldDivisionX.GetValue()-1);
287         aGridItem.nFldDivisionY = static_cast<long>(aNumFldDivisionY.GetValue()-1);
288 
289 		rCoreSet.Put( aGridItem );
290 	}
291 	return bAttrModified;
292 }
293 
294 //------------------------------------------------------------------------
295 
Reset(const SfxItemSet & rSet)296 void SvxGridTabPage::Reset( const SfxItemSet& rSet )
297 {
298 	const SfxPoolItem* pAttr = 0;
299 
300 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
301 									(const SfxPoolItem**)&pAttr ))
302 	{
303 		const SvxGridItem* pGridAttr = (SvxGridItem*)pAttr;
304 		aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
305 		aCbxSynchronize.Check( pGridAttr->bSynchronize == 1 );
306 		aCbxGridVisible.Check( pGridAttr->bGridVisible == 1 );
307 
308 		SfxMapUnit eUnit =
309 			rSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
310 		SetMetricValue( aMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
311 		SetMetricValue( aMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
312 
313         aNumFldDivisionX.SetValue( pGridAttr->nFldDivisionX+1 );
314         aNumFldDivisionY.SetValue( pGridAttr->nFldDivisionY+1 );
315 	}
316 
317 	ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
318 	bAttrModified = sal_False;
319 }
320 
321 // -----------------------------------------------------------------------
322 
ActivatePage(const SfxItemSet & rSet)323 void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
324 {
325 	const SfxPoolItem* pAttr = NULL;
326 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
327 									(const SfxPoolItem**)&pAttr ))
328 	{
329 		const SvxGridItem* pGridAttr = (SvxGridItem*) pAttr;
330 		aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
331 
332 		ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
333 	}
334 
335 	// Metrik ggfs. aendern (da TabPage im Dialog liegt,
336 	// wo die Metrik eingestellt werden kann
337 	//sal_uInt16 nWhich = GetWhich( SID_ATTR_METRIC );
338 	//if( rSet.GetItemState( GetWhich( SID_ATTR_METRIC ) ) >= SFX_ITEM_AVAILABLE )
339 	if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , sal_False,
340 									(const SfxPoolItem**)&pAttr ))
341 	{
342 		const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
343 
344 		FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
345 
346 		if( eFUnit != aMtrFldDrawX.GetUnit() )
347 		{
348 			// Metriken einstellen
349 			long nFirst, nLast, nMin, nMax;
350 			long nVal = static_cast<long>(aMtrFldDrawX.Denormalize( aMtrFldDrawX.GetValue( FUNIT_TWIP ) ));
351 
352 			lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
353 			SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
354 			lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
355 
356 			aMtrFldDrawX.SetValue( aMtrFldDrawX.Normalize( nVal ), FUNIT_TWIP );
357 
358 			nVal = static_cast<long>(aMtrFldDrawY.Denormalize( aMtrFldDrawY.GetValue( FUNIT_TWIP ) ));
359 			lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
360 			SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
361 			lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
362 			aMtrFldDrawY.SetValue( aMtrFldDrawY.Normalize( nVal ), FUNIT_TWIP );
363 
364 		}
365 	}
366 }
367 
368 // -----------------------------------------------------------------------
DeactivatePage(SfxItemSet * _pSet)369 int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
370 {
371 	if ( _pSet )
372 		FillItemSet( *_pSet );
373 	return( LEAVE_PAGE );
374 }
375 //------------------------------------------------------------------------
IMPL_LINK(SvxGridTabPage,ChangeDrawHdl_Impl,MetricField *,pField)376 IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
377 {
378 	bAttrModified = sal_True;
379 	if( aCbxSynchronize.IsChecked() )
380 	{
381         if(pField == &aMtrFldDrawX)
382             aMtrFldDrawY.SetValue( aMtrFldDrawX.GetValue() );
383         else
384             aMtrFldDrawX.SetValue( aMtrFldDrawY.GetValue() );
385     }
386 	return 0;
387 }
388 //------------------------------------------------------------------------
389 
IMPL_LINK(SvxGridTabPage,ClickRotateHdl_Impl,void *,EMPTYARG)390 IMPL_LINK( SvxGridTabPage, ClickRotateHdl_Impl, void *, EMPTYARG )
391 {
392 	if( aCbxRotate.IsChecked() )
393 		aMtrFldAngle.Enable();
394 	else
395 		aMtrFldAngle.Disable();
396 
397 	return( 0L );
398 }
399 
400 //------------------------------------------------------------------------
401 
IMPL_LINK(SvxGridTabPage,ChangeDivisionHdl_Impl,NumericField *,pField)402 IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
403 {
404 	bAttrModified = sal_True;
405 	if( aCbxSynchronize.IsChecked() )
406 	{
407         if(&aNumFldDivisionX == pField)
408             aNumFldDivisionY.SetValue( aNumFldDivisionX.GetValue() );
409         else
410             aNumFldDivisionX.SetValue( aNumFldDivisionY.GetValue() );
411     }
412 	return 0;
413 }
414 //------------------------------------------------------------------------
415 
IMPL_LINK(SvxGridTabPage,ChangeGridsnapHdl_Impl,void *,EMPTYARG)416 IMPL_LINK( SvxGridTabPage, ChangeGridsnapHdl_Impl, void *, EMPTYARG )
417 {
418 	bAttrModified = sal_True;
419 	return 0;
420 }
421 
422 
423