android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fuconstr.cxx
blobab7b4c4e1b2077f9bad03797b3df9a7e8a0ca2ae
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>
29 #include <svx/xflclit.hxx>
30 #include <svx/xlineit0.hxx>
31 #include <svx/xlnclit.hxx>
32 #include <docmodel/theme/Theme.hxx>
34 #include <app.hrc>
35 #include <strings.hrc>
36 #include <strings.hxx>
37 #include <fudraw.hxx>
38 #include <View.hxx>
39 #include <Window.hxx>
40 #include <ViewShell.hxx>
41 #include <drawdoc.hxx>
42 #include <FrameView.hxx>
43 #include <sdpage.hxx>
44 #include <sdresid.hxx>
45 #include <glob.hxx>
46 #include <comphelper/lok.hxx>
48 using namespace com::sun::star;
50 namespace sd {
53 FuConstruct::FuConstruct (
54 ViewShell* pViewSh,
55 ::sd::Window* pWin,
56 ::sd::View* pView,
57 SdDrawDocument* pDoc,
58 SfxRequest& rReq)
59 : FuDraw(pViewSh, pWin, pView, pDoc, rReq),
60 bSelectionChanged(false)
64 bool FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
66 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
68 bMBDown = true;
69 bSelectionChanged = false;
71 if ( mpView->IsAction() )
73 return true;
76 bFirstMouseMove = true;
77 aDragTimer.Start();
79 aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
80 sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
82 if (rMEvt.IsLeft() && mpView->IsExtendedMouseEventDispatcherEnabled())
84 mpWindow->CaptureMouse();
86 SdrHdl* pHdl = mpView->PickHandle(aMDPos);
88 if ( pHdl != nullptr || mpView->IsMarkedHit(aMDPos, nHitLog) )
90 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
91 mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
92 bReturn = true;
94 else if ( mpView->AreObjectsMarked() )
96 mpView->UnmarkAll();
97 bReturn = true;
101 return bReturn;
104 bool FuConstruct::MouseMove(const MouseEvent& rMEvt)
106 FuDraw::MouseMove(rMEvt);
108 if (aDragTimer.IsActive() )
110 if( bFirstMouseMove )
111 bFirstMouseMove = false;
112 else
113 aDragTimer.Stop();
116 Point aPix(rMEvt.GetPosPixel());
117 Point aPnt( mpWindow->PixelToLogic(aPix) );
119 if ( mpView->IsAction() )
121 ForceScroll(aPix);
122 mpView->MovAction(aPnt);
125 return true;
128 bool FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
130 bool bReturn = true;
132 if (aDragTimer.IsActive() )
134 aDragTimer.Stop();
135 bIsInDragMode = false;
138 FuDraw::MouseButtonUp(rMEvt);
140 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
142 if ( mpView && mpView->IsDragObj() )
144 FrameView* pFrameView = mpViewShell->GetFrameView();
145 bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
147 if (bDragWithCopy)
149 bDragWithCopy = !mpView->IsPresObjSelected(false);
152 mpView->SetDragWithCopy(bDragWithCopy);
153 mpView->EndDragObj( mpView->IsDragWithCopy() );
155 else if ( mpView && mpView->IsMarkObj() )
157 mpView->EndMarkObj();
159 else
161 bReturn = false;
164 if ( mpView && !mpView->IsAction() )
166 mpWindow->ReleaseMouse();
167 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
169 if ( !mpView->AreObjectsMarked() )
171 SdrPageView* pPV;
172 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
174 SdrObject* pObj = mpView->PickObj(aPnt, mpView->getHitTolLog(), pPV);
175 if (!pObj)
177 mpView->MarkObj(aPnt, nHitLog);
180 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
182 else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
183 !bSelectionChanged &&
184 std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
185 std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
187 // toggle between selection and rotation
188 SdrObject* pSingleObj = nullptr;
190 if (mpView->GetMarkedObjectList().GetMarkCount()==1)
192 pSingleObj = mpView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
195 const bool bTiledRendering = comphelper::LibreOfficeKit::isActive();
196 if (!bTiledRendering && (mpView->GetDragMode() == SdrDragMode::Move && mpView->IsRotateAllowed() &&
197 (mpViewShell->GetFrameView()->IsClickChangeRotation() ||
198 (pSingleObj && pSingleObj->GetObjInventor()==SdrInventor::E3d))))
200 mpView->SetDragMode(SdrDragMode::Rotate);
202 else
204 mpView->SetDragMode(SdrDragMode::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;
221 void FuConstruct::Activate()
223 mpView->SetEditMode(SdrViewEditMode::Create);
224 FuDraw::Activate();
227 void FuConstruct::Deactivate()
229 FuDraw::Deactivate();
230 mpView->SetEditMode(SdrViewEditMode::Edit);
234 * set style sheet for the object to be created
236 void FuConstruct::SetStyleSheet(SfxItemSet& rAttr, SdrObject* pObj)
238 bool bUseFillStyle, bUseNoFillStyle;
239 bUseFillStyle = bUseNoFillStyle = false;
241 switch( nSlotId )
243 case SID_DRAW_RECT:
244 case SID_DRAW_RECT_ROUND:
245 case SID_DRAW_SQUARE:
246 case SID_DRAW_SQUARE_ROUND:
247 case SID_DRAW_ELLIPSE:
248 case SID_DRAW_PIE:
249 case SID_DRAW_ELLIPSECUT:
250 case SID_DRAW_CIRCLE:
251 case SID_DRAW_CIRCLEPIE:
252 case SID_DRAW_CIRCLECUT:
253 case SID_DRAW_POLYGON:
254 case SID_DRAW_XPOLYGON:
255 case SID_DRAW_FREELINE:
256 case SID_DRAW_BEZIER_FILL:
258 bUseFillStyle = true;
259 break;
261 case SID_DRAW_RECT_NOFILL:
262 case SID_DRAW_RECT_ROUND_NOFILL:
263 case SID_DRAW_SQUARE_NOFILL:
264 case SID_DRAW_SQUARE_ROUND_NOFILL:
265 case SID_DRAW_ELLIPSE_NOFILL:
266 case SID_DRAW_PIE_NOFILL:
267 case SID_DRAW_ELLIPSECUT_NOFILL:
268 case SID_DRAW_CIRCLE_NOFILL:
269 case SID_DRAW_CIRCLEPIE_NOFILL:
270 case SID_DRAW_CIRCLECUT_NOFILL:
271 case SID_DRAW_POLYGON_NOFILL:
272 case SID_DRAW_XPOLYGON_NOFILL:
273 case SID_DRAW_FREELINE_NOFILL:
274 case SID_DRAW_LINE:
275 case SID_DRAW_XLINE:
276 case SID_CONNECTOR_ARROW_START:
277 case SID_CONNECTOR_ARROW_END:
278 case SID_CONNECTOR_ARROWS:
279 case SID_CONNECTOR_CIRCLE_START:
280 case SID_CONNECTOR_CIRCLE_END:
281 case SID_CONNECTOR_CIRCLES:
282 case SID_CONNECTOR_LINE:
283 case SID_CONNECTOR_LINE_ARROW_START:
284 case SID_CONNECTOR_LINE_ARROW_END:
285 case SID_CONNECTOR_LINE_ARROWS:
286 case SID_CONNECTOR_LINE_CIRCLE_START:
287 case SID_CONNECTOR_LINE_CIRCLE_END:
288 case SID_CONNECTOR_LINE_CIRCLES:
289 case SID_CONNECTOR_CURVE:
290 case SID_CONNECTOR_CURVE_ARROW_START:
291 case SID_CONNECTOR_CURVE_ARROW_END:
292 case SID_CONNECTOR_CURVE_ARROWS:
293 case SID_CONNECTOR_CURVE_CIRCLE_START:
294 case SID_CONNECTOR_CURVE_CIRCLE_END:
295 case SID_CONNECTOR_CURVE_CIRCLES:
296 case SID_CONNECTOR_LINES:
297 case SID_CONNECTOR_LINES_ARROW_START:
298 case SID_CONNECTOR_LINES_ARROW_END:
299 case SID_CONNECTOR_LINES_ARROWS:
300 case SID_CONNECTOR_LINES_CIRCLE_START:
301 case SID_CONNECTOR_LINES_CIRCLE_END:
302 case SID_CONNECTOR_LINES_CIRCLES:
303 case SID_DRAW_BEZIER_NOFILL:
304 case SID_LINE_ARROW_END:
306 bUseNoFillStyle = true;
307 break;
310 SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
313 void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
314 const bool bForceFillStyle, const bool bForceNoFillStyle )
316 SdPage* pPage = static_cast<SdPage*>(mpView->GetSdrPageView()->GetPage());
317 if ( pPage->IsMasterPage() && pPage->GetPageKind() == PageKind::Standard &&
318 mpDoc->GetDocumentType() == DocumentType::Impress )
320 /**********************************************
321 * Objects was created on the slide master page
322 ***********************************************/
323 OUString aName( pPage->GetLayoutName() );
324 sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + SD_LT_SEPARATOR.getLength();
325 aName = OUString::Concat(aName.subView(0, n)) + STR_LAYOUT_BACKGROUNDOBJECTS;
326 SfxStyleSheet* pSheet(
327 static_cast< SfxStyleSheet* >(
328 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page)));
329 DBG_ASSERT(pSheet, "StyleSheet missing");
330 if (pSheet)
332 // applying style sheet for background objects
333 pObj->SetStyleSheet(pSheet, false);
334 SfxItemSet& rSet = pSheet->GetItemSet();
335 const XFillStyleItem& rFillStyle = rSet.Get(XATTR_FILLSTYLE);
336 if ( bForceFillStyle )
338 if (rFillStyle.GetValue() == drawing::FillStyle_NONE)
339 rAttr.Put(XFillStyleItem(drawing::FillStyle_SOLID));
341 else if ( bForceNoFillStyle )
343 if (rFillStyle.GetValue() != drawing::FillStyle_NONE)
344 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
348 else
350 /***********************************
351 * object was created on normal page
352 ************************************/
353 if ( bForceNoFillStyle )
355 OUString aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL));
356 SfxStyleSheet* pSheet(
357 static_cast< SfxStyleSheet* >(
358 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
359 DBG_ASSERT(pSheet, "Stylesheet missing");
360 if (pSheet)
362 pObj->SetStyleSheet(pSheet, false);
363 SfxItemSet aAttr(mpView->GetDefaultAttr());
364 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
365 pObj->SetMergedItemSet(aAttr);
367 else
369 SfxItemSet aAttr(mpView->GetDefaultAttr());
370 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
371 pObj->SetMergedItemSet(aAttr);
377 } // end of namespace sd
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */