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