workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / cui / source / tabpages / connect.cxx
blobfa7109844fec51f02df09c0bc5be6fcbef40f47d
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/connctrl.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/dlgutil.hxx>
26 #include <svx/ofaitem.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/sxekitm.hxx>
30 #include <svx/sxelditm.hxx>
31 #include <svx/sxenditm.hxx>
32 #include <svtools/unitconv.hxx>
34 #include <connect.hxx>
36 const WhichRangesContainer SvxConnectionPage::pRanges(
37 svl::Items<SDRATTR_EDGE_FIRST, SDRATTR_EDGE_LAST>);
39 /*************************************************************************
41 |* dialog for changing connectors
43 \************************************************************************/
44 SvxConnectionDialog::SvxConnectionDialog(weld::Window* pParent, const SfxItemSet& rInAttrs, const SdrView* pSdrView)
45 : SfxSingleTabDialogController(pParent, &rInAttrs)
47 auto xPage = std::make_unique<SvxConnectionPage>(get_content_area(), this, rInAttrs);
49 xPage->SetView(pSdrView);
50 xPage->Construct();
52 SetTabPage(std::move(xPage));
53 m_xDialog->set_title(CuiResId(RID_CUISTR_CONNECTOR));
56 /*************************************************************************
58 |* page for changing connectors
60 \************************************************************************/
62 SvxConnectionPage::SvxConnectionPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
63 : SfxTabPage(pPage, pController, u"cui/ui/connectortabpage.ui"_ustr, u"ConnectorTabPage"_ustr, &rInAttrs)
64 , rOutAttrs(rInAttrs)
65 , aAttrSet(*rInAttrs.GetPool())
66 , pView(nullptr)
67 , m_xLbType(m_xBuilder->weld_combo_box(u"LB_TYPE"_ustr))
68 , m_xFtLine1(m_xBuilder->weld_label(u"FT_LINE_1"_ustr))
69 , m_xMtrFldLine1(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_LINE_1"_ustr, FieldUnit::CM))
70 , m_xFtLine2(m_xBuilder->weld_label(u"FT_LINE_2"_ustr))
71 , m_xMtrFldLine2(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_LINE_2"_ustr, FieldUnit::CM))
72 , m_xFtLine3(m_xBuilder->weld_label(u"FT_LINE_3"_ustr))
73 , m_xMtrFldLine3(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_LINE_3"_ustr, FieldUnit::CM))
74 , m_xMtrFldHorz1(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_HORZ_1"_ustr, FieldUnit::MM))
75 , m_xMtrFldVert1(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_VERT_1"_ustr, FieldUnit::MM))
76 , m_xMtrFldHorz2(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_HORZ_2"_ustr, FieldUnit::MM))
77 , m_xMtrFldVert2(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_VERT_2"_ustr, FieldUnit::MM))
78 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, u"CTL_PREVIEW"_ustr, m_aCtlPreview))
80 SfxItemPool* pPool = rOutAttrs.GetPool();
81 assert(pPool && "Where is the pool");
82 eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
84 FillTypeLB();
86 const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
87 SetFieldUnit( *m_xMtrFldHorz1, eFUnit );
88 SetFieldUnit( *m_xMtrFldHorz2, eFUnit );
89 SetFieldUnit( *m_xMtrFldVert1, eFUnit );
90 SetFieldUnit( *m_xMtrFldVert2, eFUnit );
91 SetFieldUnit( *m_xMtrFldLine1, eFUnit );
92 SetFieldUnit( *m_xMtrFldLine2, eFUnit );
93 SetFieldUnit( *m_xMtrFldLine3, eFUnit );
94 if( eFUnit == FieldUnit::MM )
96 m_xMtrFldHorz1->set_increments(50, 500, FieldUnit::NONE);
97 m_xMtrFldHorz2->set_increments(50, 500, FieldUnit::NONE);
98 m_xMtrFldVert1->set_increments(50, 500, FieldUnit::NONE);
99 m_xMtrFldVert2->set_increments(50, 500, FieldUnit::NONE);
100 m_xMtrFldLine1->set_increments(50, 500, FieldUnit::NONE);
101 m_xMtrFldLine2->set_increments(50, 500, FieldUnit::NONE);
102 m_xMtrFldLine3->set_increments(50, 500, FieldUnit::NONE);
105 Link<weld::MetricSpinButton&,void> aLink(LINK(this, SvxConnectionPage, ChangeAttrEditHdl_Impl));
106 m_xMtrFldHorz1->connect_value_changed(aLink);
107 m_xMtrFldVert1->connect_value_changed(aLink);
108 m_xMtrFldHorz2->connect_value_changed(aLink);
109 m_xMtrFldVert2->connect_value_changed(aLink);
110 m_xMtrFldLine1->connect_value_changed(aLink);
111 m_xMtrFldLine2->connect_value_changed(aLink);
112 m_xMtrFldLine3->connect_value_changed(aLink);
113 m_xLbType->connect_changed(LINK(this, SvxConnectionPage, ChangeAttrListBoxHdl_Impl));
116 SvxConnectionPage::~SvxConnectionPage()
118 m_xCtlPreview.reset();
121 template<class T>
122 void SvxConnectionPage::SetMetricValueAndSave(const SfxItemSet* rAttrs, weld::MetricSpinButton& rField, TypedWhichId<T> nWhich)
124 const SfxPoolItem* pItem = GetItem( *rAttrs, nWhich);
125 const SfxItemPool* pPool = rAttrs->GetPool();
126 if( !pItem )
127 pItem = &pPool->GetUserOrPoolDefaultItem( nWhich );
128 SetMetricValue(rField, pItem->StaticWhichCast(nWhich).GetValue(), eUnit);
129 rField.save_value();
132 /*************************************************************************
134 |* reads passed Item-Set
136 \************************************************************************/
138 void SvxConnectionPage::Reset( const SfxItemSet* rAttrs )
140 const SfxPoolItem* pItem;
141 const SfxItemPool* pPool = rAttrs->GetPool();
143 // SdrEdgeNode1HorzDistItem
144 SetMetricValueAndSave(rAttrs, *m_xMtrFldHorz1, SDRATTR_EDGENODE1HORZDIST);
146 // SdrEdgeNode2HorzDistItem
147 SetMetricValueAndSave(rAttrs, *m_xMtrFldHorz2, SDRATTR_EDGENODE2HORZDIST);
149 // SdrEdgeNode1VertDistItem
150 SetMetricValueAndSave(rAttrs, *m_xMtrFldVert1, SDRATTR_EDGENODE1VERTDIST);
152 // SdrEdgeNode2VertDistItem
153 SetMetricValueAndSave(rAttrs, *m_xMtrFldVert2, SDRATTR_EDGENODE2VERTDIST);
155 // SdrEdgeLine1DeltaItem
156 SetMetricValueAndSave(rAttrs, *m_xMtrFldLine1, SDRATTR_EDGELINE1DELTA);
158 // SdrEdgeLine2DeltaItem
159 SetMetricValueAndSave(rAttrs, *m_xMtrFldLine2, SDRATTR_EDGELINE2DELTA);
161 // SdrEdgeLine3DeltaItem
162 SetMetricValueAndSave(rAttrs, *m_xMtrFldLine3, SDRATTR_EDGELINE3DELTA);
164 // SdrEdgeLineDeltaAnzItem
165 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
166 if( !pItem )
167 pItem = &pPool->GetUserOrPoolDefaultItem( SDRATTR_EDGELINEDELTACOUNT );
168 switch (pItem->StaticWhichCast(SDRATTR_EDGELINEDELTACOUNT).GetValue())
170 case 0:
171 m_xFtLine1->set_sensitive(false);
172 m_xMtrFldLine1->set_sensitive(false);
173 m_xMtrFldLine1->set_text(u""_ustr);
174 [[fallthrough]];
175 case 1:
176 m_xFtLine2->set_sensitive(false);
177 m_xMtrFldLine2->set_sensitive(false);
178 m_xMtrFldLine2->set_text(u""_ustr);
179 [[fallthrough]];
180 case 2:
181 m_xFtLine3->set_sensitive(false);
182 m_xMtrFldLine3->set_sensitive(false);
183 m_xMtrFldLine3->set_text(u""_ustr);
184 break;
187 // SdrEdgeKindItem
188 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
189 if( !pItem )
190 pItem = &pPool->GetUserOrPoolDefaultItem( SDRATTR_EDGEKIND );
191 m_xLbType->set_active(
192 sal::static_int_cast<sal_uInt16>(pItem->StaticWhichCast(SDRATTR_EDGEKIND).GetValue()));
193 m_xLbType->save_value();
196 /*************************************************************************
198 |* fills the passed Item-Set width Dialogbox attributes
200 \************************************************************************/
202 bool SvxConnectionPage::FillItemSet( SfxItemSet* rAttrs)
204 bool bModified = false;
205 sal_Int32 nValue;
207 if (m_xMtrFldHorz1->get_value_changed_from_saved())
209 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
210 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
211 bModified = true;
214 if (m_xMtrFldHorz2->get_value_changed_from_saved())
216 nValue = GetCoreValue(*m_xMtrFldHorz2, eUnit);
217 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
218 bModified = true;
221 if (m_xMtrFldVert1->get_value_changed_from_saved())
223 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
224 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
225 bModified = true;
228 if (m_xMtrFldVert2->get_value_changed_from_saved())
230 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
231 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
232 bModified = true;
235 if (m_xMtrFldLine1->get_value_changed_from_saved())
237 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
238 rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
239 bModified = true;
242 if (m_xMtrFldLine2->get_value_changed_from_saved())
244 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
245 rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
246 bModified = true;
249 if (m_xMtrFldLine3->get_value_changed_from_saved())
251 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
252 rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
253 bModified = true;
256 int nPos = m_xLbType->get_active();
257 if (m_xLbType->get_value_changed_from_saved())
259 if (nPos != -1)
261 rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
262 bModified = true;
266 return bModified;
269 void SvxConnectionPage::Construct()
271 DBG_ASSERT( pView, "No valid View transfer!" );
273 m_aCtlPreview.SetView(pView);
274 m_aCtlPreview.Construct();
277 /*************************************************************************
279 |* creates the page
281 \************************************************************************/
282 std::unique_ptr<SfxTabPage> SvxConnectionPage::Create(weld::Container* pPage, weld::DialogController* pController,
283 const SfxItemSet* rAttrs)
285 return std::make_unique<SvxConnectionPage>(pPage, pController, *rAttrs);
288 IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
290 int nPos = m_xLbType->get_active();
291 if (nPos != -1)
293 aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
296 m_aCtlPreview.SetAttributes(aAttrSet);
298 // get the number of line displacements
299 sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
301 m_xFtLine3->set_sensitive( nCount > 2 );
302 m_xMtrFldLine3->set_sensitive( nCount > 2 );
303 if( nCount > 2 )
304 m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
305 else
306 m_xMtrFldLine3->set_text(u""_ustr);
308 m_xFtLine2->set_sensitive( nCount > 1 );
309 m_xMtrFldLine2->set_sensitive( nCount > 1 );
310 if( nCount > 1 )
311 m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
312 else
313 m_xMtrFldLine2->set_text(u""_ustr);
315 m_xFtLine1->set_sensitive( nCount > 0 );
316 m_xMtrFldLine1->set_sensitive( nCount > 0 );
317 if( nCount > 0 )
318 m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
319 else
320 m_xMtrFldLine1->set_text(u""_ustr);
323 IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
325 if (&r == m_xMtrFldHorz1.get())
327 sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
328 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
331 if (&r == m_xMtrFldHorz2.get())
333 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
334 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
337 if (&r == m_xMtrFldVert1.get())
339 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
340 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
343 if (&r == m_xMtrFldVert2.get())
345 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
346 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
349 if (&r == m_xMtrFldLine1.get())
351 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
352 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
355 if (&r == m_xMtrFldLine2.get())
357 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
358 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
361 if (&r == m_xMtrFldLine3.get())
363 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
364 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
367 m_aCtlPreview.SetAttributes(aAttrSet);
370 void SvxConnectionPage::FillTypeLB()
372 // fill ListBox with connector names
373 const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
374 const SfxItemPool* pPool = rOutAttrs.GetPool();
376 if( !pItem )
377 pItem = &pPool->GetUserOrPoolDefaultItem( SDRATTR_EDGEKIND );
378 const SdrEdgeKindItem* pEdgeKindItem = &pItem->StaticWhichCast(SDRATTR_EDGEKIND);
379 const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
380 for (sal_uInt16 i = 0; i < nCount; i++)
382 OUString aStr = SdrEdgeKindItem::GetValueTextByPos(i);
383 m_xLbType->append_text(aStr);
386 void SvxConnectionPage::PageCreated(const SfxAllItemSet& aSet)
388 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
389 if (pOfaPtrItem)
390 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
392 Construct();
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */