merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / dlg / adodatalinks.cxx
blob9068d58ef421b272001c82f1f95dceec1058fd5a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adodatalinks.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
35 #if defined(WIN) || defined(WNT)
36 #if defined _MSC_VER
37 #pragma warning(push, 1)
38 #pragma warning(disable: 4917)
39 #endif
40 #include "msdasc.h" // OLE DB Service Component header
41 #if defined _MSC_VER
42 #pragma warning(push, 1)
43 #endif
44 #include "stdio.h"
46 #include <initguid.h> // Include only once in your application
47 #include <adoid.h> // needed for CLSID_CADOConnection
48 #include <adoint.h> // needed for ADOConnection
50 #ifndef _DBAUI_ADO_DATALINK_HXX_
51 #include "adodatalinks.hxx"
52 #endif
54 BSTR PromptEdit(long hWnd,BSTR connstr);
55 BSTR PromptNew(long hWnd);
57 ::rtl::OUString getAdoDatalink(long hWnd,::rtl::OUString& oldLink)
59 ::rtl::OUString dataLink;
60 if (oldLink.getLength())
62 dataLink=reinterpret_cast<sal_Unicode *>(PromptEdit(hWnd,(BSTR)oldLink.getStr()));
64 else
65 dataLink=reinterpret_cast<sal_Unicode *>(PromptNew(hWnd));
66 return dataLink;
68 BSTR PromptNew(long hWnd)
70 BSTR connstr=NULL;
71 HRESULT hr;
72 IDataSourceLocator* dlPrompt = NULL;
73 ADOConnection* piTmpConnection = NULL;
74 BSTR _result=NULL;
76 // Initialize COM
77 ::CoInitialize( NULL );
79 // Instantiate DataLinks object.
80 hr = CoCreateInstance(
81 CLSID_DataLinks, //clsid -- Data Links UI
82 NULL, //pUnkOuter
83 CLSCTX_INPROC_SERVER, //dwClsContext
84 IID_IDataSourceLocator, //riid
85 (void**)&dlPrompt //ppvObj
87 if( FAILED( hr ) )
89 piTmpConnection->Release( );
90 dlPrompt->Release( );
91 return connstr;
94 dlPrompt->put_hWnd(hWnd);
95 if( FAILED( hr ) )
97 piTmpConnection->Release( );
98 dlPrompt->Release( );
99 return connstr;
102 // Prompt for connection information.
103 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
105 if( FAILED( hr ) || !piTmpConnection )
107 dlPrompt->Release( );
108 return connstr;
111 hr = piTmpConnection->get_ConnectionString(&_result);
112 if( FAILED( hr ) )
114 piTmpConnection->Release( );
115 dlPrompt->Release( );
116 return connstr;
119 piTmpConnection->Release( );
120 dlPrompt->Release( );
121 CoUninitialize();
122 return _result;
125 BSTR PromptEdit(long hWnd,BSTR connstr)
127 HRESULT hr;
128 IDataSourceLocator* dlPrompt = NULL;
129 ADOConnection* piTmpConnection = NULL;
130 BSTR _result=NULL;
132 // Initialize COM
133 ::CoInitialize( NULL );
135 hr = CoCreateInstance(CLSID_CADOConnection,
136 NULL,
137 CLSCTX_INPROC_SERVER,
138 IID_IADOConnection,
139 (LPVOID *)&piTmpConnection);
140 if( FAILED( hr ) )
142 piTmpConnection->Release( );
143 return connstr;
147 hr = piTmpConnection->put_ConnectionString(connstr);
148 if( FAILED( hr ) )
150 piTmpConnection->Release( );
151 return connstr;
154 // Instantiate DataLinks object.
155 hr = CoCreateInstance(
156 CLSID_DataLinks, //clsid -- Data Links UI
157 NULL, //pUnkOuter
158 CLSCTX_INPROC_SERVER, //dwClsContext
159 IID_IDataSourceLocator, //riid
160 (void**)&dlPrompt //ppvObj
162 if( FAILED( hr ) )
164 piTmpConnection->Release( );
165 dlPrompt->Release( );
166 return connstr;
169 dlPrompt->put_hWnd(hWnd);
170 if( FAILED( hr ) )
172 piTmpConnection->Release( );
173 dlPrompt->Release( );
174 return connstr;
177 VARIANT_BOOL pbSuccess;
179 // Prompt for connection information.
180 hr = dlPrompt->PromptEdit((IDispatch **)&piTmpConnection,&pbSuccess);
181 if( SUCCEEDED( hr ) && FALSE == pbSuccess ) //if user press cancel then FALSE == pbSuccess
183 piTmpConnection->Release( );
184 dlPrompt->Release( );
185 return connstr;
188 if( FAILED( hr ) )
190 // Prompt for new connection information.
191 piTmpConnection->Release( );
192 piTmpConnection = NULL;
193 hr = dlPrompt->PromptNew((IDispatch **)&piTmpConnection);
194 if( FAILED( hr ) || !piTmpConnection )
196 dlPrompt->Release( );
197 return connstr;
201 hr = piTmpConnection->get_ConnectionString(&_result);
202 if( FAILED( hr ) )
204 piTmpConnection->Release( );
205 dlPrompt->Release( );
206 return connstr;
209 piTmpConnection->Release( );
210 dlPrompt->Release( );
211 CoUninitialize();
212 return _result;
214 #endif