196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
596de5490SAndrew Rist * distributed with this work for additional information
696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist * "License"); you may not use this file except in compliance
996de5490SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist * software distributed under the License is distributed on an
1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist * KIND, either express or implied. See the License for the
1796de5490SAndrew Rist * specific language governing permissions and limitations
1896de5490SAndrew Rist * under the License.
19cdf0e10cSrcweir *
2096de5490SAndrew Rist *************************************************************/
2196de5490SAndrew Rist
2296de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef _SBA_EXTCTRLR_HXX
28cdf0e10cSrcweir #include "exsrcbrw.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_FORMCOMPONENTTYPE_HPP_
31cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
34cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_XGRIDCOLUMNFACTORY_HPP_
37cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
40cdf0e10cSrcweir #include <com/sun/star/form/XLoadable.hpp>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
43cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _SBA_FORMADAPTER_HXX
46cdf0e10cSrcweir #include "formadapter.hxx"
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
49cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
52cdf0e10cSrcweir #include "dbustrings.hrc"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _DBU_REGHELPER_HXX_
55cdf0e10cSrcweir #include "dbu_reghelper.hxx"
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
58cdf0e10cSrcweir #include <tools/diagnose_ex.h>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir
61cdf0e10cSrcweir using namespace ::com::sun::star::uno;
62cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
63cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
64cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
65cdf0e10cSrcweir using namespace ::com::sun::star::beans;
66cdf0e10cSrcweir using namespace ::com::sun::star::container;
67cdf0e10cSrcweir using namespace ::com::sun::star::lang;
68cdf0e10cSrcweir using namespace ::com::sun::star::form;
69cdf0e10cSrcweir using namespace ::com::sun::star::frame;
70cdf0e10cSrcweir using namespace dbaui;
71cdf0e10cSrcweir
72cdf0e10cSrcweir //==============================================================================
73cdf0e10cSrcweir //= SbaExternalSourceBrowser
74cdf0e10cSrcweir //==============================================================================
createRegistryInfo_OFormGridView()75cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OFormGridView()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir static OMultiInstanceAutoRegistration< SbaExternalSourceBrowser > aAutoRegistration;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir //------------------------------------------------------------------------------
queryInterface(const Type & _rType)80cdf0e10cSrcweir Any SAL_CALL SbaExternalSourceBrowser::queryInterface(const Type& _rType) throw (RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir Any aRet = SbaXDataBrowserController::queryInterface(_rType);
83cdf0e10cSrcweir if(!aRet.hasValue())
84cdf0e10cSrcweir aRet = ::cppu::queryInterface(_rType,
85cdf0e10cSrcweir (::com::sun::star::util::XModifyBroadcaster*)this,
86cdf0e10cSrcweir (::com::sun::star::form::XLoadListener*)this);
87cdf0e10cSrcweir
88cdf0e10cSrcweir return aRet;
89cdf0e10cSrcweir }
DBG_NAME(SbaExternalSourceBrowser)90cdf0e10cSrcweir DBG_NAME(SbaExternalSourceBrowser)
91cdf0e10cSrcweir //------------------------------------------------------------------------------
92cdf0e10cSrcweir SbaExternalSourceBrowser::SbaExternalSourceBrowser(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM)
93cdf0e10cSrcweir :SbaXDataBrowserController(_rM)
94cdf0e10cSrcweir ,m_aModifyListeners(getMutex())
95cdf0e10cSrcweir ,m_pDataSourceImpl(NULL)
96cdf0e10cSrcweir ,m_bInQueryDispatch( sal_False )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir DBG_CTOR(SbaExternalSourceBrowser,NULL);
99cdf0e10cSrcweir
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir //------------------------------------------------------------------------------
~SbaExternalSourceBrowser()103cdf0e10cSrcweir SbaExternalSourceBrowser::~SbaExternalSourceBrowser()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir
106cdf0e10cSrcweir DBG_DTOR(SbaExternalSourceBrowser,NULL);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir //-------------------------------------------------------------------------
getSupportedServiceNames()110cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL SbaExternalSourceBrowser::getSupportedServiceNames() throw(RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir return getSupportedServiceNames_Static();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir // -------------------------------------------------------------------------
getImplementationName_Static()115cdf0e10cSrcweir ::rtl::OUString SbaExternalSourceBrowser::getImplementationName_Static() throw(RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OFormGridView"));
118cdf0e10cSrcweir }
119cdf0e10cSrcweir //-------------------------------------------------------------------------
getSupportedServiceNames_Static()120cdf0e10cSrcweir ::comphelper::StringSequence SbaExternalSourceBrowser::getSupportedServiceNames_Static() throw(RuntimeException)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir ::comphelper::StringSequence aSupported(1);
123cdf0e10cSrcweir aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.FormGridView"));
124cdf0e10cSrcweir return aSupported;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir //-------------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)127cdf0e10cSrcweir Reference< XInterface > SAL_CALL SbaExternalSourceBrowser::Create(const Reference<XMultiServiceFactory >& _rxFactory)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir return *(new SbaExternalSourceBrowser(_rxFactory));
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //-------------------------------------------------------------------------
getImplementationName()132cdf0e10cSrcweir ::rtl::OUString SAL_CALL SbaExternalSourceBrowser::getImplementationName() throw(RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir return getImplementationName_Static();
135cdf0e10cSrcweir }
136cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateForm()137cdf0e10cSrcweir Reference< XRowSet > SbaExternalSourceBrowser::CreateForm()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir m_pDataSourceImpl = new SbaXFormAdapter();
140cdf0e10cSrcweir return m_pDataSourceImpl;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir //------------------------------------------------------------------------------
InitializeForm(const Reference<XPropertySet> &)144cdf0e10cSrcweir sal_Bool SbaExternalSourceBrowser::InitializeForm(const Reference< XPropertySet > & /*i_formProperties*/)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir return sal_True;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir //------------------------------------------------------------------
LoadForm()150cdf0e10cSrcweir sal_Bool SbaExternalSourceBrowser::LoadForm()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir // as we don't have a main form (yet), we have nothing to do
153cdf0e10cSrcweir // we don't call FormLoaded, because this expects a working data source
154cdf0e10cSrcweir return sal_True;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir
158cdf0e10cSrcweir //------------------------------------------------------------------
modified(const::com::sun::star::lang::EventObject & aEvent)159cdf0e10cSrcweir void SbaExternalSourceBrowser::modified(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir SbaXDataBrowserController::modified(aEvent);
162cdf0e10cSrcweir
163cdf0e10cSrcweir // multiplex this event to all my listeners
164cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
165cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt(m_aModifyListeners);
166cdf0e10cSrcweir while (aIt.hasMoreElements())
167cdf0e10cSrcweir ((::com::sun::star::util::XModifyListener*)aIt.next())->modified(aEvt);
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir //------------------------------------------------------------------
dispatch(const::com::sun::star::util::URL & aURL,const Sequence<::com::sun::star::beans::PropertyValue> & aArgs)171cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::dispatch(const ::com::sun::star::util::URL& aURL, const Sequence< ::com::sun::star::beans::PropertyValue>& aArgs) throw(::com::sun::star::uno::RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir const ::com::sun::star::beans::PropertyValue* pArguments = aArgs.getConstArray();
174cdf0e10cSrcweir if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AddGridColumn")))
175cdf0e10cSrcweir {
176cdf0e10cSrcweir // search the argument describing the column to create
177cdf0e10cSrcweir ::rtl::OUString sControlType;
178cdf0e10cSrcweir sal_Int32 nControlPos = -1;
179cdf0e10cSrcweir Sequence< ::com::sun::star::beans::PropertyValue> aControlProps;
180cdf0e10cSrcweir sal_uInt16 i;
181cdf0e10cSrcweir for ( i = 0; i < aArgs.getLength(); ++i, ++pArguments )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnType")))
184cdf0e10cSrcweir {
185cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const ::rtl::OUString*)0));
186cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnType\" !");
187cdf0e10cSrcweir if (bCorrectType)
188cdf0e10cSrcweir sControlType = ::comphelper::getString(pArguments->Value);
189cdf0e10cSrcweir }
190cdf0e10cSrcweir else if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnPosition")))
191cdf0e10cSrcweir {
192cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const sal_Int16*)0));
193cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnPosition\" !");
194cdf0e10cSrcweir if (bCorrectType)
195cdf0e10cSrcweir nControlPos = ::comphelper::getINT16(pArguments->Value);
196cdf0e10cSrcweir }
197cdf0e10cSrcweir else if (pArguments->Name.equals(::rtl::OUString::createFromAscii("ColumnProperties")))
198cdf0e10cSrcweir {
199cdf0e10cSrcweir sal_Bool bCorrectType = pArguments->Value.getValueType().equals(::getCppuType((const Sequence< ::com::sun::star::beans::PropertyValue>*)0));
200cdf0e10cSrcweir OSL_ENSURE(bCorrectType, "invalid type for argument \"ColumnProperties\" !");
201cdf0e10cSrcweir if (bCorrectType)
202cdf0e10cSrcweir aControlProps = *(Sequence< ::com::sun::star::beans::PropertyValue>*)pArguments->Value.getValue();
203cdf0e10cSrcweir }
204cdf0e10cSrcweir else
205*24c56ab9SHerbert Dürr OSL_ENSURE(sal_False, ((ByteString("SbaExternalSourceBrowser::dispatch(AddGridColumn) : unknown argument (") += ByteString(pArguments->Name.getStr(), gsl_getSystemTextEncoding()).GetBuffer()) += ") !").GetBuffer());
206cdf0e10cSrcweir }
207cdf0e10cSrcweir if (!sControlType.getLength())
208cdf0e10cSrcweir {
209cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnType) !");
210cdf0e10cSrcweir sControlType = ::rtl::OUString::createFromAscii("TextField");
211cdf0e10cSrcweir }
212cdf0e10cSrcweir OSL_ENSURE(aControlProps.getLength(), "SbaExternalSourceBrowser::dispatch(AddGridColumn) : missing argument (ColumnProperties) !");
213cdf0e10cSrcweir
214cdf0e10cSrcweir // create the col
215cdf0e10cSrcweir Reference< ::com::sun::star::form::XGridColumnFactory > xColFactory(getControlModel(), UNO_QUERY);
216cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xNewCol = xColFactory->createColumn(sControlType);
217cdf0e10cSrcweir Reference< XPropertySetInfo > xNewColProperties;
218cdf0e10cSrcweir if (xNewCol.is())
219cdf0e10cSrcweir xNewColProperties = xNewCol->getPropertySetInfo();
220cdf0e10cSrcweir // set it's properties
221cdf0e10cSrcweir if (xNewColProperties.is())
222cdf0e10cSrcweir {
223cdf0e10cSrcweir const ::com::sun::star::beans::PropertyValue* pControlProps = aControlProps.getConstArray();
224cdf0e10cSrcweir for (i=0; i<aControlProps.getLength(); ++i, ++pControlProps)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir try
227cdf0e10cSrcweir {
228cdf0e10cSrcweir if (xNewColProperties->hasPropertyByName(pControlProps->Name))
229cdf0e10cSrcweir xNewCol->setPropertyValue(pControlProps->Name, pControlProps->Value);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir catch(Exception&)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir OSL_ENSURE(sal_False,
234cdf0e10cSrcweir ( ByteString("SbaExternalSourceBrowser::dispatch : could not set a column property (")
235cdf0e10cSrcweir += ByteString(pControlProps->Name.getStr(), (sal_uInt16)pControlProps->Name.getLength(), RTL_TEXTENCODING_ASCII_US)
236cdf0e10cSrcweir += ByteString(")!")).GetBuffer());
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir // correct the position
242cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY);
243cdf0e10cSrcweir
244cdf0e10cSrcweir if (nControlPos > xColContainer->getCount())
245cdf0e10cSrcweir nControlPos = xColContainer->getCount();
246cdf0e10cSrcweir if (nControlPos < 0)
247cdf0e10cSrcweir nControlPos = 0;
248cdf0e10cSrcweir
249cdf0e10cSrcweir // append the column
250cdf0e10cSrcweir xColContainer->insertByIndex(nControlPos, makeAny(xNewCol));
251cdf0e10cSrcweir }
252cdf0e10cSrcweir else if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/ClearView")))
253cdf0e10cSrcweir {
254cdf0e10cSrcweir ClearView();
255cdf0e10cSrcweir }
256cdf0e10cSrcweir else if (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AttachToForm")))
257cdf0e10cSrcweir {
258cdf0e10cSrcweir if (!m_pDataSourceImpl)
259cdf0e10cSrcweir return;
260cdf0e10cSrcweir
261cdf0e10cSrcweir Reference< XRowSet > xMasterForm;
262cdf0e10cSrcweir // search the arguments for he master form
263cdf0e10cSrcweir for (sal_uInt16 i=0; i<aArgs.getLength(); ++i, ++pArguments)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir if ((pArguments->Name.equals(::rtl::OUString::createFromAscii("MasterForm"))) && (pArguments->Value.getValueTypeClass() == TypeClass_INTERFACE))
266cdf0e10cSrcweir {
267cdf0e10cSrcweir xMasterForm = Reference< XRowSet > (*(Reference< XInterface > *)pArguments->Value.getValue(), UNO_QUERY);
268cdf0e10cSrcweir break;
269cdf0e10cSrcweir }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir if (!xMasterForm.is())
272cdf0e10cSrcweir {
273cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::dispatch(FormSlots/AttachToForm) : please specify a form to attach to as argument !");
274cdf0e10cSrcweir return;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir Attach(xMasterForm);
278cdf0e10cSrcweir }
279cdf0e10cSrcweir else
280cdf0e10cSrcweir SbaXDataBrowserController::dispatch(aURL, aArgs);
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir //------------------------------------------------------------------
queryDispatch(const::com::sun::star::util::URL & aURL,const::rtl::OUString & aTargetFrameName,sal_Int32 nSearchFlags)284cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch > SAL_CALL SbaExternalSourceBrowser::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatch > xReturn;
287cdf0e10cSrcweir if (m_bInQueryDispatch)
288cdf0e10cSrcweir return xReturn;
289cdf0e10cSrcweir
290cdf0e10cSrcweir m_bInQueryDispatch = sal_True;
291cdf0e10cSrcweir
292cdf0e10cSrcweir if ( (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AttachToForm")))
293cdf0e10cSrcweir // attach a new external form
294cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/AddGridColumn")))
295cdf0e10cSrcweir // add a column to the grid
296cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/ClearView")))
297cdf0e10cSrcweir // clear the grid
298cdf0e10cSrcweir )
299cdf0e10cSrcweir xReturn = (::com::sun::star::frame::XDispatch*)this;
300cdf0e10cSrcweir
301cdf0e10cSrcweir if ( !xReturn.is()
302cdf0e10cSrcweir && ( (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToFirst")))
303cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToPrev")))
304cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToNext")))
305cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToLast")))
306cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/moveToNew")))
307cdf0e10cSrcweir || (aURL.Complete.equals(::rtl::OUString::createFromAscii(".uno:FormSlots/undoRecord")))
308cdf0e10cSrcweir )
309cdf0e10cSrcweir )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir OSL_ENSURE(aURL.Mark.getLength() == 0, "SbaExternalSourceBrowser::queryDispatch : the ::com::sun::star::util::URL shouldn't have a mark !");
312cdf0e10cSrcweir ::com::sun::star::util::URL aNewUrl = aURL;
313cdf0e10cSrcweir
314cdf0e10cSrcweir // split the ::com::sun::star::util::URL
315cdf0e10cSrcweir OSL_ENSURE( m_xUrlTransformer.is(), "SbaExternalSourceBrowser::queryDispatch : could not create an URLTransformer !" );
316cdf0e10cSrcweir if ( m_xUrlTransformer.is() )
317cdf0e10cSrcweir m_xUrlTransformer->parseStrict( aNewUrl );
318cdf0e10cSrcweir
319cdf0e10cSrcweir // set a new mark
320cdf0e10cSrcweir aNewUrl.Mark = ::rtl::OUString::createFromAscii("DB/FormGridView");
321cdf0e10cSrcweir // this controller is instantiated when somebody dispatches the ".component:DB/FormGridView" in any
322cdf0e10cSrcweir // frame, so we use "FormGridView" as mark that a dispatch request came from this view
323cdf0e10cSrcweir
324cdf0e10cSrcweir if (m_xUrlTransformer.is())
325cdf0e10cSrcweir m_xUrlTransformer->assemble(aNewUrl);
326cdf0e10cSrcweir
327cdf0e10cSrcweir Reference< XDispatchProvider > xFrameDispatcher( getFrame(), UNO_QUERY );
328cdf0e10cSrcweir if (xFrameDispatcher.is())
329cdf0e10cSrcweir xReturn = xFrameDispatcher->queryDispatch(aNewUrl, aTargetFrameName, FrameSearchFlag::PARENT);
330cdf0e10cSrcweir
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir if (!xReturn.is())
334cdf0e10cSrcweir xReturn = SbaXDataBrowserController::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
335cdf0e10cSrcweir
336cdf0e10cSrcweir m_bInQueryDispatch = sal_False;
337cdf0e10cSrcweir return xReturn;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir //------------------------------------------------------------------
disposing()341cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::disposing()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir // say our modify listeners goodbye
344cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt;
345cdf0e10cSrcweir aEvt.Source = (XWeak*) this;
346cdf0e10cSrcweir m_aModifyListeners.disposeAndClear(aEvt);
347cdf0e10cSrcweir
348cdf0e10cSrcweir stopListening();
349cdf0e10cSrcweir
350cdf0e10cSrcweir SbaXDataBrowserController::disposing();
351cdf0e10cSrcweir }
352cdf0e10cSrcweir
353cdf0e10cSrcweir //------------------------------------------------------------------
addModifyListener(const Reference<::com::sun::star::util::XModifyListener> & aListener)354cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::addModifyListener(const Reference< ::com::sun::star::util::XModifyListener > & aListener) throw( RuntimeException )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir m_aModifyListeners.addInterface(aListener);
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir //------------------------------------------------------------------
removeModifyListener(const Reference<::com::sun::star::util::XModifyListener> & aListener)360cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::removeModifyListener(const Reference< ::com::sun::star::util::XModifyListener > & aListener) throw( RuntimeException )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir m_aModifyListeners.removeInterface(aListener);
363cdf0e10cSrcweir }
364cdf0e10cSrcweir
365cdf0e10cSrcweir //------------------------------------------------------------------
unloading(const::com::sun::star::lang::EventObject & aEvent)366cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( RuntimeException )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir if (m_pDataSourceImpl && (m_pDataSourceImpl->getAttachedForm() == aEvent.Source))
369cdf0e10cSrcweir {
370cdf0e10cSrcweir ClearView();
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
373cdf0e10cSrcweir SbaXDataBrowserController::unloading(aEvent);
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
376cdf0e10cSrcweir //------------------------------------------------------------------
Attach(const Reference<XRowSet> & xMaster)377cdf0e10cSrcweir void SbaExternalSourceBrowser::Attach(const Reference< XRowSet > & xMaster)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir Any aOldPos;
380cdf0e10cSrcweir sal_Bool bWasInsertRow = sal_False;
381cdf0e10cSrcweir sal_Bool bBeforeFirst = sal_True;
382cdf0e10cSrcweir sal_Bool bAfterLast = sal_True;
383cdf0e10cSrcweir Reference< XResultSet > xResultSet(xMaster, UNO_QUERY);
384cdf0e10cSrcweir Reference< XRowLocate > xCursor(xMaster, UNO_QUERY);
385cdf0e10cSrcweir Reference< XPropertySet > xMasterProps(xMaster, UNO_QUERY);
386cdf0e10cSrcweir
387cdf0e10cSrcweir try
388cdf0e10cSrcweir {
389cdf0e10cSrcweir // switch the control to design mode
390cdf0e10cSrcweir if (getBrowserView() && getBrowserView()->getGridControl().is())
391cdf0e10cSrcweir getBrowserView()->getGridControl()->setDesignMode(sal_True);
392cdf0e10cSrcweir
393cdf0e10cSrcweir // the grid will move the form's cursor to the first record, but we want the form to remain unchanged
394cdf0e10cSrcweir // restore the old position
395cdf0e10cSrcweir if (xCursor.is() && xResultSet.is())
396cdf0e10cSrcweir {
397cdf0e10cSrcweir bBeforeFirst = xResultSet->isBeforeFirst();
398cdf0e10cSrcweir bAfterLast = xResultSet->isAfterLast();
399cdf0e10cSrcweir if(!bBeforeFirst && !bAfterLast)
400cdf0e10cSrcweir aOldPos = xCursor->getBookmark();
401cdf0e10cSrcweir }
402cdf0e10cSrcweir
403cdf0e10cSrcweir if (xMasterProps.is())
404cdf0e10cSrcweir xMasterProps->getPropertyValue(PROPERTY_ISNEW) >>= bWasInsertRow;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir catch( const Exception& )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
409cdf0e10cSrcweir }
410cdf0e10cSrcweir
411cdf0e10cSrcweir onStartLoading( Reference< XLoadable >( xMaster, UNO_QUERY ) );
412cdf0e10cSrcweir
413cdf0e10cSrcweir stopListening();
414cdf0e10cSrcweir m_pDataSourceImpl->AttachForm(xMaster);
415cdf0e10cSrcweir startListening();
416cdf0e10cSrcweir
417cdf0e10cSrcweir if (xMaster.is())
418cdf0e10cSrcweir {
419cdf0e10cSrcweir // at this point we have to reset the formatter for the new form
420cdf0e10cSrcweir initFormatter();
421cdf0e10cSrcweir // assume that the master form is already loaded
422cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
423cdf0e10cSrcweir {
424cdf0e10cSrcweir Reference< XLoadable > xLoadable( xMaster, UNO_QUERY );
425cdf0e10cSrcweir OSL_ENSURE( xLoadable.is() && xLoadable->isLoaded(), "SbaExternalSourceBrowser::Attach: master is not loaded!" );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir #endif
428cdf0e10cSrcweir
429cdf0e10cSrcweir LoadFinished(sal_True);
430cdf0e10cSrcweir
431cdf0e10cSrcweir Reference< XResultSetUpdate > xUpdate(xMaster, UNO_QUERY);
432cdf0e10cSrcweir try
433cdf0e10cSrcweir {
434cdf0e10cSrcweir if (bWasInsertRow && xUpdate.is())
435cdf0e10cSrcweir xUpdate->moveToInsertRow();
436cdf0e10cSrcweir else if (xCursor.is() && aOldPos.hasValue())
437cdf0e10cSrcweir xCursor->moveToBookmark(aOldPos);
438cdf0e10cSrcweir else if(bBeforeFirst && xResultSet.is())
439cdf0e10cSrcweir xResultSet->beforeFirst();
440cdf0e10cSrcweir else if(bAfterLast && xResultSet.is())
441cdf0e10cSrcweir xResultSet->afterLast();
442cdf0e10cSrcweir }
443cdf0e10cSrcweir catch(Exception&)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir OSL_ENSURE(sal_False, "SbaExternalSourceBrowser::Attach : couldn't restore the cursor position !");
446cdf0e10cSrcweir }
447cdf0e10cSrcweir
448cdf0e10cSrcweir }
449cdf0e10cSrcweir }
450cdf0e10cSrcweir
451cdf0e10cSrcweir //------------------------------------------------------------------
ClearView()452cdf0e10cSrcweir void SbaExternalSourceBrowser::ClearView()
453cdf0e10cSrcweir {
454cdf0e10cSrcweir // set a new (empty) datasource
455cdf0e10cSrcweir Attach(Reference< XRowSet > ());
456cdf0e10cSrcweir
457cdf0e10cSrcweir
458cdf0e10cSrcweir // clear all cols in the grid
459cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexContainer > xColContainer(getControlModel(), UNO_QUERY);
460cdf0e10cSrcweir while (xColContainer->getCount() > 0)
461cdf0e10cSrcweir xColContainer->removeByIndex(0);
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir //------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject & Source)465cdf0e10cSrcweir void SAL_CALL SbaExternalSourceBrowser::disposing(const ::com::sun::star::lang::EventObject& Source) throw( RuntimeException )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir if (m_pDataSourceImpl && (m_pDataSourceImpl->getAttachedForm() == Source.Source))
468cdf0e10cSrcweir {
469cdf0e10cSrcweir ClearView();
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir SbaXDataBrowserController::disposing(Source);
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
475cdf0e10cSrcweir //------------------------------------------------------------------
startListening()476cdf0e10cSrcweir void SbaExternalSourceBrowser::startListening()
477cdf0e10cSrcweir {
478cdf0e10cSrcweir if (m_pDataSourceImpl && m_pDataSourceImpl->getAttachedForm().is())
479cdf0e10cSrcweir {
480cdf0e10cSrcweir Reference< ::com::sun::star::form::XLoadable > xLoadable(m_pDataSourceImpl->getAttachedForm(), UNO_QUERY);
481cdf0e10cSrcweir xLoadable->addLoadListener((::com::sun::star::form::XLoadListener*)this);
482cdf0e10cSrcweir }
483cdf0e10cSrcweir }
484cdf0e10cSrcweir
485cdf0e10cSrcweir //------------------------------------------------------------------
stopListening()486cdf0e10cSrcweir void SbaExternalSourceBrowser::stopListening()
487cdf0e10cSrcweir {
488cdf0e10cSrcweir if (m_pDataSourceImpl && m_pDataSourceImpl->getAttachedForm().is())
489cdf0e10cSrcweir {
490cdf0e10cSrcweir Reference< ::com::sun::star::form::XLoadable > xLoadable(m_pDataSourceImpl->getAttachedForm(), UNO_QUERY);
491cdf0e10cSrcweir xLoadable->removeLoadListener((::com::sun::star::form::XLoadListener*)this);
492cdf0e10cSrcweir }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir
495cdf0e10cSrcweir //==================================================================
496cdf0e10cSrcweir //==================================================================
497