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>
24 #include <svl/itemiter.hxx>
26 #include <svx/globl3d.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/svdotable.hxx>
29 #include <editeng/outliner.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <editeng/editeng.hxx>
35 #include <fuformatpaintbrush.hxx>
36 #include <drawview.hxx>
37 #include <DrawDocShell.hxx>
38 #include <DrawViewShell.hxx>
39 #include <FrameView.hxx>
40 #include <drawdoc.hxx>
41 #include <Outliner.hxx>
42 #include <ViewShellBase.hxx>
49 FuFormatPaintBrush::FuFormatPaintBrush( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
50 : FuText(pViewSh
, pWin
, pView
, pDoc
, rReq
)
51 , mbPermanent( false )
52 , mbOldIsQuickTextEditMode( true )
56 rtl::Reference
<FuPoor
> FuFormatPaintBrush::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
58 rtl::Reference
<FuPoor
> xFunc( new FuFormatPaintBrush( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
59 xFunc
->DoExecute( rReq
);
63 void FuFormatPaintBrush::DoExecute( SfxRequest
& rReq
)
65 const SfxItemSet
*pArgs
= rReq
.GetArgs();
66 if( pArgs
&& pArgs
->Count() >= 1 )
68 mbPermanent
= pArgs
->Get(SID_FORMATPAINTBRUSH
).GetValue();
73 mpView
->TakeFormatPaintBrush( mxItemSet
);
77 void FuFormatPaintBrush::implcancel()
79 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
81 SfxViewFrame
* pViewFrame
= mpViewShell
->GetViewFrame();
82 pViewFrame
->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
83 pViewFrame
->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
87 static void unmarkimpl( SdrView
* pView
)
89 pView
->SdrEndTextEdit();
93 bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent
& rMEvt
)
98 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
100 if( (eHit
== SdrHitKind::TextEdit
) || (eHit
== SdrHitKind::TextEditObj
&& ( mpViewShell
->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj
* >( aVEvt
.pObj
) != nullptr ) ))
102 SdrPageView
* pPV
=nullptr;
103 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
104 SdrObject
* pPickObj
= mpView
->PickObj(mpWindow
->PixelToLogic(rMEvt
.GetPosPixel()),nHitLog
, pPV
, SdrSearchOptions::PICKMARKABLE
);
105 if( (pPickObj
!= nullptr) && !pPickObj
->IsEmptyPresObj() )
107 // if we text hit another shape than the one currently selected, unselect the old one now
108 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
109 if( rMarkList
.GetMarkCount() > 0 )
111 if( rMarkList
.GetMarkCount() == 1 )
113 if( rMarkList
.GetMark(0)->GetMarkedSdrObj() != pPickObj
)
116 // if current selected shape is not that of the hit text edit, deselect it
117 unmarkimpl( mpView
);
122 // more than one shape selected, deselect all of them
123 unmarkimpl( mpView
);
126 MouseEvent
aMEvt( rMEvt
.GetPosPixel(), rMEvt
.GetClicks(), rMEvt
.GetMode(), rMEvt
.GetButtons(), 0 );
127 return FuText::MouseButtonDown(aMEvt
);
130 if( aVEvt
.pObj
== nullptr )
131 aVEvt
.pObj
= pPickObj
;
134 unmarkimpl( mpView
);
138 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
139 mpView
->MarkObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ), nHitLog
, false/*bToggle*/);
146 bool FuFormatPaintBrush::MouseMove(const MouseEvent
& rMEvt
)
148 bool bReturn
= false;
149 if( mpWindow
&& mpView
)
151 if ( mpView
->IsTextEdit() )
153 bReturn
= FuText::MouseMove( rMEvt
);
154 mpWindow
->SetPointer(Pointer(PointerStyle::Fill
));
158 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
159 SdrPageView
* pPV
=nullptr;
160 SdrObject
* pObj
= mpView
->PickObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ),nHitLog
, pPV
, SdrSearchOptions::PICKMARKABLE
);
161 if (pObj
&& HasContentForThisType(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
162 mpWindow
->SetPointer(Pointer(PointerStyle::Fill
));
164 mpWindow
->SetPointer(Pointer(PointerStyle::Arrow
));
170 bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent
& rMEvt
)
172 if( mxItemSet
.get() && mpView
&& mpView
->AreObjectsMarked() )
174 bool bNoCharacterFormats
= false;
175 bool bNoParagraphFormats
= false;
177 if( (rMEvt
.GetModifier()&KEY_MOD1
) && (rMEvt
.GetModifier()&KEY_SHIFT
) )
178 bNoCharacterFormats
= true;
179 else if( rMEvt
.GetModifier() & KEY_MOD1
)
180 bNoParagraphFormats
= true;
183 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
185 pOLV
->MouseButtonUp(rMEvt
);
187 Paste( bNoCharacterFormats
, bNoParagraphFormats
);
189 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
199 bool FuFormatPaintBrush::KeyInput(const KeyEvent
& rKEvt
)
201 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
206 return FuPoor::KeyInput(rKEvt
);
209 void FuFormatPaintBrush::Activate()
211 mbOldIsQuickTextEditMode
= mpViewShell
->GetFrameView()->IsQuickEdit();
212 if( !mbOldIsQuickTextEditMode
)
214 mpViewShell
->GetFrameView()->SetQuickEdit(true);
215 mpView
->SetQuickTextEditMode(true);
219 void FuFormatPaintBrush::Deactivate()
221 if( !mbOldIsQuickTextEditMode
)
223 mpViewShell
->GetFrameView()->SetQuickEdit(false);
224 mpView
->SetQuickTextEditMode(false);
228 bool FuFormatPaintBrush::HasContentForThisType( SdrInventor nObjectInventor
, sal_uInt16 nObjectIdentifier
) const
230 if( mxItemSet
.get() == nullptr )
232 if( !mpView
|| (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor
, nObjectIdentifier
) ) )
237 void FuFormatPaintBrush::Paste( bool bNoCharacterFormats
, bool bNoParagraphFormats
)
239 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
240 if( mxItemSet
.get() && ( rMarkList
.GetMarkCount() == 1 ) )
242 SdrObject
* pObj( nullptr );
243 bool bUndo
= mpDoc
->IsUndoEnabled();
245 if( bUndo
&& !mpView
->GetTextEditOutlinerView() )
246 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
248 // n685123: ApplyFormatPaintBrush itself would store undo information
249 // except in a few cases (?)
252 OUString
sLabel( mpViewShell
->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
253 mpDoc
->BegUndo( sLabel
);
254 if (dynamic_cast< sdr::table::SdrTableObj
* >( pObj
) == nullptr)
255 mpDoc
->AddUndo( mpDoc
->GetSdrUndoFactory().CreateUndoAttrObject( *pObj
, false, true ) );
258 mpView
->ApplyFormatPaintBrush( *mxItemSet
.get(), bNoCharacterFormats
, bNoParagraphFormats
);
267 /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell
const & rDrawViewShell
, SfxItemSet
&rSet
)
269 const SdrMarkList
& rMarkList
= rDrawViewShell
.GetDrawView()->GetMarkedObjectList();
271 if( rMarkList
.GetMarkCount() == 1 )
273 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
274 if( pObj
&& SdrObjEditView::SupportsFormatPaintbrush(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
277 rSet
.DisableItem( SID_FORMATPAINTBRUSH
);
280 } // end of namespace sd
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */