diff options
author | Noel Grandin <noel@peralex.com> | 2016-08-29 14:25:07 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-08-30 08:40:03 +0200 |
commit | e9a2d9e7be22b455c1597277c152379f732ce447 (patch) | |
tree | b456ac5d6bb38d01c42598c7e6d1a07521c7d3f8 /svx | |
parent | 15b084f2034dc892ef456f8c65f162c760c69fe8 (diff) |
convert DbGridControl::NavigationBar::State to scoped enum
and remove a nasty hack where we were passing around an extra constant
(SID_FM_RECORD_UNDO) without actually adding it to the enum
Change-Id: Ib79d0a4e2d1418797b01067529d500728e95bf7e
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/fmcomp/fmgridif.cxx | 55 | ||||
-rw-r--r-- | svx/source/fmcomp/gridctrl.cxx | 92 |
2 files changed, 69 insertions, 78 deletions
diff --git a/svx/source/fmcomp/fmgridif.cxx b/svx/source/fmcomp/fmgridif.cxx index 6f40844c9088..3fb86a223a3a 100644 --- a/svx/source/fmcomp/fmgridif.cxx +++ b/svx/source/fmcomp/fmgridif.cxx @@ -2569,19 +2569,18 @@ void FmXGridPeer::statusChanged(const css::frame::FeatureStateEvent& Event) thro Sequence< css::util::URL>& aUrls = getSupportedURLs(); const css::util::URL* pUrls = aUrls.getConstArray(); - Sequence<sal_uInt16> aSlots = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSlots.getConstArray(); + const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); sal_uInt16 i; - for (i=0; i<aUrls.getLength(); ++i, ++pUrls, ++pSlots) + for (i=0; i<aUrls.getLength(); ++i, ++pUrls) { if (pUrls->Main == Event.FeatureURL.Main) { DBG_ASSERT(m_pDispatchers[i] == Event.Source, "FmXGridPeer::statusChanged : the event source is a little bit suspect !"); m_pStateCache[i] = Event.IsEnabled; VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); - if (*pSlots != SID_FM_RECORD_UNDO) - pGrid->GetNavigationBar().InvalidateState(*pSlots); + if (aSlots[i] != DbGridControlNavigationBarState::Undo) + pGrid->GetNavigationBar().InvalidateState(aSlots[i]); break; } } @@ -2653,24 +2652,16 @@ void FmXGridPeer::resetted(const EventObject& rEvent) throw( RuntimeException, s } -Sequence<sal_uInt16>& FmXGridPeer::getSupportedGridSlots() +const std::vector<DbGridControlNavigationBarState>& FmXGridPeer::getSupportedGridSlots() { - static Sequence<sal_uInt16> aSupported; - if (aSupported.getLength() == 0) - { - const sal_uInt16 nSupported[] = { - DbGridControl::NavigationBar::RECORD_FIRST, - DbGridControl::NavigationBar::RECORD_PREV, - DbGridControl::NavigationBar::RECORD_NEXT, - DbGridControl::NavigationBar::RECORD_LAST, - DbGridControl::NavigationBar::RECORD_NEW, - SID_FM_RECORD_UNDO - }; - aSupported.realloc(SAL_N_ELEMENTS(nSupported)); - sal_uInt16* pSupported = aSupported.getArray(); - for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) - *pSupported = nSupported[i]; - } + static const std::vector<DbGridControlNavigationBarState> aSupported { + DbGridControlNavigationBarState::First, + DbGridControlNavigationBarState::Prev, + DbGridControlNavigationBarState::Next, + DbGridControlNavigationBarState::Last, + DbGridControlNavigationBarState::New, + DbGridControlNavigationBarState::Undo + }; return aSupported; } @@ -2803,17 +2794,16 @@ void FmXGridPeer::DisConnectFromDispatcher() } -IMPL_LINK_TYPED(FmXGridPeer, OnQueryGridSlotState, sal_uInt16, nSlot, int) +IMPL_LINK_TYPED(FmXGridPeer, OnQueryGridSlotState, DbGridControlNavigationBarState, nSlot, int) { if (!m_pStateCache) return -1; // unspecified // search the given slot with our supported sequence - Sequence<sal_uInt16>& aSupported = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSupported.getConstArray(); - for (sal_Int32 i=0; i<aSupported.getLength(); ++i) + const std::vector<DbGridControlNavigationBarState>& aSupported = getSupportedGridSlots(); + for (size_t i=0; i<aSupported.size(); ++i) { - if (pSlots[i] == nSlot) + if (aSupported[i] == nSlot) { if (!m_pDispatchers[i].is()) return -1; // nothing known about this slot @@ -2826,7 +2816,7 @@ IMPL_LINK_TYPED(FmXGridPeer, OnQueryGridSlotState, sal_uInt16, nSlot, int) } -IMPL_LINK_TYPED(FmXGridPeer, OnExecuteGridSlot, sal_uInt16, nSlot, bool) +IMPL_LINK_TYPED(FmXGridPeer, OnExecuteGridSlot, DbGridControlNavigationBarState, nSlot, bool) { if (!m_pDispatchers) return false; // not handled @@ -2834,14 +2824,13 @@ IMPL_LINK_TYPED(FmXGridPeer, OnExecuteGridSlot, sal_uInt16, nSlot, bool) Sequence< css::util::URL>& aUrls = getSupportedURLs(); const css::util::URL* pUrls = aUrls.getConstArray(); - Sequence<sal_uInt16> aSlots = getSupportedGridSlots(); - const sal_uInt16* pSlots = aSlots.getConstArray(); + const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); - DBG_ASSERT(aSlots.getLength() == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconstent data returned by getSupportedURLs/getSupportedGridSlots !"); + DBG_ASSERT((sal_Int32)aSlots.size() == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconstent data returned by getSupportedURLs/getSupportedGridSlots !"); - for (sal_Int32 i=0; i<aSlots.getLength(); ++i, ++pUrls, ++pSlots) + for (size_t i=0; i<aSlots.size(); ++i, ++pUrls) { - if (*pSlots == nSlot) + if (aSlots[i] == nSlot) { if (m_pDispatchers[i].is()) { diff --git a/svx/source/fmcomp/gridctrl.cxx b/svx/source/fmcomp/gridctrl.cxx index 1464a08bc90c..50662ad7573f 100644 --- a/svx/source/fmcomp/gridctrl.cxx +++ b/svx/source/fmcomp/gridctrl.cxx @@ -221,18 +221,18 @@ DisposeListenerGridBridge::~DisposeListenerGridBridge() } } -static const sal_uInt16 ControlMap[] = - { - DbGridControl::NavigationBar::RECORD_TEXT, - DbGridControl::NavigationBar::RECORD_ABSOLUTE, - DbGridControl::NavigationBar::RECORD_OF, - DbGridControl::NavigationBar::RECORD_COUNT, - DbGridControl::NavigationBar::RECORD_FIRST, - DbGridControl::NavigationBar::RECORD_NEXT, - DbGridControl::NavigationBar::RECORD_PREV, - DbGridControl::NavigationBar::RECORD_LAST, - DbGridControl::NavigationBar::RECORD_NEW, - 0 +static const DbGridControlNavigationBarState ControlMap[] = + { + DbGridControlNavigationBarState::Text, + DbGridControlNavigationBarState::Absolute, + DbGridControlNavigationBarState::Of, + DbGridControlNavigationBarState::Count, + DbGridControlNavigationBarState::First, + DbGridControlNavigationBarState::Next, + DbGridControlNavigationBarState::Prev, + DbGridControlNavigationBarState::Last, + DbGridControlNavigationBarState::New, + DbGridControlNavigationBarState::NONE }; bool CompareBookmark(const Any& aLeft, const Any& aRight) @@ -308,7 +308,7 @@ void DbGridControl::NavigationBar::AbsolutePos::LoseFocus() else { static_cast<NavigationBar*>(GetParent())->PositionDataSource(static_cast<sal_Int32>(nRecord)); - static_cast<NavigationBar*>(GetParent())->InvalidateState(NavigationBar::RECORD_ABSOLUTE); + static_cast<NavigationBar*>(GetParent())->InvalidateState(DbGridControlNavigationBarState::Absolute); } } @@ -559,15 +559,15 @@ IMPL_LINK_TYPED(DbGridControl::NavigationBar, OnClick, Button *, pButton, void ) { bool lResult = false; if (pButton == m_aFirstBtn.get()) - lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_FIRST); + lResult = pParent->m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::First); else if( pButton == m_aPrevBtn.get() ) - lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_PREV); + lResult = pParent->m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::Prev); else if( pButton == m_aNextBtn.get() ) - lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_NEXT); + lResult = pParent->m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::Next); else if( pButton == m_aLastBtn.get() ) - lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_LAST); + lResult = pParent->m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::Last); else if( pButton == m_aNewBtn.get() ) - lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_NEW); + lResult = pParent->m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::New); if (lResult) // the link already handled it @@ -604,19 +604,19 @@ void DbGridControl::NavigationBar::InvalidateAll(sal_Int32 nCurrentPos, bool bAl { m_nCurrentPos = nCurrentPos; int i = 0; - while (ControlMap[i]) + while (ControlMap[i] != DbGridControlNavigationBarState::NONE) SetState(ControlMap[i++]); } else // is in the center { m_nCurrentPos = nCurrentPos; - SetState(NavigationBar::RECORD_COUNT); - SetState(NavigationBar::RECORD_ABSOLUTE); + SetState(DbGridControlNavigationBarState::Count); + SetState(DbGridControlNavigationBarState::Absolute); } } } -bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const +bool DbGridControl::NavigationBar::GetState(DbGridControlNavigationBarState nWhich) const { DbGridControl* pParent = static_cast<DbGridControl*>(GetParent()); @@ -637,11 +637,11 @@ bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const switch (nWhich) { - case NavigationBar::RECORD_FIRST: - case NavigationBar::RECORD_PREV: + case DbGridControlNavigationBarState::First: + case DbGridControlNavigationBarState::Prev: bAvailable = m_nCurrentPos > 0; break; - case NavigationBar::RECORD_NEXT: + case DbGridControlNavigationBarState::Next: if(pParent->m_bRecordCountFinal) { bAvailable = m_nCurrentPos < pParent->GetRowCount() - 1; @@ -649,7 +649,7 @@ bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const bAvailable = (m_nCurrentPos == pParent->GetRowCount() - 2) && pParent->IsModified(); } break; - case NavigationBar::RECORD_LAST: + case DbGridControlNavigationBarState::Last: if(pParent->m_bRecordCountFinal) { if (pParent->GetOptions() & DbGridControlOptions::Insert) @@ -659,40 +659,41 @@ bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const bAvailable = m_nCurrentPos != pParent->GetRowCount() - 1; } break; - case NavigationBar::RECORD_NEW: + case DbGridControlNavigationBarState::New: bAvailable = (pParent->GetOptions() & DbGridControlOptions::Insert) && pParent->GetRowCount() && m_nCurrentPos < pParent->GetRowCount() - 1; break; - case NavigationBar::RECORD_ABSOLUTE: + case DbGridControlNavigationBarState::Absolute: bAvailable = pParent->GetRowCount() > 0; break; + default: break; } return bAvailable; } } -void DbGridControl::NavigationBar::SetState(sal_uInt16 nWhich) +void DbGridControl::NavigationBar::SetState(DbGridControlNavigationBarState nWhich) { bool bAvailable = GetState(nWhich); DbGridControl* pParent = static_cast<DbGridControl*>(GetParent()); vcl::Window* pWnd = nullptr; switch (nWhich) { - case NavigationBar::RECORD_FIRST: + case DbGridControlNavigationBarState::First: pWnd = m_aFirstBtn.get(); break; - case NavigationBar::RECORD_PREV: + case DbGridControlNavigationBarState::Prev: pWnd = m_aPrevBtn.get(); break; - case NavigationBar::RECORD_NEXT: + case DbGridControlNavigationBarState::Next: pWnd = m_aNextBtn.get(); break; - case NavigationBar::RECORD_LAST: + case DbGridControlNavigationBarState::Last: pWnd = m_aLastBtn.get(); break; - case NavigationBar::RECORD_NEW: + case DbGridControlNavigationBarState::New: pWnd = m_aNewBtn.get(); break; - case NavigationBar::RECORD_ABSOLUTE: + case DbGridControlNavigationBarState::Absolute: pWnd = m_aAbsolute.get(); if (bAvailable) { @@ -711,13 +712,13 @@ void DbGridControl::NavigationBar::SetState(sal_uInt16 nWhich) else m_aAbsolute->SetText(OUString()); break; - case NavigationBar::RECORD_TEXT: + case DbGridControlNavigationBarState::Text: pWnd = m_aRecordText.get(); break; - case NavigationBar::RECORD_OF: + case DbGridControlNavigationBarState::Of: pWnd = m_aRecordOf.get(); break; - case NavigationBar::RECORD_COUNT: + case DbGridControlNavigationBarState::Count: { pWnd = m_aRecordCount.get(); OUString aText; @@ -752,6 +753,7 @@ void DbGridControl::NavigationBar::SetState(sal_uInt16 nWhich) pParent->SetRealRowCount(aText); } break; + default: break; } DBG_ASSERT(pWnd, "kein Fenster"); if (pWnd && (pWnd->IsEnabled() != bAvailable)) @@ -1097,7 +1099,7 @@ void DbGridControl::Select() DbGridControl_Base::Select(); // as the selected rows may have changed, update the according display in our navigation bar - m_aBar->InvalidateState(NavigationBar::RECORD_COUNT); + m_aBar->InvalidateState(DbGridControlNavigationBarState::Count); if (m_pGridListener) m_pGridListener->selectionChanged(); @@ -1922,7 +1924,7 @@ void DbGridControl::RowInserted(long nRow, long nNumRows, bool bDoPaint) m_nTotalCount += nNumRows; DbGridControl_Base::RowInserted(nRow, nNumRows, bDoPaint); - m_aBar->InvalidateState(NavigationBar::RECORD_COUNT); + m_aBar->InvalidateState(DbGridControlNavigationBarState::Count); } } @@ -1941,7 +1943,7 @@ void DbGridControl::RowRemoved(long nRow, long nNumRows, bool bDoPaint) m_nTotalCount -= nNumRows; DbGridControl_Base::RowRemoved(nRow, nNumRows, bDoPaint); - m_aBar->InvalidateState(NavigationBar::RECORD_COUNT); + m_aBar->InvalidateState(DbGridControlNavigationBarState::Count); } } @@ -2005,7 +2007,7 @@ void DbGridControl::AdjustRows() else m_nTotalCount = GetRowCount(); } - m_aBar->InvalidateState(NavigationBar::RECORD_COUNT); + m_aBar->InvalidateState(DbGridControlNavigationBarState::Count); } DbGridControl_Base::RowStatus DbGridControl::GetRowStatus(long nRow) const @@ -2708,7 +2710,7 @@ void DbGridControl::PreExecuteRowContextMenu(sal_uInt16 /*nRow*/, PopupMenu& rMe bool bCanUndo = IsModified(); int nState = -1; if (m_aMasterStateProvider.IsSet()) - nState = m_aMasterStateProvider.Call(SID_FM_RECORD_UNDO); + nState = m_aMasterStateProvider.Call(DbGridControlNavigationBarState::Undo); bCanUndo &= ( 0 != nState ); rMenu.EnableItem(SID_FM_RECORD_UNDO, bCanUndo); @@ -3007,11 +3009,11 @@ void DbGridControl::Undo() // check if we have somebody doin' the UNDO for us int nState = -1; if (m_aMasterStateProvider.IsSet()) - nState = m_aMasterStateProvider.Call(SID_FM_RECORD_UNDO); + nState = m_aMasterStateProvider.Call(DbGridControlNavigationBarState::Undo); if (nState>0) { // yes, we have, and the slot is enabled DBG_ASSERT(m_aMasterSlotExecutor.IsSet(), "DbGridControl::Undo : a state, but no execute link ?"); - bool lResult = m_aMasterSlotExecutor.Call(SID_FM_RECORD_UNDO); + bool lResult = m_aMasterSlotExecutor.Call(DbGridControlNavigationBarState::Undo); if (lResult) // handled return; |