xref: /AOO41X/main/embeddedobj/test/mtexecutor/bitmapcreator.cxx (revision bfd08df8d53be340829eb05b5154718deb4e1b3d) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_embeddedobj.hxx"
26 
27 #include "bitmapcreator.hxx"
28 
29 #include <vcl/bitmapex.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <tools/stream.hxx>
32 
33 using namespace ::com::sun::star;
34 
35 //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()36 uno::Sequence< ::rtl::OUString > SAL_CALL VCLBitmapCreator::impl_staticGetSupportedServiceNames()
37 {
38     uno::Sequence< ::rtl::OUString > aRet(2);
39     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.BitmapCreator");
40     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.BitmapCreator");
41     return aRet;
42 }
43 
44 //-------------------------------------------------------------------------
impl_staticGetImplementationName()45 ::rtl::OUString SAL_CALL VCLBitmapCreator::impl_staticGetImplementationName()
46 {
47     return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.BitmapCreator");
48 }
49 
50 //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)51 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::impl_staticCreateSelfInstance(
52             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
53 {
54     return uno::Reference< uno::XInterface >( *new VCLBitmapCreator( xServiceManager ) );
55 }
56 
57 //-------------------------------------------------------------------------
58 
createInstance()59 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstance()
60         throw ( uno::Exception,
61                 uno::RuntimeException)
62 {
63     BitmapEx aBitmap;
64     uno::Reference< uno::XInterface> aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
65 
66     return aResult;
67 }
68 
69 //-------------------------------------------------------------------------
createInstanceWithArguments(const uno::Sequence<uno::Any> & aArguments)70 uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstanceWithArguments(
71                                                 const uno::Sequence< uno::Any >& aArguments )
72         throw ( uno::Exception,
73                 uno::RuntimeException)
74 {
75     if ( aArguments.getLength() != 1 )
76         throw uno::Exception(); // TODO
77 
78     uno::Sequence< sal_Int8 > aOrigBitmap;
79     if ( !( aArguments[0] >>= aOrigBitmap ) )
80         throw uno::Exception(); // TODO
81 
82     BitmapEx aBitmap;
83     SvMemoryStream aStream( aOrigBitmap.getArray(), aOrigBitmap.getLength(), STREAM_READ );
84     aStream >> aBitmap;
85     if ( aStream.GetError() )
86         throw uno::Exception(); // TODO
87 
88     uno::Reference< uno::XInterface > aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
89 
90     return aResult;
91 }
92 
93 //-------------------------------------------------------------------------
getImplementationName()94 ::rtl::OUString SAL_CALL VCLBitmapCreator::getImplementationName()
95         throw ( uno::RuntimeException )
96 {
97     return impl_staticGetImplementationName();
98 }
99 
100 //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)101 sal_Bool SAL_CALL VCLBitmapCreator::supportsService( const ::rtl::OUString& ServiceName )
102         throw ( uno::RuntimeException )
103 {
104     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
105 
106     for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
107         if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
108             return sal_True;
109 
110     return sal_False;
111 }
112 
113 //-------------------------------------------------------------------------
getSupportedServiceNames()114 uno::Sequence< ::rtl::OUString > SAL_CALL VCLBitmapCreator::getSupportedServiceNames()
115         throw ( uno::RuntimeException )
116 {
117     return impl_staticGetSupportedServiceNames();
118 }
119 
120