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