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 #ifndef SC_VBA_RANGE_HXX 24 #define SC_VBA_RANGE_HXX 25 26 #include <cppuhelper/implbase4.hxx> 27 #include <com/sun/star/container/XEnumerationAccess.hpp> 28 29 #include <ooo/vba/excel/XRange.hpp> 30 #include <com/sun/star/table/XCellRange.hpp> 31 #include <ooo/vba/excel/XFont.hpp> 32 #include <ooo/vba/excel/XComment.hpp> 33 #include <ooo/vba/XCollection.hpp> 34 #include <ooo/vba/excel/XlPasteType.hdl> 35 #include <ooo/vba/excel/XlPasteSpecialOperation.hdl> 36 37 #include <comphelper/proparrhlp.hxx> 38 #include <comphelper/propertycontainer.hxx> 39 #include <com/sun/star/beans/XPropertySet.hpp> 40 #include <com/sun/star/beans/PropertyAttribute.hpp> 41 #include <com/sun/star/script/XDefaultMethod.hpp> 42 #include <com/sun/star/script/XDefaultProperty.hpp> 43 #include <com/sun/star/sheet/FillDateMode.hpp> 44 #include <com/sun/star/sheet/FillMode.hpp> 45 #include <com/sun/star/sheet/FillDirection.hpp> 46 #include <com/sun/star/sheet/XSpreadsheet.hpp> 47 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> 48 49 //#include <vbahelper/vbahelperinterface.hxx> 50 #include "vbaformat.hxx" 51 #include <formula/grammar.hxx> 52 53 class ScTableSheetsObj; 54 class ScCellRangesBase; 55 class ScCellRangeObj; 56 class ScCellRangesObj; 57 class ScDocShell; 58 class ScDocument; 59 class ScRangeList; 60 61 //typedef InheritedHelperInterfaceImpl1< ov::excel::XRange > ScVbaRange_BASE; 62 typedef ScVbaFormat< ov::excel::XRange > ScVbaRange_BASE; 63 64 class ArrayVisitor 65 { 66 public: 67 virtual void visitNode( sal_Int32 x, sal_Int32 y, const css::uno::Reference< css::table::XCell >& xCell ) = 0; ~ArrayVisitor()68 virtual ~ArrayVisitor(){} 69 }; 70 71 class ValueSetter : public ArrayVisitor 72 { 73 public: 74 virtual bool processValue( const css::uno::Any& aValue, const css::uno::Reference< css::table::XCell >& xCell ) = 0; 75 76 77 }; 78 79 class ValueGetter : public ArrayVisitor 80 { 81 82 public: 83 virtual void processValue( sal_Int32 x, sal_Int32 y, const css::uno::Any& aValue ) = 0; 84 virtual const css::uno::Any& getValue() const = 0; 85 }; 86 87 88 89 class ScVbaRange : public ScVbaRange_BASE 90 { 91 css::uno::Reference< ov::XCollection > m_Areas; 92 css::uno::Reference< ov::XCollection > m_Borders; 93 css::uno::Reference< css::table::XCellRange > mxRange; 94 css::uno::Reference< css::sheet::XSheetCellRangeContainer > mxRanges; 95 sal_Bool mbIsRows; 96 sal_Bool mbIsColumns; 97 css::uno::Reference< ov::excel::XValidation > m_xValidation; 98 99 double getCalcColWidth( const css::table::CellRangeAddress& ); 100 double getCalcRowHeight( const css::table::CellRangeAddress& ); 101 void visitArray( ArrayVisitor& vistor ); 102 103 css::uno::Reference< ov::excel::XRange > getEntireColumnOrRow( bool bColumn = true ); 104 105 void fillSeries( css::sheet::FillDirection nFillDirection, css::sheet::FillMode nFillMode, css::sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ); 106 107 void ClearContents( sal_Int32 nFlags, bool bFireEvent ); 108 109 css::uno::Any getValue( ValueGetter& rValueGetter ); 110 void setValue( const css::uno::Any& aValue, ValueSetter& setter, bool bFireEvent ); 111 112 css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ); 113 void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar, bool bFireEvent ); 114 115 css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ); 116 ScCellRangeObj* getCellRangeObj( ); 117 ScCellRangesObj* getCellRangesObj(); 118 css::uno::Reference< ov::XCollection >& getBorders(); 119 void groupUnGroup( bool bUnGroup = false ); 120 css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious ); 121 css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue); 122 css::awt::Point getPosition(); 123 124 /** Fires a Worksheet_Change event for this range or range list. */ 125 void fireChangeEvent(); 126 127 protected: 128 virtual ScCellRangesBase* getCellRangesBase(); 129 virtual SfxItemSet* getCurrentDataSet( ); 130 public: 131 ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::table::XCellRange >& xRange, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ); 132 ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ); 133 ScVbaRange( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); 134 135 ScDocument* getScDocument(); 136 ScDocShell* getScDocShell(); 137 138 /** Returns the ScVbaRange implementation object for the passed VBA Range object. */ 139 static ScVbaRange* getImplementation( const css::uno::Reference< ov::excel::XRange >& rxRange ); 140 141 css::uno::Reference< css::frame::XModel > getUnoModel(); 142 static css::uno::Reference< css::frame::XModel > getUnoModel( const css::uno::Reference< ov::excel::XRange >& rxRange ); 143 144 const ScRangeList& getScRangeList(); 145 static const ScRangeList& getScRangeList( const css::uno::Reference< ov::excel::XRange >& rxRange ); 146 147 virtual ~ScVbaRange(); thisHelperIface()148 virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() { return this; } 149 bool isSingleCellRange(); 150 151 static css::uno::Reference< ov::excel::XRange > getRangeObjectForName( 152 const css::uno::Reference< css::uno::XComponentContext >& xContext, 153 const rtl::OUString& sRangeName, ScDocShell* pDocSh, 154 formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ); 155 156 static css::uno::Reference< ov::excel::XRange > CellsHelper( 157 const css::uno::Reference< ov::XHelperInterface >& xParent, 158 const css::uno::Reference< css::uno::XComponentContext >& xContext, 159 const css::uno::Reference< css::table::XCellRange >& xRange, 160 const css::uno::Any &nRowIndex, const css::uno::Any &nColumnIndex ); 161 162 // Attributes 163 virtual css::uno::Any SAL_CALL getValue(); 164 virtual void SAL_CALL setValue( const css::uno::Any& aValue ); 165 virtual css::uno::Any SAL_CALL getFormula(); 166 virtual void SAL_CALL setFormula( const css::uno::Any& rFormula ); 167 virtual css::uno::Any SAL_CALL getFormulaArray(); 168 virtual void SAL_CALL setFormulaArray(const css::uno::Any& rFormula); 169 virtual css::uno::Any SAL_CALL getFormulaR1C1(); 170 virtual void SAL_CALL setFormulaR1C1( const css::uno::Any &rFormula ); 171 virtual ::sal_Int32 SAL_CALL getCount(); 172 virtual ::sal_Int32 SAL_CALL getRow(); 173 virtual ::sal_Int32 SAL_CALL getColumn(); 174 virtual ::rtl::OUString SAL_CALL getText(); 175 using ScVbaRange_BASE::setNumberFormat; 176 virtual void SAL_CALL setNumberFormat( const css::uno::Any& rNumberFormat ); 177 virtual css::uno::Any SAL_CALL getNumberFormat(); 178 virtual void SAL_CALL setMergeCells( const css::uno::Any& bMerge ); 179 virtual css::uno::Any SAL_CALL getMergeCells(); 180 virtual void SAL_CALL setWrapText( const css::uno::Any& bIsWrapped ); 181 virtual css::uno::Any SAL_CALL getWrapText(); 182 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireRow(); 183 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireColumn(); 184 virtual css::uno::Reference< ov::excel::XComment > SAL_CALL getComment(); 185 virtual css::uno::Any SAL_CALL getHidden(); 186 virtual void SAL_CALL setHidden( const css::uno::Any& _hidden ); 187 virtual css::uno::Any SAL_CALL getColumnWidth(); 188 virtual void SAL_CALL setColumnWidth( const css::uno::Any& _columnwidth ); 189 virtual css::uno::Any SAL_CALL getRowHeight(); 190 virtual void SAL_CALL setRowHeight( const css::uno::Any& _rowheight ); 191 virtual css::uno::Any SAL_CALL getWidth(); 192 virtual css::uno::Any SAL_CALL getHeight(); 193 virtual css::uno::Any SAL_CALL getTop(); 194 virtual css::uno::Any SAL_CALL getLeft(); 195 196 virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getWorksheet(); 197 virtual css::uno::Any SAL_CALL getPageBreak(); 198 virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ); 199 virtual css::uno::Reference< ov::excel::XValidation > SAL_CALL getValidation(); 200 virtual css::uno::Any SAL_CALL getPrefixCharacter(); 201 virtual css::uno::Any SAL_CALL getShowDetail(); 202 virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail); 203 // Methods IsRows()204 sal_Bool IsRows() { return mbIsRows; } IsColumns()205 sal_Bool IsColumns() { return mbIsColumns; } 206 virtual css::uno::Reference< ov::excel::XComment > SAL_CALL AddComment( const css::uno::Any& Text ); 207 virtual void SAL_CALL Clear(); 208 virtual void SAL_CALL ClearComments(); 209 virtual void SAL_CALL ClearContents(); 210 virtual void SAL_CALL ClearFormats(); 211 virtual css::uno::Any SAL_CALL HasFormula(); 212 virtual void SAL_CALL FillLeft(); 213 virtual void SAL_CALL FillRight(); 214 virtual void SAL_CALL FillUp(); 215 virtual void SAL_CALL FillDown(); 216 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Offset( const css::uno::Any &nRowOffset, const css::uno::Any &nColOffset ); 217 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentRegion(); 218 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentArray(); 219 virtual ::rtl::OUString SAL_CALL Characters( const css::uno::Any& nIndex, const css::uno::Any& nCount ); 220 221 virtual ::rtl::OUString SAL_CALL Address( const css::uno::Any& RowAbsolute, const css::uno::Any& ColumnAbsolute, const css::uno::Any& ReferenceStyle, const css::uno::Any& External, const css::uno::Any& RelativeTo ); 222 223 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any &nRow, const css::uno::Any &nCol ); 224 virtual void SAL_CALL Select(); 225 virtual void SAL_CALL Activate(); 226 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Rows( const css::uno::Any& nIndex ); 227 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns( const css::uno::Any &nIndex ); 228 virtual void SAL_CALL Copy( const css::uno::Any& Destination ); 229 virtual void SAL_CALL Cut( const css::uno::Any& Destination ); 230 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Resize( const css::uno::Any& RowSize, const css::uno::Any& ColumnSize ); 231 virtual css::uno::Reference< ov::excel::XFont > SAL_CALL Font(); 232 virtual css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior( ) ; 233 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2 ); 234 virtual css::uno::Reference< ov::excel::XRange > Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2, bool bForceUseInpuRangeTab ); 235 virtual css::uno::Any SAL_CALL getCellRange( ); 236 static css::uno::Any getCellRange( const css::uno::Reference< ov::excel::XRange >& rxRange ); 237 virtual void SAL_CALL PasteSpecial( const css::uno::Any& Paste, const css::uno::Any& Operation, const css::uno::Any& SkipBlanks, const css::uno::Any& Transpose ); 238 virtual ::sal_Bool SAL_CALL Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat, const css::uno::Any& ReplaceFormat ); 239 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Find( const css::uno::Any& What, const css::uno::Any& After, const css::uno::Any& LookIn, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& SearchDirection, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat ); 240 virtual void SAL_CALL Sort( const css::uno::Any& Key1, const css::uno::Any& Order1, const css::uno::Any& Key2, const css::uno::Any& Type, const css::uno::Any& Order2, const css::uno::Any& Key3, const css::uno::Any& Order3, const css::uno::Any& Header, const css::uno::Any& OrderCustom, const css::uno::Any& MatchCase, const css::uno::Any& Orientation, const css::uno::Any& SortMethod, const css::uno::Any& DataOption1, const css::uno::Any& DataOption2, const css::uno::Any& DataOption3 ); 241 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL End( ::sal_Int32 Direction ); 242 virtual css::uno::Reference< ov::excel::XCharacters > SAL_CALL characters( const css::uno::Any& Start, const css::uno::Any& Length ); 243 virtual void SAL_CALL Delete( const css::uno::Any& Shift ); 244 virtual css::uno::Any SAL_CALL Areas( const css::uno::Any& ); 245 virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& ); 246 virtual css::uno::Any SAL_CALL BorderAround( const css::uno::Any& LineStyle, 247 const css::uno::Any& Weight, const css::uno::Any& ColorIndex, const css::uno::Any& Color ); 248 virtual void SAL_CALL TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier, 249 const css::uno::Any& ConsecutinveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma, 250 const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo, 251 const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& TrailingMinusNumbers ); 252 virtual css::uno::Any SAL_CALL Hyperlinks( const css::uno::Any& aIndex ); 253 254 virtual void SAL_CALL AutoFilter( const css::uno::Any& Field, const css::uno::Any& Criteria1, const css::uno::Any& Operator, const css::uno::Any& Criteria2, const css::uno::Any& VisibleDropDown ); 255 virtual void SAL_CALL Insert( const css::uno::Any& Shift, const css::uno::Any& CopyOrigin ); 256 virtual void SAL_CALL Autofit(); 257 virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ); 258 virtual void SAL_CALL AutoFill( const css::uno::Reference< ov::excel::XRange >& Destination, const css::uno::Any& Type ) ; 259 void SAL_CALL Calculate( ); 260 virtual void SAL_CALL AutoOutline( ); 261 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Item( const ::css::uno::Any& row, const css::uno::Any& column ); 262 virtual void SAL_CALL ClearOutline( ); 263 virtual void SAL_CALL Ungroup( ); 264 virtual void SAL_CALL Group( ); 265 virtual void SAL_CALL Merge( const css::uno::Any& Across ); 266 virtual void SAL_CALL UnMerge( ); 267 virtual css::uno::Any SAL_CALL getStyle(); 268 virtual void SAL_CALL setStyle( const css::uno::Any& _style ); 269 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Next(); 270 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Previous(); 271 virtual void SAL_CALL RemoveSubtotal( ); 272 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL MergeArea(); 273 virtual void SAL_CALL Subtotal( ::sal_Int32 GroupBy, ::sal_Int32 Function, const css::uno::Sequence< ::sal_Int32 >& TotalList, const css::uno::Any& Replace, const css::uno::Any& PageBreaks, const css::uno::Any& SummaryBelowData ); 274 // XEnumerationAccess 275 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration(); 276 // XElementAccess getElementType()277 virtual css::uno::Type SAL_CALL getElementType() 278 { 279 return ov::excel::XRange::static_type(0); 280 281 } 282 virtual sal_Bool SAL_CALL hasElements(); 283 // XDefaultMethod 284 ::rtl::OUString SAL_CALL getDefaultMethodName( ); 285 // XDefaultProperty getDefaultPropertyName()286 ::rtl::OUString SAL_CALL getDefaultPropertyName( ) { return ::rtl::OUString::createFromAscii("Value"); } 287 288 289 // #TODO completely rewrite ScVbaRange, its become a hackfest 290 // it needs to be closer to ScCellRangeBase in that the underlying 291 // object model should probably be a ScRangelst. 292 // * would be nice to be able to construct a range from an address only 293 // * or a list of address ( multi-area ) 294 // * object should be a lightweight as possible 295 // * we shouldn't need hacks like this below 296 static css::uno::Reference< ov::excel::XRange > ApplicationRange( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ); 297 virtual sal_Bool SAL_CALL GoalSeek( const css::uno::Any& Goal, const css::uno::Reference< ov::excel::XRange >& ChangingCell ); 298 virtual css::uno::Reference< ov::excel::XRange > SAL_CALL SpecialCells( const css::uno::Any& _oType, const css::uno::Any& _oValue); 299 // XHelperInterface 300 virtual rtl::OUString& getServiceImplName(); 301 virtual css::uno::Sequence<rtl::OUString> getServiceNames(); 302 }; 303 #endif /* SC_VBA_RANGE_HXX */ 304