Line data Source code
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 <cuires.hrc>
21 : #include <dialmgr.hxx>
22 : #include <sfx2/app.hxx>
23 : #include <sfx2/module.hxx>
24 : #include <sfx2/request.hxx>
25 : #include <tools/shl.hxx>
26 :
27 : #include <svx/connctrl.hxx>
28 : #include <svx/dialogs.hrc>
29 : #include <svx/dlgutil.hxx>
30 : #include <svx/ofaitem.hxx>
31 : #include <svx/svdattr.hxx>
32 : #include <svx/svdoedge.hxx>
33 : #include <svx/svdview.hxx>
34 : #include <svx/sxekitm.hxx>
35 : #include <svx/sxelditm.hxx>
36 : #include <svx/sxenditm.hxx>
37 :
38 : #include "connect.hrc"
39 : #include "connect.hxx"
40 : #include "paragrph.hrc"
41 :
42 : static sal_uInt16 pRanges[] =
43 : {
44 : SDRATTR_EDGE_FIRST,
45 : SDRATTR_EDGE_LAST,
46 : 0
47 : };
48 :
49 : /*************************************************************************
50 : |*
51 : |* dialog for changing connectors
52 : |*
53 : \************************************************************************/
54 :
55 0 : SvxConnectionDialog::SvxConnectionDialog( Window* pParent, const SfxItemSet& rInAttrs,
56 : const SdrView* pSdrView ) :
57 0 : SfxNoLayoutSingleTabDialog( pParent, rInAttrs, RID_SVXPAGE_CONNECTION )
58 : {
59 0 : SvxConnectionPage* _pPage = new SvxConnectionPage( this, rInAttrs );
60 :
61 0 : _pPage->SetView( pSdrView );
62 0 : _pPage->Construct();
63 :
64 0 : SetTabPage( _pPage );
65 0 : SetText( _pPage->GetText() );
66 0 : }
67 :
68 : /*************************************************************************
69 : |*
70 : |* Dtor
71 : |*
72 : \************************************************************************/
73 :
74 0 : SvxConnectionDialog::~SvxConnectionDialog()
75 : {
76 0 : }
77 :
78 : /*************************************************************************
79 : |*
80 : |* page for changing connectors
81 : |*
82 : \************************************************************************/
83 :
84 0 : SvxConnectionPage::SvxConnectionPage( Window* pWindow, const SfxItemSet& rInAttrs ) :
85 0 : SfxTabPage ( pWindow, CUI_RES( RID_SVXPAGE_CONNECTION ),
86 : rInAttrs ),
87 :
88 0 : aFtType ( this, CUI_RES( FT_TYPE ) ),
89 0 : aLbType ( this, CUI_RES( LB_TYPE ) ),
90 :
91 0 : aFlDelta ( this, CUI_RES( FL_DELTA ) ),
92 0 : aFtLine1 ( this, CUI_RES( FT_LINE_1 ) ),
93 0 : aMtrFldLine1 ( this, CUI_RES( MTR_FLD_LINE_1 ) ),
94 0 : aFtLine2 ( this, CUI_RES( FT_LINE_2 ) ),
95 0 : aMtrFldLine2 ( this, CUI_RES( MTR_FLD_LINE_2 ) ),
96 0 : aFtLine3 ( this, CUI_RES( FT_LINE_3 ) ),
97 0 : aMtrFldLine3 ( this, CUI_RES( MTR_FLD_LINE_3 ) ),
98 :
99 0 : aFlDistance ( this, CUI_RES( FL_DISTANCE ) ),
100 0 : aFtHorz1 ( this, CUI_RES( FT_HORZ_1 ) ),
101 0 : aMtrFldHorz1 ( this, CUI_RES( MTR_FLD_HORZ_1 ) ),
102 0 : aFtVert1 ( this, CUI_RES( FT_VERT_1 ) ),
103 0 : aMtrFldVert1 ( this, CUI_RES( MTR_FLD_VERT_1 ) ),
104 0 : aFtHorz2 ( this, CUI_RES( FT_HORZ_2 ) ),
105 0 : aMtrFldHorz2 ( this, CUI_RES( MTR_FLD_HORZ_2 ) ),
106 0 : aFtVert2 ( this, CUI_RES( FT_VERT_2 ) ),
107 0 : aMtrFldVert2 ( this, CUI_RES( MTR_FLD_VERT_2 ) ),
108 :
109 0 : aCtlPreview ( this, CUI_RES( CTL_PREVIEW ), rInAttrs ),
110 : rOutAttrs ( rInAttrs ),
111 0 : aAttrSet ( *rInAttrs.GetPool() )
112 : {
113 0 : FreeResource();
114 :
115 0 : aCtlPreview.SetAccessibleName(String(CUI_RES(STR_EXAMPLE)));
116 :
117 0 : SfxItemPool* pPool = rOutAttrs.GetPool();
118 : DBG_ASSERT( pPool, "Wo ist der Pool" );
119 0 : eUnit = pPool->GetMetric( SDRATTR_EDGENODE1HORZDIST );
120 :
121 0 : FillTypeLB();
122 :
123 0 : const FieldUnit eFUnit = GetModuleFieldUnit( rInAttrs );
124 0 : SetFieldUnit( aMtrFldHorz1, eFUnit );
125 0 : SetFieldUnit( aMtrFldHorz2, eFUnit );
126 0 : SetFieldUnit( aMtrFldVert1, eFUnit );
127 0 : SetFieldUnit( aMtrFldVert2, eFUnit );
128 0 : SetFieldUnit( aMtrFldLine1, eFUnit );
129 0 : SetFieldUnit( aMtrFldLine2, eFUnit );
130 0 : SetFieldUnit( aMtrFldLine3, eFUnit );
131 0 : if( eFUnit == FUNIT_MM )
132 : {
133 0 : aMtrFldHorz1.SetSpinSize( 50 );
134 0 : aMtrFldHorz2.SetSpinSize( 50 );
135 0 : aMtrFldVert1.SetSpinSize( 50 );
136 0 : aMtrFldVert2.SetSpinSize( 50 );
137 0 : aMtrFldLine1.SetSpinSize( 50 );
138 0 : aMtrFldLine2.SetSpinSize( 50 );
139 0 : aMtrFldLine3.SetSpinSize( 50 );
140 : }
141 :
142 : // disable 3D border
143 0 : aCtlPreview.SetBorderStyle(WINDOW_BORDER_MONO);
144 :
145 0 : Link aLink( LINK( this, SvxConnectionPage, ChangeAttrHdl_Impl ) );
146 0 : aMtrFldHorz1.SetModifyHdl( aLink );
147 0 : aMtrFldVert1.SetModifyHdl( aLink );
148 0 : aMtrFldHorz2.SetModifyHdl( aLink );
149 0 : aMtrFldVert2.SetModifyHdl( aLink );
150 0 : aMtrFldLine1.SetModifyHdl( aLink );
151 0 : aMtrFldLine2.SetModifyHdl( aLink );
152 0 : aMtrFldLine3.SetModifyHdl( aLink );
153 0 : aLbType.SetSelectHdl( aLink );
154 0 : }
155 :
156 : /*************************************************************************
157 : |*
158 : |* Dtor
159 : |*
160 : \************************************************************************/
161 :
162 0 : SvxConnectionPage::~SvxConnectionPage()
163 : {
164 0 : }
165 :
166 : /*************************************************************************
167 : |*
168 : |* reads passed Item-Set
169 : |*
170 : \************************************************************************/
171 :
172 0 : void SvxConnectionPage::Reset( const SfxItemSet& rAttrs )
173 : {
174 0 : const SfxPoolItem* pItem = GetItem( rAttrs, SDRATTR_EDGENODE1HORZDIST );
175 0 : const SfxItemPool* pPool = rAttrs.GetPool();
176 :
177 : // SdrEdgeNode1HorzDistItem
178 0 : if( !pItem )
179 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1HORZDIST );
180 0 : if( pItem )
181 : {
182 0 : long nValue = ( ( const SdrEdgeNode1HorzDistItem* )pItem )->GetValue();
183 0 : SetMetricValue( aMtrFldHorz1, nValue, eUnit );
184 : }
185 : else
186 0 : aMtrFldHorz1.SetEmptyFieldValue();
187 :
188 0 : aMtrFldHorz1.SaveValue();
189 :
190 : // SdrEdgeNode2HorzDistItem
191 0 : pItem = GetItem( rAttrs, SDRATTR_EDGENODE2HORZDIST );
192 0 : if( !pItem )
193 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2HORZDIST );
194 0 : if( pItem )
195 : {
196 0 : long nValue = ( ( const SdrEdgeNode2HorzDistItem* )pItem )->GetValue();
197 0 : SetMetricValue( aMtrFldHorz2, nValue, eUnit );
198 : }
199 : else
200 0 : aMtrFldHorz2.SetEmptyFieldValue();
201 :
202 0 : aMtrFldHorz2.SaveValue();
203 :
204 : // SdrEdgeNode1VertDistItem
205 0 : pItem = GetItem( rAttrs, SDRATTR_EDGENODE1VERTDIST );
206 0 : if( !pItem )
207 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE1VERTDIST );
208 0 : if( pItem )
209 : {
210 0 : long nValue = ( ( const SdrEdgeNode1VertDistItem* )pItem )->GetValue();
211 0 : SetMetricValue( aMtrFldVert1, nValue, eUnit );
212 : }
213 : else
214 0 : aMtrFldVert1.SetEmptyFieldValue();
215 :
216 0 : aMtrFldVert1.SaveValue();
217 :
218 : // SdrEdgeNode2VertDistItem
219 0 : pItem = GetItem( rAttrs, SDRATTR_EDGENODE2VERTDIST );
220 0 : if( !pItem )
221 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGENODE2VERTDIST );
222 0 : if( pItem )
223 : {
224 0 : long nValue = ( ( const SdrEdgeNode2VertDistItem* )pItem )->GetValue();
225 0 : SetMetricValue( aMtrFldVert2, nValue, eUnit );
226 : }
227 : else
228 0 : aMtrFldVert2.SetEmptyFieldValue();
229 :
230 0 : aMtrFldVert2.SaveValue();
231 :
232 : // SdrEdgeLine1DeltaItem
233 0 : pItem = GetItem( rAttrs, SDRATTR_EDGELINE1DELTA );
234 0 : if( !pItem )
235 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE1DELTA );
236 0 : if( pItem )
237 : {
238 0 : long nValue = ( ( const SdrEdgeLine1DeltaItem* )pItem )->GetValue();
239 0 : SetMetricValue( aMtrFldLine1, nValue, eUnit );
240 : }
241 : else
242 0 : aMtrFldLine1.SetEmptyFieldValue();
243 :
244 0 : aMtrFldLine1.SaveValue();
245 :
246 : // SdrEdgeLine2DeltaItem
247 0 : pItem = GetItem( rAttrs, SDRATTR_EDGELINE2DELTA );
248 0 : if( !pItem )
249 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE2DELTA );
250 0 : if( pItem )
251 : {
252 0 : long nValue = ( ( const SdrEdgeLine2DeltaItem* )pItem )->GetValue();
253 0 : SetMetricValue( aMtrFldLine2, nValue, eUnit );
254 : }
255 : else
256 0 : aMtrFldLine2.SetEmptyFieldValue();
257 :
258 0 : aMtrFldLine2.SaveValue();
259 :
260 : // SdrEdgeLine3DeltaItem
261 0 : pItem = GetItem( rAttrs, SDRATTR_EDGELINE3DELTA );
262 0 : if( !pItem )
263 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINE3DELTA );
264 0 : if( pItem )
265 : {
266 0 : long nValue = ( ( const SdrEdgeLine3DeltaItem* )pItem )->GetValue();
267 0 : SetMetricValue( aMtrFldLine3, nValue, eUnit );
268 : }
269 : else
270 0 : aMtrFldLine3.SetEmptyFieldValue();
271 :
272 0 : aMtrFldLine3.SaveValue();
273 :
274 : // SdrEdgeLineDeltaAnzItem
275 0 : pItem = GetItem( rAttrs, SDRATTR_EDGELINEDELTAANZ );
276 0 : if( !pItem )
277 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGELINEDELTAANZ );
278 0 : if( pItem )
279 : {
280 0 : sal_uInt16 nValue = ( ( const SdrEdgeLineDeltaAnzItem* )pItem )->GetValue();
281 0 : if( nValue <= 2 )
282 : {
283 0 : aFtLine3.Enable( sal_False );
284 0 : aMtrFldLine3.Enable( sal_False );
285 0 : aMtrFldLine3.SetEmptyFieldValue();
286 : }
287 0 : if( nValue <= 1 )
288 : {
289 0 : aFtLine2.Enable( sal_False );
290 0 : aMtrFldLine2.Enable( sal_False );
291 0 : aMtrFldLine2.SetEmptyFieldValue();
292 : }
293 0 : if( nValue == 0 )
294 : {
295 0 : aFtLine1.Enable( sal_False );
296 0 : aMtrFldLine1.Enable( sal_False );
297 0 : aMtrFldLine1.SetEmptyFieldValue();
298 : }
299 : }
300 :
301 : // SdrEdgeKindItem
302 0 : pItem = GetItem( rAttrs, SDRATTR_EDGEKIND );
303 0 : if( !pItem )
304 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
305 0 : if( pItem )
306 : {
307 0 : SdrEdgeKind nValue = ( ( const SdrEdgeKindItem* )pItem )->GetValue();
308 0 : aLbType.SelectEntryPos( sal::static_int_cast< sal_uInt16 >(nValue) );
309 : }
310 : else
311 0 : aLbType.SetNoSelection();
312 0 : aLbType.SaveValue();
313 0 : }
314 :
315 : /*************************************************************************
316 : |*
317 : |* fills the passed Item-Set width Dialogbox attributes
318 : |*
319 : \************************************************************************/
320 :
321 0 : sal_Bool SvxConnectionPage::FillItemSet( SfxItemSet& rAttrs)
322 : {
323 0 : sal_Bool bModified = sal_False;
324 : sal_Int32 nValue;
325 :
326 0 : if( aMtrFldHorz1.GetText() != aMtrFldHorz1.GetSavedValue() )
327 : {
328 0 : nValue = GetCoreValue( aMtrFldHorz1, eUnit );
329 0 : rAttrs.Put( SdrEdgeNode1HorzDistItem( nValue ) );
330 0 : bModified = sal_True;
331 : }
332 :
333 0 : if( aMtrFldHorz2.GetText() != aMtrFldHorz2.GetSavedValue() )
334 : {
335 0 : nValue = GetCoreValue( aMtrFldHorz2, eUnit );
336 0 : rAttrs.Put( SdrEdgeNode2HorzDistItem( nValue ) );
337 0 : bModified = sal_True;
338 : }
339 :
340 0 : if( aMtrFldVert1.GetText() != aMtrFldVert1.GetSavedValue() )
341 : {
342 0 : nValue = GetCoreValue( aMtrFldVert1, eUnit );
343 0 : rAttrs.Put( SdrEdgeNode1VertDistItem( nValue ) );
344 0 : bModified = sal_True;
345 : }
346 :
347 0 : if( aMtrFldVert2.GetText() != aMtrFldVert2.GetSavedValue() )
348 : {
349 0 : nValue = GetCoreValue( aMtrFldVert2, eUnit );
350 0 : rAttrs.Put( SdrEdgeNode2VertDistItem( nValue ) );
351 0 : bModified = sal_True;
352 : }
353 :
354 0 : if( aMtrFldLine1.GetText() != aMtrFldLine1.GetSavedValue() )
355 : {
356 0 : nValue = GetCoreValue( aMtrFldLine1, eUnit );
357 0 : rAttrs.Put( SdrEdgeLine1DeltaItem( nValue ) );
358 0 : bModified = sal_True;
359 : }
360 :
361 0 : if( aMtrFldLine2.GetText() != aMtrFldLine2.GetSavedValue() )
362 : {
363 0 : nValue = GetCoreValue( aMtrFldLine2, eUnit );
364 0 : rAttrs.Put( SdrEdgeLine2DeltaItem( nValue ) );
365 0 : bModified = sal_True;
366 : }
367 :
368 0 : if( aMtrFldLine3.GetText() != aMtrFldLine3.GetSavedValue() )
369 : {
370 0 : nValue = GetCoreValue( aMtrFldLine3, eUnit );
371 0 : rAttrs.Put( SdrEdgeLine3DeltaItem( nValue ) );
372 0 : bModified = sal_True;
373 : }
374 :
375 :
376 0 : sal_uInt16 nPos = aLbType.GetSelectEntryPos();
377 0 : if( nPos != aLbType.GetSavedValue() )
378 : {
379 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
380 : {
381 0 : rAttrs.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
382 0 : bModified = sal_True;
383 : }
384 : }
385 :
386 0 : return( bModified );
387 : }
388 :
389 0 : void SvxConnectionPage::Construct()
390 : {
391 : DBG_ASSERT( pView, "Keine gueltige View Uebergeben!" );
392 :
393 0 : aCtlPreview.SetView( pView );
394 0 : aCtlPreview.Construct();
395 0 : }
396 :
397 : /*************************************************************************
398 : |*
399 : |* creates the page
400 : |*
401 : \************************************************************************/
402 :
403 0 : SfxTabPage* SvxConnectionPage::Create( Window* pWindow,
404 : const SfxItemSet& rAttrs )
405 : {
406 0 : return( new SvxConnectionPage( pWindow, rAttrs ) );
407 : }
408 :
409 0 : sal_uInt16* SvxConnectionPage::GetRanges()
410 : {
411 0 : return( pRanges );
412 : }
413 :
414 0 : IMPL_LINK( SvxConnectionPage, ChangeAttrHdl_Impl, void *, p )
415 : {
416 0 : if( p == &aMtrFldHorz1 )
417 : {
418 0 : sal_Int32 nValue = GetCoreValue( aMtrFldHorz1, eUnit );
419 0 : aAttrSet.Put( SdrEdgeNode1HorzDistItem( nValue ) );
420 : }
421 :
422 0 : if( p == &aMtrFldHorz2 )
423 : {
424 0 : sal_Int32 nValue = GetCoreValue( aMtrFldHorz2, eUnit );
425 0 : aAttrSet.Put( SdrEdgeNode2HorzDistItem( nValue ) );
426 : }
427 :
428 0 : if( p == &aMtrFldVert1 )
429 : {
430 0 : sal_Int32 nValue = GetCoreValue( aMtrFldVert1, eUnit );
431 0 : aAttrSet.Put( SdrEdgeNode1VertDistItem( nValue ) );
432 : }
433 :
434 0 : if( p == &aMtrFldVert2 )
435 : {
436 0 : sal_Int32 nValue = GetCoreValue( aMtrFldVert2, eUnit );
437 0 : aAttrSet.Put( SdrEdgeNode2VertDistItem( nValue ) );
438 : }
439 :
440 0 : if( p == &aMtrFldLine1 )
441 : {
442 0 : sal_Int32 nValue = GetCoreValue( aMtrFldLine1, eUnit );
443 0 : aAttrSet.Put( SdrEdgeLine1DeltaItem( nValue ) );
444 : }
445 :
446 0 : if( p == &aMtrFldLine2 )
447 : {
448 0 : sal_Int32 nValue = GetCoreValue( aMtrFldLine2, eUnit );
449 0 : aAttrSet.Put( SdrEdgeLine2DeltaItem( nValue ) );
450 : }
451 :
452 0 : if( p == &aMtrFldLine3 )
453 : {
454 0 : sal_Int32 nValue = GetCoreValue( aMtrFldLine3, eUnit );
455 0 : aAttrSet.Put( SdrEdgeLine3DeltaItem( nValue ) );
456 : }
457 :
458 :
459 0 : if( p == &aLbType )
460 : {
461 0 : sal_uInt16 nPos = aLbType.GetSelectEntryPos();
462 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND )
463 : {
464 0 : aAttrSet.Put( SdrEdgeKindItem( (SdrEdgeKind) nPos ) );
465 : }
466 : }
467 :
468 0 : aCtlPreview.SetAttributes( aAttrSet );
469 :
470 0 : if( p == &aLbType )
471 : {
472 : // get the number of line displacements
473 0 : sal_uInt16 nCount = aCtlPreview.GetLineDeltaAnz();
474 :
475 0 : aFtLine3.Enable( nCount > 2 );
476 0 : aMtrFldLine3.Enable( nCount > 2 );
477 0 : if( nCount > 2 )
478 0 : aMtrFldLine3.SetValue( aMtrFldLine3.GetValue() );
479 : else
480 0 : aMtrFldLine3.SetEmptyFieldValue();
481 :
482 0 : aFtLine2.Enable( nCount > 1 );
483 0 : aMtrFldLine2.Enable( nCount > 1 );
484 0 : if( nCount > 1 )
485 0 : aMtrFldLine2.SetValue( aMtrFldLine2.GetValue() );
486 : else
487 0 : aMtrFldLine2.SetEmptyFieldValue();
488 :
489 0 : aFtLine1.Enable( nCount > 0 );
490 0 : aMtrFldLine1.Enable( nCount > 0 );
491 0 : if( nCount > 0 )
492 0 : aMtrFldLine1.SetValue( aMtrFldLine1.GetValue() );
493 : else
494 0 : aMtrFldLine1.SetEmptyFieldValue();
495 :
496 : }
497 :
498 0 : return( 0L );
499 : }
500 :
501 0 : void SvxConnectionPage::FillTypeLB()
502 : {
503 : // fill ListBox with connector names
504 0 : const SfxPoolItem* pItem = GetItem( rOutAttrs, SDRATTR_EDGEKIND );
505 0 : const SfxItemPool* pPool = rOutAttrs.GetPool();
506 :
507 0 : if( !pItem )
508 0 : pItem = &pPool->GetDefaultItem( SDRATTR_EDGEKIND );
509 0 : if( pItem )
510 : {
511 0 : const SdrEdgeKindItem* pEdgeKindItem = (const SdrEdgeKindItem*) pItem;
512 0 : sal_uInt16 nCount = pEdgeKindItem->GetValueCount();
513 0 : String aStr;
514 :
515 0 : for( sal_uInt16 i = 0; i < nCount; i++ )
516 : {
517 0 : aStr = pEdgeKindItem->GetValueTextByPos( i );
518 0 : aLbType.InsertEntry( aStr );
519 0 : }
520 : }
521 0 : }
522 0 : void SvxConnectionPage::PageCreated (SfxAllItemSet aSet)
523 : {
524 0 : SFX_ITEMSET_ARG(&aSet,pOfaPtrItem,OfaPtrItem,SID_OBJECT_LIST,sal_False);
525 0 : if (pOfaPtrItem)
526 0 : SetView( static_cast<SdrView *>(pOfaPtrItem->GetValue()) );
527 :
528 0 : Construct();
529 0 : }
530 :
531 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|