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"
48 TYPEINIT1( FuFormatPaintBrush
, FuText
);
50 FuFormatPaintBrush::FuFormatPaintBrush( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
51 : FuText(pViewSh
, pWin
, pView
, pDoc
, rReq
)
52 , mbPermanent( false )
53 , mbOldIsQuickTextEditMode( true )
57 rtl::Reference
<FuPoor
> FuFormatPaintBrush::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
59 rtl::Reference
<FuPoor
> xFunc( new FuFormatPaintBrush( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
60 xFunc
->DoExecute( rReq
);
64 void FuFormatPaintBrush::DoExecute( SfxRequest
& rReq
)
66 const SfxItemSet
*pArgs
= rReq
.GetArgs();
67 if( pArgs
&& pArgs
->Count() >= 1 )
69 mbPermanent
= static_cast<bool>(static_cast<const SfxBoolItem
&>(pArgs
->Get(SID_FORMATPAINTBRUSH
)).GetValue());
74 mpView
->TakeFormatPaintBrush( mxItemSet
);
78 void FuFormatPaintBrush::implcancel()
80 if( mpViewShell
&& mpViewShell
->GetViewFrame() )
82 SfxViewFrame
* pViewFrame
= mpViewShell
->GetViewFrame();
83 pViewFrame
->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
84 pViewFrame
->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
88 static void unmarkimpl( SdrView
* pView
)
90 pView
->SdrEndTextEdit();
94 bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent
& rMEvt
)
99 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SdrMouseEventKind::BUTTONDOWN
, aVEvt
);
101 if( (eHit
== SDRHIT_TEXTEDIT
) || (eHit
== SDRHIT_TEXTEDITOBJ
&& ( mpViewShell
->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj
* >( aVEvt
.pObj
) != NULL
) ))
103 SdrObject
* pPickObj
=0;
105 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
106 mpView
->PickObj( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ),nHitLog
, pPickObj
, pPV
, SdrSearchOptions::PICKMARKABLE
);
108 if( (pPickObj
!= 0) && !pPickObj
->IsEmptyPresObj() )
110 // if we text hit another shape than the one currently selected, unselect the old one now
111 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
112 if( rMarkList
.GetMarkCount() > 0 )
114 if( rMarkList
.GetMarkCount() == 1 )
116 if( rMarkList
.GetMark(0)->GetMarkedSdrObj() != pPickObj
)
119 // if current selected shape is not that of the hit text edit, deselect it
120 unmarkimpl( mpView
);
125 // more than one shape selected, deselect all of them
126 unmarkimpl( mpView
);
129 MouseEvent
aMEvt( rMEvt
.GetPosPixel(), rMEvt
.GetClicks(), rMEvt
.GetMode(), rMEvt
.GetButtons(), 0 );
130 return FuText::MouseButtonDown(aMEvt
);
133 if( aVEvt
.pObj
== 0 )
134 aVEvt
.pObj
= pPickObj
;
137 unmarkimpl( mpView
);
141 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
142 bool bToggle
= false;
143 mpView
->MarkObj(mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ), nHitLog
, bToggle
, false);
150 bool FuFormatPaintBrush::MouseMove(const MouseEvent
& rMEvt
)
152 bool bReturn
= false;
153 if( mpWindow
&& mpView
)
155 if ( mpView
->IsTextEdit() )
157 bReturn
= FuText::MouseMove( rMEvt
);
158 mpWindow
->SetPointer(Pointer(PointerStyle::Fill
));
162 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
165 bool bOverMarkableObject
= mpView
->PickObj( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ),nHitLog
, pObj
, pPV
, SdrSearchOptions::PICKMARKABLE
);
167 if(bOverMarkableObject
&& HasContentForThisType(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
168 mpWindow
->SetPointer(Pointer(PointerStyle::Fill
));
170 mpWindow
->SetPointer(Pointer(PointerStyle::Arrow
));
176 bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent
& rMEvt
)
178 if( mxItemSet
.get() && mpView
&& mpView
->AreObjectsMarked() )
180 bool bNoCharacterFormats
= false;
181 bool bNoParagraphFormats
= false;
183 if( (rMEvt
.GetModifier()&KEY_MOD1
) && (rMEvt
.GetModifier()&KEY_SHIFT
) )
184 bNoCharacterFormats
= true;
185 else if( rMEvt
.GetModifier() & KEY_MOD1
)
186 bNoParagraphFormats
= true;
189 OutlinerView
* pOLV
= mpView
->GetTextEditOutlinerView();
191 pOLV
->MouseButtonUp(rMEvt
);
193 Paste( bNoCharacterFormats
, bNoParagraphFormats
);
195 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH
);
205 bool FuFormatPaintBrush::KeyInput(const KeyEvent
& rKEvt
)
207 if( (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
) && mpViewShell
)
212 return FuPoor::KeyInput(rKEvt
);
215 void FuFormatPaintBrush::Activate()
217 mbOldIsQuickTextEditMode
= mpViewShell
->GetFrameView()->IsQuickEdit();
218 if( !mbOldIsQuickTextEditMode
)
220 mpViewShell
->GetFrameView()->SetQuickEdit(true);
221 mpView
->SetQuickTextEditMode(true);
225 void FuFormatPaintBrush::Deactivate()
227 if( !mbOldIsQuickTextEditMode
)
229 mpViewShell
->GetFrameView()->SetQuickEdit(false);
230 mpView
->SetQuickTextEditMode(false);
234 bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor
, sal_uInt16 nObjectIdentifier
) const
236 if( mxItemSet
.get() == 0 )
238 if( !mpView
|| (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor
, nObjectIdentifier
) ) )
243 void FuFormatPaintBrush::Paste( bool bNoCharacterFormats
, bool bNoParagraphFormats
)
245 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
246 if( mxItemSet
.get() && ( rMarkList
.GetMarkCount() == 1 ) )
248 SdrObject
* pObj( NULL
);
249 bool bUndo
= mpDoc
->IsUndoEnabled();
251 if( bUndo
&& !mpView
->GetTextEditOutlinerView() )
252 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
254 // n685123: ApplyFormatPaintBrush itself would store undo information
255 // except in a few cases (?)
258 OUString
sLabel( mpViewShell
->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
259 mpDoc
->BegUndo( sLabel
);
260 mpDoc
->AddUndo( mpDoc
->GetSdrUndoFactory().CreateUndoAttrObject( *pObj
, false, true ) );
263 mpView
->ApplyFormatPaintBrush( *mxItemSet
.get(), bNoCharacterFormats
, bNoParagraphFormats
);
272 /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell
& rDrawViewShell
, SfxItemSet
&rSet
)
274 const SdrMarkList
& rMarkList
= rDrawViewShell
.GetDrawView()->GetMarkedObjectList();
276 if( rMarkList
.GetMarkCount() == 1 )
278 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
279 if( pObj
&& SdrObjEditView::SupportsFormatPaintbrush(pObj
->GetObjInventor(),pObj
->GetObjIdentifier()) )
282 rSet
.DisableItem( SID_FORMATPAINTBRUSH
);
285 } // end of namespace sd
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */