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 #ifndef INCLUDED_OOX_OLE_OLEHELPER_HXX 21 #define INCLUDED_OOX_OLE_OLEHELPER_HXX 22 23 #include <com/sun/star/uno/Reference.hxx> 24 #include <filter/msfilter/msocximex.hxx> 25 #include <oox/dllapi.h> 26 #include <oox/helper/binarystreambase.hxx> 27 #include <oox/helper/graphichelper.hxx> 28 #include <rtl/ustring.hxx> 29 #include <sal/types.h> 30 #include <tools/ref.hxx> 31 #include <memory> 32 33 namespace com { namespace sun { namespace star { 34 namespace awt { class XControlModel; } 35 namespace awt { struct Size; } 36 namespace form { class XFormComponent; } 37 namespace frame { class XModel; } 38 namespace io { class XOutputStream; } 39 namespace uno { class XComponentContext; } 40 } } } 41 42 class SotStorage; 43 class SotStorageStream; 44 class SvGlobalName; 45 46 namespace oox { 47 class BinaryInputStream; 48 class BinaryOutputStream; 49 } 50 51 namespace oox { 52 53 54 namespace ole { 55 class ControlModelBase; 56 class EmbeddedControl; 57 58 59 #define OLE_GUID_STDFONT "{0BE35203-8F91-11CE-9DE3-00AA004BB851}" 60 #define OLE_GUID_STDPIC "{0BE35204-8F91-11CE-9DE3-00AA004BB851}" 61 62 63 const sal_uInt16 OLE_STDFONT_NORMAL = 400; 64 const sal_uInt16 OLE_STDFONT_BOLD = 700; 65 66 const sal_uInt8 OLE_STDFONT_ITALIC = 0x02; 67 const sal_uInt8 OLE_STDFONT_UNDERLINE = 0x04; 68 const sal_uInt8 OLE_STDFONT_STRIKE = 0x08; 69 70 /** Stores data about a StdFont font structure. */ 71 struct StdFontInfo 72 { 73 OUString maName; ///< Font name. 74 sal_uInt32 mnHeight; ///< Font height (1/10,000 points). 75 sal_uInt16 mnWeight; ///< Font weight (normal/bold). 76 sal_uInt16 mnCharSet; ///< Font charset. 77 sal_uInt8 mnFlags; ///< Font flags. 78 79 explicit StdFontInfo(); 80 explicit StdFontInfo( 81 const OUString& rName, 82 sal_uInt32 nHeight ); 83 }; 84 85 86 /** Stores data about a StdHlink hyperlink. */ 87 struct StdHlinkInfo 88 { 89 OUString maTarget; 90 OUString maLocation; 91 OUString maDisplay; 92 }; 93 94 95 /** Static helper functions for OLE import/export. */ 96 namespace OleHelper 97 { 98 /** Returns the UNO RGB color from the passed encoded OLE color. 99 100 @param bDefaultColorBgr 101 True = OLE default color type is treated as BGR color. 102 False = OLE default color type is treated as palette color. 103 */ 104 OOX_DLLPUBLIC ::Color decodeOleColor( 105 const GraphicHelper& rGraphicHelper, 106 sal_uInt32 nOleColor, 107 bool bDefaultColorBgr ); 108 109 /** Returns the OLE color from the passed UNO RGB color. 110 */ 111 OOX_DLLPUBLIC sal_uInt32 encodeOleColor( sal_Int32 nRgbColor ); encodeOleColor(Color nRgbColor)112 inline sal_uInt32 encodeOleColor( Color nRgbColor ) { return encodeOleColor(sal_Int32(nRgbColor)); } 113 114 /** Imports a GUID from the passed binary stream and returns its string 115 representation (in uppercase characters). 116 */ 117 OOX_DLLPUBLIC OUString importGuid( BinaryInputStream& rInStrm ); 118 OOX_DLLPUBLIC void exportGuid( BinaryOutputStream& rOutStrm, const SvGlobalName& rId ); 119 120 /** Imports an OLE StdFont font structure from the current position of the 121 passed binary stream. 122 */ 123 OOX_DLLPUBLIC bool importStdFont( 124 StdFontInfo& orFontInfo, 125 BinaryInputStream& rInStrm, 126 bool bWithGuid ); 127 128 /** Imports an OLE StdPic picture from the current position of the passed 129 binary stream. 130 */ 131 OOX_DLLPUBLIC bool importStdPic( 132 StreamDataSequence& orGraphicData, 133 BinaryInputStream& rInStrm ); 134 } 135 136 class OOX_DLLPUBLIC OleFormCtrlExportHelper final 137 { 138 std::unique_ptr<::oox::ole::EmbeddedControl> mpControl; 139 ::oox::ole::ControlModelBase* mpModel; 140 ::oox::GraphicHelper const maGrfHelper; 141 css::uno::Reference< css::frame::XModel > mxDocModel; 142 css::uno::Reference< css::awt::XControlModel > mxControlModel; 143 144 OUString maName; 145 OUString maTypeName; 146 OUString maFullName; 147 OUString maGUID; 148 public: 149 OleFormCtrlExportHelper( const css::uno::Reference< css::uno::XComponentContext >& rxCtx, const css::uno::Reference< css::frame::XModel >& xDocModel, const css::uno::Reference< css::awt::XControlModel >& xModel ); 150 ~OleFormCtrlExportHelper(); 151 getGUID() const152 OUString getGUID() const 153 { 154 OUString sResult; 155 if ( maGUID.getLength() > 2 ) 156 sResult = maGUID.copy(1, maGUID.getLength() - 2 ); 157 return sResult; 158 } getFullName() const159 const OUString& getFullName() const { return maFullName; } getTypeName() const160 const OUString& getTypeName() const { return maTypeName; } getName() const161 const OUString& getName() const { return maName; } isValid() const162 bool isValid() const { return mpModel != nullptr; } 163 void exportName( const css::uno::Reference< css::io::XOutputStream >& rxOut ); 164 void exportCompObj( const css::uno::Reference< css::io::XOutputStream >& rxOut ); 165 void exportControl( const css::uno::Reference< css::io::XOutputStream >& rxOut, const css::awt::Size& rSize, bool bAutoClose = false ); 166 }; 167 168 // ideally it would be great to get rid of SvxMSConvertOCXControls 169 // however msfilter/source/msfilter/svdfppt.cxx still uses 170 // SvxMSConvertOCXControls as a base class, unfortunately oox depends on 171 // msfilter. Probably the solution would be to move the svdfppt.cxx 172 // implementation into the sd module itself. 173 class OOX_DLLPUBLIC MSConvertOCXControls : public SvxMSConvertOCXControls 174 { 175 protected: 176 css::uno::Reference< css::uno::XComponentContext > mxCtx; 177 ::oox::GraphicHelper const maGrfHelper; 178 179 bool importControlFromStream( ::oox::BinaryInputStream& rInStrm, 180 css::uno::Reference< css::form::XFormComponent > & rxFormComp, 181 const OUString& rGuidString ); 182 bool importControlFromStream( ::oox::BinaryInputStream& rInStrm, 183 css::uno::Reference< css::form::XFormComponent > & rxFormComp, 184 const OUString& rGuidString, 185 sal_Int32 nSize ); 186 public: 187 MSConvertOCXControls( const css::uno::Reference< css::frame::XModel >& rxModel ); 188 virtual ~MSConvertOCXControls() override; 189 bool ReadOCXStorage( tools::SvRef<SotStorage> const & rSrc1, css::uno::Reference< css::form::XFormComponent > & rxFormComp ); 190 bool ReadOCXCtlsStream(tools::SvRef<SotStorageStream> const & rSrc1, css::uno::Reference< css::form::XFormComponent > & rxFormComp, 191 sal_Int32 nPos, sal_Int32 nSize ); 192 static bool WriteOCXStream( const css::uno::Reference< css::frame::XModel >& rxModel, tools::SvRef<SotStorage> const &rSrc1, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString &rName); 193 static bool WriteOCXExcelKludgeStream( const css::uno::Reference< css::frame::XModel >& rxModel, const css::uno::Reference< css::io::XOutputStream >& xOutStrm, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString &rName); 194 }; 195 196 197 } // namespace ole 198 } // namespace oox 199 200 #endif 201 202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 203