1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include <com/sun/star/presentation/XPresentation2.hpp>
27 
28 #include <editeng/outlobj.hxx>
29 
30 #include "controller/SlsSlotManager.hxx"
31 #include "SlideSorter.hxx"
32 #include "SlideSorterViewShell.hxx"
33 #include "controller/SlideSorterController.hxx"
34 #include "controller/SlsClipboard.hxx"
35 #include "controller/SlsCurrentSlideManager.hxx"
36 #include "controller/SlsFocusManager.hxx"
37 #include "controller/SlsInsertionIndicatorHandler.hxx"
38 #include "controller/SlsPageSelector.hxx"
39 #include "controller/SlsSelectionFunction.hxx"
40 #include "controller/SlsSelectionManager.hxx"
41 #include "controller/SlsSelectionObserver.hxx"
42 #include "SlsCommand.hxx"
43 #include "model/SlideSorterModel.hxx"
44 #include "model/SlsPageEnumerationProvider.hxx"
45 #include "model/SlsPageDescriptor.hxx"
46 #include "view/SlideSorterView.hxx"
47 #include "view/SlsLayouter.hxx"
48 #include "framework/FrameworkHelper.hxx"
49 #include "Window.hxx"
50 #include "fupoor.hxx"
51 #include "fuzoom.hxx"
52 #include "fucushow.hxx"
53 #include "fusldlg.hxx"
54 #include "fuexpand.hxx"
55 #include "fusumry.hxx"
56 #include "fuscale.hxx"
57 #include "slideshow.hxx"
58 #include "app.hrc"
59 #include "strings.hrc"
60 #include "sdresid.hxx"
61 #include "drawdoc.hxx"
62 #include "DrawDocShell.hxx"
63 #include "ViewShellBase.hxx"
64 #include "ViewShellImplementation.hxx"
65 #include "sdattr.hxx"
66 #include "FrameView.hxx"
67 #include "zoomlist.hxx"
68 #include "sdpage.hxx"
69 #include "sdxfer.hxx"
70 #include "helpids.h"
71 #include "glob.hrc"
72 #include "unmodpg.hxx"
73 #include "DrawViewShell.hxx"
74 
75 #include <sfx2/request.hxx>
76 #include <sfx2/viewfrm.hxx>
77 #include <sfx2/bindings.hxx>
78 #include <sfx2/dispatch.hxx>
79 #include <sfx2/sidebar/Sidebar.hxx>
80 #include <svx/svxids.hrc>
81 #include <svx/zoomitem.hxx>
82 #include <svx/svxdlg.hxx>
83 #include <svx/dialogs.hrc>
84 #include <vcl/msgbox.hxx>
85 #include <svl/intitem.hxx>
86 #include <svl/whiter.hxx>
87 #include <svl/itempool.hxx>
88 #include <svl/aeitem.hxx>
89 #include <com/sun/star/presentation/FadeEffect.hpp>
90 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
91 #include <com/sun/star/drawing/XDrawPages.hpp>
92 #include <vcl/svapp.hxx>
93 
94 #include <boost/bind.hpp>
95 
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::presentation;
99 
100 namespace sd { namespace slidesorter { namespace controller {
101 
102 namespace {
103 
104 /** The state of a set of slides with respect to being excluded from the
105     slide show.
106 */
107 enum SlideExclusionState {UNDEFINED, EXCLUDED, INCLUDED, MIXED};
108 
109 /** Return for the given set of slides whether they included are
110     excluded from the slide show.
111 */
112 SlideExclusionState GetSlideExclusionState (model::PageEnumeration& rPageSet);
113 
114 } // end of anonymous namespace
115 
116 
117 
SlotManager(SlideSorter & rSlideSorter)118 SlotManager::SlotManager (SlideSorter& rSlideSorter)
119     : mrSlideSorter(rSlideSorter),
120       maCommandQueue()
121 {
122 }
123 
124 
125 
126 
~SlotManager(void)127 SlotManager::~SlotManager (void)
128 {
129 }
130 
131 
132 
133 
FuTemporary(SfxRequest & rRequest)134 void SlotManager::FuTemporary (SfxRequest& rRequest)
135 {
136     SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
137 
138     SlideSorterViewShell* pShell
139         = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
140     if (pShell == NULL)
141         return;
142 
143     switch (rRequest.GetSlot())
144     {
145         case SID_PRESENTATION:
146         case SID_REHEARSE_TIMINGS:
147             ShowSlideShow (rRequest);
148             pShell->Cancel();
149             rRequest.Done();
150             break;
151 
152         case SID_HIDE_SLIDE:
153             ChangeSlideExclusionState(model::SharedPageDescriptor(), true);
154             break;
155 
156         case SID_SHOW_SLIDE:
157             ChangeSlideExclusionState(model::SharedPageDescriptor(), false);
158             break;
159 
160         case SID_PAGES_PER_ROW:
161             if (rRequest.GetArgs() != NULL)
162             {
163                 SFX_REQUEST_ARG(rRequest, pPagesPerRow, SfxUInt16Item,
164                     SID_PAGES_PER_ROW, sal_False);
165                 if (pPagesPerRow != NULL)
166                 {
167                     sal_Int32 nColumnCount = pPagesPerRow->GetValue();
168                     // Force the given number of columns by setting
169                     // the minimal and maximal number of columns to
170                     // the same value.
171                     mrSlideSorter.GetView().GetLayouter().SetColumnCount (
172                         nColumnCount, nColumnCount);
173                     // Force a repaint and re-layout.
174                     pShell->ArrangeGUIElements ();
175                     // Rearrange the UI-elements controlled by the
176                     // controller and force a rearrangement of the
177                     // view.
178                     mrSlideSorter.GetController().Rearrange(true);
179                 }
180             }
181             rRequest.Done();
182             break;
183 
184         case SID_SELECTALL:
185             mrSlideSorter.GetController().GetPageSelector().SelectAllPages();
186             rRequest.Done();
187             break;
188 
189         case SID_SLIDE_TRANSITIONS_PANEL:
190         {
191             // Make the slide transition panel visible in the sidebar.
192             ::sfx2::sidebar::Sidebar::ShowPanel(
193                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SlideTransitionPanel")),
194                 pShell->GetViewFrame()->GetFrame().GetFrameInterface());
195             rRequest.Ignore ();
196             break;
197         }
198 
199         case SID_PRESENTATION_DLG:
200             FuSlideShowDlg::Create (
201                 pShell,
202                 mrSlideSorter.GetContentWindow().get(),
203                 &mrSlideSorter.GetView(),
204                 pDocument,
205                 rRequest);
206             break;
207 
208         case SID_CUSTOMSHOW_DLG:
209             FuCustomShowDlg::Create (
210                 pShell,
211                 mrSlideSorter.GetContentWindow().get(),
212                 &mrSlideSorter.GetView(),
213                 pDocument,
214                 rRequest);
215                 break;
216 
217         case SID_EXPAND_PAGE:
218             FuExpandPage::Create (
219                 pShell,
220                 mrSlideSorter.GetContentWindow().get(),
221                 &mrSlideSorter.GetView(),
222                 pDocument,
223                 rRequest);
224             break;
225 
226         case SID_SUMMARY_PAGE:
227             FuSummaryPage::Create (
228                 pShell,
229                 mrSlideSorter.GetContentWindow().get(),
230                 &mrSlideSorter.GetView(),
231                 pDocument,
232                 rRequest);
233             break;
234 
235         case SID_INSERTPAGE:
236         case SID_INSERT_MASTER_PAGE:
237             InsertSlide(rRequest);
238             rRequest.Done();
239             break;
240 
241         case SID_DUPLICATE_PAGE:
242             DuplicateSelectedSlides(rRequest);
243             rRequest.Done();
244             break;
245 
246         case SID_DELETE_PAGE:
247         case SID_DELETE_MASTER_PAGE:
248         case SID_DELETE: // we need SID_CUT to handle the delete key
249             // (DEL -> accelerator -> SID_CUT).
250             if (mrSlideSorter.GetModel().GetPageCount() > 1)
251             {
252                 mrSlideSorter.GetController().GetSelectionManager()->DeleteSelectedPages();
253             }
254 
255             rRequest.Done();
256             break;
257 
258         case SID_RENAMEPAGE:
259         case SID_RENAME_MASTER_PAGE:
260             RenameSlide ();
261             rRequest.Done ();
262             break;
263 
264         case SID_ASSIGN_LAYOUT:
265         {
266             pShell->mpImpl->AssignLayout( rRequest, mrSlideSorter.GetModel().GetPageType() );
267             rRequest.Done ();
268         }
269         break;
270 
271         default:
272             break;
273     }
274 }
275 
276 
277 
278 
FuPermanent(SfxRequest & rRequest)279 void SlotManager::FuPermanent (SfxRequest& rRequest)
280 {
281     ViewShell* pShell = mrSlideSorter.GetViewShell();
282     if (pShell == NULL)
283         return;
284 
285 	if(pShell->GetCurrentFunction().is())
286     {
287 		FunctionReference xEmpty;
288 		if (pShell->GetOldFunction() == pShell->GetCurrentFunction())
289 			pShell->SetOldFunction(xEmpty);
290 
291 		pShell->GetCurrentFunction()->Deactivate();
292 		pShell->SetCurrentFunction(xEmpty);
293 	}
294 
295 	switch(rRequest.GetSlot())
296 	{
297 		case SID_OBJECT_SELECT:
298 			pShell->SetCurrentFunction( SelectionFunction::Create(mrSlideSorter, rRequest) );
299 			rRequest.Done();
300             break;
301 
302 		default:
303                 break;
304 	}
305 
306 	if(pShell->GetOldFunction().is())
307 	{
308         pShell->GetOldFunction()->Deactivate();
309 		FunctionReference xEmpty;
310 		pShell->SetOldFunction(xEmpty);
311 	}
312 
313 	if(pShell->GetCurrentFunction().is())
314 	{
315 		pShell->GetCurrentFunction()->Activate();
316 		pShell->SetOldFunction(pShell->GetCurrentFunction());
317 	}
318 
319 	//! das ist nur bis das ENUM-Slots sind
320     //	Invalidate( SID_OBJECT_SELECT );
321 }
322 
FuSupport(SfxRequest & rRequest)323 void SlotManager::FuSupport (SfxRequest& rRequest)
324 {
325 	switch (rRequest.GetSlot())
326 	{
327         case SID_STYLE_FAMILY:
328             if (rRequest.GetArgs() != NULL)
329             {
330                 SdDrawDocument* pDocument
331                     = mrSlideSorter.GetModel().GetDocument();
332                 if (pDocument != NULL)
333                 {
334                     const SfxPoolItem& rItem (
335                         rRequest.GetArgs()->Get(SID_STYLE_FAMILY));
336                     pDocument->GetDocSh()->SetStyleFamily(
337                         static_cast<const SfxUInt16Item&>(rItem).GetValue());
338                 }
339             }
340             break;
341 
342 		case SID_PASTE:
343         {
344             SdTransferable* pTransferClip = SD_MOD()->pTransferClip;
345             if( pTransferClip )
346             {
347                 SfxObjectShell* pTransferDocShell = pTransferClip->GetDocShell();
348 
349                 DrawDocShell* pDocShell = dynamic_cast<DrawDocShell*>(pTransferDocShell);
350                 if (pDocShell && pDocShell->GetDoc()->GetPageCount() > 1)
351                 {
352                     mrSlideSorter.GetController().GetClipboard().HandleSlotCall(rRequest);
353                     break;
354                 }
355             }
356             ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
357             if (pBase != NULL)
358             {
359                 ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
360                     ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
361                 if (pDrawViewShell.get() != NULL)
362                     pDrawViewShell->FuSupport(rRequest);
363             }
364         }
365         break;
366 
367 		case SID_CUT:
368 		case SID_COPY:
369         case SID_DELETE:
370             mrSlideSorter.GetController().GetClipboard().HandleSlotCall(rRequest);
371             break;
372 
373         case SID_DRAWINGMODE:
374 		case SID_NOTESMODE:
375 		case SID_HANDOUTMODE:
376 		case SID_DIAMODE:
377 		case SID_OUTLINEMODE:
378         {
379             ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
380             if (pBase != NULL)
381             {
382                 framework::FrameworkHelper::Instance(*pBase)->HandleModeChangeSlot(
383                     rRequest.GetSlot(), rRequest);
384                 rRequest.Done();
385             }
386             break;
387         }
388 
389 		case SID_UNDO:
390         {
391             SlideSorterViewShell* pViewShell
392                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
393             if (pViewShell != NULL)
394             {
395                 view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
396                 SlideSorterController::ModelChangeLock aModelLock (mrSlideSorter.GetController());
397                 PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
398                 SelectionObserver::Context aContext (mrSlideSorter);
399                 pViewShell->ImpSidUndo (sal_False, rRequest);
400             }
401             break;
402         }
403 
404 		case SID_REDO:
405         {
406             SlideSorterViewShell* pViewShell
407                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
408             if (pViewShell != NULL)
409             {
410                 view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
411                 SlideSorterController::ModelChangeLock aModelLock (mrSlideSorter.GetController());
412                 PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
413                 SelectionObserver::Context aContext (mrSlideSorter);
414                 pViewShell->ImpSidRedo (sal_False, rRequest);
415             }
416             break;
417         }
418 
419 		default:
420             break;
421 	}
422 }
423 
424 
425 
426 
ExecCtrl(SfxRequest & rRequest)427 void SlotManager::ExecCtrl (SfxRequest& rRequest)
428 {
429     ViewShell* pViewShell = mrSlideSorter.GetViewShell();
430 	sal_uInt16 nSlot = rRequest.GetSlot();
431 	switch (nSlot)
432 	{
433 		case SID_RELOAD:
434 		{
435 			// Undo-Manager leeren
436 			mrSlideSorter.GetModel().GetDocument()->GetDocSh()->ClearUndoBuffer();
437 
438 			// Normale Weiterleitung an ViewFrame zur Ausfuehrung
439             if (pViewShell != NULL)
440                 pViewShell->GetViewFrame()->ExecuteSlot(rRequest);
441 
442 			// Muss sofort beendet werden
443 			return;
444 		}
445 
446 		case SID_OUTPUT_QUALITY_COLOR:
447 		case SID_OUTPUT_QUALITY_GRAYSCALE:
448 		case SID_OUTPUT_QUALITY_BLACKWHITE:
449 		case SID_OUTPUT_QUALITY_CONTRAST:
450 		{
451             // flush page cache
452             if (pViewShell != NULL)
453                 pViewShell->ExecReq (rRequest);
454 			break;
455 		}
456 
457 		case SID_MAIL_SCROLLBODY_PAGEDOWN:
458 		{
459             if (pViewShell != NULL)
460                 pViewShell->ExecReq (rRequest);
461 			break;
462 		}
463 
464 		case SID_OPT_LOCALE_CHANGED:
465 		{
466             mrSlideSorter.GetController().UpdateAllPages();
467             if (pViewShell != NULL)
468                 pViewShell->UpdatePreview (pViewShell->GetActualPage());
469 			rRequest.Done();
470             break;
471 		}
472 
473         case SID_SEARCH_DLG:
474             // We have to handle the SID_SEARCH_DLG slot explicitly because
475             // in some cases (when the slide sorter is displayed in the
476             // center pane) we want to disable the search dialog.  Therefore
477             // we have to handle the execution of that slot as well.
478             // We try to do that by forwarding the request to the view frame
479             // of the view shell.
480             if (pViewShell != NULL)
481                 pViewShell->GetViewFrame()->ExecuteSlot(rRequest);
482             break;
483 
484 		default:
485             break;
486 	}
487 }
488 
489 
490 
491 
GetAttrState(SfxItemSet & rSet)492 void SlotManager::GetAttrState (SfxItemSet& rSet)
493 {
494     // Iteratate over all items.
495 	SfxWhichIter aIter (rSet);
496 	sal_uInt16 nWhich = aIter.FirstWhich();
497 	while (nWhich)
498 	{
499 		sal_uInt16 nSlotId (nWhich);
500         if (SfxItemPool::IsWhich(nWhich) && mrSlideSorter.GetViewShell()!=NULL)
501 			nSlotId = mrSlideSorter.GetViewShell()->GetPool().GetSlotId(nWhich);
502 		switch (nSlotId)
503 		{
504 			case SID_PAGES_PER_ROW:
505                 rSet.Put (
506                     SfxUInt16Item (
507                         nSlotId,
508                         (sal_uInt16)mrSlideSorter.GetView().GetLayouter().GetColumnCount()
509                         )
510                     );
511 			break;
512 		}
513 		nWhich = aIter.NextWhich();
514 	}
515 }
516 
GetMenuState(SfxItemSet & rSet)517 void SlotManager::GetMenuState (SfxItemSet& rSet)
518 {
519     EditMode eEditMode = mrSlideSorter.GetModel().GetEditMode();
520     ViewShell* pShell = mrSlideSorter.GetViewShell();
521     DrawDocShell* pDocShell = mrSlideSorter.GetModel().GetDocument()->GetDocSh();
522 
523 	if (pShell!=NULL && pShell->GetCurrentFunction().is())
524 	{
525 		sal_uInt16 nSId = pShell->GetCurrentFunction()->GetSlotID();
526 
527 		rSet.Put( SfxBoolItem( nSId, sal_True ) );
528 	}
529 	rSet.Put( SfxBoolItem( SID_DRAWINGMODE, sal_False ) );
530 	rSet.Put( SfxBoolItem( SID_DIAMODE, sal_True ) );
531 	rSet.Put( SfxBoolItem( SID_OUTLINEMODE, sal_False ) );
532 	rSet.Put( SfxBoolItem( SID_NOTESMODE, sal_False ) );
533 	rSet.Put( SfxBoolItem( SID_HANDOUTMODE, sal_False ) );
534 
535 	// Vorlagenkatalog darf nicht aufgerufen werden
536 	rSet.DisableItem(SID_STYLE_CATALOG);
537 
538     if (pShell!=NULL && pShell->IsMainViewShell())
539     {
540         rSet.DisableItem(SID_SPELL_DIALOG);
541         rSet.DisableItem(SID_SEARCH_DLG);
542     }
543 
544 	if (SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_EXPAND_PAGE))
545 	{
546 		bool bDisable = true;
547         if (eEditMode == EM_PAGE)
548         {
549             // At least one of the selected pages has to contain an outline
550             // presentation objects in order to enable the expand page menu
551             // entry.
552             model::PageEnumeration aSelectedPages (
553                 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
554                     mrSlideSorter.GetModel()));
555             while (aSelectedPages.HasMoreElements())
556             {
557                 SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
558                 SdrObject* pObj = pPage->GetPresObj(PRESOBJ_OUTLINE);
559                 if (pObj!=NULL )
560 				{
561 					if( !pObj->IsEmptyPresObj() )
562 					{
563 						bDisable = false;
564 					}
565 					else
566 					{
567 						// check if the object is in edit, than its temporarely not empty
568 						SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
569 						if( pTextObj )
570 						{
571 							OutlinerParaObject* pParaObj = pTextObj->GetEditOutlinerParaObject();
572 							if( pParaObj )
573 							{
574 								delete pParaObj;
575 								bDisable = false;
576 							}
577 						}
578 					}
579 				}
580             }
581         }
582 
583 		if (bDisable)
584 			rSet.DisableItem (SID_EXPAND_PAGE);
585 	}
586 
587 	if (SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_SUMMARY_PAGE))
588 	{
589         bool bDisable = true;
590         if (eEditMode == EM_PAGE)
591         {
592             // At least one of the selected pages has to contain a title
593             // presentation objects in order to enable the summary page menu
594             // entry.
595             model::PageEnumeration aSelectedPages (
596                 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
597                     mrSlideSorter.GetModel()));
598             while (aSelectedPages.HasMoreElements())
599             {
600                 SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
601                 SdrObject* pObj = pPage->GetPresObj(PRESOBJ_TITLE);
602 
603                 if (pObj!=NULL && !pObj->IsEmptyPresObj())
604                     bDisable = false;
605             }
606         }
607 		if (bDisable)
608 			rSet.DisableItem (SID_SUMMARY_PAGE);
609 	}
610 
611 	// Starten der Praesentation moeglich?
612 	if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_PRESENTATION ) ||
613 		SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_REHEARSE_TIMINGS ) )
614 	{
615         sal_Bool bDisable = sal_True;
616         model::PageEnumeration aAllPages (
617             model::PageEnumerationProvider::CreateAllPagesEnumeration(mrSlideSorter.GetModel()));
618         while (aAllPages.HasMoreElements())
619         {
620             SdPage* pPage = aAllPages.GetNextElement()->GetPage();
621 
622             if( !pPage->IsExcluded() )
623                 bDisable = sal_False;
624 		}
625 		if( bDisable || pDocShell->IsPreview())
626 		{
627 			rSet.DisableItem( SID_PRESENTATION );
628 			rSet.DisableItem( SID_REHEARSE_TIMINGS );
629 		}
630 	}
631 
632 
633     // Disable the rename slots when there are no or more than one slides/master
634     // pages selected.
635     if (rSet.GetItemState(SID_RENAMEPAGE) == SFX_ITEM_AVAILABLE
636         || rSet.GetItemState(SID_RENAME_MASTER_PAGE)  == SFX_ITEM_AVAILABLE)
637     {
638         if (mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount() != 1)
639         {
640             rSet.DisableItem(SID_RENAMEPAGE);
641             rSet.DisableItem(SID_RENAME_MASTER_PAGE);
642         }
643     }
644 
645     if (rSet.GetItemState(SID_HIDE_SLIDE) == SFX_ITEM_AVAILABLE
646         || rSet.GetItemState(SID_SHOW_SLIDE)  == SFX_ITEM_AVAILABLE)
647     {
648         model::PageEnumeration aSelectedPages (
649             model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
650                 mrSlideSorter.GetModel()));
651         const SlideExclusionState eState (GetSlideExclusionState(aSelectedPages));
652         switch (eState)
653         {
654             case MIXED:
655                 // Show both entries.
656                 break;
657 
658             case EXCLUDED:
659                 rSet.DisableItem(SID_HIDE_SLIDE);
660                 break;
661 
662             case INCLUDED:
663                 rSet.DisableItem(SID_SHOW_SLIDE);
664                 break;
665 
666             case UNDEFINED:
667                 rSet.DisableItem(SID_HIDE_SLIDE);
668                 rSet.DisableItem(SID_SHOW_SLIDE);
669                 break;
670         }
671     }
672 
673 
674     PageKind ePageKind = mrSlideSorter.GetModel().GetPageType();
675 	if ((eEditMode == EM_MASTERPAGE) && (ePageKind != PK_HANDOUT))
676     {
677 		rSet.DisableItem(SID_ASSIGN_LAYOUT);
678 	}
679 
680 	if ((eEditMode == EM_MASTERPAGE) || (ePageKind==PK_NOTES))
681     {
682 		rSet.DisableItem(SID_INSERTPAGE);
683 	}
684 
685     // Disable some slots when in master page mode.
686     if (eEditMode == EM_MASTERPAGE)
687     {
688         if (rSet.GetItemState(SID_INSERTPAGE) == SFX_ITEM_AVAILABLE)
689             rSet.DisableItem(SID_INSERTPAGE);
690         if (rSet.GetItemState(SID_DUPLICATE_PAGE) == SFX_ITEM_AVAILABLE)
691             rSet.DisableItem(SID_DUPLICATE_PAGE);
692     }
693 }
694 
695 
696 
697 
GetClipboardState(SfxItemSet & rSet)698 void SlotManager::GetClipboardState ( SfxItemSet& rSet)
699 {
700 	SdTransferable* pTransferClip = SD_MOD()->pTransferClip;
701 
702     if (rSet.GetItemState(SID_PASTE)  == SFX_ITEM_AVAILABLE
703         || rSet.GetItemState(SID_PASTE_SPECIAL)  == SFX_ITEM_AVAILABLE)
704     {
705         // Keine eigenen Clipboard-Daten?
706         if ( !pTransferClip || !pTransferClip->GetDocShell() )
707         {
708             rSet.DisableItem(SID_PASTE);
709             rSet.DisableItem(SID_PASTE_SPECIAL);
710         }
711         else
712         {
713             SfxObjectShell* pTransferDocShell = pTransferClip->GetDocShell();
714 
715             if( !pTransferDocShell || ( (DrawDocShell*) pTransferDocShell)->GetDoc()->GetPageCount() <= 1 )
716             {
717                 bool bIsPastingSupported (false);
718 
719                 // No or just one page.  Check if there is anything that can be
720                 // pasted via a DrawViewShell.
721                 ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
722                 if (pBase != NULL)
723                 {
724                     ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
725                         ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
726                     if (pDrawViewShell.get() != NULL)
727                     {
728                         TransferableDataHelper aDataHelper (
729                             TransferableDataHelper::CreateFromSystemClipboard(
730                                 pDrawViewShell->GetActiveWindow()));
731                         if (aDataHelper.GetFormatCount() > 0)
732                             bIsPastingSupported = true;
733                     }
734                 }
735 
736                 if ( ! bIsPastingSupported)
737                 {
738                     rSet.DisableItem(SID_PASTE);
739                     rSet.DisableItem(SID_PASTE_SPECIAL);
740                 }
741             }
742         }
743 	}
744 
745     // Cut, copy and paste of master pages is not yet implemented properly
746 	if (rSet.GetItemState(SID_COPY) == SFX_ITEM_AVAILABLE
747         || rSet.GetItemState(SID_PASTE)  == SFX_ITEM_AVAILABLE
748         || rSet.GetItemState(SID_PASTE_SPECIAL)  == SFX_ITEM_AVAILABLE
749         || rSet.GetItemState(SID_CUT)  == SFX_ITEM_AVAILABLE)
750     {
751         if (mrSlideSorter.GetModel().GetEditMode() == EM_MASTERPAGE)
752         {
753             if (rSet.GetItemState(SID_CUT) == SFX_ITEM_AVAILABLE)
754                 rSet.DisableItem(SID_CUT);
755             if (rSet.GetItemState(SID_COPY) == SFX_ITEM_AVAILABLE)
756                 rSet.DisableItem(SID_COPY);
757             if (rSet.GetItemState(SID_PASTE) == SFX_ITEM_AVAILABLE)
758                 rSet.DisableItem(SID_PASTE);
759             if (rSet.GetItemState(SID_PASTE_SPECIAL) == SFX_ITEM_AVAILABLE)
760                 rSet.DisableItem(SID_PASTE_SPECIAL);
761         }
762     }
763 
764     // Cut, copy, and delete page are disabled when there is no selection.
765 	if (rSet.GetItemState(SID_CUT) == SFX_ITEM_AVAILABLE
766         || rSet.GetItemState(SID_COPY)  == SFX_ITEM_AVAILABLE
767         || rSet.GetItemState(SID_DELETE) == SFX_ITEM_AVAILABLE
768         || rSet.GetItemState(SID_DELETE_PAGE) == SFX_ITEM_AVAILABLE
769         || rSet.GetItemState(SID_DELETE_MASTER_PAGE) == SFX_ITEM_AVAILABLE)
770 	{
771         model::PageEnumeration aSelectedPages (
772             model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
773                 mrSlideSorter.GetModel()));
774 
775         // For copy to work we have to have at least one selected page.
776         if ( ! aSelectedPages.HasMoreElements())
777 			rSet.DisableItem(SID_COPY);
778 
779         bool bDisable = false;
780         // The operations that lead to the deletion of a page are valid if
781         // a) there is at least one selected page
782         // b) deleting the selected pages leaves at least one page in the
783         // document
784         // c) selected master pages must not be used by slides.
785 
786         // Test a).
787         if ( ! aSelectedPages.HasMoreElements())
788             bDisable = true;
789         // Test b): Count the number of selected pages.  It has to be less
790         // than the number of all pages.
791         else if (mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount()
792             >= mrSlideSorter.GetController().GetPageSelector().GetPageCount())
793             bDisable = true;
794         // Test c): Iterate over the selected pages and look for a master
795         // page that is used by at least one page.
796         else while (aSelectedPages.HasMoreElements())
797         {
798             SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
799             int nUseCount (mrSlideSorter.GetModel().GetDocument()
800                 ->GetMasterPageUserCount(pPage));
801             if (nUseCount > 0)
802             {
803                 bDisable = true;
804                 break;
805             }
806         }
807 
808 		if (bDisable)
809 		{
810 			rSet.DisableItem(SID_CUT);
811 			rSet.DisableItem(SID_DELETE_PAGE);
812 			rSet.DisableItem(SID_DELETE_MASTER_PAGE);
813 		}
814 	}
815 }
816 
817 
818 
819 
GetStatusBarState(SfxItemSet & rSet)820 void SlotManager::GetStatusBarState (SfxItemSet& rSet)
821 {
822 	// Seitenanzeige und Layout
823 	/*
824 	if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_PAGE ) ||
825 		SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_LAYOUT ) )
826 	*/
827 	SdPage* pPage	   = NULL;
828 	SdPage* pFirstPage = NULL;
829 	sal_uInt16	nFirstPage;
830 	sal_uInt16	nSelectedPages = (sal_uInt16)mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount();
831 	String aPageStr;
832     String aLayoutStr;
833 
834 	if (nSelectedPages > 0)
835         aPageStr = String(SdResId(STR_SD_PAGE));
836 
837 	if (nSelectedPages == 1)
838 	{
839         model::PageEnumeration aSelectedPages (
840             model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
841                 mrSlideSorter.GetModel()));
842         model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
843         if (pDescriptor)
844         {
845             pPage = pDescriptor->GetPage();
846             nFirstPage = pPage->GetPageNum()/2;
847             pFirstPage = pPage;
848 
849             aPageStr += sal_Unicode(' ');
850             aPageStr += String::CreateFromInt32( nFirstPage + 1 );
851             aPageStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
852             aPageStr += String::CreateFromInt32(
853                 mrSlideSorter.GetModel().GetPageCount());
854 
855             aLayoutStr = pFirstPage->GetLayoutName();
856             aLayoutStr.Erase( aLayoutStr.SearchAscii( SD_LT_SEPARATOR ) );
857         }
858 	}
859 
860 	rSet.Put( SfxStringItem( SID_STATUS_PAGE, aPageStr ) );
861 	rSet.Put( SfxStringItem( SID_STATUS_LAYOUT, aLayoutStr ) );
862 
863 	if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
864 	{
865         rSet.Put( SfxVoidItem( SID_ATTR_ZOOMSLIDER ) );
866     }
867 }
868 
ShowSlideShow(SfxRequest & rReq)869 void SlotManager::ShowSlideShow( SfxRequest& rReq)
870 {
871 	Reference< XPresentation2 > xPresentation( mrSlideSorter.GetModel().GetDocument()->getPresentation() );
872 	if( xPresentation.is() )
873 	{
874 		if( ( SID_REHEARSE_TIMINGS != rReq.GetSlot() ) )
875 			xPresentation->start();
876 		else
877 			xPresentation->rehearseTimings();
878 	}
879 }
880 
RenameSlide(void)881 void SlotManager::RenameSlide (void)
882 {
883     PageKind ePageKind = mrSlideSorter.GetModel().GetPageType();
884     View* pDrView = &mrSlideSorter.GetView();
885 
886     if (ePageKind==PK_STANDARD || ePageKind==PK_NOTES)
887     {
888         if ( pDrView->IsTextEdit() )
889         {
890             pDrView->SdrEndTextEdit();
891         }
892 
893         SdPage* pSelectedPage = NULL;
894         model::PageEnumeration aSelectedPages (
895             model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
896                 mrSlideSorter.GetModel()));
897         if (aSelectedPages.HasMoreElements())
898             pSelectedPage = aSelectedPages.GetNextElement()->GetPage();
899         if (pSelectedPage != NULL)
900         {
901             String aTitle( SdResId( STR_TITLE_RENAMESLIDE ) );
902             String aDescr( SdResId( STR_DESC_RENAMESLIDE ) );
903             String aPageName = pSelectedPage->GetName();
904 
905             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
906             DBG_ASSERT(pFact, "Dialogdiet fail!");
907             AbstractSvxNameDialog* aNameDlg = pFact->CreateSvxNameDialog(
908                 mrSlideSorter.GetContentWindow().get(),
909                 aPageName, aDescr);
910             DBG_ASSERT(aNameDlg, "Dialogdiet fail!");
911             aNameDlg->SetText( aTitle );
912             aNameDlg->SetCheckNameHdl( LINK( this, SlotManager, RenameSlideHdl ), true );
913             aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
914 
915             if( aNameDlg->Execute() == RET_OK )
916             {
917                 String aNewName;
918                 aNameDlg->GetName( aNewName );
919                 if( ! aNewName.Equals( aPageName ) )
920                 {
921 #ifdef DBG_UTIL
922                     bool bResult =
923 #endif
924 						RenameSlideFromDrawViewShell(
925 		                  pSelectedPage->GetPageNum()/2, aNewName );
926                     DBG_ASSERT( bResult, "Couldn't rename slide" );
927                 }
928             }
929             delete aNameDlg;
930 
931             // Tell the slide sorter about the name change (necessary for
932             // accessibility.)
933             mrSlideSorter.GetController().PageNameHasChanged(
934                 (pSelectedPage->GetPageNum()-1)/2, aPageName);
935         }
936     }
937 }
938 
IMPL_LINK(SlotManager,RenameSlideHdl,AbstractSvxNameDialog *,pDialog)939 IMPL_LINK(SlotManager, RenameSlideHdl, AbstractSvxNameDialog*, pDialog)
940 {
941     if( ! pDialog )
942         return 0;
943 
944     String aNewName;
945     pDialog->GetName( aNewName );
946 
947     model::SharedPageDescriptor pDescriptor (
948         mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
949     SdPage* pCurrentPage = NULL;
950     if (pDescriptor.get() != NULL)
951         pCurrentPage = pDescriptor->GetPage();
952 
953     return ( (pCurrentPage!=NULL && aNewName.Equals( pCurrentPage->GetName() ))
954         || (mrSlideSorter.GetViewShell()
955             && mrSlideSorter.GetViewShell()->GetDocSh()->IsNewPageNameValid( aNewName ) ));
956 }
957 
RenameSlideFromDrawViewShell(sal_uInt16 nPageId,const String & rName)958 bool SlotManager::RenameSlideFromDrawViewShell( sal_uInt16 nPageId, const String & rName  )
959 {
960     sal_Bool   bOutDummy;
961     SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
962     if( pDocument->GetPageByName( rName, bOutDummy ) != SDRPAGE_NOTFOUND )
963         return false;
964 
965     SdPage* pPageToRename = NULL;
966     PageKind ePageKind = mrSlideSorter.GetModel().GetPageType();
967 
968     ::svl::IUndoManager* pManager = pDocument->GetDocSh()->GetUndoManager();
969 
970     if( mrSlideSorter.GetModel().GetEditMode() == EM_PAGE )
971     {
972         model::SharedPageDescriptor pDescriptor (
973             mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
974         if (pDescriptor.get() != NULL)
975             pPageToRename = pDescriptor->GetPage();
976 
977         if (pPageToRename != NULL)
978         {
979             // Undo
980             SdPage* pUndoPage = pPageToRename;
981             SdrLayerAdmin &  rLayerAdmin = pDocument->GetLayerAdmin();
982             sal_uInt8 nBackground = rLayerAdmin.GetLayerID( String( SdResId( STR_LAYER_BCKGRND )), sal_False );
983             sal_uInt8 nBgObj = rLayerAdmin.GetLayerID( String( SdResId( STR_LAYER_BCKGRNDOBJ )), sal_False );
984             SetOfByte aVisibleLayers = pPageToRename->TRG_GetMasterPageVisibleLayers();
985 
986             // (#67720#)
987             ModifyPageUndoAction* pAction = new ModifyPageUndoAction(
988                 pDocument, pUndoPage, rName, pUndoPage->GetAutoLayout(),
989                 aVisibleLayers.IsSet( nBackground ),
990                 aVisibleLayers.IsSet( nBgObj ));
991             pManager->AddUndoAction( pAction );
992 
993             // rename
994             pPageToRename->SetName( rName );
995 
996             if( ePageKind == PK_STANDARD )
997             {
998                 // also rename notes-page
999                 SdPage* pNotesPage = pDocument->GetSdPage( nPageId, PK_NOTES );
1000                 if (pNotesPage != NULL)
1001                     pNotesPage->SetName (rName);
1002             }
1003         }
1004     }
1005     else
1006     {
1007         // rename MasterPage -> rename LayoutTemplate
1008         pPageToRename = pDocument->GetMasterSdPage( nPageId, ePageKind );
1009         if (pPageToRename != NULL)
1010 		{
1011 			const String aOldLayoutName( pPageToRename->GetLayoutName() );
1012 			pManager->AddUndoAction( new RenameLayoutTemplateUndoAction( pDocument, aOldLayoutName, rName ) );
1013 			pDocument->RenameLayoutTemplate( aOldLayoutName, rName );
1014 		}
1015     }
1016 
1017     bool bSuccess = pPageToRename!=NULL && ( sal_False != rName.Equals( pPageToRename->GetName()));
1018 
1019     if( bSuccess )
1020     {
1021         // user edited page names may be changed by the page so update control
1022         //        aTabControl.SetPageText( nPageId, rName );
1023 
1024         // set document to modified state
1025         pDocument->SetChanged( sal_True );
1026 
1027         // inform navigator about change
1028 		SfxBoolItem aItem( SID_NAVIGATOR_INIT, sal_True );
1029         if (mrSlideSorter.GetViewShell() != NULL)
1030             mrSlideSorter.GetViewShell()->GetDispatcher()->Execute(
1031                 SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
1032     }
1033 
1034     return bSuccess;
1035 }
1036 
1037 
1038 
1039 
1040 /** Insert a slide.  The insertion position depends on a) the selection and
1041     b) the mouse position when there is no selection.
1042 
1043     When there is a selection then insertion takes place after the last
1044     slide of the selection.  For this to work all but the last selected
1045     slide are deselected first.
1046 
1047     Otherwise, when there is no selection but the insertion marker is visible
1048     the slide is inserted at that position.  The slide before that marker is
1049     selected first.
1050 
1051     When both the selection and the insertion marker are not visible--can
1052     that happen?--the new slide is inserted after the last slide.
1053 */
InsertSlide(SfxRequest & rRequest)1054 void SlotManager::InsertSlide (SfxRequest& rRequest)
1055 {
1056     const sal_Int32 nInsertionIndex (GetInsertionPosition());
1057 
1058     PageSelector::BroadcastLock aBroadcastLock (mrSlideSorter);
1059 
1060     SdPage* pNewPage = NULL;
1061     if (mrSlideSorter.GetModel().GetEditMode() == EM_PAGE)
1062     {
1063         SlideSorterViewShell* pShell = dynamic_cast<SlideSorterViewShell*>(
1064             mrSlideSorter.GetViewShell());
1065         if (pShell != NULL)
1066         {
1067             pNewPage = pShell->CreateOrDuplicatePage (
1068                 rRequest,
1069                 mrSlideSorter.GetModel().GetPageType(),
1070                 nInsertionIndex>=0
1071                     ? mrSlideSorter.GetModel().GetPageDescriptor(nInsertionIndex)->GetPage()
1072                         : NULL);
1073         }
1074     }
1075     else
1076     {
1077         // Use the API to create a new page.
1078         SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
1079         Reference<drawing::XMasterPagesSupplier> xMasterPagesSupplier (
1080             pDocument->getUnoModel(), UNO_QUERY);
1081         if (xMasterPagesSupplier.is())
1082         {
1083             Reference<drawing::XDrawPages> xMasterPages (
1084                 xMasterPagesSupplier->getMasterPages());
1085             if (xMasterPages.is())
1086             {
1087                 xMasterPages->insertNewByIndex (nInsertionIndex+1);
1088 
1089                 // Create shapes for the default layout.
1090                 pNewPage = pDocument->GetMasterSdPage(
1091                     (sal_uInt16)(nInsertionIndex+1), PK_STANDARD);
1092                 pNewPage->CreateTitleAndLayout (sal_True,sal_True);
1093             }
1094         }
1095     }
1096     if (pNewPage == NULL)
1097         return;
1098 
1099     // When a new page has been inserted then select it, make it the
1100     // current page, and focus it.
1101     view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
1102     PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
1103     mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
1104     mrSlideSorter.GetController().GetPageSelector().SelectPage(pNewPage);
1105 }
1106 
1107 
1108 
1109 
DuplicateSelectedSlides(SfxRequest & rRequest)1110 void SlotManager::DuplicateSelectedSlides (SfxRequest& rRequest)
1111 {
1112     // Create a list of the pages that are to be duplicated.  The process of
1113     // duplication alters the selection.
1114     sal_Int32 nInsertPosition (0);
1115     ::std::vector<SdPage*> aPagesToDuplicate;
1116     model::PageEnumeration aSelectedPages (
1117         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(mrSlideSorter.GetModel()));
1118     while (aSelectedPages.HasMoreElements())
1119     {
1120         model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
1121         if (pDescriptor && pDescriptor->GetPage())
1122         {
1123             aPagesToDuplicate.push_back(pDescriptor->GetPage());
1124             nInsertPosition = pDescriptor->GetPage()->GetPageNum()+2;
1125         }
1126     }
1127 
1128     // Duplicate the pages in aPagesToDuplicate and collect the newly
1129     // created pages in aPagesToSelect.
1130 	const bool bUndo (aPagesToDuplicate.size()>1 && mrSlideSorter.GetView().IsUndoEnabled());
1131 	if (bUndo)
1132 		mrSlideSorter.GetView().BegUndo(String(SdResId(STR_INSERTPAGE)));
1133 
1134     ::std::vector<SdPage*> aPagesToSelect;
1135     for(::std::vector<SdPage*>::const_iterator
1136             iPage(aPagesToDuplicate.begin()),
1137             iEnd(aPagesToDuplicate.end());
1138         iPage!=iEnd;
1139         ++iPage, nInsertPosition+=2)
1140     {
1141         aPagesToSelect.push_back(
1142             mrSlideSorter.GetViewShell()->CreateOrDuplicatePage(
1143                 rRequest, PK_STANDARD, *iPage, nInsertPosition));
1144     }
1145     aPagesToDuplicate.clear();
1146 
1147     if (bUndo)
1148 		mrSlideSorter.GetView().EndUndo();
1149 
1150     // Set the selection to the pages in aPagesToSelect.
1151     PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
1152     rSelector.DeselectAllPages();
1153     ::std::for_each (
1154         aPagesToSelect.begin(),
1155         aPagesToSelect.end(),
1156         ::boost::bind(
1157             static_cast<void (PageSelector::*)(const SdPage*)>(&PageSelector::SelectPage),
1158             ::boost::ref(rSelector),
1159             _1));
1160 }
1161 
1162 
1163 
1164 
ExecuteCommandAsynchronously(::std::auto_ptr<Command> pCommand)1165 void SlotManager::ExecuteCommandAsynchronously (::std::auto_ptr<Command> pCommand)
1166 {
1167     // Ownership of command is (implicitely) transferred to the queue.
1168     maCommandQueue.push(pCommand.get());
1169     pCommand.release();
1170     Application::PostUserEvent(LINK(this,SlotManager,UserEventCallback));
1171 }
1172 
IMPL_LINK(SlotManager,UserEventCallback,void *,EMPTYARG)1173 IMPL_LINK(SlotManager, UserEventCallback, void*, EMPTYARG)
1174 {
1175     if ( ! maCommandQueue.empty())
1176     {
1177         Command* pCommand = maCommandQueue.front();
1178         maCommandQueue.pop();
1179 
1180         if (pCommand != NULL)
1181         {
1182             // The queue ownes the command that has just been removed from
1183             // it.  Therefore it is deleted after it has been executed.
1184             (*pCommand)();
1185             delete pCommand;
1186         }
1187     }
1188 
1189     return 1;
1190 }
1191 
1192 
1193 
1194 
ChangeSlideExclusionState(const model::SharedPageDescriptor & rpDescriptor,const bool bExcludeSlide)1195 void SlotManager::ChangeSlideExclusionState (
1196     const model::SharedPageDescriptor& rpDescriptor,
1197     const bool bExcludeSlide)
1198 {
1199     if (rpDescriptor)
1200     {
1201         mrSlideSorter.GetView().SetState(
1202             rpDescriptor,
1203             model::PageDescriptor::ST_Excluded,
1204             bExcludeSlide);
1205     }
1206     else
1207     {
1208         model::PageEnumeration aSelectedPages (
1209             model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
1210                 mrSlideSorter.GetModel()));
1211         while (aSelectedPages.HasMoreElements())
1212         {
1213             model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
1214             mrSlideSorter.GetView().SetState(
1215                 pDescriptor,
1216                 model::PageDescriptor::ST_Excluded,
1217                 bExcludeSlide);
1218         }
1219     }
1220 
1221 	SfxBindings& rBindings (mrSlideSorter.GetViewShell()->GetViewFrame()->GetBindings());
1222 	rBindings.Invalidate(SID_PRESENTATION);
1223 	rBindings.Invalidate(SID_REHEARSE_TIMINGS);
1224 	rBindings.Invalidate(SID_HIDE_SLIDE);
1225 	rBindings.Invalidate(SID_SHOW_SLIDE);
1226 	mrSlideSorter.GetModel().GetDocument()->SetChanged();
1227 }
1228 
1229 
1230 
1231 
GetInsertionPosition(void)1232 sal_Int32 SlotManager::GetInsertionPosition (void)
1233 {
1234     PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
1235 
1236     // The insertion indicator is preferred.  After all the user explicitly
1237     // used it to define the insertion position.
1238     if (mrSlideSorter.GetController().GetInsertionIndicatorHandler()->IsActive())
1239     {
1240         // Select the page before the insertion indicator.
1241         return mrSlideSorter.GetController().GetInsertionIndicatorHandler()->GetInsertionPageIndex()
1242             - 1;
1243     }
1244 
1245     // Is there a stored insertion position?
1246     else if (mrSlideSorter.GetController().GetSelectionManager()->GetInsertionPosition() >= 0)
1247     {
1248         return mrSlideSorter.GetController().GetSelectionManager()->GetInsertionPosition() - 1;
1249     }
1250 
1251     // Use the index of the last selected slide.
1252     else if (rSelector.GetSelectedPageCount() > 0)
1253     {
1254         for (int nIndex=rSelector.GetPageCount()-1; nIndex>=0; --nIndex)
1255             if (rSelector.IsPageSelected(nIndex))
1256                 return nIndex;
1257 
1258         // We should never get here.
1259         OSL_ASSERT(false);
1260         return rSelector.GetPageCount() - 1;
1261     }
1262 
1263     // Select the last page when there is at least one page.
1264     else if (rSelector.GetPageCount() > 0)
1265     {
1266         return rSelector.GetPageCount() - 1;
1267     }
1268 
1269     // Hope for the best that CreateOrDuplicatePage() can cope with an empty
1270     // selection.
1271     else
1272     {
1273         // We should never get here because there has to be at least one page.
1274         OSL_ASSERT(false);
1275         return -1;
1276     }
1277 }
1278 
1279 
1280 
1281 
NotifyEditModeChange(void)1282 void SlotManager::NotifyEditModeChange (void)
1283 {
1284 	SfxBindings& rBindings (mrSlideSorter.GetViewShell()->GetViewFrame()->GetBindings());
1285 	rBindings.Invalidate(SID_PRESENTATION);
1286 	rBindings.Invalidate(SID_INSERTPAGE);
1287 	rBindings.Invalidate(SID_DUPLICATE_PAGE);
1288 }
1289 
1290 
1291 
1292 
1293 //-----------------------------------------------------------------------------
1294 
1295 namespace {
1296 
1297 
1298 
GetSlideExclusionState(model::PageEnumeration & rPageSet)1299 SlideExclusionState GetSlideExclusionState (model::PageEnumeration& rPageSet)
1300 {
1301     SlideExclusionState eState (UNDEFINED);
1302 	sal_Bool bState;
1303 
1304     // Get toggle state of the selected pages.
1305     while (rPageSet.HasMoreElements() && eState!=MIXED)
1306     {
1307         bState = rPageSet.GetNextElement()->GetPage()->IsExcluded();
1308         switch (eState)
1309         {
1310             case UNDEFINED:
1311                 // Use the first selected page to set the inital value.
1312                 eState = bState ? EXCLUDED : INCLUDED;
1313                 break;
1314 
1315             case EXCLUDED:
1316                 // The pages before where all not part of the show,
1317                 // this one is.
1318                 if ( ! bState)
1319                     eState = MIXED;
1320                 break;
1321 
1322             case INCLUDED:
1323                 // The pages before where all part of the show,
1324                 // this one is not.
1325                 if (bState)
1326                     eState = MIXED;
1327                 break;
1328 
1329             case MIXED:
1330             default:
1331                 // No need to change anything.
1332                 break;
1333         }
1334     }
1335 
1336     return eState;
1337 }
1338 
1339 } // end of anonymous namespace
1340 
1341 } } } // end of namespace ::sd::slidesorter::controller
1342 
1343