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