xref: /aoo41x/main/cui/source/tabpages/connect.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <sfx2/app.hxx>
33 #include <sfx2/module.hxx>
34 #include <tools/shl.hxx>
35 #include "svx/ofaitem.hxx"	// add CHINA001
36 #include <sfx2/request.hxx> // add CHINA001
37 #include <svx/dialogs.hrc>
38 
39 #define _SVX_CONNECT_CXX
40 
41 #include <svx/svdoedge.hxx>
42 #include <svx/svdattr.hxx>
43 #include <svx/svdattrx.hxx>
44 #include <svx/svdview.hxx>
45 
46 #include "svx/connctrl.hxx"
47 #include "connect.hxx"
48 #include "connect.hrc"
49 #include <dialmgr.hxx>
50 #include "svx/dlgutil.hxx"
51 
52 #include "paragrph.hrc"
53 #include <cuires.hrc>
54 
55 static sal_uInt16 pRanges[] =
56 {
57 	SDRATTR_EDGE_FIRST,
58 	SDRATTR_EDGE_LAST,
59 	0
60 };
61 
62 /*************************************************************************
63 |*
64 |* Dialog zum Aendern von Konnektoren (Connectors)
65 |*
66 \************************************************************************/
67 
68 SvxConnectionDialog::SvxConnectionDialog( Window* pParent, const SfxItemSet& rInAttrs,
69 								const SdrView* pSdrView ) :
70 		SfxSingleTabDialog( pParent, rInAttrs, RID_SVXPAGE_CONNECTION )
71 {
72     SvxConnectionPage* _pPage = new SvxConnectionPage( this, rInAttrs );
73 
74     _pPage->SetView( pSdrView );
75     _pPage->Construct();
76 
77     SetTabPage( _pPage );
78     SetText( _pPage->GetText() );
79 }
80 
81 /*************************************************************************
82 |*
83 |* Dtor
84 |*
85 \************************************************************************/
86 
87 SvxConnectionDialog::~SvxConnectionDialog()
88 {
89 }
90 
91 /*************************************************************************
92 |*
93 |* Seite zum Aendern von Konnektoren (Connectors)
94 |*
95 \************************************************************************/
96 
97 SvxConnectionPage::SvxConnectionPage( Window* pWindow, const SfxItemSet& rInAttrs ) :
98 				SfxTabPage		( pWindow, CUI_RES( RID_SVXPAGE_CONNECTION ),
99 								  rInAttrs ),
100 
101 		aFtType      			( this, CUI_RES( FT_TYPE ) ),
102 		aLbType					( this, CUI_RES( LB_TYPE ) ),
103 
104         aFlDelta                ( this, CUI_RES( FL_DELTA ) ),
105         aFtLine1                ( this, CUI_RES( FT_LINE_1 ) ),
106         aMtrFldLine1            ( this, CUI_RES( MTR_FLD_LINE_1 ) ),
107         aFtLine2                ( this, CUI_RES( FT_LINE_2 ) ),
108         aMtrFldLine2            ( this, CUI_RES( MTR_FLD_LINE_2 ) ),
109         aFtLine3                ( this, CUI_RES( FT_LINE_3 ) ),
110         aMtrFldLine3            ( this, CUI_RES( MTR_FLD_LINE_3 ) ),
111 
112         aFlDistance             ( this, CUI_RES( FL_DISTANCE ) ),
113 		aFtHorz1    			( this, CUI_RES( FT_HORZ_1 ) ),
114 		aMtrFldHorz1    		( this, CUI_RES( MTR_FLD_HORZ_1 ) ),
115         aFtVert1                ( this, CUI_RES( FT_VERT_1 ) ),
116         aMtrFldVert1            ( this, CUI_RES( MTR_FLD_VERT_1 ) ),
117         aFtHorz2                ( this, CUI_RES( FT_HORZ_2 ) ),
118         aMtrFldHorz2            ( this, CUI_RES( MTR_FLD_HORZ_2 ) ),
119         aFtVert2                ( this, CUI_RES( FT_VERT_2 ) ),
120 		aMtrFldVert2    		( this, CUI_RES( MTR_FLD_VERT_2 ) ),
121 
122         aCtlPreview             ( this, CUI_RES( CTL_PREVIEW ), rInAttrs ),
123         rOutAttrs               ( rInAttrs ),
124         aAttrSet                ( *rInAttrs.GetPool() )
125 {
126 	FreeResource();
127 
128 	aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
129 
130 	SfxItemPool* pPool = rOutAttrs.GetPool();
131 	DBG_ASSERT( pPool, "Wo ist der Pool" );
132 	eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
133 
134 	FillTypeLB();
135 
136 	const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
137 	SetFieldUnit( aMtrFldHorz1, eFUnit );
138 	SetFieldUnit( aMtrFldHorz2, eFUnit );
139 	SetFieldUnit( aMtrFldVert1, eFUnit );
140 	SetFieldUnit( aMtrFldVert2, eFUnit );
141 	SetFieldUnit( aMtrFldLine1, eFUnit );
142 	SetFieldUnit( aMtrFldLine2, eFUnit );
143 	SetFieldUnit( aMtrFldLine3, eFUnit );
144 	if( eFUnit == FUNIT_MM )
145 	{
146 		aMtrFldHorz1.SetSpinSize( 50 );
147 		aMtrFldHorz2.SetSpinSize( 50 );
148 		aMtrFldVert1.SetSpinSize( 50 );
149 		aMtrFldVert2.SetSpinSize( 50 );
150 		aMtrFldLine1.SetSpinSize( 50 );
151 		aMtrFldLine2.SetSpinSize( 50 );
152 		aMtrFldLine3.SetSpinSize( 50 );
153 	}
154 
155 	// disable 3D border
156 	aCtlPreview.SetBorderStyle(WINDOW_BORDER_MONO);
157 
158 	Link aLink( LINK( this, SvxConnectionPage, ChangeAttrHdl_Impl ) );
159 	aMtrFldHorz1.SetModifyHdl( aLink );
160 	aMtrFldVert1.SetModifyHdl( aLink );
161 	aMtrFldHorz2.SetModifyHdl( aLink );
162 	aMtrFldVert2.SetModifyHdl( aLink );
163 	aMtrFldLine1.SetModifyHdl( aLink );
164 	aMtrFldLine2.SetModifyHdl( aLink );
165 	aMtrFldLine3.SetModifyHdl( aLink );
166 	aLbType.SetSelectHdl( aLink );
167 }
168 
169 /*************************************************************************
170 |*
171 |* Dtor
172 |*
173 \************************************************************************/
174 
175 SvxConnectionPage::~SvxConnectionPage()
176 {
177 }
178 
179 /*************************************************************************
180 |*
181 |* Liest uebergebenen Item-Set
182 |*
183 \************************************************************************/
184 
185 void __EXPORT SvxConnectionPage::Reset( const SfxItemSet& rAttrs )
186 {
187 	const SfxPoolItem* pItem = GetItem( rAttrs, SDRATTR_EDGENODE1HORZDIST );
188 	const SfxItemPool* pPool = rAttrs.GetPool();
189 
190 	// SdrEdgeNode1HorzDistItem
191 	if( !pItem )
192 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
193 	if( pItem )
194 	{
195 		long nValue = ( ( const SdrEdgeNode1HorzDistItem* )pItem )->GetValue();
196 		SetMetricValue( aMtrFldHorz1, nValue, eUnit );
197 	}
198 	else
199 		aMtrFldHorz1.SetEmptyFieldValue();
200 
201 	aMtrFldHorz1.SaveValue();
202 
203 	// SdrEdgeNode2HorzDistItem
204 	pItem = GetItem( rAttrs, SDRATTR_EDGENODE2HORZDIST );
205 	if( !pItem )
206 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
207 	if( pItem )
208 	{
209 		long nValue = ( ( const SdrEdgeNode2HorzDistItem* )pItem )->GetValue();
210 		SetMetricValue( aMtrFldHorz2, nValue, eUnit );
211 	}
212 	else
213 		aMtrFldHorz2.SetEmptyFieldValue();
214 
215 	aMtrFldHorz2.SaveValue();
216 
217 	// SdrEdgeNode1VertDistItem
218 	pItem = GetItem( rAttrs, SDRATTR_EDGENODE1VERTDIST );
219 	if( !pItem )
220 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
221 	if( pItem )
222 	{
223 		long nValue = ( ( const SdrEdgeNode1VertDistItem* )pItem )->GetValue();
224 		SetMetricValue( aMtrFldVert1, nValue, eUnit );
225 	}
226 	else
227 		aMtrFldVert1.SetEmptyFieldValue();
228 
229 	aMtrFldVert1.SaveValue();
230 
231 	// SdrEdgeNode2VertDistItem
232 	pItem = GetItem( rAttrs, SDRATTR_EDGENODE2VERTDIST );
233 	if( !pItem )
234 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
235 	if( pItem )
236 	{
237 		long nValue = ( ( const SdrEdgeNode2VertDistItem* )pItem )->GetValue();
238 		SetMetricValue( aMtrFldVert2, nValue, eUnit );
239 	}
240 	else
241 		aMtrFldVert2.SetEmptyFieldValue();
242 
243 	aMtrFldVert2.SaveValue();
244 
245 	// SdrEdgeLine1DeltaItem
246 	pItem = GetItem( rAttrs, SDRATTR_EDGELINE1DELTA );
247 	if( !pItem )
248 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
249 	if( pItem )
250 	{
251 		long nValue = ( ( const SdrEdgeLine1DeltaItem* )pItem )->GetValue();
252 		SetMetricValue( aMtrFldLine1, nValue, eUnit );
253 	}
254 	else
255 		aMtrFldLine1.SetEmptyFieldValue();
256 
257 	aMtrFldLine1.SaveValue();
258 
259 	// SdrEdgeLine2DeltaItem
260 	pItem = GetItem( rAttrs, SDRATTR_EDGELINE2DELTA );
261 	if( !pItem )
262 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
263 	if( pItem )
264 	{
265 		long nValue = ( ( const SdrEdgeLine2DeltaItem* )pItem )->GetValue();
266 		SetMetricValue( aMtrFldLine2, nValue, eUnit );
267 	}
268 	else
269 		aMtrFldLine2.SetEmptyFieldValue();
270 
271 	aMtrFldLine2.SaveValue();
272 
273 	// SdrEdgeLine3DeltaItem
274 	pItem = GetItem( rAttrs, SDRATTR_EDGELINE3DELTA );
275 	if( !pItem )
276 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
277 	if( pItem )
278 	{
279 		long nValue = ( ( const SdrEdgeLine3DeltaItem* )pItem )->GetValue();
280 		SetMetricValue( aMtrFldLine3, nValue, eUnit );
281 	}
282 	else
283 		aMtrFldLine3.SetEmptyFieldValue();
284 
285 	aMtrFldLine3.SaveValue();
286 
287 	// SdrEdgeLineDeltaAnzItem
288 	pItem = GetItem( rAttrs, SDRATTR_EDGELINEDELTAANZ );
289 	if( !pItem )
290 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTAANZ );
291 	if( pItem )
292 	{
293 		sal_uInt16 nValue = ( ( const SdrEdgeLineDeltaAnzItem* )pItem )->GetValue();
294 		if( nValue <= 2 )
295 		{
296 			aFtLine3.Enable( sal_False );
297 			aMtrFldLine3.Enable( sal_False );
298 			aMtrFldLine3.SetEmptyFieldValue();
299 		}
300 		if( nValue <= 1 )
301 		{
302 			aFtLine2.Enable( sal_False );
303 			aMtrFldLine2.Enable( sal_False );
304 			aMtrFldLine2.SetEmptyFieldValue();
305 		}
306 		if( nValue == 0 )
307 		{
308 			aFtLine1.Enable( sal_False );
309 			aMtrFldLine1.Enable( sal_False );
310 			aMtrFldLine1.SetEmptyFieldValue();
311 		}
312 	}
313 
314 	// SdrEdgeKindItem
315 	pItem = GetItem( rAttrs, SDRATTR_EDGEKIND );
316 	if( !pItem )
317 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
318 	if( pItem )
319 	{
320 		SdrEdgeKind nValue = ( ( const SdrEdgeKindItem* )pItem )->GetValue();
321 		aLbType.SelectEntryPos( sal::static_int_cast< sal_uInt16 >(nValue) );
322 	}
323 	else
324 		aLbType.SetNoSelection();
325 	aLbType.SaveValue();
326 }
327 
328 /*************************************************************************
329 |*
330 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
331 |*
332 \************************************************************************/
333 
334 sal_Bool SvxConnectionPage::FillItemSet( SfxItemSet& rAttrs)
335 {
336 	sal_Bool	 bModified = sal_False;
337 	sal_Int32	 nValue;
338 
339 	if( aMtrFldHorz1.GetText() != aMtrFldHorz1.GetSavedValue() )
340 	{
341 		nValue = GetCoreValue( aMtrFldHorz1, eUnit );
342 		rAttrs.Put( SdrEdgeNode1HorzDistItem( nValue ) );
343 		bModified = sal_True;
344 	}
345 
346 	if( aMtrFldHorz2.GetText() != aMtrFldHorz2.GetSavedValue() )
347 	{
348 		nValue = GetCoreValue( aMtrFldHorz2, eUnit );
349 		rAttrs.Put( SdrEdgeNode2HorzDistItem( nValue ) );
350 		bModified = sal_True;
351 	}
352 
353 	if( aMtrFldVert1.GetText() != aMtrFldVert1.GetSavedValue() )
354 	{
355 		nValue = GetCoreValue( aMtrFldVert1, eUnit );
356 		rAttrs.Put( SdrEdgeNode1VertDistItem( nValue ) );
357 		bModified = sal_True;
358 	}
359 
360 	if( aMtrFldVert2.GetText() != aMtrFldVert2.GetSavedValue() )
361 	{
362 		nValue = GetCoreValue( aMtrFldVert2, eUnit );
363 		rAttrs.Put( SdrEdgeNode2VertDistItem( nValue ) );
364 		bModified = sal_True;
365 	}
366 
367 	if( aMtrFldLine1.GetText() != aMtrFldLine1.GetSavedValue() )
368 	{
369 		nValue = GetCoreValue( aMtrFldLine1, eUnit );
370 		rAttrs.Put( SdrEdgeLine1DeltaItem( nValue ) );
371 		bModified = sal_True;
372 	}
373 
374 	if( aMtrFldLine2.GetText() != aMtrFldLine2.GetSavedValue() )
375 	{
376 		nValue = GetCoreValue( aMtrFldLine2, eUnit );
377 		rAttrs.Put( SdrEdgeLine2DeltaItem( nValue ) );
378 		bModified = sal_True;
379 	}
380 
381 	if( aMtrFldLine3.GetText() != aMtrFldLine3.GetSavedValue() )
382 	{
383 		nValue = GetCoreValue( aMtrFldLine3, eUnit );
384 		rAttrs.Put( SdrEdgeLine3DeltaItem( nValue ) );
385 		bModified = sal_True;
386 	}
387 
388 
389 	sal_uInt16 nPos = aLbType.GetSelectEntryPos();
390 	if( nPos != aLbType.GetSavedValue() )
391 	{
392 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
393 		{
394 			rAttrs.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
395 			bModified = sal_True;
396 		}
397 	}
398 
399 	return( bModified );
400 }
401 
402 /*************************************************************************
403 |*
404 |*
405 |*
406 \************************************************************************/
407 
408 void SvxConnectionPage::Construct()
409 {
410 	DBG_ASSERT( pView, "Keine gueltige View Uebergeben!" );
411 
412 	aCtlPreview.SetView( pView );
413 	aCtlPreview.Construct();
414 }
415 
416 /*************************************************************************
417 |*
418 |* Erzeugt die Seite
419 |*
420 \************************************************************************/
421 
422 SfxTabPage* SvxConnectionPage::Create( Window* pWindow,
423 				const SfxItemSet& rAttrs )
424 {
425 	return( new SvxConnectionPage( pWindow, rAttrs ) );
426 }
427 
428 /*************************************************************************
429 |*
430 |*
431 |*
432 \************************************************************************/
433 
434 sal_uInt16*	SvxConnectionPage::GetRanges()
435 {
436 	return( pRanges );
437 }
438 
439 /*************************************************************************
440 |*
441 |*
442 |*
443 \************************************************************************/
444 
445 IMPL_LINK( SvxConnectionPage, ChangeAttrHdl_Impl, void *, p )
446 {
447 	if( p == &aMtrFldHorz1 )
448 	{
449 		sal_Int32 nValue = GetCoreValue( aMtrFldHorz1, eUnit );
450 		aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
451 	}
452 
453 	if( p == &aMtrFldHorz2 )
454 	{
455 		sal_Int32 nValue = GetCoreValue( aMtrFldHorz2, eUnit );
456 		aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
457 	}
458 
459 	if( p == &aMtrFldVert1 )
460 	{
461 		sal_Int32 nValue = GetCoreValue( aMtrFldVert1, eUnit );
462 		aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
463 	}
464 
465 	if( p == &aMtrFldVert2 )
466 	{
467 		sal_Int32 nValue = GetCoreValue( aMtrFldVert2, eUnit );
468 		aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
469 	}
470 
471 	if( p == &aMtrFldLine1 )
472 	{
473 		sal_Int32 nValue = GetCoreValue( aMtrFldLine1, eUnit );
474 		aAttrSet.Put( SdrEdgeLine1DeltaItem( nValue ) );
475 	}
476 
477 	if( p == &aMtrFldLine2 )
478 	{
479 		sal_Int32 nValue = GetCoreValue( aMtrFldLine2, eUnit );
480 		aAttrSet.Put( SdrEdgeLine2DeltaItem( nValue ) );
481 	}
482 
483 	if( p == &aMtrFldLine3 )
484 	{
485 		sal_Int32 nValue = GetCoreValue( aMtrFldLine3, eUnit );
486 		aAttrSet.Put( SdrEdgeLine3DeltaItem( nValue ) );
487 	}
488 
489 
490 	if( p == &aLbType )
491 	{
492 		sal_uInt16 nPos = aLbType.GetSelectEntryPos();
493 		if( nPos != LISTBOX_ENTRY_NOTFOUND )
494 		{
495 			aAttrSet.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
496 		}
497 	}
498 
499 	aCtlPreview.SetAttributes( aAttrSet );
500 
501 	if( p == &aLbType )
502 	{
503 		// Anzahl der Linienversaetze ermitteln
504 		sal_uInt16 nCount = aCtlPreview.GetLineDeltaAnz();
505 
506 		aFtLine3.Enable( nCount > 2 );
507 		aMtrFldLine3.Enable( nCount > 2 );
508 		if( nCount > 2 )
509 			aMtrFldLine3.SetValue( aMtrFldLine3.GetValue() );
510 		else
511 			aMtrFldLine3.SetEmptyFieldValue();
512 
513 		aFtLine2.Enable( nCount > 1 );
514 		aMtrFldLine2.Enable( nCount > 1 );
515 		if( nCount > 1 )
516 			aMtrFldLine2.SetValue( aMtrFldLine2.GetValue() );
517 		else
518 			aMtrFldLine2.SetEmptyFieldValue();
519 
520 		aFtLine1.Enable( nCount > 0 );
521 		aMtrFldLine1.Enable( nCount > 0 );
522 		if( nCount > 0 )
523 			aMtrFldLine1.SetValue( aMtrFldLine1.GetValue() );
524 		else
525 			aMtrFldLine1.SetEmptyFieldValue();
526 
527 	}
528 
529 	return( 0L );
530 }
531 
532 /*************************************************************************
533 |*
534 |*
535 |*
536 \************************************************************************/
537 
538 void SvxConnectionPage::FillTypeLB()
539 {
540 	// ListBox mit Verbindernamen fuellen
541 	const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
542 	const SfxItemPool* pPool = rOutAttrs.GetPool();
543 
544 	if( !pItem )
545 		pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
546 	if( pItem )
547 	{
548 		const SdrEdgeKindItem* pEdgeKindItem = (const SdrEdgeKindItem*) pItem;
549 		sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
550 		String aStr;
551 
552 		for( sal_uInt16 i = 0; i < nCount; i++ )
553 		{
554 			aStr = pEdgeKindItem->GetValueTextByPos( i );
555 			aLbType.InsertEntry( aStr );
556 		}
557 	}
558 }
559 void SvxConnectionPage::PageCreated (SfxAllItemSet aSet) //add CHINA001
560 {
561 	SFX_ITEMSET_ARG(&aSet,pOfaPtrItem,OfaPtrItem,SID_OBJECT_LIST,sal_False);
562 	if (pOfaPtrItem)
563 		SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
564 
565 	Construct();
566 }
567 
568