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 SvxConnectionDialog::SvxConnectionDialog(weld::Window* pParent, const SfxItemSet& rInAttrs, const SdrView* pSdrView)
49  : SfxSingleTabDialogController(pParent, &rInAttrs)
50 {
51  auto xPage = std::make_unique<SvxConnectionPage>(get_content_area(), this, rInAttrs);
52 
53  xPage->SetView(pSdrView);
54  xPage->Construct();
55 
56  SetTabPage(std::move(xPage));
57  m_xDialog->set_title(CuiResId(RID_SVXSTR_CONNECTOR));
58 }
59 
60 /*************************************************************************
61 |*
62 |* page for changing connectors
63 |*
64 \************************************************************************/
65 
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))
83 {
84  SfxItemPool* pPool = rOutAttrs.GetPool();
85  DBG_ASSERT( pPool, "Where is the pool" );
87 
88  FillTypeLB();
89 
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 )
99  {
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);
107  }
108 
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));
118 }
119 
121 {
122  m_xCtlPreview.reset();
123 }
124 
125 /*************************************************************************
126 |*
127 |* reads passed Item-Set
128 |*
129 \************************************************************************/
130 
132 {
133  const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
134  const SfxItemPool* pPool = rAttrs->GetPool();
135 
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();
142 
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();
150 
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();
158 
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();
166 
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();
173 
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();
180 
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();
187 
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())
193  {
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;
209  }
210 
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();
218 }
219 
220 /*************************************************************************
221 |*
222 |* fills the passed Item-Set width Dialogbox attributes
223 |*
224 \************************************************************************/
225 
227 {
228  bool bModified = false;
229  sal_Int32 nValue;
230 
231  if (m_xMtrFldHorz1->get_value_changed_from_saved())
232  {
233  nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
234  rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
235  bModified = true;
236  }
237 
238  if (m_xMtrFldHorz2->get_value_changed_from_saved())
239  {
240  nValue = GetCoreValue(*m_xMtrFldHorz2, eUnit);
241  rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
242  bModified = true;
243  }
244 
245  if (m_xMtrFldVert1->get_value_changed_from_saved())
246  {
247  nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
248  rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
249  bModified = true;
250  }
251 
252  if (m_xMtrFldVert2->get_value_changed_from_saved())
253  {
254  nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
255  rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
256  bModified = true;
257  }
258 
259  if (m_xMtrFldLine1->get_value_changed_from_saved())
260  {
261  nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
262  rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
263  bModified = true;
264  }
265 
266  if (m_xMtrFldLine2->get_value_changed_from_saved())
267  {
268  nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
269  rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
270  bModified = true;
271  }
272 
273  if (m_xMtrFldLine3->get_value_changed_from_saved())
274  {
275  nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
276  rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
277  bModified = true;
278  }
279 
280  int nPos = m_xLbType->get_active();
281  if (m_xLbType->get_value_changed_from_saved())
282  {
283  if (nPos != -1)
284  {
285  rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
286  bModified = true;
287  }
288  }
289 
290  return bModified;
291 }
292 
294 {
295  DBG_ASSERT( pView, "No valid View transfer!" );
296 
299 }
300 
301 /*************************************************************************
302 |*
303 |* creates the page
304 |*
305 \************************************************************************/
306 std::unique_ptr<SfxTabPage> SvxConnectionPage::Create(weld::Container* pPage, weld::DialogController* pController,
307  const SfxItemSet* rAttrs)
308 {
309  return std::make_unique<SvxConnectionPage>(pPage, pController, *rAttrs);
310 }
311 
312 IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
313 {
314  int nPos = m_xLbType->get_active();
315  if (nPos != -1)
316  {
317  aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
318  }
319 
320  m_aCtlPreview.SetAttributes(aAttrSet);
321 
322  // get the number of line displacements
323  sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
324 
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("");
331 
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("");
338 
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("");
345 }
346 
347 IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
348 {
349  if (&r == m_xMtrFldHorz1.get())
350  {
351  sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
352  aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
353  }
354 
355  if (&r == m_xMtrFldHorz2.get())
356  {
357  sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
358  aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
359  }
360 
361  if (&r == m_xMtrFldVert1.get())
362  {
363  sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
364  aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
365  }
366 
367  if (&r == m_xMtrFldVert2.get())
368  {
369  sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
370  aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
371  }
372 
373  if (&r == m_xMtrFldLine1.get())
374  {
375  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
376  aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
377  }
378 
379  if (&r == m_xMtrFldLine2.get())
380  {
381  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
382  aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
383  }
384 
385  if (&r == m_xMtrFldLine3.get())
386  {
387  sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
388  aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
389  }
390 
391  m_aCtlPreview.SetAttributes(aAttrSet);
392 }
393 
395 {
396  // fill ListBox with connector names
397  const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
398  const SfxItemPool* pPool = rOutAttrs.GetPool();
399 
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++)
405  {
407  m_xLbType->append_text(aStr);
408  }
409 }
411 {
412  const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
413  if (pOfaPtrItem)
414  SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
415 
416  Construct();
417 }
418 
419 /* 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:48
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: connect.hxx:52
#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
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:71
const SdrView * pView
Definition: connect.hxx:37
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:347
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
virtual ~SvxConnectionPage() override
Definition: connect.cxx:120
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
SvxConnectionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: connect.cxx:66
SdrMetricItem makeSdrEdgeLine1DeltaItem(long nVal)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: connect.cxx:410
Dialog for changing connectors.
Definition: connect.hxx:31
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine1
Definition: connect.hxx:43
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: connect.cxx:306
virtual void Reset(const SfxItemSet *) override
Definition: connect.cxx:131
SdrMetricItem makeSdrEdgeLine2DeltaItem(long nVal)
virtual bool FillItemSet(SfxItemSet *) override
Definition: connect.cxx:226
std::unique_ptr< weld::Label > m_xFtLine3
Definition: connect.hxx:46
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:312
SvxXConnectionPreview m_aCtlPreview
Definition: connect.hxx:40
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHorz1
Definition: connect.hxx:48