LibreOffice Module cui (master)  1
connect.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <strings.hrc>
21 #include <dialmgr.hxx>
22 
23 #include <svx/connctrl.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/dlgutil.hxx>
26 #include <svx/ofaitem.hxx>
27 
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>
33 
34 #include <connect.hxx>
35 
36 const sal_uInt16 SvxConnectionPage::pRanges[] =
37 {
40  0
41 };
42 
43 /*************************************************************************
44 |*
45 |* dialog for changing connectors
46 |*
47 \************************************************************************/
48 
49 SvxConnectionDialog::SvxConnectionDialog(weld::Window* pParent, const SfxItemSet& rInAttrs, const SdrView* pSdrView)
50  : SfxSingleTabDialogController(pParent, &rInAttrs)
51 {
52  TabPageParent pPageParent(get_content_area(), this);
53  VclPtrInstance<SvxConnectionPage> pPage(pPageParent, rInAttrs);
54 
55  pPage->SetView(pSdrView);
56  pPage->Construct();
57 
58  SetTabPage(pPage);
59  m_xDialog->set_title(CuiResId( RID_SVXSTR_CONNECTOR));
60 }
61 
62 /*************************************************************************
63 |*
64 |* page for changing connectors
65 |*
66 \************************************************************************/
67 
69  : SfxTabPage(pWindow, "cui/ui/connectortabpage.ui", "ConnectorTabPage", &rInAttrs)
70  , rOutAttrs(rInAttrs)
71  , aAttrSet(*rInAttrs.GetPool())
72  , pView(nullptr)
73  , m_xLbType(m_xBuilder->weld_combo_box("LB_TYPE"))
74  , m_xFtLine1(m_xBuilder->weld_label("FT_LINE_1"))
75  , m_xMtrFldLine1(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_1", FieldUnit::CM))
76  , m_xFtLine2(m_xBuilder->weld_label("FT_LINE_2"))
77  , m_xMtrFldLine2(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_2", FieldUnit::CM))
78  , m_xFtLine3(m_xBuilder->weld_label("FT_LINE_3"))
79  , m_xMtrFldLine3(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_3", FieldUnit::CM))
80  , m_xMtrFldHorz1(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_1", FieldUnit::MM))
81  , m_xMtrFldVert1(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_1", FieldUnit::MM))
82  , m_xMtrFldHorz2(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_2", FieldUnit::MM))
83  , m_xMtrFldVert2(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_2", FieldUnit::MM))
84  , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
85 {
86  SfxItemPool* pPool = rOutAttrs.GetPool();
87  DBG_ASSERT( pPool, "Where is the pool" );
89 
90  FillTypeLB();
91 
92  const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
93  SetFieldUnit( *m_xMtrFldHorz1, eFUnit );
94  SetFieldUnit( *m_xMtrFldHorz2, eFUnit );
95  SetFieldUnit( *m_xMtrFldVert1, eFUnit );
96  SetFieldUnit( *m_xMtrFldVert2, eFUnit );
97  SetFieldUnit( *m_xMtrFldLine1, eFUnit );
98  SetFieldUnit( *m_xMtrFldLine2, eFUnit );
99  SetFieldUnit( *m_xMtrFldLine3, eFUnit );
100  if( eFUnit == FieldUnit::MM )
101  {
102  m_xMtrFldHorz1->set_increments(50, 500, FieldUnit::NONE);
103  m_xMtrFldHorz2->set_increments(50, 500, FieldUnit::NONE);
104  m_xMtrFldVert1->set_increments(50, 500, FieldUnit::NONE);
105  m_xMtrFldVert2->set_increments(50, 500, FieldUnit::NONE);
106  m_xMtrFldLine1->set_increments(50, 500, FieldUnit::NONE);
107  m_xMtrFldLine2->set_increments(50, 500, FieldUnit::NONE);
108  m_xMtrFldLine3->set_increments(50, 500, FieldUnit::NONE);
109  }
110 
111  Link<weld::MetricSpinButton&,void> aLink(LINK(this, SvxConnectionPage, ChangeAttrEditHdl_Impl));
112  m_xMtrFldHorz1->connect_value_changed(aLink);
113  m_xMtrFldVert1->connect_value_changed(aLink);
114  m_xMtrFldHorz2->connect_value_changed(aLink);
115  m_xMtrFldVert2->connect_value_changed(aLink);
116  m_xMtrFldLine1->connect_value_changed(aLink);
117  m_xMtrFldLine2->connect_value_changed(aLink);
118  m_xMtrFldLine3->connect_value_changed(aLink);
119  m_xLbType->connect_changed(LINK(this, SvxConnectionPage, ChangeAttrListBoxHdl_Impl));
120 }
121 
123 {
124  disposeOnce();
125 }
126 
128 {
129  m_xCtlPreview.reset();
131 }
132 
133 /*************************************************************************
134 |*
135 |* reads passed Item-Set
136 |*
137 \************************************************************************/
138 
140 {
141  const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
142  const SfxItemPool* pPool = rAttrs->GetPool();
143 
144  // SdrEdgeNode1HorzDistItem
145  if( !pItem )
146  pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
147  SetMetricValue(*m_xMtrFldHorz1, static_cast<const SdrEdgeNode1HorzDistItem*>(pItem)->GetValue(),
148  eUnit);
149  m_xMtrFldHorz1->save_value();
150 
151  // SdrEdgeNode2HorzDistItem
152  pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2HORZDIST );
153  if( !pItem )
154  pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
155  SetMetricValue(*m_xMtrFldHorz2, static_cast<const SdrEdgeNode2HorzDistItem*>(pItem)->GetValue(),
156  eUnit);
157  m_xMtrFldHorz2->save_value();
158 
159  // SdrEdgeNode1VertDistItem
160  pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1VERTDIST );
161  if( !pItem )
162  pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
163  SetMetricValue(*m_xMtrFldVert1, static_cast<const SdrEdgeNode1VertDistItem*>(pItem)->GetValue(),
164  eUnit);
165  m_xMtrFldVert1->save_value();
166 
167  // SdrEdgeNode2VertDistItem
168  pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2VERTDIST );
169  if( !pItem )
170  pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
171  SetMetricValue(*m_xMtrFldVert2, static_cast<const SdrEdgeNode2VertDistItem*>(pItem)->GetValue(),
172  eUnit);
173  m_xMtrFldVert2->save_value();
174 
175  // SdrEdgeLine1DeltaItem
176  pItem = GetItem( *rAttrs, SDRATTR_EDGELINE1DELTA );
177  if( !pItem )
178  pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
179  SetMetricValue(*m_xMtrFldLine1, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
180  m_xMtrFldLine1->save_value();
181 
182  // SdrEdgeLine2DeltaItem
183  pItem = GetItem( *rAttrs, SDRATTR_EDGELINE2DELTA );
184  if( !pItem )
185  pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
186  SetMetricValue(*m_xMtrFldLine2, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
187  m_xMtrFldLine2->save_value();
188 
189  // SdrEdgeLine3DeltaItem
190  pItem = GetItem( *rAttrs, SDRATTR_EDGELINE3DELTA );
191  if( !pItem )
192  pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
193  SetMetricValue(*m_xMtrFldLine3, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
194  m_xMtrFldLine3->save_value();
195 
196  // SdrEdgeLineDeltaAnzItem
197  pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
198  if( !pItem )
199  pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTACOUNT );
200  switch (static_cast<const SdrEdgeLineDeltaCountItem*>(pItem)->GetValue())
201  {
202  case 0:
203  m_xFtLine1->set_sensitive(false);
204  m_xMtrFldLine1->set_sensitive(false);
205  m_xMtrFldLine1->set_text("");
206  [[fallthrough]];
207  case 1:
208  m_xFtLine2->set_sensitive(false);
209  m_xMtrFldLine2->set_sensitive(false);
210  m_xMtrFldLine2->set_text("");
211  [[fallthrough]];
212  case 2:
213  m_xFtLine3->set_sensitive(false);
214  m_xMtrFldLine3->set_sensitive(false);
215  m_xMtrFldLine3->set_text("");
216  break;
217  }
218 
219  // SdrEdgeKindItem
220  pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
221  if( !pItem )
222  pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
223  m_xLbType->set_active(
224  sal::static_int_cast<sal_uInt16>(static_cast<const SdrEdgeKindItem*>(pItem)->GetValue()));
225  m_xLbType->save_value();
226 }
227 
228 /*************************************************************************
229 |*
230 |* fills the passed Item-Set width Dialogbox attributes
231 |*
232 \************************************************************************/
233 
235 {
236  bool bModified = false;
237  sal_Int32 nValue;
238 
239  if (m_xMtrFldHorz1->get_value_changed_from_saved())
240  {
241  nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
242  rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
243  bModified = true;
244  }
245 
246  if (m_xMtrFldHorz2->get_value_changed_from_saved())
247  {
248  nValue = GetCoreValue(*m_xMtrFldHorz2, eUnit);
249  rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
250  bModified = true;
251  }
252 
253  if (m_xMtrFldVert1->get_value_changed_from_saved())
254  {
255  nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
256  rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
257  bModified = true;
258  }
259 
260  if (m_xMtrFldVert2->get_value_changed_from_saved())
261  {
262  nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
263  rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
264  bModified = true;
265  }
266 
267  if (m_xMtrFldLine1->get_value_changed_from_saved())
268  {
269  nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
270  rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
271  bModified = true;
272  }
273 
274  if (m_xMtrFldLine2->get_value_changed_from_saved())
275  {
276  nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
277  rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
278  bModified = true;
279  }
280 
281  if (m_xMtrFldLine3->get_value_changed_from_saved())
282  {
283  nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
284  rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
285  bModified = true;
286  }
287 
288  int nPos = m_xLbType->get_active();
289  if (m_xLbType->get_value_changed_from_saved())
290  {
291  if (nPos != -1)
292  {
293  rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
294  bModified = true;
295  }
296  }
297 
298  return bModified;
299 }
300 
302 {
303  DBG_ASSERT( pView, "No valid View transfer!" );
304 
307 }
308 
309 /*************************************************************************
310 |*
311 |* creates the page
312 |*
313 \************************************************************************/
314 
316  const SfxItemSet* rAttrs)
317 {
318  return VclPtr<SvxConnectionPage>::Create(pParent, *rAttrs);
319 }
320 
321 IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
322 {
323  int nPos = m_xLbType->get_active();
324  if (nPos != -1)
325  {
326  aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
327  }
328 
329  m_aCtlPreview.SetAttributes(aAttrSet);
330 
331  // get the number of line displacements
332  sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
333 
334  m_xFtLine3->set_sensitive( nCount > 2 );
335  m_xMtrFldLine3->set_sensitive( nCount > 2 );
336  if( nCount > 2 )
337  m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
338  else
339  m_xMtrFldLine3->set_text("");
340 
341  m_xFtLine2->set_sensitive( nCount > 1 );
342  m_xMtrFldLine2->set_sensitive( nCount > 1 );
343  if( nCount > 1 )
344  m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
345  else
346  m_xMtrFldLine2->set_text("");
347 
348  m_xFtLine1->set_sensitive( nCount > 0 );
349  m_xMtrFldLine1->set_sensitive( nCount > 0 );
350  if( nCount > 0 )
351  m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
352  else
353  m_xMtrFldLine1->set_text("");
354 }
355 
356 IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
357 {
358  if (&r == m_xMtrFldHorz1.get())
359  {
360  sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
361  aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
362  }
363 
364  if (&r == m_xMtrFldHorz2.get())
365  {
366  sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
367  aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
368  }
369 
370  if (&r == m_xMtrFldVert1.get())
371  {
372  sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
373  aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
374  }
375 
376  if (&r == m_xMtrFldVert2.get())
377  {
378  sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
379  aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
380  }
381 
382  if (&r == m_xMtrFldLine1.get())
383  {
384  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
385  aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
386  }
387 
388  if (&r == m_xMtrFldLine2.get())
389  {
390  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
391  aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
392  }
393 
394  if (&r == m_xMtrFldLine3.get())
395  {
396  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
397  aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
398  }
399 
400  m_aCtlPreview.SetAttributes(aAttrSet);
401 }
402 
404 {
405  // fill ListBox with connector names
406  const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
407  const SfxItemPool* pPool = rOutAttrs.GetPool();
408 
409  if( !pItem )
410  pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
411  const SdrEdgeKindItem* pEdgeKindItem = static_cast<const SdrEdgeKindItem*>(pItem);
412  const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
413  for (sal_uInt16 i = 0; i < nCount; i++)
414  {
416  m_xLbType->append_text(aStr);
417  }
418 }
420 {
421  const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
422  if (pOfaPtrItem)
423  SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
424 
425  Construct();
426 }
427 
428 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Label > m_xFtLine2
Definition: connect.hxx:44
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldVert1
Definition: connect.hxx:49
static const sal_uInt16 pRanges[]
Definition: connect.hxx:34
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
#define SDRATTR_EDGELINE1DELTA
FieldUnit
SvxConnectionDialog(weld::Window *pParent, const SfxItemSet &rAttr, const SdrView *pView)
Definition: connect.cxx:49
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: connect.hxx:52
virtual void dispose() override
Definition: connect.cxx:127
#define SDRATTR_EDGENODE2HORZDIST
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldVert2
Definition: connect.hxx:51
std::string GetValue
#define SDRATTR_EDGE_LAST
SdrMetricItem makeSdrEdgeLine3DeltaItem(long nVal)
#define SDRATTR_EDGEKIND
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHorz2
Definition: connect.hxx:50
std::unique_ptr< weld::ComboBox > m_xLbType
Definition: connect.hxx:41
SvxConnectionPage(TabPageParent pWindow, const SfxItemSet &rInAttrs)
Definition: connect.cxx:68
const SfxItemSet & rOutAttrs
Definition: connect.hxx:35
weld::Container * get_content_area()
#define SDRATTR_EDGE_FIRST
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine3
Definition: connect.hxx:47
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine2
Definition: connect.hxx:45
#define SDRATTR_EDGENODE1HORZDIST
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
#define SDRATTR_EDGENODE2VERTDIST
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
#define SDRATTR_EDGELINE2DELTA
void SetView(const SdrView *pSdrView)
Definition: connect.hxx:72
void SetTabPage(SfxTabPage *pTabPage)
const SdrView * pView
Definition: connect.hxx:37
virtual void dispose() override
virtual sal_uInt16 GetValueCount() const override
#define SDRATTR_EDGENODE1VERTDIST
#define DBG_ASSERT(sCon, aError)
#define SDRATTR_EDGELINE3DELTA
int i
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton &, r, void)
Definition: connect.cxx:356
virtual ~SvxConnectionPage() override
Definition: connect.cxx:122
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
SdrMetricItem makeSdrEdgeLine1DeltaItem(long nVal)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: connect.cxx:419
Dialog for changing connectors.
Definition: connect.hxx:31
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine1
Definition: connect.hxx:43
static VclPtr< reference_type > Create(Arg &&...arg)
virtual void Reset(const SfxItemSet *) override
Definition: connect.cxx:139
SdrMetricItem makeSdrEdgeLine2DeltaItem(long nVal)
virtual bool FillItemSet(SfxItemSet *) override
Definition: connect.cxx:234
std::unique_ptr< weld::Label > m_xFtLine3
Definition: connect.hxx:46
static VclPtr< SfxTabPage > Create(TabPageParent, const SfxItemSet *)
Definition: connect.cxx:315
std::unique_ptr< weld::Label > m_xFtLine1
Definition: connect.hxx:42
void * GetValue() const
#define SDRATTR_EDGELINEDELTACOUNT
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_Int32 nPos
aStr
static OUString GetValueTextByPos(sal_uInt16 nPos)
void SetView(const SdrView *pSdrView)
IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox &, void)
Definition: connect.cxx:321
SvxXConnectionPreview m_aCtlPreview
Definition: connect.hxx:40
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHorz1
Definition: connect.hxx:48