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