xref: /AOO41X/main/sc/inc/dbcolect.hxx (revision 707fc0d4d52eb4f69d89a98ffec6918ca5de6326)
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 SC_DBCOLECT_HXX
25 #define SC_DBCOLECT_HXX
26 
27 #include "scdllapi.h"
28 #include "collect.hxx"
29 #include "global.hxx"       // MAXQUERY
30 #include "sortparam.hxx"    // MAXSORT
31 #include "refreshtimer.hxx"
32 #include "address.hxx"
33 #include "scdllapi.h"
34 
35 //------------------------------------------------------------------------
36 
37 class ScDocument;
38 
39 //------------------------------------------------------------------------
40 
41 class ScDBData : public ScDataObject, public ScRefreshTimer
42 {
43 friend class ScDBCollection;
44 private:
45     // DBParam
46     String          aName;
47     SCTAB           nTable;
48     SCCOL           nStartCol;
49     SCROW           nStartRow;
50     SCCOL           nEndCol;
51     SCROW           nEndRow;
52     sal_Bool            bByRow;
53     sal_Bool            bHasHeader;
54     sal_Bool            bDoSize;
55     sal_Bool            bKeepFmt;
56     sal_Bool            bStripData;
57     // SortParam
58     sal_Bool            bSortCaseSens;
59     sal_Bool            bIncludePattern;
60     sal_Bool            bSortInplace;
61     sal_Bool            bSortUserDef;
62     sal_uInt16          nSortUserIndex;
63     SCTAB           nSortDestTab;
64     SCCOL           nSortDestCol;
65     SCROW           nSortDestRow;
66     sal_Bool            bDoSort[MAXSORT];
67     SCCOLROW        nSortField[MAXSORT];
68     sal_Bool            bAscending[MAXSORT];
69     ::com::sun::star::lang::Locale aSortLocale;
70     String          aSortAlgorithm;
71     // QueryParam
72     sal_Bool            bQueryInplace;
73     sal_Bool            bQueryCaseSens;
74     sal_Bool            bQueryRegExp;
75     sal_Bool            bQueryDuplicate;
76     SCTAB           nQueryDestTab;
77     SCCOL           nQueryDestCol;
78     SCROW           nQueryDestRow;
79     sal_Bool            bDoQuery[MAXQUERY];
80     SCCOLROW        nQueryField[MAXQUERY];
81     ScQueryOp       eQueryOp[MAXQUERY];
82     sal_Bool            bQueryByString[MAXQUERY];
83     bool            bQueryByDate[MAXQUERY];
84     String*         pQueryStr[MAXQUERY];
85     double          nQueryVal[MAXQUERY];
86     ScQueryConnect  eQueryConnect[MAXQUERY];
87     sal_Bool            bIsAdvanced;        // sal_True if created by advanced filter
88     ScRange         aAdvSource;         // source range
89     // SubTotalParam
90     sal_Bool            bSubRemoveOnly;
91     sal_Bool            bSubReplace;
92     sal_Bool            bSubPagebreak;
93     sal_Bool            bSubCaseSens;
94     sal_Bool            bSubDoSort;
95     sal_Bool            bSubAscending;
96     sal_Bool            bSubIncludePattern;
97     sal_Bool            bSubUserDef;
98     sal_uInt16          nSubUserIndex;
99     sal_Bool            bDoSubTotal[MAXSUBTOTAL];
100     SCCOL           nSubField[MAXSUBTOTAL];
101     SCCOL           nSubTotals[MAXSUBTOTAL];
102     SCCOL*          pSubTotals[MAXSUBTOTAL];
103     ScSubTotalFunc* pFunctions[MAXSUBTOTAL];
104     // Datenbank-Import
105     sal_Bool            bDBImport;
106     String          aDBName;
107     String          aDBStatement;
108     sal_Bool            bDBNative;
109     sal_Bool            bDBSelection;       // nicht im Param: Wenn Selektion, Update sperren
110     sal_Bool            bDBSql;             // aDBStatement ist SQL und kein Name
111     sal_uInt8           nDBType;            // enum DBObject (bisher nur dbTable, dbQuery)
112 
113     sal_uInt16          nIndex;             // eindeutiger Index fuer Formeln
114     sal_Bool            bAutoFilter;        // AutoFilter? (nicht gespeichert)
115     sal_Bool            bModified;          // wird bei UpdateReference gesetzt/geloescht
116 
117     using ScRefreshTimer::operator==;
118 
119 public:
120             SC_DLLPUBLIC ScDBData(const String& rName,
121                      SCTAB nTab,
122                      SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
123                      sal_Bool bByR = sal_True, sal_Bool bHasH = sal_True);
124             ScDBData(const ScDBData& rData);
125             ~ScDBData();
126 
127     virtual ScDataObject*   Clone() const;
128 
129             ScDBData&   operator= (const ScDBData& rData);
130 
131             sal_Bool        operator== (const ScDBData& rData) const;
132 
133             const String& GetName() const               { return aName; }
134             void        GetName(String& rName) const    { rName = aName; }
135             void        SetName(const String& rName)    { aName = rName; }
136             void        GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
137             SC_DLLPUBLIC void       GetArea(ScRange& rRange) const;
138             void        SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
139             void        MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
140             sal_Bool        IsByRow() const                 { return bByRow; }
141             void        SetByRow(sal_Bool bByR)             { bByRow = bByR; }
142             sal_Bool        HasHeader() const               { return bHasHeader; }
143             void        SetHeader(sal_Bool bHasH)           { bHasHeader = bHasH; }
144             void        SetIndex(sal_uInt16 nInd)           { nIndex = nInd; }
145             sal_uInt16      GetIndex() const                { return nIndex; }
146             sal_Bool        IsDoSize() const                { return bDoSize; }
147             void        SetDoSize(sal_Bool bSet)            { bDoSize = bSet; }
148             sal_Bool        IsKeepFmt() const               { return bKeepFmt; }
149             void        SetKeepFmt(sal_Bool bSet)           { bKeepFmt = bSet; }
150             sal_Bool        IsStripData() const             { return bStripData; }
151             void        SetStripData(sal_Bool bSet)         { bStripData = bSet; }
152 
153 //UNUSED2008-05  sal_Bool       IsBeyond(SCROW nMaxRow) const;
154 
155             String      GetSourceString() const;
156             String      GetOperations() const;
157 
158             void        GetSortParam(ScSortParam& rSortParam) const;
159             void        SetSortParam(const ScSortParam& rSortParam);
160 
161             SC_DLLPUBLIC void       GetQueryParam(ScQueryParam& rQueryParam) const;
162             SC_DLLPUBLIC void       SetQueryParam(const ScQueryParam& rQueryParam);
163             SC_DLLPUBLIC sal_Bool       GetAdvancedQuerySource(ScRange& rSource) const;
164             SC_DLLPUBLIC void       SetAdvancedQuerySource(const ScRange* pSource);
165 
166             void        GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
167             void        SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
168 
169             void        GetImportParam(ScImportParam& rImportParam) const;
170             void        SetImportParam(const ScImportParam& rImportParam);
171 
172             sal_Bool        IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
173             sal_Bool        IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
174 
175             sal_Bool        HasImportParam() const   { return bDBImport; }
176             sal_Bool        HasQueryParam() const    { return bDoQuery[0]; }
177             sal_Bool        HasSortParam() const     { return bDoSort[0]; }
178             sal_Bool        HasSubTotalParam() const { return bDoSubTotal[0]; }
179 
180             sal_Bool        HasImportSelection() const      { return bDBSelection; }
181             void        SetImportSelection(sal_Bool bSet)   { bDBSelection = bSet; }
182 
183             sal_Bool        HasAutoFilter() const       { return bAutoFilter; }
184             void        SetAutoFilter(sal_Bool bSet)    { bAutoFilter = bSet; }
185 
186             sal_Bool        IsModified() const          { return bModified; }
187             void        SetModified(sal_Bool bMod)      { bModified = bMod; }
188 };
189 
190 
191 //------------------------------------------------------------------------
192 class SC_DLLPUBLIC ScDBCollection : public ScSortedCollection
193 {
194 
195 private:
196     Link        aRefreshHandler;
197     ScDocument* pDoc;
198     sal_uInt16 nEntryIndex;         // Zaehler fuer die eindeutigen Indizes
199 
200 public:
201     ScDBCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False, ScDocument* pDocument = NULL) :
202                     ScSortedCollection  ( nLim, nDel, bDup ),
203                     pDoc                ( pDocument ),
204                     nEntryIndex         ( SC_START_INDEX_DB_COLL )  // oberhalb der Namen
205                     {}
206     ScDBCollection(const ScDBCollection& rScDBCollection) :
207                     ScSortedCollection  ( rScDBCollection ),
208                     pDoc                ( rScDBCollection.pDoc ),
209                     nEntryIndex         ( rScDBCollection.nEntryIndex)
210                     {}
211 
212     virtual ScDataObject*   Clone() const { return new ScDBCollection(*this); }
213             ScDBData*   operator[]( const sal_uInt16 nIndex) const {return (ScDBData*)At(nIndex);}
214     virtual short       Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
215     virtual sal_Bool        IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
216             ScDBData*   GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Bool bStartOnly) const;
217             ScDBData*   GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
218             ScDBData*       GetFilterDBAtTable(SCTAB nTab) const;
219 
220     sal_Bool    SearchName( const String& rName, sal_uInt16& rIndex ) const;
221 
222     void    DeleteOnTab( SCTAB nTab );
223     void    UpdateReference(UpdateRefMode eUpdateRefMode,
224                                 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
225                                 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
226                                 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
227     void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
228 
229     ScDBData* FindIndex(sal_uInt16 nIndex);
230     sal_uInt16  GetEntryIndex()                 { return nEntryIndex; }
231     void    SetEntryIndex(sal_uInt16 nInd)      { nEntryIndex = nInd; }
232     virtual sal_Bool Insert(ScDataObject* pScDataObject);
233 
234     void            SetRefreshHandler( const Link& rLink )
235                         { aRefreshHandler = rLink; }
236     const Link&     GetRefreshHandler() const   { return aRefreshHandler; }
237 };
238 
239 #endif
240