1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
31 #include <strings.hrc>
32 #include <strings.hxx>
36 #include <ViewShell.hxx>
37 #include <drawdoc.hxx>
38 #include <FrameView.hxx>
40 #include <sdresid.hxx>
41 #include <stlpool.hxx>
42 #include <svx/globl3d.hxx>
44 using namespace com::sun::star
;
49 FuConstruct::FuConstruct (
55 : FuDraw(pViewSh
, pWin
, pView
, pDoc
, rReq
),
56 bSelectionChanged(false)
60 bool FuConstruct::MouseButtonDown(const MouseEvent
& rMEvt
)
62 bool bReturn
= FuDraw::MouseButtonDown(rMEvt
);
65 bSelectionChanged
= false;
67 if ( mpView
->IsAction() )
72 bFirstMouseMove
= true;
75 aMDPos
= mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() );
76 sal_uInt16 nHitLog
= sal_uInt16 (mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width());
78 if (rMEvt
.IsLeft() && mpView
->IsExtendedMouseEventDispatcherEnabled())
80 mpWindow
->CaptureMouse();
82 SdrHdl
* pHdl
= mpView
->PickHandle(aMDPos
);
84 if ( pHdl
!= nullptr || mpView
->IsMarkedHit(aMDPos
, nHitLog
) )
86 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
87 mpView
->BegDragObj(aMDPos
, nullptr, pHdl
, nDrgLog
);
90 else if ( mpView
->AreObjectsMarked() )
100 bool FuConstruct::MouseMove(const MouseEvent
& rMEvt
)
102 FuDraw::MouseMove(rMEvt
);
104 if (aDragTimer
.IsActive() )
106 if( bFirstMouseMove
)
107 bFirstMouseMove
= false;
112 Point
aPix(rMEvt
.GetPosPixel());
113 Point
aPnt( mpWindow
->PixelToLogic(aPix
) );
115 if ( mpView
->IsAction() )
118 mpView
->MovAction(aPnt
);
124 bool FuConstruct::MouseButtonUp(const MouseEvent
& rMEvt
)
128 if (aDragTimer
.IsActive() )
131 bIsInDragMode
= false;
134 FuDraw::MouseButtonUp(rMEvt
);
136 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
138 if ( mpView
&& mpView
->IsDragObj() )
140 FrameView
* pFrameView
= mpViewShell
->GetFrameView();
141 bool bDragWithCopy
= (rMEvt
.IsMod1() && pFrameView
->IsDragWithCopy());
145 bDragWithCopy
= !mpView
->IsPresObjSelected(false);
148 mpView
->SetDragWithCopy(bDragWithCopy
);
149 mpView
->EndDragObj( mpView
->IsDragWithCopy() );
151 else if ( mpView
&& mpView
->IsMarkObj() )
153 mpView
->EndMarkObj();
160 if ( mpView
&& !mpView
->IsAction() )
162 mpWindow
->ReleaseMouse();
163 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
165 if ( !mpView
->AreObjectsMarked() )
168 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
170 SdrObject
* pObj
= mpView
->PickObj(aPnt
, mpView
->getHitTolLog(), pPV
);
173 mpView
->MarkObj(aPnt
, nHitLog
);
176 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
178 else if (rMEvt
.IsLeft() && !rMEvt
.IsShift() && !rMEvt
.IsMod1() && !rMEvt
.IsMod2() &&
179 !bSelectionChanged
&&
180 std::abs(aPnt
.X() - aMDPos
.X()) < nDrgLog
&&
181 std::abs(aPnt
.Y() - aMDPos
.Y()) < nDrgLog
)
183 // toggle between selection and rotation
184 SdrObject
* pSingleObj
= nullptr;
186 if (mpView
->GetMarkedObjectList().GetMarkCount()==1)
188 pSingleObj
= mpView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
191 if (mpView
->GetDragMode() == SdrDragMode::Move
&& mpView
->IsRotateAllowed() &&
192 (mpViewShell
->GetFrameView()->IsClickChangeRotation() ||
193 (pSingleObj
&& pSingleObj
->GetObjInventor()==SdrInventor::E3d
)))
195 mpView
->SetDragMode(SdrDragMode::Rotate
);
199 mpView
->SetDragMode(SdrDragMode::Move
);
204 sal_uInt16 nClicks
= rMEvt
.GetClicks();
206 if (nClicks
== 2 && rMEvt
.IsLeft() && bMBDown
&&
207 !rMEvt
.IsMod1() && !rMEvt
.IsMod2() && !rMEvt
.IsShift() )
216 void FuConstruct::Activate()
218 mpView
->SetEditMode(SdrViewEditMode::Create
);
222 void FuConstruct::Deactivate()
224 FuDraw::Deactivate();
225 mpView
->SetEditMode(SdrViewEditMode::Edit
);
229 * set style sheet for the object to be created
231 void FuConstruct::SetStyleSheet(SfxItemSet
& rAttr
, SdrObject
* pObj
)
233 bool bUseFillStyle
, bUseNoFillStyle
;
234 bUseFillStyle
= bUseNoFillStyle
= false;
239 case SID_DRAW_RECT_ROUND
:
240 case SID_DRAW_SQUARE
:
241 case SID_DRAW_SQUARE_ROUND
:
242 case SID_DRAW_ELLIPSE
:
244 case SID_DRAW_ELLIPSECUT
:
245 case SID_DRAW_CIRCLE
:
246 case SID_DRAW_CIRCLEPIE
:
247 case SID_DRAW_CIRCLECUT
:
248 case SID_DRAW_POLYGON
:
249 case SID_DRAW_XPOLYGON
:
250 case SID_DRAW_FREELINE
:
251 case SID_DRAW_BEZIER_FILL
:
253 bUseFillStyle
= true;
256 case SID_DRAW_RECT_NOFILL
:
257 case SID_DRAW_RECT_ROUND_NOFILL
:
258 case SID_DRAW_SQUARE_NOFILL
:
259 case SID_DRAW_SQUARE_ROUND_NOFILL
:
260 case SID_DRAW_ELLIPSE_NOFILL
:
261 case SID_DRAW_PIE_NOFILL
:
262 case SID_DRAW_ELLIPSECUT_NOFILL
:
263 case SID_DRAW_CIRCLE_NOFILL
:
264 case SID_DRAW_CIRCLEPIE_NOFILL
:
265 case SID_DRAW_CIRCLECUT_NOFILL
:
266 case SID_DRAW_POLYGON_NOFILL
:
267 case SID_DRAW_XPOLYGON_NOFILL
:
268 case SID_DRAW_FREELINE_NOFILL
:
271 case SID_CONNECTOR_ARROW_START
:
272 case SID_CONNECTOR_ARROW_END
:
273 case SID_CONNECTOR_ARROWS
:
274 case SID_CONNECTOR_CIRCLE_START
:
275 case SID_CONNECTOR_CIRCLE_END
:
276 case SID_CONNECTOR_CIRCLES
:
277 case SID_CONNECTOR_LINE
:
278 case SID_CONNECTOR_LINE_ARROW_START
:
279 case SID_CONNECTOR_LINE_ARROW_END
:
280 case SID_CONNECTOR_LINE_ARROWS
:
281 case SID_CONNECTOR_LINE_CIRCLE_START
:
282 case SID_CONNECTOR_LINE_CIRCLE_END
:
283 case SID_CONNECTOR_LINE_CIRCLES
:
284 case SID_CONNECTOR_CURVE
:
285 case SID_CONNECTOR_CURVE_ARROW_START
:
286 case SID_CONNECTOR_CURVE_ARROW_END
:
287 case SID_CONNECTOR_CURVE_ARROWS
:
288 case SID_CONNECTOR_CURVE_CIRCLE_START
:
289 case SID_CONNECTOR_CURVE_CIRCLE_END
:
290 case SID_CONNECTOR_CURVE_CIRCLES
:
291 case SID_CONNECTOR_LINES
:
292 case SID_CONNECTOR_LINES_ARROW_START
:
293 case SID_CONNECTOR_LINES_ARROW_END
:
294 case SID_CONNECTOR_LINES_ARROWS
:
295 case SID_CONNECTOR_LINES_CIRCLE_START
:
296 case SID_CONNECTOR_LINES_CIRCLE_END
:
297 case SID_CONNECTOR_LINES_CIRCLES
:
298 case SID_DRAW_BEZIER_NOFILL
:
299 case SID_LINE_ARROW_END
:
301 bUseNoFillStyle
= true;
305 SetStyleSheet( rAttr
, pObj
, bUseFillStyle
, bUseNoFillStyle
);
308 void FuConstruct::SetStyleSheet( SfxItemSet
& rAttr
, SdrObject
* pObj
,
309 const bool bForceFillStyle
, const bool bForceNoFillStyle
)
311 SdPage
* pPage
= static_cast<SdPage
*>(mpView
->GetSdrPageView()->GetPage());
312 if ( pPage
->IsMasterPage() && pPage
->GetPageKind() == PageKind::Standard
&&
313 mpDoc
->GetDocumentType() == DocumentType::Impress
)
315 /**********************************************
316 * Objects was created on the slide master page
317 ***********************************************/
318 OUString
aName( pPage
->GetLayoutName() );
319 sal_Int32 n
= aName
.indexOf(SD_LT_SEPARATOR
) + strlen(SD_LT_SEPARATOR
);
320 aName
= aName
.copy(0, n
) + STR_LAYOUT_BACKGROUNDOBJECTS
;
321 SfxStyleSheet
* pSheet(
322 static_cast< SfxStyleSheet
* >(
323 pPage
->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName
, SfxStyleFamily::Page
)));
324 DBG_ASSERT(pSheet
, "StyleSheet missing");
327 // applying style sheet for background objects
328 pObj
->SetStyleSheet(pSheet
, false);
329 SfxItemSet
& rSet
= pSheet
->GetItemSet();
330 const XFillStyleItem
& rFillStyle
= rSet
.Get(XATTR_FILLSTYLE
);
331 if ( bForceFillStyle
)
333 if (rFillStyle
.GetValue() == drawing::FillStyle_NONE
)
334 rAttr
.Put(XFillStyleItem(drawing::FillStyle_SOLID
));
336 else if ( bForceNoFillStyle
)
338 if (rFillStyle
.GetValue() != drawing::FillStyle_NONE
)
339 rAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
345 /***********************************
346 * object was created on normal page
347 ************************************/
348 if ( bForceNoFillStyle
)
350 OUString
aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL
));
351 SfxStyleSheet
* pSheet(
352 static_cast< SfxStyleSheet
* >(
353 pPage
->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName
, SfxStyleFamily::Para
)));
354 DBG_ASSERT(pSheet
, "Stylesheet missing");
357 pObj
->SetStyleSheet(pSheet
, false);
358 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
359 aAttr
.Put(pSheet
->GetItemSet().Get(XATTR_FILLSTYLE
));
360 pObj
->SetMergedItemSet(aAttr
);
364 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
365 rAttr
.Put(XFillStyleItem(drawing::FillStyle_NONE
));
366 pObj
->SetMergedItemSet(aAttr
);
372 } // end of namespace sd
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */