LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/animations - CustomAnimationCreateDialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 305 0.3 %
Date: 2013-07-09 Functions: 2 46 4.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10