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 : #include <com/sun/star/presentation/AnimationEffect.hpp>
21 : #include <com/sun/star/presentation/AnimationSpeed.hpp>
22 : #include <svx/xoutbmp.hxx>
23 : #include <time.h>
24 : #include <svl/eitem.hxx>
25 : #include <svx/svdograf.hxx>
26 : #include <svx/svdogrp.hxx>
27 : #include <sfx2/basedlgs.hxx>
28 : #include <sfx2/dispatch.hxx>
29 : #include <sfx2/progress.hxx>
30 : #include <vcl/msgbox.hxx>
31 : #include <vcl/settings.hxx>
32 :
33 : #include "anminfo.hxx"
34 : #include "animobjs.hxx"
35 : #include "animobjs.hrc"
36 : #include "app.hrc"
37 : #include "strings.hrc"
38 : #include "sdresid.hxx"
39 : #include "View.hxx"
40 : #include "drawdoc.hxx"
41 : #include "sdpage.hxx"
42 : #include "res_bmp.hrc"
43 : #include "ViewShell.hxx"
44 :
45 : #include <vcl/svapp.hxx>
46 : #include <vcl/settings.hxx>
47 :
48 : // #i42894#
49 : #include <EffectMigration.hxx>
50 :
51 : #include <string>
52 : #include <algorithm>
53 :
54 : using namespace ::com::sun::star;
55 :
56 : namespace sd {
57 :
58 : /**
59 : * SdDisplay - Control
60 : */
61 0 : SdDisplay::SdDisplay( Window* pWin, SdResId Id ) :
62 : Control( pWin, Id ),
63 0 : aScale( 1, 1 )
64 : {
65 0 : SetMapMode( MAP_PIXEL );
66 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
67 0 : SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
68 0 : }
69 :
70 :
71 :
72 0 : SdDisplay::~SdDisplay()
73 : {
74 0 : }
75 :
76 :
77 :
78 0 : void SdDisplay::SetBitmapEx( BitmapEx* pBmpEx )
79 : {
80 0 : if( pBmpEx )
81 : {
82 0 : aBitmapEx = *pBmpEx;
83 : }
84 : else
85 : {
86 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
87 0 : const Color aFillColor = rStyles.GetFieldColor();
88 0 : aBitmapEx.Erase(aFillColor);
89 : }
90 0 : }
91 :
92 :
93 :
94 0 : void SdDisplay::Paint( const Rectangle& )
95 : {
96 0 : Point aPt;
97 0 : Size aSize = GetOutputSize();
98 0 : Size aBmpSize = aBitmapEx.GetBitmap().GetSizePixel();
99 0 : aBmpSize.Width() = (long) ( (double) aBmpSize.Width() * (double) aScale );
100 0 : aBmpSize.Height() = (long) ( (double) aBmpSize.Height() * (double) aScale );
101 :
102 0 : if( aBmpSize.Width() < aSize.Width() )
103 0 : aPt.X() = ( aSize.Width() - aBmpSize.Width() ) / 2;
104 0 : if( aBmpSize.Height() < aSize.Height() )
105 0 : aPt.Y() = ( aSize.Height() - aBmpSize.Height() ) / 2;
106 :
107 0 : aBitmapEx.Draw( this, aPt, aBmpSize );
108 0 : }
109 :
110 :
111 :
112 0 : void SdDisplay::SetScale( const Fraction& rFrac )
113 : {
114 0 : aScale = rFrac;
115 0 : }
116 :
117 0 : void SdDisplay::DataChanged( const DataChangedEvent& rDCEvt )
118 : {
119 0 : Control::DataChanged( rDCEvt );
120 :
121 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
122 : {
123 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
124 0 : SetBackground( Wallpaper( Color( rStyles.GetFieldColor() ) ) );
125 0 : SetDrawMode( GetSettings().GetStyleSettings().GetHighContrastMode()
126 : ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
127 0 : : ViewShell::OUTPUT_DRAWMODE_COLOR );
128 : }
129 0 : }
130 :
131 : /**
132 : * AnimationWindow - FloatingWindow
133 : */
134 0 : AnimationWindow::AnimationWindow( SfxBindings* pInBindings,
135 : SfxChildWindow *pCW, Window* pParent, const SdResId& rSdResId ) :
136 : SfxDockingWindow ( pInBindings, pCW, pParent, rSdResId ),
137 : aCtlDisplay ( this, SdResId( CTL_DISPLAY ) ),
138 : aBtnFirst ( this, SdResId( BTN_FIRST ) ),
139 : aBtnReverse ( this, SdResId( BTN_REVERSE ) ),
140 : aBtnStop ( this, SdResId( BTN_STOP ) ),
141 : aBtnPlay ( this, SdResId( BTN_PLAY ) ),
142 : aBtnLast ( this, SdResId( BTN_LAST ) ),
143 : aNumFldBitmap ( this, SdResId( NUM_FLD_BITMAP ) ),
144 : aTimeField ( this, SdResId( TIME_FIELD ) ),
145 : aLbLoopCount ( this, SdResId( LB_LOOP_COUNT ) ),
146 : aGrpBitmap ( this, SdResId( GRP_BITMAP ) ),
147 : aBtnGetOneObject ( this, SdResId( BTN_GET_ONE_OBJECT ) ),
148 : aBtnGetAllObjects ( this, SdResId( BTN_GET_ALL_OBJECTS ) ),
149 : aBtnRemoveBitmap ( this, SdResId( BTN_REMOVE_BITMAP ) ),
150 : aBtnRemoveAll ( this, SdResId( BTN_REMOVE_ALL ) ),
151 : aFtCount ( this, SdResId( FT_COUNT ) ),
152 : aFiCount ( this, SdResId( FI_COUNT ) ),
153 : aGrpAnimation ( this, SdResId( GRP_ANIMATION_GROUP ) ),
154 : aRbtGroup ( this, SdResId( RBT_GROUP ) ),
155 : aRbtBitmap ( this, SdResId( RBT_BITMAP ) ),
156 : aFtAdjustment ( this, SdResId( FT_ADJUSTMENT ) ),
157 : aLbAdjustment ( this, SdResId( LB_ADJUSTMENT ) ),
158 : aBtnCreateGroup ( this, SdResId( BTN_CREATE_GROUP ) ),
159 : aBtnHelp ( this, SdResId( BTN_HELP ) ),
160 :
161 :
162 : pWin ( pParent ),
163 : m_nCurrentFrame ( EMPTY_FRAMELIST ),
164 :
165 : bMovie ( sal_False ),
166 : bAllObjects ( sal_False ),
167 :
168 0 : pBindings ( pInBindings )
169 : {
170 0 : aCtlDisplay.SetAccessibleName(SD_RESSTR(STR_DISPLAY));
171 0 : FreeResource();
172 : //undo SfxDockingWindow HelpId clear hack
173 0 : reverseUniqueHelpIdHack(*this);
174 :
175 : // create new document with page
176 0 : pMyDoc = new SdDrawDocument(DOCUMENT_TYPE_IMPRESS, NULL);
177 0 : SdPage* pPage = (SdPage*) pMyDoc->AllocPage(false);
178 0 : pMyDoc->InsertPage(pPage);
179 :
180 0 : pControllerItem = new AnimationControllerItem( SID_ANIMATOR_STATE, this, pBindings );
181 :
182 : // as long as not in the resource
183 0 : aTimeField.SetFormat( TIMEF_SEC_CS );
184 :
185 0 : aBtnFirst.SetClickHdl( LINK( this, AnimationWindow, ClickFirstHdl ) );
186 0 : aBtnReverse.SetClickHdl( LINK( this, AnimationWindow, ClickPlayHdl ) );
187 0 : aBtnStop.SetClickHdl( LINK( this, AnimationWindow, ClickStopHdl ) );
188 0 : aBtnPlay.SetClickHdl( LINK( this, AnimationWindow, ClickPlayHdl ) );
189 0 : aBtnLast.SetClickHdl( LINK( this, AnimationWindow, ClickLastHdl ) );
190 :
191 0 : aBtnGetOneObject.SetClickHdl( LINK( this, AnimationWindow, ClickGetObjectHdl ) );
192 0 : aBtnGetAllObjects.SetClickHdl( LINK( this, AnimationWindow, ClickGetObjectHdl ) );
193 0 : aBtnRemoveBitmap.SetClickHdl( LINK( this, AnimationWindow, ClickRemoveBitmapHdl ) );
194 0 : aBtnRemoveAll.SetClickHdl( LINK( this, AnimationWindow, ClickRemoveBitmapHdl ) );
195 :
196 0 : aRbtGroup.SetClickHdl( LINK( this, AnimationWindow, ClickRbtHdl ) );
197 0 : aRbtBitmap.SetClickHdl( LINK( this, AnimationWindow, ClickRbtHdl ) );
198 0 : aBtnCreateGroup.SetClickHdl( LINK( this, AnimationWindow, ClickCreateGroupHdl ) );
199 0 : aNumFldBitmap.SetModifyHdl( LINK( this, AnimationWindow, ModifyBitmapHdl ) );
200 0 : aTimeField.SetModifyHdl( LINK( this, AnimationWindow, ModifyTimeHdl ) );
201 :
202 : // disable 3D border
203 0 : aCtlDisplay.SetBorderStyle(WINDOW_BORDER_MONO);
204 0 : aDisplaySize = aCtlDisplay.GetOutputSize();
205 :
206 0 : aSize = GetOutputSizePixel();
207 0 : SetMinOutputSizePixel( aSize );
208 :
209 0 : ResetAttrs();
210 :
211 : // the animator is empty; no animation group can be created
212 0 : aBtnCreateGroup.Disable();
213 :
214 0 : aBtnGetOneObject.SetAccessibleRelationMemberOf( &aGrpBitmap );
215 0 : aBtnGetAllObjects.SetAccessibleRelationMemberOf( &aGrpBitmap );
216 0 : aBtnRemoveBitmap.SetAccessibleRelationMemberOf( &aGrpBitmap );
217 0 : aBtnRemoveAll.SetAccessibleRelationMemberOf( &aGrpBitmap );
218 0 : }
219 :
220 :
221 :
222 0 : AnimationWindow::~AnimationWindow()
223 : {
224 0 : delete pControllerItem;
225 :
226 0 : for (size_t i = 0; i < m_FrameList.size(); ++i)
227 : {
228 0 : delete m_FrameList[i].first;
229 0 : delete m_FrameList[i].second;
230 : }
231 0 : m_FrameList.clear();
232 0 : m_nCurrentFrame = EMPTY_FRAMELIST;
233 :
234 : // delete the clones
235 0 : delete pMyDoc;
236 0 : }
237 :
238 :
239 :
240 0 : IMPL_LINK_NOARG(AnimationWindow, ClickFirstHdl)
241 : {
242 0 : m_nCurrentFrame = (m_FrameList.empty()) ? EMPTY_FRAMELIST : 0;
243 0 : UpdateControl();
244 :
245 0 : return( 0L );
246 : }
247 :
248 :
249 :
250 0 : IMPL_LINK_NOARG(AnimationWindow, ClickStopHdl)
251 : {
252 0 : bMovie = sal_False;
253 0 : return( 0L );
254 : }
255 :
256 :
257 :
258 0 : IMPL_LINK( AnimationWindow, ClickPlayHdl, void *, p )
259 : {
260 0 : ScopeLockGuard aGuard( maPlayLock );
261 :
262 0 : bMovie = sal_True;
263 0 : sal_Bool bDisableCtrls = sal_False;
264 0 : size_t const nCount = m_FrameList.size();
265 0 : sal_Bool bReverse = p == &aBtnReverse;
266 :
267 : // it is difficult to find it later on
268 0 : sal_Bool bRbtGroupEnabled = aRbtGroup.IsEnabled();
269 0 : sal_Bool bBtnGetAllObjectsEnabled = aBtnGetAllObjects.IsEnabled();
270 0 : sal_Bool bBtnGetOneObjectEnabled = aBtnGetOneObject.IsEnabled();
271 :
272 : // calculate overall time
273 0 : Time aTime( 0 );
274 : long nFullTime;
275 0 : if( aRbtBitmap.IsChecked() )
276 : {
277 0 : for (size_t i = 0; i < nCount; ++i)
278 : {
279 0 : aTime += *m_FrameList[i].second;
280 : }
281 0 : nFullTime = aTime.GetMSFromTime();
282 : }
283 : else
284 : {
285 0 : nFullTime = nCount * 100;
286 0 : aTime.MakeTimeFromMS( nFullTime );
287 : }
288 :
289 : // StatusBarManager from 1 second
290 0 : SfxProgress* pProgress = NULL;
291 0 : if( nFullTime >= 1000 )
292 : {
293 0 : bDisableCtrls = sal_True;
294 0 : aBtnStop.Enable();
295 0 : aBtnStop.Update();
296 0 : OUString aStr("Animator:"); // here we should think about something smart
297 0 : pProgress = new SfxProgress( NULL, aStr, nFullTime );
298 : }
299 :
300 0 : sal_uLong nTmpTime = 0;
301 0 : size_t i = 0;
302 0 : sal_Bool bCount = i < nCount;
303 0 : if( bReverse )
304 : {
305 0 : i = nCount - 1;
306 : }
307 0 : while( bCount && bMovie )
308 : {
309 : // make list and view consistent
310 : assert(0 < i && i < m_FrameList.size());
311 0 : m_nCurrentFrame = i;
312 :
313 0 : UpdateControl(bDisableCtrls);
314 :
315 0 : if( aRbtBitmap.IsChecked() )
316 : {
317 0 : Time *const pTime = m_FrameList[i].second;
318 : assert(pTime);
319 :
320 0 : aTimeField.SetTime( *pTime );
321 0 : sal_uLong nTime = pTime->GetMSFromTime();
322 :
323 0 : WaitInEffect( nTime, nTmpTime, pProgress );
324 0 : nTmpTime += nTime;
325 : }
326 : else
327 : {
328 0 : WaitInEffect( 100, nTmpTime, pProgress );
329 0 : nTmpTime += 100;
330 : }
331 0 : if( bReverse )
332 : {
333 0 : if (i == 0)
334 : {
335 : // Terminate loop.
336 0 : bCount = false;
337 : }
338 : else
339 : {
340 0 : --i;
341 : }
342 : }
343 : else
344 : {
345 0 : i++;
346 0 : if (i >= nCount)
347 : {
348 : // Terminate loop.
349 0 : bCount = false;
350 : // Move i back into valid range.
351 0 : i = nCount - 1;
352 : }
353 : }
354 : }
355 :
356 : // to re-enable the controls
357 0 : bMovie = sal_False;
358 0 : if (nCount > 0)
359 : {
360 : assert(i == m_nCurrentFrame);
361 0 : UpdateControl();
362 : }
363 :
364 0 : if( pProgress )
365 : {
366 0 : delete pProgress;
367 0 : aBtnStop.Disable();
368 : }
369 :
370 0 : aRbtGroup.Enable( bRbtGroupEnabled );
371 0 : aBtnGetAllObjects.Enable( bBtnGetAllObjectsEnabled );
372 0 : aBtnGetOneObject.Enable( bBtnGetOneObjectEnabled );
373 :
374 0 : return( 0L );
375 : }
376 :
377 :
378 :
379 0 : IMPL_LINK_NOARG(AnimationWindow, ClickLastHdl)
380 : {
381 : m_nCurrentFrame =
382 0 : (m_FrameList.empty()) ? EMPTY_FRAMELIST : m_FrameList.size() - 1 ;
383 0 : UpdateControl();
384 :
385 0 : return( 0L );
386 : }
387 :
388 :
389 :
390 0 : IMPL_LINK( AnimationWindow, ClickRbtHdl, void *, p )
391 : {
392 0 : if (m_FrameList.empty() || p == &aRbtGroup || aRbtGroup.IsChecked())
393 : {
394 0 : aTimeField.SetText( OUString() );
395 0 : aTimeField.Enable( false );
396 0 : aLbLoopCount.Enable( false );
397 : }
398 0 : else if( p == &aRbtBitmap || aRbtBitmap.IsChecked() )
399 : {
400 0 : sal_uLong n = static_cast<sal_uLong>(aNumFldBitmap.GetValue());
401 0 : if( n > 0 )
402 : {
403 0 : Time *const pTime = m_FrameList[n - 1].second;
404 0 : if( pTime )
405 0 : aTimeField.SetTime( *pTime );
406 : }
407 0 : aTimeField.Enable();
408 0 : aLbLoopCount.Enable();
409 : }
410 :
411 0 : return( 0L );
412 : }
413 :
414 :
415 :
416 0 : IMPL_LINK( AnimationWindow, ClickGetObjectHdl, void *, pBtn )
417 : {
418 0 : bAllObjects = pBtn == &aBtnGetAllObjects;
419 :
420 : // Code now in AddObj()
421 0 : SfxBoolItem aItem( SID_ANIMATOR_ADD, true );
422 :
423 0 : GetBindings().GetDispatcher()->Execute(
424 0 : SID_ANIMATOR_ADD, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
425 0 : return( 0L );
426 : }
427 :
428 :
429 :
430 0 : IMPL_LINK( AnimationWindow, ClickRemoveBitmapHdl, void *, pBtn )
431 : {
432 0 : SdPage* pPage = pMyDoc->GetSdPage(0, PK_STANDARD);
433 : SdrObject* pObject;
434 :
435 0 : if( pBtn == &aBtnRemoveBitmap )
436 : {
437 0 : delete m_FrameList[m_nCurrentFrame].first;
438 0 : delete m_FrameList[m_nCurrentFrame].second;
439 0 : m_FrameList.erase(m_FrameList.begin() + m_nCurrentFrame);
440 :
441 0 : pObject = pPage->GetObj(m_nCurrentFrame);
442 : // Through acquisition of the AnimatedGIFs, objects does not need to
443 : // exist.
444 0 : if( pObject )
445 : {
446 0 : pObject = pPage->RemoveObject(m_nCurrentFrame);
447 : DBG_ASSERT(pObject, "Clone not found during deletion");
448 0 : SdrObject::Free( pObject );
449 0 : pPage->RecalcObjOrdNums();
450 : }
451 :
452 0 : if (m_nCurrentFrame >= m_FrameList.size())
453 : {
454 : assert(m_FrameList.empty());
455 0 : m_nCurrentFrame = EMPTY_FRAMELIST;
456 : }
457 : }
458 : else // delete everything
459 : {
460 0 : WarningBox aWarnBox( this, WB_YES_NO, SD_RESSTR( STR_ASK_DELETE_ALL_PICTURES ) );
461 0 : short nReturn = aWarnBox.Execute();
462 :
463 0 : if( nReturn == RET_YES )
464 : {
465 : // clear frame list
466 0 : for (size_t i = m_FrameList.size(); i > 0; )
467 : {
468 0 : --i;
469 0 : delete m_FrameList[i].first;
470 :
471 0 : pObject = pPage->GetObj( i );
472 0 : if( pObject )
473 : {
474 0 : pObject = pPage->RemoveObject( i );
475 : DBG_ASSERT(pObject, "Clone not found during deletion");
476 0 : SdrObject::Free( pObject );
477 : //pPage->RecalcObjOrdNums();
478 : }
479 :
480 0 : delete m_FrameList[i].second;
481 : }
482 0 : m_FrameList.clear();
483 0 : m_nCurrentFrame = EMPTY_FRAMELIST;
484 0 : }
485 : }
486 :
487 : // can we create a animation group
488 0 : if (m_FrameList.empty())
489 : {
490 0 : aBtnCreateGroup.Disable();
491 : // if previous disabled by acquisition of AnimatedGIFs:
492 : //aRbtBitmap.Enable();
493 0 : aRbtGroup.Enable();
494 : }
495 :
496 : // calculate and set zoom for DisplayWin
497 0 : Fraction aFrac( GetScale() );
498 0 : aCtlDisplay.SetScale( aFrac );
499 :
500 0 : UpdateControl();
501 :
502 0 : return( 0L );
503 : }
504 :
505 :
506 :
507 0 : IMPL_LINK_NOARG(AnimationWindow, ClickCreateGroupHdl)
508 : {
509 : // Code now in CreatePresObj()
510 0 : SfxBoolItem aItem( SID_ANIMATOR_CREATE, true );
511 :
512 0 : GetBindings().GetDispatcher()->Execute(
513 0 : SID_ANIMATOR_CREATE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
514 0 : return( 0L );
515 : }
516 :
517 :
518 :
519 0 : IMPL_LINK_NOARG(AnimationWindow, ModifyBitmapHdl)
520 : {
521 0 : sal_uLong nBmp = static_cast<sal_uLong>(aNumFldBitmap.GetValue());
522 :
523 0 : if (nBmp > m_FrameList.size())
524 : {
525 0 : nBmp = m_FrameList.size();
526 : }
527 :
528 0 : m_nCurrentFrame = nBmp - 1;
529 :
530 0 : UpdateControl();
531 :
532 0 : return( 0L );
533 : }
534 :
535 :
536 :
537 0 : IMPL_LINK_NOARG(AnimationWindow, ModifyTimeHdl)
538 : {
539 0 : sal_uLong nPos = static_cast<sal_uLong>(aNumFldBitmap.GetValue() - 1);
540 :
541 0 : Time *const pTime = m_FrameList[nPos].second;
542 :
543 0 : *pTime = aTimeField.GetTime();
544 :
545 0 : return( 0L );
546 : }
547 :
548 :
549 :
550 0 : void AnimationWindow::UpdateControl(bool const bDisableCtrls)
551 : {
552 0 : if (!m_FrameList.empty())
553 : {
554 0 : BitmapEx aBmp(*m_FrameList[m_nCurrentFrame].first);
555 :
556 0 : SdPage* pPage = pMyDoc->GetSdPage(0, PK_STANDARD);
557 : SdrObject *const pObject =
558 0 : static_cast<SdrObject*>(pPage->GetObj(m_nCurrentFrame));
559 0 : if( pObject )
560 : {
561 0 : VirtualDevice aVD;
562 0 : Rectangle aObjRect( pObject->GetCurrentBoundRect() );
563 0 : Size aObjSize( aObjRect.GetSize() );
564 0 : Point aOrigin( Point( -aObjRect.Left(), -aObjRect.Top() ) );
565 0 : MapMode aMap( aVD.GetMapMode() );
566 0 : aMap.SetMapUnit( MAP_100TH_MM );
567 0 : aMap.SetOrigin( aOrigin );
568 0 : aVD.SetMapMode( aMap );
569 0 : aVD.SetOutputSize( aObjSize );
570 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
571 0 : aVD.SetBackground( Wallpaper( rStyles.GetFieldColor() ) );
572 0 : aVD.SetDrawMode( rStyles.GetHighContrastMode()
573 : ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
574 0 : : ViewShell::OUTPUT_DRAWMODE_COLOR );
575 0 : aVD.Erase();
576 0 : pObject->SingleObjectPainter( aVD );
577 0 : aBmp = BitmapEx( aVD.GetBitmap( aObjRect.TopLeft(), aObjSize ) );
578 : }
579 :
580 :
581 0 : aCtlDisplay.SetBitmapEx( &aBmp );
582 : }
583 : else
584 : {
585 0 : aCtlDisplay.SetBitmapEx(0);
586 : }
587 0 : aCtlDisplay.Invalidate();
588 0 : aCtlDisplay.Update();
589 :
590 : aFiCount.SetText(OUString::number(
591 0 : m_FrameList.size()));
592 :
593 0 : if (!m_FrameList.empty() && !bMovie)
594 : {
595 0 : aNumFldBitmap.SetValue(m_nCurrentFrame + 1);
596 :
597 : // if there is at least 1 object in the list
598 0 : aBtnFirst.Enable();
599 0 : aBtnReverse.Enable();
600 0 : aBtnPlay.Enable();
601 0 : aBtnLast.Enable();
602 0 : aNumFldBitmap.Enable();
603 0 : aTimeField.Enable();
604 0 : aLbLoopCount.Enable();
605 0 : aBtnRemoveBitmap.Enable();
606 0 : aBtnRemoveAll.Enable();
607 : }
608 : else
609 : {
610 : // if no object is in the list
611 0 : aBtnFirst.Enable( false );
612 0 : aBtnReverse.Enable( false );
613 0 : aBtnPlay.Enable( false );
614 0 : aBtnLast.Enable( false );
615 0 : aNumFldBitmap.Enable( false );
616 0 : aTimeField.Enable( false );
617 0 : aLbLoopCount.Enable( false );
618 0 : aBtnRemoveBitmap.Enable( false );
619 0 : aBtnRemoveAll.Enable( false );
620 :
621 : //aFtAdjustment.Enable();
622 : //aLbAdjustment.Enable();
623 : }
624 :
625 0 : if( bMovie && bDisableCtrls )
626 : {
627 0 : aBtnGetOneObject.Enable( false );
628 0 : aBtnGetAllObjects.Enable( false );
629 0 : aRbtGroup.Enable( false );
630 0 : aRbtBitmap.Enable( false );
631 0 : aBtnCreateGroup.Enable( false );
632 0 : aFtAdjustment.Enable( false );
633 0 : aLbAdjustment.Enable( false );
634 : }
635 : else
636 : {
637 : // enable 'group object' only if it is not a Animated GIF
638 0 : if (m_FrameList.empty())
639 : {
640 0 : aRbtGroup.Enable();
641 : }
642 :
643 0 : aRbtBitmap.Enable();
644 0 : aBtnCreateGroup.Enable(!m_FrameList.empty());
645 0 : aFtAdjustment.Enable( true );
646 0 : aLbAdjustment.Enable( true );
647 : }
648 :
649 0 : ClickRbtHdl( NULL );
650 0 : }
651 :
652 :
653 :
654 0 : void AnimationWindow::ResetAttrs()
655 : {
656 0 : aRbtGroup.Check();
657 0 : aLbAdjustment.SelectEntryPos( BA_CENTER );
658 : // LoopCount
659 0 : aLbLoopCount.SelectEntryPos( aLbLoopCount.GetEntryCount() - 1);
660 :
661 0 : UpdateControl();
662 0 : }
663 :
664 :
665 :
666 0 : void AnimationWindow::WaitInEffect( sal_uLong nMilliSeconds, sal_uLong nTime,
667 : SfxProgress* pProgress ) const
668 : {
669 0 : clock_t aEnd = Time::GetSystemTicks() + nMilliSeconds;
670 0 : clock_t aCurrent = Time::GetSystemTicks();
671 0 : while (aCurrent < aEnd)
672 : {
673 0 : aCurrent = Time::GetSystemTicks();
674 :
675 0 : if( pProgress )
676 0 : pProgress->SetState( nTime + nMilliSeconds + aCurrent - aEnd );
677 :
678 0 : Application::Reschedule();
679 :
680 0 : if( !bMovie )
681 0 : return;
682 : }
683 : }
684 :
685 :
686 :
687 0 : Fraction AnimationWindow::GetScale()
688 : {
689 0 : Fraction aFrac;
690 0 : size_t const nCount = m_FrameList.size();
691 0 : if (nCount > 0)
692 : {
693 0 : aBmpSize.Width() = 0;
694 0 : aBmpSize.Height() = 0;
695 0 : for (size_t i = 0; i < nCount; i++)
696 : {
697 0 : BitmapEx *const pBitmap = m_FrameList[i].first;
698 0 : Size aTempSize( pBitmap->GetBitmap().GetSizePixel() );
699 0 : aBmpSize.Width() = std::max( aBmpSize.Width(), aTempSize.Width() );
700 0 : aBmpSize.Height() = std::max( aBmpSize.Height(), aTempSize.Height() );
701 : }
702 :
703 0 : aBmpSize.Width() += 10;
704 0 : aBmpSize.Height() += 10;
705 :
706 0 : aFrac = Fraction( std::min( (double)aDisplaySize.Width() / (double)aBmpSize.Width(),
707 0 : (double)aDisplaySize.Height() / (double)aBmpSize.Height() ) );
708 : }
709 0 : return( aFrac );
710 : }
711 :
712 :
713 :
714 0 : void AnimationWindow::Resize()
715 : {
716 0 : if ( !IsFloatingMode() ||
717 0 : !GetFloatingWindow()->IsRollUp() )
718 : {
719 0 : Size aWinSize( GetOutputSizePixel() ); // former rSize in Resizing()
720 :
721 0 : Size aDiffSize;
722 0 : aDiffSize.Width() = aWinSize.Width() - aSize.Width();
723 0 : aDiffSize.Height() = aWinSize.Height() - aSize.Height();
724 :
725 : // resize display controls
726 0 : aDisplaySize.Width() += aDiffSize.Width();
727 0 : aDisplaySize.Height() += aDiffSize.Height();
728 0 : aCtlDisplay.SetOutputSizePixel( aDisplaySize );
729 :
730 0 : Point aPt;
731 0 : aPt.Y() = aDiffSize.Height();
732 :
733 : // move other controls
734 0 : aBtnFirst.Hide();
735 0 : aBtnReverse.Hide();
736 0 : aBtnStop.Hide();
737 0 : aBtnPlay.Hide();
738 0 : aBtnLast.Hide();
739 0 : aTimeField.Hide();
740 0 : aLbLoopCount.Hide();
741 0 : aNumFldBitmap.Hide();
742 0 : aFtCount.Hide();
743 0 : aFiCount.Hide();
744 0 : aBtnGetOneObject.Hide();
745 0 : aBtnGetAllObjects.Hide();
746 0 : aBtnRemoveBitmap.Hide();
747 0 : aBtnRemoveAll.Hide();
748 0 : aGrpBitmap.Hide();
749 0 : aRbtGroup.Hide();
750 0 : aRbtBitmap.Hide();
751 0 : aFtAdjustment.Hide();
752 0 : aLbAdjustment.Hide();
753 0 : aBtnCreateGroup.Hide();
754 0 : aGrpAnimation.Hide();
755 :
756 :
757 0 : aBtnFirst.SetPosPixel( aBtnFirst.GetPosPixel() + aPt );
758 0 : aBtnReverse.SetPosPixel( aBtnReverse.GetPosPixel() + aPt );
759 0 : aBtnStop.SetPosPixel( aBtnStop.GetPosPixel() + aPt );
760 0 : aBtnPlay.SetPosPixel( aBtnPlay.GetPosPixel() + aPt );
761 0 : aBtnLast.SetPosPixel( aBtnLast.GetPosPixel() + aPt );
762 0 : aNumFldBitmap.SetPosPixel( aNumFldBitmap.GetPosPixel() + aPt );
763 0 : aTimeField.SetPosPixel( aTimeField.GetPosPixel() + aPt );
764 0 : aLbLoopCount.SetPosPixel( aLbLoopCount.GetPosPixel() + aPt );
765 0 : aFtCount.SetPosPixel( aFtCount.GetPosPixel() + aPt );
766 0 : aFiCount.SetPosPixel( aFiCount.GetPosPixel() + aPt );
767 0 : aRbtGroup.SetPosPixel( aRbtGroup.GetPosPixel() + aPt );
768 0 : aRbtBitmap.SetPosPixel( aRbtBitmap.GetPosPixel() + aPt );
769 0 : aFtAdjustment.SetPosPixel( aFtAdjustment.GetPosPixel() + aPt );
770 0 : aLbAdjustment.SetPosPixel( aLbAdjustment.GetPosPixel() + aPt );
771 0 : aBtnGetOneObject.SetPosPixel( aBtnGetOneObject.GetPosPixel() + aPt );
772 0 : aBtnGetAllObjects.SetPosPixel( aBtnGetAllObjects.GetPosPixel() + aPt );
773 0 : aBtnRemoveBitmap.SetPosPixel( aBtnRemoveBitmap.GetPosPixel() + aPt );
774 0 : aBtnRemoveAll.SetPosPixel( aBtnRemoveAll.GetPosPixel() + aPt );
775 0 : aBtnCreateGroup.SetPosPixel( aBtnCreateGroup.GetPosPixel() + aPt );
776 0 : aGrpBitmap.SetPosPixel( aGrpBitmap.GetPosPixel() + aPt );
777 0 : aGrpAnimation.SetPosPixel( aGrpAnimation.GetPosPixel() + aPt );
778 :
779 : // calculate and set zoom for DisplayWin
780 0 : Fraction aFrac( GetScale() );
781 0 : aCtlDisplay.SetScale( aFrac );
782 :
783 0 : aBtnFirst.Show();
784 0 : aBtnReverse.Show();
785 0 : aBtnStop.Show();
786 0 : aBtnPlay.Show();
787 0 : aBtnLast.Show();
788 0 : aNumFldBitmap.Show();
789 0 : aTimeField.Show();
790 0 : aLbLoopCount.Show();
791 0 : aFtCount.Show();
792 0 : aFiCount.Show();
793 0 : aFtAdjustment.Show();
794 0 : aLbAdjustment.Show();
795 0 : aBtnGetOneObject.Show();
796 0 : aBtnGetAllObjects.Show();
797 0 : aBtnRemoveBitmap.Show();
798 0 : aBtnRemoveAll.Show();
799 0 : aGrpBitmap.Show();
800 0 : aRbtGroup.Show();
801 0 : aRbtBitmap.Show();
802 0 : aFtAdjustment.Show();
803 0 : aLbAdjustment.Show();
804 0 : aBtnCreateGroup.Show();
805 0 : aGrpAnimation.Show();
806 :
807 0 : aSize = aWinSize;
808 : }
809 0 : SfxDockingWindow::Resize();
810 0 : }
811 :
812 :
813 :
814 0 : bool AnimationWindow::Close()
815 : {
816 0 : if( maPlayLock.isLocked() )
817 : {
818 0 : return false;
819 : }
820 : else
821 : {
822 0 : SfxBoolItem aItem( SID_ANIMATION_OBJECTS, false );
823 :
824 0 : GetBindings().GetDispatcher()->Execute(
825 0 : SID_ANIMATION_OBJECTS, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
826 :
827 0 : SfxDockingWindow::Close();
828 :
829 0 : return true;
830 : }
831 : }
832 :
833 :
834 :
835 0 : void AnimationWindow::FillInfo( SfxChildWinInfo& rInfo ) const
836 : {
837 0 : SfxDockingWindow::FillInfo( rInfo ) ;
838 0 : }
839 :
840 :
841 :
842 0 : void AnimationWindow::AddObj (::sd::View& rView )
843 : {
844 : // finish text entry mode to ensure that bitmap is identical with object
845 0 : if( rView.IsTextEdit() )
846 0 : rView.SdrEndTextEdit();
847 :
848 : // clone object(s) and insert the clone(s) into the list
849 0 : const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
850 0 : sal_uLong nMarkCount = rMarkList.GetMarkCount();
851 0 : SdPage* pPage = pMyDoc->GetSdPage(0, PK_STANDARD);
852 0 : sal_uLong nCloneCount = pPage->GetObjCount();
853 :
854 0 : if (nMarkCount > 0)
855 : {
856 : // If it is ONE animation object or one group object, which was
857 : // 'individually taken', we insert the objects separately
858 0 : sal_Bool bAnimObj = sal_False;
859 0 : if( nMarkCount == 1 )
860 : {
861 0 : SdrMark* pMark = rMarkList.GetMark(0);
862 0 : SdrObject* pObject = pMark->GetMarkedSdrObj();
863 0 : SdAnimationInfo* pAnimInfo = rView.GetDoc().GetAnimationInfo( pObject );
864 0 : sal_uInt32 nInv = pObject->GetObjInventor();
865 0 : sal_uInt16 nId = pObject->GetObjIdentifier();
866 :
867 : // Animated Bitmap (GIF)
868 0 : if( nInv == SdrInventor && nId == OBJ_GRAF && ( (SdrGrafObj*) pObject )->IsAnimated() )
869 : {
870 0 : const SdrGrafObj* pGrafObj = (SdrGrafObj*) pObject;
871 0 : Graphic aGraphic( pGrafObj->GetTransformedGraphic() );
872 0 : sal_uInt16 nCount = 0;
873 :
874 0 : if( aGraphic.IsAnimated() )
875 0 : nCount = aGraphic.GetAnimation().Count();
876 :
877 0 : if( nCount > 0 )
878 : {
879 0 : const Animation aAnimation( aGraphic.GetAnimation() );
880 :
881 0 : for( sal_uInt16 i = 0; i < nCount; i++ )
882 : {
883 0 : const AnimationBitmap& rAnimBmp = aAnimation.Get( i );
884 :
885 : BitmapEx *const pBitmapEx =
886 0 : new BitmapEx(rAnimBmp.aBmpEx);
887 :
888 : // LoopCount
889 0 : if( i == 0 )
890 : {
891 0 : long nLoopCount = aAnimation.GetLoopCount();
892 :
893 0 : if( !nLoopCount ) // endless
894 0 : aLbLoopCount.SelectEntryPos( aLbLoopCount.GetEntryCount() - 1);
895 : else
896 0 : aLbLoopCount.SelectEntry(OUString::number( nLoopCount ) );
897 : }
898 :
899 0 : long nTime = rAnimBmp.nWait;
900 0 : Time* pTime = new Time( 0, 0, nTime / 100, nTime % 100 );
901 : m_FrameList.insert(
902 0 : m_FrameList.begin() + m_nCurrentFrame + 1,
903 0 : ::std::make_pair(pBitmapEx, pTime));
904 :
905 : // increment => next one inserted after this one
906 0 : ++m_nCurrentFrame;
907 : }
908 : // if a animated GIF is taken, only such one can be created
909 0 : aRbtBitmap.Check();
910 0 : aRbtGroup.Enable( false );
911 0 : bAnimObj = sal_True;
912 0 : }
913 : }
914 0 : else if( bAllObjects || ( pAnimInfo && pAnimInfo->mbIsMovie ) )
915 : {
916 : // several objects
917 0 : SdrObjList* pObjList = ((SdrObjGroup*)pObject)->GetSubList();
918 :
919 0 : for( sal_uLong nObject = 0; nObject < pObjList->GetObjCount(); nObject++ )
920 : {
921 0 : SdrObject* pSnapShot = (SdrObject*) pObjList->GetObj( nObject );
922 :
923 : BitmapEx *const pBitmapEx = new BitmapEx(
924 : SdrExchangeView::GetObjGraphic(
925 0 : pSnapShot->GetModel(), pSnapShot).GetBitmapEx() );
926 :
927 0 : Time* pTime = new Time( aTimeField.GetTime() );
928 :
929 : m_FrameList.insert(
930 0 : m_FrameList.begin() + m_nCurrentFrame + 1,
931 0 : ::std::make_pair(pBitmapEx, pTime));
932 :
933 : // increment => next one inserted after this one
934 0 : ++m_nCurrentFrame;
935 :
936 : // Clone
937 0 : pPage->InsertObject(pSnapShot->Clone(), m_nCurrentFrame);
938 : }
939 0 : bAnimObj = sal_True;
940 : }
941 : }
942 : // also one single animated object
943 0 : if( !bAnimObj && !( bAllObjects && nMarkCount > 1 ) )
944 : {
945 : BitmapEx *const pBitmapEx =
946 0 : new BitmapEx(rView.GetAllMarkedGraphic().GetBitmapEx());
947 :
948 0 : Time* pTime = new Time( aTimeField.GetTime() );
949 :
950 : m_FrameList.insert(
951 0 : m_FrameList.begin() + m_nCurrentFrame + 1,
952 0 : ::std::make_pair(pBitmapEx, pTime));
953 : }
954 :
955 : // one single object
956 0 : if( nMarkCount == 1 && !bAnimObj )
957 : {
958 0 : SdrMark* pMark = rMarkList.GetMark(0);
959 0 : SdrObject* pObject = pMark->GetMarkedSdrObj();
960 0 : SdrObject* pClone = pObject->Clone();
961 0 : pPage->InsertObject(pClone, m_nCurrentFrame + 1);
962 : }
963 : // several objects: group the clones
964 0 : else if (nMarkCount > 1)
965 : {
966 : // take objects separately
967 0 : if( bAllObjects )
968 : {
969 0 : for( sal_uLong nObject= 0; nObject < nMarkCount; nObject++ )
970 : {
971 : // Clone
972 0 : SdrObject* pObject = rMarkList.GetMark( nObject )->GetMarkedSdrObj();
973 :
974 : BitmapEx *const pBitmapEx = new BitmapEx(
975 : SdrExchangeView::GetObjGraphic(
976 0 : pObject->GetModel(), pObject).GetBitmapEx() );
977 :
978 0 : Time* pTime = new Time( aTimeField.GetTime() );
979 :
980 : m_FrameList.insert(
981 0 : m_FrameList.begin() + m_nCurrentFrame + 1,
982 0 : ::std::make_pair(pBitmapEx, pTime));
983 :
984 : // increment => next one inserted after this one
985 0 : ++m_nCurrentFrame;
986 :
987 0 : pPage->InsertObject(pObject->Clone(), m_nCurrentFrame);
988 : }
989 0 : bAnimObj = sal_True; // that we don't change again
990 : }
991 : else
992 : {
993 0 : SdrObjGroup* pCloneGroup = new SdrObjGroup;
994 0 : SdrObjList* pObjList = pCloneGroup->GetSubList();
995 :
996 0 : for (sal_uLong nObject= 0; nObject < nMarkCount; nObject++)
997 0 : pObjList->InsertObject(rMarkList.GetMark(nObject)->GetMarkedSdrObj()->Clone(), CONTAINER_APPEND);
998 :
999 0 : pPage->InsertObject(pCloneGroup, m_nCurrentFrame + 1);
1000 : }
1001 : }
1002 :
1003 0 : if( !bAnimObj )
1004 : {
1005 0 : ++m_nCurrentFrame;
1006 : }
1007 :
1008 : // if there was nothing in the animator before but now is something
1009 : // there, we can create a animation group
1010 0 : if (nCloneCount == 0 && !m_FrameList.empty())
1011 : {
1012 0 : aBtnCreateGroup.Enable();
1013 : }
1014 :
1015 : // calculate and set zoom for DisplayWin
1016 0 : Fraction aFrac( GetScale() );
1017 0 : aCtlDisplay.SetScale( aFrac );
1018 :
1019 0 : UpdateControl();
1020 : }
1021 0 : }
1022 :
1023 :
1024 :
1025 0 : void AnimationWindow::CreateAnimObj (::sd::View& rView )
1026 : {
1027 0 : ::Window* pOutWin = static_cast< ::Window*>(rView.GetFirstOutputDevice()); // GetWin( 0 );
1028 : DBG_ASSERT( pOutWin, "Window does not exist!" );
1029 :
1030 : // find window center
1031 0 : const MapMode aMap100( MAP_100TH_MM );
1032 0 : Size aMaxSizeLog;
1033 0 : Size aMaxSizePix;
1034 0 : Size aTemp( pOutWin->GetOutputSizePixel() );
1035 0 : const Point aWindowCenter( pOutWin->PixelToLogic( Point( aTemp.Width() >> 1, aTemp.Height() >> 1 ) ) );
1036 0 : const OutputDevice* pDefDev = Application::GetDefaultDevice();
1037 0 : const size_t nCount = m_FrameList.size();
1038 0 : BitmapAdjustment eBA = (BitmapAdjustment) aLbAdjustment.GetSelectEntryPos();
1039 :
1040 : // find biggest bitmap
1041 0 : for (size_t i = 0; i < nCount; ++i)
1042 : {
1043 0 : const BitmapEx& rBmpEx = *m_FrameList[i].first;
1044 0 : const Graphic aGraphic( rBmpEx );
1045 0 : Size aTmpSizeLog;
1046 0 : const Size aTmpSizePix( rBmpEx.GetSizePixel() );
1047 :
1048 0 : if ( aGraphic.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
1049 0 : aTmpSizeLog = pDefDev->PixelToLogic( aGraphic.GetPrefSize(), aMap100 );
1050 : else
1051 0 : aTmpSizeLog = pDefDev->LogicToLogic( aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), aMap100 );
1052 :
1053 0 : aMaxSizeLog.Width() = std::max( aMaxSizeLog.Width(), aTmpSizeLog.Width() );
1054 0 : aMaxSizeLog.Height() = std::max( aMaxSizeLog.Height(), aTmpSizeLog.Height() );
1055 :
1056 0 : aMaxSizePix.Width() = std::max( aMaxSizePix.Width(), aTmpSizePix.Width() );
1057 0 : aMaxSizePix.Height() = std::max( aMaxSizePix.Height(), aTmpSizePix.Height() );
1058 0 : }
1059 :
1060 0 : SdrPageView* pPV = rView.GetSdrPageView();
1061 :
1062 0 : if( aRbtBitmap.IsChecked() )
1063 : {
1064 : // create bitmap group (Animated GIF)
1065 0 : Animation aAnimation;
1066 0 : Point aPt;
1067 :
1068 0 : for (size_t i = 0; i < nCount; ++i)
1069 : {
1070 0 : Time *const pTime = m_FrameList[i].second;
1071 0 : long nTime = pTime->GetNanoSec();
1072 0 : nTime += pTime->GetSec() * 100;
1073 :
1074 0 : BitmapEx const*const pBitmapEx = m_FrameList[i].first;
1075 :
1076 : // calculate offset for the specified direction
1077 0 : const Size aBitmapSize( pBitmapEx->GetSizePixel() );
1078 :
1079 0 : switch( eBA )
1080 : {
1081 : case BA_LEFT_UP:
1082 0 : break;
1083 :
1084 : case BA_LEFT:
1085 0 : aPt.Y() = (aMaxSizePix.Height() - aBitmapSize.Height()) >> 1;
1086 0 : break;
1087 :
1088 : case BA_LEFT_DOWN:
1089 0 : aPt.Y() = aMaxSizePix.Height() - aBitmapSize.Height();
1090 0 : break;
1091 :
1092 : case BA_UP:
1093 0 : aPt.X() = (aMaxSizePix.Width() - aBitmapSize.Width()) >> 1;
1094 0 : break;
1095 :
1096 : case BA_CENTER:
1097 0 : aPt.X() = (aMaxSizePix.Width() - aBitmapSize.Width()) >> 1;
1098 0 : aPt.Y() = (aMaxSizePix.Height() - aBitmapSize.Height()) >> 1;
1099 0 : break;
1100 :
1101 : case BA_DOWN:
1102 0 : aPt.X() = (aMaxSizePix.Width() - aBitmapSize.Width()) >> 1;
1103 0 : aPt.Y() = aMaxSizePix.Height() - aBitmapSize.Height();
1104 0 : break;
1105 :
1106 : case BA_RIGHT_UP:
1107 0 : aPt.X() = aMaxSizePix.Width() - aBitmapSize.Width();
1108 0 : break;
1109 :
1110 : case BA_RIGHT:
1111 0 : aPt.X() = aMaxSizePix.Width() - aBitmapSize.Width();
1112 0 : aPt.Y() = (aMaxSizePix.Height() - aBitmapSize.Height()) >> 1;
1113 0 : break;
1114 :
1115 : case BA_RIGHT_DOWN:
1116 0 : aPt.X() = aMaxSizePix.Width() - aBitmapSize.Width();
1117 0 : aPt.Y() = aMaxSizePix.Height() - aBitmapSize.Height();
1118 0 : break;
1119 :
1120 : }
1121 :
1122 : // find LoopCount (number of passes)
1123 0 : AnimationBitmap aAnimBmp;
1124 0 : long nLoopCount = 0L;
1125 0 : sal_Int32 nPos = aLbLoopCount.GetSelectEntryPos();
1126 :
1127 0 : if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != aLbLoopCount.GetEntryCount() - 1 ) // endless
1128 0 : nLoopCount = (long) aLbLoopCount.GetSelectEntry().toInt32();
1129 :
1130 0 : aAnimBmp.aBmpEx = *pBitmapEx;
1131 0 : aAnimBmp.aPosPix = aPt;
1132 0 : aAnimBmp.aSizePix = aBitmapSize;
1133 0 : aAnimBmp.nWait = nTime;
1134 0 : aAnimBmp.eDisposal = DISPOSE_BACK;
1135 0 : aAnimBmp.bUserInput = false;
1136 :
1137 0 : aAnimation.Insert( aAnimBmp );
1138 0 : aAnimation.SetDisplaySizePixel( aMaxSizePix );
1139 0 : aAnimation.SetLoopCount( nLoopCount );
1140 0 : }
1141 :
1142 0 : SdrGrafObj* pGrafObj = new SdrGrafObj( Graphic( aAnimation ) );
1143 0 : const Point aOrg( aWindowCenter.X() - ( aMaxSizeLog.Width() >> 1 ), aWindowCenter.Y() - ( aMaxSizeLog.Height() >> 1 ) );
1144 :
1145 0 : pGrafObj->SetLogicRect( Rectangle( aOrg, aMaxSizeLog ) );
1146 0 : rView.InsertObjectAtView( pGrafObj, *pPV, SDRINSERT_SETDEFLAYER);
1147 : }
1148 : else
1149 : {
1150 : // calculate offset for the specified direction
1151 0 : Size aOffset;
1152 0 : SdrObject * pClone = NULL;
1153 0 : SdPage* pPage = pMyDoc->GetSdPage(0, PK_STANDARD);
1154 :
1155 0 : for (size_t i = 0; i < nCount; ++i)
1156 : {
1157 0 : pClone = pPage->GetObj(i);
1158 0 : Rectangle aRect( pClone->GetSnapRect() );
1159 :
1160 0 : switch( eBA )
1161 : {
1162 : case BA_LEFT_UP:
1163 0 : break;
1164 :
1165 : case BA_LEFT:
1166 0 : aOffset.Height() = (aMaxSizeLog.Height() - aRect.GetHeight()) / 2;
1167 0 : break;
1168 :
1169 : case BA_LEFT_DOWN:
1170 0 : aOffset.Height() = aMaxSizeLog.Height() - aRect.GetHeight();
1171 0 : break;
1172 :
1173 : case BA_UP:
1174 0 : aOffset.Width() = (aMaxSizeLog.Width() - aRect.GetWidth()) / 2;
1175 0 : break;
1176 :
1177 : case BA_CENTER:
1178 0 : aOffset.Width() = (aMaxSizeLog.Width() - aRect.GetWidth()) / 2;
1179 0 : aOffset.Height() = (aMaxSizeLog.Height() - aRect.GetHeight()) / 2;
1180 0 : break;
1181 :
1182 : case BA_DOWN:
1183 0 : aOffset.Width() = (aMaxSizeLog.Width() - aRect.GetWidth()) / 2;
1184 0 : aOffset.Height() = aMaxSizeLog.Height() - aRect.GetHeight();
1185 0 : break;
1186 :
1187 : case BA_RIGHT_UP:
1188 0 : aOffset.Width() = aMaxSizeLog.Width() - aRect.GetWidth();
1189 0 : break;
1190 :
1191 : case BA_RIGHT:
1192 0 : aOffset.Width() = aMaxSizeLog.Width() - aRect.GetWidth();
1193 0 : aOffset.Height() = (aMaxSizeLog.Height() - aRect.GetHeight()) / 2;
1194 0 : break;
1195 :
1196 : case BA_RIGHT_DOWN:
1197 0 : aOffset.Width() = aMaxSizeLog.Width() - aRect.GetWidth();
1198 0 : aOffset.Height() = aMaxSizeLog.Height() - aRect.GetHeight();
1199 0 : break;
1200 :
1201 : }
1202 : // Unfortunately, SetSnapRect is not implemented for ellipses !!!
1203 0 : Point aMovePt( aWindowCenter + Point( aOffset.Width(), aOffset.Height() ) - aRect.TopLeft() );
1204 0 : Size aMoveSize( aMovePt.X(), aMovePt.Y() );
1205 0 : pClone->NbcMove( aMoveSize );
1206 : }
1207 :
1208 : // #i42894# Caution(!) variable pPage looks right, but it is a page from the local
1209 : // document the dialog is using (!), so get the target page from the target view
1210 0 : SdPage* pTargetSdPage = dynamic_cast< SdPage* >(rView.GetSdrPageView() ? rView.GetSdrPageView()->GetPage() : 0);
1211 :
1212 0 : if(pTargetSdPage)
1213 : {
1214 : // create animation group
1215 0 : SdrObjGroup* pGroup = new SdrObjGroup;
1216 0 : SdrObjList* pObjList = pGroup->GetSubList();
1217 :
1218 0 : for (size_t i = 0; i < nCount; i++)
1219 : {
1220 : // the clone remains in the animatior; we insert a clone of the
1221 : // clone into the group
1222 0 : pClone = pPage->GetObj(i);
1223 0 : SdrObject* pCloneOfClone = pClone->Clone();
1224 : //SdrObject* pCloneOfClone = pPage->GetObj(i)->Clone();
1225 0 : pObjList->InsertObject(pCloneOfClone, CONTAINER_APPEND);
1226 : }
1227 :
1228 : // until now the top left corner of the group is in the window center;
1229 : // correct the position by half of the size of the group
1230 0 : aTemp = aMaxSizeLog;
1231 0 : aTemp.Height() = - aTemp.Height() / 2;
1232 0 : aTemp.Width() = - aTemp.Width() / 2;
1233 0 : pGroup->NbcMove(aTemp);
1234 :
1235 : // #i42894# create needed SMIL stuff and move child objects to page directly (see
1236 : // comments at EffectMigration::CreateAnimatedGroup why this has to be done).
1237 0 : EffectMigration::CreateAnimatedGroup(*pGroup, *pTargetSdPage);
1238 :
1239 : // #i42894# if that worked, delete the group again
1240 0 : if(!pGroup->GetSubList()->GetObjCount())
1241 : {
1242 0 : delete pGroup;
1243 : }
1244 : }
1245 : }
1246 :
1247 0 : ClickFirstHdl( this );
1248 0 : }
1249 :
1250 0 : void AnimationWindow::DataChanged( const DataChangedEvent& rDCEvt )
1251 : {
1252 0 : SfxDockingWindow::DataChanged( rDCEvt );
1253 :
1254 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1255 : {
1256 0 : UpdateControl();
1257 : }
1258 0 : }
1259 :
1260 : /**
1261 : * ControllerItem for Animator
1262 : */
1263 0 : AnimationControllerItem::AnimationControllerItem(
1264 : sal_uInt16 _nId,
1265 : AnimationWindow* pAnimWin,
1266 : SfxBindings* _pBindings)
1267 : : SfxControllerItem( _nId, *_pBindings ),
1268 0 : pAnimationWin( pAnimWin )
1269 : {
1270 0 : }
1271 :
1272 :
1273 :
1274 0 : void AnimationControllerItem::StateChanged( sal_uInt16 nSId,
1275 : SfxItemState eState, const SfxPoolItem* pItem )
1276 : {
1277 0 : if( eState >= SFX_ITEM_AVAILABLE && nSId == SID_ANIMATOR_STATE )
1278 : {
1279 0 : const SfxUInt16Item* pStateItem = PTR_CAST( SfxUInt16Item, pItem );
1280 : DBG_ASSERT( pStateItem, "SfxUInt16Item expected");
1281 0 : sal_uInt16 nState = pStateItem->GetValue();
1282 :
1283 0 : pAnimationWin->aBtnGetOneObject.Enable( nState & 1 );
1284 0 : pAnimationWin->aBtnGetAllObjects.Enable( nState & 2 );
1285 : }
1286 0 : }
1287 :
1288 :
1289 0 : } // end of namespace sd
1290 :
1291 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|