bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuconstr.cxx
blob9edd9bc866a2ff8d960b028360afc3223af15163
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "fuconstr.hxx"
22 #include <svx/svxids.hrc>
23 #include <svl/aeitem.hxx>
24 #include <svx/svdpagv.hxx>
25 #include <svx/xdef.hxx>
26 #include <svx/xfillit0.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include "app.hrc"
31 #include "glob.hrc"
32 #include "fudraw.hxx"
33 #include "View.hxx"
34 #include "Window.hxx"
35 #include "ViewShell.hxx"
36 #include "drawdoc.hxx"
37 #include "FrameView.hxx"
38 #include "sdpage.hxx"
39 #include "sdresid.hxx"
40 #include "stlpool.hxx"
41 #include <svx/globl3d.hxx>
43 using namespace com::sun::star;
45 namespace sd {
47 TYPEINIT1( FuConstruct, FuDraw );
49 FuConstruct::FuConstruct (
50 ViewShell* pViewSh,
51 ::sd::Window* pWin,
52 ::sd::View* pView,
53 SdDrawDocument* pDoc,
54 SfxRequest& rReq)
55 : FuDraw(pViewSh, pWin, pView, pDoc, rReq),
56 bSelectionChanged(false)
60 void FuConstruct::DoExecute( SfxRequest& rReq )
62 FuDraw::DoExecute( rReq );
65 bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
67 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
69 bMBDown = true;
70 bSelectionChanged = false;
72 if ( mpView->IsAction() )
74 return true;
77 bFirstMouseMove = true;
78 aDragTimer.Start();
80 aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
81 sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
83 if (rMEvt.IsLeft() && mpView->IsExtendedMouseEventDispatcherEnabled())
85 mpWindow->CaptureMouse();
87 SdrHdl* pHdl = mpView->PickHandle(aMDPos);
89 if ( pHdl != NULL || mpView->IsMarkedHit(aMDPos, nHitLog) )
91 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
92 mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
93 bReturn = true;
95 else if ( mpView->AreObjectsMarked() )
97 mpView->UnmarkAll();
98 bReturn = true;
102 return bReturn;
105 bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
107 FuDraw::MouseMove(rMEvt);
109 if (aDragTimer.IsActive() )
111 if( bFirstMouseMove )
112 bFirstMouseMove = false;
113 else
114 aDragTimer.Stop();
117 Point aPix(rMEvt.GetPosPixel());
118 Point aPnt( mpWindow->PixelToLogic(aPix) );
120 if ( mpView->IsAction() )
122 ForceScroll(aPix);
123 mpView->MovAction(aPnt);
126 return true;
129 bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
131 bool bReturn = true;
133 if (aDragTimer.IsActive() )
135 aDragTimer.Stop();
136 bIsInDragMode = false;
139 FuDraw::MouseButtonUp(rMEvt);
141 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
143 if ( mpView && mpView->IsDragObj() )
145 FrameView* pFrameView = mpViewShell->GetFrameView();
146 bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
148 if (bDragWithCopy)
150 bDragWithCopy = !mpView->IsPresObjSelected(false, true);
153 mpView->SetDragWithCopy(bDragWithCopy);
154 mpView->EndDragObj( mpView->IsDragWithCopy() );
156 else if ( mpView && mpView->IsMarkObj() )
158 mpView->EndMarkObj();
160 else
162 bReturn = false;
165 if ( mpView && !mpView->IsAction() )
167 mpWindow->ReleaseMouse();
168 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
170 if ( !mpView->AreObjectsMarked() )
172 SdrObject* pObj;
173 SdrPageView* pPV;
174 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
176 if (!mpView->PickObj(aPnt, mpView->getHitTolLog(), pObj, pPV))
178 mpView->MarkObj(aPnt, nHitLog);
181 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
183 else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
184 !bSelectionChanged &&
185 std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
186 std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
188 // toggle between selection and rotation
189 SdrObject* pSingleObj = NULL;
191 if (mpView->GetMarkedObjectList().GetMarkCount()==1)
193 pSingleObj = mpView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
196 if (mpView->GetDragMode() == SDRDRAG_MOVE && mpView->IsRotateAllowed() &&
197 (mpViewShell->GetFrameView()->IsClickChangeRotation() ||
198 (pSingleObj && pSingleObj->GetObjInventor()==E3dInventor)))
200 mpView->SetDragMode(SDRDRAG_ROTATE);
202 else
204 mpView->SetDragMode(SDRDRAG_MOVE);
209 sal_uInt16 nClicks = rMEvt.GetClicks();
211 if (nClicks == 2 && rMEvt.IsLeft() && bMBDown &&
212 !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift() )
214 DoubleClick(rMEvt);
216 bMBDown = false;
218 return bReturn;
222 * Process keyboard input
223 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
225 bool FuConstruct::KeyInput(const KeyEvent& rKEvt)
227 bool bReturn = false;
229 if ( !bReturn )
230 bReturn = FuDraw::KeyInput(rKEvt);
232 return bReturn;
235 void FuConstruct::Activate()
237 mpView->SetEditMode(SDREDITMODE_CREATE);
238 FuDraw::Activate();
241 void FuConstruct::Deactivate()
243 FuDraw::Deactivate();
244 mpView->SetEditMode(SDREDITMODE_EDIT);
248 * set style sheet for the object to be created
250 void FuConstruct::SetStyleSheet(SfxItemSet& rAttr, SdrObject* pObj)
252 bool bUseFillStyle, bUseNoFillStyle;
253 bUseFillStyle = bUseNoFillStyle = false;
255 switch( nSlotId )
257 case SID_DRAW_RECT:
258 case SID_DRAW_RECT_ROUND:
259 case SID_DRAW_SQUARE:
260 case SID_DRAW_SQUARE_ROUND:
261 case SID_DRAW_ELLIPSE:
262 case SID_DRAW_PIE:
263 case SID_DRAW_ELLIPSECUT:
264 case SID_DRAW_CIRCLE:
265 case SID_DRAW_CIRCLEPIE:
266 case SID_DRAW_CIRCLECUT:
267 case SID_DRAW_POLYGON:
268 case SID_DRAW_XPOLYGON:
269 case SID_DRAW_FREELINE:
270 case SID_DRAW_BEZIER_FILL:
272 bUseFillStyle = true;
273 break;
275 case SID_DRAW_RECT_NOFILL:
276 case SID_DRAW_RECT_ROUND_NOFILL:
277 case SID_DRAW_SQUARE_NOFILL:
278 case SID_DRAW_SQUARE_ROUND_NOFILL:
279 case SID_DRAW_ELLIPSE_NOFILL:
280 case SID_DRAW_PIE_NOFILL:
281 case SID_DRAW_ELLIPSECUT_NOFILL:
282 case SID_DRAW_CIRCLE_NOFILL:
283 case SID_DRAW_CIRCLEPIE_NOFILL:
284 case SID_DRAW_CIRCLECUT_NOFILL:
285 case SID_DRAW_POLYGON_NOFILL:
286 case SID_DRAW_XPOLYGON_NOFILL:
287 case SID_DRAW_FREELINE_NOFILL:
288 case SID_DRAW_LINE:
289 case SID_DRAW_XLINE:
290 case SID_CONNECTOR_ARROW_START:
291 case SID_CONNECTOR_ARROW_END:
292 case SID_CONNECTOR_ARROWS:
293 case SID_CONNECTOR_CIRCLE_START:
294 case SID_CONNECTOR_CIRCLE_END:
295 case SID_CONNECTOR_CIRCLES:
296 case SID_CONNECTOR_LINE:
297 case SID_CONNECTOR_LINE_ARROW_START:
298 case SID_CONNECTOR_LINE_ARROW_END:
299 case SID_CONNECTOR_LINE_ARROWS:
300 case SID_CONNECTOR_LINE_CIRCLE_START:
301 case SID_CONNECTOR_LINE_CIRCLE_END:
302 case SID_CONNECTOR_LINE_CIRCLES:
303 case SID_CONNECTOR_CURVE:
304 case SID_CONNECTOR_CURVE_ARROW_START:
305 case SID_CONNECTOR_CURVE_ARROW_END:
306 case SID_CONNECTOR_CURVE_ARROWS:
307 case SID_CONNECTOR_CURVE_CIRCLE_START:
308 case SID_CONNECTOR_CURVE_CIRCLE_END:
309 case SID_CONNECTOR_CURVE_CIRCLES:
310 case SID_CONNECTOR_LINES:
311 case SID_CONNECTOR_LINES_ARROW_START:
312 case SID_CONNECTOR_LINES_ARROW_END:
313 case SID_CONNECTOR_LINES_ARROWS:
314 case SID_CONNECTOR_LINES_CIRCLE_START:
315 case SID_CONNECTOR_LINES_CIRCLE_END:
316 case SID_CONNECTOR_LINES_CIRCLES:
317 case SID_DRAW_BEZIER_NOFILL:
318 case SID_LINE_ARROW_END:
320 bUseNoFillStyle = true;
321 break;
324 SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
327 void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
328 const bool bForceFillStyle, const bool bForceNoFillStyle )
330 SdPage* pPage = static_cast<SdPage*>(mpView->GetSdrPageView()->GetPage());
331 if ( pPage->IsMasterPage() && pPage->GetPageKind() == PK_STANDARD &&
332 mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
334 /**********************************************
335 * Objects was created on the slide master page
336 ***********************************************/
337 OUString aName( pPage->GetLayoutName() );
338 sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + strlen(SD_LT_SEPARATOR);
339 aName = aName.copy(0, n) + SD_RESSTR(STR_LAYOUT_BACKGROUNDOBJECTS);
340 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
341 GetStyleSheetPool()->
342 Find(aName, SD_STYLE_FAMILY_MASTERPAGE));
343 DBG_ASSERT(pSheet, "StyleSheet missing");
344 if (pSheet)
346 // applying style sheet for background objects
347 pObj->SetStyleSheet(pSheet, false);
348 SfxItemSet& rSet = pSheet->GetItemSet();
349 const XFillStyleItem& rFillStyle = static_cast<const XFillStyleItem&>(rSet.Get(XATTR_FILLSTYLE));
350 if ( bForceFillStyle )
352 if (rFillStyle.GetValue() == drawing::FillStyle_NONE)
353 rAttr.Put(XFillStyleItem(drawing::FillStyle_SOLID));
355 else if ( bForceNoFillStyle )
357 if (rFillStyle.GetValue() != drawing::FillStyle_NONE)
358 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
362 else
364 /***********************************
365 * object was created on normal page
366 ************************************/
367 if ( bForceNoFillStyle )
369 OUString aName(SD_RESSTR(STR_POOLSHEET_OBJWITHOUTFILL));
370 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
371 GetStyleSheetPool()->
372 Find(aName, SD_STYLE_FAMILY_GRAPHICS));
373 DBG_ASSERT(pSheet, "Stylesheet missing");
374 if (pSheet)
376 pObj->SetStyleSheet(pSheet, false);
377 SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
378 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
379 pObj->SetMergedItemSet(aAttr);
381 else
383 SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
384 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
385 pObj->SetMergedItemSet(aAttr);
391 } // end of namespace sd
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */