merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / animations / AnimationSchemesPane.cxx
blob1c6a93f448c42ea5ec5af327e5e41825587b9dca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AnimationSchemesPane.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include "AnimationSchemesPane.hxx"
34 #include "AnimationSchemesPane.hrc"
35 #include "CustomAnimation.hrc"
37 #include "TransitionPreset.hxx"
38 #include "sdresid.hxx"
39 #include "ViewShellBase.hxx"
40 #include "DrawDocShell.hxx"
41 #include "SlideSorterViewShell.hxx"
42 #include "drawdoc.hxx"
43 #include "filedlg.hxx"
44 #include "strings.hrc"
45 #include "EventMultiplexer.hxx"
46 #include <com/sun/star/beans/XPropertySet.hpp>
48 #ifndef _SVT_CONTROLDIMS_HRC_
49 #include <svtools/controldims.hrc>
50 #endif
51 #include <svx/gallery.hxx>
52 #include <svtools/pathoptions.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <tools/urlobj.hxx>
56 #include <algorithm>
59 using namespace ::com::sun::star;
61 using ::com::sun::star::uno::Reference;
62 using ::com::sun::star::uno::Sequence;
63 using ::rtl::OUString;
64 using ::com::sun::star::uno::RuntimeException;
66 // ______________________
68 // Local Helper Functions
69 // ______________________
71 namespace
74 typedef ::boost::shared_ptr<sd::slidesorter::SlideSorterViewShell::PageSelection>
75 SharedPageSelection;
76 SharedPageSelection lcl_getSelectedPages (::sd::ViewShellBase& rBase)
78 ::sd::slidesorter::SlideSorterViewShell*pSlideSorterViewShell
79 = ::sd::slidesorter::SlideSorterViewShell::GetSlideSorter(rBase);
80 DBG_ASSERT( pSlideSorterViewShell, "No Slide-Sorter available" );
82 if (pSlideSorterViewShell != NULL)
84 return pSlideSorterViewShell->GetPageSelection();
86 else
88 return SharedPageSelection(new sd::slidesorter::SlideSorterViewShell::PageSelection());
92 // void lcl_ApplyToPages( ::std::vector< SdPage * > aPages, const ::sd::impl::TransitionEffect & rEffect )
93 // {
94 // ::std::vector< SdPage * >::const_iterator aIt( aPages.begin());
95 // const ::std::vector< SdPage * >::const_iterator aEndIt( aPages.end());
96 // for( ; aIt != aEndIt; ++aIt )
97 // {
98 // rEffect.applyTo( *(*aIt) );
99 // }
100 // }
102 } // anonymous namespace
104 namespace sd
107 // ____________________
109 // AnimationSchemesPane
110 // ____________________
112 AnimationSchemesPane::AnimationSchemesPane(
113 ::Window * pParent,
114 ViewShellBase & rBase,
115 SdDrawDocument* pDoc ) :
116 Control( pParent, SdResId( DLG_ANIMATION_SCHEMES_PANE ) ),
118 mrBase( rBase ),
119 mpDrawDoc( pDoc ),
120 maFL_APPLY_SCHEME( this, SdResId( FL_APPLY_SCHEME ) ),
121 maLB_ANIMATION_SCHEMES( this, SdResId( LB_ANIMATION_SCHEMES ) ),
122 maFL_EMPTY1( this, SdResId( FL_EMPTY1 ) ),
123 maPB_APPLY_TO_ALL( this, SdResId( PB_APPLY_TO_ALL ) ),
124 maPB_PLAY( this, SdResId( PB_PLAY ) ),
125 maPB_SLIDE_SHOW( this, SdResId( PB_SLIDE_SHOW ) ),
126 maFL_EMPTY2( this, SdResId( FL_EMPTY2 ) ),
127 maCB_AUTO_PREVIEW( this, SdResId( CB_AUTO_PREVIEW ) ),
129 maSTR_NO_SCHEME( SdResId( STR_NO_SCHEME ) ),
130 mbHasSelection( false ),
131 mbUpdatingControls( false ),
132 mbIsMainViewChangePending( false )
134 // use no resource ids from here on
135 FreeResource();
137 if( pDoc )
138 mxModel.set( pDoc->getUnoModel(), uno::UNO_QUERY );
139 // TODO: get correct view
140 if( mxModel.is())
141 mxView.set( mxModel->getCurrentController(), uno::UNO_QUERY );
143 // fill list box of slide transitions
144 maLB_ANIMATION_SCHEMES.InsertEntry( maSTR_NO_SCHEME );
146 // set defaults
147 maCB_AUTO_PREVIEW.Check(); // automatic preview on
149 // update control states before adding handlers
150 updateLayout();
151 updateControls();
153 // set handlers
154 maPB_APPLY_TO_ALL.SetClickHdl( LINK( this, AnimationSchemesPane, ApplyToAllButtonClicked ));
155 maPB_PLAY.SetClickHdl( LINK( this, AnimationSchemesPane, PlayButtonClicked ));
156 maPB_SLIDE_SHOW.SetClickHdl( LINK( this, AnimationSchemesPane, SlideShowButtonClicked ));
158 maLB_ANIMATION_SCHEMES.SetSelectHdl( LINK( this, AnimationSchemesPane, SchemeSelected ));
160 addListener();
163 AnimationSchemesPane::~AnimationSchemesPane()
165 removeListener();
168 void AnimationSchemesPane::Resize()
170 updateLayout();
173 void AnimationSchemesPane::onSelectionChanged()
175 updateControls();
178 void AnimationSchemesPane::onChangeCurrentPage()
180 updateControls();
183 void AnimationSchemesPane::updateLayout()
185 ::Size aPaneSize( GetSizePixel() );
187 // start layouting elements from bottom to top. The remaining space is used
188 // for the topmost list box
189 ::Point aOffset( LogicToPixel( Point( 3, 3 ), MAP_APPFONT ) );
190 long nOffsetX = aOffset.getX();
191 long nOffsetY = aOffset.getY();
192 long nOffsetBtnX = LogicToPixel( Point( 6, 1 ), MAP_APPFONT ).getX();
194 ::Point aUpperLeft( nOffsetX, aPaneSize.getHeight() - nOffsetY );
195 long nMaxWidth = aPaneSize.getWidth() - 2 * nOffsetX;
197 // auto preview check-box
198 ::Size aCtrlSize = maCB_AUTO_PREVIEW.GetSizePixel();
199 aCtrlSize.setWidth( maCB_AUTO_PREVIEW.CalcMinimumSize( nMaxWidth ).getWidth());
200 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight());
201 maCB_AUTO_PREVIEW.SetPosSizePixel( aUpperLeft, aCtrlSize );
203 // fixed line above check-box
204 aCtrlSize = maFL_EMPTY2.GetSizePixel();
205 aCtrlSize.setWidth( nMaxWidth );
206 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight());
207 maFL_EMPTY2.SetPosSizePixel( aUpperLeft, aCtrlSize );
209 // buttons "Play" and "Slide Show"
210 long nPlayButtonWidth = maPB_PLAY.CalcMinimumSize().getWidth() + 2 * nOffsetBtnX;
211 long nSlideShowButtonWidth = maPB_SLIDE_SHOW.CalcMinimumSize().getWidth() + 2 * nOffsetBtnX;
213 if( (nPlayButtonWidth + nSlideShowButtonWidth + nOffsetX) <= nMaxWidth )
215 // place buttons side by side
216 aCtrlSize = maPB_PLAY.GetSizePixel();
217 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight());
218 aCtrlSize.setWidth( nPlayButtonWidth );
219 maPB_PLAY.SetPosSizePixel( aUpperLeft, aCtrlSize );
221 aUpperLeft.setX( aUpperLeft.getX() + nPlayButtonWidth + nOffsetX );
222 aCtrlSize.setWidth( nSlideShowButtonWidth );
223 maPB_SLIDE_SHOW.SetPosSizePixel( aUpperLeft, aCtrlSize );
224 aUpperLeft.setX( nOffsetX );
226 else
228 // place buttons on top of each other
229 aCtrlSize = maPB_SLIDE_SHOW.GetSizePixel();
230 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight());
231 aCtrlSize.setWidth( nSlideShowButtonWidth );
232 maPB_SLIDE_SHOW.SetPosSizePixel( aUpperLeft, aCtrlSize );
234 aCtrlSize = maPB_PLAY.GetSizePixel();
235 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight() - nOffsetY );
236 aCtrlSize.setWidth( nPlayButtonWidth );
237 maPB_PLAY.SetPosSizePixel( aUpperLeft, aCtrlSize );
240 // "Apply to All Slides" button
241 aCtrlSize = maPB_APPLY_TO_ALL.GetSizePixel();
242 aCtrlSize.setWidth( maPB_APPLY_TO_ALL.CalcMinimumSize( nMaxWidth ).getWidth() + 2 * nOffsetBtnX );
243 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight() - nOffsetY );
244 maPB_APPLY_TO_ALL.SetPosSizePixel( aUpperLeft, aCtrlSize );
246 // fixed line above "Apply to All Slides" button
247 aCtrlSize = maFL_EMPTY1.GetSizePixel();
248 aCtrlSize.setWidth( nMaxWidth );
249 aUpperLeft.setY( aUpperLeft.getY() - aCtrlSize.getHeight());
250 maFL_EMPTY1.SetPosSizePixel( aUpperLeft, aCtrlSize );
252 // fixed line "Apply to selected slides"
253 aCtrlSize = maFL_APPLY_SCHEME.GetSizePixel();
254 aCtrlSize.setWidth( nMaxWidth );
255 ::Point aUpperLeftCorner( nOffsetX, nOffsetY );
256 maFL_APPLY_SCHEME.SetPosSizePixel( aUpperLeftCorner, aCtrlSize );
257 aUpperLeftCorner.setY( aUpperLeftCorner.getY() + aCtrlSize.getHeight() + nOffsetY );
258 aUpperLeft.setY( aUpperLeft.getY() - nOffsetY );
260 // list box animation scheme
261 aCtrlSize.setWidth( nMaxWidth );
262 aCtrlSize.setHeight( aUpperLeft.getY() - aUpperLeftCorner.getY() );
263 maLB_ANIMATION_SCHEMES.SetPosSizePixel( aUpperLeftCorner, aCtrlSize );
266 void AnimationSchemesPane::updateControls()
268 SharedPageSelection aSelectedPages( lcl_getSelectedPages( mrBase ));
269 if( aSelectedPages->empty())
271 mbHasSelection = false;
272 return;
274 mbHasSelection = true;
276 DBG_ASSERT( ! mbUpdatingControls, "Multiple Control Updates" );
277 mbUpdatingControls = true;
279 // get model data for first page
280 #ifdef DBG_UTIL
281 SdPage * pFirstPage = aSelectedPages->front();
282 DBG_ASSERT( pFirstPage, "Invalid Page" );
283 #endif
285 // // merge with other pages
286 // ::std::vector< SdPage * >::const_iterator aIt( aSelectedPages.begin());
287 // const ::std::vector< SdPage * >::const_iterator aEndIt( aSelectedPages.end());
289 // // start with second page (note aIt != aEndIt, because ! aSelectedPages.empty())
290 // for( ++aIt ;aIt != aEndIt; ++aIt )
291 // {
292 // if( *aIt )
293 // // merge
294 // }
296 mbUpdatingControls = false;
298 updateControlState();
301 void AnimationSchemesPane::updateControlState()
303 maLB_ANIMATION_SCHEMES.Enable( mbHasSelection );
305 maPB_APPLY_TO_ALL.Enable( mbHasSelection );
306 maPB_PLAY.Enable( mbHasSelection );
307 // maPB_SLIDE_SHOW.Enable( TRUE );
308 maCB_AUTO_PREVIEW.Enable( mbHasSelection );
311 void AnimationSchemesPane::getAnimationSchemeFromControls() const
313 // TODO: Implement
316 void AnimationSchemesPane::applyToSelectedPages()
318 if( ! mbUpdatingControls )
320 SharedPageSelection aSelectedPages( lcl_getSelectedPages( mrBase ));
321 if( ! aSelectedPages->empty())
323 // lcl_ApplyToPages( aSelectedPages, getAnimationSchemeFromControls() );
325 if( maCB_AUTO_PREVIEW.IsEnabled() &&
326 maCB_AUTO_PREVIEW.IsChecked())
328 playCurrentScheme();
333 void AnimationSchemesPane::playCurrentScheme()
335 // TODO: Implement a preview in the center view
338 void AnimationSchemesPane::addListener()
340 Link aLink( LINK(this,AnimationSchemesPane,EventMultiplexerListener) );
341 mrBase.GetEventMultiplexer()->AddEventListener(
342 aLink,
343 tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
344 | tools::EventMultiplexerEvent::EID_CURRENT_PAGE
345 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
346 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
347 | tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED);
350 void AnimationSchemesPane::removeListener()
352 Link aLink( LINK(this,AnimationSchemesPane,EventMultiplexerListener) );
353 mrBase.GetEventMultiplexer()->RemoveEventListener( aLink );
356 IMPL_LINK(AnimationSchemesPane,EventMultiplexerListener,
357 tools::EventMultiplexerEvent*,pEvent)
359 switch (pEvent->meEventId)
361 case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION:
362 onSelectionChanged();
363 break;
365 case tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
366 onChangeCurrentPage();
367 break;
369 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
370 mxView = Reference<drawing::XDrawView>();
371 onSelectionChanged();
372 onChangeCurrentPage();
373 break;
375 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
376 mbIsMainViewChangePending = true;
377 break;
379 case tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
380 if (mbIsMainViewChangePending)
382 mbIsMainViewChangePending = false;
383 mxView = Reference<drawing::XDrawView>::query( mxModel->getCurrentController() );
384 onSelectionChanged();
385 onChangeCurrentPage();
387 break;
389 return 0;
392 IMPL_LINK( AnimationSchemesPane, ApplyToAllButtonClicked, void *, EMPTYARG )
394 DBG_ASSERT( mpDrawDoc, "Invalid Draw Document!" );
395 if( !mpDrawDoc )
396 return 0;
398 ::std::vector< SdPage * > aPages;
400 sal_uInt16 nPageCount = mpDrawDoc->GetSdPageCount( PK_STANDARD );
401 aPages.reserve( nPageCount );
402 for( sal_uInt16 i=0; i<nPageCount; ++i )
404 SdPage * pPage = mpDrawDoc->GetSdPage( i, PK_STANDARD );
405 if( pPage )
406 aPages.push_back( pPage );
409 // if( ! aPages.empty())
410 // lcl_ApplyToPages( aPages, getAnimationSchemeFromControls() );
412 return 0;
416 IMPL_LINK( AnimationSchemesPane, PlayButtonClicked, void *, EMPTYARG )
418 playCurrentScheme();
419 return 0;
422 IMPL_LINK( AnimationSchemesPane, SlideShowButtonClicked, void *, EMPTYARG )
424 mrBase.StartPresentation();
425 return 0;
428 IMPL_LINK( AnimationSchemesPane, SchemeSelected, void *, EMPTYARG )
430 applyToSelectedPages();
431 return 0;
434 ::Window * createAnimationSchemesPanel( ::Window* pParent, ViewShellBase& rBase )
436 ::Window* pWindow = 0;
438 DrawDocShell* pDocSh = rBase.GetDocShell();
439 if( pDocSh )
440 pWindow = new AnimationSchemesPane( pParent, rBase, pDocSh->GetDoc() );
442 return pWindow;
446 } // namespace sd