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 <textanim.hxx>
21 #include <textattr.hxx>
22 #include <TextColumnsPage.hxx>
23 #include <svx/dlgutil.hxx>
24 #include <svx/svdmark.hxx>
25 #include <svx/svdview.hxx>
26 #include <svx/sdtaaitm.hxx>
27 #include <svx/sdtacitm.hxx>
28 #include <svx/sdtaiitm.hxx>
29 #include <svx/sdtayitm.hxx>
30 #include <svtools/unitconv.hxx>
32 const WhichRangesContainer
SvxTextAnimationPage::pRanges(
33 svl::Items
<SDRATTR_TEXT_ANIKIND
, SDRATTR_TEXT_ANIAMOUNT
>);
35 /*************************************************************************
37 |* constructor of the tab dialog: adds pages to the dialog
39 \************************************************************************/
41 SvxTextTabDialog::SvxTextTabDialog(weld::Window
* pParent
, const SfxItemSet
* pAttr
, const SdrView
* pSdrView
)
42 : SfxTabDialogController(pParent
, u
"cui/ui/textdialog.ui"_ustr
, u
"TextDialog"_ustr
, pAttr
)
45 AddTabPage(u
"RID_SVXPAGE_TEXTATTR"_ustr
, SvxTextAttrPage::Create
, nullptr);
46 AddTabPage(u
"RID_SVXPAGE_TEXTANIMATION"_ustr
, SvxTextAnimationPage::Create
, nullptr);
47 AddTabPage(u
"RID_SVXPAGE_TEXTCOLUMNS"_ustr
, SvxTextColumnsPage::Create
, nullptr);
50 /*************************************************************************
54 \************************************************************************/
56 void SvxTextTabDialog::PageCreated(const OUString
& rId
, SfxTabPage
&rPage
)
58 if (rId
!= "RID_SVXPAGE_TEXTATTR")
61 SdrObjKind eKind
= SdrObjKind::NONE
;
64 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
65 bool bHasMarked
= rMarkList
.GetMarkCount() > 0;
68 if (rMarkList
.GetMarkCount() == 1)
70 const SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
71 eKind
= pObj
->GetObjIdentifier();
75 static_cast<SvxTextAttrPage
&>(rPage
).SetObjKind(eKind
);
76 static_cast<SvxTextAttrPage
&>(rPage
).Construct();
79 /*************************************************************************
83 \************************************************************************/
84 SvxTextAnimationPage::SvxTextAnimationPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
85 : SfxTabPage(pPage
, pController
, u
"cui/ui/textanimtabpage.ui"_ustr
, u
"TextAnimation"_ustr
, &rInAttrs
)
86 , eAniKind(SdrTextAniKind::NONE
)
87 , m_aUpState(TRISTATE_INDET
)
88 , m_aLeftState(TRISTATE_INDET
)
89 , m_aRightState(TRISTATE_INDET
)
90 , m_aDownState(TRISTATE_INDET
)
91 , m_xLbEffect(m_xBuilder
->weld_combo_box(u
"LB_EFFECT"_ustr
))
92 , m_xBoxDirection(m_xBuilder
->weld_widget(u
"boxDIRECTION"_ustr
))
93 , m_xBtnUp(m_xBuilder
->weld_toggle_button(u
"BTN_UP"_ustr
))
94 , m_xBtnLeft(m_xBuilder
->weld_toggle_button(u
"BTN_LEFT"_ustr
))
95 , m_xBtnRight(m_xBuilder
->weld_toggle_button(u
"BTN_RIGHT"_ustr
))
96 , m_xBtnDown(m_xBuilder
->weld_toggle_button(u
"BTN_DOWN"_ustr
))
97 , m_xFlProperties(m_xBuilder
->weld_frame(u
"FL_PROPERTIES"_ustr
))
98 , m_xTsbStartInside(m_xBuilder
->weld_check_button(u
"TSB_START_INSIDE"_ustr
))
99 , m_xTsbStopInside(m_xBuilder
->weld_check_button(u
"TSB_STOP_INSIDE"_ustr
))
100 , m_xBoxCount(m_xBuilder
->weld_widget(u
"boxCOUNT"_ustr
))
101 , m_xTsbEndless(m_xBuilder
->weld_check_button(u
"TSB_ENDLESS"_ustr
))
102 , m_xNumFldCount(m_xBuilder
->weld_spin_button(u
"NUM_FLD_COUNT"_ustr
))
103 , m_xTsbPixel(m_xBuilder
->weld_check_button(u
"TSB_PIXEL"_ustr
))
104 , m_xMtrFldAmount(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_AMOUNT"_ustr
, FieldUnit::PIXEL
))
105 , m_xTsbAuto(m_xBuilder
->weld_check_button(u
"TSB_AUTO"_ustr
))
106 , m_xMtrFldDelay(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_DELAY"_ustr
, FieldUnit::MILLISECOND
))
108 eFUnit
= GetModuleFieldUnit( rInAttrs
);
109 SfxItemPool
* pPool
= rInAttrs
.GetPool();
110 assert(pPool
&& "Where is the pool?");
111 eUnit
= pPool
->GetMetric( SDRATTR_TEXT_LEFTDIST
);
113 m_xLbEffect
->connect_changed( LINK( this, SvxTextAnimationPage
, SelectEffectHdl_Impl
) );
114 m_xTsbEndless
->connect_toggled( LINK( this, SvxTextAnimationPage
, ClickEndlessHdl_Impl
) );
115 m_xTsbAuto
->connect_toggled( LINK( this, SvxTextAnimationPage
, ClickAutoHdl_Impl
) );
116 m_xTsbPixel
->connect_toggled( LINK( this, SvxTextAnimationPage
, ClickPixelHdl_Impl
) );
118 Link
<weld::Button
&,void> aLink( LINK( this, SvxTextAnimationPage
, ClickDirectionHdl_Impl
) );
119 m_xBtnUp
->connect_clicked( aLink
);
120 m_xBtnLeft
->connect_clicked( aLink
);
121 m_xBtnRight
->connect_clicked( aLink
);
122 m_xBtnDown
->connect_clicked( aLink
);
125 SvxTextAnimationPage::~SvxTextAnimationPage()
129 /*************************************************************************
131 |* reads the passed item set
133 \************************************************************************/
135 void SvxTextAnimationPage::Reset( const SfxItemSet
* rAttrs
)
137 const SfxItemPool
* pPool
= rAttrs
->GetPool();
140 const SfxPoolItem
* pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIKIND
);
143 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANIKIND
);
145 eAniKind
= static_cast<const SdrTextAniKindItem
*>(pItem
)->GetValue();
146 m_xLbEffect
->set_active(sal::static_int_cast
<sal_Int32
>(eAniKind
));
147 m_xLbEffect
->save_value();
149 // animation direction
150 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIDIRECTION
);
152 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANIDIRECTION
);
154 SelectDirection(static_cast<const SdrTextAniDirectionItem
*>(pItem
)->GetValue());
155 m_aUpState
= m_xBtnUp
->get_state();
156 m_aLeftState
= m_xBtnLeft
->get_state();
157 m_aRightState
= m_xBtnRight
->get_state();
158 m_aDownState
= m_xBtnDown
->get_state();
161 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANISTARTINSIDE
);
163 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANISTARTINSIDE
);
165 if (static_cast<const SdrTextAniStartInsideItem
*>(pItem
)->GetValue())
166 m_xTsbStartInside
->set_state(TRISTATE_TRUE
);
168 m_xTsbStartInside
->set_state(TRISTATE_FALSE
);
169 m_xTsbStartInside
->save_state();
172 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANISTOPINSIDE
);
174 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANISTOPINSIDE
);
176 if (static_cast<const SdrTextAniStopInsideItem
*>(pItem
)->GetValue())
177 m_xTsbStopInside
->set_state(TRISTATE_TRUE
);
179 m_xTsbStopInside
->set_state(TRISTATE_FALSE
);
180 m_xTsbStopInside
->save_state();
183 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANICOUNT
);
185 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANICOUNT
);
187 tools::Long nValue
= static_cast<tools::Long
>(static_cast<const SdrTextAniCountItem
*>(pItem
)->GetValue());
188 m_xNumFldCount
->set_value(nValue
);
191 if (eAniKind
== SdrTextAniKind::Slide
)
193 m_xTsbEndless
->set_state(TRISTATE_FALSE
);
194 m_xTsbEndless
->set_sensitive(false);
198 m_xTsbEndless
->set_state(TRISTATE_TRUE
);
199 m_xNumFldCount
->set_text(u
""_ustr
);
203 m_xTsbEndless
->set_state(TRISTATE_FALSE
);
204 m_xTsbEndless
->save_state();
205 m_xNumFldCount
->save_value();
208 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIDELAY
);
210 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANIDELAY
);
212 nValue
= static_cast<tools::Long
>(static_cast<const SdrTextAniDelayItem
*>(pItem
)->GetValue());
213 m_xMtrFldDelay
->set_value(nValue
, FieldUnit::NONE
);
216 m_xTsbAuto
->set_state(TRISTATE_TRUE
);
217 m_xMtrFldDelay
->set_text(u
""_ustr
);
220 m_xTsbAuto
->set_state(TRISTATE_FALSE
);
221 m_xTsbAuto
->save_state();
222 m_xMtrFldDelay
->save_value();
225 pItem
= GetItem( *rAttrs
, SDRATTR_TEXT_ANIAMOUNT
);
227 pItem
= &pPool
->GetUserOrPoolDefaultItem( SDRATTR_TEXT_ANIAMOUNT
);
229 nValue
= static_cast<tools::Long
>(static_cast<const SdrTextAniAmountItem
*>(pItem
)->GetValue());
232 m_xTsbPixel
->set_state(TRISTATE_TRUE
);
236 m_xMtrFldAmount
->set_unit(FieldUnit::CUSTOM
);
237 m_xMtrFldAmount
->set_digits(0);
239 m_xMtrFldAmount
->set_increments(1, 10, FieldUnit::NONE
);
240 m_xMtrFldAmount
->set_range(1, 100, FieldUnit::NONE
);
241 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
245 m_xTsbPixel
->set_state(TRISTATE_FALSE
);
246 m_xMtrFldAmount
->set_unit(eFUnit
);
247 m_xMtrFldAmount
->set_digits(2);
249 m_xMtrFldAmount
->set_increments(10, 100, FieldUnit::NONE
);
250 m_xMtrFldAmount
->set_range(1, 10000, FieldUnit::NONE
);
252 SetMetricValue(*m_xMtrFldAmount
, nValue
, eUnit
);
254 m_xTsbPixel
->save_state();
255 m_xMtrFldAmount
->save_value();
257 SelectEffectHdl_Impl(*m_xLbEffect
);
258 ClickEndlessHdl_Impl(*m_xTsbEndless
);
259 ClickAutoHdl_Impl(*m_xTsbAuto
);
262 /*************************************************************************
264 |* fills the passed item set with dialog box attributes
266 \************************************************************************/
268 bool SvxTextAnimationPage::FillItemSet( SfxItemSet
* rAttrs
)
270 bool bModified
= false;
274 int nPos
= m_xLbEffect
->get_active();
276 m_xLbEffect
->get_value_changed_from_saved() )
278 rAttrs
->Put( SdrTextAniKindItem( static_cast<SdrTextAniKind
>(nPos
) ) );
282 // animation direction
283 if (m_aUpState
!= m_xBtnUp
->get_state() ||
284 m_aLeftState
!= m_xBtnLeft
->get_state() ||
285 m_aRightState
!= m_xBtnRight
->get_state() ||
286 m_aDownState
!= m_xBtnDown
->get_state())
288 SdrTextAniDirection eValue
= static_cast<SdrTextAniDirection
>(GetSelectedDirection());
289 rAttrs
->Put( SdrTextAniDirectionItem( eValue
) );
294 eState
= m_xTsbStartInside
->get_state();
295 if (m_xTsbStartInside
->get_state_changed_from_saved())
297 rAttrs
->Put( SdrTextAniStartInsideItem( TRISTATE_TRUE
== eState
) );
302 eState
= m_xTsbStopInside
->get_state();
303 if (m_xTsbStopInside
->get_state_changed_from_saved())
305 rAttrs
->Put( SdrTextAniStopInsideItem( TRISTATE_TRUE
== eState
) );
310 eState
= m_xTsbEndless
->get_state();
311 if (m_xTsbEndless
->get_state_changed_from_saved() ||
312 m_xNumFldCount
->get_value_changed_from_saved())
314 sal_Int64 nValue
= 0;
315 if( eState
== TRISTATE_TRUE
/*#89844#*/ && m_xTsbEndless
->get_sensitive())
319 if( m_xNumFldCount
->get_value_changed_from_saved() )
321 nValue
= m_xNumFldCount
->get_value();
326 rAttrs
->Put( SdrTextAniCountItem( static_cast<sal_uInt16
>(nValue
) ) );
330 eState
= m_xTsbAuto
->get_state();
331 if (m_xTsbAuto
->get_state_changed_from_saved() ||
332 m_xMtrFldDelay
->get_value_changed_from_saved())
334 sal_Int64 nValue
= 0;
335 if( eState
== TRISTATE_TRUE
)
339 if( m_xMtrFldDelay
->get_value_changed_from_saved() )
341 nValue
= m_xMtrFldDelay
->get_value(FieldUnit::NONE
);
346 rAttrs
->Put( SdrTextAniDelayItem( static_cast<sal_uInt16
>(nValue
) ) );
350 eState
= m_xTsbPixel
->get_state();
351 if (m_xTsbPixel
->get_state_changed_from_saved() ||
352 m_xMtrFldAmount
->get_value_changed_from_saved())
354 sal_Int64 nValue
= 0;
355 if( eState
== TRISTATE_TRUE
)
357 nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
);
362 nValue
= GetCoreValue( *m_xMtrFldAmount
, eUnit
);
364 rAttrs
->Put( SdrTextAniAmountItem( static_cast<sal_Int16
>(nValue
) ) );
372 /*************************************************************************
376 \************************************************************************/
378 std::unique_ptr
<SfxTabPage
> SvxTextAnimationPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rAttrs
)
380 return std::make_unique
<SvxTextAnimationPage
>(pPage
, pController
, *rAttrs
);
383 IMPL_LINK_NOARG(SvxTextAnimationPage
, SelectEffectHdl_Impl
, weld::ComboBox
&, void)
385 int nPos
= m_xLbEffect
->get_active();
389 eAniKind
= static_cast<SdrTextAniKind
>(nPos
);
392 case SdrTextAniKind::NONE
:
394 m_xBoxDirection
->set_sensitive(false);
395 m_xFlProperties
->set_sensitive(false);
399 case SdrTextAniKind::Blink
:
400 case SdrTextAniKind::Scroll
:
401 case SdrTextAniKind::Alternate
:
402 case SdrTextAniKind::Slide
:
404 m_xFlProperties
->set_sensitive(true);
405 if( eAniKind
== SdrTextAniKind::Slide
)
407 m_xTsbStartInside
->set_sensitive(false);
408 m_xTsbStopInside
->set_sensitive(false);
409 m_xTsbEndless
->set_sensitive(false);
410 m_xNumFldCount
->set_sensitive(true);
411 m_xNumFldCount
->set_value(m_xNumFldCount
->get_value());
415 m_xTsbStartInside
->set_sensitive(true);
416 m_xTsbStopInside
->set_sensitive(true);
417 m_xTsbEndless
->set_sensitive(true);
418 ClickEndlessHdl_Impl(*m_xTsbEndless
);
421 m_xTsbAuto
->set_sensitive(true);
422 ClickAutoHdl_Impl(*m_xTsbAuto
);
424 if( eAniKind
== SdrTextAniKind::Blink
)
426 m_xBoxDirection
->set_sensitive(false);
427 m_xBoxCount
->set_sensitive(false);
431 m_xBoxDirection
->set_sensitive(true);
432 m_xBoxCount
->set_sensitive(true);
439 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickEndlessHdl_Impl
, weld::Toggleable
&, void)
441 if( eAniKind
== SdrTextAniKind::Slide
)
444 TriState eState
= m_xTsbEndless
->get_state();
445 if( eState
!= TRISTATE_FALSE
)
447 m_xNumFldCount
->set_sensitive(false);
448 m_xNumFldCount
->set_text(u
""_ustr
);
452 m_xNumFldCount
->set_sensitive(true);
453 m_xNumFldCount
->set_value(m_xNumFldCount
->get_value());
457 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickAutoHdl_Impl
, weld::Toggleable
&, void)
459 TriState eState
= m_xTsbAuto
->get_state();
460 if( eState
!= TRISTATE_FALSE
)
462 m_xMtrFldDelay
->set_sensitive(false);
463 m_xMtrFldDelay
->set_text(u
""_ustr
);
467 m_xMtrFldDelay
->set_sensitive(true);
468 m_xMtrFldDelay
->set_value(m_xMtrFldDelay
->get_value(FieldUnit::NONE
), FieldUnit::NONE
); //to-do
472 IMPL_LINK_NOARG(SvxTextAnimationPage
, ClickPixelHdl_Impl
, weld::Toggleable
&, void)
474 TriState eState
= m_xTsbPixel
->get_state();
475 if (eState
== TRISTATE_TRUE
)
477 int nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
) / 10;
478 m_xMtrFldAmount
->set_sensitive(true);
479 m_xMtrFldAmount
->set_unit(FieldUnit::CUSTOM
);
480 m_xMtrFldAmount
->set_digits(0);
482 m_xMtrFldAmount
->set_increments(1, 10, FieldUnit::NONE
);
483 m_xMtrFldAmount
->set_range(1, 100, FieldUnit::NONE
);
485 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
487 else if( eState
== TRISTATE_FALSE
)
489 int nValue
= m_xMtrFldAmount
->get_value(FieldUnit::NONE
) * 10;
490 m_xMtrFldAmount
->set_sensitive(true);
491 m_xMtrFldAmount
->set_unit(eFUnit
);
492 m_xMtrFldAmount
->set_digits(2);
494 m_xMtrFldAmount
->set_increments(10, 100, FieldUnit::NONE
);
495 m_xMtrFldAmount
->set_range(1, 10000, FieldUnit::NONE
);
497 m_xMtrFldAmount
->set_value(nValue
, FieldUnit::NONE
);
501 IMPL_LINK(SvxTextAnimationPage
, ClickDirectionHdl_Impl
, weld::Button
&, rBtn
, void)
503 m_xBtnUp
->set_active(&rBtn
== m_xBtnUp
.get());
504 m_xBtnLeft
->set_active(&rBtn
== m_xBtnLeft
.get());
505 m_xBtnRight
->set_active(&rBtn
== m_xBtnRight
.get());
506 m_xBtnDown
->set_active(&rBtn
== m_xBtnDown
.get());
509 void SvxTextAnimationPage::SelectDirection( SdrTextAniDirection nValue
)
511 m_xBtnUp
->set_active( nValue
== SdrTextAniDirection::Up
);
512 m_xBtnLeft
->set_active( nValue
== SdrTextAniDirection::Left
);
513 m_xBtnRight
->set_active( nValue
== SdrTextAniDirection::Right
);
514 m_xBtnDown
->set_active( nValue
== SdrTextAniDirection::Down
);
517 sal_uInt16
SvxTextAnimationPage::GetSelectedDirection() const
519 SdrTextAniDirection nValue
= SdrTextAniDirection::Left
;
521 if( m_xBtnUp
->get_active() )
522 nValue
= SdrTextAniDirection::Up
;
523 else if( m_xBtnLeft
->get_active() )
524 nValue
= SdrTextAniDirection::Left
;
525 else if( m_xBtnRight
->get_active() )
526 nValue
= SdrTextAniDirection::Right
;
527 else if( m_xBtnDown
->get_active() )
528 nValue
= SdrTextAniDirection::Down
;
530 return static_cast<sal_uInt16
>(nValue
);
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */