1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10*5b190011SAndrew Rist *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19*5b190011SAndrew Rist *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <sfx2/request.hxx>
28cdf0e10cSrcweir #include <sfx2/bindings.hxx>
29cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <svl/itemiter.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svx/globl3d.hxx>
34cdf0e10cSrcweir #include <svx/svxids.hrc>
35cdf0e10cSrcweir #include <svx/svdotable.hxx>
36cdf0e10cSrcweir #include <editeng/outliner.hxx>
37cdf0e10cSrcweir #include <editeng/eeitem.hxx>
38cdf0e10cSrcweir #include <editeng/editeng.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #define _SD_DLL // fuer SD_MOD()
41cdf0e10cSrcweir #include "sdmod.hxx"
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include "fuformatpaintbrush.hxx"
44cdf0e10cSrcweir #include "drawview.hxx"
45cdf0e10cSrcweir #include "DrawDocShell.hxx"
46cdf0e10cSrcweir #include "DrawViewShell.hxx"
47cdf0e10cSrcweir #include "FrameView.hxx"
48cdf0e10cSrcweir #include "drawdoc.hxx"
49cdf0e10cSrcweir #include "Outliner.hxx"
50cdf0e10cSrcweir #include "ViewShellBase.hxx"
51cdf0e10cSrcweir
52cdf0e10cSrcweir #ifndef SD_WINDOW_SHELL_HXX
53cdf0e10cSrcweir #include "Window.hxx"
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace sd {
57cdf0e10cSrcweir
58cdf0e10cSrcweir TYPEINIT1( FuFormatPaintBrush, FuText );
59cdf0e10cSrcweir
FuFormatPaintBrush(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)60cdf0e10cSrcweir FuFormatPaintBrush::FuFormatPaintBrush( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
61cdf0e10cSrcweir : FuText(pViewSh, pWin, pView, pDoc, rReq)
62cdf0e10cSrcweir , mbPermanent( false )
63cdf0e10cSrcweir , mbOldIsQuickTextEditMode( true )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)67cdf0e10cSrcweir FunctionReference FuFormatPaintBrush::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir FunctionReference xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) );
70cdf0e10cSrcweir xFunc->DoExecute( rReq );
71cdf0e10cSrcweir return xFunc;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
DoExecute(SfxRequest & rReq)74cdf0e10cSrcweir void FuFormatPaintBrush::DoExecute( SfxRequest& rReq )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir const SfxItemSet *pArgs = rReq.GetArgs();
77cdf0e10cSrcweir if( pArgs && pArgs->Count() >= 1 )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir mbPermanent = static_cast<bool>(((SfxBoolItem &)pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue());
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir if( mpView )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir mpView->TakeFormatPaintBrush( mpItemSet );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
implcancel()88cdf0e10cSrcweir void FuFormatPaintBrush::implcancel()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir if( mpViewShell && mpViewShell->GetViewFrame() )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
93cdf0e10cSrcweir pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
94cdf0e10cSrcweir pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
unmarkimpl(SdrView * pView)98cdf0e10cSrcweir static void unmarkimpl( SdrView* pView )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir pView->SdrEndTextEdit();
101cdf0e10cSrcweir pView->UnMarkAll();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMEvt)104cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent& rMEvt)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir if(mpView&&mpWindow)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir SdrViewEvent aVEvt;
109cdf0e10cSrcweir SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
110cdf0e10cSrcweir
111cdf0e10cSrcweir if( (eHit == SDRHIT_TEXTEDIT) || (eHit == SDRHIT_TEXTEDITOBJ && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj* >( aVEvt.pObj ) != NULL ) ))
112cdf0e10cSrcweir {
113cdf0e10cSrcweir SdrObject* pPickObj=0;
114cdf0e10cSrcweir SdrPageView* pPV=0;
115cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
116cdf0e10cSrcweir mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPickObj, pPV, SDRSEARCH_PICKMARKABLE);
117cdf0e10cSrcweir
118cdf0e10cSrcweir if( (pPickObj != 0) && !pPickObj->IsEmptyPresObj() )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir // if we text hit another shape than the one currently selected, unselect the old one now
121cdf0e10cSrcweir const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
122cdf0e10cSrcweir if( rMarkList.GetMarkCount() >= 1 )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir if( rMarkList.GetMarkCount() == 1 )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir
129cdf0e10cSrcweir // if current selected shape is not that of the hit text edit, deselect it
130cdf0e10cSrcweir unmarkimpl( mpView );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir else
134cdf0e10cSrcweir {
135cdf0e10cSrcweir // more than one shape selected, deselect all of them
136cdf0e10cSrcweir unmarkimpl( mpView );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 );
140cdf0e10cSrcweir return FuText::MouseButtonDown(aMEvt);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir if( aVEvt.pObj == 0 )
144cdf0e10cSrcweir aVEvt.pObj = pPickObj;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir unmarkimpl( mpView );
148cdf0e10cSrcweir
149cdf0e10cSrcweir if( aVEvt.pObj )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
152cdf0e10cSrcweir sal_Bool bToggle = sal_False;
153cdf0e10cSrcweir mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, bToggle, sal_False);
154cdf0e10cSrcweir return sal_True;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir return sal_False;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
MouseMove(const MouseEvent & rMEvt)160cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseMove(const MouseEvent& rMEvt)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir sal_Bool bReturn = sal_False;
163cdf0e10cSrcweir if( mpWindow && mpView )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir if ( mpView->IsTextEdit() )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir bReturn = FuText::MouseMove( rMEvt );
168cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_FILL));
169cdf0e10cSrcweir }
170cdf0e10cSrcweir else
171cdf0e10cSrcweir {
172cdf0e10cSrcweir sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
173cdf0e10cSrcweir SdrObject* pObj=0;
174cdf0e10cSrcweir SdrPageView* pPV=0;
175cdf0e10cSrcweir sal_Bool bOverMarkableObject = mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pObj, pPV, SDRSEARCH_PICKMARKABLE);
176cdf0e10cSrcweir
177cdf0e10cSrcweir if(bOverMarkableObject && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
178cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_FILL));
179cdf0e10cSrcweir else
180cdf0e10cSrcweir mpWindow->SetPointer(Pointer(POINTER_ARROW));
181cdf0e10cSrcweir }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir return bReturn;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
MouseButtonUp(const MouseEvent & rMEvt)186cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir if( mpItemSet.get() && mpView && mpView->AreObjectsMarked() )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir bool bNoCharacterFormats = false;
191cdf0e10cSrcweir bool bNoParagraphFormats = false;
192cdf0e10cSrcweir {
193cdf0e10cSrcweir if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
194cdf0e10cSrcweir bNoCharacterFormats = true;
195cdf0e10cSrcweir else if( rMEvt.GetModifier() & KEY_MOD1 )
196cdf0e10cSrcweir bNoParagraphFormats = true;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
200cdf0e10cSrcweir if( pOLV )
201cdf0e10cSrcweir pOLV->MouseButtonUp(rMEvt);
202cdf0e10cSrcweir
203cdf0e10cSrcweir Paste( bNoCharacterFormats, bNoParagraphFormats );
204cdf0e10cSrcweir if(mpViewShell)
205cdf0e10cSrcweir mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
206cdf0e10cSrcweir
207cdf0e10cSrcweir if( mbPermanent )
208cdf0e10cSrcweir return sal_True;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir
211cdf0e10cSrcweir implcancel();
212cdf0e10cSrcweir return sal_True;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvt)215cdf0e10cSrcweir sal_Bool FuFormatPaintBrush::KeyInput(const KeyEvent& rKEvt)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir if( (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) && mpViewShell )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir implcancel();
220cdf0e10cSrcweir return sal_True;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir return FuPoor::KeyInput(rKEvt);
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
Activate()225cdf0e10cSrcweir void FuFormatPaintBrush::Activate()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir mbOldIsQuickTextEditMode = mpViewShell->GetFrameView()->IsQuickEdit();
228cdf0e10cSrcweir if( !mbOldIsQuickTextEditMode )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir mpViewShell->GetFrameView()->SetQuickEdit(sal_True);
231cdf0e10cSrcweir mpView->SetQuickTextEditMode(sal_True);
232cdf0e10cSrcweir }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
Deactivate()235cdf0e10cSrcweir void FuFormatPaintBrush::Deactivate()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir if( !mbOldIsQuickTextEditMode )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir mpViewShell->GetFrameView()->SetQuickEdit(sal_False);
240cdf0e10cSrcweir mpView->SetQuickTextEditMode(sal_False);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
HasContentForThisType(sal_uInt32 nObjectInventor,sal_uInt16 nObjectIdentifier) const244cdf0e10cSrcweir bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor, sal_uInt16 nObjectIdentifier ) const
245cdf0e10cSrcweir {
246cdf0e10cSrcweir if( mpItemSet.get() == 0 )
247cdf0e10cSrcweir return false;
248cdf0e10cSrcweir if( !mpView || (!mpView->SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) )
249cdf0e10cSrcweir return false;
250cdf0e10cSrcweir return true;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
Paste(bool bNoCharacterFormats,bool bNoParagraphFormats)253cdf0e10cSrcweir void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
256cdf0e10cSrcweir if(mpItemSet.get() && (rMarkList.GetMarkCount() == 1) )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
259cdf0e10cSrcweir
260cdf0e10cSrcweir if( mpDoc->IsUndoEnabled() )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir String sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FormatPaintbrush" ) ) ) );
263cdf0e10cSrcweir mpDoc->BegUndo( sLabel );
264cdf0e10cSrcweir mpDoc->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoAttrObject(*pObj,sal_False,sal_True));
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
267cdf0e10cSrcweir mpView->ApplyFormatPaintBrush( *mpItemSet.get(), bNoCharacterFormats, bNoParagraphFormats );
268cdf0e10cSrcweir
269cdf0e10cSrcweir if( mpDoc->IsUndoEnabled() )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir mpDoc->EndUndo();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
GetMenuState(DrawViewShell & rDrawViewShell,SfxItemSet & rSet)276cdf0e10cSrcweir /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell& rDrawViewShell, SfxItemSet &rSet )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList();
279cdf0e10cSrcweir const sal_uLong nMarkCount = rMarkList.GetMarkCount();
280cdf0e10cSrcweir
281cdf0e10cSrcweir if( nMarkCount == 1 )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
284cdf0e10cSrcweir if( pObj && rDrawViewShell.GetDrawView()->SupportsFormatPaintbrush(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
285cdf0e10cSrcweir return;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir rSet.DisableItem( SID_FORMATPAINTBRUSH );
288cdf0e10cSrcweir }
289cdf0e10cSrcweir
290cdf0e10cSrcweir
291cdf0e10cSrcweir } // end of namespace sd
292