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>
43 FuFormatPaintBrush::FuFormatPaintBrush( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
44 : FuText(pViewSh
, pWin
, pView
, pDoc
, rReq
)
45 , mbPermanent( false )
46 , mbOldIsQuickTextEditMode( true )
50 rtl::Reference
<FuPoor
> FuFormatPaintBrush::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
52 rtl::Reference
<FuPoor
> xFunc( new FuFormatPaintBrush( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
53 xFunc
->DoExecute( rReq
);
57 void FuFormatPaintBrush::DoExecute( SfxRequest
& rReq
)
59 const SfxItemSet
*pArgs
= rReq
.GetArgs();
60 if( pArgs
&& pArgs
->Count() >= 1 )
62 mbPermanent
= pArgs
->Get(SID_FORMATPAINTBRUSH
).GetValue();
67 mpView
->TakeFormatPaintBrush( mxItemSet
);
71 void FuFormatPaintBrush::implcancel()
73 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
75 SfxViewFrame
* pViewFrame
= mpViewShell
->GetViewFrame();
76 pViewFrame
->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
77 pViewFrame
->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
81 static void unmarkimpl( SdrView
* pView
)
83 pView
->SdrEndTextEdit();
87 bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent
& rMEvt
)
92 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
94 if( (eHit
== SdrHitKind::TextEdit
) || (eHit
== SdrHitKind::TextEditObj
&& ( mpViewShell
->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj
* >( aVEvt
.pObj
) != nullptr ) ))
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() )
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 )
105 if( rMarkList
.GetMarkCount() == 1 )
107 if( rMarkList
.GetMark(0)->GetMarkedSdrObj() != pPickObj
)
110 // if current selected shape is not that of the hit text edit, deselect it
111 unmarkimpl( mpView
);
116 // more than one shape selected, deselect all of them
117 unmarkimpl( mpView
);
120 MouseEvent
aMEvt( rMEvt
.GetPosPixel(), rMEvt
.GetClicks(), rMEvt
.GetMode(), rMEvt
.GetButtons(), 0 );
121 return FuText::MouseButtonDown(aMEvt
);
124 if( aVEvt
.pObj
== nullptr )
125 aVEvt
.pObj
= pPickObj
;
128 unmarkimpl( mpView
);
132 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
133 mpView
->MarkObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ), nHitLog
, false/*bToggle*/);
140 bool FuFormatPaintBrush::MouseMove(const MouseEvent
& rMEvt
)
142 bool bReturn
= false;
143 if( mpWindow
&& mpView
)
145 if ( mpView
->IsTextEdit() )
147 bReturn
= FuText::MouseMove( rMEvt
);
148 mpWindow
->SetPointer(PointerStyle::Fill
);
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
);
158 mpWindow
->SetPointer(PointerStyle::Arrow
);
164 bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent
& rMEvt
)
166 if( mxItemSet
.get() && mpView
&& mpView
->AreObjectsMarked() )
168 bool bNoCharacterFormats
= false;
169 bool bNoParagraphFormats
= false;
171 if( (rMEvt
.GetModifier()&KEY_MOD1
) && (rMEvt
.GetModifier()&KEY_SHIFT
) )
172 bNoCharacterFormats
= true;
173 else if( rMEvt
.GetModifier() & KEY_MOD1
)
174 bNoParagraphFormats
= true;
177 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
179 pOLV
->MouseButtonUp(rMEvt
);
181 Paste( bNoCharacterFormats
, bNoParagraphFormats
);
183 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
193 bool FuFormatPaintBrush::KeyInput(const KeyEvent
& rKEvt
)
195 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
200 return FuPoor::KeyInput(rKEvt
);
203 void FuFormatPaintBrush::Activate()
205 mbOldIsQuickTextEditMode
= mpViewShell
->GetFrameView()->IsQuickEdit();
206 if( !mbOldIsQuickTextEditMode
)
208 mpViewShell
->GetFrameView()->SetQuickEdit(true);
209 mpView
->SetQuickTextEditMode(true);
213 void FuFormatPaintBrush::Deactivate()
215 if( !mbOldIsQuickTextEditMode
)
217 mpViewShell
->GetFrameView()->SetQuickEdit(false);
218 mpView
->SetQuickTextEditMode(false);
222 bool FuFormatPaintBrush::HasContentForThisType( SdrInventor nObjectInventor
, sal_uInt16 nObjectIdentifier
) const
224 if (mxItemSet
== nullptr)
226 if( !mpView
|| (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor
, nObjectIdentifier
) ) )
231 void FuFormatPaintBrush::Paste( bool bNoCharacterFormats
, bool bNoParagraphFormats
)
233 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
234 if( !(mxItemSet
.get() && ( rMarkList
.GetMarkCount() == 1 )) )
237 SdrObject
* pObj( nullptr );
238 bool bUndo
= mpDoc
->IsUndoEnabled();
240 if( bUndo
&& !mpView
->GetTextEditOutlinerView() )
241 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
243 // n685123: ApplyFormatPaintBrush itself would store undo information
244 // except in a few cases (?)
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 ) );
253 mpView
->ApplyFormatPaintBrush( *mxItemSet
, bNoCharacterFormats
, bNoParagraphFormats
);
261 /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell
const & rDrawViewShell
, SfxItemSet
&rSet
)
263 const SdrMarkList
& rMarkList
= rDrawViewShell
.GetDrawView()->GetMarkedObjectList();
265 if( rMarkList
.GetMarkCount() == 1 )
267 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
268 if( pObj
&& SdrObjEditView::SupportsFormatPaintbrush(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
271 rSet
.DisableItem( SID_FORMATPAINTBRUSH
);
274 } // end of namespace sd
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */