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 <sfx2/app.hxx>
21 : #include <sfx2/module.hxx>
22 : #include <svl/intitem.hxx>
23 :
24 : #include <svx/svxids.hrc>
25 : #include <svx/dialmgr.hxx>
26 : #include "svx/optgrid.hxx"
27 : #include <svx/dialogs.hrc>
28 : #include "svx/dlgutil.hxx"
29 :
30 : // local functions
31 0 : static void lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
32 : {
33 0 : nFirst = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
34 0 : nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
35 0 : nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
36 0 : nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
37 0 : }
38 :
39 0 : static void lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
40 : {
41 0 : rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
42 0 : rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
43 0 : rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
44 0 : rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
45 0 : }
46 :
47 11048 : SvxOptionsGrid::SvxOptionsGrid() :
48 : nFldDrawX ( 100 ),
49 : nFldDivisionX ( 0 ),
50 : nFldDrawY ( 100 ),
51 : nFldDivisionY ( 0 ),
52 : nFldSnapX ( 100 ),
53 : nFldSnapY ( 100 ),
54 : bUseGridsnap ( false ),
55 : bSynchronize ( true ),
56 : bGridVisible ( false ),
57 11048 : bEqualGrid ( true )
58 : {
59 11048 : }
60 :
61 14650 : SvxOptionsGrid::~SvxOptionsGrid()
62 : {
63 14650 : }
64 :
65 0 : SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
66 : : SvxOptionsGrid()
67 0 : , SfxPoolItem(rItem)
68 : {
69 0 : bUseGridsnap = rItem.bUseGridsnap ;
70 0 : bSynchronize = rItem.bSynchronize ;
71 0 : bGridVisible = rItem.bGridVisible ;
72 0 : bEqualGrid = rItem.bEqualGrid ;
73 0 : nFldDrawX = rItem.nFldDrawX ;
74 0 : nFldDivisionX= rItem.nFldDivisionX;
75 0 : nFldDrawY = rItem.nFldDrawY ;
76 0 : nFldDivisionY= rItem.nFldDivisionY;
77 0 : nFldSnapX = rItem.nFldSnapX ;
78 0 : nFldSnapY = rItem.nFldSnapY ;
79 :
80 0 : };
81 :
82 0 : SfxPoolItem* SvxGridItem::Clone( SfxItemPool* ) const
83 : {
84 0 : return new SvxGridItem( *this );
85 : }
86 :
87 0 : bool SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
88 : {
89 : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
90 :
91 0 : const SvxGridItem& rItem = static_cast<const SvxGridItem&>(rAttr);
92 :
93 0 : return ( bUseGridsnap == rItem.bUseGridsnap &&
94 0 : bSynchronize == rItem.bSynchronize &&
95 0 : bGridVisible == rItem.bGridVisible &&
96 0 : bEqualGrid == rItem.bEqualGrid &&
97 0 : nFldDrawX == rItem.nFldDrawX &&
98 0 : nFldDivisionX== rItem.nFldDivisionX&&
99 0 : nFldDrawY == rItem.nFldDrawY &&
100 0 : nFldDivisionY== rItem.nFldDivisionY&&
101 0 : nFldSnapX == rItem.nFldSnapX &&
102 0 : nFldSnapY == rItem.nFldSnapY );
103 : }
104 :
105 0 : bool SvxGridItem::GetPresentation
106 : (
107 : SfxItemPresentation /*ePres*/,
108 : SfxMapUnit /*eCoreUnit*/,
109 : SfxMapUnit /*ePresUnit*/,
110 : OUString& rText, const IntlWrapper *
111 : ) const
112 : {
113 0 : rText = "SvxGridItem";
114 0 : return true;
115 : }
116 :
117 : // TabPage Screen Settings
118 0 : SvxGridTabPage::SvxGridTabPage( vcl::Window* pParent, const SfxItemSet& rCoreSet) :
119 :
120 : SfxTabPage( pParent, "OptGridPage" , "svx/ui/optgridpage.ui", &rCoreSet ),
121 0 : bAttrModified( false )
122 : {
123 0 : get(pCbxUseGridsnap,"usegridsnap");
124 0 : get(pCbxGridVisible,"gridvisible");
125 0 : get(pMtrFldDrawX,"mtrflddrawx");
126 0 : get(pMtrFldDrawY,"mtrflddrawy");
127 0 : get(pNumFldDivisionX,"numflddivisionx");
128 0 : get(pNumFldDivisionY,"numflddivisiony");
129 0 : get(pCbxSynchronize,"synchronize");
130 :
131 0 : get(pSnapFrames,"snapframes");
132 0 : get(pCbxSnapHelplines,"snaphelplines");
133 0 : get(pCbxSnapBorder,"snapborder");
134 0 : get(pCbxSnapFrame,"snapframe");
135 0 : get(pCbxSnapPoints,"snappoints");
136 0 : get(pMtrFldSnapArea,"mtrfldsnaparea");
137 0 : get(pCbxOrtho,"ortho");
138 0 : get(pCbxBigOrtho,"bigortho");
139 0 : get(pCbxRotate,"rotate");
140 0 : get(pMtrFldAngle,"mtrfldangle");
141 0 : get(pMtrFldBezAngle,"mtrfldbezangle");
142 :
143 : // This page requires exchange Support
144 0 : SetExchangeSupport();
145 :
146 : // Set Metrics
147 0 : FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
148 : long nFirst, nLast, nMin, nMax;
149 :
150 0 : lcl_GetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
151 0 : SetFieldUnit( *pMtrFldDrawX , eFUnit, true );
152 0 : lcl_SetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
153 :
154 0 : lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
155 0 : SetFieldUnit( *pMtrFldDrawY, eFUnit, true );
156 0 : lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
157 :
158 :
159 0 : pCbxRotate->SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
160 0 : Link<> aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
161 0 : pCbxUseGridsnap->SetClickHdl( aLink );
162 0 : pCbxSynchronize->SetClickHdl( aLink );
163 0 : pCbxGridVisible->SetClickHdl( aLink );
164 0 : pMtrFldDrawX->SetModifyHdl(
165 0 : LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
166 0 : pMtrFldDrawY->SetModifyHdl(
167 0 : LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
168 0 : pNumFldDivisionX->SetModifyHdl(
169 0 : LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
170 0 : pNumFldDivisionY->SetModifyHdl(
171 0 : LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
172 0 : }
173 :
174 0 : SvxGridTabPage::~SvxGridTabPage()
175 : {
176 0 : disposeOnce();
177 0 : }
178 :
179 0 : void SvxGridTabPage::dispose()
180 : {
181 0 : pCbxUseGridsnap.clear();
182 0 : pCbxGridVisible.clear();
183 0 : pMtrFldDrawX.clear();
184 0 : pMtrFldDrawY.clear();
185 0 : pNumFldDivisionX.clear();
186 0 : pNumFldDivisionY.clear();
187 0 : pCbxSynchronize.clear();
188 0 : pSnapFrames.clear();
189 0 : pCbxSnapHelplines.clear();
190 0 : pCbxSnapBorder.clear();
191 0 : pCbxSnapFrame.clear();
192 0 : pCbxSnapPoints.clear();
193 0 : pMtrFldSnapArea.clear();
194 0 : pCbxOrtho.clear();
195 0 : pCbxBigOrtho.clear();
196 0 : pCbxRotate.clear();
197 0 : pMtrFldAngle.clear();
198 0 : pMtrFldBezAngle.clear();
199 0 : SfxTabPage::dispose();
200 0 : }
201 :
202 :
203 0 : VclPtr<SfxTabPage> SvxGridTabPage::Create( vcl::Window* pParent, const SfxItemSet& rAttrSet )
204 : {
205 0 : return VclPtr<SvxGridTabPage>::Create( pParent, rAttrSet );
206 : }
207 :
208 :
209 :
210 0 : bool SvxGridTabPage::FillItemSet( SfxItemSet* rCoreSet )
211 : {
212 0 : if ( bAttrModified )
213 : {
214 0 : SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
215 :
216 0 : aGridItem.bUseGridsnap = pCbxUseGridsnap->IsChecked();
217 0 : aGridItem.bSynchronize = pCbxSynchronize->IsChecked();
218 0 : aGridItem.bGridVisible = pCbxGridVisible->IsChecked();
219 :
220 : SfxMapUnit eUnit =
221 0 : rCoreSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
222 0 : long nX =GetCoreValue( *pMtrFldDrawX, eUnit );
223 0 : long nY = GetCoreValue( *pMtrFldDrawY, eUnit );
224 :
225 0 : aGridItem.nFldDrawX = (sal_uInt32) nX;
226 0 : aGridItem.nFldDrawY = (sal_uInt32) nY;
227 0 : aGridItem.nFldDivisionX = static_cast<long>(pNumFldDivisionX->GetValue()-1);
228 0 : aGridItem.nFldDivisionY = static_cast<long>(pNumFldDivisionY->GetValue()-1);
229 :
230 0 : rCoreSet->Put( aGridItem );
231 : }
232 0 : return bAttrModified;
233 : }
234 :
235 :
236 :
237 0 : void SvxGridTabPage::Reset( const SfxItemSet* rSet )
238 : {
239 0 : const SfxPoolItem* pAttr = 0;
240 :
241 0 : if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRID_OPTIONS , false,
242 0 : &pAttr ))
243 : {
244 0 : const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
245 0 : pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
246 0 : pCbxSynchronize->Check( pGridAttr->bSynchronize );
247 0 : pCbxGridVisible->Check( pGridAttr->bGridVisible );
248 :
249 : SfxMapUnit eUnit =
250 0 : rSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
251 0 : SetMetricValue( *pMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
252 0 : SetMetricValue( *pMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
253 :
254 0 : pNumFldDivisionX->SetValue( pGridAttr->nFldDivisionX+1 );
255 0 : pNumFldDivisionY->SetValue( pGridAttr->nFldDivisionY+1 );
256 : }
257 :
258 0 : ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
259 0 : bAttrModified = false;
260 0 : }
261 :
262 :
263 :
264 0 : void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
265 : {
266 0 : const SfxPoolItem* pAttr = NULL;
267 0 : if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , false,
268 0 : &pAttr ))
269 : {
270 0 : const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
271 0 : pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
272 :
273 0 : ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
274 : }
275 :
276 : // Metric Change if necessary (as TabPage is in the dialog, where the
277 : // metric can be set
278 0 : if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC , false,
279 0 : &pAttr ))
280 : {
281 0 : const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
282 :
283 0 : FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
284 :
285 0 : if( eFUnit != pMtrFldDrawX->GetUnit() )
286 : {
287 : // Set Metrics
288 : long nFirst, nLast, nMin, nMax;
289 0 : long nVal = static_cast<long>(pMtrFldDrawX->Denormalize( pMtrFldDrawX->GetValue( FUNIT_TWIP ) ));
290 :
291 0 : lcl_GetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
292 0 : SetFieldUnit( *pMtrFldDrawX, eFUnit, true );
293 0 : lcl_SetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
294 :
295 0 : pMtrFldDrawX->SetValue( pMtrFldDrawX->Normalize( nVal ), FUNIT_TWIP );
296 :
297 0 : nVal = static_cast<long>(pMtrFldDrawY->Denormalize( pMtrFldDrawY->GetValue( FUNIT_TWIP ) ));
298 0 : lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
299 0 : SetFieldUnit(*pMtrFldDrawY, eFUnit, true );
300 0 : lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
301 0 : pMtrFldDrawY->SetValue( pMtrFldDrawY->Normalize( nVal ), FUNIT_TWIP );
302 :
303 : }
304 : }
305 0 : }
306 :
307 :
308 0 : SfxTabPage::sfxpg SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
309 : {
310 0 : if ( _pSet )
311 0 : FillItemSet( _pSet );
312 0 : return LEAVE_PAGE;
313 : }
314 :
315 0 : IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
316 : {
317 0 : bAttrModified = true;
318 0 : if( pCbxSynchronize->IsChecked() )
319 : {
320 0 : if(pField == pMtrFldDrawX)
321 0 : pMtrFldDrawY->SetValue( pMtrFldDrawX->GetValue() );
322 : else
323 0 : pMtrFldDrawX->SetValue( pMtrFldDrawY->GetValue() );
324 : }
325 0 : return 0;
326 : }
327 :
328 :
329 0 : IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
330 : {
331 0 : if( pCbxRotate->IsChecked() )
332 0 : pMtrFldAngle->Enable();
333 : else
334 0 : pMtrFldAngle->Disable();
335 :
336 0 : return 0L;
337 : }
338 :
339 :
340 :
341 0 : IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
342 : {
343 0 : bAttrModified = true;
344 0 : if( pCbxSynchronize->IsChecked() )
345 : {
346 0 : if(pNumFldDivisionX == pField)
347 0 : pNumFldDivisionY->SetValue( pNumFldDivisionX->GetValue() );
348 : else
349 0 : pNumFldDivisionX->SetValue( pNumFldDivisionY->GetValue() );
350 : }
351 0 : return 0;
352 : }
353 :
354 :
355 0 : IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
356 : {
357 0 : bAttrModified = true;
358 0 : return 0;
359 390 : }
360 :
361 :
362 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|