xref: /aoo4110/main/sc/inc/dbcolect.hxx (revision b1cdbd2c)
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 
GetName() const133 			const String& GetName() const				{ return aName; }
GetName(String & rName) const134 			void		GetName(String& rName) const	{ rName = aName; }
SetName(const String & rName)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 
140             bool IsInternalUnnamed() const;
141             bool IsInternalForAutoFilter() const;
142 
143             void		MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
IsByRow() const144 			sal_Bool		IsByRow() const 				{ return bByRow; }
SetByRow(sal_Bool bByR)145 			void		SetByRow(sal_Bool bByR) 			{ bByRow = bByR; }
HasHeader() const146 			sal_Bool		HasHeader() const 				{ return bHasHeader; }
SetHeader(sal_Bool bHasH)147 			void		SetHeader(sal_Bool bHasH) 			{ bHasHeader = bHasH; }
SetIndex(sal_uInt16 nInd)148             void        SetIndex(sal_uInt16 nInd)           { nIndex = nInd; }
GetIndex() const149 			sal_uInt16		GetIndex() const				{ return nIndex; }
IsDoSize() const150 			sal_Bool		IsDoSize() const				{ return bDoSize; }
SetDoSize(sal_Bool bSet)151 			void		SetDoSize(sal_Bool bSet)			{ bDoSize = bSet; }
IsKeepFmt() const152 			sal_Bool		IsKeepFmt() const				{ return bKeepFmt; }
SetKeepFmt(sal_Bool bSet)153 			void		SetKeepFmt(sal_Bool bSet)			{ bKeepFmt = bSet; }
IsStripData() const154 			sal_Bool		IsStripData() const				{ return bStripData; }
SetStripData(sal_Bool bSet)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 
HasImportParam() const179 			sal_Bool		HasImportParam() const	 { return bDBImport; }
HasQueryParam() const180 			sal_Bool		HasQueryParam() const	 { return bDoQuery[0]; }
HasSortParam() const181 			sal_Bool		HasSortParam() const	 { return bDoSort[0]; }
HasSubTotalParam() const182 			sal_Bool		HasSubTotalParam() const { return bDoSubTotal[0]; }
183 
HasImportSelection() const184 			sal_Bool		HasImportSelection() const		{ return bDBSelection; }
SetImportSelection(sal_Bool bSet)185 			void		SetImportSelection(sal_Bool bSet)	{ bDBSelection = bSet; }
186 
HasAutoFilter() const187 			sal_Bool		HasAutoFilter() const 		{ return bAutoFilter; }
SetAutoFilter(sal_Bool bSet)188 			void		SetAutoFilter(sal_Bool bSet)	{ bAutoFilter = bSet; }
189 
IsModified() const190 			sal_Bool		IsModified() const			{ return bModified; }
SetModified(sal_Bool bMod)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:
ScDBCollection(sal_uInt16 nLim=4,sal_uInt16 nDel=4,sal_Bool bDup=sal_False,ScDocument * pDocument=NULL)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 					{}
ScDBCollection(const ScDBCollection & rScDBCollection)210 	ScDBCollection(const ScDBCollection& rScDBCollection) :
211 					ScSortedCollection	( rScDBCollection ),
212 					pDoc 				( rScDBCollection.pDoc ),
213 					nEntryIndex			( rScDBCollection.nEntryIndex)
214 					{}
215 
Clone() const216 	virtual	ScDataObject*	Clone() const { return new ScDBCollection(*this); }
operator [](const sal_uInt16 nIndex) const217 			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(
222                 const SCTAB nTab,
223                 const SCCOL nCol1,
224                 const SCROW nRow1,
225                 const SCCOL nCol2,
226                 const SCROW nRow2 ) const;
227 			ScDBData*       GetFilterDBAtTable(SCTAB nTab) const;
228 
229 	sal_Bool	SearchName( const String& rName, sal_uInt16& rIndex ) const;
230 
231     void    DeleteOnTab( SCTAB nTab );
232 	void	UpdateReference(UpdateRefMode eUpdateRefMode,
233 								SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
234 								SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
235 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
236 	void	UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
237 
238 	ScDBData* FindIndex(sal_uInt16 nIndex);
GetEntryIndex()239 	sal_uInt16 	GetEntryIndex()					{ return nEntryIndex; }
SetEntryIndex(sal_uInt16 nInd)240 	void 	SetEntryIndex(sal_uInt16 nInd)		{ nEntryIndex = nInd; }
241 	virtual sal_Bool Insert(ScDataObject* pScDataObject);
242 
SetRefreshHandler(const Link & rLink)243 	void			SetRefreshHandler( const Link& rLink )
244 						{ aRefreshHandler = rLink; }
GetRefreshHandler() const245 	const Link&		GetRefreshHandler() const	{ return aRefreshHandler; }
246     String      GetNewDefaultDBName();
247     /*sal_Bool        IsFiltered(SCTAB nTab, SCROW nRow);*/
248 };
249 
250 #endif
251