bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / connect.cxx
blob21fa98fa7fc226f5fb8af13e64a3bceef672e37c
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 <cuires.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/dlgutil.hxx>
29 #include <svx/ofaitem.hxx>
30 #include <svx/svdattr.hxx>
31 #include <svx/svdoedge.hxx>
32 #include <svx/svdview.hxx>
33 #include <svx/sxekitm.hxx>
34 #include <svx/sxelditm.hxx>
35 #include <svx/sxenditm.hxx>
37 #include "connect.hxx"
38 #include "paragrph.hrc"
40 const sal_uInt16 SvxConnectionPage::pRanges[] =
42 SDRATTR_EDGE_FIRST,
43 SDRATTR_EDGE_LAST,
47 /*************************************************************************
49 |* dialog for changing connectors
51 \************************************************************************/
53 SvxConnectionDialog::SvxConnectionDialog( vcl::Window* pParent, const SfxItemSet& rInAttrs,
54 const SdrView* pSdrView )
55 : SfxSingleTabDialog(pParent, rInAttrs)
57 VclPtrInstance<SvxConnectionPage> _pPage( get_content_area(), rInAttrs );
59 _pPage->SetView( pSdrView );
60 _pPage->Construct();
62 SetTabPage( _pPage );
63 SetText(CUI_RESSTR( RID_SVXSTR_CONNECTOR ));
66 /*************************************************************************
68 |* page for changing connectors
70 \************************************************************************/
72 SvxConnectionPage::SvxConnectionPage( vcl::Window* pWindow, const SfxItemSet& rInAttrs )
73 : SfxTabPage(pWindow ,"ConnectorTabPage" ,"cui/ui/connectortabpage.ui"
74 ,&rInAttrs)
75 , rOutAttrs(rInAttrs)
76 , aAttrSet(*rInAttrs.GetPool())
77 , pView(NULL)
79 get(m_pLbType,"LB_TYPE");
81 get(m_pFtLine1,"FT_LINE_1");
82 get(m_pMtrFldLine1,"MTR_FLD_LINE_1");
83 get(m_pFtLine2,"FT_LINE_2");
84 get(m_pMtrFldLine2,"MTR_FLD_LINE_2");
85 get(m_pFtLine3,"FT_LINE_3");
86 get(m_pMtrFldLine3,"MTR_FLD_LINE_3");
88 get(m_pMtrFldHorz1,"MTR_FLD_HORZ_1");
89 get(m_pMtrFldVert1,"MTR_FLD_VERT_1");
90 get(m_pMtrFldHorz2,"MTR_FLD_HORZ_2");
91 get(m_pMtrFldVert2,"MTR_FLD_VERT_2");
93 get(m_pCtlPreview,"CTL_PREVIEW");
95 SfxItemPool* pPool = rOutAttrs.GetPool();
96 DBG_ASSERT( pPool, "Wo ist der Pool" );
97 eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
99 FillTypeLB();
101 const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
102 SetFieldUnit( *m_pMtrFldHorz1, eFUnit );
103 SetFieldUnit( *m_pMtrFldHorz2, eFUnit );
104 SetFieldUnit( *m_pMtrFldVert1, eFUnit );
105 SetFieldUnit( *m_pMtrFldVert2, eFUnit );
106 SetFieldUnit( *m_pMtrFldLine1, eFUnit );
107 SetFieldUnit( *m_pMtrFldLine2, eFUnit );
108 SetFieldUnit( *m_pMtrFldLine3, eFUnit );
109 if( eFUnit == FUNIT_MM )
111 m_pMtrFldHorz1->SetSpinSize( 50 );
112 m_pMtrFldHorz2->SetSpinSize( 50 );
113 m_pMtrFldVert1->SetSpinSize( 50 );
114 m_pMtrFldVert2->SetSpinSize( 50 );
115 m_pMtrFldLine1->SetSpinSize( 50 );
116 m_pMtrFldLine2->SetSpinSize( 50 );
117 m_pMtrFldLine3->SetSpinSize( 50 );
120 // disable 3D border
121 m_pCtlPreview->SetBorderStyle(WindowBorderStyle::MONO);
123 Link<> aLink( LINK( this, SvxConnectionPage, ChangeAttrHdl_Impl ) );
124 m_pMtrFldHorz1->SetModifyHdl( aLink );
125 m_pMtrFldVert1->SetModifyHdl( aLink );
126 m_pMtrFldHorz2->SetModifyHdl( aLink );
127 m_pMtrFldVert2->SetModifyHdl( aLink );
128 m_pMtrFldLine1->SetModifyHdl( aLink );
129 m_pMtrFldLine2->SetModifyHdl( aLink );
130 m_pMtrFldLine3->SetModifyHdl( aLink );
131 m_pLbType->SetSelectHdl( aLink );
134 SvxConnectionPage::~SvxConnectionPage()
136 disposeOnce();
139 void SvxConnectionPage::dispose()
141 m_pLbType.clear();
142 m_pFtLine1.clear();
143 m_pMtrFldLine1.clear();
144 m_pFtLine2.clear();
145 m_pMtrFldLine2.clear();
146 m_pFtLine3.clear();
147 m_pMtrFldLine3.clear();
148 m_pMtrFldHorz1.clear();
149 m_pMtrFldVert1.clear();
150 m_pMtrFldHorz2.clear();
151 m_pMtrFldVert2.clear();
152 m_pCtlPreview.clear();
153 SfxTabPage::dispose();
156 /*************************************************************************
158 |* reads passed Item-Set
160 \************************************************************************/
162 void SvxConnectionPage::Reset( const SfxItemSet* rAttrs )
164 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1HORZDIST );
165 const SfxItemPool* pPool = rAttrs->GetPool();
167 // SdrEdgeNode1HorzDistItem
168 if( !pItem )
169 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
170 if( pItem )
172 long nValue = static_cast<const SdrEdgeNode1HorzDistItem*>( pItem )->GetValue();
173 SetMetricValue( *m_pMtrFldHorz1, nValue, eUnit );
175 else
176 m_pMtrFldHorz1->SetEmptyFieldValue();
178 m_pMtrFldHorz1->SaveValue();
180 // SdrEdgeNode2HorzDistItem
181 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2HORZDIST );
182 if( !pItem )
183 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
184 if( pItem )
186 long nValue = static_cast<const SdrEdgeNode2HorzDistItem*>( pItem )->GetValue();
187 SetMetricValue( *m_pMtrFldHorz2, nValue, eUnit );
189 else
190 m_pMtrFldHorz2->SetEmptyFieldValue();
192 m_pMtrFldHorz2->SaveValue();
194 // SdrEdgeNode1VertDistItem
195 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE1VERTDIST );
196 if( !pItem )
197 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
198 if( pItem )
200 long nValue = static_cast<const SdrEdgeNode1VertDistItem*>( pItem )->GetValue();
201 SetMetricValue( *m_pMtrFldVert1, nValue, eUnit );
203 else
204 m_pMtrFldVert1->SetEmptyFieldValue();
206 m_pMtrFldVert1->SaveValue();
208 // SdrEdgeNode2VertDistItem
209 pItem = GetItem( *rAttrs, SDRATTR_EDGENODE2VERTDIST );
210 if( !pItem )
211 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
212 if( pItem )
214 long nValue = static_cast<const SdrEdgeNode2VertDistItem*>( pItem )->GetValue();
215 SetMetricValue( *m_pMtrFldVert2, nValue, eUnit );
217 else
218 m_pMtrFldVert2->SetEmptyFieldValue();
220 m_pMtrFldVert2->SaveValue();
222 // SdrEdgeLine1DeltaItem
223 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE1DELTA );
224 if( !pItem )
225 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
226 if( pItem )
228 long nValue = static_cast<const SdrMetricItem*>( pItem )->GetValue();
229 SetMetricValue( *m_pMtrFldLine1, nValue, eUnit );
231 else
232 m_pMtrFldLine1->SetEmptyFieldValue();
234 m_pMtrFldLine1->SaveValue();
236 // SdrEdgeLine2DeltaItem
237 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE2DELTA );
238 if( !pItem )
239 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
240 if( pItem )
242 long nValue = static_cast<const SdrMetricItem*>( pItem )->GetValue();
243 SetMetricValue( *m_pMtrFldLine2, nValue, eUnit );
245 else
246 m_pMtrFldLine2->SetEmptyFieldValue();
248 m_pMtrFldLine2->SaveValue();
250 // SdrEdgeLine3DeltaItem
251 pItem = GetItem( *rAttrs, SDRATTR_EDGELINE3DELTA );
252 if( !pItem )
253 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
254 if( pItem )
256 long nValue = static_cast<const SdrMetricItem*>( pItem )->GetValue();
257 SetMetricValue( *m_pMtrFldLine3, nValue, eUnit );
259 else
260 m_pMtrFldLine3->SetEmptyFieldValue();
262 m_pMtrFldLine3->SaveValue();
264 // SdrEdgeLineDeltaAnzItem
265 pItem = GetItem( *rAttrs, SDRATTR_EDGELINEDELTAANZ );
266 if( !pItem )
267 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTAANZ );
268 if( pItem )
270 sal_uInt16 nValue = static_cast<const SdrEdgeLineDeltaAnzItem*>( pItem )->GetValue();
271 if( nValue <= 2 )
273 m_pFtLine3->Enable( false );
274 m_pMtrFldLine3->Enable( false );
275 m_pMtrFldLine3->SetEmptyFieldValue();
277 if( nValue <= 1 )
279 m_pFtLine2->Enable( false );
280 m_pMtrFldLine2->Enable( false );
281 m_pMtrFldLine2->SetEmptyFieldValue();
283 if( nValue == 0 )
285 m_pFtLine1->Enable( false );
286 m_pMtrFldLine1->Enable( false );
287 m_pMtrFldLine1->SetEmptyFieldValue();
291 // SdrEdgeKindItem
292 pItem = GetItem( *rAttrs, SDRATTR_EDGEKIND );
293 if( !pItem )
294 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
295 if( pItem )
297 SdrEdgeKind nValue = static_cast<const SdrEdgeKindItem*>( pItem )->GetValue();
298 m_pLbType->SelectEntryPos( sal::static_int_cast< sal_uInt16 >(nValue) );
300 else
301 m_pLbType->SetNoSelection();
302 m_pLbType->SaveValue();
305 /*************************************************************************
307 |* fills the passed Item-Set width Dialogbox attributes
309 \************************************************************************/
311 bool SvxConnectionPage::FillItemSet( SfxItemSet* rAttrs)
313 bool bModified = false;
314 sal_Int32 nValue;
316 if( m_pMtrFldHorz1->IsValueChangedFromSaved() )
318 nValue = GetCoreValue( *m_pMtrFldHorz1, eUnit );
319 rAttrs->Put( SdrEdgeNode1HorzDistItem( nValue ) );
320 bModified = true;
323 if( m_pMtrFldHorz2->IsValueChangedFromSaved() )
325 nValue = GetCoreValue( *m_pMtrFldHorz2, eUnit );
326 rAttrs->Put( SdrEdgeNode2HorzDistItem( nValue ) );
327 bModified = true;
330 if( m_pMtrFldVert1->IsValueChangedFromSaved() )
332 nValue = GetCoreValue( *m_pMtrFldVert1, eUnit );
333 rAttrs->Put( SdrEdgeNode1VertDistItem( nValue ) );
334 bModified = true;
337 if( m_pMtrFldVert2->IsValueChangedFromSaved() )
339 nValue = GetCoreValue( *m_pMtrFldVert2, eUnit );
340 rAttrs->Put( SdrEdgeNode2VertDistItem( nValue ) );
341 bModified = true;
344 if( m_pMtrFldLine1->IsValueChangedFromSaved() )
346 nValue = GetCoreValue( *m_pMtrFldLine1, eUnit );
347 rAttrs->Put( makeSdrEdgeLine1DeltaItem( nValue ) );
348 bModified = true;
351 if( m_pMtrFldLine2->IsValueChangedFromSaved() )
353 nValue = GetCoreValue( *m_pMtrFldLine2, eUnit );
354 rAttrs->Put( makeSdrEdgeLine2DeltaItem( nValue ) );
355 bModified = true;
358 if( m_pMtrFldLine3->IsValueChangedFromSaved() )
360 nValue = GetCoreValue( *m_pMtrFldLine3, eUnit );
361 rAttrs->Put( makeSdrEdgeLine3DeltaItem( nValue ) );
362 bModified = true;
366 sal_Int32 nPos = m_pLbType->GetSelectEntryPos();
367 if( m_pLbType->IsValueChangedFromSaved() )
369 if( nPos != LISTBOX_ENTRY_NOTFOUND )
371 rAttrs->Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
372 bModified = true;
376 return bModified;
379 void SvxConnectionPage::Construct()
381 DBG_ASSERT( pView, "Keine gueltige View Uebergeben!" );
383 m_pCtlPreview->SetView( pView );
384 m_pCtlPreview->Construct();
387 /*************************************************************************
389 |* creates the page
391 \************************************************************************/
393 VclPtr<SfxTabPage> SvxConnectionPage::Create( vcl::Window* pWindow,
394 const SfxItemSet* rAttrs )
396 return VclPtr<SvxConnectionPage>::Create( pWindow, *rAttrs );
399 IMPL_LINK( SvxConnectionPage, ChangeAttrHdl_Impl, void *, p )
401 if( p == m_pMtrFldHorz1 )
403 sal_Int32 nValue = GetCoreValue( *m_pMtrFldHorz1, eUnit );
404 aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
407 if( p == m_pMtrFldHorz2 )
409 sal_Int32 nValue = GetCoreValue( *m_pMtrFldHorz2, eUnit );
410 aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
413 if( p == m_pMtrFldVert1 )
415 sal_Int32 nValue = GetCoreValue( *m_pMtrFldVert1, eUnit );
416 aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
419 if( p == m_pMtrFldVert2 )
421 sal_Int32 nValue = GetCoreValue( *m_pMtrFldVert2, eUnit );
422 aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
425 if( p == m_pMtrFldLine1 )
427 sal_Int32 nValue = GetCoreValue( *m_pMtrFldLine1, eUnit );
428 aAttrSet.Put( makeSdrEdgeLine1DeltaItem( nValue ) );
431 if( p == m_pMtrFldLine2 )
433 sal_Int32 nValue = GetCoreValue( *m_pMtrFldLine2, eUnit );
434 aAttrSet.Put( makeSdrEdgeLine2DeltaItem( nValue ) );
437 if( p == m_pMtrFldLine3 )
439 sal_Int32 nValue = GetCoreValue( *m_pMtrFldLine3, eUnit );
440 aAttrSet.Put( makeSdrEdgeLine3DeltaItem( nValue ) );
444 if( p == m_pLbType )
446 sal_Int32 nPos = m_pLbType->GetSelectEntryPos();
447 if( nPos != LISTBOX_ENTRY_NOTFOUND )
449 aAttrSet.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
453 m_pCtlPreview->SetAttributes( aAttrSet );
455 if( p == m_pLbType )
457 // get the number of line displacements
458 sal_uInt16 nCount = m_pCtlPreview->GetLineDeltaAnz();
460 m_pFtLine3->Enable( nCount > 2 );
461 m_pMtrFldLine3->Enable( nCount > 2 );
462 if( nCount > 2 )
463 m_pMtrFldLine3->SetValue( m_pMtrFldLine3->GetValue() );
464 else
465 m_pMtrFldLine3->SetEmptyFieldValue();
467 m_pFtLine2->Enable( nCount > 1 );
468 m_pMtrFldLine2->Enable( nCount > 1 );
469 if( nCount > 1 )
470 m_pMtrFldLine2->SetValue( m_pMtrFldLine2->GetValue() );
471 else
472 m_pMtrFldLine2->SetEmptyFieldValue();
474 m_pFtLine1->Enable( nCount > 0 );
475 m_pMtrFldLine1->Enable( nCount > 0 );
476 if( nCount > 0 )
477 m_pMtrFldLine1->SetValue( m_pMtrFldLine1->GetValue() );
478 else
479 m_pMtrFldLine1->SetEmptyFieldValue();
483 return 0L;
486 void SvxConnectionPage::FillTypeLB()
488 // fill ListBox with connector names
489 const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
490 const SfxItemPool* pPool = rOutAttrs.GetPool();
492 if( !pItem )
493 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
494 if( pItem )
496 const SdrEdgeKindItem* pEdgeKindItem = static_cast<const SdrEdgeKindItem*>( pItem );
497 sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
498 OUString aStr;
500 for( sal_uInt16 i = 0; i < nCount; i++ )
502 aStr = pEdgeKindItem->GetValueTextByPos( i );
503 m_pLbType->InsertEntry( aStr );
507 void SvxConnectionPage::PageCreated(const SfxAllItemSet& aSet)
509 SFX_ITEMSET_ARG(&aSet,pOfaPtrItem,OfaPtrItem,SID_OBJECT_LIST,false);
510 if (pOfaPtrItem)
511 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
513 Construct();
516 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */