update dev300-m58
[ooovba.git] / dbaccess / source / ui / misc / UITools.cxx
bloba2a6d4150c7fd2a80897210c54cfae2490e30988
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UITools.cxx,v $
10 * $Revision: 1.81.24.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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_TOOLS_HXX
35 #include "UITools.hxx"
36 #endif
37 #ifndef _SFX_DOCFILT_HACK_HXX
38 #include <sfx2/docfilt.hxx>
39 #endif
40 #ifndef _DBACCESS_UI_CALLBACKS_HXX_
41 #include "callbacks.hxx"
42 #endif
43 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
44 #include "dbustrings.hrc"
45 #endif
46 #ifndef _DBU_RESOURCE_HRC_
47 #include "dbu_resource.hrc"
48 #endif
49 #ifndef DBAUI_DLGSAVE_HXX
50 #include "dlgsave.hxx"
51 #endif
52 #ifndef DBAUI_DBTREELISTBOX_HXX
53 #include "dbtreelistbox.hxx"
54 #endif
55 #ifndef DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
56 #include "defaultobjectnamecheck.hxx"
57 #endif
58 #ifndef _COMPHELPER_EXTRACT_HXX_
59 #include <comphelper/extract.hxx>
60 #endif
61 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
62 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
63 #endif
64 #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
65 #include <com/sun/star/sdb/XCompletedConnection.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
68 #include <com/sun/star/sdbc/XDataSource.hpp>
69 #endif
70 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
71 #include <com/sun/star/sdb/SQLContext.hpp>
72 #endif
73 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
74 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
75 #endif
76 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
77 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
78 #endif
79 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
80 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
81 #endif
82 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
83 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
84 #endif
85 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
86 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
87 #endif
88 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
89 #include <com/sun/star/sdbcx/XAppend.hpp>
90 #endif
91 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
92 #include <com/sun/star/sdbc/XRow.hpp>
93 #endif
94 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
95 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
96 #endif
97 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_
98 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
99 #endif
100 #include <com/sun/star/sdbc/ColumnValue.hpp>
101 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
102 #include <com/sun/star/task/XInteractionHandler.hpp>
103 #endif
104 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
105 #include <com/sun/star/ucb/XContent.hpp>
106 #endif
107 #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
108 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
109 #endif
110 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
111 #include <com/sun/star/beans/PropertyValue.hpp>
112 #endif
113 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
114 #include <com/sun/star/container/XIndexAccess.hpp>
115 #endif
116 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
117 #include <com/sun/star/container/XNameContainer.hpp>
118 #endif
119 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
120 #include <com/sun/star/ucb/InteractiveIOException.hpp>
121 #endif
122 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
123 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
124 #endif
125 #ifndef _COM_SUN_STAR_UCB_IOERRORCODE_HPP_
126 #include <com/sun/star/ucb/IOErrorCode.hpp>
127 #endif
128 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
129 #include <toolkit/helper/vclunohelper.hxx>
130 #endif
131 #ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
132 #include <toolkit/awt/vclxwindow.hxx>
133 #endif
134 #ifndef _VCL_STDTEXT_HXX
135 #include <vcl/stdtext.hxx>
136 #endif
137 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
138 #include <com/sun/star/beans/XPropertySetInfo.hpp>
139 #endif
140 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
141 #include <com/sun/star/beans/XPropertySet.hpp>
142 #endif
143 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
144 #include <com/sun/star/container/XNameAccess.hpp>
145 #endif
146 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
147 #include <com/sun/star/container/XContainer.hpp>
148 #endif
149 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
150 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
151 #endif
152 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
153 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
154 #endif
155 #ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
156 #include <com/sun/star/awt/TextAlign.hpp>
157 #endif
158 #ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_
159 #include <com/sun/star/awt/FontDescriptor.hpp>
160 #endif
161 #ifndef _COM_SUN_STAR_AWT_FONTWEIGHT_HPP_
162 #include <com/sun/star/awt/FontWeight.hpp>
163 #endif
164 #ifndef _COM_SUN_STAR_AWT_FONTRELIEF_HPP_
165 #include <com/sun/star/awt/FontRelief.hpp>
166 #endif
167 #ifndef _COM_SUN_STAR_AWT_FONTWIDTH_HPP_
168 #include <com/sun/star/awt/FontWidth.hpp>
169 #endif
170 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
171 #include <com/sun/star/frame/XModel.hpp>
172 #endif
173 #ifndef DBAUI_SBATTRDLG_HRC
174 #include "dlgattr.hrc"
175 #endif
176 #ifndef DBAUI_TYPEINFO_HXX
177 #include "TypeInfo.hxx"
178 #endif
179 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
180 #include "FieldDescriptions.hxx"
181 #endif
182 #ifndef _COMPHELPER_STLTYPES_HXX_
183 #include <comphelper/stl_types.hxx>
184 #endif
185 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
186 #include <comphelper/componentcontext.hxx>
187 #endif
189 #ifndef _SVX_SVXIDS_HRC
190 #include <svx/svxids.hrc>
191 #endif
193 #define ITEMID_HORJUSTIFY SID_ATTR_ALIGN_HOR_JUSTIFY
194 #define ITEMID_VERJUSTIFY SID_ATTR_ALIGN_VER_JUSTIFY
195 //#define ITEMID_ORIENTATION SID_ATTR_ALIGN_ORIENTATION
196 #define ITEMID_LINEBREAK SID_ATTR_ALIGN_LINEBREAK
197 #define ITEMID_MARGIN SID_ATTR_ALIGN_MARGIN
198 #define ITEMID_NUMBERINFO SID_ATTR_NUMBERFORMAT_INFO
200 #ifndef _SFXITEMPOOL_HXX
201 #include <svtools/itempool.hxx>
202 #endif
203 #ifndef _STRING_HXX
204 #include <tools/string.hxx>
205 #endif
206 #ifndef _DBA_DBACCESS_HELPID_HRC_
207 #include "dbaccess_helpid.hrc"
208 #endif
209 #ifndef _SFXITEMSET_HXX //autogen wg. SfxItemSet
210 #include <svtools/itemset.hxx>
211 #endif
212 #ifndef DBACCESS_SBA_GRID_HRC
213 #include "sbagrid.hrc"
214 #endif
215 #ifndef _SFXRNGITEM_HXX
216 #include <svtools/rngitem.hxx>
217 #endif
218 #ifndef _SFXINTITEM_HXX
219 #include <svtools/intitem.hxx>
220 #endif
221 #ifndef _SVX_ALGITEM_HXX
222 #include <svx/algitem.hxx>
223 #endif
224 #ifndef _SVX_NUMINF_HXX
225 #include <svx/numinf.hxx>
226 #endif
227 #define _ZFORLIST_DECLARE_TABLE
228 #ifndef _SVX_NUMINF_HXX
229 #include <svx/numinf.hxx>
230 #endif
231 #ifndef _ZFORLIST_HXX
232 #include <svtools/zforlist.hxx>
233 #endif
234 #ifndef DBAUI_SBATTRDLG_HXX
235 #include "dlgattr.hxx"
236 #endif
237 #ifndef _SV_MSGBOX_HXX
238 #include <vcl/msgbox.hxx>
239 #endif
240 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
241 #include <com/sun/star/container/XChild.hpp>
242 #endif
243 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
244 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
245 #endif
246 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
247 #include <com/sun/star/util/XNumberFormatter.hpp>
248 #endif
249 #ifndef _DBU_MISC_HRC_
250 #include "dbu_misc.hrc"
251 #endif
252 #ifndef _DBAUI_SQLMESSAGE_HXX_
253 #include "sqlmessage.hxx"
254 #endif
255 #ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
256 #include <com/sun/star/util/NumberFormat.hpp>
257 #endif
258 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
259 #include <com/sun/star/util/URL.hpp>
260 #endif
261 #ifndef _SV_TOOLBOX_HXX
262 #include <vcl/toolbox.hxx>
263 #endif
264 #ifndef _DBAUI_DLGSIZE_HXX
265 #include "dlgsize.hxx"
266 #endif
267 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
268 #include <svtools/editbrowsebox.hxx>
269 #endif
270 #ifndef _UTL_CONFIGMGR_HXX_
271 #include <unotools/configmgr.hxx>
272 #endif
273 #ifndef INCLUDED_SVTOOLS_HELPOPT_HXX
274 #include <svtools/helpopt.hxx>
275 #endif
276 #ifndef _UCBHELPER_CONTENT_HXX
277 #include <ucbhelper/content.hxx>
278 #endif
279 #ifndef _URLOBJ_HXX
280 #include <tools/urlobj.hxx>
281 #endif
282 #ifndef TOOLS_DIAGNOSE_EX_H
283 #include <tools/diagnose_ex.h>
284 #endif
285 #ifndef _NUMUNO_HXX
286 #include <svtools/numuno.hxx>
287 #endif
288 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
289 #include <svtools/pathoptions.hxx>
290 #endif
291 #ifndef SVTOOLS_FILENOTATION_HXX_
292 #include <svtools/filenotation.hxx>
293 #endif
294 #ifndef _SVT_FILEVIEW_HXX
295 #include <svtools/fileview.hxx>
296 #endif
297 #ifndef _CONNECTIVITY_FILE_VALUE_HXX_
298 #include <connectivity/FValue.hxx>
299 #endif
301 // .........................................................................
302 namespace dbaui
304 // .........................................................................
305 using namespace ::dbtools;
306 using namespace ::comphelper;
307 using namespace ::com::sun::star::uno;
308 using namespace ::com::sun::star::task;
309 using namespace ::com::sun::star::sdbcx;
310 using namespace ::com::sun::star::sdbc;
311 using namespace ::com::sun::star::sdb;
312 using namespace ::com::sun::star::util;
313 using namespace ::com::sun::star::ucb;
314 using namespace ::com::sun::star::beans;
315 using namespace ::com::sun::star::container;
316 using namespace ::com::sun::star::lang;
317 using namespace ::com::sun::star::ui::dialogs;
318 using namespace ::svt;
319 using ::com::sun::star::ucb::InteractiveIOException;
320 using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
321 using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
322 using ::com::sun::star::frame::XModel;
324 // -----------------------------------------------------------------------------
325 SQLExceptionInfo createConnection( const ::rtl::OUString& _rsDataSourceName,
326 const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
327 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
328 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
329 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
331 Reference<XPropertySet> xProp;
334 xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
336 catch(Exception&)
339 SQLExceptionInfo aInfo;
341 return createConnection(xProp,_rMF,_rEvtLst,_rOUTConnection);
343 // -----------------------------------------------------------------------------
344 SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
345 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
346 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
347 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
349 SQLExceptionInfo aInfo;
350 if ( !_xDataSource.is() )
352 OSL_ENSURE(0,"createConnection: coult not retrieve the data source!");
353 return aInfo;
356 ::rtl::OUString sPwd, sUser;
357 sal_Bool bPwdReq = sal_False;
360 _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
361 bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
362 _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
364 catch(Exception&)
366 OSL_ENSURE(0,"createConnection: error while retrieving data source properties!");
372 if(bPwdReq && !sPwd.getLength())
373 { // password required, but empty -> connect using an interaction handler
374 Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
375 if (!xConnectionCompletion.is())
377 OSL_ENSURE(0,"createConnection: missing an interface ... need an error message here!");
379 else
380 { // instantiate the default SDB interaction handler
381 Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_SDB_INTERACTION_HANDLER), UNO_QUERY);
382 if (!xHandler.is())
384 OSL_ENSURE(sal_False, "createConnection: could not instantiate an interaction handler!");
385 // ShowServiceNotAvailableError(NULL, String(SERVICE_SDB_INTERACTION_HANDLER), sal_True);
386 // TODO: a real parent!
388 else
389 _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
392 else
394 Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
395 _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
397 // be notified when connection is in disposing
398 Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
399 if (xComponent.is() && _rEvtLst.is())
400 xComponent->addEventListener(_rEvtLst);
402 catch(SQLContext& e) { aInfo = SQLExceptionInfo(e); }
403 catch(SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
404 catch(SQLException& e) { aInfo = SQLExceptionInfo(e); }
405 catch(Exception&) { OSL_ENSURE(0,"SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
407 // showError(aInfo);
409 return aInfo;
411 // -----------------------------------------------------------------------------
412 Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
413 Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
415 ::comphelper::ComponentContext aContext( _rxORB );
416 Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
418 Reference< XDataSource > xDatasource;
419 Any aError;
420 SQLExceptionInfo aSQLError;
423 xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
425 catch(const WrappedTargetException& e)
427 InteractiveIOException aIOException;
428 if ( ( e.TargetException >>= aIOException )
429 && ( ( aIOException.Code == IOErrorCode_NO_FILE )
430 || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
434 String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
435 OFileNotation aTransformer( e.Message );
436 sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
437 aSQLError = SQLExceptionInfo( sErrorMessage ).get();
439 else
441 aSQLError = SQLExceptionInfo( e.TargetException );
442 if ( !aSQLError.isValid() )
443 aError = e.TargetException;
446 catch( const Exception& )
448 DBG_UNHANDLED_EXCEPTION();
451 if ( xDatasource.is() )
452 return xDatasource;
454 if ( aSQLError.isValid() )
456 if ( _pErrorInfo )
458 *_pErrorInfo = aSQLError;
460 else
462 showError( aSQLError, _pErrorMessageParent, _rxORB );
466 return Reference<XDataSource>();
468 // -----------------------------------------------------------------------------
469 Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
471 Reference< XInterface > xRet;
472 Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
473 if ( xDocumentDataSource.is() )
474 xRet = xDocumentDataSource->getDatabaseDocument();
476 if ( !xRet.is() )
478 Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
479 if ( xOfficeDoc.is() )
480 xRet = xOfficeDoc->getDataSource();
483 return xRet;
485 // -----------------------------------------------------------------------------
486 void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XMultiServiceFactory >& _xFactory)
488 OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
489 ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent),_xFactory);
492 // -----------------------------------------------------------------------------
493 ::std::vector< Reference<XNameAccess> > getKeyColumns(const Reference<XIndexAccess >& _rxKeys,
494 sal_Int32 _nKeyType)
496 // use keys and indexes for excat postioning
497 // first the keys
498 ::std::vector< Reference<XNameAccess> > vRet;
499 if(_rxKeys.is())
501 Reference<XPropertySet> xProp;
502 for(sal_Int32 i=0;i< _rxKeys->getCount();++i)
504 _rxKeys->getByIndex(i) >>= xProp;
505 sal_Int32 nKeyType = 0;
506 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
507 if(_nKeyType == nKeyType)
509 Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY);
510 OSL_ENSURE(xKeyColsSup.is(),"Columnsupplier is null!");
511 vRet.push_back(xKeyColsSup->getColumns());
516 return vRet;
518 // -----------------------------------------------------------------------------
520 TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
521 sal_Int32 _nType,
522 const ::rtl::OUString& _sTypeName,
523 const ::rtl::OUString& _sCreateParams,
524 sal_Int32 _nPrecision,
525 sal_Int32 _nScale,
526 sal_Bool _bAutoIncrement,
527 sal_Bool& _brForceToType)
529 TOTypeInfoSP pTypeInfo;
530 _brForceToType = sal_False;
531 // search for type
532 ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
533 OTypeInfoMap::const_iterator aIter = aPair.first;
534 if(aIter != _rTypeInfo.end()) // compare with end is correct here
536 for(;aIter != aPair.second;++aIter)
538 // search the best matching type
539 #ifdef DBG_UTIL
540 ::rtl::OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
541 sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
542 sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
543 sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
544 #endif
545 if ( (
546 !_sTypeName.getLength()
547 || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
549 && (
551 !aIter->second->aCreateParams.getLength()
552 && !_sCreateParams.getLength()
554 || (
555 (aIter->second->nPrecision >= _nPrecision)
556 && (aIter->second->nMaximumScale >= _nScale)
557 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
561 break;
564 if (aIter == aPair.second)
566 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
568 sal_Int32 nPrec = aIter->second->nPrecision;
569 sal_Int32 nScale = aIter->second->nMaximumScale;
570 // search the best matching type (now comparing the local names)
571 if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
572 && (nPrec >= _nPrecision)
573 && (nScale >= _nScale)
574 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
577 OSL_ENSURE(sal_False,
578 ( ::rtl::OString("getTypeInfoFromType: assuming column type ")
579 += ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), gsl_getSystemTextEncoding())
580 += ::rtl::OString("\" (expected type name ")
581 += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
582 += ::rtl::OString(" matches the type's local name).")).getStr());
583 break;
588 if (aIter == aPair.second)
589 { // no match for the names, no match for the local names
590 // -> drop the precision and the scale restriction, accept any type with the property
591 // type id (nType)
593 //OSL_ENSURE(sal_False,
594 // ( ::rtl::OString("getTypeInfoFromType: did not find a matching type")
595 // += ::rtl::OString(" (expected type name: ")
596 // += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
597 // += ::rtl::OString(")! Defaulting to the first matching type.")).getStr());
598 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
600 // search the best matching type (now comparing the local names)
601 #ifdef DBG_UTIL
602 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
603 #endif
604 sal_Int32 nPrec = aIter->second->nPrecision;
605 sal_Int32 nScale = aIter->second->nMaximumScale;
606 if ( (nPrec >= _nPrecision)
607 && (nScale >= _nScale)
608 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
610 break;
613 if (aIter == aPair.second)
615 if ( _bAutoIncrement )
617 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
619 // search the best matching type (now comparing the local names)
620 #ifdef DBG_UTIL
621 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
622 #endif
623 sal_Int32 nScale = aIter->second->nMaximumScale;
624 if ( (nScale >= _nScale)
625 && (aIter->second->bAutoIncrement == _bAutoIncrement)
627 break;
629 if ( aIter == aPair.second )
631 // try it without the auto increment flag
632 pTypeInfo = getTypeInfoFromType(_rTypeInfo,
633 _nType,
634 _sTypeName,
635 _sCreateParams,
636 _nPrecision,
637 _nScale,
638 sal_False,
639 _brForceToType);
641 else
642 pTypeInfo = aIter->second;
644 else
646 pTypeInfo = aPair.first->second;
647 _brForceToType = sal_True;
650 else
651 pTypeInfo = aIter->second;
653 else
655 ::comphelper::TStringMixEqualFunctor aCase(sal_False);
656 // search for typeinfo where the typename is equal _sTypeName
657 OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
658 OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
659 for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
661 if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
663 pTypeInfo = typeInfoLoop->second;
664 break;
669 OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
670 return pTypeInfo;
672 // -----------------------------------------------------------------------------
673 void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
674 const String& _rsTypeNames,
675 OTypeInfoMap& _rTypeInfoMap,
676 ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
678 if(!_rxConnection.is())
679 return;
680 Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
681 Reference< XRow> xRow(xRs,UNO_QUERY);
682 // Information for a single SQL type
683 if(xRs.is())
685 static const ::rtl::OUString aB1 = ::rtl::OUString::createFromAscii(" [ ");
686 static const ::rtl::OUString aB2 = ::rtl::OUString::createFromAscii(" ]");
687 Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
688 ::connectivity::ORowSetValue aValue;
689 ::std::vector<sal_Int32> aTypes;
690 ::std::vector<sal_Bool> aNullable;
691 // Loop on the result set until we reach end of file
692 while (xRs->next())
694 TOTypeInfoSP pInfo(new OTypeInfo());
695 sal_Int32 nPos = 1;
696 if ( aTypes.empty() )
698 sal_Int32 nCount = xResultSetMetaData->getColumnCount();
699 if ( nCount < 1 )
700 nCount = 18;
701 aTypes.reserve(nCount+1);
702 aTypes.push_back(-1);
703 aNullable.push_back(sal_False);
704 for (sal_Int32 j = 1; j <= nCount ; ++j)
706 aTypes.push_back(xResultSetMetaData->getColumnType(j));
707 aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
711 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
712 pInfo->aTypeName = aValue;
713 ++nPos;
714 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
715 pInfo->nType = aValue;
716 ++nPos;
717 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
718 pInfo->nPrecision = aValue;
719 ++nPos;
720 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
721 pInfo->aLiteralPrefix = aValue;
722 ++nPos;
723 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
724 pInfo->aLiteralSuffix = aValue;
725 ++nPos;
726 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
727 pInfo->aCreateParams = aValue;
728 ++nPos;
729 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
730 pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
731 ++nPos;
732 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
733 pInfo->bCaseSensitive = (sal_Bool)aValue;
734 ++nPos;
735 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
736 pInfo->nSearchType = aValue;
737 ++nPos;
738 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
739 pInfo->bUnsigned = (sal_Bool)aValue;
740 ++nPos;
741 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
742 pInfo->bCurrency = (sal_Bool)aValue;
743 ++nPos;
744 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
745 pInfo->bAutoIncrement = (sal_Bool)aValue;
746 ++nPos;
747 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
748 pInfo->aLocalTypeName = aValue;
749 ++nPos;
750 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
751 pInfo->nMinimumScale = aValue;
752 ++nPos;
753 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
754 pInfo->nMaximumScale = aValue;
755 nPos = 18;
756 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
758 // check if values are less than zero like it happens in a oracle jdbc driver
759 if( pInfo->nPrecision < 0)
760 pInfo->nPrecision = 0;
761 if( pInfo->nMinimumScale < 0)
762 pInfo->nMinimumScale = 0;
763 if( pInfo->nMaximumScale < 0)
764 pInfo->nMaximumScale = 0;
766 String aName;
767 switch(pInfo->nType)
769 case DataType::CHAR:
770 aName = _rsTypeNames.GetToken(TYPE_CHAR);
771 break;
772 case DataType::VARCHAR:
773 aName = _rsTypeNames.GetToken(TYPE_TEXT);
774 break;
775 case DataType::DECIMAL:
776 aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
777 break;
778 case DataType::NUMERIC:
779 aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
780 break;
781 case DataType::BIGINT:
782 aName = _rsTypeNames.GetToken(TYPE_BIGINT);
783 break;
784 case DataType::FLOAT:
785 aName = _rsTypeNames.GetToken(TYPE_FLOAT);
786 break;
787 case DataType::DOUBLE:
788 aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
789 break;
790 case DataType::LONGVARCHAR:
791 aName = _rsTypeNames.GetToken(TYPE_MEMO);
792 break;
793 case DataType::LONGVARBINARY:
794 aName = _rsTypeNames.GetToken(TYPE_IMAGE);
795 break;
796 case DataType::DATE:
797 aName = _rsTypeNames.GetToken(TYPE_DATE);
798 break;
799 case DataType::TIME:
800 aName = _rsTypeNames.GetToken(TYPE_TIME);
801 break;
802 case DataType::TIMESTAMP:
803 aName = _rsTypeNames.GetToken(TYPE_DATETIME);
804 break;
805 case DataType::BIT:
806 case DataType::BOOLEAN:
807 aName = _rsTypeNames.GetToken(TYPE_BOOL);
808 break;
809 case DataType::TINYINT:
810 aName = _rsTypeNames.GetToken(TYPE_TINYINT);
811 break;
812 case DataType::SMALLINT:
813 aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
814 break;
815 case DataType::INTEGER:
816 aName = _rsTypeNames.GetToken(TYPE_INTEGER);
817 break;
818 case DataType::REAL:
819 aName = _rsTypeNames.GetToken(TYPE_REAL);
820 break;
821 case DataType::BINARY:
822 aName = _rsTypeNames.GetToken(TYPE_BINARY);
823 break;
824 case DataType::VARBINARY:
825 aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
826 break;
827 case DataType::SQLNULL:
828 aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
829 break;
830 case DataType::OBJECT:
831 aName = _rsTypeNames.GetToken(TYPE_OBJECT);
832 break;
833 case DataType::DISTINCT:
834 aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
835 break;
836 case DataType::STRUCT:
837 aName = _rsTypeNames.GetToken(TYPE_STRUCT);
838 break;
839 case DataType::ARRAY:
840 aName = _rsTypeNames.GetToken(TYPE_ARRAY);
841 break;
842 case DataType::BLOB:
843 aName = _rsTypeNames.GetToken(TYPE_BLOB);
844 break;
845 case DataType::CLOB:
846 aName = _rsTypeNames.GetToken(TYPE_CLOB);
847 break;
848 case DataType::REF:
849 aName = _rsTypeNames.GetToken(TYPE_REF);
850 break;
851 case DataType::OTHER:
852 aName = _rsTypeNames.GetToken(TYPE_OTHER);
853 break;
855 if ( aName.Len() )
857 pInfo->aUIName = aName.GetBuffer();
858 pInfo->aUIName += aB1;
860 pInfo->aUIName += pInfo->aTypeName;
861 if ( aName.Len() )
862 pInfo->aUIName += aB2;
863 // Now that we have the type info, save it in the multimap
864 _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
866 // for a faster index access
867 _rTypeInfoIters.reserve(_rTypeInfoMap.size());
869 OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
870 OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
871 for(;aIter != aEnd;++aIter)
872 _rTypeInfoIters.push_back(aIter);
874 // Close the result set/statement.
876 ::comphelper::disposeComponent(xRs);
879 // -----------------------------------------------------------------------------
880 void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
882 _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
883 _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
884 _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
885 _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
886 _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
887 _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
888 _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
889 if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
890 _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
891 // set autoincrement value when available
892 // and only set when the entry is not empty, that lets the value in the column untouched
893 if ( _pFieldDesc->IsAutoIncrement() && _pFieldDesc->GetAutoIncrementValue().getLength() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
894 _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
896 // -----------------------------------------------------------------------------
897 ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
899 OSL_ENSURE(_xMetaData.is(),"No MetaData!");
900 ::rtl::OUString sDefaultName = _sName;
903 ::rtl::OUString sCatalog,sSchema,sCompsedName;
904 if(_xMetaData->supportsCatalogsInTableDefinitions())
908 Reference< XConnection> xCon = _xMetaData->getConnection();
909 if ( xCon.is() )
910 sCatalog = xCon->getCatalog();
911 if ( !sCatalog.getLength() )
913 Reference<XResultSet> xRes = _xMetaData->getCatalogs();
914 Reference<XRow> xRow(xRes,UNO_QUERY);
915 while(xRes.is() && xRes->next())
917 sCatalog = xRow->getString(1);
918 if(!xRow->wasNull())
919 break;
923 catch(const SQLException&)
927 if(_xMetaData->supportsSchemasInTableDefinitions())
929 sSchema = _xMetaData->getUserName();
931 sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
932 sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
934 catch(const SQLException&)
937 return sDefaultName;
939 // -----------------------------------------------------------------------------
940 sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
942 sal_Bool bRet = sal_False;
943 Reference< XNameAccess > xDataBaseContext(_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
944 if ( xDataBaseContext.is() )
946 bRet = xDataBaseContext->hasByName(_sDataSourceName);
947 if ( !bRet )
948 { // try if this one is a URL
951 bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
953 catch(Exception)
958 return bRet;
960 // -----------------------------------------------------------------------------
961 sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
963 sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
964 switch (_eAlignment)
966 case SVX_HOR_JUSTIFY_STANDARD:
967 case SVX_HOR_JUSTIFY_LEFT: nAlignment = ::com::sun::star::awt::TextAlign::LEFT; break;
968 case SVX_HOR_JUSTIFY_CENTER: nAlignment = ::com::sun::star::awt::TextAlign::CENTER; break;
969 case SVX_HOR_JUSTIFY_RIGHT: nAlignment = ::com::sun::star::awt::TextAlign::RIGHT; break;
970 default:
971 OSL_ENSURE(0,"Invalid TextAlign!");
973 return nAlignment;
975 // -----------------------------------------------------------------------------
976 SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
978 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
979 switch (_nAlignment)
981 case ::com::sun::star::awt::TextAlign::LEFT : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
982 case ::com::sun::star::awt::TextAlign::CENTER : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
983 case ::com::sun::star::awt::TextAlign::RIGHT : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
984 default:
985 OSL_ENSURE(0,"Invalid TextAlign!");
987 return eJustify;
989 // -----------------------------------------------------------------------------
990 float ConvertFontWeight( ::FontWeight eWeight )
992 if( eWeight == WEIGHT_DONTKNOW )
993 return ::com::sun::star::awt::FontWeight::DONTKNOW;
994 else if( eWeight == WEIGHT_THIN )
995 return ::com::sun::star::awt::FontWeight::THIN;
996 else if( eWeight == WEIGHT_ULTRALIGHT )
997 return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
998 else if( eWeight == WEIGHT_LIGHT )
999 return ::com::sun::star::awt::FontWeight::LIGHT;
1000 else if( eWeight == WEIGHT_SEMILIGHT )
1001 return ::com::sun::star::awt::FontWeight::SEMILIGHT;
1002 else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
1003 return ::com::sun::star::awt::FontWeight::NORMAL;
1004 else if( eWeight == WEIGHT_SEMIBOLD )
1005 return ::com::sun::star::awt::FontWeight::SEMIBOLD;
1006 else if( eWeight == WEIGHT_BOLD )
1007 return ::com::sun::star::awt::FontWeight::BOLD;
1008 else if( eWeight == WEIGHT_ULTRABOLD )
1009 return ::com::sun::star::awt::FontWeight::ULTRABOLD;
1010 else if( eWeight == WEIGHT_BLACK )
1011 return ::com::sun::star::awt::FontWeight::BLACK;
1013 OSL_ENSURE(0, "Unknown FontWeigth" );
1014 return ::com::sun::star::awt::FontWeight::DONTKNOW;
1016 // -----------------------------------------------------------------------------
1017 float ConvertFontWidth( ::FontWidth eWidth )
1019 if( eWidth == WIDTH_DONTKNOW )
1020 return ::com::sun::star::awt::FontWidth::DONTKNOW;
1021 else if( eWidth == WIDTH_ULTRA_CONDENSED )
1022 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
1023 else if( eWidth == WIDTH_EXTRA_CONDENSED )
1024 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
1025 else if( eWidth == WIDTH_CONDENSED )
1026 return ::com::sun::star::awt::FontWidth::CONDENSED;
1027 else if( eWidth == WIDTH_SEMI_CONDENSED )
1028 return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
1029 else if( eWidth == WIDTH_NORMAL )
1030 return ::com::sun::star::awt::FontWidth::NORMAL;
1031 else if( eWidth == WIDTH_SEMI_EXPANDED )
1032 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
1033 else if( eWidth == WIDTH_EXPANDED )
1034 return ::com::sun::star::awt::FontWidth::EXPANDED;
1035 else if( eWidth == WIDTH_EXTRA_EXPANDED )
1036 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
1037 else if( eWidth == WIDTH_ULTRA_EXPANDED )
1038 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
1040 OSL_ENSURE(0, "Unknown FontWidth" );
1041 return ::com::sun::star::awt::FontWidth::DONTKNOW;
1043 // -----------------------------------------------------------------------------
1044 ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
1046 ::com::sun::star::awt::FontDescriptor aFD;
1047 aFD.Name = rFont.GetName();
1048 aFD.StyleName = rFont.GetStyleName();
1049 aFD.Height = (sal_Int16)rFont.GetSize().Height();
1050 aFD.Width = (sal_Int16)rFont.GetSize().Width();
1051 aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
1052 aFD.CharSet = rFont.GetCharSet();
1053 aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
1054 aFD.CharacterWidth = ConvertFontWidth( rFont.GetWidthType() );
1055 aFD.Weight = ConvertFontWeight( rFont.GetWeight() );
1056 aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
1057 aFD.Underline = sal::static_int_cast< sal_Int16 >(
1058 rFont.GetUnderline());
1059 aFD.Strikeout = sal::static_int_cast< sal_Int16 >(
1060 rFont.GetStrikeout());
1061 aFD.Orientation = rFont.GetOrientation();
1062 aFD.Kerning = rFont.IsKerning();
1063 aFD.WordLineMode = rFont.IsWordLineMode();
1064 aFD.Type = 0; // ??? => Nur an Metric...
1065 return aFD;
1067 // -----------------------------------------------------------------------------
1068 void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
1069 const Reference<XPropertySet>& xField,
1070 SvNumberFormatter* _pFormatter,
1071 Window* _pParent)
1073 if (xAffectedCol.is() && xField.is())
1077 Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
1078 sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
1079 sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
1081 SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
1082 Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
1083 if (aAlignment.hasValue())
1084 eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
1085 sal_Int32 nFormatKey = 0;
1086 if ( bHasFormat )
1087 nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
1089 sal_uInt16 nFlags = 0;
1090 if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
1092 xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
1093 if (nFlags & TP_ATTR_NUMBER)
1094 xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
1098 catch( const Exception& )
1100 DBG_UNHANDLED_EXCEPTION();
1104 // -----------------------------------------------------------------------------
1105 sal_Bool callColumnFormatDialog(Window* _pParent,
1106 SvNumberFormatter* _pFormatter,
1107 sal_Int32 _nDataType,
1108 sal_Int32& _nFormatKey,
1109 SvxCellHorJustify& _eJustify,
1110 sal_uInt16& _nFlags,
1111 sal_Bool _bHasFormat)
1113 sal_Bool bRet = sal_False;
1114 // the allowed format changes depend of the type of the field ...
1115 _nFlags = TP_ATTR_ALIGN;
1117 if (_bHasFormat)
1118 _nFlags |= TP_ATTR_NUMBER;
1120 // ------------
1121 // UNO->ItemSet
1122 static SfxItemInfo aItemInfos[] =
1124 { 0, 0 },
1125 { SID_ATTR_NUMBERFORMAT_VALUE, SFX_ITEM_POOLABLE },
1126 { SID_ATTR_ALIGN_HOR_JUSTIFY, SFX_ITEM_POOLABLE },
1127 { SID_ATTR_NUMBERFORMAT_ONE_AREA, SFX_ITEM_POOLABLE },
1128 { SID_ATTR_NUMBERFORMAT_INFO, SFX_ITEM_POOLABLE }
1130 static sal_uInt16 aAttrMap[] =
1132 SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
1133 SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
1134 SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
1138 SfxPoolItem* pDefaults[] =
1140 new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
1141 new SfxUInt32Item(SBA_DEF_FMTVALUE),
1142 new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
1143 new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
1144 new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
1147 SfxItemPool* pPool = new SfxItemPool(String::CreateFromAscii("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
1148 pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why
1149 pPool->FreezeIdRanges(); // the same
1151 SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
1152 // fill it
1153 pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
1154 sal_Bool bText = sal_False;
1155 if (_bHasFormat)
1157 // if the col is bound to a text field we have to disallow all non-text formats
1158 if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType))
1160 bText = sal_True;
1161 pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
1162 if (!_pFormatter->IsTextFormat(_nFormatKey))
1163 // text fields can only have text formats
1164 _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguage());
1167 pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
1170 if (!bText)
1172 double dPreviewVal = 1234.56789;
1173 SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
1174 pFormatDescriptor->Put(aFormatter);
1177 { // want the dialog to be destroyed before our set
1178 SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
1179 if (RET_OK == aDlg.Execute())
1181 // ------------
1182 // ItemSet->UNO
1183 // UNO-properties
1184 const SfxItemSet* pSet = aDlg.GetExampleSet();
1185 // (of course we could put the modified items directly into the column, but then the UNO-model
1186 // won't reflect these changes, and why do we have a model, then ?)
1188 // horizontal justify
1189 SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
1191 _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
1193 // format key
1194 if (_nFlags & TP_ATTR_NUMBER)
1196 SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
1197 _nFormatKey = (sal_Int32)pFormat->GetValue();
1199 bRet = sal_True;
1201 // deleted formats
1202 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
1203 if (pResult)
1205 const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
1206 const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
1207 if (pInfoItem && pInfoItem->GetDelCount())
1209 const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
1211 for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
1212 _pFormatter->DeleteEntry(*pDeletedKeys);
1217 delete pFormatDescriptor;
1218 SfxItemPool::Free(pPool);
1219 for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
1220 delete pDefaults[i];
1222 return bRet;
1225 //------------------------------------------------------------------------------
1226 const SfxFilter* getStandardDatabaseFilter()
1228 static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
1229 const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
1230 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
1231 return pFilter;
1235 // -----------------------------------------------------------------------------
1236 sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
1237 const ::rtl::OUString& _sName,
1238 const Reference< XMultiServiceFactory >& _xFactory,
1239 Window* _pParent)
1241 sal_Bool bRet = sal_False;
1242 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1243 if(xChild.is())
1245 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1246 if(xProp.is())
1248 Sequence< ::rtl::OUString > aFilter;
1249 xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
1250 // first check if we have something like SCHEMA.%
1251 sal_Bool bHasToInsert = sal_True;
1252 static ::rtl::OUString sPattern = ::rtl::OUString::createFromAscii("%");
1253 const ::rtl::OUString* pBegin = aFilter.getConstArray();
1254 const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
1255 for (;pBegin != pEnd; ++pBegin)
1257 if(pBegin->indexOf('%') != -1)
1259 sal_Int32 nLen;
1260 if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
1261 bHasToInsert = sal_False;
1262 else if(pBegin->getLength() == 1)
1263 bHasToInsert = sal_False;
1267 bRet = sal_True;
1268 if(bHasToInsert)
1270 if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_xFactory))
1272 String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
1273 OSQLWarningBox( _pParent, aMessage ).Execute();
1274 bRet = sal_False;
1276 else
1278 aFilter.realloc(aFilter.getLength()+1);
1279 aFilter.getArray()[aFilter.getLength()-1] = _sName;
1280 xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
1285 return bRet;
1287 // -----------------------------------------------------------------------------
1288 void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
1290 OSL_ENSURE(_pWindow,"Window can not be null!");
1291 SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
1292 if ( pSystemWindow )
1294 _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
1297 // -----------------------------------------------------------------------------
1298 void adjustToolBoxSize(ToolBox* _pToolBox)
1300 // adjust the toolbox size, otherwise large bitmaps don't fit into
1301 Size aOldSize = _pToolBox->GetSizePixel();
1302 Size aSize = _pToolBox->CalcWindowSizePixel();
1303 if ( !aSize.Width() )
1304 aSize.Width() = aOldSize.Width();
1305 else if ( !aSize.Height() )
1306 aSize.Height() = aOldSize.Height();
1308 Size aTbSize = _pToolBox->GetSizePixel();
1309 if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
1310 (aSize.Height() && aSize.Height() != aTbSize.Height()) )
1312 _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
1313 _pToolBox->Invalidate();
1316 // -----------------------------------------------------------------------------
1317 sal_Bool isHiContrast(Window* _pWindow)
1319 OSL_ENSURE(_pWindow,"Window must be not null!");
1320 Window* pIter = _pWindow;
1321 // while( pIter && pIter->GetBackground().GetColor().GetColor() == COL_TRANSPARENT )
1322 while( pIter )
1324 if ( pIter->GetBackground().GetColor().GetColor() == COL_TRANSPARENT )
1325 pIter = pIter->GetParent();
1326 else
1327 break;
1329 return pIter && pIter->GetBackground().GetColor().IsDark();
1332 // -----------------------------------------------------------------------------
1333 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1335 sal_Int32 nColSize = -1;
1336 sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1337 if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1339 Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
1340 nColSize = aSizeMM.Width() * 10;
1343 Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
1345 DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1346 if ( aColumnSizeDlg.Execute() )
1348 sal_Int32 nValue = aColumnSizeDlg.GetValue();
1349 if ( -1 == nValue )
1350 { // default width
1351 nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1353 else
1355 Size aSizeMM( nValue / 10, 0 );
1356 nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
1358 _pBox->SetColumnWidth( _nColId, nValue );
1361 // -----------------------------------------------------------------------------
1362 // check if SQL92 name checking is enabled
1363 sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1365 return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK );
1367 // -----------------------------------------------------------------------------
1368 sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1370 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS );
1373 // -----------------------------------------------------------------------------
1374 sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1376 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME );
1379 // -----------------------------------------------------------------------------
1380 void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1381 sal_Bool& _rAutoIncrementValueEnabled,
1382 ::rtl::OUString& _rsAutoIncrementValue)
1384 if ( _xDatasource.is() )
1386 OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1387 Sequence<PropertyValue> aInfo;
1388 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
1390 // search the right propertyvalue
1391 const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
1392 aInfo.getConstArray() + aInfo.getLength(),
1393 ::std::bind2nd(TPropertyValueEqualFunctor(),PROPERTY_AUTOINCREMENTCREATION));
1394 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1395 pValue->Value >>= _rsAutoIncrementValue;
1396 pValue =::std::find_if(aInfo.getConstArray(),
1397 aInfo.getConstArray() + aInfo.getLength(),
1398 ::std::bind2nd(TPropertyValueEqualFunctor(),::rtl::OUString::createFromAscii("IsAutoRetrievingEnabled") ));
1399 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1400 pValue->Value >>= _rAutoIncrementValueEnabled;
1403 // -----------------------------------------------------------------------------
1404 void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1405 sal_Bool& _rAutoIncrementValueEnabled,
1406 ::rtl::OUString& _rsAutoIncrementValue)
1408 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1409 if(xChild.is())
1411 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1412 fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1415 // -----------------------------------------------------------------------------
1416 ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
1418 if ( !_rsDatabaseName.getLength() && _xDataSource.is() )
1422 _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
1424 catch(const Exception& )
1426 DBG_UNHANDLED_EXCEPTION();
1429 ::rtl::OUString sName = _rsDatabaseName;
1430 INetURLObject aURL(sName);
1431 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1432 sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
1433 return sName;
1435 // -----------------------------------------------------------------------------
1436 void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
1438 Any aLocale =
1439 ::utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty( ::utl::ConfigManager::LOCALE );
1440 ::rtl::OUString sLocaleStr;
1441 if ( !( aLocale >>= sLocaleStr ) )
1442 // fallback is english
1443 sLocaleStr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
1445 // query part exists?
1446 if ( _bQuestionMark )
1447 // no, so start with '?'
1448 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
1449 else
1450 // yes, so only append with '&'
1451 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
1453 // set parameters
1454 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Language="));
1455 _rURL += sLocaleStr;
1456 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&System="));
1457 _rURL += SvtHelpOptions().GetSystem();
1460 namespace
1462 // -----------------------------------------------------------------------
1464 sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
1466 sal_Bool bRet = sal_False;
1467 ::rtl::OUString sAnchor;
1471 ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
1472 Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
1473 if ( ( aCnt.getPropertyValue( ::rtl::OUString::createFromAscii( "AnchorName" ) ) >>= sAnchor ) )
1476 if ( sAnchor.getLength() > 0 )
1478 _rAnchor = sAnchor;
1479 bRet = sal_True;
1482 else
1484 DBG_ERRORFILE( "Property 'AnchorName' is missing" );
1487 catch( Exception& )
1491 return bRet;
1493 // .........................................................................
1494 } // annonymous
1495 // .........................................................................
1496 // -----------------------------------------------------------------------------
1497 ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName,const sal_Int32 _nHelpId)
1499 ::com::sun::star::util::URL aURL;
1500 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.help://" ) );
1501 aURL.Complete += _sModuleName;
1502 aURL.Complete += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
1503 aURL.Complete += ::rtl::OUString::valueOf(_nHelpId);
1505 ::rtl::OUString sAnchor;
1506 ::rtl::OUString sTempURL = aURL.Complete;
1507 AppendConfigToken( sTempURL, sal_True );
1508 sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
1509 AppendConfigToken(aURL.Complete,sal_True);
1510 if ( bHasAnchor )
1512 aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
1513 aURL.Complete += sAnchor;
1515 return aURL;
1517 // -----------------------------------------------------------------------------
1518 void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1520 OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1521 if ( _rxFormatter.is() )
1523 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1525 Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1526 SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1527 OSL_ENSURE(pSupplierImpl,"No Supplier!");
1529 if ( pSupplierImpl )
1531 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1532 pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1536 // -----------------------------------------------------------------------------
1537 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1539 TOTypeInfoSP pTypeInfo;
1540 // first we search for a type which supports autoIncrement
1541 OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
1542 OTypeInfoMap::const_iterator aEnd = _rTypeInfo.end();
1543 for(;aIter != aEnd;++aIter)
1545 // OJ: we don't want to set an autoincrement column to be key
1546 // because we don't have the possiblity to know how to create
1547 // such auto increment column later on
1548 // so until we know how to do it, we create a column without autoincrement
1549 // if ( !aIter->second->bAutoIncrement )
1550 { // therefor we have searched
1551 if ( aIter->second->nType == DataType::INTEGER )
1553 pTypeInfo = aIter->second; // alternative
1554 break;
1556 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
1557 pTypeInfo = aIter->second; // alternative
1558 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
1559 pTypeInfo = aIter->second; // alternative
1562 if ( !pTypeInfo.get() ) // just a fallback
1563 pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
1565 OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
1566 return pTypeInfo;
1568 // -----------------------------------------------------------------------------
1569 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1571 OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
1572 if(aIter != _rTypeInfo.end())
1573 return aIter->second;
1574 // fall back if the type is unknown
1575 TOTypeInfoSP pTypeInfo;
1576 switch(_nDataType)
1578 case DataType::TINYINT:
1579 if( pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo))
1580 break;
1581 // run through
1582 case DataType::SMALLINT:
1583 if( pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo))
1584 break;
1585 // run through
1586 case DataType::INTEGER:
1587 if( pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo))
1588 break;
1589 // run through
1590 case DataType::FLOAT:
1591 if( pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo))
1592 break;
1593 // run through
1594 case DataType::DATE:
1595 case DataType::TIME:
1596 if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1598 if( pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo))
1599 break;
1601 // run through
1602 case DataType::TIMESTAMP:
1603 case DataType::REAL:
1604 case DataType::BIGINT:
1605 if ( pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) )
1606 break;
1607 // run through
1608 case DataType::DOUBLE:
1609 if ( pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) )
1610 break;
1611 // run through
1612 case DataType::NUMERIC:
1613 pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
1614 break;
1615 case DataType::DECIMAL:
1616 if ( pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) )
1617 break;
1618 if ( pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) )
1619 break;
1620 break;
1621 case DataType::VARCHAR:
1622 if ( pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo) )
1623 break;
1624 break;
1625 default:
1627 } // switch(_nDataType)
1628 if ( !pTypeInfo )
1630 ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
1631 sal_Bool bForce = sal_True;
1632 pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
1633 } // if ( !pTypeInfo )
1634 OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1635 return pTypeInfo;
1637 // -----------------------------------------------------------------------------
1638 sal_Int32 askForUserAction(Window* _pParent,USHORT _nTitle,USHORT _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
1640 vos::OGuard aGuard( Application::GetSolarMutex() );
1641 String aMsg = String(ModuleRes(_nText));
1642 aMsg.SearchAndReplace(String::CreateFromAscii("%1"),String(_sName));
1643 OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
1644 if ( _bAll )
1646 aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
1647 aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1649 return aAsk.Execute();
1652 // -----------------------------------------------------------------------------
1653 namespace
1655 static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1657 ::rtl::OUString sSDBCLevelStatement( _rStatement );
1660 Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1661 Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1662 xAnalyzer->setQuery( _rStatement );
1663 sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
1665 catch( const Exception& )
1667 DBG_UNHANDLED_EXCEPTION();
1669 return sSDBCLevelStatement;
1673 // -----------------------------------------------------------------------------
1674 Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
1675 const ::rtl::OUString& _rCommand )
1677 Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1678 Reference< XNameAccess > xViews;
1679 if(xSup.is())
1680 xViews = xSup->getViews();
1681 Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1682 OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1683 if(!xFact.is())
1684 return NULL;
1686 Reference<XPropertySet> xView = xFact->createDataDescriptor();
1687 if ( !xView.is() )
1688 return NULL;
1690 ::rtl::OUString sCatalog,sSchema,sTable;
1691 ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1692 _rName,
1693 sCatalog,
1694 sSchema,
1695 sTable,
1696 ::dbtools::eInDataManipulation);
1698 xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1699 xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1700 xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1702 xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
1704 Reference<XAppend> xAppend(xViews,UNO_QUERY);
1705 if(xAppend.is())
1706 xAppend->appendByDescriptor(xView);
1708 xView = NULL;
1709 // we need to reget the view because after appending it it is no longer valid
1710 // but this time it isn't a view object it is a table object with type "VIEW"
1711 Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1712 Reference< XNameAccess > xTables;
1713 if ( xTabSup.is() )
1715 xTables = xTabSup->getTables();
1716 if ( xTables.is() && xTables->hasByName( _rName ) )
1717 xTables->getByName( _rName ) >>= xView;
1720 return xView;
1723 // -----------------------------------------------------------------------------
1724 Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
1725 ,const Reference<XPropertySet>& _rxSourceObject)
1727 ::rtl::OUString sCommand;
1728 Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
1729 if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
1731 _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
1733 sal_Bool bEscapeProcessing( sal_False );
1734 OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
1735 if ( bEscapeProcessing )
1736 sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1738 else
1740 sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
1741 sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1743 return createView( _rName, _rxConnection, sCommand );
1746 // -----------------------------------------------------------------------------
1747 sal_Bool insertHierachyElement( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
1748 const Reference<XHierarchicalNameContainer>& _xNames,
1749 const String& _sParentFolder,
1750 sal_Bool _bForm,
1751 sal_Bool _bCollection,
1752 const Reference<XContent>& _xContent,
1753 sal_Bool _bMove)
1755 OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1756 if ( !_xNames.is() )
1757 return sal_False;
1759 Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1760 ::rtl::OUString sName = _sParentFolder;
1761 if ( _xNames->hasByHierarchicalName(sName) )
1763 Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
1764 xNameAccess.set(xChild,UNO_QUERY);
1765 if ( !xNameAccess.is() && xChild.is() )
1766 xNameAccess.set(xChild->getParent(),UNO_QUERY);
1769 OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1770 if ( !xNameAccess.is() )
1771 return sal_False;
1773 ::rtl::OUString sNewName;
1774 Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1775 if ( xProp.is() )
1776 xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
1778 if ( !_bMove || !sNewName.getLength() )
1780 String sTargetName,sLabel;
1781 if ( !sNewName.getLength() || xNameAccess->hasByName(sNewName) )
1783 if ( sNewName.getLength() )
1784 sTargetName = sNewName;
1785 else
1786 sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
1787 sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
1788 sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
1791 // here we have everything needed to create a new query object ...
1792 HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
1793 // ... ehm, except a new name
1794 OSaveAsDlg aAskForName( _pParent,
1795 _rxORB,
1796 sTargetName,
1797 sLabel,
1798 aNameChecker,
1799 SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1800 if ( RET_OK != aAskForName.Execute() )
1801 // cancelled by the user
1802 return sal_False;
1804 sNewName = aAskForName.getName();
1807 else if ( xNameAccess->hasByName(sNewName) )
1809 String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1810 sError.SearchAndReplaceAscii("#",sNewName);
1811 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
1816 Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1817 Sequence< Any > aArguments(3);
1818 PropertyValue aValue;
1819 // set as folder
1820 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
1821 aValue.Value <<= sNewName;
1822 aArguments[0] <<= aValue;
1823 //parent
1824 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
1825 aValue.Value <<= xNameAccess;
1826 aArguments[1] <<= aValue;
1828 aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1829 aValue.Value <<= _xContent;
1830 aArguments[2] <<= aValue;
1832 ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
1834 Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
1835 Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1836 xNameContainer->insertByName( sNewName, makeAny( xNew ) );
1838 catch( const IllegalArgumentException& e )
1840 ::dbtools::throwGenericSQLException( e.Message, e.Context );
1842 catch( const Exception& )
1844 DBG_UNHANDLED_EXCEPTION();
1845 return sal_False;
1848 return sal_True;
1850 // -----------------------------------------------------------------------------
1851 Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF )
1853 // ---------------------------------------------------------------
1854 // create a formatter working with the connections format supplier
1855 Reference< XNumberFormatter > xFormatter;
1859 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True,_rMF));
1861 if ( xSupplier.is() )
1863 // create a new formatter
1864 xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
1865 _rMF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
1866 if ( xFormatter.is() )
1867 xFormatter->attachNumberFormatsSupplier(xSupplier);
1870 catch(const Exception&)
1872 DBG_UNHANDLED_EXCEPTION();
1874 return xFormatter;
1878 // .........................................................................
1879 } // dbaui
1880 // .........................................................................