1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26
27 #ifndef DBAUI_TOOLS_HXX
28 #include "UITools.hxx"
29 #endif
30 #ifndef _SFX_DOCFILT_HACK_HXX
31 #include <sfx2/docfilt.hxx>
32 #endif
33 #ifndef _DBACCESS_UI_CALLBACKS_HXX_
34 #include "callbacks.hxx"
35 #endif
36 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
37 #include "dbustrings.hrc"
38 #endif
39 #ifndef _DBU_RESOURCE_HRC_
40 #include "dbu_resource.hrc"
41 #endif
42 #ifndef DBAUI_DLGSAVE_HXX
43 #include "dlgsave.hxx"
44 #endif
45 #ifndef DBAUI_DBTREELISTBOX_HXX
46 #include "dbtreelistbox.hxx"
47 #endif
48 #ifndef DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
49 #include "defaultobjectnamecheck.hxx"
50 #endif
51 #ifndef _COMPHELPER_EXTRACT_HXX_
52 #include <comphelper/extract.hxx>
53 #endif
54 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
55 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
58 #include <com/sun/star/sdb/XCompletedConnection.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
61 #include <com/sun/star/sdbc/XDataSource.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
64 #include <com/sun/star/sdb/SQLContext.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
67 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
70 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
73 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
76 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
79 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
82 #include <com/sun/star/sdbcx/XAppend.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
85 #include <com/sun/star/sdbc/XRow.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
88 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_
91 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
92 #endif
93 #include <com/sun/star/sdbc/ColumnValue.hpp>
94 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
95 #include <com/sun/star/task/XInteractionHandler.hpp>
96 #endif
97 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
98 #include <com/sun/star/ucb/XContent.hpp>
99 #endif
100 #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
101 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
102 #endif
103 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
104 #include <com/sun/star/beans/PropertyValue.hpp>
105 #endif
106 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
107 #include <com/sun/star/container/XIndexAccess.hpp>
108 #endif
109 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
110 #include <com/sun/star/container/XNameContainer.hpp>
111 #endif
112 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
113 #include <com/sun/star/ucb/InteractiveIOException.hpp>
114 #endif
115 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
116 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
117 #endif
118 #ifndef _COM_SUN_STAR_UCB_IOERRORCODE_HPP_
119 #include <com/sun/star/ucb/IOErrorCode.hpp>
120 #endif
121 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
122 #include <toolkit/helper/vclunohelper.hxx>
123 #endif
124 #ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
125 #include <toolkit/awt/vclxwindow.hxx>
126 #endif
127 #ifndef _VCL_STDTEXT_HXX
128 #include <vcl/stdtext.hxx>
129 #endif
130 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
131 #include <com/sun/star/beans/XPropertySetInfo.hpp>
132 #endif
133 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
134 #include <com/sun/star/beans/XPropertySet.hpp>
135 #endif
136 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
137 #include <com/sun/star/container/XNameAccess.hpp>
138 #endif
139 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
140 #include <com/sun/star/container/XContainer.hpp>
141 #endif
142 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
143 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
144 #endif
145 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
146 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
147 #endif
148 #ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_
149 #include <com/sun/star/awt/TextAlign.hpp>
150 #endif
151 #ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_
152 #include <com/sun/star/awt/FontDescriptor.hpp>
153 #endif
154 #ifndef _COM_SUN_STAR_AWT_FONTWEIGHT_HPP_
155 #include <com/sun/star/awt/FontWeight.hpp>
156 #endif
157 #ifndef _COM_SUN_STAR_AWT_FONTRELIEF_HPP_
158 #include <com/sun/star/awt/FontRelief.hpp>
159 #endif
160 #ifndef _COM_SUN_STAR_AWT_FONTWIDTH_HPP_
161 #include <com/sun/star/awt/FontWidth.hpp>
162 #endif
163 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
164 #include <com/sun/star/frame/XModel.hpp>
165 #endif
166 #ifndef DBAUI_SBATTRDLG_HRC
167 #include "dlgattr.hrc"
168 #endif
169 #ifndef DBAUI_TYPEINFO_HXX
170 #include "TypeInfo.hxx"
171 #endif
172 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
173 #include "FieldDescriptions.hxx"
174 #endif
175 #ifndef _COMPHELPER_STLTYPES_HXX_
176 #include <comphelper/stl_types.hxx>
177 #endif
178 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
179 #include <comphelper/componentcontext.hxx>
180 #endif
181
182 #ifndef _SVX_SVXIDS_HRC
183 #include <svx/svxids.hrc>
184 #endif
185
186 #define ITEMID_HORJUSTIFY SID_ATTR_ALIGN_HOR_JUSTIFY
187 #define ITEMID_VERJUSTIFY SID_ATTR_ALIGN_VER_JUSTIFY
188 //#define ITEMID_ORIENTATION SID_ATTR_ALIGN_ORIENTATION
189 #define ITEMID_LINEBREAK SID_ATTR_ALIGN_LINEBREAK
190 #define ITEMID_MARGIN SID_ATTR_ALIGN_MARGIN
191 #define ITEMID_NUMBERINFO SID_ATTR_NUMBERFORMAT_INFO
192
193 #ifndef _SFXITEMPOOL_HXX
194 #include <svl/itempool.hxx>
195 #endif
196 #ifndef _STRING_HXX
197 #include <tools/string.hxx>
198 #endif
199 #ifndef _DBA_DBACCESS_HELPID_HRC_
200 #include "dbaccess_helpid.hrc"
201 #endif
202 #ifndef _SFXITEMSET_HXX //autogen wg. SfxItemSet
203 #include <svl/itemset.hxx>
204 #endif
205 #ifndef DBACCESS_SBA_GRID_HRC
206 #include "sbagrid.hrc"
207 #endif
208 #ifndef _SFXRNGITEM_HXX
209 #include <svl/rngitem.hxx>
210 #endif
211 #ifndef _SFXINTITEM_HXX
212 #include <svl/intitem.hxx>
213 #endif
214 #ifndef _SVX_ALGITEM_HXX
215 #include <svx/algitem.hxx>
216 #endif
217 #ifndef _SVX_NUMINF_HXX
218 #include <svx/numinf.hxx>
219 #endif
220 #define _ZFORLIST_DECLARE_TABLE
221 #ifndef _SVX_NUMINF_HXX
222 #include <svx/numinf.hxx>
223 #endif
224 #ifndef _ZFORLIST_HXX
225 #include <svl/zforlist.hxx>
226 #endif
227 #ifndef DBAUI_SBATTRDLG_HXX
228 #include "dlgattr.hxx"
229 #endif
230 #ifndef _SV_MSGBOX_HXX
231 #include <vcl/msgbox.hxx>
232 #endif
233 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
234 #include <com/sun/star/container/XChild.hpp>
235 #endif
236 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
237 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
238 #endif
239 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
240 #include <com/sun/star/util/XNumberFormatter.hpp>
241 #endif
242 #ifndef _DBU_MISC_HRC_
243 #include "dbu_misc.hrc"
244 #endif
245 #ifndef _DBAUI_SQLMESSAGE_HXX_
246 #include "sqlmessage.hxx"
247 #endif
248 #ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
249 #include <com/sun/star/util/NumberFormat.hpp>
250 #endif
251 #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
252 #include <com/sun/star/util/URL.hpp>
253 #endif
254 #ifndef _SV_TOOLBOX_HXX
255 #include <vcl/toolbox.hxx>
256 #endif
257 #ifndef _DBAUI_DLGSIZE_HXX
258 #include "dlgsize.hxx"
259 #endif
260 #ifndef _SVTOOLS_EDITBROWSEBOX_HXX_
261 #include <svtools/editbrowsebox.hxx>
262 #endif
263 #ifndef _UTL_CONFIGMGR_HXX_
264 #include <unotools/configmgr.hxx>
265 #endif
266 #ifndef INCLUDED_SVTOOLS_HELPOPT_HXX
267 #include <svtools/helpopt.hxx>
268 #endif
269 #ifndef _UCBHELPER_CONTENT_HXX
270 #include <ucbhelper/content.hxx>
271 #endif
272 #ifndef _URLOBJ_HXX
273 #include <tools/urlobj.hxx>
274 #endif
275 #ifndef TOOLS_DIAGNOSE_EX_H
276 #include <tools/diagnose_ex.h>
277 #endif
278 #ifndef _NUMUNO_HXX
279 #include <svl/numuno.hxx>
280 #endif
281 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
282 #include <unotools/pathoptions.hxx>
283 #endif
284 #ifndef SVTOOLS_FILENOTATION_HXX_
285 #include <svl/filenotation.hxx>
286 #endif
287 #ifndef _SVT_FILEVIEW_HXX
288 #include <svtools/fileview.hxx>
289 #endif
290 #ifndef _CONNECTIVITY_FILE_VALUE_HXX_
291 #include <connectivity/FValue.hxx>
292 #endif
293 #include <functional>
294
295 // .........................................................................
296 namespace dbaui
297 {
298 // .........................................................................
299 using namespace ::dbtools;
300 using namespace ::comphelper;
301 using namespace ::com::sun::star::uno;
302 using namespace ::com::sun::star::task;
303 using namespace ::com::sun::star::sdbcx;
304 using namespace ::com::sun::star::sdbc;
305 using namespace ::com::sun::star::sdb;
306 using namespace ::com::sun::star::util;
307 using namespace ::com::sun::star::ucb;
308 using namespace ::com::sun::star::beans;
309 using namespace ::com::sun::star::container;
310 using namespace ::com::sun::star::lang;
311 using namespace ::com::sun::star::ui::dialogs;
312 using namespace ::svt;
313 using ::com::sun::star::ucb::InteractiveIOException;
314 using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
315 using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
316 using ::com::sun::star::frame::XModel;
317
318 // -----------------------------------------------------------------------------
createConnection(const::rtl::OUString & _rsDataSourceName,const Reference<::com::sun::star::container::XNameAccess> & _xDatabaseContext,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rMF,Reference<::com::sun::star::lang::XEventListener> & _rEvtLst,Reference<::com::sun::star::sdbc::XConnection> & _rOUTConnection)319 SQLExceptionInfo createConnection( const ::rtl::OUString& _rsDataSourceName,
320 const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
321 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
322 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
323 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
324 {
325 Reference<XPropertySet> xProp;
326 try
327 {
328 xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
329 }
330 catch(Exception&)
331 {
332 }
333 SQLExceptionInfo aInfo;
334
335 return createConnection(xProp,_rMF,_rEvtLst,_rOUTConnection);
336 }
337 // -----------------------------------------------------------------------------
createConnection(const Reference<::com::sun::star::beans::XPropertySet> & _xDataSource,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rMF,Reference<::com::sun::star::lang::XEventListener> & _rEvtLst,Reference<::com::sun::star::sdbc::XConnection> & _rOUTConnection)338 SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
339 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
340 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
341 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
342 {
343 SQLExceptionInfo aInfo;
344 if ( !_xDataSource.is() )
345 {
346 OSL_ENSURE(0,"createConnection: coult not retrieve the data source!");
347 return aInfo;
348 }
349
350 ::rtl::OUString sPwd, sUser;
351 sal_Bool bPwdReq = sal_False;
352 try
353 {
354 _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
355 bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
356 _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
357 }
358 catch(Exception&)
359 {
360 OSL_ENSURE(0,"createConnection: error while retrieving data source properties!");
361 }
362
363
364 try
365 {
366 if(bPwdReq && !sPwd.getLength())
367 { // password required, but empty -> connect using an interaction handler
368 Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
369 if (!xConnectionCompletion.is())
370 {
371 OSL_ENSURE(0,"createConnection: missing an interface ... need an error message here!");
372 }
373 else
374 { // instantiate the default SDB interaction handler
375 Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY);
376 if (!xHandler.is())
377 {
378 OSL_ENSURE(sal_False, "createConnection: could not instantiate an interaction handler!");
379 // ShowServiceNotAvailableError(NULL, String(SERVICE_TASK_INTERACTION_HANDLER), sal_True);
380 // TODO: a real parent!
381 }
382 else
383 _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
384 }
385 }
386 else
387 {
388 Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
389 _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
390 }
391 // be notified when connection is in disposing
392 Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
393 if (xComponent.is() && _rEvtLst.is())
394 xComponent->addEventListener(_rEvtLst);
395 }
396 catch(SQLContext& e) { aInfo = SQLExceptionInfo(e); }
397 catch(SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
398 catch(SQLException& e) { aInfo = SQLExceptionInfo(e); }
399 catch(Exception&) { OSL_ENSURE(0,"SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
400
401 // showError(aInfo);
402
403 return aInfo;
404 }
405 // -----------------------------------------------------------------------------
getDataSourceByName(const::rtl::OUString & _rDataSourceName,Window * _pErrorMessageParent,Reference<XMultiServiceFactory> _rxORB,::dbtools::SQLExceptionInfo * _pErrorInfo)406 Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
407 Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
408 {
409 ::comphelper::ComponentContext aContext( _rxORB );
410 Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
411
412 Reference< XDataSource > xDatasource;
413 Any aError;
414 SQLExceptionInfo aSQLError;
415 try
416 {
417 xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
418 }
419 catch(const WrappedTargetException& e)
420 {
421 InteractiveIOException aIOException;
422 if ( ( e.TargetException >>= aIOException )
423 && ( ( aIOException.Code == IOErrorCode_NO_FILE )
424 || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
425 )
426 )
427 {
428 String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
429 OFileNotation aTransformer( e.Message );
430 sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
431 aSQLError = SQLExceptionInfo( sErrorMessage ).get();
432 }
433 else
434 {
435 aSQLError = SQLExceptionInfo( e.TargetException );
436 if ( !aSQLError.isValid() )
437 aError = e.TargetException;
438 }
439 }
440 catch( const Exception& )
441 {
442 DBG_UNHANDLED_EXCEPTION();
443 }
444
445 if ( xDatasource.is() )
446 return xDatasource;
447
448 if ( aSQLError.isValid() )
449 {
450 if ( _pErrorInfo )
451 {
452 *_pErrorInfo = aSQLError;
453 }
454 else
455 {
456 showError( aSQLError, _pErrorMessageParent, _rxORB );
457 }
458 }
459
460 return Reference<XDataSource>();
461 }
462 // -----------------------------------------------------------------------------
getDataSourceOrModel(const Reference<XInterface> & _xObject)463 Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
464 {
465 Reference< XInterface > xRet;
466 Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
467 if ( xDocumentDataSource.is() )
468 xRet = xDocumentDataSource->getDatabaseDocument();
469
470 if ( !xRet.is() )
471 {
472 Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
473 if ( xOfficeDoc.is() )
474 xRet = xOfficeDoc->getDataSource();
475 }
476
477 return xRet;
478 }
479 // -----------------------------------------------------------------------------
showError(const SQLExceptionInfo & _rInfo,Window * _pParent,const Reference<XMultiServiceFactory> & _xFactory)480 void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XMultiServiceFactory >& _xFactory)
481 {
482 OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
483 ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent),_xFactory);
484 }
485
486 // -----------------------------------------------------------------------------
getKeyColumns(const Reference<XIndexAccess> & _rxKeys,sal_Int32 _nKeyType)487 ::std::vector< Reference<XNameAccess> > getKeyColumns(const Reference<XIndexAccess >& _rxKeys,
488 sal_Int32 _nKeyType)
489 {
490 // use keys and indexes for exact positioning
491 // first the keys
492 ::std::vector< Reference<XNameAccess> > vRet;
493 if(_rxKeys.is())
494 {
495 Reference<XPropertySet> xProp;
496 for(sal_Int32 i=0;i< _rxKeys->getCount();++i)
497 {
498 _rxKeys->getByIndex(i) >>= xProp;
499 sal_Int32 nKeyType = 0;
500 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
501 if(_nKeyType == nKeyType)
502 {
503 Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY);
504 OSL_ENSURE(xKeyColsSup.is(),"Columnsupplier is null!");
505 vRet.push_back(xKeyColsSup->getColumns());
506 }
507 }
508 }
509
510 return vRet;
511 }
512 // -----------------------------------------------------------------------------
513
getTypeInfoFromType(const OTypeInfoMap & _rTypeInfo,sal_Int32 _nType,const::rtl::OUString & _sTypeName,const::rtl::OUString & _sCreateParams,sal_Int32 _nPrecision,sal_Int32 _nScale,sal_Bool _bAutoIncrement,sal_Bool & _brForceToType)514 TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
515 sal_Int32 _nType,
516 const ::rtl::OUString& _sTypeName,
517 const ::rtl::OUString& _sCreateParams,
518 sal_Int32 _nPrecision,
519 sal_Int32 _nScale,
520 sal_Bool _bAutoIncrement,
521 sal_Bool& _brForceToType)
522 {
523 TOTypeInfoSP pTypeInfo;
524 _brForceToType = sal_False;
525 // search for type
526 ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
527 OTypeInfoMap::const_iterator aIter = aPair.first;
528 if(aIter != _rTypeInfo.end()) // compare with end is correct here
529 {
530 for(;aIter != aPair.second;++aIter)
531 {
532 // search the best matching type
533 #ifdef DBG_UTIL
534 ::rtl::OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
535 sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
536 sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
537 sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
538 #endif
539 if ( (
540 !_sTypeName.getLength()
541 || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
542 )
543 && (
544 (
545 !aIter->second->aCreateParams.getLength()
546 && !_sCreateParams.getLength()
547 )
548 || (
549 (aIter->second->nPrecision >= _nPrecision)
550 && (aIter->second->nMaximumScale >= _nScale)
551 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
552 )
553 )
554 )
555 break;
556 }
557
558 if (aIter == aPair.second)
559 {
560 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
561 {
562 sal_Int32 nPrec = aIter->second->nPrecision;
563 sal_Int32 nScale = aIter->second->nMaximumScale;
564 // search the best matching type (now comparing the local names)
565 if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
566 && (nPrec >= _nPrecision)
567 && (nScale >= _nScale)
568 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
569 )
570 {
571 OSL_ENSURE(sal_False,
572 ( ::rtl::OString("getTypeInfoFromType: assuming column type ")
573 += ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), gsl_getSystemTextEncoding())
574 += ::rtl::OString("\" (expected type name ")
575 += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
576 += ::rtl::OString(" matches the type's local name).")).getStr());
577 break;
578 }
579 }
580 }
581
582 if (aIter == aPair.second)
583 { // no match for the names, no match for the local names
584 // -> drop the precision and the scale restriction, accept any type with the property
585 // type id (nType)
586
587 //OSL_ENSURE(sal_False,
588 // ( ::rtl::OString("getTypeInfoFromType: did not find a matching type")
589 // += ::rtl::OString(" (expected type name: ")
590 // += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
591 // += ::rtl::OString(")! Defaulting to the first matching type.")).getStr());
592 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
593 {
594 // search the best matching type (now comparing the local names)
595 #ifdef DBG_UTIL
596 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
597 #endif
598 sal_Int32 nPrec = aIter->second->nPrecision;
599 sal_Int32 nScale = aIter->second->nMaximumScale;
600 if ( (nPrec >= _nPrecision)
601 && (nScale >= _nScale)
602 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
603 )
604 break;
605 }
606 }
607 if (aIter == aPair.second)
608 {
609 if ( _bAutoIncrement )
610 {
611 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
612 {
613 // search the best matching type (now comparing the local names)
614 #ifdef DBG_UTIL
615 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
616 #endif
617 sal_Int32 nScale = aIter->second->nMaximumScale;
618 if ( (nScale >= _nScale)
619 && (aIter->second->bAutoIncrement == _bAutoIncrement)
620 )
621 break;
622 }
623 if ( aIter == aPair.second )
624 {
625 // try it without the auto increment flag
626 pTypeInfo = getTypeInfoFromType(_rTypeInfo,
627 _nType,
628 _sTypeName,
629 _sCreateParams,
630 _nPrecision,
631 _nScale,
632 sal_False,
633 _brForceToType);
634 }
635 else
636 pTypeInfo = aIter->second;
637 }
638 else
639 {
640 pTypeInfo = aPair.first->second;
641 _brForceToType = sal_True;
642 }
643 }
644 else
645 pTypeInfo = aIter->second;
646 }
647 else
648 {
649 ::comphelper::TStringMixEqualFunctor aCase(sal_False);
650 // search for typeinfo where the typename is equal _sTypeName
651 OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
652 OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
653 for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
654 {
655 if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
656 {
657 pTypeInfo = typeInfoLoop->second;
658 break;
659 }
660 }
661 }
662
663 OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
664 return pTypeInfo;
665 }
666 // -----------------------------------------------------------------------------
fillTypeInfo(const Reference<::com::sun::star::sdbc::XConnection> & _rxConnection,const String & _rsTypeNames,OTypeInfoMap & _rTypeInfoMap,::std::vector<OTypeInfoMap::iterator> & _rTypeInfoIters)667 void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
668 const String& _rsTypeNames,
669 OTypeInfoMap& _rTypeInfoMap,
670 ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
671 {
672 if(!_rxConnection.is())
673 return;
674 Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
675 Reference< XRow> xRow(xRs,UNO_QUERY);
676 // Information for a single SQL type
677 if(xRs.is())
678 {
679 static const ::rtl::OUString aB1 = ::rtl::OUString::createFromAscii(" [ ");
680 static const ::rtl::OUString aB2 = ::rtl::OUString::createFromAscii(" ]");
681 Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
682 ::connectivity::ORowSetValue aValue;
683 ::std::vector<sal_Int32> aTypes;
684 ::std::vector<sal_Bool> aNullable;
685 // Loop on the result set until we reach end of file
686 while (xRs->next())
687 {
688 TOTypeInfoSP pInfo(new OTypeInfo());
689 sal_Int32 nPos = 1;
690 if ( aTypes.empty() )
691 {
692 sal_Int32 nCount = xResultSetMetaData->getColumnCount();
693 if ( nCount < 1 )
694 nCount = 18;
695 aTypes.reserve(nCount+1);
696 aTypes.push_back(-1);
697 aNullable.push_back(sal_False);
698 for (sal_Int32 j = 1; j <= nCount ; ++j)
699 {
700 aTypes.push_back(xResultSetMetaData->getColumnType(j));
701 aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
702 }
703 }
704
705 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
706 pInfo->aTypeName = aValue;
707 ++nPos;
708 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
709 pInfo->nType = aValue;
710 ++nPos;
711 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
712 pInfo->nPrecision = aValue;
713 ++nPos;
714 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
715 pInfo->aLiteralPrefix = aValue;
716 ++nPos;
717 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
718 pInfo->aLiteralSuffix = aValue;
719 ++nPos;
720 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
721 pInfo->aCreateParams = aValue;
722 ++nPos;
723 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
724 pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
725 ++nPos;
726 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
727 pInfo->bCaseSensitive = (sal_Bool)aValue;
728 ++nPos;
729 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
730 pInfo->nSearchType = aValue;
731 ++nPos;
732 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
733 pInfo->bUnsigned = (sal_Bool)aValue;
734 ++nPos;
735 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
736 pInfo->bCurrency = (sal_Bool)aValue;
737 ++nPos;
738 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
739 pInfo->bAutoIncrement = (sal_Bool)aValue;
740 ++nPos;
741 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
742 pInfo->aLocalTypeName = aValue;
743 ++nPos;
744 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
745 pInfo->nMinimumScale = aValue;
746 ++nPos;
747 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
748 pInfo->nMaximumScale = aValue;
749 nPos = 18;
750 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
751
752 // check if values are less than zero like it happens in a oracle jdbc driver
753 if( pInfo->nPrecision < 0)
754 pInfo->nPrecision = 0;
755 if( pInfo->nMinimumScale < 0)
756 pInfo->nMinimumScale = 0;
757 if( pInfo->nMaximumScale < 0)
758 pInfo->nMaximumScale = 0;
759
760 String aName;
761 switch(pInfo->nType)
762 {
763 case DataType::CHAR:
764 aName = _rsTypeNames.GetToken(TYPE_CHAR);
765 break;
766 case DataType::VARCHAR:
767 aName = _rsTypeNames.GetToken(TYPE_TEXT);
768 break;
769 case DataType::DECIMAL:
770 aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
771 break;
772 case DataType::NUMERIC:
773 aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
774 break;
775 case DataType::BIGINT:
776 aName = _rsTypeNames.GetToken(TYPE_BIGINT);
777 break;
778 case DataType::FLOAT:
779 aName = _rsTypeNames.GetToken(TYPE_FLOAT);
780 break;
781 case DataType::DOUBLE:
782 aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
783 break;
784 case DataType::LONGVARCHAR:
785 aName = _rsTypeNames.GetToken(TYPE_MEMO);
786 break;
787 case DataType::LONGVARBINARY:
788 aName = _rsTypeNames.GetToken(TYPE_IMAGE);
789 break;
790 case DataType::DATE:
791 aName = _rsTypeNames.GetToken(TYPE_DATE);
792 break;
793 case DataType::TIME:
794 aName = _rsTypeNames.GetToken(TYPE_TIME);
795 break;
796 case DataType::TIMESTAMP:
797 aName = _rsTypeNames.GetToken(TYPE_DATETIME);
798 break;
799 case DataType::BIT:
800 if ( pInfo->aCreateParams.getLength() )
801 {
802 aName = _rsTypeNames.GetToken(TYPE_BIT);
803 break;
804 }
805 // run through
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;
854 }
855 if ( aName.Len() )
856 {
857 pInfo->aUIName = aName.GetBuffer();
858 pInfo->aUIName += aB1;
859 }
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));
865 }
866 // for a faster index access
867 _rTypeInfoIters.reserve(_rTypeInfoMap.size());
868
869 OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
870 OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
871 for(;aIter != aEnd;++aIter)
872 _rTypeInfoIters.push_back(aIter);
873
874 // Close the result set/statement.
875
876 ::comphelper::disposeComponent(xRs);
877 }
878 }
879 // -----------------------------------------------------------------------------
setColumnProperties(const Reference<XPropertySet> & _rxColumn,const OFieldDescription * _pFieldDesc)880 void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
881 {
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 _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
890 if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
891 _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
892 // set autoincrement value when available
893 // and only set when the entry is not empty, that lets the value in the column untouched
894 if ( _pFieldDesc->IsAutoIncrement() && _pFieldDesc->GetAutoIncrementValue().getLength() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
895 _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
896 }
897 // -----------------------------------------------------------------------------
createDefaultName(const Reference<XDatabaseMetaData> & _xMetaData,const Reference<XNameAccess> & _xTables,const::rtl::OUString & _sName)898 ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
899 {
900 OSL_ENSURE(_xMetaData.is(),"No MetaData!");
901 ::rtl::OUString sDefaultName = _sName;
902 try
903 {
904 ::rtl::OUString sCatalog,sSchema,sCompsedName;
905 if(_xMetaData->supportsCatalogsInTableDefinitions())
906 {
907 try
908 {
909 Reference< XConnection> xCon = _xMetaData->getConnection();
910 if ( xCon.is() )
911 sCatalog = xCon->getCatalog();
912 if ( !sCatalog.getLength() )
913 {
914 Reference<XResultSet> xRes = _xMetaData->getCatalogs();
915 Reference<XRow> xRow(xRes,UNO_QUERY);
916 while(xRes.is() && xRes->next())
917 {
918 sCatalog = xRow->getString(1);
919 if(!xRow->wasNull())
920 break;
921 }
922 }
923 }
924 catch(const SQLException&)
925 {
926 }
927 }
928 if(_xMetaData->supportsSchemasInTableDefinitions())
929 {
930 sSchema = _xMetaData->getUserName();
931 }
932 sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
933 sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
934 }
935 catch(const SQLException&)
936 {
937 }
938 return sDefaultName;
939 }
940 // -----------------------------------------------------------------------------
checkDataSourceAvailable(const::rtl::OUString & _sDataSourceName,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _xORB)941 sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
942 {
943 sal_Bool bRet = sal_False;
944 Reference< XNameAccess > xDataBaseContext(_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
945 if ( xDataBaseContext.is() )
946 {
947 bRet = xDataBaseContext->hasByName(_sDataSourceName);
948 if ( !bRet )
949 { // try if this one is a URL
950 try
951 {
952 bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
953 }
954 catch(Exception)
955 {
956 }
957 }
958 }
959 return bRet;
960 }
961 // -----------------------------------------------------------------------------
mapTextAllign(const SvxCellHorJustify & _eAlignment)962 sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
963 {
964 sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
965 switch (_eAlignment)
966 {
967 case SVX_HOR_JUSTIFY_STANDARD:
968 case SVX_HOR_JUSTIFY_LEFT: nAlignment = ::com::sun::star::awt::TextAlign::LEFT; break;
969 case SVX_HOR_JUSTIFY_CENTER: nAlignment = ::com::sun::star::awt::TextAlign::CENTER; break;
970 case SVX_HOR_JUSTIFY_RIGHT: nAlignment = ::com::sun::star::awt::TextAlign::RIGHT; break;
971 default:
972 OSL_ENSURE(0,"Invalid TextAlign!");
973 }
974 return nAlignment;
975 }
976 // -----------------------------------------------------------------------------
mapTextJustify(const sal_Int32 & _nAlignment)977 SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
978 {
979 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
980 switch (_nAlignment)
981 {
982 case ::com::sun::star::awt::TextAlign::LEFT : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
983 case ::com::sun::star::awt::TextAlign::CENTER : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
984 case ::com::sun::star::awt::TextAlign::RIGHT : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
985 default:
986 OSL_ENSURE(0,"Invalid TextAlign!");
987 }
988 return eJustify;
989 }
990 // -----------------------------------------------------------------------------
ConvertFontWeight(::FontWeight eWeight)991 float ConvertFontWeight( ::FontWeight eWeight )
992 {
993 if( eWeight == WEIGHT_DONTKNOW )
994 return ::com::sun::star::awt::FontWeight::DONTKNOW;
995 else if( eWeight == WEIGHT_THIN )
996 return ::com::sun::star::awt::FontWeight::THIN;
997 else if( eWeight == WEIGHT_ULTRALIGHT )
998 return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
999 else if( eWeight == WEIGHT_LIGHT )
1000 return ::com::sun::star::awt::FontWeight::LIGHT;
1001 else if( eWeight == WEIGHT_SEMILIGHT )
1002 return ::com::sun::star::awt::FontWeight::SEMILIGHT;
1003 else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
1004 return ::com::sun::star::awt::FontWeight::NORMAL;
1005 else if( eWeight == WEIGHT_SEMIBOLD )
1006 return ::com::sun::star::awt::FontWeight::SEMIBOLD;
1007 else if( eWeight == WEIGHT_BOLD )
1008 return ::com::sun::star::awt::FontWeight::BOLD;
1009 else if( eWeight == WEIGHT_ULTRABOLD )
1010 return ::com::sun::star::awt::FontWeight::ULTRABOLD;
1011 else if( eWeight == WEIGHT_BLACK )
1012 return ::com::sun::star::awt::FontWeight::BLACK;
1013
1014 OSL_ENSURE(0, "Unknown FontWeigth" );
1015 return ::com::sun::star::awt::FontWeight::DONTKNOW;
1016 }
1017 // -----------------------------------------------------------------------------
ConvertFontWidth(::FontWidth eWidth)1018 float ConvertFontWidth( ::FontWidth eWidth )
1019 {
1020 if( eWidth == WIDTH_DONTKNOW )
1021 return ::com::sun::star::awt::FontWidth::DONTKNOW;
1022 else if( eWidth == WIDTH_ULTRA_CONDENSED )
1023 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
1024 else if( eWidth == WIDTH_EXTRA_CONDENSED )
1025 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
1026 else if( eWidth == WIDTH_CONDENSED )
1027 return ::com::sun::star::awt::FontWidth::CONDENSED;
1028 else if( eWidth == WIDTH_SEMI_CONDENSED )
1029 return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
1030 else if( eWidth == WIDTH_NORMAL )
1031 return ::com::sun::star::awt::FontWidth::NORMAL;
1032 else if( eWidth == WIDTH_SEMI_EXPANDED )
1033 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
1034 else if( eWidth == WIDTH_EXPANDED )
1035 return ::com::sun::star::awt::FontWidth::EXPANDED;
1036 else if( eWidth == WIDTH_EXTRA_EXPANDED )
1037 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
1038 else if( eWidth == WIDTH_ULTRA_EXPANDED )
1039 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
1040
1041 OSL_ENSURE(0, "Unknown FontWidth" );
1042 return ::com::sun::star::awt::FontWidth::DONTKNOW;
1043 }
1044 // -----------------------------------------------------------------------------
CreateFontDescriptor(const Font & rFont)1045 ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
1046 {
1047 ::com::sun::star::awt::FontDescriptor aFD;
1048 aFD.Name = rFont.GetName();
1049 aFD.StyleName = rFont.GetStyleName();
1050 aFD.Height = (sal_Int16)rFont.GetSize().Height();
1051 aFD.Width = (sal_Int16)rFont.GetSize().Width();
1052 aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
1053 aFD.CharSet = rFont.GetCharSet();
1054 aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
1055 aFD.CharacterWidth = ConvertFontWidth( rFont.GetWidthType() );
1056 aFD.Weight = ConvertFontWeight( rFont.GetWeight() );
1057 aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
1058 aFD.Underline = sal::static_int_cast< sal_Int16 >(
1059 rFont.GetUnderline());
1060 aFD.Strikeout = sal::static_int_cast< sal_Int16 >(
1061 rFont.GetStrikeout());
1062 aFD.Orientation = rFont.GetOrientation();
1063 aFD.Kerning = rFont.IsKerning();
1064 aFD.WordLineMode = rFont.IsWordLineMode();
1065 aFD.Type = 0; // ??? => Nur an Metric...
1066 return aFD;
1067 }
1068 // -----------------------------------------------------------------------------
callColumnFormatDialog(const Reference<XPropertySet> & xAffectedCol,const Reference<XPropertySet> & xField,SvNumberFormatter * _pFormatter,Window * _pParent)1069 void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
1070 const Reference<XPropertySet>& xField,
1071 SvNumberFormatter* _pFormatter,
1072 Window* _pParent)
1073 {
1074 if (xAffectedCol.is() && xField.is())
1075 {
1076 try
1077 {
1078 Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
1079 sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
1080 sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
1081
1082 SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
1083 Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
1084 if (aAlignment.hasValue())
1085 eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
1086 sal_Int32 nFormatKey = 0;
1087 if ( bHasFormat )
1088 nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
1089
1090 sal_uInt16 nFlags = 0;
1091 if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
1092 {
1093 xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
1094 if (nFlags & TP_ATTR_NUMBER)
1095 xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
1096
1097 }
1098 }
1099 catch( const Exception& )
1100 {
1101 DBG_UNHANDLED_EXCEPTION();
1102 }
1103 }
1104 }
1105 // -----------------------------------------------------------------------------
callColumnFormatDialog(Window * _pParent,SvNumberFormatter * _pFormatter,sal_Int32 _nDataType,sal_Int32 & _nFormatKey,SvxCellHorJustify & _eJustify,sal_uInt16 & _nFlags,sal_Bool _bHasFormat)1106 sal_Bool callColumnFormatDialog(Window* _pParent,
1107 SvNumberFormatter* _pFormatter,
1108 sal_Int32 _nDataType,
1109 sal_Int32& _nFormatKey,
1110 SvxCellHorJustify& _eJustify,
1111 sal_uInt16& _nFlags,
1112 sal_Bool _bHasFormat)
1113 {
1114 sal_Bool bRet = sal_False;
1115 // the allowed format changes depend of the type of the field ...
1116 _nFlags = TP_ATTR_ALIGN;
1117
1118 if (_bHasFormat)
1119 _nFlags |= TP_ATTR_NUMBER;
1120
1121 // ------------
1122 // UNO->ItemSet
1123 static SfxItemInfo aItemInfos[] =
1124 {
1125 { 0, 0 },
1126 { SID_ATTR_NUMBERFORMAT_VALUE, SFX_ITEM_POOLABLE },
1127 { SID_ATTR_ALIGN_HOR_JUSTIFY, SFX_ITEM_POOLABLE },
1128 { SID_ATTR_NUMBERFORMAT_ONE_AREA, SFX_ITEM_POOLABLE },
1129 { SID_ATTR_NUMBERFORMAT_INFO, SFX_ITEM_POOLABLE }
1130 };
1131 static sal_uInt16 aAttrMap[] =
1132 {
1133 SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
1134 SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
1135 SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
1136 0
1137 };
1138
1139 SfxPoolItem* pDefaults[] =
1140 {
1141 new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
1142 new SfxUInt32Item(SBA_DEF_FMTVALUE),
1143 new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
1144 new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
1145 new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
1146 };
1147
1148 SfxItemPool* pPool = new SfxItemPool(String::CreateFromAscii("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
1149 pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why
1150 pPool->FreezeIdRanges(); // the same
1151
1152 SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
1153 // fill it
1154 pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
1155 sal_Bool bText = sal_False;
1156 if (_bHasFormat)
1157 {
1158 // if the col is bound to a text field we have to disallow all non-text formats
1159 if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType) || (DataType::CLOB == _nDataType))
1160 {
1161 bText = sal_True;
1162 pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
1163 if (!_pFormatter->IsTextFormat(_nFormatKey))
1164 // text fields can only have text formats
1165 _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguage());
1166 }
1167
1168 pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
1169 }
1170
1171 if (!bText)
1172 {
1173 double dPreviewVal = 1234.56789;
1174 SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
1175 pFormatDescriptor->Put(aFormatter);
1176 }
1177
1178 { // want the dialog to be destroyed before our set
1179 SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
1180 if (RET_OK == aDlg.Execute())
1181 {
1182 // ------------
1183 // ItemSet->UNO
1184 // UNO-properties
1185 const SfxItemSet* pSet = aDlg.GetExampleSet();
1186 // (of course we could put the modified items directly into the column, but then the UNO-model
1187 // won't reflect these changes, and why do we have a model, then ?)
1188
1189 // horizontal justify
1190 SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
1191
1192 _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
1193
1194 // format key
1195 if (_nFlags & TP_ATTR_NUMBER)
1196 {
1197 SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
1198 _nFormatKey = (sal_Int32)pFormat->GetValue();
1199 }
1200 bRet = sal_True;
1201 }
1202 // deleted formats
1203 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
1204 if (pResult)
1205 {
1206 const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
1207 const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
1208 if (pInfoItem && pInfoItem->GetDelCount())
1209 {
1210 const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
1211
1212 for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
1213 _pFormatter->DeleteEntry(*pDeletedKeys);
1214 }
1215 }
1216 }
1217
1218 delete pFormatDescriptor;
1219 SfxItemPool::Free(pPool);
1220 for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
1221 delete pDefaults[i];
1222
1223 return bRet;
1224 }
1225
1226 //------------------------------------------------------------------------------
getStandardDatabaseFilter()1227 const SfxFilter* getStandardDatabaseFilter()
1228 {
1229 static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
1230 const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
1231 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
1232 return pFilter;
1233 }
1234
1235
1236 // -----------------------------------------------------------------------------
appendToFilter(const Reference<XConnection> & _xConnection,const::rtl::OUString & _sName,const Reference<XMultiServiceFactory> & _xFactory,Window * _pParent)1237 sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
1238 const ::rtl::OUString& _sName,
1239 const Reference< XMultiServiceFactory >& _xFactory,
1240 Window* _pParent)
1241 {
1242 sal_Bool bRet = sal_False;
1243 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1244 if(xChild.is())
1245 {
1246 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1247 if(xProp.is())
1248 {
1249 Sequence< ::rtl::OUString > aFilter;
1250 xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
1251 // first check if we have something like SCHEMA.%
1252 sal_Bool bHasToInsert = sal_True;
1253 static ::rtl::OUString sPattern = ::rtl::OUString::createFromAscii("%");
1254 const ::rtl::OUString* pBegin = aFilter.getConstArray();
1255 const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
1256 for (;pBegin != pEnd; ++pBegin)
1257 {
1258 if(pBegin->indexOf('%') != -1)
1259 {
1260 sal_Int32 nLen;
1261 if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
1262 bHasToInsert = sal_False;
1263 else if(pBegin->getLength() == 1)
1264 bHasToInsert = sal_False;
1265 }
1266 }
1267
1268 bRet = sal_True;
1269 if(bHasToInsert)
1270 {
1271 if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_xFactory))
1272 {
1273 String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
1274 OSQLWarningBox( _pParent, aMessage ).Execute();
1275 bRet = sal_False;
1276 }
1277 else
1278 {
1279 aFilter.realloc(aFilter.getLength()+1);
1280 aFilter.getArray()[aFilter.getLength()-1] = _sName;
1281 xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
1282 }
1283 }
1284 }
1285 }
1286 return bRet;
1287 }
1288 // -----------------------------------------------------------------------------
notifySystemWindow(Window * _pWindow,Window * _pToRegister,::comphelper::mem_fun1_t<TaskPaneList,Window * > _rMemFunc)1289 void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
1290 {
1291 OSL_ENSURE(_pWindow,"Window can not be null!");
1292 SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
1293 if ( pSystemWindow )
1294 {
1295 _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
1296 }
1297 }
1298 // -----------------------------------------------------------------------------
adjustToolBoxSize(ToolBox * _pToolBox)1299 void adjustToolBoxSize(ToolBox* _pToolBox)
1300 {
1301 // adjust the toolbox size, otherwise large bitmaps don't fit into
1302 Size aOldSize = _pToolBox->GetSizePixel();
1303 Size aSize = _pToolBox->CalcWindowSizePixel();
1304 if ( !aSize.Width() )
1305 aSize.Width() = aOldSize.Width();
1306 else if ( !aSize.Height() )
1307 aSize.Height() = aOldSize.Height();
1308
1309 Size aTbSize = _pToolBox->GetSizePixel();
1310 if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
1311 (aSize.Height() && aSize.Height() != aTbSize.Height()) )
1312 {
1313 _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
1314 _pToolBox->Invalidate();
1315 }
1316 }
1317 // -----------------------------------------------------------------------------
isHiContrast(Window * _pWindow)1318 sal_Bool isHiContrast(Window* _pWindow)
1319 {
1320 OSL_ENSURE(_pWindow,"Window must be not null!");
1321 Window* pIter = _pWindow;
1322 // while( pIter && pIter->GetBackground().GetColor().GetColor() == COL_TRANSPARENT )
1323 while( pIter )
1324 {
1325 if ( pIter->GetBackground().GetColor().GetColor() == COL_TRANSPARENT )
1326 pIter = pIter->GetParent();
1327 else
1328 break;
1329 }
1330 return pIter && pIter->GetSettings().GetStyleSettings().GetHighContrastMode();
1331 }
1332
1333 // -----------------------------------------------------------------------------
adjustBrowseBoxColumnWidth(::svt::EditBrowseBox * _pBox,sal_uInt16 _nColId)1334 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1335 {
1336 sal_Int32 nColSize = -1;
1337 sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1338 if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1339 {
1340 Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
1341 nColSize = aSizeMM.Width() * 10;
1342 }
1343
1344 Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
1345
1346 DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1347 if ( aColumnSizeDlg.Execute() )
1348 {
1349 sal_Int32 nValue = aColumnSizeDlg.GetValue();
1350 if ( -1 == nValue )
1351 { // default width
1352 nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1353 }
1354 else
1355 {
1356 Size aSizeMM( nValue / 10, 0 );
1357 nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
1358 }
1359 _pBox->SetColumnWidth( _nColId, nValue );
1360 }
1361 }
1362 // -----------------------------------------------------------------------------
1363 // check if SQL92 name checking is enabled
isSQL92CheckEnabled(const Reference<XConnection> & _xConnection)1364 sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1365 {
1366 return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK );
1367 }
1368 // -----------------------------------------------------------------------------
isAppendTableAliasEnabled(const Reference<XConnection> & _xConnection)1369 sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1370 {
1371 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS );
1372 }
1373
1374 // -----------------------------------------------------------------------------
generateAsBeforeTableAlias(const Reference<XConnection> & _xConnection)1375 sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1376 {
1377 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME );
1378 }
1379
1380 // -----------------------------------------------------------------------------
fillAutoIncrementValue(const Reference<XPropertySet> & _xDatasource,sal_Bool & _rAutoIncrementValueEnabled,::rtl::OUString & _rsAutoIncrementValue)1381 void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1382 sal_Bool& _rAutoIncrementValueEnabled,
1383 ::rtl::OUString& _rsAutoIncrementValue)
1384 {
1385 if ( _xDatasource.is() )
1386 {
1387 OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1388 Sequence<PropertyValue> aInfo;
1389 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
1390
1391 // search the right propertyvalue
1392 const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
1393 aInfo.getConstArray() + aInfo.getLength(),
1394 ::std::bind(TPropertyValueEqualFunctor(), ::std::placeholders::_1,static_cast<const ::rtl::OUString&>(PROPERTY_AUTOINCREMENTCREATION)));
1395 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1396 pValue->Value >>= _rsAutoIncrementValue;
1397 pValue =::std::find_if(aInfo.getConstArray(),
1398 aInfo.getConstArray() + aInfo.getLength(),
1399 ::std::bind(TPropertyValueEqualFunctor(), ::std::placeholders::_1,::rtl::OUString::createFromAscii("IsAutoRetrievingEnabled") ));
1400 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1401 pValue->Value >>= _rAutoIncrementValueEnabled;
1402 }
1403 }
1404 // -----------------------------------------------------------------------------
fillAutoIncrementValue(const Reference<XConnection> & _xConnection,sal_Bool & _rAutoIncrementValueEnabled,::rtl::OUString & _rsAutoIncrementValue)1405 void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1406 sal_Bool& _rAutoIncrementValueEnabled,
1407 ::rtl::OUString& _rsAutoIncrementValue)
1408 {
1409 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1410 if(xChild.is())
1411 {
1412 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1413 fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1414 }
1415 }
1416 // -----------------------------------------------------------------------------
getStrippedDatabaseName(const Reference<XPropertySet> & _xDataSource,::rtl::OUString & _rsDatabaseName)1417 ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
1418 {
1419 if ( !_rsDatabaseName.getLength() && _xDataSource.is() )
1420 {
1421 try
1422 {
1423 _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
1424 }
1425 catch(const Exception& )
1426 {
1427 DBG_UNHANDLED_EXCEPTION();
1428 }
1429 }
1430 ::rtl::OUString sName = _rsDatabaseName;
1431 INetURLObject aURL(sName);
1432 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1433 sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
1434 return sName;
1435 }
1436 // -----------------------------------------------------------------------------
AppendConfigToken(::rtl::OUString & _rURL,sal_Bool _bQuestionMark)1437 void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
1438 {
1439 Any aLocale =
1440 ::utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty( ::utl::ConfigManager::LOCALE );
1441 ::rtl::OUString sLocaleStr;
1442 if ( !( aLocale >>= sLocaleStr ) )
1443 // fallback is english
1444 sLocaleStr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
1445
1446 // query part exists?
1447 if ( _bQuestionMark )
1448 // no, so start with '?'
1449 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
1450 else
1451 // yes, so only append with '&'
1452 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
1453
1454 // set parameters
1455 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Language="));
1456 _rURL += sLocaleStr;
1457 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&System="));
1458 _rURL += SvtHelpOptions().GetSystem();
1459 }
1460
1461 namespace
1462 {
1463 // -----------------------------------------------------------------------
1464
GetHelpAnchor_Impl(const::rtl::OUString & _rURL,::rtl::OUString & _rAnchor)1465 sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
1466 {
1467 sal_Bool bRet = sal_False;
1468 ::rtl::OUString sAnchor;
1469
1470 try
1471 {
1472 ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
1473 Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
1474 if ( ( aCnt.getPropertyValue( ::rtl::OUString::createFromAscii( "AnchorName" ) ) >>= sAnchor ) )
1475 {
1476
1477 if ( sAnchor.getLength() > 0 )
1478 {
1479 _rAnchor = sAnchor;
1480 bRet = sal_True;
1481 }
1482 }
1483 else
1484 {
1485 DBG_ERRORFILE( "Property 'AnchorName' is missing" );
1486 }
1487 }
1488 catch( Exception& )
1489 {
1490 }
1491
1492 return bRet;
1493 }
1494 // .........................................................................
1495 } // anonymous
1496 // .........................................................................
1497 // -----------------------------------------------------------------------------
createHelpAgentURL(const::rtl::OUString & _sModuleName,const rtl::OString & sHelpId)1498 ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName, const rtl::OString& sHelpId)
1499 {
1500 ::com::sun::star::util::URL aURL;
1501 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.help://" ) );
1502 aURL.Complete += _sModuleName;
1503 aURL.Complete += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
1504 aURL.Complete += ::rtl::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8);
1505
1506 ::rtl::OUString sAnchor;
1507 ::rtl::OUString sTempURL = aURL.Complete;
1508 AppendConfigToken( sTempURL, sal_True );
1509 sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
1510 AppendConfigToken(aURL.Complete,sal_True);
1511 if ( bHasAnchor )
1512 {
1513 aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
1514 aURL.Complete += sAnchor;
1515 }
1516 return aURL;
1517 }
1518 // -----------------------------------------------------------------------------
setEvalDateFormatForFormatter(Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter)1519 void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1520 {
1521 OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1522 if ( _rxFormatter.is() )
1523 {
1524 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1525
1526 Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1527 SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1528 OSL_ENSURE(pSupplierImpl,"No Supplier!");
1529
1530 if ( pSupplierImpl )
1531 {
1532 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1533 pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1534 }
1535 }
1536 }
1537 // -----------------------------------------------------------------------------
queryPrimaryKeyType(const OTypeInfoMap & _rTypeInfo)1538 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1539 {
1540 TOTypeInfoSP pTypeInfo;
1541 // first we search for a type which supports autoIncrement
1542 OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
1543 OTypeInfoMap::const_iterator aEnd = _rTypeInfo.end();
1544 for(;aIter != aEnd;++aIter)
1545 {
1546 // OJ: we don't want to set an autoincrement column to be key
1547 // because we don't have the possibility to know how to create
1548 // such auto increment column later on
1549 // so until we know how to do it, we create a column without autoincrement
1550 // if ( !aIter->second->bAutoIncrement )
1551 { // therefor we have searched
1552 if ( aIter->second->nType == DataType::INTEGER )
1553 {
1554 pTypeInfo = aIter->second; // alternative
1555 break;
1556 }
1557 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
1558 pTypeInfo = aIter->second; // alternative
1559 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
1560 pTypeInfo = aIter->second; // alternative
1561 }
1562 }
1563 if ( !pTypeInfo.get() ) // just a fallback
1564 pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
1565
1566 OSL_ENSURE(pTypeInfo.get(),"checkColumns: can't find a type which is useable as a key!");
1567 return pTypeInfo;
1568 }
1569 // -----------------------------------------------------------------------------
queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap & _rTypeInfo)1570 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1571 {
1572 OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
1573 if(aIter != _rTypeInfo.end())
1574 return aIter->second;
1575 // fall back if the type is unknown
1576 TOTypeInfoSP pTypeInfo;
1577 switch(_nDataType)
1578 {
1579 case DataType::TINYINT:
1580 pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo);
1581 if( bool(pTypeInfo))
1582 break;
1583 // run through
1584 case DataType::SMALLINT:
1585 pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo);
1586 if( bool(pTypeInfo))
1587 break;
1588 // run through
1589 case DataType::INTEGER:
1590 pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo);
1591 if( bool(pTypeInfo))
1592 break;
1593 // run through
1594 case DataType::FLOAT:
1595 pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo);
1596 if( bool(pTypeInfo))
1597 break;
1598 // run through
1599 case DataType::DATE:
1600 case DataType::TIME:
1601 if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1602 {
1603 pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo);
1604 if( bool(pTypeInfo))
1605 break;
1606 }
1607 // run through
1608 case DataType::TIMESTAMP:
1609 case DataType::REAL:
1610 case DataType::BIGINT:
1611 pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo);
1612 if( bool(pTypeInfo))
1613 break;
1614 // run through
1615 case DataType::DOUBLE:
1616 pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo);
1617 if( bool(pTypeInfo))
1618 break;
1619 // run through
1620 case DataType::NUMERIC:
1621 pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
1622 break;
1623 case DataType::DECIMAL:
1624 pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo);
1625 if( bool(pTypeInfo))
1626 break;
1627 pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo);
1628 if( bool(pTypeInfo))
1629 break;
1630 break;
1631 case DataType::VARCHAR:
1632 pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo);
1633 if( bool(pTypeInfo))
1634 break;
1635 break;
1636 case DataType::LONGVARCHAR:
1637 pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo);
1638 if( bool(pTypeInfo))
1639 break;
1640 break;
1641 default:
1642 ;
1643 } // switch(_nDataType)
1644 if ( !pTypeInfo )
1645 {
1646 ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
1647 sal_Bool bForce = sal_True;
1648 pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
1649 } // if ( !pTypeInfo )
1650 OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1651 return pTypeInfo;
1652 }
1653 // -----------------------------------------------------------------------------
askForUserAction(Window * _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const::rtl::OUString & _sName)1654 sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
1655 {
1656 vos::OGuard aGuard( Application::GetSolarMutex() );
1657 String aMsg = String(ModuleRes(_nText));
1658 aMsg.SearchAndReplace(String::CreateFromAscii("%1"),String(_sName));
1659 OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
1660 if ( _bAll )
1661 {
1662 aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
1663 aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1664 }
1665 return aAsk.Execute();
1666 }
1667
1668 // -----------------------------------------------------------------------------
1669 namespace
1670 {
lcl_createSDBCLevelStatement(const::rtl::OUString & _rStatement,const Reference<XConnection> & _rxConnection)1671 static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1672 {
1673 ::rtl::OUString sSDBCLevelStatement( _rStatement );
1674 try
1675 {
1676 Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1677 Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1678 xAnalyzer->setQuery( _rStatement );
1679 sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
1680 }
1681 catch( const Exception& )
1682 {
1683 DBG_UNHANDLED_EXCEPTION();
1684 }
1685 return sSDBCLevelStatement;
1686 }
1687 }
1688
1689 // -----------------------------------------------------------------------------
createView(const::rtl::OUString & _rName,const Reference<XConnection> & _rxConnection,const::rtl::OUString & _rCommand)1690 Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
1691 const ::rtl::OUString& _rCommand )
1692 {
1693 Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1694 Reference< XNameAccess > xViews;
1695 if(xSup.is())
1696 xViews = xSup->getViews();
1697 Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1698 OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1699 if(!xFact.is())
1700 return NULL;
1701
1702 Reference<XPropertySet> xView = xFact->createDataDescriptor();
1703 if ( !xView.is() )
1704 return NULL;
1705
1706 ::rtl::OUString sCatalog,sSchema,sTable;
1707 ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1708 _rName,
1709 sCatalog,
1710 sSchema,
1711 sTable,
1712 ::dbtools::eInDataManipulation);
1713
1714 xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1715 xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1716 xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1717
1718 xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
1719
1720 Reference<XAppend> xAppend(xViews,UNO_QUERY);
1721 if(xAppend.is())
1722 xAppend->appendByDescriptor(xView);
1723
1724 xView = NULL;
1725 // we need to reget the view because after appending it it is no longer valid
1726 // but this time it isn't a view object it is a table object with type "VIEW"
1727 Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1728 Reference< XNameAccess > xTables;
1729 if ( xTabSup.is() )
1730 {
1731 xTables = xTabSup->getTables();
1732 if ( xTables.is() && xTables->hasByName( _rName ) )
1733 xTables->getByName( _rName ) >>= xView;
1734 }
1735
1736 return xView;
1737 }
1738
1739 // -----------------------------------------------------------------------------
createView(const::rtl::OUString & _rName,const Reference<XConnection> & _rxConnection,const Reference<XPropertySet> & _rxSourceObject)1740 Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
1741 ,const Reference<XPropertySet>& _rxSourceObject)
1742 {
1743 ::rtl::OUString sCommand;
1744 Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
1745 if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
1746 {
1747 _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
1748
1749 sal_Bool bEscapeProcessing( sal_False );
1750 OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
1751 if ( bEscapeProcessing )
1752 sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1753 }
1754 else
1755 {
1756 sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
1757 sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1758 }
1759 return createView( _rName, _rxConnection, sCommand );
1760 }
1761
1762 // -----------------------------------------------------------------------------
insertHierachyElement(Window * _pParent,const Reference<XMultiServiceFactory> & _rxORB,const Reference<XHierarchicalNameContainer> & _xNames,const String & _sParentFolder,sal_Bool _bForm,sal_Bool _bCollection,const Reference<XContent> & _xContent,sal_Bool _bMove)1763 sal_Bool insertHierachyElement( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
1764 const Reference<XHierarchicalNameContainer>& _xNames,
1765 const String& _sParentFolder,
1766 sal_Bool _bForm,
1767 sal_Bool _bCollection,
1768 const Reference<XContent>& _xContent,
1769 sal_Bool _bMove)
1770 {
1771 OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1772 if ( !_xNames.is() )
1773 return sal_False;
1774
1775 Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1776 ::rtl::OUString sName = _sParentFolder;
1777 if ( _xNames->hasByHierarchicalName(sName) )
1778 {
1779 Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
1780 xNameAccess.set(xChild,UNO_QUERY);
1781 if ( !xNameAccess.is() && xChild.is() )
1782 xNameAccess.set(xChild->getParent(),UNO_QUERY);
1783 }
1784
1785 OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1786 if ( !xNameAccess.is() )
1787 return sal_False;
1788
1789 ::rtl::OUString sNewName;
1790 Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1791 if ( xProp.is() )
1792 xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
1793
1794 if ( !_bMove || !sNewName.getLength() )
1795 {
1796 String sTargetName,sLabel;
1797 if ( !sNewName.getLength() || xNameAccess->hasByName(sNewName) )
1798 {
1799 if ( sNewName.getLength() )
1800 sTargetName = sNewName;
1801 else
1802 sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
1803 sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
1804 sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
1805
1806
1807 // here we have everything needed to create a new query object ...
1808 HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
1809 // ... ehm, except a new name
1810 OSaveAsDlg aAskForName( _pParent,
1811 _rxORB,
1812 sTargetName,
1813 sLabel,
1814 aNameChecker,
1815 SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1816 if ( RET_OK != aAskForName.Execute() )
1817 // cancelled by the user
1818 return sal_False;
1819
1820 sNewName = aAskForName.getName();
1821 }
1822 }
1823 else if ( xNameAccess->hasByName(sNewName) )
1824 {
1825 String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1826 sError.SearchAndReplaceAscii("#",sNewName);
1827 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
1828 }
1829
1830 try
1831 {
1832 Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1833 Sequence< Any > aArguments(3);
1834 PropertyValue aValue;
1835 // set as folder
1836 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
1837 aValue.Value <<= sNewName;
1838 aArguments[0] <<= aValue;
1839 //parent
1840 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
1841 aValue.Value <<= xNameAccess;
1842 aArguments[1] <<= aValue;
1843
1844 aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1845 aValue.Value <<= _xContent;
1846 aArguments[2] <<= aValue;
1847
1848 ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
1849
1850 Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
1851 Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1852 xNameContainer->insertByName( sNewName, makeAny( xNew ) );
1853 }
1854 catch( const IllegalArgumentException& e )
1855 {
1856 ::dbtools::throwGenericSQLException( e.Message, e.Context );
1857 }
1858 catch( const Exception& )
1859 {
1860 DBG_UNHANDLED_EXCEPTION();
1861 return sal_False;
1862 }
1863
1864 return sal_True;
1865 }
1866 // -----------------------------------------------------------------------------
getNumberFormatter(const Reference<XConnection> & _rxConnection,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rMF)1867 Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF )
1868 {
1869 // ---------------------------------------------------------------
1870 // create a formatter working with the connections format supplier
1871 Reference< XNumberFormatter > xFormatter;
1872
1873 try
1874 {
1875 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True,_rMF));
1876
1877 if ( xSupplier.is() )
1878 {
1879 // create a new formatter
1880 xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
1881 _rMF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
1882 if ( xFormatter.is() )
1883 xFormatter->attachNumberFormatsSupplier(xSupplier);
1884 }
1885 }
1886 catch(const Exception&)
1887 {
1888 DBG_UNHANDLED_EXCEPTION();
1889 }
1890 return xFormatter;
1891 }
1892
1893
1894 // .........................................................................
1895 } // dbaui
1896 // .........................................................................
1897