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 #ifndef OOX_XLS_DRAWINGFRAGMENT_HXX 25 #define OOX_XLS_DRAWINGFRAGMENT_HXX 26 27 #include <com/sun/star/awt/Rectangle.hpp> 28 #include <com/sun/star/awt/Size.hpp> 29 #include "oox/drawingml/shape.hxx" 30 #include "oox/drawingml/shapegroupcontext.hxx" 31 #include "oox/ole/axcontrol.hxx" 32 #include "oox/ole/vbaproject.hxx" 33 #include "oox/vml/vmldrawing.hxx" 34 #include "oox/vml/vmldrawingfragment.hxx" 35 #include "oox/vml/vmltextbox.hxx" 36 #include "oox/xls/drawingbase.hxx" 37 #include "oox/xls/excelhandlers.hxx" 38 39 namespace oox { namespace ole { 40 struct AxFontData; 41 class AxMorphDataModelBase; 42 } } 43 44 namespace oox { 45 namespace xls { 46 47 // ============================================================================ 48 // DrawingML 49 // ============================================================================ 50 51 class ShapeMacroAttacher : public ::oox::ole::VbaMacroAttacherBase 52 { 53 public: 54 explicit ShapeMacroAttacher( const ::rtl::OUString& rMacroName, 55 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape ); 56 57 private: 58 virtual void attachMacro( const ::rtl::OUString& rMacroUrl ); 59 60 private: 61 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxShape; 62 }; 63 64 // ============================================================================ 65 66 class Shape : public ::oox::drawingml::Shape, public WorksheetHelper 67 { 68 public: 69 explicit Shape( 70 const WorksheetHelper& rHelper, 71 const AttributeList& rAttribs, 72 const sal_Char* pcServiceName = 0 ); 73 74 protected: 75 virtual void finalizeXShape( 76 ::oox::core::XmlFilterBase& rFilter, 77 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes ); 78 79 private: 80 ::rtl::OUString maMacroName; 81 }; 82 83 // ============================================================================ 84 85 /** Context handler for creation of shapes embedded in group shapes. */ 86 class GroupShapeContext : public ::oox::drawingml::ShapeGroupContext, public WorksheetHelper 87 { 88 public: 89 explicit GroupShapeContext( 90 ::oox::core::ContextHandler& rParent, 91 const WorksheetHelper& rHelper, 92 const ::oox::drawingml::ShapePtr& rxParentShape, 93 const ::oox::drawingml::ShapePtr& rxShape ); 94 95 static ::oox::core::ContextHandlerRef 96 createShapeContext( 97 ::oox::core::ContextHandler& rParent, 98 const WorksheetHelper& rHelper, 99 sal_Int32 nElement, 100 const AttributeList& rAttribs, 101 const ::oox::drawingml::ShapePtr& rxParentShape, 102 ::oox::drawingml::ShapePtr* pxShape = 0 ); 103 104 protected: 105 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL 106 createFastChildContext( 107 sal_Int32 nElement, 108 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs ) 109 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); 110 }; 111 112 // ============================================================================ 113 114 /** Fragment handler for a complete sheet drawing. */ 115 class DrawingFragment : public WorksheetFragmentBase 116 { 117 public: 118 explicit DrawingFragment( 119 const WorksheetHelper& rHelper, 120 const ::rtl::OUString& rFragmentPath ); 121 122 protected: 123 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 124 virtual void onCharacters( const ::rtl::OUString& rChars ); 125 virtual void onEndElement(); 126 127 private: 128 typedef ::std::auto_ptr< ShapeAnchor > ShapeAnchorRef; 129 130 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > 131 mxDrawPage; /// Drawing page of this sheet. 132 ::oox::drawingml::ShapePtr mxShape; /// Current top-level shape. 133 ShapeAnchorRef mxAnchor; /// Current anchor of top-level shape. 134 }; 135 136 // ============================================================================ 137 // VML 138 // ============================================================================ 139 140 class VmlControlMacroAttacher : public ::oox::ole::VbaMacroAttacherBase 141 { 142 public: 143 explicit VmlControlMacroAttacher( const ::rtl::OUString& rMacroName, 144 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rxCtrlFormIC, 145 sal_Int32 nCtrlIndex, sal_Int32 nCtrlType, sal_Int32 nDropStyle ); 146 147 private: 148 virtual void attachMacro( const ::rtl::OUString& rMacroUrl ); 149 150 private: 151 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > mxCtrlFormIC; 152 sal_Int32 mnCtrlIndex; 153 sal_Int32 mnCtrlType; 154 sal_Int32 mnDropStyle; 155 }; 156 157 // ============================================================================ 158 159 class VmlDrawing : public ::oox::vml::Drawing, public WorksheetHelper 160 { 161 public: 162 explicit VmlDrawing( const WorksheetHelper& rHelper ); 163 164 /** Returns the drawing shape for a cell note at the specified position. */ 165 const ::oox::vml::ShapeBase* getNoteShape( const ::com::sun::star::table::CellAddress& rPos ) const; 166 167 /** Filters cell note shapes. */ 168 virtual bool isShapeSupported( const ::oox::vml::ShapeBase& rShape ) const; 169 170 /** Returns additional base names for automatic shape name creation. */ 171 virtual ::rtl::OUString getShapeBaseName( const ::oox::vml::ShapeBase& rShape ) const; 172 173 /** Calculates the shape rectangle from a cell anchor string. */ 174 virtual bool convertClientAnchor( 175 ::com::sun::star::awt::Rectangle& orShapeRect, 176 const ::rtl::OUString& rShapeAnchor ) const; 177 178 /** Creates a UNO control shape for legacy drawing controls. */ 179 virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > 180 createAndInsertClientXShape( 181 const ::oox::vml::ShapeBase& rShape, 182 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 183 const ::com::sun::star::awt::Rectangle& rShapeRect ) const; 184 185 /** Updates the bounding box covering all shapes of this drawing. */ 186 virtual void notifyXShapeInserted( 187 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rxShape, 188 const ::com::sun::star::awt::Rectangle& rShapeRect, 189 const ::oox::vml::ShapeBase& rShape, bool bGroupChild ); 190 191 private: 192 /** Converts the passed VML textbox text color to an OLE color. */ 193 sal_uInt32 convertControlTextColor( const ::rtl::OUString& rTextColor ) const; 194 /** Converts the passed VML textbox font to an ActiveX form control font. */ 195 void convertControlFontData( 196 ::oox::ole::AxFontData& rAxFontData, sal_uInt32& rnOleTextColor, 197 const ::oox::vml::TextFontModel& rFontModel ) const; 198 /** Converts the caption, the font settings, and the horizontal alignment 199 from the passed VML textbox to ActiveX form control settings. */ 200 void convertControlText( 201 ::oox::ole::AxFontData& rAxFontData, sal_uInt32& rnOleTextColor, ::rtl::OUString& rCaption, 202 const ::oox::vml::TextBox* pTextBox, sal_Int32 nTextHAlign ) const; 203 /** Converts the passed VML shape background formatting to ActiveX control formatting. */ 204 void convertControlBackground( 205 ::oox::ole::AxMorphDataModelBase& rAxModel, 206 const ::oox::vml::ShapeBase& rShape ) const; 207 208 private: 209 ::oox::ole::ControlConverter maControlConv; 210 ::oox::vml::TextFontModel maListBoxFont; 211 }; 212 213 // ============================================================================ 214 215 class VmlDrawingFragment : public ::oox::vml::DrawingFragment, public WorksheetHelper 216 { 217 public: 218 explicit VmlDrawingFragment( 219 const WorksheetHelper& rHelper, 220 const ::rtl::OUString& rFragmentPath ); 221 222 protected: 223 virtual void finalizeImport(); 224 }; 225 226 // ============================================================================ 227 228 } // namespace xls 229 } // namespace oox 230 231 #endif 232