Tag: cws_dev300_dba30d User: fs Date: 2008-06-09 13:45:46+0000 Modified: dba/dbaccess/source/ui/app/AppDetailPageHelper.cxx dba/dbaccess/source/ui/app/AppDetailPageHelper.hxx
Log: #i80943# retrieve the proper selection for the context menu interceptors File Changes: Directory: /dba/dbaccess/source/ui/app/ ======================================= File [changed]: AppDetailPageHelper.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppDetailPageHelper.cxx?r1=1.32.10.2&r2=1.32.10.3 Delta lines: +136 -44 ---------------------- --- AppDetailPageHelper.cxx 2008-06-01 21:02:32+0000 1.32.10.2 +++ AppDetailPageHelper.cxx 2008-06-09 13:45:43+0000 1.32.10.3 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: AppDetailPageHelper.cxx,v $ - * $Revision: 1.32.10.2 $ + * $Revision: 1.32.10.3 $ * * This file is part of OpenOffice.org. * @@ -123,6 +123,8 @@ #ifndef _COM_SUN_STAR_SDB_APPLICATION_XDATABASEDOCUMENTUI_HPP_ #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> #endif +#include <com/sun/star/sdb/application/DatabaseObject.hpp> +#include <com/sun/star/sdb/application/DatabaseObjectFolder.hpp> #ifndef DBAUI_APPVIEW_HXX #include "AppView.hxx" #endif @@ -159,6 +161,9 @@ #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif #include "IApplicationController.hxx" #include <com/sun/star/document/XDocumentProperties.hpp> @@ -177,6 +182,9 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star; +namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject; +namespace DatabaseObjectFolder = ::com::sun::star::sdb::application::DatabaseObjectFolder; + namespace { SvLBoxEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvLBoxEntry* _pFirst) @@ -318,7 +326,7 @@ m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview ); SetUniqueId(UID_APP_DETAILPAGE_HELPER); - for (int i=0; i < CONTROL_COUNT; ++i) + for (int i=0; i < ELEMENT_COUNT; ++i) m_pLists[i] = NULL; ImplInitSettings(); } @@ -336,7 +344,7 @@ OSL_ENSURE(0,"Exception thrown while disposing preview frame!"); } - for (int i=0; i < CONTROL_COUNT; ++i) + for (int i=0; i < ELEMENT_COUNT; ++i) { if ( m_pLists[i] ) { @@ -355,7 +363,7 @@ int OAppDetailPageHelper::getVisibleControlIndex() const { int i = 0; - for (; i < CONTROL_COUNT ; ++i) + for (; i < ELEMENT_COUNT ; ++i) { if ( m_pLists[i] && m_pLists[i]->IsVisible() ) break; @@ -366,7 +374,7 @@ void OAppDetailPageHelper::selectAll() { int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { m_pLists[nPos]->lockAutoSelect(); m_pLists[nPos]->SelectAll(TRUE); @@ -388,7 +396,7 @@ { SvSortMode eSortMode = SortNone; int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { SvLBoxTreeList* pModel = m_pLists[nPos]->GetModel(); eSortMode = pModel->GetSortMode(); @@ -399,21 +407,21 @@ void OAppDetailPageHelper::sortDown() { int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) sort(nPos,SortDescending); } // ----------------------------------------------------------------------------- void OAppDetailPageHelper::sortUp() { int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) sort(nPos,SortAscending); } // ----------------------------------------------------------------------------- void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const { int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { DBTreeListBox& rTree = *m_pLists[nPos]; sal_Int32 nCount = rTree.GetEntryCount(); @@ -447,11 +455,12 @@ void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Any& _out_rSelectedObjects ) { DBTreeListBox* pList = NULL; - for ( size_t i=0; i < CONTROL_COUNT; ++i ) + enum ElementType eType = E_TABLE; + for ( size_t i=0; i < ELEMENT_COUNT; eType = static_cast< ElementType >( ++i ) ) { - if ( m_pLists[i] == &_rControl ) + if ( m_pLists[eType] == &_rControl ) { - pList = m_pLists[i]; + pList = m_pLists[eType]; break; } } @@ -459,15 +468,72 @@ if ( !pList ) return; - // TODO - (void)_out_rSelectedObjects; + ::std::vector< NamedDatabaseObject > aSelected; + aSelected.reserve( pList->GetEntryCount() ); + + SvLBoxEntry* pEntry = pList->FirstSelected(); + while( pEntry ) + { + NamedDatabaseObject aObject; + switch ( eType ) + { + case E_TABLE: + { + OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList ); + aObject = rTableTree.describeObject( pEntry ); + } + break; + case E_QUERY: + aObject.Type = DatabaseObject::QUERY; + aObject.Name = pList->GetEntryText( pEntry ); + break; + + case E_FORM: + case E_REPORT: + { + ::rtl::OUString sName = pList->GetEntryText(pEntry); + SvLBoxEntry* pParent = pList->GetParent(pEntry); + while ( pParent ) + { + ::rtl::OUStringBuffer buffer; + buffer.append( pList->GetEntryText( pParent ) ); + buffer.append( sal_Unicode( '/' ) ); + buffer.append( sName ); + sName = buffer.makeStringAndClear(); + + pParent = pList->GetParent( pParent ); + } + + if ( isLeaf( pEntry ) ) + aObject.Type = ( eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT; + else + aObject.Type = ( eType == E_FORM ) ? DatabaseObjectFolder::FORMS_FOLDER : DatabaseObjectFolder::REPORTS_FOLDER; + aObject.Name = sName; + } + break; + default: + OSL_ENSURE( false, "OAppDetailPageHelper::describeCurrentSelectionForControl: unexpected type!" ); + break; + } + + if ( aObject.Name.getLength() ) + { + aSelected.push_back( aObject ); + } + + pEntry = pList->NextSelected(pEntry); + } + + Sequence< NamedDatabaseObject > aSelectedObjects( aSelected.size() ); + ::std::copy( aSelected.begin(), aSelected.end(), aSelectedObjects.getArray() ); + _out_rSelectedObjects <<= aSelectedObjects; } // ----------------------------------------------------------------------------- void OAppDetailPageHelper::selectElements(const Sequence< ::rtl::OUString>& _aNames) { int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { DBTreeListBox& rTree = *m_pLists[nPos]; rTree.SelectAll(FALSE); @@ -487,7 +553,7 @@ int nPos = getVisibleControlIndex(); ::rtl::OUString sComposedName; - if ( nPos >= CONTROL_COUNT ) + if ( nPos >= ELEMENT_COUNT ) return sComposedName; OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF"); @@ -529,7 +595,7 @@ { sal_Int32 nCount = 0; int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { DBTreeListBox& rTree = *m_pLists[nPos]; SvLBoxEntry* pEntry = rTree.FirstSelected(); @@ -546,7 +612,7 @@ { sal_Int32 nCount = 0; int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { nCount = m_pLists[nPos]->GetEntryCount(); } @@ -582,28 +648,32 @@ { } // ----------------------------------------------------------------------------- -sal_Bool OAppDetailPageHelper::isLeaf(SvLBoxEntry* _pEntry) const +bool OAppDetailPageHelper::isLeaf(SvLBoxEntry* _pEntry) const { - int nPos = getVisibleControlIndex(); - sal_Bool bLeafSelected = sal_False; - if ( nPos < CONTROL_COUNT && _pEntry ) - { - bLeafSelected = reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData()) != FOLDER_INDICATOR; - } - return bLeafSelected; + sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() ); + if ( ( nEntryType == DatabaseObjectFolder::ALL_TABLES ) + || ( nEntryType == DatabaseObjectFolder::CATALOG ) + || ( nEntryType == DatabaseObjectFolder::SCHEMA ) + || ( nEntryType == DatabaseObjectFolder::FORMS_FOLDER ) + || ( nEntryType == DatabaseObjectFolder::REPORTS_FOLDER ) + ) + return false; + + return true; } + // ----------------------------------------------------------------------------- sal_Bool OAppDetailPageHelper::isALeafSelected() const { int nPos = getVisibleControlIndex(); sal_Bool bLeafSelected = sal_False; - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) { DBTreeListBox& rTree = *m_pLists[nPos]; SvLBoxEntry* pEntry = rTree.FirstSelected( ); while( !bLeafSelected && pEntry ) { - bLeafSelected = reinterpret_cast<sal_IntPtr>(pEntry->GetUserData()) != FOLDER_INDICATOR; + bLeafSelected = isLeaf( pEntry ); pEntry = rTree.NextSelected(pEntry); } } @@ -614,7 +684,7 @@ { SvLBoxEntry* pReturn = NULL; int nPos = getVisibleControlIndex(); - if ( nPos < CONTROL_COUNT ) + if ( nPos < ELEMENT_COUNT ) pReturn = m_pLists[nPos]->GetEntry( _aPosPixel,TRUE ); return pReturn; } @@ -713,7 +783,7 @@ { if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() ) { - fillNames( _xContainer, *m_pLists[ _eType ], nImageId, nImageIdH ); + fillNames( _xContainer, _eType, nImageId, nImageIdH, NULL ); m_pLists[_eType]->SelectAll(FALSE); } @@ -743,14 +813,35 @@ _pWindow->GrabFocus(); Resize(); } + +// ----------------------------------------------------------------------------- +namespace +{ + static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType ) + { + const sal_Int32 nFolderIndicator = + ( _eType == E_FORM ) ? DatabaseObjectFolder::FORMS_FOLDER + : ( _eType == E_REPORT ) ? DatabaseObjectFolder::REPORTS_FOLDER : -1; + return nFolderIndicator; + } +} + // ----------------------------------------------------------------------------- -void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, DBTreeListBox& _rList, - USHORT _nImageId, USHORT _nHighContrastImageId, SvLBoxEntry* _pParent ) +void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType, + const USHORT _nImageId, const USHORT _nHighContrastImageId, SvLBoxEntry* _pParent ) { OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF"); + OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" ); + + DBTreeListBox* pList = m_pLists[ _eType ]; + OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" ); + if ( !pList ) + return; if ( _xContainer.is() && _xContainer->hasElements() ) { + const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType ); + Sequence< ::rtl::OUString> aSeq = _xContainer->getElementNames(); const ::rtl::OUString* pIter = aSeq.getConstArray(); const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); @@ -760,21 +851,21 @@ Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY); if ( xSubElements.is() ) { - pEntry = _rList.InsertEntry( *pIter, _pParent, FALSE, LIST_APPEND, reinterpret_cast< void* >( FOLDER_INDICATOR ) ); + pEntry = pList->InsertEntry( *pIter, _pParent, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) ); getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) ); - fillNames( xSubElements, _rList, _nImageId, _nHighContrastImageId, pEntry ); + fillNames( xSubElements, _eType, _nImageId, _nHighContrastImageId, pEntry ); } else { - pEntry = _rList.InsertEntry( *pIter, _pParent ); + pEntry = pList->InsertEntry( *pIter, _pParent ); Image aImage = Image( ModuleRes( _nImageId ) ); - _rList.SetExpandedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL ); - _rList.SetCollapsedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL ); + pList->SetExpandedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL ); + pList->SetCollapsedEntryBmp( pEntry, aImage, BMP_COLOR_NORMAL ); Image aHCImage = Image( ModuleRes( _nHighContrastImageId ) ); - _rList.SetExpandedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST ); - _rList.SetCollapsedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST ); + pList->SetExpandedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST ); + pList->SetCollapsedEntryBmp( pEntry, aHCImage, BMP_COLOR_HIGHCONTRAST ); } } } @@ -821,7 +912,7 @@ void OAppDetailPageHelper::clearPages() { showPreview(NULL); - for (size_t i=0; i < CONTROL_COUNT; ++i) + for (size_t i=0; i < ELEMENT_COUNT; ++i) { if ( m_pLists[i] ) m_pLists[i]->Clear(); @@ -831,9 +922,9 @@ sal_Bool OAppDetailPageHelper::isFilled() const { size_t i = 0; - for (; i < CONTROL_COUNT && !m_pLists[i]; ++i) + for (; i < ELEMENT_COUNT && !m_pLists[i]; ++i) ; - return i != CONTROL_COUNT; + return i != ELEMENT_COUNT; } // ----------------------------------------------------------------------------- void OAppDetailPageHelper::elementReplaced(ElementType _eType @@ -898,8 +989,9 @@ Reference<XNameAccess> xContainer(_rObject,UNO_QUERY); if ( xContainer.is() ) { - pRet = pTreeView->InsertEntry(_rName,pEntry,FALSE,LIST_APPEND,reinterpret_cast<void*>(FOLDER_INDICATOR)); - fillNames( xContainer, *pTreeView, nImageId, nImageIdH, pRet ); + const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType ); + pRet = pTreeView->InsertEntry( _rName, pEntry, FALSE, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) ); + fillNames( xContainer, _eType, nImageId, nImageIdH, pRet ); } else { File [changed]: AppDetailPageHelper.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/app/AppDetailPageHelper.hxx?r1=1.14.30.2&r2=1.14.30.3 Delta lines: +12 -11 --------------------- --- AppDetailPageHelper.hxx 2008-06-01 21:02:32+0000 1.14.30.2 +++ AppDetailPageHelper.hxx 2008-06-09 13:45:44+0000 1.14.30.3 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: AppDetailPageHelper.hxx,v $ - * $Revision: 1.14.30.2 $ + * $Revision: 1.14.30.3 $ * * This file is part of OpenOffice.org. * @@ -72,7 +72,7 @@ namespace com{ namespace sun { namespace star { namespace frame { class XFrame; } } } } namespace com{ namespace sun { namespace star { namespace io { class XPersist; } } } } -#define CONTROL_COUNT 4 +#define ELEMENT_COUNT size_t(E_ELEMENT_TYPE_COUNT) namespace dbaui { @@ -111,7 +111,7 @@ //================================================================== class OAppDetailPageHelper : public Window { - DBTreeListBox* m_pLists[CONTROL_COUNT]; + DBTreeListBox* m_pLists[ELEMENT_COUNT]; OAppBorderWindow& m_rBorderWin; FixedLine m_aFL; ToolBox m_aTBPreview; @@ -147,8 +147,8 @@ /** fills the names in the listbox @param _xContainer This can either be the queries, forms or report names. - @param _rList - The tree list box to fill + @param _eType + the type of elements which are being filled @param _nImageId the resource id of the image to use for non-container entries @param _nHighContrastImageId @@ -156,11 +156,12 @@ @param _pParent The parent of the entries to be inserted. */ - void fillNames( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer - ,DBTreeListBox& _rList - ,USHORT _nImageId - ,USHORT _nHighContrastImageId - ,SvLBoxEntry* _pParent = NULL); + void fillNames( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer, + const ElementType _eType, + const USHORT _nImageId, + const USHORT _nHighContrastImageId, + SvLBoxEntry* _pParent ); + /** sets the detail page @param _pWindow The control which should be visible. @@ -300,7 +301,7 @@ @return <TRUE/> if the entry is a leaf, otherwise <FALSE/> */ - sal_Bool isLeaf(SvLBoxEntry* _pEntry) const; + bool isLeaf(SvLBoxEntry* _pEntry) const; /** returns if one of the selected entries is a leaf @return --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
