1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_svx.hxx"
29 #include <svx/sdr/primitive2d/primitiveFactory2d.hxx>
30 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/svdpage.hxx>
33 #include <svx/unoapi.hxx>
34 #include <svx/sdr/contact/viewcontact.hxx>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 using namespace com::sun::star;
39 
40 //////////////////////////////////////////////////////////////////////////////
41 // UNO API helper methods
42 
43 namespace drawinglayer
44 {
45 	namespace primitive2d
46 	{
47 		uno::Reference< uno::XInterface > SAL_CALL XPrimitiveFactory2DProvider_createInstance(
48 			const uno::Reference< lang::XMultiServiceFactory >& /*rSMgr*/) throw( uno::Exception )
49 		{
50 			return *(new PrimitiveFactory2D());
51 		}
52 	} // end of namespace primitive2d
53 } // end of namespace drawinglayer
54 
55 //////////////////////////////////////////////////////////////////////////////
56 // UNO API helper methods
57 
58 namespace drawinglayer
59 {
60 	namespace primitive2d
61 	{
62 		PrimitiveFactory2D::PrimitiveFactory2D()
63 		:	PrimitiveFactory2DImplBase(m_aMutex)
64 		{
65 		}
66 
67 		Primitive2DSequence SAL_CALL PrimitiveFactory2D::createPrimitivesFromXShape(
68 			const uno::Reference< drawing::XShape >& xShape,
69 			const uno::Sequence< beans::PropertyValue >& /*aParms*/ ) throw (uno::RuntimeException)
70 		{
71 			Primitive2DSequence aRetval;
72 
73 			if(xShape.is())
74 			{
75 				SdrObject* pSource = GetSdrObjectFromXShape(xShape);
76 
77 				if(pSource)
78 				{
79 					const sdr::contact::ViewContact& rSource(pSource->GetViewContact());
80 					aRetval = rSource.getViewIndependentPrimitive2DSequence();
81 				}
82 			}
83 
84 			return aRetval;
85 		}
86 
87 		Primitive2DSequence SAL_CALL PrimitiveFactory2D::createPrimitivesFromXDrawPage(
88 			const uno::Reference< drawing::XDrawPage >& xDrawPage,
89 			const uno::Sequence< beans::PropertyValue >& /*aParms*/ ) throw (uno::RuntimeException)
90 		{
91 			Primitive2DSequence aRetval;
92 
93 			if(xDrawPage.is())
94 			{
95 				SdrPage* pSource = GetSdrPageFromXDrawPage(xDrawPage);
96 
97 				if(pSource)
98 				{
99 					const sdr::contact::ViewContact& rSource(pSource->GetViewContact());
100 
101                     aRetval = rSource.getViewIndependentPrimitive2DSequence();
102 				}
103 			}
104 
105 			return aRetval;
106 		}
107 
108 		rtl::OUString PrimitiveFactory2D::getImplementationName_Static()
109 		{
110 			static rtl::OUString aRetval(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.graphic.PrimitiveFactory2D"));
111 			return aRetval;
112 		}
113 
114 		uno::Sequence< rtl::OUString > PrimitiveFactory2D::getSupportedServiceNames_Static()
115 		{
116 			static uno::Sequence< rtl::OUString > aSeq;
117 			osl::Mutex aMutex;
118 			osl::MutexGuard aGuard( aMutex );
119 
120 			if(!aSeq.getLength())
121 			{
122 				aSeq.realloc(1L);
123 				aSeq.getArray()[0L] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.graphic.PrimitiveFactory2D"));
124 			}
125 
126 			return aSeq;
127 		}
128 	} // end of namespace primitive2d
129 } // end of namespace drawinglayer
130 
131 //////////////////////////////////////////////////////////////////////////////
132 // eof
133