Bump version to 6.4.7.2.M8
[LibreOffice.git] / cui / source / tabpages / connect.cxx
blob70b38bbc95af23d66370917da8066c9795f086c8
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 sal_uInt16 SvxConnectionPage::pRanges[] =
38 SDRATTR_EDGE_FIRST,
39 SDRATTR_EDGE_LAST,
43 /*************************************************************************
45 |* dialog for changing connectors
47 \************************************************************************/
48 SvxConnectionDialog::SvxConnectionDialog(weld::Window* pParent, const SfxItemSet& rInAttrs, const SdrView* pSdrView)
49 : SfxSingleTabDialogController(pParent, &rInAttrs)
51 auto xPage = std::make_unique<SvxConnectionPage>(get_content_area(), this, rInAttrs);
53 xPage->SetView(pSdrView);
54 xPage->Construct();
56 SetTabPage(std::move(xPage));
57 m_xDialog->set_title(CuiResId(RID_SVXSTR_CONNECTOR));
60 /*************************************************************************
62 |* page for changing connectors
64 \************************************************************************/
66 SvxConnectionPage::SvxConnectionPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
67 : SfxTabPage(pPage, pController, "cui/ui/connectortabpage.ui", "ConnectorTabPage", &rInAttrs)
68 , rOutAttrs(rInAttrs)
69 , aAttrSet(*rInAttrs.GetPool())
70 , pView(nullptr)
71 , m_xLbType(m_xBuilder->weld_combo_box("LB_TYPE"))
72 , m_xFtLine1(m_xBuilder->weld_label("FT_LINE_1"))
73 , m_xMtrFldLine1(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_1", FieldUnit::CM))
74 , m_xFtLine2(m_xBuilder->weld_label("FT_LINE_2"))
75 , m_xMtrFldLine2(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_2", FieldUnit::CM))
76 , m_xFtLine3(m_xBuilder->weld_label("FT_LINE_3"))
77 , m_xMtrFldLine3(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_3", FieldUnit::CM))
78 , m_xMtrFldHorz1(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_1", FieldUnit::MM))
79 , m_xMtrFldVert1(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_1", FieldUnit::MM))
80 , m_xMtrFldHorz2(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_2", FieldUnit::MM))
81 , m_xMtrFldVert2(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_2", FieldUnit::MM))
82 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
84 SfxItemPool* pPool = rOutAttrs.GetPool();
85 DBG_ASSERT( pPool, "Where is the pool" );
86 eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
88 FillTypeLB();
90 const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
91 SetFieldUnit( *m_xMtrFldHorz1, eFUnit );
92 SetFieldUnit( *m_xMtrFldHorz2, eFUnit );
93 SetFieldUnit( *m_xMtrFldVert1, eFUnit );
94 SetFieldUnit( *m_xMtrFldVert2, eFUnit );
95 SetFieldUnit( *m_xMtrFldLine1, eFUnit );
96 SetFieldUnit( *m_xMtrFldLine2, eFUnit );
97 SetFieldUnit( *m_xMtrFldLine3, eFUnit );
98 if( eFUnit == FieldUnit::MM )
100 m_xMtrFldHorz1->set_increments(50, 500, FieldUnit::NONE);
101 m_xMtrFldHorz2->set_increments(50, 500, FieldUnit::NONE);
102 m_xMtrFldVert1->set_increments(50, 500, FieldUnit::NONE);
103 m_xMtrFldVert2->set_increments(50, 500, FieldUnit::NONE);
104 m_xMtrFldLine1->set_increments(50, 500, FieldUnit::NONE);
105 m_xMtrFldLine2->set_increments(50, 500, FieldUnit::NONE);
106 m_xMtrFldLine3->set_increments(50, 500, FieldUnit::NONE);
109 Link<weld::MetricSpinButton&,void> aLink(LINK(this, SvxConnectionPage, ChangeAttrEditHdl_Impl));
110 m_xMtrFldHorz1->connect_value_changed(aLink);
111 m_xMtrFldVert1->connect_value_changed(aLink);
112 m_xMtrFldHorz2->connect_value_changed(aLink);
113 m_xMtrFldVert2->connect_value_changed(aLink);
114 m_xMtrFldLine1->connect_value_changed(aLink);
115 m_xMtrFldLine2->connect_value_changed(aLink);
116 m_xMtrFldLine3->connect_value_changed(aLink);
117 m_xLbType->connect_changed(LINK(this, SvxConnectionPage, ChangeAttrListBoxHdl_Impl));
120 SvxConnectionPage::~SvxConnectionPage()
122 m_xCtlPreview.reset();
125 /*************************************************************************
127 |* reads passed Item-Set
129 \************************************************************************/
131 void SvxConnectionPage::Reset( const SfxItemSet* rAttrs )
133 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
134 const SfxItemPool* pPool = rAttrs->GetPool();
136 // SdrEdgeNode1HorzDistItem
137 if( !pItem )
138 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
139 SetMetricValue(*m_xMtrFldHorz1, static_cast<const SdrEdgeNode1HorzDistItem*>(pItem)->GetValue(),
140 eUnit);
141 m_xMtrFldHorz1->save_value();
143 // SdrEdgeNode2HorzDistItem
144 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2HORZDIST );
145 if( !pItem )
146 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
147 SetMetricValue(*m_xMtrFldHorz2, static_cast<const SdrEdgeNode2HorzDistItem*>(pItem)->GetValue(),
148 eUnit);
149 m_xMtrFldHorz2->save_value();
151 // SdrEdgeNode1VertDistItem
152 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1VERTDIST );
153 if( !pItem )
154 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
155 SetMetricValue(*m_xMtrFldVert1, static_cast<const SdrEdgeNode1VertDistItem*>(pItem)->GetValue(),
156 eUnit);
157 m_xMtrFldVert1->save_value();
159 // SdrEdgeNode2VertDistItem
160 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2VERTDIST );
161 if( !pItem )
162 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
163 SetMetricValue(*m_xMtrFldVert2, static_cast<const SdrEdgeNode2VertDistItem*>(pItem)->GetValue(),
164 eUnit);
165 m_xMtrFldVert2->save_value();
167 // SdrEdgeLine1DeltaItem
168 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE1DELTA );
169 if( !pItem )
170 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
171 SetMetricValue(*m_xMtrFldLine1, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
172 m_xMtrFldLine1->save_value();
174 // SdrEdgeLine2DeltaItem
175 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE2DELTA );
176 if( !pItem )
177 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
178 SetMetricValue(*m_xMtrFldLine2, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
179 m_xMtrFldLine2->save_value();
181 // SdrEdgeLine3DeltaItem
182 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE3DELTA );
183 if( !pItem )
184 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
185 SetMetricValue(*m_xMtrFldLine3, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
186 m_xMtrFldLine3->save_value();
188 // SdrEdgeLineDeltaAnzItem
189 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
190 if( !pItem )
191 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTACOUNT );
192 switch (static_cast<const SdrEdgeLineDeltaCountItem*>(pItem)->GetValue())
194 case 0:
195 m_xFtLine1->set_sensitive(false);
196 m_xMtrFldLine1->set_sensitive(false);
197 m_xMtrFldLine1->set_text("");
198 [[fallthrough]];
199 case 1:
200 m_xFtLine2->set_sensitive(false);
201 m_xMtrFldLine2->set_sensitive(false);
202 m_xMtrFldLine2->set_text("");
203 [[fallthrough]];
204 case 2:
205 m_xFtLine3->set_sensitive(false);
206 m_xMtrFldLine3->set_sensitive(false);
207 m_xMtrFldLine3->set_text("");
208 break;
211 // SdrEdgeKindItem
212 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
213 if( !pItem )
214 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
215 m_xLbType->set_active(
216 sal::static_int_cast<sal_uInt16>(static_cast<const SdrEdgeKindItem*>(pItem)->GetValue()));
217 m_xLbType->save_value();
220 /*************************************************************************
222 |* fills the passed Item-Set width Dialogbox attributes
224 \************************************************************************/
226 bool SvxConnectionPage::FillItemSet( SfxItemSet* rAttrs)
228 bool bModified = false;
229 sal_Int32 nValue;
231 if (m_xMtrFldHorz1->get_value_changed_from_saved())
233 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
234 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
235 bModified = true;
238 if (m_xMtrFldHorz2->get_value_changed_from_saved())
240 nValue = GetCoreValue(*m_xMtrFldHorz2, eUnit);
241 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
242 bModified = true;
245 if (m_xMtrFldVert1->get_value_changed_from_saved())
247 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
248 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
249 bModified = true;
252 if (m_xMtrFldVert2->get_value_changed_from_saved())
254 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
255 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
256 bModified = true;
259 if (m_xMtrFldLine1->get_value_changed_from_saved())
261 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
262 rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
263 bModified = true;
266 if (m_xMtrFldLine2->get_value_changed_from_saved())
268 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
269 rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
270 bModified = true;
273 if (m_xMtrFldLine3->get_value_changed_from_saved())
275 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
276 rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
277 bModified = true;
280 int nPos = m_xLbType->get_active();
281 if (m_xLbType->get_value_changed_from_saved())
283 if (nPos != -1)
285 rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
286 bModified = true;
290 return bModified;
293 void SvxConnectionPage::Construct()
295 DBG_ASSERT( pView, "No valid View transfer!" );
297 m_aCtlPreview.SetView(pView);
298 m_aCtlPreview.Construct();
301 /*************************************************************************
303 |* creates the page
305 \************************************************************************/
306 std::unique_ptr<SfxTabPage> SvxConnectionPage::Create(weld::Container* pPage, weld::DialogController* pController,
307 const SfxItemSet* rAttrs)
309 return std::make_unique<SvxConnectionPage>(pPage, pController, *rAttrs);
312 IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
314 int nPos = m_xLbType->get_active();
315 if (nPos != -1)
317 aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
320 m_aCtlPreview.SetAttributes(aAttrSet);
322 // get the number of line displacements
323 sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
325 m_xFtLine3->set_sensitive( nCount > 2 );
326 m_xMtrFldLine3->set_sensitive( nCount > 2 );
327 if( nCount > 2 )
328 m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
329 else
330 m_xMtrFldLine3->set_text("");
332 m_xFtLine2->set_sensitive( nCount > 1 );
333 m_xMtrFldLine2->set_sensitive( nCount > 1 );
334 if( nCount > 1 )
335 m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
336 else
337 m_xMtrFldLine2->set_text("");
339 m_xFtLine1->set_sensitive( nCount > 0 );
340 m_xMtrFldLine1->set_sensitive( nCount > 0 );
341 if( nCount > 0 )
342 m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
343 else
344 m_xMtrFldLine1->set_text("");
347 IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
349 if (&r == m_xMtrFldHorz1.get())
351 sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
352 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
355 if (&r == m_xMtrFldHorz2.get())
357 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
358 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
361 if (&r == m_xMtrFldVert1.get())
363 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
364 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
367 if (&r == m_xMtrFldVert2.get())
369 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
370 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
373 if (&r == m_xMtrFldLine1.get())
375 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
376 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
379 if (&r == m_xMtrFldLine2.get())
381 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
382 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
385 if (&r == m_xMtrFldLine3.get())
387 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
388 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
391 m_aCtlPreview.SetAttributes(aAttrSet);
394 void SvxConnectionPage::FillTypeLB()
396 // fill ListBox with connector names
397 const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
398 const SfxItemPool* pPool = rOutAttrs.GetPool();
400 if( !pItem )
401 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
402 const SdrEdgeKindItem* pEdgeKindItem = static_cast<const SdrEdgeKindItem*>(pItem);
403 const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
404 for (sal_uInt16 i = 0; i < nCount; i++)
406 OUString aStr = SdrEdgeKindItem::GetValueTextByPos(i);
407 m_xLbType->append_text(aStr);
410 void SvxConnectionPage::PageCreated(const SfxAllItemSet& aSet)
412 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
413 if (pOfaPtrItem)
414 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
416 Construct();
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */