diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-11-24 17:45:31 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-11-24 22:56:33 +0100 |
commit | 502f0cde77bd45979ba3562e80b59a7d5fd8dc56 (patch) | |
tree | 3def423e053a7a0cbbe62558190bf855746e4f4d /sw | |
parent | cbdf4e007650cfda4f7808402e8e24ae66d45792 (diff) |
SwContentTree: those 3 booleans are mutually exclusive
Which is not immediately obvious but SwContentTree::Display() will set
them accordingly, and it looks like none of the code that currently
sees 0 or 2 booleans set checks them before Display() cleans them up.
Replace with a state enum which is much more obvious.
Change-Id: I75aaf10dd2e8e1e0547bad1fabb1b6ab48220d62
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/inc/conttree.hxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 106 |
2 files changed, 56 insertions, 65 deletions
diff --git a/sw/source/uibase/inc/conttree.hxx b/sw/source/uibase/inc/conttree.hxx index 4dd2bf4db31a..5d61660c55bb 100644 --- a/sw/source/uibase/inc/conttree.hxx +++ b/sw/source/uibase/inc/conttree.hxx @@ -85,9 +85,8 @@ class SwContentTree ContentTypeId m_nLastSelType; sal_uInt8 m_nOutlineLevel; - bool m_bIsActive :1; - bool m_bIsConstant :1; - bool m_bIsHidden :1; + enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState; + bool m_bDocChgdInDragging :1; bool m_bIsInternalDrag :1; bool m_bIsRoot :1; @@ -184,9 +183,7 @@ public: void SetConstantShell(SwWrtShell* pSh); SwWrtShell* GetWrtShell() - {return m_bIsActive||m_bIsConstant ? - m_pActiveShell : - m_pHiddenShell;} + { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; } static bool IsInDrag() {return bIsInDrag;} @@ -205,9 +202,9 @@ public: /** folded together will not be glidled */ void HideTree(); - bool IsConstantView() {return m_bIsConstant;} - bool IsActiveView() {return m_bIsActive;} - bool IsHiddenView() {return m_bIsHidden;} + bool IsConstantView() { return State::CONSTANT == m_eState; } + bool IsActiveView() { return State::ACTIVE == m_eState; } + bool IsHiddenView() { return State::HIDDEN == m_eState; } const SwWrtShell* GetActiveWrtShell() {return m_pActiveShell;} SwWrtShell* GetHiddenWrtShell() {return m_pHiddenShell;} diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx index 971e4a4b9677..ac97ec496c72 100644 --- a/sw/source/uibase/utlui/content.cxx +++ b/sw/source/uibase/utlui/content.cxx @@ -789,9 +789,7 @@ SwContentTree::SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog) , m_nRootType(ContentTypeId::UNKNOWN) , m_nLastSelType(ContentTypeId::UNKNOWN) , m_nOutlineLevel(MAXLEVEL) - , m_bIsActive(true) - , m_bIsConstant(false) - , m_bIsHidden(false) + , m_eState(State::ACTIVE) , m_bDocChgdInDragging(false) , m_bIsInternalDrag(false) , m_bIsRoot(false) @@ -1135,7 +1133,7 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu() sInsert += ")"; } pSubPop3->InsertItem(nId, sInsert); - if(m_bIsConstant && m_pActiveShell == &pView->GetWrtShell()) + if (State::CONSTANT == m_eState && m_pActiveShell == &pView->GetWrtShell()) pSubPop3->CheckItem(nId); pView = SwModule::GetNextView(pView); nId++; @@ -1150,9 +1148,9 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu() pSubPop3->InsertItem(nId, sHiddenEntry); } - if(m_bIsActive) + if (State::ACTIVE == m_eState) pSubPop3->CheckItem( --nId ); - else if(m_bIsHidden) + else if (State::HIDDEN == m_eState) pSubPop3->CheckItem( nId ); pPop->InsertItem( 1, m_aContextStrings[STR_OUTLINE_LEVEL - STR_CONTEXT_FIRST]); @@ -1161,7 +1159,7 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu() // Now edit SvTreeListEntry* pEntry = nullptr; // Edit only if the shown content is coming from the current view. - if((m_bIsActive || m_pActiveShell == pActiveView->GetWrtShellPtr()) + if ((State::ACTIVE == m_eState || m_pActiveShell == pActiveView->GetWrtShellPtr()) && nullptr != (pEntry = FirstSelected()) && lcl_IsContent(pEntry)) { assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData()))); @@ -1422,7 +1420,7 @@ bool SwContentTree::Expand( SvTreeListEntry* pParent ) { SwContentType* pCntType = static_cast<SwContentType*>(pParent->GetUserData()); const sal_Int32 nOr = 1 << (int)pCntType->GetType(); //linear -> Bitposition - if(m_bIsActive || m_bIsConstant) + if (State::HIDDEN != m_eState) { m_nActiveBlock |= nOr; m_pConfig->SetActiveBlock(m_nActiveBlock); @@ -1483,7 +1481,7 @@ bool SwContentTree::Collapse( SvTreeListEntry* pParent ) return false; SwContentType* pCntType = static_cast<SwContentType*>(pParent->GetUserData()); const sal_Int32 nAnd = ~(1 << (int)pCntType->GetType()); - if(m_bIsActive || m_bIsConstant) + if (State::HIDDEN != m_eState) { m_nActiveBlock &= nAnd; m_pConfig->SetActiveBlock(m_nActiveBlock); @@ -1515,9 +1513,9 @@ IMPL_LINK_NOARG(SwContentTree, ContentDoubleClickHdl, SvTreeListBox*, bool) { if(lcl_IsContentType(pEntry) && !pEntry->HasChildren()) RequestingChildren(pEntry); - else if(!lcl_IsContentType(pEntry) && (m_bIsActive || m_bIsConstant)) + else if (!lcl_IsContentType(pEntry) && (State::HIDDEN != m_eState)) { - if(m_bIsConstant) + if (State::CONSTANT == m_eState) { m_pActiveShell->GetView().GetViewFrame()->GetWindow().ToTop(); } @@ -1566,9 +1564,10 @@ void SwContentTree::Display( bool bActive ) } Clear(); SetUpdateMode( false ); - if(bActive && !m_bIsConstant && !m_bIsActive) - m_bIsActive = bActive; - m_bIsHidden = !bActive; + if (!bActive) + m_eState = State::HIDDEN; + else if (State::HIDDEN == m_eState) + m_eState = State::ACTIVE; SwWrtShell* pShell = GetWrtShell(); const bool bReadOnly = !pShell || pShell->GetView().GetDocShell()->IsReadOnly(); if(bReadOnly != m_bIsLastReadOnly) @@ -1603,9 +1602,9 @@ void SwContentTree::Display( bool bActive ) nullptr, bChOnDemand, TREELIST_APPEND, (*ppContentT)); if(nCntType == m_nLastSelType) pSelEntry = pEntry; - sal_Int32 nExpandOptions = m_bIsActive || m_bIsConstant ? - m_nActiveBlock : - m_nHiddenBlock; + sal_Int32 nExpandOptions = (State::HIDDEN == m_eState) + ? m_nHiddenBlock + : m_nActiveBlock; if(nExpandOptions & (1 << (int)nCntType)) { Expand(pEntry); @@ -1671,7 +1670,7 @@ void SwContentTree::Display( bool bActive ) else RequestingChildren(pParent); Expand(pParent); - if( m_nRootType == ContentTypeId::OUTLINE && m_bIsActive ) + if (m_nRootType == ContentTypeId::OUTLINE && State::ACTIVE == m_eState) { // find out where the cursor is const sal_uInt16 nActPos = pShell->GetOutlinePos(MAXLEVEL); @@ -1822,7 +1821,7 @@ bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer, // without a filename into its own document. bRet = true; } - else if(m_bIsConstant && + else if (State::CONSTANT == m_eState && ( !::GetActiveView() || m_pActiveShell != ::GetActiveView()->GetWrtShellPtr())) { @@ -1891,7 +1890,7 @@ void SwContentTree::ToggleToRoot() } m_nRootType = pCntType->GetType(); m_bIsRoot = true; - Display(m_bIsActive || m_bIsConstant); + Display(State::HIDDEN != m_eState); } } else @@ -1899,7 +1898,7 @@ void SwContentTree::ToggleToRoot() m_nRootType = ContentTypeId::UNKNOWN; m_bIsRoot = false; FindActiveTypeAndRemoveUserData(); - Display(m_bIsActive || m_bIsConstant); + Display(State::HIDDEN != m_eState); if( m_bIsKeySpace ) { HideFocus(); @@ -1929,7 +1928,7 @@ bool SwContentTree::HasContentChanged() bool bRepaint = false; bool bInvalidate = false; - if(!m_bIsActive && ! m_bIsConstant) + if (State::HIDDEN == m_eState) { for(ContentTypeId i : o3tl::enumrange<ContentTypeId>()) { @@ -2156,14 +2155,13 @@ void SwContentTree::FindActiveTypeAndRemoveUserData() void SwContentTree::SetHiddenShell(SwWrtShell* pSh) { m_pHiddenShell = pSh; - m_bIsHidden = true; - m_bIsActive = m_bIsConstant = false; + m_eState = State::HIDDEN; FindActiveTypeAndRemoveUserData(); for(ContentTypeId i : o3tl::enumrange<ContentTypeId>()) { DELETEZ(m_aHiddenContentArr[i]); } - Display(m_bIsActive); + Display(false); GetParentWindow()->UpdateListBox(); } @@ -2173,7 +2171,7 @@ void SwContentTree::SetActiveShell(SwWrtShell* pSh) if(m_bIsInternalDrag) m_bDocChgdInDragging = true; bool bClear = m_pActiveShell != pSh; - if(m_bIsActive && bClear) + if (State::ACTIVE == m_eState && bClear) { if (m_pActiveShell) EndListening(*m_pActiveShell->GetView().GetDocShell()); @@ -2181,18 +2179,17 @@ void SwContentTree::SetActiveShell(SwWrtShell* pSh) FindActiveTypeAndRemoveUserData(); Clear(); } - else if(m_bIsConstant) + else if (State::CONSTANT == m_eState) { if (m_pActiveShell) EndListening(*m_pActiveShell->GetView().GetDocShell()); m_pActiveShell = pSh; - m_bIsActive = true; - m_bIsConstant = false; + m_eState = State::ACTIVE; bClear = true; } // Only if it is the active view, the array will be deleted and // the screen filled new. - if(m_bIsActive && bClear) + if (State::ACTIVE == m_eState && bClear) { if (m_pActiveShell) StartListening(*m_pActiveShell->GetView().GetDocShell()); @@ -2210,8 +2207,7 @@ void SwContentTree::SetConstantShell(SwWrtShell* pSh) if (m_pActiveShell) EndListening(*m_pActiveShell->GetView().GetDocShell()); m_pActiveShell = pSh; - m_bIsActive = false; - m_bIsConstant = true; + m_eState = State::CONSTANT; StartListening(*m_pActiveShell->GetView().GetDocShell()); FindActiveTypeAndRemoveUserData(); for(ContentTypeId i : o3tl::enumrange<ContentTypeId>()) @@ -2247,8 +2243,8 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bModifier) if (!bUpDown && !bLeftRight) return; if( !GetWrtShell()->GetView().GetDocShell()->IsReadOnly() && - (m_bIsActive || - (m_bIsConstant && m_pActiveShell == GetParentWindow()->GetCreateView()->GetWrtShellPtr()))) + (State::ACTIVE == m_eState || + (State::CONSTANT == m_eState && m_pActiveShell == GetParentWindow()->GetCreateView()->GetWrtShellPtr()))) { SwWrtShell* pShell = GetWrtShell(); sal_Int8 nActOutlineLevel = m_nOutlineLevel; @@ -2425,24 +2421,24 @@ IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void) m_bViewHasChanged = false; m_bIsIdleClear = false; SwWrtShell* pActShell = pView->GetWrtShellPtr(); - if( m_bIsConstant && !lcl_FindShell( m_pActiveShell ) ) + if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell)) { SetActiveShell(pActShell); GetParentWindow()->UpdateListBox(); } - if(m_bIsActive && pActShell != GetWrtShell()) + if (State::ACTIVE == m_eState && pActShell != GetWrtShell()) { SetActiveShell(pActShell); } - else if( (m_bIsActive || (m_bIsConstant && pActShell == GetWrtShell())) && + else if ((State::ACTIVE == m_eState || (State::CONSTANT == m_eState && pActShell == GetWrtShell())) && HasContentChanged()) { FindActiveTypeAndRemoveUserData(); Display(true); } } - else if(!pView && m_bIsActive && !m_bIsIdleClear) + else if (!pView && State::ACTIVE == m_eState && !m_bIsIdleClear) { if(m_pActiveShell) { @@ -2458,11 +2454,11 @@ DragDropMode SwContentTree::NotifyStartDrag( SvTreeListEntry* pEntry ) { DragDropMode eMode = (DragDropMode)0; - if( m_bIsActive && m_nRootType == ContentTypeId::OUTLINE && + if (State::ACTIVE == m_eState && m_nRootType == ContentTypeId::OUTLINE && GetModel()->GetAbsPos( pEntry ) > 0 && !GetWrtShell()->GetView().GetDocShell()->IsReadOnly()) eMode = GetDragDropMode(); - else if(!m_bIsActive && GetWrtShell()->GetView().GetDocShell()->HasName()) + else if (State::ACTIVE != m_eState && GetWrtShell()->GetView().GetDocShell()->HasName()) eMode = DragDropMode::APP_COPY; sal_Int8 nDragMode; @@ -2586,20 +2582,20 @@ void SwContentTree::GetFocus() if(pActView) { SwWrtShell* pActShell = pActView->GetWrtShellPtr(); - if(m_bIsConstant && !lcl_FindShell(m_pActiveShell)) + if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell)) { SetActiveShell(pActShell); } - if(m_bIsActive && pActShell != GetWrtShell()) + if (State::ACTIVE == m_eState && pActShell != GetWrtShell()) SetActiveShell(pActShell); - else if( (m_bIsActive || (m_bIsConstant && pActShell == GetWrtShell())) && + else if ((State::ACTIVE == m_eState || (State::CONSTANT == m_eState && pActShell == GetWrtShell())) && HasContentChanged()) { Display(true); } } - else if(m_bIsActive) + else if (State::ACTIVE == m_eState) Clear(); SvTreeListBox::GetFocus(); } @@ -2662,9 +2658,9 @@ void SwContentTree::KeyInput(const KeyEvent& rEvent) if(pEntry) { - if(m_bIsActive || m_bIsConstant) + if (State::HIDDEN != m_eState) { - if(m_bIsConstant) + if (State::CONSTANT == m_eState) { m_pActiveShell->GetView().GetViewFrame()->GetWindow().ToTop(); } @@ -2967,8 +2963,8 @@ void SwContentTree::ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) } if(nSelectedPopupEntry) { - m_bViewHasChanged = m_bIsActive = nSelectedPopupEntry == 1; - m_bIsConstant = false; + m_bViewHasChanged = nSelectedPopupEntry == 1; + m_eState = (nSelectedPopupEntry == 1) ? State::ACTIVE : State::HIDDEN; Display(nSelectedPopupEntry == 1); } } @@ -2980,15 +2976,15 @@ void SwContentTree::SetOutlineLevel(sal_uInt8 nSet) { m_nOutlineLevel = nSet; m_pConfig->SetOutlineLevel( m_nOutlineLevel ); - SwContentType** ppContentT = m_bIsActive ? - &m_aActiveContentArr[ContentTypeId::OUTLINE] : - &m_aHiddenContentArr[ContentTypeId::OUTLINE]; + SwContentType** ppContentT = (State::ACTIVE == m_eState) + ? &m_aActiveContentArr[ContentTypeId::OUTLINE] + : &m_aHiddenContentArr[ContentTypeId::OUTLINE]; if(*ppContentT) { (*ppContentT)->SetOutlineLevel(m_nOutlineLevel); (*ppContentT)->Init(); } - Display(m_bIsActive); + Display(State::ACTIVE == m_eState); } // Mode Change: Show dropped Doc @@ -2997,8 +2993,7 @@ void SwContentTree::ShowHiddenShell() { if(m_pHiddenShell) { - m_bIsConstant = false; - m_bIsActive = false; + m_eState = State::HIDDEN; Display(false); } } @@ -3007,8 +3002,7 @@ void SwContentTree::ShowHiddenShell() void SwContentTree::ShowActualView() { - m_bIsActive = true; - m_bIsConstant = false; + m_eState = State::ACTIVE; Display(true); GetParentWindow()->UpdateListBox(); } |