Update ooo320-m1
[ooovba.git] / sd / source / ui / slidesorter / controller / SlsSlotManager.cxx
bloba55e8a5c9b5fb23ed31568e4adc8663bf209ba9e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsSlotManager.cxx,v $
10 * $Revision: 1.34.52.3 $
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 #include "precompiled_sd.hxx"
33 #include <com/sun/star/presentation/XPresentation2.hpp>
35 #include "controller/SlsSlotManager.hxx"
36 #include "SlideSorter.hxx"
37 #include "SlideSorterViewShell.hxx"
38 #include "controller/SlideSorterController.hxx"
39 #include "controller/SlsPageSelector.hxx"
40 #include "controller/SlsClipboard.hxx"
41 #include "controller/SlsSelectionFunction.hxx"
42 #include "controller/SlsFocusManager.hxx"
43 #include "controller/SlsCurrentSlideManager.hxx"
44 #include "controller/SlsSelectionManager.hxx"
45 #include "SlsHideSlideFunction.hxx"
46 #include "SlsCommand.hxx"
47 #include "model/SlideSorterModel.hxx"
48 #include "model/SlsPageEnumerationProvider.hxx"
49 #include "model/SlsPageDescriptor.hxx"
50 #include "view/SlideSorterView.hxx"
51 #include "view/SlsLayouter.hxx"
52 #include "view/SlsViewOverlay.hxx"
53 #include "framework/FrameworkHelper.hxx"
54 #include "Window.hxx"
55 #include "fupoor.hxx"
56 #include "fuzoom.hxx"
57 #include "fucushow.hxx"
58 #include "fusldlg.hxx"
59 #include "fuexpand.hxx"
60 #include "fusumry.hxx"
61 #include "fuscale.hxx"
62 #include "slideshow.hxx"
63 #include "app.hrc"
64 #include "strings.hrc"
65 #include "sdresid.hxx"
66 #include "drawdoc.hxx"
67 #include "DrawDocShell.hxx"
68 #include "ViewShellBase.hxx"
69 #include "ViewShellImplementation.hxx"
70 #include "sdattr.hxx"
71 #include "TaskPaneViewShell.hxx"
72 #include "FrameView.hxx"
73 #include "zoomlist.hxx"
74 #include "sdpage.hxx"
75 #include "sdxfer.hxx"
76 #include "helpids.h"
77 #include "glob.hrc"
78 #include "unmodpg.hxx"
79 #include "DrawViewShell.hxx"
81 #include <sfx2/request.hxx>
82 #include <sfx2/viewfrm.hxx>
83 #include <sfx2/topfrm.hxx>
84 #include <sfx2/bindings.hxx>
85 #include <sfx2/dispatch.hxx>
86 #include <svx/svxids.hrc>
87 #include <svx/zoomitem.hxx>
88 #include <svx/svxdlg.hxx>
89 #include <svx/dialogs.hrc>
90 #include <vcl/msgbox.hxx>
91 #include <svtools/intitem.hxx>
92 #include <svtools/whiter.hxx>
93 #include <svtools/itempool.hxx>
94 #include <svtools/aeitem.hxx>
95 #include <com/sun/star/presentation/FadeEffect.hpp>
96 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
97 #include <com/sun/star/drawing/XDrawPages.hpp>
98 #include <vcl/svapp.hxx>
100 using namespace ::com::sun::star;
101 using namespace ::com::sun::star::uno;
102 using namespace ::com::sun::star::presentation;
104 namespace sd { namespace slidesorter { namespace controller {
106 SlotManager::SlotManager (SlideSorter& rSlideSorter)
107 : mrSlideSorter(rSlideSorter),
108 maCommandQueue()
115 SlotManager::~SlotManager (void)
122 void SlotManager::FuTemporary (SfxRequest& rRequest)
124 SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
126 SlideSorterViewShell* pShell
127 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
128 if (pShell == NULL)
129 return;
131 switch (rRequest.GetSlot())
133 case SID_PRESENTATION:
134 case SID_REHEARSE_TIMINGS:
135 ShowSlideShow (rRequest);
136 pShell->Cancel();
137 rRequest.Done();
138 break;
140 case SID_HIDE_SLIDE:
141 case SID_SHOW_SLIDE:
142 HideSlideFunction::Create(mrSlideSorter, rRequest);
143 break;
145 case SID_PAGES_PER_ROW:
146 if (rRequest.GetArgs() != NULL)
148 SFX_REQUEST_ARG(rRequest, pPagesPerRow, SfxUInt16Item,
149 SID_PAGES_PER_ROW, FALSE);
150 if (pPagesPerRow != NULL)
152 sal_Int32 nColumnCount = pPagesPerRow->GetValue();
153 // Force the given number of columns by setting the
154 // minimal and maximal number of columns to the same
155 // value.
156 mrSlideSorter.GetView().GetLayouter().SetColumnCount (
157 nColumnCount, nColumnCount);
158 // Force a repaint and re-layout.
159 pShell->ArrangeGUIElements ();
160 // Rearrange the UI-elements controlled by the
161 // controller and force a rearrangement of the view.
162 mrSlideSorter.GetController().Rearrange(true);
165 rRequest.Done();
166 break;
168 case SID_SELECTALL:
169 mrSlideSorter.GetController().GetPageSelector().SelectAllPages();
170 rRequest.Done();
171 break;
173 case SID_SLIDE_TRANSITIONS_PANEL:
175 // Make the slide transition panel visible (expand it) in the
176 // tool pane.
177 if (mrSlideSorter.GetViewShellBase() != NULL)
178 framework::FrameworkHelper::Instance(*mrSlideSorter.GetViewShellBase())
179 ->RequestTaskPanel(sd::framework::FrameworkHelper::msSlideTransitionTaskPanelURL);
180 rRequest.Ignore ();
181 break;
184 case SID_PRESENTATION_DLG:
185 FuSlideShowDlg::Create (
186 pShell,
187 mrSlideSorter.GetView().GetWindow(),
188 &mrSlideSorter.GetView(),
189 pDocument,
190 rRequest);
191 break;
193 case SID_CUSTOMSHOW_DLG:
194 FuCustomShowDlg::Create (
195 pShell,
196 mrSlideSorter.GetView().GetWindow(),
197 &mrSlideSorter.GetView(),
198 pDocument,
199 rRequest);
200 break;
202 case SID_EXPAND_PAGE:
203 FuExpandPage::Create (
204 pShell,
205 mrSlideSorter.GetView().GetWindow(),
206 &mrSlideSorter.GetView(),
207 pDocument,
208 rRequest);
209 break;
211 case SID_SUMMARY_PAGE:
212 FuSummaryPage::Create (
213 pShell,
214 mrSlideSorter.GetView().GetWindow(),
215 &mrSlideSorter.GetView(),
216 pDocument,
217 rRequest);
218 break;
220 case SID_INSERTPAGE:
221 case SID_INSERT_MASTER_PAGE:
222 InsertSlide(rRequest);
223 rRequest.Done();
224 break;
226 case SID_DELETE_PAGE:
227 case SID_DELETE_MASTER_PAGE:
228 case SID_DELETE: // we need SID_CUT to handle the delete key
229 // (DEL -> accelerator -> SID_CUT).
230 if (mrSlideSorter.GetModel().GetPageCount() > 1)
232 mrSlideSorter.GetController().GetSelectionManager()->DeleteSelectedPages();
235 rRequest.Done();
236 break;
238 case SID_RENAMEPAGE:
239 case SID_RENAME_MASTER_PAGE:
240 RenameSlide ();
241 rRequest.Done ();
242 break;
244 case SID_ASSIGN_LAYOUT:
246 SFX_REQUEST_ARG (rRequest, pWhatPage, SfxUInt32Item, ID_VAL_WHATPAGE, FALSE);
247 SFX_REQUEST_ARG (rRequest, pWhatLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, FALSE);
248 pShell->mpImpl->AssignLayout(
249 pDocument->GetSdPage((USHORT)pWhatPage->GetValue(),
250 mrSlideSorter.GetModel().GetPageType()),
251 (AutoLayout)pWhatLayout->GetValue());
252 rRequest.Done ();
254 break;
256 default:
257 break;
264 void SlotManager::FuPermanent (SfxRequest& rRequest)
266 ViewShell* pShell = mrSlideSorter.GetViewShell();
267 if (pShell == NULL)
268 return;
270 if(pShell->GetCurrentFunction().is())
272 FunctionReference xEmpty;
273 if (pShell->GetOldFunction() == pShell->GetCurrentFunction())
274 pShell->SetOldFunction(xEmpty);
276 pShell->GetCurrentFunction()->Deactivate();
277 pShell->SetCurrentFunction(xEmpty);
280 switch(rRequest.GetSlot())
282 case SID_OBJECT_SELECT:
283 pShell->SetCurrentFunction( SelectionFunction::Create(mrSlideSorter, rRequest) );
284 rRequest.Done();
285 break;
287 default:
288 break;
291 if(pShell->GetOldFunction().is())
293 pShell->GetOldFunction()->Deactivate();
294 FunctionReference xEmpty;
295 pShell->SetOldFunction(xEmpty);
298 if(pShell->GetCurrentFunction().is())
300 pShell->GetCurrentFunction()->Activate();
301 pShell->SetOldFunction(pShell->GetCurrentFunction());
304 //! das ist nur bis das ENUM-Slots sind
305 // Invalidate( SID_OBJECT_SELECT );
308 void SlotManager::FuSupport (SfxRequest& rRequest)
310 switch (rRequest.GetSlot())
312 case SID_STYLE_FAMILY:
313 if (rRequest.GetArgs() != NULL)
315 SdDrawDocument* pDocument
316 = mrSlideSorter.GetModel().GetDocument();
317 if (pDocument != NULL)
319 const SfxPoolItem& rItem (
320 rRequest.GetArgs()->Get(SID_STYLE_FAMILY));
321 pDocument->GetDocSh()->SetStyleFamily(
322 static_cast<const SfxUInt16Item&>(rItem).GetValue());
325 break;
327 case SID_PASTE:
329 SdTransferable* pTransferClip = SD_MOD()->pTransferClip;
330 if( pTransferClip )
332 SfxObjectShell* pTransferDocShell = pTransferClip->GetDocShell();
334 DrawDocShell* pDocShell = dynamic_cast<DrawDocShell*>(pTransferDocShell);
335 if (pDocShell && pDocShell->GetDoc()->GetPageCount() > 1)
337 mrSlideSorter.GetController().GetClipboard().HandleSlotCall(rRequest);
338 break;
341 ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
342 if (pBase != NULL)
344 ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
345 ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
346 if (pDrawViewShell.get() != NULL)
347 pDrawViewShell->FuSupport(rRequest);
350 break;
352 case SID_CUT:
353 case SID_COPY:
354 case SID_DELETE:
355 mrSlideSorter.GetController().GetClipboard().HandleSlotCall(rRequest);
356 break;
358 case SID_DRAWINGMODE:
359 case SID_NOTESMODE:
360 case SID_HANDOUTMODE:
361 case SID_DIAMODE:
362 case SID_OUTLINEMODE:
364 ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
365 if (pBase != NULL)
367 framework::FrameworkHelper::Instance(*pBase)->HandleModeChangeSlot(
368 rRequest.GetSlot(), rRequest);
369 rRequest.Done();
371 break;
374 case SID_UNDO :
376 SlideSorterViewShell* pViewShell
377 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
378 if (pViewShell != NULL)
379 pViewShell->ImpSidUndo (FALSE, rRequest);
380 break;
383 case SID_REDO :
385 SlideSorterViewShell* pViewShell
386 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
387 if (pViewShell != NULL)
388 pViewShell->ImpSidRedo (FALSE, rRequest);
389 break;
392 default:
393 break;
400 void SlotManager::ExecCtrl (SfxRequest& rRequest)
402 ViewShell* pViewShell = mrSlideSorter.GetViewShell();
403 USHORT nSlot = rRequest.GetSlot();
404 switch (nSlot)
406 case SID_RELOAD:
408 // Undo-Manager leeren
409 mrSlideSorter.GetModel().GetDocument()->GetDocSh()->ClearUndoBuffer();
411 // Normale Weiterleitung an ViewFrame zur Ausfuehrung
412 if (pViewShell != NULL)
413 pViewShell->GetViewFrame()->ExecuteSlot(rRequest);
415 // Muss sofort beendet werden
416 return;
419 case SID_OUTPUT_QUALITY_COLOR:
420 case SID_OUTPUT_QUALITY_GRAYSCALE:
421 case SID_OUTPUT_QUALITY_BLACKWHITE:
422 case SID_OUTPUT_QUALITY_CONTRAST:
424 // flush page cache
425 if (pViewShell != NULL)
426 pViewShell->ExecReq (rRequest);
427 break;
430 case SID_MAIL_SCROLLBODY_PAGEDOWN:
432 if (pViewShell != NULL)
433 pViewShell->ExecReq (rRequest);
434 break;
437 case SID_OPT_LOCALE_CHANGED:
439 mrSlideSorter.GetController().UpdateAllPages();
440 if (pViewShell != NULL)
441 pViewShell->UpdatePreview (pViewShell->GetActualPage());
442 rRequest.Done();
443 break;
446 case SID_SEARCH_DLG:
447 // We have to handle the SID_SEARCH_DLG slot explicitly because
448 // in some cases (when the slide sorter is displayed in the
449 // center pane) we want to disable the search dialog. Therefore
450 // we have to handle the execution of that slot as well.
451 // We try to do that by forwarding the request to the view frame
452 // of the view shell.
453 if (pViewShell != NULL)
454 pViewShell->GetViewFrame()->ExecuteSlot(rRequest);
455 break;
457 default:
458 break;
465 void SlotManager::GetAttrState (SfxItemSet& rSet)
467 // Iteratate over all items.
468 SfxWhichIter aIter (rSet);
469 USHORT nWhich = aIter.FirstWhich();
470 while (nWhich)
472 USHORT nSlotId (nWhich);
473 if (SfxItemPool::IsWhich(nWhich) && mrSlideSorter.GetViewShell()!=NULL)
474 nSlotId = mrSlideSorter.GetViewShell()->GetPool().GetSlotId(nWhich);
475 switch (nSlotId)
477 case SID_PAGES_PER_ROW:
478 rSet.Put (
479 SfxUInt16Item (
480 nSlotId,
481 (USHORT)mrSlideSorter.GetView().GetLayouter().GetColumnCount()
484 break;
486 nWhich = aIter.NextWhich();
493 void SlotManager::GetCtrlState (SfxItemSet& rSet)
495 if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
497 // "Letzte Version" vom SFx en/disablen lassen
498 ViewShell* pShell = mrSlideSorter.GetViewShell();
499 if (pShell != NULL)
501 SfxViewFrame* pSlideViewFrame = pShell->GetViewFrame();
502 DBG_ASSERT(pSlideViewFrame!=NULL,
503 "SlideSorterController::GetCtrlState: ViewFrame not found");
504 if (pSlideViewFrame->ISA(SfxTopViewFrame))
506 pSlideViewFrame->GetSlotState (SID_RELOAD, NULL, &rSet);
508 else // MI sagt: kein MDIFrame --> disablen
510 rSet.DisableItem(SID_RELOAD);
515 // Output quality.
516 if (rSet.GetItemState(SID_OUTPUT_QUALITY_COLOR)==SFX_ITEM_AVAILABLE
517 ||rSet.GetItemState(SID_OUTPUT_QUALITY_GRAYSCALE)==SFX_ITEM_AVAILABLE
518 ||rSet.GetItemState(SID_OUTPUT_QUALITY_BLACKWHITE)==SFX_ITEM_AVAILABLE
519 ||rSet.GetItemState(SID_OUTPUT_QUALITY_CONTRAST)==SFX_ITEM_AVAILABLE)
521 ULONG nMode = mrSlideSorter.GetView().GetWindow()->GetDrawMode();
522 UINT16 nQuality = 0;
524 switch (nMode)
526 case ::sd::ViewShell::OUTPUT_DRAWMODE_COLOR:
527 nQuality = 0;
528 break;
529 case ::sd::ViewShell::OUTPUT_DRAWMODE_GRAYSCALE:
530 nQuality = 1;
531 break;
532 case ::sd::ViewShell::OUTPUT_DRAWMODE_BLACKWHITE:
533 nQuality = 2;
534 break;
535 case ::sd::ViewShell::OUTPUT_DRAWMODE_CONTRAST:
536 nQuality = 3;
537 break;
540 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_COLOR,
541 (BOOL)(nQuality==0)));
542 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_GRAYSCALE,
543 (BOOL)(nQuality==1)));
544 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_BLACKWHITE,
545 (BOOL)(nQuality==2)));
546 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_CONTRAST,
547 (BOOL)(nQuality==3)));
550 if (rSet.GetItemState(SID_MAIL_SCROLLBODY_PAGEDOWN) == SFX_ITEM_AVAILABLE)
552 rSet.Put (SfxBoolItem( SID_MAIL_SCROLLBODY_PAGEDOWN, TRUE));
559 void SlotManager::GetMenuState ( SfxItemSet& rSet)
561 EditMode eEditMode = mrSlideSorter.GetModel().GetEditMode();
562 ViewShell* pShell = mrSlideSorter.GetViewShell();
563 DrawDocShell* pDocShell = mrSlideSorter.GetModel().GetDocument()->GetDocSh();
565 if (pShell!=NULL && pShell->GetCurrentFunction().is())
567 USHORT nSId = pShell->GetCurrentFunction()->GetSlotID();
569 rSet.Put( SfxBoolItem( nSId, TRUE ) );
571 rSet.Put( SfxBoolItem( SID_DRAWINGMODE, FALSE ) );
572 rSet.Put( SfxBoolItem( SID_DIAMODE, TRUE ) );
573 rSet.Put( SfxBoolItem( SID_OUTLINEMODE, FALSE ) );
574 rSet.Put( SfxBoolItem( SID_NOTESMODE, FALSE ) );
575 rSet.Put( SfxBoolItem( SID_HANDOUTMODE, FALSE ) );
577 // Vorlagenkatalog darf nicht aufgerufen werden
578 rSet.DisableItem(SID_STYLE_CATALOG);
580 if (pShell!=NULL && pShell->IsMainViewShell())
582 rSet.DisableItem(SID_SPELL_DIALOG);
583 rSet.DisableItem(SID_SEARCH_DLG);
586 if (SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_EXPAND_PAGE))
588 bool bDisable = true;
589 if (eEditMode == EM_PAGE)
591 // At least one of the selected pages has to contain an outline
592 // presentation objects in order to enable the expand page menu
593 // entry.
594 model::PageEnumeration aSelectedPages (
595 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
596 mrSlideSorter.GetModel()));
597 while (aSelectedPages.HasMoreElements())
599 SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
600 SdrObject* pObj = pPage->GetPresObj(PRESOBJ_OUTLINE);
601 if (pObj!=NULL && !pObj->IsEmptyPresObj())
602 bDisable = false;
606 if (bDisable)
607 rSet.DisableItem (SID_EXPAND_PAGE);
610 if (SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_SUMMARY_PAGE))
612 bool bDisable = true;
613 if (eEditMode == EM_PAGE)
615 // At least one of the selected pages has to contain a title
616 // presentation objects in order to enable the summary page menu
617 // entry.
618 model::PageEnumeration aSelectedPages (
619 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
620 mrSlideSorter.GetModel()));
621 while (aSelectedPages.HasMoreElements())
623 SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
624 SdrObject* pObj = pPage->GetPresObj(PRESOBJ_TITLE);
626 if (pObj!=NULL && !pObj->IsEmptyPresObj())
627 bDisable = false;
630 if (bDisable)
631 rSet.DisableItem (SID_SUMMARY_PAGE);
634 // Starten der Praesentation moeglich?
635 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_PRESENTATION ) ||
636 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_REHEARSE_TIMINGS ) )
638 BOOL bDisable = TRUE;
639 model::PageEnumeration aAllPages (
640 model::PageEnumerationProvider::CreateAllPagesEnumeration(mrSlideSorter.GetModel()));
641 while (aAllPages.HasMoreElements())
643 SdPage* pPage = aAllPages.GetNextElement()->GetPage();
645 if( !pPage->IsExcluded() )
646 bDisable = FALSE;
648 if( bDisable || pDocShell->IsPreview())
650 rSet.DisableItem( SID_PRESENTATION );
651 rSet.DisableItem( SID_REHEARSE_TIMINGS );
656 // Disable the rename slots when there are no or more than one slides/master
657 // pages selected.
658 if (rSet.GetItemState(SID_RENAMEPAGE) == SFX_ITEM_AVAILABLE
659 || rSet.GetItemState(SID_RENAME_MASTER_PAGE) == SFX_ITEM_AVAILABLE)
661 if (mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount() != 1)
663 rSet.DisableItem(SID_RENAMEPAGE);
664 rSet.DisableItem(SID_RENAME_MASTER_PAGE);
668 if (rSet.GetItemState(SID_HIDE_SLIDE) == SFX_ITEM_AVAILABLE
669 || rSet.GetItemState(SID_SHOW_SLIDE) == SFX_ITEM_AVAILABLE)
671 model::PageEnumeration aSelectedPages (
672 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
673 mrSlideSorter.GetModel()));
674 HideSlideFunction::ExclusionState eState (
675 HideSlideFunction::GetExclusionState(aSelectedPages));
676 switch (eState)
678 case HideSlideFunction::MIXED:
679 // Show both entries.
680 break;
682 case HideSlideFunction::EXCLUDED:
683 rSet.DisableItem(SID_HIDE_SLIDE);
684 break;
686 case HideSlideFunction::INCLUDED:
687 rSet.DisableItem(SID_SHOW_SLIDE);
688 break;
690 case HideSlideFunction::UNDEFINED:
691 rSet.DisableItem(SID_HIDE_SLIDE);
692 rSet.DisableItem(SID_SHOW_SLIDE);
693 break;
701 void SlotManager::GetClipboardState ( SfxItemSet& rSet)
703 SdTransferable* pTransferClip = SD_MOD()->pTransferClip;
705 if (rSet.GetItemState(SID_PASTE) == SFX_ITEM_AVAILABLE
706 || rSet.GetItemState(SID_PASTE_SPECIAL) == SFX_ITEM_AVAILABLE)
708 // Keine eigenen Clipboard-Daten?
709 if ( !pTransferClip || !pTransferClip->GetDocShell() )
711 rSet.DisableItem(SID_PASTE);
712 rSet.DisableItem(SID_PASTE_SPECIAL);
714 else
716 SfxObjectShell* pTransferDocShell = pTransferClip->GetDocShell();
718 if( !pTransferDocShell || ( (DrawDocShell*) pTransferDocShell)->GetDoc()->GetPageCount() <= 1 )
720 bool bIsPastingSupported (false);
722 // No or just one page. Check if there is anything that can be
723 // pasted via a DrawViewShell.
724 ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
725 if (pBase != NULL)
727 ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
728 ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
729 if (pDrawViewShell.get() != NULL)
731 TransferableDataHelper aDataHelper (
732 TransferableDataHelper::CreateFromSystemClipboard(
733 pDrawViewShell->GetActiveWindow()));
734 if (aDataHelper.GetFormatCount() > 0)
735 bIsPastingSupported = true;
739 if ( ! bIsPastingSupported)
741 rSet.DisableItem(SID_PASTE);
742 rSet.DisableItem(SID_PASTE_SPECIAL);
748 // Cut, copy and paste of master pages is not yet implemented properly
749 if (rSet.GetItemState(SID_COPY) == SFX_ITEM_AVAILABLE
750 || rSet.GetItemState(SID_PASTE) == SFX_ITEM_AVAILABLE
751 || rSet.GetItemState(SID_PASTE_SPECIAL) == SFX_ITEM_AVAILABLE
752 || rSet.GetItemState(SID_CUT) == SFX_ITEM_AVAILABLE)
754 if (mrSlideSorter.GetModel().GetEditMode() == EM_MASTERPAGE)
756 if (rSet.GetItemState(SID_CUT) == SFX_ITEM_AVAILABLE)
757 rSet.DisableItem(SID_CUT);
758 if (rSet.GetItemState(SID_COPY) == SFX_ITEM_AVAILABLE)
759 rSet.DisableItem(SID_COPY);
760 if (rSet.GetItemState(SID_PASTE) == SFX_ITEM_AVAILABLE)
761 rSet.DisableItem(SID_PASTE);
762 if (rSet.GetItemState(SID_PASTE_SPECIAL) == SFX_ITEM_AVAILABLE)
763 rSet.DisableItem(SID_PASTE_SPECIAL);
767 // Cut, copy, and delete page are disabled when there is no selection.
768 if (rSet.GetItemState(SID_CUT) == SFX_ITEM_AVAILABLE
769 || rSet.GetItemState(SID_COPY) == SFX_ITEM_AVAILABLE
770 || rSet.GetItemState(SID_DELETE) == SFX_ITEM_AVAILABLE
771 || rSet.GetItemState(SID_DELETE_PAGE) == SFX_ITEM_AVAILABLE
772 || rSet.GetItemState(SID_DELETE_MASTER_PAGE) == SFX_ITEM_AVAILABLE)
774 model::PageEnumeration aSelectedPages (
775 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
776 mrSlideSorter.GetModel()));
778 // For copy to work we have to have at least one selected page.
779 if ( ! aSelectedPages.HasMoreElements())
780 rSet.DisableItem(SID_COPY);
782 bool bDisable = false;
783 // The operations that lead to the deletion of a page are valid if
784 // a) there is at least one selected page
785 // b) deleting the selected pages leaves at least one page in the
786 // document
787 // c) selected master pages must not be used by slides.
789 // Test a).
790 if ( ! aSelectedPages.HasMoreElements())
791 bDisable = true;
792 // Test b): Count the number of selected pages. It has to be less
793 // than the number of all pages.
794 else if (mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount()
795 >= mrSlideSorter.GetController().GetPageSelector().GetPageCount())
796 bDisable = true;
797 // Test c): Iterate over the selected pages and look for a master
798 // page that is used by at least one page.
799 else while (aSelectedPages.HasMoreElements())
801 SdPage* pPage = aSelectedPages.GetNextElement()->GetPage();
802 int nUseCount (mrSlideSorter.GetModel().GetDocument()
803 ->GetMasterPageUserCount(pPage));
804 if (nUseCount > 0)
806 bDisable = true;
807 break;
811 if (bDisable)
813 rSet.DisableItem(SID_CUT);
814 rSet.DisableItem(SID_DELETE_PAGE);
815 rSet.DisableItem(SID_DELETE_MASTER_PAGE);
823 void SlotManager::GetStatusBarState (SfxItemSet& rSet)
825 // Seitenanzeige und Layout
827 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_PAGE ) ||
828 SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STATUS_LAYOUT ) )
830 SdPage* pPage = NULL;
831 SdPage* pFirstPage = NULL;
832 USHORT nFirstPage;
833 USHORT nSelectedPages = (USHORT)mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount();
834 String aPageStr;
835 String aLayoutStr;
837 if (nSelectedPages > 0)
838 aPageStr = String(SdResId(STR_SD_PAGE));
840 if (nSelectedPages == 1)
842 model::PageEnumeration aSelectedPages (
843 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
844 mrSlideSorter.GetModel()));
845 pPage = aSelectedPages.GetNextElement()->GetPage();
846 nFirstPage = pPage->GetPageNum()/2;
847 pFirstPage = pPage;
849 aPageStr += sal_Unicode(' ');
850 aPageStr += String::CreateFromInt32( nFirstPage + 1 );
851 aPageStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
852 aPageStr += String::CreateFromInt32(
853 mrSlideSorter.GetModel().GetPageCount());
855 aLayoutStr = pFirstPage->GetLayoutName();
856 aLayoutStr.Erase( aLayoutStr.SearchAscii( SD_LT_SEPARATOR ) );
859 rSet.Put( SfxStringItem( SID_STATUS_PAGE, aPageStr ) );
860 rSet.Put( SfxStringItem( SID_STATUS_LAYOUT, aLayoutStr ) );
862 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
864 rSet.Put( SfxVoidItem( SID_ATTR_ZOOMSLIDER ) );
868 void SlotManager::ShowSlideShow( SfxRequest& rReq)
870 Reference< XPresentation2 > xPresentation( mrSlideSorter.GetModel().GetDocument()->getPresentation() );
871 if( xPresentation.is() )
873 if( ( SID_REHEARSE_TIMINGS != rReq.GetSlot() ) )
874 xPresentation->start();
875 else
876 xPresentation->rehearseTimings();
880 void SlotManager::RenameSlide (void)
882 PageKind ePageKind = mrSlideSorter.GetModel().GetPageType();
883 View* pDrView = &mrSlideSorter.GetView();
885 if (ePageKind==PK_STANDARD || ePageKind==PK_NOTES)
887 if ( pDrView->IsTextEdit() )
889 pDrView->SdrEndTextEdit();
892 SdPage* pSelectedPage = NULL;
893 model::PageEnumeration aSelectedPages (
894 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
895 mrSlideSorter.GetModel()));
896 if (aSelectedPages.HasMoreElements())
897 pSelectedPage = aSelectedPages.GetNextElement()->GetPage();
898 if (pSelectedPage != NULL)
900 String aTitle( SdResId( STR_TITLE_RENAMESLIDE ) );
901 String aDescr( SdResId( STR_DESC_RENAMESLIDE ) );
902 String aPageName = pSelectedPage->GetName();
904 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
905 DBG_ASSERT(pFact, "Dialogdiet fail!");
906 AbstractSvxNameDialog* aNameDlg = pFact->CreateSvxNameDialog(
907 mrSlideSorter.GetActiveWindow(),
908 aPageName, aDescr, RID_SVXDLG_NAME);
909 DBG_ASSERT(aNameDlg, "Dialogdiet fail!");
910 aNameDlg->SetText( aTitle );
911 aNameDlg->SetCheckNameHdl( LINK( this, SlotManager, RenameSlideHdl ), true );
912 aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
914 if( aNameDlg->Execute() == RET_OK )
916 String aNewName;
917 aNameDlg->GetName( aNewName );
918 if( ! aNewName.Equals( aPageName ) )
920 #ifdef DBG_UTIL
921 bool bResult =
922 #endif
923 RenameSlideFromDrawViewShell(
924 pSelectedPage->GetPageNum()/2, aNewName );
925 DBG_ASSERT( bResult, "Couldn't rename slide" );
928 delete aNameDlg;
930 // Tell the slide sorter about the name change (necessary for
931 // accessibility.)
932 mrSlideSorter.GetController().PageNameHasChanged(
933 (pSelectedPage->GetPageNum()-1)/2, aPageName);
938 IMPL_LINK(SlotManager, RenameSlideHdl, AbstractSvxNameDialog*, pDialog)
940 if( ! pDialog )
941 return 0;
943 String aNewName;
944 pDialog->GetName( aNewName );
946 model::SharedPageDescriptor pDescriptor (
947 mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
948 SdPage* pCurrentPage = NULL;
949 if (pDescriptor.get() != NULL)
950 pCurrentPage = pDescriptor->GetPage();
952 return ( (pCurrentPage!=NULL && aNewName.Equals( pCurrentPage->GetName() ))
953 || (mrSlideSorter.GetViewShell()
954 && mrSlideSorter.GetViewShell()->GetDocSh()->IsNewPageNameValid( aNewName ) ));
957 bool SlotManager::RenameSlideFromDrawViewShell( USHORT nPageId, const String & rName )
959 BOOL bOutDummy;
960 SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
961 if( pDocument->GetPageByName( rName, bOutDummy ) != SDRPAGE_NOTFOUND )
962 return false;
964 SdPage* pPageToRename = NULL;
965 PageKind ePageKind = mrSlideSorter.GetModel().GetPageType();
967 SfxUndoManager* pManager = pDocument->GetDocSh()->GetUndoManager();
969 if( mrSlideSorter.GetModel().GetEditMode() == EM_PAGE )
971 model::SharedPageDescriptor pDescriptor (
972 mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
973 if (pDescriptor.get() != NULL)
974 pPageToRename = pDescriptor->GetPage();
976 if (pPageToRename != NULL)
978 // Undo
979 SdPage* pUndoPage = pPageToRename;
980 SdrLayerAdmin & rLayerAdmin = pDocument->GetLayerAdmin();
981 BYTE nBackground = rLayerAdmin.GetLayerID( String( SdResId( STR_LAYER_BCKGRND )), FALSE );
982 BYTE nBgObj = rLayerAdmin.GetLayerID( String( SdResId( STR_LAYER_BCKGRNDOBJ )), FALSE );
983 SetOfByte aVisibleLayers = pPageToRename->TRG_GetMasterPageVisibleLayers();
985 // (#67720#)
986 ModifyPageUndoAction* pAction = new ModifyPageUndoAction(
987 pManager, pDocument, pUndoPage, rName, pUndoPage->GetAutoLayout(),
988 aVisibleLayers.IsSet( nBackground ),
989 aVisibleLayers.IsSet( nBgObj ));
990 pManager->AddUndoAction( pAction );
992 // rename
993 pPageToRename->SetName( rName );
995 if( ePageKind == PK_STANDARD )
997 // also rename notes-page
998 SdPage* pNotesPage = pDocument->GetSdPage( nPageId, PK_NOTES );
999 if (pNotesPage != NULL)
1000 pNotesPage->SetName (rName);
1004 else
1006 // rename MasterPage -> rename LayoutTemplate
1007 pPageToRename = pDocument->GetMasterSdPage( nPageId, ePageKind );
1008 if (pPageToRename != NULL)
1010 const String aOldLayoutName( pPageToRename->GetLayoutName() );
1011 pManager->AddUndoAction( new RenameLayoutTemplateUndoAction( pDocument, aOldLayoutName, rName ) );
1012 pDocument->RenameLayoutTemplate( aOldLayoutName, rName );
1016 bool bSuccess = pPageToRename!=NULL && ( FALSE != rName.Equals( pPageToRename->GetName()));
1018 if( bSuccess )
1020 // user edited page names may be changed by the page so update control
1021 // aTabControl.SetPageText( nPageId, rName );
1023 // set document to modified state
1024 pDocument->SetChanged( TRUE );
1026 // inform navigator about change
1027 SfxBoolItem aItem( SID_NAVIGATOR_INIT, TRUE );
1028 if (mrSlideSorter.GetViewShell() != NULL)
1029 mrSlideSorter.GetViewShell()->GetDispatcher()->Execute(
1030 SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );
1033 return bSuccess;
1039 /** Insert a slide. The insertion position depends on a) the selection and
1040 b) the mouse position when there is no selection.
1042 When there is a selection then insertion takes place after the last
1043 slide of the selection. For this to work all but the last selected
1044 slide are deselected first.
1046 Otherwise, when there is no selection but the insertion marker is visible
1047 the slide is inserted at that position. The slide before that marker is
1048 selected first.
1050 When both the selection and the insertion marker are not visible--can
1051 that happen?--the new slide is inserted after the last slide.
1053 void SlotManager::InsertSlide (SfxRequest& rRequest)
1055 PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
1056 // The fallback insertion position is after the last slide.
1057 sal_Int32 nInsertionIndex (rSelector.GetPageCount() - 1);
1058 if (rSelector.GetSelectedPageCount() > 0)
1060 // Deselect all but the last selected slide.
1061 bool bLastSelectedSlideSeen (false);
1062 for (int nIndex=rSelector.GetPageCount()-1; nIndex>=0; --nIndex)
1064 if (rSelector.IsPageSelected(nIndex))
1066 if (bLastSelectedSlideSeen)
1067 rSelector.DeselectPage (nIndex);
1068 else
1070 nInsertionIndex = nIndex;
1071 bLastSelectedSlideSeen = true;
1077 // No selection. Is there an insertion indicator?
1078 else if (mrSlideSorter.GetView().GetOverlay()
1079 .GetInsertionIndicatorOverlay().isVisible())
1081 // Select the page before the insertion indicator.
1082 nInsertionIndex = mrSlideSorter.GetView().GetOverlay()
1083 .GetInsertionIndicatorOverlay().GetInsertionPageIndex();
1084 nInsertionIndex --;
1085 rSelector.SelectPage (nInsertionIndex);
1088 // Select the last page when there is at least one page.
1089 else if (rSelector.GetPageCount() > 0)
1091 nInsertionIndex = rSelector.GetPageCount() - 1;
1092 rSelector.SelectPage (nInsertionIndex);
1095 // Hope for the best that CreateOrDuplicatePage() can cope with an empty
1096 // selection.
1097 else
1099 nInsertionIndex = -1;
1102 USHORT nPageCount ((USHORT)mrSlideSorter.GetModel().GetPageCount());
1104 rSelector.DisableBroadcasting();
1105 // In order for SlideSorterController::GetActualPage() to select the
1106 // selected page as current page we have to turn off the focus
1107 // temporarily.
1109 FocusManager::FocusHider aTemporaryFocusHider (
1110 mrSlideSorter.GetController().GetFocusManager());
1112 SdPage* pPreviousPage = NULL;
1113 if (nInsertionIndex >= 0)
1114 pPreviousPage = mrSlideSorter.GetModel()
1115 .GetPageDescriptor(nInsertionIndex)->GetPage();
1117 if (mrSlideSorter.GetModel().GetEditMode() == EM_PAGE)
1119 SlideSorterViewShell* pShell = dynamic_cast<SlideSorterViewShell*>(
1120 mrSlideSorter.GetViewShell());
1121 if (pShell != NULL)
1123 pShell->CreateOrDuplicatePage (
1124 rRequest,
1125 mrSlideSorter.GetModel().GetPageType(),
1126 pPreviousPage);
1129 else
1131 // Use the API to create a new page.
1132 SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
1133 Reference<drawing::XMasterPagesSupplier> xMasterPagesSupplier (
1134 pDocument->getUnoModel(), UNO_QUERY);
1135 if (xMasterPagesSupplier.is())
1137 Reference<drawing::XDrawPages> xMasterPages (
1138 xMasterPagesSupplier->getMasterPages());
1139 if (xMasterPages.is())
1141 xMasterPages->insertNewByIndex (nInsertionIndex+1);
1143 // Create shapes for the default layout.
1144 SdPage* pMasterPage = pDocument->GetMasterSdPage(
1145 (USHORT)(nInsertionIndex+1), PK_STANDARD);
1146 pMasterPage->CreateTitleAndLayout (TRUE,TRUE);
1152 // When a new page has been inserted then select it and make it the
1153 // current page.
1154 mrSlideSorter.GetView().LockRedraw(TRUE);
1155 if (mrSlideSorter.GetModel().GetPageCount() > nPageCount)
1157 nInsertionIndex++;
1158 model::SharedPageDescriptor pDescriptor = mrSlideSorter.GetModel().GetPageDescriptor(nInsertionIndex);
1159 if (pDescriptor.get() != NULL)
1160 mrSlideSorter.GetController().GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
1162 rSelector.EnableBroadcasting();
1163 mrSlideSorter.GetView().LockRedraw(FALSE);
1169 void SlotManager::AssignTransitionEffect (void)
1171 model::SlideSorterModel& rModel (mrSlideSorter.GetModel());
1173 // We have to manually select the pages in the document that are
1174 // selected in the slide sorter.
1175 rModel.SynchronizeDocumentSelection();
1177 // #i34011#: Needs review, AF's bugfix is removed here
1178 //rShell.AssignFromSlideChangeWindow(rModel.GetEditMode());
1180 // We have to remove the selection of master pages to not confuse the
1181 // model.
1182 if (rModel.GetEditMode() == EM_MASTERPAGE)
1184 SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument();
1185 USHORT nMasterPageCount = pDocument->GetMasterSdPageCount(PK_STANDARD);
1186 for (USHORT nIndex=0; nIndex<nMasterPageCount; nIndex++)
1188 SdPage* pPage = pDocument->GetMasterSdPage(nIndex, PK_STANDARD);
1189 if (pPage != NULL)
1190 pPage->SetSelected (FALSE);
1198 void SlotManager::ExecuteCommandAsynchronously (::std::auto_ptr<Command> pCommand)
1200 // Ownership of command is (implicitely) transferred to the queue.
1201 maCommandQueue.push(pCommand.get());
1202 pCommand.release();
1203 Application::PostUserEvent(LINK(this,SlotManager,UserEventCallback));
1206 IMPL_LINK(SlotManager, UserEventCallback, void*, EMPTYARG)
1208 if ( ! maCommandQueue.empty())
1210 Command* pCommand = maCommandQueue.front();
1211 maCommandQueue.pop();
1213 if (pCommand != NULL)
1215 // The queue ownes the command that has just been removed from
1216 // it. Therefore it is deleted after it has been executed.
1217 (*pCommand)();
1218 delete pCommand;
1222 return 1;
1225 } } } // end of namespace ::sd::slidesorter::controller