xref: /AOO41X/main/extensions/source/bibliography/framectr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
31*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
33*cdf0e10cSrcweir #include <osl/mutex.hxx>
34*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
35*cdf0e10cSrcweir #include <tools/debug.hxx>
36*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
37*cdf0e10cSrcweir #include <comphelper/types.hxx>
38*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
39*cdf0e10cSrcweir #include "framectr.hxx"
40*cdf0e10cSrcweir #include "datman.hxx"
41*cdf0e10cSrcweir #include "bibresid.hxx"
42*cdf0e10cSrcweir #include "bib.hrc"
43*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
44*cdf0e10cSrcweir #include "bibconfig.hxx"
45*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> // helper for implementations
46*cdf0e10cSrcweir #include <vcl/svapp.hxx>
47*cdf0e10cSrcweir #include "bibliography.hrc"
48*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
49*cdf0e10cSrcweir #include <com/sun/star/form/XConfirmDeleteListener.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/sdb/RowChangeAction.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/frame/CommandGroup.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
59*cdf0e10cSrcweir #include <sot/exchange.hxx>
60*cdf0e10cSrcweir #include <sot/formats.hxx>
61*cdf0e10cSrcweir #include <vcl/edit.hxx>
62*cdf0e10cSrcweir #include <vos/mutex.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <hash_map>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir using namespace osl;
67*cdf0e10cSrcweir using namespace cppu;
68*cdf0e10cSrcweir using namespace rtl;
69*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
70*cdf0e10cSrcweir using namespace com::sun::star::frame;
71*cdf0e10cSrcweir using namespace com::sun::star::uno;
72*cdf0e10cSrcweir using namespace com::sun::star;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir struct DispatchInfo
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     const char*   pCommand;
79*cdf0e10cSrcweir     sal_Int16     nGroupId;
80*cdf0e10cSrcweir     sal_Bool      bActiveConnection;
81*cdf0e10cSrcweir };
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir struct CacheDispatchInfo
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     sal_Int16     nGroupId;
86*cdf0e10cSrcweir     sal_Bool      bActiveConnection;
87*cdf0e10cSrcweir };
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir // Attention: commands must be sorted by command groups. Implementation is dependent
90*cdf0e10cSrcweir // on this!!
91*cdf0e10cSrcweir static DispatchInfo SupportedCommandsArray[] =
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir     { ".uno:Undo"               ,   frame::CommandGroup::EDIT       , sal_False },
94*cdf0e10cSrcweir     { ".uno:Cut"                ,   frame::CommandGroup::EDIT       , sal_False },
95*cdf0e10cSrcweir     { ".uno:Copy"               ,   frame::CommandGroup::EDIT       , sal_False },
96*cdf0e10cSrcweir     { ".uno:Paste"              ,   frame::CommandGroup::EDIT       , sal_False },
97*cdf0e10cSrcweir     { ".uno:SelectAll"          ,   frame::CommandGroup::EDIT       , sal_False },
98*cdf0e10cSrcweir     { ".uno:CloseDoc"           ,   frame::CommandGroup::DOCUMENT   , sal_False },
99*cdf0e10cSrcweir     { ".uno:StatusBarVisible"   ,   frame::CommandGroup::VIEW       , sal_False },
100*cdf0e10cSrcweir     { ".uno:AvailableToolbars"  ,   frame::CommandGroup::VIEW       , sal_False },
101*cdf0e10cSrcweir     { ".uno:Bib/standardFilter" ,   frame::CommandGroup::DATA       , sal_True  },
102*cdf0e10cSrcweir     { ".uno:Bib/DeleteRecord"   ,   frame::CommandGroup::DATA       , sal_True  },
103*cdf0e10cSrcweir     { ".uno:Bib/InsertRecord"   ,   frame::CommandGroup::DATA       , sal_True  },
104*cdf0e10cSrcweir     { ".uno:Bib/query"          ,   frame::CommandGroup::DATA       , sal_True  },
105*cdf0e10cSrcweir     { ".uno:Bib/autoFilter"     ,   frame::CommandGroup::DATA       , sal_True  },
106*cdf0e10cSrcweir     { ".uno:Bib/source"         ,   frame::CommandGroup::DATA       , sal_True  },
107*cdf0e10cSrcweir     { ".uno:Bib/removeFilter"   ,   frame::CommandGroup::DATA       , sal_True  },
108*cdf0e10cSrcweir     { ".uno:Bib/sdbsource"      ,   frame::CommandGroup::DATA       , sal_True  },
109*cdf0e10cSrcweir     { ".uno:Bib/Mapping"        ,   frame::CommandGroup::DATA       , sal_True  },
110*cdf0e10cSrcweir     { 0                         ,   0                               , sal_False }
111*cdf0e10cSrcweir };
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString, CacheDispatchInfo, rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CmdToInfoCache;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir SV_IMPL_PTRARR( BibStatusDispatchArr, BibStatusDispatchPtr );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir const CmdToInfoCache& GetCommandToInfoCache()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     static sal_Bool       bCacheInitialized = sal_False;
120*cdf0e10cSrcweir     static CmdToInfoCache aCmdToInfoCache;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     if ( !bCacheInitialized )
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
125*cdf0e10cSrcweir         if ( !bCacheInitialized )
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             sal_Int32 i( 0 );
128*cdf0e10cSrcweir             while ( SupportedCommandsArray[i].pCommand != 0 )
129*cdf0e10cSrcweir             {
130*cdf0e10cSrcweir                 rtl::OUString aCommand( rtl::OUString::createFromAscii( SupportedCommandsArray[i].pCommand ));
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir                 CacheDispatchInfo aDispatchInfo;
133*cdf0e10cSrcweir                 aDispatchInfo.nGroupId          = SupportedCommandsArray[i].nGroupId;
134*cdf0e10cSrcweir                 aDispatchInfo.bActiveConnection = SupportedCommandsArray[i].bActiveConnection;
135*cdf0e10cSrcweir                 aCmdToInfoCache.insert( CmdToInfoCache::value_type( aCommand, aDispatchInfo ));
136*cdf0e10cSrcweir                 ++i;
137*cdf0e10cSrcweir             }
138*cdf0e10cSrcweir             bCacheInitialized = sal_True;
139*cdf0e10cSrcweir         }
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     return aCmdToInfoCache;
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir class BibFrameCtrl_Impl : public cppu::WeakImplHelper1 < XFrameActionListener >
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir public:
149*cdf0e10cSrcweir 	Mutex								aMutex;
150*cdf0e10cSrcweir 	OMultiTypeInterfaceContainerHelper	aLC;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	BibFrameController_Impl*			pController;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 										BibFrameCtrl_Impl()
155*cdf0e10cSrcweir 											: aLC( aMutex )
156*cdf0e10cSrcweir 											, pController(0)
157*cdf0e10cSrcweir 										{}
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 										~BibFrameCtrl_Impl();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	virtual void						SAL_CALL frameAction(const FrameActionEvent& aEvent) throw( RuntimeException );
162*cdf0e10cSrcweir 	virtual void						SAL_CALL disposing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
163*cdf0e10cSrcweir };
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir BibFrameCtrl_Impl::~BibFrameCtrl_Impl()
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir void BibFrameCtrl_Impl::frameAction(const FrameActionEvent& aEvent) throw( uno::RuntimeException )
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	if ( pController && aEvent.Frame == pController->getFrame())
173*cdf0e10cSrcweir 	{
174*cdf0e10cSrcweir 		if(aEvent.Action == FrameAction_FRAME_ACTIVATED)
175*cdf0e10cSrcweir 		{
176*cdf0e10cSrcweir 			pController->activate();
177*cdf0e10cSrcweir 		}
178*cdf0e10cSrcweir 		else if(aEvent.Action == FrameAction_FRAME_DEACTIVATING)
179*cdf0e10cSrcweir 		{
180*cdf0e10cSrcweir 			pController->deactivate();
181*cdf0e10cSrcweir 		}
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir void BibFrameCtrl_Impl::disposing( const lang::EventObject& /*Source*/ )
186*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
189*cdf0e10cSrcweir     if ( pController )
190*cdf0e10cSrcweir 		pController->getFrame()->removeFrameActionListener( this );
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWindow > & xComponent,
194*cdf0e10cSrcweir 												BibDataManager* pDataManager)
195*cdf0e10cSrcweir 	:xWindow( xComponent )
196*cdf0e10cSrcweir 	,m_xDatMan( pDataManager )
197*cdf0e10cSrcweir 	,pDatMan( pDataManager )
198*cdf0e10cSrcweir 	,pBibMod(NULL)
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	Window* pParent = VCLUnoHelper::GetWindow( xWindow );
201*cdf0e10cSrcweir 	pParent->SetUniqueId(UID_BIB_FRAME_WINDOW);
202*cdf0e10cSrcweir 	bDisposing=sal_False;
203*cdf0e10cSrcweir 	bHierarchical=sal_True;
204*cdf0e10cSrcweir 	pImp = new BibFrameCtrl_Impl;
205*cdf0e10cSrcweir 	pImp->pController = this;
206*cdf0e10cSrcweir 	pImp->acquire();
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir BibFrameController_Impl::~BibFrameController_Impl()
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir 	pImp->pController = NULL;
212*cdf0e10cSrcweir 	pImp->release();
213*cdf0e10cSrcweir 	delete pDatMan;
214*cdf0e10cSrcweir 	if(pBibMod)
215*cdf0e10cSrcweir 		CloseBibModul(pBibMod);
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir ::rtl::OUString SAL_CALL BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException)
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.comp.extensions.Bibliography");
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir sal_Bool SAL_CALL BibFrameController_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (::com::sun::star::uno::RuntimeException)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     return (
226*cdf0e10cSrcweir             sServiceName.equalsAscii("com.sun.star.frame.Bibliography") ||
227*cdf0e10cSrcweir             sServiceName.equalsAscii("com.sun.star.frame.Controller")
228*cdf0e10cSrcweir            );
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException)
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir     // return only top level services ...
234*cdf0e10cSrcweir     // base services are included there and should be asked by uno-rtti.
235*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString > lNames(1);
236*cdf0e10cSrcweir     lNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.Bibliography");
237*cdf0e10cSrcweir     return lNames;
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg ) throw (::com::sun::star::uno::RuntimeException)
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir 	xFrame = xArg;
243*cdf0e10cSrcweir 	xFrame->addFrameActionListener( pImp );
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException)
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir 	return sal_False;
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir sal_Bool BibFrameController_Impl::suspend( sal_Bool bSuspend ) throw (::com::sun::star::uno::RuntimeException)
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir 	if ( bSuspend )
254*cdf0e10cSrcweir 		getFrame()->removeFrameActionListener( pImp );
255*cdf0e10cSrcweir 	else
256*cdf0e10cSrcweir 		getFrame()->addFrameActionListener( pImp );
257*cdf0e10cSrcweir 	return sal_True;
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir uno::Any BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException)
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	return uno::Any();
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir void BibFrameController_Impl::restoreViewData( const uno::Any& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException)
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir uno::Reference< XFrame >  BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException)
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	return xFrame;
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir uno::Reference< XModel >  BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	return uno::Reference< XModel > ();
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException)
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	bDisposing = sal_True;
282*cdf0e10cSrcweir 	lang::EventObject aObject;
283*cdf0e10cSrcweir 	aObject.Source = (XController*)this;
284*cdf0e10cSrcweir 	pImp->aLC.disposeAndClear(aObject);
285*cdf0e10cSrcweir 	m_xDatMan = 0;
286*cdf0e10cSrcweir 	pDatMan = 0;
287*cdf0e10cSrcweir 	aStatusListeners.DeleteAndDestroy( 0, aStatusListeners.Count() );
288*cdf0e10cSrcweir  }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	pImp->aLC.addInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir 	pImp->aLC.removeInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir uno::Reference< frame::XDispatch >	BibFrameController_Impl::queryDispatch( const util::URL& aURL, const rtl::OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ ) throw (::com::sun::star::uno::RuntimeException)
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir     if ( !bDisposing )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir         const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
305*cdf0e10cSrcweir         CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
306*cdf0e10cSrcweir         if ( pIter != rCmdCache.end() )
307*cdf0e10cSrcweir         {
308*cdf0e10cSrcweir             if (( pDatMan->HasActiveConnection() ) ||
309*cdf0e10cSrcweir                 ( !pIter->second.bActiveConnection ))
310*cdf0e10cSrcweir                 return (frame::XDispatch*) this;
311*cdf0e10cSrcweir         }
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	return uno::Reference< frame::XDispatch > ();
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts ) throw (::com::sun::star::uno::RuntimeException)
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir 	uno::Sequence< uno::Reference< XDispatch > > aDispatches( aDescripts.getLength() );
320*cdf0e10cSrcweir     for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i )
321*cdf0e10cSrcweir         aDispatches[i] = queryDispatch( aDescripts[i].FeatureURL, aDescripts[i].FrameName, aDescripts[i].SearchFlags );
322*cdf0e10cSrcweir     return aDispatches;
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups()
326*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     uno::Sequence< ::sal_Int16 > aDispatchInfo( 4 );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     aDispatchInfo[0] = frame::CommandGroup::EDIT;
331*cdf0e10cSrcweir     aDispatchInfo[1] = frame::CommandGroup::DOCUMENT;
332*cdf0e10cSrcweir     aDispatchInfo[2] = frame::CommandGroup::DATA;
333*cdf0e10cSrcweir     aDispatchInfo[3] = frame::CommandGroup::VIEW;
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     return aDispatchInfo;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup )
339*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     sal_Bool                                    bGroupFound( sal_False );
344*cdf0e10cSrcweir     frame::DispatchInformation                  aDispatchInfo;
345*cdf0e10cSrcweir     std::list< frame::DispatchInformation >     aDispatchInfoList;
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir     if (( nCommandGroup == frame::CommandGroup::EDIT ) ||
348*cdf0e10cSrcweir         ( nCommandGroup == frame::CommandGroup::DOCUMENT ) ||
349*cdf0e10cSrcweir         ( nCommandGroup == frame::CommandGroup::DATA ) ||
350*cdf0e10cSrcweir         ( nCommandGroup == frame::CommandGroup::VIEW ))
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         CmdToInfoCache::const_iterator pIter = rCmdCache.begin();
353*cdf0e10cSrcweir         while ( pIter != rCmdCache.end() )
354*cdf0e10cSrcweir         {
355*cdf0e10cSrcweir             if ( pIter->second.nGroupId == nCommandGroup )
356*cdf0e10cSrcweir             {
357*cdf0e10cSrcweir                 bGroupFound = sal_True;
358*cdf0e10cSrcweir                 aDispatchInfo.Command = pIter->first;
359*cdf0e10cSrcweir                 aDispatchInfo.GroupId = pIter->second.nGroupId;
360*cdf0e10cSrcweir                 aDispatchInfoList.push_back( aDispatchInfo );
361*cdf0e10cSrcweir             }
362*cdf0e10cSrcweir             else if ( bGroupFound )
363*cdf0e10cSrcweir                 break;
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir             ++pIter;
366*cdf0e10cSrcweir         }
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
370*cdf0e10cSrcweir         comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aDispatchInfoList );
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     return aSeq;
373*cdf0e10cSrcweir }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir sal_Bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet)
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir     sal_Int32 nPriv = 0;
378*cdf0e10cSrcweir     _rxCursorSet->getPropertyValue(C2U("Privileges")) >>= nPriv;
379*cdf0e10cSrcweir     return ((_rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0));
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir /* -----------------------------08.05.2002 08:58------------------------------
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
384*cdf0e10cSrcweir sal_Bool BibFrameController_Impl::SaveModified(const Reference< form::runtime::XFormController>& xController)
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     if (!xController.is())
387*cdf0e10cSrcweir 		return sal_False;
388*cdf0e10cSrcweir     sal_Bool bInserted = sal_False;
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     Reference< XResultSetUpdate> _xCursor = Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY);
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	if (!_xCursor.is())
393*cdf0e10cSrcweir 		return sal_False;
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     Reference< beans::XPropertySet> _xSet = Reference< beans::XPropertySet>(_xCursor, UNO_QUERY);
396*cdf0e10cSrcweir 	if (!_xSet.is())
397*cdf0e10cSrcweir 		return sal_False;
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	// mu� gespeichert werden ?
400*cdf0e10cSrcweir     sal_Bool  bIsNew        = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsNew")));
401*cdf0e10cSrcweir     sal_Bool  bIsModified   = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsModified")));
402*cdf0e10cSrcweir 	sal_Bool bResult = !bIsModified;
403*cdf0e10cSrcweir 	if (bIsModified)
404*cdf0e10cSrcweir 	{
405*cdf0e10cSrcweir 		try
406*cdf0e10cSrcweir 		{
407*cdf0e10cSrcweir 			if (bIsNew)
408*cdf0e10cSrcweir 				_xCursor->insertRow();
409*cdf0e10cSrcweir 			else
410*cdf0e10cSrcweir 				_xCursor->updateRow();
411*cdf0e10cSrcweir 			bResult = sal_True;
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 		catch(Exception&)
414*cdf0e10cSrcweir 		{
415*cdf0e10cSrcweir             DBG_ERROR("SaveModified: Exception occured!");
416*cdf0e10cSrcweir 		}
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir         bInserted = bIsNew && bResult;
419*cdf0e10cSrcweir 	}
420*cdf0e10cSrcweir 	return bResult;
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir Window* lcl_GetFocusChild( Window* pParent )
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     sal_uInt16 nChildren = pParent->GetChildCount();
426*cdf0e10cSrcweir     for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
427*cdf0e10cSrcweir     {
428*cdf0e10cSrcweir         Window* pChild = pParent->GetChild( nChild );
429*cdf0e10cSrcweir         if(pChild->HasFocus())
430*cdf0e10cSrcweir             return pChild;
431*cdf0e10cSrcweir         Window* pSubChild = lcl_GetFocusChild( pChild );
432*cdf0e10cSrcweir         if(pSubChild)
433*cdf0e10cSrcweir             return pSubChild;
434*cdf0e10cSrcweir     }
435*cdf0e10cSrcweir     return 0;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir //class XDispatch
439*cdf0e10cSrcweir void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs) throw (::com::sun::star::uno::RuntimeException)
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	if ( !bDisposing )
442*cdf0e10cSrcweir 	{
443*cdf0e10cSrcweir         vos::OGuard aGuard(Application::GetSolarMutex());
444*cdf0e10cSrcweir         Window* pParent = VCLUnoHelper::GetWindow( xWindow );
445*cdf0e10cSrcweir 		WaitObject aWaitObject( pParent );
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 		String aCommand( _rURL.Path);
448*cdf0e10cSrcweir 		if(aCommand.EqualsAscii("Bib/Mapping"))
449*cdf0e10cSrcweir 		{
450*cdf0e10cSrcweir 			pDatMan->CreateMappingDialog(pParent);
451*cdf0e10cSrcweir 		}
452*cdf0e10cSrcweir 		else if(aCommand.EqualsAscii("Bib/source"))
453*cdf0e10cSrcweir 		{
454*cdf0e10cSrcweir 			ChangeDataSource(aArgs);
455*cdf0e10cSrcweir 		}
456*cdf0e10cSrcweir 		else if(aCommand.EqualsAscii("Bib/sdbsource"))
457*cdf0e10cSrcweir 		{
458*cdf0e10cSrcweir 			rtl::OUString aURL = pDatMan->CreateDBChangeDialog(pParent);
459*cdf0e10cSrcweir 			if(aURL.getLength())
460*cdf0e10cSrcweir 			{
461*cdf0e10cSrcweir 				try
462*cdf0e10cSrcweir 				{
463*cdf0e10cSrcweir 					uno::Sequence< beans::PropertyValue > aNewDataSource(2);
464*cdf0e10cSrcweir 					beans::PropertyValue* pProps = aNewDataSource.getArray();
465*cdf0e10cSrcweir 					pProps[0].Value <<= rtl::OUString();
466*cdf0e10cSrcweir 					pProps[1].Value <<= aURL;
467*cdf0e10cSrcweir 					ChangeDataSource(aNewDataSource);
468*cdf0e10cSrcweir 				}
469*cdf0e10cSrcweir 				catch(const Exception&)
470*cdf0e10cSrcweir 				{
471*cdf0e10cSrcweir 					DBG_ERROR("Exception catched while changing the data source");
472*cdf0e10cSrcweir 				}
473*cdf0e10cSrcweir 			}
474*cdf0e10cSrcweir 		}
475*cdf0e10cSrcweir 		else if(aCommand.EqualsAscii("Bib/autoFilter"))
476*cdf0e10cSrcweir 		{
477*cdf0e10cSrcweir 			sal_uInt16 nCount = aStatusListeners.Count();
478*cdf0e10cSrcweir 			for ( sal_uInt16 n=0; n<nCount; n++ )
479*cdf0e10cSrcweir 			{
480*cdf0e10cSrcweir 				BibStatusDispatch *pObj = aStatusListeners[n];
481*cdf0e10cSrcweir 				if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
482*cdf0e10cSrcweir 				{
483*cdf0e10cSrcweir 					FeatureStateEvent  aEvent;
484*cdf0e10cSrcweir 					aEvent.FeatureURL = pObj->aURL;
485*cdf0e10cSrcweir 					aEvent.IsEnabled  = sal_True;
486*cdf0e10cSrcweir 					aEvent.Requery	  = sal_False;
487*cdf0e10cSrcweir 					aEvent.Source	  = (XDispatch *) this;
488*cdf0e10cSrcweir 					pObj->xListener->statusChanged( aEvent );
489*cdf0e10cSrcweir 					//break; because there are more than one
490*cdf0e10cSrcweir 				}
491*cdf0e10cSrcweir 			}
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 			const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
494*cdf0e10cSrcweir 			uno::Any aValue=pPropertyValue[0].Value;
495*cdf0e10cSrcweir 			rtl::OUString aQuery;
496*cdf0e10cSrcweir 			aValue >>= aQuery;
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 			aValue=pPropertyValue[1].Value;
499*cdf0e10cSrcweir 			rtl::OUString aQueryField;
500*cdf0e10cSrcweir 			aValue >>= aQueryField;
501*cdf0e10cSrcweir 			BibConfig* pConfig = BibModul::GetConfig();
502*cdf0e10cSrcweir 			pConfig->setQueryField(aQueryField);
503*cdf0e10cSrcweir 			pDatMan->startQueryWith(aQuery);
504*cdf0e10cSrcweir 		}
505*cdf0e10cSrcweir 		else if(aCommand.EqualsAscii("Bib/standardFilter"))
506*cdf0e10cSrcweir 		{
507*cdf0e10cSrcweir 			try
508*cdf0e10cSrcweir 			{
509*cdf0e10cSrcweir 				uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 				// build the arguments for the filter dialog to be created
512*cdf0e10cSrcweir 				Sequence< Any > aDialogCreationArgs( 3 );
513*cdf0e10cSrcweir 				Any* pDialogCreationArgs = aDialogCreationArgs.getArray();
514*cdf0e10cSrcweir 				// the query composer
515*cdf0e10cSrcweir 				*pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "QueryComposer" ),
516*cdf0e10cSrcweir 														-1,
517*cdf0e10cSrcweir 														makeAny( pDatMan->getParser() ),
518*cdf0e10cSrcweir 														beans::PropertyState_DIRECT_VALUE
519*cdf0e10cSrcweir 													  );
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 				// the rowset
522*cdf0e10cSrcweir 				*pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "RowSet" ),
523*cdf0e10cSrcweir 														-1,
524*cdf0e10cSrcweir 														makeAny( pDatMan->getForm() ),
525*cdf0e10cSrcweir 														beans::PropertyState_DIRECT_VALUE
526*cdf0e10cSrcweir 													  );
527*cdf0e10cSrcweir 				// the parent window for the dialog
528*cdf0e10cSrcweir 				*pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "ParentWindow" ),
529*cdf0e10cSrcweir 														-1,
530*cdf0e10cSrcweir 														makeAny( xWindow ),
531*cdf0e10cSrcweir 														beans::PropertyState_DIRECT_VALUE
532*cdf0e10cSrcweir 													  );
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 				// create the dialog object
535*cdf0e10cSrcweir 				const ::rtl::OUString sDialogServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.sdb.FilterDialog" );
536*cdf0e10cSrcweir 				uno::Reference< uno::XInterface > xDialog = xORB->createInstanceWithArguments(
537*cdf0e10cSrcweir 					sDialogServiceName,
538*cdf0e10cSrcweir 					aDialogCreationArgs
539*cdf0e10cSrcweir 				);
540*cdf0e10cSrcweir 				if ( !xDialog.is() )
541*cdf0e10cSrcweir 				{
542*cdf0e10cSrcweir 					ShowServiceNotAvailableError( VCLUnoHelper::GetWindow( xWindow ), sDialogServiceName, sal_True );
543*cdf0e10cSrcweir 				}
544*cdf0e10cSrcweir 				else
545*cdf0e10cSrcweir 				{
546*cdf0e10cSrcweir 					// execute it
547*cdf0e10cSrcweir 					uno::Reference< ui::dialogs::XExecutableDialog > xExec( xDialog, UNO_QUERY );
548*cdf0e10cSrcweir 					DBG_ASSERT( xExec.is(), "BibFrameController_Impl::dispatch: missing an interface on the dialog!" );
549*cdf0e10cSrcweir 					if ( xExec.is() )
550*cdf0e10cSrcweir 						if ( xExec->execute( ) )
551*cdf0e10cSrcweir 						{
552*cdf0e10cSrcweir 							// the dialog has been executed successfully, and the filter on the query composer
553*cdf0e10cSrcweir 							// has been changed
554*cdf0e10cSrcweir 							::rtl::OUString sNewFilter = pDatMan->getParser()->getFilter();
555*cdf0e10cSrcweir 							pDatMan->setFilter( sNewFilter );
556*cdf0e10cSrcweir 						}
557*cdf0e10cSrcweir 				}
558*cdf0e10cSrcweir 			}
559*cdf0e10cSrcweir 			catch( const uno::Exception& )
560*cdf0e10cSrcweir 			{
561*cdf0e10cSrcweir 				DBG_ERROR( "BibFrameController_Impl::dispatch: caught an exception!" );
562*cdf0e10cSrcweir 			}
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 			sal_uInt16 nCount = aStatusListeners.Count();
565*cdf0e10cSrcweir 			for ( sal_uInt16 n=0; n<nCount; n++ )
566*cdf0e10cSrcweir 			{
567*cdf0e10cSrcweir 				BibStatusDispatch *pObj = aStatusListeners[n];
568*cdf0e10cSrcweir 				if ( pObj->aURL.Path == C2U("Bib/removeFilter") && pDatMan->getParser().is())
569*cdf0e10cSrcweir 				{
570*cdf0e10cSrcweir 					FeatureStateEvent  aEvent;
571*cdf0e10cSrcweir 					aEvent.FeatureURL = pObj->aURL;
572*cdf0e10cSrcweir 					aEvent.IsEnabled  = 0 != pDatMan->getParser()->getFilter().getLength();
573*cdf0e10cSrcweir 					aEvent.Requery	  = sal_False;
574*cdf0e10cSrcweir 					aEvent.Source	  = (XDispatch *) this;
575*cdf0e10cSrcweir 					pObj->xListener->statusChanged( aEvent );
576*cdf0e10cSrcweir 				}
577*cdf0e10cSrcweir 			}
578*cdf0e10cSrcweir 		}
579*cdf0e10cSrcweir 		else if(aCommand.EqualsAscii("Bib/removeFilter"))
580*cdf0e10cSrcweir 		{
581*cdf0e10cSrcweir 			RemoveFilter();
582*cdf0e10cSrcweir 		}
583*cdf0e10cSrcweir 		else if(_rURL.Complete.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("slot:5503")) ||
584*cdf0e10cSrcweir 			    aCommand.EqualsAscii("CloseDoc"))
585*cdf0e10cSrcweir 		{
586*cdf0e10cSrcweir 			Application::PostUserEvent( STATIC_LINK( this, BibFrameController_Impl,
587*cdf0e10cSrcweir 										DisposeHdl ), 0 );
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 		}
590*cdf0e10cSrcweir         else if(aCommand.EqualsAscii("Bib/InsertRecord"))
591*cdf0e10cSrcweir         {
592*cdf0e10cSrcweir             Reference<form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
593*cdf0e10cSrcweir             if(SaveModified(xFormCtrl))
594*cdf0e10cSrcweir 			{
595*cdf0e10cSrcweir                 try
596*cdf0e10cSrcweir                 {
597*cdf0e10cSrcweir                     Reference< sdbc::XResultSet >  xCursor( pDatMan->getForm(), UNO_QUERY );
598*cdf0e10cSrcweir                     xCursor->last();
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir                     Reference< XResultSetUpdate >  xUpdateCursor( pDatMan->getForm(), UNO_QUERY );
601*cdf0e10cSrcweir                     xUpdateCursor->moveToInsertRow();
602*cdf0e10cSrcweir                 }
603*cdf0e10cSrcweir                 catch(Exception&)
604*cdf0e10cSrcweir                 {
605*cdf0e10cSrcweir                     DBG_ERROR("Exception in last() or moveToInsertRow()");
606*cdf0e10cSrcweir                 }
607*cdf0e10cSrcweir 			}
608*cdf0e10cSrcweir         }
609*cdf0e10cSrcweir         else if(aCommand.EqualsAscii("Bib/DeleteRecord"))
610*cdf0e10cSrcweir         {
611*cdf0e10cSrcweir             Reference< ::com::sun::star::sdbc::XResultSet >  xCursor(pDatMan->getForm(), UNO_QUERY);
612*cdf0e10cSrcweir             Reference< XResultSetUpdate >  xUpdateCursor(xCursor, UNO_QUERY);
613*cdf0e10cSrcweir             Reference< beans::XPropertySet >  xSet(pDatMan->getForm(), UNO_QUERY);
614*cdf0e10cSrcweir             sal_Bool  bIsNew  = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
615*cdf0e10cSrcweir             if(!bIsNew)
616*cdf0e10cSrcweir             {
617*cdf0e10cSrcweir                 sal_uInt32 nCount = 0;
618*cdf0e10cSrcweir                 xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
619*cdf0e10cSrcweir                 // naechste position festellen
620*cdf0e10cSrcweir                 sal_Bool bSuccess = sal_False;
621*cdf0e10cSrcweir                 sal_Bool bLeft = sal_False;
622*cdf0e10cSrcweir                 sal_Bool bRight = sal_False;
623*cdf0e10cSrcweir                 try
624*cdf0e10cSrcweir                 {
625*cdf0e10cSrcweir                     bLeft = xCursor->isLast() && nCount > 1;
626*cdf0e10cSrcweir                     bRight= !xCursor->isLast();
627*cdf0e10cSrcweir                     // ask for confirmation
628*cdf0e10cSrcweir                     Reference< frame::XController > xCtrl = pImp->pController;
629*cdf0e10cSrcweir                     Reference< form::XConfirmDeleteListener >  xConfirm(pDatMan->GetFormController(),UNO_QUERY);
630*cdf0e10cSrcweir                     if (xConfirm.is())
631*cdf0e10cSrcweir                     {
632*cdf0e10cSrcweir                         sdb::RowChangeEvent aEvent;
633*cdf0e10cSrcweir                         aEvent.Source = Reference< XInterface > (xCursor, UNO_QUERY);
634*cdf0e10cSrcweir                         aEvent.Action = sdb::RowChangeAction::DELETE;
635*cdf0e10cSrcweir                         aEvent.Rows = 1;
636*cdf0e10cSrcweir                         bSuccess = xConfirm->confirmDelete(aEvent);
637*cdf0e10cSrcweir                     }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir                     // das Ding loeschen
640*cdf0e10cSrcweir                     if (bSuccess)
641*cdf0e10cSrcweir                         xUpdateCursor->deleteRow();
642*cdf0e10cSrcweir                 }
643*cdf0e10cSrcweir                 catch(Exception&)
644*cdf0e10cSrcweir                 {
645*cdf0e10cSrcweir                     bSuccess = sal_False;
646*cdf0e10cSrcweir                 }
647*cdf0e10cSrcweir                 if (bSuccess)
648*cdf0e10cSrcweir                 {
649*cdf0e10cSrcweir                     if (bLeft || bRight)
650*cdf0e10cSrcweir                         xCursor->relative(bRight ? 1 : -1);
651*cdf0e10cSrcweir                     else
652*cdf0e10cSrcweir                     {
653*cdf0e10cSrcweir                         sal_Bool bCanInsert = canInsertRecords(xSet);
654*cdf0e10cSrcweir                         // kann noch ein Datensatz eingefuegt weden
655*cdf0e10cSrcweir                         try
656*cdf0e10cSrcweir                         {
657*cdf0e10cSrcweir                             if (bCanInsert)
658*cdf0e10cSrcweir                                 xUpdateCursor->moveToInsertRow();
659*cdf0e10cSrcweir                             else
660*cdf0e10cSrcweir                                 // Datensatz bewegen um Stati neu zu setzen
661*cdf0e10cSrcweir                                 xCursor->first();
662*cdf0e10cSrcweir                         }
663*cdf0e10cSrcweir                         catch(Exception&)
664*cdf0e10cSrcweir                         {
665*cdf0e10cSrcweir                             DBG_ERROR("DeleteRecord : exception caught !");
666*cdf0e10cSrcweir                         }
667*cdf0e10cSrcweir                     }
668*cdf0e10cSrcweir                 }
669*cdf0e10cSrcweir             }
670*cdf0e10cSrcweir         }
671*cdf0e10cSrcweir         else if(aCommand.EqualsAscii("Cut"))
672*cdf0e10cSrcweir         {
673*cdf0e10cSrcweir             Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
674*cdf0e10cSrcweir             if(pChild)
675*cdf0e10cSrcweir             {
676*cdf0e10cSrcweir                 KeyEvent aEvent( 0, KEYFUNC_CUT );
677*cdf0e10cSrcweir                 pChild->KeyInput( aEvent );
678*cdf0e10cSrcweir             }
679*cdf0e10cSrcweir         }
680*cdf0e10cSrcweir         else if(aCommand.EqualsAscii("Copy"))
681*cdf0e10cSrcweir         {
682*cdf0e10cSrcweir             Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
683*cdf0e10cSrcweir             if(pChild)
684*cdf0e10cSrcweir             {
685*cdf0e10cSrcweir                 KeyEvent aEvent( 0, KEYFUNC_COPY );
686*cdf0e10cSrcweir                 pChild->KeyInput( aEvent );
687*cdf0e10cSrcweir             }
688*cdf0e10cSrcweir         }
689*cdf0e10cSrcweir         else if(aCommand.EqualsAscii("Paste"))
690*cdf0e10cSrcweir         {
691*cdf0e10cSrcweir             Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
692*cdf0e10cSrcweir             if(pChild)
693*cdf0e10cSrcweir             {
694*cdf0e10cSrcweir                 KeyEvent aEvent( 0, KEYFUNC_PASTE );
695*cdf0e10cSrcweir                 pChild->KeyInput( aEvent );
696*cdf0e10cSrcweir             }
697*cdf0e10cSrcweir         }
698*cdf0e10cSrcweir     }
699*cdf0e10cSrcweir }
700*cdf0e10cSrcweir IMPL_STATIC_LINK( BibFrameController_Impl, DisposeHdl, void*, EMPTYARG )
701*cdf0e10cSrcweir {
702*cdf0e10cSrcweir 	pThis->xFrame->dispose();
703*cdf0e10cSrcweir 	return 0;
704*cdf0e10cSrcweir };
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir //-----------------------------------------------------------------------------
707*cdf0e10cSrcweir void BibFrameController_Impl::addStatusListener(
708*cdf0e10cSrcweir 	const uno::Reference< frame::XStatusListener > & aListener,
709*cdf0e10cSrcweir 	const util::URL& aURL)
710*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
711*cdf0e10cSrcweir {
712*cdf0e10cSrcweir 	BibConfig* pConfig = BibModul::GetConfig();
713*cdf0e10cSrcweir 	// create a new Reference and insert into listener array
714*cdf0e10cSrcweir 	aStatusListeners.Insert( new BibStatusDispatch( aURL, aListener ), aStatusListeners.Count() );
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 	// den ersten Status synchron zusenden
717*cdf0e10cSrcweir     FeatureStateEvent aEvent;
718*cdf0e10cSrcweir     aEvent.FeatureURL = aURL;
719*cdf0e10cSrcweir     aEvent.Requery    = sal_False;
720*cdf0e10cSrcweir     aEvent.Source     = (XDispatch *) this;
721*cdf0e10cSrcweir     if ( aURL.Path == C2U("StatusBarVisible") )
722*cdf0e10cSrcweir     {
723*cdf0e10cSrcweir         aEvent.IsEnabled  = sal_False;
724*cdf0e10cSrcweir 		aEvent.State <<= sal_Bool( sal_False );
725*cdf0e10cSrcweir     }
726*cdf0e10cSrcweir     else if ( aURL.Path == C2U("Bib/hierarchical") )
727*cdf0e10cSrcweir 	{
728*cdf0e10cSrcweir 		aEvent.IsEnabled  = sal_True;
729*cdf0e10cSrcweir 		const char*  pHier = bHierarchical? "" : "*" ;
730*cdf0e10cSrcweir 		aEvent.State <<= rtl::OUString::createFromAscii(pHier);
731*cdf0e10cSrcweir 	}
732*cdf0e10cSrcweir 	else if(aURL.Path == C2U("Bib/MenuFilter"))
733*cdf0e10cSrcweir 	{
734*cdf0e10cSrcweir 		aEvent.IsEnabled  = sal_True;
735*cdf0e10cSrcweir 		aEvent.FeatureDescriptor=pDatMan->getQueryField();
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 		uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
738*cdf0e10cSrcweir 		aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	}
741*cdf0e10cSrcweir 	else if ( aURL.Path == C2U("Bib/source"))
742*cdf0e10cSrcweir 	{
743*cdf0e10cSrcweir 		aEvent.IsEnabled  = sal_True;
744*cdf0e10cSrcweir 		aEvent.FeatureDescriptor=pDatMan->getActiveDataTable();
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir 		uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getDataSources();
747*cdf0e10cSrcweir 		aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
748*cdf0e10cSrcweir 	}
749*cdf0e10cSrcweir     else if(aURL.Path == C2U("Bib/sdbsource") ||
750*cdf0e10cSrcweir             aURL.Path == C2U("Bib/Mapping") ||
751*cdf0e10cSrcweir             aURL.Path == C2U("Bib/autoFilter") ||
752*cdf0e10cSrcweir             aURL.Path.equalsAscii("Bib/standardFilter"))
753*cdf0e10cSrcweir 	{
754*cdf0e10cSrcweir 		aEvent.IsEnabled  = sal_True;
755*cdf0e10cSrcweir 	}
756*cdf0e10cSrcweir 	else if(aURL.Path == C2U("Bib/query"))
757*cdf0e10cSrcweir 	{
758*cdf0e10cSrcweir 		aEvent.IsEnabled  = sal_True;
759*cdf0e10cSrcweir 		aEvent.State <<= pConfig->getQueryText();
760*cdf0e10cSrcweir 	}
761*cdf0e10cSrcweir 	else if (aURL.Path == C2U("Bib/removeFilter") )
762*cdf0e10cSrcweir 	{
763*cdf0e10cSrcweir 		rtl::OUString aFilterStr=pDatMan->getFilter();
764*cdf0e10cSrcweir 		aEvent.IsEnabled  = (aFilterStr.getLength() > 0);
765*cdf0e10cSrcweir 	}
766*cdf0e10cSrcweir     else if(aURL.Path == C2U("Cut"))
767*cdf0e10cSrcweir 	{
768*cdf0e10cSrcweir         Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
769*cdf0e10cSrcweir         Edit* pEdit = dynamic_cast<Edit*>( pChild );
770*cdf0e10cSrcweir         if( pEdit )
771*cdf0e10cSrcweir             aEvent.IsEnabled  = !pEdit->IsReadOnly() && pEdit->GetSelection().Len();
772*cdf0e10cSrcweir     }
773*cdf0e10cSrcweir     if(aURL.Path == C2U("Copy"))
774*cdf0e10cSrcweir     {
775*cdf0e10cSrcweir         Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
776*cdf0e10cSrcweir         Edit* pEdit = dynamic_cast<Edit*>( pChild );
777*cdf0e10cSrcweir         if( pEdit )
778*cdf0e10cSrcweir             aEvent.IsEnabled  = pEdit->GetSelection().Len() > 0;
779*cdf0e10cSrcweir     }
780*cdf0e10cSrcweir     else if(aURL.Path == C2U("Paste") )
781*cdf0e10cSrcweir 	{
782*cdf0e10cSrcweir         aEvent.IsEnabled  = sal_False;
783*cdf0e10cSrcweir         Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
784*cdf0e10cSrcweir         if(pChild)
785*cdf0e10cSrcweir         {
786*cdf0e10cSrcweir             uno::Reference< datatransfer::clipboard::XClipboard > xClip = pChild->GetClipboard();
787*cdf0e10cSrcweir             if(xClip.is())
788*cdf0e10cSrcweir             {
789*cdf0e10cSrcweir                 uno::Reference< datatransfer::XTransferable > xDataObj;
790*cdf0e10cSrcweir                 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
791*cdf0e10cSrcweir                 try
792*cdf0e10cSrcweir                 {
793*cdf0e10cSrcweir                     xDataObj = xClip->getContents();
794*cdf0e10cSrcweir                 }
795*cdf0e10cSrcweir                 catch( const uno::Exception& )
796*cdf0e10cSrcweir                 {
797*cdf0e10cSrcweir                 }
798*cdf0e10cSrcweir                 Application::AcquireSolarMutex( nRef );
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir                 if ( xDataObj.is() )
801*cdf0e10cSrcweir                 {
802*cdf0e10cSrcweir                     datatransfer::DataFlavor aFlavor;
803*cdf0e10cSrcweir                     SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
804*cdf0e10cSrcweir                     try
805*cdf0e10cSrcweir                     {
806*cdf0e10cSrcweir                         uno::Any aData = xDataObj->getTransferData( aFlavor );
807*cdf0e10cSrcweir                         ::rtl::OUString aText;
808*cdf0e10cSrcweir                         aData >>= aText;
809*cdf0e10cSrcweir                         aEvent.IsEnabled  = aText.getLength() > 0;
810*cdf0e10cSrcweir                     }
811*cdf0e10cSrcweir                     catch( const uno::Exception& )
812*cdf0e10cSrcweir                     {
813*cdf0e10cSrcweir                     }
814*cdf0e10cSrcweir                 }
815*cdf0e10cSrcweir             }
816*cdf0e10cSrcweir             uno::Reference< datatransfer::XTransferable > xContents = xClip->getContents(  );
817*cdf0e10cSrcweir         }
818*cdf0e10cSrcweir     }
819*cdf0e10cSrcweir     else if(aURL.Path == C2U("Bib/DeleteRecord"))
820*cdf0e10cSrcweir     {
821*cdf0e10cSrcweir         Reference< ::com::sun::star::sdbc::XResultSet >  xCursor(pDatMan->getForm(), UNO_QUERY);
822*cdf0e10cSrcweir         Reference< XResultSetUpdate >  xUpdateCursor(xCursor, UNO_QUERY);
823*cdf0e10cSrcweir         Reference< beans::XPropertySet >  xSet(pDatMan->getForm(), UNO_QUERY);
824*cdf0e10cSrcweir         sal_Bool  bIsNew  = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
825*cdf0e10cSrcweir         if(!bIsNew)
826*cdf0e10cSrcweir         {
827*cdf0e10cSrcweir             sal_uInt32 nCount = 0;
828*cdf0e10cSrcweir             xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
829*cdf0e10cSrcweir             aEvent.IsEnabled  = nCount > 0;
830*cdf0e10cSrcweir         }
831*cdf0e10cSrcweir     }
832*cdf0e10cSrcweir     else if (aURL.Path == C2U("Bib/InsertRecord"))
833*cdf0e10cSrcweir     {
834*cdf0e10cSrcweir         Reference< beans::XPropertySet >  xSet(pDatMan->getForm(), UNO_QUERY);
835*cdf0e10cSrcweir         aEvent.IsEnabled = canInsertRecords(xSet);
836*cdf0e10cSrcweir     }
837*cdf0e10cSrcweir     aListener->statusChanged( aEvent );
838*cdf0e10cSrcweir }
839*cdf0e10cSrcweir //-----------------------------------------------------------------------------
840*cdf0e10cSrcweir void BibFrameController_Impl::removeStatusListener(
841*cdf0e10cSrcweir 	const uno::Reference< frame::XStatusListener > & aObject, const util::URL& aURL)
842*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
843*cdf0e10cSrcweir {
844*cdf0e10cSrcweir 	// search listener array for given listener
845*cdf0e10cSrcweir 	// for checking equality always "cast" to XInterface
846*cdf0e10cSrcweir 	if ( !bDisposing )
847*cdf0e10cSrcweir 	{
848*cdf0e10cSrcweir 		sal_uInt16 nCount = aStatusListeners.Count();
849*cdf0e10cSrcweir 		for ( sal_uInt16 n=0; n<nCount; n++ )
850*cdf0e10cSrcweir 		{
851*cdf0e10cSrcweir 			BibStatusDispatch *pObj = aStatusListeners[n];
852*cdf0e10cSrcweir 			sal_Bool bFlag=pObj->xListener.is();
853*cdf0e10cSrcweir 			if (!bFlag || (pObj->xListener == aObject &&
854*cdf0e10cSrcweir 				( !aURL.Complete.getLength() || pObj->aURL.Path == aURL.Path  )))
855*cdf0e10cSrcweir 			{
856*cdf0e10cSrcweir 				aStatusListeners.DeleteAndDestroy( n );
857*cdf0e10cSrcweir 				break;
858*cdf0e10cSrcweir 			}
859*cdf0e10cSrcweir 		}
860*cdf0e10cSrcweir 	}
861*cdf0e10cSrcweir }
862*cdf0e10cSrcweir //-----------------------------------------------------------------------------
863*cdf0e10cSrcweir void BibFrameController_Impl::RemoveFilter()
864*cdf0e10cSrcweir {
865*cdf0e10cSrcweir 	rtl::OUString aQuery;
866*cdf0e10cSrcweir 	pDatMan->startQueryWith(aQuery);
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 	sal_uInt16 nCount = aStatusListeners.Count();
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir 	sal_Bool bRemoveFilter=sal_False;
871*cdf0e10cSrcweir 	sal_Bool bQueryText=sal_False;
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 	for ( sal_uInt16 n=0; n<nCount; n++ )
874*cdf0e10cSrcweir 	{
875*cdf0e10cSrcweir 		BibStatusDispatch *pObj = aStatusListeners[n];
876*cdf0e10cSrcweir 		if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
877*cdf0e10cSrcweir 		{
878*cdf0e10cSrcweir 	        FeatureStateEvent  aEvent;
879*cdf0e10cSrcweir 			aEvent.FeatureURL = pObj->aURL;
880*cdf0e10cSrcweir 			aEvent.IsEnabled  = sal_False;
881*cdf0e10cSrcweir 			aEvent.Requery	  = sal_False;
882*cdf0e10cSrcweir 			aEvent.Source	  = (XDispatch *) this;
883*cdf0e10cSrcweir 			pObj->xListener->statusChanged( aEvent );
884*cdf0e10cSrcweir 			bRemoveFilter=sal_True;
885*cdf0e10cSrcweir 		}
886*cdf0e10cSrcweir 		else if(pObj->aURL.Path == C2U("Bib/query"))
887*cdf0e10cSrcweir 		{
888*cdf0e10cSrcweir 	        FeatureStateEvent  aEvent;
889*cdf0e10cSrcweir 			aEvent.FeatureURL = pObj->aURL;
890*cdf0e10cSrcweir 			aEvent.IsEnabled  = sal_True;
891*cdf0e10cSrcweir 			aEvent.Requery	  = sal_False;
892*cdf0e10cSrcweir 			aEvent.Source	  = (XDispatch *) this;
893*cdf0e10cSrcweir 			aEvent.State <<= aQuery;
894*cdf0e10cSrcweir 			pObj->xListener->statusChanged( aEvent );
895*cdf0e10cSrcweir 			bQueryText=sal_True;
896*cdf0e10cSrcweir 		}
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir 		if(bRemoveFilter && bQueryText)
899*cdf0e10cSrcweir 			break;
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir 	}
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir //-----------------------------------------------------------------------------
904*cdf0e10cSrcweir void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs)
905*cdf0e10cSrcweir {
906*cdf0e10cSrcweir 	const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
907*cdf0e10cSrcweir 	uno::Any aValue=pPropertyValue[0].Value;
908*cdf0e10cSrcweir 	rtl::OUString aDBTableName;
909*cdf0e10cSrcweir 	aValue >>= aDBTableName;
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir 	if(aArgs.getLength() > 1)
913*cdf0e10cSrcweir 	{
914*cdf0e10cSrcweir 		uno::Any aDB = pPropertyValue[1].Value;
915*cdf0e10cSrcweir 		rtl::OUString aURL;
916*cdf0e10cSrcweir 		aDB >>= aURL;
917*cdf0e10cSrcweir 		pDatMan->setActiveDataSource(aURL);
918*cdf0e10cSrcweir 		aDBTableName = pDatMan->getActiveDataTable();
919*cdf0e10cSrcweir 	}
920*cdf0e10cSrcweir 	else
921*cdf0e10cSrcweir     {
922*cdf0e10cSrcweir         m_xDatMan->unload();
923*cdf0e10cSrcweir         pDatMan->setActiveDataTable(aDBTableName);
924*cdf0e10cSrcweir         pDatMan->updateGridModel();
925*cdf0e10cSrcweir         m_xDatMan->load();
926*cdf0e10cSrcweir     }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir 	sal_uInt16 nCount = aStatusListeners.Count();
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir 	sal_Bool bMenuFilter=sal_False;
932*cdf0e10cSrcweir 	sal_Bool bQueryText=sal_False;
933*cdf0e10cSrcweir 	for ( sal_uInt16 n=0; n<nCount; n++ )
934*cdf0e10cSrcweir 	{
935*cdf0e10cSrcweir 		BibStatusDispatch *pObj = aStatusListeners[n];
936*cdf0e10cSrcweir 		if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/MenuFilter"))
937*cdf0e10cSrcweir 		{
938*cdf0e10cSrcweir 	        FeatureStateEvent  aEvent;
939*cdf0e10cSrcweir 			aEvent.FeatureURL = pObj->aURL;
940*cdf0e10cSrcweir 			aEvent.IsEnabled  = sal_True;
941*cdf0e10cSrcweir 			aEvent.Requery	  = sal_False;
942*cdf0e10cSrcweir 			aEvent.Source	  = (XDispatch *) this;
943*cdf0e10cSrcweir 			aEvent.FeatureDescriptor=pDatMan->getQueryField();
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 			uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
946*cdf0e10cSrcweir 			aEvent.State  = makeAny( aStringSeq );
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir 			pObj->xListener->statusChanged( aEvent );
949*cdf0e10cSrcweir 			bMenuFilter=sal_True;
950*cdf0e10cSrcweir 		}
951*cdf0e10cSrcweir 		else if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/query"))
952*cdf0e10cSrcweir 		{
953*cdf0e10cSrcweir 	        FeatureStateEvent  aEvent;
954*cdf0e10cSrcweir 			aEvent.FeatureURL = pObj->aURL;
955*cdf0e10cSrcweir 			aEvent.IsEnabled  = sal_True;
956*cdf0e10cSrcweir 			aEvent.Requery	  = sal_False;
957*cdf0e10cSrcweir 			aEvent.Source	  = (XDispatch *) this;
958*cdf0e10cSrcweir 			BibConfig* pConfig = BibModul::GetConfig();
959*cdf0e10cSrcweir 			aEvent.State <<= pConfig->getQueryText();
960*cdf0e10cSrcweir 			pObj->xListener->statusChanged( aEvent );
961*cdf0e10cSrcweir 			bQueryText=sal_True;
962*cdf0e10cSrcweir 		}
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 		if (bMenuFilter && bQueryText)
965*cdf0e10cSrcweir 			break;
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir 	}
968*cdf0e10cSrcweir }
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir void BibFrameController_Impl::activate()
971*cdf0e10cSrcweir {
972*cdf0e10cSrcweir }
973*cdf0e10cSrcweir void BibFrameController_Impl::deactivate()
974*cdf0e10cSrcweir {
975*cdf0e10cSrcweir }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir 
978