xref: /AOO41X/main/dbaccess/source/ui/misc/linkeddocuments.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef _DBAUI_LINKEDDOCUMENTS_HXX_
32*cdf0e10cSrcweir #include "linkeddocuments.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
35*cdf0e10cSrcweir #include <osl/diagnose.h>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
38*cdf0e10cSrcweir #include <unotools/confignode.hxx>
39*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
40*cdf0e10cSrcweir #include "dbustrings.hrc"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #include <comphelper/classids.hxx>
43*cdf0e10cSrcweir #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX
44*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
47*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
50*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
53*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
56*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
59*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
62*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
63*cdf0e10cSrcweir #endif
64*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
65*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT_HPP_
68*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument.hpp>
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
71*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
74*cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
77*cdf0e10cSrcweir #include <comphelper/extract.hxx>
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_
80*cdf0e10cSrcweir #include <comphelper/types.hxx>
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
83*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir #ifndef _UCBHELPER_CONTENT_HXX
86*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
87*cdf0e10cSrcweir #endif
88*cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_
89*cdf0e10cSrcweir #include "dbu_misc.hrc"
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_
92*cdf0e10cSrcweir #include <svl/filenotation.hxx>
93*cdf0e10cSrcweir #endif
94*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
95*cdf0e10cSrcweir #include "browserids.hxx"
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir #ifndef _SFXNEW_HXX
98*cdf0e10cSrcweir #include <sfx2/new.hxx>
99*cdf0e10cSrcweir #endif
100*cdf0e10cSrcweir #ifndef _SVTOOLS_TEMPLDLG_HXX
101*cdf0e10cSrcweir #include <svtools/templdlg.hxx>
102*cdf0e10cSrcweir #endif
103*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
104*cdf0e10cSrcweir #include "moduledbu.hxx"
105*cdf0e10cSrcweir #endif
106*cdf0e10cSrcweir // -----------------
107*cdf0e10cSrcweir // for calling basic
108*cdf0e10cSrcweir #ifndef _SFXAPP_HXX
109*cdf0e10cSrcweir #include <sfx2/app.hxx>
110*cdf0e10cSrcweir #endif
111*cdf0e10cSrcweir #ifndef _SBXCLASS_HXX
112*cdf0e10cSrcweir #include <basic/sbx.hxx>
113*cdf0e10cSrcweir #endif
114*cdf0e10cSrcweir #ifndef _SB_SBUNO_HXX
115*cdf0e10cSrcweir #include <basic/sbuno.hxx>
116*cdf0e10cSrcweir #endif
117*cdf0e10cSrcweir #ifndef _EHDL_HXX
118*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
119*cdf0e10cSrcweir #endif
120*cdf0e10cSrcweir #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
121*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
122*cdf0e10cSrcweir #endif
123*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
124*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
125*cdf0e10cSrcweir #endif
126*cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
127*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
128*cdf0e10cSrcweir #endif
129*cdf0e10cSrcweir #ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
130*cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
131*cdf0e10cSrcweir #endif
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
134*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
135*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
136*cdf0e10cSrcweir #include <com/sun/star/io/WrongFormatException.hpp>
137*cdf0e10cSrcweir #include "com/sun/star/sdb/RowSetVetoException.hpp"
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir //......................................................................
140*cdf0e10cSrcweir namespace dbaui
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir //......................................................................
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
145*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
146*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
147*cdf0e10cSrcweir 	using namespace ::com::sun::star::frame;
148*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
149*cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
150*cdf0e10cSrcweir 	using namespace ::com::sun::star::ucb;
151*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
152*cdf0e10cSrcweir     using namespace ::com::sun::star::sdb::application;
153*cdf0e10cSrcweir 	using namespace ::com::sun::star::task;
154*cdf0e10cSrcweir 	using namespace ::svt;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	namespace
157*cdf0e10cSrcweir 	{
158*cdf0e10cSrcweir 		Sequence< sal_Int8 > lcl_GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
159*cdf0e10cSrcweir 													sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
160*cdf0e10cSrcweir 													sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 )
161*cdf0e10cSrcweir 		{
162*cdf0e10cSrcweir 			Sequence< sal_Int8 > aResult( 16 );
163*cdf0e10cSrcweir 			aResult[0] = static_cast<sal_Int8>(n1 >> 24);
164*cdf0e10cSrcweir 			aResult[1] = static_cast<sal_Int8>(( n1 << 8 ) >> 24);
165*cdf0e10cSrcweir 			aResult[2] = static_cast<sal_Int8>(( n1 << 16 ) >> 24);
166*cdf0e10cSrcweir 			aResult[3] = static_cast<sal_Int8>(( n1 << 24 ) >> 24);
167*cdf0e10cSrcweir 			aResult[4] = static_cast<sal_Int8>(n2 >> 8);
168*cdf0e10cSrcweir 			aResult[5] = static_cast<sal_Int8>(( n2 << 8 ) >> 8);
169*cdf0e10cSrcweir 			aResult[6] = static_cast<sal_Int8>(n3 >> 8);
170*cdf0e10cSrcweir 			aResult[7] = static_cast<sal_Int8>(( n3 << 8 ) >> 8);
171*cdf0e10cSrcweir 			aResult[8] = b8;
172*cdf0e10cSrcweir 			aResult[9] = b9;
173*cdf0e10cSrcweir 			aResult[10] = b10;
174*cdf0e10cSrcweir 			aResult[11] = b11;
175*cdf0e10cSrcweir 			aResult[12] = b12;
176*cdf0e10cSrcweir 			aResult[13] = b13;
177*cdf0e10cSrcweir 			aResult[14] = b14;
178*cdf0e10cSrcweir 			aResult[15] = b15;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 			return aResult;
181*cdf0e10cSrcweir 		}
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	//==================================================================
186*cdf0e10cSrcweir 	//= OLinkedDocumentsAccess
187*cdf0e10cSrcweir 	//==================================================================
188*cdf0e10cSrcweir 	DBG_NAME(OLinkedDocumentsAccess)
189*cdf0e10cSrcweir 	//------------------------------------------------------------------
190*cdf0e10cSrcweir 	OLinkedDocumentsAccess::OLinkedDocumentsAccess( Window* _pDialogParent, const Reference< XDatabaseDocumentUI >& i_rDocumentUI,
191*cdf0e10cSrcweir         const Reference< XMultiServiceFactory >& _rxORB, const Reference< XNameAccess >& _rxContainer,
192*cdf0e10cSrcweir         const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName )
193*cdf0e10cSrcweir 		:m_xORB(_rxORB)
194*cdf0e10cSrcweir 		,m_xDocumentContainer(_rxContainer)
195*cdf0e10cSrcweir 		,m_xConnection(_xConnection)
196*cdf0e10cSrcweir         ,m_xDocumentUI( i_rDocumentUI )
197*cdf0e10cSrcweir 		,m_pDialogParent(_pDialogParent)
198*cdf0e10cSrcweir         ,m_sDataSourceName(_sDataSourceName)
199*cdf0e10cSrcweir 	{
200*cdf0e10cSrcweir 		DBG_CTOR(OLinkedDocumentsAccess,NULL);
201*cdf0e10cSrcweir 		OSL_ENSURE(m_xORB.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid service factory!");
202*cdf0e10cSrcweir 		OSL_ENSURE(m_pDialogParent, "OLinkedDocumentsAccess::OLinkedDocumentsAccess: really need a dialog parent!");
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	//------------------------------------------------------------------
205*cdf0e10cSrcweir 	OLinkedDocumentsAccess::~OLinkedDocumentsAccess()
206*cdf0e10cSrcweir 	{
207*cdf0e10cSrcweir 		DBG_DTOR(OLinkedDocumentsAccess,NULL);
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir 	//------------------------------------------------------------------
210*cdf0e10cSrcweir 	Reference< XComponent> OLinkedDocumentsAccess::impl_open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
211*cdf0e10cSrcweir         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		Reference< XComponent> xRet;
214*cdf0e10cSrcweir         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid document container!");
215*cdf0e10cSrcweir 		Reference< XComponentLoader > xComponentLoader(m_xDocumentContainer,UNO_QUERY);
216*cdf0e10cSrcweir 		if ( !xComponentLoader.is() )
217*cdf0e10cSrcweir 			return xRet;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		WaitObject aWaitCursor( m_pDialogParent );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArguments;
222*cdf0e10cSrcweir         ::rtl::OUString sOpenMode;
223*cdf0e10cSrcweir 		switch ( _eOpenMode )
224*cdf0e10cSrcweir 		{
225*cdf0e10cSrcweir             case E_OPEN_NORMAL:
226*cdf0e10cSrcweir                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) );
227*cdf0e10cSrcweir                 break;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir             case E_OPEN_FOR_MAIL:
230*cdf0e10cSrcweir                 aArguments.put( "Hidden", true );
231*cdf0e10cSrcweir                 // fall through
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir             case E_OPEN_DESIGN:
234*cdf0e10cSrcweir                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
235*cdf0e10cSrcweir                 break;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir             default:
238*cdf0e10cSrcweir                 OSL_ENSURE( false, "OLinkedDocumentsAccess::implOpen: invalid open mode!" );
239*cdf0e10cSrcweir                 break;
240*cdf0e10cSrcweir         }
241*cdf0e10cSrcweir         aArguments.put( "OpenMode", sOpenMode );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir         aArguments.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
244*cdf0e10cSrcweir 		try
245*cdf0e10cSrcweir 		{
246*cdf0e10cSrcweir 			Reference<XHierarchicalNameContainer> xHier(m_xDocumentContainer,UNO_QUERY);
247*cdf0e10cSrcweir 			if ( xHier.is() && xHier->hasByHierarchicalName(_rLinkName) )
248*cdf0e10cSrcweir 			{
249*cdf0e10cSrcweir 				_xDefinition.set(xHier->getByHierarchicalName(_rLinkName),UNO_QUERY);
250*cdf0e10cSrcweir 			}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir             aArguments.merge( _rAdditionalArgs, true );
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 			xRet = xComponentLoader->loadComponentFromURL( _rLinkName, ::rtl::OUString(), 0, aArguments.getPropertyValues() );
255*cdf0e10cSrcweir 		}
256*cdf0e10cSrcweir 		catch(Exception& e)
257*cdf0e10cSrcweir 		{
258*cdf0e10cSrcweir 			(void)e;
259*cdf0e10cSrcweir 			throw;
260*cdf0e10cSrcweir 		}
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 		return xRet;
263*cdf0e10cSrcweir 	}
264*cdf0e10cSrcweir     //------------------------------------------------------------------
265*cdf0e10cSrcweir     void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService,
266*cdf0e10cSrcweir         const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		try
269*cdf0e10cSrcweir 		{
270*cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArgs;
271*cdf0e10cSrcweir             aArgs.put( "DataSourceName", m_sDataSourceName );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 			if ( m_xConnection.is() )
274*cdf0e10cSrcweir                 aArgs.put( "ActiveConnection", m_xConnection );
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir             if ( _rObjectName.getLength() && ( _nCommandType != -1 ) )
277*cdf0e10cSrcweir             {
278*cdf0e10cSrcweir                 aArgs.put( "CommandType", _nCommandType );
279*cdf0e10cSrcweir                 aArgs.put( "Command", _rObjectName );
280*cdf0e10cSrcweir             }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir             aArgs.put( "DocumentUI", m_xDocumentUI );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 			Reference< XJobExecutor > xWizard;
285*cdf0e10cSrcweir 			{
286*cdf0e10cSrcweir 				WaitObject aWaitCursor( m_pDialogParent );
287*cdf0e10cSrcweir                 xWizard.set( m_xORB->createInstanceWithArguments(
288*cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii( _pWizardService ),
289*cdf0e10cSrcweir                     aArgs.getWrappedPropertyValues()
290*cdf0e10cSrcweir                     ), UNO_QUERY_THROW );
291*cdf0e10cSrcweir 			}
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 			xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) );
294*cdf0e10cSrcweir             ::comphelper::disposeComponent( xWizard );
295*cdf0e10cSrcweir 		}
296*cdf0e10cSrcweir 		catch(const Exception& e)
297*cdf0e10cSrcweir 		{
298*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
299*cdf0e10cSrcweir 		}
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir 	//------------------------------------------------------------------
302*cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName );
305*cdf0e10cSrcweir 	}
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     //------------------------------------------------------------------
308*cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
309*cdf0e10cSrcweir 	{
310*cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName );
311*cdf0e10cSrcweir 	}
312*cdf0e10cSrcweir     //------------------------------------------------------------------
313*cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newTableWithPilot()
314*cdf0e10cSrcweir 	{
315*cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() );
316*cdf0e10cSrcweir 	}
317*cdf0e10cSrcweir     //------------------------------------------------------------------
318*cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newQueryWithPilot()
319*cdf0e10cSrcweir 	{
320*cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() );
321*cdf0e10cSrcweir 	}
322*cdf0e10cSrcweir 	//------------------------------------------------------------------
323*cdf0e10cSrcweir     Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID,
324*cdf0e10cSrcweir         const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!");
327*cdf0e10cSrcweir 		// determine the class ID to use for the new document
328*cdf0e10cSrcweir 		Sequence<sal_Int8> aClassId;
329*cdf0e10cSrcweir         if  (   !i_rCreationArgs.has( "ClassID" )
330*cdf0e10cSrcweir             &&  !i_rCreationArgs.has( "MediaType" )
331*cdf0e10cSrcweir             &&  !i_rCreationArgs.has( "DocumentServiceName" )
332*cdf0e10cSrcweir             )
333*cdf0e10cSrcweir         {
334*cdf0e10cSrcweir 		    switch ( i_nActionID )
335*cdf0e10cSrcweir 		    {
336*cdf0e10cSrcweir 			    case ID_FORM_NEW_TEXT:
337*cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID);
338*cdf0e10cSrcweir 				    OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal");
339*cdf0e10cSrcweir 				    break;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 			    case ID_FORM_NEW_CALC:
342*cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID);
343*cdf0e10cSrcweir 				    break;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 			    case ID_FORM_NEW_IMPRESS:
346*cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID);
347*cdf0e10cSrcweir 				    break;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 			    case ID_REPORT_NEW_TEXT:
350*cdf0e10cSrcweir 				    aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
351*cdf0e10cSrcweir 				    break;
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 			    default:
354*cdf0e10cSrcweir 				    OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" );
355*cdf0e10cSrcweir 				    return Reference< XComponent >();
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 		    }
358*cdf0e10cSrcweir         }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 		// load the document as template
361*cdf0e10cSrcweir 		Reference< XComponent > xNewDocument;
362*cdf0e10cSrcweir 		try
363*cdf0e10cSrcweir 		{	// get the desktop object
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 			Reference<XMultiServiceFactory> xORB(m_xDocumentContainer,UNO_QUERY);
366*cdf0e10cSrcweir 			if ( xORB.is() )
367*cdf0e10cSrcweir 			{
368*cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs );
369*cdf0e10cSrcweir                 if ( aClassId.getLength() )
370*cdf0e10cSrcweir                     aCreationArgs.put( "ClassID", aClassId );
371*cdf0e10cSrcweir                 aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir                 // separate values which are real creation args from args relevant for opening the doc
374*cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aCommandArgs;
375*cdf0e10cSrcweir                 if ( aCreationArgs.has( "Hidden" ) )
376*cdf0e10cSrcweir                 {
377*cdf0e10cSrcweir                     aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) );
378*cdf0e10cSrcweir                     aCreationArgs.remove( "Hidden" );
379*cdf0e10cSrcweir                 }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 				Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments(
382*cdf0e10cSrcweir                         SERVICE_SDB_DOCUMENTDEFINITION,
383*cdf0e10cSrcweir                         aCreationArgs.getWrappedPropertyValues()
384*cdf0e10cSrcweir                     ),
385*cdf0e10cSrcweir                     UNO_QUERY_THROW
386*cdf0e10cSrcweir                 );
387*cdf0e10cSrcweir 				o_rDefinition.set( xContent, UNO_QUERY );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir                 // put the OpenMode into the OpenArgs
390*cdf0e10cSrcweir                 OpenCommandArgument aOpenModeArg;
391*cdf0e10cSrcweir 			    aOpenModeArg.Mode = OpenMode::DOCUMENT;
392*cdf0e10cSrcweir                 aCommandArgs.put( "OpenMode", aOpenModeArg );
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 			    Command aCommand;
395*cdf0e10cSrcweir 			    aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
396*cdf0e10cSrcweir 			    aCommand.Argument <<= aCommandArgs.getPropertyValues();
397*cdf0e10cSrcweir 			    WaitObject aWaitCursor( m_pDialogParent );
398*cdf0e10cSrcweir 			    xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY );
399*cdf0e10cSrcweir 			}
400*cdf0e10cSrcweir 		}
401*cdf0e10cSrcweir 		catch(const Exception& )
402*cdf0e10cSrcweir 		{
403*cdf0e10cSrcweir 			DBG_UNHANDLED_EXCEPTION();
404*cdf0e10cSrcweir 		}
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 		return xNewDocument;
407*cdf0e10cSrcweir 	}
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	//------------------------------------------------------------------
410*cdf0e10cSrcweir 	Reference< XComponent > OLinkedDocumentsAccess::open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
411*cdf0e10cSrcweir         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
412*cdf0e10cSrcweir 	{
413*cdf0e10cSrcweir 		dbtools::SQLExceptionInfo aInfo;
414*cdf0e10cSrcweir         Reference< XComponent > xRet;
415*cdf0e10cSrcweir 		try
416*cdf0e10cSrcweir 		{
417*cdf0e10cSrcweir 			xRet = impl_open( _rLinkName, _xDefinition, _eOpenMode, _rAdditionalArgs );
418*cdf0e10cSrcweir 			if ( !xRet.is() )
419*cdf0e10cSrcweir 			{
420*cdf0e10cSrcweir                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
421*cdf0e10cSrcweir                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir                 com::sun::star::sdbc::SQLException aSQLException;
424*cdf0e10cSrcweir                 aSQLException.Message = sMessage;
425*cdf0e10cSrcweir                 // aSQLException.Context = e.Context;
426*cdf0e10cSrcweir                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
427*cdf0e10cSrcweir 			}
428*cdf0e10cSrcweir 			return xRet;
429*cdf0e10cSrcweir 		}
430*cdf0e10cSrcweir 		catch (com::sun::star::io::WrongFormatException e)
431*cdf0e10cSrcweir 		{
432*cdf0e10cSrcweir             com::sun::star::sdbc::SQLException aSQLException;
433*cdf0e10cSrcweir             aSQLException.Message = e.Message;
434*cdf0e10cSrcweir             aSQLException.Context = e.Context;
435*cdf0e10cSrcweir 			aInfo = dbtools::SQLExceptionInfo(aSQLException);
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 			// more like a hack, insert an empty message
438*cdf0e10cSrcweir             String sText( ModuleRes( RID_STR_EXTENSION_NOT_PRESENT ) );
439*cdf0e10cSrcweir             sText.SearchAndReplaceAscii("$file$",_rLinkName);
440*cdf0e10cSrcweir             aInfo.prepend(sText);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 			String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
443*cdf0e10cSrcweir 			sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
444*cdf0e10cSrcweir             aInfo.prepend(sMessage);
445*cdf0e10cSrcweir         }
446*cdf0e10cSrcweir         catch(Exception& e)
447*cdf0e10cSrcweir         {
448*cdf0e10cSrcweir             Any aAny = ::cppu::getCaughtException();
449*cdf0e10cSrcweir             com::sun::star::sdbc::SQLException a;
450*cdf0e10cSrcweir             if ( !(aAny >>= a) || (a.ErrorCode != dbtools::ParameterInteractionCancelled) )
451*cdf0e10cSrcweir             {
452*cdf0e10cSrcweir                 com::sun::star::sdbc::SQLException aSQLException;
453*cdf0e10cSrcweir                 aSQLException.Message = e.Message;
454*cdf0e10cSrcweir                 aSQLException.Context = e.Context;
455*cdf0e10cSrcweir                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir                 // more like a hack, insert an empty message
458*cdf0e10cSrcweir                 aInfo.prepend(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \n")));
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
461*cdf0e10cSrcweir                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
462*cdf0e10cSrcweir                 aInfo.prepend(sMessage);
463*cdf0e10cSrcweir             }
464*cdf0e10cSrcweir         }
465*cdf0e10cSrcweir         if (aInfo.isValid())
466*cdf0e10cSrcweir         {
467*cdf0e10cSrcweir             showError(aInfo, VCLUnoHelper::GetInterface(m_pDialogParent), m_xORB );
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir         return xRet;
470*cdf0e10cSrcweir     }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir //......................................................................
474*cdf0e10cSrcweir }	// namespace dbaui
475*cdf0e10cSrcweir //......................................................................
476*cdf0e10cSrcweir 
477