1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/dialogs.hrc>
25 #include <textanim.hxx>
26 #include <textattr.hxx>
27 #include <svx/dlgutil.hxx>
28 #include <svx/svdmark.hxx>
29 #include <svx/svdview.hxx>
30 #include <svx/sdtaaitm.hxx>
31 #include <svx/sdtacitm.hxx>
32 #include <svx/sdtaiitm.hxx>
33 #include <svx/sdtayitm.hxx>
34 #include <svtools/unitconv.hxx>
36 const sal_uInt16
SvxTextAnimationPage::pRanges
[] =
39 SDRATTR_TEXT_ANIAMOUNT
,
43 /*************************************************************************
45 |* constructor of the tab dialog: adds pages to the dialog
47 \************************************************************************/
49 SvxTextTabDialog::SvxTextTabDialog(weld::Window
* pParent
, const SfxItemSet
* pAttr
, const SdrView
* pSdrView
)
50 : SfxTabDialogController(pParent
, "cui/ui/textdialog.ui", "TextDialog", pAttr
)
53 AddTabPage("RID_SVXPAGE_TEXTATTR", SvxTextAttrPage::Create
, nullptr);
54 AddTabPage("RID_SVXPAGE_TEXTANIMATION", SvxTextAnimationPage::Create
, nullptr);
57 /*************************************************************************
61 \************************************************************************/
63 void SvxTextTabDialog::PageCreated(const OString
& rId
, SfxTabPage
&rPage
)
65 if (rId
== "RID_SVXPAGE_TEXTATTR")
67 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
68 bool bHasMarked
= rMarkList
.GetMarkCount() > 0;
69 SdrObjKind eKind
= OBJ_NONE
;
72 if (rMarkList
.GetMarkCount() == 1)
74 const SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
75 eKind
= static_cast<SdrObjKind
>(pObj
->GetObjIdentifier());
78 static_cast<SvxTextAttrPage
&>(rPage
).SetObjKind(eKind
);
79 static_cast<SvxTextAttrPage
&>(rPage
).Construct();
84 /*************************************************************************
88 \************************************************************************/
90 SvxTextAnimationPage::SvxTextAnimationPage(TabPageParent pPage
, const SfxItemSet
& rInAttrs
)
91 : SfxTabPage(pPage
, "cui/ui/textanimtabpage.ui", "TextAnimation", &rInAttrs
)
93 , eAniKind(SdrTextAniKind::NONE
)
94 , m_aUpState(TRISTATE_INDET
)
95 , m_aLeftState(TRISTATE_INDET
)
96 , m_aRightState(TRISTATE_INDET
)
97 , m_aDownState(TRISTATE_INDET
)
98 , m_xLbEffect(m_xBuilder
->weld_combo_box("LB_EFFECT"))
99 , m_xBoxDirection(m_xBuilder
->weld_widget("boxDIRECTION"))
100 , m_xBtnUp(m_xBuilder
->weld_toggle_button("BTN_UP"))
101 , m_xBtnLeft(m_xBuilder
->weld_toggle_button("BTN_LEFT"))
102 , m_xBtnRight(m_xBuilder
->weld_toggle_button("BTN_RIGHT"))
103 , m_xBtnDown(m_xBuilder
->weld_toggle_button("BTN_DOWN"))
104 , m_xFlProperties(m_xBuilder
->weld_frame("FL_PROPERTIES"))
105 , m_xTsbStartInside(m_xBuilder
->weld_check_button("TSB_START_INSIDE"))
106 , m_xTsbStopInside(m_xBuilder
->weld_check_button("TSB_STOP_INSIDE"))
107 , m_xBoxCount(m_xBuilder
->weld_widget("boxCOUNT"))
108 , m_xTsbEndless(m_xBuilder
->weld_check_button("TSB_ENDLESS"))
109 , m_xNumFldCount(m_xBuilder
->weld_spin_button("NUM_FLD_COUNT"))
110 , m_xTsbPixel(m_xBuilder
->weld_check_button("TSB_PIXEL"))
111 , m_xMtrFldAmount(m_xBuilder
->weld_metric_spin_button("MTR_FLD_AMOUNT", FieldUnit::PIXEL
))
112 , m_xTsbAuto(m_xBuilder
->weld_check_button("TSB_AUTO"))
113 , m_xMtrFldDelay(m_xBuilder
->weld_metric_spin_button("MTR_FLD_DELAY", FieldUnit::MILLISECOND
))
115 eFUnit
= GetModuleFieldUnit( rInAttrs
);
116 SfxItemPool
* pPool
= rOutAttrs
.GetPool();
117 DBG_ASSERT( pPool
, "Where is the pool?" );
118 eUnit
= pPool
->GetMetric( SDRATTR_TEXT_LEFTDIST
);
120 m_xLbEffect
->connect_changed( LINK( this, SvxTextAnimationPage
, SelectEffectHdl_Impl
) );
121 m_xTsbEndless
->connect_clicked( LINK( this, SvxTextAnimationPage
, ClickEndlessHdl_Impl
) );
122 m_xTsbAuto
->connect_clicked( LINK( this, SvxTextAnimationPage
, ClickAutoHdl_Impl
) );
123 m_xTsbPixel
->connect_clicked( LINK( this, SvxTextAnimationPage
, ClickPixelHdl_Impl
) );
125 Link
<weld::Button
&,void> aLink( LINK( this, SvxTextAnimationPage
, ClickDirectionHdl_Impl
) );
126 m_xBtnUp
->connect_clicked( aLink
);
127 m_xBtnLeft
->connect_clicked( aLink
);
128 m_xBtnRight
->connect_clicked( aLink
);
129 m_xBtnDown
->connect_clicked( aLink
);
132 SvxTextAnimationPage::~SvxTextAnimationPage()
136 /*************************************************************************
138 |* reads the passed item set
140 \************************************************************************/
142 void SvxTextAnimationPage::Reset( const SfxItemSet
* rAttrs
)
144 const SfxItemPool
* pPool
= rAttrs
->GetPool();
147 const SfxPoolItem
* pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIKIND
);
150 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANIKIND
);
152 eAniKind
= static_cast<const SdrTextAniKindItem
*>(pItem
)->GetValue();
153 m_xLbEffect
->set_active(sal::static_int_cast
<sal_Int32
>(eAniKind
));
154 m_xLbEffect
->save_value();
156 // animation direction
157 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIDIRECTION
);
159 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANIDIRECTION
);
161 SelectDirection(static_cast<const SdrTextAniDirectionItem
*>(pItem
)->GetValue());
162 m_aUpState
= m_xBtnUp
->get_state();
163 m_aLeftState
= m_xBtnLeft
->get_state();
164 m_aRightState
= m_xBtnRight
->get_state();
165 m_aDownState
= m_xBtnDown
->get_state();
168 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANISTARTINSIDE
);
170 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANISTARTINSIDE
);
172 if (static_cast<const SdrTextAniStartInsideItem
*>(pItem
)->GetValue())
173 m_xTsbStartInside
->set_state(TRISTATE_TRUE
);
175 m_xTsbStartInside
->set_state(TRISTATE_FALSE
);
176 m_xTsbStartInside
->save_state();
179 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANISTOPINSIDE
);
181 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANISTOPINSIDE
);
183 if (static_cast<const SdrTextAniStopInsideItem
*>(pItem
)->GetValue())
184 m_xTsbStopInside
->set_state(TRISTATE_TRUE
);
186 m_xTsbStopInside
->set_state(TRISTATE_FALSE
);
187 m_xTsbStopInside
->save_state();
190 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANICOUNT
);
192 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANICOUNT
);
194 long nValue
= static_cast<long>(static_cast<const SdrTextAniCountItem
*>(pItem
)->GetValue());
195 m_xNumFldCount
->set_value(nValue
);
198 if (eAniKind
== SdrTextAniKind::Slide
)
200 m_xTsbEndless
->set_state(TRISTATE_FALSE
);
201 m_xTsbEndless
->set_sensitive(false);
205 m_xTsbEndless
->set_state(TRISTATE_TRUE
);
206 m_xNumFldCount
->set_text("");
210 m_xTsbEndless
->set_state(TRISTATE_FALSE
);
211 m_xTsbEndless
->save_state();
212 m_xNumFldCount
->save_value();
215 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIDELAY
);
217 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANIDELAY
);
219 nValue
= static_cast<long>(static_cast<const SdrTextAniDelayItem
*>(pItem
)->GetValue());
220 m_xMtrFldDelay
->set_value(nValue
, FieldUnit::NONE
);
223 m_xTsbAuto
->set_state(TRISTATE_TRUE
);
224 m_xMtrFldDelay
->set_text("");
227 m_xTsbAuto
->set_state(TRISTATE_FALSE
);
228 m_xTsbAuto
->save_state();
229 m_xMtrFldDelay
->save_value();
232 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIAMOUNT
);
234 pItem
= &pPool
->GetDefaultItem( SDRATTR_TEXT_ANIAMOUNT
);
236 nValue
= static_cast<long>(static_cast<const SdrTextAniAmountItem
*>(pItem
)->GetValue());
239 m_xTsbPixel
->set_state(TRISTATE_TRUE
);
243 m_xMtrFldAmount
->set_unit(FieldUnit::CUSTOM
);
244 m_xMtrFldAmount
->set_digits(0);
246 m_xMtrFldAmount
->set_increments(1, 10, FieldUnit::NONE
);
247 m_xMtrFldAmount
->set_range(1, 100, FieldUnit::NONE
);
248 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
252 m_xTsbPixel
->set_state(TRISTATE_FALSE
);
253 m_xMtrFldAmount
->set_unit(eFUnit
);
254 m_xMtrFldAmount
->set_digits(2);
256 m_xMtrFldAmount
->set_increments(10, 100, FieldUnit::NONE
);
257 m_xMtrFldAmount
->set_range(1, 10000, FieldUnit::NONE
);
259 SetMetricValue(*m_xMtrFldAmount
, nValue
, eUnit
);
261 m_xTsbPixel
->save_state();
262 m_xMtrFldAmount
->save_value();
264 SelectEffectHdl_Impl(*m_xLbEffect
);
265 ClickEndlessHdl_Impl(*m_xTsbEndless
);
266 ClickAutoHdl_Impl(*m_xTsbAuto
);
269 /*************************************************************************
271 |* fills the passed item set with dialog box attributes
273 \************************************************************************/
275 bool SvxTextAnimationPage::FillItemSet( SfxItemSet
* rAttrs
)
277 bool bModified
= false;
281 int nPos
= m_xLbEffect
->get_active();
283 m_xLbEffect
->get_value_changed_from_saved() )
285 rAttrs
->Put( SdrTextAniKindItem( static_cast<SdrTextAniKind
>(nPos
) ) );
289 // animation direction
290 if (m_aUpState
!= m_xBtnUp
->get_state() ||
291 m_aLeftState
!= m_xBtnLeft
->get_state() ||
292 m_aRightState
!= m_xBtnRight
->get_state() ||
293 m_aDownState
!= m_xBtnDown
->get_state())
295 SdrTextAniDirection eValue
= static_cast<SdrTextAniDirection
>(GetSelectedDirection());
296 rAttrs
->Put( SdrTextAniDirectionItem( eValue
) );
301 eState
= m_xTsbStartInside
->get_state();
302 if (m_xTsbStartInside
->get_state_changed_from_saved())
304 rAttrs
->Put( SdrTextAniStartInsideItem( TRISTATE_TRUE
== eState
) );
309 eState
= m_xTsbStopInside
->get_state();
310 if (m_xTsbStopInside
->get_state_changed_from_saved())
312 rAttrs
->Put( SdrTextAniStopInsideItem( TRISTATE_TRUE
== eState
) );
317 eState
= m_xTsbEndless
->get_state();
318 if (m_xTsbEndless
->get_state_changed_from_saved() ||
319 m_xNumFldCount
->get_value_changed_from_saved())
321 sal_Int64 nValue
= 0;
322 if( eState
== TRISTATE_TRUE
/*#89844#*/ && m_xTsbEndless
->get_sensitive())
326 if( m_xNumFldCount
->get_value_changed_from_saved() )
328 nValue
= m_xNumFldCount
->get_value();
333 rAttrs
->Put( SdrTextAniCountItem( static_cast<sal_uInt16
>(nValue
) ) );
337 eState
= m_xTsbAuto
->get_state();
338 if (m_xTsbAuto
->get_state_changed_from_saved() ||
339 m_xMtrFldDelay
->get_value_changed_from_saved())
341 sal_Int64 nValue
= 0;
342 if( eState
== TRISTATE_TRUE
)
346 if( m_xMtrFldDelay
->get_value_changed_from_saved() )
348 nValue
= m_xMtrFldDelay
->get_value(FieldUnit::NONE
);
353 rAttrs
->Put( SdrTextAniDelayItem( static_cast<sal_uInt16
>(nValue
) ) );
357 eState
= m_xTsbPixel
->get_state();
358 if (m_xTsbPixel
->get_state_changed_from_saved() ||
359 m_xMtrFldAmount
->get_value_changed_from_saved())
361 sal_Int64 nValue
= 0;
362 if( eState
== TRISTATE_TRUE
)
364 nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
);
369 nValue
= GetCoreValue( *m_xMtrFldAmount
, eUnit
);
371 rAttrs
->Put( SdrTextAniAmountItem( static_cast<sal_Int16
>(nValue
) ) );
379 /*************************************************************************
383 \************************************************************************/
385 VclPtr
<SfxTabPage
> SvxTextAnimationPage::Create(TabPageParent pParent
, const SfxItemSet
* rAttrs
)
387 return VclPtr
<SvxTextAnimationPage
>::Create(pParent
, *rAttrs
);
390 IMPL_LINK_NOARG(SvxTextAnimationPage
, SelectEffectHdl_Impl
, weld::ComboBox
&, void)
392 int nPos
= m_xLbEffect
->get_active();
395 eAniKind
= static_cast<SdrTextAniKind
>(nPos
);
398 case SdrTextAniKind::NONE
:
400 m_xBoxDirection
->set_sensitive(false);
401 m_xFlProperties
->set_sensitive(false);
405 case SdrTextAniKind::Blink
:
406 case SdrTextAniKind::Scroll
:
407 case SdrTextAniKind::Alternate
:
408 case SdrTextAniKind::Slide
:
410 m_xFlProperties
->set_sensitive(true);
411 if( eAniKind
== SdrTextAniKind::Slide
)
413 m_xTsbStartInside
->set_sensitive(false);
414 m_xTsbStopInside
->set_sensitive(false);
415 m_xTsbEndless
->set_sensitive(false);
416 m_xNumFldCount
->set_sensitive(true);
417 m_xNumFldCount
->set_value(m_xNumFldCount
->get_value());
421 m_xTsbStartInside
->set_sensitive(true);
422 m_xTsbStopInside
->set_sensitive(true);
423 m_xTsbEndless
->set_sensitive(true);
424 ClickEndlessHdl_Impl(*m_xTsbEndless
);
427 m_xTsbAuto
->set_sensitive(true);
428 ClickAutoHdl_Impl(*m_xTsbAuto
);
430 if( eAniKind
== SdrTextAniKind::Blink
)
432 m_xBoxDirection
->set_sensitive(false);
433 m_xBoxCount
->set_sensitive(false);
437 m_xBoxDirection
->set_sensitive(true);
438 m_xBoxCount
->set_sensitive(true);
447 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickEndlessHdl_Impl
, weld::Button
&, void)
449 if( eAniKind
!= SdrTextAniKind::Slide
)
451 TriState eState
= m_xTsbEndless
->get_state();
452 if( eState
!= TRISTATE_FALSE
)
454 m_xNumFldCount
->set_sensitive(false);
455 m_xNumFldCount
->set_text("");
459 m_xNumFldCount
->set_sensitive(true);
460 m_xNumFldCount
->set_value(m_xNumFldCount
->get_value());
465 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickAutoHdl_Impl
, weld::Button
&, void)
467 TriState eState
= m_xTsbAuto
->get_state();
468 if( eState
!= TRISTATE_FALSE
)
470 m_xMtrFldDelay
->set_sensitive(false);
471 m_xMtrFldDelay
->set_text("");
475 m_xMtrFldDelay
->set_sensitive(true);
476 m_xMtrFldDelay
->set_value(m_xMtrFldDelay
->get_value(FieldUnit::NONE
), FieldUnit::NONE
); //to-do
480 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickPixelHdl_Impl
, weld::Button
&, void)
482 TriState eState
= m_xTsbPixel
->get_state();
483 if (eState
== TRISTATE_TRUE
)
485 int nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
) / 10;
486 m_xMtrFldAmount
->set_sensitive(true);
487 m_xMtrFldAmount
->set_unit(FieldUnit::CUSTOM
);
488 m_xMtrFldAmount
->set_digits(0);
490 m_xMtrFldAmount
->set_increments(1, 10, FieldUnit::NONE
);
491 m_xMtrFldAmount
->set_range(1, 100, FieldUnit::NONE
);
493 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
495 else if( eState
== TRISTATE_FALSE
)
497 int nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
) * 10;
498 m_xMtrFldAmount
->set_sensitive(true);
499 m_xMtrFldAmount
->set_unit(eFUnit
);
500 m_xMtrFldAmount
->set_digits(2);
502 m_xMtrFldAmount
->set_increments(10, 100, FieldUnit::NONE
);
503 m_xMtrFldAmount
->set_range(1, 10000, FieldUnit::NONE
);
505 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
509 IMPL_LINK(SvxTextAnimationPage
, ClickDirectionHdl_Impl
, weld::Button
&, rBtn
, void)
511 m_xBtnUp
->set_active(&rBtn
== m_xBtnUp
.get());
512 m_xBtnLeft
->set_active(&rBtn
== m_xBtnLeft
.get());
513 m_xBtnRight
->set_active(&rBtn
== m_xBtnRight
.get());
514 m_xBtnDown
->set_active(&rBtn
== m_xBtnDown
.get());
517 void SvxTextAnimationPage::SelectDirection( SdrTextAniDirection nValue
)
519 m_xBtnUp
->set_active( nValue
== SdrTextAniDirection::Up
);
520 m_xBtnLeft
->set_active( nValue
== SdrTextAniDirection::Left
);
521 m_xBtnRight
->set_active( nValue
== SdrTextAniDirection::Right
);
522 m_xBtnDown
->set_active( nValue
== SdrTextAniDirection::Down
);
525 sal_uInt16
SvxTextAnimationPage::GetSelectedDirection()
527 SdrTextAniDirection nValue
= SdrTextAniDirection::Left
;
529 if( m_xBtnUp
->get_active() )
530 nValue
= SdrTextAniDirection::Up
;
531 else if( m_xBtnLeft
->get_active() )
532 nValue
= SdrTextAniDirection::Left
;
533 else if( m_xBtnRight
->get_active() )
534 nValue
= SdrTextAniDirection::Right
;
535 else if( m_xBtnDown
->get_active() )
536 nValue
= SdrTextAniDirection::Down
;
538 return static_cast<sal_uInt16
>(nValue
);
542 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */