merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / querydesign / SelectionBrowseBox.hxx
blobfcc9a532093be5584799dcc2e39d3b647cfb5254
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SelectionBrowseBox.hxx,v $
10 * $Revision: 1.29 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
31 #define DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
33 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
34 #include <svtools/editbrowsebox.hxx>
35 #endif
36 //#ifndef DBAUI_QUERYCONTROLLER_HXX
37 //#include "querycontroller.hxx"
38 //#endif
39 #ifndef DBAUI_TABLEFIELDDESC_HXX
40 #include "TableFieldDescription.hxx"
41 #endif
42 #ifndef DBAUI_JOINEXCHANGE_HXX
43 #include "JoinExchange.hxx"
44 #endif
45 #ifndef DBAUI_ENUMTYPES_HXX
46 #include "QEnumTypes.hxx"
47 #endif
48 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
49 #include <com/sun/star/util/XNumberFormatter.hpp>
50 #endif
51 #ifndef _STRING_HXX
52 #include <tools/string.hxx>
53 #endif
54 #ifndef _TRANSFER_HXX
55 #include <svtools/transfer.hxx>
56 #endif
58 namespace connectivity
60 class OSQLParseNode;
63 namespace dbaui
65 //==================================================================
66 #define SIZ_NONE 0
67 #define SIZ_TOP 1
68 #define SIZ_BOTTOM 2
69 #define SIZ_LEFT 4
70 #define SIZ_RIGHT 8
72 #define BROW_FIELD_ROW 0
73 #define BROW_COLUMNALIAS_ROW 1
74 #define BROW_TABLE_ROW 2
75 #define BROW_ORDER_ROW 3
76 #define BROW_VIS_ROW 4
77 #define BROW_FUNCTION_ROW 5
78 #define BROW_CRIT1_ROW 6
79 #define BROW_CRIT2_ROW 7
80 #define BROW_CRIT3_ROW 8
81 #define BROW_CRIT4_ROW 9
82 #define BROW_CRIT5_ROW 10
83 #define BROW_CRIT6_ROW 11
84 #define BROW_ROW_CNT 12
86 //==================================================================
87 class OQueryDesignView;
88 class OSelectionBrowseBox : public ::svt::EditBrowseBox
90 friend class OQueryDesignView;
91 ::std::vector<bool> m_bVisibleRow; // an Pos steht die RowId
92 Timer m_timerInvalidate;
94 long m_nSeekRow;
95 BrowserMode m_nMode; // Merken des BrowseModes
96 Edit* m_pTextCell;
97 ::svt::CheckBoxControl* m_pVisibleCell;
98 ::svt::ComboBoxControl* m_pFieldCell;
99 ::svt::ListBoxControl* m_pFunctionCell;
100 ::svt::ListBoxControl* m_pTableCell;
101 ::svt::ListBoxControl* m_pOrderCell;
103 OTableFieldDescRef m_pEmptyEntry; // default entry in the list may reference more than once
105 sal_Int32 m_nMaxColumns; // maximale Anzahl der Spalten in einem Select-Statement
107 String m_aFunctionStrings;
108 sal_uInt16 m_nVisibleCount; // Anzahl der max sichtbaren Zeilen
109 sal_Bool m_bOrderByUnRelated;
110 sal_Bool m_bGroupByUnRelated;
111 sal_Bool m_bStopTimer;
112 sal_Bool m_bWasEditing;
113 sal_Bool m_bDisableErrorBox;
114 sal_Bool m_bInUndoMode;
116 DECL_LINK(OnInvalidateTimer, void*);
117 public: OSelectionBrowseBox( Window* pParent );
118 ~OSelectionBrowseBox();
120 void initialize();
121 OTableFieldDescRef InsertField( const OJoinExchangeData& jxdSource, USHORT _nColumnPostion = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
122 OTableFieldDescRef InsertField( const OTableFieldDescRef& rInfo, USHORT _nColumnPostion = BROWSER_INVALIDID, sal_Bool bVis=sal_True, sal_Bool bActivate=sal_True );
123 void InsertColumn( OTableFieldDescRef pEntry, USHORT& _nColumnPostion );
124 void RemoveColumn( USHORT _nColumnId );
125 void DeleteFields( const String& rAliasName );
127 bool HasFieldByAliasName(const ::rtl::OUString& rFieldName, OTableFieldDescRef& rInfo) const;
128 // AddGroupBy:: F"ugt ein Feld mit Funktion == Grupierung. Falls das Feld schon vorhanden ist und ein Aggregate Funktion
129 // benutzt, wird das Flag nicht gesetzt
130 void AddGroupBy( const OTableFieldDescRef& rInfo,sal_uInt32 _nCurrentPos);
131 void AddCondition( const OTableFieldDescRef& rInfo,
132 const String& rValue,
133 const sal_uInt16 nLevel,
134 bool _bAddOrOnOneLine );
135 void AddOrder(const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos);
136 void ClearAll();
137 OTableFieldDescRef AppendNewCol( sal_uInt16 nCnt=1 );
138 sal_Bool Save();
139 OQueryDesignView* getDesignView();
140 OQueryDesignView* getDesignView() const;
141 sal_uInt16 FieldsCount();
143 void SetColWidth(sal_uInt16 nColId, long lNewWidth);
144 // beachtet im Gegensatz zum SetColumnWidth der Basisklasse auch eine eventuell aktive Zelle in dieser Spalte
146 String GetCellContents(sal_Int32 nCellIndex, USHORT nColId);
147 void SetCellContents(sal_Int32 nCellIndex, USHORT nColId, const String& strNewText);
148 // Zelleninhalt (als String formatiert) setzen/liefern
149 sal_Int32 GetNoneVisibleRows() const;
150 void SetNoneVisbleRow(long nRows);
151 sal_Bool IsRowVisible(sal_uInt16 _nWhich) const;
152 void SetRowVisible(sal_uInt16 _nWhich, sal_Bool _bVis);
154 void SetReadOnly(sal_Bool bRO);
155 // calculate an optimal size. Basically, this takes into account the number of visible rows.
156 Size CalcOptimalSize( const Size& _rAvailable );
158 // can the current content be cut
159 sal_Bool isPasteAllowed();
160 sal_Bool isCutAllowed();
161 sal_Bool isCopyAllowed();
162 void cut();
163 void paste();
164 void copy();
166 virtual void GetFocus();
167 virtual void DeactivateCell(sal_Bool bUpdate = sal_True);
168 virtual void ColumnMoved( USHORT nColId ) { ColumnMoved(nColId,TRUE); }
169 void ColumnMoved( USHORT nColId,BOOL _bCreateUndo);
171 void Fill();
172 void PreFill();
174 /** Disables the generation of undo actions
176 inline void EnterUndoMode() { m_bInUndoMode = sal_True; }
177 /** Enables the generation of undo actions
179 inline void LeaveUndoMode() { m_bInUndoMode = sal_False; }
181 /** GetCellText returns the text at the given position
182 @param _nRow
183 the number of the row
184 @param _nColId
185 the ID of the column
186 @return
187 the text out of the cell
189 virtual String GetCellText(long _nRow, USHORT _nColId) const;
191 /** returns the description of the row.
192 @param _nRow
193 The row number.
194 @return
195 The header text of the specified row.
197 virtual ::rtl::OUString GetRowDescription( sal_Int32 _nRow ) const;
199 /** return the name of the specified object.
200 @param eObjType
201 The type to ask for
202 @param _nPosition
203 The position of a tablecell (index position), header bar colum/row cell
204 @return
205 The name of the specified object.
207 virtual ::rtl::OUString GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition = -1) const;
209 // IAccessibleTableProvider
210 /** Creates the accessible object of a data table cell.
211 @param nRow The row index of the cell.
212 @param nColumnId The column ID of the cell.
213 @return The XAccessible interface of the specified cell. */
214 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessibleCell( sal_Int32 nRow, sal_uInt16 nColumnId );
217 protected:
218 virtual sal_Bool SeekRow( long nRow );
220 virtual void PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const;
221 virtual void PaintCell(OutputDevice& rDev, const Rectangle& rRect,
222 sal_uInt16 nColumnId ) const;
224 virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt );
225 virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
226 virtual void MouseButtonDown( const BrowserMouseEvent& rEvt );
227 virtual void MouseButtonUp( const BrowserMouseEvent& rEvt );
228 virtual void KeyInput( const KeyEvent& rEvt );
229 virtual void Command(const CommandEvent& rEvt);
230 virtual void ArrangeControls(sal_uInt16& nX, sal_uInt16 nY);
232 virtual ::svt::CellController* GetController(long nRow, sal_uInt16 nCol);
233 virtual void InitController(::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol);
234 virtual void CellModified();
235 virtual sal_Bool SaveModified();
236 virtual void Init();
237 virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId) const;
238 virtual void ColumnResized( sal_uInt16 nColId );
240 virtual sal_uInt32 GetTotalCellWidth(long nRow, sal_uInt16 nColId);
242 virtual sal_uInt16 GetDefaultColumnWidth(const String& rName) const;
243 // if you want to have an own header ...
244 virtual BrowserHeader* imp_CreateHeaderBar(BrowseBox* pParent);
246 void stopTimer();
247 void startTimer();
249 private:
250 OTableFieldDescRef FindFirstFreeCol(USHORT& _rColumnPosition);
251 // rCol enthaelt die Nummer (in pOTableFieldDescList) der ersten Spalte, die von sich sagt, dass sie leer ist
252 // wenn es keine solche gibt, ist rCol undefiniert und der Rueckgabewert NULL
253 void CheckFreeColumns(USHORT& _rColumnPosition);
254 // testet, ob es noch freie Spalten gibt, wenn nicht, wird ein neuer Packen angefuegt
255 // rCol enthaelt die Nummer der ersten freien Spalte (in pOTableFieldDescList)
257 void RemoveField( sal_uInt16 nId );
258 Rectangle GetInvalidRect( sal_uInt16 nColId );
259 long GetRealRow(long nRow) const;
260 long GetBrowseRow(long nRowId) const;
261 sal_Bool GetFunctionName(sal_uInt32 _nFunctionTokenId,String& rFkt);
262 void appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow,sal_Bool& _bListAction);
263 void appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow);
264 OTableFields& getFields() const;
265 void enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl);
266 void setTextCellContext(const OTableFieldDescRef& _rEntry,const String& _sText,ULONG _nHelpId);
267 void invalidateUndoRedo();
268 OTableFieldDescRef getEntry(OTableFields::size_type _nPos);
270 void adjustSelectionMode( sal_Bool _bClickedOntoHeader, sal_Bool _bClickedOntoHandleCol );
272 /** save the filed change in save modified
273 @param _sFieldName
274 The field name inserted by the user.
275 @param _pEntry
276 The entry which will contain the nescessary entries.
277 @param _bListAction
278 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
279 @return
280 <TRUE/> if an error occured otherwise <FALSE/>
282 sal_Bool saveField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction);
284 /** sets the table window at the _pEntry
285 @param _pEntry
286 The entry where the window should be set.
287 @param _sTableName
288 The table name to search for.
289 @return
290 <TRUE/> if the table name was set otherwise <FALSE/>
292 sal_Bool fillEntryTable(OTableFieldDescRef& _pEntry,const ::rtl::OUString& _sTableName);
294 /** uses the parse node to fill all information into the field
295 @param _pColumnRef
296 The parse node used to fill the info into the field.
297 @param _xMetaData
298 Use to parse the node to a string.
299 @param _pEntry
300 The entry which will contain the nescessary entries.
301 @param _bListAction
302 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
303 @return
304 <TRUE/> if an error occured otherwise <FALSE/>
306 sal_Bool fillColumnRef( const ::connectivity::OSQLParseNode* _pColumnRef,
307 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
308 OTableFieldDescRef& _pEntry,
309 sal_Bool& _bListAction);
310 sal_Bool fillColumnRef( const ::rtl::OUString& _sColumnName,
311 const ::rtl::OUString& _sTableRange,
312 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData,
313 OTableFieldDescRef& _pEntry,
314 sal_Bool& _bListAction);
317 /** append an undo action for the table field
318 @param _sOldAlias
319 The old table alias.
320 @param _sAlias
321 The new alias name.
322 @param _bListAction
323 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
325 void notifyTableFieldChanged(const String& _sOldAlias,const String& _sAlias,sal_Bool& _bListAction,USHORT _nColumnId);
327 /** append an undo action for the function field
328 @param _sOldFunctionName
329 The old value.
330 @param _sFunctionName
331 The new function name.
332 @param _bListAction
333 Will be set to <TRUE/> when we are in a list action otherwise <FALSE/>
335 void notifyFunctionFieldChanged(const String& _sOldFunctionName,const String& _sFunctionName,sal_Bool& _bListAction,USHORT _nColumnId);
337 /** clears the function fields of the submitted entry if it doesn't match the SQL standard and append an undo action.
338 E.q. AGGREGATE functions are only valid when the field name isn't an asterix
339 @param _sFieldName
340 The field name.
341 @param _pEntry
342 The entry to be cleared
343 @param _bListAction
344 When <TRUE/> an list action will be created.
346 void clearEntryFunctionField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction,USHORT _nColumnId);
348 /** remove or insert the necessary function types
349 @param _pEntry
350 The currently edited entry.
352 void setFunctionCell(OTableFieldDescRef& _pEntry);
354 private:
355 using ::svt::EditBrowseBox::AcceptDrop;
356 using ::svt::EditBrowseBox::ExecuteDrop;
357 using ::svt::EditBrowseBox::MouseButtonDown;
358 using ::svt::EditBrowseBox::MouseButtonUp;
361 #endif // DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX