1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <sfx2/request.hxx>
21 #include <sfx2/bindings.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/viewfrm.hxx>
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>
31 #include <fuformatpaintbrush.hxx>
32 #include <drawview.hxx>
33 #include <DrawViewShell.hxx>
34 #include <FrameView.hxx>
35 #include <drawdoc.hxx>
36 #include <ViewShellBase.hxx>
42 // Paragraph properties are pasted if the selection contains a whole paragraph
43 bool ShouldPasteParaFormatPerSelection(const OutlinerView
* pOLV
)
48 if(!pOLV
->GetEditView().HasSelection())
51 if(!pOLV
->GetEditView().IsSelectionWithinSinglePara())
54 return pOLV
->GetEditView().IsSelectionFullPara();
61 FuFormatPaintBrush::FuFormatPaintBrush( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
62 : FuText(pViewSh
, pWin
, pView
, pDoc
, rReq
)
64 , mbPermanent( false )
65 , mbOldIsQuickTextEditMode(true)
69 rtl::Reference
<FuPoor
> FuFormatPaintBrush::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
71 rtl::Reference
<FuPoor
> xFunc( new FuFormatPaintBrush( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
72 xFunc
->DoExecute( rReq
);
76 void FuFormatPaintBrush::DoExecute( SfxRequest
& rReq
)
78 const SfxItemSet
*pArgs
= rReq
.GetArgs();
79 if( pArgs
&& pArgs
->Count() >= 1 )
81 mbPermanent
= pArgs
->Get(SID_FORMATPAINTBRUSH
).GetValue();
86 mnDepth
= mpView
->TakeFormatPaintBrush( mxItemSet
);
90 void FuFormatPaintBrush::implcancel()
92 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
94 SfxViewFrame
* pViewFrame
= mpViewShell
->GetViewFrame();
95 pViewFrame
->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
96 pViewFrame
->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
100 static void unmarkimpl( SdrView
* pView
)
102 pView
->SdrEndTextEdit();
106 bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent
& rMEvt
)
111 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
113 if( (eHit
== SdrHitKind::TextEdit
) || (eHit
== SdrHitKind::TextEditObj
&& ( mpViewShell
->GetFrameView()->IsQuickEdit() || dynamic_cast<sdr::table::SdrTableObj
*>(aVEvt
.mpObj
) != nullptr ) ))
115 SdrPageView
* pPV
=nullptr;
116 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
117 SdrObject
* pPickObj
= mpView
->PickObj(mpWindow
->PixelToLogic(rMEvt
.GetPosPixel()),nHitLog
, pPV
, SdrSearchOptions::PICKMARKABLE
);
118 if( (pPickObj
!= nullptr) && !pPickObj
->IsEmptyPresObj() )
120 // if we text hit another shape than the one currently selected, unselect the old one now
121 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
122 if( rMarkList
.GetMarkCount() > 0 )
124 if( rMarkList
.GetMarkCount() == 1 )
126 if( rMarkList
.GetMark(0)->GetMarkedSdrObj() != pPickObj
)
129 // if current selected shape is not that of the hit text edit, deselect it
130 unmarkimpl( mpView
);
135 // more than one shape selected, deselect all of them
136 unmarkimpl( mpView
);
139 MouseEvent
aMEvt( rMEvt
.GetPosPixel(), rMEvt
.GetClicks(), rMEvt
.GetMode(), rMEvt
.GetButtons(), 0 );
140 return FuText::MouseButtonDown(aMEvt
);
143 if (aVEvt
.mpObj
== nullptr)
144 aVEvt
.mpObj
= pPickObj
;
147 unmarkimpl( mpView
);
151 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
152 mpView
->MarkObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ), nHitLog
, false/*bToggle*/);
160 bool FuFormatPaintBrush::MouseMove(const MouseEvent
& rMEvt
)
162 bool bReturn
= false;
163 if( mpWindow
&& mpView
)
165 if ( mpView
->IsTextEdit() )
167 bReturn
= FuText::MouseMove( rMEvt
);
168 mpWindow
->SetPointer(PointerStyle::Fill
);
172 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
173 SdrPageView
* pPV
=nullptr;
174 SdrObject
* pObj
= mpView
->PickObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ),nHitLog
, pPV
, SdrSearchOptions::PICKMARKABLE
);
175 if (pObj
&& HasContentForThisType(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
176 mpWindow
->SetPointer(PointerStyle::Fill
);
178 mpWindow
->SetPointer(PointerStyle::Arrow
);
184 bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent
& rMEvt
)
186 if( mxItemSet
&& mpView
&& mpView
->GetMarkedObjectList().GetMarkCount() != 0 )
188 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
190 bool bNoCharacterFormats
= false;
191 bool bNoParagraphFormats
= !ShouldPasteParaFormatPerSelection(pOLV
);
193 if ((rMEvt
.GetModifier() & KEY_MOD1
) && (rMEvt
.GetModifier() & KEY_SHIFT
))
195 bNoCharacterFormats
= true;
196 bNoParagraphFormats
= false;
198 else if (rMEvt
.GetModifier() & KEY_MOD1
)
200 bNoParagraphFormats
= true;
204 pOLV
->MouseButtonUp(rMEvt
);
206 Paste( bNoCharacterFormats
, bNoParagraphFormats
);
208 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
218 bool FuFormatPaintBrush::KeyInput(const KeyEvent
& rKEvt
)
220 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
225 return FuPoor::KeyInput(rKEvt
);
228 void FuFormatPaintBrush::Activate()
230 mbOldIsQuickTextEditMode
= mpViewShell
->GetFrameView()->IsQuickEdit();
231 if( !mbOldIsQuickTextEditMode
)
233 mpViewShell
->GetFrameView()->SetQuickEdit(true);
234 mpView
->SetQuickTextEditMode(true);
238 void FuFormatPaintBrush::Deactivate()
240 if( !mbOldIsQuickTextEditMode
)
242 mpViewShell
->GetFrameView()->SetQuickEdit(false);
243 mpView
->SetQuickTextEditMode(false);
247 bool FuFormatPaintBrush::HasContentForThisType( SdrInventor nObjectInventor
, SdrObjKind nObjectIdentifier
) const
249 if (mxItemSet
== nullptr)
251 if( !mpView
|| (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor
, nObjectIdentifier
) ) )
256 void FuFormatPaintBrush::Paste( bool bNoCharacterFormats
, bool bNoParagraphFormats
)
258 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
259 if( !(mxItemSet
&& ( rMarkList
.GetMarkCount() == 1 )) )
262 SdrObject
* pObj( nullptr );
263 bool bUndo
= mpDoc
->IsUndoEnabled();
265 if( bUndo
&& !mpView
->GetTextEditOutlinerView() )
266 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
268 // n685123: ApplyFormatPaintBrush itself would store undo information
269 // except in a few cases (?)
272 OUString
sLabel( mpViewShell
->GetViewShellBase().RetrieveLabelFromCommand(u
".uno:FormatPaintbrush"_ustr
) );
273 mpDoc
->BegUndo( sLabel
);
274 if (dynamic_cast< sdr::table::SdrTableObj
* >( pObj
) == nullptr)
275 mpDoc
->AddUndo( mpDoc
->GetSdrUndoFactory().CreateUndoAttrObject( *pObj
, false, true ) );
278 mpView
->ApplyFormatPaintBrush( *mxItemSet
, mnDepth
, bNoCharacterFormats
, bNoParagraphFormats
);
286 /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell
const & rDrawViewShell
, SfxItemSet
&rSet
)
288 const SdrMarkList
& rMarkList
= rDrawViewShell
.GetDrawView()->GetMarkedObjectList();
290 if( rMarkList
.GetMarkCount() == 1 )
292 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
294 SdrObjEditView::SupportsFormatPaintbrush(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
297 rSet
.DisableItem( SID_FORMATPAINTBRUSH
);
300 } // end of namespace sd
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */