1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sfx2/request.hxx> 32*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 33*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <svl/itemiter.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <svx/globl3d.hxx> 38*cdf0e10cSrcweir #include <svx/svxids.hrc> 39*cdf0e10cSrcweir #include <svx/svdotable.hxx> 40*cdf0e10cSrcweir #include <editeng/outliner.hxx> 41*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 42*cdf0e10cSrcweir #include <editeng/editeng.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #define _SD_DLL // fuer SD_MOD() 45*cdf0e10cSrcweir #include "sdmod.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include "fuformatpaintbrush.hxx" 48*cdf0e10cSrcweir #include "drawview.hxx" 49*cdf0e10cSrcweir #include "DrawDocShell.hxx" 50*cdf0e10cSrcweir #include "DrawViewShell.hxx" 51*cdf0e10cSrcweir #include "FrameView.hxx" 52*cdf0e10cSrcweir #include "drawdoc.hxx" 53*cdf0e10cSrcweir #include "Outliner.hxx" 54*cdf0e10cSrcweir #include "ViewShellBase.hxx" 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifndef SD_WINDOW_SHELL_HXX 57*cdf0e10cSrcweir #include "Window.hxx" 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace sd { 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir TYPEINIT1( FuFormatPaintBrush, FuText ); 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir FuFormatPaintBrush::FuFormatPaintBrush( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 65*cdf0e10cSrcweir : FuText(pViewSh, pWin, pView, pDoc, rReq) 66*cdf0e10cSrcweir , mbPermanent( false ) 67*cdf0e10cSrcweir , mbOldIsQuickTextEditMode( true ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir FunctionReference FuFormatPaintBrush::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir FunctionReference xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) ); 74*cdf0e10cSrcweir xFunc->DoExecute( rReq ); 75*cdf0e10cSrcweir return xFunc; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir void FuFormatPaintBrush::DoExecute( SfxRequest& rReq ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir const SfxItemSet *pArgs = rReq.GetArgs(); 81*cdf0e10cSrcweir if( pArgs && pArgs->Count() >= 1 ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir mbPermanent = static_cast<bool>(((SfxBoolItem &)pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue()); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir if( mpView ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir mpView->TakeFormatPaintBrush( mpItemSet ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir void FuFormatPaintBrush::implcancel() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir if( mpViewShell && mpViewShell->GetViewFrame() ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame(); 97*cdf0e10cSrcweir pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH); 98*cdf0e10cSrcweir pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir static void unmarkimpl( SdrView* pView ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir pView->SdrEndTextEdit(); 105*cdf0e10cSrcweir pView->UnMarkAll(); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent& rMEvt) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if(mpView&&mpWindow) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir SdrViewEvent aVEvt; 113*cdf0e10cSrcweir SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir if( (eHit == SDRHIT_TEXTEDIT) || (eHit == SDRHIT_TEXTEDITOBJ && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj* >( aVEvt.pObj ) != NULL ) )) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir SdrObject* pPickObj=0; 118*cdf0e10cSrcweir SdrPageView* pPV=0; 119*cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() ); 120*cdf0e10cSrcweir mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPickObj, pPV, SDRSEARCH_PICKMARKABLE); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if( (pPickObj != 0) && !pPickObj->IsEmptyPresObj() ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir // if we text hit another shape than the one currently selected, unselect the old one now 125*cdf0e10cSrcweir const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); 126*cdf0e10cSrcweir if( rMarkList.GetMarkCount() >= 1 ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir if( rMarkList.GetMarkCount() == 1 ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // if current selected shape is not that of the hit text edit, deselect it 134*cdf0e10cSrcweir unmarkimpl( mpView ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir else 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir // more than one shape selected, deselect all of them 140*cdf0e10cSrcweir unmarkimpl( mpView ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 ); 144*cdf0e10cSrcweir return FuText::MouseButtonDown(aMEvt); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir if( aVEvt.pObj == 0 ) 148*cdf0e10cSrcweir aVEvt.pObj = pPickObj; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir unmarkimpl( mpView ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if( aVEvt.pObj ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() ); 156*cdf0e10cSrcweir sal_Bool bToggle = sal_False; 157*cdf0e10cSrcweir mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, bToggle, sal_False); 158*cdf0e10cSrcweir return sal_True; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir return sal_False; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseMove(const MouseEvent& rMEvt) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir sal_Bool bReturn = sal_False; 167*cdf0e10cSrcweir if( mpWindow && mpView ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if ( mpView->IsTextEdit() ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir bReturn = FuText::MouseMove( rMEvt ); 172*cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_FILL)); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir else 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() ); 177*cdf0e10cSrcweir SdrObject* pObj=0; 178*cdf0e10cSrcweir SdrPageView* pPV=0; 179*cdf0e10cSrcweir sal_Bool bOverMarkableObject = mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pObj, pPV, SDRSEARCH_PICKMARKABLE); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if(bOverMarkableObject && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) ) 182*cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_FILL)); 183*cdf0e10cSrcweir else 184*cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_ARROW)); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir return bReturn; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir if( mpItemSet.get() && mpView && mpView->AreObjectsMarked() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir bool bNoCharacterFormats = false; 195*cdf0e10cSrcweir bool bNoParagraphFormats = false; 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) ) 198*cdf0e10cSrcweir bNoCharacterFormats = true; 199*cdf0e10cSrcweir else if( rMEvt.GetModifier() & KEY_MOD1 ) 200*cdf0e10cSrcweir bNoParagraphFormats = true; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); 204*cdf0e10cSrcweir if( pOLV ) 205*cdf0e10cSrcweir pOLV->MouseButtonUp(rMEvt); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir Paste( bNoCharacterFormats, bNoParagraphFormats ); 208*cdf0e10cSrcweir if(mpViewShell) 209*cdf0e10cSrcweir mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir if( mbPermanent ) 212*cdf0e10cSrcweir return sal_True; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir implcancel(); 216*cdf0e10cSrcweir return sal_True; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::KeyInput(const KeyEvent& rKEvt) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir if( (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) && mpViewShell ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir implcancel(); 224*cdf0e10cSrcweir return sal_True; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir return FuPoor::KeyInput(rKEvt); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir void FuFormatPaintBrush::Activate() 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir mbOldIsQuickTextEditMode = mpViewShell->GetFrameView()->IsQuickEdit(); 232*cdf0e10cSrcweir if( !mbOldIsQuickTextEditMode ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir mpViewShell->GetFrameView()->SetQuickEdit(sal_True); 235*cdf0e10cSrcweir mpView->SetQuickTextEditMode(sal_True); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir void FuFormatPaintBrush::Deactivate() 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir if( !mbOldIsQuickTextEditMode ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir mpViewShell->GetFrameView()->SetQuickEdit(sal_False); 244*cdf0e10cSrcweir mpView->SetQuickTextEditMode(sal_False); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor, sal_uInt16 nObjectIdentifier ) const 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir if( mpItemSet.get() == 0 ) 251*cdf0e10cSrcweir return false; 252*cdf0e10cSrcweir if( !mpView || (!mpView->SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) ) 253*cdf0e10cSrcweir return false; 254*cdf0e10cSrcweir return true; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir const SdrMarkList& rMarkList = mpView->GetMarkedObjectList(); 260*cdf0e10cSrcweir if(mpItemSet.get() && (rMarkList.GetMarkCount() == 1) ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir if( mpDoc->IsUndoEnabled() ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir String sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FormatPaintbrush" ) ) ) ); 267*cdf0e10cSrcweir mpDoc->BegUndo( sLabel ); 268*cdf0e10cSrcweir mpDoc->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoAttrObject(*pObj,sal_False,sal_True)); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir mpView->ApplyFormatPaintBrush( *mpItemSet.get(), bNoCharacterFormats, bNoParagraphFormats ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir if( mpDoc->IsUndoEnabled() ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir mpDoc->EndUndo(); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell& rDrawViewShell, SfxItemSet &rSet ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList(); 283*cdf0e10cSrcweir const sal_uLong nMarkCount = rMarkList.GetMarkCount(); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if( nMarkCount == 1 ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 288*cdf0e10cSrcweir if( pObj && rDrawViewShell.GetDrawView()->SupportsFormatPaintbrush(pObj->GetObjInventor(),pObj->GetObjIdentifier()) ) 289*cdf0e10cSrcweir return; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir rSet.DisableItem( SID_FORMATPAINTBRUSH ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir } // end of namespace sd 296