Update ooo320-m1
[ooovba.git] / svx / source / options / optgrid.cxx
blob69fd27a3b541c90e0b374302ee71f134e79d81c6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optgrid.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
36 #include <sfx2/app.hxx>
37 #include <sfx2/module.hxx>
39 #define _SVX_OPTGRID_CXX
41 #include <svx/svxids.hrc>
42 #include <svx/dialmgr.hxx>
43 #include "optgrid.hxx"
44 #include <svx/dialogs.hrc>
45 #include "optgrid.hrc"
46 #include "dlgutil.hxx"
48 /* -----------------18.08.98 17:41-------------------
49 * local functions
50 * --------------------------------------------------*/
51 void lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
53 nFirst = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
54 nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
55 nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
56 nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
59 void lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
61 rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
62 rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
63 rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
64 rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
67 /*--------------------------------------------------------------------
68 Beschreibung: Rastereinstellungen Ctor
69 --------------------------------------------------------------------*/
71 SvxOptionsGrid::SvxOptionsGrid() :
72 nFldDrawX ( 100 ),
73 nFldDivisionX ( 0 ),
74 nFldDrawY ( 100 ),
75 nFldDivisionY ( 0 ),
76 nFldSnapX ( 100 ),
77 nFldSnapY ( 100 ),
78 bUseGridsnap ( 0 ),
79 bSynchronize ( 1 ),
80 bGridVisible ( 0 ),
81 bEqualGrid ( 1 )
85 /*--------------------------------------------------------------------
86 Beschreibung: Rastereinstellungen Dtor
87 --------------------------------------------------------------------*/
89 SvxOptionsGrid::~SvxOptionsGrid()
93 /*--------------------------------------------------------------------
94 Beschreibung: Item fuer Rastereinstellungen
95 --------------------------------------------------------------------*/
97 SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
98 : SvxOptionsGrid()
99 , SfxPoolItem(rItem)
101 bUseGridsnap = rItem.bUseGridsnap ;
102 bSynchronize = rItem.bSynchronize ;
103 bGridVisible = rItem.bGridVisible ;
104 bEqualGrid = rItem.bEqualGrid ;
105 nFldDrawX = rItem.nFldDrawX ;
106 nFldDivisionX= rItem.nFldDivisionX;
107 nFldDrawY = rItem.nFldDrawY ;
108 nFldDivisionY= rItem.nFldDivisionY;
109 nFldSnapX = rItem.nFldSnapX ;
110 nFldSnapY = rItem.nFldSnapY ;
114 /*--------------------------------------------------------------------
115 Beschreibung:
116 --------------------------------------------------------------------*/
118 SfxPoolItem* SvxGridItem::Clone( SfxItemPool* ) const
120 return new SvxGridItem( *this );
123 /*--------------------------------------------------------------------
124 Beschreibung:
125 --------------------------------------------------------------------*/
127 int SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
129 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" );
131 const SvxGridItem& rItem = (const SvxGridItem&) rAttr;
133 return ( bUseGridsnap == rItem.bUseGridsnap &&
134 bSynchronize == rItem.bSynchronize &&
135 bGridVisible == rItem.bGridVisible &&
136 bEqualGrid == rItem.bEqualGrid &&
137 nFldDrawX == rItem.nFldDrawX &&
138 nFldDivisionX== rItem.nFldDivisionX&&
139 nFldDrawY == rItem.nFldDrawY &&
140 nFldDivisionY== rItem.nFldDivisionY&&
141 nFldSnapX == rItem.nFldSnapX &&
142 nFldSnapY == rItem.nFldSnapY );
145 /*--------------------------------------------------------------------
146 Beschreibung:
147 --------------------------------------------------------------------*/
149 SfxItemPresentation SvxGridItem::GetPresentation
151 SfxItemPresentation ePres,
152 SfxMapUnit /*eCoreUnit*/,
153 SfxMapUnit /*ePresUnit*/,
154 String& rText, const IntlWrapper *
155 ) const
157 switch ( ePres )
159 case SFX_ITEM_PRESENTATION_NONE:
160 rText.Erase();
161 return SFX_ITEM_PRESENTATION_NONE;
162 case SFX_ITEM_PRESENTATION_NAMELESS:
163 case SFX_ITEM_PRESENTATION_COMPLETE:
164 rText = String::CreateFromAscii("SvxGridItem");
165 return ePres;
166 default:
167 return SFX_ITEM_PRESENTATION_NONE;
172 /*----------------- OS 23.02.95 -----------------------
173 TabPage Rastereinstellungen
174 -------------------------------------------------------*/
176 SvxGridTabPage::SvxGridTabPage( Window* pParent, const SfxItemSet& rCoreSet) :
178 SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_GRID ), rCoreSet ),
180 aCbxUseGridsnap ( this, SVX_RES( CBX_USE_GRIDSNAP ) ),
181 aCbxGridVisible ( this, SVX_RES( CBX_GRID_VISIBLE ) ),
183 aFlResolution ( this, SVX_RES( FL_RESOLUTION ) ),
184 aFtDrawX ( this, SVX_RES( FT_DRAW_X ) ),
185 aMtrFldDrawX ( this, SVX_RES( MTR_FLD_DRAW_X ) ),
186 aFtDrawY ( this, SVX_RES( FT_DRAW_Y ) ),
187 aMtrFldDrawY ( this, SVX_RES( MTR_FLD_DRAW_Y ) ),
189 aFlDivision ( this, SVX_RES( FL_DIVISION ) ),
190 aFtDivisionX( this, SVX_RES( FT_DIVISION_X) ),
191 aNumFldDivisionX( this, SVX_RES( NUM_FLD_DIVISION_X ) ),
192 aDivisionPointX( this, SVX_RES( FT_HORZ_POINTS) ),
194 aFtDivisionY( this, SVX_RES( FT_DIVISION_Y) ),
195 aNumFldDivisionY( this, SVX_RES( NUM_FLD_DIVISION_Y ) ),
196 aDivisionPointY( this, SVX_RES( FT_VERT_POINTS) ),
198 aCbxSynchronize ( this, SVX_RES( CBX_SYNCHRONIZE ) ),
199 aGrpDrawGrid ( this, SVX_RES( GRP_DRAWGRID ) ),
201 aGrpSnap ( this, SVX_RES( GRP_SNAP ) ),
202 aCbxSnapHelplines ( this, SVX_RES( CBX_SNAP_HELPLINES ) ),
203 aCbxSnapBorder ( this, SVX_RES( CBX_SNAP_BORDER ) ),
204 aCbxSnapFrame ( this, SVX_RES( CBX_SNAP_FRAME ) ),
205 aCbxSnapPoints ( this, SVX_RES( CBX_SNAP_POINTS ) ),
206 aFtSnapArea ( this, SVX_RES( FT_SNAP_AREA ) ),
207 aMtrFldSnapArea ( this, SVX_RES( MTR_FLD_SNAP_AREA ) ),
209 aSeparatorFL ( this, SVX_RES( FL_SEPARATOR ) ),
211 aGrpOrtho ( this, SVX_RES( GRP_ORTHO ) ),
212 aCbxOrtho ( this, SVX_RES( CBX_ORTHO ) ),
213 aCbxBigOrtho ( this, SVX_RES( CBX_BIGORTHO ) ),
214 aCbxRotate ( this, SVX_RES( CBX_ROTATE ) ),
215 aMtrFldAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
216 aFtBezAngle ( this, SVX_RES( FT_BEZ_ANGLE ) ),
217 aMtrFldBezAngle ( this, SVX_RES( MTR_FLD_BEZ_ANGLE ) ),
219 bAttrModified( FALSE )
221 // diese Page braucht ExchangeSupport
222 SetExchangeSupport();
224 FreeResource();
226 aDivisionPointY.SetText(aDivisionPointX.GetText());
227 // Metrik einstellen
228 FieldUnit eFUnit = GetModuleFieldUnit( &rCoreSet );
229 long nFirst, nLast, nMin, nMax;
231 lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
232 SetFieldUnit( aMtrFldDrawX, eFUnit, TRUE );
233 lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
235 lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
236 SetFieldUnit( aMtrFldDrawY, eFUnit, TRUE );
237 lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
240 aCbxRotate.SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
241 Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
242 aCbxUseGridsnap.SetClickHdl( aLink );
243 aCbxSynchronize.SetClickHdl( aLink );
244 aCbxGridVisible.SetClickHdl( aLink );
245 aMtrFldDrawX.SetModifyHdl(
246 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
247 aMtrFldDrawY.SetModifyHdl(
248 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
249 aNumFldDivisionX.SetModifyHdl(
250 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
251 aNumFldDivisionY.SetModifyHdl(
252 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
255 //------------------------------------------------------------------------
257 SfxTabPage* SvxGridTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
259 return ( new SvxGridTabPage( pParent, rAttrSet ) );
262 //------------------------------------------------------------------------
264 BOOL SvxGridTabPage::FillItemSet( SfxItemSet& rCoreSet )
266 if ( bAttrModified )
268 SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
270 aGridItem.bUseGridsnap = aCbxUseGridsnap.IsChecked();
271 aGridItem.bSynchronize = aCbxSynchronize.IsChecked();
272 aGridItem.bGridVisible = aCbxGridVisible.IsChecked();
274 SfxMapUnit eUnit =
275 rCoreSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
276 long nX =GetCoreValue( aMtrFldDrawX, eUnit );
277 long nY = GetCoreValue( aMtrFldDrawY, eUnit );
279 aGridItem.nFldDrawX = (UINT32) nX;
280 aGridItem.nFldDrawY = (UINT32) nY;
281 aGridItem.nFldDivisionX = static_cast<long>(aNumFldDivisionX.GetValue());
282 aGridItem.nFldDivisionY = static_cast<long>(aNumFldDivisionY.GetValue());
284 rCoreSet.Put( aGridItem );
286 return bAttrModified;
289 //------------------------------------------------------------------------
291 void SvxGridTabPage::Reset( const SfxItemSet& rSet )
293 const SfxPoolItem* pAttr = 0;
295 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , FALSE,
296 (const SfxPoolItem**)&pAttr ))
298 const SvxGridItem* pGridAttr = (SvxGridItem*)pAttr;
299 aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
300 aCbxSynchronize.Check( pGridAttr->bSynchronize == 1 );
301 aCbxGridVisible.Check( pGridAttr->bGridVisible == 1 );
303 SfxMapUnit eUnit =
304 rSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
305 SetMetricValue( aMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
306 SetMetricValue( aMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
308 // UINT32 nFineX = pGridAttr->nFldDivisionX;
309 // UINT32 nFineY = pGridAttr->nFldDivisionY;
310 // aNumFldDivisionX.SetValue( nFineX ? (pGridAttr->nFldDrawX / nFineX - 1) : 0 );
311 // aNumFldDivisionY.SetValue( nFineY ? (pGridAttr->nFldDrawY / nFineY - 1) : 0 );
312 aNumFldDivisionX.SetValue( pGridAttr->nFldDivisionX );
313 aNumFldDivisionY.SetValue( pGridAttr->nFldDivisionY );
316 ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
317 bAttrModified = FALSE;
320 // -----------------------------------------------------------------------
322 void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
324 const SfxPoolItem* pAttr = NULL;
325 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , FALSE,
326 (const SfxPoolItem**)&pAttr ))
328 const SvxGridItem* pGridAttr = (SvxGridItem*) pAttr;
329 aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
331 ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
334 // Metrik ggfs. aendern (da TabPage im Dialog liegt,
335 // wo die Metrik eingestellt werden kann
336 //USHORT nWhich = GetWhich( SID_ATTR_METRIC );
337 //if( rSet.GetItemState( GetWhich( SID_ATTR_METRIC ) ) >= SFX_ITEM_AVAILABLE )
338 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , FALSE,
339 (const SfxPoolItem**)&pAttr ))
341 const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
343 FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
345 if( eFUnit != aMtrFldDrawX.GetUnit() )
347 // Metriken einstellen
348 long nFirst, nLast, nMin, nMax;
349 long nVal = static_cast<long>(aMtrFldDrawX.Denormalize( aMtrFldDrawX.GetValue( FUNIT_TWIP ) ));
351 lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
352 SetFieldUnit( aMtrFldDrawX, eFUnit, TRUE );
353 lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
355 aMtrFldDrawX.SetValue( aMtrFldDrawX.Normalize( nVal ), FUNIT_TWIP );
357 nVal = static_cast<long>(aMtrFldDrawY.Denormalize( aMtrFldDrawY.GetValue( FUNIT_TWIP ) ));
358 lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
359 SetFieldUnit( aMtrFldDrawY, eFUnit, TRUE );
360 lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
361 aMtrFldDrawY.SetValue( aMtrFldDrawY.Normalize( nVal ), FUNIT_TWIP );
367 // -----------------------------------------------------------------------
368 int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
370 if ( _pSet )
371 FillItemSet( *_pSet );
372 return( LEAVE_PAGE );
374 //------------------------------------------------------------------------
375 IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
377 bAttrModified = TRUE;
378 if( aCbxSynchronize.IsChecked() )
380 if(pField == &aMtrFldDrawX)
381 aMtrFldDrawY.SetValue( aMtrFldDrawX.GetValue() );
382 else
383 aMtrFldDrawX.SetValue( aMtrFldDrawY.GetValue() );
385 return 0;
387 //------------------------------------------------------------------------
389 IMPL_LINK( SvxGridTabPage, ClickRotateHdl_Impl, void *, EMPTYARG )
391 if( aCbxRotate.IsChecked() )
392 aMtrFldAngle.Enable();
393 else
394 aMtrFldAngle.Disable();
396 return( 0L );
399 //------------------------------------------------------------------------
401 IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
403 bAttrModified = TRUE;
404 if( aCbxSynchronize.IsChecked() )
406 if(&aNumFldDivisionX == pField)
407 aNumFldDivisionY.SetValue( aNumFldDivisionX.GetValue() );
408 else
409 aNumFldDivisionX.SetValue( aNumFldDivisionY.GetValue() );
411 return 0;
413 //------------------------------------------------------------------------
415 IMPL_LINK( SvxGridTabPage, ChangeGridsnapHdl_Impl, void *, EMPTYARG )
417 bAttrModified = TRUE;
418 return 0;