Bump version to 4.3-4
[LibreOffice.git] / cui / source / tabpages / textanim.cxx
blob84cd104103ad7a4280e70df932fc0f382cf4a146
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>
22 #include <tools/shl.hxx>
24 #include <cuires.hrc>
25 #include <svx/dialogs.hrc>
27 #include "textanim.hxx"
28 #include "textattr.hxx"
29 #include <dialmgr.hxx>
30 #include "svx/dlgutil.hxx"
32 static const sal_uInt16 pRanges[] =
34 SDRATTR_TEXT_ANIKIND,
35 SDRATTR_TEXT_ANIAMOUNT,
39 /*************************************************************************
41 |* constructor of the tab dialog: adds pages to the dialog
43 \************************************************************************/
45 SvxTextTabDialog::SvxTextTabDialog( Window* pParent,
46 const SfxItemSet* pAttr,
47 const SdrView* pSdrView ) :
48 SfxTabDialog ( pParent
49 ,"TextDialog"
50 ,"cui/ui/textdialog.ui"
51 , pAttr ),
52 pView ( pSdrView )
54 m_nTextId = AddTabPage( "RID_SVXPAGE_TEXTATTR", SvxTextAttrPage::Create, 0);
55 m_nTextAnimId = AddTabPage( "RID_SVXPAGE_TEXTANIMATION", SvxTextAnimationPage::Create, 0);
58 /*************************************************************************
60 |* PageCreated()
62 \************************************************************************/
64 void SvxTextTabDialog::PageCreated( sal_uInt16 nId, SfxTabPage &rPage )
66 if (nId == m_nTextId)
68 ( (SvxTextAttrPage&) rPage ).SetView( pView );
69 ( (SvxTextAttrPage&) rPage ).Construct();
74 /*************************************************************************
76 |* Page
78 \************************************************************************/
80 SvxTextAnimationPage::SvxTextAnimationPage( Window* pWindow, const SfxItemSet& rInAttrs ) :
81 SfxTabPage ( pWindow
82 ,"TextAnimation"
83 ,"cui/ui/textanimtabpage.ui"
84 ,rInAttrs ),
85 rOutAttrs ( rInAttrs ),
86 eAniKind ( SDRTEXTANI_NONE )
88 get(m_pLbEffect, "LB_EFFECT");
89 get(m_pBoxDirection,"boxDIRECTION");
90 get(m_pBtnUp, "BTN_UP");
91 get(m_pBtnLeft, "BTN_LEFT");
92 get(m_pBtnRight, "BTN_RIGHT");
93 get(m_pBtnDown, "BTN_DOWN");
95 get(m_pFlProperties, "FL_PROPERTIES");
96 get(m_pTsbStartInside, "TSB_START_INSIDE");
97 get(m_pTsbStopInside, "TSB_STOP_INSIDE");
99 get(m_pBoxCount, "boxCOUNT");
100 get(m_pTsbEndless,"TSB_ENDLESS");
101 get(m_pNumFldCount,"NUM_FLD_COUNT");
103 get(m_pTsbPixel, "TSB_PIXEL");
104 get(m_pMtrFldAmount, "MTR_FLD_AMOUNT");
106 get(m_pTsbAuto, "TSB_AUTO");
107 get(m_pMtrFldDelay, "MTR_FLD_DELAY");
109 eFUnit = GetModuleFieldUnit( rInAttrs );
110 SfxItemPool* pPool = rOutAttrs.GetPool();
111 DBG_ASSERT( pPool, "Wo ist der Pool" );
112 eUnit = pPool->GetMetric( SDRATTR_TEXT_LEFTDIST );
114 m_pLbEffect->SetSelectHdl( LINK( this, SvxTextAnimationPage, SelectEffectHdl_Impl ) );
115 m_pTsbEndless->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickEndlessHdl_Impl ) );
116 m_pTsbAuto->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickAutoHdl_Impl ) );
117 m_pTsbPixel->SetClickHdl( LINK( this, SvxTextAnimationPage, ClickPixelHdl_Impl ) );
119 Link aLink( LINK( this, SvxTextAnimationPage, ClickDirectionHdl_Impl ) );
120 m_pBtnUp->SetClickHdl( aLink );
121 m_pBtnLeft->SetClickHdl( aLink );
122 m_pBtnRight->SetClickHdl( aLink );
123 m_pBtnDown->SetClickHdl( aLink );
126 /*************************************************************************
128 |* Dtor
130 \************************************************************************/
132 SvxTextAnimationPage::~SvxTextAnimationPage()
136 /*************************************************************************
138 |* reads the passed item set
140 \************************************************************************/
142 void SvxTextAnimationPage::Reset( const SfxItemSet& rAttrs )
144 const SfxItemPool* pPool = rAttrs.GetPool();
146 // animation type
147 const SfxPoolItem* pItem = GetItem( rAttrs, SDRATTR_TEXT_ANIKIND );
149 if( !pItem )
150 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIKIND );
151 if( pItem )
153 eAniKind = ( ( const SdrTextAniKindItem* )pItem )->GetValue();
154 m_pLbEffect->SelectEntryPos( sal::static_int_cast< sal_Int32 >(eAniKind) );
156 else
157 m_pLbEffect->SetNoSelection();
158 m_pLbEffect->SaveValue();
160 // animation direction
161 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANIDIRECTION );
162 if( !pItem )
163 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDIRECTION );
164 if( pItem )
166 SdrTextAniDirection eValue = ( ( const SdrTextAniDirectionItem* )pItem )->GetValue();
167 SelectDirection( eValue );
169 else
171 m_pBtnUp->Check( false );
172 m_pBtnLeft->Check( false );
173 m_pBtnRight->Check( false );
174 m_pBtnDown->Check( false );
176 m_pBtnUp->SaveValue();
177 m_pBtnLeft->SaveValue();
178 m_pBtnRight->SaveValue();
179 m_pBtnDown->SaveValue();
181 // Start inside
182 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANISTARTINSIDE );
183 if( !pItem )
184 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTARTINSIDE );
185 if( pItem )
187 m_pTsbStartInside->EnableTriState( false );
188 bool bValue = ( ( const SdrTextAniStartInsideItem* )pItem )->GetValue();
189 if( bValue )
190 m_pTsbStartInside->SetState( TRISTATE_TRUE );
191 else
192 m_pTsbStartInside->SetState( TRISTATE_FALSE );
194 else
195 m_pTsbStartInside->SetState( TRISTATE_INDET );
196 m_pTsbStartInside->SaveValue();
198 // Stop inside
199 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANISTOPINSIDE );
200 if( !pItem )
201 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTOPINSIDE );
202 if( pItem )
204 m_pTsbStopInside->EnableTriState( false );
205 bool bValue = ( ( const SdrTextAniStopInsideItem* )pItem )->GetValue();
206 if( bValue )
207 m_pTsbStopInside->SetState( TRISTATE_TRUE );
208 else
209 m_pTsbStopInside->SetState( TRISTATE_FALSE );
211 else
212 m_pTsbStopInside->SetState( TRISTATE_INDET );
213 m_pTsbStopInside->SaveValue();
215 // quantity
216 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANICOUNT );
217 if( !pItem )
218 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANICOUNT );
219 if( pItem )
221 m_pTsbEndless->EnableTriState( false );
222 long nValue = (long) ( ( const SdrTextAniCountItem* )pItem )->GetValue();
223 m_pNumFldCount->SetValue( nValue );
224 if( nValue == 0 )
226 if( eAniKind == SDRTEXTANI_SLIDE )
228 m_pTsbEndless->SetState( TRISTATE_FALSE );
229 m_pTsbEndless->Enable( false );
231 else
233 m_pTsbEndless->SetState( TRISTATE_TRUE );
234 m_pNumFldCount->SetEmptyFieldValue();
237 else
238 m_pTsbEndless->SetState( TRISTATE_FALSE );
240 else
242 m_pNumFldCount->SetEmptyFieldValue();
243 m_pTsbEndless->SetState( TRISTATE_INDET );
245 m_pTsbEndless->SaveValue();
246 m_pNumFldCount->SaveValue();
248 // delay
249 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANIDELAY );
250 if( !pItem )
251 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDELAY );
252 if( pItem )
254 m_pTsbAuto->EnableTriState( false );
255 long nValue = (long) ( ( const SdrTextAniDelayItem* )pItem )->GetValue();
256 m_pMtrFldDelay->SetValue( nValue );
257 if( nValue == 0 )
259 m_pTsbAuto->SetState( TRISTATE_TRUE );
260 m_pMtrFldDelay->SetEmptyFieldValue();
262 else
263 m_pTsbAuto->SetState( TRISTATE_FALSE );
265 else
267 m_pMtrFldDelay->SetEmptyFieldValue();
268 m_pTsbAuto->SetState( TRISTATE_INDET );
270 m_pTsbAuto->SaveValue();
271 m_pMtrFldDelay->SaveValue();
273 // step size
274 pItem = GetItem( rAttrs, SDRATTR_TEXT_ANIAMOUNT );
275 if( !pItem )
276 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIAMOUNT );
277 if( pItem )
279 m_pTsbPixel->EnableTriState( false );
280 long nValue = (long) ( ( const SdrTextAniAmountItem* )pItem )->GetValue();
281 if( nValue <= 0 )
283 m_pTsbPixel->SetState( TRISTATE_TRUE );
284 nValue = -nValue;
285 if( nValue == 0 )
286 nValue++;
287 m_pMtrFldAmount->SetUnit( FUNIT_CUSTOM );
288 m_pMtrFldAmount->SetDecimalDigits( 0 );
290 m_pMtrFldAmount->SetSpinSize( 1 );
291 m_pMtrFldAmount->SetMin( 1 );
292 m_pMtrFldAmount->SetFirst( 1 );
293 m_pMtrFldAmount->SetMax( 100 );
294 m_pMtrFldAmount->SetLast( 100 );
296 m_pMtrFldAmount->SetValue( nValue );
298 else
300 m_pTsbPixel->SetState( TRISTATE_FALSE );
301 m_pMtrFldAmount->SetUnit( eFUnit );
302 m_pMtrFldAmount->SetDecimalDigits( 2 );
304 m_pMtrFldAmount->SetSpinSize( 10 );
305 m_pMtrFldAmount->SetMin( 1 );
306 m_pMtrFldAmount->SetFirst( 1 );
307 m_pMtrFldAmount->SetMax( 10000 );
308 m_pMtrFldAmount->SetLast( 10000 );
310 SetMetricValue( *m_pMtrFldAmount, nValue, eUnit );
313 else
315 m_pMtrFldAmount->Disable();
316 m_pMtrFldAmount->SetEmptyFieldValue();
317 m_pTsbPixel->SetState( TRISTATE_INDET );
319 m_pTsbPixel->SaveValue();
320 m_pMtrFldAmount->SaveValue();
323 SelectEffectHdl_Impl( NULL );
324 ClickEndlessHdl_Impl( NULL );
325 ClickAutoHdl_Impl( NULL );
326 //ClickPixelHdl_Impl( NULL );
329 /*************************************************************************
331 |* fills the passed item set with dialog box attributes
333 \************************************************************************/
335 bool SvxTextAnimationPage::FillItemSet( SfxItemSet& rAttrs)
337 bool bModified = false;
338 sal_Int32 nPos;
339 TriState eState;
341 // animation type
342 nPos = m_pLbEffect->GetSelectEntryPos();
343 if( nPos != LISTBOX_ENTRY_NOTFOUND &&
344 m_pLbEffect->IsValueChangedFromSaved() )
346 rAttrs.Put( SdrTextAniKindItem( (SdrTextAniKind) nPos ) );
347 bModified = true;
350 // animation direction
351 if( m_pBtnUp->IsValueChangedFromSaved() ||
352 m_pBtnLeft->IsValueChangedFromSaved() ||
353 m_pBtnRight->IsValueChangedFromSaved() ||
354 m_pBtnDown->IsValueChangedFromSaved() )
356 SdrTextAniDirection eValue = (SdrTextAniDirection) GetSelectedDirection();
357 rAttrs.Put( SdrTextAniDirectionItem( eValue ) );
358 bModified = true;
361 // Start inside
362 eState = m_pTsbStartInside->GetState();
363 if( m_pTsbStartInside->IsValueChangedFromSaved() )
365 rAttrs.Put( SdrTextAniStartInsideItem( TRISTATE_TRUE == eState ) );
366 bModified = true;
369 // Stop inside
370 eState = m_pTsbStopInside->GetState();
371 if( m_pTsbStopInside->IsValueChangedFromSaved() )
373 rAttrs.Put( SdrTextAniStopInsideItem( TRISTATE_TRUE == eState ) );
374 bModified = true;
377 // quantity
378 eState = m_pTsbEndless->GetState();
379 OUString aStr = m_pNumFldCount->GetText();
380 if( m_pTsbEndless->IsValueChangedFromSaved() ||
381 m_pNumFldCount->IsValueChangedFromSaved() )
383 sal_Int64 nValue = 0;
384 if( eState == TRISTATE_TRUE /*#89844#*/ && m_pTsbEndless->IsEnabled())
385 bModified = true;
386 else
388 if( m_pNumFldCount->IsValueChangedFromSaved() )
390 nValue = m_pNumFldCount->GetValue();
391 bModified = true;
394 if( bModified )
395 rAttrs.Put( SdrTextAniCountItem( (sal_uInt16) nValue ) );
398 // delay
399 eState = m_pTsbAuto->GetState();
400 aStr = m_pMtrFldDelay->GetText();
401 if( m_pTsbAuto->IsValueChangedFromSaved() ||
402 m_pMtrFldDelay->IsValueChangedFromSaved() )
404 sal_Int64 nValue = 0;
405 if( eState == TRISTATE_TRUE )
406 bModified = true;
407 else
409 if( m_pMtrFldDelay->IsValueChangedFromSaved() )
411 nValue = m_pMtrFldDelay->GetValue();
412 bModified = true;
415 if( bModified )
416 rAttrs.Put( SdrTextAniDelayItem( (sal_uInt16) nValue ) );
419 // step size
420 eState = m_pTsbPixel->GetState();
421 aStr = m_pMtrFldAmount->GetText();
422 if( m_pTsbPixel->IsValueChangedFromSaved() ||
423 m_pMtrFldAmount->IsValueChangedFromSaved() )
425 sal_Int64 nValue = 0;
426 if( eState == TRISTATE_TRUE )
428 nValue = m_pMtrFldAmount->GetValue();
429 nValue = -nValue;
431 else
433 nValue = GetCoreValue( *m_pMtrFldAmount, eUnit );
435 rAttrs.Put( SdrTextAniAmountItem( (sal_Int16) nValue ) );
437 bModified = true;
440 return( bModified );
443 const sal_uInt16* SvxTextAnimationPage::GetRanges()
445 return( pRanges );
448 /*************************************************************************
450 |* creates the page
452 \************************************************************************/
454 SfxTabPage* SvxTextAnimationPage::Create( Window* pWindow,
455 const SfxItemSet& rAttrs )
457 return( new SvxTextAnimationPage( pWindow, rAttrs ) );
460 IMPL_LINK_NOARG(SvxTextAnimationPage, SelectEffectHdl_Impl)
462 sal_Int32 nPos = m_pLbEffect->GetSelectEntryPos();
463 if( nPos != LISTBOX_ENTRY_NOTFOUND )
465 eAniKind = (SdrTextAniKind) nPos;
466 switch( eAniKind )
468 case SDRTEXTANI_NONE:
470 m_pBoxDirection->Disable();
471 m_pFlProperties->Disable();
473 break;
475 case SDRTEXTANI_BLINK:
476 case SDRTEXTANI_SCROLL:
477 case SDRTEXTANI_ALTERNATE:
478 case SDRTEXTANI_SLIDE:
480 m_pFlProperties->Enable();
481 if( eAniKind == SDRTEXTANI_SLIDE )
483 m_pTsbStartInside->Disable();
484 m_pTsbStopInside->Disable();
485 m_pTsbEndless->Disable();
486 m_pNumFldCount->Enable();
487 m_pNumFldCount->SetValue( m_pNumFldCount->GetValue() );
489 else
491 m_pTsbStartInside->Enable();
492 m_pTsbStopInside->Enable();
493 m_pTsbEndless->Enable();
494 ClickEndlessHdl_Impl( NULL );
497 m_pTsbAuto->Enable();
498 ClickAutoHdl_Impl( NULL );
500 if( eAniKind == SDRTEXTANI_BLINK )
502 m_pBoxDirection->Disable();
503 m_pBoxCount->Disable();
505 else
507 m_pBoxDirection->Enable();
508 m_pBoxCount->Enable();
511 break;
515 return( 0L );
518 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickEndlessHdl_Impl)
521 if( eAniKind != SDRTEXTANI_SLIDE )
523 TriState eState = m_pTsbEndless->GetState();
524 if( eState != TRISTATE_FALSE )
526 m_pNumFldCount->Disable();
527 m_pNumFldCount->SetEmptyFieldValue();
529 else
531 m_pNumFldCount->Enable();
532 m_pNumFldCount->SetValue( m_pNumFldCount->GetValue() );
535 return( 0L );
538 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickAutoHdl_Impl)
540 TriState eState = m_pTsbAuto->GetState();
541 if( eState != TRISTATE_FALSE )
543 m_pMtrFldDelay->Disable();
544 m_pMtrFldDelay->SetEmptyFieldValue();
546 else
548 m_pMtrFldDelay->Enable();
549 m_pMtrFldDelay->SetValue( m_pMtrFldDelay->GetValue() );
552 return( 0L );
555 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickPixelHdl_Impl)
557 TriState eState = m_pTsbPixel->GetState();
558 if( eState == TRISTATE_TRUE )
560 sal_Int64 nValue = m_pMtrFldAmount->GetValue() / 10;
561 m_pMtrFldAmount->Enable();
562 m_pMtrFldAmount->SetUnit( FUNIT_CUSTOM );
563 //SetFieldUnit( aMtrFldAmount, FUNIT_CUSTOM );
564 m_pMtrFldAmount->SetDecimalDigits( 0 );
566 m_pMtrFldAmount->SetSpinSize( 1 );
567 m_pMtrFldAmount->SetMin( 1 );
568 m_pMtrFldAmount->SetFirst( 1 );
569 m_pMtrFldAmount->SetMax( 100 );
570 m_pMtrFldAmount->SetLast( 100 );
572 m_pMtrFldAmount->SetValue( nValue );
574 else if( eState == TRISTATE_FALSE )
576 sal_Int64 nValue = m_pMtrFldAmount->GetValue() * 10;
577 m_pMtrFldAmount->Enable();
578 m_pMtrFldAmount->SetUnit( eFUnit );
579 //SetFieldUnit( aMtrFldAmount, eFUnit );
580 m_pMtrFldAmount->SetDecimalDigits( 2 );
582 m_pMtrFldAmount->SetSpinSize( 10 );
583 m_pMtrFldAmount->SetMin( 1 );
584 m_pMtrFldAmount->SetFirst( 1 );
585 m_pMtrFldAmount->SetMax( 10000 );
586 m_pMtrFldAmount->SetLast( 10000 );
588 m_pMtrFldAmount->SetValue( nValue );
591 return( 0L );
594 IMPL_LINK( SvxTextAnimationPage, ClickDirectionHdl_Impl, ImageButton *, pBtn )
596 m_pBtnUp->Check( pBtn == m_pBtnUp );
597 m_pBtnLeft->Check( pBtn == m_pBtnLeft );
598 m_pBtnRight->Check( pBtn == m_pBtnRight );
599 m_pBtnDown->Check( pBtn == m_pBtnDown );
601 return( 0L );
604 void SvxTextAnimationPage::SelectDirection( SdrTextAniDirection nValue )
606 m_pBtnUp->Check( nValue == SDRTEXTANI_UP );
607 m_pBtnLeft->Check( nValue == SDRTEXTANI_LEFT );
608 m_pBtnRight->Check( nValue == SDRTEXTANI_RIGHT );
609 m_pBtnDown->Check( nValue == SDRTEXTANI_DOWN );
612 sal_uInt16 SvxTextAnimationPage::GetSelectedDirection()
614 sal_uInt16 nValue = 0;
616 if( m_pBtnUp->IsChecked() )
617 nValue = SDRTEXTANI_UP;
618 else if( m_pBtnLeft->IsChecked() )
619 nValue = SDRTEXTANI_LEFT;
620 else if( m_pBtnRight->IsChecked() )
621 nValue = SDRTEXTANI_RIGHT;
622 else if( m_pBtnDown->IsChecked() )
623 nValue = SDRTEXTANI_DOWN;
625 return( nValue );
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */