LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuformatpaintbrush.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 130 6.2 %
Date: 2012-08-25 Functions: 1 19 5.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 206 2.4 %

           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 <sfx2/request.hxx>
      31                 :            : #include <sfx2/bindings.hxx>
      32                 :            : #include <sfx2/dispatch.hxx>
      33                 :            : 
      34                 :            : #include <svl/itemiter.hxx>
      35                 :            : 
      36                 :            : #include <svx/globl3d.hxx>
      37                 :            : #include <svx/svxids.hrc>
      38                 :            : #include <svx/svdotable.hxx>
      39                 :            : #include <editeng/outliner.hxx>
      40                 :            : #include <editeng/eeitem.hxx>
      41                 :            : #include <editeng/editeng.hxx>
      42                 :            : 
      43                 :            : #include "sdmod.hxx"
      44                 :            : 
      45                 :            : #include "fuformatpaintbrush.hxx"
      46                 :            : #include "drawview.hxx"
      47                 :            : #include "DrawDocShell.hxx"
      48                 :            : #include "DrawViewShell.hxx"
      49                 :            : #include "FrameView.hxx"
      50                 :            : #include "drawdoc.hxx"
      51                 :            : #include "Outliner.hxx"
      52                 :            : #include "ViewShellBase.hxx"
      53                 :            : 
      54                 :            : #include "Window.hxx"
      55                 :            : 
      56                 :            : namespace sd {
      57                 :            : 
      58 [ #  # ][ #  # ]:          0 : TYPEINIT1( FuFormatPaintBrush, FuText );
      59                 :            : 
      60                 :          0 : FuFormatPaintBrush::FuFormatPaintBrush( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      61                 :            : : FuText(pViewSh, pWin, pView, pDoc, rReq)
      62                 :            : , mbPermanent( false )
      63         [ #  # ]:          0 : , mbOldIsQuickTextEditMode( true )
      64                 :            : {
      65                 :          0 : }
      66                 :            : 
      67                 :          0 : FunctionReference FuFormatPaintBrush::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      68                 :            : {
      69 [ #  # ][ #  # ]:          0 :     FunctionReference xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) );
      70         [ #  # ]:          0 :     xFunc->DoExecute( rReq );
      71                 :          0 :     return xFunc;
      72                 :            : }
      73                 :            : 
      74                 :          0 : void FuFormatPaintBrush::DoExecute( SfxRequest& rReq )
      75                 :            : {
      76                 :          0 :     const SfxItemSet *pArgs = rReq.GetArgs();
      77 [ #  # ][ #  # ]:          0 :     if( pArgs && pArgs->Count() >= 1 )
                 [ #  # ]
      78                 :            :     {
      79                 :          0 :         mbPermanent = static_cast<bool>(((SfxBoolItem &)pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue());
      80                 :            :     }
      81                 :            : 
      82         [ #  # ]:          0 :     if( mpView )
      83                 :            :     {
      84                 :          0 :         mpView->TakeFormatPaintBrush( mpItemSet );
      85                 :            :     }
      86                 :          0 : }
      87                 :            : 
      88                 :          0 : void FuFormatPaintBrush::implcancel()
      89                 :            : {
      90 [ #  # ][ #  # ]:          0 :     if( mpViewShell && mpViewShell->GetViewFrame() )
                 [ #  # ]
      91                 :            :     {
      92                 :          0 :         SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
      93                 :          0 :         pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
      94                 :          0 :         pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
      95                 :            :     }
      96                 :          0 : }
      97                 :            : 
      98                 :          0 : static void unmarkimpl( SdrView* pView )
      99                 :            : {
     100                 :          0 :     pView->SdrEndTextEdit();
     101                 :          0 :     pView->UnMarkAll();
     102                 :          0 : }
     103                 :            : 
     104                 :          0 : sal_Bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent& rMEvt)
     105                 :            : {
     106 [ #  # ][ #  # ]:          0 :     if(mpView&&mpWindow)
     107                 :            :     {
     108         [ #  # ]:          0 :         SdrViewEvent aVEvt;
     109         [ #  # ]:          0 :         SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
     110                 :            : 
     111 [ #  # ][ #  # ]:          0 :         if( (eHit == SDRHIT_TEXTEDIT) || (eHit == SDRHIT_TEXTEDITOBJ && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj* >( aVEvt.pObj ) != NULL ) ))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     112                 :            :         {
     113                 :          0 :             SdrObject* pPickObj=0;
     114                 :          0 :             SdrPageView* pPV=0;
     115         [ #  # ]:          0 :             sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
     116 [ #  # ][ #  # ]:          0 :             mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPickObj, pPV, SDRSEARCH_PICKMARKABLE);
     117                 :            : 
     118 [ #  # ][ #  # ]:          0 :             if( (pPickObj != 0) && !pPickObj->IsEmptyPresObj() )
         [ #  # ][ #  # ]
     119                 :            :             {
     120                 :            :                 // if we text hit another shape than the one currently selected, unselect the old one now
     121                 :          0 :                 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     122         [ #  # ]:          0 :                 if( rMarkList.GetMarkCount() >= 1 )
     123                 :            :                 {
     124         [ #  # ]:          0 :                     if( rMarkList.GetMarkCount() == 1 )
     125                 :            :                     {
     126 [ #  # ][ #  # ]:          0 :                         if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj )
                 [ #  # ]
     127                 :            :                         {
     128                 :            : 
     129                 :            :                             // if current selected shape is not that of the hit text edit, deselect it
     130         [ #  # ]:          0 :                             unmarkimpl( mpView );
     131                 :            :                         }
     132                 :            :                     }
     133                 :            :                     else
     134                 :            :                     {
     135                 :            :                         // more than one shape selected, deselect all of them
     136         [ #  # ]:          0 :                         unmarkimpl( mpView );
     137                 :            :                     }
     138                 :            :                 }
     139         [ #  # ]:          0 :                 MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 );
     140         [ #  # ]:          0 :                 return FuText::MouseButtonDown(aMEvt);
     141                 :            :             }
     142                 :            : 
     143         [ #  # ]:          0 :             if( aVEvt.pObj == 0 )
     144                 :          0 :                 aVEvt.pObj = pPickObj;
     145                 :            :         }
     146                 :            : 
     147         [ #  # ]:          0 :         unmarkimpl( mpView );
     148                 :            : 
     149         [ #  # ]:          0 :         if( aVEvt.pObj )
     150                 :            :         {
     151         [ #  # ]:          0 :             sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
     152                 :          0 :             sal_Bool bToggle = sal_False;
     153 [ #  # ][ #  # ]:          0 :             mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, bToggle, sal_False);
     154                 :          0 :             return sal_True;
     155 [ #  # ][ #  # ]:          0 :         }
     156                 :            :     }
     157                 :          0 :     return sal_False;
     158                 :            : }
     159                 :            : 
     160                 :          0 : sal_Bool FuFormatPaintBrush::MouseMove(const MouseEvent& rMEvt)
     161                 :            : {
     162                 :          0 :     sal_Bool bReturn = sal_False;
     163 [ #  # ][ #  # ]:          0 :     if( mpWindow && mpView )
     164                 :            :     {
     165         [ #  # ]:          0 :         if ( mpView->IsTextEdit() )
     166                 :            :         {
     167                 :          0 :             bReturn = FuText::MouseMove( rMEvt );
     168         [ #  # ]:          0 :             mpWindow->SetPointer(Pointer(POINTER_FILL));
     169                 :            :         }
     170                 :            :         else
     171                 :            :         {
     172         [ #  # ]:          0 :             sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
     173                 :          0 :             SdrObject* pObj=0;
     174                 :          0 :             SdrPageView* pPV=0;
     175 [ #  # ][ #  # ]:          0 :             sal_Bool bOverMarkableObject = mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pObj, pPV, SDRSEARCH_PICKMARKABLE);
     176                 :            : 
     177 [ #  # ][ #  # ]:          0 :             if(bOverMarkableObject && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     178         [ #  # ]:          0 :                 mpWindow->SetPointer(Pointer(POINTER_FILL));
     179                 :            :             else
     180         [ #  # ]:          0 :                 mpWindow->SetPointer(Pointer(POINTER_ARROW));
     181                 :            :         }
     182                 :            :     }
     183                 :          0 :     return bReturn;
     184                 :            : }
     185                 :            : 
     186                 :          0 : sal_Bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
     187                 :            : {
     188 [ #  # ][ #  # ]:          0 :     if( mpItemSet.get() && mpView && mpView->AreObjectsMarked() )
         [ #  # ][ #  # ]
     189                 :            :     {
     190                 :          0 :         bool bNoCharacterFormats = false;
     191                 :          0 :         bool bNoParagraphFormats = false;
     192                 :            :         {
     193 [ #  # ][ #  # ]:          0 :             if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
                 [ #  # ]
     194                 :          0 :                 bNoCharacterFormats = true;
     195         [ #  # ]:          0 :             else if( rMEvt.GetModifier() & KEY_MOD1 )
     196                 :          0 :                 bNoParagraphFormats = true;
     197                 :            :         }
     198                 :            : 
     199                 :          0 :         OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
     200         [ #  # ]:          0 :         if( pOLV )
     201                 :          0 :             pOLV->MouseButtonUp(rMEvt);
     202                 :            : 
     203                 :          0 :         Paste( bNoCharacterFormats, bNoParagraphFormats );
     204         [ #  # ]:          0 :         if(mpViewShell)
     205                 :          0 :             mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
     206                 :            : 
     207         [ #  # ]:          0 :         if( mbPermanent )
     208                 :          0 :             return sal_True;
     209                 :            :     }
     210                 :            : 
     211                 :          0 :     implcancel();
     212                 :          0 :     return sal_True;
     213                 :            : }
     214                 :            : 
     215                 :          0 : sal_Bool FuFormatPaintBrush::KeyInput(const KeyEvent& rKEvt)
     216                 :            : {
     217 [ #  # ][ #  # ]:          0 :     if( (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) && mpViewShell )
                 [ #  # ]
     218                 :            :     {
     219                 :          0 :         implcancel();
     220                 :          0 :         return sal_True;
     221                 :            :     }
     222                 :          0 :     return FuPoor::KeyInput(rKEvt);
     223                 :            : }
     224                 :            : 
     225                 :          0 : void FuFormatPaintBrush::Activate()
     226                 :            : {
     227                 :          0 :     mbOldIsQuickTextEditMode = mpViewShell->GetFrameView()->IsQuickEdit();
     228         [ #  # ]:          0 :     if( !mbOldIsQuickTextEditMode  )
     229                 :            :     {
     230                 :          0 :         mpViewShell->GetFrameView()->SetQuickEdit(sal_True);
     231                 :          0 :         mpView->SetQuickTextEditMode(sal_True);
     232                 :            :     }
     233                 :          0 : }
     234                 :            : 
     235                 :          0 : void FuFormatPaintBrush::Deactivate()
     236                 :            : {
     237         [ #  # ]:          0 :     if( !mbOldIsQuickTextEditMode  )
     238                 :            :     {
     239                 :          0 :         mpViewShell->GetFrameView()->SetQuickEdit(sal_False);
     240                 :          0 :         mpView->SetQuickTextEditMode(sal_False);
     241                 :            :     }
     242                 :          0 : }
     243                 :            : 
     244                 :          0 : bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor, sal_uInt16 nObjectIdentifier ) const
     245                 :            : {
     246         [ #  # ]:          0 :     if( mpItemSet.get() == 0 )
     247                 :          0 :         return false;
     248 [ #  # ][ #  # ]:          0 :     if( !mpView || (!mpView->SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) )
                 [ #  # ]
     249                 :          0 :         return false;
     250                 :          0 :     return true;
     251                 :            : }
     252                 :            : 
     253                 :          0 : void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats )
     254                 :            : {
     255                 :          0 :     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     256 [ #  # ][ #  # ]:          0 :     if( mpItemSet.get() && ( rMarkList.GetMarkCount() == 1 ) )
                 [ #  # ]
     257                 :            :     {
     258                 :          0 :         SdrObject* pObj( NULL );
     259                 :          0 :         bool bUndo = mpDoc->IsUndoEnabled();
     260                 :            : 
     261 [ #  # ][ #  # ]:          0 :         if( bUndo && !mpView->GetTextEditOutlinerView() )
                 [ #  # ]
     262                 :          0 :             pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     263                 :            : 
     264                 :            :         // n685123: ApplyFormatPaintBrush itself would store undo information
     265                 :            :         // except in a few cases (?)
     266         [ #  # ]:          0 :         if( pObj )
     267                 :            :         {
     268 [ #  # ][ #  # ]:          0 :             rtl::OUString sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
     269 [ #  # ][ #  # ]:          0 :             mpDoc->BegUndo( sLabel );
                 [ #  # ]
     270 [ #  # ][ #  # ]:          0 :             mpDoc->AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, sal_False, sal_True ) );
                 [ #  # ]
     271                 :            :         }
     272                 :            : 
     273                 :          0 :         mpView->ApplyFormatPaintBrush( *mpItemSet.get(), bNoCharacterFormats, bNoParagraphFormats );
     274                 :            : 
     275         [ #  # ]:          0 :         if( pObj )
     276                 :            :         {
     277                 :          0 :             mpDoc->EndUndo();
     278                 :            :         }
     279                 :            :     }
     280                 :          0 : }
     281                 :            : 
     282                 :       6385 : /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell& rDrawViewShell, SfxItemSet &rSet )
     283                 :            : {
     284                 :       6385 :     const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList();
     285                 :       6385 :     const sal_uLong nMarkCount = rMarkList.GetMarkCount();
     286                 :            : 
     287         [ +  + ]:       6385 :     if( nMarkCount == 1 )
     288                 :            :     {
     289                 :          3 :         SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
     290 [ +  - ][ +  - ]:          3 :         if( pObj && rDrawViewShell.GetDrawView()->SupportsFormatPaintbrush(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
                 [ +  - ]
     291                 :       6385 :             return;
     292                 :            :     }
     293                 :       6382 :     rSet.DisableItem( SID_FORMATPAINTBRUSH );
     294                 :            : }
     295                 :            : 
     296                 :            : 
     297                 :            : } // end of namespace sd
     298                 :            : 
     299                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10