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 DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
24 #define DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
25 
26 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
27 #include <svtools/editbrowsebox.hxx>
28 #endif
29 //#ifndef DBAUI_QUERYCONTROLLER_HXX
30 //#include "querycontroller.hxx"
31 //#endif
32 #ifndef DBAUI_TABLEFIELDDESC_HXX
33 #include "TableFieldDescription.hxx"
34 #endif
35 #ifndef DBAUI_JOINEXCHANGE_HXX
36 #include "JoinExchange.hxx"
37 #endif
38 #ifndef DBAUI_ENUMTYPES_HXX
39 #include "QEnumTypes.hxx"
40 #endif
41 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
42 #include <com/sun/star/util/XNumberFormatter.hpp>
43 #endif
44 #ifndef _STRING_HXX
45 #include <tools/string.hxx>
46 #endif
47 #ifndef _TRANSFER_HXX
48 #include <svtools/transfer.hxx>
49 #endif
50 
51 namespace connectivity
52 {
53 	class OSQLParseNode;
54 }
55 
56 namespace dbaui
57 {
58 	//==================================================================
59 #define SIZ_NONE		0
60 #define SIZ_TOP			1
61 #define SIZ_BOTTOM		2
62 #define SIZ_LEFT		4
63 #define SIZ_RIGHT		8
64 
65 #define BROW_FIELD_ROW			0
66 #define BROW_COLUMNALIAS_ROW	1
67 #define BROW_TABLE_ROW			2
68 #define BROW_ORDER_ROW			3
69 #define BROW_VIS_ROW			4
70 #define BROW_FUNCTION_ROW		5
71 #define BROW_CRIT1_ROW			6
72 #define BROW_CRIT2_ROW			7
73 #define BROW_CRIT3_ROW			8
74 #define BROW_CRIT4_ROW			9
75 #define BROW_CRIT5_ROW			10
76 #define BROW_CRIT6_ROW			11
77 #define BROW_ROW_CNT			12
78 
79 	//==================================================================
80 	class OQueryDesignView;
81 	class OSelectionBrowseBox : public ::svt::EditBrowseBox
82 	{
83 		friend class OQueryDesignView;
84 		::std::vector<bool> 				m_bVisibleRow;	// an Pos steht die RowId
85 		Timer								m_timerInvalidate;
86 
87 		long								m_nSeekRow;
88 		BrowserMode							m_nMode;						// Merken des BrowseModes
89 		Edit*								m_pTextCell;
90 		::svt::CheckBoxControl*				m_pVisibleCell;
91 		::svt::ComboBoxControl*				m_pFieldCell;
92 		::svt::ListBoxControl*				m_pFunctionCell;
93 		::svt::ListBoxControl*				m_pTableCell;
94 		::svt::ListBoxControl*				m_pOrderCell;
95 
96 		OTableFieldDescRef					m_pEmptyEntry;		// default entry in the list may reference more than once
97 
98 		sal_Int32							m_nMaxColumns;				// maximale Anzahl der Spalten in einem Select-Statement
99 
100 		String								m_aFunctionStrings;
101 		sal_uInt16							m_nVisibleCount;				// Anzahl der max sichtbaren Zeilen
102 		sal_Bool							m_bOrderByUnRelated;
103 		sal_Bool							m_bGroupByUnRelated;
104 		sal_Bool							m_bStopTimer;
105 		sal_Bool							m_bWasEditing;
106 		sal_Bool							m_bDisableErrorBox;
107 		sal_Bool							m_bInUndoMode;
108 
109 		DECL_LINK(OnInvalidateTimer, void*);
110 	public:							OSelectionBrowseBox( Window* pParent );
111 									~OSelectionBrowseBox();
112 
113 		void						initialize();
114 		OTableFieldDescRef			InsertField( const OJoinExchangeData& jxdSource, sal_uInt16 _nColumnPostion = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
115 		OTableFieldDescRef			InsertField( const OTableFieldDescRef& rInfo, sal_uInt16 _nColumnPostion = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
116 		void						InsertColumn( OTableFieldDescRef pEntry, sal_uInt16& _nColumnPostion );
117 		void						RemoveColumn( sal_uInt16 _nColumnId );
118 		void						DeleteFields( const String& rAliasName );
119 
120         bool                        HasFieldByAliasName(const ::rtl::OUString& rFieldName, OTableFieldDescRef& rInfo) const;
121 		// AddGroupBy:: F"ugt ein Feld mit Funktion == Grupierung. Falls das Feld schon vorhanden ist und ein Aggregate Funktion
122 		// benutzt, wird das Flag nicht gesetzt
123 		void						AddGroupBy( const OTableFieldDescRef& rInfo,sal_uInt32 _nCurrentPos);
124 		void						AddCondition( const OTableFieldDescRef& rInfo,
125 												  const String& rValue,
126 												  const sal_uInt16 nLevel,
127                                                   bool _bAddOrOnOneLine  );
128 		void						DuplicateConditionLevel( const sal_uInt16 nLevel);
129 		void						AddOrder(const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos);
130 		void						ClearAll();
131 		OTableFieldDescRef			AppendNewCol( sal_uInt16 nCnt=1 );
132 		sal_Bool					Save();
133 		OQueryDesignView*			getDesignView();
134 		OQueryDesignView*			getDesignView() const;
135 		sal_uInt16					FieldsCount();
136 
137 		void						SetColWidth(sal_uInt16 nColId, long lNewWidth);
138 									// beachtet im Gegensatz zum SetColumnWidth der Basisklasse auch eine eventuell aktive Zelle in dieser Spalte
139 
140 		String						GetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId);
141 		void						SetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId, const String& strNewText);
142 										// Zelleninhalt (als String formatiert) setzen/liefern
143 		sal_Int32					GetNoneVisibleRows() const;
144 		void						SetNoneVisbleRow(long nRows);
145 		sal_Bool					IsRowVisible(sal_uInt16 _nWhich) const;
146 		void						SetRowVisible(sal_uInt16 _nWhich, sal_Bool _bVis);
147 
148 		void						SetReadOnly(sal_Bool bRO);
149 		// calculate an optimal size. Basically, this takes into account the number of visible rows.
150 		Size						CalcOptimalSize( const Size& _rAvailable );
151 
152 		// can the current content be cut
153 		sal_Bool					isPasteAllowed();
154 		sal_Bool					isCutAllowed();
155 		sal_Bool					isCopyAllowed();
156 		void						cut();
157 		void						paste();
158 		void						copy();
159 
160 		virtual void				GetFocus();
161 		virtual void				DeactivateCell(sal_Bool bUpdate = sal_True);
ColumnMoved(sal_uInt16 nColId)162 		virtual void				ColumnMoved( sal_uInt16 nColId ) { ColumnMoved(nColId,sal_True); }
163 		void						ColumnMoved( sal_uInt16 nColId,sal_Bool _bCreateUndo);
164 
165 		void						Fill();
166 		void						PreFill();
167 
168 		/** Disables the generation of undo actions
169 		*/
EnterUndoMode()170 		inline void					EnterUndoMode() { m_bInUndoMode = sal_True; }
171 		/** Enables the generation of undo actions
172 		*/
LeaveUndoMode()173 		inline void					LeaveUndoMode() { m_bInUndoMode = sal_False; }
174 
175 		/** GetCellText returns the text at the given position
176 			@param	_nRow
177 				the number of the row
178 			@param	_nColId
179 				the ID of the column
180 			@return
181 				the text out of the cell
182 		*/
183 		virtual String				GetCellText(long _nRow, sal_uInt16 _nColId) const;
184 
185 		/** returns the description of the row.
186 			@param	_nRow
187 				The row number.
188 			@return
189 				The header text of the specified row.
190 		*/
191 		virtual ::rtl::OUString		GetRowDescription( sal_Int32 _nRow ) const;
192 
193 		/** return the name of the specified object.
194 			@param	eObjType
195 				The type to ask for
196 			@param	_nPosition
197 				The position of a tablecell (index position), header bar  colum/row cell
198 			@return
199 				The name of the specified object.
200 		*/
201 		virtual ::rtl::OUString		GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
202 
203 		// IAccessibleTableProvider
204 		/** Creates the accessible object of a data table cell.
205         @param nRow  The row index of the cell.
206         @param nColumnId  The column ID of the cell.
207         @return  The XAccessible interface of the specified cell. */
208 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 nRow, sal_uInt16 nColumnId );
209 
210 
211 	protected:
212 		virtual sal_Bool			SeekRow( long nRow );
213 
214 		virtual void				PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const;
215 		virtual void				PaintCell(OutputDevice& rDev, const Rectangle& rRect,
216 											  sal_uInt16 nColumnId ) const;
217 
218 		virtual sal_Int8			AcceptDrop( const BrowserAcceptDropEvent& rEvt );
219 		virtual sal_Int8			ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
220 		virtual void				MouseButtonDown( const BrowserMouseEvent& rEvt );
221 		virtual void				MouseButtonUp( const BrowserMouseEvent& rEvt );
222 		virtual void				KeyInput( const KeyEvent& rEvt );
223 		virtual void				Command(const CommandEvent& rEvt);
224 		virtual void				ArrangeControls(sal_uInt16& nX, sal_uInt16 nY);
225 
226 		virtual ::svt::CellController*	GetController(long nRow, sal_uInt16 nCol);
227 		virtual void				InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol);
228 		virtual void				CellModified();
229 		virtual sal_Bool			SaveModified();
230 		virtual void				Init();
231 		virtual sal_uInt32			GetTotalCellWidth(long nRow, sal_uInt16 nColId) const;
232 		virtual void				ColumnResized( sal_uInt16 nColId );
233 
234 		virtual sal_uInt32			GetTotalCellWidth(long nRow, sal_uInt16 nColId);
235 
236 		virtual sal_uInt16			GetDefaultColumnWidth(const String& rName) const;
237 		// if you want to have an own header ...
238 		virtual BrowserHeader*		imp_CreateHeaderBar(BrowseBox* pParent);
239 
240 		void						stopTimer();
241 		void						startTimer();
242 
243 	private:
244 		OTableFieldDescRef			FindFirstFreeCol(sal_uInt16& _rColumnPosition);
245 			// rCol enthaelt die Nummer (in pOTableFieldDescList) der ersten Spalte, die von sich sagt, dass sie leer ist
246 			// wenn es keine solche gibt, ist rCol undefiniert und der Rueckgabewert NULL
247 		void						CheckFreeColumns(sal_uInt16& _rColumnPosition);
248 			// testet, ob es noch freie Spalten gibt, wenn nicht, wird ein neuer Packen angefuegt
249 			// rCol enthaelt die Nummer der ersten freien Spalte (in pOTableFieldDescList)
250 
251 		void			RemoveField( sal_uInt16 nId );
252 		Rectangle		GetInvalidRect( sal_uInt16 nColId );
253 		long			GetRealRow(long nRow) const;
254 		long			GetBrowseRow(long nRowId) const;
255 		sal_Bool		GetFunctionName(sal_uInt32 _nFunctionTokenId,String& rFkt);
256 		void			appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow,sal_Bool& _bListAction);
257 		void			appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow);
258 		OTableFields&	getFields() const;
259 		void			enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl);
260 		void			setTextCellContext(const OTableFieldDescRef& _rEntry,const String& _sText,const rtl::OString& _sHelpId);
261 		void			invalidateUndoRedo();
262 		OTableFieldDescRef getEntry(OTableFields::size_type _nPos);
263 
264 		void			adjustSelectionMode( sal_Bool _bClickedOntoHeader, sal_Bool _bClickedOntoHandleCol );
265 
266 		/** save the filed change in save modified
267 			@param	_sFieldName
268 				The field name inserted by the user.
269 			@param	_pEntry
270 				The entry which will contain the nescessary entries.
271 			@param	_bListAction
272 				Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
273 			@return
274 				<TRUE/> if an error occured otherwise <FALSE/>
275 		*/
276 		sal_Bool		saveField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction);
277 
278 		/** sets the table window at the _pEntry
279 			@param	_pEntry
280 				The entry where the window should be set.
281 			@param	_sTableName
282 				The table name to search for.
283 			@return
284 				<TRUE/> if the table name was set otherwise <FALSE/>
285 		*/
286 		sal_Bool		fillEntryTable(OTableFieldDescRef& _pEntry,const ::rtl::OUString& _sTableName);
287 
288 		/** uses the parse node to fill all information into the field
289 			@param	_pColumnRef
290 				The parse node used to fill the info into the field.
291 			@param	_xMetaData
292 				Use to parse the node to a string.
293 			@param	_pEntry
294 				The entry which will contain the nescessary entries.
295 			@param	_bListAction
296 				Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
297 			@return
298 				<TRUE/> if an error occured otherwise <FALSE/>
299 		*/
300 		sal_Bool		fillColumnRef(	const ::connectivity::OSQLParseNode* _pColumnRef,
301 										const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
302 										OTableFieldDescRef& _pEntry,
303 										sal_Bool& _bListAction);
304 		sal_Bool		fillColumnRef(	const ::rtl::OUString& _sColumnName,
305 										const ::rtl::OUString& _sTableRange,
306 										const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData,
307 										OTableFieldDescRef& _pEntry,
308 										sal_Bool& _bListAction);
309 
310 
311 		/** append an undo action for the table field
312 			@param	_sOldAlias
313 				The old table alias.
314 			@param	_sAlias
315 				The new alias name.
316 			@param	_bListAction
317 				Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
318 		*/
319 		void			notifyTableFieldChanged(const String& _sOldAlias,const String& _sAlias,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
320 
321 		/** append an undo action for the function field
322 			@param	_sOldFunctionName
323 				The old value.
324 			@param	_sFunctionName
325 				The new function name.
326 			@param	_bListAction
327 				Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
328 		*/
329 		void			notifyFunctionFieldChanged(const String& _sOldFunctionName,const String& _sFunctionName,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
330 
331 		/** clears the function fields of the submitted entry if it doesn't match the SQL standard and append an undo action.
332 			E.q. AGGREGATE functions are only valid when the field name isn't an asterix
333 			@param	_sFieldName
334 				The field name.
335 			@param	_pEntry
336 				The entry to be cleared
337 			@param	_bListAction
338 				When <TRUE/> an list action will be created.
339 		*/
340 		void			clearEntryFunctionField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
341 
342 		/** remove or insert the necessary function types
343 			@param	_pEntry
344 				The currently edited entry.
345 		*/
346 		void			setFunctionCell(OTableFieldDescRef& _pEntry);
347 
348     private:
349         using ::svt::EditBrowseBox::AcceptDrop;
350         using ::svt::EditBrowseBox::ExecuteDrop;
351         using ::svt::EditBrowseBox::MouseButtonDown;
352         using ::svt::EditBrowseBox::MouseButtonUp;
353 	};
354 }
355 #endif // DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
356 
357 
358 
359