bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / tabpages / connect.cxx
bloba20a38011869c737fc4ed580290c475fc3cde9f3
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>
22 #include <sfx2/app.hxx>
23 #include <sfx2/module.hxx>
24 #include <sfx2/request.hxx>
26 #include <svx/connctrl.hxx>
27 #include <svx/dialogs.hrc>
28 #include <svx/svxids.hrc>
29 #include <svx/dlgutil.hxx>
30 #include <svx/ofaitem.hxx>
32 #include <svx/svdoedge.hxx>
33 #include <svx/svdview.hxx>
34 #include <svx/sxekitm.hxx>
35 #include <svx/sxelditm.hxx>
36 #include <svx/sxenditm.hxx>
37 #include <svtools/unitconv.hxx>
39 #include <connect.hxx>
41 const sal_uInt16 SvxConnectionPage::pRanges[] =
43 SDRATTR_EDGE_FIRST,
44 SDRATTR_EDGE_LAST,
48 /*************************************************************************
50 |* dialog for changing connectors
52 \************************************************************************/
54 SvxConnectionDialog::SvxConnectionDialog(weld::Window* pParent, const SfxItemSet& rInAttrs, const SdrView* pSdrView)
55 : SfxSingleTabDialogController(pParent, &rInAttrs)
57 TabPageParent pPageParent(get_content_area(), this);
58 VclPtrInstance<SvxConnectionPage> pPage(pPageParent, rInAttrs);
60 pPage->SetView(pSdrView);
61 pPage->Construct();
63 SetTabPage(pPage);
64 m_xDialog->set_title(CuiResId( RID_SVXSTR_CONNECTOR));
67 /*************************************************************************
69 |* page for changing connectors
71 \************************************************************************/
73 SvxConnectionPage::SvxConnectionPage(TabPageParent pWindow, const SfxItemSet& rInAttrs)
74 : SfxTabPage(pWindow, "cui/ui/connectortabpage.ui", "ConnectorTabPage", &rInAttrs)
75 , rOutAttrs(rInAttrs)
76 , aAttrSet(*rInAttrs.GetPool())
77 , pView(nullptr)
78 , m_xLbType(m_xBuilder->weld_combo_box("LB_TYPE"))
79 , m_xFtLine1(m_xBuilder->weld_label("FT_LINE_1"))
80 , m_xMtrFldLine1(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_1", FieldUnit::CM))
81 , m_xFtLine2(m_xBuilder->weld_label("FT_LINE_2"))
82 , m_xMtrFldLine2(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_2", FieldUnit::CM))
83 , m_xFtLine3(m_xBuilder->weld_label("FT_LINE_3"))
84 , m_xMtrFldLine3(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_3", FieldUnit::CM))
85 , m_xMtrFldHorz1(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_1", FieldUnit::MM))
86 , m_xMtrFldVert1(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_1", FieldUnit::MM))
87 , m_xMtrFldHorz2(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_2", FieldUnit::MM))
88 , m_xMtrFldVert2(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_2", FieldUnit::MM))
89 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
91 SfxItemPool* pPool = rOutAttrs.GetPool();
92 DBG_ASSERT( pPool, "Where is the pool" );
93 eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
95 FillTypeLB();
97 const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
98 SetFieldUnit( *m_xMtrFldHorz1, eFUnit );
99 SetFieldUnit( *m_xMtrFldHorz2, eFUnit );
100 SetFieldUnit( *m_xMtrFldVert1, eFUnit );
101 SetFieldUnit( *m_xMtrFldVert2, eFUnit );
102 SetFieldUnit( *m_xMtrFldLine1, eFUnit );
103 SetFieldUnit( *m_xMtrFldLine2, eFUnit );
104 SetFieldUnit( *m_xMtrFldLine3, eFUnit );
105 if( eFUnit == FieldUnit::MM )
107 m_xMtrFldHorz1->set_increments(50, 500, FieldUnit::NONE);
108 m_xMtrFldHorz2->set_increments(50, 500, FieldUnit::NONE);
109 m_xMtrFldVert1->set_increments(50, 500, FieldUnit::NONE);
110 m_xMtrFldVert2->set_increments(50, 500, FieldUnit::NONE);
111 m_xMtrFldLine1->set_increments(50, 500, FieldUnit::NONE);
112 m_xMtrFldLine2->set_increments(50, 500, FieldUnit::NONE);
113 m_xMtrFldLine3->set_increments(50, 500, FieldUnit::NONE);
116 Link<weld::MetricSpinButton&,void> aLink(LINK(this, SvxConnectionPage, ChangeAttrEditHdl_Impl));
117 m_xMtrFldHorz1->connect_value_changed(aLink);
118 m_xMtrFldVert1->connect_value_changed(aLink);
119 m_xMtrFldHorz2->connect_value_changed(aLink);
120 m_xMtrFldVert2->connect_value_changed(aLink);
121 m_xMtrFldLine1->connect_value_changed(aLink);
122 m_xMtrFldLine2->connect_value_changed(aLink);
123 m_xMtrFldLine3->connect_value_changed(aLink);
124 m_xLbType->connect_changed(LINK(this, SvxConnectionPage, ChangeAttrListBoxHdl_Impl));
127 SvxConnectionPage::~SvxConnectionPage()
129 disposeOnce();
132 void SvxConnectionPage::dispose()
134 m_xCtlPreview.reset();
135 SfxTabPage::dispose();
138 /*************************************************************************
140 |* reads passed Item-Set
142 \************************************************************************/
144 void SvxConnectionPage::Reset( const SfxItemSet* rAttrs )
146 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
147 const SfxItemPool* pPool = rAttrs->GetPool();
149 // SdrEdgeNode1HorzDistItem
150 if( !pItem )
151 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
152 SetMetricValue(*m_xMtrFldHorz1, static_cast<const SdrEdgeNode1HorzDistItem*>(pItem)->GetValue(),
153 eUnit);
154 m_xMtrFldHorz1->save_value();
156 // SdrEdgeNode2HorzDistItem
157 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2HORZDIST );
158 if( !pItem )
159 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
160 SetMetricValue(*m_xMtrFldHorz2, static_cast<const SdrEdgeNode2HorzDistItem*>(pItem)->GetValue(),
161 eUnit);
162 m_xMtrFldHorz2->save_value();
164 // SdrEdgeNode1VertDistItem
165 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1VERTDIST );
166 if( !pItem )
167 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
168 SetMetricValue(*m_xMtrFldVert1, static_cast<const SdrEdgeNode1VertDistItem*>(pItem)->GetValue(),
169 eUnit);
170 m_xMtrFldVert1->save_value();
172 // SdrEdgeNode2VertDistItem
173 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2VERTDIST );
174 if( !pItem )
175 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
176 SetMetricValue(*m_xMtrFldVert2, static_cast<const SdrEdgeNode2VertDistItem*>(pItem)->GetValue(),
177 eUnit);
178 m_xMtrFldVert2->save_value();
180 // SdrEdgeLine1DeltaItem
181 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE1DELTA );
182 if( !pItem )
183 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
184 SetMetricValue(*m_xMtrFldLine1, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
185 m_xMtrFldLine1->save_value();
187 // SdrEdgeLine2DeltaItem
188 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE2DELTA );
189 if( !pItem )
190 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
191 SetMetricValue(*m_xMtrFldLine2, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
192 m_xMtrFldLine2->save_value();
194 // SdrEdgeLine3DeltaItem
195 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE3DELTA );
196 if( !pItem )
197 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
198 SetMetricValue(*m_xMtrFldLine3, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
199 m_xMtrFldLine3->save_value();
201 // SdrEdgeLineDeltaAnzItem
202 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
203 if( !pItem )
204 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTACOUNT );
205 switch (static_cast<const SdrEdgeLineDeltaCountItem*>(pItem)->GetValue())
207 case 0:
208 m_xFtLine1->set_sensitive(false);
209 m_xMtrFldLine1->set_sensitive(false);
210 m_xMtrFldLine1->set_text("");
211 [[fallthrough]];
212 case 1:
213 m_xFtLine2->set_sensitive(false);
214 m_xMtrFldLine2->set_sensitive(false);
215 m_xMtrFldLine2->set_text("");
216 [[fallthrough]];
217 case 2:
218 m_xFtLine3->set_sensitive(false);
219 m_xMtrFldLine3->set_sensitive(false);
220 m_xMtrFldLine3->set_text("");
221 break;
224 // SdrEdgeKindItem
225 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
226 if( !pItem )
227 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
228 m_xLbType->set_active(
229 sal::static_int_cast<sal_uInt16>(static_cast<const SdrEdgeKindItem*>(pItem)->GetValue()));
230 m_xLbType->save_value();
233 /*************************************************************************
235 |* fills the passed Item-Set width Dialogbox attributes
237 \************************************************************************/
239 bool SvxConnectionPage::FillItemSet( SfxItemSet* rAttrs)
241 bool bModified = false;
242 sal_Int32 nValue;
244 if (m_xMtrFldHorz1->get_value_changed_from_saved())
246 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
247 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
248 bModified = true;
251 if (m_xMtrFldHorz2->get_value_changed_from_saved())
253 nValue = GetCoreValue(*m_xMtrFldHorz2, eUnit);
254 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
255 bModified = true;
258 if (m_xMtrFldVert1->get_value_changed_from_saved())
260 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
261 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
262 bModified = true;
265 if (m_xMtrFldVert2->get_value_changed_from_saved())
267 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
268 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
269 bModified = true;
272 if (m_xMtrFldLine1->get_value_changed_from_saved())
274 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
275 rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
276 bModified = true;
279 if (m_xMtrFldLine2->get_value_changed_from_saved())
281 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
282 rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
283 bModified = true;
286 if (m_xMtrFldLine3->get_value_changed_from_saved())
288 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
289 rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
290 bModified = true;
293 int nPos = m_xLbType->get_active();
294 if (m_xLbType->get_value_changed_from_saved())
296 if (nPos != -1)
298 rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
299 bModified = true;
303 return bModified;
306 void SvxConnectionPage::Construct()
308 DBG_ASSERT( pView, "No valid View transfer!" );
310 m_aCtlPreview.SetView(pView);
311 m_aCtlPreview.Construct();
314 /*************************************************************************
316 |* creates the page
318 \************************************************************************/
320 VclPtr<SfxTabPage> SvxConnectionPage::Create(TabPageParent pParent,
321 const SfxItemSet* rAttrs)
323 return VclPtr<SvxConnectionPage>::Create(pParent, *rAttrs);
326 IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
328 int nPos = m_xLbType->get_active();
329 if (nPos != -1)
331 aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
334 m_aCtlPreview.SetAttributes(aAttrSet);
336 // get the number of line displacements
337 sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
339 m_xFtLine3->set_sensitive( nCount > 2 );
340 m_xMtrFldLine3->set_sensitive( nCount > 2 );
341 if( nCount > 2 )
342 m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
343 else
344 m_xMtrFldLine3->set_text("");
346 m_xFtLine2->set_sensitive( nCount > 1 );
347 m_xMtrFldLine2->set_sensitive( nCount > 1 );
348 if( nCount > 1 )
349 m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
350 else
351 m_xMtrFldLine2->set_text("");
353 m_xFtLine1->set_sensitive( nCount > 0 );
354 m_xMtrFldLine1->set_sensitive( nCount > 0 );
355 if( nCount > 0 )
356 m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
357 else
358 m_xMtrFldLine1->set_text("");
361 IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
363 if (&r == m_xMtrFldHorz1.get())
365 sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
366 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
369 if (&r == m_xMtrFldHorz2.get())
371 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
372 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
375 if (&r == m_xMtrFldVert1.get())
377 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
378 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
381 if (&r == m_xMtrFldVert2.get())
383 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
384 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
387 if (&r == m_xMtrFldLine1.get())
389 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
390 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
393 if (&r == m_xMtrFldLine2.get())
395 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
396 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
399 if (&r == m_xMtrFldLine3.get())
401 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
402 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
405 m_aCtlPreview.SetAttributes(aAttrSet);
408 void SvxConnectionPage::FillTypeLB()
410 // fill ListBox with connector names
411 const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
412 const SfxItemPool* pPool = rOutAttrs.GetPool();
414 if( !pItem )
415 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
416 const SdrEdgeKindItem* pEdgeKindItem = static_cast<const SdrEdgeKindItem*>(pItem);
417 const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
418 for (sal_uInt16 i = 0; i < nCount; i++)
420 OUString aStr = SdrEdgeKindItem::GetValueTextByPos(i);
421 m_xLbType->append_text(aStr);
424 void SvxConnectionPage::PageCreated(const SfxAllItemSet& aSet)
426 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
427 if (pOfaPtrItem)
428 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
430 Construct();
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */