xref: /aoo42x/main/sd/source/ui/func/fuconstr.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "fuconstr.hxx"
32 
33 #include <svx/svxids.hrc>
34 #include <svl/aeitem.hxx>
35 #include <svx/svdpagv.hxx>
36 #include <svx/xdef.hxx>
37 #include <svx/xfillit0.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/viewfrm.hxx>
40 
41 #include "app.hrc"
42 #include "glob.hrc"
43 #include "fudraw.hxx"
44 #include "View.hxx"
45 #include "Window.hxx"
46 #include "ViewShell.hxx"
47 #include "drawdoc.hxx"
48 #include "FrameView.hxx"
49 #include "sdpage.hxx"
50 #include "sdresid.hxx"
51 #include "stlpool.hxx"
52 #include <svx/globl3d.hxx>
53 
54 namespace sd {
55 
56 TYPEINIT1( FuConstruct, FuDraw );
57 
58 /*************************************************************************
59 |*
60 |* Konstruktor
61 |*
62 \************************************************************************/
63 
64 FuConstruct::FuConstruct (
65     ViewShell*		pViewSh,
66     ::sd::Window*			pWin,
67     ::sd::View*			pView,
68     SdDrawDocument*	pDoc,
69     SfxRequest&		rReq)
70     : FuDraw(pViewSh, pWin, pView, pDoc, rReq),
71       bSelectionChanged(sal_False)
72 {
73 }
74 
75 void FuConstruct::DoExecute( SfxRequest& rReq )
76 {
77 	FuDraw::DoExecute( rReq );
78 }
79 
80 /*************************************************************************
81 |*
82 |* MouseButtonDown-event
83 |*
84 \************************************************************************/
85 
86 sal_Bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
87 {
88 	sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
89 
90 	bMBDown = sal_True;
91 	bSelectionChanged = sal_False;
92 
93 	if ( mpView->IsAction() )
94 	{
95 		// #90235# this extra triggering is an error and leads to
96 		// erasing the last two points when creating a polygon.
97 		// if ( rMEvt.IsRight() )
98 		//	mpView->BckAction();
99 		return sal_True;
100 	}
101 
102 	bFirstMouseMove = sal_True;
103 	aDragTimer.Start();
104 
105 	aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
106 	sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
107 
108 	if (rMEvt.IsLeft() && mpView->IsExtendedMouseEventDispatcherEnabled())
109 	{
110 		mpWindow->CaptureMouse();
111 
112 		SdrHdl* pHdl = mpView->PickHandle(aMDPos);
113 
114 		if ( pHdl != NULL || mpView->IsMarkedHit(aMDPos, nHitLog) )
115 		{
116 			sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
117 			mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
118 			bReturn = sal_True;
119 		}
120 		else if ( mpView->AreObjectsMarked() )
121 		{
122 			mpView->UnmarkAll();
123 			bReturn = sal_True;
124 		}
125 	}
126 
127 	return bReturn;
128 }
129 
130 /*************************************************************************
131 |*
132 |* MouseMove-event
133 |*
134 \************************************************************************/
135 
136 sal_Bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
137 {
138 	FuDraw::MouseMove(rMEvt);
139 
140 	if (aDragTimer.IsActive() )
141 	{
142 		if( bFirstMouseMove )
143 			bFirstMouseMove = sal_False;
144 		else
145 			aDragTimer.Stop();
146 	}
147 
148 	Point aPix(rMEvt.GetPosPixel());
149 	Point aPnt( mpWindow->PixelToLogic(aPix) );
150 
151 	if ( mpView->IsAction() )
152 	{
153 		ForceScroll(aPix);
154 		mpView->MovAction(aPnt);
155 	}
156 
157 	return sal_True;
158 }
159 
160 /*************************************************************************
161 |*
162 |* MouseButtonUp-event
163 |*
164 \************************************************************************/
165 
166 sal_Bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
167 {
168 	sal_Bool bReturn = sal_True;
169 
170 	if (aDragTimer.IsActive() )
171 	{
172 		aDragTimer.Stop();
173 		bIsInDragMode = sal_False;
174 	}
175 
176 	FuDraw::MouseButtonUp(rMEvt);
177 
178 	Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
179 
180 	if ( mpView && mpView->IsDragObj() )
181 	{
182 		FrameView* pFrameView = mpViewShell->GetFrameView();
183 		sal_Bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
184 
185 		if (bDragWithCopy)
186 		{
187 			bDragWithCopy = !mpView->IsPresObjSelected(sal_False, sal_True);
188 		}
189 
190 		mpView->SetDragWithCopy(bDragWithCopy);
191 		mpView->EndDragObj( mpView->IsDragWithCopy() );
192 	}
193 	else if ( mpView && mpView->IsMarkObj() )
194 	{
195 		mpView->EndMarkObj();
196 	}
197 	else
198 	{
199 		bReturn = sal_False;
200 	}
201 
202 	if ( mpView &&  !mpView->IsAction() )
203 	{
204 		mpWindow->ReleaseMouse();
205 		sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
206 
207 		if ( !mpView->AreObjectsMarked() )
208 		{
209 			SdrObject* pObj;
210 			SdrPageView* pPV;
211 			sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
212 
213 			if (!mpView->PickObj(aPnt, mpView->getHitTolLog(), pObj, pPV))
214 			{
215 				mpView->MarkObj(aPnt, nHitLog);
216 			}
217 
218 			mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
219 		}
220 		else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
221 				 !bSelectionChanged                   &&
222 				 Abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
223 				 Abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
224 		{
225 			/**************************************************************
226 			* Toggle zw. Selektion und Rotation
227 			**************************************************************/
228 			SdrObject* pSingleObj = NULL;
229 			sal_uLong nMarkCount = mpView->GetMarkedObjectList().GetMarkCount();
230 
231 			if (nMarkCount==1)
232 			{
233 				pSingleObj = mpView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
234 			}
235 
236 			if (mpView->GetDragMode() == SDRDRAG_MOVE && mpView->IsRotateAllowed() &&
237 				(mpViewShell->GetFrameView()->IsClickChangeRotation() ||
238 				 (pSingleObj && pSingleObj->GetObjInventor()==E3dInventor)))
239 			{
240 				mpView->SetDragMode(SDRDRAG_ROTATE);
241 			}
242 			else
243 			{
244 				mpView->SetDragMode(SDRDRAG_MOVE);
245 			}
246 		}
247 	}
248 
249 	sal_uInt16 nClicks = rMEvt.GetClicks();
250 
251 	if (nClicks == 2 && rMEvt.IsLeft() && bMBDown &&
252 		!rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift() )
253 	{
254 		DoubleClick(rMEvt);
255 	}
256 	bMBDown = sal_False;
257 
258 	return bReturn;
259 }
260 
261 /*************************************************************************
262 |*
263 |* Tastaturereignisse bearbeiten
264 |*
265 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
266 |* sal_False.
267 |*
268 \************************************************************************/
269 
270 sal_Bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
271 {
272 	sal_Bool bReturn = sal_False;
273 
274 	if ( !bReturn )
275 		bReturn = FuDraw::KeyInput(rKEvt);
276 
277 	return(bReturn);
278 }
279 
280 /*************************************************************************
281 |*
282 |* Function aktivieren
283 |*
284 \************************************************************************/
285 
286 void FuConstruct::Activate()
287 {
288 	mpView->SetEditMode(SDREDITMODE_CREATE);
289 	FuDraw::Activate();
290 }
291 
292 /*************************************************************************
293 |*
294 |* Function deaktivieren
295 |*
296 \************************************************************************/
297 
298 void FuConstruct::Deactivate()
299 {
300 	FuDraw::Deactivate();
301 	mpView->SetEditMode(SDREDITMODE_EDIT);
302 }
303 
304 /*************************************************************************
305 |*
306 |* StyleSheet fuer das zu erzeugende Objekt setzen
307 |*
308 \************************************************************************/
309 
310 void FuConstruct::SetStyleSheet(SfxItemSet& rAttr, SdrObject* pObj)
311 {
312 	sal_Bool bUseFillStyle, bUseNoFillStyle;
313 	bUseFillStyle = bUseNoFillStyle = sal_False;
314 
315 	switch( nSlotId )
316 	{
317 	case SID_DRAW_RECT:
318 	case SID_DRAW_RECT_ROUND:
319 	case SID_DRAW_SQUARE:
320 	case SID_DRAW_SQUARE_ROUND:
321 	case SID_DRAW_ELLIPSE:
322 	case SID_DRAW_PIE:
323 	case SID_DRAW_ELLIPSECUT:
324 	case SID_DRAW_CIRCLE:
325 	case SID_DRAW_CIRCLEPIE:
326 	case SID_DRAW_CIRCLECUT:
327 	case SID_DRAW_POLYGON:
328 	case SID_DRAW_XPOLYGON:
329 	case SID_DRAW_FREELINE:
330 	case SID_DRAW_BEZIER_FILL:
331 	{
332 		bUseFillStyle = sal_True;
333 		break;
334 	}
335 	case  SID_DRAW_RECT_NOFILL:
336 	case SID_DRAW_RECT_ROUND_NOFILL:
337 	case SID_DRAW_SQUARE_NOFILL:
338 	case SID_DRAW_SQUARE_ROUND_NOFILL:
339 	case SID_DRAW_ELLIPSE_NOFILL:
340 	case SID_DRAW_PIE_NOFILL:
341 	case SID_DRAW_ELLIPSECUT_NOFILL:
342 	case SID_DRAW_CIRCLE_NOFILL:
343 	case SID_DRAW_CIRCLEPIE_NOFILL:
344 	case SID_DRAW_CIRCLECUT_NOFILL:
345 	case SID_DRAW_POLYGON_NOFILL:
346 	case SID_DRAW_XPOLYGON_NOFILL:
347 	case SID_DRAW_FREELINE_NOFILL:
348 	case SID_DRAW_LINE:
349 	case SID_DRAW_XLINE:
350 	case SID_CONNECTOR_ARROW_START:
351 	case SID_CONNECTOR_ARROW_END:
352 	case SID_CONNECTOR_ARROWS:
353 	case SID_CONNECTOR_CIRCLE_START:
354 	case SID_CONNECTOR_CIRCLE_END:
355 	case SID_CONNECTOR_CIRCLES:
356 	case SID_CONNECTOR_LINE:
357 	case SID_CONNECTOR_LINE_ARROW_START:
358 	case SID_CONNECTOR_LINE_ARROW_END:
359 	case SID_CONNECTOR_LINE_ARROWS:
360 	case SID_CONNECTOR_LINE_CIRCLE_START:
361 	case SID_CONNECTOR_LINE_CIRCLE_END:
362 	case SID_CONNECTOR_LINE_CIRCLES:
363 	case SID_CONNECTOR_CURVE:
364 	case SID_CONNECTOR_CURVE_ARROW_START:
365 	case SID_CONNECTOR_CURVE_ARROW_END:
366 	case SID_CONNECTOR_CURVE_ARROWS:
367 	case SID_CONNECTOR_CURVE_CIRCLE_START:
368 	case SID_CONNECTOR_CURVE_CIRCLE_END:
369 	case SID_CONNECTOR_CURVE_CIRCLES:
370 	case SID_CONNECTOR_LINES:
371 	case SID_CONNECTOR_LINES_ARROW_START:
372 	case SID_CONNECTOR_LINES_ARROW_END:
373 	case SID_CONNECTOR_LINES_ARROWS:
374 	case SID_CONNECTOR_LINES_CIRCLE_START:
375 	case SID_CONNECTOR_LINES_CIRCLE_END:
376 	case SID_CONNECTOR_LINES_CIRCLES:
377 	case SID_DRAW_BEZIER_NOFILL:
378 	case SID_LINE_ARROW_END:
379 	{
380 		bUseNoFillStyle = sal_True;
381 		break;
382 	}
383 	}
384 	SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
385 }
386 
387 void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
388 		const sal_Bool bForceFillStyle, const sal_Bool bForceNoFillStyle )
389 {
390 	SdPage* pPage = (SdPage*)mpView->GetSdrPageView()->GetPage();
391 	if ( pPage->IsMasterPage() && pPage->GetPageKind() == PK_STANDARD &&
392 	     mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
393 	{
394 		/**********************************************
395 		* Objects was created on the slide master page
396 		***********************************************/
397 		String aName( pPage->GetLayoutName() );
398 		String aSep = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ) );
399 		sal_uInt16 n = aName.Search(aSep);
400 		n = n + aSep.Len();
401 		aName.Erase(n);
402 		aName.Append( String ( SdResId( STR_LAYOUT_BACKGROUNDOBJECTS ) ) );
403 		SfxStyleSheet* pSheet = (SfxStyleSheet*)pPage->GetModel()->
404 												GetStyleSheetPool()->
405 												Find(aName, SD_STYLE_FAMILY_MASTERPAGE);
406 		DBG_ASSERT(pSheet, "Objektvorlage nicht gefunden");
407 		if (pSheet)
408 		{
409 			// applying style sheet for background objects
410 			pObj->SetStyleSheet(pSheet, sal_False);
411 			SfxItemSet& rSet = pSheet->GetItemSet();
412 			const XFillStyleItem& rFillStyle = (const XFillStyleItem&)rSet.Get(XATTR_FILLSTYLE);
413 			if ( bForceFillStyle )
414 			{
415 				if (rFillStyle.GetValue() == XFILL_NONE)
416 					rAttr.Put(XFillStyleItem(XFILL_SOLID));
417 			}
418 			else if ( bForceNoFillStyle )
419 			{
420 				if (rFillStyle.GetValue() != XFILL_NONE)
421 					rAttr.Put(XFillStyleItem(XFILL_NONE));
422 			}
423 		}
424 	}
425 	else
426 	{
427 		/***********************************
428 		* object was created on normal page
429 		************************************/
430 		if ( bForceNoFillStyle )
431 		{
432 			String aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL));
433 			SfxStyleSheet* pSheet = (SfxStyleSheet*)pPage->GetModel()->
434 										 GetStyleSheetPool()->
435 										 Find(aName, SD_STYLE_FAMILY_GRAPHICS);
436 			DBG_ASSERT(pSheet, "Objektvorlage nicht gefunden");
437 			if (pSheet)
438 			{
439 				pObj->SetStyleSheet(pSheet, sal_False);
440 				SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
441 				aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
442 				pObj->SetMergedItemSet(aAttr);
443 			}
444 			else
445 			{
446 				SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
447 				rAttr.Put(XFillStyleItem(XFILL_NONE));
448 				pObj->SetMergedItemSet(aAttr);
449 			}
450 		}
451 	}
452 }
453 
454 } // end of namespace sd
455