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