fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / dialog / optgrid.cxx
blob664c70eb1f1b987cb7a4854a2d3449e301bb8906
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/shl.hxx>
21 #include <sfx2/app.hxx>
22 #include <sfx2/module.hxx>
23 #include <svl/intitem.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/dialmgr.hxx>
27 #include "svx/optgrid.hxx"
28 #include <svx/dialogs.hrc>
29 #include "optgrid.hrc"
30 #include "svx/dlgutil.hxx"
32 // local functions
33 static void lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
35 nFirst = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
36 nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
37 nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
38 nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
41 static void lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
43 rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
44 rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
45 rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
46 rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
49 SvxOptionsGrid::SvxOptionsGrid() :
50 nFldDrawX ( 100 ),
51 nFldDivisionX ( 0 ),
52 nFldDrawY ( 100 ),
53 nFldDivisionY ( 0 ),
54 nFldSnapX ( 100 ),
55 nFldSnapY ( 100 ),
56 bUseGridsnap ( 0 ),
57 bSynchronize ( 1 ),
58 bGridVisible ( 0 ),
59 bEqualGrid ( 1 )
63 SvxOptionsGrid::~SvxOptionsGrid()
67 SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
68 : SvxOptionsGrid()
69 , SfxPoolItem(rItem)
71 bUseGridsnap = rItem.bUseGridsnap ;
72 bSynchronize = rItem.bSynchronize ;
73 bGridVisible = rItem.bGridVisible ;
74 bEqualGrid = rItem.bEqualGrid ;
75 nFldDrawX = rItem.nFldDrawX ;
76 nFldDivisionX= rItem.nFldDivisionX;
77 nFldDrawY = rItem.nFldDrawY ;
78 nFldDivisionY= rItem.nFldDivisionY;
79 nFldSnapX = rItem.nFldSnapX ;
80 nFldSnapY = rItem.nFldSnapY ;
84 SfxPoolItem* SvxGridItem::Clone( SfxItemPool* ) const
86 return new SvxGridItem( *this );
89 int SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
91 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
93 const SvxGridItem& rItem = (const SvxGridItem&) rAttr;
95 return ( 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 );
107 SfxItemPresentation SvxGridItem::GetPresentation
109 SfxItemPresentation ePres,
110 SfxMapUnit /*eCoreUnit*/,
111 SfxMapUnit /*ePresUnit*/,
112 OUString& rText, const IntlWrapper *
113 ) const
115 switch ( ePres )
117 case SFX_ITEM_PRESENTATION_NONE:
118 rText = OUString();
119 return SFX_ITEM_PRESENTATION_NONE;
120 case SFX_ITEM_PRESENTATION_NAMELESS:
121 case SFX_ITEM_PRESENTATION_COMPLETE:
122 rText = "SvxGridItem";
123 return ePres;
124 default:
125 return SFX_ITEM_PRESENTATION_NONE;
129 // TabPage Screen Settings
130 SvxGridTabPage::SvxGridTabPage( Window* pParent, const SfxItemSet& rCoreSet) :
132 SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_GRID ), rCoreSet ),
134 aCbxUseGridsnap ( this, SVX_RES( CBX_USE_GRIDSNAP ) ),
135 aCbxGridVisible ( this, SVX_RES( CBX_GRID_VISIBLE ) ),
137 aFlResolution ( this, SVX_RES( FL_RESOLUTION ) ),
138 aFtDrawX ( this, SVX_RES( FT_DRAW_X ) ),
139 aMtrFldDrawX ( this, SVX_RES( MTR_FLD_DRAW_X ) ),
140 aFtDrawY ( this, SVX_RES( FT_DRAW_Y ) ),
141 aMtrFldDrawY ( this, SVX_RES( MTR_FLD_DRAW_Y ) ),
143 aFlDivision ( this, SVX_RES( FL_DIVISION ) ),
144 aFtDivisionX( this, SVX_RES( FT_DIVISION_X) ),
145 aNumFldDivisionX( this, SVX_RES( NUM_FLD_DIVISION_X ) ),
146 aDivisionPointX( this, SVX_RES( FT_HORZ_POINTS) ),
148 aFtDivisionY( this, SVX_RES( FT_DIVISION_Y) ),
149 aNumFldDivisionY( this, SVX_RES( NUM_FLD_DIVISION_Y ) ),
150 aDivisionPointY( this, SVX_RES( FT_VERT_POINTS) ),
152 aCbxSynchronize ( this, SVX_RES( CBX_SYNCHRONIZE ) ),
153 aGrpDrawGrid ( this, SVX_RES( GRP_DRAWGRID ) ),
155 aGrpSnap ( this, SVX_RES( GRP_SNAP ) ),
156 aCbxSnapHelplines ( this, SVX_RES( CBX_SNAP_HELPLINES ) ),
157 aCbxSnapBorder ( this, SVX_RES( CBX_SNAP_BORDER ) ),
158 aCbxSnapFrame ( this, SVX_RES( CBX_SNAP_FRAME ) ),
159 aCbxSnapPoints ( this, SVX_RES( CBX_SNAP_POINTS ) ),
160 aFtSnapArea ( this, SVX_RES( FT_SNAP_AREA ) ),
161 aMtrFldSnapArea ( this, SVX_RES( MTR_FLD_SNAP_AREA ) ),
163 aSeparatorFL ( this, SVX_RES( FL_SEPARATOR ) ),
165 aGrpOrtho ( this, SVX_RES( GRP_ORTHO ) ),
166 aCbxOrtho ( this, SVX_RES( CBX_ORTHO ) ),
167 aCbxBigOrtho ( this, SVX_RES( CBX_BIGORTHO ) ),
168 aCbxRotate ( this, SVX_RES( CBX_ROTATE ) ),
169 aMtrFldAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
170 aFtBezAngle ( this, SVX_RES( FT_BEZ_ANGLE ) ),
171 aMtrFldBezAngle ( this, SVX_RES( MTR_FLD_BEZ_ANGLE ) ),
173 bAttrModified( sal_False )
175 // This page requires exchange Support
176 SetExchangeSupport();
178 FreeResource();
180 aDivisionPointY.SetText(aDivisionPointX.GetText());
181 // Set Metrics
182 FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
183 long nFirst, nLast, nMin, nMax;
185 lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
186 SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
187 lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
189 lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
190 SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
191 lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
194 aCbxRotate.SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
195 Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
196 aCbxUseGridsnap.SetClickHdl( aLink );
197 aCbxSynchronize.SetClickHdl( aLink );
198 aCbxGridVisible.SetClickHdl( aLink );
199 aMtrFldDrawX.SetModifyHdl(
200 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
201 aMtrFldDrawY.SetModifyHdl(
202 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
203 aNumFldDivisionX.SetModifyHdl(
204 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
205 aNumFldDivisionY.SetModifyHdl(
206 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
208 OUString sFlResolution( aFlResolution.GetDisplayText() );
209 OUString sFtDrawX(aFtDrawX.GetDisplayText());
210 OUString sFtDrawY(aFtDrawY.GetDisplayText());
211 aMtrFldDrawX.SetAccessibleName( sFtDrawX + sFlResolution );
212 aMtrFldDrawY.SetAccessibleName( sFtDrawY + sFlResolution );
213 OUString sFlDivision( aFlDivision.GetDisplayText() );
214 OUString sFtDivisionX(aFtDivisionX.GetDisplayText());
215 OUString sFtDivisionY(aFtDivisionY.GetDisplayText());
216 aNumFldDivisionX.SetAccessibleName( sFtDivisionX + sFlDivision );
217 aNumFldDivisionY.SetAccessibleName( sFtDivisionY + sFlDivision );
220 //------------------------------------------------------------------------
222 SfxTabPage* SvxGridTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
224 return ( new SvxGridTabPage( pParent, rAttrSet ) );
227 //------------------------------------------------------------------------
229 sal_Bool SvxGridTabPage::FillItemSet( SfxItemSet& rCoreSet )
231 if ( bAttrModified )
233 SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
235 aGridItem.bUseGridsnap = aCbxUseGridsnap.IsChecked();
236 aGridItem.bSynchronize = aCbxSynchronize.IsChecked();
237 aGridItem.bGridVisible = aCbxGridVisible.IsChecked();
239 SfxMapUnit eUnit =
240 rCoreSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
241 long nX =GetCoreValue( aMtrFldDrawX, eUnit );
242 long nY = GetCoreValue( aMtrFldDrawY, eUnit );
244 aGridItem.nFldDrawX = (sal_uInt32) nX;
245 aGridItem.nFldDrawY = (sal_uInt32) nY;
246 aGridItem.nFldDivisionX = static_cast<long>(aNumFldDivisionX.GetValue()-1);
247 aGridItem.nFldDivisionY = static_cast<long>(aNumFldDivisionY.GetValue()-1);
249 rCoreSet.Put( aGridItem );
251 return bAttrModified;
254 //------------------------------------------------------------------------
256 void SvxGridTabPage::Reset( const SfxItemSet& rSet )
258 const SfxPoolItem* pAttr = 0;
260 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
261 (const SfxPoolItem**)&pAttr ))
263 const SvxGridItem* pGridAttr = (SvxGridItem*)pAttr;
264 aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
265 aCbxSynchronize.Check( pGridAttr->bSynchronize == 1 );
266 aCbxGridVisible.Check( pGridAttr->bGridVisible == 1 );
268 SfxMapUnit eUnit =
269 rSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
270 SetMetricValue( aMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
271 SetMetricValue( aMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
273 aNumFldDivisionX.SetValue( pGridAttr->nFldDivisionX+1 );
274 aNumFldDivisionY.SetValue( pGridAttr->nFldDivisionY+1 );
277 ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
278 bAttrModified = sal_False;
281 // -----------------------------------------------------------------------
283 void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
285 const SfxPoolItem* pAttr = NULL;
286 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
287 (const SfxPoolItem**)&pAttr ))
289 const SvxGridItem* pGridAttr = (SvxGridItem*) pAttr;
290 aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
292 ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
295 // Metric Change if necessary (as TabPage is in the dialog, where the
296 // metric can be set
297 if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , sal_False,
298 (const SfxPoolItem**)&pAttr ))
300 const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
302 FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
304 if( eFUnit != aMtrFldDrawX.GetUnit() )
306 // Set Metrics
307 long nFirst, nLast, nMin, nMax;
308 long nVal = static_cast<long>(aMtrFldDrawX.Denormalize( aMtrFldDrawX.GetValue( FUNIT_TWIP ) ));
310 lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
311 SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
312 lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
314 aMtrFldDrawX.SetValue( aMtrFldDrawX.Normalize( nVal ), FUNIT_TWIP );
316 nVal = static_cast<long>(aMtrFldDrawY.Denormalize( aMtrFldDrawY.GetValue( FUNIT_TWIP ) ));
317 lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
318 SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
319 lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
320 aMtrFldDrawY.SetValue( aMtrFldDrawY.Normalize( nVal ), FUNIT_TWIP );
326 // -----------------------------------------------------------------------
327 int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
329 if ( _pSet )
330 FillItemSet( *_pSet );
331 return( LEAVE_PAGE );
333 //------------------------------------------------------------------------
334 IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
336 bAttrModified = sal_True;
337 if( aCbxSynchronize.IsChecked() )
339 if(pField == &aMtrFldDrawX)
340 aMtrFldDrawY.SetValue( aMtrFldDrawX.GetValue() );
341 else
342 aMtrFldDrawX.SetValue( aMtrFldDrawY.GetValue() );
344 return 0;
346 //------------------------------------------------------------------------
348 IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
350 if( aCbxRotate.IsChecked() )
351 aMtrFldAngle.Enable();
352 else
353 aMtrFldAngle.Disable();
355 return( 0L );
358 //------------------------------------------------------------------------
360 IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
362 bAttrModified = sal_True;
363 if( aCbxSynchronize.IsChecked() )
365 if(&aNumFldDivisionX == pField)
366 aNumFldDivisionY.SetValue( aNumFldDivisionX.GetValue() );
367 else
368 aNumFldDivisionX.SetValue( aNumFldDivisionY.GetValue() );
370 return 0;
372 //------------------------------------------------------------------------
374 IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
376 bAttrModified = sal_True;
377 return 0;
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */