LibreOffice Module sd (master) 1
fuformatpaintbrush.cxx
Go to the documentation of this file.
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 <sfx2/request.hxx>
21#include <sfx2/bindings.hxx>
22#include <sfx2/dispatch.hxx>
23#include <sfx2/viewfrm.hxx>
24
25#include <svx/svxids.hrc>
26#include <svx/svdotable.hxx>
27#include <svx/svdundo.hxx>
28#include <editeng/outliner.hxx>
29#include <vcl/ptrstyle.hxx>
30
32#include <drawview.hxx>
33#include <DrawViewShell.hxx>
34#include <FrameView.hxx>
35#include <drawdoc.hxx>
36#include <ViewShellBase.hxx>
37
38#include <Window.hxx>
39
40namespace sd {
41
42
44: FuText(pViewSh, pWin, pView, pDoc, rReq)
45, mbPermanent( false )
46, mbOldIsQuickTextEditMode( true )
47{
48}
49
51{
52 rtl::Reference<FuPoor> xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) );
53 xFunc->DoExecute( rReq );
54 return xFunc;
55}
56
58{
59 const SfxItemSet *pArgs = rReq.GetArgs();
60 if( pArgs && pArgs->Count() >= 1 )
61 {
62 mbPermanent = pArgs->Get(SID_FORMATPAINTBRUSH).GetValue();
63 }
64
65 if( mpView )
66 {
68 }
69}
70
72{
74 {
75 SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
76 pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
77 pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
78 }
79}
80
81static void unmarkimpl( SdrView* pView )
82{
83 pView->SdrEndTextEdit();
84 pView->UnMarkAll();
85}
86
88{
89 if(mpView&&mpWindow)
90 {
91 SdrViewEvent aVEvt;
92 SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
93
94 if( (eHit == SdrHitKind::TextEdit) || (eHit == SdrHitKind::TextEditObj && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast<sdr::table::SdrTableObj*>(aVEvt.mpObj) != nullptr ) ))
95 {
96 SdrPageView* pPV=nullptr;
97 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
98 SdrObject* pPickObj = mpView->PickObj(mpWindow->PixelToLogic(rMEvt.GetPosPixel()),nHitLog, pPV, SdrSearchOptions::PICKMARKABLE);
99 if( (pPickObj != nullptr) && !pPickObj->IsEmptyPresObj() )
100 {
101 // if we text hit another shape than the one currently selected, unselect the old one now
102 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
103 if( rMarkList.GetMarkCount() > 0 )
104 {
105 if( rMarkList.GetMarkCount() == 1 )
106 {
107 if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj )
108 {
109
110 // if current selected shape is not that of the hit text edit, deselect it
112 }
113 }
114 else
115 {
116 // more than one shape selected, deselect all of them
118 }
119 }
120 MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 );
121 return FuText::MouseButtonDown(aMEvt);
122 }
123
124 if (aVEvt.mpObj == nullptr)
125 aVEvt.mpObj = pPickObj;
126 }
127
129
130 if (aVEvt.mpObj)
131 {
132 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
133 mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, false/*bToggle*/);
134 return true;
135 }
136 }
137 return false;
138}
139
141{
142 bool bReturn = false;
143 if( mpWindow && mpView )
144 {
145 if ( mpView->IsTextEdit() )
146 {
147 bReturn = FuText::MouseMove( rMEvt );
148 mpWindow->SetPointer(PointerStyle::Fill);
149 }
150 else
151 {
152 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
153 SdrPageView* pPV=nullptr;
154 SdrObject* pObj = mpView->PickObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPV, SdrSearchOptions::PICKMARKABLE);
155 if (pObj && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
156 mpWindow->SetPointer(PointerStyle::Fill);
157 else
158 mpWindow->SetPointer(PointerStyle::Arrow);
159 }
160 }
161 return bReturn;
162}
163
165{
167 {
168 bool bNoCharacterFormats = false;
169 bool bNoParagraphFormats = false;
170 {
171 if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
172 bNoCharacterFormats = true;
173 else if( rMEvt.GetModifier() & KEY_MOD1 )
174 bNoParagraphFormats = true;
175 }
176
178 if( pOLV )
179 pOLV->MouseButtonUp(rMEvt);
180
181 Paste( bNoCharacterFormats, bNoParagraphFormats );
182 if(mpViewShell)
183 mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
184
185 if( mbPermanent )
186 return true;
187 }
188
189 implcancel();
190 return true;
191}
192
194{
195 if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
196 {
197 implcancel();
198 return true;
199 }
200 return FuPoor::KeyInput(rKEvt);
201}
202
204{
207 {
210 }
211}
212
214{
216 {
219 }
220}
221
222bool FuFormatPaintBrush::HasContentForThisType( SdrInventor nObjectInventor, SdrObjKind nObjectIdentifier ) const
223{
224 if (mxItemSet == nullptr)
225 return false;
226 if( !mpView || (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) )
227 return false;
228 return true;
229}
230
231void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats )
232{
233 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
234 if( !(mxItemSet && ( rMarkList.GetMarkCount() == 1 )) )
235 return;
236
237 SdrObject* pObj( nullptr );
238 bool bUndo = mpDoc->IsUndoEnabled();
239
240 if( bUndo && !mpView->GetTextEditOutlinerView() )
241 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
242
243 // n685123: ApplyFormatPaintBrush itself would store undo information
244 // except in a few cases (?)
245 if( pObj )
246 {
247 OUString sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
248 mpDoc->BegUndo( sLabel );
249 if (dynamic_cast< sdr::table::SdrTableObj* >( pObj ) == nullptr)
250 mpDoc->AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, false, true ) );
251 }
252
253 mpView->ApplyFormatPaintBrush( *mxItemSet, bNoCharacterFormats, bNoParagraphFormats );
254
255 if( pObj )
256 {
257 mpDoc->EndUndo();
258 }
259}
260
261/* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell const & rDrawViewShell, SfxItemSet &rSet )
262{
263 const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList();
264
265 if( rMarkList.GetMarkCount() == 1 )
266 {
267 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
269 return;
270 }
271 rSet.DisableItem( SID_FORMATPAINTBRUSH );
272}
273
274} // end of namespace sd
275
276/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const vcl::KeyCode & GetKeyCode() const
MouseEventModifiers GetMode() const
sal_uInt16 GetModifier() const
sal_uInt16 GetClicks() const
sal_uInt16 GetButtons() const
const Point & GetPosPixel() const
bool MouseButtonUp(const MouseEvent &)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
void UnMarkAll(SdrPageView const *pPV=nullptr)
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrObject * GetMarkedSdrObj() const
void BegUndo()
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
SdrUndoFactory & GetSdrUndoFactory() const
bool IsUndoEnabled() const
void EndUndo()
static bool SupportsFormatPaintbrush(SdrInventor nObjectInventor, SdrObjKind nObjectIdentifier)
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false)
const OutlinerView * GetTextEditOutlinerView() const
void TakeFormatPaintBrush(std::shared_ptr< SfxItemSet > &rFormatSet)
void ApplyFormatPaintBrush(SfxItemSet &rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats)
virtual bool IsTextEdit() const final override
void SetQuickTextEditMode(bool bOn)
virtual SdrInventor GetObjInventor() const
bool IsEmptyPresObj() const
virtual SdrObjKind GetObjIdentifier() const
virtual std::unique_ptr< SdrUndoAction > CreateUndoAttrObject(SdrObject &rObject, bool bStyleSheet1=false, bool bSaveText=false)
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
sal_uInt16 Count() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void DisableItem(sal_uInt16 nWhich)
const SfxItemSet * GetArgs() const
SfxBindings & GetBindings()
SfxDispatcher * GetDispatcher()
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
DrawView * GetDrawView() const
void SetQuickEdit(bool bQEdit)
Definition: FrameView.hxx:122
bool IsQuickEdit() const
Definition: FrameView.hxx:124
static void GetMenuState(DrawViewShell const &rDrawViewShell, SfxItemSet &rSet)
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
virtual void Activate() override
activates the function
virtual bool MouseMove(const MouseEvent &rMEvt) override
void DoExecute(SfxRequest &rReq) override
std::shared_ptr< SfxItemSet > mxItemSet
bool HasContentForThisType(SdrInventor nObjectInventor, SdrObjKind nObjectIdentifier) const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
virtual void Deactivate() override
deactivates the function
virtual bool KeyInput(const KeyEvent &rKEvt) override
handle keyboard events
FuFormatPaintBrush(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
virtual bool KeyInput(const KeyEvent &rKEvt)
handle keyboard events
Definition: fupoor.cxx:175
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
ViewShell * mpViewShell
Definition: fupoor.hxx:145
::sd::View * mpView
Definition: fupoor.hxx:144
static const int HITPIX
Definition: fupoor.hxx:50
Base class for text functions.
Definition: futext.hxx:36
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: futext.cxx:484
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: futext.cxx:246
OUString RetrieveLabelFromCommand(const OUString &aCmdURL) const
returns the ui descriptive name for the given uno slot.
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
FrameView * GetFrameView()
Definition: ViewShell.hxx:221
SD_DLLPUBLIC ViewShellBase & GetViewShellBase() const
Definition: viewshel.cxx:1397
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
sal_uInt16 GetCode() const
constexpr sal_uInt16 KEY_ESCAPE
constexpr sal_uInt16 KEY_MOD1
constexpr sal_uInt16 KEY_SHIFT
static void unmarkimpl(SdrView *pView)
static SfxItemSet & rSet
SdrObject * mpObj
SdrHitKind
SdrInventor
SdrObjKind