LCOV - code coverage report
Current view: top level - sd/source/ui/func - smarttag.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 53 178 29.8 %
Date: 2015-06-13 12:38:46 Functions: 17 43 39.5 %
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             : #include "ViewShell.hxx"
      21             : #include "smarttag.hxx"
      22             : #include "Window.hxx"
      23             : #include "View.hxx"
      24             : 
      25             : namespace sd
      26             : {
      27             : 
      28           0 : SmartTag::SmartTag( ::sd::View& rView )
      29             : : mrView( rView )
      30           0 : , mbSelected( false )
      31             : {
      32           0 :     SmartTagReference xThis( this );
      33           0 :     mrView.getSmartTags().add( xThis );
      34           0 : }
      35             : 
      36           0 : SmartTag::~SmartTag()
      37             : {
      38           0 : }
      39             : 
      40           0 : bool SmartTag::MouseButtonDown( const MouseEvent&, SmartHdl&  )
      41             : {
      42           0 :     return false;
      43             : }
      44             : 
      45             : /** returns true if the SmartTag consumes this event. */
      46           0 : bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
      47             : {
      48           0 :     return false;
      49             : }
      50             : 
      51             : /** returns true if the SmartTag consumes this event. */
      52           0 : bool SmartTag::RequestHelp( const HelpEvent& /*rHEvt*/ )
      53             : {
      54           0 :     return false;
      55             : }
      56             : 
      57             : /** returns true if the SmartTag consumes this event. */
      58           0 : bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
      59             : {
      60           0 :     return false;
      61             : }
      62             : 
      63           0 : void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
      64             : {
      65           0 : }
      66             : 
      67           0 : void SmartTag::select()
      68             : {
      69           0 :     mbSelected = true;
      70           0 : }
      71             : 
      72           0 : void SmartTag::deselect()
      73             : {
      74           0 :     mbSelected = false;
      75           0 : }
      76             : 
      77           0 : void SmartTag::disposing()
      78             : {
      79           0 :     SmartTagReference xThis( this );
      80           0 :     mrView.getSmartTags().remove( xThis );
      81           0 : }
      82             : 
      83           0 : bool SmartTag::getContext( SdrViewContext& /*rContext*/ )
      84             : {
      85           0 :     return false;
      86             : }
      87             : 
      88           0 : sal_uLong SmartTag::GetMarkablePointCount() const
      89             : {
      90           0 :     return 0;
      91             : }
      92             : 
      93           0 : sal_uLong SmartTag::GetMarkedPointCount() const
      94             : {
      95           0 :     return 0;
      96             : }
      97             : 
      98           0 : bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
      99             : {
     100           0 :     return false;
     101             : }
     102             : 
     103           0 : bool SmartTag::MarkPoints(const Rectangle* /*pRect*/, bool /*bUnmark*/ )
     104             : {
     105           0 :     return false;
     106             : }
     107             : 
     108           0 : void SmartTag::CheckPossibilities()
     109             : {
     110           0 : }
     111             : 
     112         323 : SmartTagSet::SmartTagSet( View& rView )
     113         323 : : mrView( rView )
     114             : {
     115         323 : }
     116             : 
     117         323 : SmartTagSet::~SmartTagSet()
     118             : {
     119         323 : }
     120             : 
     121           0 : void SmartTagSet::add( const SmartTagReference& xTag )
     122             : {
     123           0 :     maSet.insert( xTag );
     124           0 :     mrView.InvalidateAllWin();
     125             : 
     126           0 :     if( xTag == mxMouseOverTag )
     127           0 :         mxMouseOverTag.clear();
     128             : 
     129           0 :     if( xTag == mxSelectedTag )
     130           0 :         mxSelectedTag.clear();
     131           0 : }
     132             : 
     133           0 : void SmartTagSet::remove( const SmartTagReference& xTag )
     134             : {
     135           0 :     std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
     136           0 :     if( aIter != maSet.end() )
     137           0 :         maSet.erase( aIter );
     138           0 :     mrView.InvalidateAllWin();
     139             : 
     140           0 :     if( xTag == mxMouseOverTag )
     141           0 :         mxMouseOverTag.clear();
     142             : 
     143           0 :     if( xTag == mxSelectedTag )
     144           0 :         mxSelectedTag.clear();
     145           0 : }
     146             : 
     147         323 : void SmartTagSet::Dispose()
     148             : {
     149         323 :     std::set< SmartTagReference > aSet;
     150         323 :     aSet.swap( maSet );
     151         646 :     for( std::set< SmartTagReference >::iterator aIter( aSet.begin() ); aIter != aSet.end(); )
     152           0 :         (*aIter++)->Dispose();
     153         323 :     mrView.InvalidateAllWin();
     154         323 :     mxMouseOverTag.clear();
     155         323 :     mxSelectedTag.clear();
     156         323 : }
     157             : 
     158           0 : void SmartTagSet::select( const SmartTagReference& xTag )
     159             : {
     160           0 :     if( mxSelectedTag != xTag )
     161             :     {
     162           0 :         if( mxSelectedTag.is() )
     163           0 :             mxSelectedTag->deselect();
     164             : 
     165           0 :         mxSelectedTag = xTag;
     166           0 :         mxSelectedTag->select();
     167           0 :         mrView.SetPossibilitiesDirty();
     168           0 :         if( mrView.GetMarkedObjectCount() > 0 )
     169           0 :             mrView.UnmarkAllObj();
     170             :         else
     171           0 :             mrView.updateHandles();
     172             :     }
     173           0 : }
     174             : 
     175           6 : void SmartTagSet::deselect()
     176             : {
     177           6 :     if( mxSelectedTag.is() )
     178             :     {
     179           0 :         mxSelectedTag->deselect();
     180           0 :         mxSelectedTag.clear();
     181           0 :         mrView.SetPossibilitiesDirty();
     182           0 :         mrView.updateHandles();
     183             :     }
     184           6 : }
     185             : 
     186           2 : bool SmartTagSet::MouseButtonDown( const MouseEvent& rMEvt )
     187             : {
     188           2 :     Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
     189           2 :     SdrHdl* pHdl = mrView.PickHandle(aMDPos);
     190             : 
     191             :     // check if a smart tag is selected and no handle is hit
     192           2 :     if( mxSelectedTag.is() && !pHdl )
     193             :     {
     194             :         // deselect smart tag
     195           0 :         deselect();
     196           0 :         return false;
     197             :     }
     198             : 
     199             :     // if a smart tag handle is hit, forward event to its smart tag
     200           2 :     SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
     201           2 :     if(pSmartHdl && pSmartHdl->getTag().is() )
     202             :     {
     203           0 :         SmartTagReference xTag( pSmartHdl->getTag() );
     204           0 :         return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
     205             :     }
     206             : 
     207           2 :     return false;
     208             : }
     209             : 
     210           1 : bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
     211             : {
     212           1 :     if( mxSelectedTag.is() )
     213           0 :         return mxSelectedTag->KeyInput( rKEvt );
     214           1 :     else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
     215             :     {
     216           0 :         SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
     217           0 :         if( pSmartHdl )
     218             :         {
     219           0 :             const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
     220           0 :             SmartTagReference xTag( pSmartHdl->getTag() );
     221           0 :             select( xTag );
     222           0 :             return true;
     223             :         }
     224             :     }
     225             : 
     226           1 :     return false;
     227             : }
     228             : 
     229           0 : bool SmartTagSet::RequestHelp( const HelpEvent& rHEvt )
     230             : {
     231           0 :     Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rHEvt.GetMousePosPixel() ) );
     232           0 :     SdrHdl* pHdl = mrView.PickHandle(aMDPos);
     233             : 
     234           0 :     if( pHdl )
     235             :     {
     236             :         // if a smart tag handle is hit, forward event to its smart tag
     237           0 :         SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
     238           0 :         if(pSmartHdl && pSmartHdl->getTag().is() )
     239             :         {
     240           0 :             SmartTagReference xTag( pSmartHdl->getTag() );
     241           0 :             return xTag->RequestHelp( rHEvt );
     242             :         }
     243             :     }
     244             : 
     245           0 :     return false;
     246             : }
     247             : 
     248             : /** returns true if the SmartTag consumes this event. */
     249           0 : bool SmartTagSet::Command( const CommandEvent& rCEvt )
     250             : {
     251           0 :     if( rCEvt.IsMouseEvent() )
     252             :     {
     253           0 :         Point aMDPos( mrView.GetViewShell()->GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() ) );
     254           0 :         SdrHdl* pHdl = mrView.PickHandle(aMDPos);
     255             : 
     256           0 :         if( pHdl )
     257             :         {
     258             :             // if a smart tag handle is hit, forward event to its smart tag
     259           0 :             SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
     260           0 :             if(pSmartHdl && pSmartHdl->getTag().is() )
     261             :             {
     262           0 :                 SmartTagReference xTag( pSmartHdl->getTag() );
     263           0 :                 return xTag->Command( rCEvt );
     264             :             }
     265             :         }
     266             :     }
     267             :     else
     268             :     {
     269           0 :         if( mxSelectedTag.is() )
     270           0 :             return mxSelectedTag->Command( rCEvt );
     271             : 
     272             :     }
     273             : 
     274           0 :     return false;
     275             : }
     276             : 
     277         788 : void SmartTagSet::addCustomHandles( SdrHdlList& rHandlerList )
     278             : {
     279         788 :     if( !maSet.empty() )
     280             :     {
     281           0 :         for( std::set< SmartTagReference >::iterator aIter( maSet.begin() ); aIter != maSet.end(); )
     282           0 :             (*aIter++)->addCustomHandles( rHandlerList );
     283             :     }
     284         788 : }
     285             : 
     286             : /** returns true if the currently selected smart tag has
     287             :     a special context, returned in rContext. */
     288        1064 : bool SmartTagSet::getContext( SdrViewContext& rContext ) const
     289             : {
     290        1064 :     if( mxSelectedTag.is() )
     291           0 :         return mxSelectedTag->getContext( rContext );
     292             :     else
     293        1064 :         return false;
     294             : }
     295             : 
     296             : // support point editing
     297             : 
     298        1414 : bool SmartTagSet::HasMarkablePoints() const
     299             : {
     300        1414 :     return GetMarkablePointCount() != 0;
     301             : }
     302             : 
     303        1414 : sal_uLong SmartTagSet::GetMarkablePointCount() const
     304             : {
     305        1414 :     if( mxSelectedTag.is() )
     306           0 :         return mxSelectedTag->GetMarkablePointCount();
     307        1414 :     return 0;
     308             : }
     309             : 
     310           5 : bool SmartTagSet::HasMarkedPoints() const
     311             : {
     312           5 :     return GetMarkedPointCount() != 0;
     313             : }
     314             : 
     315           5 : sal_uLong SmartTagSet::GetMarkedPointCount() const
     316             : {
     317           5 :     if( mxSelectedTag.is() )
     318           0 :         return mxSelectedTag->GetMarkedPointCount();
     319             :     else
     320           5 :         return 0;
     321             : }
     322             : 
     323          36 : bool SmartTagSet::IsPointMarkable(const SdrHdl& rHdl)
     324             : {
     325          36 :     const SmartHdl* pSmartHdl = dynamic_cast< const SmartHdl* >( &rHdl );
     326             : 
     327          36 :     return pSmartHdl && pSmartHdl->isMarkable();
     328             : }
     329             : 
     330           0 : bool SmartTagSet::MarkPoint(SdrHdl& rHdl, bool bUnmark )
     331             : {
     332           0 :     if( mxSelectedTag.is() )
     333           0 :         return mxSelectedTag->MarkPoint( rHdl, bUnmark );
     334             : 
     335           0 :     return false;
     336             : }
     337             : 
     338         135 : bool SmartTagSet::MarkPoints(const Rectangle* pRect, bool bUnmark)
     339             : {
     340         135 :     if( mxSelectedTag.is() )
     341           0 :         return mxSelectedTag->MarkPoints( pRect, bUnmark );
     342         135 :     return false;
     343             : }
     344             : 
     345        2320 : void SmartTagSet::CheckPossibilities()
     346             : {
     347        2320 :     if( mxSelectedTag.is() )
     348           0 :         mxSelectedTag->CheckPossibilities();
     349        2320 : }
     350             : 
     351           0 : SmartHdl::SmartHdl( const SmartTagReference& xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
     352             : : SdrHdl( rPnt, eNewKind )
     353           0 : , mxTag( xTag )
     354             : {
     355           0 :     SetObj( pObject );
     356           0 : }
     357             : 
     358           0 : SmartHdl::SmartHdl( const SmartTagReference& xTag, const Point& rPnt, SdrHdlKind eNewKind /*=HDL_MOVE*/ )
     359             : : SdrHdl( rPnt, eNewKind )
     360           0 : , mxTag( xTag )
     361             : {
     362           0 : }
     363             : 
     364           0 : bool SmartHdl::isMarkable() const
     365             : {
     366           0 :     return false;
     367             : }
     368             : 
     369          66 : } // end of namespace sd
     370             : 
     371             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11