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_INC_UITOOLS_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_INC_UITOOLS_HXX
22 #include <connectivity/dbexception.hxx>
23 #include <comphelper/stl_types.hxx>
24 #include "TypeInfo.hxx"
25 #include <editeng/svxenum.hxx>
26 #include <vcl/taskpanelist.hxx>
27 #include <connectivity/dbtools.hxx>
33 // we only need forward decl here
34 namespace com
{ namespace sun
{ namespace star
{
36 namespace beans
{ class XPropertySet
;}
40 class XHierarchicalNameContainer
;
48 struct FontDescriptor
;
52 class XDatabaseMetaData
;
58 class XNumberFormatter
;
60 namespace ucb
{ class XContent
; }
61 namespace uno
{ class XComponentContext
; }
70 namespace vcl
{ class Window
; }
72 namespace vcl
{ class Font
; }
73 class SvNumberFormatter
;
79 /** creates a new connection and appends the eventlistener
80 @param _rsDataSourceName name of the datasource
81 @param _xDatabaseContext the database context
82 @param _rxContext the UNO component context
83 @param _rEvtLst the eventlistener which will be added to the new created connection
84 @param _rOUTConnection this parameter will be filled with the new created connection
85 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
87 ::dbtools::SQLExceptionInfo
createConnection(
88 const OUString
& _rsDataSourceName
,
89 const css::uno::Reference
< css::container::XNameAccess
>& _xDatabaseContext
,
90 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
,
91 css::uno::Reference
< css::lang::XEventListener
>& _rEvtLst
,
92 css::uno::Reference
< css::sdbc::XConnection
>& _rOUTConnection
);
93 /** creates a new connection and appends the eventlistener
94 @param _xDataSource the datasource
95 @param _rxContext the UNO component context
96 @param _rEvtLst the eventlistener which will be added to the new created connection
97 @param _rOUTConnection this parameter will be filled with the new created connection
98 @return SQLExceptionInfo contains a SQLException, SQLContext or a SQLWarning when they araised else .isValid() will return false
100 ::dbtools::SQLExceptionInfo
createConnection(
101 const css::uno::Reference
< css::beans::XPropertySet
>& _xDataSource
,
102 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
,
103 css::uno::Reference
< css::lang::XEventListener
>& _rEvtLst
,
104 css::uno::Reference
< css::sdbc::XConnection
>& _rOUTConnection
);
106 /** creates a error dialog which displays the SQLExceptionInfo. Also it supports a "more" button where detailed information are available
107 @param _rInfo the error which should be shown, if the info is not valid no error dialog will appear
108 @param _pParent the parent of the error dialog
109 @param _rxContext need to create the dialog
111 void showError( const ::dbtools::SQLExceptionInfo
& _rInfo
,
112 vcl::Window
* _pParent
,
113 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
115 /** fills a map and a vector with localized type names
116 @param _rxConnection the connection to access the metadata
117 @param _rsTypeNames a list of localized type names separated with ';'
118 @param _rTypeInfoMap the filled map with the type names
119 @param _rTypeInfoIters the vector filled with map iterators
121 void fillTypeInfo( const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,
122 const OUString
& _rsTypeNames
,
123 OTypeInfoMap
& _rTypeInfoMap
,
124 ::std::vector
<OTypeInfoMap::iterator
>& _rTypeInfoIters
);
126 /** fill a column with data of a field description
127 @param _rxColumn the column which should be filled
128 @param _pFieldDesc the source of the data
130 class OFieldDescription
;
131 void setColumnProperties( const css::uno::Reference
< css::beans::XPropertySet
>& _rxColumn
,
132 const OFieldDescription
* _pFieldDesc
);
134 OUString
createDefaultName( const css::uno::Reference
< css::sdbc::XDatabaseMetaData
>& _xMetaData
,
135 const css::uno::Reference
< css::container::XNameAccess
>& _xTables
,
136 const OUString
& _sName
);
138 /** checks if the given name exists in the database context
140 bool checkDataSourceAvailable( const OUString
& _sDataSourceName
,
141 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
143 /** maps SvxCellHorJustify to css::awt::TextAlign
144 @param SvxCellHorJustify& _eAlignment
145 @return the corresponding css::awt::TextAlign
147 sal_Int32
mapTextAllign(const SvxCellHorJustify
& _eAlignment
);
149 /** retrieves a data source given by name or URL, and displays an error if this fails
151 Any <type scope="css::sdbc">SQLException</type>s which occur will be displayed.
152 Additionally, and Exceptions which indicate a data source name pointing to a non-existent database
153 URL will also be denoted. Yet more additionally, and other exceptions will be forwarded to
154 a <type scope="css::sdb">InteractionHandler</type>.
156 @param _rDataSourceName
157 the URL of the database document, or the name of a registered data source
158 @param _pErrorMessageParent
159 the window to use as parent for error messages
161 a service factory to use for components to be created
163 takes the error info in case of failure. If <NULL/>, the error is displayed to the user.
165 css::uno::Reference
< css::sdbc::XDataSource
>
167 const OUString
& _rDataSourceName
,
168 vcl::Window
* _pErrorMessageParent
,
169 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
,
170 ::dbtools::SQLExceptionInfo
* _pErrorInfo
173 /** returns either the model when data source is given as parameter,
174 or returns a data source when a model is given.
175 @param _xObject Either a data source or a model.
177 css::uno::Reference
< css::uno::XInterface
> getDataSourceOrModel(const css::uno::Reference
< css::uno::XInterface
>& _xObject
);
179 /** maps css::awt::TextAlign to SvxCellHorJustify
180 @param css::awt::TextAlign& _nAlignment
181 @return the corresponding SvxCellHorJustify
183 SvxCellHorJustify
mapTextJustify(sal_Int32 _nAlignment
);
185 /** call the format dialog and set the selected format at the column
186 @param _xAffectedCol Font to be converted
187 @param _xField Font to be converted
189 void callColumnFormatDialog(const css::uno::Reference
< css::beans::XPropertySet
>& _xAffectedCol
,
190 const css::uno::Reference
< css::beans::XPropertySet
>& _xField
,
191 SvNumberFormatter
* _pFormatter
,
192 vcl::Window
* _pParent
);
194 /** second variant of the function before
196 bool callColumnFormatDialog(vcl::Window
* _pParent
,
197 SvNumberFormatter
* _pFormatter
,
198 sal_Int32 _nDataType
,
199 sal_Int32
& _nFormatKey
,
200 SvxCellHorJustify
& _eJustify
,
202 /** append a name to tablefilter of a datasource
203 @param _xConnection the connection is need to get the datasource
204 @param _sName the name which should be appended
205 @param _rxContext needed to check if datasource is available
206 @param _pParent needed when an error must be shown
207 @return false when datsource is not available otherwise true
209 bool appendToFilter(const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
210 const OUString
& _sName
,
211 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
,
212 vcl::Window
* _pParent
);
214 /** notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search _pWindow.
216 The window which is used to search for the SystemWindow.
218 The window which should be added or removed on the TaskPaneList.
220 The member function which should be called at the SystemWindow when found.
222 ::comphelper::mem_fun(&TaskPaneList::AddWindow)
223 ::comphelper::mem_fun(&TaskPaneList::RemoveWindow)
225 void notifySystemWindow(vcl::Window
* _pWindow
,
226 vcl::Window
* _pToRegister
,
227 const ::comphelper::mem_fun1_t
<TaskPaneList
,vcl::Window
*>& _rMemFunc
);
229 /** adjustToolBoxSize checks if the size of the ToolBox is still valid. If not it will be resized.
231 The Toolbox which should be resized.
233 void adjustToolBoxSize(ToolBox
* _pToolBox
);
235 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox
* _pBox
, sal_uInt16 _nColId
);
237 /** check if SQL92 name checking is enabled
239 Used to get the datasource as parent from the connection.
241 <TRUE/> if so otherwise <FALSE/>
243 bool isSQL92CheckEnabled(const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
);
245 /** check if the alias name of the table should be added at select statements
247 Used to get the datasource as parent from the connection.
249 <TRUE/> if so otherwise <FALSE/>
251 bool isAppendTableAliasEnabled(const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
);
253 /** determines whether when generating SQL statements, AS should be placed before a table alias
255 bool generateAsBeforeTableAlias( const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
);
257 /** fills the bool and string value with information out of the datasource info property
259 Asked for the properties.
260 @param _rAutoIncrementValueEnabled
261 <OUT/> Set to sal_True when the property was set in the datasource.
262 @param _rsAutoIncrementValue
263 <OUT/> Set to the value when the property was set in the datasource.
265 void fillAutoIncrementValue(const css::uno::Reference
< css::beans::XPropertySet
>& _xDatasource
266 ,bool& _rAutoIncrementValueEnabled
267 ,OUString
& _rsAutoIncrementValue
);
269 /** fills the bool and string value with information out of the datasource info property
271 Used to get the datasource as parent from the connection.
272 @param _rAutoIncrementValueEnabled
273 <OUT/> Set to sal_True when the property was set in the datasource.
274 @param _rsAutoIncrementValue
275 <OUT/> Set to the value when the property was set in the datasource.
277 void fillAutoIncrementValue(const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
278 ,bool& _rAutoIncrementValueEnabled
279 ,OUString
& _rsAutoIncrementValue
);
281 /** creates the URL or the help agent
285 The URL for the help agent to dispatch.
287 css::util::URL
createHelpAgentURL(const OUString
& _sModuleName
,const OString
& _rHelpId
);
289 /** set the evaluation flag at the number formatter
292 void setEvalDateFormatForFormatter(css::uno::Reference
< css::util::XNumberFormatter
>& _rxFormatter
);
294 /** query for a type info which can be used to create a primary key column
296 The map which contains all available types.
298 The type info which can be used to create a primary key column.
300 TOTypeInfoSP
queryPrimaryKeyType(const OTypeInfoMap
& _rTypeInfo
);
302 /** query for a specific type.
304 The type we are searching.
306 The map which contains all available types.
308 The type or <NULL/> if we can't find it.
310 TOTypeInfoSP
queryTypeInfoByType(sal_Int32 _nDataType
,const OTypeInfoMap
& _rTypeInfo
);
312 /** returns the configuration node name of user defined drivers.
314 the configuration node name of user defined drivers.
317 /** returns the result of the user action when view the query dialog.
319 The parent of the dialog
321 A string resource id for the text which will be displayed as title.
323 A string resource id for the text which will be displayed above the buttons.
324 When the string contains a #1. This will be replaced by the name.
326 When set to <TRUE/>, the all button will be appended.
328 The name of the object to ask for.
330 RET_YES, RET_NO, RET_ALL
332 sal_Int32
askForUserAction(vcl::Window
* _pParent
,sal_uInt16 _nTitle
,sal_uInt16 _nText
,bool _bAll
,const OUString
& _sName
);
334 /** creates a new view from a query or table
336 The name of the view to be created.
338 The source connection.
339 @param _xSourceObject
340 The object for which a view should be created.
344 css::uno::Reference
< css::beans::XPropertySet
> createView( const OUString
& _sName
345 ,const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
346 ,const css::uno::Reference
< css::beans::XPropertySet
>& _xSourceObject
);
348 /** creates a view with the given command
350 css::uno::Reference
< css::beans::XPropertySet
> createView(
351 const OUString
& _rName
,
352 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
353 const OUString
& _rCommand
356 /** returns the stripped database name.
359 @param _rsDatabaseName
360 Will be filled with the original data source if it is empty.
362 The stripped database name either the registered name or if it is a file url the last segment.
364 OUString
getStrippedDatabaseName(const css::uno::Reference
< css::beans::XPropertySet
>& _xDataSource
365 ,OUString
& _rsDatabaseName
);
367 /** returns the standard database filter
371 std::shared_ptr
<const SfxFilter
> getStandardDatabaseFilter();
373 /** opens a save dialog to store a form or report folder in the current hierarchy.
375 The parent of the dialog.
377 a multi service factory which can be used to instantiate usual global services
379 Where to insert the new object.
380 @param _sParentFolder
381 The name of the parent folder.
383 <TRUE/> if a form should be inserted
385 A folder should be inserted
387 The content which should be copied.
389 if <TRUE/> the name of the content must be inserted without any change, otherwise not.
391 <TRUE/> if the insert opertions was successful, otherwise <FALSE/>.
393 bool insertHierachyElement(
394 vcl::Window
* _pParent
,
395 const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
,
396 const css::uno::Reference
< css::container::XHierarchicalNameContainer
>& _xNames
,
397 const OUString
& _sParentFolder
,
399 bool _bCollection
= true,
400 const css::uno::Reference
< css::ucb::XContent
>& _xContent
= nullptr,
404 /** creates a number formatter
406 The connection is needed to create the formatter
408 The multi service factory
410 css::uno::Reference
< css::util::XNumberFormatter
> getNumberFormatter(const css::uno::Reference
< css::sdbc::XConnection
>& _rxConnection
,const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
412 // this completes a help url with the system parameters "Language" and "System"
413 // detect installed locale
414 void AppendConfigToken( OUString
& _rURL
, bool _bQuestionMark
);
417 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_UITOOLS_HXX
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */