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