1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: framectr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include <vcl/waitobj.hxx>
34 #include <cppuhelper/interfacecontainer.hxx>
35 #include <com/sun/star/util/URL.hpp>
36 #include <osl/mutex.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/stdtext.hxx>
40 #include <comphelper/types.hxx>
41 #include <comphelper/sequence.hxx>
42 #include "framectr.hxx"
44 #include "bibresid.hxx"
48 #ifndef _TOOLKIT_UNOHLP_HXX
49 #include <toolkit/helper/vclunohelper.hxx>
51 #include "bibconfig.hxx"
52 #include <cppuhelper/implbase1.hxx> // helper for implementations
53 #include <vcl/svapp.hxx>
54 #ifndef EXTENSIONS_INC_EXTENSIO_HRC
55 #include <extensio.hrc>
57 #include <comphelper/processfactory.hxx>
58 #include <com/sun/star/form/XConfirmDeleteListener.hpp>
59 #include <com/sun/star/form/XFormController.hpp>
60 #include <com/sun/star/beans/PropertyState.hpp>
61 #include <com/sun/star/beans/PropertyValue.hpp>
62 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
63 #include <com/sun/star/sdbcx/Privilege.hpp>
64 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
65 #include <com/sun/star/sdb/RowChangeAction.hpp>
66 #include <com/sun/star/frame/CommandGroup.hpp>
67 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
68 #include <sot/exchange.hxx>
69 #include <sot/formats.hxx>
70 #include <vcl/edit.hxx>
71 #include <vos/mutex.hxx>
78 using namespace com::sun::star::sdbc
;
79 using namespace com::sun::star::frame
;
80 using namespace com::sun::star::uno
;
81 using namespace com::sun::star
;
83 #define C2U(cChar) OUString::createFromAscii(cChar)
89 sal_Bool bActiveConnection
;
92 struct CacheDispatchInfo
95 sal_Bool bActiveConnection
;
98 // Attention: commands must be sorted by command groups. Implementation is dependent
100 static DispatchInfo SupportedCommandsArray
[] =
102 { ".uno:Undo" , frame::CommandGroup::EDIT
, sal_False
},
103 { ".uno:Cut" , frame::CommandGroup::EDIT
, sal_False
},
104 { ".uno:Copy" , frame::CommandGroup::EDIT
, sal_False
},
105 { ".uno:Paste" , frame::CommandGroup::EDIT
, sal_False
},
106 { ".uno:SelectAll" , frame::CommandGroup::EDIT
, sal_False
},
107 { ".uno:CloseDoc" , frame::CommandGroup::DOCUMENT
, sal_False
},
108 { ".uno:StatusBarVisible" , frame::CommandGroup::VIEW
, sal_False
},
109 { ".uno:AvailableToolbars" , frame::CommandGroup::VIEW
, sal_False
},
110 { ".uno:Bib/standardFilter" , frame::CommandGroup::DATA
, sal_True
},
111 { ".uno:Bib/DeleteRecord" , frame::CommandGroup::DATA
, sal_True
},
112 { ".uno:Bib/InsertRecord" , frame::CommandGroup::DATA
, sal_True
},
113 { ".uno:Bib/query" , frame::CommandGroup::DATA
, sal_True
},
114 { ".uno:Bib/autoFilter" , frame::CommandGroup::DATA
, sal_True
},
115 { ".uno:Bib/source" , frame::CommandGroup::DATA
, sal_True
},
116 { ".uno:Bib/removeFilter" , frame::CommandGroup::DATA
, sal_True
},
117 { ".uno:Bib/sdbsource" , frame::CommandGroup::DATA
, sal_True
},
118 { ".uno:Bib/Mapping" , frame::CommandGroup::DATA
, sal_True
},
119 { 0 , 0 , sal_False
}
122 typedef ::std::hash_map
< ::rtl::OUString
, CacheDispatchInfo
, rtl::OUStringHash
, ::std::equal_to
< ::rtl::OUString
> > CmdToInfoCache
;
124 SV_IMPL_PTRARR( BibStatusDispatchArr
, BibStatusDispatchPtr
);
126 const CmdToInfoCache
& GetCommandToInfoCache()
128 static sal_Bool bCacheInitialized
= sal_False
;
129 static CmdToInfoCache aCmdToInfoCache
;
131 if ( !bCacheInitialized
)
133 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
134 if ( !bCacheInitialized
)
137 while ( SupportedCommandsArray
[i
].pCommand
!= 0 )
139 rtl::OUString
aCommand( rtl::OUString::createFromAscii( SupportedCommandsArray
[i
].pCommand
));
141 CacheDispatchInfo aDispatchInfo
;
142 aDispatchInfo
.nGroupId
= SupportedCommandsArray
[i
].nGroupId
;
143 aDispatchInfo
.bActiveConnection
= SupportedCommandsArray
[i
].bActiveConnection
;
144 aCmdToInfoCache
.insert( CmdToInfoCache::value_type( aCommand
, aDispatchInfo
));
147 bCacheInitialized
= sal_True
;
151 return aCmdToInfoCache
;
155 class BibFrameCtrl_Impl
: public cppu::WeakImplHelper1
< XFrameActionListener
>
159 OMultiTypeInterfaceContainerHelper aLC
;
161 BibFrameController_Impl
* pController
;
168 ~BibFrameCtrl_Impl();
170 virtual void SAL_CALL
frameAction(const FrameActionEvent
& aEvent
) throw( RuntimeException
);
171 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
175 BibFrameCtrl_Impl::~BibFrameCtrl_Impl()
179 void BibFrameCtrl_Impl::frameAction(const FrameActionEvent
& aEvent
) throw( uno::RuntimeException
)
181 if ( pController
&& aEvent
.Frame
== pController
->getFrame())
183 if(aEvent
.Action
== FrameAction_FRAME_ACTIVATED
)
185 pController
->activate();
187 else if(aEvent
.Action
== FrameAction_FRAME_DEACTIVATING
)
189 pController
->deactivate();
194 void BibFrameCtrl_Impl::disposing( const lang::EventObject
& /*Source*/ )
195 throw (::com::sun::star::uno::RuntimeException
)
197 vos::OGuard
aGuard(Application::GetSolarMutex());
199 pController
->getFrame()->removeFrameActionListener( this );
202 BibFrameController_Impl::BibFrameController_Impl( const uno::Reference
< awt::XWindow
> & xComponent
,
203 BibDataManager
* pDataManager
)
204 :xWindow( xComponent
)
205 ,m_xDatMan( pDataManager
)
206 ,pDatMan( pDataManager
)
209 Window
* pParent
= VCLUnoHelper::GetWindow( xWindow
);
210 pParent
->SetUniqueId(UID_BIB_FRAME_WINDOW
);
211 bDisposing
=sal_False
;
212 bHierarchical
=sal_True
;
213 pImp
= new BibFrameCtrl_Impl
;
214 pImp
->pController
= this;
218 BibFrameController_Impl::~BibFrameController_Impl()
220 pImp
->pController
= NULL
;
224 CloseBibModul(pBibMod
);
227 ::rtl::OUString SAL_CALL
BibFrameController_Impl::getImplementationName() throw (::com::sun::star::uno::RuntimeException
)
229 return ::rtl::OUString::createFromAscii("com.sun.star.comp.extensions.Bibliography");
232 sal_Bool SAL_CALL
BibFrameController_Impl::supportsService( const ::rtl::OUString
& sServiceName
) throw (::com::sun::star::uno::RuntimeException
)
235 sServiceName
.equalsAscii("com.sun.star.frame.Bibliography") ||
236 sServiceName
.equalsAscii("com.sun.star.frame.Controller")
240 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
BibFrameController_Impl::getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException
)
242 // return only top level services ...
243 // base services are included there and should be asked by uno-rtti.
244 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> lNames(1);
245 lNames
[0] = ::rtl::OUString::createFromAscii("com.sun.star.frame.Bibliography");
249 void BibFrameController_Impl::attachFrame( const uno::Reference
< XFrame
> & xArg
) throw (::com::sun::star::uno::RuntimeException
)
252 xFrame
->addFrameActionListener( pImp
);
255 sal_Bool
BibFrameController_Impl::attachModel( const uno::Reference
< XModel
> & /*xModel*/ ) throw (::com::sun::star::uno::RuntimeException
)
260 sal_Bool
BibFrameController_Impl::suspend( sal_Bool bSuspend
) throw (::com::sun::star::uno::RuntimeException
)
263 getFrame()->removeFrameActionListener( pImp
);
265 getFrame()->addFrameActionListener( pImp
);
269 uno::Any
BibFrameController_Impl::getViewData() throw (::com::sun::star::uno::RuntimeException
)
274 void BibFrameController_Impl::restoreViewData( const uno::Any
& /*Value*/ ) throw (::com::sun::star::uno::RuntimeException
)
278 uno::Reference
< XFrame
> BibFrameController_Impl::getFrame() throw (::com::sun::star::uno::RuntimeException
)
283 uno::Reference
< XModel
> BibFrameController_Impl::getModel() throw (::com::sun::star::uno::RuntimeException
)
285 return uno::Reference
< XModel
> ();
288 void BibFrameController_Impl::dispose() throw (::com::sun::star::uno::RuntimeException
)
290 bDisposing
= sal_True
;
291 lang::EventObject aObject
;
292 aObject
.Source
= (XController
*)this;
293 pImp
->aLC
.disposeAndClear(aObject
);
296 aStatusListeners
.DeleteAndDestroy( 0, aStatusListeners
.Count() );
299 void BibFrameController_Impl::addEventListener( const uno::Reference
< lang::XEventListener
> & aListener
) throw (::com::sun::star::uno::RuntimeException
)
301 pImp
->aLC
.addInterface( ::getCppuType((const Reference
< lang::XEventListener
>*)0), aListener
);
304 void BibFrameController_Impl::removeEventListener( const uno::Reference
< lang::XEventListener
> & aListener
) throw (::com::sun::star::uno::RuntimeException
)
306 pImp
->aLC
.removeInterface( ::getCppuType((const Reference
< lang::XEventListener
>*)0), aListener
);
309 uno::Reference
< frame::XDispatch
> BibFrameController_Impl::queryDispatch( const util::URL
& aURL
, const rtl::OUString
& /*aTarget*/, sal_Int32
/*nSearchFlags*/ ) throw (::com::sun::star::uno::RuntimeException
)
313 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
314 CmdToInfoCache::const_iterator pIter
= rCmdCache
.find( aURL
.Complete
);
315 if ( pIter
!= rCmdCache
.end() )
317 if (( pDatMan
->HasActiveConnection() ) ||
318 ( !pIter
->second
.bActiveConnection
))
319 return (frame::XDispatch
*) this;
323 return uno::Reference
< frame::XDispatch
> ();
326 uno::Sequence
<uno::Reference
< XDispatch
> > BibFrameController_Impl::queryDispatches( const uno::Sequence
<DispatchDescriptor
>& aDescripts
) throw (::com::sun::star::uno::RuntimeException
)
328 uno::Sequence
< uno::Reference
< XDispatch
> > aDispatches( aDescripts
.getLength() );
329 for ( sal_Int32 i
=0; i
<aDescripts
.getLength(); ++i
)
330 aDispatches
[i
] = queryDispatch( aDescripts
[i
].FeatureURL
, aDescripts
[i
].FrameName
, aDescripts
[i
].SearchFlags
);
334 uno::Sequence
< ::sal_Int16
> SAL_CALL
BibFrameController_Impl::getSupportedCommandGroups()
335 throw (::com::sun::star::uno::RuntimeException
)
337 uno::Sequence
< ::sal_Int16
> aDispatchInfo( 4 );
339 aDispatchInfo
[0] = frame::CommandGroup::EDIT
;
340 aDispatchInfo
[1] = frame::CommandGroup::DOCUMENT
;
341 aDispatchInfo
[2] = frame::CommandGroup::DATA
;
342 aDispatchInfo
[3] = frame::CommandGroup::VIEW
;
344 return aDispatchInfo
;
347 uno::Sequence
< frame::DispatchInformation
> SAL_CALL
BibFrameController_Impl::getConfigurableDispatchInformation( ::sal_Int16 nCommandGroup
)
348 throw (::com::sun::star::uno::RuntimeException
)
350 const CmdToInfoCache
& rCmdCache
= GetCommandToInfoCache();
352 sal_Bool
bGroupFound( sal_False
);
353 frame::DispatchInformation aDispatchInfo
;
354 std::list
< frame::DispatchInformation
> aDispatchInfoList
;
356 if (( nCommandGroup
== frame::CommandGroup::EDIT
) ||
357 ( nCommandGroup
== frame::CommandGroup::DOCUMENT
) ||
358 ( nCommandGroup
== frame::CommandGroup::DATA
) ||
359 ( nCommandGroup
== frame::CommandGroup::VIEW
))
361 CmdToInfoCache::const_iterator pIter
= rCmdCache
.begin();
362 while ( pIter
!= rCmdCache
.end() )
364 if ( pIter
->second
.nGroupId
== nCommandGroup
)
366 bGroupFound
= sal_True
;
367 aDispatchInfo
.Command
= pIter
->first
;
368 aDispatchInfo
.GroupId
= pIter
->second
.nGroupId
;
369 aDispatchInfoList
.push_back( aDispatchInfo
);
371 else if ( bGroupFound
)
378 ::com::sun::star::uno::Sequence
< ::com::sun::star::frame::DispatchInformation
> aSeq
=
379 comphelper::containerToSequence
< ::com::sun::star::frame::DispatchInformation
, std::list
< ::com::sun::star::frame::DispatchInformation
> >( aDispatchInfoList
);
384 sal_Bool
canInsertRecords(const Reference
< beans::XPropertySet
>& _rxCursorSet
)
387 _rxCursorSet
->getPropertyValue(C2U("Privileges")) >>= nPriv
;
388 return ((_rxCursorSet
.is() && (nPriv
& sdbcx::Privilege::INSERT
) != 0));
390 /* -----------------------------08.05.2002 08:58------------------------------
392 ---------------------------------------------------------------------------*/
393 sal_Bool
BibFrameController_Impl::SaveModified(const Reference
< form::XFormController
>& xController
)
395 if (!xController
.is())
397 sal_Bool bInserted
= sal_False
;
399 Reference
< XResultSetUpdate
> _xCursor
= Reference
< XResultSetUpdate
>(xController
->getModel(), UNO_QUERY
);
404 Reference
< beans::XPropertySet
> _xSet
= Reference
< beans::XPropertySet
>(_xCursor
, UNO_QUERY
);
408 // muß gespeichert werden ?
409 sal_Bool bIsNew
= ::comphelper::getBOOL(_xSet
->getPropertyValue(C2U("IsNew")));
410 sal_Bool bIsModified
= ::comphelper::getBOOL(_xSet
->getPropertyValue(C2U("IsModified")));
411 sal_Bool bResult
= !bIsModified
;
417 _xCursor
->insertRow();
419 _xCursor
->updateRow();
424 DBG_ERROR("SaveModified: Exception occured!");
427 bInserted
= bIsNew
&& bResult
;
432 Window
* lcl_GetFocusChild( Window
* pParent
)
434 USHORT nChildren
= pParent
->GetChildCount();
435 for( USHORT nChild
= 0; nChild
< nChildren
; ++nChild
)
437 Window
* pChild
= pParent
->GetChild( nChild
);
438 if(pChild
->HasFocus())
440 Window
* pSubChild
= lcl_GetFocusChild( pChild
);
448 void BibFrameController_Impl::dispatch(const util::URL
& _rURL
, const uno::Sequence
< beans::PropertyValue
>& aArgs
) throw (::com::sun::star::uno::RuntimeException
)
452 vos::OGuard
aGuard(Application::GetSolarMutex());
453 Window
* pParent
= VCLUnoHelper::GetWindow( xWindow
);
454 WaitObject
aWaitObject( pParent
);
456 String
aCommand( _rURL
.Path
);
457 if(aCommand
.EqualsAscii("Bib/Mapping"))
459 pDatMan
->CreateMappingDialog(pParent
);
461 else if(aCommand
.EqualsAscii("Bib/source"))
463 ChangeDataSource(aArgs
);
465 else if(aCommand
.EqualsAscii("Bib/sdbsource"))
467 rtl::OUString aURL
= pDatMan
->CreateDBChangeDialog(pParent
);
472 uno::Sequence
< beans::PropertyValue
> aNewDataSource(2);
473 beans::PropertyValue
* pProps
= aNewDataSource
.getArray();
474 pProps
[0].Value
<<= rtl::OUString();
475 pProps
[1].Value
<<= aURL
;
476 ChangeDataSource(aNewDataSource
);
478 catch(const Exception
&)
480 DBG_ERROR("Exception catched while changing the data source");
484 else if(aCommand
.EqualsAscii("Bib/autoFilter"))
486 sal_uInt16 nCount
= aStatusListeners
.Count();
487 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
489 BibStatusDispatch
*pObj
= aStatusListeners
[n
];
490 if ( pObj
->aURL
.Path
== C2U("Bib/removeFilter") )
492 FeatureStateEvent aEvent
;
493 aEvent
.FeatureURL
= pObj
->aURL
;
494 aEvent
.IsEnabled
= sal_True
;
495 aEvent
.Requery
= sal_False
;
496 aEvent
.Source
= (XDispatch
*) this;
497 pObj
->xListener
->statusChanged( aEvent
);
498 //break; because there are more than one
502 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
503 uno::Any aValue
=pPropertyValue
[0].Value
;
504 rtl::OUString aQuery
;
507 aValue
=pPropertyValue
[1].Value
;
508 rtl::OUString aQueryField
;
509 aValue
>>= aQueryField
;
510 BibConfig
* pConfig
= BibModul::GetConfig();
511 pConfig
->setQueryField(aQueryField
);
512 pDatMan
->startQueryWith(aQuery
);
514 else if(aCommand
.EqualsAscii("Bib/standardFilter"))
518 uno::Reference
< lang::XMultiServiceFactory
> xORB
= ::comphelper::getProcessServiceFactory();
520 // build the arguments for the filter dialog to be created
521 Sequence
< Any
> aDialogCreationArgs( 3 );
522 Any
* pDialogCreationArgs
= aDialogCreationArgs
.getArray();
523 // the query composer
524 *pDialogCreationArgs
++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "QueryComposer" ),
526 makeAny( pDatMan
->getParser() ),
527 beans::PropertyState_DIRECT_VALUE
531 *pDialogCreationArgs
++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "RowSet" ),
533 makeAny( pDatMan
->getForm() ),
534 beans::PropertyState_DIRECT_VALUE
536 // the parent window for the dialog
537 *pDialogCreationArgs
++ <<= beans::PropertyValue( ::rtl::OUString::createFromAscii( "ParentWindow" ),
540 beans::PropertyState_DIRECT_VALUE
543 // create the dialog object
544 const ::rtl::OUString sDialogServiceName
= ::rtl::OUString::createFromAscii( "com.sun.star.sdb.FilterDialog" );
545 uno::Reference
< uno::XInterface
> xDialog
= xORB
->createInstanceWithArguments(
551 ShowServiceNotAvailableError( VCLUnoHelper::GetWindow( xWindow
), sDialogServiceName
, sal_True
);
556 uno::Reference
< ui::dialogs::XExecutableDialog
> xExec( xDialog
, UNO_QUERY
);
557 DBG_ASSERT( xExec
.is(), "BibFrameController_Impl::dispatch: missing an interface on the dialog!" );
559 if ( xExec
->execute( ) )
561 // the dialog has been executed successfully, and the filter on the query composer
563 ::rtl::OUString sNewFilter
= pDatMan
->getParser()->getFilter();
564 pDatMan
->setFilter( sNewFilter
);
568 catch( const uno::Exception
& )
570 DBG_ERROR( "BibFrameController_Impl::dispatch: caught an exception!" );
573 sal_uInt16 nCount
= aStatusListeners
.Count();
574 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
576 BibStatusDispatch
*pObj
= aStatusListeners
[n
];
577 if ( pObj
->aURL
.Path
== C2U("Bib/removeFilter") && pDatMan
->getParser().is())
579 FeatureStateEvent aEvent
;
580 aEvent
.FeatureURL
= pObj
->aURL
;
581 aEvent
.IsEnabled
= 0 != pDatMan
->getParser()->getFilter().getLength();
582 aEvent
.Requery
= sal_False
;
583 aEvent
.Source
= (XDispatch
*) this;
584 pObj
->xListener
->statusChanged( aEvent
);
588 else if(aCommand
.EqualsAscii("Bib/removeFilter"))
592 else if(_rURL
.Complete
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("slot:5503")) ||
593 aCommand
.EqualsAscii("CloseDoc"))
595 Application::PostUserEvent( STATIC_LINK( this, BibFrameController_Impl
,
599 else if(aCommand
.EqualsAscii("Bib/InsertRecord"))
601 Reference
<form::XFormController
> xFormCtrl
= pDatMan
->GetFormController();
602 if(SaveModified(xFormCtrl
))
606 Reference
< sdbc::XResultSet
> xCursor( pDatMan
->getForm(), UNO_QUERY
);
609 Reference
< XResultSetUpdate
> xUpdateCursor( pDatMan
->getForm(), UNO_QUERY
);
610 xUpdateCursor
->moveToInsertRow();
614 DBG_ERROR("Exception in last() or moveToInsertRow()");
618 else if(aCommand
.EqualsAscii("Bib/DeleteRecord"))
620 Reference
< ::com::sun::star::sdbc::XResultSet
> xCursor(pDatMan
->getForm(), UNO_QUERY
);
621 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
622 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
623 sal_Bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue(C2U("IsNew")));
626 sal_uInt32 nCount
= 0;
627 xSet
->getPropertyValue(C2U("RowCount")) >>= nCount
;
628 // naechste position festellen
629 sal_Bool bSuccess
= sal_False
;
630 sal_Bool bLeft
= sal_False
;
631 sal_Bool bRight
= sal_False
;
634 bLeft
= xCursor
->isLast() && nCount
> 1;
635 bRight
= !xCursor
->isLast();
636 // ask for confirmation
637 Reference
< frame::XController
> xCtrl
= pImp
->pController
;
638 Reference
< form::XConfirmDeleteListener
> xConfirm(pDatMan
->GetFormController(),UNO_QUERY
);
641 sdb::RowChangeEvent aEvent
;
642 aEvent
.Source
= Reference
< XInterface
> (xCursor
, UNO_QUERY
);
643 aEvent
.Action
= sdb::RowChangeAction::DELETE
;
645 bSuccess
= xConfirm
->confirmDelete(aEvent
);
650 xUpdateCursor
->deleteRow();
654 bSuccess
= sal_False
;
659 xCursor
->relative(bRight
? 1 : -1);
662 sal_Bool bCanInsert
= canInsertRecords(xSet
);
663 // kann noch ein Datensatz eingefuegt weden
667 xUpdateCursor
->moveToInsertRow();
669 // Datensatz bewegen um Stati neu zu setzen
674 DBG_ERROR("DeleteRecord : exception caught !");
680 else if(aCommand
.EqualsAscii("Cut"))
682 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
685 KeyEvent
aEvent( 0, KEYFUNC_CUT
);
686 pChild
->KeyInput( aEvent
);
689 else if(aCommand
.EqualsAscii("Copy"))
691 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
694 KeyEvent
aEvent( 0, KEYFUNC_COPY
);
695 pChild
->KeyInput( aEvent
);
698 else if(aCommand
.EqualsAscii("Paste"))
700 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
703 KeyEvent
aEvent( 0, KEYFUNC_PASTE
);
704 pChild
->KeyInput( aEvent
);
709 IMPL_STATIC_LINK( BibFrameController_Impl
, DisposeHdl
, void*, EMPTYARG
)
711 pThis
->xFrame
->dispose();
715 //-----------------------------------------------------------------------------
716 void BibFrameController_Impl::addStatusListener(
717 const uno::Reference
< frame::XStatusListener
> & aListener
,
718 const util::URL
& aURL
)
719 throw (::com::sun::star::uno::RuntimeException
)
721 BibConfig
* pConfig
= BibModul::GetConfig();
722 // create a new Reference and insert into listener array
723 aStatusListeners
.Insert( new BibStatusDispatch( aURL
, aListener
), aStatusListeners
.Count() );
725 // den ersten Status synchron zusenden
726 FeatureStateEvent aEvent
;
727 aEvent
.FeatureURL
= aURL
;
728 aEvent
.Requery
= sal_False
;
729 aEvent
.Source
= (XDispatch
*) this;
730 if ( aURL
.Path
== C2U("StatusBarVisible") )
732 aEvent
.IsEnabled
= sal_False
;
733 aEvent
.State
<<= sal_Bool( sal_False
);
735 else if ( aURL
.Path
== C2U("Bib/hierarchical") )
737 aEvent
.IsEnabled
= sal_True
;
738 const char* pHier
= bHierarchical
? "" : "*" ;
739 aEvent
.State
<<= rtl::OUString::createFromAscii(pHier
);
741 else if(aURL
.Path
== C2U("Bib/MenuFilter"))
743 aEvent
.IsEnabled
= sal_True
;
744 aEvent
.FeatureDescriptor
=pDatMan
->getQueryField();
746 uno::Sequence
<rtl::OUString
> aStringSeq
=pDatMan
->getQueryFields();
747 aEvent
.State
.setValue(&aStringSeq
,::getCppuType((uno::Sequence
<rtl::OUString
>*)0));
750 else if ( aURL
.Path
== C2U("Bib/source"))
752 aEvent
.IsEnabled
= sal_True
;
753 aEvent
.FeatureDescriptor
=pDatMan
->getActiveDataTable();
755 uno::Sequence
<rtl::OUString
> aStringSeq
=pDatMan
->getDataSources();
756 aEvent
.State
.setValue(&aStringSeq
,::getCppuType((uno::Sequence
<rtl::OUString
>*)0));
758 else if(aURL
.Path
== C2U("Bib/sdbsource") ||
759 aURL
.Path
== C2U("Bib/Mapping") ||
760 aURL
.Path
== C2U("Bib/autoFilter") ||
761 aURL
.Path
.equalsAscii("Bib/standardFilter"))
763 aEvent
.IsEnabled
= sal_True
;
765 else if(aURL
.Path
== C2U("Bib/query"))
767 aEvent
.IsEnabled
= sal_True
;
768 aEvent
.State
<<= pConfig
->getQueryText();
770 else if (aURL
.Path
== C2U("Bib/removeFilter") )
772 rtl::OUString aFilterStr
=pDatMan
->getFilter();
773 aEvent
.IsEnabled
= (aFilterStr
.getLength() > 0);
775 else if(aURL
.Path
== C2U("Cut"))
777 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
778 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
780 aEvent
.IsEnabled
= !pEdit
->IsReadOnly() && pEdit
->GetSelection().Len();
782 if(aURL
.Path
== C2U("Copy"))
784 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
785 Edit
* pEdit
= dynamic_cast<Edit
*>( pChild
);
787 aEvent
.IsEnabled
= pEdit
->GetSelection().Len() > 0;
789 else if(aURL
.Path
== C2U("Paste") )
791 aEvent
.IsEnabled
= sal_False
;
792 Window
* pChild
= lcl_GetFocusChild( VCLUnoHelper::GetWindow( xWindow
) );
795 uno::Reference
< datatransfer::clipboard::XClipboard
> xClip
= pChild
->GetClipboard();
798 uno::Reference
< datatransfer::XTransferable
> xDataObj
;
799 const sal_uInt32 nRef
= Application::ReleaseSolarMutex();
802 xDataObj
= xClip
->getContents();
804 catch( const uno::Exception
& )
807 Application::AcquireSolarMutex( nRef
);
811 datatransfer::DataFlavor aFlavor
;
812 SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING
, aFlavor
);
815 uno::Any aData
= xDataObj
->getTransferData( aFlavor
);
816 ::rtl::OUString aText
;
818 aEvent
.IsEnabled
= aText
.getLength() > 0;
820 catch( const uno::Exception
& )
825 uno::Reference
< datatransfer::XTransferable
> xContents
= xClip
->getContents( );
828 else if(aURL
.Path
== C2U("Bib/DeleteRecord"))
830 Reference
< ::com::sun::star::sdbc::XResultSet
> xCursor(pDatMan
->getForm(), UNO_QUERY
);
831 Reference
< XResultSetUpdate
> xUpdateCursor(xCursor
, UNO_QUERY
);
832 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
833 sal_Bool bIsNew
= ::comphelper::getBOOL(xSet
->getPropertyValue(C2U("IsNew")));
836 sal_uInt32 nCount
= 0;
837 xSet
->getPropertyValue(C2U("RowCount")) >>= nCount
;
838 aEvent
.IsEnabled
= nCount
> 0;
841 else if (aURL
.Path
== C2U("Bib/InsertRecord"))
843 Reference
< beans::XPropertySet
> xSet(pDatMan
->getForm(), UNO_QUERY
);
844 aEvent
.IsEnabled
= canInsertRecords(xSet
);
846 aListener
->statusChanged( aEvent
);
848 //-----------------------------------------------------------------------------
849 void BibFrameController_Impl::removeStatusListener(
850 const uno::Reference
< frame::XStatusListener
> & aObject
, const util::URL
& aURL
)
851 throw (::com::sun::star::uno::RuntimeException
)
853 // search listener array for given listener
854 // for checking equality always "cast" to XInterface
857 sal_uInt16 nCount
= aStatusListeners
.Count();
858 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
860 BibStatusDispatch
*pObj
= aStatusListeners
[n
];
861 sal_Bool bFlag
=pObj
->xListener
.is();
862 if (!bFlag
|| (pObj
->xListener
== aObject
&&
863 ( !aURL
.Complete
.getLength() || pObj
->aURL
.Path
== aURL
.Path
)))
865 aStatusListeners
.DeleteAndDestroy( n
);
871 //-----------------------------------------------------------------------------
872 void BibFrameController_Impl::RemoveFilter()
874 rtl::OUString aQuery
;
875 pDatMan
->startQueryWith(aQuery
);
877 sal_uInt16 nCount
= aStatusListeners
.Count();
879 sal_Bool bRemoveFilter
=sal_False
;
880 sal_Bool bQueryText
=sal_False
;
882 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
884 BibStatusDispatch
*pObj
= aStatusListeners
[n
];
885 if ( pObj
->aURL
.Path
== C2U("Bib/removeFilter") )
887 FeatureStateEvent aEvent
;
888 aEvent
.FeatureURL
= pObj
->aURL
;
889 aEvent
.IsEnabled
= sal_False
;
890 aEvent
.Requery
= sal_False
;
891 aEvent
.Source
= (XDispatch
*) this;
892 pObj
->xListener
->statusChanged( aEvent
);
893 bRemoveFilter
=sal_True
;
895 else if(pObj
->aURL
.Path
== C2U("Bib/query"))
897 FeatureStateEvent aEvent
;
898 aEvent
.FeatureURL
= pObj
->aURL
;
899 aEvent
.IsEnabled
= sal_True
;
900 aEvent
.Requery
= sal_False
;
901 aEvent
.Source
= (XDispatch
*) this;
902 aEvent
.State
<<= aQuery
;
903 pObj
->xListener
->statusChanged( aEvent
);
907 if(bRemoveFilter
&& bQueryText
)
912 //-----------------------------------------------------------------------------
913 void BibFrameController_Impl::ChangeDataSource(const uno::Sequence
< beans::PropertyValue
>& aArgs
)
915 const beans::PropertyValue
* pPropertyValue
= aArgs
.getConstArray();
916 uno::Any aValue
=pPropertyValue
[0].Value
;
917 rtl::OUString aDBTableName
;
918 aValue
>>= aDBTableName
;
921 if(aArgs
.getLength() > 1)
923 uno::Any aDB
= pPropertyValue
[1].Value
;
926 pDatMan
->setActiveDataSource(aURL
);
927 aDBTableName
= pDatMan
->getActiveDataTable();
932 pDatMan
->setActiveDataTable(aDBTableName
);
933 pDatMan
->updateGridModel();
938 sal_uInt16 nCount
= aStatusListeners
.Count();
940 sal_Bool bMenuFilter
=sal_False
;
941 sal_Bool bQueryText
=sal_False
;
942 for ( sal_uInt16 n
=0; n
<nCount
; n
++ )
944 BibStatusDispatch
*pObj
= aStatusListeners
[n
];
945 if(COMPARE_EQUAL
== pObj
->aURL
.Path
.compareToAscii("Bib/MenuFilter"))
947 FeatureStateEvent aEvent
;
948 aEvent
.FeatureURL
= pObj
->aURL
;
949 aEvent
.IsEnabled
= sal_True
;
950 aEvent
.Requery
= sal_False
;
951 aEvent
.Source
= (XDispatch
*) this;
952 aEvent
.FeatureDescriptor
=pDatMan
->getQueryField();
954 uno::Sequence
<rtl::OUString
> aStringSeq
=pDatMan
->getQueryFields();
955 aEvent
.State
= makeAny( aStringSeq
);
957 pObj
->xListener
->statusChanged( aEvent
);
958 bMenuFilter
=sal_True
;
960 else if(COMPARE_EQUAL
== pObj
->aURL
.Path
.compareToAscii("Bib/query"))
962 FeatureStateEvent aEvent
;
963 aEvent
.FeatureURL
= pObj
->aURL
;
964 aEvent
.IsEnabled
= sal_True
;
965 aEvent
.Requery
= sal_False
;
966 aEvent
.Source
= (XDispatch
*) this;
967 BibConfig
* pConfig
= BibModul::GetConfig();
968 aEvent
.State
<<= pConfig
->getQueryText();
969 pObj
->xListener
->statusChanged( aEvent
);
973 if (bMenuFilter
&& bQueryText
)
979 void BibFrameController_Impl::activate()
982 void BibFrameController_Impl::deactivate()