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 OTableFieldDescRef m_pEmptyEntry
; // default entry in the list may reference more than once
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
;
77 bool m_bDisableErrorBox
;
80 DECL_LINK_TYPED(OnInvalidateTimer
, Timer
*, void);
81 public: OSelectionBrowseBox( vcl::Window
* pParent
);
82 virtual ~OSelectionBrowseBox();
83 virtual void dispose() SAL_OVERRIDE
;
86 OTableFieldDescRef
InsertField( const OJoinExchangeData
& jxdSource
, sal_uInt16 _nColumnPosition
= BROWSER_INVALIDID
, bool bVis
=true, bool bActivate
=true );
87 OTableFieldDescRef
InsertField( const OTableFieldDescRef
& rInfo
, sal_uInt16 _nColumnPosition
= BROWSER_INVALIDID
, bool bVis
=true, bool bActivate
=true );
88 void InsertColumn( OTableFieldDescRef pEntry
, sal_uInt16
& _nColumnPosition
);
89 void RemoveColumn( sal_uInt16 _nColumnId
);
90 void DeleteFields( const OUString
& rAliasName
);
92 bool HasFieldByAliasName(const OUString
& rFieldName
, OTableFieldDescRef
& rInfo
) const;
94 // AddGroupBy:: inserts a field with function == grouping. If the fields already exists and uses an aggregate function,
95 // the flag is not set
96 void AddGroupBy( const OTableFieldDescRef
& rInfo
,sal_uInt32 _nCurrentPos
);
97 void AddCondition( const OTableFieldDescRef
& rInfo
,
98 const OUString
& rValue
,
99 const sal_uInt16 nLevel
,
100 bool _bAddOrOnOneLine
);
101 void DuplicateConditionLevel( const sal_uInt16 nLevel
);
102 void AddOrder(const OTableFieldDescRef
& rInfo
, const EOrderDir eDir
, sal_uInt32 _nCurrentPos
);
104 OTableFieldDescRef
AppendNewCol( sal_uInt16 nCnt
=1 );
106 OQueryDesignView
* getDesignView();
107 OQueryDesignView
* getDesignView() const;
108 sal_uInt16
FieldsCount();
110 void SetColWidth(sal_uInt16 nColId
, long lNewWidth
);
111 // unlike SetColumnWidth of the base class it checks an active cell in this column
113 OUString
GetCellContents(sal_Int32 nCellIndex
, sal_uInt16 nColId
);
114 void SetCellContents(sal_Int32 nCellIndex
, sal_uInt16 nColId
, const OUString
& strNewText
);
115 // cell content (formatted as string) set/return
116 sal_Int32
GetNoneVisibleRows() const;
117 void SetNoneVisbleRow(long nRows
);
118 bool IsRowVisible(sal_uInt16 _nWhich
) const;
119 void SetRowVisible(sal_uInt16 _nWhich
, bool _bVis
);
121 void SetReadOnly(bool bRO
);
122 // calculate an optimal size. Basically, this takes into account the number of visible rows.
123 Size
CalcOptimalSize( const Size
& _rAvailable
);
125 // can the current content be cut
126 bool isPasteAllowed();
128 bool isCopyAllowed();
133 virtual void GetFocus() SAL_OVERRIDE
;
134 virtual void DeactivateCell(bool bUpdate
= true) SAL_OVERRIDE
;
135 virtual void ColumnMoved( sal_uInt16 nColId
) SAL_OVERRIDE
{ ColumnMoved(nColId
,true); }
136 void ColumnMoved( sal_uInt16 nColId
, bool _bCreateUndo
);
141 /** Disables the generation of undo actions
143 inline void EnterUndoMode() { m_bInUndoMode
= true; }
144 /** Enables the generation of undo actions
146 inline void LeaveUndoMode() { m_bInUndoMode
= false; }
148 /** GetCellText returns the text at the given position
150 the number of the row
154 the text out of the cell
156 virtual OUString
GetCellText(long _nRow
, sal_uInt16 _nColId
) const SAL_OVERRIDE
;
158 /** returns the description of the row.
162 The header text of the specified row.
164 virtual OUString
GetRowDescription( sal_Int32 _nRow
) const SAL_OVERRIDE
;
166 /** return the name of the specified object.
170 The position of a tablecell (index position), header bar column/row cell
172 The name of the specified object.
174 virtual OUString
GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
= -1) const SAL_OVERRIDE
;
176 // IAccessibleTableProvider
177 /** Creates the accessible object of a data table cell.
178 @param nRow The row index of the cell.
179 @param nColumnId The column ID of the cell.
180 @return The XAccessible interface of the specified cell. */
181 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> CreateAccessibleCell( sal_Int32 nRow
, sal_uInt16 nColumnId
) SAL_OVERRIDE
;
184 virtual bool SeekRow( long nRow
) SAL_OVERRIDE
;
186 virtual void PaintStatusCell(OutputDevice
& rDev
, const Rectangle
& rRect
) const SAL_OVERRIDE
;
187 virtual void PaintCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
188 sal_uInt16 nColumnId
) const SAL_OVERRIDE
;
190 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
) SAL_OVERRIDE
;
191 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
) SAL_OVERRIDE
;
192 virtual void MouseButtonDown( const BrowserMouseEvent
& rEvt
) SAL_OVERRIDE
;
193 virtual void MouseButtonUp( const BrowserMouseEvent
& rEvt
) SAL_OVERRIDE
;
194 virtual void KeyInput( const KeyEvent
& rEvt
) SAL_OVERRIDE
;
195 virtual void Command(const CommandEvent
& rEvt
) SAL_OVERRIDE
;
196 virtual void ArrangeControls(sal_uInt16
& nX
, sal_uInt16 nY
) SAL_OVERRIDE
;
198 virtual ::svt::CellController
* GetController(long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
199 virtual void InitController(::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
200 virtual void CellModified() SAL_OVERRIDE
;
201 virtual bool SaveModified() SAL_OVERRIDE
;
202 virtual void Init() SAL_OVERRIDE
;
203 sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
) const;
204 virtual void ColumnResized( sal_uInt16 nColId
) SAL_OVERRIDE
;
206 virtual sal_uInt32
GetTotalCellWidth(long nRow
, sal_uInt16 nColId
) SAL_OVERRIDE
;
208 // if you want to have an own header ...
209 virtual VclPtr
<BrowserHeader
> imp_CreateHeaderBar(BrowseBox
* pParent
) SAL_OVERRIDE
;
215 OTableFieldDescRef
FindFirstFreeCol(sal_uInt16
& _rColumnPosition
);
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
);
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)
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 bool GetFunctionName(sal_uInt32 _nFunctionTokenId
, OUString
& rFkt
);
229 void appendUndoAction(const OUString
& _rOldValue
,const OUString
& _rNewValue
,sal_Int32 _nRow
, bool& _bListAction
);
230 void appendUndoAction(const OUString
& _rOldValue
,const OUString
& _rNewValue
,sal_Int32 _nRow
);
231 OTableFields
& getFields() const;
232 static 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
);
237 void adjustSelectionMode( bool _bClickedOntoHeader
, bool _bClickedOntoHandleCol
);
239 /** save the filed change in save modified
241 The field name inserted by the user.
243 The entry which will contain the necessary entries.
245 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
247 <TRUE/> if an error occurred otherwise <FALSE/>
249 bool saveField(OUString
& _sFieldName
, OTableFieldDescRef
& _pEntry
, bool& _bListAction
);
251 /** sets the table window at the _pEntry
253 The entry where the window should be set.
255 The table name to search for.
257 <TRUE/> if the table name was set otherwise <FALSE/>
259 bool fillEntryTable(OTableFieldDescRef
& _pEntry
,const OUString
& _sTableName
);
261 /** uses the parse node to fill all information into the field
263 The parse node used to fill the info into the field.
265 Use to parse the node to a string.
267 The entry which will contain the necessary entries.
269 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
271 <TRUE/> if an error occurred otherwise <FALSE/>
273 bool fillColumnRef( const ::connectivity::OSQLParseNode
* _pColumnRef
,
274 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
,
275 OTableFieldDescRef
& _pEntry
,
277 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
,
283 /** append an undo action for the table field
289 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
291 void notifyTableFieldChanged(const OUString
& _sOldAlias
,const OUString
& _sAlias
, bool& _bListAction
,sal_uInt16 _nColumnId
);
293 /** append an undo action for the function field
294 @param _sOldFunctionName
296 @param _sFunctionName
297 The new function name.
299 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
301 void notifyFunctionFieldChanged(const OUString
& _sOldFunctionName
,const OUString
& _sFunctionName
, bool& _bListAction
,sal_uInt16 _nColumnId
);
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
308 The entry to be cleared
310 When <TRUE/> an list action will be created.
312 void clearEntryFunctionField(const OUString
& _sFieldName
,OTableFieldDescRef
& _pEntry
, bool& _bListAction
,sal_uInt16 _nColumnId
);
314 /** remove or insert the necessary function types
316 The currently edited entry.
318 void setFunctionCell(OTableFieldDescRef
& _pEntry
);
321 using ::svt::EditBrowseBox::AcceptDrop
;
322 using ::svt::EditBrowseBox::ExecuteDrop
;
323 using ::svt::EditBrowseBox::MouseButtonDown
;
324 using ::svt::EditBrowseBox::MouseButtonUp
;
327 #endif // INCLUDED_DBACCESS_SOURCE_UI_QUERYDESIGN_SELECTIONBROWSEBOX_HXX
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */