LibreOffice Module sd (master) 1
fuconstr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <fuconstr.hxx>
21
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>
33
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>
47
48using namespace com::sun::star;
49
50namespace sd {
51
52
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)
61{
62}
63
65{
66 bool bReturn = FuDraw::MouseButtonDown(rMEvt);
67
68 bMBDown = true;
69 bSelectionChanged = false;
70
71 if ( mpView->IsAction() )
72 {
73 return true;
74 }
75
76 bFirstMouseMove = true;
78
79 aMDPos = mpWindow->PixelToLogic( rMEvt.GetPosPixel() );
80 sal_uInt16 nHitLog = sal_uInt16 (mpWindow->PixelToLogic(Size(HITPIX,0)).Width());
81
83 {
84 mpWindow->CaptureMouse();
85
87
88 if ( pHdl != nullptr || mpView->IsMarkedHit(aMDPos, nHitLog) )
89 {
90 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
91 mpView->BegDragObj(aMDPos, nullptr, pHdl, nDrgLog);
92 bReturn = true;
93 }
94 else if ( mpView->AreObjectsMarked() )
95 {
97 bReturn = true;
98 }
99 }
100
101 return bReturn;
102}
103
105{
106 FuDraw::MouseMove(rMEvt);
107
108 if (aDragTimer.IsActive() )
109 {
110 if( bFirstMouseMove )
111 bFirstMouseMove = false;
112 else
114 }
115
116 Point aPix(rMEvt.GetPosPixel());
117 Point aPnt( mpWindow->PixelToLogic(aPix) );
118
119 if ( mpView->IsAction() )
120 {
121 ForceScroll(aPix);
122 mpView->MovAction(aPnt);
123 }
124
125 return true;
126}
127
129{
130 bool bReturn = true;
131
132 if (aDragTimer.IsActive() )
133 {
135 bIsInDragMode = false;
136 }
137
139
140 Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
141
142 if ( mpView && mpView->IsDragObj() )
143 {
144 FrameView* pFrameView = mpViewShell->GetFrameView();
145 bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
146
147 if (bDragWithCopy)
148 {
149 bDragWithCopy = !mpView->IsPresObjSelected(false);
150 }
151
152 mpView->SetDragWithCopy(bDragWithCopy);
154 }
155 else if ( mpView && mpView->IsMarkObj() )
156 {
158 }
159 else
160 {
161 bReturn = false;
162 }
163
164 if ( mpView && !mpView->IsAction() )
165 {
166 mpWindow->ReleaseMouse();
167 sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() );
168
169 if ( !mpView->AreObjectsMarked() )
170 {
171 SdrPageView* pPV;
172 sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
173
174 SdrObject* pObj = mpView->PickObj(aPnt, mpView->getHitTolLog(), pPV);
175 if (!pObj)
176 {
177 mpView->MarkObj(aPnt, nHitLog);
178 }
179
180 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
181 }
182 else if (rMEvt.IsLeft() && !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() &&
184 std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
185 std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
186 {
187 // toggle between selection and rotation
188 SdrObject* pSingleObj = nullptr;
189
191 {
193 }
194
195 const bool bTiledRendering = comphelper::LibreOfficeKit::isActive();
196 if (!bTiledRendering && (mpView->GetDragMode() == SdrDragMode::Move && mpView->IsRotateAllowed() &&
198 (pSingleObj && pSingleObj->GetObjInventor()==SdrInventor::E3d))))
199 {
200 mpView->SetDragMode(SdrDragMode::Rotate);
201 }
202 else
203 {
204 mpView->SetDragMode(SdrDragMode::Move);
205 }
206 }
207 }
208
209 sal_uInt16 nClicks = rMEvt.GetClicks();
210
211 if (nClicks == 2 && rMEvt.IsLeft() && bMBDown &&
212 !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift() )
213 {
214 DoubleClick(rMEvt);
215 }
216 bMBDown = false;
217
218 return bReturn;
219}
220
222{
223 mpView->SetEditMode(SdrViewEditMode::Create);
225}
226
228{
230 mpView->SetEditMode(SdrViewEditMode::Edit);
231}
232
234{
235 // tdf#153446 if there is a MouseButtonUp without a previous MouseButtonDown event,
236 // the MouseButtonDown was probably swallowed by a gain-focus action,
237 // and then this MouseButtonUp should be ignored
238
239 if (bMBDown || bIsInDragMode)
240 return false;
241
242 // Don't ignore if there are pending mouse-initiated tasks to complete.
243 return !mpView->IsDragObj() && !mpWindow->IsMouseCaptured() && !mpView->IsAction();
244}
245
250{
251 bool bUseFillStyle, bUseNoFillStyle;
252 bUseFillStyle = bUseNoFillStyle = false;
253
254 switch( nSlotId )
255 {
256 case SID_DRAW_RECT:
257 case SID_DRAW_RECT_ROUND:
258 case SID_DRAW_SQUARE:
259 case SID_DRAW_SQUARE_ROUND:
260 case SID_DRAW_ELLIPSE:
261 case SID_DRAW_PIE:
262 case SID_DRAW_ELLIPSECUT:
263 case SID_DRAW_CIRCLE:
264 case SID_DRAW_CIRCLEPIE:
265 case SID_DRAW_CIRCLECUT:
266 case SID_DRAW_POLYGON:
267 case SID_DRAW_XPOLYGON:
268 case SID_DRAW_FREELINE:
269 case SID_DRAW_BEZIER_FILL:
270 {
271 bUseFillStyle = true;
272 break;
273 }
274 case SID_DRAW_RECT_NOFILL:
275 case SID_DRAW_RECT_ROUND_NOFILL:
276 case SID_DRAW_SQUARE_NOFILL:
277 case SID_DRAW_SQUARE_ROUND_NOFILL:
278 case SID_DRAW_ELLIPSE_NOFILL:
279 case SID_DRAW_PIE_NOFILL:
280 case SID_DRAW_ELLIPSECUT_NOFILL:
281 case SID_DRAW_CIRCLE_NOFILL:
282 case SID_DRAW_CIRCLEPIE_NOFILL:
283 case SID_DRAW_CIRCLECUT_NOFILL:
284 case SID_DRAW_POLYGON_NOFILL:
285 case SID_DRAW_XPOLYGON_NOFILL:
286 case SID_DRAW_FREELINE_NOFILL:
287 case SID_DRAW_LINE:
288 case SID_DRAW_XLINE:
289 case SID_CONNECTOR_ARROW_START:
290 case SID_CONNECTOR_ARROW_END:
291 case SID_CONNECTOR_ARROWS:
292 case SID_CONNECTOR_CIRCLE_START:
293 case SID_CONNECTOR_CIRCLE_END:
294 case SID_CONNECTOR_CIRCLES:
295 case SID_CONNECTOR_LINE:
296 case SID_CONNECTOR_LINE_ARROW_START:
297 case SID_CONNECTOR_LINE_ARROW_END:
298 case SID_CONNECTOR_LINE_ARROWS:
299 case SID_CONNECTOR_LINE_CIRCLE_START:
300 case SID_CONNECTOR_LINE_CIRCLE_END:
301 case SID_CONNECTOR_LINE_CIRCLES:
302 case SID_CONNECTOR_CURVE:
303 case SID_CONNECTOR_CURVE_ARROW_START:
304 case SID_CONNECTOR_CURVE_ARROW_END:
305 case SID_CONNECTOR_CURVE_ARROWS:
306 case SID_CONNECTOR_CURVE_CIRCLE_START:
307 case SID_CONNECTOR_CURVE_CIRCLE_END:
308 case SID_CONNECTOR_CURVE_CIRCLES:
309 case SID_CONNECTOR_LINES:
310 case SID_CONNECTOR_LINES_ARROW_START:
311 case SID_CONNECTOR_LINES_ARROW_END:
312 case SID_CONNECTOR_LINES_ARROWS:
313 case SID_CONNECTOR_LINES_CIRCLE_START:
314 case SID_CONNECTOR_LINES_CIRCLE_END:
315 case SID_CONNECTOR_LINES_CIRCLES:
316 case SID_DRAW_BEZIER_NOFILL:
317 case SID_LINE_ARROW_END:
318 {
319 bUseNoFillStyle = true;
320 break;
321 }
322 }
323 SetStyleSheet( rAttr, pObj, bUseFillStyle, bUseNoFillStyle );
324}
325
327 const bool bForceFillStyle, const bool bForceNoFillStyle )
328{
329 SdPage* pPage = static_cast<SdPage*>(mpView->GetSdrPageView()->GetPage());
330 if ( pPage->IsMasterPage() && pPage->GetPageKind() == PageKind::Standard &&
332 {
333 /**********************************************
334 * Objects was created on the slide master page
335 ***********************************************/
336 OUString aName( pPage->GetLayoutName() );
337 sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + SD_LT_SEPARATOR.getLength();
338 aName = OUString::Concat(aName.subView(0, n)) + STR_LAYOUT_BACKGROUNDOBJECTS;
339 SfxStyleSheet* pSheet(
340 static_cast< SfxStyleSheet* >(
341 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page)));
342 DBG_ASSERT(pSheet, "StyleSheet missing");
343 if (pSheet)
344 {
345 // applying style sheet for background objects
346 pObj->SetStyleSheet(pSheet, false);
347 SfxItemSet& rSet = pSheet->GetItemSet();
348 const XFillStyleItem& rFillStyle = rSet.Get(XATTR_FILLSTYLE);
349 if ( bForceFillStyle )
350 {
351 if (rFillStyle.GetValue() == drawing::FillStyle_NONE)
352 rAttr.Put(XFillStyleItem(drawing::FillStyle_SOLID));
353 }
354 else if ( bForceNoFillStyle )
355 {
356 if (rFillStyle.GetValue() != drawing::FillStyle_NONE)
357 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
358 }
359 }
360 }
361 else
362 {
363 /***********************************
364 * object was created on normal page
365 ************************************/
366 if ( bForceNoFillStyle )
367 {
368 OUString aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL));
369 SfxStyleSheet* pSheet(
370 static_cast< SfxStyleSheet* >(
371 pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
372 DBG_ASSERT(pSheet, "Stylesheet missing");
373 if (pSheet)
374 {
375 pObj->SetStyleSheet(pSheet, false);
377 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
378 pObj->SetMergedItemSet(aAttr);
379 }
380 else
381 {
383 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
384 pObj->SetMergedItemSet(aAttr);
385 }
386 }
387 }
388}
389
390} // end of namespace sd
391
392/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool BegDragObj(const Point &rPnt, OutputDevice *pOut, SdrHdl *pHdl, short nMinMov=-3, SdrDragMethod *pForcedMeth=nullptr) override
virtual void MovAction(const Point &rPnt) override
bool IsMod1() const
bool IsMod2() const
sal_uInt16 GetClicks() const
const Point & GetPosPixel() const
bool IsLeft() const
bool IsShift() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
PageKind GetPageKind() const
Definition: sdpage.hxx:205
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
void SetEditMode(SdrViewEditMode eMode)
virtual bool IsAction() const override
bool EndDragObj(bool bCopy=false)
sal_Int32 GetDragThresholdPixels() const
bool IsDragWithCopy() const
void SetDragWithCopy(bool bOn)
bool IsDragObj() const
bool IsRotateAllowed(bool b90Deg=false) const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
void SetDragMode(SdrDragMode eMode)
SdrHdl * PickHandle(const Point &rPnt) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
SdrObject * PickObj(const Point &rPnt, short nTol, SdrPageView *&rpPV, SdrSearchOptions nOptions, SdrObject **ppRootObj, bool *pbHitPassDirect=nullptr) const
bool IsMarkObj() const
SdrDragMode GetDragMode() const
bool IsMarkedHit(const Point &rPnt, short nTol=-2) const
bool EndMarkObj()
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrObject * GetMarkedSdrObj() const
SfxStyleSheetBasePool * GetStyleSheetPool() const
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
virtual SdrInventor GetObjInventor() const
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
SdrPage * GetPage() const
bool IsMasterPage() const
SdrModel & getSdrModelFromSdrPage() const
const SfxItemSet & GetDefaultAttr() const
SdrPageView * GetSdrPageView() const
sal_uInt16 getHitTolLog() const
bool IsExtendedMouseEventDispatcherEnabled() const
void UnmarkAll()
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual SfxItemSet & GetItemSet()
SfxDispatcher * GetDispatcher()
bool IsActive() const
void Stop()
virtual void Start(bool bStartTimer=true) override
View for MDIFrame.
Definition: FrameView.hxx:36
bool IsClickChangeRotation() const
Definition: FrameView.hxx:130
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:104
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:128
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fuconstr.cxx:64
virtual void Deactivate() override
deactivates the function
Definition: fuconstr.cxx:227
virtual void Activate() override
activates the function
Definition: fuconstr.cxx:221
void SetStyleSheet(SfxItemSet &rAttr, SdrObject *pObj)
set style sheet for the object to be created
Definition: fuconstr.cxx:249
bool IsIgnoreUnexpectedMouseButtonUp()
Definition: fuconstr.cxx:233
bool bSelectionChanged
Definition: fuconstr.hxx:62
FuConstruct(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuconstr.cxx:53
Base class for all Draw specific functions.
Definition: fudraw.hxx:34
virtual void Activate() override
activates the function
Definition: fudraw.cxx:441
bool bMBDown
Definition: fudraw.hxx:73
virtual bool MouseMove(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:214
virtual void DoubleClick(const MouseEvent &rMEvt)
Response of doubleclick.
Definition: fudraw.cxx:627
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:274
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: fudraw.cxx:141
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
Point aMDPos
position of MouseButtonDown
Definition: fupoor.hxx:159
ViewShell * mpViewShell
Definition: fupoor.hxx:145
sal_uInt16 nSlotId
Definition: fupoor.hxx:150
void ForceScroll(const Point &aPixPos)
scroll when approached the border of the window; is called by MouseMove
Definition: fupoor.cxx:121
virtual void Deactivate()
deactivates the function
Definition: fupoor.cxx:102
bool bIsInDragMode
Definition: fupoor.hxx:158
Timer aDragTimer
for Drag&Drop
Definition: fupoor.hxx:156
::sd::View * mpView
Definition: fupoor.hxx:144
static const int HITPIX
Definition: fupoor.hxx:50
bool bFirstMouseMove
Definition: fupoor.hxx:168
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
FrameView * GetFrameView()
Definition: ViewShell.hxx:221
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
bool IsPresObjSelected(bool bOnPage=true, bool bOnMasterPage=true, bool bCheckPresObjListOnly=false, bool bCheckLayoutOnly=false) const
Is a presentation object selected?
Definition: sdview.cxx:523
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral SD_LT_SEPARATOR
Definition: glob.hxx:49
OUString aName
sal_Int64 n
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
static SfxItemSet & rSet
constexpr OUStringLiteral STR_LAYOUT_BACKGROUNDOBJECTS
Definition: strings.hxx:18
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)