1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "AppController.hxx"
28cdf0e10cSrcweir #include "dbustrings.hrc"
29cdf0e10cSrcweir #include "advancedsettingsdlg.hxx"
30cdf0e10cSrcweir #include "subcomponentmanager.hxx"
31cdf0e10cSrcweir #include "closeveto.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /** === begin UNO includes === **/
34cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
35cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
36cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
37cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
41cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
42cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdb/XBookmarksSupplier.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAlterView.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRename.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
55cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
56cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
57cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
58cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
59cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
61cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp>
62cdf0e10cSrcweir #include <com/sun/star/frame/XModel2.hpp>
63cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
64cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
65cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
66cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
67cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
68cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
69cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
70cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
71cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
72cdf0e10cSrcweir #include <com/sun/star/sdb/application/DatabaseObject.hpp>
73cdf0e10cSrcweir #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
74cdf0e10cSrcweir #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
75cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalName.hpp>
76cdf0e10cSrcweir /** === end UNO includes === **/
77cdf0e10cSrcweir #include <tools/debug.hxx>
78cdf0e10cSrcweir #include <tools/diagnose_ex.h>
79cdf0e10cSrcweir #include <tools/string.hxx>
80cdf0e10cSrcweir 
81cdf0e10cSrcweir #include <svl/urihelper.hxx>
82cdf0e10cSrcweir #include <svl/filenotation.hxx>
83cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
84cdf0e10cSrcweir #include <svtools/transfer.hxx>
85cdf0e10cSrcweir #include <svtools/cliplistener.hxx>
86cdf0e10cSrcweir #include <svtools/svlbitm.hxx>
87cdf0e10cSrcweir #include <svtools/insdlg.hxx>
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #include <comphelper/sequence.hxx>
90cdf0e10cSrcweir #include <comphelper/uno3.hxx>
91cdf0e10cSrcweir #include <comphelper/string.hxx>
92cdf0e10cSrcweir #include <comphelper/types.hxx>
93cdf0e10cSrcweir #include <comphelper/interaction.hxx>
94cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
95cdf0e10cSrcweir 
96cdf0e10cSrcweir #include <vcl/msgbox.hxx>
97cdf0e10cSrcweir #include <vcl/stdtext.hxx>
98cdf0e10cSrcweir #include <vcl/svapp.hxx>
99cdf0e10cSrcweir #include <vcl/menu.hxx>
100cdf0e10cSrcweir #include <vcl/lstbox.hxx>
101cdf0e10cSrcweir 
102cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
103cdf0e10cSrcweir #include <unotools/tempfile.hxx>
104cdf0e10cSrcweir #include <unotools/internaloptions.hxx>
105cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
106cdf0e10cSrcweir #include <unotools/historyoptions.hxx>
107cdf0e10cSrcweir 
108cdf0e10cSrcweir #include <sfx2/mailmodelapi.hxx>
109cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
110cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
111cdf0e10cSrcweir #include <sfx2/QuerySaveDocument.hxx>
112cdf0e10cSrcweir 
113cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
114cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
115cdf0e10cSrcweir 
116cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
117cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
118cdf0e10cSrcweir 
119cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
120cdf0e10cSrcweir #include <svx/dbaobjectex.hxx>
121cdf0e10cSrcweir #include <svx/svxdlg.hxx>
122cdf0e10cSrcweir 
123cdf0e10cSrcweir #include <vos/mutex.hxx>
124cdf0e10cSrcweir #include "AppView.hxx"
125cdf0e10cSrcweir #include "browserids.hxx"
126cdf0e10cSrcweir #include "dbu_reghelper.hxx"
127cdf0e10cSrcweir #include "dbu_app.hrc"
128cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
129cdf0e10cSrcweir #include "databaseobjectview.hxx"
130cdf0e10cSrcweir #include "listviewitems.hxx"
131cdf0e10cSrcweir #include "AppDetailView.hxx"
132cdf0e10cSrcweir #include "linkeddocuments.hxx"
133cdf0e10cSrcweir #include "sqlmessage.hxx"
134cdf0e10cSrcweir #include "UITools.hxx"
135cdf0e10cSrcweir #include "dsntypes.hxx"
136cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
137cdf0e10cSrcweir #include "dlgsave.hxx"
138cdf0e10cSrcweir #include "dbaccess_slotid.hrc"
139cdf0e10cSrcweir 
140cdf0e10cSrcweir #include <algorithm>
141cdf0e10cSrcweir #include <functional>
142cdf0e10cSrcweir 
143cdf0e10cSrcweir #include <boost/noncopyable.hpp>
144cdf0e10cSrcweir 
145cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_ODBApplication()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OApplicationController > aAutoRegistration;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir //........................................................................
150cdf0e10cSrcweir namespace dbaui
151cdf0e10cSrcweir {
152cdf0e10cSrcweir //........................................................................
153cdf0e10cSrcweir using namespace ::dbtools;
154cdf0e10cSrcweir using namespace ::svx;
155cdf0e10cSrcweir using namespace ::com::sun::star;
156cdf0e10cSrcweir using namespace ::com::sun::star::uno;
157cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
158cdf0e10cSrcweir using namespace ::com::sun::star::view;
159cdf0e10cSrcweir using namespace ::com::sun::star::util;
160cdf0e10cSrcweir using namespace ::com::sun::star::beans;
161cdf0e10cSrcweir using namespace ::com::sun::star::lang;
162cdf0e10cSrcweir using namespace ::com::sun::star::frame;
163cdf0e10cSrcweir using namespace ::com::sun::star::container;
164cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
165cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
166cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
167cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
168cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
169cdf0e10cSrcweir using namespace ::com::sun::star::task;
170cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts;
171cdf0e10cSrcweir using ::com::sun::star::document::XDocumentEventBroadcaster;
172cdf0e10cSrcweir using ::com::sun::star::document::DocumentEvent;
173cdf0e10cSrcweir using ::com::sun::star::sdb::application::NamedDatabaseObject;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
176cdf0e10cSrcweir namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //------------------------------------------------------------------------------
179cdf0e10cSrcweir ::rtl::OUString SAL_CALL OApplicationController::getImplementationName() throw( RuntimeException )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	return getImplementationName_Static();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir //------------------------------------------------------------------------------
185cdf0e10cSrcweir ::rtl::OUString OApplicationController::getImplementationName_Static() throw( RuntimeException )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	return ::rtl::OUString(SERVICE_SDB_APPLICATIONCONTROLLER);
188cdf0e10cSrcweir }
189cdf0e10cSrcweir //------------------------------------------------------------------------------
190cdf0e10cSrcweir Sequence< ::rtl::OUString> OApplicationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	Sequence< ::rtl::OUString> aSupported(1);
193cdf0e10cSrcweir 	aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.application.DefaultViewController");
194cdf0e10cSrcweir 	return aSupported;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir //-------------------------------------------------------------------------
197cdf0e10cSrcweir Sequence< ::rtl::OUString> SAL_CALL OApplicationController::getSupportedServiceNames() throw(RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir // -------------------------------------------------------------------------
202cdf0e10cSrcweir Reference< XInterface > SAL_CALL OApplicationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	return *(new OApplicationController(_rxFactory));
205cdf0e10cSrcweir }
206cdf0e10cSrcweir // -----------------------------------------------------------------------------
207cdf0e10cSrcweir 
208cdf0e10cSrcweir struct XContainerFunctor : public ::std::unary_function< OApplicationController::TContainerVector::value_type , bool>
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	Reference<XContainerListener> m_xContainerListener;
211cdf0e10cSrcweir 	XContainerFunctor( const Reference<XContainerListener>& _xContainerListener)
212cdf0e10cSrcweir 		: m_xContainerListener(_xContainerListener){}
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	bool operator() (const OApplicationController::TContainerVector::value_type& lhs) const
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		if ( lhs.is() )
217cdf0e10cSrcweir 			lhs->removeContainerListener(m_xContainerListener);
218cdf0e10cSrcweir 		return true;
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir };
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //====================================================================
223cdf0e10cSrcweir //= OApplicationController
224cdf0e10cSrcweir //====================================================================
225cdf0e10cSrcweir class SelectionNotifier : public ::boost::noncopyable
226cdf0e10cSrcweir {
227cdf0e10cSrcweir private:
228cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper   m_aSelectionListeners;
229cdf0e10cSrcweir     ::cppu::OWeakObject&                m_rContext;
230cdf0e10cSrcweir     sal_Int32                           m_nSelectionNestingLevel;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir public:
233cdf0e10cSrcweir     SelectionNotifier( ::osl::Mutex& _rMutex, ::cppu::OWeakObject& _rContext )
234cdf0e10cSrcweir         :m_aSelectionListeners( _rMutex )
235cdf0e10cSrcweir         ,m_rContext( _rContext )
236cdf0e10cSrcweir         ,m_nSelectionNestingLevel( 0 )
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     void addListener( const Reference< XSelectionChangeListener >& _Listener )
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         m_aSelectionListeners.addInterface( _Listener );
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     void removeListener( const Reference< XSelectionChangeListener >& _Listener )
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         m_aSelectionListeners.removeInterface( _Listener );
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     void disposing()
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         EventObject aEvent( m_rContext );
253cdf0e10cSrcweir         m_aSelectionListeners.disposeAndClear( aEvent );
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     ~SelectionNotifier()
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     struct SelectionGuardAccess { friend class SelectionGuard; private: SelectionGuardAccess() { }  };
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     /** enters a block which modifies the selection of our owner.
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         Can be called multiple times, the only important thing is to call leaveSelection
265cdf0e10cSrcweir         equally often.
266cdf0e10cSrcweir     */
267cdf0e10cSrcweir     void    enterSelection( SelectionGuardAccess )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         ++m_nSelectionNestingLevel;
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     /** leaves a block which modifies the selection of our owner
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         Must be paired with enterSelection calls.
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         When the last block is left, i.e. the last leaveSelection call is made on the current stack,
277cdf0e10cSrcweir         then our SelectionChangeListeners are notified
278cdf0e10cSrcweir     */
279cdf0e10cSrcweir     void    leaveSelection( SelectionGuardAccess )
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         if ( --m_nSelectionNestingLevel == 0 )
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             EventObject aEvent( m_rContext );
284cdf0e10cSrcweir             m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aEvent );
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir     }
287cdf0e10cSrcweir };
288cdf0e10cSrcweir 
289cdf0e10cSrcweir class SelectionGuard : public ::boost::noncopyable
290cdf0e10cSrcweir {
291cdf0e10cSrcweir public:
292cdf0e10cSrcweir     SelectionGuard( SelectionNotifier& _rNotifier )
293cdf0e10cSrcweir         :m_rNotifier( _rNotifier )
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir         m_rNotifier.enterSelection( SelectionNotifier::SelectionGuardAccess() );
296cdf0e10cSrcweir     }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     ~SelectionGuard()
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir         m_rNotifier.leaveSelection( SelectionNotifier::SelectionGuardAccess() );
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir private:
304cdf0e10cSrcweir     SelectionNotifier&  m_rNotifier;
305cdf0e10cSrcweir };
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //====================================================================
308cdf0e10cSrcweir //= OApplicationController
309cdf0e10cSrcweir //====================================================================
310cdf0e10cSrcweir DBG_NAME(OApplicationController)
311cdf0e10cSrcweir //--------------------------------------------------------------------
312cdf0e10cSrcweir OApplicationController::OApplicationController(const Reference< XMultiServiceFactory >& _rxORB)
313cdf0e10cSrcweir 	:OApplicationController_CBASE( _rxORB )
314cdf0e10cSrcweir     ,m_aContextMenuInterceptors( getMutex() )
315cdf0e10cSrcweir     ,m_pSubComponentManager( new SubComponentManager( *this, getSharedMutex() ) )
316cdf0e10cSrcweir     ,m_aTypeCollection(_rxORB)
317cdf0e10cSrcweir     ,m_aTableCopyHelper(this)
318cdf0e10cSrcweir 	,m_pClipbordNotifier(NULL)
319cdf0e10cSrcweir 	,m_nAsyncDrop(0)
320cdf0e10cSrcweir     ,m_aControllerConnectedEvent( LINK( this, OApplicationController, OnFirstControllerConnected ) )
321cdf0e10cSrcweir     ,m_aSelectContainerEvent( LINK( this, OApplicationController, OnSelectContainer ) )
322cdf0e10cSrcweir 	,m_ePreviewMode(E_PREVIEWNONE)
323cdf0e10cSrcweir 	,m_eCurrentType(E_NONE)
324cdf0e10cSrcweir 	,m_bNeedToReconnect(sal_False)
325cdf0e10cSrcweir     ,m_bSuspended( sal_False )
326cdf0e10cSrcweir     ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     DBG_CTOR(OApplicationController,NULL);
329cdf0e10cSrcweir }
330cdf0e10cSrcweir //------------------------------------------------------------------------------
331cdf0e10cSrcweir OApplicationController::~OApplicationController()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir 	if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
334cdf0e10cSrcweir 	{
335cdf0e10cSrcweir 		OSL_ENSURE(0,"Please check who doesn't dispose this component!");
336cdf0e10cSrcweir         // increment ref count to prevent double call of Dtor
337cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
338cdf0e10cSrcweir         dispose();
339cdf0e10cSrcweir 	}
340cdf0e10cSrcweir 	::std::auto_ptr< Window> aTemp( getView() );
341cdf0e10cSrcweir     clearView();
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     DBG_DTOR(OApplicationController,NULL);
344cdf0e10cSrcweir }
345cdf0e10cSrcweir //--------------------------------------------------------------------
346cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
347cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2(OApplicationController,OApplicationController_CBASE,OApplicationController_Base)
348cdf0e10cSrcweir // -----------------------------------------------------------------------------
349cdf0e10cSrcweir void OApplicationController::disconnect()
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     if ( m_xDataSourceConnection.is() )
352cdf0e10cSrcweir 	    stopConnectionListening( m_xDataSourceConnection );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     try
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         // temporary (hopefully!) hack for #i55274#
357cdf0e10cSrcweir         Reference< XFlushable > xFlush( m_xDataSourceConnection, UNO_QUERY );
358cdf0e10cSrcweir         if ( xFlush.is() && m_xMetaData.is() && !m_xMetaData->isReadOnly() )
359cdf0e10cSrcweir             xFlush->flush();
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir     catch( const Exception& )
362cdf0e10cSrcweir     {
363cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     m_xDataSourceConnection.clear();
367cdf0e10cSrcweir     m_xMetaData.clear();
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	InvalidateAll();
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir //--------------------------------------------------------------------
373cdf0e10cSrcweir void SAL_CALL OApplicationController::disposing()
374cdf0e10cSrcweir {
375cdf0e10cSrcweir     m_aControllerConnectedEvent.CancelCall();
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
378cdf0e10cSrcweir 	m_aCurrentContainers.clear();
379cdf0e10cSrcweir     m_pSubComponentManager->disposing();
380cdf0e10cSrcweir     m_pSelectionNotifier->disposing();
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	if ( getView() )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir 		getContainer()->showPreview(NULL);
385cdf0e10cSrcweir 		m_pClipbordNotifier->ClearCallbackLink();
386cdf0e10cSrcweir 		m_pClipbordNotifier->AddRemoveListener( getView(), sal_False );
387cdf0e10cSrcweir 		m_pClipbordNotifier->release();
388cdf0e10cSrcweir 		m_pClipbordNotifier = NULL;
389cdf0e10cSrcweir 	}
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	disconnect();
392cdf0e10cSrcweir 	try
393cdf0e10cSrcweir 	{
394cdf0e10cSrcweir 		Reference < XFrame > xFrame;
395cdf0e10cSrcweir 		attachFrame( xFrame );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         if ( m_xDataSource.is() )
398cdf0e10cSrcweir 		{
399cdf0e10cSrcweir 		    m_xDataSource->removePropertyChangeListener(::rtl::OUString(), this);
400cdf0e10cSrcweir             m_xDataSource->removePropertyChangeListener(PROPERTY_INFO, this);
401cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_URL, this);
402cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
403cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_LAYOUTINFORMATION, this);
404cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_SUPPRESSVERSIONCL, this);
405cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_TABLEFILTER, this);
406cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_TABLETYPEFILTER, this);
407cdf0e10cSrcweir 			m_xDataSource->removePropertyChangeListener(PROPERTY_USER, this);
408cdf0e10cSrcweir 			// otherwise we may delete our datasource twice
409cdf0e10cSrcweir 			Reference<XPropertySet> xProp = m_xDataSource;
410cdf0e10cSrcweir 			m_xDataSource = NULL;
411cdf0e10cSrcweir 		}
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 		Reference< XModifyBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
414cdf0e10cSrcweir 		if ( xBroadcaster.is() )
415cdf0e10cSrcweir 			xBroadcaster->removeModifyListener(static_cast<XModifyListener*>(this));
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 		if ( m_xModel.is() )
418cdf0e10cSrcweir 		{
419cdf0e10cSrcweir 			::rtl::OUString sUrl = m_xModel->getURL();
420cdf0e10cSrcweir 			if ( sUrl.getLength() )
421cdf0e10cSrcweir 	    	{
422cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aArgs( m_xModel->getArgs() );
423cdf0e10cSrcweir                 if ( true == aArgs.getOrDefault( "PickListEntry", true ) )
424cdf0e10cSrcweir                 {
425cdf0e10cSrcweir     				::rtl::OUString		aFilter;
426cdf0e10cSrcweir     				INetURLObject		aURL( m_xModel->getURL() );
427cdf0e10cSrcweir     				const SfxFilter* pFilter = getStandardDatabaseFilter();
428cdf0e10cSrcweir     				if ( pFilter )
429cdf0e10cSrcweir     					aFilter = pFilter->GetFilterName();
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     				// add to svtool history options
432cdf0e10cSrcweir     				SvtHistoryOptions().AppendItem( ePICKLIST,
433cdf0e10cSrcweir     						aURL.GetURLNoPass( INetURLObject::NO_DECODE ),
434cdf0e10cSrcweir     						aFilter,
435cdf0e10cSrcweir     						getStrippedDatabaseName(),
436cdf0e10cSrcweir     						::rtl::OUString() );
437cdf0e10cSrcweir                 }
438cdf0e10cSrcweir             }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir             m_xModel->disconnectController( this );
441cdf0e10cSrcweir 
442cdf0e10cSrcweir             m_xModel.clear();
443cdf0e10cSrcweir 		}
444cdf0e10cSrcweir 	}
445cdf0e10cSrcweir 	catch(Exception)
446cdf0e10cSrcweir 	{
447cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
448cdf0e10cSrcweir 	}
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     clearView();
451cdf0e10cSrcweir 	OApplicationController_CBASE::disposing(); // here the m_refCount must be equal 5
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir //--------------------------------------------------------------------
455cdf0e10cSrcweir sal_Bool OApplicationController::Construct(Window* _pParent)
456cdf0e10cSrcweir {
457cdf0e10cSrcweir 	setView( * new OApplicationView( _pParent, getORB(), *this, m_ePreviewMode ) );
458cdf0e10cSrcweir 	getView()->SetUniqueId(UID_APP_VIEW);
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	// late construction
461cdf0e10cSrcweir 	sal_Bool bSuccess = sal_False;
462cdf0e10cSrcweir 	try
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 		getContainer()->Construct();
465cdf0e10cSrcweir 		bSuccess = sal_True;
466cdf0e10cSrcweir 	}
467cdf0e10cSrcweir 	catch(SQLException&)
468cdf0e10cSrcweir 	{
469cdf0e10cSrcweir 	}
470cdf0e10cSrcweir 	catch(Exception&)
471cdf0e10cSrcweir 	{
472cdf0e10cSrcweir 		DBG_ERROR("OApplicationController::Construct : the construction of UnoDataBrowserView failed !");
473cdf0e10cSrcweir 	}
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	if ( !bSuccess )
476cdf0e10cSrcweir 	{
477cdf0e10cSrcweir 		::std::auto_ptr< Window> aTemp( getView() );
478cdf0e10cSrcweir         clearView();
479cdf0e10cSrcweir 		return sal_False;
480cdf0e10cSrcweir 	}
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	// now that we have a view we can create the clipboard listener
483cdf0e10cSrcweir 	m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
484cdf0e10cSrcweir 	m_aSystemClipboard.StartClipboardListening( );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	m_pClipbordNotifier = new TransferableClipboardListener( LINK( this, OApplicationController, OnClipboardChanged ) );
487cdf0e10cSrcweir 	m_pClipbordNotifier->acquire();
488cdf0e10cSrcweir 	m_pClipbordNotifier->AddRemoveListener( getView(), sal_True );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	OApplicationController_CBASE::Construct( _pParent );
491cdf0e10cSrcweir 	getView()->Show();
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	return sal_True;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir //--------------------------------------------------------------------
497cdf0e10cSrcweir void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
500cdf0e10cSrcweir 	Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
501cdf0e10cSrcweir 	if ( xCon.is() )
502cdf0e10cSrcweir 	{
503cdf0e10cSrcweir         DBG_ASSERT( m_xDataSourceConnection == xCon,
504cdf0e10cSrcweir             "OApplicationController::disposing: which connection does this come from?" );
505cdf0e10cSrcweir 
506cdf0e10cSrcweir         if ( getContainer() && getContainer()->getElementType() == E_TABLE )
507cdf0e10cSrcweir             getContainer()->clearPages();
508cdf0e10cSrcweir         if ( m_xDataSourceConnection == xCon )
509cdf0e10cSrcweir         {
510cdf0e10cSrcweir 			m_xMetaData.clear();
511cdf0e10cSrcweir             m_xDataSourceConnection.clear();
512cdf0e10cSrcweir 		}
513cdf0e10cSrcweir 	}
514cdf0e10cSrcweir 	else if ( _rSource.Source == m_xModel )
515cdf0e10cSrcweir 	{
516cdf0e10cSrcweir 		m_xModel.clear();
517cdf0e10cSrcweir 	}
518cdf0e10cSrcweir 	else if ( _rSource.Source == m_xDataSource )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 		m_xDataSource = NULL;
521cdf0e10cSrcweir 	}
522cdf0e10cSrcweir 	else
523cdf0e10cSrcweir 	{
524cdf0e10cSrcweir 		Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
525cdf0e10cSrcweir 		if ( xContainer.is() )
526cdf0e10cSrcweir 		{
527cdf0e10cSrcweir 			TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
528cdf0e10cSrcweir 			if ( aFind != m_aCurrentContainers.end() )
529cdf0e10cSrcweir 				m_aCurrentContainers.erase(aFind);
530cdf0e10cSrcweir 		}
531cdf0e10cSrcweir 		OApplicationController_CBASE::disposing( _rSource );
532cdf0e10cSrcweir 	}
533cdf0e10cSrcweir }
534cdf0e10cSrcweir //--------------------------------------------------------------------
535cdf0e10cSrcweir sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( RuntimeException )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     // notify the OnPrepareViewClosing event (before locking any mutex)
538cdf0e10cSrcweir     Reference< XDocumentEventBroadcaster > xBroadcaster( m_xModel, UNO_QUERY );
539cdf0e10cSrcweir     if ( xBroadcaster.is() )
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         xBroadcaster->notifyDocumentEvent(
542cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrepareViewClosing" ) ),
543cdf0e10cSrcweir             this,
544cdf0e10cSrcweir             Any()
545cdf0e10cSrcweir         );
546cdf0e10cSrcweir     }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
549cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     if ( getView() && getView()->IsInModalMode() )
552cdf0e10cSrcweir         return sal_False;
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     sal_Bool bCanSuspend = sal_True;
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     if ( m_bSuspended != bSuspend )
557cdf0e10cSrcweir     {
558cdf0e10cSrcweir 	    if ( bSuspend && !closeSubComponents() )
559cdf0e10cSrcweir 		    return sal_False;
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	    Reference<XModifiable> xModi(m_xModel,UNO_QUERY);
562cdf0e10cSrcweir         Reference<XStorable> xStor(getModel(),UNO_QUERY);
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	    if  (   bSuspend
565cdf0e10cSrcweir             &&  xStor.is()
566cdf0e10cSrcweir             &&  !xStor->isReadonly()
567cdf0e10cSrcweir             &&  (   xModi.is()
568cdf0e10cSrcweir                 &&  xModi->isModified()
569cdf0e10cSrcweir                 )
570cdf0e10cSrcweir             )
571cdf0e10cSrcweir 	    {
572cdf0e10cSrcweir 		    switch (ExecuteQuerySaveDocument(getView(),getStrippedDatabaseName()))
573cdf0e10cSrcweir 		    {
574cdf0e10cSrcweir 			    case RET_YES:
575cdf0e10cSrcweir 				    Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
576cdf0e10cSrcweir 				    bCanSuspend = !xModi->isModified();
577cdf0e10cSrcweir                     // when we save the document this must be false else some press cancel
578cdf0e10cSrcweir 				    break;
579cdf0e10cSrcweir 			    case RET_CANCEL:
580cdf0e10cSrcweir 				    bCanSuspend = sal_False;
581cdf0e10cSrcweir 			    default:
582cdf0e10cSrcweir 				    break;
583cdf0e10cSrcweir 		    }
584cdf0e10cSrcweir 	    }
585cdf0e10cSrcweir     }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     if ( bCanSuspend )
588cdf0e10cSrcweir 	    m_bSuspended = bSuspend;
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 	return bCanSuspend;
591cdf0e10cSrcweir }
592cdf0e10cSrcweir // -----------------------------------------------------------------------------
593cdf0e10cSrcweir FeatureState OApplicationController::GetState(sal_uInt16 _nId) const
594cdf0e10cSrcweir {
595cdf0e10cSrcweir 	FeatureState aReturn;
596cdf0e10cSrcweir 	aReturn.bEnabled = sal_False;
597cdf0e10cSrcweir 	// check this first
598cdf0e10cSrcweir 	if ( !getContainer() || m_bReadOnly )
599cdf0e10cSrcweir 		return aReturn;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 	try
602cdf0e10cSrcweir 	{
603cdf0e10cSrcweir 		switch (_nId)
604cdf0e10cSrcweir 		{
605cdf0e10cSrcweir             case SID_OPENURL:
606cdf0e10cSrcweir                 aReturn.bEnabled = sal_True;
607cdf0e10cSrcweir                 if ( m_xModel.is() )
608cdf0e10cSrcweir 				    aReturn.sTitle = m_xModel->getURL();
609cdf0e10cSrcweir                 break;
610cdf0e10cSrcweir 			case ID_BROWSER_COPY:
611cdf0e10cSrcweir 				{
612cdf0e10cSrcweir 					sal_Int32 nCount = getContainer()->getSelectionCount();
613cdf0e10cSrcweir 					aReturn.bEnabled = nCount >= 1;
614cdf0e10cSrcweir 					if ( aReturn.bEnabled && nCount == 1 && getContainer()->getElementType() == E_TABLE )
615cdf0e10cSrcweir 						aReturn.bEnabled = getContainer()->isALeafSelected();
616cdf0e10cSrcweir 				}
617cdf0e10cSrcweir 				break;
618cdf0e10cSrcweir 			case ID_BROWSER_CUT:
619cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() >= 1;
620cdf0e10cSrcweir 				aReturn.bEnabled = aReturn.bEnabled && ( (ID_BROWSER_CUT == _nId && getContainer()->getElementType() == E_TABLE) ? getContainer()->isCutAllowed() : sal_True);
621cdf0e10cSrcweir 				break;
622cdf0e10cSrcweir 			case ID_BROWSER_PASTE:
623cdf0e10cSrcweir 				switch( getContainer()->getElementType() )
624cdf0e10cSrcweir 				{
625cdf0e10cSrcweir 					case E_TABLE:
626cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
627cdf0e10cSrcweir 						break;
628cdf0e10cSrcweir 					case E_QUERY:
629cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && getViewClipboard().HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
630cdf0e10cSrcweir 						break;
631cdf0e10cSrcweir 					default:
632cdf0e10cSrcweir 						aReturn.bEnabled = !isDataSourceReadOnly() && OComponentTransferable::canExtractComponentDescriptor(getViewClipboard().GetDataFlavorExVector(),getContainer()->getElementType() == E_FORM);
633cdf0e10cSrcweir 				}
634cdf0e10cSrcweir 				break;
635cdf0e10cSrcweir 			case SID_DB_APP_PASTE_SPECIAL:
636cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && !isDataSourceReadOnly() && !isConnectionReadOnly() && isTableFormat();
637cdf0e10cSrcweir 				break;
638cdf0e10cSrcweir 			case SID_OPENDOC:
639cdf0e10cSrcweir 			case SID_HELP_INDEX:
640cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
641cdf0e10cSrcweir 				break;
642cdf0e10cSrcweir 			case ID_BROWSER_SAVEDOC:
643cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && m_xDocumentModify.is() && m_xDocumentModify->isModified();
644cdf0e10cSrcweir 				break;
645cdf0e10cSrcweir 			case ID_BROWSER_SAVEASDOC:
646cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
647cdf0e10cSrcweir 				break;
648cdf0e10cSrcweir 			case ID_BROWSER_SORTUP:
649cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
650cdf0e10cSrcweir 				aReturn.bChecked = aReturn.bEnabled && getContainer()->isSortUp();
651cdf0e10cSrcweir 				break;
652cdf0e10cSrcweir 			case ID_BROWSER_SORTDOWN:
653cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->isFilled() && getContainer()->getElementCount();
654cdf0e10cSrcweir 				aReturn.bChecked = aReturn.bEnabled && !getContainer()->isSortUp();
655cdf0e10cSrcweir 				break;
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 			case SID_NEWDOC:
658cdf0e10cSrcweir 			case SID_APP_NEW_FORM:
659cdf0e10cSrcweir 			case ID_DOCUMENT_CREATE_REPWIZ:
660cdf0e10cSrcweir                 aReturn.bEnabled = !isDataSourceReadOnly() && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
661cdf0e10cSrcweir 				break;
662cdf0e10cSrcweir 			case SID_APP_NEW_REPORT:
663cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly()
664cdf0e10cSrcweir                                     && SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER);
665cdf0e10cSrcweir                 if ( aReturn.bEnabled )
666cdf0e10cSrcweir                 {
667cdf0e10cSrcweir                     Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
668cdf0e10cSrcweir 					aReturn.bEnabled = xEnumAccess.is();
669cdf0e10cSrcweir 	                if ( aReturn.bEnabled )
670cdf0e10cSrcweir                     {
671cdf0e10cSrcweir                         const ::rtl::OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xServiceFactory);
672cdf0e10cSrcweir                         aReturn.bEnabled = sReportEngineServiceName.getLength() != 0;
673cdf0e10cSrcweir                         if ( aReturn.bEnabled )
674cdf0e10cSrcweir                         {
675cdf0e10cSrcweir                     	    const Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(sReportEngineServiceName);
676cdf0e10cSrcweir                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
677cdf0e10cSrcweir                         }
678cdf0e10cSrcweir                     }
679cdf0e10cSrcweir                 }
680cdf0e10cSrcweir 				break;
681cdf0e10cSrcweir 			case SID_DB_APP_VIEW_TABLES:
682cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
683cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_TABLE;
684cdf0e10cSrcweir 				break;
685cdf0e10cSrcweir 			case SID_DB_APP_VIEW_QUERIES:
686cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
687cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_QUERY;
688cdf0e10cSrcweir 				break;
689cdf0e10cSrcweir 			case SID_DB_APP_VIEW_FORMS:
690cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
691cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_FORM;
692cdf0e10cSrcweir 				break;
693cdf0e10cSrcweir 			case SID_DB_APP_VIEW_REPORTS:
694cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
695cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getElementType() == E_REPORT;
696cdf0e10cSrcweir 				break;
697cdf0e10cSrcweir 			case ID_NEW_QUERY_DESIGN:
698cdf0e10cSrcweir 			case ID_NEW_QUERY_SQL:
699cdf0e10cSrcweir 			case ID_APP_NEW_QUERY_AUTO_PILOT:
700cdf0e10cSrcweir 			case SID_DB_FORM_NEW_PILOT:
701cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
702cdf0e10cSrcweir 				break;
703cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN:
704cdf0e10cSrcweir 			case SID_DB_NEW_VIEW_SQL:
705cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
706cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
707cdf0e10cSrcweir 				if ( aReturn.bEnabled )
708cdf0e10cSrcweir 				{
709cdf0e10cSrcweir 					Reference<XViewsSupplier> xViewsSup( getConnection(), UNO_QUERY );
710cdf0e10cSrcweir 					aReturn.bEnabled = xViewsSup.is();
711cdf0e10cSrcweir 				}
712cdf0e10cSrcweir 				break;
713cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN:
714cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
715cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && !isConnectionReadOnly();
716cdf0e10cSrcweir 				break;
717cdf0e10cSrcweir 			case ID_DIRECT_SQL:
718cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
719cdf0e10cSrcweir 				break;
720cdf0e10cSrcweir             case ID_MIGRATE_SCRIPTS:
721cdf0e10cSrcweir             {
722cdf0e10cSrcweir                 // Our document supports embedding scripts into it, if and only if there are no
723cdf0e10cSrcweir                 // forms/reports with macros/scripts into them. So, we need to enable migration
724cdf0e10cSrcweir                 // if and only if the database document does *not* support embedding scripts.
725cdf0e10cSrcweir                 bool bAvailable =
726cdf0e10cSrcweir                         !Reference< XEmbeddedScripts >( m_xModel, UNO_QUERY ).is()
727cdf0e10cSrcweir                     &&  !Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly();
728cdf0e10cSrcweir                 aReturn.bEnabled = bAvailable;
729cdf0e10cSrcweir                 if ( !bAvailable )
730cdf0e10cSrcweir                     aReturn.bInvisible = true;
731cdf0e10cSrcweir             }
732cdf0e10cSrcweir             break;
733cdf0e10cSrcweir 			case SID_APP_NEW_FOLDER:
734cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() <= 1;
735cdf0e10cSrcweir 				if ( aReturn.bEnabled )
736cdf0e10cSrcweir 				{
737cdf0e10cSrcweir 					const ElementType eType = getContainer()->getElementType();
738cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_REPORT || eType == E_FORM;
739cdf0e10cSrcweir 				}
740cdf0e10cSrcweir 				break;
741cdf0e10cSrcweir 			case SID_FORM_CREATE_REPWIZ_PRE_SEL:
742cdf0e10cSrcweir 			case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
743cdf0e10cSrcweir             case SID_APP_NEW_REPORT_PRE_SEL:
744cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly()
745cdf0e10cSrcweir 									&& SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SWRITER)
746cdf0e10cSrcweir 									&& getContainer()->isALeafSelected();
747cdf0e10cSrcweir 				if ( aReturn.bEnabled )
748cdf0e10cSrcweir 				{
749cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
750cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_QUERY || eType == E_TABLE;
751cdf0e10cSrcweir                     if ( aReturn.bEnabled && SID_APP_NEW_REPORT_PRE_SEL == _nId )
752cdf0e10cSrcweir                     {
753cdf0e10cSrcweir                         Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, UNO_QUERY);
754cdf0e10cSrcweir 					    aReturn.bEnabled = xEnumAccess.is();
755cdf0e10cSrcweir 	                    if ( aReturn.bEnabled )
756cdf0e10cSrcweir                         {
757cdf0e10cSrcweir                             static ::rtl::OUString s_sReportDesign(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOReportJobFactory"));
758cdf0e10cSrcweir                     	    Reference< XEnumeration > xEnumDrivers = xEnumAccess->createContentEnumeration(s_sReportDesign);
759cdf0e10cSrcweir                             aReturn.bEnabled = xEnumDrivers.is() && xEnumDrivers->hasMoreElements();
760cdf0e10cSrcweir                         }
761cdf0e10cSrcweir                     }
762cdf0e10cSrcweir 				}
763cdf0e10cSrcweir 				break;
764cdf0e10cSrcweir 			case SID_DB_APP_DELETE:
765cdf0e10cSrcweir 			case SID_DB_APP_RENAME:
766cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(getContainer()->getElementType(), _nId == SID_DB_APP_DELETE);
767cdf0e10cSrcweir 				break;
768cdf0e10cSrcweir 			case SID_DB_APP_TABLE_DELETE:
769cdf0e10cSrcweir 			case SID_DB_APP_TABLE_RENAME:
770cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_TABLE, _nId == SID_DB_APP_TABLE_DELETE);
771cdf0e10cSrcweir 				break;
772cdf0e10cSrcweir 			case SID_DB_APP_QUERY_DELETE:
773cdf0e10cSrcweir 			case SID_DB_APP_QUERY_RENAME:
774cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_QUERY, _nId == SID_DB_APP_QUERY_DELETE);
775cdf0e10cSrcweir 				break;
776cdf0e10cSrcweir 			case SID_DB_APP_FORM_DELETE:
777cdf0e10cSrcweir 			case SID_DB_APP_FORM_RENAME:
778cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_FORM, _nId == SID_DB_APP_FORM_DELETE);
779cdf0e10cSrcweir 				break;
780cdf0e10cSrcweir 			case SID_DB_APP_REPORT_DELETE:
781cdf0e10cSrcweir 			case SID_DB_APP_REPORT_RENAME:
782cdf0e10cSrcweir 				aReturn.bEnabled = isRenameDeleteAllowed(E_REPORT, _nId == SID_DB_APP_REPORT_DELETE);
783cdf0e10cSrcweir 				break;
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 			case SID_SELECTALL:
786cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementCount() > 0 && getContainer()->getSelectionCount() != getContainer()->getElementCount();
787cdf0e10cSrcweir 				break;
788cdf0e10cSrcweir 			case SID_DB_APP_EDIT:
789cdf0e10cSrcweir 			case SID_DB_APP_TABLE_EDIT:
790cdf0e10cSrcweir 			case SID_DB_APP_QUERY_EDIT:
791cdf0e10cSrcweir 			case SID_DB_APP_FORM_EDIT:
792cdf0e10cSrcweir 			case SID_DB_APP_REPORT_EDIT:
793cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly() && getContainer()->getSelectionCount() > 0
794cdf0e10cSrcweir 									&& getContainer()->isALeafSelected();
795cdf0e10cSrcweir 				break;
796cdf0e10cSrcweir 			case SID_DB_APP_EDIT_SQL_VIEW:
797cdf0e10cSrcweir                 if ( isDataSourceReadOnly() )
798cdf0e10cSrcweir 				    aReturn.bEnabled = sal_False;
799cdf0e10cSrcweir                 else
800cdf0e10cSrcweir                 {
801cdf0e10cSrcweir                     switch ( getContainer()->getElementType() )
802cdf0e10cSrcweir                     {
803cdf0e10cSrcweir                     case E_QUERY:
804cdf0e10cSrcweir                         aReturn.bEnabled =  ( getContainer()->getSelectionCount() > 0 )
805cdf0e10cSrcweir                                         &&  ( getContainer()->isALeafSelected() );
806cdf0e10cSrcweir                         break;
807cdf0e10cSrcweir                     case E_TABLE:
808cdf0e10cSrcweir                         aReturn.bEnabled = sal_False;
809cdf0e10cSrcweir                         // there's one exception: views which support altering their underlying
810cdf0e10cSrcweir                         // command can be edited in SQL view, too
811cdf0e10cSrcweir                         if  (   ( getContainer()->getSelectionCount() > 0 )
812cdf0e10cSrcweir                             &&  ( getContainer()->isALeafSelected() )
813cdf0e10cSrcweir                             )
814cdf0e10cSrcweir                         {
815cdf0e10cSrcweir 						    ::std::vector< ::rtl::OUString > aSelected;
816cdf0e10cSrcweir 						    getSelectionElementNames( aSelected );
817cdf0e10cSrcweir                             bool bAlterableViews = true;
818cdf0e10cSrcweir                             for (   ::std::vector< ::rtl::OUString >::const_iterator selectedName = aSelected.begin();
819cdf0e10cSrcweir                                     bAlterableViews && ( selectedName != aSelected.end() ) ;
820cdf0e10cSrcweir                                     ++selectedName
821cdf0e10cSrcweir                                 )
822cdf0e10cSrcweir                             {
823cdf0e10cSrcweir                                 bAlterableViews &= impl_isAlterableView_nothrow( *selectedName );
824cdf0e10cSrcweir                             }
825cdf0e10cSrcweir                             aReturn.bEnabled = bAlterableViews;
826cdf0e10cSrcweir                         }
827cdf0e10cSrcweir                         break;
828cdf0e10cSrcweir                     default:
829cdf0e10cSrcweir                         break;
830cdf0e10cSrcweir                     }
831cdf0e10cSrcweir                 }
832cdf0e10cSrcweir                 break;
833cdf0e10cSrcweir 			case SID_DB_APP_OPEN:
834cdf0e10cSrcweir 			case SID_DB_APP_TABLE_OPEN:
835cdf0e10cSrcweir 			case SID_DB_APP_QUERY_OPEN:
836cdf0e10cSrcweir 			case SID_DB_APP_FORM_OPEN:
837cdf0e10cSrcweir 			case SID_DB_APP_REPORT_OPEN:
838cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
839cdf0e10cSrcweir 				break;
840cdf0e10cSrcweir 			case SID_DB_APP_DSUSERADMIN:
841cdf0e10cSrcweir 				aReturn.bEnabled = !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
842cdf0e10cSrcweir 			    break;
843cdf0e10cSrcweir 			case SID_DB_APP_DSRELDESIGN:
844cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
845cdf0e10cSrcweir 				break;
846cdf0e10cSrcweir 			case SID_DB_APP_TABLEFILTER:
847cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
848cdf0e10cSrcweir 				break;
849cdf0e10cSrcweir 			case SID_DB_APP_REFRESH_TABLES:
850cdf0e10cSrcweir 				aReturn.bEnabled = getContainer()->getElementType() == E_TABLE && isConnected();
851cdf0e10cSrcweir 				break;
852cdf0e10cSrcweir 			case SID_DB_APP_DSPROPS:
853cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is() && m_aTypeCollection.isShowPropertiesEnabled(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
854cdf0e10cSrcweir 				break;
855cdf0e10cSrcweir 			case SID_DB_APP_DSCONNECTION_TYPE:
856cdf0e10cSrcweir                 aReturn.bEnabled = !isDataSourceReadOnly() && m_xDataSource.is() && !m_aTypeCollection.isEmbeddedDatabase(::comphelper::getString(m_xDataSource->getPropertyValue(PROPERTY_URL)));
857cdf0e10cSrcweir 				break;
858cdf0e10cSrcweir 			case SID_DB_APP_DSADVANCED_SETTINGS:
859cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is() && AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( m_aTypeCollection.getType(::comphelper::getString( m_xDataSource->getPropertyValue( PROPERTY_URL ) )) );
860cdf0e10cSrcweir 				break;
861cdf0e10cSrcweir 			case SID_DB_APP_CONVERTTOVIEW:
862cdf0e10cSrcweir 				aReturn.bEnabled = !isDataSourceReadOnly();
863cdf0e10cSrcweir 				if ( aReturn.bEnabled )
864cdf0e10cSrcweir 				{
865cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
866cdf0e10cSrcweir 					aReturn.bEnabled = eType == E_QUERY && getContainer()->getSelectionCount() > 0;
867cdf0e10cSrcweir 					if ( aReturn.bEnabled )
868cdf0e10cSrcweir 					{
869cdf0e10cSrcweir 						Reference<XViewsSupplier> xViewSup( getConnection(), UNO_QUERY );
870cdf0e10cSrcweir 						aReturn.bEnabled = xViewSup.is() && Reference<XAppend>(xViewSup->getViews(),UNO_QUERY).is();
871cdf0e10cSrcweir 					}
872cdf0e10cSrcweir 				}
873cdf0e10cSrcweir 				break;
874cdf0e10cSrcweir 			case SID_DB_APP_DISABLE_PREVIEW:
875cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
876cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getPreviewMode() == E_PREVIEWNONE;
877cdf0e10cSrcweir 				break;
878cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
879cdf0e10cSrcweir 				{
880cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
881cdf0e10cSrcweir 					aReturn.bEnabled = (E_REPORT == eType || E_FORM == eType);
882cdf0e10cSrcweir 					aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENTINFO;
883cdf0e10cSrcweir 				}
884cdf0e10cSrcweir 				break;
885cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOC_PREVIEW:
886cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
887cdf0e10cSrcweir 				aReturn.bChecked = getContainer()->getPreviewMode() == E_DOCUMENT;
888cdf0e10cSrcweir 				break;
889cdf0e10cSrcweir             case ID_BROWSER_UNDO:
890cdf0e10cSrcweir                 aReturn.bEnabled = sal_False;
891cdf0e10cSrcweir                 break;
892cdf0e10cSrcweir 			case SID_MAIL_SENDDOC:
893cdf0e10cSrcweir 				aReturn.bEnabled = sal_True;
894cdf0e10cSrcweir 				break;
895cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTASMAIL:
896cdf0e10cSrcweir 				{
897cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
898cdf0e10cSrcweir 					aReturn.bEnabled = E_REPORT == eType && getContainer()->getSelectionCount() > 0 && getContainer()->isALeafSelected();
899cdf0e10cSrcweir 				}
900cdf0e10cSrcweir 				break;
901cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTTOWRITER:
902cdf0e10cSrcweir 			case SID_DB_APP_DBADMIN:
903cdf0e10cSrcweir 				aReturn.bEnabled = sal_False;
904cdf0e10cSrcweir 				break;
905cdf0e10cSrcweir 			case SID_DB_APP_STATUS_TYPE:
906cdf0e10cSrcweir                 aReturn.bEnabled = m_xDataSource.is();
907cdf0e10cSrcweir 				if ( aReturn.bEnabled )
908cdf0e10cSrcweir 				{
909cdf0e10cSrcweir                     ::rtl::OUString sURL;
910cdf0e10cSrcweir                     m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
911cdf0e10cSrcweir                     ::rtl::OUString sDSTypeName;
912cdf0e10cSrcweir                     if ( m_aTypeCollection.isEmbeddedDatabase( sURL ) )
913cdf0e10cSrcweir                     {
914cdf0e10cSrcweir                         sDSTypeName = String( ModuleRes( RID_STR_EMBEDDED_DATABASE ) );
915cdf0e10cSrcweir                     }
916cdf0e10cSrcweir                     else
917cdf0e10cSrcweir                     {
918cdf0e10cSrcweir 					    sDSTypeName = m_aTypeCollection.getTypeDisplayName(sURL);
919cdf0e10cSrcweir                     }
920cdf0e10cSrcweir 				    aReturn.sTitle = sDSTypeName;
921cdf0e10cSrcweir 				}
922cdf0e10cSrcweir 				break;
923cdf0e10cSrcweir 			case SID_DB_APP_STATUS_DBNAME:
924cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
925cdf0e10cSrcweir 				if ( aReturn.bEnabled )
926cdf0e10cSrcweir 				{
927cdf0e10cSrcweir 					::rtl::OUString sURL;
928cdf0e10cSrcweir 					m_xDataSource->getPropertyValue(PROPERTY_URL) >>= sURL;
929cdf0e10cSrcweir                     String sDatabaseName;
930cdf0e10cSrcweir 					String sHostName;
931cdf0e10cSrcweir 					sal_Int32 nPortNumber( -1 );
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 					m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir                     if ( !sDatabaseName.Len() )
936cdf0e10cSrcweir 						sDatabaseName = m_aTypeCollection.cutPrefix( sURL );
937cdf0e10cSrcweir 					if ( m_aTypeCollection.isFileSystemBased(sURL) )
938cdf0e10cSrcweir 					{
939cdf0e10cSrcweir 						sDatabaseName = SvtPathOptions().SubstituteVariable( sDatabaseName );
940cdf0e10cSrcweir 						if ( sDatabaseName.Len() )
941cdf0e10cSrcweir 						{
942cdf0e10cSrcweir 							::svt::OFileNotation aFileNotation(sDatabaseName);
943cdf0e10cSrcweir 							// set this decoded URL as text
944cdf0e10cSrcweir 							sDatabaseName = aFileNotation.get(::svt::OFileNotation::N_SYSTEM);
945cdf0e10cSrcweir 						}
946cdf0e10cSrcweir 					}
947cdf0e10cSrcweir 
948cdf0e10cSrcweir                     if ( sDatabaseName.Len() == 0 )
949cdf0e10cSrcweir                         sDatabaseName = m_aTypeCollection.getTypeDisplayName( sURL );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir                     aReturn.sTitle = sDatabaseName;
952cdf0e10cSrcweir 				}
953cdf0e10cSrcweir 				break;
954cdf0e10cSrcweir 			case SID_DB_APP_STATUS_USERNAME:
955cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
956cdf0e10cSrcweir 				if ( aReturn.bEnabled )
957cdf0e10cSrcweir                     m_xDataSource->getPropertyValue( PROPERTY_USER ) >>= aReturn.sTitle;
958cdf0e10cSrcweir 				break;
959cdf0e10cSrcweir 			case SID_DB_APP_STATUS_HOSTNAME:
960cdf0e10cSrcweir 				aReturn.bEnabled = m_xDataSource.is();
961cdf0e10cSrcweir 				if ( aReturn.bEnabled )
962cdf0e10cSrcweir 				{
963cdf0e10cSrcweir 					::rtl::OUString sURL;
964cdf0e10cSrcweir 					m_xDataSource->getPropertyValue( PROPERTY_URL ) >>= sURL;
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 					String sHostName, sDatabaseName;
967cdf0e10cSrcweir 					sal_Int32 nPortNumber = -1;
968cdf0e10cSrcweir 					m_aTypeCollection.extractHostNamePort( sURL, sDatabaseName, sHostName, nPortNumber );
969cdf0e10cSrcweir 					aReturn.sTitle = sHostName;
970cdf0e10cSrcweir 				}
971cdf0e10cSrcweir 				break;
972cdf0e10cSrcweir 			default:
973cdf0e10cSrcweir 				aReturn = OApplicationController_CBASE::GetState(_nId);
974cdf0e10cSrcweir 		}
975cdf0e10cSrcweir 	}
976cdf0e10cSrcweir 	catch(const Exception& )
977cdf0e10cSrcweir 	{
978cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
979cdf0e10cSrcweir 	}
980cdf0e10cSrcweir 	return aReturn;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir // -----------------------------------------------------------------------------
984cdf0e10cSrcweir namespace
985cdf0e10cSrcweir {
986cdf0e10cSrcweir     bool lcl_handleException_nothrow( const Reference< XModel >& _rxDocument, const Any& _rException )
987cdf0e10cSrcweir     {
988cdf0e10cSrcweir         bool bHandled = false;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir         // try handling the error with an interaction handler
991cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArgs( _rxDocument->getArgs() );
992cdf0e10cSrcweir         Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
993cdf0e10cSrcweir         if ( xHandler.is() )
994cdf0e10cSrcweir         {
995cdf0e10cSrcweir             ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rException ) );
996cdf0e10cSrcweir             ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
997cdf0e10cSrcweir             pRequest->addContinuation( pApprove.get() );
998cdf0e10cSrcweir 
999cdf0e10cSrcweir             try
1000cdf0e10cSrcweir             {
1001cdf0e10cSrcweir                 xHandler->handle( pRequest.get() );
1002cdf0e10cSrcweir             }
1003cdf0e10cSrcweir             catch( const Exception& )
1004cdf0e10cSrcweir             {
1005cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
1006cdf0e10cSrcweir             }
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir             bHandled = pApprove->wasSelected();
1009cdf0e10cSrcweir         }
1010cdf0e10cSrcweir         return bHandled;
1011cdf0e10cSrcweir     }
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir // -----------------------------------------------------------------------------
1015cdf0e10cSrcweir void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir 	::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1018cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir     if ( isUserDefinedFeature( _nId ) )
1021cdf0e10cSrcweir     {
1022cdf0e10cSrcweir         OApplicationController_CBASE::Execute( _nId, aArgs );
1023cdf0e10cSrcweir         return;
1024cdf0e10cSrcweir     }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir 	if ( !getContainer() || m_bReadOnly )
1027cdf0e10cSrcweir 		return; // return without execution
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 	try
1030cdf0e10cSrcweir 	{
1031cdf0e10cSrcweir 		switch(_nId)
1032cdf0e10cSrcweir 		{
1033cdf0e10cSrcweir 			case ID_BROWSER_CUT:
1034cdf0e10cSrcweir 				getContainer()->cut();
1035cdf0e10cSrcweir 				break;
1036cdf0e10cSrcweir 			case ID_BROWSER_COPY:
1037cdf0e10cSrcweir 				{
1038cdf0e10cSrcweir 					TransferableHelper* pTransfer = copyObject( );
1039cdf0e10cSrcweir 					Reference< XTransferable> aEnsureDelete = pTransfer;
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir 					if ( pTransfer )
1042cdf0e10cSrcweir 						pTransfer->CopyToClipboard(getView());
1043cdf0e10cSrcweir 				}
1044cdf0e10cSrcweir 				break;
1045cdf0e10cSrcweir 			case ID_BROWSER_PASTE:
1046cdf0e10cSrcweir 				{
1047cdf0e10cSrcweir 					const TransferableDataHelper& rTransferData( getViewClipboard() );
1048cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 					switch( eType )
1051cdf0e10cSrcweir 					{
1052cdf0e10cSrcweir 						case E_TABLE:
1053cdf0e10cSrcweir 							{
1054cdf0e10cSrcweir 								// get the selected tablename
1055cdf0e10cSrcweir 								::std::vector< ::rtl::OUString > aList;
1056cdf0e10cSrcweir 								getSelectionElementNames( aList );
1057cdf0e10cSrcweir 								if ( !aList.empty() )
1058cdf0e10cSrcweir 									m_aTableCopyHelper.SetTableNameForAppend( *aList.begin() );
1059cdf0e10cSrcweir                                 else
1060cdf0e10cSrcweir                                     m_aTableCopyHelper.ResetTableNameForAppend();
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 								m_aTableCopyHelper.pasteTable( rTransferData , getDatabaseName(), ensureConnection() );
1063cdf0e10cSrcweir 							}
1064cdf0e10cSrcweir 							break;
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 						case E_QUERY:
1067cdf0e10cSrcweir                             if ( rTransferData.HasFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY) )
1068cdf0e10cSrcweir 							    paste( E_QUERY, ODataAccessObjectTransferable::extractObjectDescriptor( rTransferData ) );
1069cdf0e10cSrcweir 							break;
1070cdf0e10cSrcweir 						default:
1071cdf0e10cSrcweir 							{
1072cdf0e10cSrcweir 								::std::vector< ::rtl::OUString> aList;
1073cdf0e10cSrcweir 								getSelectionElementNames(aList);
1074cdf0e10cSrcweir 								::rtl::OUString sFolderNameToInsertInto;
1075cdf0e10cSrcweir 								if ( !aList.empty() )
1076cdf0e10cSrcweir 								{
1077cdf0e10cSrcweir 									Reference< XHierarchicalNameAccess > xContainer(getElements(eType),UNO_QUERY);
1078cdf0e10cSrcweir 									if ( xContainer.is()
1079cdf0e10cSrcweir 										&& xContainer->hasByHierarchicalName(*aList.begin())
1080cdf0e10cSrcweir 										&& (xContainer->getByHierarchicalName(*aList.begin()) >>= xContainer)
1081cdf0e10cSrcweir 										&& xContainer.is()
1082cdf0e10cSrcweir 										)
1083cdf0e10cSrcweir 										sFolderNameToInsertInto = *aList.begin();
1084cdf0e10cSrcweir 								}
1085cdf0e10cSrcweir 								paste( eType, OComponentTransferable::extractComponentDescriptor( rTransferData ),
1086cdf0e10cSrcweir                                     sFolderNameToInsertInto );
1087cdf0e10cSrcweir 							}
1088cdf0e10cSrcweir 							break;
1089cdf0e10cSrcweir 					}
1090cdf0e10cSrcweir 				}
1091cdf0e10cSrcweir 				break;
1092cdf0e10cSrcweir 			case SID_DB_APP_PASTE_SPECIAL:
1093cdf0e10cSrcweir 				{
1094cdf0e10cSrcweir 					if ( !aArgs.getLength() )
1095cdf0e10cSrcweir 					{
1096cdf0e10cSrcweir                         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1097cdf0e10cSrcweir                         ::std::auto_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( getView() ));
1098cdf0e10cSrcweir 						::std::vector<SotFormatStringId> aFormatIds;
1099cdf0e10cSrcweir 						getSupportedFormats(getContainer()->getElementType(),aFormatIds);
1100cdf0e10cSrcweir 						const ::std::vector<SotFormatStringId>::iterator aEnd = aFormatIds.end();
1101cdf0e10cSrcweir                         ::rtl::OUString sEmpty;
1102cdf0e10cSrcweir 						for (::std::vector<SotFormatStringId>::iterator aIter = aFormatIds.begin();aIter != aEnd; ++aIter)
1103cdf0e10cSrcweir 							pDlg->Insert(*aIter,sEmpty);
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir 						const TransferableDataHelper& rClipboard = getViewClipboard();
1106cdf0e10cSrcweir 						pasteFormat(pDlg->GetFormat(rClipboard.GetTransferable()));
1107cdf0e10cSrcweir 					}
1108cdf0e10cSrcweir 					else
1109cdf0e10cSrcweir 					{
1110cdf0e10cSrcweir 						const PropertyValue* pIter = aArgs.getConstArray();
1111cdf0e10cSrcweir 						const PropertyValue* pEnd  = pIter + aArgs.getLength();
1112cdf0e10cSrcweir 						for( ; pIter != pEnd ; ++pIter)
1113cdf0e10cSrcweir 						{
1114cdf0e10cSrcweir 							if ( pIter->Name.equalsAscii("FormatStringId") )
1115cdf0e10cSrcweir 							{
1116cdf0e10cSrcweir 								SotFormatStringId nFormatId = 0;
1117cdf0e10cSrcweir 								if ( pIter->Value >>= nFormatId )
1118cdf0e10cSrcweir 									pasteFormat(nFormatId);
1119cdf0e10cSrcweir 								break;
1120cdf0e10cSrcweir 							}
1121cdf0e10cSrcweir 						}
1122cdf0e10cSrcweir 					}
1123cdf0e10cSrcweir 				}
1124cdf0e10cSrcweir 				break;
1125cdf0e10cSrcweir 			case SID_OPENDOC:
1126cdf0e10cSrcweir 			case SID_HELP_INDEX:
1127cdf0e10cSrcweir 				{
1128cdf0e10cSrcweir 					Reference < XDispatchProvider > xProv( getFrame(), UNO_QUERY );
1129cdf0e10cSrcweir 					if ( xProv.is() )
1130cdf0e10cSrcweir 					{
1131cdf0e10cSrcweir 						URL aURL;
1132cdf0e10cSrcweir 						switch(_nId)
1133cdf0e10cSrcweir 						{
1134cdf0e10cSrcweir 							case SID_HELP_INDEX:
1135cdf0e10cSrcweir 								aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:HelpIndex"));
1136cdf0e10cSrcweir 								break;
1137cdf0e10cSrcweir 							case SID_OPENDOC:
1138cdf0e10cSrcweir 								aURL.Complete = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Open"));
1139cdf0e10cSrcweir 								break;
1140cdf0e10cSrcweir 						}
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 						if ( m_xUrlTransformer.is() )
1143cdf0e10cSrcweir 							m_xUrlTransformer->parseStrict( aURL );
1144cdf0e10cSrcweir 						Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, String(), 0 );
1145cdf0e10cSrcweir             			if ( xDisp.is() )
1146cdf0e10cSrcweir                 			xDisp->dispatch( aURL, Sequence < PropertyValue >() );
1147cdf0e10cSrcweir 					}
1148cdf0e10cSrcweir 				}
1149cdf0e10cSrcweir 				break;
1150cdf0e10cSrcweir 			case ID_BROWSER_SAVEDOC:
1151cdf0e10cSrcweir 				{
1152cdf0e10cSrcweir 					Reference< XStorable > xStore( m_xModel, UNO_QUERY_THROW );
1153cdf0e10cSrcweir                     try
1154cdf0e10cSrcweir                     {
1155cdf0e10cSrcweir                         xStore->store();
1156cdf0e10cSrcweir                     }
1157cdf0e10cSrcweir                     catch( const Exception& )
1158cdf0e10cSrcweir                     {
1159cdf0e10cSrcweir                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1160cdf0e10cSrcweir                     }
1161cdf0e10cSrcweir 				}
1162cdf0e10cSrcweir 				break;
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir             case ID_BROWSER_SAVEASDOC:
1165cdf0e10cSrcweir 				{
1166cdf0e10cSrcweir 					WinBits nBits(WB_STDMODAL|WB_SAVEAS);
1167cdf0e10cSrcweir                     ::rtl::OUString sUrl;
1168cdf0e10cSrcweir 			        if ( m_xModel.is() )
1169cdf0e10cSrcweir 				        sUrl = m_xModel->getURL();
1170cdf0e10cSrcweir 			        if ( !sUrl.getLength() )
1171cdf0e10cSrcweir                         sUrl = SvtPathOptions().GetWorkPath();
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 					::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,static_cast<sal_uInt32>(nBits) ,getView());
1174cdf0e10cSrcweir 					aFileDlg.SetDisplayDirectory( sUrl );
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir 					const SfxFilter* pFilter = getStandardDatabaseFilter();
1177cdf0e10cSrcweir 					if ( pFilter )
1178cdf0e10cSrcweir 					{
1179cdf0e10cSrcweir 						aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
1180cdf0e10cSrcweir 						aFileDlg.SetCurrentFilter(pFilter->GetUIName());
1181cdf0e10cSrcweir 					}
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 					if ( aFileDlg.Execute() != ERRCODE_NONE )
1184cdf0e10cSrcweir                         break;
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir                     Reference<XStorable> xStore( m_xModel, UNO_QUERY_THROW );
1187cdf0e10cSrcweir 					INetURLObject aURL( aFileDlg.GetPath() );
1188cdf0e10cSrcweir                     try
1189cdf0e10cSrcweir                     {
1190cdf0e10cSrcweir                         xStore->storeAsURL( aURL.GetMainURL( INetURLObject::NO_DECODE ), Sequence< PropertyValue >() );
1191cdf0e10cSrcweir                     }
1192cdf0e10cSrcweir                     catch( const Exception& )
1193cdf0e10cSrcweir                     {
1194cdf0e10cSrcweir                         lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
1195cdf0e10cSrcweir                     }
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir 					/*updateTitle();*/
1198cdf0e10cSrcweir 					m_bCurrentlyModified = sal_False;
1199cdf0e10cSrcweir 					InvalidateFeature(ID_BROWSER_SAVEDOC);
1200cdf0e10cSrcweir                     if ( getContainer()->getElementType() == E_NONE )
1201cdf0e10cSrcweir                     {
1202cdf0e10cSrcweir                         getContainer()->selectContainer(E_NONE);
1203cdf0e10cSrcweir                         getContainer()->selectContainer(E_TABLE);
1204cdf0e10cSrcweir                         // #i95524#
1205cdf0e10cSrcweir                         getContainer()->Invalidate();
1206cdf0e10cSrcweir                         refreshTables();
1207cdf0e10cSrcweir                     }
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 				}
1210cdf0e10cSrcweir 				break;
1211cdf0e10cSrcweir 			case ID_BROWSER_SORTUP:
1212cdf0e10cSrcweir 				getContainer()->sortUp();
1213cdf0e10cSrcweir 				InvalidateFeature(ID_BROWSER_SORTDOWN);
1214cdf0e10cSrcweir 				break;
1215cdf0e10cSrcweir 			case ID_BROWSER_SORTDOWN:
1216cdf0e10cSrcweir 				getContainer()->sortDown();
1217cdf0e10cSrcweir 				InvalidateFeature(ID_BROWSER_SORTUP);
1218cdf0e10cSrcweir 				break;
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1221cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN_AUTO_PILOT:
1222cdf0e10cSrcweir 			case ID_APP_NEW_QUERY_AUTO_PILOT:
1223cdf0e10cSrcweir 			case SID_DB_FORM_NEW_PILOT:
1224cdf0e10cSrcweir 			case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1225cdf0e10cSrcweir             case SID_APP_NEW_REPORT_PRE_SEL:
1226cdf0e10cSrcweir 			case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1227cdf0e10cSrcweir 			case ID_DOCUMENT_CREATE_REPWIZ:
1228cdf0e10cSrcweir 			case SID_APP_NEW_FORM:
1229cdf0e10cSrcweir 			case SID_APP_NEW_REPORT:
1230cdf0e10cSrcweir 			case ID_NEW_QUERY_SQL:
1231cdf0e10cSrcweir 			case ID_NEW_QUERY_DESIGN:
1232cdf0e10cSrcweir 			case ID_NEW_TABLE_DESIGN:
1233cdf0e10cSrcweir 				{
1234cdf0e10cSrcweir 					ElementType eType = E_TABLE;
1235cdf0e10cSrcweir 					sal_Bool bAutoPilot = sal_False;
1236cdf0e10cSrcweir                     ::comphelper::NamedValueCollection aCreationArgs;
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir 					switch( _nId )
1239cdf0e10cSrcweir 					{
1240cdf0e10cSrcweir 						case SID_DB_FORM_NEW_PILOT:
1241cdf0e10cSrcweir 						case SID_FORM_CREATE_REPWIZ_PRE_SEL:
1242cdf0e10cSrcweir 							bAutoPilot = sal_True;
1243cdf0e10cSrcweir 							// run through
1244cdf0e10cSrcweir 						case SID_APP_NEW_FORM:
1245cdf0e10cSrcweir 							eType = E_FORM;
1246cdf0e10cSrcweir 							break;
1247cdf0e10cSrcweir 						case ID_DOCUMENT_CREATE_REPWIZ:
1248cdf0e10cSrcweir 						case SID_REPORT_CREATE_REPWIZ_PRE_SEL:
1249cdf0e10cSrcweir 							bAutoPilot = sal_True;
1250cdf0e10cSrcweir 							// run through
1251cdf0e10cSrcweir 						case SID_APP_NEW_REPORT:
1252cdf0e10cSrcweir                         case SID_APP_NEW_REPORT_PRE_SEL:
1253cdf0e10cSrcweir 							eType = E_REPORT;
1254cdf0e10cSrcweir 							break;
1255cdf0e10cSrcweir 						case ID_APP_NEW_QUERY_AUTO_PILOT:
1256cdf0e10cSrcweir 							bAutoPilot = sal_True;
1257cdf0e10cSrcweir 							eType = E_QUERY;
1258cdf0e10cSrcweir 							break;
1259cdf0e10cSrcweir 						case ID_NEW_QUERY_DESIGN:
1260cdf0e10cSrcweir                             aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, sal_True );
1261cdf0e10cSrcweir 							// run through
1262cdf0e10cSrcweir 						case ID_NEW_QUERY_SQL:
1263cdf0e10cSrcweir 							eType = E_QUERY;
1264cdf0e10cSrcweir 							break;
1265cdf0e10cSrcweir  						case ID_NEW_TABLE_DESIGN_AUTO_PILOT:
1266cdf0e10cSrcweir  							bAutoPilot = sal_True;
1267cdf0e10cSrcweir  							// run through
1268cdf0e10cSrcweir 						case ID_NEW_TABLE_DESIGN:
1269cdf0e10cSrcweir 							break;
1270cdf0e10cSrcweir 						default:
1271cdf0e10cSrcweir 							OSL_ENSURE(0,"illegal switch call!");
1272cdf0e10cSrcweir 					}
1273cdf0e10cSrcweir                     if ( bAutoPilot )
1274cdf0e10cSrcweir                         getContainer()->PostUserEvent( LINK( this, OApplicationController, OnCreateWithPilot ), reinterpret_cast< void* >( eType ) );
1275cdf0e10cSrcweir                     else
1276cdf0e10cSrcweir                     {
1277cdf0e10cSrcweir                         Reference< XComponent > xDocDefinition;
1278cdf0e10cSrcweir 					    newElement( eType, aCreationArgs, xDocDefinition );
1279cdf0e10cSrcweir                     }
1280cdf0e10cSrcweir 				}
1281cdf0e10cSrcweir 				break;
1282cdf0e10cSrcweir 			case SID_APP_NEW_FOLDER:
1283cdf0e10cSrcweir 				{
1284cdf0e10cSrcweir 					ElementType eType = getContainer()->getElementType();
1285cdf0e10cSrcweir 					::rtl::OUString sName = getContainer()->getQualifiedName( NULL );
1286cdf0e10cSrcweir 					insertHierachyElement(eType,sName);
1287cdf0e10cSrcweir 				}
1288cdf0e10cSrcweir 				break;
1289cdf0e10cSrcweir 			case ID_NEW_VIEW_DESIGN:
1290cdf0e10cSrcweir 			case SID_DB_NEW_VIEW_SQL:
1291cdf0e10cSrcweir 				{
1292cdf0e10cSrcweir                     SharedConnection xConnection( ensureConnection() );
1293cdf0e10cSrcweir 					if ( xConnection.is() )
1294cdf0e10cSrcweir 					{
1295cdf0e10cSrcweir 						QueryDesigner aDesigner( getORB(), this, getFrame(), true );
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir                         ::comphelper::NamedValueCollection aCreationArgs;
1298cdf0e10cSrcweir                         aCreationArgs.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, ID_NEW_VIEW_DESIGN == _nId );
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1301cdf0e10cSrcweir 						const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource, aCreationArgs ), UNO_QUERY );
1302cdf0e10cSrcweir                         onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
1303cdf0e10cSrcweir 					}
1304cdf0e10cSrcweir 				}
1305cdf0e10cSrcweir 				break;
1306cdf0e10cSrcweir 			case SID_DB_APP_DELETE:
1307cdf0e10cSrcweir 			case SID_DB_APP_TABLE_DELETE:
1308cdf0e10cSrcweir 			case SID_DB_APP_QUERY_DELETE:
1309cdf0e10cSrcweir 			case SID_DB_APP_FORM_DELETE:
1310cdf0e10cSrcweir 			case SID_DB_APP_REPORT_DELETE:
1311cdf0e10cSrcweir 				deleteEntries();
1312cdf0e10cSrcweir 				break;
1313cdf0e10cSrcweir 			case SID_DB_APP_RENAME:
1314cdf0e10cSrcweir 			case SID_DB_APP_TABLE_RENAME:
1315cdf0e10cSrcweir 			case SID_DB_APP_QUERY_RENAME:
1316cdf0e10cSrcweir 			case SID_DB_APP_FORM_RENAME:
1317cdf0e10cSrcweir 			case SID_DB_APP_REPORT_RENAME:
1318cdf0e10cSrcweir 				renameEntry();
1319cdf0e10cSrcweir 				break;
1320cdf0e10cSrcweir 			case SID_DB_APP_EDIT:
1321cdf0e10cSrcweir 			case SID_DB_APP_EDIT_SQL_VIEW:
1322cdf0e10cSrcweir 			case SID_DB_APP_TABLE_EDIT:
1323cdf0e10cSrcweir 			case SID_DB_APP_QUERY_EDIT:
1324cdf0e10cSrcweir 			case SID_DB_APP_FORM_EDIT:
1325cdf0e10cSrcweir 			case SID_DB_APP_REPORT_EDIT:
1326cdf0e10cSrcweir 				doAction( _nId, E_OPEN_DESIGN );
1327cdf0e10cSrcweir                 break;
1328cdf0e10cSrcweir 			case SID_DB_APP_OPEN:
1329cdf0e10cSrcweir 			case SID_DB_APP_TABLE_OPEN:
1330cdf0e10cSrcweir 			case SID_DB_APP_QUERY_OPEN:
1331cdf0e10cSrcweir 			case SID_DB_APP_FORM_OPEN:
1332cdf0e10cSrcweir 			case SID_DB_APP_REPORT_OPEN:
1333cdf0e10cSrcweir 				doAction( _nId, E_OPEN_NORMAL );
1334cdf0e10cSrcweir 				break;
1335cdf0e10cSrcweir 			case SID_DB_APP_CONVERTTOVIEW:
1336cdf0e10cSrcweir 				doAction( _nId, E_OPEN_NORMAL );
1337cdf0e10cSrcweir 				break;
1338cdf0e10cSrcweir 			case SID_SELECTALL:
1339cdf0e10cSrcweir 				getContainer()->selectAll();
1340cdf0e10cSrcweir 				InvalidateAll();
1341cdf0e10cSrcweir 				break;
1342cdf0e10cSrcweir 			case SID_DB_APP_DSRELDESIGN:
1343cdf0e10cSrcweir             {
1344cdf0e10cSrcweir                 Reference< XComponent > xRelationDesigner;
1345cdf0e10cSrcweir                 if ( !m_pSubComponentManager->activateSubFrame( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xRelationDesigner ) )
1346cdf0e10cSrcweir                 {
1347cdf0e10cSrcweir 				    SharedConnection xConnection( ensureConnection() );
1348cdf0e10cSrcweir 				    if ( xConnection.is() )
1349cdf0e10cSrcweir 				    {
1350cdf0e10cSrcweir 					    RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir                         const Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
1353cdf0e10cSrcweir 					    const Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
1354cdf0e10cSrcweir                         onDocumentOpened( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
1355cdf0e10cSrcweir 				    }
1356cdf0e10cSrcweir                 }
1357cdf0e10cSrcweir             }
1358cdf0e10cSrcweir 			break;
1359cdf0e10cSrcweir 			case SID_DB_APP_DSUSERADMIN:
1360cdf0e10cSrcweir 				{
1361cdf0e10cSrcweir 					SharedConnection xConnection( ensureConnection() );
1362cdf0e10cSrcweir 					if ( xConnection.is() )
1363cdf0e10cSrcweir 						openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.UserAdministrationDialog")));
1364cdf0e10cSrcweir 				}
1365cdf0e10cSrcweir 				break;
1366cdf0e10cSrcweir 			case SID_DB_APP_TABLEFILTER:
1367cdf0e10cSrcweir 				openTableFilterDialog();
1368cdf0e10cSrcweir 				askToReconnect();
1369cdf0e10cSrcweir 				break;
1370cdf0e10cSrcweir 			case SID_DB_APP_REFRESH_TABLES:
1371cdf0e10cSrcweir 				refreshTables();
1372cdf0e10cSrcweir 				break;
1373cdf0e10cSrcweir 			case SID_DB_APP_DSPROPS:
1374cdf0e10cSrcweir 				openDataSourceAdminDialog();
1375cdf0e10cSrcweir 				askToReconnect();
1376cdf0e10cSrcweir 				break;
1377cdf0e10cSrcweir 			case SID_DB_APP_DSADVANCED_SETTINGS:
1378cdf0e10cSrcweir 				openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.AdvancedDatabaseSettingsDialog")));
1379cdf0e10cSrcweir 				askToReconnect();
1380cdf0e10cSrcweir 				break;
1381cdf0e10cSrcweir 			case SID_DB_APP_DSCONNECTION_TYPE:
1382cdf0e10cSrcweir 				openDialog(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog")));
1383cdf0e10cSrcweir 				askToReconnect();
1384cdf0e10cSrcweir 				break;
1385cdf0e10cSrcweir 			case ID_DIRECT_SQL:
1386cdf0e10cSrcweir 				{
1387cdf0e10cSrcweir 					SharedConnection xConnection( ensureConnection() );
1388cdf0e10cSrcweir 					if ( xConnection.is() )
1389cdf0e10cSrcweir 						openDirectSQLDialog();
1390cdf0e10cSrcweir 				}
1391cdf0e10cSrcweir 				break;
1392cdf0e10cSrcweir             case ID_MIGRATE_SCRIPTS:
1393cdf0e10cSrcweir                 impl_migrateScripts_nothrow();
1394cdf0e10cSrcweir                 break;
1395cdf0e10cSrcweir 			case SID_DB_APP_VIEW_TABLES:
1396cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_TABLE ) );
1397cdf0e10cSrcweir 				break;
1398cdf0e10cSrcweir 			case SID_DB_APP_VIEW_QUERIES:
1399cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_QUERY ) );
1400cdf0e10cSrcweir 				break;
1401cdf0e10cSrcweir 			case SID_DB_APP_VIEW_FORMS:
1402cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_FORM ) );
1403cdf0e10cSrcweir 				break;
1404cdf0e10cSrcweir 			case SID_DB_APP_VIEW_REPORTS:
1405cdf0e10cSrcweir                 m_aSelectContainerEvent.Call( reinterpret_cast< void* >( E_REPORT ) );
1406cdf0e10cSrcweir 				break;
1407cdf0e10cSrcweir 			case SID_DB_APP_DISABLE_PREVIEW:
1408cdf0e10cSrcweir 				m_ePreviewMode = E_PREVIEWNONE;
1409cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1410cdf0e10cSrcweir 				break;
1411cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOCINFO_PREVIEW:
1412cdf0e10cSrcweir 				m_ePreviewMode = E_DOCUMENTINFO;
1413cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1414cdf0e10cSrcweir 				break;
1415cdf0e10cSrcweir 			case SID_DB_APP_VIEW_DOC_PREVIEW:
1416cdf0e10cSrcweir 				m_ePreviewMode = E_DOCUMENT;
1417cdf0e10cSrcweir 				getContainer()->switchPreview(m_ePreviewMode);
1418cdf0e10cSrcweir 				break;
1419cdf0e10cSrcweir 			case SID_MAIL_SENDDOC:
1420cdf0e10cSrcweir 				{
1421cdf0e10cSrcweir 					SfxMailModel aSendMail;
1422cdf0e10cSrcweir                     if ( aSendMail.AttachDocument(rtl::OUString(),getModel(), rtl::OUString()) == SfxMailModel::SEND_MAIL_OK )
1423cdf0e10cSrcweir 						aSendMail.Send( getFrame() );
1424cdf0e10cSrcweir 				}
1425cdf0e10cSrcweir 				break;
1426cdf0e10cSrcweir 			case SID_DB_APP_SENDREPORTASMAIL:
1427cdf0e10cSrcweir 				doAction( _nId, E_OPEN_FOR_MAIL );
1428cdf0e10cSrcweir 				break;
1429cdf0e10cSrcweir 		}
1430cdf0e10cSrcweir 	}
1431cdf0e10cSrcweir 	catch( const Exception& )
1432cdf0e10cSrcweir 	{
1433cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1434cdf0e10cSrcweir 	}
1435cdf0e10cSrcweir 	InvalidateFeature(_nId);
1436cdf0e10cSrcweir }
1437cdf0e10cSrcweir // -----------------------------------------------------------------------------
1438cdf0e10cSrcweir void OApplicationController::describeSupportedFeatures()
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir 	OApplicationController_CBASE::describeSupportedFeatures();
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Save",               ID_BROWSER_SAVEDOC,        CommandGroup::DOCUMENT );
1443cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SaveAs",             ID_BROWSER_SAVEASDOC,      CommandGroup::DOCUMENT );
1444cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:SendMail",			 SID_MAIL_SENDDOC,			CommandGroup::DOCUMENT );
1445cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBSendReportAsMail",SID_DB_APP_SENDREPORTASMAIL,
1446cdf0e10cSrcweir 																						CommandGroup::DOCUMENT );
1447cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBSendReportToWriter",SID_DB_APP_SENDREPORTTOWRITER,
1448cdf0e10cSrcweir 																						CommandGroup::DOCUMENT );
1449cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewForm",          SID_APP_NEW_FORM,          CommandGroup::INSERT );
1450cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFolder",        SID_APP_NEW_FOLDER,        CommandGroup::INSERT );
1451cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilot", SID_DB_FORM_NEW_PILOT,     CommandGroup::INSERT );
1452cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewFormAutoPilotWithPreSelection",
1453cdf0e10cSrcweir                                                              SID_FORM_CREATE_REPWIZ_PRE_SEL,
1454cdf0e10cSrcweir                                                                                         CommandGroup::APPLICATION );
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBNewReport",		 SID_APP_NEW_REPORT,		CommandGroup::INSERT );
1457cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilot",
1458cdf0e10cSrcweir                                                              ID_DOCUMENT_CREATE_REPWIZ, CommandGroup::INSERT );
1459cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportAutoPilotWithPreSelection",
1460cdf0e10cSrcweir                                                              SID_REPORT_CREATE_REPWIZ_PRE_SEL,
1461cdf0e10cSrcweir                                                                                         CommandGroup::APPLICATION );
1462cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQuery",         ID_NEW_QUERY_DESIGN,       CommandGroup::INSERT );
1463cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQuerySql",      ID_NEW_QUERY_SQL,          CommandGroup::INSERT );
1464cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewQueryAutoPilot",ID_APP_NEW_QUERY_AUTO_PILOT,
1465cdf0e10cSrcweir                                                                                         CommandGroup::INSERT );
1466cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewTable",         ID_NEW_TABLE_DESIGN,       CommandGroup::INSERT );
1467cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewTableAutoPilot",ID_NEW_TABLE_DESIGN_AUTO_PILOT,
1468cdf0e10cSrcweir                                                                                         CommandGroup::INSERT );
1469cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewView",          ID_NEW_VIEW_DESIGN,        CommandGroup::INSERT );
1470cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewViewSQL",       SID_DB_NEW_VIEW_SQL,       CommandGroup::INSERT );
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDelete",           SID_DB_APP_DELETE,         CommandGroup::EDIT );
1473cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Delete",			 SID_DB_APP_DELETE,         CommandGroup::EDIT );
1474cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRename",           SID_DB_APP_RENAME,         CommandGroup::EDIT );
1475cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBEdit",             SID_DB_APP_EDIT,           CommandGroup::EDIT );
1476cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBEditSqlView",      SID_DB_APP_EDIT_SQL_VIEW,  CommandGroup::EDIT );
1477cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBOpen",             SID_DB_APP_OPEN,           CommandGroup::EDIT );
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableDelete",      SID_DB_APP_TABLE_DELETE,   CommandGroup::EDIT );
1480cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableRename",      SID_DB_APP_TABLE_RENAME,   CommandGroup::EDIT );
1481cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableEdit",        SID_DB_APP_TABLE_EDIT,     CommandGroup::EDIT );
1482cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableOpen",        SID_DB_APP_TABLE_OPEN,     CommandGroup::EDIT );
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryDelete",      SID_DB_APP_QUERY_DELETE,   CommandGroup::EDIT );
1485cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryRename",      SID_DB_APP_QUERY_RENAME,   CommandGroup::EDIT );
1486cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryEdit",        SID_DB_APP_QUERY_EDIT,     CommandGroup::EDIT );
1487cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBQueryOpen",        SID_DB_APP_QUERY_OPEN,     CommandGroup::EDIT );
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormDelete",       SID_DB_APP_FORM_DELETE,    CommandGroup::EDIT );
1490cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormRename",       SID_DB_APP_FORM_RENAME,    CommandGroup::EDIT );
1491cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormEdit",         SID_DB_APP_FORM_EDIT,      CommandGroup::EDIT );
1492cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBFormOpen",         SID_DB_APP_FORM_OPEN,      CommandGroup::EDIT );
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportDelete",     SID_DB_APP_REPORT_DELETE,  CommandGroup::EDIT );
1495cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportRename",     SID_DB_APP_REPORT_RENAME,  CommandGroup::EDIT );
1496cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportEdit",       SID_DB_APP_REPORT_EDIT,    CommandGroup::EDIT );
1497cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBReportOpen",       SID_DB_APP_REPORT_OPEN,    CommandGroup::EDIT );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SelectAll",          SID_SELECTALL,             CommandGroup::EDIT );
1500cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Undo",               ID_BROWSER_UNDO,           CommandGroup::EDIT );
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Sortup",             ID_BROWSER_SORTUP,         CommandGroup::VIEW );
1503cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:SortDown",           ID_BROWSER_SORTDOWN,       CommandGroup::VIEW );
1504cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRelationDesign",   SID_DB_APP_DSRELDESIGN,    CommandGroup::APPLICATION );
1505cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBUserAdmin",        SID_DB_APP_DSUSERADMIN,    CommandGroup::APPLICATION );
1506cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBTableFilter",      SID_DB_APP_TABLEFILTER,    CommandGroup::APPLICATION );
1507cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSProperties",     SID_DB_APP_DSPROPS,        CommandGroup::EDIT );
1508cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSConnectionType", SID_DB_APP_DSCONNECTION_TYPE,
1509cdf0e10cSrcweir                                                                                         CommandGroup::EDIT );
1510cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDSAdvancedSettings",
1511cdf0e10cSrcweir                                                              SID_DB_APP_DSADVANCED_SETTINGS,
1512cdf0e10cSrcweir                                                                                         CommandGroup::EDIT );
1513cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:PasteSpecial",       SID_DB_APP_PASTE_SPECIAL,  CommandGroup::EDIT );
1514cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBConvertToView",    SID_DB_APP_CONVERTTOVIEW,  CommandGroup::EDIT );
1515cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBRefreshTables",    SID_DB_APP_REFRESH_TABLES, CommandGroup::APPLICATION );
1516cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDirectSQL",        ID_DIRECT_SQL,             CommandGroup::APPLICATION );
1517cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBMigrateScripts",   ID_MIGRATE_SCRIPTS,        CommandGroup::APPLICATION );
1518cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewTables",       SID_DB_APP_VIEW_TABLES,    CommandGroup::VIEW );
1519cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewQueries",      SID_DB_APP_VIEW_QUERIES,   CommandGroup::VIEW );
1520cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewForms",        SID_DB_APP_VIEW_FORMS,     CommandGroup::VIEW );
1521cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBViewReports",      SID_DB_APP_VIEW_REPORTS,   CommandGroup::VIEW );
1522cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBDisablePreview",   SID_DB_APP_DISABLE_PREVIEW,CommandGroup::VIEW );
1523cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBShowDocInfoPreview",
1524cdf0e10cSrcweir                                                              SID_DB_APP_VIEW_DOCINFO_PREVIEW,
1525cdf0e10cSrcweir                                                                                         CommandGroup::VIEW );
1526cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBShowDocPreview",   SID_DB_APP_VIEW_DOC_PREVIEW,
1527cdf0e10cSrcweir                                                                                         CommandGroup::VIEW );
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:OpenUrl",            SID_OPENURL,               CommandGroup::APPLICATION );
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir     // this one should not appear under Tools->Customize->Keyboard
1532cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:DBNewReportWithPreSelection",
1533cdf0e10cSrcweir                                                              SID_APP_NEW_REPORT_PRE_SEL,CommandGroup::INTERNAL );
1534cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDSImport",		SID_DB_APP_DSIMPORT, CommandGroup::INTERNAL);
1535cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDSExport",		SID_DB_APP_DSEXPORT, CommandGroup::INTERNAL);
1536cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBDBAdmin",			SID_DB_APP_DBADMIN, CommandGroup::INTERNAL);
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir 	// status info
1539cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusType",		SID_DB_APP_STATUS_TYPE, CommandGroup::INTERNAL);
1540cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusDBName",	SID_DB_APP_STATUS_DBNAME, CommandGroup::INTERNAL);
1541cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusUserName",	SID_DB_APP_STATUS_USERNAME, CommandGroup::INTERNAL);
1542cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DBStatusHostName",	SID_DB_APP_STATUS_HOSTNAME, CommandGroup::INTERNAL);
1543cdf0e10cSrcweir }
1544cdf0e10cSrcweir // -----------------------------------------------------------------------------
1545cdf0e10cSrcweir OApplicationView*	OApplicationController::getContainer() const
1546cdf0e10cSrcweir {
1547cdf0e10cSrcweir 	return static_cast< OApplicationView* >( getView() );
1548cdf0e10cSrcweir }
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir // -----------------------------------------------------------------------------
1551cdf0e10cSrcweir // ::com::sun::star::container::XContainerListener
1552cdf0e10cSrcweir void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
1553cdf0e10cSrcweir {
1554cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1555cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1558cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1559cdf0e10cSrcweir 	{
1560cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1561cdf0e10cSrcweir 		if ( getContainer() )
1562cdf0e10cSrcweir 		{
1563cdf0e10cSrcweir 			::rtl::OUString sName;
1564cdf0e10cSrcweir 			_rEvent.Accessor >>= sName;
1565cdf0e10cSrcweir 			ElementType eType = getElementType(xContainer);
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir 			switch( eType )
1568cdf0e10cSrcweir 			{
1569cdf0e10cSrcweir 				case E_TABLE:
1570cdf0e10cSrcweir 					ensureConnection();
1571cdf0e10cSrcweir 					break;
1572cdf0e10cSrcweir 				case E_FORM:
1573cdf0e10cSrcweir 				case E_REPORT:
1574cdf0e10cSrcweir 					{
1575cdf0e10cSrcweir 						Reference< XContainer > xSubContainer(_rEvent.Element,UNO_QUERY);
1576cdf0e10cSrcweir 						if ( xSubContainer.is() )
1577cdf0e10cSrcweir 							containerFound(xSubContainer);
1578cdf0e10cSrcweir 					}
1579cdf0e10cSrcweir 					break;
1580cdf0e10cSrcweir                 default:
1581cdf0e10cSrcweir                     break;
1582cdf0e10cSrcweir 			}
1583cdf0e10cSrcweir 			getContainer()->elementAdded(eType,sName,_rEvent.Element);
1584cdf0e10cSrcweir 		}
1585cdf0e10cSrcweir 	}
1586cdf0e10cSrcweir }
1587cdf0e10cSrcweir // -----------------------------------------------------------------------------
1588cdf0e10cSrcweir void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
1589cdf0e10cSrcweir {
1590cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1591cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1594cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1595cdf0e10cSrcweir 	{
1596cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1597cdf0e10cSrcweir 		::rtl::OUString sName;
1598cdf0e10cSrcweir 		_rEvent.Accessor >>= sName;
1599cdf0e10cSrcweir 		ElementType eType = getElementType(xContainer);
1600cdf0e10cSrcweir 		switch( eType )
1601cdf0e10cSrcweir 		{
1602cdf0e10cSrcweir 			case E_TABLE:
1603cdf0e10cSrcweir 				ensureConnection();
1604cdf0e10cSrcweir 				break;
1605cdf0e10cSrcweir 			case E_FORM:
1606cdf0e10cSrcweir 			case E_REPORT:
1607cdf0e10cSrcweir 				{
1608cdf0e10cSrcweir 					Reference<XContent> xContent(xContainer,UNO_QUERY);
1609cdf0e10cSrcweir 					if ( xContent.is() )
1610cdf0e10cSrcweir 					{
1611cdf0e10cSrcweir 						sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1612cdf0e10cSrcweir 					}
1613cdf0e10cSrcweir 				}
1614cdf0e10cSrcweir 				break;
1615cdf0e10cSrcweir             default:
1616cdf0e10cSrcweir                 break;
1617cdf0e10cSrcweir 		}
1618cdf0e10cSrcweir 		getContainer()->elementRemoved(eType,sName);
1619cdf0e10cSrcweir 	}
1620cdf0e10cSrcweir }
1621cdf0e10cSrcweir // -----------------------------------------------------------------------------
1622cdf0e10cSrcweir void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1625cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir 	Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
1628cdf0e10cSrcweir 	if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
1629cdf0e10cSrcweir 	{
1630cdf0e10cSrcweir 		OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1631cdf0e10cSrcweir 		::rtl::OUString sName;
1632cdf0e10cSrcweir 		try
1633cdf0e10cSrcweir 		{
1634cdf0e10cSrcweir 			_rEvent.Accessor >>= sName;
1635cdf0e10cSrcweir 			Reference<XConnection> xConnection;
1636cdf0e10cSrcweir 			Reference<XPropertySet> xProp(_rEvent.Element,UNO_QUERY);
1637cdf0e10cSrcweir 			::rtl::OUString sNewName;
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir 			ElementType eType = getElementType(xContainer);
1640cdf0e10cSrcweir 			switch( eType )
1641cdf0e10cSrcweir 			{
1642cdf0e10cSrcweir 				case E_TABLE:
1643cdf0e10cSrcweir                 {
1644cdf0e10cSrcweir 					ensureConnection();
1645cdf0e10cSrcweir 					if ( xProp.is() && m_xMetaData.is() )
1646cdf0e10cSrcweir 						sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
1647cdf0e10cSrcweir                 }
1648cdf0e10cSrcweir 				break;
1649cdf0e10cSrcweir 				case E_FORM:
1650cdf0e10cSrcweir 				case E_REPORT:
1651cdf0e10cSrcweir 					{
1652cdf0e10cSrcweir 						Reference<XContent> xContent(xContainer,UNO_QUERY);
1653cdf0e10cSrcweir 						if ( xContent.is() )
1654cdf0e10cSrcweir 						{
1655cdf0e10cSrcweir 							sName = xContent->getIdentifier()->getContentIdentifier() + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
1656cdf0e10cSrcweir 						}
1657cdf0e10cSrcweir 					}
1658cdf0e10cSrcweir 					break;
1659cdf0e10cSrcweir                 default:
1660cdf0e10cSrcweir                     break;
1661cdf0e10cSrcweir 			}
1662cdf0e10cSrcweir 			//	getContainer()->elementReplaced(getContainer()->getElementType(),sName,sNewName);
1663cdf0e10cSrcweir 		}
1664cdf0e10cSrcweir 		catch( Exception& )
1665cdf0e10cSrcweir 		{
1666cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1667cdf0e10cSrcweir 		}
1668cdf0e10cSrcweir 	}
1669cdf0e10cSrcweir }
1670cdf0e10cSrcweir namespace
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir 	::rtl::OUString lcl_getToolBarResource(ElementType _eType)
1673cdf0e10cSrcweir 	{
1674cdf0e10cSrcweir 		::rtl::OUString sToolbar;
1675cdf0e10cSrcweir 		switch(_eType)
1676cdf0e10cSrcweir 		{
1677cdf0e10cSrcweir 			case E_TABLE:
1678cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/tableobjectbar" ));
1679cdf0e10cSrcweir 				break;
1680cdf0e10cSrcweir 			case E_QUERY:
1681cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/queryobjectbar" ));
1682cdf0e10cSrcweir 				break;
1683cdf0e10cSrcweir 			case E_FORM:
1684cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/formobjectbar" ));
1685cdf0e10cSrcweir 				break;
1686cdf0e10cSrcweir 			case E_REPORT:
1687cdf0e10cSrcweir 				sToolbar = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/reportobjectbar" ));
1688cdf0e10cSrcweir 				break;
1689cdf0e10cSrcweir 			case E_NONE:
1690cdf0e10cSrcweir 				break;
1691cdf0e10cSrcweir 			default:
1692cdf0e10cSrcweir 				OSL_ENSURE(0,"Invalid ElementType!");
1693cdf0e10cSrcweir 				break;
1694cdf0e10cSrcweir 		}
1695cdf0e10cSrcweir 		return sToolbar;
1696cdf0e10cSrcweir 	}
1697cdf0e10cSrcweir }
1698cdf0e10cSrcweir // -----------------------------------------------------------------------------
1699cdf0e10cSrcweir sal_Bool OApplicationController::onContainerSelect(ElementType _eType)
1700cdf0e10cSrcweir {
1701cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir     if ( m_eCurrentType != _eType && _eType != E_NONE )
1704cdf0e10cSrcweir 	{
1705cdf0e10cSrcweir         SelectionGuard aSelGuard( *m_pSelectionNotifier );
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir         if ( _eType == E_TABLE )
1708cdf0e10cSrcweir 		{
1709cdf0e10cSrcweir 			try
1710cdf0e10cSrcweir 			{
1711cdf0e10cSrcweir 				SharedConnection xConnection( ensureConnection() );
1712cdf0e10cSrcweir 				if ( xConnection.is() && getContainer()->getDetailView() )
1713cdf0e10cSrcweir 				{
1714cdf0e10cSrcweir 					getContainer()->getDetailView()->createTablesPage(xConnection);
1715cdf0e10cSrcweir 					Reference<XTablesSupplier> xTabSup(xConnection,UNO_QUERY);
1716cdf0e10cSrcweir 					if ( xTabSup.is() )
1717cdf0e10cSrcweir 						addContainerListener(xTabSup->getTables());
1718cdf0e10cSrcweir 				}
1719cdf0e10cSrcweir 				else
1720cdf0e10cSrcweir 				{
1721cdf0e10cSrcweir 					return sal_False;
1722cdf0e10cSrcweir 				}
1723cdf0e10cSrcweir 			}
1724cdf0e10cSrcweir 			catch( const Exception& )
1725cdf0e10cSrcweir 			{
1726cdf0e10cSrcweir 				return sal_False;
1727cdf0e10cSrcweir 			}
1728cdf0e10cSrcweir 		}
1729cdf0e10cSrcweir         Reference< XLayoutManager > xLayoutManager = getLayoutManager( getFrame() );
1730cdf0e10cSrcweir         if ( xLayoutManager.is() )
1731cdf0e10cSrcweir         {
1732cdf0e10cSrcweir 		    ::rtl::OUString sToolbar = lcl_getToolBarResource(_eType);
1733cdf0e10cSrcweir 		    ::rtl::OUString sDestroyToolbar = lcl_getToolBarResource(m_eCurrentType);
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir 		    xLayoutManager->lock();
1736cdf0e10cSrcweir 		    xLayoutManager->destroyElement( sDestroyToolbar );
1737cdf0e10cSrcweir 		    if ( sToolbar.getLength() )
1738cdf0e10cSrcweir 		    {
1739cdf0e10cSrcweir 			    xLayoutManager->createElement( sToolbar );
1740cdf0e10cSrcweir 			    xLayoutManager->requestElement( sToolbar );
1741cdf0e10cSrcweir 		    }
1742cdf0e10cSrcweir 		    xLayoutManager->unlock();
1743cdf0e10cSrcweir 		    xLayoutManager->doLayout();
1744cdf0e10cSrcweir         }
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir 		if ( _eType != E_TABLE && getContainer()->getDetailView() )
1747cdf0e10cSrcweir 		{
1748cdf0e10cSrcweir 			Reference< XNameAccess > xContainer = getElements(_eType);
1749cdf0e10cSrcweir 			addContainerListener(xContainer);
1750cdf0e10cSrcweir 			getContainer()->getDetailView()->createPage(_eType,xContainer);
1751cdf0e10cSrcweir 		}
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir         SelectionByElementType::iterator pendingSelection = m_aPendingSelection.find( _eType );
1754cdf0e10cSrcweir         if ( pendingSelection != m_aPendingSelection.end() )
1755cdf0e10cSrcweir         {
1756cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelected( pendingSelection->second.size() );
1757cdf0e10cSrcweir             ::std::copy( pendingSelection->second.begin(), pendingSelection->second.end(), aSelected.getArray() );
1758cdf0e10cSrcweir             getContainer()->selectElements( aSelected );
1759cdf0e10cSrcweir 
1760cdf0e10cSrcweir             m_aPendingSelection.erase( pendingSelection );
1761cdf0e10cSrcweir         }
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir 		InvalidateAll();
1764cdf0e10cSrcweir 	}
1765cdf0e10cSrcweir 	m_eCurrentType = _eType;
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir 	return sal_True;
1768cdf0e10cSrcweir }
1769cdf0e10cSrcweir // -----------------------------------------------------------------------------
1770cdf0e10cSrcweir bool OApplicationController::onEntryDoubleClick( SvTreeListBox& _rTree )
1771cdf0e10cSrcweir {
1772cdf0e10cSrcweir 	if ( getContainer() && getContainer()->isLeaf( _rTree.GetHdlEntry() ) )
1773cdf0e10cSrcweir 	{
1774cdf0e10cSrcweir 		try
1775cdf0e10cSrcweir 		{
1776cdf0e10cSrcweir 			openElement(
1777cdf0e10cSrcweir                 getContainer()->getQualifiedName( _rTree.GetHdlEntry() ),
1778cdf0e10cSrcweir                 getContainer()->getElementType(),
1779cdf0e10cSrcweir                 E_OPEN_NORMAL
1780cdf0e10cSrcweir             );
1781cdf0e10cSrcweir             return true;    // handled
1782cdf0e10cSrcweir 		}
1783cdf0e10cSrcweir 		catch(const Exception&)
1784cdf0e10cSrcweir 		{
1785cdf0e10cSrcweir 			DBG_UNHANDLED_EXCEPTION();
1786cdf0e10cSrcweir 		}
1787cdf0e10cSrcweir 	}
1788cdf0e10cSrcweir     return false;   // not handled
1789cdf0e10cSrcweir }
1790cdf0e10cSrcweir // -----------------------------------------------------------------------------
1791cdf0e10cSrcweir bool OApplicationController::impl_isAlterableView_nothrow( const ::rtl::OUString& _rTableOrViewName ) const
1792cdf0e10cSrcweir {
1793cdf0e10cSrcweir     OSL_PRECOND( m_xDataSourceConnection.is(), "OApplicationController::impl_isAlterableView_nothrow: no connection!" );
1794cdf0e10cSrcweir 
1795cdf0e10cSrcweir     bool bIsAlterableView( false );
1796cdf0e10cSrcweir     try
1797cdf0e10cSrcweir     {
1798cdf0e10cSrcweir         Reference< XViewsSupplier > xViewsSupp( m_xDataSourceConnection, UNO_QUERY );
1799cdf0e10cSrcweir         Reference< XNameAccess > xViews;
1800cdf0e10cSrcweir         if ( xViewsSupp.is() )
1801cdf0e10cSrcweir             xViews = xViewsSupp->getViews();
1802cdf0e10cSrcweir 
1803cdf0e10cSrcweir         Reference< XAlterView > xAsAlterableView;
1804cdf0e10cSrcweir         if ( xViews.is() && xViews->hasByName( _rTableOrViewName ) )
1805cdf0e10cSrcweir             xAsAlterableView.set( xViews->getByName( _rTableOrViewName ), UNO_QUERY );
1806cdf0e10cSrcweir 
1807cdf0e10cSrcweir         bIsAlterableView = xAsAlterableView.is();
1808cdf0e10cSrcweir     }
1809cdf0e10cSrcweir     catch( const Exception& )
1810cdf0e10cSrcweir     {
1811cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1812cdf0e10cSrcweir     }
1813cdf0e10cSrcweir     return bIsAlterableView;
1814cdf0e10cSrcweir }
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir // -----------------------------------------------------------------------------
1817cdf0e10cSrcweir Reference< XComponent > OApplicationController::openElement(const ::rtl::OUString& _sName, ElementType _eType,
1818cdf0e10cSrcweir     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand )
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir     return openElementWithArguments( _sName, _eType, _eOpenMode, _nInstigatorCommand, ::comphelper::NamedValueCollection() );
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir 
1823cdf0e10cSrcweir // -----------------------------------------------------------------------------
1824cdf0e10cSrcweir Reference< XComponent > OApplicationController::openElementWithArguments( const ::rtl::OUString& _sName, ElementType _eType,
1825cdf0e10cSrcweir     ElementOpenMode _eOpenMode, sal_uInt16 _nInstigatorCommand, const ::comphelper::NamedValueCollection& _rAdditionalArguments )
1826cdf0e10cSrcweir {
1827cdf0e10cSrcweir     OSL_PRECOND( getContainer(), "OApplicationController::openElementWithArguments: no view!" );
1828cdf0e10cSrcweir     if ( !getContainer() )
1829cdf0e10cSrcweir         return NULL;
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir 	Reference< XComponent > xRet;
1832cdf0e10cSrcweir 	if ( _eOpenMode == E_OPEN_DESIGN )
1833cdf0e10cSrcweir 	{
1834cdf0e10cSrcweir 		// OJ: http://www.openoffice.org/issues/show_bug.cgi?id=30382
1835cdf0e10cSrcweir 		getContainer()->showPreview(NULL);
1836cdf0e10cSrcweir 	}
1837cdf0e10cSrcweir 
1838cdf0e10cSrcweir     bool isStandaloneDocument = false;
1839cdf0e10cSrcweir     switch ( _eType )
1840cdf0e10cSrcweir 	{
1841cdf0e10cSrcweir 	case E_REPORT:
1842cdf0e10cSrcweir         if ( _eOpenMode != E_OPEN_DESIGN )
1843cdf0e10cSrcweir         {
1844cdf0e10cSrcweir             // reports which are opened in a mode other than design are no sub components of our application
1845cdf0e10cSrcweir             // component, but standalone documents.
1846cdf0e10cSrcweir             isStandaloneDocument = true;
1847cdf0e10cSrcweir         }
1848cdf0e10cSrcweir         // NO break!
1849cdf0e10cSrcweir 	case E_FORM:
1850cdf0e10cSrcweir 	{
1851cdf0e10cSrcweir         if ( isStandaloneDocument || !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1852cdf0e10cSrcweir         {
1853cdf0e10cSrcweir 		    ::std::auto_ptr< OLinkedDocumentsAccess > aHelper = getDocumentsAccess( _eType );
1854cdf0e10cSrcweir             if ( !aHelper->isConnected() )
1855cdf0e10cSrcweir                 break;
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir 		    Reference< XComponent > xDefinition;
1858cdf0e10cSrcweir 		    xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
1859cdf0e10cSrcweir 
1860cdf0e10cSrcweir             if ( !isStandaloneDocument )
1861cdf0e10cSrcweir 		        onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
1862cdf0e10cSrcweir         }
1863cdf0e10cSrcweir 	}
1864cdf0e10cSrcweir 	break;
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir 	case E_QUERY:
1867cdf0e10cSrcweir 	case E_TABLE:
1868cdf0e10cSrcweir 	{
1869cdf0e10cSrcweir         if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode, xRet ) )
1870cdf0e10cSrcweir         {
1871cdf0e10cSrcweir 		    SharedConnection xConnection( ensureConnection() );
1872cdf0e10cSrcweir 		    if ( !xConnection.is() )
1873cdf0e10cSrcweir                 break;
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir             ::std::auto_ptr< DatabaseObjectView > pDesigner;
1876cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArguments( _rAdditionalArguments );
1877cdf0e10cSrcweir 
1878cdf0e10cSrcweir             Any aDataSource;
1879cdf0e10cSrcweir 		    if ( _eOpenMode == E_OPEN_DESIGN )
1880cdf0e10cSrcweir 		    {
1881cdf0e10cSrcweir                 bool bAddViewTypeArg = false;
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir 			    if ( _eType == E_TABLE )
1884cdf0e10cSrcweir 			    {
1885cdf0e10cSrcweir                     if ( impl_isAlterableView_nothrow( _sName ) )
1886cdf0e10cSrcweir                     {
1887cdf0e10cSrcweir                         pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), true ) );
1888cdf0e10cSrcweir                         bAddViewTypeArg = true;
1889cdf0e10cSrcweir                     }
1890cdf0e10cSrcweir                     else
1891cdf0e10cSrcweir                     {
1892cdf0e10cSrcweir                         pDesigner.reset( new TableDesigner( getORB(), this, m_aCurrentFrame.getFrame() ) );
1893cdf0e10cSrcweir                     }
1894cdf0e10cSrcweir 			    }
1895cdf0e10cSrcweir 			    else if ( _eType == E_QUERY )
1896cdf0e10cSrcweir 			    {
1897cdf0e10cSrcweir                     pDesigner.reset( new QueryDesigner( getORB(), this, m_aCurrentFrame.getFrame(), false ) );
1898cdf0e10cSrcweir                     bAddViewTypeArg = true;
1899cdf0e10cSrcweir 			    }
1900cdf0e10cSrcweir 			    aDataSource <<= m_xDataSource;
1901cdf0e10cSrcweir 
1902cdf0e10cSrcweir                 if ( bAddViewTypeArg )
1903cdf0e10cSrcweir                 {
1904cdf0e10cSrcweir                     const bool bQueryGraphicalMode =( _nInstigatorCommand != SID_DB_APP_EDIT_SQL_VIEW );
1905cdf0e10cSrcweir                     aArguments.put( (::rtl::OUString)PROPERTY_GRAPHICAL_DESIGN, bQueryGraphicalMode );
1906cdf0e10cSrcweir                 }
1907cdf0e10cSrcweir 
1908cdf0e10cSrcweir 		    }
1909cdf0e10cSrcweir 		    else
1910cdf0e10cSrcweir 		    {
1911cdf0e10cSrcweir 			    pDesigner.reset( new ResultSetBrowser( getORB(), this, m_aCurrentFrame.getFrame(), _eType == E_TABLE ) );
1912cdf0e10cSrcweir 
1913cdf0e10cSrcweir                 if ( !aArguments.has( (::rtl::OUString)PROPERTY_SHOWMENU ) )
1914cdf0e10cSrcweir                     aArguments.put( (::rtl::OUString)PROPERTY_SHOWMENU, makeAny( (sal_Bool)sal_True ) );
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 		        aDataSource <<= getDatabaseName();
1917cdf0e10cSrcweir 		    }
1918cdf0e10cSrcweir 
1919cdf0e10cSrcweir 		    xRet.set( pDesigner->openExisting( aDataSource, _sName, aArguments ) );
1920cdf0e10cSrcweir 	        onDocumentOpened( _sName, _eType, _eOpenMode, xRet, NULL );
1921cdf0e10cSrcweir         }
1922cdf0e10cSrcweir 	}
1923cdf0e10cSrcweir 	break;
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir     default:
1926cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::openElement: illegal object type!" );
1927cdf0e10cSrcweir         break;
1928cdf0e10cSrcweir 	}
1929cdf0e10cSrcweir 	return xRet;
1930cdf0e10cSrcweir }
1931cdf0e10cSrcweir // -----------------------------------------------------------------------------
1932cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnSelectContainer, void*, _pType )
1933cdf0e10cSrcweir {
1934cdf0e10cSrcweir     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1935cdf0e10cSrcweir     getContainer()->selectContainer(eType);
1936cdf0e10cSrcweir     return 0L;
1937cdf0e10cSrcweir }
1938cdf0e10cSrcweir // -----------------------------------------------------------------------------
1939cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnCreateWithPilot, void*, _pType )
1940cdf0e10cSrcweir {
1941cdf0e10cSrcweir     ElementType eType = (ElementType)reinterpret_cast< sal_IntPtr >( _pType );
1942cdf0e10cSrcweir     newElementWithPilot( eType );
1943cdf0e10cSrcweir     return 0L;
1944cdf0e10cSrcweir }
1945cdf0e10cSrcweir 
1946cdf0e10cSrcweir // -----------------------------------------------------------------------------
1947cdf0e10cSrcweir void OApplicationController::newElementWithPilot( ElementType _eType )
1948cdf0e10cSrcweir {
1949cdf0e10cSrcweir     CloseVeto aKeepDoc( getFrame() );
1950cdf0e10cSrcweir         // prevent the document being closed while the wizard is open
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir     OSL_ENSURE( getContainer(), "OApplicationController::newElementWithPilot: without a view?" );
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir 	switch ( _eType )
1955cdf0e10cSrcweir 	{
1956cdf0e10cSrcweir 		case E_REPORT:
1957cdf0e10cSrcweir 		case E_FORM:
1958cdf0e10cSrcweir 		{
1959cdf0e10cSrcweir 			::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1960cdf0e10cSrcweir             if ( aHelper->isConnected() )
1961cdf0e10cSrcweir 			{
1962cdf0e10cSrcweir                 sal_Int32 nCommandType = -1;
1963cdf0e10cSrcweir                 const ::rtl::OUString sCurrentSelected( getCurrentlySelectedName( nCommandType ) );
1964cdf0e10cSrcweir 				if ( E_REPORT == _eType )
1965cdf0e10cSrcweir 					aHelper->newReportWithPilot( nCommandType, sCurrentSelected );
1966cdf0e10cSrcweir 				else
1967cdf0e10cSrcweir 					aHelper->newFormWithPilot( nCommandType, sCurrentSelected );
1968cdf0e10cSrcweir 			}
1969cdf0e10cSrcweir         }
1970cdf0e10cSrcweir         break;
1971cdf0e10cSrcweir         case E_QUERY:
1972cdf0e10cSrcweir         case E_TABLE:
1973cdf0e10cSrcweir  		{
1974cdf0e10cSrcweir 		    ::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
1975cdf0e10cSrcweir             if ( aHelper->isConnected() )
1976cdf0e10cSrcweir             {
1977cdf0e10cSrcweir 		        if ( E_QUERY == _eType )
1978cdf0e10cSrcweir 			        aHelper->newQueryWithPilot();
1979cdf0e10cSrcweir 		        else
1980cdf0e10cSrcweir 			        aHelper->newTableWithPilot();
1981cdf0e10cSrcweir 		    }
1982cdf0e10cSrcweir  		}
1983cdf0e10cSrcweir  		break;
1984cdf0e10cSrcweir         case E_NONE:
1985cdf0e10cSrcweir             break;
1986cdf0e10cSrcweir     }
1987cdf0e10cSrcweir 
1988cdf0e10cSrcweir     // no need for onDocumentOpened, the table wizard opens the created table by using
1989cdf0e10cSrcweir     // XDatabaseDocumentUI::loadComponent method.
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir // -----------------------------------------------------------------------------
1993cdf0e10cSrcweir Reference< XComponent > OApplicationController::newElement( ElementType _eType, const ::comphelper::NamedValueCollection& i_rAdditionalArguments,
1994cdf0e10cSrcweir                                                            Reference< XComponent >& o_rDocumentDefinition )
1995cdf0e10cSrcweir {
1996cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir     Reference< XComponent > xComponent;
1999cdf0e10cSrcweir     o_rDocumentDefinition.clear();
2000cdf0e10cSrcweir 
2001cdf0e10cSrcweir 	switch ( _eType )
2002cdf0e10cSrcweir 	{
2003cdf0e10cSrcweir         case E_FORM:
2004cdf0e10cSrcweir 		case E_REPORT:
2005cdf0e10cSrcweir 		{
2006cdf0e10cSrcweir 			::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess( _eType );
2007cdf0e10cSrcweir             if ( !aHelper->isConnected() )
2008cdf0e10cSrcweir                 break;
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir             xComponent = aHelper->newDocument( _eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT, i_rAdditionalArguments, o_rDocumentDefinition );
2011cdf0e10cSrcweir 		}
2012cdf0e10cSrcweir 		break;
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir 		case E_QUERY:
2015cdf0e10cSrcweir 		case E_TABLE:
2016cdf0e10cSrcweir 		{
2017cdf0e10cSrcweir 			::std::auto_ptr< DatabaseObjectView > pDesigner;
2018cdf0e10cSrcweir 			SharedConnection xConnection( ensureConnection() );
2019cdf0e10cSrcweir 			if ( !xConnection.is() )
2020cdf0e10cSrcweir                 break;
2021cdf0e10cSrcweir 
2022cdf0e10cSrcweir             if ( _eType == E_TABLE )
2023cdf0e10cSrcweir 			{
2024cdf0e10cSrcweir 				pDesigner.reset( new TableDesigner( getORB(), this, getFrame() ) );
2025cdf0e10cSrcweir 			}
2026cdf0e10cSrcweir 			else if ( _eType == E_QUERY )
2027cdf0e10cSrcweir 			{
2028cdf0e10cSrcweir 				pDesigner.reset( new QueryDesigner( getORB(), this, getFrame(), false ) );
2029cdf0e10cSrcweir 			}
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir             Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
2032cdf0e10cSrcweir 			xComponent.set( pDesigner->createNew( xDataSource, i_rAdditionalArguments ), UNO_QUERY );
2033cdf0e10cSrcweir 		}
2034cdf0e10cSrcweir 		break;
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir         default:
2037cdf0e10cSrcweir             OSL_ENSURE( false, "OApplicationController::newElement: illegal type!" );
2038cdf0e10cSrcweir             break;
2039cdf0e10cSrcweir 	}
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir     if ( xComponent.is() )
2042cdf0e10cSrcweir         onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, o_rDocumentDefinition );
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir     return xComponent;
2045cdf0e10cSrcweir }
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir // -----------------------------------------------------------------------------
2048cdf0e10cSrcweir void OApplicationController::addContainerListener(const Reference<XNameAccess>& _xCollection)
2049cdf0e10cSrcweir {
2050cdf0e10cSrcweir 	try
2051cdf0e10cSrcweir 	{
2052cdf0e10cSrcweir 		Reference< XContainer > xCont(_xCollection, UNO_QUERY);
2053cdf0e10cSrcweir 		if ( xCont.is() )
2054cdf0e10cSrcweir 		{
2055cdf0e10cSrcweir 			// add as listener to get notified if elements are inserted or removed
2056cdf0e10cSrcweir 			TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xCont);
2057cdf0e10cSrcweir 			if ( aFind == m_aCurrentContainers.end() )
2058cdf0e10cSrcweir 			{
2059cdf0e10cSrcweir 				xCont->addContainerListener(this);
2060cdf0e10cSrcweir 				m_aCurrentContainers.push_back(xCont);
2061cdf0e10cSrcweir 			}
2062cdf0e10cSrcweir 		}
2063cdf0e10cSrcweir 	}
2064cdf0e10cSrcweir 	catch( const Exception& )
2065cdf0e10cSrcweir 	{
2066cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2067cdf0e10cSrcweir 	}
2068cdf0e10cSrcweir }
2069cdf0e10cSrcweir // -----------------------------------------------------------------------------
2070cdf0e10cSrcweir void OApplicationController::renameEntry()
2071cdf0e10cSrcweir {
2072cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
2073cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2074cdf0e10cSrcweir 
2075cdf0e10cSrcweir 	OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
2076cdf0e10cSrcweir 	::std::vector< ::rtl::OUString> aList;
2077cdf0e10cSrcweir 	getSelectionElementNames(aList);
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 	Reference< XNameAccess > xContainer = getElements(getContainer()->getElementType());
2080cdf0e10cSrcweir 	OSL_ENSURE(aList.size() == 1,"Invalid rename call here. More than one element!");
2081cdf0e10cSrcweir     if ( aList.empty() )
2082cdf0e10cSrcweir         return;
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir 	try
2085cdf0e10cSrcweir 	{
2086cdf0e10cSrcweir 		if ( xContainer.is() )
2087cdf0e10cSrcweir 		{
2088cdf0e10cSrcweir             ::std::auto_ptr< IObjectNameCheck > pNameChecker;
2089cdf0e10cSrcweir             ::std::auto_ptr< OSaveAsDlg > aDialog;
2090cdf0e10cSrcweir 
2091cdf0e10cSrcweir 			Reference<XRename> xRename;
2092cdf0e10cSrcweir 			const ElementType eType = getContainer()->getElementType();
2093cdf0e10cSrcweir 			switch( eType )
2094cdf0e10cSrcweir 			{
2095cdf0e10cSrcweir 				case E_FORM:
2096cdf0e10cSrcweir 				case E_REPORT:
2097cdf0e10cSrcweir 					{
2098cdf0e10cSrcweir 						Reference<XHierarchicalNameContainer> xHNames(xContainer, UNO_QUERY);
2099cdf0e10cSrcweir 						if ( xHNames.is() )
2100cdf0e10cSrcweir 						{
2101cdf0e10cSrcweir 							String sLabel;
2102cdf0e10cSrcweir 							if ( eType == E_FORM )
2103cdf0e10cSrcweir 								sLabel = String(ModuleRes( STR_FRM_LABEL ));
2104cdf0e10cSrcweir 							else
2105cdf0e10cSrcweir 								sLabel = String(ModuleRes( STR_RPT_LABEL ));
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir 							::rtl::OUString sName = *aList.begin();
2108cdf0e10cSrcweir 							if ( xHNames->hasByHierarchicalName(sName) )
2109cdf0e10cSrcweir 							{
2110cdf0e10cSrcweir 								xRename.set(xHNames->getByHierarchicalName(sName),UNO_QUERY);
2111cdf0e10cSrcweir 								Reference<XChild> xChild(xRename,UNO_QUERY);
2112cdf0e10cSrcweir 								if ( xChild.is() )
2113cdf0e10cSrcweir 								{
2114cdf0e10cSrcweir 									Reference<XHierarchicalNameContainer> xParent(xChild->getParent(),UNO_QUERY);
2115cdf0e10cSrcweir 									if ( xParent.is() )
2116cdf0e10cSrcweir 									{
2117cdf0e10cSrcweir 										xHNames = xParent;
2118cdf0e10cSrcweir 										Reference<XPropertySet>(xRename,UNO_QUERY)->getPropertyValue(PROPERTY_NAME) >>= sName;
2119cdf0e10cSrcweir 									}
2120cdf0e10cSrcweir 								}
2121cdf0e10cSrcweir                                 pNameChecker.reset( new HierarchicalNameCheck( xHNames.get(), String() ) );
2122cdf0e10cSrcweir 								aDialog.reset( new OSaveAsDlg(
2123cdf0e10cSrcweir                                     getView(), getORB(), sName, sLabel, *pNameChecker, SAD_TITLE_RENAME ) );
2124cdf0e10cSrcweir 							}
2125cdf0e10cSrcweir 						}
2126cdf0e10cSrcweir 					}
2127cdf0e10cSrcweir 					break;
2128cdf0e10cSrcweir 				case E_TABLE:
2129cdf0e10cSrcweir                     ensureConnection();
2130cdf0e10cSrcweir                     if ( !getConnection().is() )
2131cdf0e10cSrcweir                         break;
2132cdf0e10cSrcweir                     // NO break
2133cdf0e10cSrcweir 				case E_QUERY:
2134cdf0e10cSrcweir 					if ( xContainer->hasByName(*aList.begin()) )
2135cdf0e10cSrcweir 					{
2136cdf0e10cSrcweir 						xRename.set(xContainer->getByName(*aList.begin()),UNO_QUERY);
2137cdf0e10cSrcweir                         sal_Int32 nCommandType = eType == E_QUERY ? CommandType::QUERY : CommandType::TABLE;
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir                         ensureConnection();
2140cdf0e10cSrcweir                         pNameChecker.reset( new DynamicTableOrQueryNameCheck( getConnection(), nCommandType ) );
2141cdf0e10cSrcweir 					    aDialog.reset( new OSaveAsDlg(
2142cdf0e10cSrcweir                             getView(), nCommandType, getORB(), getConnection(),
2143cdf0e10cSrcweir                                 *aList.begin(), *pNameChecker, SAD_TITLE_RENAME ) );
2144cdf0e10cSrcweir 					}
2145cdf0e10cSrcweir 					break;
2146cdf0e10cSrcweir                 default:
2147cdf0e10cSrcweir                     break;
2148cdf0e10cSrcweir 			}
2149cdf0e10cSrcweir 
2150cdf0e10cSrcweir 			if ( xRename.is() && aDialog.get() )
2151cdf0e10cSrcweir 			{
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir 				sal_Bool bTryAgain = sal_True;
2154cdf0e10cSrcweir 				while( bTryAgain )
2155cdf0e10cSrcweir 				{
2156cdf0e10cSrcweir 					if ( aDialog->Execute() == RET_OK )
2157cdf0e10cSrcweir 					{
2158cdf0e10cSrcweir 						try
2159cdf0e10cSrcweir 						{
2160cdf0e10cSrcweir 							::rtl::OUString sNewName;
2161cdf0e10cSrcweir 							if ( eType == E_TABLE )
2162cdf0e10cSrcweir 							{
2163cdf0e10cSrcweir 								::rtl::OUString sName = aDialog->getName();
2164cdf0e10cSrcweir 								::rtl::OUString sCatalog = aDialog->getCatalog();
2165cdf0e10cSrcweir 								::rtl::OUString sSchema	 = aDialog->getSchema();
2166cdf0e10cSrcweir 
2167cdf0e10cSrcweir 								sNewName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sName, sal_False, ::dbtools::eInDataManipulation );
2168cdf0e10cSrcweir 							}
2169cdf0e10cSrcweir 							else
2170cdf0e10cSrcweir 								sNewName = aDialog->getName();
2171cdf0e10cSrcweir 
2172cdf0e10cSrcweir 							::rtl::OUString sOldName = *aList.begin();
2173cdf0e10cSrcweir 							if ( eType == E_FORM || eType == E_REPORT )
2174cdf0e10cSrcweir 							{
2175cdf0e10cSrcweir 								Reference<XContent> xContent(xRename,UNO_QUERY);
2176cdf0e10cSrcweir 								if ( xContent.is() )
2177cdf0e10cSrcweir 								{
2178cdf0e10cSrcweir 									sOldName = xContent->getIdentifier()->getContentIdentifier();
2179cdf0e10cSrcweir 								}
2180cdf0e10cSrcweir 							}
2181cdf0e10cSrcweir 
2182cdf0e10cSrcweir 							xRename->rename(sNewName);
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir                             if ( eType == E_TABLE )
2185cdf0e10cSrcweir                             {
2186cdf0e10cSrcweir                                 Reference<XPropertySet> xProp(xRename,UNO_QUERY);
2187cdf0e10cSrcweir                                 sNewName = ::dbaui::composeTableName( m_xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false );
2188cdf0e10cSrcweir                             }
2189cdf0e10cSrcweir 							getContainer()->elementReplaced( eType , sOldName, sNewName );
2190cdf0e10cSrcweir 
2191cdf0e10cSrcweir 							bTryAgain = sal_False;
2192cdf0e10cSrcweir 						}
2193cdf0e10cSrcweir 						catch(const SQLException& )
2194cdf0e10cSrcweir                         {
2195cdf0e10cSrcweir                             showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir 						}
2198cdf0e10cSrcweir 						catch(const ElementExistException& e)
2199cdf0e10cSrcweir 						{
2200cdf0e10cSrcweir 							static ::rtl::OUString sStatus = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000"));
2201cdf0e10cSrcweir 							String sMsg = String( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
2202cdf0e10cSrcweir 							sMsg.SearchAndReplace('#',e.Message);
2203cdf0e10cSrcweir 							showError(SQLExceptionInfo(SQLException(sMsg, e.Context, sStatus, 0, Any())));
2204cdf0e10cSrcweir 						}
2205cdf0e10cSrcweir 						catch(const Exception& )
2206cdf0e10cSrcweir 						{
2207cdf0e10cSrcweir                             DBG_UNHANDLED_EXCEPTION();
2208cdf0e10cSrcweir 						}
2209cdf0e10cSrcweir 					}
2210cdf0e10cSrcweir 					else
2211cdf0e10cSrcweir 						bTryAgain = sal_False;
2212cdf0e10cSrcweir 				}
2213cdf0e10cSrcweir 			}
2214cdf0e10cSrcweir 		}
2215cdf0e10cSrcweir 	}
2216cdf0e10cSrcweir 	catch(const Exception& )
2217cdf0e10cSrcweir 	{
2218cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2219cdf0e10cSrcweir 	}
2220cdf0e10cSrcweir }
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir // -----------------------------------------------------------------------------
2223cdf0e10cSrcweir void OApplicationController::onSelectionChanged()
2224cdf0e10cSrcweir {
2225cdf0e10cSrcweir 	InvalidateAll();
2226cdf0e10cSrcweir 
2227cdf0e10cSrcweir     SelectionGuard aSelGuard( *m_pSelectionNotifier );
2228cdf0e10cSrcweir 
2229cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2230cdf0e10cSrcweir     if ( !pView )
2231cdf0e10cSrcweir         return;
2232cdf0e10cSrcweir 
2233cdf0e10cSrcweir     if ( pView->getSelectionCount() == 1 )
2234cdf0e10cSrcweir     {
2235cdf0e10cSrcweir         const ElementType eType = pView->getElementType();
2236cdf0e10cSrcweir   	    if ( pView->isALeafSelected() )
2237cdf0e10cSrcweir         {
2238cdf0e10cSrcweir             const ::rtl::OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
2239cdf0e10cSrcweir             showPreviewFor( eType, sName );
2240cdf0e10cSrcweir         }
2241cdf0e10cSrcweir     }
2242cdf0e10cSrcweir }
2243cdf0e10cSrcweir // -----------------------------------------------------------------------------
2244cdf0e10cSrcweir void OApplicationController::showPreviewFor(const ElementType _eType,const ::rtl::OUString& _sName)
2245cdf0e10cSrcweir {
2246cdf0e10cSrcweir     if ( m_ePreviewMode == E_PREVIEWNONE )
2247cdf0e10cSrcweir         return;
2248cdf0e10cSrcweir 
2249cdf0e10cSrcweir     OApplicationView* pView = getContainer();
2250cdf0e10cSrcweir     if ( !pView )
2251cdf0e10cSrcweir         return;
2252cdf0e10cSrcweir 
2253cdf0e10cSrcweir 	try
2254cdf0e10cSrcweir 	{
2255cdf0e10cSrcweir 		switch( _eType )
2256cdf0e10cSrcweir 		{
2257cdf0e10cSrcweir 			case E_FORM:
2258cdf0e10cSrcweir 			case E_REPORT:
2259cdf0e10cSrcweir             {
2260cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
2261cdf0e10cSrcweir                 Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
2262cdf0e10cSrcweir 	            pView->showPreview( xContent );
2263cdf0e10cSrcweir             }
2264cdf0e10cSrcweir 			break;
2265cdf0e10cSrcweir 
2266cdf0e10cSrcweir             case E_TABLE:
2267cdf0e10cSrcweir 			case E_QUERY:
2268cdf0e10cSrcweir                 {
2269cdf0e10cSrcweir                     SharedConnection xConnection( ensureConnection() );
2270cdf0e10cSrcweir 					if ( xConnection.is() )
2271cdf0e10cSrcweir 						pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
2272cdf0e10cSrcweir                 }
2273cdf0e10cSrcweir 				return;
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir             default:
2276cdf0e10cSrcweir                 OSL_ENSURE( false, "OApplicationController::showPreviewFor: unexpected element type!" );
2277cdf0e10cSrcweir                 break;
2278cdf0e10cSrcweir 		}
2279cdf0e10cSrcweir 	}
2280cdf0e10cSrcweir 	catch( const SQLException& )
2281cdf0e10cSrcweir 	{
2282cdf0e10cSrcweir         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
2283cdf0e10cSrcweir 	}
2284cdf0e10cSrcweir 	catch(const Exception& )
2285cdf0e10cSrcweir 	{
2286cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
2287cdf0e10cSrcweir 	}
2288cdf0e10cSrcweir }
2289cdf0e10cSrcweir 
2290cdf0e10cSrcweir //------------------------------------------------------------------------------
2291cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnClipboardChanged, void*, EMPTYARG )
2292cdf0e10cSrcweir {
2293cdf0e10cSrcweir 	return OnInvalidateClipboard( NULL );
2294cdf0e10cSrcweir }
2295cdf0e10cSrcweir //------------------------------------------------------------------------------
2296cdf0e10cSrcweir IMPL_LINK(OApplicationController, OnInvalidateClipboard, void*, EMPTYARG)
2297cdf0e10cSrcweir {
2298cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_CUT);
2299cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_COPY);
2300cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_PASTE);
2301cdf0e10cSrcweir 	InvalidateFeature(SID_DB_APP_PASTE_SPECIAL);
2302cdf0e10cSrcweir 	return 0L;
2303cdf0e10cSrcweir }
2304cdf0e10cSrcweir // -----------------------------------------------------------------------------
2305cdf0e10cSrcweir void OApplicationController::onCutEntry()
2306cdf0e10cSrcweir {
2307cdf0e10cSrcweir }
2308cdf0e10cSrcweir // -----------------------------------------------------------------------------
2309cdf0e10cSrcweir void OApplicationController::onCopyEntry()
2310cdf0e10cSrcweir {
2311cdf0e10cSrcweir 	Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
2312cdf0e10cSrcweir }
2313cdf0e10cSrcweir // -----------------------------------------------------------------------------
2314cdf0e10cSrcweir void OApplicationController::onPasteEntry()
2315cdf0e10cSrcweir {
2316cdf0e10cSrcweir 	Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
2317cdf0e10cSrcweir }
2318cdf0e10cSrcweir // -----------------------------------------------------------------------------
2319cdf0e10cSrcweir void OApplicationController::onDeleteEntry()
2320cdf0e10cSrcweir {
2321cdf0e10cSrcweir 	ElementType eType = getContainer()->getElementType();
2322cdf0e10cSrcweir 	sal_uInt16 nId = 0;
2323cdf0e10cSrcweir 	switch(eType)
2324cdf0e10cSrcweir 	{
2325cdf0e10cSrcweir 		case E_TABLE:
2326cdf0e10cSrcweir 			nId = SID_DB_APP_TABLE_DELETE;
2327cdf0e10cSrcweir 			break;
2328cdf0e10cSrcweir 		case E_QUERY:
2329cdf0e10cSrcweir 			nId = SID_DB_APP_QUERY_DELETE;
2330cdf0e10cSrcweir 			break;
2331cdf0e10cSrcweir 		case E_FORM:
2332cdf0e10cSrcweir 			nId = SID_DB_APP_FORM_DELETE;
2333cdf0e10cSrcweir 			break;
2334cdf0e10cSrcweir 		case E_REPORT:
2335cdf0e10cSrcweir 			nId = SID_DB_APP_REPORT_DELETE;
2336cdf0e10cSrcweir 			break;
2337cdf0e10cSrcweir 		default:
2338cdf0e10cSrcweir 			OSL_ENSURE(0,"Invalid ElementType!");
2339cdf0e10cSrcweir 			break;
2340cdf0e10cSrcweir 	}
2341cdf0e10cSrcweir 	executeChecked(nId,Sequence<PropertyValue>());
2342cdf0e10cSrcweir }
2343cdf0e10cSrcweir 
2344cdf0e10cSrcweir // -----------------------------------------------------------------------------
2345cdf0e10cSrcweir void OApplicationController::executeUnChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2346cdf0e10cSrcweir {
2347cdf0e10cSrcweir     OApplicationController_CBASE::executeUnChecked( _rCommand, aArgs );
2348cdf0e10cSrcweir }
2349cdf0e10cSrcweir 
2350cdf0e10cSrcweir // -----------------------------------------------------------------------------
2351cdf0e10cSrcweir void OApplicationController::executeChecked(const URL& _rCommand, const Sequence< PropertyValue>& aArgs)
2352cdf0e10cSrcweir {
2353cdf0e10cSrcweir     OApplicationController_CBASE::executeChecked( _rCommand, aArgs );
2354cdf0e10cSrcweir }
2355cdf0e10cSrcweir 
2356cdf0e10cSrcweir // -----------------------------------------------------------------------------
2357cdf0e10cSrcweir void OApplicationController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2358cdf0e10cSrcweir {
2359cdf0e10cSrcweir     OApplicationController_CBASE::executeUnChecked( _nCommandId, aArgs );
2360cdf0e10cSrcweir }
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir // -----------------------------------------------------------------------------
2363cdf0e10cSrcweir void OApplicationController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue>& aArgs)
2364cdf0e10cSrcweir {
2365cdf0e10cSrcweir     OApplicationController_CBASE::executeChecked( _nCommandId, aArgs );
2366cdf0e10cSrcweir }
2367cdf0e10cSrcweir 
2368cdf0e10cSrcweir // -----------------------------------------------------------------------------
2369cdf0e10cSrcweir sal_Bool OApplicationController::isCommandEnabled(sal_uInt16 _nCommandId) const
2370cdf0e10cSrcweir {
2371cdf0e10cSrcweir     return OApplicationController_CBASE::isCommandEnabled( _nCommandId );
2372cdf0e10cSrcweir }
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir // -----------------------------------------------------------------------------
2375cdf0e10cSrcweir sal_Bool OApplicationController::isCommandEnabled( const ::rtl::OUString& _rCompleteCommandURL ) const
2376cdf0e10cSrcweir {
2377cdf0e10cSrcweir     return OApplicationController_CBASE::isCommandEnabled( _rCompleteCommandURL );
2378cdf0e10cSrcweir }
2379cdf0e10cSrcweir 
2380cdf0e10cSrcweir // -----------------------------------------------------------------------------
2381cdf0e10cSrcweir sal_uInt16 OApplicationController::registerCommandURL( const ::rtl::OUString& _rCompleteCommandURL )
2382cdf0e10cSrcweir {
2383cdf0e10cSrcweir     return OApplicationController_CBASE::registerCommandURL( _rCompleteCommandURL );
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir // -----------------------------------------------------------------------------
2387cdf0e10cSrcweir void OApplicationController::notifyHiContrastChanged()
2388cdf0e10cSrcweir {
2389cdf0e10cSrcweir     OApplicationController_CBASE::notifyHiContrastChanged();
2390cdf0e10cSrcweir }
2391cdf0e10cSrcweir 
2392cdf0e10cSrcweir // -----------------------------------------------------------------------------
2393cdf0e10cSrcweir Reference< XController > OApplicationController::getXController() throw( RuntimeException )
2394cdf0e10cSrcweir {
2395cdf0e10cSrcweir     return OApplicationController_CBASE::getXController();
2396cdf0e10cSrcweir }
2397cdf0e10cSrcweir 
2398cdf0e10cSrcweir // -----------------------------------------------------------------------------
2399cdf0e10cSrcweir bool OApplicationController::interceptUserInput( const NotifyEvent& _rEvent )
2400cdf0e10cSrcweir {
2401cdf0e10cSrcweir     return OApplicationController_CBASE::interceptUserInput( _rEvent );
2402cdf0e10cSrcweir }
2403cdf0e10cSrcweir 
2404cdf0e10cSrcweir // -----------------------------------------------------------------------------
2405cdf0e10cSrcweir PopupMenu* OApplicationController::getContextMenu( Control& /*_rControl*/ ) const
2406cdf0e10cSrcweir {
2407cdf0e10cSrcweir     return new PopupMenu( ModuleRes( RID_MENU_APP_EDIT ) );
2408cdf0e10cSrcweir }
2409cdf0e10cSrcweir 
2410cdf0e10cSrcweir // -----------------------------------------------------------------------------
2411cdf0e10cSrcweir IController& OApplicationController::getCommandController()
2412cdf0e10cSrcweir {
2413cdf0e10cSrcweir     return *static_cast< IApplicationController* >( this );
2414cdf0e10cSrcweir }
2415cdf0e10cSrcweir 
2416cdf0e10cSrcweir // -----------------------------------------------------------------------------
2417cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* OApplicationController::getContextMenuInterceptors()
2418cdf0e10cSrcweir {
2419cdf0e10cSrcweir     return &m_aContextMenuInterceptors;
2420cdf0e10cSrcweir }
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir // -----------------------------------------------------------------------------
2423cdf0e10cSrcweir Any OApplicationController::getCurrentSelection( Control& _rControl ) const
2424cdf0e10cSrcweir {
2425cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aSelection;
2426cdf0e10cSrcweir 	getContainer()->describeCurrentSelectionForControl( _rControl, aSelection );
2427cdf0e10cSrcweir     return makeAny( aSelection );
2428cdf0e10cSrcweir }
2429cdf0e10cSrcweir 
2430cdf0e10cSrcweir // -----------------------------------------------------------------------------
2431cdf0e10cSrcweir sal_Bool OApplicationController::requestQuickHelp( const SvLBoxEntry* /*_pEntry*/, String& /*_rText*/ ) const
2432cdf0e10cSrcweir {
2433cdf0e10cSrcweir     return sal_False;
2434cdf0e10cSrcweir }
2435cdf0e10cSrcweir 
2436cdf0e10cSrcweir // -----------------------------------------------------------------------------
2437cdf0e10cSrcweir sal_Bool OApplicationController::requestDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
2438cdf0e10cSrcweir {
2439cdf0e10cSrcweir 	TransferableHelper* pTransfer = NULL;
2440cdf0e10cSrcweir 	if ( getContainer() && getContainer()->getSelectionCount() )
2441cdf0e10cSrcweir 	{
2442cdf0e10cSrcweir 		try
2443cdf0e10cSrcweir 		{
2444cdf0e10cSrcweir 			pTransfer = copyObject( );
2445cdf0e10cSrcweir 			Reference< XTransferable> xEnsureDelete = pTransfer;
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir 			if ( pTransfer && getContainer()->getDetailView() )
2448cdf0e10cSrcweir 			{
2449cdf0e10cSrcweir 				ElementType eType = getContainer()->getElementType();
2450cdf0e10cSrcweir 				pTransfer->StartDrag( getContainer()->getDetailView()->getTreeWindow(), ((eType == E_FORM || eType == E_REPORT) ? DND_ACTION_COPYMOVE : DND_ACTION_COPY) );
2451cdf0e10cSrcweir 			}
2452cdf0e10cSrcweir 		}
2453cdf0e10cSrcweir 		catch(const Exception& )
2454cdf0e10cSrcweir 		{
2455cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2456cdf0e10cSrcweir 		}
2457cdf0e10cSrcweir 	}
2458cdf0e10cSrcweir 
2459cdf0e10cSrcweir 	return NULL != pTransfer;
2460cdf0e10cSrcweir }
2461cdf0e10cSrcweir // -----------------------------------------------------------------------------
2462cdf0e10cSrcweir sal_Int8 OApplicationController::queryDrop( const AcceptDropEvent& _rEvt, const DataFlavorExVector& _rFlavors )
2463cdf0e10cSrcweir {
2464cdf0e10cSrcweir 	sal_Int8 nActionAskedFor = _rEvt.mnAction;
2465cdf0e10cSrcweir 	// check if we're a table or query container
2466cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2467cdf0e10cSrcweir 	if ( pView && !isDataSourceReadOnly() )
2468cdf0e10cSrcweir 	{
2469cdf0e10cSrcweir 		ElementType eType = pView->getElementType();
2470cdf0e10cSrcweir 		if ( eType != E_NONE && (eType != E_TABLE || !isConnectionReadOnly()) )
2471cdf0e10cSrcweir 		{
2472cdf0e10cSrcweir 			// check for the concrete type
2473cdf0e10cSrcweir 			if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),TAppSupportedSotFunctor(eType,sal_True)) != _rFlavors.end())
2474cdf0e10cSrcweir 				return DND_ACTION_COPY;
2475cdf0e10cSrcweir 			if ( eType == E_FORM || eType == E_REPORT )
2476cdf0e10cSrcweir 			{
2477cdf0e10cSrcweir 				sal_Int8 nAction = OComponentTransferable::canExtractComponentDescriptor(_rFlavors,eType == E_FORM) ? DND_ACTION_COPY : DND_ACTION_NONE;
2478cdf0e10cSrcweir 				if ( nAction != DND_ACTION_NONE )
2479cdf0e10cSrcweir 				{
2480cdf0e10cSrcweir 					SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2481cdf0e10cSrcweir 					::rtl::OUString sName;
2482cdf0e10cSrcweir 					if ( pHitEntry )
2483cdf0e10cSrcweir 					{
2484cdf0e10cSrcweir 						sName = pView->getQualifiedName( pHitEntry );
2485cdf0e10cSrcweir 						if ( sName.getLength() )
2486cdf0e10cSrcweir 						{
2487cdf0e10cSrcweir 							Reference< XHierarchicalNameAccess > xContainer(getElements(pView->getElementType()),UNO_QUERY);
2488cdf0e10cSrcweir 							if ( xContainer.is() && xContainer->hasByHierarchicalName(sName) )
2489cdf0e10cSrcweir 							{
2490cdf0e10cSrcweir 								Reference< XHierarchicalNameAccess > xHitObject(xContainer->getByHierarchicalName(sName),UNO_QUERY);
2491cdf0e10cSrcweir 								if ( xHitObject.is() )
2492cdf0e10cSrcweir 									nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2493cdf0e10cSrcweir 							}
2494cdf0e10cSrcweir 							else
2495cdf0e10cSrcweir 								nAction = DND_ACTION_NONE;
2496cdf0e10cSrcweir 						}
2497cdf0e10cSrcweir 					}
2498cdf0e10cSrcweir 					/*else
2499cdf0e10cSrcweir 						nAction = nActionAskedFor & DND_ACTION_COPYMOVE;
2500cdf0e10cSrcweir                     */
2501cdf0e10cSrcweir 				}
2502cdf0e10cSrcweir 				return nAction;
2503cdf0e10cSrcweir 			}
2504cdf0e10cSrcweir 		}
2505cdf0e10cSrcweir 	}
2506cdf0e10cSrcweir 
2507cdf0e10cSrcweir 	return DND_ACTION_NONE;
2508cdf0e10cSrcweir }
2509cdf0e10cSrcweir // -----------------------------------------------------------------------------
2510cdf0e10cSrcweir sal_Int8 OApplicationController::executeDrop( const ExecuteDropEvent& _rEvt )
2511cdf0e10cSrcweir {
2512cdf0e10cSrcweir 	OApplicationView* pView = getContainer();
2513cdf0e10cSrcweir 	if ( !pView || pView->getElementType() == E_NONE )
2514cdf0e10cSrcweir 	{
2515cdf0e10cSrcweir 		DBG_ERROR("OApplicationController::executeDrop: what the hell did queryDrop do?");
2516cdf0e10cSrcweir 			// queryDrop shoud not have allowed us to reach this situation ....
2517cdf0e10cSrcweir 		return DND_ACTION_NONE;
2518cdf0e10cSrcweir 	}
2519cdf0e10cSrcweir 
2520cdf0e10cSrcweir 	// a TransferableDataHelper for accessing the dropped data
2521cdf0e10cSrcweir 	TransferableDataHelper aDroppedData(_rEvt.maDropEvent.Transferable);
2522cdf0e10cSrcweir 
2523cdf0e10cSrcweir 
2524cdf0e10cSrcweir 	// reset the data of the previous async drop (if any)
2525cdf0e10cSrcweir 	if ( m_nAsyncDrop )
2526cdf0e10cSrcweir 		Application::RemoveUserEvent(m_nAsyncDrop);
2527cdf0e10cSrcweir 
2528cdf0e10cSrcweir 
2529cdf0e10cSrcweir 	m_nAsyncDrop = 0;
2530cdf0e10cSrcweir 	m_aAsyncDrop.aDroppedData.clear();
2531cdf0e10cSrcweir 	m_aAsyncDrop.nType			= pView->getElementType();
2532cdf0e10cSrcweir 	m_aAsyncDrop.nAction		= _rEvt.mnAction;
2533cdf0e10cSrcweir 	m_aAsyncDrop.bError			= sal_False;
2534cdf0e10cSrcweir 	m_aAsyncDrop.bHtml			= sal_False;
2535cdf0e10cSrcweir 	m_aAsyncDrop.aUrl			= ::rtl::OUString();
2536cdf0e10cSrcweir 
2537cdf0e10cSrcweir 
2538cdf0e10cSrcweir 	// loop through the available formats and see what we can do ...
2539cdf0e10cSrcweir 	// first we have to check if it is our own format, if not we have to copy the stream :-(
2540cdf0e10cSrcweir 	if ( ODataAccessObjectTransferable::canExtractObjectDescriptor(aDroppedData.GetDataFlavorExVector()) )
2541cdf0e10cSrcweir 	{
2542cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData	= ODataAccessObjectTransferable::extractObjectDescriptor(aDroppedData);
2543cdf0e10cSrcweir 
2544cdf0e10cSrcweir 		// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2545cdf0e10cSrcweir 		m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2546cdf0e10cSrcweir 		return DND_ACTION_COPY;
2547cdf0e10cSrcweir 	}
2548cdf0e10cSrcweir 	else if ( OComponentTransferable::canExtractComponentDescriptor(aDroppedData.GetDataFlavorExVector(),m_aAsyncDrop.nType == E_FORM) )
2549cdf0e10cSrcweir 	{
2550cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData = OComponentTransferable::extractComponentDescriptor(aDroppedData);
2551cdf0e10cSrcweir 		SvLBoxEntry* pHitEntry = pView->getEntry(_rEvt.maPosPixel);
2552cdf0e10cSrcweir 		if ( pHitEntry )
2553cdf0e10cSrcweir 			m_aAsyncDrop.aUrl = pView->getQualifiedName( pHitEntry );
2554cdf0e10cSrcweir 
2555cdf0e10cSrcweir 		sal_Int8 nAction = _rEvt.mnAction;
2556cdf0e10cSrcweir 		Reference<XContent> xContent;
2557cdf0e10cSrcweir 		m_aAsyncDrop.aDroppedData[daComponent] >>= xContent;
2558cdf0e10cSrcweir 		if ( xContent.is() )
2559cdf0e10cSrcweir 		{
2560cdf0e10cSrcweir 			::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
2561cdf0e10cSrcweir 			sal_Int32 nIndex = 0;
2562cdf0e10cSrcweir 			sName = sName.copy(sName.getToken(0,'/',nIndex).getLength() + 1);
2563cdf0e10cSrcweir 			if ( m_aAsyncDrop.aUrl.Len() >= sName.getLength() && 0 == sName.compareTo(m_aAsyncDrop.aUrl,sName.getLength()) )
2564cdf0e10cSrcweir 			{
2565cdf0e10cSrcweir 				m_aAsyncDrop.aDroppedData.clear();
2566cdf0e10cSrcweir 				return DND_ACTION_NONE;
2567cdf0e10cSrcweir 			}
2568cdf0e10cSrcweir 
2569cdf0e10cSrcweir 			// check if move is allowed, if another object with the same name exists only copy is allowed
2570cdf0e10cSrcweir 			Reference< XHierarchicalNameAccess > xContainer(getElements(m_aAsyncDrop.nType),UNO_QUERY);
2571cdf0e10cSrcweir 			Reference<XNameAccess> xNameAccess(xContainer,UNO_QUERY);
2572cdf0e10cSrcweir 
2573cdf0e10cSrcweir 			if ( m_aAsyncDrop.aUrl.Len() && xContainer.is() && xContainer->hasByHierarchicalName(m_aAsyncDrop.aUrl) )
2574cdf0e10cSrcweir 				xNameAccess.set(xContainer->getByHierarchicalName(m_aAsyncDrop.aUrl),UNO_QUERY);
2575cdf0e10cSrcweir 
2576cdf0e10cSrcweir 			if ( xNameAccess.is() )
2577cdf0e10cSrcweir 			{
2578cdf0e10cSrcweir 				Reference<XPropertySet> xProp(xContent,UNO_QUERY);
2579cdf0e10cSrcweir 				if ( xProp.is() )
2580cdf0e10cSrcweir 				{
2581cdf0e10cSrcweir 					xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
2582cdf0e10cSrcweir 					if ( xNameAccess.is() && xNameAccess->hasByName(sName) )
2583cdf0e10cSrcweir 						nAction &= ~DND_ACTION_MOVE;
2584cdf0e10cSrcweir 				}
2585cdf0e10cSrcweir 				else
2586cdf0e10cSrcweir 					nAction &= ~DND_ACTION_MOVE;
2587cdf0e10cSrcweir 			}
2588cdf0e10cSrcweir 		}
2589cdf0e10cSrcweir 		if ( nAction != DND_ACTION_NONE )
2590cdf0e10cSrcweir 		{
2591cdf0e10cSrcweir 			m_aAsyncDrop.nAction = nAction;
2592cdf0e10cSrcweir 			// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2593cdf0e10cSrcweir 			m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2594cdf0e10cSrcweir 		}
2595cdf0e10cSrcweir 		else
2596cdf0e10cSrcweir 			m_aAsyncDrop.aDroppedData.clear();
2597cdf0e10cSrcweir 		return nAction;
2598cdf0e10cSrcweir 	}
2599cdf0e10cSrcweir 	else
2600cdf0e10cSrcweir 	{
2601cdf0e10cSrcweir         SharedConnection xConnection( ensureConnection() );
2602cdf0e10cSrcweir         if ( xConnection.is() && m_aTableCopyHelper.copyTagTable( aDroppedData, m_aAsyncDrop, xConnection ) )
2603cdf0e10cSrcweir         {
2604cdf0e10cSrcweir 			// asyncron because we some dialogs and we aren't allowed to show them while in D&D
2605cdf0e10cSrcweir 			m_nAsyncDrop = Application::PostUserEvent(LINK(this, OApplicationController, OnAsyncDrop));
2606cdf0e10cSrcweir 			return DND_ACTION_COPY;
2607cdf0e10cSrcweir 		}
2608cdf0e10cSrcweir 	}
2609cdf0e10cSrcweir 
2610cdf0e10cSrcweir 	return DND_ACTION_NONE;
2611cdf0e10cSrcweir }
2612cdf0e10cSrcweir // -----------------------------------------------------------------------------
2613cdf0e10cSrcweir Reference< XModel >  SAL_CALL OApplicationController::getModel(void) throw( RuntimeException )
2614cdf0e10cSrcweir {
2615cdf0e10cSrcweir 	return m_xModel;
2616cdf0e10cSrcweir }
2617cdf0e10cSrcweir 
2618cdf0e10cSrcweir // -----------------------------------------------------------------------------
2619cdf0e10cSrcweir void OApplicationController::onAttachedFrame()
2620cdf0e10cSrcweir {
2621cdf0e10cSrcweir     sal_Int32 nConnectedControllers( 0 );
2622cdf0e10cSrcweir     try
2623cdf0e10cSrcweir     {
2624cdf0e10cSrcweir         Reference< XModel2 > xModel( m_xModel, UNO_QUERY_THROW );
2625cdf0e10cSrcweir         Reference< XEnumeration > xEnumControllers( xModel->getControllers(), UNO_SET_THROW );
2626cdf0e10cSrcweir         while ( xEnumControllers->hasMoreElements() )
2627cdf0e10cSrcweir         {
2628cdf0e10cSrcweir             Reference< XController > xController( xEnumControllers->nextElement(), UNO_QUERY_THROW );
2629cdf0e10cSrcweir             ++nConnectedControllers;
2630cdf0e10cSrcweir         }
2631cdf0e10cSrcweir     }
2632cdf0e10cSrcweir     catch( const Exception& )
2633cdf0e10cSrcweir     {
2634cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2635cdf0e10cSrcweir     }
2636cdf0e10cSrcweir 
2637cdf0e10cSrcweir     if ( nConnectedControllers > 1 )
2638cdf0e10cSrcweir     {   // we are not the first connected controller, there were already others
2639cdf0e10cSrcweir         return;
2640cdf0e10cSrcweir     }
2641cdf0e10cSrcweir 
2642cdf0e10cSrcweir     m_aControllerConnectedEvent.Call();
2643cdf0e10cSrcweir }
2644cdf0e10cSrcweir 
2645cdf0e10cSrcweir // -----------------------------------------------------------------------------
2646cdf0e10cSrcweir IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ )
2647cdf0e10cSrcweir {
2648cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2649cdf0e10cSrcweir 
2650cdf0e10cSrcweir     if ( !m_xModel.is() )
2651cdf0e10cSrcweir     {
2652cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::OnFirstControllerConnected: too late!" );
2653cdf0e10cSrcweir     }
2654cdf0e10cSrcweir 
2655cdf0e10cSrcweir     // if we have forms or reports which contain macros/scripts, then show a warning
2656cdf0e10cSrcweir     // which suggests the user to migrate them to the database document
2657cdf0e10cSrcweir     Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
2658cdf0e10cSrcweir     if ( xDocumentScripts.is() )
2659cdf0e10cSrcweir     {
2660cdf0e10cSrcweir         // no need to show this warning, obviously the document supports embedding scripts
2661cdf0e10cSrcweir         // into itself, so there are no "old-style" forms/reports which have macros/scripts
2662cdf0e10cSrcweir         // themselves
2663cdf0e10cSrcweir         return 0L;
2664cdf0e10cSrcweir     }
2665cdf0e10cSrcweir 
2666cdf0e10cSrcweir     try
2667cdf0e10cSrcweir     {
2668cdf0e10cSrcweir         // If the migration just happened, but was not successful, the document is reloaded.
2669cdf0e10cSrcweir         // In this case, we should not show the warning, again.
2670cdf0e10cSrcweir         ::comphelper::NamedValueCollection aModelArgs( m_xModel->getArgs() );
2671cdf0e10cSrcweir         if ( aModelArgs.getOrDefault( "SuppressMigrationWarning", sal_False ) )
2672cdf0e10cSrcweir             return 0L;
2673cdf0e10cSrcweir 
2674cdf0e10cSrcweir         // also, if the document is read-only, then no migration is possible, and the
2675cdf0e10cSrcweir         // respective menu entry is hidden. So, don't show the warning in this case, too.
2676cdf0e10cSrcweir         if ( Reference< XStorable >( m_xModel, UNO_QUERY_THROW )->isReadonly() )
2677cdf0e10cSrcweir             return 0L;
2678cdf0e10cSrcweir 
2679cdf0e10cSrcweir         SQLWarning aWarning;
2680cdf0e10cSrcweir         aWarning.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS ) );
2681cdf0e10cSrcweir         SQLException aDetail;
2682cdf0e10cSrcweir         aDetail.Message = String( ModuleRes( STR_SUB_DOCS_WITH_SCRIPTS_DETAIL ) );
2683cdf0e10cSrcweir         aWarning.NextException <<= aDetail;
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( getORB() );
2686cdf0e10cSrcweir         Sequence< Any > aArgs(1);
2687cdf0e10cSrcweir         aArgs[0] <<= NamedValue( PROPERTY_SQLEXCEPTION, makeAny( aWarning ) );
2688cdf0e10cSrcweir         Reference< XExecutableDialog > xDialog(
2689cdf0e10cSrcweir             aContext.createComponentWithArguments( "com.sun.star.sdb.ErrorMessageDialog", aArgs ),
2690cdf0e10cSrcweir             UNO_QUERY_THROW );
2691cdf0e10cSrcweir         xDialog->execute();
2692cdf0e10cSrcweir     }
2693cdf0e10cSrcweir     catch( const Exception& )
2694cdf0e10cSrcweir     {
2695cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2696cdf0e10cSrcweir     }
2697cdf0e10cSrcweir 
2698cdf0e10cSrcweir     return 1L;
2699cdf0e10cSrcweir }
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir // -----------------------------------------------------------------------------
2702cdf0e10cSrcweir void SAL_CALL OApplicationController::attachFrame( const Reference< XFrame > & i_rxFrame ) throw( RuntimeException )
2703cdf0e10cSrcweir {
2704cdf0e10cSrcweir     OApplicationController_CBASE::attachFrame( i_rxFrame );
2705cdf0e10cSrcweir     if ( getFrame().is() )
2706cdf0e10cSrcweir         onAttachedFrame();
2707cdf0e10cSrcweir }
2708cdf0e10cSrcweir 
2709cdf0e10cSrcweir // -----------------------------------------------------------------------------
2710cdf0e10cSrcweir sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException )
2711cdf0e10cSrcweir {
2712cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2713cdf0e10cSrcweir     const Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
2714cdf0e10cSrcweir     const Reference< XModifiable > xDocModify( _rxModel, UNO_QUERY );
2715cdf0e10cSrcweir     if ( ( !xOfficeDoc.is() || !xDocModify.is() ) && _rxModel.is() )
2716cdf0e10cSrcweir     {
2717cdf0e10cSrcweir         DBG_ERROR( "OApplicationController::attachModel: invalid model!" );
2718cdf0e10cSrcweir         return sal_False;
2719cdf0e10cSrcweir     }
2720cdf0e10cSrcweir 
2721cdf0e10cSrcweir     if ( m_xModel.is() && ( m_xModel != _rxModel ) && ( _rxModel.is() ) )
2722cdf0e10cSrcweir     {
2723cdf0e10cSrcweir         OSL_ENSURE( false, "OApplicationController::attachModel: missing implementation: setting a new model while we have another one!" );
2724cdf0e10cSrcweir         // we'd need to completely update our view here, close sub components, and the like
2725cdf0e10cSrcweir         return sal_False;
2726cdf0e10cSrcweir     }
2727cdf0e10cSrcweir 
2728cdf0e10cSrcweir     const ::rtl::OUString aPropertyNames[] =
2729cdf0e10cSrcweir     {
2730cdf0e10cSrcweir         PROPERTY_URL, PROPERTY_USER
2731cdf0e10cSrcweir     };
2732cdf0e10cSrcweir 
2733cdf0e10cSrcweir     // disconnect from old model
2734cdf0e10cSrcweir     try
2735cdf0e10cSrcweir     {
2736cdf0e10cSrcweir         if ( m_xDataSource.is() )
2737cdf0e10cSrcweir         {
2738cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2739cdf0e10cSrcweir             {
2740cdf0e10cSrcweir                 m_xDataSource->removePropertyChangeListener( aPropertyNames[i], this );
2741cdf0e10cSrcweir             }
2742cdf0e10cSrcweir         }
2743cdf0e10cSrcweir 
2744cdf0e10cSrcweir 		Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY );
2745cdf0e10cSrcweir         if ( xBroadcaster.is() )
2746cdf0e10cSrcweir 		    xBroadcaster->removeModifyListener( this );
2747cdf0e10cSrcweir     }
2748cdf0e10cSrcweir     catch( const Exception& )
2749cdf0e10cSrcweir     {
2750cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2751cdf0e10cSrcweir     }
2752cdf0e10cSrcweir 
2753cdf0e10cSrcweir     m_xModel = _rxModel;
2754cdf0e10cSrcweir     m_xDocumentModify = xDocModify;
2755cdf0e10cSrcweir     m_xDataSource.set( xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference< XDataSource >(), UNO_QUERY );
2756cdf0e10cSrcweir 
2757cdf0e10cSrcweir     // connect to new model
2758cdf0e10cSrcweir     try
2759cdf0e10cSrcweir     {
2760cdf0e10cSrcweir         if ( m_xDataSource.is() )
2761cdf0e10cSrcweir         {
2762cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
2763cdf0e10cSrcweir             {
2764cdf0e10cSrcweir                 m_xDataSource->addPropertyChangeListener( aPropertyNames[i], this );
2765cdf0e10cSrcweir             }
2766cdf0e10cSrcweir         }
2767cdf0e10cSrcweir 
2768cdf0e10cSrcweir 		Reference< XModifyBroadcaster >  xBroadcaster( m_xModel, UNO_QUERY_THROW );
2769cdf0e10cSrcweir 		xBroadcaster->addModifyListener( this );
2770cdf0e10cSrcweir 
2771cdf0e10cSrcweir     }
2772cdf0e10cSrcweir     catch( const Exception& )
2773cdf0e10cSrcweir     {
2774cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
2775cdf0e10cSrcweir     }
2776cdf0e10cSrcweir 
2777cdf0e10cSrcweir     // initial preview mode
2778cdf0e10cSrcweir 	if ( m_xDataSource.is() )
2779cdf0e10cSrcweir 	{
2780cdf0e10cSrcweir 		try
2781cdf0e10cSrcweir 		{
2782cdf0e10cSrcweir 			// to get the 'modified' for the data source
2783cdf0e10cSrcweir             ::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
2784cdf0e10cSrcweir             if ( aLayoutInfo.has( (rtl::OUString)INFO_PREVIEW ) )
2785cdf0e10cSrcweir             {
2786cdf0e10cSrcweir                 const sal_Int32 nPreviewMode( aLayoutInfo.getOrDefault( (rtl::OUString)INFO_PREVIEW, (sal_Int32)0 ) );
2787cdf0e10cSrcweir 				m_ePreviewMode = static_cast< PreviewMode >( nPreviewMode );
2788cdf0e10cSrcweir                 if ( getView() )
2789cdf0e10cSrcweir                     getContainer()->switchPreview( m_ePreviewMode );
2790cdf0e10cSrcweir 			}
2791cdf0e10cSrcweir 		}
2792cdf0e10cSrcweir 		catch( const Exception& )
2793cdf0e10cSrcweir 		{
2794cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2795cdf0e10cSrcweir 		}
2796cdf0e10cSrcweir 	}
2797cdf0e10cSrcweir 
2798cdf0e10cSrcweir 	return sal_True;
2799cdf0e10cSrcweir }
2800cdf0e10cSrcweir // -----------------------------------------------------------------------------
2801cdf0e10cSrcweir void OApplicationController::containerFound( const Reference< XContainer >& _xContainer)
2802cdf0e10cSrcweir {
2803cdf0e10cSrcweir 	try
2804cdf0e10cSrcweir 	{
2805cdf0e10cSrcweir 		if ( _xContainer.is() )
2806cdf0e10cSrcweir 		{
2807cdf0e10cSrcweir 			m_aCurrentContainers.push_back(_xContainer);
2808cdf0e10cSrcweir 			_xContainer->addContainerListener(this);
2809cdf0e10cSrcweir 		}
2810cdf0e10cSrcweir 	}
2811cdf0e10cSrcweir 	catch(const Exception&)
2812cdf0e10cSrcweir 	{
2813cdf0e10cSrcweir 		DBG_UNHANDLED_EXCEPTION();
2814cdf0e10cSrcweir 	}
2815cdf0e10cSrcweir }
2816cdf0e10cSrcweir // -----------------------------------------------------------------------------
2817cdf0e10cSrcweir ::rtl::OUString OApplicationController::getCurrentlySelectedName(sal_Int32& _rnCommandType) const
2818cdf0e10cSrcweir {
2819cdf0e10cSrcweir     _rnCommandType = ( (getContainer()->getElementType() == E_QUERY)
2820cdf0e10cSrcweir 								? CommandType::QUERY : ( (getContainer()->getElementType() == E_TABLE) ? CommandType::TABLE : -1 ));
2821cdf0e10cSrcweir 
2822cdf0e10cSrcweir 
2823cdf0e10cSrcweir 	::rtl::OUString sName;
2824cdf0e10cSrcweir 	if ( _rnCommandType != -1 )
2825cdf0e10cSrcweir 	{
2826cdf0e10cSrcweir 		try
2827cdf0e10cSrcweir 		{
2828cdf0e10cSrcweir 			sName = getContainer()->getQualifiedName( NULL );
2829cdf0e10cSrcweir             OSL_ENSURE( sName.getLength(), "OApplicationController::getCurrentlySelectedName: no name given!" );
2830cdf0e10cSrcweir 		}
2831cdf0e10cSrcweir 		catch( const Exception& )
2832cdf0e10cSrcweir 		{
2833cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
2834cdf0e10cSrcweir 		}
2835cdf0e10cSrcweir 	}
2836cdf0e10cSrcweir     return sName;
2837cdf0e10cSrcweir }
2838cdf0e10cSrcweir 
2839cdf0e10cSrcweir // -----------------------------------------------------------------------------
2840cdf0e10cSrcweir void SAL_CALL OApplicationController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2841cdf0e10cSrcweir {
2842cdf0e10cSrcweir     m_pSelectionNotifier->addListener( _Listener );
2843cdf0e10cSrcweir }
2844cdf0e10cSrcweir 
2845cdf0e10cSrcweir // -----------------------------------------------------------------------------
2846cdf0e10cSrcweir void SAL_CALL OApplicationController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& _Listener ) throw (RuntimeException)
2847cdf0e10cSrcweir {
2848cdf0e10cSrcweir     m_pSelectionNotifier->removeListener( _Listener );
2849cdf0e10cSrcweir }
2850cdf0e10cSrcweir 
2851cdf0e10cSrcweir // -----------------------------------------------------------------------------
2852cdf0e10cSrcweir ::sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException)
2853cdf0e10cSrcweir {
2854cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2855cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
2856cdf0e10cSrcweir     Sequence< ::rtl::OUString> aSelection;
2857cdf0e10cSrcweir     if ( !_aSelection.hasValue() || !getView() )
2858cdf0e10cSrcweir     {
2859cdf0e10cSrcweir         getContainer()->selectElements(aSelection);
2860cdf0e10cSrcweir         return sal_True;
2861cdf0e10cSrcweir     }
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir     // --------------------------------------------------------------
2864cdf0e10cSrcweir     // BEGIN compatibility
2865cdf0e10cSrcweir     Sequence< NamedValue > aCurrentSelection;
2866cdf0e10cSrcweir     if ( (_aSelection >>= aCurrentSelection) && aCurrentSelection.getLength() )
2867cdf0e10cSrcweir     {
2868cdf0e10cSrcweir         ElementType eType = E_NONE;
2869cdf0e10cSrcweir         const NamedValue* pIter = aCurrentSelection.getConstArray();
2870cdf0e10cSrcweir         const NamedValue* pEnd	= pIter + aCurrentSelection.getLength();
2871cdf0e10cSrcweir         for(;pIter != pEnd;++pIter)
2872cdf0e10cSrcweir         {
2873cdf0e10cSrcweir             if ( pIter->Name.equalsAscii("Type") )
2874cdf0e10cSrcweir             {
2875cdf0e10cSrcweir                 sal_Int32 nType = 0;
2876cdf0e10cSrcweir                 pIter->Value >>= nType;
2877cdf0e10cSrcweir                 if ( nType < DatabaseObject::TABLE || nType > DatabaseObject::REPORT )
2878cdf0e10cSrcweir                     throw IllegalArgumentException();
2879cdf0e10cSrcweir                 eType = static_cast< ElementType >( nType );
2880cdf0e10cSrcweir             }
2881cdf0e10cSrcweir             else if ( pIter->Name.equalsAscii("Selection") )
2882cdf0e10cSrcweir                 pIter->Value >>= aSelection;
2883cdf0e10cSrcweir         }
2884cdf0e10cSrcweir 
2885cdf0e10cSrcweir         m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
2886cdf0e10cSrcweir         getContainer()->selectContainer(eType);
2887cdf0e10cSrcweir         getContainer()->selectElements(aSelection);
2888cdf0e10cSrcweir         return sal_True;
2889cdf0e10cSrcweir     }
2890cdf0e10cSrcweir     // END compatibility
2891cdf0e10cSrcweir     // --------------------------------------------------------------
2892cdf0e10cSrcweir 
2893cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aSelectedObjects;
2894cdf0e10cSrcweir     if ( !( _aSelection >>= aSelectedObjects ) )
2895cdf0e10cSrcweir     {
2896cdf0e10cSrcweir         aSelectedObjects.realloc( 1 );
2897cdf0e10cSrcweir         if ( !( _aSelection >>= aSelectedObjects[0] ) )
2898cdf0e10cSrcweir             throw IllegalArgumentException();
2899cdf0e10cSrcweir     }
2900cdf0e10cSrcweir 
2901cdf0e10cSrcweir     SelectionByElementType aSelectedElements;
2902cdf0e10cSrcweir     ElementType eSelectedCategory = E_NONE;
2903cdf0e10cSrcweir     for (   const NamedDatabaseObject* pObject = aSelectedObjects.getConstArray();
2904cdf0e10cSrcweir             pObject != aSelectedObjects.getConstArray() + aSelectedObjects.getLength();
2905cdf0e10cSrcweir             ++pObject
2906cdf0e10cSrcweir         )
2907cdf0e10cSrcweir     {
2908cdf0e10cSrcweir         switch ( pObject->Type )
2909cdf0e10cSrcweir         {
2910cdf0e10cSrcweir             case DatabaseObject::TABLE:
2911cdf0e10cSrcweir             case DatabaseObjectContainer::SCHEMA:
2912cdf0e10cSrcweir             case DatabaseObjectContainer::CATALOG:
2913cdf0e10cSrcweir                 aSelectedElements[ E_TABLE ].push_back( pObject->Name );
2914cdf0e10cSrcweir                 break;
2915cdf0e10cSrcweir             case DatabaseObject::QUERY:
2916cdf0e10cSrcweir                 aSelectedElements[ E_QUERY ].push_back( pObject->Name );
2917cdf0e10cSrcweir                 break;
2918cdf0e10cSrcweir             case DatabaseObject::FORM:
2919cdf0e10cSrcweir             case DatabaseObjectContainer::FORMS_FOLDER:
2920cdf0e10cSrcweir                 aSelectedElements[ E_FORM ].push_back( pObject->Name );
2921cdf0e10cSrcweir                 break;
2922cdf0e10cSrcweir             case DatabaseObject::REPORT:
2923cdf0e10cSrcweir             case DatabaseObjectContainer::REPORTS_FOLDER:
2924cdf0e10cSrcweir                 aSelectedElements[ E_REPORT ].push_back( pObject->Name );
2925cdf0e10cSrcweir                 break;
2926cdf0e10cSrcweir             case DatabaseObjectContainer::TABLES:
2927cdf0e10cSrcweir             case DatabaseObjectContainer::QUERIES:
2928cdf0e10cSrcweir             case DatabaseObjectContainer::FORMS:
2929cdf0e10cSrcweir             case DatabaseObjectContainer::REPORTS:
2930cdf0e10cSrcweir                 if ( eSelectedCategory != E_NONE )
2931cdf0e10cSrcweir                     throw IllegalArgumentException(
2932cdf0e10cSrcweir                         String(ModuleRes(RID_STR_NO_DIFF_CAT)),
2933cdf0e10cSrcweir                         *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ) );
2934cdf0e10cSrcweir                 eSelectedCategory =
2935cdf0e10cSrcweir                         ( pObject->Type == DatabaseObjectContainer::TABLES )  ? E_TABLE
2936cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::QUERIES ) ? E_QUERY
2937cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::FORMS )   ? E_FORM
2938cdf0e10cSrcweir                     :   ( pObject->Type == DatabaseObjectContainer::REPORTS ) ? E_REPORT
2939cdf0e10cSrcweir                     :   E_NONE;
2940cdf0e10cSrcweir                 break;
2941cdf0e10cSrcweir 
2942cdf0e10cSrcweir             default:
2943cdf0e10cSrcweir             case DatabaseObjectContainer::DATA_SOURCE:
2944cdf0e10cSrcweir             {
2945cdf0e10cSrcweir                 ::rtl::OUString sMessage = String(ModuleRes( RID_STR_UNSUPPORTED_OBJECT_TYPE ));
2946cdf0e10cSrcweir                 ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$type$", ::rtl::OUString::valueOf(sal_Int32( pObject->Type )) );
2947cdf0e10cSrcweir                 throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() ));
2948cdf0e10cSrcweir             }
2949cdf0e10cSrcweir         }
2950cdf0e10cSrcweir     }
2951cdf0e10cSrcweir 
2952cdf0e10cSrcweir     for (   SelectionByElementType::const_iterator sel = aSelectedElements.begin();
2953cdf0e10cSrcweir             sel != aSelectedElements.end();
2954cdf0e10cSrcweir             ++sel
2955cdf0e10cSrcweir         )
2956cdf0e10cSrcweir     {
2957cdf0e10cSrcweir         if ( sel->first == m_eCurrentType )
2958cdf0e10cSrcweir         {
2959cdf0e10cSrcweir             Sequence< ::rtl::OUString > aSelected( sel->second.size() );
2960cdf0e10cSrcweir             ::std::copy( sel->second.begin(), sel->second.end(), aSelected.getArray() );
2961cdf0e10cSrcweir             getContainer()->selectElements( aSelected );
2962cdf0e10cSrcweir         }
2963cdf0e10cSrcweir         else
2964cdf0e10cSrcweir         {
2965cdf0e10cSrcweir             m_aPendingSelection[ sel->first ] = sel->second;
2966cdf0e10cSrcweir         }
2967cdf0e10cSrcweir     }
2968cdf0e10cSrcweir 
2969cdf0e10cSrcweir     m_aSelectContainerEvent.CancelCall();   // just in case the async select request was running
2970cdf0e10cSrcweir     getContainer()->selectContainer( eSelectedCategory );
2971cdf0e10cSrcweir 
2972cdf0e10cSrcweir     return sal_True;
2973cdf0e10cSrcweir }
2974cdf0e10cSrcweir // -----------------------------------------------------------------------------
2975cdf0e10cSrcweir Any SAL_CALL OApplicationController::getSelection(  ) throw (RuntimeException)
2976cdf0e10cSrcweir {
2977cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
2978cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
2979cdf0e10cSrcweir 
2980cdf0e10cSrcweir     Sequence< NamedDatabaseObject > aCurrentSelection;
2981cdf0e10cSrcweir     const ElementType eType( getContainer()->getElementType() );
2982cdf0e10cSrcweir     if ( eType != E_NONE )
2983cdf0e10cSrcweir     {
2984cdf0e10cSrcweir         getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
2985cdf0e10cSrcweir         if ( aCurrentSelection.getLength() == 0 )
2986cdf0e10cSrcweir         {   // if no objects are selected, add an entry to the sequence which describes the overall category
2987cdf0e10cSrcweir             // which is selected currently
2988cdf0e10cSrcweir             aCurrentSelection.realloc(1);
2989cdf0e10cSrcweir             aCurrentSelection[0].Name = getDatabaseName();
2990cdf0e10cSrcweir             switch ( eType )
2991cdf0e10cSrcweir             {
2992cdf0e10cSrcweir             case E_TABLE:   aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES;   break;
2993cdf0e10cSrcweir             case E_QUERY:   aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES;  break;
2994cdf0e10cSrcweir             case E_FORM:    aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS;    break;
2995cdf0e10cSrcweir             case E_REPORT:  aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS;  break;
2996cdf0e10cSrcweir             default:
2997cdf0e10cSrcweir                 OSL_ENSURE( false, "OApplicationController::getSelection: unexpected current element type!" );
2998cdf0e10cSrcweir                 break;
2999cdf0e10cSrcweir             }
3000cdf0e10cSrcweir         }
3001cdf0e10cSrcweir     }
3002cdf0e10cSrcweir     return makeAny( aCurrentSelection );
3003cdf0e10cSrcweir }
3004cdf0e10cSrcweir // -----------------------------------------------------------------------------
3005cdf0e10cSrcweir void OApplicationController::impl_migrateScripts_nothrow()
3006cdf0e10cSrcweir {
3007cdf0e10cSrcweir     try
3008cdf0e10cSrcweir     {
3009cdf0e10cSrcweir         ::rtl::OUString sDialogService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
3010cdf0e10cSrcweir         ::comphelper::ComponentContext aContext( getORB() );
3011cdf0e10cSrcweir         Sequence< Any > aDialogArgs(1);
3012cdf0e10cSrcweir         aDialogArgs[0] <<= Reference< XOfficeDatabaseDocument >( m_xModel, UNO_QUERY_THROW );
3013cdf0e10cSrcweir         Reference< XExecutableDialog > xDialog(
3014cdf0e10cSrcweir             aContext.createComponentWithArguments( sDialogService, aDialogArgs ),
3015cdf0e10cSrcweir             UNO_QUERY );
3016cdf0e10cSrcweir 
3017cdf0e10cSrcweir         if ( !xDialog.is() )
3018cdf0e10cSrcweir         {
3019cdf0e10cSrcweir             ShowServiceNotAvailableError( getView(), sDialogService, true );
3020cdf0e10cSrcweir             return;
3021cdf0e10cSrcweir         }
3022cdf0e10cSrcweir 
3023cdf0e10cSrcweir         xDialog->execute();
3024cdf0e10cSrcweir     }
3025cdf0e10cSrcweir     catch( const Exception& )
3026cdf0e10cSrcweir     {
3027cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
3028cdf0e10cSrcweir     }
3029cdf0e10cSrcweir }
3030cdf0e10cSrcweir 
3031cdf0e10cSrcweir //........................................................................
3032cdf0e10cSrcweir }	// namespace dbaui
3033cdf0e10cSrcweir //........................................................................
3034cdf0e10cSrcweir 
3035