Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / cui / source / tabpages / measure.cxx
blobe7a7fbe12fdf111e25eb66c0cef6826465e1b7ab
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 <strings.hrc>
21 #include <dialmgr.hxx>
23 #include <svx/svxids.hrc>
24 #include <svx/dlgutil.hxx>
25 #include <svx/measctrl.hxx>
26 #include <svx/ofaitem.hxx>
27 #include <svx/strarray.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/sxmbritm.hxx>
30 #include <svx/sxmlhitm.hxx>
31 #include <svx/sxmtfitm.hxx>
32 #include <svx/sxmtpitm.hxx>
33 #include <svx/sxmtritm.hxx>
34 #include <svx/sxmuitm.hxx>
35 #include <svtools/unitconv.hxx>
37 #include <measure.hxx>
39 const sal_uInt16 SvxMeasurePage::pRanges[] =
41 SDRATTR_MEASURE_FIRST,
42 SDRATTR_MEASURE_LAST,
46 /*************************************************************************
48 |* Dialog to change measure-attributes
50 \************************************************************************/
51 SvxMeasureDialog::SvxMeasureDialog(weld::Window* pParent, const SfxItemSet& rInAttrs,
52 const SdrView* pSdrView)
53 : SfxSingleTabDialogController(pParent, &rInAttrs)
55 auto xPage = std::make_unique<SvxMeasurePage>(get_content_area(), this, rInAttrs);
57 xPage->SetView(pSdrView);
58 xPage->Construct();
60 SetTabPage(std::move(xPage));
61 m_xDialog->set_title(CuiResId(RID_SVXSTR_DIMENSION_LINE));
64 /*************************************************************************
66 |* Tabpage for changing measure-attributes
68 \************************************************************************/
70 SvxMeasurePage::SvxMeasurePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
71 : SvxTabPage(pPage, pController, "cui/ui/dimensionlinestabpage.ui", "DimensionLinesTabPage", rInAttrs)
72 , rOutAttrs(rInAttrs)
73 , aAttrSet(*rInAttrs.GetPool())
74 , pView(nullptr)
75 , eUnit(MapUnit::Map100thMM)
76 , bPositionModified(false)
77 , m_aCtlPosition(this)
78 , m_xMtrFldLineDist(m_xBuilder->weld_metric_spin_button("MTR_LINE_DIST", FieldUnit::MM))
79 , m_xMtrFldHelplineOverhang(m_xBuilder->weld_metric_spin_button("MTR_FLD_HELPLINE_OVERHANG", FieldUnit::MM))
80 , m_xMtrFldHelplineDist(m_xBuilder->weld_metric_spin_button("MTR_FLD_HELPLINE_DIST", FieldUnit::MM))
81 , m_xMtrFldHelpline1Len(m_xBuilder->weld_metric_spin_button("MTR_FLD_HELPLINE1_LEN", FieldUnit::MM))
82 , m_xMtrFldHelpline2Len(m_xBuilder->weld_metric_spin_button("MTR_FLD_HELPLINE2_LEN", FieldUnit::MM))
83 , m_xTsbBelowRefEdge(m_xBuilder->weld_check_button("TSB_BELOW_REF_EDGE"))
84 , m_xMtrFldDecimalPlaces(m_xBuilder->weld_spin_button("MTR_FLD_DECIMALPLACES"))
85 , m_xTsbAutoPosV(m_xBuilder->weld_check_button("TSB_AUTOPOSV"))
86 , m_xTsbAutoPosH(m_xBuilder->weld_check_button("TSB_AUTOPOSH"))
87 , m_xTsbShowUnit(m_xBuilder->weld_check_button("TSB_SHOW_UNIT"))
88 , m_xLbUnit(m_xBuilder->weld_combo_box("LB_UNIT"))
89 , m_xTsbParallel(m_xBuilder->weld_check_button("TSB_PARALLEL"))
90 , m_xFtAutomatic(m_xBuilder->weld_label("STR_MEASURE_AUTOMATIC"))
91 , m_xCtlPosition(new weld::CustomWeld(*m_xBuilder, "CTL_POSITION", m_aCtlPosition))
92 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
94 m_aCtlPreview.SetAttributes(rInAttrs);
96 FillUnitLB();
98 const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
99 SetFieldUnit( *m_xMtrFldLineDist, eFUnit );
100 SetFieldUnit( *m_xMtrFldHelplineOverhang, eFUnit );
101 SetFieldUnit( *m_xMtrFldHelplineDist, eFUnit );
102 SetFieldUnit( *m_xMtrFldHelpline1Len, eFUnit );
103 SetFieldUnit( *m_xMtrFldHelpline2Len, eFUnit );
104 if( eFUnit == FieldUnit::MM )
106 m_xMtrFldLineDist->set_increments(50, 500, FieldUnit::NONE);
107 m_xMtrFldHelplineOverhang->set_increments(50, 500, FieldUnit::NONE);
108 m_xMtrFldHelplineDist->set_increments(50, 500, FieldUnit::NONE);
109 m_xMtrFldHelpline1Len->set_increments(50, 500, FieldUnit::NONE);
110 m_xMtrFldHelpline2Len->set_increments(50, 500, FieldUnit::NONE);
113 m_xTsbAutoPosV->connect_toggled(LINK( this, SvxMeasurePage, ClickAutoPosHdl_Impl));
114 m_xTsbAutoPosH->connect_toggled(LINK(this, SvxMeasurePage, ClickAutoPosHdl_Impl));
116 Link<weld::MetricSpinButton&,void> aLink(LINK(this, SvxMeasurePage, ChangeAttrEditHdl_Impl));
117 m_xMtrFldLineDist->connect_value_changed(aLink);
118 m_xMtrFldHelplineOverhang->connect_value_changed(aLink);
119 m_xMtrFldHelplineDist->connect_value_changed(aLink);
120 m_xMtrFldHelpline1Len->connect_value_changed(aLink);
121 m_xMtrFldHelpline2Len->connect_value_changed(aLink);
122 m_xMtrFldDecimalPlaces->connect_value_changed(LINK(this, SvxMeasurePage, ChangeAttrSpinHdl_Impl));
123 m_xTsbBelowRefEdge->connect_toggled(LINK(this, SvxMeasurePage, ChangeAttrClickHdl_Impl));
124 m_xTsbParallel->connect_toggled( LINK( this, SvxMeasurePage, ChangeAttrClickHdl_Impl));
125 m_xTsbShowUnit->connect_toggled(LINK(this, SvxMeasurePage, ChangeAttrClickHdl_Impl));
126 m_xLbUnit->connect_changed(LINK(this, SvxMeasurePage, ChangeAttrListBoxHdl_Impl));
129 SvxMeasurePage::~SvxMeasurePage()
131 m_xCtlPreview.reset();
132 m_xCtlPosition.reset();
135 /*************************************************************************
137 |* read the delivered Item-Set
139 \************************************************************************/
141 void SvxMeasurePage::Reset( const SfxItemSet* rAttrs )
143 SfxItemPool* pPool = rAttrs->GetPool();
144 DBG_ASSERT( pPool, "Where is the pool?" );
145 eUnit = pPool->GetMetric( SDRATTR_MEASURELINEDIST );
147 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_MEASURELINEDIST );
149 // SdrMeasureLineDistItem
150 if( pItem == nullptr )
151 pItem = &pPool->GetDefaultItem( SDRATTR_MEASURELINEDIST );
152 SetMetricValue(*m_xMtrFldLineDist, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
153 m_xMtrFldLineDist->save_value();
155 // SdrMeasureHelplineOverhangItem
156 pItem = GetItem( *rAttrs, SDRATTR_MEASUREHELPLINEOVERHANG );
157 if( pItem == nullptr )
158 pItem = &pPool->GetDefaultItem( SDRATTR_MEASUREHELPLINEOVERHANG );
159 SetMetricValue(*m_xMtrFldHelplineOverhang, static_cast<const SdrMetricItem*>(pItem)->GetValue(),
160 eUnit);
161 m_xMtrFldHelplineOverhang->save_value();
163 // SdrMeasureHelplineDistItem
164 pItem = GetItem( *rAttrs, SDRATTR_MEASUREHELPLINEDIST );
165 if( pItem == nullptr )
166 pItem = &pPool->GetDefaultItem( SDRATTR_MEASUREHELPLINEDIST );
167 SetMetricValue(*m_xMtrFldHelplineDist, static_cast<const SdrMetricItem*>(pItem)->GetValue(),
168 eUnit);
169 m_xMtrFldHelplineDist->save_value();
171 // SdrMeasureHelpline1LenItem
172 pItem = GetItem( *rAttrs, SDRATTR_MEASUREHELPLINE1LEN );
173 if( pItem == nullptr )
174 pItem = &pPool->GetDefaultItem( SDRATTR_MEASUREHELPLINE1LEN );
175 SetMetricValue(*m_xMtrFldHelpline1Len, static_cast<const SdrMetricItem*>(pItem)->GetValue(),
176 eUnit);
177 m_xMtrFldHelpline1Len->save_value();
179 // SdrMeasureHelpline2LenItem
180 pItem = GetItem( *rAttrs, SDRATTR_MEASUREHELPLINE2LEN );
181 if( pItem == nullptr )
182 pItem = &pPool->GetDefaultItem( SDRATTR_MEASUREHELPLINE2LEN );
183 SetMetricValue(*m_xMtrFldHelpline2Len, static_cast<const SdrMetricItem*>(pItem)->GetValue(),
184 eUnit);
185 m_xMtrFldHelpline2Len->save_value();
187 // SdrMeasureBelowRefEdgeItem
188 if( rAttrs->GetItemState( SDRATTR_MEASUREBELOWREFEDGE ) != SfxItemState::DONTCARE )
190 m_xTsbBelowRefEdge->set_state( rAttrs->Get( SDRATTR_MEASUREBELOWREFEDGE ).
191 GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
193 else
195 m_xTsbBelowRefEdge->set_state( TRISTATE_INDET );
197 m_xTsbBelowRefEdge->save_state();
199 // SdrMeasureDecimalPlacesItem
200 pItem = GetItem( *rAttrs, SDRATTR_MEASUREDECIMALPLACES );
201 if( pItem == nullptr )
202 pItem = &pPool->GetDefaultItem( SDRATTR_MEASUREDECIMALPLACES );
203 m_xMtrFldDecimalPlaces->set_value(
204 static_cast<const SdrMeasureDecimalPlacesItem*>(pItem)->GetValue());
205 m_xMtrFldDecimalPlaces->save_value();
207 // SdrMeasureTextRota90Item
208 // Attention: negate !
209 if( rAttrs->GetItemState( SDRATTR_MEASURETEXTROTA90 ) != SfxItemState::DONTCARE )
211 m_xTsbParallel->set_state( rAttrs->Get( SDRATTR_MEASURETEXTROTA90 ).
212 GetValue() ? TRISTATE_FALSE : TRISTATE_TRUE );
214 else
216 m_xTsbParallel->set_state( TRISTATE_INDET );
218 m_xTsbParallel->save_state();
220 // SdrMeasureShowUnitItem
221 if( rAttrs->GetItemState( SDRATTR_MEASURESHOWUNIT ) != SfxItemState::DONTCARE )
223 m_xTsbShowUnit->set_state( rAttrs->Get( SDRATTR_MEASURESHOWUNIT ).
224 GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
226 else
228 m_xTsbShowUnit->set_state( TRISTATE_INDET );
230 m_xTsbShowUnit->save_state();
232 // SdrMeasureUnitItem
233 if( rAttrs->GetItemState( SDRATTR_MEASUREUNIT ) != SfxItemState::DONTCARE )
235 long nFieldUnit = static_cast<long>(rAttrs->Get( SDRATTR_MEASUREUNIT ).GetValue());
237 for (sal_Int32 i = 0; i < m_xLbUnit->get_count(); ++i)
239 if (m_xLbUnit->get_id(i).toInt32() == nFieldUnit)
241 m_xLbUnit->set_active(i);
242 break;
246 else
248 m_xLbUnit->set_active(-1);
250 m_xLbUnit->save_value();
252 // Position
253 if ( rAttrs->GetItemState( SDRATTR_MEASURETEXTVPOS ) != SfxItemState::DONTCARE )
255 css::drawing::MeasureTextVertPos eVPos =
256 rAttrs->Get( SDRATTR_MEASURETEXTVPOS ).GetValue();
258 if ( rAttrs->GetItemState( SDRATTR_MEASURETEXTHPOS ) != SfxItemState::DONTCARE )
260 css::drawing::MeasureTextHorzPos eHPos =
261 rAttrs->Get( SDRATTR_MEASURETEXTHPOS ).GetValue();
262 RectPoint eRP = RectPoint::MM;
263 switch( eVPos )
265 case css::drawing::MeasureTextVertPos_EAST:
266 switch( eHPos )
268 case css::drawing::MeasureTextHorzPos_LEFTOUTSIDE: eRP = RectPoint::LT; break;
269 case css::drawing::MeasureTextHorzPos_INSIDE: eRP = RectPoint::MT; break;
270 case css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE: eRP = RectPoint::RT; break;
271 case css::drawing::MeasureTextHorzPos_AUTO: eRP = RectPoint::MT; break;
272 default: break;
274 break;
275 case css::drawing::MeasureTextVertPos_CENTERED:
276 switch( eHPos )
278 case css::drawing::MeasureTextHorzPos_LEFTOUTSIDE: eRP = RectPoint::LM; break;
279 case css::drawing::MeasureTextHorzPos_INSIDE: eRP = RectPoint::MM; break;
280 case css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE: eRP = RectPoint::RM; break;
281 case css::drawing::MeasureTextHorzPos_AUTO: eRP = RectPoint::MM; break;
282 default: break;
284 break;
285 case css::drawing::MeasureTextVertPos_WEST:
286 switch( eHPos )
288 case css::drawing::MeasureTextHorzPos_LEFTOUTSIDE: eRP = RectPoint::LB; break;
289 case css::drawing::MeasureTextHorzPos_INSIDE: eRP = RectPoint::MB; break;
290 case css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE: eRP = RectPoint::RB; break;
291 case css::drawing::MeasureTextHorzPos_AUTO: eRP = RectPoint::MB; break;
292 default: break;
294 break;
295 case css::drawing::MeasureTextVertPos_AUTO:
296 switch( eHPos )
298 case css::drawing::MeasureTextHorzPos_LEFTOUTSIDE: eRP = RectPoint::LM; break;
299 case css::drawing::MeasureTextHorzPos_INSIDE: eRP = RectPoint::MM; break;
300 case css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE: eRP = RectPoint::RM; break;
301 case css::drawing::MeasureTextHorzPos_AUTO: eRP = RectPoint::MM; break;
302 default: break;
304 break;
305 default: ;//prevent warning
308 CTL_STATE nState = CTL_STATE::NONE;
310 if (eHPos == css::drawing::MeasureTextHorzPos_AUTO)
312 m_xTsbAutoPosH->set_state( TRISTATE_TRUE );
313 nState = CTL_STATE::NOHORZ;
316 if (eVPos == css::drawing::MeasureTextVertPos_AUTO)
318 m_xTsbAutoPosV->set_state( TRISTATE_TRUE );
319 nState |= CTL_STATE::NOVERT;
322 m_aCtlPosition.SetState(nState);
323 m_aCtlPosition.SetActualRP(eRP);
327 else
329 m_aCtlPosition.Reset();
330 m_xTsbAutoPosV->set_state( TRISTATE_INDET );
331 m_xTsbAutoPosH->set_state( TRISTATE_INDET );
334 // put the attributes to the preview-control,
335 // otherwise the control don't know about
336 // the settings of the dialog (#67930)
337 ChangeAttrHdl_Impl(m_xTsbShowUnit.get());
338 m_aCtlPreview.SetAttributes(*rAttrs);
340 bPositionModified = false;
343 /*************************************************************************
345 |* Fill the delivered Item-Set with dialogbox-attributes
347 \************************************************************************/
349 bool SvxMeasurePage::FillItemSet( SfxItemSet* rAttrs)
351 bool bModified = false;
352 sal_Int32 nValue;
353 TriState eState;
355 if( m_xMtrFldLineDist->get_value_changed_from_saved() )
357 nValue = GetCoreValue( *m_xMtrFldLineDist, eUnit );
358 rAttrs->Put( makeSdrMeasureLineDistItem( nValue ) );
359 bModified = true;
362 if( m_xMtrFldHelplineOverhang->get_value_changed_from_saved() )
364 nValue = GetCoreValue( *m_xMtrFldHelplineOverhang, eUnit );
365 rAttrs->Put( makeSdrMeasureHelplineOverhangItem( nValue ) );
366 bModified = true;
369 if( m_xMtrFldHelplineDist->get_value_changed_from_saved() )
371 nValue = GetCoreValue( *m_xMtrFldHelplineDist, eUnit );
372 rAttrs->Put( makeSdrMeasureHelplineDistItem( nValue ) );
373 bModified = true;
376 if( m_xMtrFldHelpline1Len->get_value_changed_from_saved() )
378 nValue = GetCoreValue( *m_xMtrFldHelpline1Len, eUnit );
379 rAttrs->Put( makeSdrMeasureHelpline1LenItem( nValue ) );
380 bModified = true;
383 if( m_xMtrFldHelpline2Len->get_value_changed_from_saved() )
385 nValue = GetCoreValue( *m_xMtrFldHelpline2Len, eUnit );
386 rAttrs->Put( makeSdrMeasureHelpline2LenItem( nValue ) );
387 bModified = true;
390 eState = m_xTsbBelowRefEdge->get_state();
391 if( m_xTsbBelowRefEdge->get_state_changed_from_saved() )
393 rAttrs->Put( SdrMeasureBelowRefEdgeItem( TRISTATE_TRUE == eState ) );
394 bModified = true;
397 if( m_xMtrFldDecimalPlaces->get_value_changed_from_saved() )
399 nValue = m_xMtrFldDecimalPlaces->get_value();
400 rAttrs->Put(
401 SdrMeasureDecimalPlacesItem(
402 sal::static_int_cast< sal_Int16 >( nValue ) ) );
403 bModified = true;
406 eState = m_xTsbParallel->get_state();
407 if( m_xTsbParallel->get_state_changed_from_saved() )
409 rAttrs->Put( SdrMeasureTextRota90Item( TRISTATE_FALSE == eState ) );
410 bModified = true;
413 eState = m_xTsbShowUnit->get_state();
414 if( m_xTsbShowUnit->get_state_changed_from_saved() )
416 rAttrs->Put( SdrYesNoItem(SDRATTR_MEASURESHOWUNIT, TRISTATE_TRUE == eState ) );
417 bModified = true;
420 int nPos = m_xLbUnit->get_active();
421 if( m_xLbUnit->get_value_changed_from_saved() )
423 if (nPos != -1)
425 sal_uInt16 nFieldUnit = m_xLbUnit->get_id(nPos).toUInt32();
426 FieldUnit _eUnit = static_cast<FieldUnit>(nFieldUnit);
427 rAttrs->Put( SdrMeasureUnitItem( _eUnit ) );
428 bModified = true;
432 if( bPositionModified )
434 // Position
435 css::drawing::MeasureTextVertPos eVPos, eOldVPos;
436 css::drawing::MeasureTextHorzPos eHPos, eOldHPos;
438 RectPoint eRP = m_aCtlPosition.GetActualRP();
439 switch( eRP )
441 default:
442 case RectPoint::LT: eVPos = css::drawing::MeasureTextVertPos_EAST;
443 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
444 case RectPoint::LM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
445 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
446 case RectPoint::LB: eVPos = css::drawing::MeasureTextVertPos_WEST;
447 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
448 case RectPoint::MT: eVPos = css::drawing::MeasureTextVertPos_EAST;
449 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
450 case RectPoint::MM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
451 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
452 case RectPoint::MB: eVPos = css::drawing::MeasureTextVertPos_WEST;
453 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
454 case RectPoint::RT: eVPos = css::drawing::MeasureTextVertPos_EAST;
455 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
456 case RectPoint::RM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
457 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
458 case RectPoint::RB: eVPos = css::drawing::MeasureTextVertPos_WEST;
459 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
461 if (m_xTsbAutoPosH->get_state() == TRISTATE_TRUE)
462 eHPos = css::drawing::MeasureTextHorzPos_AUTO;
464 if (m_xTsbAutoPosV->get_state() == TRISTATE_TRUE)
465 eVPos = css::drawing::MeasureTextVertPos_AUTO;
467 if ( rAttrs->GetItemState( SDRATTR_MEASURETEXTVPOS ) != SfxItemState::DONTCARE )
469 eOldVPos = rOutAttrs.Get(SDRATTR_MEASURETEXTVPOS).GetValue();
470 if( eOldVPos != eVPos )
472 rAttrs->Put( SdrMeasureTextVPosItem( eVPos ) );
473 bModified = true;
476 else
478 rAttrs->Put( SdrMeasureTextVPosItem( eVPos ) );
479 bModified = true;
482 if ( rAttrs->GetItemState( SDRATTR_MEASURETEXTHPOS ) != SfxItemState::DONTCARE )
484 eOldHPos = rOutAttrs.Get( SDRATTR_MEASURETEXTHPOS ).GetValue();
485 if( eOldHPos != eHPos )
487 rAttrs->Put( SdrMeasureTextHPosItem( eHPos ) );
488 bModified = true;
491 else
493 rAttrs->Put( SdrMeasureTextHPosItem( eHPos ) );
494 bModified = true;
498 return bModified;
501 /*************************************************************************
503 |* The View have to set at the measure-object to be able to notify
504 |* unit and floatingpoint-values
506 \************************************************************************/
508 void SvxMeasurePage::Construct()
510 DBG_ASSERT( pView, "No valid View transferred!" );
512 // TTTT
513 // pMeasureObj is member of SvxXMeasurePreview and can only be accessed due to
514 // SvxMeasurePage being a friend. It has its own SdrModel (also in SvxXMeasurePreview)
515 // and 'setting' the SdrModel is a hack. The comment above about 'notify unit and
516 // floatingpoint-values' is not clear, but has to be done another way - if needed.
517 // Checked on original aw080, is just commented out there, too.
519 m_aCtlPreview.Invalidate();
522 std::unique_ptr<SfxTabPage> SvxMeasurePage::Create(weld::Container* pPage, weld::DialogController* pController,
523 const SfxItemSet* rAttrs)
525 return std::make_unique<SvxMeasurePage>(pPage, pController, *rAttrs);
528 void SvxMeasurePage::PointChanged(weld::DrawingArea* pDrawingArea, RectPoint /*eRP*/)
530 ChangeAttrHdl_Impl(pDrawingArea);
533 IMPL_LINK( SvxMeasurePage, ClickAutoPosHdl_Impl, weld::ToggleButton&, rBox, void )
535 if (m_xTsbAutoPosH->get_state() == TRISTATE_TRUE)
537 switch( m_aCtlPosition.GetActualRP() )
539 case RectPoint::LT:
540 case RectPoint::RT:
541 m_aCtlPosition.SetActualRP( RectPoint::MT );
542 break;
544 case RectPoint::LM:
545 case RectPoint::RM:
546 m_aCtlPosition.SetActualRP( RectPoint::MM );
547 break;
549 case RectPoint::LB:
550 case RectPoint::RB:
551 m_aCtlPosition.SetActualRP( RectPoint::MB );
552 break;
553 default: ;//prevent warning
556 if (m_xTsbAutoPosV->get_state() == TRISTATE_TRUE)
558 switch( m_aCtlPosition.GetActualRP() )
560 case RectPoint::LT:
561 case RectPoint::LB:
562 m_aCtlPosition.SetActualRP( RectPoint::LM );
563 break;
565 case RectPoint::MT:
566 case RectPoint::MB:
567 m_aCtlPosition.SetActualRP( RectPoint::MM );
568 break;
570 case RectPoint::RT:
571 case RectPoint::RB:
572 m_aCtlPosition.SetActualRP( RectPoint::RM );
573 break;
574 default: ;//prevent warning
577 ChangeAttrHdl_Impl(&rBox);
580 IMPL_LINK(SvxMeasurePage, ChangeAttrClickHdl_Impl, weld::ToggleButton&, r, void)
582 ChangeAttrHdl_Impl(&r);
585 IMPL_LINK(SvxMeasurePage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, rBox, void)
587 ChangeAttrHdl_Impl(&rBox);
590 IMPL_LINK(SvxMeasurePage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, rBox, void)
592 ChangeAttrHdl_Impl(&rBox);
595 IMPL_LINK( SvxMeasurePage, ChangeAttrSpinHdl_Impl, weld::SpinButton&, rBox, void )
597 ChangeAttrHdl_Impl(&rBox);
600 void SvxMeasurePage::ChangeAttrHdl_Impl( void const * p )
602 if (p == m_xMtrFldLineDist.get())
604 sal_Int32 nValue = GetCoreValue( *m_xMtrFldLineDist, eUnit );
605 aAttrSet.Put( makeSdrMeasureLineDistItem( nValue ) );
608 if (p == m_xMtrFldHelplineOverhang.get())
610 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHelplineOverhang, eUnit );
611 aAttrSet.Put( makeSdrMeasureHelplineOverhangItem( nValue) );
614 if (p == m_xMtrFldHelplineDist.get())
616 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHelplineDist, eUnit );
617 aAttrSet.Put( makeSdrMeasureHelplineDistItem( nValue) );
620 if (p == m_xMtrFldHelpline1Len.get())
622 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHelpline1Len, eUnit );
623 aAttrSet.Put( makeSdrMeasureHelpline1LenItem( nValue ) );
626 if (p == m_xMtrFldHelpline2Len.get())
628 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHelpline2Len, eUnit );
629 aAttrSet.Put( makeSdrMeasureHelpline2LenItem( nValue ) );
632 if (p == m_xTsbBelowRefEdge.get())
634 TriState eState = m_xTsbBelowRefEdge->get_state();
635 if( eState != TRISTATE_INDET )
636 aAttrSet.Put( SdrMeasureBelowRefEdgeItem( TRISTATE_TRUE == eState ) );
639 if (p == m_xMtrFldDecimalPlaces.get())
641 sal_Int16 nValue = sal::static_int_cast< sal_Int16 >(
642 m_xMtrFldDecimalPlaces->get_value() );
643 aAttrSet.Put( SdrMeasureDecimalPlacesItem( nValue ) );
646 if (p == m_xTsbParallel.get())
648 TriState eState = m_xTsbParallel->get_state();
649 if( eState != TRISTATE_INDET )
650 aAttrSet.Put( SdrMeasureTextRota90Item( TRISTATE_FALSE == eState ) );
653 if (p == m_xTsbShowUnit.get())
655 TriState eState = m_xTsbShowUnit->get_state();
656 if( eState != TRISTATE_INDET )
657 aAttrSet.Put( SdrYesNoItem( SDRATTR_MEASURESHOWUNIT, TRISTATE_TRUE == eState ) );
660 if (p == m_xLbUnit.get())
662 int nPos = m_xLbUnit->get_active();
663 if (nPos != -1)
665 sal_uInt16 nFieldUnit = m_xLbUnit->get_id(nPos).toUInt32();
666 FieldUnit _eUnit = static_cast<FieldUnit>(nFieldUnit);
667 aAttrSet.Put( SdrMeasureUnitItem( _eUnit ) );
671 if (p == m_xTsbAutoPosV.get() || p == m_xTsbAutoPosH.get() || p == m_aCtlPosition.GetDrawingArea())
673 bPositionModified = true;
675 // Position
676 RectPoint eRP = m_aCtlPosition.GetActualRP();
677 css::drawing::MeasureTextVertPos eVPos;
678 css::drawing::MeasureTextHorzPos eHPos;
680 switch( eRP )
682 default:
683 case RectPoint::LT: eVPos = css::drawing::MeasureTextVertPos_EAST;
684 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
685 case RectPoint::LM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
686 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
687 case RectPoint::LB: eVPos = css::drawing::MeasureTextVertPos_WEST;
688 eHPos = css::drawing::MeasureTextHorzPos_LEFTOUTSIDE; break;
689 case RectPoint::MT: eVPos = css::drawing::MeasureTextVertPos_EAST;
690 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
691 case RectPoint::MM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
692 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
693 case RectPoint::MB: eVPos = css::drawing::MeasureTextVertPos_WEST;
694 eHPos = css::drawing::MeasureTextHorzPos_INSIDE; break;
695 case RectPoint::RT: eVPos = css::drawing::MeasureTextVertPos_EAST;
696 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
697 case RectPoint::RM: eVPos = css::drawing::MeasureTextVertPos_CENTERED;
698 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
699 case RectPoint::RB: eVPos = css::drawing::MeasureTextVertPos_WEST;
700 eHPos = css::drawing::MeasureTextHorzPos_RIGHTOUTSIDE; break;
703 CTL_STATE nState = CTL_STATE::NONE;
705 if (m_xTsbAutoPosH->get_state() == TRISTATE_TRUE)
707 eHPos = css::drawing::MeasureTextHorzPos_AUTO;
708 nState = CTL_STATE::NOHORZ;
711 if (m_xTsbAutoPosV->get_state() == TRISTATE_TRUE)
713 eVPos = css::drawing::MeasureTextVertPos_AUTO;
714 nState |= CTL_STATE::NOVERT;
717 if (p == m_xTsbAutoPosV.get() || p == m_xTsbAutoPosH.get())
718 m_aCtlPosition.SetState( nState );
720 aAttrSet.Put( SdrMeasureTextVPosItem( eVPos ) );
721 aAttrSet.Put( SdrMeasureTextHPosItem( eHPos ) );
724 m_aCtlPreview.SetAttributes(aAttrSet);
725 m_aCtlPreview.Invalidate();
728 void SvxMeasurePage::FillUnitLB()
730 // fill ListBox with metrics
732 FieldUnit nUnit = FieldUnit::NONE;
733 OUString aStrMetric(m_xFtAutomatic->get_label());
734 m_xLbUnit->append(OUString::number(sal_uInt32(nUnit)), aStrMetric);
736 for( sal_uInt32 i = 0; i < SvxFieldUnitTable::Count(); ++i )
738 aStrMetric = SvxFieldUnitTable::GetString(i);
739 nUnit = SvxFieldUnitTable::GetValue(i);
740 m_xLbUnit->append(OUString::number(sal_uInt32(nUnit)), aStrMetric);
744 void SvxMeasurePage::PageCreated(const SfxAllItemSet& aSet)
746 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
748 if (pOfaPtrItem)
749 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()));
751 Construct();
754 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */