1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connect.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
38 // include ---------------------------------------------------------------
39 #include <sfx2/app.hxx>
40 #include <sfx2/module.hxx>
41 #include <tools/shl.hxx>
42 #include "ofaitem.hxx" // add CHINA001
43 #include <sfx2/request.hxx> // add CHINA001
44 #define _SVX_CONNECT_CXX
46 #include <svx/svdoedge.hxx>
47 #include <svx/svdattr.hxx>
48 #include <svx/svdattrx.hxx>
49 #include <svx/svdview.hxx>
51 #include "connctrl.hxx"
52 #include "connect.hxx"
53 #include "connect.hrc"
54 #include <svx/dialmgr.hxx>
55 #include "dlgutil.hxx"
57 #include <svx/dialogs.hrc>
59 static USHORT pRanges
[] =
66 /*************************************************************************
68 |* Dialog zum Aendern von Konnektoren (Connectors)
70 \************************************************************************/
72 SvxConnectionDialog::SvxConnectionDialog( Window
* pParent
, const SfxItemSet
& rInAttrs
,
73 const SdrView
* pSdrView
) :
74 SfxSingleTabDialog( pParent
, rInAttrs
, RID_SVXPAGE_CONNECTION
)
76 SvxConnectionPage
* _pPage
= new SvxConnectionPage( this, rInAttrs
);
78 _pPage
->SetView( pSdrView
);
82 SetText( _pPage
->GetText() );
85 /*************************************************************************
89 \************************************************************************/
91 SvxConnectionDialog::~SvxConnectionDialog()
95 /*************************************************************************
97 |* Seite zum Aendern von Konnektoren (Connectors)
99 \************************************************************************/
101 SvxConnectionPage::SvxConnectionPage( Window
* pWindow
, const SfxItemSet
& rInAttrs
) :
102 SfxTabPage ( pWindow
, SVX_RES( RID_SVXPAGE_CONNECTION
),
105 aFtType ( this, SVX_RES( FT_TYPE
) ),
106 aLbType ( this, SVX_RES( LB_TYPE
) ),
108 aFlDelta ( this, SVX_RES( FL_DELTA
) ),
109 aFtLine1 ( this, SVX_RES( FT_LINE_1
) ),
110 aMtrFldLine1 ( this, SVX_RES( MTR_FLD_LINE_1
) ),
111 aFtLine2 ( this, SVX_RES( FT_LINE_2
) ),
112 aMtrFldLine2 ( this, SVX_RES( MTR_FLD_LINE_2
) ),
113 aFtLine3 ( this, SVX_RES( FT_LINE_3
) ),
114 aMtrFldLine3 ( this, SVX_RES( MTR_FLD_LINE_3
) ),
116 aFlDistance ( this, SVX_RES( FL_DISTANCE
) ),
117 aFtHorz1 ( this, SVX_RES( FT_HORZ_1
) ),
118 aMtrFldHorz1 ( this, SVX_RES( MTR_FLD_HORZ_1
) ),
119 aFtVert1 ( this, SVX_RES( FT_VERT_1
) ),
120 aMtrFldVert1 ( this, SVX_RES( MTR_FLD_VERT_1
) ),
121 aFtHorz2 ( this, SVX_RES( FT_HORZ_2
) ),
122 aMtrFldHorz2 ( this, SVX_RES( MTR_FLD_HORZ_2
) ),
123 aFtVert2 ( this, SVX_RES( FT_VERT_2
) ),
124 aMtrFldVert2 ( this, SVX_RES( MTR_FLD_VERT_2
) ),
126 aCtlPreview ( this, SVX_RES( CTL_PREVIEW
), rInAttrs
),
127 rOutAttrs ( rInAttrs
),
128 aAttrSet ( *rInAttrs
.GetPool() )
132 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
133 DBG_ASSERT( pPool
, "Wo ist der Pool" );
134 eUnit
= pPool
->GetMetric( SDRATTR_EDGENODE1HORZDIST
);
138 const FieldUnit eFUnit
= GetModuleFieldUnit( &rInAttrs
);
139 SetFieldUnit( aMtrFldHorz1
, eFUnit
);
140 SetFieldUnit( aMtrFldHorz2
, eFUnit
);
141 SetFieldUnit( aMtrFldVert1
, eFUnit
);
142 SetFieldUnit( aMtrFldVert2
, eFUnit
);
143 SetFieldUnit( aMtrFldLine1
, eFUnit
);
144 SetFieldUnit( aMtrFldLine2
, eFUnit
);
145 SetFieldUnit( aMtrFldLine3
, eFUnit
);
146 if( eFUnit
== FUNIT_MM
)
148 aMtrFldHorz1
.SetSpinSize( 50 );
149 aMtrFldHorz2
.SetSpinSize( 50 );
150 aMtrFldVert1
.SetSpinSize( 50 );
151 aMtrFldVert2
.SetSpinSize( 50 );
152 aMtrFldLine1
.SetSpinSize( 50 );
153 aMtrFldLine2
.SetSpinSize( 50 );
154 aMtrFldLine3
.SetSpinSize( 50 );
158 aCtlPreview
.SetBorderStyle(WINDOW_BORDER_MONO
);
160 Link
aLink( LINK( this, SvxConnectionPage
, ChangeAttrHdl_Impl
) );
161 aMtrFldHorz1
.SetModifyHdl( aLink
);
162 aMtrFldVert1
.SetModifyHdl( aLink
);
163 aMtrFldHorz2
.SetModifyHdl( aLink
);
164 aMtrFldVert2
.SetModifyHdl( aLink
);
165 aMtrFldLine1
.SetModifyHdl( aLink
);
166 aMtrFldLine2
.SetModifyHdl( aLink
);
167 aMtrFldLine3
.SetModifyHdl( aLink
);
168 aLbType
.SetSelectHdl( aLink
);
171 /*************************************************************************
175 \************************************************************************/
177 SvxConnectionPage::~SvxConnectionPage()
181 /*************************************************************************
183 |* Liest uebergebenen Item-Set
185 \************************************************************************/
187 void __EXPORT
SvxConnectionPage::Reset( const SfxItemSet
& rAttrs
)
189 const SfxPoolItem
* pItem
= GetItem( rAttrs
, SDRATTR_EDGENODE1HORZDIST
);
190 const SfxItemPool
* pPool
= rAttrs
.GetPool();
192 // SdrEdgeNode1HorzDistItem
194 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST
);
197 long nValue
= ( ( const SdrEdgeNode1HorzDistItem
* )pItem
)->GetValue();
198 SetMetricValue( aMtrFldHorz1
, nValue
, eUnit
);
201 aMtrFldHorz1
.SetEmptyFieldValue();
203 aMtrFldHorz1
.SaveValue();
205 // SdrEdgeNode2HorzDistItem
206 pItem
= GetItem( rAttrs
, SDRATTR_EDGENODE2HORZDIST
);
208 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST
);
211 long nValue
= ( ( const SdrEdgeNode2HorzDistItem
* )pItem
)->GetValue();
212 SetMetricValue( aMtrFldHorz2
, nValue
, eUnit
);
215 aMtrFldHorz2
.SetEmptyFieldValue();
217 aMtrFldHorz2
.SaveValue();
219 // SdrEdgeNode1VertDistItem
220 pItem
= GetItem( rAttrs
, SDRATTR_EDGENODE1VERTDIST
);
222 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST
);
225 long nValue
= ( ( const SdrEdgeNode1VertDistItem
* )pItem
)->GetValue();
226 SetMetricValue( aMtrFldVert1
, nValue
, eUnit
);
229 aMtrFldVert1
.SetEmptyFieldValue();
231 aMtrFldVert1
.SaveValue();
233 // SdrEdgeNode2VertDistItem
234 pItem
= GetItem( rAttrs
, SDRATTR_EDGENODE2VERTDIST
);
236 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST
);
239 long nValue
= ( ( const SdrEdgeNode2VertDistItem
* )pItem
)->GetValue();
240 SetMetricValue( aMtrFldVert2
, nValue
, eUnit
);
243 aMtrFldVert2
.SetEmptyFieldValue();
245 aMtrFldVert2
.SaveValue();
247 // SdrEdgeLine1DeltaItem
248 pItem
= GetItem( rAttrs
, SDRATTR_EDGELINE1DELTA
);
250 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGELINE1DELTA
);
253 long nValue
= ( ( const SdrEdgeLine1DeltaItem
* )pItem
)->GetValue();
254 SetMetricValue( aMtrFldLine1
, nValue
, eUnit
);
257 aMtrFldLine1
.SetEmptyFieldValue();
259 aMtrFldLine1
.SaveValue();
261 // SdrEdgeLine2DeltaItem
262 pItem
= GetItem( rAttrs
, SDRATTR_EDGELINE2DELTA
);
264 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGELINE2DELTA
);
267 long nValue
= ( ( const SdrEdgeLine2DeltaItem
* )pItem
)->GetValue();
268 SetMetricValue( aMtrFldLine2
, nValue
, eUnit
);
271 aMtrFldLine2
.SetEmptyFieldValue();
273 aMtrFldLine2
.SaveValue();
275 // SdrEdgeLine3DeltaItem
276 pItem
= GetItem( rAttrs
, SDRATTR_EDGELINE3DELTA
);
278 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGELINE3DELTA
);
281 long nValue
= ( ( const SdrEdgeLine3DeltaItem
* )pItem
)->GetValue();
282 SetMetricValue( aMtrFldLine3
, nValue
, eUnit
);
285 aMtrFldLine3
.SetEmptyFieldValue();
287 aMtrFldLine3
.SaveValue();
289 // SdrEdgeLineDeltaAnzItem
290 pItem
= GetItem( rAttrs
, SDRATTR_EDGELINEDELTAANZ
);
292 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGELINEDELTAANZ
);
295 UINT16 nValue
= ( ( const SdrEdgeLineDeltaAnzItem
* )pItem
)->GetValue();
298 aFtLine3
.Enable( FALSE
);
299 aMtrFldLine3
.Enable( FALSE
);
300 aMtrFldLine3
.SetEmptyFieldValue();
304 aFtLine2
.Enable( FALSE
);
305 aMtrFldLine2
.Enable( FALSE
);
306 aMtrFldLine2
.SetEmptyFieldValue();
310 aFtLine1
.Enable( FALSE
);
311 aMtrFldLine1
.Enable( FALSE
);
312 aMtrFldLine1
.SetEmptyFieldValue();
317 pItem
= GetItem( rAttrs
, SDRATTR_EDGEKIND
);
319 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGEKIND
);
322 SdrEdgeKind nValue
= ( ( const SdrEdgeKindItem
* )pItem
)->GetValue();
323 aLbType
.SelectEntryPos( sal::static_int_cast
< USHORT
>(nValue
) );
326 aLbType
.SetNoSelection();
330 /*************************************************************************
332 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
334 \************************************************************************/
336 BOOL
SvxConnectionPage::FillItemSet( SfxItemSet
& rAttrs
)
338 BOOL bModified
= FALSE
;
341 if( aMtrFldHorz1
.GetText() != aMtrFldHorz1
.GetSavedValue() )
343 nValue
= GetCoreValue( aMtrFldHorz1
, eUnit
);
344 rAttrs
.Put( SdrEdgeNode1HorzDistItem( nValue
) );
348 if( aMtrFldHorz2
.GetText() != aMtrFldHorz2
.GetSavedValue() )
350 nValue
= GetCoreValue( aMtrFldHorz2
, eUnit
);
351 rAttrs
.Put( SdrEdgeNode2HorzDistItem( nValue
) );
355 if( aMtrFldVert1
.GetText() != aMtrFldVert1
.GetSavedValue() )
357 nValue
= GetCoreValue( aMtrFldVert1
, eUnit
);
358 rAttrs
.Put( SdrEdgeNode1VertDistItem( nValue
) );
362 if( aMtrFldVert2
.GetText() != aMtrFldVert2
.GetSavedValue() )
364 nValue
= GetCoreValue( aMtrFldVert2
, eUnit
);
365 rAttrs
.Put( SdrEdgeNode2VertDistItem( nValue
) );
369 if( aMtrFldLine1
.GetText() != aMtrFldLine1
.GetSavedValue() )
371 nValue
= GetCoreValue( aMtrFldLine1
, eUnit
);
372 rAttrs
.Put( SdrEdgeLine1DeltaItem( nValue
) );
376 if( aMtrFldLine2
.GetText() != aMtrFldLine2
.GetSavedValue() )
378 nValue
= GetCoreValue( aMtrFldLine2
, eUnit
);
379 rAttrs
.Put( SdrEdgeLine2DeltaItem( nValue
) );
383 if( aMtrFldLine3
.GetText() != aMtrFldLine3
.GetSavedValue() )
385 nValue
= GetCoreValue( aMtrFldLine3
, eUnit
);
386 rAttrs
.Put( SdrEdgeLine3DeltaItem( nValue
) );
391 USHORT nPos
= aLbType
.GetSelectEntryPos();
392 if( nPos
!= aLbType
.GetSavedValue() )
394 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
396 rAttrs
.Put( SdrEdgeKindItem( (SdrEdgeKind
) nPos
) );
404 /*************************************************************************
408 \************************************************************************/
410 void SvxConnectionPage::Construct()
412 DBG_ASSERT( pView
, "Keine gueltige View Uebergeben!" );
414 aCtlPreview
.SetView( pView
);
415 aCtlPreview
.Construct();
418 /*************************************************************************
422 \************************************************************************/
424 SfxTabPage
* SvxConnectionPage::Create( Window
* pWindow
,
425 const SfxItemSet
& rAttrs
)
427 return( new SvxConnectionPage( pWindow
, rAttrs
) );
430 /*************************************************************************
434 \************************************************************************/
436 USHORT
* SvxConnectionPage::GetRanges()
441 /*************************************************************************
445 \************************************************************************/
447 IMPL_LINK( SvxConnectionPage
, ChangeAttrHdl_Impl
, void *, p
)
449 if( p
== &aMtrFldHorz1
)
451 INT32 nValue
= GetCoreValue( aMtrFldHorz1
, eUnit
);
452 aAttrSet
.Put( SdrEdgeNode1HorzDistItem( nValue
) );
455 if( p
== &aMtrFldHorz2
)
457 INT32 nValue
= GetCoreValue( aMtrFldHorz2
, eUnit
);
458 aAttrSet
.Put( SdrEdgeNode2HorzDistItem( nValue
) );
461 if( p
== &aMtrFldVert1
)
463 INT32 nValue
= GetCoreValue( aMtrFldVert1
, eUnit
);
464 aAttrSet
.Put( SdrEdgeNode1VertDistItem( nValue
) );
467 if( p
== &aMtrFldVert2
)
469 INT32 nValue
= GetCoreValue( aMtrFldVert2
, eUnit
);
470 aAttrSet
.Put( SdrEdgeNode2VertDistItem( nValue
) );
473 if( p
== &aMtrFldLine1
)
475 INT32 nValue
= GetCoreValue( aMtrFldLine1
, eUnit
);
476 aAttrSet
.Put( SdrEdgeLine1DeltaItem( nValue
) );
479 if( p
== &aMtrFldLine2
)
481 INT32 nValue
= GetCoreValue( aMtrFldLine2
, eUnit
);
482 aAttrSet
.Put( SdrEdgeLine2DeltaItem( nValue
) );
485 if( p
== &aMtrFldLine3
)
487 INT32 nValue
= GetCoreValue( aMtrFldLine3
, eUnit
);
488 aAttrSet
.Put( SdrEdgeLine3DeltaItem( nValue
) );
494 USHORT nPos
= aLbType
.GetSelectEntryPos();
495 if( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
497 aAttrSet
.Put( SdrEdgeKindItem( (SdrEdgeKind
) nPos
) );
501 aCtlPreview
.SetAttributes( aAttrSet
);
505 // Anzahl der Linienversaetze ermitteln
506 USHORT nCount
= aCtlPreview
.GetLineDeltaAnz();
508 aFtLine3
.Enable( nCount
> 2 );
509 aMtrFldLine3
.Enable( nCount
> 2 );
511 aMtrFldLine3
.SetValue( aMtrFldLine3
.GetValue() );
513 aMtrFldLine3
.SetEmptyFieldValue();
515 aFtLine2
.Enable( nCount
> 1 );
516 aMtrFldLine2
.Enable( nCount
> 1 );
518 aMtrFldLine2
.SetValue( aMtrFldLine2
.GetValue() );
520 aMtrFldLine2
.SetEmptyFieldValue();
522 aFtLine1
.Enable( nCount
> 0 );
523 aMtrFldLine1
.Enable( nCount
> 0 );
525 aMtrFldLine1
.SetValue( aMtrFldLine1
.GetValue() );
527 aMtrFldLine1
.SetEmptyFieldValue();
534 /*************************************************************************
538 \************************************************************************/
540 void SvxConnectionPage::FillTypeLB()
542 // ListBox mit Verbindernamen fuellen
543 const SfxPoolItem
* pItem
= GetItem( rOutAttrs
, SDRATTR_EDGEKIND
);
544 const SfxItemPool
* pPool
= rOutAttrs
.GetPool();
547 pItem
= &pPool
->GetDefaultItem( SDRATTR_EDGEKIND
);
550 const SdrEdgeKindItem
* pEdgeKindItem
= (const SdrEdgeKindItem
*) pItem
;
551 USHORT nCount
= pEdgeKindItem
->GetValueCount();
554 for( USHORT i
= 0; i
< nCount
; i
++ )
556 aStr
= pEdgeKindItem
->GetValueTextByPos( i
);
557 aLbType
.InsertEntry( aStr
);
561 void SvxConnectionPage::PageCreated (SfxAllItemSet aSet
) //add CHINA001
563 SFX_ITEMSET_ARG(&aSet
,pOfaPtrItem
,OfaPtrItem
,SID_OBJECT_LIST
,sal_False
);
565 SetView( static_cast<SdrView
*>(pOfaPtrItem
->GetValue()) );