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