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

Generated by: LCOV version 1.10