Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
20 : #define INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
21 :
22 : #include <svtools/editbrowsebox.hxx>
23 : #include "TableFieldDescription.hxx"
24 : #include "JoinExchange.hxx"
25 : #include "QEnumTypes.hxx"
26 : #include <com/sun/star/util/XNumberFormatter.hpp>
27 : #include <svtools/transfer.hxx>
28 :
29 : namespace connectivity
30 : {
31 : class OSQLParseNode;
32 : }
33 :
34 : namespace dbaui
35 : {
36 : #define BROW_FIELD_ROW 0
37 : #define BROW_COLUMNALIAS_ROW 1
38 : #define BROW_TABLE_ROW 2
39 : #define BROW_ORDER_ROW 3
40 : #define BROW_VIS_ROW 4
41 : #define BROW_FUNCTION_ROW 5
42 : #define BROW_CRIT1_ROW 6
43 : #define BROW_CRIT2_ROW 7
44 : #define BROW_CRIT3_ROW 8
45 : #define BROW_CRIT4_ROW 9
46 : #define BROW_CRIT5_ROW 10
47 : #define BROW_CRIT6_ROW 11
48 : #define BROW_ROW_CNT 12
49 :
50 : class OQueryDesignView;
51 : class OSelectionBrowseBox : public ::svt::EditBrowseBox
52 : {
53 : friend class OQueryDesignView;
54 : ::std::vector<bool> m_bVisibleRow; // at pos we find the RowId
55 : Timer m_timerInvalidate;
56 :
57 : long m_nSeekRow;
58 : BrowserMode m_nMode; // remember the BrowseModes
59 : Edit* m_pTextCell;
60 : ::svt::CheckBoxControl* m_pVisibleCell;
61 : ::svt::ComboBoxControl* m_pFieldCell;
62 : ::svt::ListBoxControl* m_pFunctionCell;
63 : ::svt::ListBoxControl* m_pTableCell;
64 : ::svt::ListBoxControl* m_pOrderCell;
65 :
66 : OTableFieldDescRef m_pEmptyEntry; // default entry in the list may reference more than once
67 :
68 : sal_Int32 m_nMaxColumns; // maximum number of columns in a Select-Statement
69 :
70 : OUString m_aFunctionStrings;
71 : sal_uInt16 m_nVisibleCount; // maximum number of visible rows
72 : sal_uInt32 m_nLastSortColumn; // index of last (highest) sort column
73 : sal_Bool m_bOrderByUnRelated;
74 : sal_Bool m_bGroupByUnRelated;
75 : sal_Bool m_bStopTimer;
76 : sal_Bool m_bWasEditing;
77 : sal_Bool m_bDisableErrorBox;
78 : sal_Bool m_bInUndoMode;
79 :
80 : DECL_LINK(OnInvalidateTimer, void*);
81 : public: OSelectionBrowseBox( Window* pParent );
82 : virtual ~OSelectionBrowseBox();
83 :
84 : void initialize();
85 : OTableFieldDescRef InsertField( const OJoinExchangeData& jxdSource, sal_uInt16 _nColumnPosition = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
86 : OTableFieldDescRef InsertField( const OTableFieldDescRef& rInfo, sal_uInt16 _nColumnPosition = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
87 : void InsertColumn( OTableFieldDescRef pEntry, sal_uInt16& _nColumnPosition );
88 : void RemoveColumn( sal_uInt16 _nColumnId );
89 : void DeleteFields( const OUString& rAliasName );
90 :
91 : bool HasFieldByAliasName(const OUString& rFieldName, OTableFieldDescRef& rInfo) const;
92 :
93 : // AddGroupBy:: inserts a field with function == grouping. If the fields already exists and uses an aggregate function,
94 : // the flag is not set
95 : void AddGroupBy( const OTableFieldDescRef& rInfo,sal_uInt32 _nCurrentPos);
96 : void AddCondition( const OTableFieldDescRef& rInfo,
97 : const OUString& rValue,
98 : const sal_uInt16 nLevel,
99 : bool _bAddOrOnOneLine );
100 : void DuplicateConditionLevel( const sal_uInt16 nLevel);
101 : void AddOrder(const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos);
102 : void ClearAll();
103 : OTableFieldDescRef AppendNewCol( sal_uInt16 nCnt=1 );
104 : sal_Bool Save();
105 : OQueryDesignView* getDesignView();
106 : OQueryDesignView* getDesignView() const;
107 : sal_uInt16 FieldsCount();
108 :
109 : void SetColWidth(sal_uInt16 nColId, long lNewWidth);
110 : // unlike SetColumnWidth of the base class it checks an active cell in this column
111 :
112 : OUString GetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId);
113 : void SetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId, const OUString& strNewText);
114 : // cell content (formatted as string) set/return
115 : sal_Int32 GetNoneVisibleRows() const;
116 : void SetNoneVisbleRow(long nRows);
117 : sal_Bool IsRowVisible(sal_uInt16 _nWhich) const;
118 : void SetRowVisible(sal_uInt16 _nWhich, sal_Bool _bVis);
119 :
120 : void SetReadOnly(sal_Bool bRO);
121 : // calculate an optimal size. Basically, this takes into account the number of visible rows.
122 : Size CalcOptimalSize( const Size& _rAvailable );
123 :
124 : // can the current content be cut
125 : sal_Bool isPasteAllowed();
126 : sal_Bool isCutAllowed();
127 : sal_Bool isCopyAllowed();
128 : void cut();
129 : void paste();
130 : void copy();
131 :
132 : virtual void GetFocus() SAL_OVERRIDE;
133 : virtual void DeactivateCell(bool bUpdate = true) SAL_OVERRIDE;
134 0 : virtual void ColumnMoved( sal_uInt16 nColId ) SAL_OVERRIDE { ColumnMoved(nColId,sal_True); }
135 : void ColumnMoved( sal_uInt16 nColId,sal_Bool _bCreateUndo);
136 :
137 : void Fill();
138 : void PreFill();
139 :
140 : /** Disables the generation of undo actions
141 : */
142 0 : inline void EnterUndoMode() { m_bInUndoMode = sal_True; }
143 : /** Enables the generation of undo actions
144 : */
145 0 : inline void LeaveUndoMode() { m_bInUndoMode = sal_False; }
146 :
147 : /** GetCellText returns the text at the given position
148 : @param _nRow
149 : the number of the row
150 : @param _nColId
151 : the ID of the column
152 : @return
153 : the text out of the cell
154 : */
155 : virtual OUString GetCellText(long _nRow, sal_uInt16 _nColId) const SAL_OVERRIDE;
156 :
157 : /** returns the description of the row.
158 : @param _nRow
159 : The row number.
160 : @return
161 : The header text of the specified row.
162 : */
163 : virtual OUString GetRowDescription( sal_Int32 _nRow ) const SAL_OVERRIDE;
164 :
165 : /** return the name of the specified object.
166 : @param eObjType
167 : The type to ask for
168 : @param _nPosition
169 : The position of a tablecell (index position), header bar column/row cell
170 : @return
171 : The name of the specified object.
172 : */
173 : virtual OUString GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const SAL_OVERRIDE;
174 :
175 : // IAccessibleTableProvider
176 : /** Creates the accessible object of a data table cell.
177 : @param nRow The row index of the cell.
178 : @param nColumnId The column ID of the cell.
179 : @return The XAccessible interface of the specified cell. */
180 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 nRow, sal_uInt16 nColumnId ) SAL_OVERRIDE;
181 :
182 : protected:
183 : virtual bool SeekRow( long nRow ) SAL_OVERRIDE;
184 :
185 : virtual void PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const SAL_OVERRIDE;
186 : virtual void PaintCell(OutputDevice& rDev, const Rectangle& rRect,
187 : sal_uInt16 nColumnId ) const SAL_OVERRIDE;
188 :
189 : virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt ) SAL_OVERRIDE;
190 : virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) SAL_OVERRIDE;
191 : virtual void MouseButtonDown( const BrowserMouseEvent& rEvt ) SAL_OVERRIDE;
192 : virtual void MouseButtonUp( const BrowserMouseEvent& rEvt ) SAL_OVERRIDE;
193 : virtual void KeyInput( const KeyEvent& rEvt ) SAL_OVERRIDE;
194 : virtual void Command(const CommandEvent& rEvt) SAL_OVERRIDE;
195 : virtual void ArrangeControls(sal_uInt16& nX, sal_uInt16 nY) SAL_OVERRIDE;
196 :
197 : virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
198 : virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol) SAL_OVERRIDE;
199 : virtual void CellModified() SAL_OVERRIDE;
200 : virtual bool SaveModified() SAL_OVERRIDE;
201 : virtual void Init() SAL_OVERRIDE;
202 : virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId) const;
203 : virtual void ColumnResized( sal_uInt16 nColId ) SAL_OVERRIDE;
204 :
205 : virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId) SAL_OVERRIDE;
206 :
207 : virtual sal_uInt16 GetDefaultColumnWidth(const OUString& rName) const;
208 : // if you want to have an own header ...
209 : virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent) SAL_OVERRIDE;
210 :
211 : void stopTimer();
212 : void startTimer();
213 :
214 : private:
215 : OTableFieldDescRef FindFirstFreeCol(sal_uInt16& _rColumnPosition);
216 :
217 : // rCol contains the Nummer (in pOTableFieldDescList) of the first column, which itself tells it is empty
218 : // if there are none, rCol is undefined and the returnvalue NULL
219 : void CheckFreeColumns(sal_uInt16& _rColumnPosition);
220 :
221 : // check if empty columns are available, if not, a new Packen is appended
222 : // rCol contains the Nummer of the first empty column (in pOTableFieldDescList)
223 :
224 : void RemoveField( sal_uInt16 nId );
225 : Rectangle GetInvalidRect( sal_uInt16 nColId );
226 : long GetRealRow(long nRow) const;
227 : long GetBrowseRow(long nRowId) const;
228 : sal_Bool GetFunctionName(sal_uInt32 _nFunctionTokenId, OUString& rFkt);
229 : void appendUndoAction(const OUString& _rOldValue,const OUString& _rNewValue,sal_Int32 _nRow,sal_Bool& _bListAction);
230 : void appendUndoAction(const OUString& _rOldValue,const OUString& _rNewValue,sal_Int32 _nRow);
231 : OTableFields& getFields() const;
232 : void enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl);
233 : void setTextCellContext(const OTableFieldDescRef& _rEntry,const OUString& _sText,const OString& _sHelpId);
234 : void invalidateUndoRedo();
235 : OTableFieldDescRef getEntry(OTableFields::size_type _nPos);
236 :
237 : void adjustSelectionMode( sal_Bool _bClickedOntoHeader, sal_Bool _bClickedOntoHandleCol );
238 :
239 : /** save the filed change in save modified
240 : @param _sFieldName
241 : The field name inserted by the user.
242 : @param _pEntry
243 : The entry which will contain the necessary entries.
244 : @param _bListAction
245 : Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
246 : @return
247 : <TRUE/> if an error occurred otherwise <FALSE/>
248 : */
249 : sal_Bool saveField(OUString& _sFieldName, OTableFieldDescRef& _pEntry, sal_Bool& _bListAction);
250 :
251 : /** sets the table window at the _pEntry
252 : @param _pEntry
253 : The entry where the window should be set.
254 : @param _sTableName
255 : The table name to search for.
256 : @return
257 : <TRUE/> if the table name was set otherwise <FALSE/>
258 : */
259 : sal_Bool fillEntryTable(OTableFieldDescRef& _pEntry,const OUString& _sTableName);
260 :
261 : /** uses the parse node to fill all information into the field
262 : @param _pColumnRef
263 : The parse node used to fill the info into the field.
264 : @param _xMetaData
265 : Use to parse the node to a string.
266 : @param _pEntry
267 : The entry which will contain the necessary entries.
268 : @param _bListAction
269 : Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
270 : @return
271 : <TRUE/> if an error occurred otherwise <FALSE/>
272 : */
273 : sal_Bool fillColumnRef( const ::connectivity::OSQLParseNode* _pColumnRef,
274 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
275 : OTableFieldDescRef& _pEntry,
276 : sal_Bool& _bListAction);
277 : sal_Bool fillColumnRef( const OUString& _sColumnName,
278 : const OUString& _sTableRange,
279 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData,
280 : OTableFieldDescRef& _pEntry,
281 : sal_Bool& _bListAction);
282 :
283 : /** append an undo action for the table field
284 : @param _sOldAlias
285 : The old table alias.
286 : @param _sAlias
287 : The new alias name.
288 : @param _bListAction
289 : Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
290 : */
291 : void notifyTableFieldChanged(const OUString& _sOldAlias,const OUString& _sAlias,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
292 :
293 : /** append an undo action for the function field
294 : @param _sOldFunctionName
295 : The old value.
296 : @param _sFunctionName
297 : The new function name.
298 : @param _bListAction
299 : Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
300 : */
301 : void notifyFunctionFieldChanged(const OUString& _sOldFunctionName,const OUString& _sFunctionName,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
302 :
303 : /** clears the function fields of the submitted entry if it doesn't match the SQL standard and append an undo action.
304 : E.q. AGGREGATE functions are only valid when the field name isn't an asterisk
305 : @param _sFieldName
306 : The field name.
307 : @param _pEntry
308 : The entry to be cleared
309 : @param _bListAction
310 : When <TRUE/> an list action will be created.
311 : */
312 : void clearEntryFunctionField(const OUString& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction,sal_uInt16 _nColumnId);
313 :
314 : /** remove or insert the necessary function types
315 : @param _pEntry
316 : The currently edited entry.
317 : */
318 : void setFunctionCell(OTableFieldDescRef& _pEntry);
319 :
320 : private:
321 : using ::svt::EditBrowseBox::AcceptDrop;
322 : using ::svt::EditBrowseBox::ExecuteDrop;
323 : using ::svt::EditBrowseBox::MouseButtonDown;
324 : using ::svt::EditBrowseBox::MouseButtonUp;
325 : };
326 : }
327 : #endif // INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
328 :
329 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|