LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/slidesorter/controller - SlsInsertionIndicatorHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 105 0.0 %
Date: 2012-12-27 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "controller/SlsInsertionIndicatorHandler.hxx"
      22             : #include "controller/SlsProperties.hxx"
      23             : #include "view/SlideSorterView.hxx"
      24             : #include "view/SlsLayouter.hxx"
      25             : #include "view/SlsInsertionIndicatorOverlay.hxx"
      26             : #include "model/SlideSorterModel.hxx"
      27             : #include "model/SlsPageEnumerationProvider.hxx"
      28             : #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
      29             : 
      30             : #include "SlideSorter.hxx"
      31             : 
      32             : using namespace ::com::sun::star::datatransfer::dnd::DNDConstants;
      33             : 
      34             : namespace sd { namespace slidesorter { namespace controller {
      35             : 
      36             : 
      37           0 : InsertionIndicatorHandler::InsertionIndicatorHandler (SlideSorter& rSlideSorter)
      38             :     : mrSlideSorter(rSlideSorter),
      39             :       mpInsertAnimator(),
      40           0 :       mpInsertionIndicatorOverlay(new view::InsertionIndicatorOverlay(rSlideSorter)),
      41             :       maInsertPosition(),
      42             :       meMode(MoveMode),
      43             :       mbIsActive(false),
      44           0 :       mbIsReadOnly(mrSlideSorter.GetModel().IsReadOnly()),
      45             :       mbIsOverSourceView(true),
      46             :       maIconSize(0,0),
      47           0 :       mbIsForcedShow(false)
      48             : {
      49           0 : }
      50             : 
      51             : 
      52             : 
      53             : 
      54           0 : InsertionIndicatorHandler::~InsertionIndicatorHandler (void)
      55             : {
      56           0 : }
      57             : 
      58             : 
      59             : 
      60             : 
      61           0 : void InsertionIndicatorHandler::Start (const bool bIsOverSourceView)
      62             : {
      63           0 :     if (mbIsActive)
      64             :     {
      65             :         OSL_ASSERT(!mbIsActive);
      66             :     }
      67             : 
      68           0 :     mbIsReadOnly = mrSlideSorter.GetModel().IsReadOnly();
      69           0 :     if (mbIsReadOnly)
      70           0 :         return;
      71             : 
      72           0 :     mbIsActive = true;
      73           0 :     mbIsOverSourceView = bIsOverSourceView;
      74             : }
      75             : 
      76             : 
      77             : 
      78             : 
      79           0 : void InsertionIndicatorHandler::End (const controller::Animator::AnimationMode eMode)
      80             : {
      81           0 :     if (mbIsForcedShow ||  ! mbIsActive || mbIsReadOnly)
      82           0 :         return;
      83             : 
      84           0 :     GetInsertAnimator()->Reset(eMode);
      85             : 
      86           0 :     mbIsActive = false;
      87             :     //    maInsertPosition = view::InsertPosition();
      88           0 :     meMode = UnknownMode;
      89             : 
      90           0 :     mpInsertionIndicatorOverlay->Hide();
      91           0 :     mpInsertionIndicatorOverlay.reset(new view::InsertionIndicatorOverlay(mrSlideSorter));
      92             : }
      93             : 
      94             : 
      95             : 
      96             : 
      97           0 : void InsertionIndicatorHandler::ForceShow (void)
      98             : {
      99           0 :     mbIsForcedShow = true;
     100           0 : }
     101             : 
     102             : 
     103             : 
     104             : 
     105           0 : void InsertionIndicatorHandler::ForceEnd (void)
     106             : {
     107           0 :     mbIsForcedShow = false;
     108           0 :     End(Animator::AM_Immediate);
     109           0 : }
     110             : 
     111             : 
     112             : 
     113             : 
     114           0 : void InsertionIndicatorHandler::UpdateIndicatorIcon (const SdTransferable* pTransferable)
     115             : {
     116           0 :     mpInsertionIndicatorOverlay->Create(pTransferable);
     117           0 :     maIconSize = mpInsertionIndicatorOverlay->GetSize();
     118           0 : }
     119             : 
     120             : 
     121             : 
     122             : 
     123           0 : InsertionIndicatorHandler::Mode InsertionIndicatorHandler::GetModeFromDndAction (
     124             :     const sal_Int8 nDndAction)
     125             : {
     126           0 :     if ((nDndAction & ACTION_MOVE) != 0)
     127           0 :         return MoveMode;
     128           0 :     else if ((nDndAction & ACTION_COPY) != 0)
     129           0 :         return CopyMode;
     130             :     else
     131           0 :         return UnknownMode;
     132             : }
     133             : 
     134             : 
     135             : 
     136             : 
     137           0 : void InsertionIndicatorHandler::UpdatePosition (
     138             :     const Point& rMouseModelPosition,
     139             :     const Mode eMode)
     140             : {
     141           0 :     if ( ! mbIsActive)
     142           0 :         return;
     143             : 
     144           0 :     if (mbIsReadOnly)
     145           0 :         return;
     146             : 
     147           0 :     SetPosition(rMouseModelPosition, eMode);
     148             : }
     149             : 
     150             : 
     151             : 
     152             : 
     153           0 : void InsertionIndicatorHandler::UpdatePosition (
     154             :     const Point& rMouseModelPosition,
     155             :     const sal_Int8 nDndAction)
     156             : {
     157           0 :     UpdatePosition(rMouseModelPosition, GetModeFromDndAction(nDndAction));
     158           0 : }
     159             : 
     160             : 
     161             : 
     162             : 
     163           0 : bool InsertionIndicatorHandler::IsActive (void) const
     164             : {
     165           0 :     return mbIsActive;
     166             : }
     167             : 
     168             : 
     169             : 
     170             : 
     171           0 : sal_Int32 InsertionIndicatorHandler::GetInsertionPageIndex (void) const
     172             : {
     173           0 :     if (mbIsReadOnly)
     174           0 :         return -1;
     175             :     else
     176           0 :         return maInsertPosition.GetIndex();
     177             : }
     178             : 
     179             : 
     180             : 
     181             : 
     182           0 : void InsertionIndicatorHandler::SetPosition (
     183             :     const Point& rPoint,
     184             :     const Mode eMode)
     185             : {
     186           0 :     view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter());
     187             : 
     188             :     const view::InsertPosition aInsertPosition (rLayouter.GetInsertPosition(
     189             :         rPoint,
     190             :         maIconSize,
     191           0 :         mrSlideSorter.GetModel()));
     192             : 
     193           0 :     if (maInsertPosition != aInsertPosition
     194             :         || meMode != eMode
     195             :         //        || ! mpInsertionIndicatorOverlay->IsVisible()
     196             :         )
     197             :     {
     198           0 :         maInsertPosition = aInsertPosition;
     199           0 :         meMode = eMode;
     200           0 :         mbIsInsertionTrivial = IsInsertionTrivial(maInsertPosition.GetIndex(), eMode);
     201           0 :         if (maInsertPosition.GetIndex()>=0 && ! mbIsInsertionTrivial)
     202             :         {
     203           0 :             mpInsertionIndicatorOverlay->SetLocation(maInsertPosition.GetLocation());
     204             : 
     205           0 :             GetInsertAnimator()->SetInsertPosition(maInsertPosition);
     206           0 :             mpInsertionIndicatorOverlay->Show();
     207             :         }
     208             :         else
     209             :         {
     210           0 :             GetInsertAnimator()->Reset(Animator::AM_Animated);
     211           0 :             mpInsertionIndicatorOverlay->Hide();
     212             :         }
     213             :     }
     214           0 : }
     215             : 
     216             : 
     217             : 
     218             : 
     219           0 : ::boost::shared_ptr<view::InsertAnimator> InsertionIndicatorHandler::GetInsertAnimator (void)
     220             : {
     221           0 :     if ( ! mpInsertAnimator)
     222           0 :         mpInsertAnimator.reset(new view::InsertAnimator(mrSlideSorter));
     223           0 :     return mpInsertAnimator;
     224             : }
     225             : 
     226             : 
     227             : 
     228             : 
     229           0 : bool InsertionIndicatorHandler::IsInsertionTrivial (
     230             :     const sal_Int32 nInsertionIndex,
     231             :     const Mode eMode) const
     232             : {
     233           0 :     if (eMode == CopyMode)
     234           0 :         return false;
     235           0 :     else if (eMode == UnknownMode)
     236           0 :         return true;
     237             : 
     238           0 :     if ( ! mbIsOverSourceView)
     239           0 :         return false;
     240             : 
     241             :     // Iterate over all selected pages and check whether there are
     242             :     // holes.  While we do this we remember the indices of the first and
     243             :     // last selected page as preparation for the next step.
     244           0 :     sal_Int32 nCurrentIndex = -1;
     245           0 :     sal_Int32 nFirstIndex = -1;
     246           0 :     sal_Int32 nLastIndex = -1;
     247             :     model::PageEnumeration aSelectedPages (
     248             :         model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
     249           0 :             mrSlideSorter.GetModel()));
     250           0 :     while (aSelectedPages.HasMoreElements())
     251             :     {
     252           0 :         model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
     253             : 
     254             :         // Get the page number and compare it to the last one.
     255           0 :         const sal_Int32 nPageNumber (pDescriptor->GetPageIndex());
     256           0 :         if (nCurrentIndex>=0 && nPageNumber>(nCurrentIndex+1))
     257           0 :             return false;
     258             :         else
     259           0 :             nCurrentIndex = nPageNumber;
     260             : 
     261             :         // Remember indices of the first and last page of the selection.
     262           0 :         if (nFirstIndex == -1)
     263           0 :             nFirstIndex = nPageNumber;
     264           0 :         nLastIndex = nPageNumber;
     265           0 :     }
     266             : 
     267             :     // When we come here then the selection has no holes.  We still have
     268             :     // to check that the insertion position is not directly in front or
     269             :     // directly behind the selection and thus moving the selection there
     270             :     // would not change the model.
     271           0 :     if (nInsertionIndex<nFirstIndex || nInsertionIndex>(nLastIndex+1))
     272           0 :         return false;
     273             : 
     274           0 :     return true;
     275             : }
     276             : 
     277             : 
     278             : 
     279             : 
     280           0 : bool InsertionIndicatorHandler::IsInsertionTrivial (const sal_Int8 nDndAction)
     281             : {
     282           0 :     return IsInsertionTrivial(GetInsertionPageIndex(), GetModeFromDndAction(nDndAction));
     283             : }
     284             : 
     285             : 
     286             : 
     287             : 
     288             : //===== InsertionIndicatorHandler::ForceShowContext ===========================
     289             : 
     290           0 : InsertionIndicatorHandler::ForceShowContext::ForceShowContext (
     291             :     const ::boost::shared_ptr<InsertionIndicatorHandler>& rpHandler)
     292           0 :     : mpHandler(rpHandler)
     293             : {
     294           0 :     mpHandler->ForceShow();
     295           0 : }
     296             : 
     297             : 
     298             : 
     299             : 
     300           0 : InsertionIndicatorHandler::ForceShowContext::~ForceShowContext (void)
     301             : {
     302           0 :     mpHandler->ForceEnd();
     303           0 : }
     304             : 
     305             : } } } // end of namespace ::sd::slidesorter::controller
     306             : 
     307             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10