bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuformatpaintbrush.cxx
blob87b0c571cf9539b395c401737f4b9ecb78143820
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sfx2/request.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
25 #include <svl/itemiter.hxx>
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>
34 #include "sdmod.hxx"
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"
45 #include "Window.hxx"
47 namespace sd {
49 TYPEINIT1( FuFormatPaintBrush, FuText );
51 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 , mbOldIsQuickTextEditMode( true )
58 FunctionReference FuFormatPaintBrush::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
60 FunctionReference xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) );
61 xFunc->DoExecute( rReq );
62 return xFunc;
65 void FuFormatPaintBrush::DoExecute( SfxRequest& rReq )
67 const SfxItemSet *pArgs = rReq.GetArgs();
68 if( pArgs && pArgs->Count() >= 1 )
70 mbPermanent = static_cast<bool>(((SfxBoolItem &)pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue());
73 if( mpView )
75 mpView->TakeFormatPaintBrush( mpItemSet );
79 void FuFormatPaintBrush::implcancel()
81 if( mpViewShell && mpViewShell->GetViewFrame() )
83 SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
84 pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
85 pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
89 static void unmarkimpl( SdrView* pView )
91 pView->SdrEndTextEdit();
92 pView->UnMarkAll();
95 sal_Bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent& rMEvt)
97 if(mpView&&mpWindow)
99 SdrViewEvent aVEvt;
100 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
102 if( (eHit == SDRHIT_TEXTEDIT) || (eHit == SDRHIT_TEXTEDITOBJ && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj* >( aVEvt.pObj ) != NULL ) ))
104 SdrObject* pPickObj=0;
105 SdrPageView* pPV=0;
106 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
107 mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPickObj, pPV, SDRSEARCH_PICKMARKABLE);
109 if( (pPickObj != 0) && !pPickObj->IsEmptyPresObj() )
111 // if we text hit another shape than the one currently selected, unselect the old one now
112 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
113 if( rMarkList.GetMarkCount() >= 1 )
115 if( rMarkList.GetMarkCount() == 1 )
117 if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj )
120 // if current selected shape is not that of the hit text edit, deselect it
121 unmarkimpl( mpView );
124 else
126 // more than one shape selected, deselect all of them
127 unmarkimpl( mpView );
130 MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 );
131 return FuText::MouseButtonDown(aMEvt);
134 if( aVEvt.pObj == 0 )
135 aVEvt.pObj = pPickObj;
138 unmarkimpl( mpView );
140 if( aVEvt.pObj )
142 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
143 sal_Bool bToggle = sal_False;
144 mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, bToggle, sal_False);
145 return sal_True;
148 return sal_False;
151 sal_Bool FuFormatPaintBrush::MouseMove(const MouseEvent& rMEvt)
153 sal_Bool bReturn = sal_False;
154 if( mpWindow && mpView )
156 if ( mpView->IsTextEdit() )
158 bReturn = FuText::MouseMove( rMEvt );
159 mpWindow->SetPointer(Pointer(POINTER_FILL));
161 else
163 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
164 SdrObject* pObj=0;
165 SdrPageView* pPV=0;
166 sal_Bool bOverMarkableObject = mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pObj, pPV, SDRSEARCH_PICKMARKABLE);
168 if(bOverMarkableObject && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
169 mpWindow->SetPointer(Pointer(POINTER_FILL));
170 else
171 mpWindow->SetPointer(Pointer(POINTER_ARROW));
174 return bReturn;
177 sal_Bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
179 if( mpItemSet.get() && mpView && mpView->AreObjectsMarked() )
181 bool bNoCharacterFormats = false;
182 bool bNoParagraphFormats = false;
184 if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
185 bNoCharacterFormats = true;
186 else if( rMEvt.GetModifier() & KEY_MOD1 )
187 bNoParagraphFormats = true;
190 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
191 if( pOLV )
192 pOLV->MouseButtonUp(rMEvt);
194 Paste( bNoCharacterFormats, bNoParagraphFormats );
195 if(mpViewShell)
196 mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
198 if( mbPermanent )
199 return sal_True;
202 implcancel();
203 return sal_True;
206 sal_Bool FuFormatPaintBrush::KeyInput(const KeyEvent& rKEvt)
208 if( (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) && mpViewShell )
210 implcancel();
211 return sal_True;
213 return FuPoor::KeyInput(rKEvt);
216 void FuFormatPaintBrush::Activate()
218 mbOldIsQuickTextEditMode = mpViewShell->GetFrameView()->IsQuickEdit();
219 if( !mbOldIsQuickTextEditMode )
221 mpViewShell->GetFrameView()->SetQuickEdit(sal_True);
222 mpView->SetQuickTextEditMode(sal_True);
226 void FuFormatPaintBrush::Deactivate()
228 if( !mbOldIsQuickTextEditMode )
230 mpViewShell->GetFrameView()->SetQuickEdit(sal_False);
231 mpView->SetQuickTextEditMode(sal_False);
235 bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor, sal_uInt16 nObjectIdentifier ) const
237 if( mpItemSet.get() == 0 )
238 return false;
239 if( !mpView || (!mpView->SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) )
240 return false;
241 return true;
244 void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats )
246 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
247 if( mpItemSet.get() && ( rMarkList.GetMarkCount() == 1 ) )
249 SdrObject* pObj( NULL );
250 bool bUndo = mpDoc->IsUndoEnabled();
252 if( bUndo && !mpView->GetTextEditOutlinerView() )
253 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
255 // n685123: ApplyFormatPaintBrush itself would store undo information
256 // except in a few cases (?)
257 if( pObj )
259 OUString sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
260 mpDoc->BegUndo( sLabel );
261 mpDoc->AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, sal_False, sal_True ) );
264 mpView->ApplyFormatPaintBrush( *mpItemSet.get(), bNoCharacterFormats, bNoParagraphFormats );
266 if( pObj )
268 mpDoc->EndUndo();
273 /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell& rDrawViewShell, SfxItemSet &rSet )
275 const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList();
276 const sal_uLong nMarkCount = rMarkList.GetMarkCount();
278 if( nMarkCount == 1 )
280 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
281 if( pObj && rDrawViewShell.GetDrawView()->SupportsFormatPaintbrush(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
282 return;
284 rSet.DisableItem( SID_FORMATPAINTBRUSH );
288 } // end of namespace sd
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */