summaryrefslogtreecommitdiff
path: root/svx/source/customshapes/BarCodeCustomShapeEngine.cxx
blob: 798598ab9265b92f2aa030362200929cdb172714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/drawing/XCustomShapeEngine.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <basegfx/tools/unotools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/supportsservice.hxx>

#include <svx/unoapi.hxx>
#include <svx/unopage.hxx>
#include <svx/unoshape.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdogrp.hxx>
#include <svx/svdpage.hxx>
#include <svx/sdasitm.hxx>

#include "BarCodeRender.hxx"

using namespace css;
using namespace css::uno;

namespace {

class BarCodeCustomShapeEngine : public cppu::WeakImplHelper3
        < lang::XInitialization, lang::XServiceInfo,
          drawing::XCustomShapeEngine >
{
    Reference< drawing::XShape > mxShape;

public:
             BarCodeCustomShapeEngine() {}
    virtual ~BarCodeCustomShapeEngine() {}

    // XInitialization
    virtual void SAL_CALL initialize( const uno::Sequence< uno::Any >& aArguments )
        throw ( uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE
    {
        return OUString( "org.libreoffice.draw.barcode" );
    }
    virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName )
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE
    {
        return cppu::supportsService(this, rServiceName);
    }
    virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE
    {
        Sequence< OUString > aRet(1);
        OUString* pArray = aRet.getArray();
        pArray[0] = "com.sun.star.drawing.CustomShapeEngine";
        return aRet;
    }

    // XCustomShapeEngine
    virtual uno::Reference< drawing::XShape > SAL_CALL render()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
    virtual awt::Rectangle SAL_CALL getTextBounds()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
    virtual drawing::PolyPolygonBezierCoords SAL_CALL getLineGeometry()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
    virtual uno::Sequence< uno::Reference< drawing::XCustomShapeHandle > > SAL_CALL getInteraction()
        throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
};

// XInitialization
void SAL_CALL BarCodeCustomShapeEngine::initialize( const Sequence< Any >& aArgs )
    throw ( Exception, RuntimeException, std::exception )
{
    sal_Int32 i;
    Sequence< beans::PropertyValue > aParameter;
    for ( i = 0; i < aArgs.getLength(); i++ )
    {
        if ( aArgs[ i ] >>= aParameter )
            break;
    }
    for ( i = 0; i < aParameter.getLength(); i++ )
    {
        const beans::PropertyValue& rProp = aParameter[ i ];
        if ( rProp.Name == "CustomShape" )
            rProp.Value >>= mxShape;
    }
}

Reference< drawing::XShape > SAL_CALL BarCodeCustomShapeEngine::render()
    throw ( RuntimeException, std::exception )
{
    Reference< drawing::XShape > xShape;
    SAL_INFO("svx", "barcode engine render");
    SdrObject* pSdrObjCustomShape( GetSdrObjectFromXShape( mxShape ) );
    if ( pSdrObjCustomShape )
    {
        Point aP( pSdrObjCustomShape->GetSnapRect().Center() );
        Size aS( pSdrObjCustomShape->GetLogicRect().GetSize() );
        aP.X() -= aS.Width() / 2;
        aP.Y() -= aS.Height() / 2;

        Rectangle aLogicRect;
        aLogicRect = Rectangle( aP, aS );

        OUString aData(static_cast<const SdrCustomShapeDataItem&>(pSdrObjCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_DATA )).GetValue());

        SdrObjGroup *pShape = svx::BarCodeRender(aLogicRect, aData);
        if (pShape)
        {
            SfxItemSet aSet( pSdrObjCustomShape->GetMergedItemSet() );
            pShape->SetMergedItemSet( aSet );

            pShape->NbcSetStyleSheet( pSdrObjCustomShape->GetStyleSheet(), true );
            pShape->RecalcSnapRect();

            xShape = SvxDrawPage::CreateShapeByTypeAndInventor(
                        pShape->GetObjIdentifier(),
                        pShape->GetObjInventor(), pShape, NULL );
        }

        if ( xShape.is() )
        {
            SvxShape* pTake = SvxShape::getImplementation( xShape );
            if ( pTake )
                pTake->TakeSdrObjectOwnership();
        }
    }
    return xShape;
}

awt::Rectangle SAL_CALL BarCodeCustomShapeEngine::getTextBounds()
    throw ( RuntimeException, std::exception )
{
    awt::Rectangle aTextRect;
    SAL_INFO("svx", "barcode engine get text bounds: stub");
    return aTextRect;
}

drawing::PolyPolygonBezierCoords SAL_CALL BarCodeCustomShapeEngine::getLineGeometry()
    throw ( RuntimeException, std::exception )
{
    drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
    SAL_INFO("svx", "barcode engine get line geometry: stub");
    return aPolyPolygonBezierCoords;
}

Sequence< Reference< drawing::XCustomShapeHandle > > SAL_CALL BarCodeCustomShapeEngine::getInteraction()
    throw ( RuntimeException, std::exception )
{
    return Sequence< Reference< drawing::XCustomShapeHandle > >();
}

}

extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface * SAL_CALL
org_libreoffice_draw_barcode_get_implementation(
    uno::XComponentContext *,
    uno::Sequence<uno::Any> const &)
{
    return cppu::acquire(new BarCodeCustomShapeEngine);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */