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
37 svl::Items<SDRATTR_EDGE_FIRST, SDRATTR_EDGE_LAST>);
38
39/*************************************************************************
40|*
41|* dialog for changing connectors
42|*
43\************************************************************************/
45 : SfxSingleTabDialogController(pParent, &rInAttrs)
46{
47 auto xPage = std::make_unique<SvxConnectionPage>(get_content_area(), this, rInAttrs);
48
49 xPage->SetView(pSdrView);
50 xPage->Construct();
51
52 SetTabPage(std::move(xPage));
53 m_xDialog->set_title(CuiResId(RID_CUISTR_CONNECTOR));
54}
55
56/*************************************************************************
57|*
58|* page for changing connectors
59|*
60\************************************************************************/
61
63 : SfxTabPage(pPage, pController, "cui/ui/connectortabpage.ui", "ConnectorTabPage", &rInAttrs)
64 , rOutAttrs(rInAttrs)
65 , aAttrSet(*rInAttrs.GetPool())
66 , pView(nullptr)
67 , m_xLbType(m_xBuilder->weld_combo_box("LB_TYPE"))
68 , m_xFtLine1(m_xBuilder->weld_label("FT_LINE_1"))
69 , m_xMtrFldLine1(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_1", FieldUnit::CM))
70 , m_xFtLine2(m_xBuilder->weld_label("FT_LINE_2"))
71 , m_xMtrFldLine2(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_2", FieldUnit::CM))
72 , m_xFtLine3(m_xBuilder->weld_label("FT_LINE_3"))
73 , m_xMtrFldLine3(m_xBuilder->weld_metric_spin_button("MTR_FLD_LINE_3", FieldUnit::CM))
74 , m_xMtrFldHorz1(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_1", FieldUnit::MM))
75 , m_xMtrFldVert1(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_1", FieldUnit::MM))
76 , m_xMtrFldHorz2(m_xBuilder->weld_metric_spin_button("MTR_FLD_HORZ_2", FieldUnit::MM))
77 , m_xMtrFldVert2(m_xBuilder->weld_metric_spin_button("MTR_FLD_VERT_2", FieldUnit::MM))
78 , m_xCtlPreview(new weld::CustomWeld(*m_xBuilder, "CTL_PREVIEW", m_aCtlPreview))
79{
80 SfxItemPool* pPool = rOutAttrs.GetPool();
81 DBG_ASSERT( pPool, "Where is the pool" );
83
84 FillTypeLB();
85
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 )
95 {
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);
103 }
104
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));
114}
115
117{
118 m_xCtlPreview.reset();
119}
120
121/*************************************************************************
122|*
123|* reads passed Item-Set
124|*
125\************************************************************************/
126
128{
129 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
130 const SfxItemPool* pPool = rAttrs->GetPool();
131
132 // SdrEdgeNode1HorzDistItem
133 if( !pItem )
134 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
135 SetMetricValue(*m_xMtrFldHorz1, static_cast<const SdrEdgeNode1HorzDistItem*>(pItem)->GetValue(),
136 eUnit);
137 m_xMtrFldHorz1->save_value();
138
139 // SdrEdgeNode2HorzDistItem
140 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2HORZDIST );
141 if( !pItem )
142 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
143 SetMetricValue(*m_xMtrFldHorz2, static_cast<const SdrEdgeNode2HorzDistItem*>(pItem)->GetValue(),
144 eUnit);
145 m_xMtrFldHorz2->save_value();
146
147 // SdrEdgeNode1VertDistItem
148 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1VERTDIST );
149 if( !pItem )
150 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
151 SetMetricValue(*m_xMtrFldVert1, static_cast<const SdrEdgeNode1VertDistItem*>(pItem)->GetValue(),
152 eUnit);
153 m_xMtrFldVert1->save_value();
154
155 // SdrEdgeNode2VertDistItem
156 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2VERTDIST );
157 if( !pItem )
158 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
159 SetMetricValue(*m_xMtrFldVert2, static_cast<const SdrEdgeNode2VertDistItem*>(pItem)->GetValue(),
160 eUnit);
161 m_xMtrFldVert2->save_value();
162
163 // SdrEdgeLine1DeltaItem
164 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE1DELTA );
165 if( !pItem )
166 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
167 SetMetricValue(*m_xMtrFldLine1, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
168 m_xMtrFldLine1->save_value();
169
170 // SdrEdgeLine2DeltaItem
171 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE2DELTA );
172 if( !pItem )
173 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
174 SetMetricValue(*m_xMtrFldLine2, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
175 m_xMtrFldLine2->save_value();
176
177 // SdrEdgeLine3DeltaItem
178 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE3DELTA );
179 if( !pItem )
180 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
181 SetMetricValue(*m_xMtrFldLine3, static_cast<const SdrMetricItem*>(pItem)->GetValue(), eUnit);
182 m_xMtrFldLine3->save_value();
183
184 // SdrEdgeLineDeltaAnzItem
185 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
186 if( !pItem )
188 switch (static_cast<const SdrEdgeLineDeltaCountItem*>(pItem)->GetValue())
189 {
190 case 0:
191 m_xFtLine1->set_sensitive(false);
192 m_xMtrFldLine1->set_sensitive(false);
193 m_xMtrFldLine1->set_text("");
194 [[fallthrough]];
195 case 1:
196 m_xFtLine2->set_sensitive(false);
197 m_xMtrFldLine2->set_sensitive(false);
198 m_xMtrFldLine2->set_text("");
199 [[fallthrough]];
200 case 2:
201 m_xFtLine3->set_sensitive(false);
202 m_xMtrFldLine3->set_sensitive(false);
203 m_xMtrFldLine3->set_text("");
204 break;
205 }
206
207 // SdrEdgeKindItem
208 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
209 if( !pItem )
210 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
211 m_xLbType->set_active(
212 sal::static_int_cast<sal_uInt16>(static_cast<const SdrEdgeKindItem*>(pItem)->GetValue()));
213 m_xLbType->save_value();
214}
215
216/*************************************************************************
217|*
218|* fills the passed Item-Set width Dialogbox attributes
219|*
220\************************************************************************/
221
223{
224 bool bModified = false;
225 sal_Int32 nValue;
226
227 if (m_xMtrFldHorz1->get_value_changed_from_saved())
228 {
230 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
231 bModified = true;
232 }
233
234 if (m_xMtrFldHorz2->get_value_changed_from_saved())
235 {
237 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
238 bModified = true;
239 }
240
241 if (m_xMtrFldVert1->get_value_changed_from_saved())
242 {
244 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
245 bModified = true;
246 }
247
248 if (m_xMtrFldVert2->get_value_changed_from_saved())
249 {
251 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
252 bModified = true;
253 }
254
255 if (m_xMtrFldLine1->get_value_changed_from_saved())
256 {
259 bModified = true;
260 }
261
262 if (m_xMtrFldLine2->get_value_changed_from_saved())
263 {
266 bModified = true;
267 }
268
269 if (m_xMtrFldLine3->get_value_changed_from_saved())
270 {
273 bModified = true;
274 }
275
276 int nPos = m_xLbType->get_active();
277 if (m_xLbType->get_value_changed_from_saved())
278 {
279 if (nPos != -1)
280 {
281 rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
282 bModified = true;
283 }
284 }
285
286 return bModified;
287}
288
290{
291 DBG_ASSERT( pView, "No valid View transfer!" );
292
295}
296
297/*************************************************************************
298|*
299|* creates the page
300|*
301\************************************************************************/
302std::unique_ptr<SfxTabPage> SvxConnectionPage::Create(weld::Container* pPage, weld::DialogController* pController,
303 const SfxItemSet* rAttrs)
304{
305 return std::make_unique<SvxConnectionPage>(pPage, pController, *rAttrs);
306}
307
308IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
309{
310 int nPos = m_xLbType->get_active();
311 if (nPos != -1)
312 {
313 aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
314 }
315
316 m_aCtlPreview.SetAttributes(aAttrSet);
317
318 // get the number of line displacements
319 sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
320
321 m_xFtLine3->set_sensitive( nCount > 2 );
322 m_xMtrFldLine3->set_sensitive( nCount > 2 );
323 if( nCount > 2 )
324 m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
325 else
326 m_xMtrFldLine3->set_text("");
327
328 m_xFtLine2->set_sensitive( nCount > 1 );
329 m_xMtrFldLine2->set_sensitive( nCount > 1 );
330 if( nCount > 1 )
331 m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
332 else
333 m_xMtrFldLine2->set_text("");
334
335 m_xFtLine1->set_sensitive( nCount > 0 );
336 m_xMtrFldLine1->set_sensitive( nCount > 0 );
337 if( nCount > 0 )
338 m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
339 else
340 m_xMtrFldLine1->set_text("");
341}
342
343IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
344{
345 if (&r == m_xMtrFldHorz1.get())
346 {
347 sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
348 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
349 }
350
351 if (&r == m_xMtrFldHorz2.get())
352 {
353 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
354 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
355 }
356
357 if (&r == m_xMtrFldVert1.get())
358 {
359 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
360 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
361 }
362
363 if (&r == m_xMtrFldVert2.get())
364 {
365 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
366 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
367 }
368
369 if (&r == m_xMtrFldLine1.get())
370 {
371 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
372 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
373 }
374
375 if (&r == m_xMtrFldLine2.get())
376 {
377 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
378 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
379 }
380
381 if (&r == m_xMtrFldLine3.get())
382 {
383 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
384 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
385 }
386
387 m_aCtlPreview.SetAttributes(aAttrSet);
388}
389
391{
392 // fill ListBox with connector names
394 const SfxItemPool* pPool = rOutAttrs.GetPool();
395
396 if( !pItem )
397 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
398 const SdrEdgeKindItem* pEdgeKindItem = static_cast<const SdrEdgeKindItem*>(pItem);
399 const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
400 for (sal_uInt16 i = 0; i < nCount; i++)
401 {
403 m_xLbType->append_text(aStr);
404 }
405}
407{
408 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
409 if (pOfaPtrItem)
410 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
411
412 Construct();
413}
414
415/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void * GetValue() const
static OUString GetValueTextByPos(sal_uInt16 nPos)
virtual sal_uInt16 GetValueCount() const override
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
weld::Container * get_content_area()
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
SvxConnectionDialog(weld::Window *pParent, const SfxItemSet &rAttr, const SdrView *pView)
Definition: connect.cxx:44
Dialog for changing connectors.
Definition: connect.hxx:31
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine1
Definition: connect.hxx:42
std::unique_ptr< weld::Label > m_xFtLine1
Definition: connect.hxx:41
const SdrView * pView
Definition: connect.hxx:36
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine3
Definition: connect.hxx:46
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHorz1
Definition: connect.hxx:47
std::unique_ptr< weld::Label > m_xFtLine3
Definition: connect.hxx:45
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldVert2
Definition: connect.hxx:50
virtual bool FillItemSet(SfxItemSet *) override
Definition: connect.cxx:222
std::unique_ptr< weld::Label > m_xFtLine2
Definition: connect.hxx:43
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldHorz2
Definition: connect.hxx:49
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldLine2
Definition: connect.hxx:44
virtual void Reset(const SfxItemSet *) override
Definition: connect.cxx:127
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: connect.cxx:406
std::unique_ptr< weld::CustomWeld > m_xCtlPreview
Definition: connect.hxx:51
virtual ~SvxConnectionPage() override
Definition: connect.cxx:116
SvxConnectionPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: connect.cxx:62
static const WhichRangesContainer pRanges
Definition: connect.hxx:33
std::unique_ptr< weld::MetricSpinButton > m_xMtrFldVert1
Definition: connect.hxx:48
void SetView(const SdrView *pSdrView)
Definition: connect.hxx:70
std::unique_ptr< weld::ComboBox > m_xLbType
Definition: connect.hxx:40
SvxXConnectionPreview m_aCtlPreview
Definition: connect.hxx:39
const SfxItemSet & rOutAttrs
Definition: connect.hxx:34
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: connect.cxx:302
void SetView(const SdrView *pSdrView)
IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton &, r, void)
Definition: connect.cxx:343
IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox &, void)
Definition: connect.cxx:308
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define DBG_ASSERT(sCon, aError)
virtual tools::Long GetValue() const override
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
FieldUnit
sal_Int16 nValue
sal_uInt16 nPos
aStr
int i
constexpr TypedWhichId< SdrEdgeNode1HorzDistItem > SDRATTR_EDGENODE1HORZDIST(SDRATTR_EDGE_FIRST+1)
constexpr TypedWhichId< SdrEdgeLineDeltaCountItem > SDRATTR_EDGELINEDELTACOUNT(SDRATTR_EDGE_FIRST+7)
constexpr TypedWhichId< SdrEdgeKindItem > SDRATTR_EDGEKIND(SDRATTR_EDGE_FIRST+0)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_EDGELINE2DELTA(SDRATTR_EDGE_FIRST+9)
constexpr TypedWhichId< SdrEdgeNode1VertDistItem > SDRATTR_EDGENODE1VERTDIST(SDRATTR_EDGE_FIRST+2)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_EDGELINE3DELTA(SDRATTR_EDGE_FIRST+10)
constexpr TypedWhichId< SdrEdgeNode2HorzDistItem > SDRATTR_EDGENODE2HORZDIST(SDRATTR_EDGE_FIRST+3)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_EDGELINE1DELTA(SDRATTR_EDGE_FIRST+8)
constexpr TypedWhichId< SdrEdgeNode2VertDistItem > SDRATTR_EDGENODE2VERTDIST(SDRATTR_EDGE_FIRST+4)
SdrEdgeKind
SdrMetricItem makeSdrEdgeLine2DeltaItem(tools::Long nVal)
SdrMetricItem makeSdrEdgeLine1DeltaItem(tools::Long nVal)
SdrMetricItem makeSdrEdgeLine3DeltaItem(tools::Long nVal)
SVT_DLLPUBLIC sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
SVT_DLLPUBLIC void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton &rCtrl, FieldUnit eUnit, bool bAll=false)