bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / func / fuconstr.cxx
blobe4eb8b3eda5fee0be321e74c738ccc03b2969644
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 <svx/svdpagv.hxx>
24 #include <svx/xdef.hxx>
25 #include <svx/xfillit0.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <tools/debug.hxx>
30 #include <app.hrc>
31 #include <strings.hrc>
32 #include <strings.hxx>
33 #include <fudraw.hxx>
34 #include <View.hxx>
35 #include <Window.hxx>
36 #include <ViewShell.hxx>
37 #include <drawdoc.hxx>
38 #include <FrameView.hxx>
39 #include <sdpage.hxx>
40 #include <sdresid.hxx>
41 #include <glob.hxx>
43 using namespace com::sun::star;
45 namespace sd {
48 FuConstruct::FuConstruct (
49 ViewShell* pViewSh,
50 ::sd::Window* pWin,
51 ::sd::View* pView,
52 SdDrawDocument* pDoc,
53 SfxRequest& rReq)
54 : FuDraw(pViewSh, pWin, pView, pDoc, rReq),
55 bSelectionChanged(false)
59 bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
61 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
63 bMBDown = true;
64 bSelectionChanged = false;
66 if ( mpView->IsAction() )
68 return true;
71 bFirstMouseMove = true;
72 aDragTimer.Start();
74 aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
75 sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
77 if (rMEvt.IsLeft() && mpView->IsExtendedMouseEventDispatcherEnabled())
79 mpWindow->CaptureMouse();
81 SdrHdl* pHdl = mpView->PickHandle(aMDPos);
83 if ( pHdl != nullptr || mpView->IsMarkedHit(aMDPos, nHitLog) )
85 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
86 mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
87 bReturn = true;
89 else if ( mpView->AreObjectsMarked() )
91 mpView->UnmarkAll();
92 bReturn = true;
96 return bReturn;
99 bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
101 FuDraw::MouseMove(rMEvt);
103 if (aDragTimer.IsActive() )
105 if( bFirstMouseMove )
106 bFirstMouseMove = false;
107 else
108 aDragTimer.Stop();
111 Point aPix(rMEvt.GetPosPixel());
112 Point aPnt( mpWindow->PixelToLogic(aPix) );
114 if ( mpView->IsAction() )
116 ForceScroll(aPix);
117 mpView->MovAction(aPnt);
120 return true;
123 bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
125 bool bReturn = true;
127 if (aDragTimer.IsActive() )
129 aDragTimer.Stop();
130 bIsInDragMode = false;
133 FuDraw::MouseButtonUp(rMEvt);
135 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
137 if ( mpView && mpView->IsDragObj() )
139 FrameView* pFrameView = mpViewShell->GetFrameView();
140 bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
142 if (bDragWithCopy)
144 bDragWithCopy = !mpView->IsPresObjSelected(false);
147 mpView->SetDragWithCopy(bDragWithCopy);
148 mpView->EndDragObj( mpView->IsDragWithCopy() );
150 else if ( mpView && mpView->IsMarkObj() )
152 mpView->EndMarkObj();
154 else
156 bReturn = false;
159 if ( mpView && !mpView->IsAction() )
161 mpWindow->ReleaseMouse();
162 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
164 if ( !mpView->AreObjectsMarked() )
166 SdrPageView* pPV;
167 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
169 SdrObject* pObj = mpView->PickObj(aPnt, mpView->getHitTolLog(), pPV);
170 if (!pObj)
172 mpView->MarkObj(aPnt, nHitLog);
175 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
177 else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
178 !bSelectionChanged &&
179 std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
180 std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
182 // toggle between selection and rotation
183 SdrObject* pSingleObj = nullptr;
185 if (mpView->GetMarkedObjectList().GetMarkCount()==1)
187 pSingleObj = mpView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
190 if (mpView->GetDragMode() == SdrDragMode::Move && mpView->IsRotateAllowed() &&
191 (mpViewShell->GetFrameView()->IsClickChangeRotation() ||
192 (pSingleObj && pSingleObj->GetObjInventor()==SdrInventor::E3d)))
194 mpView->SetDragMode(SdrDragMode::Rotate);
196 else
198 mpView->SetDragMode(SdrDragMode::Move);
203 sal_uInt16 nClicks = rMEvt.GetClicks();
205 if (nClicks == 2 && rMEvt.IsLeft() && bMBDown &&
206 !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift() )
208 DoubleClick(rMEvt);
210 bMBDown = false;
212 return bReturn;
215 void FuConstruct::Activate()
217 mpView->SetEditMode(SdrViewEditMode::Create);
218 FuDraw::Activate();
221 void FuConstruct::Deactivate()
223 FuDraw::Deactivate();
224 mpView->SetEditMode(SdrViewEditMode::Edit);
228 * set style sheet for the object to be created
230 void FuConstruct::SetStyleSheet(SfxItemSet& rAttr, SdrObject* pObj)
232 bool bUseFillStyle, bUseNoFillStyle;
233 bUseFillStyle = bUseNoFillStyle = false;
235 switch( nSlotId )
237 case SID_DRAW_RECT:
238 case SID_DRAW_RECT_ROUND:
239 case SID_DRAW_SQUARE:
240 case SID_DRAW_SQUARE_ROUND:
241 case SID_DRAW_ELLIPSE:
242 case SID_DRAW_PIE:
243 case SID_DRAW_ELLIPSECUT:
244 case SID_DRAW_CIRCLE:
245 case SID_DRAW_CIRCLEPIE:
246 case SID_DRAW_CIRCLECUT:
247 case SID_DRAW_POLYGON:
248 case SID_DRAW_XPOLYGON:
249 case SID_DRAW_FREELINE:
250 case SID_DRAW_BEZIER_FILL:
252 bUseFillStyle = true;
253 break;
255 case SID_DRAW_RECT_NOFILL:
256 case SID_DRAW_RECT_ROUND_NOFILL:
257 case SID_DRAW_SQUARE_NOFILL:
258 case SID_DRAW_SQUARE_ROUND_NOFILL:
259 case SID_DRAW_ELLIPSE_NOFILL:
260 case SID_DRAW_PIE_NOFILL:
261 case SID_DRAW_ELLIPSECUT_NOFILL:
262 case SID_DRAW_CIRCLE_NOFILL:
263 case SID_DRAW_CIRCLEPIE_NOFILL:
264 case SID_DRAW_CIRCLECUT_NOFILL:
265 case SID_DRAW_POLYGON_NOFILL:
266 case SID_DRAW_XPOLYGON_NOFILL:
267 case SID_DRAW_FREELINE_NOFILL:
268 case SID_DRAW_LINE:
269 case SID_DRAW_XLINE:
270 case SID_CONNECTOR_ARROW_START:
271 case SID_CONNECTOR_ARROW_END:
272 case SID_CONNECTOR_ARROWS:
273 case SID_CONNECTOR_CIRCLE_START:
274 case SID_CONNECTOR_CIRCLE_END:
275 case SID_CONNECTOR_CIRCLES:
276 case SID_CONNECTOR_LINE:
277 case SID_CONNECTOR_LINE_ARROW_START:
278 case SID_CONNECTOR_LINE_ARROW_END:
279 case SID_CONNECTOR_LINE_ARROWS:
280 case SID_CONNECTOR_LINE_CIRCLE_START:
281 case SID_CONNECTOR_LINE_CIRCLE_END:
282 case SID_CONNECTOR_LINE_CIRCLES:
283 case SID_CONNECTOR_CURVE:
284 case SID_CONNECTOR_CURVE_ARROW_START:
285 case SID_CONNECTOR_CURVE_ARROW_END:
286 case SID_CONNECTOR_CURVE_ARROWS:
287 case SID_CONNECTOR_CURVE_CIRCLE_START:
288 case SID_CONNECTOR_CURVE_CIRCLE_END:
289 case SID_CONNECTOR_CURVE_CIRCLES:
290 case SID_CONNECTOR_LINES:
291 case SID_CONNECTOR_LINES_ARROW_START:
292 case SID_CONNECTOR_LINES_ARROW_END:
293 case SID_CONNECTOR_LINES_ARROWS:
294 case SID_CONNECTOR_LINES_CIRCLE_START:
295 case SID_CONNECTOR_LINES_CIRCLE_END:
296 case SID_CONNECTOR_LINES_CIRCLES:
297 case SID_DRAW_BEZIER_NOFILL:
298 case SID_LINE_ARROW_END:
300 bUseNoFillStyle = true;
301 break;
304 SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
307 void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
308 const bool bForceFillStyle, const bool bForceNoFillStyle )
310 SdPage* pPage = static_cast<SdPage*>(mpView->GetSdrPageView()->GetPage());
311 if ( pPage->IsMasterPage() && pPage->GetPageKind() == PageKind::Standard &&
312 mpDoc->GetDocumentType() == DocumentType::Impress )
314 /**********************************************
315 * Objects was created on the slide master page
316 ***********************************************/
317 OUString aName( pPage->GetLayoutName() );
318 sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + strlen(SD_LT_SEPARATOR);
319 aName = aName.copy(0, n) + STR_LAYOUT_BACKGROUNDOBJECTS;
320 SfxStyleSheet* pSheet(
321 static_cast< SfxStyleSheet* >(
322 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page)));
323 DBG_ASSERT(pSheet, "StyleSheet missing");
324 if (pSheet)
326 // applying style sheet for background objects
327 pObj->SetStyleSheet(pSheet, false);
328 SfxItemSet& rSet = pSheet->GetItemSet();
329 const XFillStyleItem& rFillStyle = rSet.Get(XATTR_FILLSTYLE);
330 if ( bForceFillStyle )
332 if (rFillStyle.GetValue() == drawing::FillStyle_NONE)
333 rAttr.Put(XFillStyleItem(drawing::FillStyle_SOLID));
335 else if ( bForceNoFillStyle )
337 if (rFillStyle.GetValue() != drawing::FillStyle_NONE)
338 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
342 else
344 /***********************************
345 * object was created on normal page
346 ************************************/
347 if ( bForceNoFillStyle )
349 OUString aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL));
350 SfxStyleSheet* pSheet(
351 static_cast< SfxStyleSheet* >(
352 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
353 DBG_ASSERT(pSheet, "Stylesheet missing");
354 if (pSheet)
356 pObj->SetStyleSheet(pSheet, false);
357 SfxItemSet aAttr(mpView->GetDefaultAttr());
358 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
359 pObj->SetMergedItemSet(aAttr);
361 else
363 SfxItemSet aAttr(mpView->GetDefaultAttr());
364 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
365 pObj->SetMergedItemSet(aAttr);
371 } // end of namespace sd
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */