1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2011 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_DBCOLECT_HXX 29 #define SC_DBCOLECT_HXX 30 31 #include "scdllapi.h" 32 #include "collect.hxx" 33 #include "global.hxx" // MAXQUERY 34 #include "sortparam.hxx" // MAXSORT 35 #include "refreshtimer.hxx" 36 #include "address.hxx" 37 #include "scdllapi.h" 38 39 //------------------------------------------------------------------------ 40 41 class ScDocument; 42 43 //------------------------------------------------------------------------ 44 45 class ScDBData : public ScDataObject, public ScRefreshTimer 46 { 47 friend class ScDBCollection; 48 private: 49 // DBParam 50 String aName; 51 SCTAB nTable; 52 SCCOL nStartCol; 53 SCROW nStartRow; 54 SCCOL nEndCol; 55 SCROW nEndRow; 56 sal_Bool bByRow; 57 sal_Bool bHasHeader; 58 sal_Bool bDoSize; 59 sal_Bool bKeepFmt; 60 sal_Bool bStripData; 61 // SortParam 62 sal_Bool bSortCaseSens; 63 sal_Bool bIncludePattern; 64 sal_Bool bSortInplace; 65 sal_Bool bSortUserDef; 66 sal_uInt16 nSortUserIndex; 67 SCTAB nSortDestTab; 68 SCCOL nSortDestCol; 69 SCROW nSortDestRow; 70 sal_Bool bDoSort[MAXSORT]; 71 SCCOLROW nSortField[MAXSORT]; 72 sal_Bool bAscending[MAXSORT]; 73 ::com::sun::star::lang::Locale aSortLocale; 74 String aSortAlgorithm; 75 // QueryParam 76 sal_Bool bQueryInplace; 77 sal_Bool bQueryCaseSens; 78 sal_Bool bQueryRegExp; 79 sal_Bool bQueryDuplicate; 80 SCTAB nQueryDestTab; 81 SCCOL nQueryDestCol; 82 SCROW nQueryDestRow; 83 sal_Bool bDoQuery[MAXQUERY]; 84 SCCOLROW nQueryField[MAXQUERY]; 85 ScQueryOp eQueryOp[MAXQUERY]; 86 sal_Bool bQueryByString[MAXQUERY]; 87 bool bQueryByDate[MAXQUERY]; 88 String* pQueryStr[MAXQUERY]; 89 double nQueryVal[MAXQUERY]; 90 ScQueryConnect eQueryConnect[MAXQUERY]; 91 sal_Bool bIsAdvanced; // sal_True if created by advanced filter 92 ScRange aAdvSource; // source range 93 // SubTotalParam 94 sal_Bool bSubRemoveOnly; 95 sal_Bool bSubReplace; 96 sal_Bool bSubPagebreak; 97 sal_Bool bSubCaseSens; 98 sal_Bool bSubDoSort; 99 sal_Bool bSubAscending; 100 sal_Bool bSubIncludePattern; 101 sal_Bool bSubUserDef; 102 sal_uInt16 nSubUserIndex; 103 sal_Bool bDoSubTotal[MAXSUBTOTAL]; 104 SCCOL nSubField[MAXSUBTOTAL]; 105 SCCOL nSubTotals[MAXSUBTOTAL]; 106 SCCOL* pSubTotals[MAXSUBTOTAL]; 107 ScSubTotalFunc* pFunctions[MAXSUBTOTAL]; 108 // Datenbank-Import 109 sal_Bool bDBImport; 110 String aDBName; 111 String aDBStatement; 112 sal_Bool bDBNative; 113 sal_Bool bDBSelection; // nicht im Param: Wenn Selektion, Update sperren 114 sal_Bool bDBSql; // aDBStatement ist SQL und kein Name 115 sal_uInt8 nDBType; // enum DBObject (bisher nur dbTable, dbQuery) 116 117 sal_uInt16 nIndex; // eindeutiger Index fuer Formeln 118 sal_Bool bAutoFilter; // AutoFilter? (nicht gespeichert) 119 sal_Bool bModified; // wird bei UpdateReference gesetzt/geloescht 120 121 using ScRefreshTimer::operator==; 122 123 public: 124 SC_DLLPUBLIC ScDBData(const String& rName, 125 SCTAB nTab, 126 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, 127 sal_Bool bByR = sal_True, sal_Bool bHasH = sal_True); 128 ScDBData(const ScDBData& rData); 129 ~ScDBData(); 130 131 virtual ScDataObject* Clone() const; 132 133 ScDBData& operator= (const ScDBData& rData); 134 135 sal_Bool operator== (const ScDBData& rData) const; 136 137 const String& GetName() const { return aName; } 138 void GetName(String& rName) const { rName = aName; } 139 void SetName(const String& rName) { aName = rName; } 140 void GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const; 141 SC_DLLPUBLIC void GetArea(ScRange& rRange) const; 142 void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2); 143 void MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2); 144 sal_Bool IsByRow() const { return bByRow; } 145 void SetByRow(sal_Bool bByR) { bByRow = bByR; } 146 sal_Bool HasHeader() const { return bHasHeader; } 147 void SetHeader(sal_Bool bHasH) { bHasHeader = bHasH; } 148 void SetIndex(sal_uInt16 nInd) { nIndex = nInd; } 149 sal_uInt16 GetIndex() const { return nIndex; } 150 sal_Bool IsDoSize() const { return bDoSize; } 151 void SetDoSize(sal_Bool bSet) { bDoSize = bSet; } 152 sal_Bool IsKeepFmt() const { return bKeepFmt; } 153 void SetKeepFmt(sal_Bool bSet) { bKeepFmt = bSet; } 154 sal_Bool IsStripData() const { return bStripData; } 155 void SetStripData(sal_Bool bSet) { bStripData = bSet; } 156 157 //UNUSED2008-05 sal_Bool IsBeyond(SCROW nMaxRow) const; 158 159 String GetSourceString() const; 160 String GetOperations() const; 161 162 void GetSortParam(ScSortParam& rSortParam) const; 163 void SetSortParam(const ScSortParam& rSortParam); 164 165 SC_DLLPUBLIC void GetQueryParam(ScQueryParam& rQueryParam) const; 166 SC_DLLPUBLIC void SetQueryParam(const ScQueryParam& rQueryParam); 167 SC_DLLPUBLIC sal_Bool GetAdvancedQuerySource(ScRange& rSource) const; 168 SC_DLLPUBLIC void SetAdvancedQuerySource(const ScRange* pSource); 169 170 void GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const; 171 void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam); 172 173 void GetImportParam(ScImportParam& rImportParam) const; 174 void SetImportParam(const ScImportParam& rImportParam); 175 176 sal_Bool IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const; 177 sal_Bool IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const; 178 179 sal_Bool HasImportParam() const { return bDBImport; } 180 sal_Bool HasQueryParam() const { return bDoQuery[0]; } 181 sal_Bool HasSortParam() const { return bDoSort[0]; } 182 sal_Bool HasSubTotalParam() const { return bDoSubTotal[0]; } 183 184 sal_Bool HasImportSelection() const { return bDBSelection; } 185 void SetImportSelection(sal_Bool bSet) { bDBSelection = bSet; } 186 187 sal_Bool HasAutoFilter() const { return bAutoFilter; } 188 void SetAutoFilter(sal_Bool bSet) { bAutoFilter = bSet; } 189 190 sal_Bool IsModified() const { return bModified; } 191 void SetModified(sal_Bool bMod) { bModified = bMod; } 192 }; 193 194 195 //------------------------------------------------------------------------ 196 class SC_DLLPUBLIC ScDBCollection : public ScSortedCollection 197 { 198 199 private: 200 Link aRefreshHandler; 201 ScDocument* pDoc; 202 sal_uInt16 nEntryIndex; // Zaehler fuer die eindeutigen Indizes 203 204 public: 205 ScDBCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False, ScDocument* pDocument = NULL) : 206 ScSortedCollection ( nLim, nDel, bDup ), 207 pDoc ( pDocument ), 208 nEntryIndex ( SC_START_INDEX_DB_COLL ) // oberhalb der Namen 209 {} 210 ScDBCollection(const ScDBCollection& rScDBCollection) : 211 ScSortedCollection ( rScDBCollection ), 212 pDoc ( rScDBCollection.pDoc ), 213 nEntryIndex ( rScDBCollection.nEntryIndex) 214 {} 215 216 virtual ScDataObject* Clone() const { return new ScDBCollection(*this); } 217 ScDBData* operator[]( const sal_uInt16 nIndex) const {return (ScDBData*)At(nIndex);} 218 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const; 219 virtual sal_Bool IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const; 220 ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const; 221 ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const; 222 ScDBData* GetFilterDBAtTable(SCTAB nTab) const; 223 224 sal_Bool SearchName( const String& rName, sal_uInt16& rIndex ) const; 225 226 void DeleteOnTab( SCTAB nTab ); 227 void UpdateReference(UpdateRefMode eUpdateRefMode, 228 SCCOL nCol1, SCROW nRow1, SCTAB nTab1, 229 SCCOL nCol2, SCROW nRow2, SCTAB nTab2, 230 SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 231 void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ); 232 233 ScDBData* FindIndex(sal_uInt16 nIndex); 234 sal_uInt16 GetEntryIndex() { return nEntryIndex; } 235 void SetEntryIndex(sal_uInt16 nInd) { nEntryIndex = nInd; } 236 virtual sal_Bool Insert(ScDataObject* pScDataObject); 237 238 void SetRefreshHandler( const Link& rLink ) 239 { aRefreshHandler = rLink; } 240 const Link& GetRefreshHandler() const { return aRefreshHandler; } 241 }; 242 243 #endif 244