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