Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <tools/shl.hxx>
21 : #include <sfx2/app.hxx>
22 : #include <sfx2/module.hxx>
23 : #include <svl/intitem.hxx>
24 :
25 : #define _SVX_OPTGRID_CXX
26 :
27 : #include <svx/svxids.hrc>
28 : #include <svx/dialmgr.hxx>
29 : #include "svx/optgrid.hxx"
30 : #include <svx/dialogs.hrc>
31 : #include "optgrid.hrc"
32 : #include "svx/dlgutil.hxx"
33 :
34 : // local functions
35 0 : static void lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
36 : {
37 0 : nFirst = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
38 0 : nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
39 0 : nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
40 0 : nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
41 0 : }
42 :
43 0 : static void lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
44 : {
45 0 : rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
46 0 : rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
47 0 : rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
48 0 : rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
49 0 : }
50 :
51 1129 : SvxOptionsGrid::SvxOptionsGrid() :
52 : nFldDrawX ( 100 ),
53 : nFldDivisionX ( 0 ),
54 : nFldDrawY ( 100 ),
55 : nFldDivisionY ( 0 ),
56 : nFldSnapX ( 100 ),
57 : nFldSnapY ( 100 ),
58 : bUseGridsnap ( 0 ),
59 : bSynchronize ( 1 ),
60 : bGridVisible ( 0 ),
61 1129 : bEqualGrid ( 1 )
62 : {
63 1129 : }
64 :
65 1194 : SvxOptionsGrid::~SvxOptionsGrid()
66 : {
67 1194 : }
68 :
69 0 : SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
70 : : SvxOptionsGrid()
71 0 : , SfxPoolItem(rItem)
72 : {
73 0 : bUseGridsnap = rItem.bUseGridsnap ;
74 0 : bSynchronize = rItem.bSynchronize ;
75 0 : bGridVisible = rItem.bGridVisible ;
76 0 : bEqualGrid = rItem.bEqualGrid ;
77 0 : nFldDrawX = rItem.nFldDrawX ;
78 0 : nFldDivisionX= rItem.nFldDivisionX;
79 0 : nFldDrawY = rItem.nFldDrawY ;
80 0 : nFldDivisionY= rItem.nFldDivisionY;
81 0 : nFldSnapX = rItem.nFldSnapX ;
82 0 : nFldSnapY = rItem.nFldSnapY ;
83 :
84 0 : };
85 :
86 0 : SfxPoolItem* SvxGridItem::Clone( SfxItemPool* ) const
87 : {
88 0 : return new SvxGridItem( *this );
89 : }
90 :
91 0 : int SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
92 : {
93 : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
94 :
95 0 : const SvxGridItem& rItem = (const SvxGridItem&) rAttr;
96 :
97 : return ( bUseGridsnap == rItem.bUseGridsnap &&
98 : bSynchronize == rItem.bSynchronize &&
99 : bGridVisible == rItem.bGridVisible &&
100 : bEqualGrid == rItem.bEqualGrid &&
101 : nFldDrawX == rItem.nFldDrawX &&
102 : nFldDivisionX== rItem.nFldDivisionX&&
103 : nFldDrawY == rItem.nFldDrawY &&
104 : nFldDivisionY== rItem.nFldDivisionY&&
105 : nFldSnapX == rItem.nFldSnapX &&
106 0 : nFldSnapY == rItem.nFldSnapY );
107 : }
108 :
109 0 : SfxItemPresentation SvxGridItem::GetPresentation
110 : (
111 : SfxItemPresentation ePres,
112 : SfxMapUnit /*eCoreUnit*/,
113 : SfxMapUnit /*ePresUnit*/,
114 : String& rText, const IntlWrapper *
115 : ) const
116 : {
117 0 : switch ( ePres )
118 : {
119 : case SFX_ITEM_PRESENTATION_NONE:
120 0 : rText.Erase();
121 0 : return SFX_ITEM_PRESENTATION_NONE;
122 : case SFX_ITEM_PRESENTATION_NAMELESS:
123 : case SFX_ITEM_PRESENTATION_COMPLETE:
124 0 : rText = rtl::OUString("SvxGridItem");
125 0 : return ePres;
126 : default:
127 0 : return SFX_ITEM_PRESENTATION_NONE;
128 : }
129 : }
130 :
131 : // TabPage Screen Settings
132 0 : SvxGridTabPage::SvxGridTabPage( Window* pParent, const SfxItemSet& rCoreSet) :
133 :
134 0 : SfxTabPage( pParent, SVX_RES( RID_SVXPAGE_GRID ), rCoreSet ),
135 :
136 0 : aCbxUseGridsnap ( this, SVX_RES( CBX_USE_GRIDSNAP ) ),
137 0 : aCbxGridVisible ( this, SVX_RES( CBX_GRID_VISIBLE ) ),
138 :
139 0 : aFlResolution ( this, SVX_RES( FL_RESOLUTION ) ),
140 0 : aFtDrawX ( this, SVX_RES( FT_DRAW_X ) ),
141 0 : aMtrFldDrawX ( this, SVX_RES( MTR_FLD_DRAW_X ) ),
142 0 : aFtDrawY ( this, SVX_RES( FT_DRAW_Y ) ),
143 0 : aMtrFldDrawY ( this, SVX_RES( MTR_FLD_DRAW_Y ) ),
144 :
145 0 : aFlDivision ( this, SVX_RES( FL_DIVISION ) ),
146 0 : aFtDivisionX( this, SVX_RES( FT_DIVISION_X) ),
147 0 : aNumFldDivisionX( this, SVX_RES( NUM_FLD_DIVISION_X ) ),
148 0 : aDivisionPointX( this, SVX_RES( FT_HORZ_POINTS) ),
149 :
150 0 : aFtDivisionY( this, SVX_RES( FT_DIVISION_Y) ),
151 0 : aNumFldDivisionY( this, SVX_RES( NUM_FLD_DIVISION_Y ) ),
152 0 : aDivisionPointY( this, SVX_RES( FT_VERT_POINTS) ),
153 :
154 0 : aCbxSynchronize ( this, SVX_RES( CBX_SYNCHRONIZE ) ),
155 0 : aGrpDrawGrid ( this, SVX_RES( GRP_DRAWGRID ) ),
156 :
157 0 : aGrpSnap ( this, SVX_RES( GRP_SNAP ) ),
158 0 : aCbxSnapHelplines ( this, SVX_RES( CBX_SNAP_HELPLINES ) ),
159 0 : aCbxSnapBorder ( this, SVX_RES( CBX_SNAP_BORDER ) ),
160 0 : aCbxSnapFrame ( this, SVX_RES( CBX_SNAP_FRAME ) ),
161 0 : aCbxSnapPoints ( this, SVX_RES( CBX_SNAP_POINTS ) ),
162 0 : aFtSnapArea ( this, SVX_RES( FT_SNAP_AREA ) ),
163 0 : aMtrFldSnapArea ( this, SVX_RES( MTR_FLD_SNAP_AREA ) ),
164 :
165 0 : aSeparatorFL ( this, SVX_RES( FL_SEPARATOR ) ),
166 :
167 0 : aGrpOrtho ( this, SVX_RES( GRP_ORTHO ) ),
168 0 : aCbxOrtho ( this, SVX_RES( CBX_ORTHO ) ),
169 0 : aCbxBigOrtho ( this, SVX_RES( CBX_BIGORTHO ) ),
170 0 : aCbxRotate ( this, SVX_RES( CBX_ROTATE ) ),
171 0 : aMtrFldAngle ( this, SVX_RES( MTR_FLD_ANGLE ) ),
172 0 : aFtBezAngle ( this, SVX_RES( FT_BEZ_ANGLE ) ),
173 0 : aMtrFldBezAngle ( this, SVX_RES( MTR_FLD_BEZ_ANGLE ) ),
174 :
175 0 : bAttrModified( sal_False )
176 : {
177 : // This page requires exchange Support
178 0 : SetExchangeSupport();
179 :
180 0 : FreeResource();
181 :
182 0 : aDivisionPointY.SetText(aDivisionPointX.GetText());
183 : // Set Metrics
184 0 : FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
185 : long nFirst, nLast, nMin, nMax;
186 :
187 0 : lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
188 0 : SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
189 0 : lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
190 :
191 0 : lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
192 0 : SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
193 0 : lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
194 :
195 :
196 0 : aCbxRotate.SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
197 0 : Link aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
198 0 : aCbxUseGridsnap.SetClickHdl( aLink );
199 0 : aCbxSynchronize.SetClickHdl( aLink );
200 0 : aCbxGridVisible.SetClickHdl( aLink );
201 : aMtrFldDrawX.SetModifyHdl(
202 0 : LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
203 : aMtrFldDrawY.SetModifyHdl(
204 0 : LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
205 : aNumFldDivisionX.SetModifyHdl(
206 0 : LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
207 : aNumFldDivisionY.SetModifyHdl(
208 0 : LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
209 :
210 0 : ::rtl::OUString sFlResolution( aFlResolution.GetDisplayText() );
211 0 : ::rtl::OUString sFtDrawX(aFtDrawX.GetDisplayText());
212 0 : ::rtl::OUString sFtDrawY(aFtDrawY.GetDisplayText());
213 0 : aMtrFldDrawX.SetAccessibleName( sFtDrawX + sFlResolution );
214 0 : aMtrFldDrawY.SetAccessibleName( sFtDrawY + sFlResolution );
215 0 : ::rtl::OUString sFlDivision( aFlDivision.GetDisplayText() );
216 0 : ::rtl::OUString sFtDivisionX(aFtDivisionX.GetDisplayText());
217 0 : ::rtl::OUString sFtDivisionY(aFtDivisionY.GetDisplayText());
218 0 : aNumFldDivisionX.SetAccessibleName( sFtDivisionX + sFlDivision );
219 0 : aNumFldDivisionY.SetAccessibleName( sFtDivisionY + sFlDivision );
220 0 : }
221 :
222 : //------------------------------------------------------------------------
223 :
224 0 : SfxTabPage* SvxGridTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
225 : {
226 0 : return ( new SvxGridTabPage( pParent, rAttrSet ) );
227 : }
228 :
229 : //------------------------------------------------------------------------
230 :
231 0 : sal_Bool SvxGridTabPage::FillItemSet( SfxItemSet& rCoreSet )
232 : {
233 0 : if ( bAttrModified )
234 : {
235 0 : SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
236 :
237 0 : aGridItem.bUseGridsnap = aCbxUseGridsnap.IsChecked();
238 0 : aGridItem.bSynchronize = aCbxSynchronize.IsChecked();
239 0 : aGridItem.bGridVisible = aCbxGridVisible.IsChecked();
240 :
241 : SfxMapUnit eUnit =
242 0 : rCoreSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
243 0 : long nX =GetCoreValue( aMtrFldDrawX, eUnit );
244 0 : long nY = GetCoreValue( aMtrFldDrawY, eUnit );
245 :
246 0 : aGridItem.nFldDrawX = (sal_uInt32) nX;
247 0 : aGridItem.nFldDrawY = (sal_uInt32) nY;
248 0 : aGridItem.nFldDivisionX = static_cast<long>(aNumFldDivisionX.GetValue()-1);
249 0 : aGridItem.nFldDivisionY = static_cast<long>(aNumFldDivisionY.GetValue()-1);
250 :
251 0 : rCoreSet.Put( aGridItem );
252 : }
253 0 : return bAttrModified;
254 : }
255 :
256 : //------------------------------------------------------------------------
257 :
258 0 : void SvxGridTabPage::Reset( const SfxItemSet& rSet )
259 : {
260 0 : const SfxPoolItem* pAttr = 0;
261 :
262 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
263 0 : (const SfxPoolItem**)&pAttr ))
264 : {
265 0 : const SvxGridItem* pGridAttr = (SvxGridItem*)pAttr;
266 0 : aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
267 0 : aCbxSynchronize.Check( pGridAttr->bSynchronize == 1 );
268 0 : aCbxGridVisible.Check( pGridAttr->bGridVisible == 1 );
269 :
270 : SfxMapUnit eUnit =
271 0 : rSet.GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
272 0 : SetMetricValue( aMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
273 0 : SetMetricValue( aMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
274 :
275 0 : aNumFldDivisionX.SetValue( pGridAttr->nFldDivisionX+1 );
276 0 : aNumFldDivisionY.SetValue( pGridAttr->nFldDivisionY+1 );
277 : }
278 :
279 0 : ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
280 0 : bAttrModified = sal_False;
281 0 : }
282 :
283 : // -----------------------------------------------------------------------
284 :
285 0 : void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
286 : {
287 0 : const SfxPoolItem* pAttr = NULL;
288 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , sal_False,
289 0 : (const SfxPoolItem**)&pAttr ))
290 : {
291 0 : const SvxGridItem* pGridAttr = (SvxGridItem*) pAttr;
292 0 : aCbxUseGridsnap.Check( pGridAttr->bUseGridsnap == 1 );
293 :
294 0 : ChangeGridsnapHdl_Impl( &aCbxUseGridsnap );
295 : }
296 :
297 : // Metric Change if necessary (as TabPage is in the dialog, where the
298 : // metric can be set
299 0 : if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_METRIC , sal_False,
300 0 : (const SfxPoolItem**)&pAttr ))
301 : {
302 0 : const SfxUInt16Item* pItem = (SfxUInt16Item*) pAttr;
303 :
304 0 : FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
305 :
306 0 : if( eFUnit != aMtrFldDrawX.GetUnit() )
307 : {
308 : // Set Metrics
309 : long nFirst, nLast, nMin, nMax;
310 0 : long nVal = static_cast<long>(aMtrFldDrawX.Denormalize( aMtrFldDrawX.GetValue( FUNIT_TWIP ) ));
311 :
312 0 : lcl_GetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
313 0 : SetFieldUnit( aMtrFldDrawX, eFUnit, sal_True );
314 0 : lcl_SetMinMax(aMtrFldDrawX, nFirst, nLast, nMin, nMax);
315 :
316 0 : aMtrFldDrawX.SetValue( aMtrFldDrawX.Normalize( nVal ), FUNIT_TWIP );
317 :
318 0 : nVal = static_cast<long>(aMtrFldDrawY.Denormalize( aMtrFldDrawY.GetValue( FUNIT_TWIP ) ));
319 0 : lcl_GetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
320 0 : SetFieldUnit( aMtrFldDrawY, eFUnit, sal_True );
321 0 : lcl_SetMinMax(aMtrFldDrawY, nFirst, nLast, nMin, nMax);
322 0 : aMtrFldDrawY.SetValue( aMtrFldDrawY.Normalize( nVal ), FUNIT_TWIP );
323 :
324 : }
325 : }
326 0 : }
327 :
328 : // -----------------------------------------------------------------------
329 0 : int SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
330 : {
331 0 : if ( _pSet )
332 0 : FillItemSet( *_pSet );
333 0 : return( LEAVE_PAGE );
334 : }
335 : //------------------------------------------------------------------------
336 0 : IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
337 : {
338 0 : bAttrModified = sal_True;
339 0 : if( aCbxSynchronize.IsChecked() )
340 : {
341 0 : if(pField == &aMtrFldDrawX)
342 0 : aMtrFldDrawY.SetValue( aMtrFldDrawX.GetValue() );
343 : else
344 0 : aMtrFldDrawX.SetValue( aMtrFldDrawY.GetValue() );
345 : }
346 0 : return 0;
347 : }
348 : //------------------------------------------------------------------------
349 :
350 0 : IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
351 : {
352 0 : if( aCbxRotate.IsChecked() )
353 0 : aMtrFldAngle.Enable();
354 : else
355 0 : aMtrFldAngle.Disable();
356 :
357 0 : return( 0L );
358 : }
359 :
360 : //------------------------------------------------------------------------
361 :
362 0 : IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
363 : {
364 0 : bAttrModified = sal_True;
365 0 : if( aCbxSynchronize.IsChecked() )
366 : {
367 0 : if(&aNumFldDivisionX == pField)
368 0 : aNumFldDivisionY.SetValue( aNumFldDivisionX.GetValue() );
369 : else
370 0 : aNumFldDivisionX.SetValue( aNumFldDivisionY.GetValue() );
371 : }
372 0 : return 0;
373 : }
374 : //------------------------------------------------------------------------
375 :
376 0 : IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
377 : {
378 0 : bAttrModified = sal_True;
379 0 : return 0;
380 57 : }
381 :
382 :
383 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|