merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / bibliography / framectr.cxx
blob4489fad70161e876b778f8fd5cbbde094a711d95
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include <vcl/waitobj.hxx>
31 #include <cppuhelper/interfacecontainer.hxx>
32 #include <com/sun/star/util/URL.hpp>
33 #include <osl/mutex.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <tools/debug.hxx>
36 #include <vcl/stdtext.hxx>
37 #include <comphelper/types.hxx>
38 #include <comphelper/sequence.hxx>
39 #include "framectr.hxx"
40 #include "datman.hxx"
41 #include "bibresid.hxx"
42 #include "bib.hrc"
43 #include <toolkit/helper/vclunohelper.hxx>
44 #include "bibconfig.hxx"
45 #include <cppuhelper/implbase1.hxx> // helper for implementations
46 #include <vcl/svapp.hxx>
47 #include "bibliography.hrc"
48 #include <comphelper/processfactory.hxx>
49 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
50 #include <com/sun/star/form/runtime/XFormController.hpp>
51 #include <com/sun/star/beans/PropertyState.hpp>
52 #include <com/sun/star/beans/PropertyValue.hpp>
53 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
54 #include <com/sun/star/sdbcx/Privilege.hpp>
55 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
56 #include <com/sun/star/sdb/RowChangeAction.hpp>
57 #include <com/sun/star/frame/CommandGroup.hpp>
58 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
59 #include <sot/exchange.hxx>
60 #include <sot/formats.hxx>
61 #include <vcl/edit.hxx>
62 #include <vos/mutex.hxx>
64 #include <hash_map>
66 using namespace osl;
67 using namespace cppu;
68 using namespace rtl;
69 using namespace com::sun::star::sdbc;
70 using namespace com::sun::star::frame;
71 using namespace com::sun::star::uno;
72 using namespace com::sun::star;
74 #define C2U(cChar) OUString::createFromAscii(cChar)
76 struct DispatchInfo
78 const char* pCommand;
79 sal_Int16 nGroupId;
80 sal_Bool bActiveConnection;
83 struct CacheDispatchInfo
85 sal_Int16 nGroupId;
86 sal_Bool bActiveConnection;
89 // Attention: commands must be sorted by command groups. Implementation is dependent
90 // on this!!
91 static DispatchInfo SupportedCommandsArray[] =
93 { ".uno:Undo" , frame::CommandGroup::EDIT , sal_False },
94 { ".uno:Cut" , frame::CommandGroup::EDIT , sal_False },
95 { ".uno:Copy" , frame::CommandGroup::EDIT , sal_False },
96 { ".uno:Paste" , frame::CommandGroup::EDIT , sal_False },
97 { ".uno:SelectAll" , frame::CommandGroup::EDIT , sal_False },
98 { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT , sal_False },
99 { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW , sal_False },
100 { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW , sal_False },
101 { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA , sal_True },
102 { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA , sal_True },
103 { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA , sal_True },
104 { ".uno:Bib/query" , frame::CommandGroup::DATA , sal_True },
105 { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA , sal_True },
106 { ".uno:Bib/source" , frame::CommandGroup::DATA , sal_True },
107 { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA , sal_True },
108 { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA , sal_True },
109 { ".uno:Bib/Mapping" , frame::CommandGroup::DATA , sal_True },
110 { 0 , 0 , sal_False }
113 typedef ::std::hash_map< ::rtl::OUString, CacheDispatchInfo, rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CmdToInfoCache;
115 SV_IMPL_PTRARR( BibStatusDispatchArr, BibStatusDispatchPtr );
117 const CmdToInfoCache& GetCommandToInfoCache()
119 static sal_Bool bCacheInitialized = sal_False;
120 static CmdToInfoCache aCmdToInfoCache;
122 if ( !bCacheInitialized )
124 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
125 if ( !bCacheInitialized )
127 sal_Int32 i( 0 );
128 while ( SupportedCommandsArray[i].pCommand != 0 )
130 rtl::OUString aCommand( rtl::OUString::createFromAscii( SupportedCommandsArray[i].pCommand ));
132 CacheDispatchInfo aDispatchInfo;
133 aDispatchInfo.nGroupId = SupportedCommandsArray[i].nGroupId;
134 aDispatchInfo.bActiveConnection = SupportedCommandsArray[i].bActiveConnection;
135 aCmdToInfoCache.insert( CmdToInfoCache::value_type( aCommand, aDispatchInfo ));
136 ++i;
138 bCacheInitialized = sal_True;
142 return aCmdToInfoCache;
146 class BibFrameCtrl_Impl : public cppu::WeakImplHelper1 < XFrameActionListener >
148 public:
149 Mutex aMutex;
150 OMultiTypeInterfaceContainerHelper aLC;
152 BibFrameController_Impl* pController;
154 BibFrameCtrl_Impl()
155 : aLC( aMutex )
156 , pController(0)
159 ~BibFrameCtrl_Impl();
161 virtual void SAL_CALL frameAction(const FrameActionEvent& aEvent) throw( RuntimeException );
162 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
166 BibFrameCtrl_Impl::~BibFrameCtrl_Impl()
170 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent& aEvent) throw( uno::RuntimeException )
172 if ( pController && aEvent.Frame == pController->getFrame())
174 if(aEvent.Action == FrameAction_FRAME_ACTIVATED)
176 pController->activate();
178 else if(aEvent.Action == FrameAction_FRAME_DEACTIVATING)
180 pController->deactivate();
185 void BibFrameCtrl_Impl::disposing( const lang::EventObject& /*Source*/ )
186 throw (::com::sun::star::uno::RuntimeException)
188 vos::OGuard aGuard(Application::GetSolarMutex());
189 if ( pController )
190 pController->getFrame()->removeFrameActionListener( this );
193 BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWindow > & xComponent,
194 BibDataManager* pDataManager)
195 :xWindow( xComponent )
196 ,m_xDatMan( pDataManager )
197 ,pDatMan( pDataManager )
198 ,pBibMod(NULL)
200 Window* pParent = VCLUnoHelper::GetWindow( xWindow );
201 pParent->SetUniqueId(UID_BIB_FRAME_WINDOW);
202 bDisposing=sal_False;
203 bHierarchical=sal_True;
204 pImp = new BibFrameCtrl_Impl;
205 pImp->pController = this;
206 pImp->acquire();
209 BibFrameController_Impl::~BibFrameController_Impl()
211 pImp->pController = NULL;
212 pImp->release();
213 delete pDatMan;
214 if(pBibMod)
215 CloseBibModul(pBibMod);
218 ::rtl::OUString SAL_CALL BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException)
220 return ::rtl::OUString::createFromAscii("com.sun.star.comp.extensions.Bibliography");
223 sal_Bool SAL_CALL BibFrameController_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (::com::sun::star::uno::RuntimeException)
225 return (
226 sServiceName.equalsAscii("com.sun.star.frame.Bibliography") ||
227 sServiceName.equalsAscii("com.sun.star.frame.Controller")
231 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException)
233 // return only top level services ...
234 // base services are included there and should be asked by uno-rtti.
235 ::com::sun::star::uno::Sequence< ::rtl::OUString > lNames(1);
236 lNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.Bibliography");
237 return lNames;
240 void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg ) throw (::com::sun::star::uno::RuntimeException)
242 xFrame = xArg;
243 xFrame->addFrameActionListener( pImp );
246 sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException)
248 return sal_False;
251 sal_Bool BibFrameController_Impl::suspend( sal_Bool bSuspend ) throw (::com::sun::star::uno::RuntimeException)
253 if ( bSuspend )
254 getFrame()->removeFrameActionListener( pImp );
255 else
256 getFrame()->addFrameActionListener( pImp );
257 return sal_True;
260 uno::Any BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException)
262 return uno::Any();
265 void BibFrameController_Impl::restoreViewData( const uno::Any& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException)
269 uno::Reference< XFrame > BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException)
271 return xFrame;
274 uno::Reference< XModel > BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException)
276 return uno::Reference< XModel > ();
279 void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException)
281 bDisposing = sal_True;
282 lang::EventObject aObject;
283 aObject.Source = (XController*)this;
284 pImp->aLC.disposeAndClear(aObject);
285 m_xDatMan = 0;
286 pDatMan = 0;
287 aStatusListeners.DeleteAndDestroy( 0, aStatusListeners.Count() );
290 void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
292 pImp->aLC.addInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
295 void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
297 pImp->aLC.removeInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
300 uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( const util::URL& aURL, const rtl::OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ ) throw (::com::sun::star::uno::RuntimeException)
302 if ( !bDisposing )
304 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
305 CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
306 if ( pIter != rCmdCache.end() )
308 if (( pDatMan->HasActiveConnection() ) ||
309 ( !pIter->second.bActiveConnection ))
310 return (frame::XDispatch*) this;
314 return uno::Reference< frame::XDispatch > ();
317 uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts ) throw (::com::sun::star::uno::RuntimeException)
319 uno::Sequence< uno::Reference< XDispatch > > aDispatches( aDescripts.getLength() );
320 for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i )
321 aDispatches[i] = queryDispatch( aDescripts[i].FeatureURL, aDescripts[i].FrameName, aDescripts[i].SearchFlags );
322 return aDispatches;
325 uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups()
326 throw (::com::sun::star::uno::RuntimeException)
328 uno::Sequence< ::sal_Int16 > aDispatchInfo( 4 );
330 aDispatchInfo[0] = frame::CommandGroup::EDIT;
331 aDispatchInfo[1] = frame::CommandGroup::DOCUMENT;
332 aDispatchInfo[2] = frame::CommandGroup::DATA;
333 aDispatchInfo[3] = frame::CommandGroup::VIEW;
335 return aDispatchInfo;
338 uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup )
339 throw (::com::sun::star::uno::RuntimeException)
341 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
343 sal_Bool bGroupFound( sal_False );
344 frame::DispatchInformation aDispatchInfo;
345 std::list< frame::DispatchInformation > aDispatchInfoList;
347 if (( nCommandGroup == frame::CommandGroup::EDIT ) ||
348 ( nCommandGroup == frame::CommandGroup::DOCUMENT ) ||
349 ( nCommandGroup == frame::CommandGroup::DATA ) ||
350 ( nCommandGroup == frame::CommandGroup::VIEW ))
352 CmdToInfoCache::const_iterator pIter = rCmdCache.begin();
353 while ( pIter != rCmdCache.end() )
355 if ( pIter->second.nGroupId == nCommandGroup )
357 bGroupFound = sal_True;
358 aDispatchInfo.Command = pIter->first;
359 aDispatchInfo.GroupId = pIter->second.nGroupId;
360 aDispatchInfoList.push_back( aDispatchInfo );
362 else if ( bGroupFound )
363 break;
365 ++pIter;
369 ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
370 comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aDispatchInfoList );
372 return aSeq;
375 sal_Bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet)
377 sal_Int32 nPriv = 0;
378 _rxCursorSet->getPropertyValue(C2U("Privileges")) >>= nPriv;
379 return ((_rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0));
381 /* -----------------------------08.05.2002 08:58------------------------------
383 ---------------------------------------------------------------------------*/
384 sal_Bool BibFrameController_Impl::SaveModified(const Reference< form::runtime::XFormController>& xController)
386 if (!xController.is())
387 return sal_False;
388 sal_Bool bInserted = sal_False;
390 Reference< XResultSetUpdate> _xCursor = Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY);
392 if (!_xCursor.is())
393 return sal_False;
395 Reference< beans::XPropertySet> _xSet = Reference< beans::XPropertySet>(_xCursor, UNO_QUERY);
396 if (!_xSet.is())
397 return sal_False;
399 // muß gespeichert werden ?
400 sal_Bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsNew")));
401 sal_Bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsModified")));
402 sal_Bool bResult = !bIsModified;
403 if (bIsModified)
407 if (bIsNew)
408 _xCursor->insertRow();
409 else
410 _xCursor->updateRow();
411 bResult = sal_True;
413 catch(Exception&)
415 DBG_ERROR("SaveModified: Exception occured!");
418 bInserted = bIsNew && bResult;
420 return bResult;
423 Window* lcl_GetFocusChild( Window* pParent )
425 USHORT nChildren = pParent->GetChildCount();
426 for( USHORT nChild = 0; nChild < nChildren; ++nChild)
428 Window* pChild = pParent->GetChild( nChild );
429 if(pChild->HasFocus())
430 return pChild;
431 Window* pSubChild = lcl_GetFocusChild( pChild );
432 if(pSubChild)
433 return pSubChild;
435 return 0;
438 //class XDispatch
439 void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs) throw (::com::sun::star::uno::RuntimeException)
441 if ( !bDisposing )
443 vos::OGuard aGuard(Application::GetSolarMutex());
444 Window* pParent = VCLUnoHelper::GetWindow( xWindow );
445 WaitObject aWaitObject( pParent );
447 String aCommand( _rURL.Path);
448 if(aCommand.EqualsAscii("Bib/Mapping"))
450 pDatMan->CreateMappingDialog(pParent);
452 else if(aCommand.EqualsAscii("Bib/source"))
454 ChangeDataSource(aArgs);
456 else if(aCommand.EqualsAscii("Bib/sdbsource"))
458 rtl::OUString aURL = pDatMan->CreateDBChangeDialog(pParent);
459 if(aURL.getLength())
463 uno::Sequence< beans::PropertyValue > aNewDataSource(2);
464 beans::PropertyValue* pProps = aNewDataSource.getArray();
465 pProps[0].Value <<= rtl::OUString();
466 pProps[1].Value <<= aURL;
467 ChangeDataSource(aNewDataSource);
469 catch(const Exception&)
471 DBG_ERROR("Exception catched while changing the data source");
475 else if(aCommand.EqualsAscii("Bib/autoFilter"))
477 sal_uInt16 nCount = aStatusListeners.Count();
478 for ( sal_uInt16 n=0; n<nCount; n++ )
480 BibStatusDispatch *pObj = aStatusListeners[n];
481 if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
483 FeatureStateEvent aEvent;
484 aEvent.FeatureURL = pObj->aURL;
485 aEvent.IsEnabled = sal_True;
486 aEvent.Requery = sal_False;
487 aEvent.Source = (XDispatch *) this;
488 pObj->xListener->statusChanged( aEvent );
489 //break; because there are more than one
493 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
494 uno::Any aValue=pPropertyValue[0].Value;
495 rtl::OUString aQuery;
496 aValue >>= aQuery;
498 aValue=pPropertyValue[1].Value;
499 rtl::OUString aQueryField;
500 aValue >>= aQueryField;
501 BibConfig* pConfig = BibModul::GetConfig();
502 pConfig->setQueryField(aQueryField);
503 pDatMan->startQueryWith(aQuery);
505 else if(aCommand.EqualsAscii("Bib/standardFilter"))
509 uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
511 // build the arguments for the filter dialog to be created
512 Sequence< Any > aDialogCreationArgs( 3 );
513 Any* pDialogCreationArgs = aDialogCreationArgs.getArray();
514 // the query composer
515 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "QueryComposer" ),
517 makeAny( pDatMan->getParser() ),
518 beans::PropertyState_DIRECT_VALUE
521 // the rowset
522 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "RowSet" ),
524 makeAny( pDatMan->getForm() ),
525 beans::PropertyState_DIRECT_VALUE
527 // the parent window for the dialog
528 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "ParentWindow" ),
530 makeAny( xWindow ),
531 beans::PropertyState_DIRECT_VALUE
534 // create the dialog object
535 const ::rtl::OUString sDialogServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.sdb.FilterDialog" );
536 uno::Reference< uno::XInterface > xDialog = xORB->createInstanceWithArguments(
537 sDialogServiceName,
538 aDialogCreationArgs
540 if ( !xDialog.is() )
542 ShowServiceNotAvailableError( VCLUnoHelper::GetWindow( xWindow ), sDialogServiceName, sal_True );
544 else
546 // execute it
547 uno::Reference< ui::dialogs::XExecutableDialog > xExec( xDialog, UNO_QUERY );
548 DBG_ASSERT( xExec.is(), "BibFrameController_Impl::dispatch: missing an interface on the dialog!" );
549 if ( xExec.is() )
550 if ( xExec->execute( ) )
552 // the dialog has been executed successfully, and the filter on the query composer
553 // has been changed
554 ::rtl::OUString sNewFilter = pDatMan->getParser()->getFilter();
555 pDatMan->setFilter( sNewFilter );
559 catch( const uno::Exception& )
561 DBG_ERROR( "BibFrameController_Impl::dispatch: caught an exception!" );
564 sal_uInt16 nCount = aStatusListeners.Count();
565 for ( sal_uInt16 n=0; n<nCount; n++ )
567 BibStatusDispatch *pObj = aStatusListeners[n];
568 if ( pObj->aURL.Path == C2U("Bib/removeFilter") && pDatMan->getParser().is())
570 FeatureStateEvent aEvent;
571 aEvent.FeatureURL = pObj->aURL;
572 aEvent.IsEnabled = 0 != pDatMan->getParser()->getFilter().getLength();
573 aEvent.Requery = sal_False;
574 aEvent.Source = (XDispatch *) this;
575 pObj->xListener->statusChanged( aEvent );
579 else if(aCommand.EqualsAscii("Bib/removeFilter"))
581 RemoveFilter();
583 else if(_rURL.Complete.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("slot:5503")) ||
584 aCommand.EqualsAscii("CloseDoc"))
586 Application::PostUserEvent( STATIC_LINK( this, BibFrameController_Impl,
587 DisposeHdl ), 0 );
590 else if(aCommand.EqualsAscii("Bib/InsertRecord"))
592 Reference<form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
593 if(SaveModified(xFormCtrl))
597 Reference< sdbc::XResultSet > xCursor( pDatMan->getForm(), UNO_QUERY );
598 xCursor->last();
600 Reference< XResultSetUpdate > xUpdateCursor( pDatMan->getForm(), UNO_QUERY );
601 xUpdateCursor->moveToInsertRow();
603 catch(Exception&)
605 DBG_ERROR("Exception in last() or moveToInsertRow()");
609 else if(aCommand.EqualsAscii("Bib/DeleteRecord"))
611 Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY);
612 Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
613 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
614 sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
615 if(!bIsNew)
617 sal_uInt32 nCount = 0;
618 xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
619 // naechste position festellen
620 sal_Bool bSuccess = sal_False;
621 sal_Bool bLeft = sal_False;
622 sal_Bool bRight = sal_False;
625 bLeft = xCursor->isLast() && nCount > 1;
626 bRight= !xCursor->isLast();
627 // ask for confirmation
628 Reference< frame::XController > xCtrl = pImp->pController;
629 Reference< form::XConfirmDeleteListener > xConfirm(pDatMan->GetFormController(),UNO_QUERY);
630 if (xConfirm.is())
632 sdb::RowChangeEvent aEvent;
633 aEvent.Source = Reference< XInterface > (xCursor, UNO_QUERY);
634 aEvent.Action = sdb::RowChangeAction::DELETE;
635 aEvent.Rows = 1;
636 bSuccess = xConfirm->confirmDelete(aEvent);
639 // das Ding loeschen
640 if (bSuccess)
641 xUpdateCursor->deleteRow();
643 catch(Exception&)
645 bSuccess = sal_False;
647 if (bSuccess)
649 if (bLeft || bRight)
650 xCursor->relative(bRight ? 1 : -1);
651 else
653 sal_Bool bCanInsert = canInsertRecords(xSet);
654 // kann noch ein Datensatz eingefuegt weden
657 if (bCanInsert)
658 xUpdateCursor->moveToInsertRow();
659 else
660 // Datensatz bewegen um Stati neu zu setzen
661 xCursor->first();
663 catch(Exception&)
665 DBG_ERROR("DeleteRecord : exception caught !");
671 else if(aCommand.EqualsAscii("Cut"))
673 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
674 if(pChild)
676 KeyEvent aEvent( 0, KEYFUNC_CUT );
677 pChild->KeyInput( aEvent );
680 else if(aCommand.EqualsAscii("Copy"))
682 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
683 if(pChild)
685 KeyEvent aEvent( 0, KEYFUNC_COPY );
686 pChild->KeyInput( aEvent );
689 else if(aCommand.EqualsAscii("Paste"))
691 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
692 if(pChild)
694 KeyEvent aEvent( 0, KEYFUNC_PASTE );
695 pChild->KeyInput( aEvent );
700 IMPL_STATIC_LINK( BibFrameController_Impl, DisposeHdl, void*, EMPTYARG )
702 pThis->xFrame->dispose();
703 return 0;
706 //-----------------------------------------------------------------------------
707 void BibFrameController_Impl::addStatusListener(
708 const uno::Reference< frame::XStatusListener > & aListener,
709 const util::URL& aURL)
710 throw (::com::sun::star::uno::RuntimeException)
712 BibConfig* pConfig = BibModul::GetConfig();
713 // create a new Reference and insert into listener array
714 aStatusListeners.Insert( new BibStatusDispatch( aURL, aListener ), aStatusListeners.Count() );
716 // den ersten Status synchron zusenden
717 FeatureStateEvent aEvent;
718 aEvent.FeatureURL = aURL;
719 aEvent.Requery = sal_False;
720 aEvent.Source = (XDispatch *) this;
721 if ( aURL.Path == C2U("StatusBarVisible") )
723 aEvent.IsEnabled = sal_False;
724 aEvent.State <<= sal_Bool( sal_False );
726 else if ( aURL.Path == C2U("Bib/hierarchical") )
728 aEvent.IsEnabled = sal_True;
729 const char* pHier = bHierarchical? "" : "*" ;
730 aEvent.State <<= rtl::OUString::createFromAscii(pHier);
732 else if(aURL.Path == C2U("Bib/MenuFilter"))
734 aEvent.IsEnabled = sal_True;
735 aEvent.FeatureDescriptor=pDatMan->getQueryField();
737 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
738 aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
741 else if ( aURL.Path == C2U("Bib/source"))
743 aEvent.IsEnabled = sal_True;
744 aEvent.FeatureDescriptor=pDatMan->getActiveDataTable();
746 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getDataSources();
747 aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
749 else if(aURL.Path == C2U("Bib/sdbsource") ||
750 aURL.Path == C2U("Bib/Mapping") ||
751 aURL.Path == C2U("Bib/autoFilter") ||
752 aURL.Path.equalsAscii("Bib/standardFilter"))
754 aEvent.IsEnabled = sal_True;
756 else if(aURL.Path == C2U("Bib/query"))
758 aEvent.IsEnabled = sal_True;
759 aEvent.State <<= pConfig->getQueryText();
761 else if (aURL.Path == C2U("Bib/removeFilter") )
763 rtl::OUString aFilterStr=pDatMan->getFilter();
764 aEvent.IsEnabled = (aFilterStr.getLength() > 0);
766 else if(aURL.Path == C2U("Cut"))
768 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
769 Edit* pEdit = dynamic_cast<Edit*>( pChild );
770 if( pEdit )
771 aEvent.IsEnabled = !pEdit->IsReadOnly() && pEdit->GetSelection().Len();
773 if(aURL.Path == C2U("Copy"))
775 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
776 Edit* pEdit = dynamic_cast<Edit*>( pChild );
777 if( pEdit )
778 aEvent.IsEnabled = pEdit->GetSelection().Len() > 0;
780 else if(aURL.Path == C2U("Paste") )
782 aEvent.IsEnabled = sal_False;
783 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
784 if(pChild)
786 uno::Reference< datatransfer::clipboard::XClipboard > xClip = pChild->GetClipboard();
787 if(xClip.is())
789 uno::Reference< datatransfer::XTransferable > xDataObj;
790 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
793 xDataObj = xClip->getContents();
795 catch( const uno::Exception& )
798 Application::AcquireSolarMutex( nRef );
800 if ( xDataObj.is() )
802 datatransfer::DataFlavor aFlavor;
803 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
806 uno::Any aData = xDataObj->getTransferData( aFlavor );
807 ::rtl::OUString aText;
808 aData >>= aText;
809 aEvent.IsEnabled = aText.getLength() > 0;
811 catch( const uno::Exception& )
816 uno::Reference< datatransfer::XTransferable > xContents = xClip->getContents( );
819 else if(aURL.Path == C2U("Bib/DeleteRecord"))
821 Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY);
822 Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
823 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
824 sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
825 if(!bIsNew)
827 sal_uInt32 nCount = 0;
828 xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
829 aEvent.IsEnabled = nCount > 0;
832 else if (aURL.Path == C2U("Bib/InsertRecord"))
834 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
835 aEvent.IsEnabled = canInsertRecords(xSet);
837 aListener->statusChanged( aEvent );
839 //-----------------------------------------------------------------------------
840 void BibFrameController_Impl::removeStatusListener(
841 const uno::Reference< frame::XStatusListener > & aObject, const util::URL& aURL)
842 throw (::com::sun::star::uno::RuntimeException)
844 // search listener array for given listener
845 // for checking equality always "cast" to XInterface
846 if ( !bDisposing )
848 sal_uInt16 nCount = aStatusListeners.Count();
849 for ( sal_uInt16 n=0; n<nCount; n++ )
851 BibStatusDispatch *pObj = aStatusListeners[n];
852 sal_Bool bFlag=pObj->xListener.is();
853 if (!bFlag || (pObj->xListener == aObject &&
854 ( !aURL.Complete.getLength() || pObj->aURL.Path == aURL.Path )))
856 aStatusListeners.DeleteAndDestroy( n );
857 break;
862 //-----------------------------------------------------------------------------
863 void BibFrameController_Impl::RemoveFilter()
865 rtl::OUString aQuery;
866 pDatMan->startQueryWith(aQuery);
868 sal_uInt16 nCount = aStatusListeners.Count();
870 sal_Bool bRemoveFilter=sal_False;
871 sal_Bool bQueryText=sal_False;
873 for ( sal_uInt16 n=0; n<nCount; n++ )
875 BibStatusDispatch *pObj = aStatusListeners[n];
876 if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
878 FeatureStateEvent aEvent;
879 aEvent.FeatureURL = pObj->aURL;
880 aEvent.IsEnabled = sal_False;
881 aEvent.Requery = sal_False;
882 aEvent.Source = (XDispatch *) this;
883 pObj->xListener->statusChanged( aEvent );
884 bRemoveFilter=sal_True;
886 else if(pObj->aURL.Path == C2U("Bib/query"))
888 FeatureStateEvent aEvent;
889 aEvent.FeatureURL = pObj->aURL;
890 aEvent.IsEnabled = sal_True;
891 aEvent.Requery = sal_False;
892 aEvent.Source = (XDispatch *) this;
893 aEvent.State <<= aQuery;
894 pObj->xListener->statusChanged( aEvent );
895 bQueryText=sal_True;
898 if(bRemoveFilter && bQueryText)
899 break;
903 //-----------------------------------------------------------------------------
904 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs)
906 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
907 uno::Any aValue=pPropertyValue[0].Value;
908 rtl::OUString aDBTableName;
909 aValue >>= aDBTableName;
912 if(aArgs.getLength() > 1)
914 uno::Any aDB = pPropertyValue[1].Value;
915 rtl::OUString aURL;
916 aDB >>= aURL;
917 pDatMan->setActiveDataSource(aURL);
918 aDBTableName = pDatMan->getActiveDataTable();
920 else
922 m_xDatMan->unload();
923 pDatMan->setActiveDataTable(aDBTableName);
924 pDatMan->updateGridModel();
925 m_xDatMan->load();
929 sal_uInt16 nCount = aStatusListeners.Count();
931 sal_Bool bMenuFilter=sal_False;
932 sal_Bool bQueryText=sal_False;
933 for ( sal_uInt16 n=0; n<nCount; n++ )
935 BibStatusDispatch *pObj = aStatusListeners[n];
936 if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/MenuFilter"))
938 FeatureStateEvent aEvent;
939 aEvent.FeatureURL = pObj->aURL;
940 aEvent.IsEnabled = sal_True;
941 aEvent.Requery = sal_False;
942 aEvent.Source = (XDispatch *) this;
943 aEvent.FeatureDescriptor=pDatMan->getQueryField();
945 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
946 aEvent.State = makeAny( aStringSeq );
948 pObj->xListener->statusChanged( aEvent );
949 bMenuFilter=sal_True;
951 else if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/query"))
953 FeatureStateEvent aEvent;
954 aEvent.FeatureURL = pObj->aURL;
955 aEvent.IsEnabled = sal_True;
956 aEvent.Requery = sal_False;
957 aEvent.Source = (XDispatch *) this;
958 BibConfig* pConfig = BibModul::GetConfig();
959 aEvent.State <<= pConfig->getQueryText();
960 pObj->xListener->statusChanged( aEvent );
961 bQueryText=sal_True;
964 if (bMenuFilter && bQueryText)
965 break;
970 void BibFrameController_Impl::activate()
973 void BibFrameController_Impl::deactivate()