1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /************************************************************************* 3 * 4 * The Contents of this file are made available subject to the terms of 5 * either of the following licenses 6 * 7 * - GNU Lesser General Public License Version 2.1 8 * - Sun Industry Standards Source License Version 1.1 9 * 10 * Sun Microsystems Inc., October, 2000 11 * 12 * GNU Lesser General Public License Version 2.1 13 * ============================================= 14 * Copyright 2000 by Sun Microsystems, Inc. 15 * 901 San Antonio Road, Palo Alto, CA 94303, USA 16 * 17 * This library is free software; you can redistribute it and/or 18 * modify it under the terms of the GNU Lesser General Public 19 * License version 2.1, as published by the Free Software Foundation. 20 * 21 * This library is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 * Lesser General Public License for more details. 25 * 26 * You should have received a copy of the GNU Lesser General Public 27 * License along with this library; if not, write to the Free Software 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 29 * MA 02111-1307 USA 30 * 31 * 32 * Sun Industry Standards Source License Version 1.1 33 * ================================================= 34 * The contents of this file are subject to the Sun Industry Standards 35 * Source License Version 1.1 (the "License"); You may not use this file 36 * except in compliance with the License. You may obtain a copy of the 37 * License at http://www.openoffice.org/license.html. 38 * 39 * Software provided under this License is provided on an "AS IS" basis, 40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, 41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, 42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. 43 * See the License for the specific provisions governing your rights and 44 * obligations concerning the Software. 45 * 46 * The Initial Developer of the Original Code is: IBM Corporation 47 * 48 * Copyright: 2008 by IBM Corporation 49 * 50 * All Rights Reserved. 51 * 52 * Contributor(s): _______________________________________ 53 * 54 * 55 ************************************************************************/ 56 /** 57 * @file 58 * For LWP filter architecture prototype - table object 59 */ 60 61 #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPTBLFORMULA_HXX 62 #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_LWPTBLFORMULA_HXX 63 64 /* These token types are written to the file. Don't change their 65 values unless you filter them. 66 */ 67 enum lTokenType 68 { 69 TK_BAD = 0, 70 TK_OPERAND = 1, 71 TK_END = 2, 72 TK_RIGHTPAREN = 3, 73 TK_FUNCTION = 4, 74 TK_LEFTPAREN = 5, 75 TK_UNARY_MINUS = 6, 76 TK_ADD = 7, 77 TK_SUBTRACT = 8, 78 TK_MULTIPLY = 9, 79 TK_DIVIDE = 10, 80 TK_EQUAL = 11, 81 TK_LESS = 12, 82 TK_GREATER = 13, 83 TK_NOT_EQUAL = 14, 84 TK_GREATER_OR_EQUAL = 15, 85 TK_LESS_OR_EQUAL = 16, 86 TK_NOT = 17, 87 TK_AND = 18, 88 TK_OR = 19, 89 TK_CELLID = 20, 90 TK_CONSTANT = 21, 91 TK_TEXT = 22, 92 TK_SUM = 23, 93 TK_IF = 24, 94 TK_AVERAGE = 25, 95 TK_MAXIMUM = 26, 96 TK_MINIMUM = 27, 97 TK_COUNT = 28, 98 TK_CELLRANGE = 29, 99 TK_EXPRESSION = 30, 100 TK_OPEN_FUNCTION = 31, 101 TK_LIST_SEPARATOR = 32 102 }; 103 class LwpTableLayout; 104 class LwpFormulaArg 105 { 106 public: 107 virtual ~LwpFormulaArg() = 0; 108 virtual OUString ToString(LwpTableLayout* pCellsMap)=0; ToArgString(LwpTableLayout * pCellsMap)109 virtual OUString ToArgString(LwpTableLayout* pCellsMap){ return ToString(pCellsMap);} 110 }; 111 112 class LwpFormulaTools 113 { 114 public: 115 static OUString GetName(sal_uInt16 nTokenType); 116 static OUString GetCellAddr(sal_Int16 nRow, sal_Int16 nCol, LwpTableLayout* pCellsMap); 117 }; 118 119 class LwpFormulaConst:public LwpFormulaArg 120 { 121 public: 122 explicit LwpFormulaConst( double dVal); 123 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 124 private: 125 double m_dVal; 126 }; 127 128 class LwpFormulaText:public LwpFormulaArg 129 { 130 public: 131 explicit LwpFormulaText( const OUString& aText); ToString(LwpTableLayout *)132 virtual OUString ToString(LwpTableLayout* /*pCellsMap*/) override {return m_aText;} 133 private: 134 OUString m_aText; 135 }; 136 137 class LwpFormulaCellAddr:public LwpFormulaArg 138 { 139 public: 140 LwpFormulaCellAddr(sal_Int16 aCol, sal_Int16 aRow); 141 GetCol() const142 sal_Int16 GetCol() const {return m_aCol;} GetRow() const143 sal_Int16 GetRow() const {return m_aRow;} 144 145 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 146 private: 147 sal_Int16 m_aCol; 148 sal_Int16 m_aRow; 149 }; 150 151 class LwpFormulaCellRangeAddr:public LwpFormulaArg 152 { 153 public: 154 LwpFormulaCellRangeAddr(sal_Int16 aStartCol, sal_Int16 aStartRow, sal_Int16 aEndCol, sal_Int16 aEndRow); 155 156 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 157 private: 158 sal_Int16 m_aStartCol; 159 sal_Int16 m_aStartRow; 160 sal_Int16 m_aEndCol; 161 sal_Int16 m_aEndRow; 162 }; 163 164 class LwpFormulaFunc :public LwpFormulaArg 165 { 166 public: 167 explicit LwpFormulaFunc(sal_uInt16 nTokenType); 168 virtual ~LwpFormulaFunc() override; 169 170 void AddArg(std::unique_ptr<LwpFormulaArg> pArg); 171 172 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 173 OUString ToArgString(LwpTableLayout* pCellsMap) override; 174 175 protected: 176 std::vector<std::unique_ptr<LwpFormulaArg>> m_aArgs; 177 sal_uInt16 m_nTokenType; 178 }; 179 180 class LwpFormulaOp : public LwpFormulaFunc 181 { 182 public: LwpFormulaOp(sal_uInt16 nTokenType)183 explicit LwpFormulaOp(sal_uInt16 nTokenType):LwpFormulaFunc(nTokenType){} 184 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 185 }; 186 187 class LwpFormulaUnaryOp : public LwpFormulaFunc 188 { 189 public: LwpFormulaUnaryOp(sal_uInt16 nTokenType)190 explicit LwpFormulaUnaryOp(sal_uInt16 nTokenType):LwpFormulaFunc(nTokenType){} 191 virtual OUString ToString(LwpTableLayout* pCellsMap) override; 192 }; 193 194 class LwpFormulaInfo final : public LwpCellList 195 { 196 public: 197 LwpFormulaInfo(LwpObjectHeader const &objHdr, LwpSvStream* pStrm); 198 OUString Convert(LwpTableLayout* pCellsMap); 199 void Convert(XFCell * pCell, LwpTableLayout* pCellsMap=nullptr) override; 200 private: 201 void Read() override; 202 void ReadCellID(); 203 void ReadText(); 204 void ReadCellRange(); 205 void ReadExpression(); 206 void ReadArguments(LwpFormulaFunc& aFunc); 207 bool m_bSupported; 208 virtual ~LwpFormulaInfo() override; 209 void ReadConst(); 210 void MarkUnsupported(sal_uInt16 TokenType); 211 212 std::vector<std::unique_ptr<LwpFormulaArg>> m_aStack; 213 sal_uInt16 m_nFormulaRow; 214 }; 215 216 #endif 217 218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 219