Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/graphic/XPrimitiveFactory2D.hpp>
21 : #include <com/sun/star/lang/XServiceInfo.hpp>
22 : #include <com/sun/star/uno/XComponentContext.hpp>
23 : #include <cppuhelper/compbase.hxx>
24 : #include <cppuhelper/supportsservice.hxx>
25 : #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
26 : #include <rtl/ref.hxx>
27 : #include <svx/svdobj.hxx>
28 : #include <svx/svdpage.hxx>
29 : #include <svx/unoapi.hxx>
30 : #include <svx/sdr/contact/viewcontact.hxx>
31 :
32 : using namespace com::sun::star;
33 :
34 : namespace {
35 :
36 : typedef cppu::WeakComponentImplHelper< ::com::sun::star::graphic::XPrimitiveFactory2D, css::lang::XServiceInfo > PrimitiveFactory2DImplBase;
37 :
38 : // base class for C++ implementation of com::sun::star::graphic::XPrimitiveFactory2D
39 426 : class PrimitiveFactory2D
40 : : protected comphelper::OBaseMutex,
41 : public PrimitiveFactory2DImplBase
42 : {
43 : public:
44 213 : PrimitiveFactory2D(): PrimitiveFactory2DImplBase(m_aMutex) {}
45 :
46 : // Methods from XPrimitiveFactory2D
47 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XPrimitive2D > > SAL_CALL createPrimitivesFromXShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aParms ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
48 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XPrimitive2D > > SAL_CALL createPrimitivesFromXDrawPage( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xDrawPage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aParms ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
49 :
50 1 : OUString SAL_CALL getImplementationName()
51 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
52 1 : { return OUString("com.sun.star.comp.graphic.PrimitiveFactory2D"); }
53 :
54 0 : sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
55 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
56 0 : { return cppu::supportsService(this, ServiceName); }
57 :
58 1 : css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
59 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
60 : {
61 : return css::uno::Sequence<OUString>{
62 1 : "com.sun.star.graphic.PrimitiveFactory2D"};
63 : }
64 : };
65 :
66 212 : Primitive2DSequence SAL_CALL PrimitiveFactory2D::createPrimitivesFromXShape(
67 : const uno::Reference< drawing::XShape >& xShape,
68 : const uno::Sequence< beans::PropertyValue >& /*aParms*/ ) throw (uno::RuntimeException, std::exception)
69 : {
70 212 : Primitive2DSequence aRetval;
71 :
72 212 : if(xShape.is())
73 : {
74 212 : SdrObject* pSource = GetSdrObjectFromXShape(xShape);
75 :
76 212 : if(pSource)
77 : {
78 212 : const sdr::contact::ViewContact& rSource(pSource->GetViewContact());
79 212 : aRetval = rSource.getViewIndependentPrimitive2DSequence();
80 : }
81 : }
82 :
83 212 : return aRetval;
84 : }
85 :
86 0 : Primitive2DSequence SAL_CALL PrimitiveFactory2D::createPrimitivesFromXDrawPage(
87 : const uno::Reference< drawing::XDrawPage >& xDrawPage,
88 : const uno::Sequence< beans::PropertyValue >& /*aParms*/ ) throw (uno::RuntimeException, std::exception)
89 : {
90 0 : Primitive2DSequence aRetval;
91 :
92 0 : if(xDrawPage.is())
93 : {
94 0 : SdrPage* pSource = GetSdrPageFromXDrawPage(xDrawPage);
95 :
96 0 : if(pSource)
97 : {
98 0 : const sdr::contact::ViewContact& rSource(pSource->GetViewContact());
99 :
100 0 : aRetval = rSource.getViewIndependentPrimitive2DSequence();
101 : }
102 : }
103 :
104 0 : return aRetval;
105 : }
106 :
107 : }
108 :
109 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
110 213 : com_sun_star_comp_graphic_PrimitiveFactory2D_get_implementation(
111 : css::uno::XComponentContext *,
112 : css::uno::Sequence<css::uno::Any> const &)
113 : {
114 213 : return cppu::acquire(new PrimitiveFactory2D);
115 : }
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|