Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / extensions / source / bibliography / framectr.cxx
blobeb0998e581fc1b699ad8f7ebe582408a852c61db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/waitobj.hxx>
21 #include <cppuhelper/interfacecontainer.hxx>
22 #include <com/sun/star/util/URL.hpp>
23 #include <vcl/msgbox.hxx>
24 #include <tools/debug.hxx>
25 #include <vcl/stdtext.hxx>
26 #include <comphelper/types.hxx>
27 #include <comphelper/sequence.hxx>
28 #include "framectr.hxx"
29 #include "datman.hxx"
30 #include "bibresid.hxx"
31 #include "bib.hrc"
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include "bibconfig.hxx"
34 #include <cppuhelper/implbase1.hxx> // helper for implementations
35 #include <vcl/svapp.hxx>
36 #include "bibliography.hrc"
37 #include <comphelper/processfactory.hxx>
38 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
39 #include <com/sun/star/form/runtime/XFormController.hpp>
40 #include <com/sun/star/beans/PropertyState.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
43 #include <com/sun/star/sdbcx/Privilege.hpp>
44 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
45 #include <com/sun/star/sdb/RowChangeAction.hpp>
46 #include <com/sun/star/frame/CommandGroup.hpp>
47 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
48 #include <sot/exchange.hxx>
49 #include <sot/formats.hxx>
50 #include <vcl/edit.hxx>
51 #include <osl/mutex.hxx>
53 #include <boost/unordered_map.hpp>
55 using namespace osl;
56 using namespace cppu;
57 using namespace com::sun::star::sdbc;
58 using namespace com::sun::star::frame;
59 using namespace com::sun::star::uno;
60 using namespace com::sun::star;
62 using ::rtl::OUString;
64 #define C2U(cChar) OUString::createFromAscii(cChar)
66 struct DispatchInfo
68 const char* pCommand;
69 sal_Int16 nGroupId;
70 sal_Bool bActiveConnection;
73 struct CacheDispatchInfo
75 sal_Int16 nGroupId;
76 sal_Bool bActiveConnection;
79 // Attention: commands must be sorted by command groups. Implementation is dependent
80 // on this!!
81 static DispatchInfo SupportedCommandsArray[] =
83 { ".uno:Undo" , frame::CommandGroup::EDIT , sal_False },
84 { ".uno:Cut" , frame::CommandGroup::EDIT , sal_False },
85 { ".uno:Copy" , frame::CommandGroup::EDIT , sal_False },
86 { ".uno:Paste" , frame::CommandGroup::EDIT , sal_False },
87 { ".uno:SelectAll" , frame::CommandGroup::EDIT , sal_False },
88 { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT , sal_False },
89 { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW , sal_False },
90 { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW , sal_False },
91 { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA , sal_True },
92 { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA , sal_True },
93 { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA , sal_True },
94 { ".uno:Bib/query" , frame::CommandGroup::DATA , sal_True },
95 { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA , sal_True },
96 { ".uno:Bib/source" , frame::CommandGroup::DATA , sal_True },
97 { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA , sal_True },
98 { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA , sal_True },
99 { ".uno:Bib/Mapping" , frame::CommandGroup::DATA , sal_True },
100 { 0 , 0 , sal_False }
103 typedef ::boost::unordered_map< ::rtl::OUString, CacheDispatchInfo, rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CmdToInfoCache;
105 const CmdToInfoCache& GetCommandToInfoCache()
107 static sal_Bool bCacheInitialized = sal_False;
108 static CmdToInfoCache aCmdToInfoCache;
110 if ( !bCacheInitialized )
112 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
113 if ( !bCacheInitialized )
115 sal_Int32 i( 0 );
116 while ( SupportedCommandsArray[i].pCommand != 0 )
118 rtl::OUString aCommand( rtl::OUString::createFromAscii( SupportedCommandsArray[i].pCommand ));
120 CacheDispatchInfo aDispatchInfo;
121 aDispatchInfo.nGroupId = SupportedCommandsArray[i].nGroupId;
122 aDispatchInfo.bActiveConnection = SupportedCommandsArray[i].bActiveConnection;
123 aCmdToInfoCache.insert( CmdToInfoCache::value_type( aCommand, aDispatchInfo ));
124 ++i;
126 bCacheInitialized = sal_True;
130 return aCmdToInfoCache;
134 class BibFrameCtrl_Impl : public cppu::WeakImplHelper1 < XFrameActionListener >
136 public:
137 Mutex aMutex;
138 OMultiTypeInterfaceContainerHelper aLC;
140 BibFrameController_Impl* pController;
142 BibFrameCtrl_Impl()
143 : aLC( aMutex )
144 , pController(0)
147 ~BibFrameCtrl_Impl();
149 virtual void SAL_CALL frameAction(const FrameActionEvent& aEvent) throw( RuntimeException );
150 virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
154 BibFrameCtrl_Impl::~BibFrameCtrl_Impl()
158 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent& aEvent) throw( uno::RuntimeException )
160 if ( pController && aEvent.Frame == pController->getFrame())
162 if(aEvent.Action == FrameAction_FRAME_ACTIVATED)
164 pController->activate();
166 else if(aEvent.Action == FrameAction_FRAME_DEACTIVATING)
168 pController->deactivate();
173 void BibFrameCtrl_Impl::disposing( const lang::EventObject& /*Source*/ )
174 throw (::com::sun::star::uno::RuntimeException)
176 ::SolarMutexGuard aGuard;
177 if ( pController )
178 pController->getFrame()->removeFrameActionListener( this );
181 BibFrameController_Impl::BibFrameController_Impl( const uno::Reference< awt::XWindow > & xComponent,
182 BibDataManager* pDataManager)
183 :xWindow( xComponent )
184 ,m_xDatMan( pDataManager )
185 ,pDatMan( pDataManager )
186 ,pBibMod(NULL)
188 Window* pParent = VCLUnoHelper::GetWindow( xWindow );
189 pParent->SetUniqueId(UID_BIB_FRAME_WINDOW);
190 bDisposing=sal_False;
191 bHierarchical=sal_True;
192 pImp = new BibFrameCtrl_Impl;
193 pImp->pController = this;
194 pImp->acquire();
197 BibFrameController_Impl::~BibFrameController_Impl()
199 pImp->pController = NULL;
200 pImp->release();
201 delete pDatMan;
202 if(pBibMod)
203 CloseBibModul(pBibMod);
206 ::rtl::OUString SAL_CALL BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException)
208 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.extensions.Bibliography"));
211 sal_Bool SAL_CALL BibFrameController_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (::com::sun::star::uno::RuntimeException)
213 return ( sServiceName == "com.sun.star.frame.Bibliography" || sServiceName == "com.sun.star.frame.Controller" );
216 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException)
218 // return only top level services ...
219 // base services are included there and should be asked by uno-rtti.
220 ::com::sun::star::uno::Sequence< ::rtl::OUString > lNames(1);
221 lNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Bibliography"));
222 return lNames;
225 void BibFrameController_Impl::attachFrame( const uno::Reference< XFrame > & xArg ) throw (::com::sun::star::uno::RuntimeException)
227 xFrame = xArg;
228 xFrame->addFrameActionListener( pImp );
231 sal_Bool BibFrameController_Impl::attachModel( const uno::Reference< XModel > & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException)
233 return sal_False;
236 sal_Bool BibFrameController_Impl::suspend( sal_Bool bSuspend ) throw (::com::sun::star::uno::RuntimeException)
238 if ( bSuspend )
239 getFrame()->removeFrameActionListener( pImp );
240 else
241 getFrame()->addFrameActionListener( pImp );
242 return sal_True;
245 uno::Any BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException)
247 return uno::Any();
250 void BibFrameController_Impl::restoreViewData( const uno::Any& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException)
254 uno::Reference< XFrame > BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException)
256 return xFrame;
259 uno::Reference< XModel > BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException)
261 return uno::Reference< XModel > ();
264 void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException)
266 bDisposing = sal_True;
267 lang::EventObject aObject;
268 aObject.Source = (XController*)this;
269 pImp->aLC.disposeAndClear(aObject);
270 m_xDatMan = 0;
271 pDatMan = 0;
272 aStatusListeners.clear();
275 void BibFrameController_Impl::addEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
277 pImp->aLC.addInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
280 void BibFrameController_Impl::removeEventListener( const uno::Reference< lang::XEventListener > & aListener ) throw (::com::sun::star::uno::RuntimeException)
282 pImp->aLC.removeInterface( ::getCppuType((const Reference< lang::XEventListener >*)0), aListener );
285 uno::Reference< frame::XDispatch > BibFrameController_Impl::queryDispatch( const util::URL& aURL, const rtl::OUString& /*aTarget*/, sal_Int32 /*nSearchFlags*/ ) throw (::com::sun::star::uno::RuntimeException)
287 if ( !bDisposing )
289 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
290 CmdToInfoCache::const_iterator pIter = rCmdCache.find( aURL.Complete );
291 if ( pIter != rCmdCache.end() )
293 if (( pDatMan->HasActiveConnection() ) ||
294 ( !pIter->second.bActiveConnection ))
295 return (frame::XDispatch*) this;
299 return uno::Reference< frame::XDispatch > ();
302 uno::Sequence<uno::Reference< XDispatch > > BibFrameController_Impl::queryDispatches( const uno::Sequence<DispatchDescriptor>& aDescripts ) throw (::com::sun::star::uno::RuntimeException)
304 uno::Sequence< uno::Reference< XDispatch > > aDispatches( aDescripts.getLength() );
305 for ( sal_Int32 i=0; i<aDescripts.getLength(); ++i )
306 aDispatches[i] = queryDispatch( aDescripts[i].FeatureURL, aDescripts[i].FrameName, aDescripts[i].SearchFlags );
307 return aDispatches;
310 uno::Sequence< ::sal_Int16 > SAL_CALL BibFrameController_Impl::getSupportedCommandGroups()
311 throw (::com::sun::star::uno::RuntimeException)
313 uno::Sequence< ::sal_Int16 > aDispatchInfo( 4 );
315 aDispatchInfo[0] = frame::CommandGroup::EDIT;
316 aDispatchInfo[1] = frame::CommandGroup::DOCUMENT;
317 aDispatchInfo[2] = frame::CommandGroup::DATA;
318 aDispatchInfo[3] = frame::CommandGroup::VIEW;
320 return aDispatchInfo;
323 uno::Sequence< frame::DispatchInformation > SAL_CALL BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup )
324 throw (::com::sun::star::uno::RuntimeException)
326 const CmdToInfoCache& rCmdCache = GetCommandToInfoCache();
328 sal_Bool bGroupFound( sal_False );
329 frame::DispatchInformation aDispatchInfo;
330 std::list< frame::DispatchInformation > aDispatchInfoList;
332 if (( nCommandGroup == frame::CommandGroup::EDIT ) ||
333 ( nCommandGroup == frame::CommandGroup::DOCUMENT ) ||
334 ( nCommandGroup == frame::CommandGroup::DATA ) ||
335 ( nCommandGroup == frame::CommandGroup::VIEW ))
337 CmdToInfoCache::const_iterator pIter = rCmdCache.begin();
338 while ( pIter != rCmdCache.end() )
340 if ( pIter->second.nGroupId == nCommandGroup )
342 bGroupFound = sal_True;
343 aDispatchInfo.Command = pIter->first;
344 aDispatchInfo.GroupId = pIter->second.nGroupId;
345 aDispatchInfoList.push_back( aDispatchInfo );
347 else if ( bGroupFound )
348 break;
350 ++pIter;
354 ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
355 comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aDispatchInfoList );
357 return aSeq;
360 sal_Bool canInsertRecords(const Reference< beans::XPropertySet>& _rxCursorSet)
362 sal_Int32 nPriv = 0;
363 _rxCursorSet->getPropertyValue(C2U("Privileges")) >>= nPriv;
364 return ((_rxCursorSet.is() && (nPriv & sdbcx::Privilege::INSERT) != 0));
367 sal_Bool BibFrameController_Impl::SaveModified(const Reference< form::runtime::XFormController>& xController)
369 if (!xController.is())
370 return sal_False;
372 Reference< XResultSetUpdate> _xCursor = Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY);
374 if (!_xCursor.is())
375 return sal_False;
377 Reference< beans::XPropertySet> _xSet = Reference< beans::XPropertySet>(_xCursor, UNO_QUERY);
378 if (!_xSet.is())
379 return sal_False;
381 // need to save?
382 sal_Bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsNew")));
383 sal_Bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue(C2U("IsModified")));
384 sal_Bool bResult = !bIsModified;
385 if (bIsModified)
389 if (bIsNew)
390 _xCursor->insertRow();
391 else
392 _xCursor->updateRow();
393 bResult = sal_True;
395 catch(const Exception&)
397 OSL_FAIL("SaveModified: Exception occurred!");
400 return bResult;
403 static Window* lcl_GetFocusChild( Window* pParent )
405 sal_uInt16 nChildren = pParent->GetChildCount();
406 for( sal_uInt16 nChild = 0; nChild < nChildren; ++nChild)
408 Window* pChild = pParent->GetChild( nChild );
409 if(pChild->HasFocus())
410 return pChild;
411 Window* pSubChild = lcl_GetFocusChild( pChild );
412 if(pSubChild)
413 return pSubChild;
415 return 0;
418 //class XDispatch
419 void BibFrameController_Impl::dispatch(const util::URL& _rURL, const uno::Sequence< beans::PropertyValue >& aArgs) throw (::com::sun::star::uno::RuntimeException)
421 if ( !bDisposing )
423 ::SolarMutexGuard aGuard;
424 Window* pParent = VCLUnoHelper::GetWindow( xWindow );
425 WaitObject aWaitObject( pParent );
427 String aCommand( _rURL.Path);
428 if(aCommand.EqualsAscii("Bib/Mapping"))
430 pDatMan->CreateMappingDialog(pParent);
432 else if(aCommand.EqualsAscii("Bib/source"))
434 ChangeDataSource(aArgs);
436 else if(aCommand.EqualsAscii("Bib/sdbsource"))
438 rtl::OUString aURL = pDatMan->CreateDBChangeDialog(pParent);
439 if(!aURL.isEmpty())
443 uno::Sequence< beans::PropertyValue > aNewDataSource(2);
444 beans::PropertyValue* pProps = aNewDataSource.getArray();
445 pProps[0].Value <<= rtl::OUString();
446 pProps[1].Value <<= aURL;
447 ChangeDataSource(aNewDataSource);
449 catch(const Exception&)
451 OSL_FAIL("Exception catched while changing the data source");
455 else if(aCommand.EqualsAscii("Bib/autoFilter"))
457 sal_uInt16 nCount = aStatusListeners.size();
458 for ( sal_uInt16 n=0; n<nCount; n++ )
460 BibStatusDispatch *pObj = &aStatusListeners[n];
461 if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
463 FeatureStateEvent aEvent;
464 aEvent.FeatureURL = pObj->aURL;
465 aEvent.IsEnabled = sal_True;
466 aEvent.Requery = sal_False;
467 aEvent.Source = (XDispatch *) this;
468 pObj->xListener->statusChanged( aEvent );
469 //break; because there are more than one
473 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
474 uno::Any aValue=pPropertyValue[0].Value;
475 rtl::OUString aQuery;
476 aValue >>= aQuery;
478 aValue=pPropertyValue[1].Value;
479 rtl::OUString aQueryField;
480 aValue >>= aQueryField;
481 BibConfig* pConfig = BibModul::GetConfig();
482 pConfig->setQueryField(aQueryField);
483 pDatMan->startQueryWith(aQuery);
485 else if(aCommand.EqualsAscii("Bib/standardFilter"))
489 uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
491 // build the arguments for the filter dialog to be created
492 Sequence< Any > aDialogCreationArgs( 3 );
493 Any* pDialogCreationArgs = aDialogCreationArgs.getArray();
494 // the query composer
495 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "QueryComposer" )),
497 makeAny( pDatMan->getParser() ),
498 beans::PropertyState_DIRECT_VALUE
501 // the rowset
502 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowSet" )),
504 makeAny( pDatMan->getForm() ),
505 beans::PropertyState_DIRECT_VALUE
507 // the parent window for the dialog
508 *pDialogCreationArgs++ <<= beans::PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" )),
510 makeAny( xWindow ),
511 beans::PropertyState_DIRECT_VALUE
514 // create the dialog object
515 const ::rtl::OUString sDialogServiceName(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FilterDialog" ));
516 uno::Reference< uno::XInterface > xDialog = xORB->createInstanceWithArguments(
517 sDialogServiceName,
518 aDialogCreationArgs
520 if ( !xDialog.is() )
522 ShowServiceNotAvailableError( VCLUnoHelper::GetWindow( xWindow ), sDialogServiceName, sal_True );
524 else
526 // execute it
527 uno::Reference< ui::dialogs::XExecutableDialog > xExec( xDialog, UNO_QUERY );
528 DBG_ASSERT( xExec.is(), "BibFrameController_Impl::dispatch: missing an interface on the dialog!" );
529 if ( xExec.is() )
530 if ( xExec->execute( ) )
532 // the dialog has been executed successfully, and the filter on the query composer
533 // has been changed
534 ::rtl::OUString sNewFilter = pDatMan->getParser()->getFilter();
535 pDatMan->setFilter( sNewFilter );
539 catch( const uno::Exception& )
541 OSL_FAIL( "BibFrameController_Impl::dispatch: caught an exception!" );
544 sal_uInt16 nCount = aStatusListeners.size();
545 for ( sal_uInt16 n=0; n<nCount; n++ )
547 BibStatusDispatch *pObj = &aStatusListeners[n];
548 if ( pObj->aURL.Path == C2U("Bib/removeFilter") && pDatMan->getParser().is())
550 FeatureStateEvent aEvent;
551 aEvent.FeatureURL = pObj->aURL;
552 aEvent.IsEnabled = !pDatMan->getParser()->getFilter().isEmpty();
553 aEvent.Requery = sal_False;
554 aEvent.Source = (XDispatch *) this;
555 pObj->xListener->statusChanged( aEvent );
559 else if(aCommand.EqualsAscii("Bib/removeFilter"))
561 RemoveFilter();
563 else if( _rURL.Complete == "slot:5503" || aCommand.EqualsAscii("CloseDoc") )
565 Application::PostUserEvent( STATIC_LINK( this, BibFrameController_Impl,
566 DisposeHdl ), 0 );
569 else if(aCommand.EqualsAscii("Bib/InsertRecord"))
571 Reference<form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
572 if(SaveModified(xFormCtrl))
576 Reference< sdbc::XResultSet > xCursor( pDatMan->getForm(), UNO_QUERY );
577 xCursor->last();
579 Reference< XResultSetUpdate > xUpdateCursor( pDatMan->getForm(), UNO_QUERY );
580 xUpdateCursor->moveToInsertRow();
582 catch(const Exception&)
584 OSL_FAIL("Exception in last() or moveToInsertRow()");
588 else if(aCommand.EqualsAscii("Bib/DeleteRecord"))
590 Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY);
591 Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
592 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
593 sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
594 if(!bIsNew)
596 sal_uInt32 nCount = 0;
597 xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
598 // naechste position festellen
599 sal_Bool bSuccess = sal_False;
600 sal_Bool bLeft = sal_False;
601 sal_Bool bRight = sal_False;
604 bLeft = xCursor->isLast() && nCount > 1;
605 bRight= !xCursor->isLast();
606 // ask for confirmation
607 Reference< frame::XController > xCtrl = pImp->pController;
608 Reference< form::XConfirmDeleteListener > xConfirm(pDatMan->GetFormController(),UNO_QUERY);
609 if (xConfirm.is())
611 sdb::RowChangeEvent aEvent;
612 aEvent.Source = Reference< XInterface > (xCursor, UNO_QUERY);
613 aEvent.Action = sdb::RowChangeAction::DELETE;
614 aEvent.Rows = 1;
615 bSuccess = xConfirm->confirmDelete(aEvent);
618 // das Ding loeschen
619 if (bSuccess)
620 xUpdateCursor->deleteRow();
622 catch(const Exception&)
624 bSuccess = sal_False;
626 if (bSuccess)
628 if (bLeft || bRight)
629 xCursor->relative(bRight ? 1 : -1);
630 else
632 sal_Bool bCanInsert = canInsertRecords(xSet);
633 // kann noch ein Datensatz eingefuegt weden
636 if (bCanInsert)
637 xUpdateCursor->moveToInsertRow();
638 else
639 // Datensatz bewegen um Stati neu zu setzen
640 xCursor->first();
642 catch(const Exception&)
644 OSL_FAIL("DeleteRecord : exception caught !");
650 else if(aCommand.EqualsAscii("Cut"))
652 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
653 if(pChild)
655 KeyEvent aEvent( 0, KEYFUNC_CUT );
656 pChild->KeyInput( aEvent );
659 else if(aCommand.EqualsAscii("Copy"))
661 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
662 if(pChild)
664 KeyEvent aEvent( 0, KEYFUNC_COPY );
665 pChild->KeyInput( aEvent );
668 else if(aCommand.EqualsAscii("Paste"))
670 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
671 if(pChild)
673 KeyEvent aEvent( 0, KEYFUNC_PASTE );
674 pChild->KeyInput( aEvent );
679 IMPL_STATIC_LINK( BibFrameController_Impl, DisposeHdl, void*, EMPTYARG )
681 pThis->xFrame->dispose();
682 return 0;
685 //-----------------------------------------------------------------------------
686 void BibFrameController_Impl::addStatusListener(
687 const uno::Reference< frame::XStatusListener > & aListener,
688 const util::URL& aURL)
689 throw (::com::sun::star::uno::RuntimeException)
691 BibConfig* pConfig = BibModul::GetConfig();
692 // create a new Reference and insert into listener array
693 aStatusListeners.push_back( new BibStatusDispatch( aURL, aListener ) );
695 // den ersten Status synchron zusenden
696 FeatureStateEvent aEvent;
697 aEvent.FeatureURL = aURL;
698 aEvent.Requery = sal_False;
699 aEvent.Source = (XDispatch *) this;
700 if ( aURL.Path == C2U("StatusBarVisible") )
702 aEvent.IsEnabled = sal_False;
703 aEvent.State <<= sal_Bool( sal_False );
705 else if ( aURL.Path == C2U("Bib/hierarchical") )
707 aEvent.IsEnabled = sal_True;
708 const char* pHier = bHierarchical? "" : "*" ;
709 aEvent.State <<= rtl::OUString::createFromAscii(pHier);
711 else if(aURL.Path == C2U("Bib/MenuFilter"))
713 aEvent.IsEnabled = sal_True;
714 aEvent.FeatureDescriptor=pDatMan->getQueryField();
716 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
717 aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
720 else if ( aURL.Path == C2U("Bib/source"))
722 aEvent.IsEnabled = sal_True;
723 aEvent.FeatureDescriptor=pDatMan->getActiveDataTable();
725 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getDataSources();
726 aEvent.State.setValue(&aStringSeq,::getCppuType((uno::Sequence<rtl::OUString>*)0));
728 else if( aURL.Path == "Bib/sdbsource" ||
729 aURL.Path == "Bib/Mapping" ||
730 aURL.Path == "Bib/autoFilter" ||
731 aURL.Path == "Bib/standardFilter" )
733 aEvent.IsEnabled = sal_True;
735 else if(aURL.Path == C2U("Bib/query"))
737 aEvent.IsEnabled = sal_True;
738 aEvent.State <<= pConfig->getQueryText();
740 else if (aURL.Path == C2U("Bib/removeFilter") )
742 rtl::OUString aFilterStr=pDatMan->getFilter();
743 aEvent.IsEnabled = !aFilterStr.isEmpty();
745 else if(aURL.Path == C2U("Cut"))
747 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
748 Edit* pEdit = dynamic_cast<Edit*>( pChild );
749 if( pEdit )
750 aEvent.IsEnabled = !pEdit->IsReadOnly() && pEdit->GetSelection().Len();
752 if(aURL.Path == C2U("Copy"))
754 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
755 Edit* pEdit = dynamic_cast<Edit*>( pChild );
756 if( pEdit )
757 aEvent.IsEnabled = pEdit->GetSelection().Len() > 0;
759 else if(aURL.Path == C2U("Paste") )
761 aEvent.IsEnabled = sal_False;
762 Window* pChild = lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow ) );
763 if(pChild)
765 uno::Reference< datatransfer::clipboard::XClipboard > xClip = pChild->GetClipboard();
766 if(xClip.is())
768 uno::Reference< datatransfer::XTransferable > xDataObj;
769 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
772 xDataObj = xClip->getContents();
774 catch( const uno::Exception& )
777 Application::AcquireSolarMutex( nRef );
779 if ( xDataObj.is() )
781 datatransfer::DataFlavor aFlavor;
782 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
785 uno::Any aData = xDataObj->getTransferData( aFlavor );
786 ::rtl::OUString aText;
787 aData >>= aText;
788 aEvent.IsEnabled = !aText.isEmpty();
790 catch( const uno::Exception& )
795 uno::Reference< datatransfer::XTransferable > xContents = xClip->getContents( );
798 else if(aURL.Path == C2U("Bib/DeleteRecord"))
800 Reference< ::com::sun::star::sdbc::XResultSet > xCursor(pDatMan->getForm(), UNO_QUERY);
801 Reference< XResultSetUpdate > xUpdateCursor(xCursor, UNO_QUERY);
802 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
803 sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(C2U("IsNew")));
804 if(!bIsNew)
806 sal_uInt32 nCount = 0;
807 xSet->getPropertyValue(C2U("RowCount")) >>= nCount;
808 aEvent.IsEnabled = nCount > 0;
811 else if (aURL.Path == C2U("Bib/InsertRecord"))
813 Reference< beans::XPropertySet > xSet(pDatMan->getForm(), UNO_QUERY);
814 aEvent.IsEnabled = canInsertRecords(xSet);
816 aListener->statusChanged( aEvent );
818 //-----------------------------------------------------------------------------
819 void BibFrameController_Impl::removeStatusListener(
820 const uno::Reference< frame::XStatusListener > & aObject, const util::URL& aURL)
821 throw (::com::sun::star::uno::RuntimeException)
823 // search listener array for given listener
824 // for checking equality always "cast" to XInterface
825 if ( !bDisposing )
827 sal_uInt16 nCount = aStatusListeners.size();
828 for ( sal_uInt16 n=0; n<nCount; n++ )
830 BibStatusDispatch *pObj = &aStatusListeners[n];
831 sal_Bool bFlag=pObj->xListener.is();
832 if (!bFlag || (pObj->xListener == aObject &&
833 ( aURL.Complete.isEmpty() || pObj->aURL.Path == aURL.Path )))
835 aStatusListeners.erase( aStatusListeners.begin() + n );
836 break;
841 //-----------------------------------------------------------------------------
842 void BibFrameController_Impl::RemoveFilter()
844 rtl::OUString aQuery;
845 pDatMan->startQueryWith(aQuery);
847 sal_uInt16 nCount = aStatusListeners.size();
849 sal_Bool bRemoveFilter=sal_False;
850 sal_Bool bQueryText=sal_False;
852 for ( sal_uInt16 n=0; n<nCount; n++ )
854 BibStatusDispatch *pObj = &aStatusListeners[n];
855 if ( pObj->aURL.Path == C2U("Bib/removeFilter") )
857 FeatureStateEvent aEvent;
858 aEvent.FeatureURL = pObj->aURL;
859 aEvent.IsEnabled = sal_False;
860 aEvent.Requery = sal_False;
861 aEvent.Source = (XDispatch *) this;
862 pObj->xListener->statusChanged( aEvent );
863 bRemoveFilter=sal_True;
865 else if(pObj->aURL.Path == C2U("Bib/query"))
867 FeatureStateEvent aEvent;
868 aEvent.FeatureURL = pObj->aURL;
869 aEvent.IsEnabled = sal_True;
870 aEvent.Requery = sal_False;
871 aEvent.Source = (XDispatch *) this;
872 aEvent.State <<= aQuery;
873 pObj->xListener->statusChanged( aEvent );
874 bQueryText=sal_True;
877 if(bRemoveFilter && bQueryText)
878 break;
882 //-----------------------------------------------------------------------------
883 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence< beans::PropertyValue >& aArgs)
885 const beans::PropertyValue* pPropertyValue = aArgs.getConstArray();
886 uno::Any aValue=pPropertyValue[0].Value;
887 rtl::OUString aDBTableName;
888 aValue >>= aDBTableName;
891 if(aArgs.getLength() > 1)
893 uno::Any aDB = pPropertyValue[1].Value;
894 rtl::OUString aURL;
895 aDB >>= aURL;
896 pDatMan->setActiveDataSource(aURL);
897 aDBTableName = pDatMan->getActiveDataTable();
899 else
901 m_xDatMan->unload();
902 pDatMan->setActiveDataTable(aDBTableName);
903 pDatMan->updateGridModel();
904 m_xDatMan->load();
908 sal_uInt16 nCount = aStatusListeners.size();
910 sal_Bool bMenuFilter=sal_False;
911 sal_Bool bQueryText=sal_False;
912 for ( sal_uInt16 n=0; n<nCount; n++ )
914 BibStatusDispatch *pObj = &aStatusListeners[n];
915 if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/MenuFilter"))
917 FeatureStateEvent aEvent;
918 aEvent.FeatureURL = pObj->aURL;
919 aEvent.IsEnabled = sal_True;
920 aEvent.Requery = sal_False;
921 aEvent.Source = (XDispatch *) this;
922 aEvent.FeatureDescriptor=pDatMan->getQueryField();
924 uno::Sequence<rtl::OUString> aStringSeq=pDatMan->getQueryFields();
925 aEvent.State = makeAny( aStringSeq );
927 pObj->xListener->statusChanged( aEvent );
928 bMenuFilter=sal_True;
930 else if(COMPARE_EQUAL == pObj->aURL.Path.compareToAscii("Bib/query"))
932 FeatureStateEvent aEvent;
933 aEvent.FeatureURL = pObj->aURL;
934 aEvent.IsEnabled = sal_True;
935 aEvent.Requery = sal_False;
936 aEvent.Source = (XDispatch *) this;
937 BibConfig* pConfig = BibModul::GetConfig();
938 aEvent.State <<= pConfig->getQueryText();
939 pObj->xListener->statusChanged( aEvent );
940 bQueryText=sal_True;
943 if (bMenuFilter && bQueryText)
944 break;
949 void BibFrameController_Impl::activate()
952 void BibFrameController_Impl::deactivate()
957 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */