diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-10-29 21:26:38 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-10-29 21:26:38 +0100 |
commit | 97b267dea22695eb9a0d12a97dcc3dbffe1ab419 (patch) | |
tree | 1fc0fcee87051a5c1e2fb1825fa4a0003c65bea9 | |
parent | 834a384180018be5d8ad3833f5f9f5918be88922 (diff) |
moved the responsibility for always having an empty filter row to the navigator, so the mere FormController implementation now is able to work on an empty filter
-rw-r--r-- | svx/source/form/filtnav.cxx | 57 | ||||
-rw-r--r-- | svx/source/form/fmctrler.cxx | 41 | ||||
-rw-r--r-- | svx/source/inc/filtnav.hxx | 2 | ||||
-rw-r--r-- | svx/source/inc/fmctrler.hxx | 4 |
4 files changed, 25 insertions, 79 deletions
diff --git a/svx/source/form/filtnav.cxx b/svx/source/form/filtnav.cxx index 90091d62e269..73b077068ac3 100644 --- a/svx/source/form/filtnav.cxx +++ b/svx/source/form/filtnav.cxx @@ -488,7 +488,9 @@ void FmFilterAdapter::predicateExpressionChanged( const FilterEvent& _Event ) th pFilterItem = new FmFilterItem( m_pModel->getORB(), pFilter, aFieldName, _Event.PredicateExpression, _Event.FilterComponent ); m_pModel->Insert(pFilter->GetChildren().end(), pFilterItem); } - m_pModel->CheckIntegrity(pFormItem); + + // ensure there's one empty term in the filter, just in case the active term was previously empty + m_pModel->EnsureEmptyFilterRows( *pFormItem ); } //------------------------------------------------------------------------ @@ -521,6 +523,9 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermRemoved( const FilterEvent& _Event // finally remove the entry from the model m_pModel->Remove( rTermItems.begin() + _Event.DisjunctiveTerm ); + + // ensure there's one empty term in the filter, just in case the currently removed one was the last empty one + m_pModel->EnsureEmptyFilterRows( *pFormItem ); } //------------------------------------------------------------------------ @@ -551,7 +556,6 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermAdded( const FilterEvent& _Event ) m_pModel->Insert( insertPos, pFilterItems ); } - //======================================================================== // class FmFilterModel //======================================================================== @@ -625,7 +629,7 @@ void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, const m_pAdapter->acquire(); SetCurrentController(xCurrent); - CheckIntegrity(this); + EnsureEmptyFilterRows( *this ); } else SetCurrentController(xCurrent); @@ -774,18 +778,6 @@ void FmFilterModel::SetCurrentController(const Reference< XFormController > & xC //------------------------------------------------------------------------ void FmFilterModel::AppendFilterItems( FmFormItem& _rFormItem ) { - OSL_ENSURE( false, "FmFilterModel::AppendFilterItems: this should be dead code!" ); - // Before the UNOization of hte FormController, the controller implementation itself - // did not care for keeping at least one empty filter row. With the changes done now, - // it should be impossible to get a FormController to *not* have at least one empty - // filter row. - // Since the task of this method here was to ensure the controller *has* an empty row, - // this means the method should not be needed anymore. However, it's left here for the moment, - // to be on the safe side ... - // If the assertion above fires, then it needs to be investigated at which place the - // FormController failed to fulfill its contract of having at least one empty filter row - // all the time. - // insert the condition behind the last filter items ::std::vector<FmFilterData*>::reverse_iterator iter; for ( iter = _rFormItem.GetChildren().rbegin(); @@ -1018,37 +1010,36 @@ void FmFilterModel::SetCurrentItems(FmFilterItems* pCurrent) } //------------------------------------------------------------------------ -void FmFilterModel::CheckIntegrity(FmParentData* pItem) +void FmFilterModel::EnsureEmptyFilterRows( FmParentData& _rItem ) { // checks whether for each form there's one free level for input + ::std::vector< FmFilterData* >& rChildren = _rItem.GetChildren(); + sal_Bool bAppendLevel = _rItem.ISA( FmFormItem ); - ::std::vector< FmFilterData* >& rItems = pItem->GetChildren(); - sal_Bool bAppendLevel = sal_False; - - for ( ::std::vector<FmFilterData*>::iterator i = rItems.begin(); - i != rItems.end(); + for ( ::std::vector<FmFilterData*>::iterator i = rChildren.begin(); + i != rChildren.end(); ++i ) { FmFilterItems* pItems = PTR_CAST(FmFilterItems, *i); - if (pItems) + if ( pItems && pItems->GetChildren().empty() ) { - bAppendLevel = !pItems->GetChildren().empty(); - continue; + bAppendLevel = sal_False; + break; } FmFormItem* pFormItem = PTR_CAST(FmFormItem, *i); if (pFormItem) { - CheckIntegrity(pFormItem); + EnsureEmptyFilterRows( *pFormItem ); continue; } } if ( bAppendLevel ) { - FmFormItem* pFormItem = PTR_CAST( FmFormItem, pItem ); - OSL_ENSURE( pFormItem, "FmFilterModel::CheckIntegrity: no FmFormItem, but a FmFilterItems child?" ); + FmFormItem* pFormItem = PTR_CAST( FmFormItem, &_rItem ); + OSL_ENSURE( pFormItem, "FmFilterModel::EnsureEmptyFilterRows: no FmFormItem, but a FmFilterItems child?" ); if ( pFormItem ) AppendFilterItems( *pFormItem ); } @@ -1595,13 +1586,15 @@ void FmFilterNavigator::Insert(FmFilterData* pItem, sal_Int32 nPos) const FmParentData* pParent = pItem->GetParent() ? pItem->GetParent() : GetFilterModel(); // insert the item - SvLBoxEntry* pParentEntry = FindEntry(pParent); + SvLBoxEntry* pParentEntry = FindEntry( pParent ); SvLBoxEntry* pNewEntry = InsertEntry(pItem->GetText(), pItem->GetImage(), pItem->GetImage(), pParentEntry, sal_False, nPos, pItem ); if ( pNewEntry ) { SetExpandedEntryBmp( pNewEntry, pItem->GetImage( BMP_COLOR_HIGHCONTRAST ), BMP_COLOR_HIGHCONTRAST ); SetCollapsedEntryBmp( pNewEntry, pItem->GetImage( BMP_COLOR_HIGHCONTRAST ), BMP_COLOR_HIGHCONTRAST ); } + if ( pParentEntry ) + Expand( pParentEntry ); } //------------------------------------------------------------------------ @@ -1678,8 +1671,10 @@ void FmFilterNavigator::insertFilterItem(const ::std::vector<FmFilterItem*>& _rF // now set the text for the new dragged item m_pModel->SetTextForItem( pFilterItem, aText ); } - m_pModel->CheckIntegrity( (FmFormItem*)_pTargetItems->GetParent() ); + + m_pModel->EnsureEmptyFilterRows( *_pTargetItems->GetParent() ); } + //------------------------------------------------------------------------------ void FmFilterNavigator::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ ) { @@ -1936,11 +1931,7 @@ void FmFilterNavigator::DeleteSelection() i.base() != aEntryList.rend().base(); i++) { m_pModel->Remove((FmFilterData*)(*i)->GetUserData()); - Update(); } - - // now check if we need to insert new items - m_pModel->CheckIntegrity(m_pModel); } // ----------------------------------------------------------------------------- diff --git a/svx/source/form/fmctrler.cxx b/svx/source/form/fmctrler.cxx index c23897522626..cc3855518889 100644 --- a/svx/source/form/fmctrler.cxx +++ b/svx/source/form/fmctrler.cxx @@ -1062,9 +1062,6 @@ void SAL_CALL FormController::removeDisjunctiveTerm( ::sal_Int32 _Term ) throw ( aGuard.clear(); // <-- SYNCHRONIZED - // ensure there's an empty row (perhaps we just removed the last empty row) - implts_ensureEmptyFilterRow_nothrow(); - m_aFilterListeners.notifyEach( &XFilterControllerListener::disjunctiveTermRemoved, aEvent ); } @@ -1530,9 +1527,6 @@ void SAL_CALL FormController::textChanged(const TextEvent& e) throw( RuntimeExce aGuard.clear(); // <-- SYNCHRONIZED - // ensure there's an empty row (perhaps we just filled the previously empty row) - implts_ensureEmptyFilterRow_nothrow(); - // notify the changed filter expression m_aFilterListeners.notifyEach( &XFilterControllerListener::predicateExpressionChanged, aEvent ); } @@ -1628,39 +1622,6 @@ void FormController::impl_addFilterRow( const FmFilterRow& _row ) } //------------------------------------------------------------------------------ -void FormController::implts_ensureEmptyFilterRow_nothrow() -{ - // TODO: - // strictly, this method should not be needed. There is no compelling reason why a FormController must always - // have an empty filter row (or, in API terminology, an empty disjunctive term). Except ... the implementation - // probably cannot cope with an empty filter row container. - // Before the UNOiization of the FormController, the responsibility between ensuring the empty row was - // shared between the form controller and the filter navigator, which of course is nonsense. In the course - // of the UNOization, this was changed so that now the FormController is responsible alone. - // However, ideally, the FormController should not expect this empty row, and be able to work with no row at all. - // It would then be the responsibility of the UI (aka the filter navigator), to always ensure this empty row, - // if it really needs it. - - // SYNCHRONIZED --> - ::osl::ClearableMutexGuard aGuard( m_aMutex ); - impl_checkDisposed_throw(); - - // do we have an empty row? - for ( FmFilterRows::const_iterator pos = m_aFilterRows.begin(); - pos != m_aFilterRows.end(); - ++pos - ) - { - if ( pos->empty() ) - // all fine, found one - return; - } - - impl_appendEmptyFilterRow( aGuard ); - // <-- SYNCHRONIZED -} - -//------------------------------------------------------------------------------ void FormController::impl_appendEmptyFilterRow( ::osl::ClearableMutexGuard& _rClearBeforeNotify ) { // SYNCHRONIZED --> @@ -3278,8 +3239,6 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) { m_aFilterComponents.push_back( field->xText ); } - - implts_ensureEmptyFilterRow_nothrow(); } //------------------------------------------------------------------------------ diff --git a/svx/source/inc/filtnav.hxx b/svx/source/inc/filtnav.hxx index 93532ed1a92a..f1ae1ed4398d 100644 --- a/svx/source/inc/filtnav.hxx +++ b/svx/source/inc/filtnav.hxx @@ -204,7 +204,7 @@ public: void Remove(FmFilterData* pFilterItem); void AppendFilterItems( FmFormItem& _rItem ); - void CheckIntegrity(FmParentData* pItem); + void EnsureEmptyFilterRows( FmParentData& _rItem ); protected: void Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pFilterItem); diff --git a/svx/source/inc/fmctrler.hxx b/svx/source/inc/fmctrler.hxx index af4d5402db04..550bce611c73 100644 --- a/svx/source/inc/fmctrler.hxx +++ b/svx/source/inc/fmctrler.hxx @@ -528,10 +528,6 @@ namespace svxform void impl_onModify(); - /** ensures that m_aFilterRows contains at least one empty row - */ - void implts_ensureEmptyFilterRow_nothrow(); - /** adds the given filter row to m_aFilterRows, setting m_nCurrentFilterPosition to 0 if the newly added row is the first one. |