bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / tabpages / textanim.cxx
blobeb58430b65b157f3396d872a870ca20b0bfb0978
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 <sfx2/app.hxx>
21 #include <sfx2/module.hxx>
23 #include <cuires.hrc>
24 #include <svx/dialogs.hrc>
26 #include "textanim.hxx"
27 #include "textattr.hxx"
28 #include <dialmgr.hxx>
29 #include "svx/dlgutil.hxx"
31 const sal_uInt16 SvxTextAnimationPage::pRanges[] =
33 SDRATTR_TEXT_ANIKIND,
34 SDRATTR_TEXT_ANIAMOUNT,
38 /*************************************************************************
40 |* constructor of the tab dialog: adds pages to the dialog
42 \************************************************************************/
44 SvxTextTabDialog::SvxTextTabDialog( vcl::Window* pParent,
45 const SfxItemSet* pAttr,
46 const SdrView* pSdrView ) :
47 SfxTabDialog ( pParent
48 ,"TextDialog"
49 ,"cui/ui/textdialog.ui"
50 , pAttr ),
51 pView ( pSdrView )
53 m_nTextId = AddTabPage( "RID_SVXPAGE_TEXTATTR", SvxTextAttrPage::Create, 0);
54 m_nTextAnimId = AddTabPage( "RID_SVXPAGE_TEXTANIMATION", SvxTextAnimationPage::Create, 0);
57 /*************************************************************************
59 |* PageCreated()
61 \************************************************************************/
63 void SvxTextTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
65 if (nId == m_nTextId)
67 static_cast<SvxTextAttrPage&>(rPage).SetView( pView );
68 static_cast<SvxTextAttrPage&>(rPage).Construct();
73 /*************************************************************************
75 |* Page
77 \************************************************************************/
79 SvxTextAnimationPage::SvxTextAnimationPage( vcl::Window* pWindow, const SfxItemSet& rInAttrs ) :
80 SfxTabPage ( pWindow
81 ,"TextAnimation"
82 ,"cui/ui/textanimtabpage.ui"
83 ,&rInAttrs ),
84 rOutAttrs ( rInAttrs ),
85 eAniKind ( SDRTEXTANI_NONE )
87 get(m_pLbEffect, "LB_EFFECT");
88 get(m_pBoxDirection,"boxDIRECTION");
89 get(m_pBtnUp, "BTN_UP");
90 get(m_pBtnLeft, "BTN_LEFT");
91 get(m_pBtnRight, "BTN_RIGHT");
92 get(m_pBtnDown, "BTN_DOWN");
94 get(m_pFlProperties, "FL_PROPERTIES");
95 get(m_pTsbStartInside, "TSB_START_INSIDE");
96 get(m_pTsbStopInside, "TSB_STOP_INSIDE");
98 get(m_pBoxCount, "boxCOUNT");
99 get(m_pTsbEndless,"TSB_ENDLESS");
100 get(m_pNumFldCount,"NUM_FLD_COUNT");
102 get(m_pTsbPixel, "TSB_PIXEL");
103 get(m_pMtrFldAmount, "MTR_FLD_AMOUNT");
105 get(m_pTsbAuto, "TSB_AUTO");
106 get(m_pMtrFldDelay, "MTR_FLD_DELAY");
108 eFUnit = GetModuleFieldUnit( rInAttrs );
109 SfxItemPool* pPool = rOutAttrs.GetPool();
110 DBG_ASSERT( pPool, "Wo ist der Pool" );
111 eUnit = pPool->GetMetric( SDRATTR_TEXT_LEFTDIST );
113 m_pLbEffect->SetSelectHdl( LINK( this, SvxTextAnimationPage, SelectEffectHdl_Impl ) );
114 m_pTsbEndless->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickEndlessHdl_Impl ) );
115 m_pTsbAuto->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickAutoHdl_Impl ) );
116 m_pTsbPixel->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickPixelHdl_Impl ) );
118 Link<> aLink( LINK( this, SvxTextAnimationPage, ClickDirectionHdl_Impl ) );
119 m_pBtnUp->SetClickHdl( aLink );
120 m_pBtnLeft->SetClickHdl( aLink );
121 m_pBtnRight->SetClickHdl( aLink );
122 m_pBtnDown->SetClickHdl( aLink );
125 SvxTextAnimationPage::~SvxTextAnimationPage()
127 disposeOnce();
130 void SvxTextAnimationPage::dispose()
132 m_pLbEffect.clear();
133 m_pBoxDirection.clear();
134 m_pBtnUp.clear();
135 m_pBtnLeft.clear();
136 m_pBtnRight.clear();
137 m_pBtnDown.clear();
138 m_pFlProperties.clear();
139 m_pTsbStartInside.clear();
140 m_pTsbStopInside.clear();
141 m_pBoxCount.clear();
142 m_pTsbEndless.clear();
143 m_pNumFldCount.clear();
144 m_pTsbPixel.clear();
145 m_pMtrFldAmount.clear();
146 m_pTsbAuto.clear();
147 m_pMtrFldDelay.clear();
148 SfxTabPage::dispose();
151 /*************************************************************************
153 |* reads the passed item set
155 \************************************************************************/
157 void SvxTextAnimationPage::Reset( const SfxItemSet* rAttrs )
159 const SfxItemPool* pPool = rAttrs->GetPool();
161 // animation type
162 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIKIND );
164 if( !pItem )
165 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIKIND );
166 if( pItem )
168 eAniKind = static_cast<const SdrTextAniKindItem*>(pItem)->GetValue();
169 m_pLbEffect->SelectEntryPos( sal::static_int_cast< sal_Int32 >(eAniKind) );
171 else
172 m_pLbEffect->SetNoSelection();
173 m_pLbEffect->SaveValue();
175 // animation direction
176 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIDIRECTION );
177 if( !pItem )
178 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDIRECTION );
179 if( pItem )
181 SdrTextAniDirection eValue = static_cast<const SdrTextAniDirectionItem*>(pItem)->GetValue();
182 SelectDirection( eValue );
184 else
186 m_pBtnUp->Check( false );
187 m_pBtnLeft->Check( false );
188 m_pBtnRight->Check( false );
189 m_pBtnDown->Check( false );
191 m_pBtnUp->SaveValue();
192 m_pBtnLeft->SaveValue();
193 m_pBtnRight->SaveValue();
194 m_pBtnDown->SaveValue();
196 // Start inside
197 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANISTARTINSIDE );
198 if( !pItem )
199 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTARTINSIDE );
200 if( pItem )
202 m_pTsbStartInside->EnableTriState( false );
203 bool bValue = static_cast<const SdrTextAniStartInsideItem*>(pItem)->GetValue();
204 if( bValue )
205 m_pTsbStartInside->SetState( TRISTATE_TRUE );
206 else
207 m_pTsbStartInside->SetState( TRISTATE_FALSE );
209 else
210 m_pTsbStartInside->SetState( TRISTATE_INDET );
211 m_pTsbStartInside->SaveValue();
213 // Stop inside
214 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANISTOPINSIDE );
215 if( !pItem )
216 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTOPINSIDE );
217 if( pItem )
219 m_pTsbStopInside->EnableTriState( false );
220 bool bValue = static_cast<const SdrTextAniStopInsideItem*>(pItem)->GetValue();
221 if( bValue )
222 m_pTsbStopInside->SetState( TRISTATE_TRUE );
223 else
224 m_pTsbStopInside->SetState( TRISTATE_FALSE );
226 else
227 m_pTsbStopInside->SetState( TRISTATE_INDET );
228 m_pTsbStopInside->SaveValue();
230 // quantity
231 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANICOUNT );
232 if( !pItem )
233 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANICOUNT );
234 if( pItem )
236 m_pTsbEndless->EnableTriState( false );
237 long nValue = (long) static_cast<const SdrTextAniCountItem*>(pItem)->GetValue();
238 m_pNumFldCount->SetValue( nValue );
239 if( nValue == 0 )
241 if( eAniKind == SDRTEXTANI_SLIDE )
243 m_pTsbEndless->SetState( TRISTATE_FALSE );
244 m_pTsbEndless->Enable( false );
246 else
248 m_pTsbEndless->SetState( TRISTATE_TRUE );
249 m_pNumFldCount->SetEmptyFieldValue();
252 else
253 m_pTsbEndless->SetState( TRISTATE_FALSE );
255 else
257 m_pNumFldCount->SetEmptyFieldValue();
258 m_pTsbEndless->SetState( TRISTATE_INDET );
260 m_pTsbEndless->SaveValue();
261 m_pNumFldCount->SaveValue();
263 // delay
264 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIDELAY );
265 if( !pItem )
266 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDELAY );
267 if( pItem )
269 m_pTsbAuto->EnableTriState( false );
270 long nValue = (long) static_cast<const SdrTextAniDelayItem*>(pItem)->GetValue();
271 m_pMtrFldDelay->SetValue( nValue );
272 if( nValue == 0 )
274 m_pTsbAuto->SetState( TRISTATE_TRUE );
275 m_pMtrFldDelay->SetEmptyFieldValue();
277 else
278 m_pTsbAuto->SetState( TRISTATE_FALSE );
280 else
282 m_pMtrFldDelay->SetEmptyFieldValue();
283 m_pTsbAuto->SetState( TRISTATE_INDET );
285 m_pTsbAuto->SaveValue();
286 m_pMtrFldDelay->SaveValue();
288 // step size
289 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIAMOUNT );
290 if( !pItem )
291 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIAMOUNT );
292 if( pItem )
294 m_pTsbPixel->EnableTriState( false );
295 long nValue = (long) static_cast<const SdrTextAniAmountItem*>(pItem)->GetValue();
296 if( nValue <= 0 )
298 m_pTsbPixel->SetState( TRISTATE_TRUE );
299 nValue = -nValue;
300 if( nValue == 0 )
301 nValue++;
302 m_pMtrFldAmount->SetUnit( FUNIT_CUSTOM );
303 m_pMtrFldAmount->SetDecimalDigits( 0 );
305 m_pMtrFldAmount->SetSpinSize( 1 );
306 m_pMtrFldAmount->SetMin( 1 );
307 m_pMtrFldAmount->SetFirst( 1 );
308 m_pMtrFldAmount->SetMax( 100 );
309 m_pMtrFldAmount->SetLast( 100 );
311 m_pMtrFldAmount->SetValue( nValue );
313 else
315 m_pTsbPixel->SetState( TRISTATE_FALSE );
316 m_pMtrFldAmount->SetUnit( eFUnit );
317 m_pMtrFldAmount->SetDecimalDigits( 2 );
319 m_pMtrFldAmount->SetSpinSize( 10 );
320 m_pMtrFldAmount->SetMin( 1 );
321 m_pMtrFldAmount->SetFirst( 1 );
322 m_pMtrFldAmount->SetMax( 10000 );
323 m_pMtrFldAmount->SetLast( 10000 );
325 SetMetricValue( *m_pMtrFldAmount, nValue, eUnit );
328 else
330 m_pMtrFldAmount->Disable();
331 m_pMtrFldAmount->SetEmptyFieldValue();
332 m_pTsbPixel->SetState( TRISTATE_INDET );
334 m_pTsbPixel->SaveValue();
335 m_pMtrFldAmount->SaveValue();
338 SelectEffectHdl_Impl( NULL );
339 ClickEndlessHdl_Impl( NULL );
340 ClickAutoHdl_Impl( NULL );
341 //ClickPixelHdl_Impl( NULL );
344 /*************************************************************************
346 |* fills the passed item set with dialog box attributes
348 \************************************************************************/
350 bool SvxTextAnimationPage::FillItemSet( SfxItemSet* rAttrs)
352 bool bModified = false;
353 sal_Int32 nPos;
354 TriState eState;
356 // animation type
357 nPos = m_pLbEffect->GetSelectEntryPos();
358 if( nPos != LISTBOX_ENTRY_NOTFOUND &&
359 m_pLbEffect->IsValueChangedFromSaved() )
361 rAttrs->Put( SdrTextAniKindItem( (SdrTextAniKind) nPos ) );
362 bModified = true;
365 // animation direction
366 if( m_pBtnUp->IsValueChangedFromSaved() ||
367 m_pBtnLeft->IsValueChangedFromSaved() ||
368 m_pBtnRight->IsValueChangedFromSaved() ||
369 m_pBtnDown->IsValueChangedFromSaved() )
371 SdrTextAniDirection eValue = (SdrTextAniDirection) GetSelectedDirection();
372 rAttrs->Put( SdrTextAniDirectionItem( eValue ) );
373 bModified = true;
376 // Start inside
377 eState = m_pTsbStartInside->GetState();
378 if( m_pTsbStartInside->IsValueChangedFromSaved() )
380 rAttrs->Put( SdrTextAniStartInsideItem( TRISTATE_TRUE == eState ) );
381 bModified = true;
384 // Stop inside
385 eState = m_pTsbStopInside->GetState();
386 if( m_pTsbStopInside->IsValueChangedFromSaved() )
388 rAttrs->Put( SdrTextAniStopInsideItem( TRISTATE_TRUE == eState ) );
389 bModified = true;
392 // quantity
393 eState = m_pTsbEndless->GetState();
394 OUString aStr = m_pNumFldCount->GetText();
395 if( m_pTsbEndless->IsValueChangedFromSaved() ||
396 m_pNumFldCount->IsValueChangedFromSaved() )
398 sal_Int64 nValue = 0;
399 if( eState == TRISTATE_TRUE /*#89844#*/ && m_pTsbEndless->IsEnabled())
400 bModified = true;
401 else
403 if( m_pNumFldCount->IsValueChangedFromSaved() )
405 nValue = m_pNumFldCount->GetValue();
406 bModified = true;
409 if( bModified )
410 rAttrs->Put( SdrTextAniCountItem( (sal_uInt16) nValue ) );
413 // delay
414 eState = m_pTsbAuto->GetState();
415 aStr = m_pMtrFldDelay->GetText();
416 if( m_pTsbAuto->IsValueChangedFromSaved() ||
417 m_pMtrFldDelay->IsValueChangedFromSaved() )
419 sal_Int64 nValue = 0;
420 if( eState == TRISTATE_TRUE )
421 bModified = true;
422 else
424 if( m_pMtrFldDelay->IsValueChangedFromSaved() )
426 nValue = m_pMtrFldDelay->GetValue();
427 bModified = true;
430 if( bModified )
431 rAttrs->Put( SdrTextAniDelayItem( (sal_uInt16) nValue ) );
434 // step size
435 eState = m_pTsbPixel->GetState();
436 aStr = m_pMtrFldAmount->GetText();
437 if( m_pTsbPixel->IsValueChangedFromSaved() ||
438 m_pMtrFldAmount->IsValueChangedFromSaved() )
440 sal_Int64 nValue = 0;
441 if( eState == TRISTATE_TRUE )
443 nValue = m_pMtrFldAmount->GetValue();
444 nValue = -nValue;
446 else
448 nValue = GetCoreValue( *m_pMtrFldAmount, eUnit );
450 rAttrs->Put( SdrTextAniAmountItem( (sal_Int16) nValue ) );
452 bModified = true;
455 return bModified;
458 /*************************************************************************
460 |* creates the page
462 \************************************************************************/
464 VclPtr<SfxTabPage> SvxTextAnimationPage::Create( vcl::Window* pWindow,
465 const SfxItemSet* rAttrs )
467 return VclPtr<SvxTextAnimationPage>::Create( pWindow, *rAttrs );
470 IMPL_LINK_NOARG(SvxTextAnimationPage, SelectEffectHdl_Impl)
472 sal_Int32 nPos = m_pLbEffect->GetSelectEntryPos();
473 if( nPos != LISTBOX_ENTRY_NOTFOUND )
475 eAniKind = (SdrTextAniKind) nPos;
476 switch( eAniKind )
478 case SDRTEXTANI_NONE:
480 m_pBoxDirection->Disable();
481 m_pFlProperties->Disable();
483 break;
485 case SDRTEXTANI_BLINK:
486 case SDRTEXTANI_SCROLL:
487 case SDRTEXTANI_ALTERNATE:
488 case SDRTEXTANI_SLIDE:
490 m_pFlProperties->Enable();
491 if( eAniKind == SDRTEXTANI_SLIDE )
493 m_pTsbStartInside->Disable();
494 m_pTsbStopInside->Disable();
495 m_pTsbEndless->Disable();
496 m_pNumFldCount->Enable();
497 m_pNumFldCount->SetValue( m_pNumFldCount->GetValue() );
499 else
501 m_pTsbStartInside->Enable();
502 m_pTsbStopInside->Enable();
503 m_pTsbEndless->Enable();
504 ClickEndlessHdl_Impl( NULL );
507 m_pTsbAuto->Enable();
508 ClickAutoHdl_Impl( NULL );
510 if( eAniKind == SDRTEXTANI_BLINK )
512 m_pBoxDirection->Disable();
513 m_pBoxCount->Disable();
515 else
517 m_pBoxDirection->Enable();
518 m_pBoxCount->Enable();
521 break;
525 return 0L;
528 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickEndlessHdl_Impl)
531 if( eAniKind != SDRTEXTANI_SLIDE )
533 TriState eState = m_pTsbEndless->GetState();
534 if( eState != TRISTATE_FALSE )
536 m_pNumFldCount->Disable();
537 m_pNumFldCount->SetEmptyFieldValue();
539 else
541 m_pNumFldCount->Enable();
542 m_pNumFldCount->SetValue( m_pNumFldCount->GetValue() );
545 return 0L;
548 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickAutoHdl_Impl)
550 TriState eState = m_pTsbAuto->GetState();
551 if( eState != TRISTATE_FALSE )
553 m_pMtrFldDelay->Disable();
554 m_pMtrFldDelay->SetEmptyFieldValue();
556 else
558 m_pMtrFldDelay->Enable();
559 m_pMtrFldDelay->SetValue( m_pMtrFldDelay->GetValue() );
562 return 0L;
565 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickPixelHdl_Impl)
567 TriState eState = m_pTsbPixel->GetState();
568 if( eState == TRISTATE_TRUE )
570 sal_Int64 nValue = m_pMtrFldAmount->GetValue() / 10;
571 m_pMtrFldAmount->Enable();
572 m_pMtrFldAmount->SetUnit( FUNIT_CUSTOM );
573 //SetFieldUnit( aMtrFldAmount, FUNIT_CUSTOM );
574 m_pMtrFldAmount->SetDecimalDigits( 0 );
576 m_pMtrFldAmount->SetSpinSize( 1 );
577 m_pMtrFldAmount->SetMin( 1 );
578 m_pMtrFldAmount->SetFirst( 1 );
579 m_pMtrFldAmount->SetMax( 100 );
580 m_pMtrFldAmount->SetLast( 100 );
582 m_pMtrFldAmount->SetValue( nValue );
584 else if( eState == TRISTATE_FALSE )
586 sal_Int64 nValue = m_pMtrFldAmount->GetValue() * 10;
587 m_pMtrFldAmount->Enable();
588 m_pMtrFldAmount->SetUnit( eFUnit );
589 //SetFieldUnit( aMtrFldAmount, eFUnit );
590 m_pMtrFldAmount->SetDecimalDigits( 2 );
592 m_pMtrFldAmount->SetSpinSize( 10 );
593 m_pMtrFldAmount->SetMin( 1 );
594 m_pMtrFldAmount->SetFirst( 1 );
595 m_pMtrFldAmount->SetMax( 10000 );
596 m_pMtrFldAmount->SetLast( 10000 );
598 m_pMtrFldAmount->SetValue( nValue );
601 return 0L;
604 IMPL_LINK( SvxTextAnimationPage, ClickDirectionHdl_Impl, ImageButton *, pBtn )
606 m_pBtnUp->Check( pBtn == m_pBtnUp );
607 m_pBtnLeft->Check( pBtn == m_pBtnLeft );
608 m_pBtnRight->Check( pBtn == m_pBtnRight );
609 m_pBtnDown->Check( pBtn == m_pBtnDown );
611 return 0L;
614 void SvxTextAnimationPage::SelectDirection( SdrTextAniDirection nValue )
616 m_pBtnUp->Check( nValue == SDRTEXTANI_UP );
617 m_pBtnLeft->Check( nValue == SDRTEXTANI_LEFT );
618 m_pBtnRight->Check( nValue == SDRTEXTANI_RIGHT );
619 m_pBtnDown->Check( nValue == SDRTEXTANI_DOWN );
622 sal_uInt16 SvxTextAnimationPage::GetSelectedDirection()
624 sal_uInt16 nValue = 0;
626 if( m_pBtnUp->IsChecked() )
627 nValue = SDRTEXTANI_UP;
628 else if( m_pBtnLeft->IsChecked() )
629 nValue = SDRTEXTANI_LEFT;
630 else if( m_pBtnRight->IsChecked() )
631 nValue = SDRTEXTANI_RIGHT;
632 else if( m_pBtnDown->IsChecked() )
633 nValue = SDRTEXTANI_DOWN;
635 return nValue;
639 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */