1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
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>
29 namespace connectivity
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
50 class OQueryDesignView
;
51 class OSelectionBrowseBox
: public ::svt::EditBrowseBox
53 friend class OQueryDesignView
;
54 ::std::vector
<bool> m_bVisibleRow
; // at pos we find the RowId
55 Timer m_timerInvalidate
;
58 BrowserMode m_nMode
; // remember the BrowseModes
59 VclPtr
<Edit
> m_pTextCell
;
60 VclPtr
< ::svt::CheckBoxControl
> m_pVisibleCell
;
61 VclPtr
< ::svt::ComboBoxControl
> m_pFieldCell
;
62 VclPtr
< ::svt::ListBoxControl
> m_pFunctionCell
;
63 VclPtr
< ::svt::ListBoxControl
> m_pTableCell
;
64 VclPtr
< ::svt::ListBoxControl
> m_pOrderCell
;
66 sal_Int32 m_nMaxColumns
; // maximum number of columns in a Select-Statement
68 OUString m_aFunctionStrings
;
69 sal_uInt16 m_nVisibleCount
; // maximum number of visible rows
70 sal_uInt32 m_nLastSortColumn
; // index of last (highest) sort column
71 bool m_bOrderByUnRelated
;
72 bool m_bGroupByUnRelated
;
75 bool m_bDisableErrorBox
;
78 DECL_LINK_TYPED(OnInvalidateTimer
, Timer
*, void);
80 explicit OSelectionBrowseBox( vcl::Window
* pParent
);
81 virtual ~OSelectionBrowseBox();
82 virtual void dispose() override
;
85 OTableFieldDescRef
InsertField( const OJoinExchangeData
& jxdSource
);
86 OTableFieldDescRef
InsertField( const OTableFieldDescRef
& rInfo
, sal_uInt16 _nColumnPosition
= BROWSER_INVALIDID
, bool bVis
=true, bool bActivate
=true );
87 void InsertColumn( const OTableFieldDescRef
& pEntry
, sal_uInt16
& _nColumnPosition
);
88 void RemoveColumn( sal_uInt16 _nColumnId
);
89 void DeleteFields( const OUString
& rAliasName
);
91 bool HasFieldByAliasName(const OUString
& rFieldName
, OTableFieldDescRef
& rInfo
) const;
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
);
103 OTableFieldDescRef
AppendNewCol( sal_uInt16 nCnt
=1 );
105 OQueryDesignView
* getDesignView();
106 OQueryDesignView
* getDesignView() const;
107 sal_uInt16
FieldsCount();
109 void SetColWidth(sal_uInt16 nColId
, long lNewWidth
);
110 // unlike SetColumnWidth of the base class it checks an active cell in this column
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 bool IsRowVisible(sal_uInt16 _nWhich
) const;
118 void SetRowVisible(sal_uInt16 _nWhich
, bool _bVis
);
120 void SetReadOnly(bool bRO
);
121 // calculate an optimal size. Basically, this takes into account the number of visible rows.
122 Size
CalcOptimalSize( const Size
& _rAvailable
);
124 // can the current content be cut
125 bool isPasteAllowed();
127 bool isCopyAllowed();
132 virtual void GetFocus() override
;
133 virtual void DeactivateCell(bool bUpdate
= true) override
;
134 virtual void ColumnMoved( sal_uInt16 nColId
) override
{ ColumnMoved(nColId
,true); }
135 void ColumnMoved( sal_uInt16 nColId
, bool _bCreateUndo
);
140 /** Disables the generation of undo actions
142 inline void EnterUndoMode() { m_bInUndoMode
= true; }
143 /** Enables the generation of undo actions
145 inline void LeaveUndoMode() { m_bInUndoMode
= false; }
147 /** GetCellText returns the text at the given position
149 the number of the row
153 the text out of the cell
155 virtual OUString
GetCellText(long _nRow
, sal_uInt16 _nColId
) const override
;
157 /** returns the description of the row.
161 The header text of the specified row.
163 virtual OUString
GetRowDescription( sal_Int32 _nRow
) const override
;
165 /** return the name of the specified object.
169 The position of a tablecell (index position), header bar column/row cell
171 The name of the specified object.
173 virtual OUString
GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const override
;
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 css::uno::Reference
< css::accessibility::XAccessible
> CreateAccessibleCell( sal_Int32 nRow
, sal_uInt16 nColumnId
) override
;
183 virtual bool SeekRow( long nRow
) override
;
185 virtual void PaintStatusCell(OutputDevice
& rDev
, const Rectangle
& rRect
) const override
;
186 virtual void PaintCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
187 sal_uInt16 nColumnId
) const override
;
189 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
) override
;
190 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
) override
;
191 virtual void MouseButtonDown( const BrowserMouseEvent
& rEvt
) override
;
192 virtual void MouseButtonUp( const BrowserMouseEvent
& rEvt
) override
;
193 virtual void KeyInput( const KeyEvent
& rEvt
) override
;
194 virtual void Command(const CommandEvent
& rEvt
) override
;
195 virtual void ArrangeControls(sal_uInt16
& nX
, sal_uInt16 nY
) override
;
197 virtual ::svt::CellController
* GetController(long nRow
, sal_uInt16 nCol
) override
;
198 virtual void InitController(::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
) override
;
199 virtual void CellModified() override
;
200 virtual bool SaveModified() override
;
201 virtual void Init() override
;
202 virtual void ColumnResized( sal_uInt16 nColId
) override
;
204 virtual sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
) override
;
206 // if you want to have an own header ...
207 virtual VclPtr
<BrowserHeader
> imp_CreateHeaderBar(BrowseBox
* pParent
) override
;
213 OTableFieldDescRef
FindFirstFreeCol(sal_uInt16
& _rColumnPosition
);
215 // rCol contains the Nummer (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
);
219 // check if empty columns are available, if not, a new Packen is appended
220 // rCol contains the Nummer of the first empty column (in pOTableFieldDescList)
222 void RemoveField( sal_uInt16 nId
);
223 Rectangle
GetInvalidRect( sal_uInt16 nColId
);
224 long GetRealRow(long nRow
) const;
225 long GetBrowseRow(long nRowId
) const;
226 bool GetFunctionName(sal_uInt32 _nFunctionTokenId
, OUString
& rFkt
);
227 void appendUndoAction(const OUString
& _rOldValue
,const OUString
& _rNewValue
,sal_Int32 _nRow
, bool& _bListAction
);
228 void appendUndoAction(const OUString
& _rOldValue
,const OUString
& _rNewValue
,sal_Int32 _nRow
);
229 OTableFields
& getFields() const;
230 static void enableControl(const OTableFieldDescRef
& _rEntry
,Window
* _pControl
);
231 void setTextCellContext(const OTableFieldDescRef
& _rEntry
,const OUString
& _sText
,const OString
& _sHelpId
);
232 void invalidateUndoRedo();
233 OTableFieldDescRef
getEntry(OTableFields::size_type _nPos
);
235 void adjustSelectionMode( bool _bClickedOntoHeader
, bool _bClickedOntoHandleCol
);
237 /** save the filed change in save modified
239 The field name inserted by the user.
241 The entry which will contain the necessary entries.
243 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
245 <TRUE/> if an error occurred otherwise <FALSE/>
247 bool saveField(OUString
& _sFieldName
, OTableFieldDescRef
& _pEntry
, bool& _bListAction
);
249 /** sets the table window at the _pEntry
251 The entry where the window should be set.
253 The table name to search for.
255 <TRUE/> if the table name was set otherwise <FALSE/>
257 bool fillEntryTable(OTableFieldDescRef
& _pEntry
,const OUString
& _sTableName
);
259 /** uses the parse node to fill all information into the field
261 The parse node used to fill the info into the field.
263 Use to parse the node to a string.
265 The entry which will contain the necessary entries.
267 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
269 <TRUE/> if an error occurred otherwise <FALSE/>
271 bool fillColumnRef( const ::connectivity::OSQLParseNode
* _pColumnRef
,
272 const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
273 OTableFieldDescRef
& _pEntry
,
275 bool fillColumnRef( const OUString
& _sColumnName
,
276 const OUString
& _sTableRange
,
277 const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _xMetaData
,
278 OTableFieldDescRef
& _pEntry
,
281 /** append an undo action for the table field
287 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
289 void notifyTableFieldChanged(const OUString
& _sOldAlias
,const OUString
& _sAlias
, bool& _bListAction
,sal_uInt16 _nColumnId
);
291 /** append an undo action for the function field
292 @param _sOldFunctionName
294 @param _sFunctionName
295 The new function name.
297 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
299 void notifyFunctionFieldChanged(const OUString
& _sOldFunctionName
,const OUString
& _sFunctionName
, bool& _bListAction
,sal_uInt16 _nColumnId
);
301 /** clears the function fields of the submitted entry if it doesn't match the SQL standard and append an undo action.
302 E.q. AGGREGATE functions are only valid when the field name isn't an asterisk
306 The entry to be cleared
308 When <TRUE/> an list action will be created.
310 void clearEntryFunctionField(const OUString
& _sFieldName
,OTableFieldDescRef
& _pEntry
, bool& _bListAction
,sal_uInt16 _nColumnId
);
312 /** remove or insert the necessary function types
314 The currently edited entry.
316 void setFunctionCell(OTableFieldDescRef
& _pEntry
);
319 using ::svt::EditBrowseBox::AcceptDrop
;
320 using ::svt::EditBrowseBox::ExecuteDrop
;
321 using ::svt::EditBrowseBox::MouseButtonDown
;
322 using ::svt::EditBrowseBox::MouseButtonUp
;
325 #endif // INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */