Update ooo320-m1
[ooovba.git] / svx / source / cui / connect.cxx
blob486bb024031cd3b29c616ebd2f813e8e74255317
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connect.cxx,v $
10 * $Revision: 1.16 $
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
36 #endif
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[] =
61 SDRATTR_EDGE_FIRST,
62 SDRATTR_EDGE_LAST,
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 );
79 _pPage->Construct();
81 SetTabPage( _pPage );
82 SetText( _pPage->GetText() );
85 /*************************************************************************
87 |* Dtor
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 ),
103 rInAttrs ),
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() )
130 FreeResource();
132 SfxItemPool* pPool = rOutAttrs.GetPool();
133 DBG_ASSERT( pPool, "Wo ist der Pool" );
134 eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
136 FillTypeLB();
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 );
157 // disable 3D border
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 /*************************************************************************
173 |* Dtor
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
193 if( !pItem )
194 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
195 if( pItem )
197 long nValue = ( ( const SdrEdgeNode1HorzDistItem* )pItem )->GetValue();
198 SetMetricValue( aMtrFldHorz1, nValue, eUnit );
200 else
201 aMtrFldHorz1.SetEmptyFieldValue();
203 aMtrFldHorz1.SaveValue();
205 // SdrEdgeNode2HorzDistItem
206 pItem = GetItem( rAttrs, SDRATTR_EDGENODE2HORZDIST );
207 if( !pItem )
208 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
209 if( pItem )
211 long nValue = ( ( const SdrEdgeNode2HorzDistItem* )pItem )->GetValue();
212 SetMetricValue( aMtrFldHorz2, nValue, eUnit );
214 else
215 aMtrFldHorz2.SetEmptyFieldValue();
217 aMtrFldHorz2.SaveValue();
219 // SdrEdgeNode1VertDistItem
220 pItem = GetItem( rAttrs, SDRATTR_EDGENODE1VERTDIST );
221 if( !pItem )
222 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
223 if( pItem )
225 long nValue = ( ( const SdrEdgeNode1VertDistItem* )pItem )->GetValue();
226 SetMetricValue( aMtrFldVert1, nValue, eUnit );
228 else
229 aMtrFldVert1.SetEmptyFieldValue();
231 aMtrFldVert1.SaveValue();
233 // SdrEdgeNode2VertDistItem
234 pItem = GetItem( rAttrs, SDRATTR_EDGENODE2VERTDIST );
235 if( !pItem )
236 pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
237 if( pItem )
239 long nValue = ( ( const SdrEdgeNode2VertDistItem* )pItem )->GetValue();
240 SetMetricValue( aMtrFldVert2, nValue, eUnit );
242 else
243 aMtrFldVert2.SetEmptyFieldValue();
245 aMtrFldVert2.SaveValue();
247 // SdrEdgeLine1DeltaItem
248 pItem = GetItem( rAttrs, SDRATTR_EDGELINE1DELTA );
249 if( !pItem )
250 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
251 if( pItem )
253 long nValue = ( ( const SdrEdgeLine1DeltaItem* )pItem )->GetValue();
254 SetMetricValue( aMtrFldLine1, nValue, eUnit );
256 else
257 aMtrFldLine1.SetEmptyFieldValue();
259 aMtrFldLine1.SaveValue();
261 // SdrEdgeLine2DeltaItem
262 pItem = GetItem( rAttrs, SDRATTR_EDGELINE2DELTA );
263 if( !pItem )
264 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
265 if( pItem )
267 long nValue = ( ( const SdrEdgeLine2DeltaItem* )pItem )->GetValue();
268 SetMetricValue( aMtrFldLine2, nValue, eUnit );
270 else
271 aMtrFldLine2.SetEmptyFieldValue();
273 aMtrFldLine2.SaveValue();
275 // SdrEdgeLine3DeltaItem
276 pItem = GetItem( rAttrs, SDRATTR_EDGELINE3DELTA );
277 if( !pItem )
278 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
279 if( pItem )
281 long nValue = ( ( const SdrEdgeLine3DeltaItem* )pItem )->GetValue();
282 SetMetricValue( aMtrFldLine3, nValue, eUnit );
284 else
285 aMtrFldLine3.SetEmptyFieldValue();
287 aMtrFldLine3.SaveValue();
289 // SdrEdgeLineDeltaAnzItem
290 pItem = GetItem( rAttrs, SDRATTR_EDGELINEDELTAANZ );
291 if( !pItem )
292 pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTAANZ );
293 if( pItem )
295 UINT16 nValue = ( ( const SdrEdgeLineDeltaAnzItem* )pItem )->GetValue();
296 if( nValue <= 2 )
298 aFtLine3.Enable( FALSE );
299 aMtrFldLine3.Enable( FALSE );
300 aMtrFldLine3.SetEmptyFieldValue();
302 if( nValue <= 1 )
304 aFtLine2.Enable( FALSE );
305 aMtrFldLine2.Enable( FALSE );
306 aMtrFldLine2.SetEmptyFieldValue();
308 if( nValue == 0 )
310 aFtLine1.Enable( FALSE );
311 aMtrFldLine1.Enable( FALSE );
312 aMtrFldLine1.SetEmptyFieldValue();
316 // SdrEdgeKindItem
317 pItem = GetItem( rAttrs, SDRATTR_EDGEKIND );
318 if( !pItem )
319 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
320 if( pItem )
322 SdrEdgeKind nValue = ( ( const SdrEdgeKindItem* )pItem )->GetValue();
323 aLbType.SelectEntryPos( sal::static_int_cast< USHORT >(nValue) );
325 else
326 aLbType.SetNoSelection();
327 aLbType.SaveValue();
330 /*************************************************************************
332 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
334 \************************************************************************/
336 BOOL SvxConnectionPage::FillItemSet( SfxItemSet& rAttrs)
338 BOOL bModified = FALSE;
339 INT32 nValue;
341 if( aMtrFldHorz1.GetText() != aMtrFldHorz1.GetSavedValue() )
343 nValue = GetCoreValue( aMtrFldHorz1, eUnit );
344 rAttrs.Put( SdrEdgeNode1HorzDistItem( nValue ) );
345 bModified = TRUE;
348 if( aMtrFldHorz2.GetText() != aMtrFldHorz2.GetSavedValue() )
350 nValue = GetCoreValue( aMtrFldHorz2, eUnit );
351 rAttrs.Put( SdrEdgeNode2HorzDistItem( nValue ) );
352 bModified = TRUE;
355 if( aMtrFldVert1.GetText() != aMtrFldVert1.GetSavedValue() )
357 nValue = GetCoreValue( aMtrFldVert1, eUnit );
358 rAttrs.Put( SdrEdgeNode1VertDistItem( nValue ) );
359 bModified = TRUE;
362 if( aMtrFldVert2.GetText() != aMtrFldVert2.GetSavedValue() )
364 nValue = GetCoreValue( aMtrFldVert2, eUnit );
365 rAttrs.Put( SdrEdgeNode2VertDistItem( nValue ) );
366 bModified = TRUE;
369 if( aMtrFldLine1.GetText() != aMtrFldLine1.GetSavedValue() )
371 nValue = GetCoreValue( aMtrFldLine1, eUnit );
372 rAttrs.Put( SdrEdgeLine1DeltaItem( nValue ) );
373 bModified = TRUE;
376 if( aMtrFldLine2.GetText() != aMtrFldLine2.GetSavedValue() )
378 nValue = GetCoreValue( aMtrFldLine2, eUnit );
379 rAttrs.Put( SdrEdgeLine2DeltaItem( nValue ) );
380 bModified = TRUE;
383 if( aMtrFldLine3.GetText() != aMtrFldLine3.GetSavedValue() )
385 nValue = GetCoreValue( aMtrFldLine3, eUnit );
386 rAttrs.Put( SdrEdgeLine3DeltaItem( nValue ) );
387 bModified = TRUE;
391 USHORT nPos = aLbType.GetSelectEntryPos();
392 if( nPos != aLbType.GetSavedValue() )
394 if( nPos != LISTBOX_ENTRY_NOTFOUND )
396 rAttrs.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
397 bModified = TRUE;
401 return( bModified );
404 /*************************************************************************
408 \************************************************************************/
410 void SvxConnectionPage::Construct()
412 DBG_ASSERT( pView, "Keine gueltige View Uebergeben!" );
414 aCtlPreview.SetView( pView );
415 aCtlPreview.Construct();
418 /*************************************************************************
420 |* Erzeugt die Seite
422 \************************************************************************/
424 SfxTabPage* SvxConnectionPage::Create( Window* pWindow,
425 const SfxItemSet& rAttrs )
427 return( new SvxConnectionPage( pWindow, rAttrs ) );
430 /*************************************************************************
434 \************************************************************************/
436 USHORT* SvxConnectionPage::GetRanges()
438 return( pRanges );
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 ) );
492 if( p == &aLbType )
494 USHORT nPos = aLbType.GetSelectEntryPos();
495 if( nPos != LISTBOX_ENTRY_NOTFOUND )
497 aAttrSet.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
501 aCtlPreview.SetAttributes( aAttrSet );
503 if( p == &aLbType )
505 // Anzahl der Linienversaetze ermitteln
506 USHORT nCount = aCtlPreview.GetLineDeltaAnz();
508 aFtLine3.Enable( nCount > 2 );
509 aMtrFldLine3.Enable( nCount > 2 );
510 if( nCount > 2 )
511 aMtrFldLine3.SetValue( aMtrFldLine3.GetValue() );
512 else
513 aMtrFldLine3.SetEmptyFieldValue();
515 aFtLine2.Enable( nCount > 1 );
516 aMtrFldLine2.Enable( nCount > 1 );
517 if( nCount > 1 )
518 aMtrFldLine2.SetValue( aMtrFldLine2.GetValue() );
519 else
520 aMtrFldLine2.SetEmptyFieldValue();
522 aFtLine1.Enable( nCount > 0 );
523 aMtrFldLine1.Enable( nCount > 0 );
524 if( nCount > 0 )
525 aMtrFldLine1.SetValue( aMtrFldLine1.GetValue() );
526 else
527 aMtrFldLine1.SetEmptyFieldValue();
531 return( 0L );
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();
546 if( !pItem )
547 pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
548 if( pItem )
550 const SdrEdgeKindItem* pEdgeKindItem = (const SdrEdgeKindItem*) pItem;
551 USHORT nCount = pEdgeKindItem->GetValueCount();
552 String aStr;
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);
564 if (pOfaPtrItem)
565 SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
567 Construct();