xref: /trunk/main/embeddedobj/test/mtexecutor/bitmapcreator.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_embeddedobj.hxx"
30 
31 #include "bitmapcreator.hxx"
32 
33 #include <vcl/bitmapex.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <tools/stream.hxx>
36 
37 using namespace ::com::sun::star;
38 
39 //-------------------------------------------------------------------------
40 uno::Sequence< ::rtl::OUString > SAL_CALL VCLBitmapCreator::impl_staticGetSupportedServiceNames()
41 {
42     uno::Sequence< ::rtl::OUString > aRet(2);
43     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.BitmapCreator");
44     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.BitmapCreator");
45     return aRet;
46 }
47 
48 //-------------------------------------------------------------------------
49 ::rtl::OUString SAL_CALL VCLBitmapCreator::impl_staticGetImplementationName()
50 {
51     return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.BitmapCreator");
52 }
53 
54 //-------------------------------------------------------------------------
55 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::impl_staticCreateSelfInstance(
56             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
57 {
58     return uno::Reference< uno::XInterface >( *new VCLBitmapCreator( xServiceManager ) );
59 }
60 
61 //-------------------------------------------------------------------------
62 
63 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstance()
64         throw ( uno::Exception,
65                 uno::RuntimeException)
66 {
67     BitmapEx aBitmap;
68     uno::Reference< uno::XInterface> aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
69 
70     return aResult;
71 }
72 
73 //-------------------------------------------------------------------------
74 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstanceWithArguments(
75                                                 const uno::Sequence< uno::Any >& aArguments )
76         throw ( uno::Exception,
77                 uno::RuntimeException)
78 {
79     if ( aArguments.getLength() != 1 )
80         throw uno::Exception(); // TODO
81 
82     uno::Sequence< sal_Int8 > aOrigBitmap;
83     if ( !( aArguments[0] >>= aOrigBitmap ) )
84         throw uno::Exception(); // TODO
85 
86     BitmapEx aBitmap;
87     SvMemoryStream aStream( aOrigBitmap.getArray(), aOrigBitmap.getLength(), STREAM_READ );
88     aStream >> aBitmap;
89     if ( aStream.GetError() )
90         throw uno::Exception(); // TODO
91 
92     uno::Reference< uno::XInterface > aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
93 
94     return aResult;
95 }
96 
97 //-------------------------------------------------------------------------
98 ::rtl::OUString SAL_CALL VCLBitmapCreator::getImplementationName()
99         throw ( uno::RuntimeException )
100 {
101     return impl_staticGetImplementationName();
102 }
103 
104 //-------------------------------------------------------------------------
105 sal_Bool SAL_CALL VCLBitmapCreator::supportsService( const ::rtl::OUString& ServiceName )
106         throw ( uno::RuntimeException )
107 {
108     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
109 
110     for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
111         if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
112             return sal_True;
113 
114     return sal_False;
115 }
116 
117 //-------------------------------------------------------------------------
118 uno::Sequence< ::rtl::OUString > SAL_CALL VCLBitmapCreator::getSupportedServiceNames()
119         throw ( uno::RuntimeException )
120 {
121     return impl_staticGetSupportedServiceNames();
122 }
123 
124