fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / dialog / optgrid.cxx
blob2d2fca69b106483485506f314a3310c98da85752
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 <sfx2/app.hxx>
21 #include <sfx2/module.hxx>
22 #include <svl/intitem.hxx>
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"
30 // local functions
31 static void lcl_GetMinMax(MetricField& rField, long& nFirst, long& nLast, long& nMin, long& nMax)
33 nFirst = static_cast<long>(rField.Denormalize( rField.GetFirst( FUNIT_TWIP ) ));
34 nLast = static_cast<long>(rField.Denormalize( rField.GetLast( FUNIT_TWIP ) ));
35 nMin = static_cast<long>(rField.Denormalize( rField.GetMin( FUNIT_TWIP ) ));
36 nMax = static_cast<long>(rField.Denormalize( rField.GetMax( FUNIT_TWIP ) ));
39 static void lcl_SetMinMax(MetricField& rField, long nFirst, long nLast, long nMin, long nMax)
41 rField.SetFirst( rField.Normalize( nFirst ), FUNIT_TWIP );
42 rField.SetLast( rField.Normalize( nLast ), FUNIT_TWIP );
43 rField.SetMin( rField.Normalize( nMin ), FUNIT_TWIP );
44 rField.SetMax( rField.Normalize( nMax ), FUNIT_TWIP );
47 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 bEqualGrid ( true )
61 SvxOptionsGrid::~SvxOptionsGrid()
65 SvxGridItem::SvxGridItem( const SvxGridItem& rItem )
66 : SvxOptionsGrid()
67 , SfxPoolItem(rItem)
69 bUseGridsnap = rItem.bUseGridsnap ;
70 bSynchronize = rItem.bSynchronize ;
71 bGridVisible = rItem.bGridVisible ;
72 bEqualGrid = rItem.bEqualGrid ;
73 nFldDrawX = rItem.nFldDrawX ;
74 nFldDivisionX= rItem.nFldDivisionX;
75 nFldDrawY = rItem.nFldDrawY ;
76 nFldDivisionY= rItem.nFldDivisionY;
77 nFldSnapX = rItem.nFldSnapX ;
78 nFldSnapY = rItem.nFldSnapY ;
82 SfxPoolItem* SvxGridItem::Clone( SfxItemPool* ) const
84 return new SvxGridItem( *this );
87 bool SvxGridItem::operator==( const SfxPoolItem& rAttr ) const
89 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "different types ");
91 const SvxGridItem& rItem = static_cast<const SvxGridItem&>(rAttr);
93 return ( bUseGridsnap == rItem.bUseGridsnap &&
94 bSynchronize == rItem.bSynchronize &&
95 bGridVisible == rItem.bGridVisible &&
96 bEqualGrid == rItem.bEqualGrid &&
97 nFldDrawX == rItem.nFldDrawX &&
98 nFldDivisionX== rItem.nFldDivisionX&&
99 nFldDrawY == rItem.nFldDrawY &&
100 nFldDivisionY== rItem.nFldDivisionY&&
101 nFldSnapX == rItem.nFldSnapX &&
102 nFldSnapY == rItem.nFldSnapY );
105 bool SvxGridItem::GetPresentation
107 SfxItemPresentation /*ePres*/,
108 SfxMapUnit /*eCoreUnit*/,
109 SfxMapUnit /*ePresUnit*/,
110 OUString& rText, const IntlWrapper *
111 ) const
113 rText = "SvxGridItem";
114 return true;
117 // TabPage Screen Settings
118 SvxGridTabPage::SvxGridTabPage( vcl::Window* pParent, const SfxItemSet& rCoreSet) :
120 SfxTabPage( pParent, "OptGridPage" , "svx/ui/optgridpage.ui", &rCoreSet ),
121 bAttrModified( false )
123 get(pCbxUseGridsnap,"usegridsnap");
124 get(pCbxGridVisible,"gridvisible");
125 get(pMtrFldDrawX,"mtrflddrawx");
126 get(pMtrFldDrawY,"mtrflddrawy");
127 get(pNumFldDivisionX,"numflddivisionx");
128 get(pNumFldDivisionY,"numflddivisiony");
129 get(pCbxSynchronize,"synchronize");
131 get(pSnapFrames,"snapframes");
132 get(pCbxSnapHelplines,"snaphelplines");
133 get(pCbxSnapBorder,"snapborder");
134 get(pCbxSnapFrame,"snapframe");
135 get(pCbxSnapPoints,"snappoints");
136 get(pMtrFldSnapArea,"mtrfldsnaparea");
137 get(pCbxOrtho,"ortho");
138 get(pCbxBigOrtho,"bigortho");
139 get(pCbxRotate,"rotate");
140 get(pMtrFldAngle,"mtrfldangle");
141 get(pMtrFldBezAngle,"mtrfldbezangle");
143 // This page requires exchange Support
144 SetExchangeSupport();
146 // Set Metrics
147 FieldUnit eFUnit = GetModuleFieldUnit( rCoreSet );
148 long nFirst, nLast, nMin, nMax;
150 lcl_GetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
151 SetFieldUnit( *pMtrFldDrawX , eFUnit, true );
152 lcl_SetMinMax(*pMtrFldDrawX , nFirst, nLast, nMin, nMax);
154 lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
155 SetFieldUnit( *pMtrFldDrawY, eFUnit, true );
156 lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
159 pCbxRotate->SetClickHdl( LINK( this, SvxGridTabPage, ClickRotateHdl_Impl ) );
160 Link<> aLink = LINK( this, SvxGridTabPage, ChangeGridsnapHdl_Impl );
161 pCbxUseGridsnap->SetClickHdl( aLink );
162 pCbxSynchronize->SetClickHdl( aLink );
163 pCbxGridVisible->SetClickHdl( aLink );
164 pMtrFldDrawX->SetModifyHdl(
165 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
166 pMtrFldDrawY->SetModifyHdl(
167 LINK( this, SvxGridTabPage, ChangeDrawHdl_Impl ) );
168 pNumFldDivisionX->SetModifyHdl(
169 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
170 pNumFldDivisionY->SetModifyHdl(
171 LINK( this, SvxGridTabPage, ChangeDivisionHdl_Impl ) );
174 SvxGridTabPage::~SvxGridTabPage()
176 disposeOnce();
179 void SvxGridTabPage::dispose()
181 pCbxUseGridsnap.clear();
182 pCbxGridVisible.clear();
183 pMtrFldDrawX.clear();
184 pMtrFldDrawY.clear();
185 pNumFldDivisionX.clear();
186 pNumFldDivisionY.clear();
187 pCbxSynchronize.clear();
188 pSnapFrames.clear();
189 pCbxSnapHelplines.clear();
190 pCbxSnapBorder.clear();
191 pCbxSnapFrame.clear();
192 pCbxSnapPoints.clear();
193 pMtrFldSnapArea.clear();
194 pCbxOrtho.clear();
195 pCbxBigOrtho.clear();
196 pCbxRotate.clear();
197 pMtrFldAngle.clear();
198 pMtrFldBezAngle.clear();
199 SfxTabPage::dispose();
203 VclPtr<SfxTabPage> SvxGridTabPage::Create( vcl::Window* pParent, const SfxItemSet& rAttrSet )
205 return VclPtr<SvxGridTabPage>::Create( pParent, rAttrSet );
210 bool SvxGridTabPage::FillItemSet( SfxItemSet* rCoreSet )
212 if ( bAttrModified )
214 SvxGridItem aGridItem( SID_ATTR_GRID_OPTIONS );
216 aGridItem.bUseGridsnap = pCbxUseGridsnap->IsChecked();
217 aGridItem.bSynchronize = pCbxSynchronize->IsChecked();
218 aGridItem.bGridVisible = pCbxGridVisible->IsChecked();
220 SfxMapUnit eUnit =
221 rCoreSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
222 long nX =GetCoreValue( *pMtrFldDrawX, eUnit );
223 long nY = GetCoreValue( *pMtrFldDrawY, eUnit );
225 aGridItem.nFldDrawX = (sal_uInt32) nX;
226 aGridItem.nFldDrawY = (sal_uInt32) nY;
227 aGridItem.nFldDivisionX = static_cast<long>(pNumFldDivisionX->GetValue()-1);
228 aGridItem.nFldDivisionY = static_cast<long>(pNumFldDivisionY->GetValue()-1);
230 rCoreSet->Put( aGridItem );
232 return bAttrModified;
237 void SvxGridTabPage::Reset( const SfxItemSet* rSet )
239 const SfxPoolItem* pAttr = 0;
241 if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRID_OPTIONS , false,
242 &pAttr ))
244 const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
245 pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
246 pCbxSynchronize->Check( pGridAttr->bSynchronize );
247 pCbxGridVisible->Check( pGridAttr->bGridVisible );
249 SfxMapUnit eUnit =
250 rSet->GetPool()->GetMetric( GetWhich( SID_ATTR_GRID_OPTIONS ) );
251 SetMetricValue( *pMtrFldDrawX , pGridAttr->nFldDrawX, eUnit );
252 SetMetricValue( *pMtrFldDrawY , pGridAttr->nFldDrawY, eUnit );
254 pNumFldDivisionX->SetValue( pGridAttr->nFldDivisionX+1 );
255 pNumFldDivisionY->SetValue( pGridAttr->nFldDivisionY+1 );
258 ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
259 bAttrModified = false;
264 void SvxGridTabPage::ActivatePage( const SfxItemSet& rSet )
266 const SfxPoolItem* pAttr = NULL;
267 if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS , false,
268 &pAttr ))
270 const SvxGridItem* pGridAttr = static_cast<const SvxGridItem*>(pAttr);
271 pCbxUseGridsnap->Check( pGridAttr->bUseGridsnap );
273 ChangeGridsnapHdl_Impl( pCbxUseGridsnap );
276 // Metric Change if necessary (as TabPage is in the dialog, where the
277 // metric can be set
278 if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC , false,
279 &pAttr ))
281 const SfxUInt16Item* pItem = static_cast<const SfxUInt16Item*>(pAttr);
283 FieldUnit eFUnit = (FieldUnit)(long)pItem->GetValue();
285 if( eFUnit != pMtrFldDrawX->GetUnit() )
287 // Set Metrics
288 long nFirst, nLast, nMin, nMax;
289 long nVal = static_cast<long>(pMtrFldDrawX->Denormalize( pMtrFldDrawX->GetValue( FUNIT_TWIP ) ));
291 lcl_GetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
292 SetFieldUnit( *pMtrFldDrawX, eFUnit, true );
293 lcl_SetMinMax(*pMtrFldDrawX, nFirst, nLast, nMin, nMax);
295 pMtrFldDrawX->SetValue( pMtrFldDrawX->Normalize( nVal ), FUNIT_TWIP );
297 nVal = static_cast<long>(pMtrFldDrawY->Denormalize( pMtrFldDrawY->GetValue( FUNIT_TWIP ) ));
298 lcl_GetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
299 SetFieldUnit(*pMtrFldDrawY, eFUnit, true );
300 lcl_SetMinMax(*pMtrFldDrawY, nFirst, nLast, nMin, nMax);
301 pMtrFldDrawY->SetValue( pMtrFldDrawY->Normalize( nVal ), FUNIT_TWIP );
308 SfxTabPage::sfxpg SvxGridTabPage::DeactivatePage( SfxItemSet* _pSet )
310 if ( _pSet )
311 FillItemSet( _pSet );
312 return LEAVE_PAGE;
315 IMPL_LINK( SvxGridTabPage, ChangeDrawHdl_Impl, MetricField *, pField )
317 bAttrModified = true;
318 if( pCbxSynchronize->IsChecked() )
320 if(pField == pMtrFldDrawX)
321 pMtrFldDrawY->SetValue( pMtrFldDrawX->GetValue() );
322 else
323 pMtrFldDrawX->SetValue( pMtrFldDrawY->GetValue() );
325 return 0;
329 IMPL_LINK_NOARG(SvxGridTabPage, ClickRotateHdl_Impl)
331 if( pCbxRotate->IsChecked() )
332 pMtrFldAngle->Enable();
333 else
334 pMtrFldAngle->Disable();
336 return 0L;
341 IMPL_LINK( SvxGridTabPage, ChangeDivisionHdl_Impl, NumericField *, pField )
343 bAttrModified = true;
344 if( pCbxSynchronize->IsChecked() )
346 if(pNumFldDivisionX == pField)
347 pNumFldDivisionY->SetValue( pNumFldDivisionX->GetValue() );
348 else
349 pNumFldDivisionX->SetValue( pNumFldDivisionY->GetValue() );
351 return 0;
355 IMPL_LINK_NOARG(SvxGridTabPage, ChangeGridsnapHdl_Impl)
357 bAttrModified = true;
358 return 0;
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */