1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconstr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "fuconstr.hxx"
36 #include <svx/svxids.hrc>
37 #include <svtools/aeitem.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <svx/xdef.hxx>
40 #include <svx/xfillit0.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/viewfrm.hxx>
49 #include "ViewShell.hxx"
50 #include "drawdoc.hxx"
51 #include "FrameView.hxx"
53 #include "sdresid.hxx"
54 #include "stlpool.hxx"
55 #include <svx/globl3d.hxx>
59 TYPEINIT1( FuConstruct
, FuDraw
);
61 /*************************************************************************
65 \************************************************************************/
67 FuConstruct::FuConstruct (
73 : FuDraw(pViewSh
, pWin
, pView
, pDoc
, rReq
),
74 bSelectionChanged(FALSE
)
78 FunctionReference
FuConstruct::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
80 FunctionReference
xFunc( new FuConstruct( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
81 xFunc
->DoExecute(rReq
);
85 void FuConstruct::DoExecute( SfxRequest
& rReq
)
87 FuDraw::DoExecute( rReq
);
90 /*************************************************************************
92 |* MouseButtonDown-event
94 \************************************************************************/
96 BOOL
FuConstruct::MouseButtonDown(const MouseEvent
& rMEvt
)
98 BOOL bReturn
= FuDraw::MouseButtonDown(rMEvt
);
101 bSelectionChanged
= FALSE
;
103 if ( mpView
->IsAction() )
105 // #90235# this extra triggering is an error and leads to
106 // erasing the last two points when creating a polygon.
107 // if ( rMEvt.IsRight() )
108 // mpView->BckAction();
112 bFirstMouseMove
= TRUE
;
115 aMDPos
= mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() );
116 USHORT nHitLog
= USHORT (mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width());
118 if (rMEvt
.IsLeft() && mpView
->IsExtendedMouseEventDispatcherEnabled())
120 mpWindow
->CaptureMouse();
122 SdrHdl
* pHdl
= mpView
->PickHandle(aMDPos
);
124 if ( pHdl
!= NULL
|| mpView
->IsMarkedHit(aMDPos
, nHitLog
) )
126 USHORT nDrgLog
= USHORT ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
127 mpView
->BegDragObj(aMDPos
, (OutputDevice
*) NULL
, pHdl
, nDrgLog
);
130 else if ( mpView
->AreObjectsMarked() )
140 /*************************************************************************
144 \************************************************************************/
146 BOOL
FuConstruct::MouseMove(const MouseEvent
& rMEvt
)
148 FuDraw::MouseMove(rMEvt
);
150 if (aDragTimer
.IsActive() )
152 if( bFirstMouseMove
)
153 bFirstMouseMove
= FALSE
;
158 Point
aPix(rMEvt
.GetPosPixel());
159 Point
aPnt( mpWindow
->PixelToLogic(aPix
) );
161 if ( mpView
->IsAction() )
164 mpView
->MovAction(aPnt
);
170 /*************************************************************************
172 |* MouseButtonUp-event
174 \************************************************************************/
176 BOOL
FuConstruct::MouseButtonUp(const MouseEvent
& rMEvt
)
180 if (aDragTimer
.IsActive() )
183 bIsInDragMode
= FALSE
;
186 FuDraw::MouseButtonUp(rMEvt
);
188 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
190 if ( mpView
&& mpView
->IsDragObj() )
192 FrameView
* pFrameView
= mpViewShell
->GetFrameView();
193 BOOL bDragWithCopy
= (rMEvt
.IsMod1() && pFrameView
->IsDragWithCopy());
197 bDragWithCopy
= !mpView
->IsPresObjSelected(FALSE
, TRUE
);
200 mpView
->SetDragWithCopy(bDragWithCopy
);
201 mpView
->EndDragObj( mpView
->IsDragWithCopy() );
203 else if ( mpView
&& mpView
->IsMarkObj() )
205 mpView
->EndMarkObj();
212 if ( mpView
&& !mpView
->IsAction() )
214 mpWindow
->ReleaseMouse();
215 USHORT nDrgLog
= USHORT ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
217 if ( !mpView
->AreObjectsMarked() )
221 USHORT nHitLog
= USHORT ( mpWindow
->PixelToLogic(Size(HITPIX
,0)).Width() );
223 if (!mpView
->PickObj(aPnt
, mpView
->getHitTolLog(), pObj
, pPV
))
225 mpView
->MarkObj(aPnt
, nHitLog
);
228 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
230 else if (rMEvt
.IsLeft() && !rMEvt
.IsShift() && !rMEvt
.IsMod1() && !rMEvt
.IsMod2() &&
231 !bSelectionChanged
&&
232 Abs(aPnt
.X() - aMDPos
.X()) < nDrgLog
&&
233 Abs(aPnt
.Y() - aMDPos
.Y()) < nDrgLog
)
235 /**************************************************************
236 * Toggle zw. Selektion und Rotation
237 **************************************************************/
238 SdrObject
* pSingleObj
= NULL
;
239 ULONG nMarkCount
= mpView
->GetMarkedObjectList().GetMarkCount();
243 pSingleObj
= mpView
->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
246 if (mpView
->GetDragMode() == SDRDRAG_MOVE
&& mpView
->IsRotateAllowed() &&
247 (mpViewShell
->GetFrameView()->IsClickChangeRotation() ||
248 (pSingleObj
&& pSingleObj
->GetObjInventor()==E3dInventor
)))
250 mpView
->SetDragMode(SDRDRAG_ROTATE
);
254 mpView
->SetDragMode(SDRDRAG_MOVE
);
259 USHORT nClicks
= rMEvt
.GetClicks();
261 if (nClicks
== 2 && rMEvt
.IsLeft() && bMBDown
&&
262 !rMEvt
.IsMod1() && !rMEvt
.IsMod2() && !rMEvt
.IsShift() )
271 /*************************************************************************
273 |* Tastaturereignisse bearbeiten
275 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
278 \************************************************************************/
280 BOOL
FuConstruct::KeyInput(const KeyEvent
& rKEvt
)
282 BOOL bReturn
= FALSE
;
285 bReturn
= FuDraw::KeyInput(rKEvt
);
290 /*************************************************************************
292 |* Function aktivieren
294 \************************************************************************/
296 void FuConstruct::Activate()
298 mpView
->SetEditMode(SDREDITMODE_CREATE
);
302 /*************************************************************************
304 |* Function deaktivieren
306 \************************************************************************/
308 void FuConstruct::Deactivate()
310 FuDraw::Deactivate();
311 mpView
->SetEditMode(SDREDITMODE_EDIT
);
314 /*************************************************************************
316 |* StyleSheet fuer das zu erzeugende Objekt setzen
318 \************************************************************************/
320 void FuConstruct::SetStyleSheet(SfxItemSet
& rAttr
, SdrObject
* pObj
)
322 sal_Bool bUseFillStyle
, bUseNoFillStyle
;
323 bUseFillStyle
= bUseNoFillStyle
= sal_False
;
325 if (nSlotId
== SID_DRAW_RECT
|| // Rechteck
326 nSlotId
== SID_DRAW_RECT_ROUND
|| // Rechteck, rund
327 nSlotId
== SID_DRAW_SQUARE
|| // Quadrat
328 nSlotId
== SID_DRAW_SQUARE_ROUND
|| // Quadrat, rund
329 nSlotId
== SID_DRAW_ELLIPSE
|| // Ellipse
330 nSlotId
== SID_DRAW_PIE
|| // Ellipsensegment
331 nSlotId
== SID_DRAW_ELLIPSECUT
|| // Ellipsenabschnitt
332 nSlotId
== SID_DRAW_CIRCLE
|| // Kreis
333 nSlotId
== SID_DRAW_CIRCLEPIE
|| // Kreissegment
334 nSlotId
== SID_DRAW_CIRCLECUT
|| // Ellipsenabschnitt
335 nSlotId
== SID_DRAW_POLYGON
|| // Polygon
336 nSlotId
== SID_DRAW_XPOLYGON
|| // 45ø-Polygon
337 nSlotId
== SID_DRAW_FREELINE
|| // Freihandlinie
338 nSlotId
== SID_DRAW_BEZIER_FILL
) // Bezier
340 bUseFillStyle
= sal_True
;
343 (nSlotId
== SID_DRAW_RECT_NOFILL
|| // Rechteck
344 nSlotId
== SID_DRAW_RECT_ROUND_NOFILL
|| // Rechteck, rund
345 nSlotId
== SID_DRAW_SQUARE_NOFILL
|| // Quadrat
346 nSlotId
== SID_DRAW_SQUARE_ROUND_NOFILL
|| // Quadrat, rund
347 nSlotId
== SID_DRAW_ELLIPSE_NOFILL
|| // Ellipse
348 nSlotId
== SID_DRAW_PIE_NOFILL
|| // Ellipsensegment
349 nSlotId
== SID_DRAW_ELLIPSECUT_NOFILL
|| // Ellipsenabschnitt
350 nSlotId
== SID_DRAW_CIRCLE_NOFILL
|| // Kreis
351 nSlotId
== SID_DRAW_CIRCLEPIE_NOFILL
|| // Kreissegment
352 nSlotId
== SID_DRAW_CIRCLECUT_NOFILL
|| // Ellipsenabschnitt
353 nSlotId
== SID_DRAW_POLYGON_NOFILL
|| // Polygon
354 nSlotId
== SID_DRAW_XPOLYGON_NOFILL
|| // 45ø-Polygon
355 nSlotId
== SID_DRAW_FREELINE_NOFILL
|| // Freihandlinie
356 nSlotId
== SID_DRAW_BEZIER_NOFILL
) // Bezier
358 bUseNoFillStyle
= sal_True
;
360 SetStyleSheet( rAttr
, pObj
, bUseFillStyle
, bUseNoFillStyle
);
363 void FuConstruct::SetStyleSheet( SfxItemSet
& rAttr
, SdrObject
* pObj
,
364 const sal_Bool bForceFillStyle
, const sal_Bool bForceNoFillStyle
)
366 SdPage
* pPage
= (SdPage
*)mpView
->GetSdrPageView()->GetPage();
367 if ( pPage
->IsMasterPage() && pPage
->GetPageKind() == PK_STANDARD
&&
368 mpDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
)
370 /**********************************************
371 * Objects was created on the slide master page
372 ***********************************************/
373 String
aName( pPage
->GetLayoutName() );
374 String aSep
= UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
) );
375 USHORT n
= aName
.Search(aSep
);
378 aName
.Append( String ( SdResId( STR_LAYOUT_BACKGROUNDOBJECTS
) ) );
379 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pPage
->GetModel()->
380 GetStyleSheetPool()->
381 Find(aName
, SD_STYLE_FAMILY_MASTERPAGE
);
382 DBG_ASSERT(pSheet
, "Objektvorlage nicht gefunden");
385 // applying style sheet for background objects
386 pObj
->SetStyleSheet(pSheet
, FALSE
);
387 SfxItemSet
& rSet
= pSheet
->GetItemSet();
388 const XFillStyleItem
& rFillStyle
= (const XFillStyleItem
&)rSet
.Get(XATTR_FILLSTYLE
);
389 if ( bForceFillStyle
)
391 if (rFillStyle
.GetValue() == XFILL_NONE
)
392 rAttr
.Put(XFillStyleItem(XFILL_SOLID
));
394 else if ( bForceNoFillStyle
)
396 if (rFillStyle
.GetValue() != XFILL_NONE
)
397 rAttr
.Put(XFillStyleItem(XFILL_NONE
));
403 /***********************************
404 * object was created on normal page
405 ************************************/
406 if ( bForceNoFillStyle
)
408 String
aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL
));
409 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pPage
->GetModel()->
410 GetStyleSheetPool()->
411 Find(aName
, SD_STYLE_FAMILY_GRAPHICS
);
412 DBG_ASSERT(pSheet
, "Objektvorlage nicht gefunden");
415 pObj
->SetStyleSheet(pSheet
, FALSE
);
416 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
417 aAttr
.Put(pSheet
->GetItemSet().Get(XATTR_FILLSTYLE
));
418 pObj
->SetMergedItemSet(aAttr
);
422 SfxItemSet
aAttr(*mpView
->GetDefaultAttr().Clone());
423 rAttr
.Put(XFillStyleItem(XFILL_NONE
));
424 pObj
->SetMergedItemSet(aAttr
);
430 } // end of namespace sd