LibreOffice Module dbaccess (master) 1
SelectionBrowseBox.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <sal/config.h>
22
23#include <string_view>
24
28#include <QEnumTypes.hxx>
29#include <com/sun/star/sdbc/XConnection.hpp>
30
31namespace connectivity
32{
33 class OSQLParseNode;
34}
35
36namespace dbaui
37{
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
51
52 class OQueryDesignView;
54 {
55 friend class OQueryDesignView;
56 std::vector<bool> m_bVisibleRow; // at pos we find the RowId
58
59 sal_Int32 m_nSeekRow;
60 BrowserMode m_nMode; // remember the BrowseModes
67
68 sal_Int32 m_nMaxColumns; // maximum number of columns in a Select-Statement
69
71 sal_uInt16 m_nVisibleCount; // maximum number of visible rows
72 sal_uInt32 m_nLastSortColumn; // index of last (highest) sort column
79
80 DECL_LINK(OnInvalidateTimer, Timer*, void);
81 public:
82 explicit OSelectionBrowseBox( vcl::Window* pParent );
83 virtual ~OSelectionBrowseBox() override;
84 virtual void dispose() override;
85
86 void initialize();
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 );
92
93 bool HasFieldByAliasName(std::u16string_view rFieldName, OTableFieldDescRef const & rInfo) const;
94
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();
109 sal_uInt16 FieldsCount();
110
111 void SetColWidth(sal_uInt16 nColId, tools::Long lNewWidth);
112 // unlike SetColumnWidth of the base class it checks an active cell in this column
113
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);
121
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 );
125
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();
133
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);
138
139 void Fill();
140 void PreFill();
141
144 void EnterUndoMode() { m_bInUndoMode = true; }
147 void LeaveUndoMode() { m_bInUndoMode = false; }
148
157 virtual OUString GetCellText(sal_Int32 _nRow, sal_uInt16 _nColId) const override;
158
165 virtual OUString GetRowDescription( sal_Int32 _nRow ) const override;
166
175 virtual OUString GetAccessibleObjectName( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const override;
176
177 // IAccessibleTableProvider
182 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 nRow, sal_uInt16 nColumnId ) override;
183
184 private:
185 virtual bool SeekRow( sal_Int32 nRow ) override;
186
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;
190
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;
197
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;
204
205 virtual sal_uInt32 GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId) override;
206
207 // if you want to have an own header ...
208 virtual VclPtr<BrowserHeader> imp_CreateHeaderBar(BrowseBox* pParent) override;
209
210 void stopTimer();
211 void startTimer();
212
213 OTableFieldDescRef FindFirstFreeCol(sal_uInt16& _rColumnPosition);
214
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)
220
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);
233
234 void adjustSelectionMode( bool _bClickedOntoHeader, bool _bClickedOntoHandleCol );
235
246 bool saveField(OUString& _sFieldName, OTableFieldDescRef const & _pEntry, bool& _bListAction);
247
256 bool fillEntryTable(OTableFieldDescRef const & _pEntry,const OUString& _sTableName);
257
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);
279
288 void notifyTableFieldChanged(const OUString& _sOldAlias,std::u16string_view _sAlias, bool& _bListAction,sal_uInt16 _nColumnId);
289
298 void notifyFunctionFieldChanged(const OUString& _sOldFunctionName,std::u16string_view _sFunctionName, bool& _bListAction,sal_uInt16 _nColumnId);
299
309 void clearEntryFunctionField(std::u16string_view _sFieldName,OTableFieldDescRef const & _pEntry, bool& _bListAction,sal_uInt16 _nColumnId);
310
315 void setFunctionCell(OTableFieldDescRef const & _pEntry);
316
317 using ::svt::EditBrowseBox::AcceptDrop;
318 using ::svt::EditBrowseBox::ExecuteDrop;
319 using ::svt::EditBrowseBox::MouseButtonDown;
320 using ::svt::EditBrowseBox::MouseButtonUp;
321 };
322}
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AccessibleBrowseBoxObjType
BrowserMode
bool saveField(OUString &_sFieldName, OTableFieldDescRef const &_pEntry, bool &_bListAction)
save the field change in save modified
sal_Int32 GetBrowseRow(sal_Int32 nRowId) const
tools::Rectangle GetInvalidRect(sal_uInt16 nColId)
void SetColWidth(sal_uInt16 nColId, tools::Long lNewWidth)
virtual VclPtr< BrowserHeader > imp_CreateHeaderBar(BrowseBox *pParent) override
OTableFieldDescRef InsertField(const OJoinExchangeData &jxdSource)
virtual ::svt::CellController * GetController(sal_Int32 nRow, sal_uInt16 nCol) override
virtual void CellModified() override
void SetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId, const OUString &strNewText)
void RemoveColumn(sal_uInt16 _nColumnId)
OTableFieldDescRef FindFirstFreeCol(sal_uInt16 &_rColumnPosition)
virtual OUString GetCellText(sal_Int32 _nRow, sal_uInt16 _nColId) const override
GetCellText returns the text at the given position.
void AddCondition(const OTableFieldDescRef &rInfo, const OUString &rValue, const sal_uInt16 nLevel, bool _bAddOrOnOneLine)
void AddGroupBy(const OTableFieldDescRef &rInfo)
virtual OUString GetAccessibleObjectName(AccessibleBrowseBoxObjType eObjType, sal_Int32 _nPosition=-1) const override
return the name of the specified object.
OQueryDesignView * getDesignView()
virtual sal_uInt32 GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId) override
void DuplicateConditionLevel(const sal_uInt16 nLevel)
void CheckFreeColumns(sal_uInt16 &_rColumnPosition)
bool fillColumnRef(const ::connectivity::OSQLParseNode *_pColumnRef, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, OTableFieldDescRef const &_pEntry, bool &_bListAction)
uses the parse node to fill all information into the field
virtual void Command(const CommandEvent &rEvt) override
VclPtr< ::svt::CheckBoxControl > m_pVisibleCell
bool GetFunctionName(sal_uInt32 _nFunctionTokenId, OUString &rFkt)
void DeleteFields(const OUString &rAliasName)
void appendUndoAction(const OUString &_rOldValue, std::u16string_view _rNewValue, sal_Int32 _nRow, bool &_bListAction)
void EnterUndoMode()
Disables the generation of undo actions.
virtual void KeyInput(const KeyEvent &rEvt) override
OTableFields & getFields() const
virtual void GetFocus() override
void InsertColumn(const OTableFieldDescRef &pEntry, sal_uInt16 &_nColumnPosition)
virtual void ColumnResized(sal_uInt16 nColId) override
void setFunctionCell(OTableFieldDescRef const &_pEntry)
remove or insert the necessary function types
VclPtr< ::svt::ListBoxControl > m_pTableCell
virtual bool SeekRow(sal_Int32 nRow) override
VclPtr< ::svt::ComboBoxControl > m_pFieldCell
bool HasFieldByAliasName(std::u16string_view rFieldName, OTableFieldDescRef const &rInfo) const
static void enableControl(const OTableFieldDescRef &_rEntry, Window *_pControl)
void setTextCellContext(const OTableFieldDescRef &_rEntry, const OUString &_sText, const OUString &_sHelpId)
virtual void MouseButtonUp(const BrowserMouseEvent &rEvt) override
virtual sal_Int8 AcceptDrop(const BrowserAcceptDropEvent &rEvt) override
DECL_LINK(OnInvalidateTimer, Timer *, void)
void LeaveUndoMode()
Enables the generation of undo actions.
virtual void dispose() override
virtual void PaintStatusCell(OutputDevice &rDev, const tools::Rectangle &rRect) const override
OUString GetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId)
void notifyTableFieldChanged(const OUString &_sOldAlias, std::u16string_view _sAlias, bool &_bListAction, sal_uInt16 _nColumnId)
append an undo action for the table field
void SetNoneVisibleRow(sal_Int32 nRows)
OTableFieldDescRef InsertField(const OTableFieldDescRef &rInfo, sal_uInt16 _nColumnPosition=BROWSER_INVALIDID, bool bVis=true, bool bActivate=true)
VclPtr< ::svt::ListBoxControl > m_pFunctionCell
OTableFieldDescRef const & AppendNewCol(sal_uInt16 nCnt=1)
std::vector< bool > m_bVisibleRow
VclPtr< ::svt::ListBoxControl > m_pOrderCell
OSelectionBrowseBox(vcl::Window *pParent)
virtual void InitController(::svt::CellControllerRef &rController, sal_Int32 nRow, sal_uInt16 nCol) override
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCell(sal_Int32 nRow, sal_uInt16 nColumnId) override
Creates the accessible object of a data table cell.
virtual sal_Int8 ExecuteDrop(const BrowserExecuteDropEvent &rEvt) override
virtual bool SaveModified() override
bool IsRowVisible(sal_uInt16 _nWhich) const
void adjustSelectionMode(bool _bClickedOntoHeader, bool _bClickedOntoHandleCol)
Size CalcOptimalSize(const Size &_rAvailable)
void SetRowVisible(sal_uInt16 _nWhich, bool _bVis)
VclPtr< ::svt::EditControl > m_pTextCell
void AddOrder(const OTableFieldDescRef &rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos)
sal_Int32 GetRealRow(sal_Int32 nRow) const
virtual ~OSelectionBrowseBox() override
virtual void ColumnMoved(sal_uInt16 nColId) override
void RemoveField(sal_uInt16 nId)
virtual void MouseButtonDown(const BrowserMouseEvent &rEvt) override
void notifyFunctionFieldChanged(const OUString &_sOldFunctionName, std::u16string_view _sFunctionName, bool &_bListAction, sal_uInt16 _nColumnId)
append an undo action for the function field
bool fillEntryTable(OTableFieldDescRef const &_pEntry, const OUString &_sTableName)
sets the table window at the _pEntry
virtual OUString GetRowDescription(sal_Int32 _nRow) const override
returns the description of the row.
virtual void Init() override
bool fillColumnRef(const OUString &_sColumnName, std::u16string_view _sTableRange, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_xMetaData, OTableFieldDescRef const &_pEntry, bool &_bListAction)
virtual void DeactivateCell(bool bUpdate=true) override
void clearEntryFunctionField(std::u16string_view _sFieldName, OTableFieldDescRef const &_pEntry, bool &_bListAction, sal_uInt16 _nColumnId)
clears the function fields of the submitted entry if it doesn't match the SQL standard and append an ...
virtual void PaintCell(OutputDevice &rDev, const tools::Rectangle &rRect, sal_uInt16 nColumnId) const override
OTableFieldDescRef getEntry(OTableFields::size_type _nPos)
std::vector< OTableFieldDescRef > OTableFields
long Long
signed char sal_Int8