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
294 // .........................................................................
295 namespace dbaui
296 {
297 // .........................................................................
298 using namespace ::dbtools;
299 using namespace ::comphelper;
300 using namespace ::com::sun::star::uno;
301 using namespace ::com::sun::star::task;
302 using namespace ::com::sun::star::sdbcx;
303 using namespace ::com::sun::star::sdbc;
304 using namespace ::com::sun::star::sdb;
305 using namespace ::com::sun::star::util;
306 using namespace ::com::sun::star::ucb;
307 using namespace ::com::sun::star::beans;
308 using namespace ::com::sun::star::container;
309 using namespace ::com::sun::star::lang;
310 using namespace ::com::sun::star::ui::dialogs;
311 using namespace ::svt;
312 using ::com::sun::star::ucb::InteractiveIOException;
313 using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
314 using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
315 using ::com::sun::star::frame::XModel;
316
317 // -----------------------------------------------------------------------------
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)318 SQLExceptionInfo createConnection( const ::rtl::OUString& _rsDataSourceName,
319 const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
320 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
321 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
322 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
323 {
324 Reference<XPropertySet> xProp;
325 try
326 {
327 xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
328 }
329 catch(Exception&)
330 {
331 }
332 SQLExceptionInfo aInfo;
333
334 return createConnection(xProp,_rMF,_rEvtLst,_rOUTConnection);
335 }
336 // -----------------------------------------------------------------------------
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)337 SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
338 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
339 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
340 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
341 {
342 SQLExceptionInfo aInfo;
343 if ( !_xDataSource.is() )
344 {
345 OSL_ENSURE(0,"createConnection: coult not retrieve the data source!");
346 return aInfo;
347 }
348
349 ::rtl::OUString sPwd, sUser;
350 sal_Bool bPwdReq = sal_False;
351 try
352 {
353 _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
354 bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
355 _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
356 }
357 catch(Exception&)
358 {
359 OSL_ENSURE(0,"createConnection: error while retrieving data source properties!");
360 }
361
362
363 try
364 {
365 if(bPwdReq && !sPwd.getLength())
366 { // password required, but empty -> connect using an interaction handler
367 Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
368 if (!xConnectionCompletion.is())
369 {
370 OSL_ENSURE(0,"createConnection: missing an interface ... need an error message here!");
371 }
372 else
373 { // instantiate the default SDB interaction handler
374 Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY);
375 if (!xHandler.is())
376 {
377 OSL_ENSURE(sal_False, "createConnection: could not instantiate an interaction handler!");
378 // ShowServiceNotAvailableError(NULL, String(SERVICE_TASK_INTERACTION_HANDLER), sal_True);
379 // TODO: a real parent!
380 }
381 else
382 _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
383 }
384 }
385 else
386 {
387 Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
388 _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
389 }
390 // be notified when connection is in disposing
391 Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
392 if (xComponent.is() && _rEvtLst.is())
393 xComponent->addEventListener(_rEvtLst);
394 }
395 catch(SQLContext& e) { aInfo = SQLExceptionInfo(e); }
396 catch(SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
397 catch(SQLException& e) { aInfo = SQLExceptionInfo(e); }
398 catch(Exception&) { OSL_ENSURE(0,"SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
399
400 // showError(aInfo);
401
402 return aInfo;
403 }
404 // -----------------------------------------------------------------------------
getDataSourceByName(const::rtl::OUString & _rDataSourceName,Window * _pErrorMessageParent,Reference<XMultiServiceFactory> _rxORB,::dbtools::SQLExceptionInfo * _pErrorInfo)405 Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
406 Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
407 {
408 ::comphelper::ComponentContext aContext( _rxORB );
409 Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
410
411 Reference< XDataSource > xDatasource;
412 Any aError;
413 SQLExceptionInfo aSQLError;
414 try
415 {
416 xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
417 }
418 catch(const WrappedTargetException& e)
419 {
420 InteractiveIOException aIOException;
421 if ( ( e.TargetException >>= aIOException )
422 && ( ( aIOException.Code == IOErrorCode_NO_FILE )
423 || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
424 )
425 )
426 {
427 String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
428 OFileNotation aTransformer( e.Message );
429 sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
430 aSQLError = SQLExceptionInfo( sErrorMessage ).get();
431 }
432 else
433 {
434 aSQLError = SQLExceptionInfo( e.TargetException );
435 if ( !aSQLError.isValid() )
436 aError = e.TargetException;
437 }
438 }
439 catch( const Exception& )
440 {
441 DBG_UNHANDLED_EXCEPTION();
442 }
443
444 if ( xDatasource.is() )
445 return xDatasource;
446
447 if ( aSQLError.isValid() )
448 {
449 if ( _pErrorInfo )
450 {
451 *_pErrorInfo = aSQLError;
452 }
453 else
454 {
455 showError( aSQLError, _pErrorMessageParent, _rxORB );
456 }
457 }
458
459 return Reference<XDataSource>();
460 }
461 // -----------------------------------------------------------------------------
getDataSourceOrModel(const Reference<XInterface> & _xObject)462 Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
463 {
464 Reference< XInterface > xRet;
465 Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
466 if ( xDocumentDataSource.is() )
467 xRet = xDocumentDataSource->getDatabaseDocument();
468
469 if ( !xRet.is() )
470 {
471 Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
472 if ( xOfficeDoc.is() )
473 xRet = xOfficeDoc->getDataSource();
474 }
475
476 return xRet;
477 }
478 // -----------------------------------------------------------------------------
showError(const SQLExceptionInfo & _rInfo,Window * _pParent,const Reference<XMultiServiceFactory> & _xFactory)479 void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XMultiServiceFactory >& _xFactory)
480 {
481 OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
482 ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent),_xFactory);
483 }
484
485 // -----------------------------------------------------------------------------
getKeyColumns(const Reference<XIndexAccess> & _rxKeys,sal_Int32 _nKeyType)486 ::std::vector< Reference<XNameAccess> > getKeyColumns(const Reference<XIndexAccess >& _rxKeys,
487 sal_Int32 _nKeyType)
488 {
489 // use keys and indexes for exact positioning
490 // first the keys
491 ::std::vector< Reference<XNameAccess> > vRet;
492 if(_rxKeys.is())
493 {
494 Reference<XPropertySet> xProp;
495 for(sal_Int32 i=0;i< _rxKeys->getCount();++i)
496 {
497 _rxKeys->getByIndex(i) >>= xProp;
498 sal_Int32 nKeyType = 0;
499 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
500 if(_nKeyType == nKeyType)
501 {
502 Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY);
503 OSL_ENSURE(xKeyColsSup.is(),"Columnsupplier is null!");
504 vRet.push_back(xKeyColsSup->getColumns());
505 }
506 }
507 }
508
509 return vRet;
510 }
511 // -----------------------------------------------------------------------------
512
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)513 TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
514 sal_Int32 _nType,
515 const ::rtl::OUString& _sTypeName,
516 const ::rtl::OUString& _sCreateParams,
517 sal_Int32 _nPrecision,
518 sal_Int32 _nScale,
519 sal_Bool _bAutoIncrement,
520 sal_Bool& _brForceToType)
521 {
522 TOTypeInfoSP pTypeInfo;
523 _brForceToType = sal_False;
524 // search for type
525 ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
526 OTypeInfoMap::const_iterator aIter = aPair.first;
527 if(aIter != _rTypeInfo.end()) // compare with end is correct here
528 {
529 for(;aIter != aPair.second;++aIter)
530 {
531 // search the best matching type
532 #ifdef DBG_UTIL
533 ::rtl::OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
534 sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
535 sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
536 sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
537 #endif
538 if ( (
539 !_sTypeName.getLength()
540 || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
541 )
542 && (
543 (
544 !aIter->second->aCreateParams.getLength()
545 && !_sCreateParams.getLength()
546 )
547 || (
548 (aIter->second->nPrecision >= _nPrecision)
549 && (aIter->second->nMaximumScale >= _nScale)
550 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
551 )
552 )
553 )
554 break;
555 }
556
557 if (aIter == aPair.second)
558 {
559 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
560 {
561 sal_Int32 nPrec = aIter->second->nPrecision;
562 sal_Int32 nScale = aIter->second->nMaximumScale;
563 // search the best matching type (now comparing the local names)
564 if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
565 && (nPrec >= _nPrecision)
566 && (nScale >= _nScale)
567 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
568 )
569 {
570 OSL_ENSURE(sal_False,
571 ( ::rtl::OString("getTypeInfoFromType: assuming column type ")
572 += ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), gsl_getSystemTextEncoding())
573 += ::rtl::OString("\" (expected type name ")
574 += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
575 += ::rtl::OString(" matches the type's local name).")).getStr());
576 break;
577 }
578 }
579 }
580
581 if (aIter == aPair.second)
582 { // no match for the names, no match for the local names
583 // -> drop the precision and the scale restriction, accept any type with the property
584 // type id (nType)
585
586 //OSL_ENSURE(sal_False,
587 // ( ::rtl::OString("getTypeInfoFromType: did not find a matching type")
588 // += ::rtl::OString(" (expected type name: ")
589 // += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), gsl_getSystemTextEncoding())
590 // += ::rtl::OString(")! Defaulting to the first matching type.")).getStr());
591 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
592 {
593 // search the best matching type (now comparing the local names)
594 #ifdef DBG_UTIL
595 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
596 #endif
597 sal_Int32 nPrec = aIter->second->nPrecision;
598 sal_Int32 nScale = aIter->second->nMaximumScale;
599 if ( (nPrec >= _nPrecision)
600 && (nScale >= _nScale)
601 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
602 )
603 break;
604 }
605 }
606 if (aIter == aPair.second)
607 {
608 if ( _bAutoIncrement )
609 {
610 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
611 {
612 // search the best matching type (now comparing the local names)
613 #ifdef DBG_UTIL
614 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
615 #endif
616 sal_Int32 nScale = aIter->second->nMaximumScale;
617 if ( (nScale >= _nScale)
618 && (aIter->second->bAutoIncrement == _bAutoIncrement)
619 )
620 break;
621 }
622 if ( aIter == aPair.second )
623 {
624 // try it without the auto increment flag
625 pTypeInfo = getTypeInfoFromType(_rTypeInfo,
626 _nType,
627 _sTypeName,
628 _sCreateParams,
629 _nPrecision,
630 _nScale,
631 sal_False,
632 _brForceToType);
633 }
634 else
635 pTypeInfo = aIter->second;
636 }
637 else
638 {
639 pTypeInfo = aPair.first->second;
640 _brForceToType = sal_True;
641 }
642 }
643 else
644 pTypeInfo = aIter->second;
645 }
646 else
647 {
648 ::comphelper::TStringMixEqualFunctor aCase(sal_False);
649 // search for typeinfo where the typename is equal _sTypeName
650 OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
651 OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
652 for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
653 {
654 if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
655 {
656 pTypeInfo = typeInfoLoop->second;
657 break;
658 }
659 }
660 }
661
662 OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
663 return pTypeInfo;
664 }
665 // -----------------------------------------------------------------------------
fillTypeInfo(const Reference<::com::sun::star::sdbc::XConnection> & _rxConnection,const String & _rsTypeNames,OTypeInfoMap & _rTypeInfoMap,::std::vector<OTypeInfoMap::iterator> & _rTypeInfoIters)666 void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
667 const String& _rsTypeNames,
668 OTypeInfoMap& _rTypeInfoMap,
669 ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
670 {
671 if(!_rxConnection.is())
672 return;
673 Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
674 Reference< XRow> xRow(xRs,UNO_QUERY);
675 // Information for a single SQL type
676 if(xRs.is())
677 {
678 static const ::rtl::OUString aB1 = ::rtl::OUString::createFromAscii(" [ ");
679 static const ::rtl::OUString aB2 = ::rtl::OUString::createFromAscii(" ]");
680 Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
681 ::connectivity::ORowSetValue aValue;
682 ::std::vector<sal_Int32> aTypes;
683 ::std::vector<sal_Bool> aNullable;
684 // Loop on the result set until we reach end of file
685 while (xRs->next())
686 {
687 TOTypeInfoSP pInfo(new OTypeInfo());
688 sal_Int32 nPos = 1;
689 if ( aTypes.empty() )
690 {
691 sal_Int32 nCount = xResultSetMetaData->getColumnCount();
692 if ( nCount < 1 )
693 nCount = 18;
694 aTypes.reserve(nCount+1);
695 aTypes.push_back(-1);
696 aNullable.push_back(sal_False);
697 for (sal_Int32 j = 1; j <= nCount ; ++j)
698 {
699 aTypes.push_back(xResultSetMetaData->getColumnType(j));
700 aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
701 }
702 }
703
704 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
705 pInfo->aTypeName = aValue;
706 ++nPos;
707 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
708 pInfo->nType = aValue;
709 ++nPos;
710 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
711 pInfo->nPrecision = aValue;
712 ++nPos;
713 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
714 pInfo->aLiteralPrefix = aValue;
715 ++nPos;
716 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
717 pInfo->aLiteralSuffix = aValue;
718 ++nPos;
719 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
720 pInfo->aCreateParams = aValue;
721 ++nPos;
722 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
723 pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
724 ++nPos;
725 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
726 pInfo->bCaseSensitive = (sal_Bool)aValue;
727 ++nPos;
728 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
729 pInfo->nSearchType = aValue;
730 ++nPos;
731 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
732 pInfo->bUnsigned = (sal_Bool)aValue;
733 ++nPos;
734 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
735 pInfo->bCurrency = (sal_Bool)aValue;
736 ++nPos;
737 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
738 pInfo->bAutoIncrement = (sal_Bool)aValue;
739 ++nPos;
740 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
741 pInfo->aLocalTypeName = aValue;
742 ++nPos;
743 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
744 pInfo->nMinimumScale = aValue;
745 ++nPos;
746 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
747 pInfo->nMaximumScale = aValue;
748 nPos = 18;
749 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
750
751 // check if values are less than zero like it happens in a oracle jdbc driver
752 if( pInfo->nPrecision < 0)
753 pInfo->nPrecision = 0;
754 if( pInfo->nMinimumScale < 0)
755 pInfo->nMinimumScale = 0;
756 if( pInfo->nMaximumScale < 0)
757 pInfo->nMaximumScale = 0;
758
759 String aName;
760 switch(pInfo->nType)
761 {
762 case DataType::CHAR:
763 aName = _rsTypeNames.GetToken(TYPE_CHAR);
764 break;
765 case DataType::VARCHAR:
766 aName = _rsTypeNames.GetToken(TYPE_TEXT);
767 break;
768 case DataType::DECIMAL:
769 aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
770 break;
771 case DataType::NUMERIC:
772 aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
773 break;
774 case DataType::BIGINT:
775 aName = _rsTypeNames.GetToken(TYPE_BIGINT);
776 break;
777 case DataType::FLOAT:
778 aName = _rsTypeNames.GetToken(TYPE_FLOAT);
779 break;
780 case DataType::DOUBLE:
781 aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
782 break;
783 case DataType::LONGVARCHAR:
784 aName = _rsTypeNames.GetToken(TYPE_MEMO);
785 break;
786 case DataType::LONGVARBINARY:
787 aName = _rsTypeNames.GetToken(TYPE_IMAGE);
788 break;
789 case DataType::DATE:
790 aName = _rsTypeNames.GetToken(TYPE_DATE);
791 break;
792 case DataType::TIME:
793 aName = _rsTypeNames.GetToken(TYPE_TIME);
794 break;
795 case DataType::TIMESTAMP:
796 aName = _rsTypeNames.GetToken(TYPE_DATETIME);
797 break;
798 case DataType::BIT:
799 if ( pInfo->aCreateParams.getLength() )
800 {
801 aName = _rsTypeNames.GetToken(TYPE_BIT);
802 break;
803 }
804 // run through
805 case DataType::BOOLEAN:
806 aName = _rsTypeNames.GetToken(TYPE_BOOL);
807 break;
808 case DataType::TINYINT:
809 aName = _rsTypeNames.GetToken(TYPE_TINYINT);
810 break;
811 case DataType::SMALLINT:
812 aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
813 break;
814 case DataType::INTEGER:
815 aName = _rsTypeNames.GetToken(TYPE_INTEGER);
816 break;
817 case DataType::REAL:
818 aName = _rsTypeNames.GetToken(TYPE_REAL);
819 break;
820 case DataType::BINARY:
821 aName = _rsTypeNames.GetToken(TYPE_BINARY);
822 break;
823 case DataType::VARBINARY:
824 aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
825 break;
826 case DataType::SQLNULL:
827 aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
828 break;
829 case DataType::OBJECT:
830 aName = _rsTypeNames.GetToken(TYPE_OBJECT);
831 break;
832 case DataType::DISTINCT:
833 aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
834 break;
835 case DataType::STRUCT:
836 aName = _rsTypeNames.GetToken(TYPE_STRUCT);
837 break;
838 case DataType::ARRAY:
839 aName = _rsTypeNames.GetToken(TYPE_ARRAY);
840 break;
841 case DataType::BLOB:
842 aName = _rsTypeNames.GetToken(TYPE_BLOB);
843 break;
844 case DataType::CLOB:
845 aName = _rsTypeNames.GetToken(TYPE_CLOB);
846 break;
847 case DataType::REF:
848 aName = _rsTypeNames.GetToken(TYPE_REF);
849 break;
850 case DataType::OTHER:
851 aName = _rsTypeNames.GetToken(TYPE_OTHER);
852 break;
853 }
854 if ( aName.Len() )
855 {
856 pInfo->aUIName = aName.GetBuffer();
857 pInfo->aUIName += aB1;
858 }
859 pInfo->aUIName += pInfo->aTypeName;
860 if ( aName.Len() )
861 pInfo->aUIName += aB2;
862 // Now that we have the type info, save it in the multimap
863 _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
864 }
865 // for a faster index access
866 _rTypeInfoIters.reserve(_rTypeInfoMap.size());
867
868 OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
869 OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
870 for(;aIter != aEnd;++aIter)
871 _rTypeInfoIters.push_back(aIter);
872
873 // Close the result set/statement.
874
875 ::comphelper::disposeComponent(xRs);
876 }
877 }
878 // -----------------------------------------------------------------------------
setColumnProperties(const Reference<XPropertySet> & _rxColumn,const OFieldDescription * _pFieldDesc)879 void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
880 {
881 _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
882 _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
883 _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
884 _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
885 _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
886 _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
887 _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
888 _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
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()));
895 }
896 // -----------------------------------------------------------------------------
createDefaultName(const Reference<XDatabaseMetaData> & _xMetaData,const Reference<XNameAccess> & _xTables,const::rtl::OUString & _sName)897 ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
898 {
899 OSL_ENSURE(_xMetaData.is(),"No MetaData!");
900 ::rtl::OUString sDefaultName = _sName;
901 try
902 {
903 ::rtl::OUString sCatalog,sSchema,sCompsedName;
904 if(_xMetaData->supportsCatalogsInTableDefinitions())
905 {
906 try
907 {
908 Reference< XConnection> xCon = _xMetaData->getConnection();
909 if ( xCon.is() )
910 sCatalog = xCon->getCatalog();
911 if ( !sCatalog.getLength() )
912 {
913 Reference<XResultSet> xRes = _xMetaData->getCatalogs();
914 Reference<XRow> xRow(xRes,UNO_QUERY);
915 while(xRes.is() && xRes->next())
916 {
917 sCatalog = xRow->getString(1);
918 if(!xRow->wasNull())
919 break;
920 }
921 }
922 }
923 catch(const SQLException&)
924 {
925 }
926 }
927 if(_xMetaData->supportsSchemasInTableDefinitions())
928 {
929 sSchema = _xMetaData->getUserName();
930 }
931 sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
932 sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
933 }
934 catch(const SQLException&)
935 {
936 }
937 return sDefaultName;
938 }
939 // -----------------------------------------------------------------------------
checkDataSourceAvailable(const::rtl::OUString & _sDataSourceName,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _xORB)940 sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
941 {
942 sal_Bool bRet = sal_False;
943 Reference< XNameAccess > xDataBaseContext(_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
944 if ( xDataBaseContext.is() )
945 {
946 bRet = xDataBaseContext->hasByName(_sDataSourceName);
947 if ( !bRet )
948 { // try if this one is a URL
949 try
950 {
951 bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
952 }
953 catch(Exception)
954 {
955 }
956 }
957 }
958 return bRet;
959 }
960 // -----------------------------------------------------------------------------
mapTextAllign(const SvxCellHorJustify & _eAlignment)961 sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
962 {
963 sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
964 switch (_eAlignment)
965 {
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!");
972 }
973 return nAlignment;
974 }
975 // -----------------------------------------------------------------------------
mapTextJustify(const sal_Int32 & _nAlignment)976 SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
977 {
978 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
979 switch (_nAlignment)
980 {
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!");
986 }
987 return eJustify;
988 }
989 // -----------------------------------------------------------------------------
ConvertFontWeight(::FontWeight eWeight)990 float ConvertFontWeight( ::FontWeight eWeight )
991 {
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;
1012
1013 OSL_ENSURE(0, "Unknown FontWeigth" );
1014 return ::com::sun::star::awt::FontWeight::DONTKNOW;
1015 }
1016 // -----------------------------------------------------------------------------
ConvertFontWidth(::FontWidth eWidth)1017 float ConvertFontWidth( ::FontWidth eWidth )
1018 {
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;
1039
1040 OSL_ENSURE(0, "Unknown FontWidth" );
1041 return ::com::sun::star::awt::FontWidth::DONTKNOW;
1042 }
1043 // -----------------------------------------------------------------------------
CreateFontDescriptor(const Font & rFont)1044 ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
1045 {
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;
1066 }
1067 // -----------------------------------------------------------------------------
callColumnFormatDialog(const Reference<XPropertySet> & xAffectedCol,const Reference<XPropertySet> & xField,SvNumberFormatter * _pFormatter,Window * _pParent)1068 void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
1069 const Reference<XPropertySet>& xField,
1070 SvNumberFormatter* _pFormatter,
1071 Window* _pParent)
1072 {
1073 if (xAffectedCol.is() && xField.is())
1074 {
1075 try
1076 {
1077 Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
1078 sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
1079 sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
1080
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));
1088
1089 sal_uInt16 nFlags = 0;
1090 if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
1091 {
1092 xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
1093 if (nFlags & TP_ATTR_NUMBER)
1094 xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
1095
1096 }
1097 }
1098 catch( const Exception& )
1099 {
1100 DBG_UNHANDLED_EXCEPTION();
1101 }
1102 }
1103 }
1104 // -----------------------------------------------------------------------------
callColumnFormatDialog(Window * _pParent,SvNumberFormatter * _pFormatter,sal_Int32 _nDataType,sal_Int32 & _nFormatKey,SvxCellHorJustify & _eJustify,sal_uInt16 & _nFlags,sal_Bool _bHasFormat)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)
1112 {
1113 sal_Bool bRet = sal_False;
1114 // the allowed format changes depend of the type of the field ...
1115 _nFlags = TP_ATTR_ALIGN;
1116
1117 if (_bHasFormat)
1118 _nFlags |= TP_ATTR_NUMBER;
1119
1120 // ------------
1121 // UNO->ItemSet
1122 static SfxItemInfo aItemInfos[] =
1123 {
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 }
1129 };
1130 static sal_uInt16 aAttrMap[] =
1131 {
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,
1135 0
1136 };
1137
1138 SfxPoolItem* pDefaults[] =
1139 {
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)
1145 };
1146
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
1150
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)
1156 {
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) || (DataType::CLOB == _nDataType))
1159 {
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());
1165 }
1166
1167 pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
1168 }
1169
1170 if (!bText)
1171 {
1172 double dPreviewVal = 1234.56789;
1173 SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
1174 pFormatDescriptor->Put(aFormatter);
1175 }
1176
1177 { // want the dialog to be destroyed before our set
1178 SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
1179 if (RET_OK == aDlg.Execute())
1180 {
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 ?)
1187
1188 // horizontal justify
1189 SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
1190
1191 _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
1192
1193 // format key
1194 if (_nFlags & TP_ATTR_NUMBER)
1195 {
1196 SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
1197 _nFormatKey = (sal_Int32)pFormat->GetValue();
1198 }
1199 bRet = sal_True;
1200 }
1201 // deleted formats
1202 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
1203 if (pResult)
1204 {
1205 const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
1206 const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
1207 if (pInfoItem && pInfoItem->GetDelCount())
1208 {
1209 const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
1210
1211 for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
1212 _pFormatter->DeleteEntry(*pDeletedKeys);
1213 }
1214 }
1215 }
1216
1217 delete pFormatDescriptor;
1218 SfxItemPool::Free(pPool);
1219 for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
1220 delete pDefaults[i];
1221
1222 return bRet;
1223 }
1224
1225 //------------------------------------------------------------------------------
getStandardDatabaseFilter()1226 const SfxFilter* getStandardDatabaseFilter()
1227 {
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;
1232 }
1233
1234
1235 // -----------------------------------------------------------------------------
appendToFilter(const Reference<XConnection> & _xConnection,const::rtl::OUString & _sName,const Reference<XMultiServiceFactory> & _xFactory,Window * _pParent)1236 sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
1237 const ::rtl::OUString& _sName,
1238 const Reference< XMultiServiceFactory >& _xFactory,
1239 Window* _pParent)
1240 {
1241 sal_Bool bRet = sal_False;
1242 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1243 if(xChild.is())
1244 {
1245 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1246 if(xProp.is())
1247 {
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)
1256 {
1257 if(pBegin->indexOf('%') != -1)
1258 {
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;
1264 }
1265 }
1266
1267 bRet = sal_True;
1268 if(bHasToInsert)
1269 {
1270 if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_xFactory))
1271 {
1272 String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
1273 OSQLWarningBox( _pParent, aMessage ).Execute();
1274 bRet = sal_False;
1275 }
1276 else
1277 {
1278 aFilter.realloc(aFilter.getLength()+1);
1279 aFilter.getArray()[aFilter.getLength()-1] = _sName;
1280 xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
1281 }
1282 }
1283 }
1284 }
1285 return bRet;
1286 }
1287 // -----------------------------------------------------------------------------
notifySystemWindow(Window * _pWindow,Window * _pToRegister,::comphelper::mem_fun1_t<TaskPaneList,Window * > _rMemFunc)1288 void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
1289 {
1290 OSL_ENSURE(_pWindow,"Window can not be null!");
1291 SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
1292 if ( pSystemWindow )
1293 {
1294 _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
1295 }
1296 }
1297 // -----------------------------------------------------------------------------
adjustToolBoxSize(ToolBox * _pToolBox)1298 void adjustToolBoxSize(ToolBox* _pToolBox)
1299 {
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();
1307
1308 Size aTbSize = _pToolBox->GetSizePixel();
1309 if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
1310 (aSize.Height() && aSize.Height() != aTbSize.Height()) )
1311 {
1312 _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
1313 _pToolBox->Invalidate();
1314 }
1315 }
1316 // -----------------------------------------------------------------------------
isHiContrast(Window * _pWindow)1317 sal_Bool isHiContrast(Window* _pWindow)
1318 {
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 )
1323 {
1324 if ( pIter->GetBackground().GetColor().GetColor() == COL_TRANSPARENT )
1325 pIter = pIter->GetParent();
1326 else
1327 break;
1328 }
1329 return pIter && pIter->GetSettings().GetStyleSettings().GetHighContrastMode();
1330 }
1331
1332 // -----------------------------------------------------------------------------
adjustBrowseBoxColumnWidth(::svt::EditBrowseBox * _pBox,sal_uInt16 _nColId)1333 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1334 {
1335 sal_Int32 nColSize = -1;
1336 sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1337 if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1338 {
1339 Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
1340 nColSize = aSizeMM.Width() * 10;
1341 }
1342
1343 Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
1344
1345 DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1346 if ( aColumnSizeDlg.Execute() )
1347 {
1348 sal_Int32 nValue = aColumnSizeDlg.GetValue();
1349 if ( -1 == nValue )
1350 { // default width
1351 nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1352 }
1353 else
1354 {
1355 Size aSizeMM( nValue / 10, 0 );
1356 nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
1357 }
1358 _pBox->SetColumnWidth( _nColId, nValue );
1359 }
1360 }
1361 // -----------------------------------------------------------------------------
1362 // check if SQL92 name checking is enabled
isSQL92CheckEnabled(const Reference<XConnection> & _xConnection)1363 sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1364 {
1365 return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK );
1366 }
1367 // -----------------------------------------------------------------------------
isAppendTableAliasEnabled(const Reference<XConnection> & _xConnection)1368 sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1369 {
1370 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS );
1371 }
1372
1373 // -----------------------------------------------------------------------------
generateAsBeforeTableAlias(const Reference<XConnection> & _xConnection)1374 sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1375 {
1376 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME );
1377 }
1378
1379 // -----------------------------------------------------------------------------
fillAutoIncrementValue(const Reference<XPropertySet> & _xDatasource,sal_Bool & _rAutoIncrementValueEnabled,::rtl::OUString & _rsAutoIncrementValue)1380 void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1381 sal_Bool& _rAutoIncrementValueEnabled,
1382 ::rtl::OUString& _rsAutoIncrementValue)
1383 {
1384 if ( _xDatasource.is() )
1385 {
1386 OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1387 Sequence<PropertyValue> aInfo;
1388 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
1389
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;
1401 }
1402 }
1403 // -----------------------------------------------------------------------------
fillAutoIncrementValue(const Reference<XConnection> & _xConnection,sal_Bool & _rAutoIncrementValueEnabled,::rtl::OUString & _rsAutoIncrementValue)1404 void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1405 sal_Bool& _rAutoIncrementValueEnabled,
1406 ::rtl::OUString& _rsAutoIncrementValue)
1407 {
1408 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1409 if(xChild.is())
1410 {
1411 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1412 fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1413 }
1414 }
1415 // -----------------------------------------------------------------------------
getStrippedDatabaseName(const Reference<XPropertySet> & _xDataSource,::rtl::OUString & _rsDatabaseName)1416 ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
1417 {
1418 if ( !_rsDatabaseName.getLength() && _xDataSource.is() )
1419 {
1420 try
1421 {
1422 _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
1423 }
1424 catch(const Exception& )
1425 {
1426 DBG_UNHANDLED_EXCEPTION();
1427 }
1428 }
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;
1434 }
1435 // -----------------------------------------------------------------------------
AppendConfigToken(::rtl::OUString & _rURL,sal_Bool _bQuestionMark)1436 void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
1437 {
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"));
1444
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("&"));
1452
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();
1458 }
1459
1460 namespace
1461 {
1462 // -----------------------------------------------------------------------
1463
GetHelpAnchor_Impl(const::rtl::OUString & _rURL,::rtl::OUString & _rAnchor)1464 sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
1465 {
1466 sal_Bool bRet = sal_False;
1467 ::rtl::OUString sAnchor;
1468
1469 try
1470 {
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 ) )
1474 {
1475
1476 if ( sAnchor.getLength() > 0 )
1477 {
1478 _rAnchor = sAnchor;
1479 bRet = sal_True;
1480 }
1481 }
1482 else
1483 {
1484 DBG_ERRORFILE( "Property 'AnchorName' is missing" );
1485 }
1486 }
1487 catch( Exception& )
1488 {
1489 }
1490
1491 return bRet;
1492 }
1493 // .........................................................................
1494 } // annonymous
1495 // .........................................................................
1496 // -----------------------------------------------------------------------------
createHelpAgentURL(const::rtl::OUString & _sModuleName,const rtl::OString & sHelpId)1497 ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName, const rtl::OString& sHelpId)
1498 {
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::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8);
1504
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 )
1511 {
1512 aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
1513 aURL.Complete += sAnchor;
1514 }
1515 return aURL;
1516 }
1517 // -----------------------------------------------------------------------------
setEvalDateFormatForFormatter(Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter)1518 void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1519 {
1520 OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1521 if ( _rxFormatter.is() )
1522 {
1523 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1524
1525 Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1526 SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1527 OSL_ENSURE(pSupplierImpl,"No Supplier!");
1528
1529 if ( pSupplierImpl )
1530 {
1531 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1532 pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1533 }
1534 }
1535 }
1536 // -----------------------------------------------------------------------------
queryPrimaryKeyType(const OTypeInfoMap & _rTypeInfo)1537 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1538 {
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)
1544 {
1545 // OJ: we don't want to set an autoincrement column to be key
1546 // because we don't have the possibility 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 )
1552 {
1553 pTypeInfo = aIter->second; // alternative
1554 break;
1555 }
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
1560 }
1561 }
1562 if ( !pTypeInfo.get() ) // just a fallback
1563 pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
1564
1565 OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
1566 return pTypeInfo;
1567 }
1568 // -----------------------------------------------------------------------------
queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap & _rTypeInfo)1569 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1570 {
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)
1577 {
1578 case DataType::TINYINT:
1579 pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo);
1580 if( bool(pTypeInfo))
1581 break;
1582 // run through
1583 case DataType::SMALLINT:
1584 pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo);
1585 if( bool(pTypeInfo))
1586 break;
1587 // run through
1588 case DataType::INTEGER:
1589 pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo);
1590 if( bool(pTypeInfo))
1591 break;
1592 // run through
1593 case DataType::FLOAT:
1594 pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo);
1595 if( bool(pTypeInfo))
1596 break;
1597 // run through
1598 case DataType::DATE:
1599 case DataType::TIME:
1600 if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1601 {
1602 pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo);
1603 if( bool(pTypeInfo))
1604 break;
1605 }
1606 // run through
1607 case DataType::TIMESTAMP:
1608 case DataType::REAL:
1609 case DataType::BIGINT:
1610 pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo);
1611 if( bool(pTypeInfo))
1612 break;
1613 // run through
1614 case DataType::DOUBLE:
1615 pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo);
1616 if( bool(pTypeInfo))
1617 break;
1618 // run through
1619 case DataType::NUMERIC:
1620 pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
1621 break;
1622 case DataType::DECIMAL:
1623 pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo);
1624 if( bool(pTypeInfo))
1625 break;
1626 pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo);
1627 if( bool(pTypeInfo))
1628 break;
1629 break;
1630 case DataType::VARCHAR:
1631 pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo);
1632 if( bool(pTypeInfo))
1633 break;
1634 break;
1635 case DataType::LONGVARCHAR:
1636 pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo);
1637 if( bool(pTypeInfo))
1638 break;
1639 break;
1640 default:
1641 ;
1642 } // switch(_nDataType)
1643 if ( !pTypeInfo )
1644 {
1645 ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
1646 sal_Bool bForce = sal_True;
1647 pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
1648 } // if ( !pTypeInfo )
1649 OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1650 return pTypeInfo;
1651 }
1652 // -----------------------------------------------------------------------------
askForUserAction(Window * _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const::rtl::OUString & _sName)1653 sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
1654 {
1655 vos::OGuard aGuard( Application::GetSolarMutex() );
1656 String aMsg = String(ModuleRes(_nText));
1657 aMsg.SearchAndReplace(String::CreateFromAscii("%1"),String(_sName));
1658 OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
1659 if ( _bAll )
1660 {
1661 aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
1662 aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1663 }
1664 return aAsk.Execute();
1665 }
1666
1667 // -----------------------------------------------------------------------------
1668 namespace
1669 {
lcl_createSDBCLevelStatement(const::rtl::OUString & _rStatement,const Reference<XConnection> & _rxConnection)1670 static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1671 {
1672 ::rtl::OUString sSDBCLevelStatement( _rStatement );
1673 try
1674 {
1675 Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1676 Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1677 xAnalyzer->setQuery( _rStatement );
1678 sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
1679 }
1680 catch( const Exception& )
1681 {
1682 DBG_UNHANDLED_EXCEPTION();
1683 }
1684 return sSDBCLevelStatement;
1685 }
1686 }
1687
1688 // -----------------------------------------------------------------------------
createView(const::rtl::OUString & _rName,const Reference<XConnection> & _rxConnection,const::rtl::OUString & _rCommand)1689 Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
1690 const ::rtl::OUString& _rCommand )
1691 {
1692 Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1693 Reference< XNameAccess > xViews;
1694 if(xSup.is())
1695 xViews = xSup->getViews();
1696 Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1697 OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1698 if(!xFact.is())
1699 return NULL;
1700
1701 Reference<XPropertySet> xView = xFact->createDataDescriptor();
1702 if ( !xView.is() )
1703 return NULL;
1704
1705 ::rtl::OUString sCatalog,sSchema,sTable;
1706 ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1707 _rName,
1708 sCatalog,
1709 sSchema,
1710 sTable,
1711 ::dbtools::eInDataManipulation);
1712
1713 xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1714 xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1715 xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1716
1717 xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
1718
1719 Reference<XAppend> xAppend(xViews,UNO_QUERY);
1720 if(xAppend.is())
1721 xAppend->appendByDescriptor(xView);
1722
1723 xView = NULL;
1724 // we need to reget the view because after appending it it is no longer valid
1725 // but this time it isn't a view object it is a table object with type "VIEW"
1726 Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1727 Reference< XNameAccess > xTables;
1728 if ( xTabSup.is() )
1729 {
1730 xTables = xTabSup->getTables();
1731 if ( xTables.is() && xTables->hasByName( _rName ) )
1732 xTables->getByName( _rName ) >>= xView;
1733 }
1734
1735 return xView;
1736 }
1737
1738 // -----------------------------------------------------------------------------
createView(const::rtl::OUString & _rName,const Reference<XConnection> & _rxConnection,const Reference<XPropertySet> & _rxSourceObject)1739 Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
1740 ,const Reference<XPropertySet>& _rxSourceObject)
1741 {
1742 ::rtl::OUString sCommand;
1743 Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
1744 if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
1745 {
1746 _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
1747
1748 sal_Bool bEscapeProcessing( sal_False );
1749 OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
1750 if ( bEscapeProcessing )
1751 sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1752 }
1753 else
1754 {
1755 sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
1756 sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1757 }
1758 return createView( _rName, _rxConnection, sCommand );
1759 }
1760
1761 // -----------------------------------------------------------------------------
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)1762 sal_Bool insertHierachyElement( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
1763 const Reference<XHierarchicalNameContainer>& _xNames,
1764 const String& _sParentFolder,
1765 sal_Bool _bForm,
1766 sal_Bool _bCollection,
1767 const Reference<XContent>& _xContent,
1768 sal_Bool _bMove)
1769 {
1770 OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1771 if ( !_xNames.is() )
1772 return sal_False;
1773
1774 Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1775 ::rtl::OUString sName = _sParentFolder;
1776 if ( _xNames->hasByHierarchicalName(sName) )
1777 {
1778 Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
1779 xNameAccess.set(xChild,UNO_QUERY);
1780 if ( !xNameAccess.is() && xChild.is() )
1781 xNameAccess.set(xChild->getParent(),UNO_QUERY);
1782 }
1783
1784 OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1785 if ( !xNameAccess.is() )
1786 return sal_False;
1787
1788 ::rtl::OUString sNewName;
1789 Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1790 if ( xProp.is() )
1791 xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
1792
1793 if ( !_bMove || !sNewName.getLength() )
1794 {
1795 String sTargetName,sLabel;
1796 if ( !sNewName.getLength() || xNameAccess->hasByName(sNewName) )
1797 {
1798 if ( sNewName.getLength() )
1799 sTargetName = sNewName;
1800 else
1801 sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
1802 sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
1803 sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
1804
1805
1806 // here we have everything needed to create a new query object ...
1807 HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
1808 // ... ehm, except a new name
1809 OSaveAsDlg aAskForName( _pParent,
1810 _rxORB,
1811 sTargetName,
1812 sLabel,
1813 aNameChecker,
1814 SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1815 if ( RET_OK != aAskForName.Execute() )
1816 // cancelled by the user
1817 return sal_False;
1818
1819 sNewName = aAskForName.getName();
1820 }
1821 }
1822 else if ( xNameAccess->hasByName(sNewName) )
1823 {
1824 String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1825 sError.SearchAndReplaceAscii("#",sNewName);
1826 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
1827 }
1828
1829 try
1830 {
1831 Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1832 Sequence< Any > aArguments(3);
1833 PropertyValue aValue;
1834 // set as folder
1835 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
1836 aValue.Value <<= sNewName;
1837 aArguments[0] <<= aValue;
1838 //parent
1839 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
1840 aValue.Value <<= xNameAccess;
1841 aArguments[1] <<= aValue;
1842
1843 aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1844 aValue.Value <<= _xContent;
1845 aArguments[2] <<= aValue;
1846
1847 ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
1848
1849 Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
1850 Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1851 xNameContainer->insertByName( sNewName, makeAny( xNew ) );
1852 }
1853 catch( const IllegalArgumentException& e )
1854 {
1855 ::dbtools::throwGenericSQLException( e.Message, e.Context );
1856 }
1857 catch( const Exception& )
1858 {
1859 DBG_UNHANDLED_EXCEPTION();
1860 return sal_False;
1861 }
1862
1863 return sal_True;
1864 }
1865 // -----------------------------------------------------------------------------
getNumberFormatter(const Reference<XConnection> & _rxConnection,const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rMF)1866 Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF )
1867 {
1868 // ---------------------------------------------------------------
1869 // create a formatter working with the connections format supplier
1870 Reference< XNumberFormatter > xFormatter;
1871
1872 try
1873 {
1874 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True,_rMF));
1875
1876 if ( xSupplier.is() )
1877 {
1878 // create a new formatter
1879 xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
1880 _rMF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
1881 if ( xFormatter.is() )
1882 xFormatter->attachNumberFormatsSupplier(xSupplier);
1883 }
1884 }
1885 catch(const Exception&)
1886 {
1887 DBG_UNHANDLED_EXCEPTION();
1888 }
1889 return xFormatter;
1890 }
1891
1892
1893 // .........................................................................
1894 } // dbaui
1895 // .........................................................................
1896