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: fuconcs.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 "fuconcs.hxx"
35 #include <svx/svdpagv.hxx>
38 #include <svx/svxids.hrc>
39 #include <svx/dialogs.hrc>
40 #include <svx/dialmgr.hxx>
43 #include <svtools/aeitem.hxx>
44 #include <svx/xlnstwit.hxx>
45 #include <svx/xlnedwit.hxx>
46 #include <svx/xlnedit.hxx>
47 #include <svx/xlnstit.hxx>
48 #include <svx/xlnwtit.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <svx/sdtmfitm.hxx>
51 #include <svx/sxekitm.hxx>
52 #include <svx/sderitm.hxx>
53 #include <sfx2/dispatch.hxx>
54 #include <svx/svdopath.hxx>
55 #include <svx/svdocirc.hxx>
56 #include <svtools/intitem.hxx>
57 #include <sfx2/request.hxx>
58 #include <svx/adjitem.hxx>
59 #include <svx/xtable.hxx>
60 #include <svx/sdasitm.hxx>
61 #include <svx/tbxcustomshapes.hxx>
62 #include <svx/svdoashp.hxx>
63 #include <svx/sdtagitm.hxx>
66 #include <svx/svdocapt.hxx>
69 #include <svx/svdomeas.hxx>
70 #include "ViewShell.hxx"
71 #include "ViewShellBase.hxx"
72 #include "ToolBarManager.hxx"
74 #include <svx/writingmodeitem.hxx>
75 #include <svx/gallery.hxx>
76 #include <svtools/itempool.hxx>
77 #include <com/sun/star/uno/Any.hxx>
79 #include "sdresid.hxx"
83 #include "stlpool.hxx"
84 #include "drawdoc.hxx"
85 #include "res_bmp.hrc"
90 TYPEINIT1( FuConstructCustomShape
, FuConstruct
);
92 /*************************************************************************
96 \************************************************************************/
98 FuConstructCustomShape::FuConstructCustomShape (
102 SdDrawDocument
* pDoc
,
104 FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
108 FunctionReference
FuConstructCustomShape::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
110 FuConstructCustomShape
* pFunc
;
111 FunctionReference
xFunc( pFunc
= new FuConstructCustomShape( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
112 xFunc
->DoExecute(rReq
);
113 pFunc
->SetPermanent( bPermanent
);
117 void FuConstructCustomShape::DoExecute( SfxRequest
& rReq
)
119 FuConstruct::DoExecute( rReq
);
121 const SfxItemSet
* pArgs
= rReq
.GetArgs();
124 const SfxStringItem
& rItm
= (const SfxStringItem
&)pArgs
->Get( rReq
.GetSlot() );
125 aCustomShape
= rItm
.GetValue();
128 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
129 ToolBarManager::TBG_FUNCTION
,
130 ToolBarManager::msDrawingObjectToolBar
);
133 /*************************************************************************
135 |* MouseButtonDown-event
137 \************************************************************************/
139 BOOL
FuConstructCustomShape::MouseButtonDown(const MouseEvent
& rMEvt
)
141 BOOL bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
143 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
145 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
147 mpWindow
->CaptureMouse();
148 USHORT nDrgLog
= USHORT ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
150 mpView
->BegCreateObj(aPnt
, (OutputDevice
*) NULL
, nDrgLog
);
152 SdrObject
* pObj
= mpView
->GetCreateObj();
155 SetAttributes( pObj
);
156 sal_Bool bForceFillStyle
= sal_True
;
157 sal_Bool bForceNoFillStyle
= sal_False
;
158 if ( ((SdrObjCustomShape
*)pObj
)->UseNoFillStyle() )
160 bForceFillStyle
= sal_False
;
161 bForceNoFillStyle
= sal_True
;
163 SfxItemSet
aAttr(mpDoc
->GetPool());
164 SetStyleSheet( aAttr
, pObj
, bForceFillStyle
, bForceNoFillStyle
);
165 pObj
->SetMergedItemSet(aAttr
);
172 /*************************************************************************
176 \************************************************************************/
178 BOOL
FuConstructCustomShape::MouseMove(const MouseEvent
& rMEvt
)
180 return FuConstruct::MouseMove(rMEvt
);
183 /*************************************************************************
185 |* MouseButtonUp-event
187 \************************************************************************/
189 BOOL
FuConstructCustomShape::MouseButtonUp(const MouseEvent
& rMEvt
)
191 sal_Bool
bReturn(sal_False
);
193 if(mpView
->IsCreateObj() && rMEvt
.IsLeft())
195 SdrObject
* pObj
= mpView
->GetCreateObj();
196 if( pObj
&& mpView
->EndCreateObj( SDRCREATE_FORCEEND
) )
201 bReturn
= FuConstruct::MouseButtonUp (rMEvt
) || bReturn
;
204 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
209 /*************************************************************************
211 |* Tastaturereignisse bearbeiten
213 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
216 \************************************************************************/
218 BOOL
FuConstructCustomShape::KeyInput(const KeyEvent
& rKEvt
)
220 BOOL bReturn
= FuConstruct::KeyInput(rKEvt
);
224 /*************************************************************************
226 |* Function aktivieren
228 \************************************************************************/
230 void FuConstructCustomShape::Activate()
232 mpView
->SetCurrentObj( OBJ_CUSTOMSHAPE
);
233 FuConstruct::Activate();
236 /*************************************************************************
238 |* Attribute fuer das zu erzeugende Objekt setzen
240 \************************************************************************/
242 void FuConstructCustomShape::SetAttributes( SdrObject
* pObj
)
244 sal_Bool bAttributesAppliedFromGallery
= sal_False
;
246 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
248 std::vector
< rtl::OUString
> aObjList
;
249 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
252 for ( i
= 0; i
< aObjList
.size(); i
++ )
254 if ( aObjList
[ i
].equalsIgnoreAsciiCase( aCustomShape
) )
256 FmFormModel aFormModel
;
257 SfxItemPool
& rPool
= aFormModel
.GetItemPool();
258 rPool
.FreezeIdRanges();
259 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aFormModel
) )
261 const SdrPage
* pPage
= aFormModel
.GetPage( 0 );
264 const SdrObject
* pSourceObj
= pPage
->GetObj( 0 );
267 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
268 SfxItemSet
aDest( pObj
->GetModel()->GetItemPool(), // ranges from SdrAttrObj
269 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
270 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
271 SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
,
272 // Graphic Attributes
273 SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
,
275 SDRATTR_3D_FIRST
, SDRATTR_3D_LAST
,
276 // CustomShape properties
277 SDRATTR_CUSTOMSHAPE_FIRST
, SDRATTR_CUSTOMSHAPE_LAST
,
278 // range from SdrTextObj
279 EE_ITEMS_START
, EE_ITEMS_END
,
282 aDest
.Set( rSource
);
283 pObj
->SetMergedItemSet( aDest
);
284 sal_Int32 nAngle
= pSourceObj
->GetRotateAngle();
287 double a
= nAngle
* F_PI18000
;
288 pObj
->NbcRotate( pObj
->GetSnapRect().Center(), nAngle
, sin( a
), cos( a
) );
290 bAttributesAppliedFromGallery
= sal_True
;
294 com::sun::star::uno::Any aAny;
295 if ( ((SdrCustomShapeGeometryItem&)pObj->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )).QueryValue( aAny ) )
297 aGeometryItem.PutValue( aAny );
298 pObj->SetMergedItem( aGeometryItem );
299 bAttributesAppliedFromGallery = sal_True;
310 if ( !bAttributesAppliedFromGallery
)
312 pObj
->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER
, EE_PARA_JUST
) );
313 pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
314 pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
315 pObj
->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False
) );
316 ((SdrObjCustomShape
*)pObj
)->MergeDefaultAttributes( &aCustomShape
);
321 SdrObject
* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16
, const Rectangle
& rRectangle
)
323 SdrObject
* pObj
= SdrObjFactory::MakeNewObject(
324 mpView
->GetCurrentObjInventor(), mpView
->GetCurrentObjIdentifier(),
329 Rectangle
aRect( rRectangle
);
330 if ( doConstructOrthogonal() )
331 ImpForceQuadratic( aRect
);
332 pObj
->SetLogicRect( aRect
);
333 SetAttributes( pObj
);
334 SfxItemSet
aAttr(mpDoc
->GetPool());
335 SetStyleSheet(aAttr
, pObj
);
336 pObj
->SetMergedItemSet(aAttr
);
342 bool FuConstructCustomShape::doConstructOrthogonal() const
344 return SdrObjCustomShape::doConstructOrthogonal(aCustomShape
);
347 } // end of namespace sd