merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / shell / SlideSorterViewShell.cxx
blob1559d536cf823571f0c6b3cc8c141b99dc344662
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: SlideSorterViewShell.cxx,v $
10 * $Revision: 1.32.70.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 "SlideSorterViewShell.hxx"
34 #include "ViewShellImplementation.hxx"
36 #include "SlideSorter.hxx"
37 #include "controller/SlideSorterController.hxx"
38 #include "controller/SlsClipboard.hxx"
39 #include "controller/SlsFocusManager.hxx"
40 #include "controller/SlsScrollBarManager.hxx"
41 #include "controller/SlsPageSelector.hxx"
42 #include "controller/SlsSlotManager.hxx"
43 #include "controller/SlsCurrentSlideManager.hxx"
44 #include "controller/SlsSelectionManager.hxx"
45 #include "view/SlideSorterView.hxx"
46 #include "view/SlsLayouter.hxx"
47 #include "model/SlideSorterModel.hxx"
48 #include "model/SlsPageEnumeration.hxx"
49 #include "model/SlsPageDescriptor.hxx"
50 #include "framework/FrameworkHelper.hxx"
51 #include "ViewShellBase.hxx"
52 #include "drawdoc.hxx"
53 #include "app.hrc"
54 #include "glob.hrc"
55 #include "sdattr.hrc"
56 #include "sdresid.hxx"
57 #include "AccessibleSlideSorterView.hxx"
58 #include "DrawDocShell.hxx"
59 #include "FrameView.hxx"
60 #include "SdUnoSlideView.hxx"
61 #include "ViewShellManager.hxx"
62 #include "Window.hxx"
63 #include <sfx2/app.hxx>
64 #include <sfx2/msg.hxx>
65 #include <sfx2/objface.hxx>
66 #include <sfx2/viewfrm.hxx>
67 #include <sfx2/bindings.hxx>
68 #include <sfx2/dispatch.hxx>
69 #include <sfx2/request.hxx>
70 #include <svx/svxids.hrc>
71 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
72 #include <com/sun/star/drawing/framework/ResourceId.hpp>
73 #include <cppuhelper/bootstrap.hxx>
74 #include <comphelper/processfactory.hxx>
76 using namespace ::sd::slidesorter;
77 #define SlideSorterViewShell
78 #include "sdslots.hxx"
80 using namespace ::com::sun::star;
81 using namespace ::com::sun::star::uno;
82 using namespace ::com::sun::star::drawing::framework;
84 using ::sd::framework::FrameworkHelper;
86 namespace sd { namespace slidesorter {
89 SFX_IMPL_INTERFACE(SlideSorterViewShell, SfxShell, SdResId(STR_SLIDESORTERVIEWSHELL))
95 TYPEINIT1(SlideSorterViewShell, ViewShell);
99 ::boost::shared_ptr<SlideSorterViewShell> SlideSorterViewShell::Create (
100 SfxViewFrame* pFrame,
101 ViewShellBase& rViewShellBase,
102 ::Window* pParentWindow,
103 FrameView* pFrameViewArgument)
105 ::boost::shared_ptr<SlideSorterViewShell> pViewShell;
108 pViewShell.reset(
109 new SlideSorterViewShell(pFrame,rViewShellBase,pParentWindow,pFrameViewArgument));
110 pViewShell->Initialize();
111 if (pViewShell->mpSlideSorter.get() == NULL)
112 pViewShell.reset();
114 catch(Exception&)
116 pViewShell.reset();
118 return pViewShell;
124 SlideSorterViewShell::SlideSorterViewShell (
125 SfxViewFrame* pFrame,
126 ViewShellBase& rViewShellBase,
127 ::Window* pParentWindow,
128 FrameView* pFrameViewArgument)
129 : ViewShell (pFrame, pParentWindow, rViewShellBase),
130 mpSlideSorter()
132 meShellType = ST_SLIDE_SORTER;
134 SetPool( &GetDoc()->GetPool() );
135 SetUndoManager( GetDoc()->GetDocSh()->GetUndoManager() );
137 if (pFrameViewArgument != NULL)
138 mpFrameView = pFrameViewArgument;
139 else
140 mpFrameView = new FrameView(GetDoc());
141 GetFrameView()->Connect();
143 SetName (String (RTL_CONSTASCII_USTRINGPARAM("SlideSorterViewShell")));
145 pParentWindow->SetStyle(pParentWindow->GetStyle() | WB_DIALOGCONTROL);
151 SlideSorterViewShell::~SlideSorterViewShell (void)
153 DisposeFunctions();
157 ::sd::Window* pWindow = GetActiveWindow();
158 if (pWindow!=NULL)
160 ::com::sun::star::uno::Reference<
161 ::com::sun::star::lang::XComponent> xComponent (
162 pWindow->GetAccessible(false),
163 ::com::sun::star::uno::UNO_QUERY);
164 if (xComponent.is())
165 xComponent->dispose();
168 catch( ::com::sun::star::uno::Exception& e )
170 (void)e;
171 DBG_ERROR("sd::SlideSorterViewShell::~SlideSorterViewShell(), exception caught!" );
179 void SlideSorterViewShell::Initialize (void)
181 mpSlideSorter = SlideSorter::CreateSlideSorter(
182 *this,
183 mpContentWindow,
184 mpHorizontalScrollBar,
185 mpVerticalScrollBar,
186 mpScrollBarBox);
187 mpView = &mpSlideSorter->GetView();
189 // For accessibility we have to shortly hide the content window.
190 // This triggers the construction of a new accessibility object for
191 // the new view shell. (One is created earlier while the construtor
192 // of the base class is executed. At that time the correct
193 // accessibility object can not be constructed.)
194 ::Window* pWindow = mpSlideSorter->GetActiveWindow();
195 if (pWindow != NULL)
197 pWindow->Hide();
198 pWindow->Show();
205 void SlideSorterViewShell::Init (bool bIsMainViewShell)
207 ViewShell::Init(bIsMainViewShell);
209 mpSlideSorter->GetModel().UpdatePageList();
211 if (mpContentWindow.get() != NULL)
212 mpContentWindow->SetViewShell(this);
218 SlideSorterViewShell* SlideSorterViewShell::GetSlideSorter (ViewShellBase& rBase)
220 SlideSorterViewShell* pViewShell = NULL;
222 // Test the center, left, and then the right pane for showing a slide sorter.
223 ::rtl::OUString aPaneURLs[] = {
224 FrameworkHelper::msCenterPaneURL,
225 FrameworkHelper::msFullScreenPaneURL,
226 FrameworkHelper::msLeftImpressPaneURL,
227 FrameworkHelper::msRightPaneURL,
228 ::rtl::OUString()};
232 ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (FrameworkHelper::Instance(rBase));
233 if (pFrameworkHelper->IsValid())
234 for (int i=0; pViewShell==NULL && aPaneURLs[i].getLength()>0; ++i)
236 pViewShell = dynamic_cast<SlideSorterViewShell*>(
237 pFrameworkHelper->GetViewShell(aPaneURLs[i]).get());
240 catch (RuntimeException&)
243 return pViewShell;
249 Reference<drawing::XDrawSubController> SlideSorterViewShell::CreateSubController (void)
251 Reference<drawing::XDrawSubController> xSubController;
253 if (IsMainViewShell())
255 // Create uno controller for the main view shell.
256 xSubController = Reference<drawing::XDrawSubController>(
257 new SdUnoSlideView (
258 GetViewShellBase().GetDrawController(),
259 *mpSlideSorter,
260 *GetView()));
263 return xSubController;
269 /** If there is a valid controller then create a new instance of
270 <type>AccessibleSlideSorterView</type>. Otherwise delegate this call
271 to the base class to return a default object (probably an empty
272 reference).
274 ::com::sun::star::uno::Reference<
275 ::com::sun::star::accessibility::XAccessible>
276 SlideSorterViewShell::CreateAccessibleDocumentView (::sd::Window* pWindow)
278 OSL_ASSERT(mpSlideSorter.get()!=NULL);
280 // When the view is not set then the initialization is not yet complete
281 // and we can not yet provide an accessibility object.
282 if (mpView == NULL)
283 return NULL;
285 return new ::accessibility::AccessibleSlideSorterView (
286 *mpSlideSorter.get(),
287 pWindow->GetAccessibleParentWindow()->GetAccessible(),
288 pWindow);
294 SlideSorter& SlideSorterViewShell::GetSlideSorter (void) const
296 OSL_ASSERT(mpSlideSorter.get()!=NULL);
297 return *mpSlideSorter;
303 bool SlideSorterViewShell::RelocateToParentWindow (::Window* pParentWindow)
305 OSL_ASSERT(mpSlideSorter.get()!=NULL);
306 return mpSlideSorter->RelocateToWindow(pParentWindow);
312 SfxUndoManager* SlideSorterViewShell::ImpGetUndoManager (void) const
314 SfxShell* pObjectBar = GetViewShellBase().GetViewShellManager()->GetTopShell();
315 if (pObjectBar != NULL)
317 // When it exists then return the undo manager of the currently
318 // active object bar. The object bar is missing when the
319 // SlideSorterViewShell is not the main view shell.
320 return pObjectBar->GetUndoManager();
322 else
324 // Return the undo manager of this shell when there is no object or
325 // tool bar.
326 return const_cast<SlideSorterViewShell*>(this)->GetUndoManager();
333 SfxShell* SlideSorterViewShell::CreateInstance (
334 sal_Int32,
335 SfxShell*,
336 void* pUserData,
337 ViewShellBase& rBase)
339 return new SlideSorterViewShell (
340 rBase.GetViewFrame(),
341 rBase,
342 static_cast< ::Window*>(pUserData),
343 NULL);
349 void SlideSorterViewShell::GetFocus (void)
351 OSL_ASSERT(mpSlideSorter.get()!=NULL);
352 mpSlideSorter->GetController().GetFocusManager().ShowFocus();
358 void SlideSorterViewShell::LoseFocus (void)
360 OSL_ASSERT(mpSlideSorter.get()!=NULL);
361 mpSlideSorter->GetController().GetFocusManager().HideFocus();
367 SdPage* SlideSorterViewShell::getCurrentPage(void) const
369 // since SlideSorterViewShell::GetActualPage() currently also
370 // returns master pages, which is a wrong behaviour for GetActualPage(),
371 // we can just use that for now
372 return const_cast<SlideSorterViewShell*>(this)->GetActualPage();
378 SdPage* SlideSorterViewShell::GetActualPage (void)
380 SdPage* pCurrentPage = NULL;
382 // 1. Try to get the current page from the view shell in the center pane
383 // (if we are that not ourself).
384 if ( ! IsMainViewShell())
386 ::boost::shared_ptr<ViewShell> pMainViewShell = GetViewShellBase().GetMainViewShell();
387 if (pMainViewShell.get() != NULL)
388 pCurrentPage = pMainViewShell->GetActualPage();
391 if (pCurrentPage == NULL)
393 model::SharedPageDescriptor pDescriptor (
394 mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide());
395 if (pDescriptor.get() != NULL)
396 pCurrentPage = pDescriptor->GetPage();
399 return pCurrentPage;
405 void SlideSorterViewShell::GetMenuState ( SfxItemSet& rSet)
407 ViewShell::GetMenuState(rSet);
408 OSL_ASSERT(mpSlideSorter.get()!=NULL);
409 mpSlideSorter->GetController().GetSlotManager()->GetMenuState(rSet);
415 void SlideSorterViewShell::GetClipboardState ( SfxItemSet& rSet)
417 ViewShell::GetMenuState(rSet);
418 OSL_ASSERT(mpSlideSorter.get()!=NULL);
419 mpSlideSorter->GetController().GetSlotManager()->GetClipboardState(rSet);
425 void SlideSorterViewShell::ExecCtrl (SfxRequest& rRequest)
427 OSL_ASSERT(mpSlideSorter.get()!=NULL);
428 mpSlideSorter->GetController().ExecCtrl(rRequest);
434 void SlideSorterViewShell::GetCtrlState (SfxItemSet& rSet)
436 OSL_ASSERT(mpSlideSorter.get()!=NULL);
437 mpSlideSorter->GetController().GetCtrlState(rSet);
443 void SlideSorterViewShell::FuSupport (SfxRequest& rRequest)
445 OSL_ASSERT(mpSlideSorter.get()!=NULL);
446 mpSlideSorter->GetController().FuSupport(rRequest);
452 /** We have to handle those slot calls here that need to have access to
453 private or protected members and methods of this class.
455 void SlideSorterViewShell::FuTemporary (SfxRequest& rRequest)
457 OSL_ASSERT(mpSlideSorter.get()!=NULL);
458 switch (rRequest.GetSlot())
460 case SID_MODIFYPAGE:
462 SdPage* pCurrentPage = GetActualPage();
463 if (pCurrentPage != NULL)
464 mpImpl->ProcessModifyPageSlot (
465 rRequest,
466 pCurrentPage,
467 mpSlideSorter->GetModel().GetPageType());
468 Cancel();
469 rRequest.Done ();
471 break;
473 default:
474 mpSlideSorter->GetController().FuTemporary(rRequest);
475 break;
482 void SlideSorterViewShell::GetStatusBarState (SfxItemSet& rSet)
484 OSL_ASSERT(mpSlideSorter.get()!=NULL);
485 mpSlideSorter->GetController().GetStatusBarState(rSet);
491 void SlideSorterViewShell::FuPermanent (SfxRequest& rRequest)
493 OSL_ASSERT(mpSlideSorter.get()!=NULL);
494 mpSlideSorter->GetController().FuPermanent(rRequest);
500 void SlideSorterViewShell::GetAttrState (SfxItemSet& rSet)
502 OSL_ASSERT(mpSlideSorter.get()!=NULL);
503 mpSlideSorter->GetController().GetAttrState(rSet);
509 void SlideSorterViewShell::ExecStatusBar (SfxRequest& rRequest)
511 OSL_ASSERT(mpSlideSorter.get()!=NULL);
512 mpSlideSorter->GetController().ExecStatusBar(rRequest);
518 void SlideSorterViewShell::PrePaint()
520 OSL_ASSERT(mpSlideSorter.get()!=NULL);
521 if (mpSlideSorter.get() != NULL)
522 mpSlideSorter->GetController().PrePaint();
528 void SlideSorterViewShell::Paint (
529 const Rectangle& rBBox,
530 ::sd::Window* pWindow)
532 SetActiveWindow (pWindow);
533 OSL_ASSERT(mpSlideSorter.get()!=NULL);
534 if (mpSlideSorter.get() != NULL)
535 mpSlideSorter->GetController().Paint(rBBox,pWindow);
541 void SlideSorterViewShell::ArrangeGUIElements (void)
543 OSL_ASSERT(mpSlideSorter.get()!=NULL);
544 mpSlideSorter->ArrangeGUIElements(
545 maViewPos,
546 maViewSize);
552 SvBorder SlideSorterViewShell::GetBorder (bool )
554 OSL_ASSERT(mpSlideSorter.get()!=NULL);
555 return mpSlideSorter->GetBorder();
561 void SlideSorterViewShell::Command (
562 const CommandEvent& rEvent,
563 ::sd::Window* pWindow)
565 OSL_ASSERT(mpSlideSorter.get()!=NULL);
566 if ( ! mpSlideSorter->GetController().Command (rEvent, pWindow))
567 ViewShell::Command (rEvent, pWindow);
573 void SlideSorterViewShell::ReadFrameViewData (FrameView* pFrameView)
575 OSL_ASSERT(mpSlideSorter.get()!=NULL);
576 if (pFrameView != NULL)
578 view::SlideSorterView& rView (mpSlideSorter->GetView());
580 USHORT nSlidesPerRow (pFrameView->GetSlidesPerRow());
581 if (nSlidesPerRow == 0 || ! IsMainViewShell())
583 // When a value of 0 (automatic) is given or the the slide
584 // sorter is displayed in a side pane then we ignore the value
585 // of the frame view and adapt the number of columns
586 // automatically to the window width.
587 rView.GetLayouter().SetColumnCount(1,5);
589 else
590 rView.GetLayouter().SetColumnCount(nSlidesPerRow,nSlidesPerRow);
591 mpSlideSorter->GetController().Rearrange(true);
593 // DrawMode for 'main' window
594 if (GetActiveWindow()->GetDrawMode() != pFrameView->GetDrawMode() )
595 GetActiveWindow()->SetDrawMode( pFrameView->GetDrawMode() );
602 void SlideSorterViewShell::WriteFrameViewData()
604 OSL_ASSERT(mpSlideSorter.get()!=NULL);
605 if (mpFrameView != NULL)
607 view::SlideSorterView& rView (mpSlideSorter->GetView());
608 mpFrameView->SetSlidesPerRow((USHORT)rView.GetLayouter().GetColumnCount());
610 // DrawMode for 'main' window
611 if( mpFrameView->GetDrawMode() != GetActiveWindow()->GetDrawMode() )
612 mpFrameView->SetDrawMode( GetActiveWindow()->GetDrawMode() );
614 SdPage* pActualPage = GetActualPage();
615 if (pActualPage != NULL)
617 // The slide sorter is not expected to switch the current page
618 // other then by double clicks. That is handled seperatly.
619 // mpFrameView->SetSelectedPage((pActualPage->GetPageNum()- 1) / 2);
621 else
623 // We have no current page to set but at least we can make sure
624 // that the index of the frame view has a legal value.
625 if (mpFrameView->GetSelectedPage() >= mpSlideSorter->GetModel().GetPageCount())
626 mpFrameView->SetSelectedPage((USHORT)mpSlideSorter->GetModel().GetPageCount()-1);
634 void SlideSorterViewShell::SetZoom (long int )
636 // Ignored.
637 // The zoom scale is adapted internally to fit a number of columns in
638 // the window.
641 void SlideSorterViewShell::SetZoomRect (const Rectangle& rZoomRect)
643 OSL_ASSERT(mpSlideSorter.get()!=NULL);
644 Size aPageSize (mpSlideSorter->GetView().GetPageBoundingBox(
646 view::SlideSorterView::CS_MODEL,
647 view::SlideSorterView::BBT_SHAPE).GetSize());
649 Rectangle aRect(rZoomRect);
651 if (aRect.GetWidth() < aPageSize.Width())
653 long nWidthDiff = (aPageSize.Width() - aRect.GetWidth()) / 2;
655 aRect.Left() -= nWidthDiff;
656 aRect.Right() += nWidthDiff;
658 if (aRect.Left() < 0)
660 aRect.SetPos(Point(0, aRect.Top()));
664 if (aRect.GetHeight() < aPageSize.Height())
666 long nHeightDiff = (aPageSize.Height() - aRect.GetHeight()) / 2;
668 aRect.Top() -= nHeightDiff;
669 aRect.Bottom() += nHeightDiff;
671 if (aRect.Top() < 0)
673 aRect.SetPos(Point(aRect.Left(), 0));
677 ViewShell::SetZoomRect(aRect);
679 // #106268#
680 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
681 GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
687 void SlideSorterViewShell::UpdateScrollBars (void)
689 // Do not call the overwritten method of the base class: We do all the
690 // scroll bar setup by ourselves.
691 mpSlideSorter->GetController().GetScrollBarManager().UpdateScrollBars (false);
697 void SlideSorterViewShell::StartDrag (
698 const Point& rDragPt,
699 ::Window* pWindow )
701 OSL_ASSERT(mpSlideSorter.get()!=NULL);
702 mpSlideSorter->GetController().GetClipboard().StartDrag (
703 rDragPt,
704 pWindow);
710 void SlideSorterViewShell::DragFinished (
711 sal_Int8 nDropAction)
713 OSL_ASSERT(mpSlideSorter.get()!=NULL);
714 mpSlideSorter->GetController().GetClipboard().DragFinished (nDropAction);
720 sal_Int8 SlideSorterViewShell::AcceptDrop (
721 const AcceptDropEvent& rEvt,
722 DropTargetHelper& rTargetHelper,
723 ::sd::Window* pTargetWindow,
724 USHORT nPage,
725 USHORT nLayer)
727 OSL_ASSERT(mpSlideSorter.get()!=NULL);
728 return mpSlideSorter->GetController().GetClipboard().AcceptDrop (
729 rEvt,
730 rTargetHelper,
731 pTargetWindow,
732 nPage,
733 nLayer);
739 sal_Int8 SlideSorterViewShell::ExecuteDrop (
740 const ExecuteDropEvent& rEvt,
741 DropTargetHelper& rTargetHelper,
742 ::sd::Window* pTargetWindow,
743 USHORT nPage,
744 USHORT nLayer)
746 OSL_ASSERT(mpSlideSorter.get()!=NULL);
747 return mpSlideSorter->GetController().GetClipboard().ExecuteDrop (
748 rEvt,
749 rTargetHelper,
750 pTargetWindow,
751 nPage,
752 nLayer);
758 ::boost::shared_ptr<SlideSorterViewShell::PageSelection>
759 SlideSorterViewShell::GetPageSelection (void) const
761 OSL_ASSERT(mpSlideSorter.get()!=NULL);
762 return mpSlideSorter->GetController().GetPageSelector().GetPageSelection();
768 void SlideSorterViewShell::SetPageSelection (
769 const ::boost::shared_ptr<PageSelection>& rSelection)
771 OSL_ASSERT(mpSlideSorter.get()!=NULL);
772 mpSlideSorter->GetController().GetPageSelector().SetPageSelection(rSelection);
778 void SlideSorterViewShell::AddSelectionChangeListener (
779 const Link& rCallback)
781 OSL_ASSERT(mpSlideSorter.get()!=NULL);
782 mpSlideSorter->GetController().GetSelectionManager()->AddSelectionChangeListener(rCallback);
788 void SlideSorterViewShell::RemoveSelectionChangeListener (
789 const Link& rCallback)
791 OSL_ASSERT(mpSlideSorter.get()!=NULL);
792 mpSlideSorter->GetController().GetSelectionManager()->RemoveSelectionChangeListener(rCallback);
797 } } // end of namespace ::sd::slidesorter