Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / cui / source / tabpages / textanim.cxx
blob254f87c79b48b177e122a1eecdc1c9c0e57e7c7c
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 <textanim.hxx>
21 #include <textattr.hxx>
22 #include <svx/dlgutil.hxx>
23 #include <svx/svdmark.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/sdtaaitm.hxx>
26 #include <svx/sdtacitm.hxx>
27 #include <svx/sdtaiitm.hxx>
28 #include <svx/sdtayitm.hxx>
29 #include <svtools/unitconv.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(weld::Window* pParent, const SfxItemSet* pAttr, const SdrView* pSdrView)
45 : SfxTabDialogController(pParent, "cui/ui/textdialog.ui", "TextDialog", pAttr)
46 , pView(pSdrView)
48 AddTabPage("RID_SVXPAGE_TEXTATTR", SvxTextAttrPage::Create, nullptr);
49 AddTabPage("RID_SVXPAGE_TEXTANIMATION", SvxTextAnimationPage::Create, nullptr);
52 /*************************************************************************
54 |* PageCreated()
56 \************************************************************************/
58 void SvxTextTabDialog::PageCreated(const OString& rId, SfxTabPage &rPage)
60 if (rId == "RID_SVXPAGE_TEXTATTR")
62 SdrObjKind eKind = OBJ_NONE;
63 if (pView)
65 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
66 bool bHasMarked = rMarkList.GetMarkCount() > 0;
67 if (bHasMarked)
69 if (rMarkList.GetMarkCount() == 1)
71 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
72 eKind = static_cast<SdrObjKind>(pObj->GetObjIdentifier());
76 static_cast<SvxTextAttrPage&>(rPage).SetObjKind(eKind);
77 static_cast<SvxTextAttrPage&>(rPage).Construct();
81 /*************************************************************************
83 |* Page
85 \************************************************************************/
86 SvxTextAnimationPage::SvxTextAnimationPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
87 : SfxTabPage(pPage, pController, "cui/ui/textanimtabpage.ui", "TextAnimation", &rInAttrs)
88 , rOutAttrs(rInAttrs)
89 , eAniKind(SdrTextAniKind::NONE)
90 , m_aUpState(TRISTATE_INDET)
91 , m_aLeftState(TRISTATE_INDET)
92 , m_aRightState(TRISTATE_INDET)
93 , m_aDownState(TRISTATE_INDET)
94 , m_xLbEffect(m_xBuilder->weld_combo_box("LB_EFFECT"))
95 , m_xBoxDirection(m_xBuilder->weld_widget("boxDIRECTION"))
96 , m_xBtnUp(m_xBuilder->weld_toggle_button("BTN_UP"))
97 , m_xBtnLeft(m_xBuilder->weld_toggle_button("BTN_LEFT"))
98 , m_xBtnRight(m_xBuilder->weld_toggle_button("BTN_RIGHT"))
99 , m_xBtnDown(m_xBuilder->weld_toggle_button("BTN_DOWN"))
100 , m_xFlProperties(m_xBuilder->weld_frame("FL_PROPERTIES"))
101 , m_xTsbStartInside(m_xBuilder->weld_check_button("TSB_START_INSIDE"))
102 , m_xTsbStopInside(m_xBuilder->weld_check_button("TSB_STOP_INSIDE"))
103 , m_xBoxCount(m_xBuilder->weld_widget("boxCOUNT"))
104 , m_xTsbEndless(m_xBuilder->weld_check_button("TSB_ENDLESS"))
105 , m_xNumFldCount(m_xBuilder->weld_spin_button("NUM_FLD_COUNT"))
106 , m_xTsbPixel(m_xBuilder->weld_check_button("TSB_PIXEL"))
107 , m_xMtrFldAmount(m_xBuilder->weld_metric_spin_button("MTR_FLD_AMOUNT", FieldUnit::PIXEL))
108 , m_xTsbAuto(m_xBuilder->weld_check_button("TSB_AUTO"))
109 , m_xMtrFldDelay(m_xBuilder->weld_metric_spin_button("MTR_FLD_DELAY", FieldUnit::MILLISECOND))
111 eFUnit = GetModuleFieldUnit( rInAttrs );
112 SfxItemPool* pPool = rOutAttrs.GetPool();
113 DBG_ASSERT( pPool, "Where is the pool?" );
114 eUnit = pPool->GetMetric( SDRATTR_TEXT_LEFTDIST );
116 m_xLbEffect->connect_changed( LINK( this, SvxTextAnimationPage, SelectEffectHdl_Impl ) );
117 m_xTsbEndless->connect_clicked( LINK( this, SvxTextAnimationPage, ClickEndlessHdl_Impl ) );
118 m_xTsbAuto->connect_clicked( LINK( this, SvxTextAnimationPage, ClickAutoHdl_Impl ) );
119 m_xTsbPixel->connect_clicked( LINK( this, SvxTextAnimationPage, ClickPixelHdl_Impl ) );
121 Link<weld::Button&,void> aLink( LINK( this, SvxTextAnimationPage, ClickDirectionHdl_Impl ) );
122 m_xBtnUp->connect_clicked( aLink );
123 m_xBtnLeft->connect_clicked( aLink );
124 m_xBtnRight->connect_clicked( aLink );
125 m_xBtnDown->connect_clicked( aLink );
128 SvxTextAnimationPage::~SvxTextAnimationPage()
132 /*************************************************************************
134 |* reads the passed item set
136 \************************************************************************/
138 void SvxTextAnimationPage::Reset( const SfxItemSet* rAttrs )
140 const SfxItemPool* pPool = rAttrs->GetPool();
142 // animation type
143 const SfxPoolItem* pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIKIND );
145 if( !pItem )
146 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIKIND );
148 eAniKind = static_cast<const SdrTextAniKindItem*>(pItem)->GetValue();
149 m_xLbEffect->set_active(sal::static_int_cast<sal_Int32>(eAniKind));
150 m_xLbEffect->save_value();
152 // animation direction
153 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIDIRECTION );
154 if( !pItem )
155 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDIRECTION );
157 SelectDirection(static_cast<const SdrTextAniDirectionItem*>(pItem)->GetValue());
158 m_aUpState = m_xBtnUp->get_state();
159 m_aLeftState = m_xBtnLeft->get_state();
160 m_aRightState = m_xBtnRight->get_state();
161 m_aDownState = m_xBtnDown->get_state();
163 // Start inside
164 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANISTARTINSIDE );
165 if( !pItem )
166 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTARTINSIDE );
168 if (static_cast<const SdrTextAniStartInsideItem*>(pItem)->GetValue())
169 m_xTsbStartInside->set_state(TRISTATE_TRUE);
170 else
171 m_xTsbStartInside->set_state(TRISTATE_FALSE);
172 m_xTsbStartInside->save_state();
174 // Stop inside
175 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANISTOPINSIDE );
176 if( !pItem )
177 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANISTOPINSIDE );
179 if (static_cast<const SdrTextAniStopInsideItem*>(pItem)->GetValue())
180 m_xTsbStopInside->set_state(TRISTATE_TRUE);
181 else
182 m_xTsbStopInside->set_state(TRISTATE_FALSE);
183 m_xTsbStopInside->save_state();
185 // quantity
186 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANICOUNT );
187 if( !pItem )
188 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANICOUNT );
190 long nValue = static_cast<long>(static_cast<const SdrTextAniCountItem*>(pItem)->GetValue());
191 m_xNumFldCount->set_value(nValue);
192 if (nValue == 0)
194 if (eAniKind == SdrTextAniKind::Slide)
196 m_xTsbEndless->set_state(TRISTATE_FALSE);
197 m_xTsbEndless->set_sensitive(false);
199 else
201 m_xTsbEndless->set_state(TRISTATE_TRUE);
202 m_xNumFldCount->set_text("");
205 else
206 m_xTsbEndless->set_state(TRISTATE_FALSE);
207 m_xTsbEndless->save_state();
208 m_xNumFldCount->save_value();
210 // delay
211 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIDELAY );
212 if( !pItem )
213 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIDELAY );
215 nValue = static_cast<long>(static_cast<const SdrTextAniDelayItem*>(pItem)->GetValue());
216 m_xMtrFldDelay->set_value(nValue, FieldUnit::NONE);
217 if (nValue == 0)
219 m_xTsbAuto->set_state(TRISTATE_TRUE);
220 m_xMtrFldDelay->set_text("");
222 else
223 m_xTsbAuto->set_state(TRISTATE_FALSE);
224 m_xTsbAuto->save_state();
225 m_xMtrFldDelay->save_value();
227 // step size
228 pItem = GetItem( *rAttrs, SDRATTR_TEXT_ANIAMOUNT );
229 if( !pItem )
230 pItem = &pPool->GetDefaultItem( SDRATTR_TEXT_ANIAMOUNT );
232 nValue = static_cast<long>(static_cast<const SdrTextAniAmountItem*>(pItem)->GetValue());
233 if (nValue <= 0)
235 m_xTsbPixel->set_state(TRISTATE_TRUE);
236 nValue = -nValue;
237 if (nValue == 0)
238 nValue++;
239 m_xMtrFldAmount->set_unit(FieldUnit::CUSTOM);
240 m_xMtrFldAmount->set_digits(0);
242 m_xMtrFldAmount->set_increments(1, 10, FieldUnit::NONE);
243 m_xMtrFldAmount->set_range(1, 100, FieldUnit::NONE);
244 m_xMtrFldAmount->set_value(nValue, FieldUnit::NONE);
246 else
248 m_xTsbPixel->set_state(TRISTATE_FALSE);
249 m_xMtrFldAmount->set_unit(eFUnit);
250 m_xMtrFldAmount->set_digits(2);
252 m_xMtrFldAmount->set_increments(10, 100, FieldUnit::NONE);
253 m_xMtrFldAmount->set_range(1, 10000, FieldUnit::NONE);
255 SetMetricValue(*m_xMtrFldAmount, nValue, eUnit);
257 m_xTsbPixel->save_state();
258 m_xMtrFldAmount->save_value();
260 SelectEffectHdl_Impl(*m_xLbEffect);
261 ClickEndlessHdl_Impl(*m_xTsbEndless);
262 ClickAutoHdl_Impl(*m_xTsbAuto);
265 /*************************************************************************
267 |* fills the passed item set with dialog box attributes
269 \************************************************************************/
271 bool SvxTextAnimationPage::FillItemSet( SfxItemSet* rAttrs)
273 bool bModified = false;
274 TriState eState;
276 // animation type
277 int nPos = m_xLbEffect->get_active();
278 if( nPos != -1 &&
279 m_xLbEffect->get_value_changed_from_saved() )
281 rAttrs->Put( SdrTextAniKindItem( static_cast<SdrTextAniKind>(nPos) ) );
282 bModified = true;
285 // animation direction
286 if (m_aUpState != m_xBtnUp->get_state() ||
287 m_aLeftState != m_xBtnLeft->get_state() ||
288 m_aRightState != m_xBtnRight->get_state() ||
289 m_aDownState != m_xBtnDown->get_state())
291 SdrTextAniDirection eValue = static_cast<SdrTextAniDirection>(GetSelectedDirection());
292 rAttrs->Put( SdrTextAniDirectionItem( eValue ) );
293 bModified = true;
296 // Start inside
297 eState = m_xTsbStartInside->get_state();
298 if (m_xTsbStartInside->get_state_changed_from_saved())
300 rAttrs->Put( SdrTextAniStartInsideItem( TRISTATE_TRUE == eState ) );
301 bModified = true;
304 // Stop inside
305 eState = m_xTsbStopInside->get_state();
306 if (m_xTsbStopInside->get_state_changed_from_saved())
308 rAttrs->Put( SdrTextAniStopInsideItem( TRISTATE_TRUE == eState ) );
309 bModified = true;
312 // quantity
313 eState = m_xTsbEndless->get_state();
314 if (m_xTsbEndless->get_state_changed_from_saved() ||
315 m_xNumFldCount->get_value_changed_from_saved())
317 sal_Int64 nValue = 0;
318 if( eState == TRISTATE_TRUE /*#89844#*/ && m_xTsbEndless->get_sensitive())
319 bModified = true;
320 else
322 if( m_xNumFldCount->get_value_changed_from_saved() )
324 nValue = m_xNumFldCount->get_value();
325 bModified = true;
328 if( bModified )
329 rAttrs->Put( SdrTextAniCountItem( static_cast<sal_uInt16>(nValue) ) );
332 // delay
333 eState = m_xTsbAuto->get_state();
334 if (m_xTsbAuto->get_state_changed_from_saved() ||
335 m_xMtrFldDelay->get_value_changed_from_saved())
337 sal_Int64 nValue = 0;
338 if( eState == TRISTATE_TRUE )
339 bModified = true;
340 else
342 if( m_xMtrFldDelay->get_value_changed_from_saved() )
344 nValue = m_xMtrFldDelay->get_value(FieldUnit::NONE);
345 bModified = true;
348 if( bModified )
349 rAttrs->Put( SdrTextAniDelayItem( static_cast<sal_uInt16>(nValue) ) );
352 // step size
353 eState = m_xTsbPixel->get_state();
354 if (m_xTsbPixel->get_state_changed_from_saved() ||
355 m_xMtrFldAmount->get_value_changed_from_saved())
357 sal_Int64 nValue = 0;
358 if( eState == TRISTATE_TRUE )
360 nValue = m_xMtrFldAmount->get_value(FieldUnit::NONE);
361 nValue = -nValue;
363 else
365 nValue = GetCoreValue( *m_xMtrFldAmount, eUnit );
367 rAttrs->Put( SdrTextAniAmountItem( static_cast<sal_Int16>(nValue) ) );
369 bModified = true;
372 return bModified;
375 /*************************************************************************
377 |* creates the page
379 \************************************************************************/
381 std::unique_ptr<SfxTabPage> SvxTextAnimationPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrs)
383 return std::make_unique<SvxTextAnimationPage>(pPage, pController, *rAttrs);
386 IMPL_LINK_NOARG(SvxTextAnimationPage, SelectEffectHdl_Impl, weld::ComboBox&, void)
388 int nPos = m_xLbEffect->get_active();
389 if (nPos != -1)
391 eAniKind = static_cast<SdrTextAniKind>(nPos);
392 switch( eAniKind )
394 case SdrTextAniKind::NONE:
396 m_xBoxDirection->set_sensitive(false);
397 m_xFlProperties->set_sensitive(false);
399 break;
401 case SdrTextAniKind::Blink:
402 case SdrTextAniKind::Scroll:
403 case SdrTextAniKind::Alternate:
404 case SdrTextAniKind::Slide:
406 m_xFlProperties->set_sensitive(true);
407 if( eAniKind == SdrTextAniKind::Slide )
409 m_xTsbStartInside->set_sensitive(false);
410 m_xTsbStopInside->set_sensitive(false);
411 m_xTsbEndless->set_sensitive(false);
412 m_xNumFldCount->set_sensitive(true);
413 m_xNumFldCount->set_value(m_xNumFldCount->get_value());
415 else
417 m_xTsbStartInside->set_sensitive(true);
418 m_xTsbStopInside->set_sensitive(true);
419 m_xTsbEndless->set_sensitive(true);
420 ClickEndlessHdl_Impl(*m_xTsbEndless);
423 m_xTsbAuto->set_sensitive(true);
424 ClickAutoHdl_Impl(*m_xTsbAuto);
426 if( eAniKind == SdrTextAniKind::Blink )
428 m_xBoxDirection->set_sensitive(false);
429 m_xBoxCount->set_sensitive(false);
431 else
433 m_xBoxDirection->set_sensitive(true);
434 m_xBoxCount->set_sensitive(true);
437 break;
443 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickEndlessHdl_Impl, weld::Button&, void)
445 if( eAniKind != SdrTextAniKind::Slide )
447 TriState eState = m_xTsbEndless->get_state();
448 if( eState != TRISTATE_FALSE )
450 m_xNumFldCount->set_sensitive(false);
451 m_xNumFldCount->set_text("");
453 else
455 m_xNumFldCount->set_sensitive(true);
456 m_xNumFldCount->set_value(m_xNumFldCount->get_value());
461 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickAutoHdl_Impl, weld::Button&, void)
463 TriState eState = m_xTsbAuto->get_state();
464 if( eState != TRISTATE_FALSE )
466 m_xMtrFldDelay->set_sensitive(false);
467 m_xMtrFldDelay->set_text("");
469 else
471 m_xMtrFldDelay->set_sensitive(true);
472 m_xMtrFldDelay->set_value(m_xMtrFldDelay->get_value(FieldUnit::NONE), FieldUnit::NONE); //to-do
476 IMPL_LINK_NOARG(SvxTextAnimationPage, ClickPixelHdl_Impl, weld::Button&, void)
478 TriState eState = m_xTsbPixel->get_state();
479 if (eState == TRISTATE_TRUE)
481 int nValue = m_xMtrFldAmount->get_value(FieldUnit::NONE) / 10;
482 m_xMtrFldAmount->set_sensitive(true);
483 m_xMtrFldAmount->set_unit(FieldUnit::CUSTOM);
484 m_xMtrFldAmount->set_digits(0);
486 m_xMtrFldAmount->set_increments(1, 10, FieldUnit::NONE);
487 m_xMtrFldAmount->set_range(1, 100, FieldUnit::NONE);
489 m_xMtrFldAmount->set_value(nValue, FieldUnit::NONE);
491 else if( eState == TRISTATE_FALSE )
493 int nValue = m_xMtrFldAmount->get_value(FieldUnit::NONE) * 10;
494 m_xMtrFldAmount->set_sensitive(true);
495 m_xMtrFldAmount->set_unit(eFUnit);
496 m_xMtrFldAmount->set_digits(2);
498 m_xMtrFldAmount->set_increments(10, 100, FieldUnit::NONE);
499 m_xMtrFldAmount->set_range(1, 10000, FieldUnit::NONE);
501 m_xMtrFldAmount->set_value(nValue, FieldUnit::NONE);
505 IMPL_LINK(SvxTextAnimationPage, ClickDirectionHdl_Impl, weld::Button&, rBtn, void)
507 m_xBtnUp->set_active(&rBtn == m_xBtnUp.get());
508 m_xBtnLeft->set_active(&rBtn == m_xBtnLeft.get());
509 m_xBtnRight->set_active(&rBtn == m_xBtnRight.get());
510 m_xBtnDown->set_active(&rBtn == m_xBtnDown.get());
513 void SvxTextAnimationPage::SelectDirection( SdrTextAniDirection nValue )
515 m_xBtnUp->set_active( nValue == SdrTextAniDirection::Up );
516 m_xBtnLeft->set_active( nValue == SdrTextAniDirection::Left );
517 m_xBtnRight->set_active( nValue == SdrTextAniDirection::Right );
518 m_xBtnDown->set_active( nValue == SdrTextAniDirection::Down );
521 sal_uInt16 SvxTextAnimationPage::GetSelectedDirection() const
523 SdrTextAniDirection nValue = SdrTextAniDirection::Left;
525 if( m_xBtnUp->get_active() )
526 nValue = SdrTextAniDirection::Up;
527 else if( m_xBtnLeft->get_active() )
528 nValue = SdrTextAniDirection::Left;
529 else if( m_xBtnRight->get_active() )
530 nValue = SdrTextAniDirection::Right;
531 else if( m_xBtnDown->get_active() )
532 nValue = SdrTextAniDirection::Down;
534 return static_cast<sal_uInt16>(nValue);
538 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */