1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UITools.hxx,v $
10 * $Revision: 1.37.26.1 $
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_TOOLS_HXX
31 #define DBAUI_TOOLS_HXX
33 #ifndef _DBHELPER_DBEXCEPTION_HXX_
34 #include <connectivity/dbexception.hxx>
36 #ifndef _COMPHELPER_STLTYPES_HXX_
37 #include <comphelper/stl_types.hxx>
39 #ifndef DBAUI_TYPEINFO_HXX
40 #include "TypeInfo.hxx"
42 #ifndef _SVX_SVXENUM_HXX
43 #include <svx/svxenum.hxx>
45 #ifndef _SV_TASKPANELIST_HXX
46 #include <vcl/taskpanelist.hxx>
48 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
49 #include <connectivity/dbtools.hxx>
54 // we only need forward decl here
55 namespace com
{ namespace sun
{ namespace star
{
57 namespace beans
{ class XPropertySet
;}
62 class XHierarchicalNameContainer
;
68 class XMultiServiceFactory
;
72 struct FontDescriptor
;
76 class XDatabaseMetaData
;
82 class XNumberFormatter
;
88 namespace ucb
{ class XContent
; }
100 class SvNumberFormatter
;
104 // .........................................................................
107 // .........................................................................
108 //class ODsnTypeCollection;
111 /** creates a new connection and appends the eventlistener
112 @param _rsDataSourceName name of the datasource
113 @param _xDatabaseContext the database context
114 @param _rMF the multi service factory
115 @param _rEvtLst the eventlistener which will be added to the new created connection
116 @param _rOUTConnection this parameter will be filled with the new created connection
117 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
119 ::dbtools::SQLExceptionInfo
createConnection(
120 const ::rtl::OUString
& _rsDataSourceName
,
121 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& _xDatabaseContext
,
122 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rMF
,
123 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& _rEvtLst
,
124 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rOUTConnection
);
125 /** creates a new connection and appends the eventlistener
126 @param _xDataSource the datasource
127 @param _rMF the multi service factory
128 @param _rEvtLst the eventlistener which will be added to the new created connection
129 @param _rOUTConnection this parameter will be filled with the new created connection
130 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
132 ::dbtools::SQLExceptionInfo
createConnection(
133 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDataSource
,
134 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rMF
,
135 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& _rEvtLst
,
136 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rOUTConnection
);
138 /** creates a error dialog which displays the SQLExceptionInfo. Also it supports a "more" button where detailed information are available
139 @param _rInfo the error which should be shown, if the info is not valid no error dialog will appear
140 @param _pParent the parent of the error dialog
141 @param _xFactory need to create the dialog
143 void showError( const ::dbtools::SQLExceptionInfo
& _rInfo
,
145 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xFactory
);
147 /** return a vector which contains all key columns for the @see com::sun::star::sdbc::KeyType _nKeyType
148 @param _rxTable the table which must be a @see com::sun::star::sdbcx::XColumnsSupplier
149 @param _nKeyType @see com::sun::star::sdbc::KeyType
152 ::std::vector
< ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> >
153 getKeyColumns( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XIndexAccess
>& _rxKeys
,
154 sal_Int32 _nKeyType
);
156 /** fills a map and a vector with localized type names
157 @param _rxConnection the connection to acces the metadata
158 @param _rsTypeNames a list of localized type names seperated with ';'
159 @param _rTypeInfoMap the filled map with the type names
160 @param _rTypeInfoIters the vector filled with map iterators
162 void fillTypeInfo( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
,
163 const String
& _rsTypeNames
,
164 OTypeInfoMap
& _rTypeInfoMap
,
165 ::std::vector
<OTypeInfoMap::iterator
>& _rTypeInfoIters
);
167 /** fill a column with data of a field description
168 @param _rxColumn the column which should be filled
169 @param _pFieldDesc the source of the data
171 class OFieldDescription
;
172 void setColumnProperties( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxColumn
,
173 const OFieldDescription
* _pFieldDesc
);
175 ::rtl::OUString
createDefaultName( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
>& _xMetaData
,
176 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& _xTables
,
177 const ::rtl::OUString
& _sName
);
179 /** checks if the given name exists in the database context
181 sal_Bool
checkDataSourceAvailable( const ::rtl::OUString
& _sDataSourceName
,
182 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xFactory_xORB
);
184 /** maps SvxCellHorJustify to com::sun::star::awt::TextAlign
185 @param SvxCellHorJustify& _eAlignment
186 @return the corresponding com::sun::star::awt::TextAlign
188 sal_Int32
mapTextAllign(const SvxCellHorJustify
& _eAlignment
);
190 /** retrieves a data source given by name or URL, and displays an error if this fails
192 Any <type scope="com::sun::star::sdbc">SQLException</type>s which occur will be displayed.
193 Additionally, and Exceptions which indicate a data source name pointing to a non-existent database
194 URL will also be denoted. Yet more additionally, and other exceptions will be forwarded to
195 a <type scope="com::sun::star::sdb">InteractionHandler</type>.
197 @param _rDataSourceName
198 the URL of the database document, or the name of a registered data source
199 @param _pErrorMessageParent
200 the window to use as parent for error messages
202 a service factory to use for components to be created
204 takes the error info in case of failure. If <NULL/>, the error is displayed to the user.
206 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDataSource
>
208 const ::rtl::OUString
& _rDataSourceName
,
209 Window
* _pErrorMessageParent
,
210 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> _rxORB
,
211 ::dbtools::SQLExceptionInfo
* _pErrorInfo
214 /** returns either the model when data source is given as parameter,
215 or returns a data source when a model is given.
216 @param _xObject Either a data source or a model.
218 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getDataSourceOrModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xObject
);
220 /** maps com::sun::star::awt::TextAlign to SvxCellHorJustify
221 @param com::sun::star::awt::TextAlign& _nAlignment
222 @return the corresponding SvxCellHorJustify
224 SvxCellHorJustify
mapTextJustify(const sal_Int32
& _nAlignment
);
226 /** convert Font to ::com::sun::star::awt::FontDescriptor
227 @param _rFont Font to be converted
228 @return the new FontDescriptor
230 ::com::sun::star::awt::FontDescriptor
CreateFontDescriptor( const Font
& _rFont
);
232 /** call teh format dialog and set the selected format at the column
233 @param _xAffectedCol Font to be converted
234 @param _xField Font to be converted
236 void callColumnFormatDialog(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xAffectedCol
,
237 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xField
,
238 SvNumberFormatter
* _pFormatter
,
241 /** second variant of the function before
243 sal_Bool
callColumnFormatDialog(Window
* _pParent
,
244 SvNumberFormatter
* _pFormatter
,
245 sal_Int32 _nDataType
,
246 sal_Int32
& _nFormatKey
,
247 SvxCellHorJustify
& _eJustify
,
249 sal_Bool _bHasFormat
);
250 /** append a name to tablefilter of a datasource
251 @param _xConnection the connection is need to get the datasource
252 @param _sName the name which should be appended
253 @param _xFactory needed to check if datasource is available
254 @param _pParent needed when an error must be shown
255 @return false when datsource is not available otherwise true
257 sal_Bool
appendToFilter(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
258 const ::rtl::OUString
& _sName
,
259 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xFactory
,
262 /** notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search _pWindow.
264 The window which is used to search for the SystemWindow.
266 The window which should be added or removed on the TaskPaneList.
268 The member function which should be called at the SystemWindow when found.
270 ::comphelper::mem_fun(&TaskPaneList::AddWindow)
271 ::comphelper::mem_fun(&TaskPaneList::RemoveWindow)
273 void notifySystemWindow(Window
* _pWindow
,
274 Window
* _pToRegister
,
275 ::comphelper::mem_fun1_t
<TaskPaneList
,Window
*> _rMemFunc
);
277 /** adjustToolBoxSize checks if the size of the ToolBox is still valid. If not it will be resized.
279 The Toolbox which should be resized.
281 void adjustToolBoxSize(ToolBox
* _pToolBox
);
283 /** isHiContrast check if we are in hi contrast mode.
285 The window we have to check on.
287 <TRUE/> if so, otherwise <FALSE/>
289 sal_Bool
isHiContrast(Window
* _pWindow
);
291 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox
* _pBox
, sal_uInt16 _nColId
);
293 /** check if SQL92 name checking is enabled
295 Used to get the datasource as parent from the connection.
297 <TRUE/> if so otherwise <FALSE/>
299 sal_Bool
isSQL92CheckEnabled(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
);
301 /** check if the alias name of the table should be added at select statements
303 Used to get the datasource as parent from the connection.
305 <TRUE/> if so otherwise <FALSE/>
307 sal_Bool
isAppendTableAliasEnabled(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
);
309 /** determines whether when generating SQL statements, AS should be placed before a table alias
311 sal_Bool
generateAsBeforeTableAlias( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _rxConnection
);
313 /** fills the bool and string value with information out of the datasource info property
315 Asked for the properties.
316 @param _rAutoIncrementValueEnabled
317 <OUT/> Set to TRUE when the property was set in the datasource.
318 @param _rsAutoIncrementValue
319 <OUT/> Set to the value when the property was set in the datasource.
321 void fillAutoIncrementValue(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDatasource
322 ,sal_Bool
& _rAutoIncrementValueEnabled
323 ,::rtl::OUString
& _rsAutoIncrementValue
);
325 /** fills the bool and string value with information out of the datasource info property
327 Used to get the datasource as parent from the connection.
328 @param _rAutoIncrementValueEnabled
329 <OUT/> Set to TRUE when the property was set in the datasource.
330 @param _rsAutoIncrementValue
331 <OUT/> Set to the value when the property was set in the datasource.
333 void fillAutoIncrementValue(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
334 ,sal_Bool
& _rAutoIncrementValueEnabled
335 ,::rtl::OUString
& _rsAutoIncrementValue
);
337 /** creates the URL or the help agent
341 The URL for the help agent to dispatch.
343 ::com::sun::star::util::URL
createHelpAgentURL(const ::rtl::OUString
& _sModuleName
,const sal_Int32 _nHelpId
);
345 /** set the evaluation flag at the number formatter
348 void setEvalDateFormatForFormatter(::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
);
350 /** query for a type info which can be used to create a primary key column
352 The map which contains all available types.
354 The type info which can be used to create a primary key column.
356 TOTypeInfoSP
queryPrimaryKeyType(const OTypeInfoMap
& _rTypeInfo
);
358 /** query for a specific type.
360 The type we are searching.
362 The map which contains all available types.
364 The type or <NULL/> if we can't find it.
366 TOTypeInfoSP
queryTypeInfoByType(sal_Int32 _nDataType
,const OTypeInfoMap
& _rTypeInfo
);
368 /** returns the configuration node name of user defined drivers.
370 the configuration node name of user defined drivers.
373 /** returns the result of the user action when view the query dialog.
375 The parent of the dialog
377 A string resource id for the text which will be displayed as title.
379 A string resource id for the text which will be displayed above the buttons.
380 When the string contains a #1. This will be replaced by the name.
382 When set to <TRUE/>, the all button will be appended.
384 The name of the object to ask for.
386 RET_YES, RET_NO, RET_ALL
388 sal_Int32
askForUserAction(Window
* _pParent
,USHORT _nTitle
,USHORT _nText
,sal_Bool _bAll
,const ::rtl::OUString
& _sName
);
390 /** creates a new view from a query or table
392 The name of the view to be created.
394 The source connection.
395 @param _xSourceObject
396 The object for which a view should be created.
400 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> createView( const ::rtl::OUString
& _sName
401 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
402 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xSourceObject
);
404 /** creates a view with the given command
406 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> createView(
407 const ::rtl::OUString
& _rName
,
408 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
409 const ::rtl::OUString
& _rCommand
412 /** returns the stripped database name.
415 @param _rsDatabaseName
416 Will be filled with the original data source if it is empty.
418 The stripped database name either the registered naem or if it is a file url the last segment.
420 ::rtl::OUString
getStrippedDatabaseName(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDataSource
421 ,::rtl::OUString
& _rsDatabaseName
);
423 /** returns the standard database filter
427 const SfxFilter
* getStandardDatabaseFilter();
429 /** opens a save dialog to store a form or report folder in the current hierachy.
431 The parent of the dialog.
433 a multi service factory which can be used to instantiate usual global services
435 Where to insert the new object.
436 @param _sParentFolder
437 The name of the parent folder.
439 <TRUE/> if a form should be inserted
441 A folder should be inserted
443 The content which should be copied.
445 if <TRUE/> the name of the content must be inserted without any change, otherwise not.
447 <TRUE/> if the insert opertions was successfull, otherwise <FALSE/>.
449 sal_Bool
insertHierachyElement(
451 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
,
452 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XHierarchicalNameContainer
>& _xNames
,
453 const String
& _sParentFolder
,
455 sal_Bool _bCollection
= sal_True
,
456 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContent
>& _xContent
= NULL
,
457 sal_Bool _bMove
= sal_False
460 /** creates a number formatter
462 The connection is needed to create the formatter
464 The multi service factory
466 ::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
);
468 // this completes a help url with the system parameters "Language" and "System"
469 // detect installed locale
470 void AppendConfigToken( ::rtl::OUString
& _rURL
, sal_Bool _bQuestionMark
);
472 // .........................................................................
474 // .........................................................................
475 #endif // DBAUI_TOOLS_HXX