LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsInsertionIndicatorHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 105 9.5 %
Date: 2012-08-25 Functions: 3 18 16.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 120 7.5 %

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

Generated by: LCOV version 1.10