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
121template<class T>
123{
124 const SfxPoolItem* pItem = GetItem( *rAttrs, nWhich);
125 const SfxItemPool* pPool = rAttrs->GetPool();
126 if( !pItem )
127 pItem = &pPool->GetDefaultItem( nWhich );
128 SetMetricValue(rField, pItem->StaticWhichCast(nWhich).GetValue(), eUnit);
129 rField.save_value();
130}
131
132/*************************************************************************
133|*
134|* reads passed Item-Set
135|*
136\************************************************************************/
137
139{
140 const SfxPoolItem* pItem;
141 const SfxItemPool* pPool = rAttrs->GetPool();
142
143 // SdrEdgeNode1HorzDistItem
145
146 // SdrEdgeNode2HorzDistItem
148
149 // SdrEdgeNode1VertDistItem
151
152 // SdrEdgeNode2VertDistItem
154
155 // SdrEdgeLine1DeltaItem
157
158 // SdrEdgeLine2DeltaItem
160
161 // SdrEdgeLine3DeltaItem
163
164 // SdrEdgeLineDeltaAnzItem
165 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTACOUNT );
166 if( !pItem )
168 switch (pItem->StaticWhichCast(SDRATTR_EDGELINEDELTACOUNT).GetValue())
169 {
170 case 0:
171 m_xFtLine1->set_sensitive(false);
172 m_xMtrFldLine1->set_sensitive(false);
173 m_xMtrFldLine1->set_text("");
174 [[fallthrough]];
175 case 1:
176 m_xFtLine2->set_sensitive(false);
177 m_xMtrFldLine2->set_sensitive(false);
178 m_xMtrFldLine2->set_text("");
179 [[fallthrough]];
180 case 2:
181 m_xFtLine3->set_sensitive(false);
182 m_xMtrFldLine3->set_sensitive(false);
183 m_xMtrFldLine3->set_text("");
184 break;
185 }
186
187 // SdrEdgeKindItem
188 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
189 if( !pItem )
190 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
191 m_xLbType->set_active(
192 sal::static_int_cast<sal_uInt16>(pItem->StaticWhichCast(SDRATTR_EDGEKIND).GetValue()));
193 m_xLbType->save_value();
194}
195
196/*************************************************************************
197|*
198|* fills the passed Item-Set width Dialogbox attributes
199|*
200\************************************************************************/
201
203{
204 bool bModified = false;
205 sal_Int32 nValue;
206
207 if (m_xMtrFldHorz1->get_value_changed_from_saved())
208 {
210 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
211 bModified = true;
212 }
213
214 if (m_xMtrFldHorz2->get_value_changed_from_saved())
215 {
217 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
218 bModified = true;
219 }
220
221 if (m_xMtrFldVert1->get_value_changed_from_saved())
222 {
224 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
225 bModified = true;
226 }
227
228 if (m_xMtrFldVert2->get_value_changed_from_saved())
229 {
231 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
232 bModified = true;
233 }
234
235 if (m_xMtrFldLine1->get_value_changed_from_saved())
236 {
239 bModified = true;
240 }
241
242 if (m_xMtrFldLine2->get_value_changed_from_saved())
243 {
246 bModified = true;
247 }
248
249 if (m_xMtrFldLine3->get_value_changed_from_saved())
250 {
253 bModified = true;
254 }
255
256 int nPos = m_xLbType->get_active();
257 if (m_xLbType->get_value_changed_from_saved())
258 {
259 if (nPos != -1)
260 {
261 rAttrs->Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
262 bModified = true;
263 }
264 }
265
266 return bModified;
267}
268
270{
271 DBG_ASSERT( pView, "No valid View transfer!" );
272
275}
276
277/*************************************************************************
278|*
279|* creates the page
280|*
281\************************************************************************/
282std::unique_ptr<SfxTabPage> SvxConnectionPage::Create(weld::Container* pPage, weld::DialogController* pController,
283 const SfxItemSet* rAttrs)
284{
285 return std::make_unique<SvxConnectionPage>(pPage, pController, *rAttrs);
286}
287
288IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox&, void)
289{
290 int nPos = m_xLbType->get_active();
291 if (nPos != -1)
292 {
293 aAttrSet.Put( SdrEdgeKindItem( static_cast<SdrEdgeKind>(nPos) ) );
294 }
295
296 m_aCtlPreview.SetAttributes(aAttrSet);
297
298 // get the number of line displacements
299 sal_uInt16 nCount = m_aCtlPreview.GetLineDeltaCount();
300
301 m_xFtLine3->set_sensitive( nCount > 2 );
302 m_xMtrFldLine3->set_sensitive( nCount > 2 );
303 if( nCount > 2 )
304 m_xMtrFldLine3->set_value(m_xMtrFldLine3->get_value(FieldUnit::NONE), FieldUnit::NONE);
305 else
306 m_xMtrFldLine3->set_text("");
307
308 m_xFtLine2->set_sensitive( nCount > 1 );
309 m_xMtrFldLine2->set_sensitive( nCount > 1 );
310 if( nCount > 1 )
311 m_xMtrFldLine2->set_value(m_xMtrFldLine2->get_value(FieldUnit::NONE), FieldUnit::NONE);
312 else
313 m_xMtrFldLine2->set_text("");
314
315 m_xFtLine1->set_sensitive( nCount > 0 );
316 m_xMtrFldLine1->set_sensitive( nCount > 0 );
317 if( nCount > 0 )
318 m_xMtrFldLine1->set_value(m_xMtrFldLine1->get_value(FieldUnit::NONE), FieldUnit::NONE);
319 else
320 m_xMtrFldLine1->set_text("");
321}
322
323IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton&, r, void)
324{
325 if (&r == m_xMtrFldHorz1.get())
326 {
327 sal_Int32 nValue = GetCoreValue(*m_xMtrFldHorz1, eUnit);
328 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
329 }
330
331 if (&r == m_xMtrFldHorz2.get())
332 {
333 sal_Int32 nValue = GetCoreValue( *m_xMtrFldHorz2, eUnit );
334 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
335 }
336
337 if (&r == m_xMtrFldVert1.get())
338 {
339 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert1, eUnit);
340 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
341 }
342
343 if (&r == m_xMtrFldVert2.get())
344 {
345 sal_Int32 nValue = GetCoreValue(*m_xMtrFldVert2, eUnit);
346 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
347 }
348
349 if (&r == m_xMtrFldLine1.get())
350 {
351 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine1, eUnit);
352 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
353 }
354
355 if (&r == m_xMtrFldLine2.get())
356 {
357 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine2, eUnit);
358 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
359 }
360
361 if (&r == m_xMtrFldLine3.get())
362 {
363 sal_Int32 nValue = GetCoreValue(*m_xMtrFldLine3, eUnit);
364 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
365 }
366
367 m_aCtlPreview.SetAttributes(aAttrSet);
368}
369
371{
372 // fill ListBox with connector names
374 const SfxItemPool* pPool = rOutAttrs.GetPool();
375
376 if( !pItem )
377 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
378 const SdrEdgeKindItem* pEdgeKindItem = &pItem->StaticWhichCast(SDRATTR_EDGEKIND);
379 const sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
380 for (sal_uInt16 i = 0; i < nCount; i++)
381 {
383 m_xLbType->append_text(aStr);
384 }
385}
387{
388 const OfaPtrItem* pOfaPtrItem = aSet.GetItem<OfaPtrItem>(SID_OBJECT_LIST, false);
389 if (pOfaPtrItem)
390 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
391
392 Construct();
393}
394
395/* 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)
T & StaticWhichCast(TypedWhichId< T > nId)
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:202
std::unique_ptr< weld::Label > m_xFtLine2
Definition: connect.hxx:43
void SetMetricValueAndSave(const SfxItemSet *rAttrs, weld::MetricSpinButton &rField, TypedWhichId< T > nWhich)
Definition: connect.cxx:122
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:138
virtual void PageCreated(const SfxAllItemSet &aSet) override
Definition: connect.cxx:386
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:72
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:282
void SetView(const SdrView *pSdrView)
IMPL_LINK(SvxConnectionPage, ChangeAttrEditHdl_Impl, weld::MetricSpinButton &, r, void)
Definition: connect.cxx:323
IMPL_LINK_NOARG(SvxConnectionPage, ChangeAttrListBoxHdl_Impl, weld::ComboBox &, void)
Definition: connect.cxx:288
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define DBG_ASSERT(sCon, aError)
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)