merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / controller / SlideSorterController.cxx
blobc8355752cd2f0a824afd9c0c74369b22714e034e
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: SlideSorterController.cxx,v $
10 * $Revision: 1.45 $
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 "controller/SlideSorterController.hxx"
35 #include "SlideSorter.hxx"
36 #include "controller/SlsPageSelector.hxx"
37 #include "controller/SlsSelectionFunction.hxx"
38 #include "controller/SlsProperties.hxx"
39 #include "controller/SlsCurrentSlideManager.hxx"
40 #include "SlsListener.hxx"
41 #include "controller/SlsFocusManager.hxx"
42 #include "SlsSelectionCommand.hxx"
43 #include "controller/SlsAnimator.hxx"
44 #include "controller/SlsClipboard.hxx"
45 #include "controller/SlsScrollBarManager.hxx"
46 #include "controller/SlsPageObjectFactory.hxx"
47 #include "controller/SlsSelectionManager.hxx"
48 #include "controller/SlsSlotManager.hxx"
49 #include "model/SlideSorterModel.hxx"
50 #include "model/SlsPageEnumerationProvider.hxx"
51 #include "model/SlsPageDescriptor.hxx"
52 #include "view/SlideSorterView.hxx"
53 #include "view/SlsLayouter.hxx"
54 #include "view/SlsViewOverlay.hxx"
55 #include "view/SlsFontProvider.hxx"
56 #include "cache/SlsPageCache.hxx"
57 #include "cache/SlsPageCacheManager.hxx"
59 #include "drawdoc.hxx"
60 #include "DrawViewShell.hxx"
61 #include "TextLogger.hxx"
62 #include "ViewShellBase.hxx"
63 #include "Window.hxx"
64 #include "FrameView.hxx"
65 #include "DrawDocShell.hxx"
66 #include "sdpage.hxx"
67 #include "res_bmp.hrc"
68 #include "sdresid.hxx"
69 #include "strings.hrc"
70 #include "app.hrc"
71 #include "glob.hrc"
72 #include "sdmod.hxx"
73 #include "sdxfer.hxx"
74 #include "FrameView.hxx"
75 #include "ViewShellHint.hxx"
76 #include "AccessibleSlideSorterView.hxx"
77 #include "AccessibleSlideSorterObject.hxx"
79 #include <vcl/window.hxx>
80 #include <svx/svdopage.hxx>
81 #include <svx/svxids.hrc>
82 #include <svx/ruler.hxx>
83 #include <svx/zoomitem.hxx>
84 #include <svtools/tabbar.hxx>
85 #include <sfx2/request.hxx>
86 #include <sfx2/viewfrm.hxx>
87 #include <sfx2/dispatch.hxx>
88 #include <sfx2/topfrm.hxx>
89 #include <tools/link.hxx>
90 #include <vcl/svapp.hxx>
92 #include <com/sun/star/lang/XComponent.hpp>
93 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
94 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
95 #include <com/sun/star/drawing/XDrawPages.hpp>
96 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
99 using namespace ::com::sun::star;
100 using namespace ::com::sun::star::uno;
101 using namespace ::sd::slidesorter::model;
102 using namespace ::sd::slidesorter::view;
103 using namespace ::sd::slidesorter::controller;
105 namespace sd { namespace slidesorter { namespace controller {
108 SlideSorterController::SlideSorterController (SlideSorter& rSlideSorter)
109 : mrSlideSorter(rSlideSorter),
110 mrModel(mrSlideSorter.GetModel()),
111 mrView(mrSlideSorter.GetView()),
112 mpPageSelector(),
113 mpFocusManager(),
114 mpSlotManager(),
115 mpClipboard(),
116 mpScrollBarManager(),
117 mpCurrentSlideManager(),
118 mpSelectionManager(),
119 mpAnimator(new Animator(rSlideSorter)),
120 mpListener(),
121 mnModelChangeLockCount(0),
122 mbPreModelChangeDone(false),
123 mbPostModelChangePending(false),
124 maSelectionBeforeSwitch(),
125 mnCurrentPageBeforeSwitch(0),
126 mpEditModeChangeMasterPage(NULL),
127 maTotalWindowArea(),
128 mnPaintEntranceCount(0),
129 mbIsContextMenuOpen(false),
130 mpProperties(new Properties())
132 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
133 OSL_ASSERT(pWindow!=NULL);
134 if (pWindow != NULL)
136 // The whole background is painted by the view and controls.
137 ::Window* pParentWindow = pWindow->GetParent();
138 OSL_ASSERT(pParentWindow!=NULL);
139 pParentWindow->SetBackground (Wallpaper());
141 // Connect the view with the window that has been created by our base
142 // class.
143 pWindow->SetBackground (Wallpaper());
144 mrView.AddWindowToPaintView(pWindow);
145 mrView.SetActualWin(pWindow);
146 pWindow->SetCenterAllowed (false);
147 pWindow->SetViewSize (mrView.GetModelArea().GetSize());
148 pWindow->EnableRTL(FALSE);
150 // Reinitialize colors in Properties with window specific values.
151 mpProperties->SetBackgroundColor(
152 pWindow->GetSettings().GetStyleSettings().GetWindowColor());
153 mpProperties->SetTextColor(
154 pWindow->GetSettings().GetStyleSettings().GetWindowTextColor());
155 mpProperties->SetSelectionColor(
156 pWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
157 mpProperties->SetHighlightColor(
158 pWindow->GetSettings().GetStyleSettings().GetMenuHighlightColor());
165 void SlideSorterController::Init (void)
167 mrView.HandleModelChange();
169 mpCurrentSlideManager.reset(new CurrentSlideManager(mrSlideSorter));
170 mpPageSelector.reset(new PageSelector(mrSlideSorter));
171 mpFocusManager.reset(new FocusManager(mrSlideSorter));
172 mpSlotManager.reset(new SlotManager(mrSlideSorter));
173 mpClipboard.reset(new Clipboard(mrSlideSorter));
174 mpScrollBarManager.reset(new ScrollBarManager(mrSlideSorter));
175 mpSelectionManager.reset(new SelectionManager(mrSlideSorter));
177 mpScrollBarManager->LateInitialization();
179 // Create the selection function.
180 SfxRequest aRequest (
181 SID_OBJECT_SELECT,
183 mrModel.GetDocument()->GetItemPool());
184 mrSlideSorter.SetCurrentFunction(CreateSelectionFunction(aRequest));
186 mpListener = new Listener(mrSlideSorter);
188 mpPageSelector->UpdateAllPages();
189 GetSelectionManager()->SelectionHasChanged();
195 SlideSorterController::~SlideSorterController (void)
199 uno::Reference<lang::XComponent> xComponent (
200 static_cast<XWeak*>(mpListener.get()), uno::UNO_QUERY);
201 if (xComponent.is())
202 xComponent->dispose();
204 catch( uno::Exception& e )
206 (void)e;
207 DBG_ERROR( "sd::SlideSorterController::~SlideSorterController(), exception caught!" );
210 // dispose should have been called by now so that nothing is to be done
211 // to shut down cleanly.
217 SlideSorter& SlideSorterController::GetSlideSorter (void) const
219 return mrSlideSorter;
225 model::SharedPageDescriptor SlideSorterController::GetPageAt (
226 const Point& aPixelPosition)
228 sal_Int32 nHitPageIndex (mrView.GetPageIndexAtPoint(aPixelPosition));
229 model::SharedPageDescriptor pDescriptorAtPoint;
230 if (nHitPageIndex >= 0)
231 pDescriptorAtPoint = mrModel.GetPageDescriptor(nHitPageIndex);
233 return pDescriptorAtPoint;
239 model::SharedPageDescriptor SlideSorterController::GetFadePageAt (
240 const Point& aPixelPosition)
242 sal_Int32 nHitPageIndex (mrView.GetFadePageIndexAtPoint(aPixelPosition));
243 model::SharedPageDescriptor pDescriptorAtPoint;
244 if (nHitPageIndex >= 0)
245 pDescriptorAtPoint = mrModel.GetPageDescriptor(nHitPageIndex);
247 return pDescriptorAtPoint;
253 PageSelector& SlideSorterController::GetPageSelector (void)
255 OSL_ASSERT(mpPageSelector.get()!=NULL);
256 return *mpPageSelector.get();
262 FocusManager& SlideSorterController::GetFocusManager (void)
264 OSL_ASSERT(mpFocusManager.get()!=NULL);
265 return *mpFocusManager.get();
271 Clipboard& SlideSorterController::GetClipboard (void)
273 OSL_ASSERT(mpClipboard.get()!=NULL);
274 return *mpClipboard.get();
280 ScrollBarManager& SlideSorterController::GetScrollBarManager (void)
282 OSL_ASSERT(mpScrollBarManager.get()!=NULL);
283 return *mpScrollBarManager.get();
289 ::boost::shared_ptr<CurrentSlideManager> SlideSorterController::GetCurrentSlideManager (void) const
291 OSL_ASSERT(mpCurrentSlideManager.get()!=NULL);
292 return mpCurrentSlideManager;
298 ::boost::shared_ptr<SlotManager> SlideSorterController::GetSlotManager (void) const
300 OSL_ASSERT(mpSlotManager.get()!=NULL);
301 return mpSlotManager;
307 ::boost::shared_ptr<SelectionManager> SlideSorterController::GetSelectionManager (void) const
309 OSL_ASSERT(mpSelectionManager.get()!=NULL);
310 return mpSelectionManager;
316 void SlideSorterController::PrePaint()
318 // forward VCLs PrePaint window event to DrawingLayer
319 mrView.PrePaint();
325 void SlideSorterController::Paint (
326 const Rectangle& rBBox,
327 ::Window* pWindow)
329 // if (mnPaintEntranceCount == 0)
331 ++mnPaintEntranceCount;
335 if (GetSelectionManager()->IsMakeSelectionVisiblePending())
336 GetSelectionManager()->MakeSelectionVisible();
338 mrView.SetApplicationDocumentColor(GetProperties()->GetBackgroundColor());
339 mrView.CompleteRedraw(pWindow, Region(rBBox), 0);
341 catch (const Exception&)
343 // Ignore all exceptions.
346 --mnPaintEntranceCount;
353 void SlideSorterController::FuTemporary (SfxRequest& rRequest)
355 mpSlotManager->FuTemporary (rRequest);
361 void SlideSorterController::FuPermanent (SfxRequest &rRequest)
363 mpSlotManager->FuPermanent (rRequest);
369 void SlideSorterController::FuSupport (SfxRequest &rRequest)
371 mpSlotManager->FuSupport (rRequest);
377 bool SlideSorterController::Command (
378 const CommandEvent& rEvent,
379 ::sd::Window* pWindow)
381 bool bEventHasBeenHandled = false;
383 ViewShell* pViewShell = mrSlideSorter.GetViewShell();
385 switch (rEvent.GetCommand())
387 case COMMAND_CONTEXTMENU:
389 SdPage* pPage = NULL;
390 USHORT nPopupId;
392 model::PageEnumeration aSelectedPages (
393 PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
394 if (aSelectedPages.HasMoreElements())
395 pPage = aSelectedPages.GetNextElement()->GetPage();
397 // Choose the popup menu depending on a) the type of the main
398 // view shell, b) the edit mode, and c) on whether the selection
399 // is empty or not.
400 ViewShell::ShellType eMainViewShellType (ViewShell::ST_NONE);
401 ::boost::shared_ptr<ViewShell> pMainViewShell (
402 pViewShell->GetViewShellBase().GetMainViewShell());
403 if (pMainViewShell.get() != NULL)
404 eMainViewShellType = pMainViewShell->GetShellType();
405 switch (eMainViewShellType)
407 case ViewShell::ST_DRAW:
408 if (pPage != NULL)
409 nPopupId = RID_SLIDE_SORTER_DRAW_SEL_POPUP;
410 else
411 nPopupId = RID_SLIDE_SORTER_DRAW_NOSEL_POPUP;
412 break;
414 default:
415 if (mrModel.GetEditMode() == EM_PAGE)
416 if (pPage != NULL)
417 nPopupId = RID_SLIDE_SORTER_IMPRESS_SEL_POPUP;
418 else
419 nPopupId = RID_SLIDE_SORTER_IMPRESS_NOSEL_POPUP;
420 else
421 if (pPage != NULL)
422 nPopupId = RID_SLIDE_SORTER_MASTER_SEL_POPUP;
423 else
424 nPopupId = RID_SLIDE_SORTER_MASTER_NOSEL_POPUP;
427 if (pPage == NULL)
429 // When there is no selection, then we show the insertion
430 // indicator so that the user knows where a page insertion
431 // would take place.
432 mrView.GetOverlay().GetInsertionIndicatorOverlay().SetPosition(
433 pWindow->PixelToLogic(rEvent.GetMousePosPixel()));
434 mrView.GetOverlay().GetInsertionIndicatorOverlay().setVisible(true);
437 pWindow->ReleaseMouse();
438 if (rEvent.IsMouseEvent())
440 mbIsContextMenuOpen = true;
441 if (pViewShell != NULL)
443 SfxDispatcher* pDispatcher = pViewShell->GetDispatcher();
444 if (pDispatcher != NULL)
445 pDispatcher->ExecutePopup(SdResId(nPopupId));
448 else
450 // The event is not a mouse event. Use the center of the
451 // focused page as top left position of the context menu.
452 if (pPage != NULL)
454 model::SharedPageDescriptor pDescriptor (
455 GetFocusManager().GetFocusedPageDescriptor());
456 if (pDescriptor.get() != NULL)
458 Rectangle aBBox (mrView.GetPageBoundingBox (
459 pDescriptor,
460 view::SlideSorterView::CS_SCREEN,
461 view::SlideSorterView::BBT_SHAPE));
462 Point aPosition (aBBox.Center());
463 mbIsContextMenuOpen = true;
464 if (pViewShell != NULL)
465 pViewShell->GetViewFrame()->GetDispatcher()->ExecutePopup(
466 SdResId(nPopupId),
467 pWindow,
468 &aPosition);
472 mbIsContextMenuOpen = false;
473 if (pPage == NULL)
475 // Remember the position of the insertion indicator before
476 // it is hidden, so that a pending slide insertion slot call
477 // finds the right place to insert a new slide.
478 GetSelectionManager()->SetInsertionPosition(
479 mrView.GetOverlay().GetInsertionIndicatorOverlay().GetInsertionPageIndex());
480 mrView.GetOverlay().GetInsertionIndicatorOverlay().setVisible(false);
482 bEventHasBeenHandled = true;
484 break;
486 case COMMAND_WHEEL:
488 // We ignore zooming with control+mouse wheel.
489 const CommandWheelData* pData = rEvent.GetWheelData();
490 if (pData!=NULL && pData->IsMod1())
491 bEventHasBeenHandled = true;
493 break;
496 return bEventHasBeenHandled;
502 void SlideSorterController::LockModelChange (void)
504 mnModelChangeLockCount += 1;
510 void SlideSorterController::UnlockModelChange (void)
512 mnModelChangeLockCount -= 1;
513 if (mnModelChangeLockCount==0 && mbPostModelChangePending)
514 PostModelChange();
520 void SlideSorterController::PreModelChange (void)
522 // Prevent PreModelChange to execute more than once per model lock.
523 if (mbPostModelChangePending)
524 return;
525 mbPreModelChangeDone = true;
527 if (mrSlideSorter.GetViewShell() != NULL)
528 mrSlideSorter.GetViewShell()->Broadcast(
529 ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START));
531 mpPageSelector->PrepareModelChange();
532 GetCurrentSlideManager()->PrepareModelChange();
534 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
535 if (pWindow != NULL)
536 mrView.PreModelChange();
538 mbPostModelChangePending = true;
544 void SlideSorterController::PostModelChange (void)
546 mbPostModelChangePending = false;
547 mrModel.Resync();
549 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
550 if (pWindow != NULL)
552 GetCurrentSlideManager()->HandleModelChange();
554 mrView.PostModelChange ();
556 pWindow->SetViewOrigin (Point (0,0));
557 pWindow->SetViewSize (mrView.GetModelArea().GetSize());
559 // The visibility of the scroll bars may have to be changed. Then
560 // the size of the view has to change, too. Let Rearrange() handle
561 // that.
562 Rearrange();
565 mpPageSelector->HandleModelChange ();
567 if (mrSlideSorter.GetViewShell() != NULL)
568 mrSlideSorter.GetViewShell()->Broadcast(
569 ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END));
575 void SlideSorterController::HandleModelChange (void)
577 // Ignore this call when the document is not in a valid state, i.e. has
578 // not the same number of regular and notes pages.
579 bool bIsDocumentValid = (mrModel.GetDocument()->GetPageCount() % 2 == 1);
581 if (bIsDocumentValid)
583 ModelChangeLock aLock (*this);
584 PreModelChange();
591 IMPL_LINK(SlideSorterController, WindowEventHandler, VclWindowEvent*, pEvent)
593 if (pEvent != NULL)
595 ::Window* pWindow = pEvent->GetWindow();
596 ::sd::Window* pActiveWindow = mrSlideSorter.GetActiveWindow();
597 switch (pEvent->GetId())
599 case VCLEVENT_WINDOW_ACTIVATE:
600 case VCLEVENT_WINDOW_SHOW:
601 if (pActiveWindow != NULL && pWindow == pActiveWindow->GetParent())
602 mrView.RequestRepaint();
603 break;
605 case VCLEVENT_WINDOW_GETFOCUS:
606 if (pActiveWindow != NULL && pWindow == pActiveWindow)
607 GetFocusManager().ShowFocus();
608 break;
610 case VCLEVENT_WINDOW_LOSEFOCUS:
611 if (pActiveWindow != NULL && pWindow == pActiveWindow)
612 GetFocusManager().HideFocus();
613 break;
615 case VCLEVENT_APPLICATION_DATACHANGED:
617 // Invalidate the preview cache.
618 cache::PageCacheManager::Instance()->InvalidateAllCaches();
620 // Update the draw mode.
621 ULONG nDrawMode (Application::GetSettings().GetStyleSettings().GetHighContrastMode()
622 ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
623 : ViewShell::OUTPUT_DRAWMODE_COLOR);
624 if (mrSlideSorter.GetViewShell() != NULL)
625 mrSlideSorter.GetViewShell()->GetFrameView()->SetDrawMode(nDrawMode);
626 if (pActiveWindow != NULL)
627 pActiveWindow->SetDrawMode(nDrawMode);
628 mrView.HandleDrawModeChange();
630 // When the system font has changed a layout has to be done.
631 mrView.Resize();
632 FontProvider::Instance().Invalidate();
634 break;
636 default:
637 break;
641 return TRUE;
647 void SlideSorterController::GetCtrlState (SfxItemSet& rSet)
649 if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
651 // "Letzte Version" vom SFx en/disablen lassen
652 SfxViewFrame* pSlideViewFrame = SfxViewFrame::Current();
653 DBG_ASSERT(pSlideViewFrame!=NULL,
654 "SlideSorterController::GetCtrlState: ViewFrame not found");
655 if (pSlideViewFrame && pSlideViewFrame->ISA(SfxTopViewFrame))
657 pSlideViewFrame->GetSlotState (SID_RELOAD, NULL, &rSet);
659 else // MI sagt: kein MDIFrame --> disablen
661 rSet.DisableItem(SID_RELOAD);
665 // Output quality.
666 if (rSet.GetItemState(SID_OUTPUT_QUALITY_COLOR)==SFX_ITEM_AVAILABLE
667 ||rSet.GetItemState(SID_OUTPUT_QUALITY_GRAYSCALE)==SFX_ITEM_AVAILABLE
668 ||rSet.GetItemState(SID_OUTPUT_QUALITY_BLACKWHITE)==SFX_ITEM_AVAILABLE
669 ||rSet.GetItemState(SID_OUTPUT_QUALITY_CONTRAST)==SFX_ITEM_AVAILABLE)
671 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
672 if (pWindow != NULL)
674 ULONG nMode = pWindow->GetDrawMode();
675 UINT16 nQuality = 0;
677 switch (nMode)
679 case ViewShell::OUTPUT_DRAWMODE_COLOR:
680 nQuality = 0;
681 break;
682 case ViewShell::OUTPUT_DRAWMODE_GRAYSCALE:
683 nQuality = 1;
684 break;
685 case ViewShell::OUTPUT_DRAWMODE_BLACKWHITE:
686 nQuality = 2;
687 break;
688 case ViewShell::OUTPUT_DRAWMODE_CONTRAST:
689 nQuality = 3;
690 break;
693 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_COLOR,
694 (BOOL)(nQuality==0)));
695 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_GRAYSCALE,
696 (BOOL)(nQuality==1)));
697 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_BLACKWHITE,
698 (BOOL)(nQuality==2)));
699 rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_CONTRAST,
700 (BOOL)(nQuality==3)));
704 if (rSet.GetItemState(SID_MAIL_SCROLLBODY_PAGEDOWN) == SFX_ITEM_AVAILABLE)
706 rSet.Put (SfxBoolItem( SID_MAIL_SCROLLBODY_PAGEDOWN, TRUE));
713 void SlideSorterController::GetStatusBarState (SfxItemSet& rSet)
715 mpSlotManager->GetStatusBarState (rSet);
721 void SlideSorterController::ExecCtrl (SfxRequest& rRequest)
723 mpSlotManager->ExecCtrl (rRequest);
729 void SlideSorterController::GetAttrState (SfxItemSet& rSet)
731 mpSlotManager->GetAttrState (rSet);
737 void SlideSorterController::ExecStatusBar (SfxRequest& )
744 void SlideSorterController::UpdateAllPages (void)
746 // Do a redraw.
747 mrView.InvalidateAllWin();
753 Rectangle SlideSorterController::Resize (const Rectangle& rAvailableSpace)
755 Rectangle aContentArea (rAvailableSpace);
757 if (maTotalWindowArea != rAvailableSpace)
759 maTotalWindowArea = rAvailableSpace;
760 aContentArea = Rearrange(true);
763 return aContentArea;
769 Rectangle SlideSorterController::Rearrange (bool bForce)
771 Rectangle aNewContentArea (maTotalWindowArea);
773 ::boost::shared_ptr<sd::Window> pWindow = mrSlideSorter.GetContentWindow();
774 if (pWindow.get() != NULL)
776 // Place the scroll bars.
777 aNewContentArea = GetScrollBarManager().PlaceScrollBars(maTotalWindowArea);
779 bool bSizeHasChanged (false);
780 // Only when bForce is not true we have to test for a size change in
781 // order to determine whether the window and the view have to be resized.
782 if ( ! bForce)
784 Rectangle aCurrentContentArea (
785 pWindow->GetPosPixel(),
786 pWindow->GetOutputSizePixel());
787 bSizeHasChanged = (aNewContentArea != aCurrentContentArea);
789 if (bForce || bSizeHasChanged)
791 // The browser window gets the remaining space.
792 pWindow->SetPosSizePixel (aNewContentArea.TopLeft(), aNewContentArea.GetSize());
793 mrView.Resize();
796 // Adapt the scroll bars to the new zoom factor of the browser
797 // window and the arrangement of the page objects.
798 GetScrollBarManager().UpdateScrollBars(false, !bForce);
801 return aNewContentArea;
807 void SlideSorterController::SetZoom (long int nZoom)
809 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
810 long int nCurrentZoom ((long int)(
811 pWindow->GetMapMode().GetScaleX().operator double() * 100));
813 if (nZoom > nCurrentZoom)
815 Size aPageSize (mrView.GetPageBoundingBox(
817 view::SlideSorterView::CS_MODEL,
818 view::SlideSorterView::BBT_SHAPE).GetSize());
819 Size aWindowSize (pWindow->PixelToLogic(
820 pWindow->GetOutputSizePixel()));
822 // The zoom factor must not grow by more then the ratio of the
823 // widths of the output window and the page objects.
824 long nMaxFactor
825 = nCurrentZoom * aWindowSize.Width() / aPageSize.Width();
826 // Apply rounding, so that a current zoom factor of 1 is still
827 // increased.
828 nMaxFactor = (nCurrentZoom * 18 + 5) / 10;
829 nZoom = Min(nMaxFactor, nZoom);
831 if (nZoom < 1)
832 nZoom = 1;
834 mrView.LockRedraw (TRUE);
835 mrView.GetLayouter().SetZoom(nZoom/100.0, pWindow);
836 mrView.Layout();
837 GetScrollBarManager().UpdateScrollBars (false);
838 mrView.GetPreviewCache()->InvalidateCache();
839 mrView.RequestRepaint();
840 mrView.LockRedraw (FALSE);
843 ViewShell::SetZoom (nZoom);
844 GetViewFrame()->GetBindings().Invalidate (SID_ATTR_ZOOM);
851 FunctionReference SlideSorterController::CreateSelectionFunction (SfxRequest& rRequest)
853 FunctionReference xFunc( SelectionFunction::Create(mrSlideSorter, rRequest) );
854 return xFunc;
860 void SlideSorterController::PrepareEditModeChange (void)
862 // Before we throw away the page descriptors we prepare for selecting
863 // descriptors in the other mode and for restoring the current
864 // selection when switching back to the current mode.
865 if (mrModel.GetEditMode() == EM_PAGE)
867 maSelectionBeforeSwitch.clear();
869 // Search for the first selected page and determine the master page
870 // used by its page object. It will be selected after the switch.
871 // In the same loop the current selection is stored.
872 PageEnumeration aSelectedPages (
873 PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
874 while (aSelectedPages.HasMoreElements())
876 SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
877 SdPage* pPage = pDescriptor->GetPage();
878 // Remember the master page of the first selected descriptor.
879 if (pPage!=NULL && mpEditModeChangeMasterPage==NULL)
880 mpEditModeChangeMasterPage = &static_cast<SdPage&>(
881 pPage->TRG_GetMasterPage());
883 maSelectionBeforeSwitch.push_back(pPage);
886 // Remember the current page.
887 if (mrSlideSorter.GetViewShell() != NULL)
888 mnCurrentPageBeforeSwitch = (mrSlideSorter.GetViewShell()->GetViewShellBase()
889 .GetMainViewShell()->GetActualPage()->GetPageNum()-1)/2;
896 bool SlideSorterController::ChangeEditMode (EditMode eEditMode)
898 bool bResult (false);
899 if (mrModel.GetEditMode() != eEditMode)
901 ModelChangeLock aLock (*this);
902 PreModelChange();
903 // Do the actual edit mode switching.
904 bResult = mrModel.SetEditMode(eEditMode);
905 if (bResult)
906 HandleModelChange();
908 return bResult;
914 void SlideSorterController::FinishEditModeChange (void)
916 if (mrModel.GetEditMode() == EM_MASTERPAGE)
918 // Search for the master page that was determined in
919 // PrepareEditModeChange() and make it the current page.
920 PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
921 while (aAllPages.HasMoreElements())
923 SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
924 if (pDescriptor->GetPage() == mpEditModeChangeMasterPage)
926 GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
927 break;
931 else
933 SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnCurrentPageBeforeSwitch));
934 GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
936 // Restore the selection.
937 ::std::vector<SdPage*>::iterator iPage;
938 for (iPage=maSelectionBeforeSwitch.begin();
939 iPage!=maSelectionBeforeSwitch.end();
940 ++iPage)
942 mpPageSelector->SelectPage(*iPage);
944 maSelectionBeforeSwitch.clear( );
946 mpEditModeChangeMasterPage = NULL;
952 void SlideSorterController::PageNameHasChanged (int nPageIndex, const String& rsOldName)
954 // Request a repaint for the page object whose name has changed.
955 model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
956 if (pDescriptor.get() != NULL)
957 mrView.RequestRepaint(pDescriptor);
959 // Get a pointer to the corresponding accessible object and notify
960 // that of the name change.
963 ::sd::Window* pWindow = mrSlideSorter.GetActiveWindow();
964 if (pWindow == NULL)
965 break;
967 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
968 xAccessible (pWindow->GetAccessible(FALSE));
969 if ( ! xAccessible.is())
970 break;
972 // Now comes a small hack. We assume that the accessible object is
973 // an instantiation of AccessibleSlideSorterView and cast it to that
974 // class. The cleaner alternative to this cast would be a new member
975 // in which we would store the last AccessibleSlideSorterView object
976 // created by SlideSorterViewShell::CreateAccessibleDocumentView().
977 // But then there is no guaranty that the accessible object obtained
978 // from the window really is that instance last created by
979 // CreateAccessibleDocumentView().
980 // However, the dynamic cast together with the check of the result
981 // being NULL should be safe enough.
982 ::accessibility::AccessibleSlideSorterView* pAccessibleView
983 = dynamic_cast< ::accessibility::AccessibleSlideSorterView*>(xAccessible.get());
984 if (pAccessibleView == NULL)
985 break;
987 ::accessibility::AccessibleSlideSorterObject* pChild
988 = pAccessibleView->GetAccessibleChildImplementation(nPageIndex);
989 if (pChild == NULL || pChild->GetPage() == NULL)
990 break;
992 ::rtl::OUString sOldName (rsOldName);
993 ::rtl::OUString sNewName (pChild->GetPage()->GetName());
994 pChild->FireAccessibleEvent(
995 ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
996 makeAny(sOldName),
997 makeAny(sNewName));
999 while (false);
1005 bool SlideSorterController::IsContextMenuOpen (void) const
1007 return mbIsContextMenuOpen;
1013 ::boost::shared_ptr<Properties> SlideSorterController::GetProperties (void) const
1015 return mpProperties;
1021 void SlideSorterController::SetDocumentSlides (const Reference<container::XIndexAccess>& rxSlides)
1023 if (mrModel.GetDocumentSlides() != rxSlides)
1025 ModelChangeLock aLock (*this);
1026 PreModelChange();
1028 mrModel.SetDocumentSlides(rxSlides);
1029 mrView.Layout();
1036 ::boost::shared_ptr<Animator> SlideSorterController::GetAnimator (void) const
1038 return mpAnimator;
1044 //===== SlideSorterController::ModelChangeLock ================================
1046 SlideSorterController::ModelChangeLock::ModelChangeLock (
1047 SlideSorterController& rController)
1048 : mpController(&rController)
1050 mpController->LockModelChange();
1056 SlideSorterController::ModelChangeLock::~ModelChangeLock (void)
1058 Release();
1064 void SlideSorterController::ModelChangeLock::Release (void)
1066 if (mpController != NULL)
1068 mpController->UnlockModelChange();
1069 mpController = NULL;
1073 } } } // end of namespace ::sd::slidesorter