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 .
21 #include "fuconstr.hxx"
23 #include <svx/svxids.hrc>
24 #include <svl/aeitem.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <svx/xdef.hxx>
27 #include <svx/xfillit0.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/viewfrm.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>
46 TYPEINIT1( FuConstruct
, FuDraw
);
49 FuConstruct::FuConstruct (
55 : FuDraw(pViewSh
, pWin
, pView
, pDoc
, rReq
),
56 bSelectionChanged(sal_False
)
60 void FuConstruct::DoExecute( SfxRequest
& rReq
)
62 FuDraw::DoExecute( rReq
);
66 sal_Bool
FuConstruct::MouseButtonDown(const MouseEvent
& rMEvt
)
68 sal_Bool bReturn
= FuDraw::MouseButtonDown(rMEvt
);
71 bSelectionChanged
= sal_False
;
73 if ( mpView
->IsAction() )
78 bFirstMouseMove
= sal_True
;
81 aMDPos
= mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() );
82 sal_uInt16 nHitLog
= sal_uInt16 (mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width());
84 if (rMEvt
.IsLeft() && mpView
->IsExtendedMouseEventDispatcherEnabled())
86 mpWindow
->CaptureMouse();
88 SdrHdl
* pHdl
= mpView
->PickHandle(aMDPos
);
90 if ( pHdl
!= NULL
|| mpView
->IsMarkedHit(aMDPos
, nHitLog
) )
92 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
93 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
96 else if ( mpView
->AreObjectsMarked() )
107 sal_Bool
FuConstruct::MouseMove(const MouseEvent
& rMEvt
)
109 FuDraw::MouseMove(rMEvt
);
111 if (aDragTimer
.IsActive() )
113 if( bFirstMouseMove
)
114 bFirstMouseMove
= sal_False
;
119 Point
aPix(rMEvt
.GetPosPixel());
120 Point
aPnt( mpWindow
->PixelToLogic(aPix
) );
122 if ( mpView
->IsAction() )
125 mpView
->MovAction(aPnt
);
132 sal_Bool
FuConstruct::MouseButtonUp(const MouseEvent
& rMEvt
)
134 sal_Bool bReturn
= sal_True
;
136 if (aDragTimer
.IsActive() )
139 bIsInDragMode
= sal_False
;
142 FuDraw::MouseButtonUp(rMEvt
);
144 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
146 if ( mpView
&& mpView
->IsDragObj() )
148 FrameView
* pFrameView
= mpViewShell
->GetFrameView();
149 sal_Bool bDragWithCopy
= (rMEvt
.IsMod1() && pFrameView
->IsDragWithCopy());
153 bDragWithCopy
= !mpView
->IsPresObjSelected(sal_False
, sal_True
);
156 mpView
->SetDragWithCopy(bDragWithCopy
);
157 mpView
->EndDragObj( mpView
->IsDragWithCopy() );
159 else if ( mpView
&& mpView
->IsMarkObj() )
161 mpView
->EndMarkObj();
168 if ( mpView
&& !mpView
->IsAction() )
170 mpWindow
->ReleaseMouse();
171 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
173 if ( !mpView
->AreObjectsMarked() )
177 sal_uInt16 nHitLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
179 if (!mpView
->PickObj(aPnt
, mpView
->getHitTolLog(), pObj
, pPV
))
181 mpView
->MarkObj(aPnt
, nHitLog
);
184 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
186 else if (rMEvt
.IsLeft() && !rMEvt
.IsShift() && !rMEvt
.IsMod1() && !rMEvt
.IsMod2() &&
187 !bSelectionChanged
&&
188 std::abs(aPnt
.X() - aMDPos
.X()) < nDrgLog
&&
189 std::abs(aPnt
.Y() - aMDPos
.Y()) < nDrgLog
)
191 // toggle between selection and rotation
192 SdrObject
* pSingleObj
= NULL
;
193 sal_uLong nMarkCount
= mpView
->GetMarkedObjectList().GetMarkCount();
197 pSingleObj
= mpView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
200 if (mpView
->GetDragMode() == SDRDRAG_MOVE
&& mpView
->IsRotateAllowed() &&
201 (mpViewShell
->GetFrameView()->IsClickChangeRotation() ||
202 (pSingleObj
&& pSingleObj
->GetObjInventor()==E3dInventor
)))
204 mpView
->SetDragMode(SDRDRAG_ROTATE
);
208 mpView
->SetDragMode(SDRDRAG_MOVE
);
213 sal_uInt16 nClicks
= rMEvt
.GetClicks();
215 if (nClicks
== 2 && rMEvt
.IsLeft() && bMBDown
&&
216 !rMEvt
.IsMod1() && !rMEvt
.IsMod2() && !rMEvt
.IsShift() )
226 * Process keyboard input
227 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
229 sal_Bool
FuConstruct::KeyInput(const KeyEvent
& rKEvt
)
231 sal_Bool bReturn
= sal_False
;
234 bReturn
= FuDraw::KeyInput(rKEvt
);
240 void FuConstruct::Activate()
242 mpView
->SetEditMode(SDREDITMODE_CREATE
);
247 void FuConstruct::Deactivate()
249 FuDraw::Deactivate();
250 mpView
->SetEditMode(SDREDITMODE_EDIT
);
254 * set style sheet for the object to be created
256 void FuConstruct::SetStyleSheet(SfxItemSet
& rAttr
, SdrObject
* pObj
)
258 sal_Bool bUseFillStyle
, bUseNoFillStyle
;
259 bUseFillStyle
= bUseNoFillStyle
= sal_False
;
264 case SID_DRAW_RECT_ROUND
:
265 case SID_DRAW_SQUARE
:
266 case SID_DRAW_SQUARE_ROUND
:
267 case SID_DRAW_ELLIPSE
:
269 case SID_DRAW_ELLIPSECUT
:
270 case SID_DRAW_CIRCLE
:
271 case SID_DRAW_CIRCLEPIE
:
272 case SID_DRAW_CIRCLECUT
:
273 case SID_DRAW_POLYGON
:
274 case SID_DRAW_XPOLYGON
:
275 case SID_DRAW_FREELINE
:
276 case SID_DRAW_BEZIER_FILL
:
278 bUseFillStyle
= sal_True
;
281 case SID_DRAW_RECT_NOFILL
:
282 case SID_DRAW_RECT_ROUND_NOFILL
:
283 case SID_DRAW_SQUARE_NOFILL
:
284 case SID_DRAW_SQUARE_ROUND_NOFILL
:
285 case SID_DRAW_ELLIPSE_NOFILL
:
286 case SID_DRAW_PIE_NOFILL
:
287 case SID_DRAW_ELLIPSECUT_NOFILL
:
288 case SID_DRAW_CIRCLE_NOFILL
:
289 case SID_DRAW_CIRCLEPIE_NOFILL
:
290 case SID_DRAW_CIRCLECUT_NOFILL
:
291 case SID_DRAW_POLYGON_NOFILL
:
292 case SID_DRAW_XPOLYGON_NOFILL
:
293 case SID_DRAW_FREELINE_NOFILL
:
296 case SID_CONNECTOR_ARROW_START
:
297 case SID_CONNECTOR_ARROW_END
:
298 case SID_CONNECTOR_ARROWS
:
299 case SID_CONNECTOR_CIRCLE_START
:
300 case SID_CONNECTOR_CIRCLE_END
:
301 case SID_CONNECTOR_CIRCLES
:
302 case SID_CONNECTOR_LINE
:
303 case SID_CONNECTOR_LINE_ARROW_START
:
304 case SID_CONNECTOR_LINE_ARROW_END
:
305 case SID_CONNECTOR_LINE_ARROWS
:
306 case SID_CONNECTOR_LINE_CIRCLE_START
:
307 case SID_CONNECTOR_LINE_CIRCLE_END
:
308 case SID_CONNECTOR_LINE_CIRCLES
:
309 case SID_CONNECTOR_CURVE
:
310 case SID_CONNECTOR_CURVE_ARROW_START
:
311 case SID_CONNECTOR_CURVE_ARROW_END
:
312 case SID_CONNECTOR_CURVE_ARROWS
:
313 case SID_CONNECTOR_CURVE_CIRCLE_START
:
314 case SID_CONNECTOR_CURVE_CIRCLE_END
:
315 case SID_CONNECTOR_CURVE_CIRCLES
:
316 case SID_CONNECTOR_LINES
:
317 case SID_CONNECTOR_LINES_ARROW_START
:
318 case SID_CONNECTOR_LINES_ARROW_END
:
319 case SID_CONNECTOR_LINES_ARROWS
:
320 case SID_CONNECTOR_LINES_CIRCLE_START
:
321 case SID_CONNECTOR_LINES_CIRCLE_END
:
322 case SID_CONNECTOR_LINES_CIRCLES
:
323 case SID_DRAW_BEZIER_NOFILL
:
324 case SID_LINE_ARROW_END
:
326 bUseNoFillStyle
= sal_True
;
330 SetStyleSheet( rAttr
, pObj
, bUseFillStyle
, bUseNoFillStyle
);
333 void FuConstruct::SetStyleSheet( SfxItemSet
& rAttr
, SdrObject
* pObj
,
334 const sal_Bool bForceFillStyle
, const sal_Bool bForceNoFillStyle
)
336 SdPage
* pPage
= (SdPage
*)mpView
->GetSdrPageView()->GetPage();
337 if ( pPage
->IsMasterPage() && pPage
->GetPageKind() == PK_STANDARD
&&
338 mpDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
)
340 /**********************************************
341 * Objects was created on the slide master page
342 ***********************************************/
343 String
aName( pPage
->GetLayoutName() );
344 String aSep
= OUString(SD_LT_SEPARATOR
);
345 sal_uInt16 n
= aName
.Search(aSep
);
348 aName
.Append( String ( SdResId( STR_LAYOUT_BACKGROUNDOBJECTS
) ) );
349 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pPage
->GetModel()->
350 GetStyleSheetPool()->
351 Find(aName
, SD_STYLE_FAMILY_MASTERPAGE
);
352 DBG_ASSERT(pSheet
, "StyleSheet missing");
355 // applying style sheet for background objects
356 pObj
->SetStyleSheet(pSheet
, sal_False
);
357 SfxItemSet
& rSet
= pSheet
->GetItemSet();
358 const XFillStyleItem
& rFillStyle
= (const XFillStyleItem
&)rSet
.Get(XATTR_FILLSTYLE
);
359 if ( bForceFillStyle
)
361 if (rFillStyle
.GetValue() == XFILL_NONE
)
362 rAttr
.Put(XFillStyleItem(XFILL_SOLID
));
364 else if ( bForceNoFillStyle
)
366 if (rFillStyle
.GetValue() != XFILL_NONE
)
367 rAttr
.Put(XFillStyleItem(XFILL_NONE
));
373 /***********************************
374 * object was created on normal page
375 ************************************/
376 if ( bForceNoFillStyle
)
378 String
aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL
));
379 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pPage
->GetModel()->
380 GetStyleSheetPool()->
381 Find(aName
, SD_STYLE_FAMILY_GRAPHICS
);
382 DBG_ASSERT(pSheet
, "Stylesheet missing");
385 pObj
->SetStyleSheet(pSheet
, sal_False
);
386 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
387 aAttr
.Put(pSheet
->GetItemSet().Get(XATTR_FILLSTYLE
));
388 pObj
->SetMergedItemSet(aAttr
);
392 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
393 rAttr
.Put(XFillStyleItem(XFILL_NONE
));
394 pObj
->SetMergedItemSet(aAttr
);
400 } // end of namespace sd
402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */