1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unobtabl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svtools/itempool.hxx>
34 #include <vcl/cvtgrf.hxx>
35 #include <svtools/itemset.hxx>
36 #include <svx/xit.hxx>
38 #ifndef _SFXDOCFILE_HXX
39 #include <sfx2/docfile.hxx>
42 #include "UnoNameItemTable.hxx"
44 #include <svx/xbtmpit.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/xflhtit.hxx>
49 #include <svx/unomid.hxx>
50 #include <svx/unoprnms.hxx>
51 #include "unofill.hxx"
53 using namespace ::com::sun::star
;
54 using namespace ::rtl
;
55 using namespace ::cppu
;
57 class SvxUnoBitmapTable
: public SvxUnoNameItemTable
60 SvxUnoBitmapTable( SdrModel
* pModel
) throw();
61 virtual ~SvxUnoBitmapTable() throw();
63 virtual NameOrIndex
* createItem() const throw();
64 virtual bool isValid( const NameOrIndex
* pItem
) const;
67 virtual OUString SAL_CALL
getImplementationName( ) throw( uno::RuntimeException
);
68 virtual uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw( uno::RuntimeException
);
71 virtual uno::Type SAL_CALL
getElementType( ) throw( uno::RuntimeException
);
74 SvxUnoBitmapTable::SvxUnoBitmapTable( SdrModel
* pModel
) throw()
75 : SvxUnoNameItemTable( pModel
, XATTR_FILLBITMAP
, MID_GRAFURL
)
79 SvxUnoBitmapTable::~SvxUnoBitmapTable() throw()
83 bool SvxUnoBitmapTable::isValid( const NameOrIndex
* pItem
) const
85 if( SvxUnoNameItemTable::isValid( pItem
) )
87 const XFillBitmapItem
* pBitmapItem
= dynamic_cast< const XFillBitmapItem
* >( pItem
);
90 const GraphicObject
& rGraphic
= pBitmapItem
->GetBitmapValue().GetGraphicObject();
91 return rGraphic
.GetSizeBytes() > 0;
98 OUString SAL_CALL
SvxUnoBitmapTable::getImplementationName() throw( uno::RuntimeException
)
100 return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoBitmapTable") );
103 uno::Sequence
< OUString
> SAL_CALL
SvxUnoBitmapTable::getSupportedServiceNames( )
104 throw( uno::RuntimeException
)
106 uno::Sequence
< OUString
> aSNS( 1 );
107 aSNS
.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.BitmapTable" ));
111 NameOrIndex
* SvxUnoBitmapTable::createItem() const throw()
113 return new XFillBitmapItem();
117 uno::Type SAL_CALL
SvxUnoBitmapTable::getElementType( )
118 throw( uno::RuntimeException
)
120 return ::getCppuType( (const ::rtl::OUString
*)0 );
124 * Create a bitmaptable
126 uno::Reference
< uno::XInterface
> SAL_CALL
SvxUnoBitmapTable_createInstance( SdrModel
* pModel
)
128 return *new SvxUnoBitmapTable(pModel
);
130 #include <tools/stream.hxx>
131 #include <unotools/localfilehelper.hxx>
133 /** returns a GraphicObject for this URL */
134 GraphicObject
CreateGraphicObjectFromURL( const ::rtl::OUString
&rURL
) throw()
136 const String
aURL( rURL
), aPrefix( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX
) );
138 if( aURL
.Search( aPrefix
) == 0 )
140 // graphic manager url
141 ByteString
aUniqueID( String(rURL
.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX
) - 1 )), RTL_TEXTENCODING_UTF8
);
142 return GraphicObject( aUniqueID
);
151 SfxMedium
aMedium( aURL
, STREAM_READ
, TRUE
);
152 SvStream
* pStream
= aMedium
.GetInStream();
155 GraphicConverter::Import( *pStream
, aGraphic
);
158 String
aSystemPath( rURL
);
159 utl::LocalFileHelper::ConvertURLToSystemPath( aSystemPath
, aSystemPath
);
160 SvFileStream
aFile( aSystemPath
, STREAM_READ
);
161 GraphicConverter::Import( aFile
, aGraphic
);
165 return GraphicObject( aGraphic
);