cid#1640468 Dereference after null check
[LibreOffice.git] / dbaccess / source / ui / querydesign / SelectionBrowseBox.hxx
blobd5e11c03e33257ebb9d70f1548fe5bf02212d6c9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <sal/config.h>
23 #include <string_view>
25 #include <svtools/editbrowsebox.hxx>
26 #include <TableFieldDescription.hxx>
27 #include <TableWindowListBox.hxx>
28 #include <QEnumTypes.hxx>
29 #include <com/sun/star/sdbc/XConnection.hpp>
31 namespace connectivity
33 class OSQLParseNode;
36 namespace dbaui
38 #define BROW_FIELD_ROW 0
39 #define BROW_COLUMNALIAS_ROW 1
40 #define BROW_TABLE_ROW 2
41 #define BROW_ORDER_ROW 3
42 #define BROW_VIS_ROW 4
43 #define BROW_FUNCTION_ROW 5
44 #define BROW_CRIT1_ROW 6
45 #define BROW_CRIT2_ROW 7
46 #define BROW_CRIT3_ROW 8
47 #define BROW_CRIT4_ROW 9
48 #define BROW_CRIT5_ROW 10
49 #define BROW_CRIT6_ROW 11
50 #define BROW_ROW_CNT 12
52 class OQueryDesignView;
53 class OSelectionBrowseBox final : public ::svt::EditBrowseBox
55 friend class OQueryDesignView;
56 std::vector<bool> m_bVisibleRow; // at pos we find the RowId
57 Timer m_timerInvalidate;
59 sal_Int32 m_nSeekRow;
60 BrowserMode m_nMode; // remember the BrowseModes
61 VclPtr< ::svt::EditControl> m_pTextCell;
62 VclPtr< ::svt::CheckBoxControl> m_pVisibleCell;
63 VclPtr< ::svt::ComboBoxControl> m_pFieldCell;
64 VclPtr< ::svt::ListBoxControl> m_pFunctionCell;
65 VclPtr< ::svt::ListBoxControl> m_pTableCell;
66 VclPtr< ::svt::ListBoxControl> m_pOrderCell;
68 sal_Int32 m_nMaxColumns; // maximum number of columns in a Select-Statement
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 bool m_bOrderByUnRelated;
74 bool m_bGroupByUnRelated;
75 bool m_bStopTimer;
76 bool m_bWasEditing;
77 bool m_bDisableErrorBox;
78 bool m_bInUndoMode;
80 DECL_LINK(OnInvalidateTimer, Timer*, void);
81 public:
82 explicit OSelectionBrowseBox( vcl::Window* pParent );
83 virtual ~OSelectionBrowseBox() override;
84 virtual void dispose() override;
86 void initialize();
87 OTableFieldDescRef InsertField( const OJoinExchangeData& jxdSource );
88 OTableFieldDescRef InsertField( const OTableFieldDescRef& rInfo, sal_uInt16 _nColumnPosition = BROWSER_INVALIDID, bool bVis=true, bool bActivate=true );
89 void InsertColumn( const OTableFieldDescRef& pEntry, sal_uInt16& _nColumnPosition );
90 void RemoveColumn( sal_uInt16 _nColumnId );
91 void DeleteFields( const OUString& rAliasName );
93 bool HasFieldByAliasName(std::u16string_view rFieldName, OTableFieldDescRef const & rInfo) const;
95 // AddGroupBy:: inserts a field with function == grouping. If the fields already exists and uses an aggregate function,
96 // the flag is not set
97 void AddGroupBy( const OTableFieldDescRef& rInfo );
98 void AddCondition( const OTableFieldDescRef& rInfo,
99 const OUString& rValue,
100 const sal_uInt16 nLevel,
101 bool _bAddOrOnOneLine );
102 void DuplicateConditionLevel( const sal_uInt16 nLevel);
103 void AddOrder(const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos);
104 void ClearAll();
105 OTableFieldDescRef const & AppendNewCol( sal_uInt16 nCnt=1 );
106 bool Save();
107 OQueryDesignView* getDesignView();
108 OQueryDesignView* getDesignView() const;
109 sal_uInt16 FieldsCount();
111 void SetColWidth(sal_uInt16 nColId, tools::Long lNewWidth);
112 // unlike SetColumnWidth of the base class it checks an active cell in this column
114 OUString GetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId);
115 void SetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId, const OUString& strNewText);
116 // cell content (formatted as string) set/return
117 sal_Int32 GetNoneVisibleRows() const;
118 void SetNoneVisibleRow(sal_Int32 nRows);
119 bool IsRowVisible(sal_uInt16 _nWhich) const;
120 void SetRowVisible(sal_uInt16 _nWhich, bool _bVis);
122 void SetReadOnly(bool bRO);
123 // calculate an optimal size. Basically, this takes into account the number of visible rows.
124 Size CalcOptimalSize( const Size& _rAvailable );
126 // can the current content be cut
127 bool isPasteAllowed() const;
128 bool isCutAllowed() const;
129 bool isCopyAllowed() const;
130 void cut();
131 void paste();
132 void copy();
134 virtual void GetFocus() override;
135 virtual void DeactivateCell(bool bUpdate = true) override;
136 virtual void ColumnMoved( sal_uInt16 nColId ) override { ColumnMoved(nColId,true); }
137 void ColumnMoved( sal_uInt16 nColId, bool _bCreateUndo);
139 void Fill();
140 void PreFill();
142 /** Disables the generation of undo actions
144 void EnterUndoMode() { m_bInUndoMode = true; }
145 /** Enables the generation of undo actions
147 void LeaveUndoMode() { m_bInUndoMode = false; }
149 /** GetCellText returns the text at the given position
150 @param _nRow
151 the number of the row
152 @param _nColId
153 the ID of the column
154 @return
155 the text out of the cell
157 virtual OUString GetCellText(sal_Int32 _nRow, sal_uInt16 _nColId) const override;
159 /** returns the description of the row.
160 @param _nRow
161 The row number.
162 @return
163 The header text of the specified row.
165 virtual OUString GetRowDescription( sal_Int32 _nRow ) const override;
167 /** return the name of the specified object.
168 @param eObjType
169 The type to ask for
170 @param _nPosition
171 The position of a tablecell (index position), header bar column/row cell
172 @return
173 The name of the specified object.
175 virtual OUString GetAccessibleObjectName( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const override;
177 // IAccessibleTableProvider
178 /** Creates the accessible object of a data table cell.
179 @param nRow The row index of the cell.
180 @param nColumnId The column ID of the cell.
181 @return The XAccessible interface of the specified cell. */
182 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 nRow, sal_uInt16 nColumnId ) override;
184 private:
185 virtual bool SeekRow( sal_Int32 nRow ) override;
187 virtual void PaintStatusCell(OutputDevice& rDev, const tools::Rectangle& rRect) const override;
188 virtual void PaintCell(OutputDevice& rDev, const tools::Rectangle& rRect,
189 sal_uInt16 nColumnId ) const override;
191 virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt ) override;
192 virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) override;
193 virtual void MouseButtonDown( const BrowserMouseEvent& rEvt ) override;
194 virtual void MouseButtonUp( const BrowserMouseEvent& rEvt ) override;
195 virtual void KeyInput( const KeyEvent& rEvt ) override;
196 virtual void Command(const CommandEvent& rEvt) override;
198 virtual ::svt::CellController* GetController(sal_Int32 nRow, sal_uInt16 nCol) override;
199 virtual void InitController(::svt::CellControllerRef& rController, sal_Int32 nRow, sal_uInt16 nCol) override;
200 virtual void CellModified() override;
201 virtual bool SaveModified() override;
202 virtual void Init() override;
203 virtual void ColumnResized( sal_uInt16 nColId ) override;
205 virtual sal_uInt32 GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId) override;
207 // if you want to have an own header ...
208 virtual VclPtr<BrowserHeader> imp_CreateHeaderBar(BrowseBox* pParent) override;
210 void stopTimer();
211 void startTimer();
213 OTableFieldDescRef FindFirstFreeCol(sal_uInt16& _rColumnPosition);
215 // rCol contains the number (in pOTableFieldDescList) of the first column, which itself tells it is empty
216 // if there are none, rCol is undefined and the returnvalue NULL
217 void CheckFreeColumns(sal_uInt16& _rColumnPosition);
218 // checks if empty columns are available, if not, a new pack is appended
219 // rCol contains the number of the first empty column (in pOTableFieldDescList)
221 void RemoveField( sal_uInt16 nId );
222 tools::Rectangle GetInvalidRect( sal_uInt16 nColId );
223 sal_Int32 GetRealRow(sal_Int32 nRow) const;
224 sal_Int32 GetBrowseRow(sal_Int32 nRowId) const;
225 bool GetFunctionName(sal_uInt32 _nFunctionTokenId, OUString& rFkt);
226 void appendUndoAction(const OUString& _rOldValue,std::u16string_view _rNewValue,sal_Int32 _nRow, bool& _bListAction);
227 void appendUndoAction(const OUString& _rOldValue,std::u16string_view _rNewValue,sal_Int32 _nRow);
228 OTableFields& getFields() const;
229 static void enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl);
230 void setTextCellContext(const OTableFieldDescRef& _rEntry,const OUString& _sText,const OUString& _sHelpId);
231 void invalidateUndoRedo();
232 OTableFieldDescRef getEntry(OTableFields::size_type _nPos);
234 void adjustSelectionMode( bool _bClickedOntoHeader, bool _bClickedOntoHandleCol );
236 /** save the field change in save modified
237 @param _sFieldName
238 The field name inserted by the user.
239 @param _pEntry
240 The entry which will contain the necessary entries.
241 @param _bListAction
242 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
243 @return
244 <TRUE/> if an error occurred otherwise <FALSE/>
246 bool saveField(OUString& _sFieldName, OTableFieldDescRef const & _pEntry, bool& _bListAction);
248 /** sets the table window at the _pEntry
249 @param _pEntry
250 The entry where the window should be set.
251 @param _sTableName
252 The table name to search for.
253 @return
254 <TRUE/> if the table name was set otherwise <FALSE/>
256 bool fillEntryTable(OTableFieldDescRef const & _pEntry,const OUString& _sTableName);
258 /** uses the parse node to fill all information into the field
259 @param _pColumnRef
260 The parse node used to fill the info into the field.
261 @param _xMetaData
262 Use to parse the node to a string.
263 @param _pEntry
264 The entry which will contain the necessary entries.
265 @param _bListAction
266 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
267 @return
268 <TRUE/> if an error occurred otherwise <FALSE/>
270 bool fillColumnRef( const ::connectivity::OSQLParseNode* _pColumnRef,
271 const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,
272 OTableFieldDescRef const & _pEntry,
273 bool& _bListAction);
274 bool fillColumnRef( const OUString& _sColumnName,
275 std::u16string_view _sTableRange,
276 const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData,
277 OTableFieldDescRef const & _pEntry,
278 bool& _bListAction);
280 /** append an undo action for the table field
281 @param _sOldAlias
282 The old table alias.
283 @param _sAlias
284 The new alias name.
285 @param _bListAction
286 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
288 void notifyTableFieldChanged(const OUString& _sOldAlias,std::u16string_view _sAlias, bool& _bListAction,sal_uInt16 _nColumnId);
290 /** append an undo action for the function field
291 @param _sOldFunctionName
292 The old value.
293 @param _sFunctionName
294 The new function name.
295 @param _bListAction
296 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
298 void notifyFunctionFieldChanged(const OUString& _sOldFunctionName,std::u16string_view _sFunctionName, bool& _bListAction,sal_uInt16 _nColumnId);
300 /** clears the function fields of the submitted entry if it doesn't match the SQL standard and append an undo action.
301 E.q. AGGREGATE functions are only valid when the field name isn't an asterisk
302 @param _sFieldName
303 The field name.
304 @param _pEntry
305 The entry to be cleared
306 @param _bListAction
307 When <TRUE/> a list action will be created.
309 void clearEntryFunctionField(std::u16string_view _sFieldName,OTableFieldDescRef const & _pEntry, bool& _bListAction,sal_uInt16 _nColumnId);
311 /** remove or insert the necessary function types
312 @param _pEntry
313 The currently edited entry.
315 void setFunctionCell(OTableFieldDescRef const & _pEntry);
317 using ::svt::EditBrowseBox::AcceptDrop;
318 using ::svt::EditBrowseBox::ExecuteDrop;
319 using ::svt::EditBrowseBox::MouseButtonDown;
320 using ::svt::EditBrowseBox::MouseButtonUp;
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */