xref: /trunk/main/sd/source/ui/animations/CustomAnimationCreateDialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #ifndef _COM_SUN_STAR_UTIL_XCOLLATOR_HPP_
32 #include <com/sun/star/i18n/XCollator.hpp>
33 #endif
34 
35 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
36 #include <comphelper/processfactory.hxx>
37 #endif
38 #include <vcl/svapp.hxx>
39 #include <vcl/tabctrl.hxx>
40 #include <vcl/tabpage.hxx>
41 
42 #ifndef _SV_BUTTON_HXX
43 #include <vcl/button.hxx>
44 #endif
45 #include <vcl/fixed.hxx>
46 #include <vcl/lstbox.hxx>
47 #include <vcl/combobox.hxx>
48 #include <svtools/valueset.hxx>
49 
50 #include <svx/svdetc.hxx>
51 #include <svx/svdstr.hrc>
52 #include "sdresid.hxx"
53 #include <unotools/viewoptions.hxx>
54 #include <com/sun/star/presentation/EffectNodeType.hpp>
55 #include "CustomAnimationCreateDialog.hxx"
56 #ifndef _SD_CUSTOMANIMATIONCREATEDIALOG_HRC
57 #include "CustomAnimationCreateDialog.hrc"
58 #endif
59 #ifndef _SD_CUSTOMANIMATION_HRC
60 #include "CustomAnimation.hrc"
61 #endif
62 #include "CustomAnimationPane.hxx"
63 #include "optsitem.hxx"
64 #include "sddll.hxx"
65 
66 #include "helpids.h"
67 
68 using namespace ::com::sun::star;
69 
70 using ::rtl::OUString;
71 using ::com::sun::star::uno::UNO_QUERY;
72 using ::com::sun::star::uno::UNO_QUERY_THROW;
73 using ::com::sun::star::uno::Any;
74 using ::com::sun::star::uno::Reference;
75 using ::com::sun::star::uno::Exception;
76 
77 using namespace ::com::sun::star::presentation;
78 
79 namespace sd {
80 
81 
82 const int ENTRANCE = 0;
83 const int EMPHASIS = 1;
84 const int EXIT = 2;
85 const int MOTIONPATH = 3;
86 const int MISCEFFECTS = 4;
87 
88 extern void fillDurationComboBox( ComboBox* pBox );
89 
90 // --------------------------------------------------------------------
91 
92 class CategoryListBox : public ListBox
93 {
94 public:
95     CategoryListBox( Window* pParent, const ResId& rResId );
96     ~CategoryListBox();
97 
98     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
99 
100     sal_uInt16          InsertCategory( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND );
101 
102     void            SetDoubleClickLink( const Link& rDoubleClickHdl ) { maDoubleClickHdl = rDoubleClickHdl; }
103 
104     DECL_LINK( implDoubleClickHdl, Control* );
105 
106 private:
107     virtual void    UserDraw( const UserDrawEvent& rUDEvt );
108 
109     Link            maDoubleClickHdl;
110 };
111 
112 CategoryListBox::CategoryListBox( Window* pParent, const ResId& rResId )
113 : ListBox( pParent, rResId )
114 {
115     EnableUserDraw( sal_True );
116     SetDoubleClickHdl( LINK( this, CategoryListBox, implDoubleClickHdl ) );
117 }
118 
119 CategoryListBox::~CategoryListBox()
120 {
121 }
122 
123 sal_uInt16 CategoryListBox::InsertCategory( const XubString& rStr, sal_uInt16 nPos /* = LISTBOX_APPEND */ )
124 {
125     sal_uInt16 n = ListBox::InsertEntry( rStr, nPos );
126     if( n != LISTBOX_ENTRY_NOTFOUND )
127         ListBox::SetEntryFlags( n, ListBox::GetEntryFlags(n) | LISTBOX_ENTRY_FLAG_DISABLE_SELECTION );
128 
129     return n;
130 }
131 
132 void CategoryListBox::UserDraw( const UserDrawEvent& rUDEvt )
133 {
134     const sal_uInt16 nItem = rUDEvt.GetItemId();
135 
136     if( ListBox::GetEntryFlags(nItem) & LISTBOX_ENTRY_FLAG_DISABLE_SELECTION )
137     {
138         Rectangle aOutRect( rUDEvt.GetRect() );
139         OutputDevice* pDev = rUDEvt.GetDevice();
140 
141         // fill the background
142         Color aColor (GetSettings().GetStyleSettings().GetDialogColor());
143 
144         pDev->SetFillColor (aColor);
145         pDev->SetLineColor ();
146         pDev->DrawRect(aOutRect);
147 
148         // Erase the four corner pixels to make the rectangle appear rounded.
149         pDev->SetLineColor( GetSettings().GetStyleSettings().GetWindowColor());
150         pDev->DrawPixel( aOutRect.TopLeft());
151         pDev->DrawPixel( Point(aOutRect.Right(), aOutRect.Top()));
152         pDev->DrawPixel( Point(aOutRect.Left(), aOutRect.Bottom()));
153         pDev->DrawPixel( Point(aOutRect.Right(), aOutRect.Bottom()));
154 
155         // draw the category title
156         pDev->DrawText (aOutRect, GetEntry(nItem), TEXT_DRAW_CENTER );
157     }
158     else
159     {
160         DrawEntry( rUDEvt, sal_True, sal_True );
161     }
162 }
163 
164 // --------------------------------------------------------------------
165 
166 IMPL_LINK( CategoryListBox, implDoubleClickHdl, Control*, EMPTYARG )
167 {
168     CaptureMouse();
169     return 0;
170 }
171 
172 // --------------------------------------------------------------------
173 
174 void CategoryListBox::MouseButtonUp( const MouseEvent& rMEvt )
175 {
176     ReleaseMouse();
177     if( rMEvt.IsLeft() && (rMEvt.GetClicks() == 2) )
178     {
179         if( maDoubleClickHdl.IsSet() )
180             maDoubleClickHdl.Call( this );
181     }
182     else
183     {
184         ListBox::MouseButtonUp( rMEvt );
185     }
186 }
187 
188 // --------------------------------------------------------------------
189 
190 class CustomAnimationCreateTabPage : public TabPage
191 {
192 public:
193     CustomAnimationCreateTabPage( Window* pParent, CustomAnimationCreateDialog* pDialogParent, int nTabId, const PresetCategoryList& rCategoryList, bool bHasText );
194     ~CustomAnimationCreateTabPage();
195 
196     PathKind getCreatePathKind() const;
197     CustomAnimationPresetPtr getSelectedPreset() const;
198     double getDuration() const;
199     void setDuration( double fDuration );
200 
201     bool getIsPreview() const;
202     void setIsPreview( bool bIsPreview );
203 
204     bool select( const OUString& rsPresetId );
205 
206 private:
207     DECL_LINK( implSelectHdl, Control* );
208     DECL_LINK( implDoubleClickHdl, Control* );
209 
210     void onSelectEffect();
211 
212     void clearEffects();
213 
214 private:
215     CategoryListBox*    mpLBEffects;
216     FixedText*  mpFTSpeed;
217     ComboBox*   mpCBSpeed;
218     CheckBox*   mpCBXPReview;
219 
220     CustomAnimationCreateDialog*        mpParent;
221 
222     sal_uInt16 mnCurvePathPos;
223     sal_uInt16 mnPolygonPathPos;
224     sal_uInt16 mnFreeformPathPos;
225 
226 };
227 
228 struct ImplStlEffectCategorySortHelper
229 {
230     ImplStlEffectCategorySortHelper();
231     bool operator()( const CustomAnimationPresetPtr& p1, const CustomAnimationPresetPtr& p2 );
232 
233 private:
234     uno::Reference< i18n::XCollator > mxCollator;
235 };
236 
237 ImplStlEffectCategorySortHelper::ImplStlEffectCategorySortHelper()
238 {
239     uno::Reference<lang::XMultiServiceFactory> xFac( ::comphelper::getProcessServiceFactory() );
240     if( xFac.is() )
241     {
242         mxCollator.set( xFac->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ) ), uno::UNO_QUERY );
243 
244         if( mxCollator.is() )
245         {
246             const lang::Locale& rLocale = Application::GetSettings().GetLocale();
247             mxCollator->loadDefaultCollator(rLocale, 0);
248         }
249     }
250 }
251 
252 bool ImplStlEffectCategorySortHelper::operator()( const CustomAnimationPresetPtr& p1, const CustomAnimationPresetPtr& p2 )
253 {
254     return mxCollator.is() ? mxCollator->compareString(p1->getLabel(), p2->getLabel()) == -1 : false;
255 }
256 
257 CustomAnimationCreateTabPage::CustomAnimationCreateTabPage( Window* pParent, CustomAnimationCreateDialog* pDialogParent, int nTabId, const PresetCategoryList& rCategoryList, bool bHasText )
258 : TabPage( pParent, SdResId( RID_TP_CUSTOMANIMATION_ENTRANCE ) )
259 , mpParent( pDialogParent )
260 , mnCurvePathPos( LISTBOX_ENTRY_NOTFOUND )
261 , mnPolygonPathPos( LISTBOX_ENTRY_NOTFOUND )
262 , mnFreeformPathPos( LISTBOX_ENTRY_NOTFOUND )
263 {
264     mpLBEffects = new CategoryListBox( this, SdResId( LB_EFFECTS ) );
265     mpFTSpeed = new FixedText( this, SdResId( FT_SPEED ) );
266     mpCBSpeed = new ComboBox( this, SdResId( CB_SPEED ) );
267     mpCBXPReview = new CheckBox( this, SdResId( CBX_PREVIEW ) );
268 
269     String sMotionPathLabel( SdResId( STR_USERPATH ) );
270 
271     FreeResource();
272 
273     sal_uInt16 nFirstEffect = LISTBOX_ENTRY_NOTFOUND;
274 
275     if( nTabId == MOTIONPATH )
276     {
277         mpLBEffects->InsertCategory( sMotionPathLabel );
278 
279         mnCurvePathPos = nFirstEffect = mpLBEffects->InsertEntry( sdr::GetResourceString(STR_ObjNameSingulCOMBLINE) );
280         mnPolygonPathPos = mpLBEffects->InsertEntry( sdr::GetResourceString(STR_ObjNameSingulPOLY) );
281         mnFreeformPathPos = mpLBEffects->InsertEntry( sdr::GetResourceString(STR_ObjNameSingulFREELINE) );
282     };
283 
284     PresetCategoryList::const_iterator aCategoryIter( rCategoryList.begin() );
285     const PresetCategoryList::const_iterator aCategoryEnd( rCategoryList.end() );
286     while( aCategoryIter != aCategoryEnd )
287     {
288         PresetCategoryPtr pCategory( *aCategoryIter++ );
289         if( pCategory.get() )
290         {
291             mpLBEffects->InsertCategory( pCategory->maLabel );
292 
293             std::vector< CustomAnimationPresetPtr > aSortedVector(pCategory->maEffects.size());
294             std::copy( pCategory->maEffects.begin(), pCategory->maEffects.end(), aSortedVector.begin() );
295             ImplStlEffectCategorySortHelper aSortHelper;
296             std::sort( aSortedVector.begin(), aSortedVector.end(), aSortHelper );
297 
298             std::vector< CustomAnimationPresetPtr >::const_iterator aIter( aSortedVector.begin() );
299             const std::vector< CustomAnimationPresetPtr >::const_iterator aEnd( aSortedVector.end() );
300             while( aIter != aEnd )
301             {
302                 CustomAnimationPresetPtr pDescriptor = (*aIter++);
303                 if( pDescriptor.get() && (bHasText || !pDescriptor->isTextOnly() ) )
304                 {
305                     sal_uInt16 nPos = mpLBEffects->InsertEntry( pDescriptor->getLabel() );
306                     mpLBEffects->SetEntryData( nPos, static_cast<void*>( new CustomAnimationPresetPtr( pDescriptor ) ) );
307 
308                     if( nFirstEffect == LISTBOX_ENTRY_NOTFOUND )
309                         nFirstEffect = nPos;
310                 }
311             }
312         }
313     }
314 
315     mpLBEffects->SelectEntryPos( nFirstEffect );
316 
317     fillDurationComboBox( mpCBSpeed );
318 
319     if( nFirstEffect != LISTBOX_ENTRY_NOTFOUND )
320         onSelectEffect();
321 
322     mpLBEffects->SetSelectHdl( LINK( this, CustomAnimationCreateTabPage, implSelectHdl ) );
323     mpLBEffects->SetDoubleClickLink( LINK( this, CustomAnimationCreateTabPage, implDoubleClickHdl ) );
324 }
325 
326 CustomAnimationCreateTabPage::~CustomAnimationCreateTabPage()
327 {
328     clearEffects();
329 
330     delete mpLBEffects;
331     delete mpFTSpeed;
332     delete mpCBSpeed;
333     delete mpCBXPReview;
334 }
335 
336 IMPL_LINK( CustomAnimationCreateTabPage, implSelectHdl, Control*, pControl )
337 {
338     if( pControl == mpLBEffects )
339         onSelectEffect();
340     return 0;
341 }
342 
343 IMPL_LINK( CustomAnimationCreateTabPage, implDoubleClickHdl, Control*, pControl )
344 {
345     if( pControl == mpLBEffects )
346     {
347         if( mpLBEffects->GetSelectEntryCount() )
348             mpParent->EndDialog( sal_True );
349     }
350     return 0;
351 }
352 
353 void CustomAnimationCreateTabPage::onSelectEffect()
354 {
355     CustomAnimationPresetPtr*p = static_cast< CustomAnimationPresetPtr* >( mpLBEffects->GetEntryData( mpLBEffects->GetSelectEntryPos() ) );
356 
357     if( !p )
358         return;
359 
360     CustomAnimationPresetPtr pPreset( *p );
361 
362     const double fDuration = pPreset->getDuration();
363     sal_uInt16 nPos = 0xffff;
364 
365     if( fDuration == 5.0 )
366         nPos = 0;
367     else if( fDuration == 3.0 )
368         nPos = 1;
369     else if( fDuration == 2.0 )
370         nPos = 2;
371     else if( fDuration == 1.0 )
372         nPos = 3;
373     else if( fDuration == 0.5 )
374         nPos = 4;
375 
376     mpCBSpeed->SelectEntryPos( nPos );
377 
378     bool bHasSpeed = pPreset->getDuration() > 0.001;
379     mpCBSpeed->Enable( bHasSpeed );
380     mpFTSpeed->Enable( bHasSpeed );
381 
382     if( mpCBXPReview->IsChecked() )
383     {
384         mpParent->preview( pPreset );
385     }
386 }
387 
388 void CustomAnimationCreateTabPage::clearEffects()
389 {
390     sal_uInt16 nPos = mpLBEffects->GetEntryCount();
391     while( nPos-- )
392         delete static_cast< CustomAnimationPresetPtr* >( mpLBEffects->GetEntryData( nPos ) );
393 
394     mpLBEffects->Clear();
395 }
396 
397 CustomAnimationPresetPtr CustomAnimationCreateTabPage::getSelectedPreset() const
398 {
399     CustomAnimationPresetPtr pPreset;
400 
401     if( mpLBEffects->GetSelectEntryCount() == 1 )
402     {
403         void* pEntryData = mpLBEffects->GetEntryData( mpLBEffects->GetSelectEntryPos() );
404         if( pEntryData )
405             pPreset = *static_cast< CustomAnimationPresetPtr* >( pEntryData );
406     }
407 
408     return pPreset;
409 }
410 
411 PathKind CustomAnimationCreateTabPage::getCreatePathKind() const
412 {
413     PathKind eKind = NONE;
414 
415     if( mpLBEffects->GetSelectEntryCount() == 1 )
416     {
417         const sal_uInt16 nPos = mpLBEffects->GetSelectEntryPos();
418         if( nPos == mnCurvePathPos )
419         {
420             eKind = CURVE;
421         }
422         else if( nPos == mnPolygonPathPos )
423         {
424             eKind = POLYGON;
425         }
426         else if( nPos == mnFreeformPathPos )
427         {
428             eKind = FREEFORM;
429         }
430     }
431 
432     return eKind;
433 }
434 
435 
436 
437 double CustomAnimationCreateTabPage::getDuration() const
438 {
439     sal_uInt16 nPos = mpCBSpeed->GetSelectEntryPos();
440     if( (nPos == 0xffff) || !mpCBSpeed->IsEnabled() )
441     {
442         CustomAnimationPresetPtr pPreset = getSelectedPreset();
443         if( pPreset.get() )
444             return pPreset->getDuration();
445     }
446 
447     switch( nPos )
448     {
449     case 0: return 5.0f;
450     case 1: return 3.0f;
451     case 2: return 2.0f;
452     case 3: return 1.0f;
453     case 4: return 0.5f;
454     }
455 
456     return 0.0f;
457 }
458 
459 void CustomAnimationCreateTabPage::setDuration( double fDuration )
460 {
461     sal_uInt16 nPos = 0;
462     if( fDuration < 2.0f )
463     {
464         if( fDuration < 1.0f )
465         {
466             nPos = 4;
467         }
468         else
469         {
470             nPos = 3;
471         }
472     }
473     else if( fDuration < 5.0f )
474     {
475         if( fDuration < 3.0f )
476         {
477             nPos = 2;
478         }
479         else
480         {
481             nPos = 1;
482         }
483     }
484 
485     mpCBSpeed->SelectEntryPos( nPos );
486 }
487 
488 bool CustomAnimationCreateTabPage::getIsPreview() const
489 {
490     return mpCBXPReview->IsChecked() ? true : false;
491 }
492 
493 void CustomAnimationCreateTabPage::setIsPreview( bool bIsPreview )
494 {
495     mpCBXPReview->Check( bIsPreview ? sal_True : sal_False );
496 }
497 
498 bool CustomAnimationCreateTabPage::select( const OUString& rsPresetId )
499 {
500     sal_uInt16 nPos = mpLBEffects->GetEntryCount();
501     while( nPos-- )
502     {
503         void* pEntryData = mpLBEffects->GetEntryData( nPos );
504         if( pEntryData )
505         {
506             CustomAnimationPresetPtr& pPtr = *static_cast< CustomAnimationPresetPtr* >(pEntryData);
507             if( pPtr.get() && pPtr->getPresetId() == rsPresetId )
508             {
509                 mpLBEffects->SelectEntryPos( nPos );
510                 return true;
511             }
512         }
513     }
514 
515     return false;
516 }
517 
518 // --------------------------------------------------------------------
519 
520 CustomAnimationCreateDialog::CustomAnimationCreateDialog( Window* pParent, CustomAnimationPane* pPane, const std::vector< ::com::sun::star::uno::Any >& rTargets, bool bHasText, const ::rtl::OUString& rsPresetId, double fDuration  )
521 :   TabDialog( pParent, SdResId( DLG_CUSTOMANIMATION_CREATE ) )
522 ,   mpPane( pPane )
523 ,   mrTargets( rTargets )
524 ,   mfDuration( fDuration )
525 {
526     mpTabControl = new TabControl( this, SdResId( 1 ) );
527     mpOKButton = new OKButton(this, SdResId( 1 ) ) ;
528     mpCancelButton = new CancelButton(this, SdResId( 1 ) );
529     mpHelpButton = new HelpButton(this, SdResId( 1 ) );
530 
531     FreeResource();
532 
533     SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
534     mbIsPreview = pOptions->IsPreviewNewEffects();
535 
536     const CustomAnimationPresets& rPresets = CustomAnimationPresets::getCustomAnimationPresets();
537     mpTabPages[ENTRANCE] = new CustomAnimationCreateTabPage( mpTabControl, this, ENTRANCE, rPresets.getEntrancePresets(), bHasText );
538     mpTabPages[ENTRANCE]->SetHelpId( HID_SD_CUSTOMANIMATIONDIALOG_ENTRANCE );
539     mpTabControl->SetTabPage( RID_TP_CUSTOMANIMATION_ENTRANCE, mpTabPages[ENTRANCE] );
540     mpTabPages[EMPHASIS] = new CustomAnimationCreateTabPage( mpTabControl, this, EMPHASIS, rPresets.getEmphasisPresets(), bHasText );
541     mpTabPages[EMPHASIS]->SetHelpId( HID_SD_CUSTOMANIMATIONDIALOG_EMPHASIS );
542     mpTabControl->SetTabPage( RID_TP_CUSTOMANIMATION_EMPHASIS, mpTabPages[EMPHASIS] );
543     mpTabPages[EXIT] = new CustomAnimationCreateTabPage( mpTabControl, this, EXIT, rPresets.getExitPresets(), bHasText );
544     mpTabPages[EXIT]->SetHelpId( HID_SD_CUSTOMANIMATIONDIALOG_EXIT );
545     mpTabControl->SetTabPage( RID_TP_CUSTOMANIMATION_EXIT, mpTabPages[EXIT] );
546     mpTabPages[MOTIONPATH] = new CustomAnimationCreateTabPage( mpTabControl, this, MOTIONPATH, rPresets.getMotionPathsPresets(), bHasText );
547     mpTabPages[MOTIONPATH]->SetHelpId( HID_SD_CUSTOMANIMATIONDIALOG_MOTIONPATH );
548     mpTabControl->SetTabPage( RID_TP_CUSTOMANIMATION_MOTIONPATH, mpTabPages[MOTIONPATH] );
549     mpTabPages[MISCEFFECTS] = new CustomAnimationCreateTabPage( mpTabControl, this, MISCEFFECTS, rPresets.getMiscPresets(), bHasText );
550     mpTabPages[MISCEFFECTS]->SetHelpId( HID_SD_CUSTOMANIMATIONDIALOG_MISCEFFECTS );
551     mpTabControl->SetTabPage( RID_TP_CUSTOMANIMATION_MISCEFFECTS, mpTabPages[MISCEFFECTS] );
552 
553     getCurrentPage()->setDuration( mfDuration );
554     getCurrentPage()->setIsPreview( mbIsPreview );
555 
556     mpTabControl->SetActivatePageHdl( LINK( this, CustomAnimationCreateDialog, implActivatePagekHdl ) );
557     mpTabControl->SetDeactivatePageHdl( LINK( this, CustomAnimationCreateDialog, implDeactivatePagekHdl ) );
558 
559     setPosition();
560 
561     // select current preset if available
562     if( rsPresetId.getLength() != 0 )
563     {
564         for( sal_uInt16 i = ENTRANCE; i <= MOTIONPATH; i++ )
565         {
566             if( mpTabPages[i]->select( rsPresetId ) )
567             {
568                 mpTabControl->SetCurPageId( RID_TP_CUSTOMANIMATION_ENTRANCE + i );
569                 break;
570             }
571         }
572     }
573 }
574 
575 CustomAnimationCreateDialog::~CustomAnimationCreateDialog()
576 {
577     storePosition();
578 
579     SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
580     pOptions->SetPreviewNewEffects( getCurrentPage()->getIsPreview() );
581 
582     delete mpTabPages[ENTRANCE];
583     delete mpTabPages[EMPHASIS];
584     delete mpTabPages[EXIT];
585     delete mpTabPages[MOTIONPATH];
586     delete mpTabPages[MISCEFFECTS];
587 
588     delete mpTabControl;
589     delete mpOKButton;
590     delete mpCancelButton;
591     delete mpHelpButton;
592 }
593 
594 CustomAnimationCreateTabPage* CustomAnimationCreateDialog::getCurrentPage() const
595 {
596     switch( mpTabControl->GetCurPageId() )
597     {
598     case RID_TP_CUSTOMANIMATION_ENTRANCE:   return mpTabPages[ENTRANCE];
599     case RID_TP_CUSTOMANIMATION_EMPHASIS:   return mpTabPages[EMPHASIS];
600     case RID_TP_CUSTOMANIMATION_EXIT:       return mpTabPages[EXIT];
601     case RID_TP_CUSTOMANIMATION_MISCEFFECTS:return mpTabPages[MISCEFFECTS];
602     //case RID_TP_CUSTOMANIMATION_MOTIONPATH:
603     default:
604                                             return mpTabPages[MOTIONPATH];
605     }
606 }
607 
608 PathKind CustomAnimationCreateDialog::getCreatePathKind() const
609 {
610     return getCurrentPage()->getCreatePathKind();
611 }
612 
613 CustomAnimationPresetPtr CustomAnimationCreateDialog::getSelectedPreset() const
614 {
615     return getCurrentPage()->getSelectedPreset();
616 }
617 
618 double CustomAnimationCreateDialog::getSelectedDuration() const
619 {
620     return getCurrentPage()->getDuration();
621 }
622 
623 IMPL_LINK( CustomAnimationCreateDialog, implActivatePagekHdl, Control*, EMPTYARG )
624 {
625     getCurrentPage()->setDuration( mfDuration );
626     getCurrentPage()->setIsPreview( mbIsPreview );
627     return 1;
628 }
629 
630 IMPL_LINK( CustomAnimationCreateDialog, implDeactivatePagekHdl, Control*, EMPTYARG )
631 {
632     mfDuration = getCurrentPage()->getDuration();
633     mbIsPreview = getCurrentPage()->getIsPreview();
634     return 1;
635 }
636 
637 void CustomAnimationCreateDialog::preview( const CustomAnimationPresetPtr& pPreset ) const
638 {
639     MainSequencePtr pSequence( new MainSequence() );
640 
641     std::vector< Any >::const_iterator aIter( mrTargets.begin() );
642     const std::vector< Any >::const_iterator aEnd( mrTargets.end() );
643 
644     const double fDuration = getSelectedDuration();
645 
646     bool bFirst = true;
647     while( aIter != aEnd )
648     {
649         CustomAnimationEffectPtr pNew(
650             pSequence->append( pPreset, (*aIter++), fDuration ) );
651 
652         if( bFirst )
653             bFirst = false;
654         else
655             pNew->setNodeType( EffectNodeType::WITH_PREVIOUS );
656     }
657 
658     mpPane->preview( pSequence->getRootNode() );
659 }
660 
661 namespace
662 {
663 Window * lcl_GetTopmostParent( Window * pWindow )
664 {
665     Window * pResult = 0;
666     Window * pCurrent = pWindow ? pWindow->GetParent() : 0;
667     while( pCurrent )
668     {
669         pResult = pCurrent;
670         pCurrent = pCurrent->GetParent();
671     }
672     return pResult;
673 }
674 }
675 
676 void CustomAnimationCreateDialog::setPosition()
677 {
678     SvtViewOptions aDlgOpt(
679         E_TABDIALOG, String::CreateFromInt32( DLG_CUSTOMANIMATION_CREATE ) );
680     if ( aDlgOpt.Exists() )
681     {
682         SetWindowState( ByteString( aDlgOpt.GetWindowState().getStr(),
683                                     RTL_TEXTENCODING_ASCII_US ) );
684     }
685     else
686     {
687         // default position: aligned with right edge of parent
688         Window * pParent = lcl_GetTopmostParent( this );
689         if( pParent )
690         {
691             Point aPos( GetPosPixel());
692             Size  aSize( GetSizePixel());
693             Point aParentPos( pParent->GetPosPixel());
694             Size  aParentSize( pParent->GetSizePixel());
695 
696             // right center
697             aPos.setX( aParentSize.getWidth() - aSize.getWidth() );
698             aPos.setY( (aParentSize.getHeight() - aSize.getHeight()) / 2 );
699             SetPosPixel( aPos );
700         }
701     }
702 }
703 
704 void CustomAnimationCreateDialog::storePosition()
705 {
706     // save settings (screen position and current page)
707     SvtViewOptions aDlgOpt(
708         E_TABDIALOG, String::CreateFromInt32( DLG_CUSTOMANIMATION_CREATE ) );
709     aDlgOpt.SetWindowState(
710         OUString::createFromAscii( GetWindowState( WINDOWSTATE_MASK_POS ).GetBuffer() ) );
711 }
712 
713 }
714