1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef DBAUI_TOOLS_HXX 24 #define DBAUI_TOOLS_HXX 25 26 #ifndef _DBHELPER_DBEXCEPTION_HXX_ 27 #include <connectivity/dbexception.hxx> 28 #endif 29 #ifndef _COMPHELPER_STLTYPES_HXX_ 30 #include <comphelper/stl_types.hxx> 31 #endif 32 #ifndef DBAUI_TYPEINFO_HXX 33 #include "TypeInfo.hxx" 34 #endif 35 #ifndef _SVX_SVXENUM_HXX 36 #include <editeng/svxenum.hxx> 37 #endif 38 #ifndef _SV_TASKPANELIST_HXX 39 #include <vcl/taskpanelist.hxx> 40 #endif 41 #ifndef _CONNECTIVITY_DBTOOLS_HXX_ 42 #include <connectivity/dbtools.hxx> 43 #endif 44 45 #define RET_ALL 10 46 47 // we only need forward decl here 48 namespace com { namespace sun { namespace star { 49 50 namespace beans { class XPropertySet;} 51 namespace container 52 { 53 class XNameAccess; 54 class XIndexAccess; 55 class XHierarchicalNameContainer; 56 class XNameContainer; 57 } 58 namespace lang 59 { 60 class XEventListener; 61 class XMultiServiceFactory; 62 } 63 namespace awt 64 { 65 struct FontDescriptor; 66 } 67 namespace sdbc 68 { 69 class XDatabaseMetaData; 70 class XConnection; 71 } 72 namespace util 73 { 74 struct URL; 75 class XNumberFormatter; 76 } 77 namespace frame 78 { 79 class XModel; 80 } 81 namespace ucb { class XContent; } 82 83 }}} 84 85 namespace svt 86 { 87 class EditBrowseBox; 88 } 89 90 class Window; 91 class ToolBox; 92 class Font; 93 class SvNumberFormatter; 94 class SfxFilter; 95 class SvLBoxEntry; 96 97 // ......................................................................... 98 namespace dbaui 99 { 100 // ......................................................................... 101 //class ODsnTypeCollection; 102 class DBTreeListBox; 103 104 /** creates a new connection and appends the eventlistener 105 @param _rsDataSourceName name of the datasource 106 @param _xDatabaseContext the database context 107 @param _rMF the multi service factory 108 @param _rEvtLst the eventlistener which will be added to the new created connection 109 @param _rOUTConnection this parameter will be filled with the new created connection 110 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false 111 */ 112 ::dbtools::SQLExceptionInfo createConnection( 113 const ::rtl::OUString& _rsDataSourceName, 114 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext, 115 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF, 116 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst, 117 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection ); 118 /** creates a new connection and appends the eventlistener 119 @param _xDataSource the datasource 120 @param _rMF the multi service factory 121 @param _rEvtLst the eventlistener which will be added to the new created connection 122 @param _rOUTConnection this parameter will be filled with the new created connection 123 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false 124 */ 125 ::dbtools::SQLExceptionInfo createConnection( 126 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDataSource, 127 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF, 128 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst, 129 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection ); 130 131 /** creates a error dialog which displays the SQLExceptionInfo. Also it supports a "more" button where detailed information are available 132 @param _rInfo the error which should be shown, if the info is not valid no error dialog will appear 133 @param _pParent the parent of the error dialog 134 @param _xFactory need to create the dialog 135 */ 136 void showError( const ::dbtools::SQLExceptionInfo& _rInfo, 137 Window* _pParent, 138 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory); 139 140 /** return a vector which contains all key columns for the @see com::sun::star::sdbc::KeyType _nKeyType 141 @param _rxTable the table which must be a @see com::sun::star::sdbcx::XColumnsSupplier 142 @param _nKeyType @see com::sun::star::sdbc::KeyType 143 */ 144 145 ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> > 146 getKeyColumns( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _rxKeys, 147 sal_Int32 _nKeyType); 148 149 /** fills a map and a vector with localized type names 150 @param _rxConnection the connection to acces the metadata 151 @param _rsTypeNames a list of localized type names separated with ';' 152 @param _rTypeInfoMap the filled map with the type names 153 @param _rTypeInfoIters the vector filled with map iterators 154 */ 155 void fillTypeInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection, 156 const String& _rsTypeNames, 157 OTypeInfoMap& _rTypeInfoMap, 158 ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters); 159 160 /** fill a column with data of a field description 161 @param _rxColumn the column which should be filled 162 @param _pFieldDesc the source of the data 163 */ 164 class OFieldDescription; 165 void setColumnProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxColumn, 166 const OFieldDescription* _pFieldDesc); 167 168 ::rtl::OUString createDefaultName( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData, 169 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTables, 170 const ::rtl::OUString& _sName); 171 172 /** checks if the given name exists in the database context 173 */ 174 sal_Bool checkDataSourceAvailable( const ::rtl::OUString& _sDataSourceName, 175 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory_xORB); 176 177 /** maps SvxCellHorJustify to com::sun::star::awt::TextAlign 178 @param SvxCellHorJustify& _eAlignment 179 @return the corresponding com::sun::star::awt::TextAlign 180 */ 181 sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment); 182 183 /** retrieves a data source given by name or URL, and displays an error if this fails 184 185 Any <type scope="com::sun::star::sdbc">SQLException</type>s which occur will be displayed. 186 Additionally, and Exceptions which indicate a data source name pointing to a non-existent database 187 URL will also be denoted. Yet more additionally, and other exceptions will be forwarded to 188 a <type scope="com::sun::star::sdb">InteractionHandler</type>. 189 190 @param _rDataSourceName 191 the URL of the database document, or the name of a registered data source 192 @param _pErrorMessageParent 193 the window to use as parent for error messages 194 @param _rxORB 195 a service factory to use for components to be created 196 @param _pErrorInfo 197 takes the error info in case of failure. If <NULL/>, the error is displayed to the user. 198 */ 199 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > 200 getDataSourceByName( 201 const ::rtl::OUString& _rDataSourceName, 202 Window* _pErrorMessageParent, 203 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB, 204 ::dbtools::SQLExceptionInfo* _pErrorInfo 205 ); 206 207 /** returns either the model when data source is given as parameter, 208 or returns a data source when a model is given. 209 @param _xObject Either a data source or a model. 210 */ 211 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getDataSourceOrModel(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xObject); 212 213 /** maps com::sun::star::awt::TextAlign to SvxCellHorJustify 214 @param com::sun::star::awt::TextAlign& _nAlignment 215 @return the corresponding SvxCellHorJustify 216 */ 217 SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment); 218 219 /** convert Font to ::com::sun::star::awt::FontDescriptor 220 @param _rFont Font to be converted 221 @return the new FontDescriptor 222 */ 223 ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& _rFont ); 224 225 /** call the format dialog and set the selected format at the column 226 @param _xAffectedCol Font to be converted 227 @param _xField Font to be converted 228 */ 229 void callColumnFormatDialog(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xAffectedCol, 230 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xField, 231 SvNumberFormatter* _pFormatter, 232 Window* _pParent); 233 234 /** second variant of the function before 235 */ 236 sal_Bool callColumnFormatDialog(Window* _pParent, 237 SvNumberFormatter* _pFormatter, 238 sal_Int32 _nDataType, 239 sal_Int32& _nFormatKey, 240 SvxCellHorJustify& _eJustify, 241 sal_uInt16& _nFlags, 242 sal_Bool _bHasFormat); 243 /** append a name to tablefilter of a datasource 244 @param _xConnection the connection is need to get the datasource 245 @param _sName the name which should be appended 246 @param _xFactory needed to check if datasource is available 247 @param _pParent needed when an error must be shown 248 @return false when datsource is not available otherwise true 249 */ 250 sal_Bool appendToFilter(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection, 251 const ::rtl::OUString& _sName, 252 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory, 253 Window* _pParent); 254 255 /** notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search _pWindow. 256 @param _pWindow 257 The window which is used to search for the SystemWindow. 258 @param _pToRegister 259 The window which should be added or removed on the TaskPaneList. 260 @param _rMemFunc 261 The member function which should be called at the SystemWindow when found. 262 Possible values are: 263 ::comphelper::mem_fun(&TaskPaneList::AddWindow) 264 ::comphelper::mem_fun(&TaskPaneList::RemoveWindow) 265 */ 266 void notifySystemWindow(Window* _pWindow, 267 Window* _pToRegister, 268 ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc); 269 270 /** adjustToolBoxSize checks if the size of the ToolBox is still valid. If not it will be resized. 271 @param _pToolBox 272 The Toolbox which should be resized. 273 */ 274 void adjustToolBoxSize(ToolBox* _pToolBox); 275 276 /** isHiContrast check if we are in hi contrast mode. 277 @param _pWindow 278 The window we have to check on. 279 @return 280 <TRUE/> if so, otherwise <FALSE/> 281 */ 282 sal_Bool isHiContrast(Window* _pWindow); 283 284 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId ); 285 286 /** check if SQL92 name checking is enabled 287 @param _xConnection 288 Used to get the datasource as parent from the connection. 289 @return 290 <TRUE/> if so otherwise <FALSE/> 291 */ 292 sal_Bool isSQL92CheckEnabled(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection); 293 294 /** check if the alias name of the table should be added at select statements 295 @param _xConnection 296 Used to get the datasource as parent from the connection. 297 @return 298 <TRUE/> if so otherwise <FALSE/> 299 */ 300 sal_Bool isAppendTableAliasEnabled(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection); 301 302 /** determines whether when generating SQL statements, AS should be placed before a table alias 303 */ 304 sal_Bool generateAsBeforeTableAlias( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection ); 305 306 /** fills the bool and string value with information out of the datasource info property 307 @param _xDatasource 308 Asked for the properties. 309 @param _rAutoIncrementValueEnabled 310 <OUT/> Set to sal_True when the property was set in the datasource. 311 @param _rsAutoIncrementValue 312 <OUT/> Set to the value when the property was set in the datasource. 313 */ 314 void fillAutoIncrementValue(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDatasource 315 ,sal_Bool& _rAutoIncrementValueEnabled 316 ,::rtl::OUString& _rsAutoIncrementValue); 317 318 /** fills the bool and string value with information out of the datasource info property 319 @param _xConnection 320 Used to get the datasource as parent from the connection. 321 @param _rAutoIncrementValueEnabled 322 <OUT/> Set to sal_True when the property was set in the datasource. 323 @param _rsAutoIncrementValue 324 <OUT/> Set to the value when the property was set in the datasource. 325 */ 326 void fillAutoIncrementValue(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection 327 ,sal_Bool& _rAutoIncrementValueEnabled 328 ,::rtl::OUString& _rsAutoIncrementValue); 329 330 /** creates the URL or the help agent 331 @param _sModuleName 332 @param _nHelpId 333 @return 334 The URL for the help agent to dispatch. 335 */ 336 ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName,const rtl::OString& _rHelpId); 337 338 /** set the evaluation flag at the number formatter 339 @param _rxFormatter 340 */ 341 void setEvalDateFormatForFormatter(::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter); 342 343 /** query for a type info which can be used to create a primary key column 344 @param _rTypeInfo 345 The map which contains all available types. 346 @return 347 The type info which can be used to create a primary key column. 348 */ 349 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo); 350 351 /** query for a specific type. 352 @param _nDataType 353 The type we are searching. 354 @param _rTypeInfo 355 The map which contains all available types. 356 @return 357 The type or <NULL/> if we can't find it. 358 */ 359 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo); 360 361 /** returns the configuration node name of user defined drivers. 362 @return 363 the configuration node name of user defined drivers. 364 */ 365 366 /** returns the result of the user action when view the query dialog. 367 @param _pParent 368 The parent of the dialog 369 @param _nTitle 370 A string resource id for the text which will be displayed as title. 371 @param _nText 372 A string resource id for the text which will be displayed above the buttons. 373 When the string contains a #1. This will be replaced by the name. 374 @param _bAll 375 When set to <TRUE/>, the all button will be appended. 376 @param _sName 377 The name of the object to ask for. 378 @return 379 RET_YES, RET_NO, RET_ALL 380 */ 381 sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName); 382 383 /** creates a new view from a query or table 384 @param _sName 385 The name of the view to be created. 386 @param _xConnection 387 The source connection. 388 @param _xSourceObject 389 The object for which a view should be created. 390 @return 391 The created view. 392 */ 393 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> createView( const ::rtl::OUString& _sName 394 ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection 395 ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xSourceObject); 396 397 /** creates a view with the given command 398 */ 399 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> createView( 400 const ::rtl::OUString& _rName, 401 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, 402 const ::rtl::OUString& _rCommand 403 ); 404 405 /** returns the stripped database name. 406 @param _xDataSource 407 The data source 408 @param _rsDatabaseName 409 Will be filled with the original data source if it is empty. 410 @return 411 The stripped database name either the registered naem or if it is a file url the last segment. 412 */ 413 ::rtl::OUString getStrippedDatabaseName(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource 414 ,::rtl::OUString& _rsDatabaseName); 415 416 /** returns the standard database filter 417 @retrun 418 the filter 419 */ 420 const SfxFilter* getStandardDatabaseFilter(); 421 422 /** opens a save dialog to store a form or report folder in the current hierarchy. 423 @param _pParent 424 The parent of the dialog. 425 @param _rxORB 426 a multi service factory which can be used to instantiate usual global services 427 @param _xNames 428 Where to insert the new object. 429 @param _sParentFolder 430 The name of the parent folder. 431 @param _bForm 432 <TRUE/> if a form should be inserted 433 @param _bCollection 434 A folder should be inserted 435 @param _xContent 436 The content which should be copied. 437 @param _bMove 438 if <TRUE/> the name of the content must be inserted without any change, otherwise not. 439 @return 440 <TRUE/> if the insert opertions was successful, otherwise <FALSE/>. 441 */ 442 sal_Bool insertHierachyElement( 443 Window* _pParent, 444 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 445 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameContainer>& _xNames, 446 const String& _sParentFolder, 447 sal_Bool _bForm, 448 sal_Bool _bCollection = sal_True, 449 const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>& _xContent = NULL, 450 sal_Bool _bMove = sal_False 451 ); 452 453 /** creates a number formatter 454 @param _rxConnection 455 The connection is needed to create the formatter 456 @param _rMF 457 The multi service factory 458 */ 459 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > getNumberFormatter(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF ); 460 461 // this completes a help url with the system parameters "Language" and "System" 462 // detect installed locale 463 void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark ); 464 465 // ......................................................................... 466 } 467 // ......................................................................... 468 #endif // DBAUI_TOOLS_HXX 469 470 471