compilerplugins/clang/flatten.cxx | 7 sw/source/uibase/utlui/attrdesc.cxx | 26 +-- sw/source/uibase/utlui/bookctrl.cxx | 58 +++---- sw/source/uibase/utlui/glbltree.cxx | 28 +-- sw/source/uibase/utlui/navicfg.cxx | 58 +++---- sw/source/uibase/utlui/navipi.cxx | 87 +++++------ sw/source/uibase/utlui/tmplctrl.cxx | 66 ++++---- sw/source/uibase/utlui/uitool.cxx | 44 ++--- sw/source/uibase/utlui/unotools.cxx | 50 +++--- sw/source/uibase/wrtsh/navmgr.cxx | 82 +++++------ sw/source/uibase/wrtsh/select.cxx | 34 ++-- sw/source/uibase/wrtsh/wrtsh1.cxx | 266 ++++++++++++++++++------------------ sw/source/uibase/wrtsh/wrtsh2.cxx | 76 +++++----- 13 files changed, 443 insertions(+), 439 deletions(-)
New commits: commit 6af041b8160a7193ed24df9a1adc117dda61cd65 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jul 30 10:41:56 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Jul 30 12:18:29 2020 +0200 loplugin:flatten in sw/uibase/utl..sw/uibase/wrtsh Change-Id: I9010524952ce3b99a62e53dbf715a72c86a89b01 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99766 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx index bac4ae8a4370..a615b8366b63 100644 --- a/compilerplugins/clang/flatten.cxx +++ b/compilerplugins/clang/flatten.cxx @@ -427,7 +427,7 @@ llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, Sour // an if statement will automatically invoke a bool-conversion method if (auto memberCallExpr = dyn_cast<CXXMemberCallExpr>(condExpr)) { - if (isa<CXXConversionDecl>(memberCallExpr->getMethodDecl())) + if (memberCallExpr->getMethodDecl() && isa<CXXConversionDecl>(memberCallExpr->getMethodDecl())) condExpr = memberCallExpr->getImplicitObjectArgument()->IgnoreImpCasts(); } @@ -665,6 +665,11 @@ std::string Flatten::getSourceAsString(SourceRange range) // in case it happens during code replacement return "clang returned bad pointers"; } + if (p2 - p1 > 64 * 1024) { + // workaround clang weirdness, but don't return empty string + // in case it happens during code replacement + return "clang returned overlay large source range"; + } return std::string( p1, p2 - p1); } diff --git a/sw/source/uibase/utlui/attrdesc.cxx b/sw/source/uibase/utlui/attrdesc.cxx index a839c436f725..98c092246a81 100644 --- a/sw/source/uibase/utlui/attrdesc.cxx +++ b/sw/source/uibase/utlui/attrdesc.cxx @@ -68,20 +68,20 @@ void SwAttrSet::GetPresentation( { rText.clear(); OUString aStr; - if( Count() ) + if( !Count() ) + return; + + SfxItemIter aIter( *this ); + const SfxPoolItem* pItem = aIter.GetCurItem(); + const IntlWrapper aInt(SvtSysLocale().GetUILanguageTag()); + do { - SfxItemIter aIter( *this ); - const SfxPoolItem* pItem = aIter.GetCurItem(); - const IntlWrapper aInt(SvtSysLocale().GetUILanguageTag()); - do - { - pItem->GetPresentation(ePres, eCoreMetric, ePresMetric, aStr, aInt); - if( rText.getLength() && aStr.getLength() ) - rText += ", "; - rText += aStr; - pItem = aIter.NextItem(); - } while (pItem); - } + pItem->GetPresentation(ePres, eCoreMetric, ePresMetric, aStr, aInt); + if( rText.getLength() && aStr.getLength() ) + rText += ", "; + rText += aStr; + pItem = aIter.NextItem(); + } while (pItem); } bool SwFormatCharFormat::GetPresentation diff --git a/sw/source/uibase/utlui/bookctrl.cxx b/sw/source/uibase/utlui/bookctrl.cxx index ea9c1d7429f5..aa1f84506d0e 100644 --- a/sw/source/uibase/utlui/bookctrl.cxx +++ b/sw/source/uibase/utlui/bookctrl.cxx @@ -103,39 +103,39 @@ void SwBookmarkControl::Paint( const UserDrawEvent& ) void SwBookmarkControl::Command( const CommandEvent& rCEvt ) { - if ( rCEvt.GetCommand() == CommandEventId::ContextMenu && - !GetStatusBar().GetItemText( GetId() ).isEmpty() ) + if ( rCEvt.GetCommand() != CommandEventId::ContextMenu || + GetStatusBar().GetItemText( GetId() ).isEmpty()) + return; + + ScopedVclPtrInstance<BookmarkPopup_Impl> aPop; + SwWrtShell* pWrtShell = ::GetActiveWrtShell(); + if( !(pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0) ) + return; + + IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess(); + IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin(); + sal_uInt16 nPopupId = 1; + std::map<sal_Int32, sal_uInt16> aBookmarkIdx; + for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart; + ppBookmark != pMarkAccess->getBookmarksEnd(); + ++ppBookmark) { - ScopedVclPtrInstance<BookmarkPopup_Impl> aPop; - SwWrtShell* pWrtShell = ::GetActiveWrtShell(); - if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 ) + if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) { - IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess(); - IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin(); - sal_uInt16 nPopupId = 1; - std::map<sal_Int32, sal_uInt16> aBookmarkIdx; - for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart; - ppBookmark != pMarkAccess->getBookmarksEnd(); - ++ppBookmark) - { - if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) - { - aPop->InsertItem( nPopupId, (*ppBookmark)->GetName() ); - aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); - nPopupId++; - } - } - aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); - sal_uInt16 nCurrId = aPop->GetCurId(); - if( nCurrId != USHRT_MAX) - { - SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] ); - SfxViewFrame::Current()->GetDispatcher()->ExecuteList(FN_STAT_BOOKMARK, - SfxCallMode::ASYNCHRON|SfxCallMode::RECORD, - { &aBookmark }); - } + aPop->InsertItem( nPopupId, (*ppBookmark)->GetName() ); + aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); + nPopupId++; } } + aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); + sal_uInt16 nCurrId = aPop->GetCurId(); + if( nCurrId != USHRT_MAX) + { + SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] ); + SfxViewFrame::Current()->GetDispatcher()->ExecuteList(FN_STAT_BOOKMARK, + SfxCallMode::ASYNCHRON|SfxCallMode::RECORD, + { &aBookmark }); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx index ed8e87abf2c8..751b4b256879 100644 --- a/sw/source/uibase/utlui/glbltree.cxx +++ b/sw/source/uibase/utlui/glbltree.cxx @@ -1069,22 +1069,22 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, vo return; SfxMediumList aMedList(m_pDocInserter->CreateMediumList()); - if ( !aMedList.empty() ) + if ( aMedList.empty() ) + return; + + Sequence< OUString >aFileNames( aMedList.size() ); + OUString* pFileNames = aFileNames.getArray(); + sal_Int32 nPos = 0; + for (const std::unique_ptr<SfxMedium>& pMed : aMedList) { - Sequence< OUString >aFileNames( aMedList.size() ); - OUString* pFileNames = aFileNames.getArray(); - sal_Int32 nPos = 0; - for (const std::unique_ptr<SfxMedium>& pMed : aMedList) - { - OUString sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ) - + OUStringChar(sfx2::cTokenSeparator) - + pMed->GetFilter()->GetFilterName() - + OUStringChar(sfx2::cTokenSeparator); - pFileNames[nPos++] = sFileName; - } - InsertRegion( m_pDocContent.get(), aFileNames ); - m_pDocContent.reset(); + OUString sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ) + + OUStringChar(sfx2::cTokenSeparator) + + pMed->GetFilter()->GetFilterName() + + OUStringChar(sfx2::cTokenSeparator); + pFileNames[nPos++] = sFileName; } + InsertRegion( m_pDocContent.get(), aFileNames ); + m_pDocContent.reset(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/utlui/navicfg.cxx b/sw/source/uibase/utlui/navicfg.cxx index f1b4f39834d9..b28ff4f755ba 100644 --- a/sw/source/uibase/utlui/navicfg.cxx +++ b/sw/source/uibase/utlui/navicfg.cxx @@ -54,44 +54,44 @@ SwNavigationConfig::SwNavigationConfig() : Sequence<Any> aValues = GetProperties(aNames); const Any* pValues = aValues.getConstArray(); OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed"); - if(aValues.getLength() == aNames.getLength()) + if(aValues.getLength() != aNames.getLength()) + return; + + for(int nProp = 0; nProp < aNames.getLength(); nProp++) { - for(int nProp = 0; nProp < aNames.getLength(); nProp++) + if(pValues[nProp].hasValue()) { - if(pValues[nProp].hasValue()) + switch(nProp) { - switch(nProp) + case 0: { - case 0: + sal_Int32 nTmp = {}; // spurious -Werror=maybe-uninitialized + if (pValues[nProp] >>= nTmp) { - sal_Int32 nTmp = {}; // spurious -Werror=maybe-uninitialized - if (pValues[nProp] >>= nTmp) + if (nTmp < sal_Int32(ContentTypeId::UNKNOWN) + || nTmp > sal_Int32(ContentTypeId::LAST)) { - if (nTmp < sal_Int32(ContentTypeId::UNKNOWN) - || nTmp > sal_Int32(ContentTypeId::LAST)) - { - SAL_WARN( - "sw", - "out-of-bounds ContentTypeId " << nTmp); - nTmp = sal_Int32(ContentTypeId::UNKNOWN); - } - nRootType = static_cast<ContentTypeId>(nTmp); + SAL_WARN( + "sw", + "out-of-bounds ContentTypeId " << nTmp); + nTmp = sal_Int32(ContentTypeId::UNKNOWN); } - break; - } - case 1: pValues[nProp] >>= nSelectedPos; break; - case 2: pValues[nProp] >>= nOutlineLevel; break; - case 3: - { - sal_uInt16 nTmp; - if (pValues[nProp] >>= nTmp) - nRegionMode = static_cast<RegionMode>(nTmp); - break; + nRootType = static_cast<ContentTypeId>(nTmp); } - case 4: pValues[nProp] >>= nActiveBlock; break; - case 5: bIsSmall = *o3tl::doAccess<bool>(pValues[nProp]); break; - case 6: bIsGlobalActive = *o3tl::doAccess<bool>(pValues[nProp]); break; + break; + } + case 1: pValues[nProp] >>= nSelectedPos; break; + case 2: pValues[nProp] >>= nOutlineLevel; break; + case 3: + { + sal_uInt16 nTmp; + if (pValues[nProp] >>= nTmp) + nRegionMode = static_cast<RegionMode>(nTmp); + break; } + case 4: pValues[nProp] >>= nActiveBlock; break; + case 5: bIsSmall = *o3tl::doAccess<bool>(pValues[nProp]); break; + case 6: bIsGlobalActive = *o3tl::doAccess<bool>(pValues[nProp]); break; } } } diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx index 577aba8fc645..1da86f1b917e 100644 --- a/sw/source/uibase/utlui/navipi.cxx +++ b/sw/source/uibase/utlui/navipi.cxx @@ -92,25 +92,24 @@ void SwNavigationPI::MoveOutline(SwOutlineNodes::size_type nSource, SwOutlineNod SwWrtShell &rSh = pView->GetWrtShell(); if(nTarget < nSource || nTarget == SwOutlineNodes::npos) nTarget ++; - if ( rSh.IsOutlineMovable( nSource )) - { + if ( !rSh.IsOutlineMovable( nSource )) + return; - SwOutlineNodes::difference_type nMove = nTarget-nSource; //( nDir<0 ) ? 1 : 0 ; - rSh.GotoOutline(nSource); - rSh.MakeOutlineSel(nSource, nSource, true); - // While moving, the selected children does not counting. - const SwOutlineNodes::size_type nLastOutlinePos = rSh.GetOutlinePos(MAXLEVEL); - if(nMove > 1 && nLastOutlinePos < nTarget) - { - if(!rSh.IsCursorPtAtEnd()) - rSh.SwapPam(); - nMove -= nLastOutlinePos - nSource; - } - if( nMove < 1 || nLastOutlinePos < nTarget ) - rSh.MoveOutlinePara( nMove ); - rSh.ClearMark(); - rSh.GotoOutline( nSource + nMove); + SwOutlineNodes::difference_type nMove = nTarget-nSource; //( nDir<0 ) ? 1 : 0 ; + rSh.GotoOutline(nSource); + rSh.MakeOutlineSel(nSource, nSource, true); + // While moving, the selected children does not counting. + const SwOutlineNodes::size_type nLastOutlinePos = rSh.GetOutlinePos(MAXLEVEL); + if(nMove > 1 && nLastOutlinePos < nTarget) + { + if(!rSh.IsCursorPtAtEnd()) + rSh.SwapPam(); + nMove -= nLastOutlinePos - nSource; } + if( nMove < 1 || nLastOutlinePos < nTarget ) + rSh.MoveOutlinePara( nMove ); + rSh.ClearMark(); + rSh.GotoOutline( nSource + nMove); } @@ -348,20 +347,20 @@ IMPL_LINK(SwNavigationPI, ToolBox3DropdownClickHdl, const OString&, rCommand, vo if (!m_xContent3ToolBox->get_menu_item_active(rCommand)) return; - if (rCommand == "dragmode") + if (rCommand != "dragmode") + return; + + switch (m_nRegionMode) { - switch (m_nRegionMode) - { - case RegionMode::NONE: - m_xDragModeMenu->set_active("hyperlink", true); - break; - case RegionMode::LINK: - m_xDragModeMenu->set_active("link", true); - break; - case RegionMode::EMBEDDED: - m_xDragModeMenu->set_active("copy", true); - break; - } + case RegionMode::NONE: + m_xDragModeMenu->set_active("hyperlink", true); + break; + case RegionMode::LINK: + m_xDragModeMenu->set_active("link", true); + break; + case RegionMode::EMBEDDED: + m_xDragModeMenu->set_active("copy", true); + break; } } @@ -867,21 +866,21 @@ void SwNavigationPI::UpdateListBox() IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem const *, pItem, void) { const SfxViewFrameItem* pFrameItem = dynamic_cast<SfxViewFrameItem const *>( pItem ); - if( pFrameItem ) + if( !pFrameItem ) + return; + + SfxViewFrame* pFrame = pFrameItem->GetFrame(); + if(pFrame) { - SfxViewFrame* pFrame = pFrameItem->GetFrame(); - if(pFrame) - { - m_xContentTree->clear(); - m_pContentView = dynamic_cast<SwView*>( pFrame->GetViewShell() ); - OSL_ENSURE(m_pContentView, "no SwView"); - if(m_pContentView) - m_pContentWrtShell = m_pContentView->GetWrtShellPtr(); - else - m_pContentWrtShell = nullptr; - m_pxObjectShell.reset( new SfxObjectShellLock(pFrame->GetObjectShell()) ); - FillBox(); - } + m_xContentTree->clear(); + m_pContentView = dynamic_cast<SwView*>( pFrame->GetViewShell() ); + OSL_ENSURE(m_pContentView, "no SwView"); + if(m_pContentView) + m_pContentWrtShell = m_pContentView->GetWrtShellPtr(); + else + m_pContentWrtShell = nullptr; + m_pxObjectShell.reset( new SfxObjectShellLock(pFrame->GetObjectShell()) ); + FillBox(); } } diff --git a/sw/source/uibase/utlui/tmplctrl.cxx b/sw/source/uibase/utlui/tmplctrl.cxx index 2220c776e2b6..d398dadee0b8 100644 --- a/sw/source/uibase/utlui/tmplctrl.cxx +++ b/sw/source/uibase/utlui/tmplctrl.cxx @@ -96,43 +96,43 @@ void SwTemplateControl::Paint( const UserDrawEvent& ) void SwTemplateControl::Command( const CommandEvent& rCEvt ) { - if ( rCEvt.GetCommand() == CommandEventId::ContextMenu && - !GetStatusBar().GetItemText( GetId() ).isEmpty() ) + if ( rCEvt.GetCommand() != CommandEventId::ContextMenu || + GetStatusBar().GetItemText( GetId() ).isEmpty()) + return; + + ScopedVclPtrInstance<SwTemplatePopup_Impl> aPop; { - ScopedVclPtrInstance<SwTemplatePopup_Impl> aPop; + SwView* pView = ::GetActiveView(); + SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr); + if (nullptr != pWrtShell && + !pWrtShell->SwCursorShell::HasSelection()&& + !pWrtShell->IsSelFrameMode() && + !pWrtShell->IsObjSelected()) { - SwView* pView = ::GetActiveView(); - SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr); - if (nullptr != pWrtShell && - !pWrtShell->SwCursorShell::HasSelection()&& - !pWrtShell->IsSelFrameMode() && - !pWrtShell->IsObjSelected()) + SfxStyleSheetBasePool* pPool = pView->GetDocShell()-> + GetStyleSheetPool(); + auto xIter = pPool->CreateIterator(SfxStyleFamily::Page); + if (xIter->Count() > 1) { - SfxStyleSheetBasePool* pPool = pView->GetDocShell()-> - GetStyleSheetPool(); - auto xIter = pPool->CreateIterator(SfxStyleFamily::Page); - if (xIter->Count() > 1) + sal_uInt16 nCount = 0; + SfxStyleSheetBase* pStyle = xIter->First(); + while( pStyle ) + { + aPop->InsertItem( ++nCount, pStyle->GetName() ); + pStyle = xIter->Next(); + } + + aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); + const sal_uInt16 nCurrId = aPop->GetCurId(); + if( nCurrId != USHRT_MAX) { - sal_uInt16 nCount = 0; - SfxStyleSheetBase* pStyle = xIter->First(); - while( pStyle ) - { - aPop->InsertItem( ++nCount, pStyle->GetName() ); - pStyle = xIter->Next(); - } - - aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); - const sal_uInt16 nCurrId = aPop->GetCurId(); - if( nCurrId != USHRT_MAX) - { - // looks a bit awkward, but another way is not possible - pStyle = xIter->operator[]( nCurrId - 1 ); - SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() ); - pWrtShell->GetView().GetViewFrame()->GetDispatcher()->ExecuteList( - FN_SET_PAGE_STYLE, - SfxCallMode::SLOT|SfxCallMode::RECORD, - { &aStyle }); - } + // looks a bit awkward, but another way is not possible + pStyle = xIter->operator[]( nCurrId - 1 ); + SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() ); + pWrtShell->GetView().GetViewFrame()->GetDispatcher()->ExecuteList( + FN_SET_PAGE_STYLE, + SfxCallMode::SLOT|SfxCallMode::RECORD, + { &aStyle }); } } } diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx index 742d354c495c..f8871b8f3c28 100644 --- a/sw/source/uibase/utlui/uitool.cxx +++ b/sw/source/uibase/utlui/uitool.cxx @@ -373,32 +373,32 @@ void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc ) // Register compliant - if(SfxItemState::SET == rSet.GetItemState( + if(SfxItemState::SET != rSet.GetItemState( SID_SWREGISTER_MODE, false, &pItem)) + return; + + bool bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + if(!bSet) + rPageDesc.SetRegisterFormatColl(nullptr); + else if(SfxItemState::SET == rSet.GetItemState( + SID_SWREGISTER_COLLECTION, false, &pItem)) { - bool bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue(); - if(!bSet) - rPageDesc.SetRegisterFormatColl(nullptr); - else if(SfxItemState::SET == rSet.GetItemState( - SID_SWREGISTER_COLLECTION, false, &pItem)) + const OUString& rColl = static_cast<const SfxStringItem*>(pItem)->GetValue(); + SwDoc& rDoc = *rMaster.GetDoc(); + SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( rColl ); + if( !pColl ) { - const OUString& rColl = static_cast<const SfxStringItem*>(pItem)->GetValue(); - SwDoc& rDoc = *rMaster.GetDoc(); - SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( rColl ); - if( !pColl ) - { - const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( - rColl, SwGetPoolIdFromName::TxtColl ); - if( USHRT_MAX != nId ) - pColl = rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool( nId ); - else - pColl = rDoc.MakeTextFormatColl( rColl, - rDoc.GetDfltTextFormatColl() ); - } - if( pColl ) - pColl->SetFormatAttr( SwRegisterItem ( true )); - rPageDesc.SetRegisterFormatColl( pColl ); + const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( + rColl, SwGetPoolIdFromName::TxtColl ); + if( USHRT_MAX != nId ) + pColl = rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool( nId ); + else + pColl = rDoc.MakeTextFormatColl( rColl, + rDoc.GetDfltTextFormatColl() ); } + if( pColl ) + pColl->SetFormatAttr( SwRegisterItem ( true )); + rPageDesc.SetRegisterFormatColl( pColl ); } } diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx index c7f46d63982c..e580e0b5817a 100644 --- a/sw/source/uibase/utlui/unotools.cxx +++ b/sw/source/uibase/utlui/unotools.cxx @@ -428,34 +428,34 @@ IMPL_LINK( SwOneExampleFrame, TimeoutHdl, Timer*, pTimer, void ) void SwOneExampleFrame::ClearDocument() { uno::Reference< lang::XUnoTunnel> xTunnel( m_xCursor, uno::UNO_QUERY); - if( xTunnel.is() ) + if( !xTunnel.is() ) + return; + + OTextCursorHelper* pCursor = reinterpret_cast<OTextCursorHelper*>(xTunnel->getSomething( + OTextCursorHelper::getUnoTunnelId()) ); + if( pCursor ) { - OTextCursorHelper* pCursor = reinterpret_cast<OTextCursorHelper*>(xTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId()) ); - if( pCursor ) - { - SwDoc* pDoc = pCursor->GetDoc(); - SwEditShell* pSh = pDoc->GetEditShell(); - pSh->LockPaint(); - pSh->StartAllAction(); - pSh->KillPams(); - pSh->ClearMark(); - pDoc->ClearDoc(); - pSh->ClearUpCursors(); - - if( m_aLoadedIdle.IsActive()) - { - pSh->EndAllAction(); - pSh->UnlockPaint(); - } - m_aLoadedIdle.Start(); - } - else + SwDoc* pDoc = pCursor->GetDoc(); + SwEditShell* pSh = pDoc->GetEditShell(); + pSh->LockPaint(); + pSh->StartAllAction(); + pSh->KillPams(); + pSh->ClearMark(); + pDoc->ClearDoc(); + pSh->ClearUpCursors(); + + if( m_aLoadedIdle.IsActive()) { - m_xCursor->gotoStart(false); - m_xCursor->gotoEnd(true); - m_xCursor->setString(OUString()); + pSh->EndAllAction(); + pSh->UnlockPaint(); } + m_aLoadedIdle.Start(); + } + else + { + m_xCursor->gotoStart(false); + m_xCursor->gotoEnd(true); + m_xCursor->setString(OUString()); } } diff --git a/sw/source/uibase/wrtsh/navmgr.cxx b/sw/source/uibase/wrtsh/navmgr.cxx index c43992662914..b123408b820e 100644 --- a/sw/source/uibase/wrtsh/navmgr.cxx +++ b/sw/source/uibase/wrtsh/navmgr.cxx @@ -103,42 +103,42 @@ void SwNavigationMgr::goBack() { // the UI is sometimes not as responsive as we would like it to be :) // this check prevents segmentation faults and in this way the class is not relying on the UI - if (backEnabled()) { - /* Trying to get the current cursor */ - SwPaM* pPaM = m_rMyShell.GetCursor(); - if (!pPaM) { - return; - } - // This flag will be used to manually refresh the buttons + if (!backEnabled()) return; - bool bForwardWasDisabled = !forwardEnabled(); + /* Trying to get the current cursor */ + SwPaM* pPaM = m_rMyShell.GetCursor(); + if (!pPaM) { + return; + } + // This flag will be used to manually refresh the buttons - // If we're going backwards in our history, but the current location is not - // in the history then we need to add *here* to it so that we can "go - // forward" to here again. + bool bForwardWasDisabled = !forwardEnabled(); - if (bForwardWasDisabled) { + // If we're going backwards in our history, but the current location is not + // in the history then we need to add *here* to it so that we can "go + // forward" to here again. - // the cursor consists of two SwPositions: Point and Mark. - // We are adding the current Point to the navigation history - // so we could later navigate forward to it + if (bForwardWasDisabled) { - // The addEntry() method returns true iff we should decrement - // the index before navigating back + // the cursor consists of two SwPositions: Point and Mark. + // We are adding the current Point to the navigation history + // so we could later navigate forward to it - if (addEntry(*pPaM->GetPoint()) ) { - m_nCurrent--; - } + // The addEntry() method returns true iff we should decrement + // the index before navigating back + + if (addEntry(*pPaM->GetPoint()) ) { + m_nCurrent--; } - m_nCurrent--; - // Position cursor to appropriate navigation history entry - GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); - // Refresh the buttons - if (bForwardWasDisabled) - m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD); - if (!backEnabled()) - m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK); } + m_nCurrent--; + // Position cursor to appropriate navigation history entry + GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); + // Refresh the buttons + if (bForwardWasDisabled) + m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD); + if (!backEnabled()) + m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK); } // The goForward() method positions the cursor to the next entry in the navigation history @@ -149,19 +149,19 @@ void SwNavigationMgr::goForward() { // the UI is sometimes not as responsive as we would like it to be :) // this check prevents segmentation faults and in this way the class is not relying on the UI - if (forwardEnabled()) { - // This flag will be used to manually refresh the buttons - bool bBackWasDisabled = !backEnabled(); - // The current index is positioned at the current entry in the navigation history - // We have to increment it to go to the next entry - m_nCurrent++; - GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); - // Refresh the buttons - if (bBackWasDisabled) - m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK); - if (!forwardEnabled()) - m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD); - } + if (!forwardEnabled()) return; + + // This flag will be used to manually refresh the buttons + bool bBackWasDisabled = !backEnabled(); + // The current index is positioned at the current entry in the navigation history + // We have to increment it to go to the next entry + m_nCurrent++; + GotoSwPosition(*m_entries[m_nCurrent]->GetPoint()); + // Refresh the buttons + if (bBackWasDisabled) + m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_BACK); + if (!forwardEnabled()) + m_rMyShell.GetView().GetViewFrame()->GetBindings().Invalidate(FN_NAVIGATION_FORWARD); } // This method adds the SwPosition rPos to the navigation history diff --git a/sw/source/uibase/wrtsh/select.cxx b/sw/source/uibase/wrtsh/select.cxx index a5c1ecbb7299..dc47cb73acdb 100644 --- a/sw/source/uibase/wrtsh/select.cxx +++ b/sw/source/uibase/wrtsh/select.cxx @@ -478,26 +478,26 @@ void SwWrtShell::ExtSelWrd(const Point *pPt, bool ) SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); // restore the saved cursor - if( bMoveCursor ) + if( !bMoveCursor ) + return; + + // select to Top but cursor select to Bottom? or + // select to Bottom but cursor select to Top? --> swap the cursor + if( bToTop ) + SwapPam(); + + SwCursorShell::Push(); // save cur cursor + if( SwCursorShell::SelectWord( pPt )) // select the current word { - // select to Top but cursor select to Bottom? or - // select to Bottom but cursor select to Top? --> swap the cursor if( bToTop ) SwapPam(); - - SwCursorShell::Push(); // save cur cursor - if( SwCursorShell::SelectWord( pPt )) // select the current word - { - if( bToTop ) - SwapPam(); - Combine(); - } - else - { - SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); - if( bToTop ) - SwapPam(); - } + Combine(); + } + else + { + SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent); + if( bToTop ) + SwapPam(); } } diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 2c208eb2d592..96cc83e62167 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -169,22 +169,22 @@ bool SwWrtShell::IsEndWrd() // Insert string void SwWrtShell::InsertByWord( const OUString & rStr) { - if( !rStr.isEmpty() ) - { - bool bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 ); - sal_Int32 nPos = 0, nStt = 0; - for( ; nPos < rStr.getLength(); nPos++ ) - { - bool bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos ); - if( bTmpDelim != bDelim ) - { - Insert( rStr.copy( nStt, nPos - nStt )); - nStt = nPos; - } - } - if( nStt != nPos ) + if( rStr.isEmpty() ) + return; + + bool bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 ); + sal_Int32 nPos = 0, nStt = 0; + for( ; nPos < rStr.getLength(); nPos++ ) + { + bool bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos ); + if( bTmpDelim != bDelim ) + { Insert( rStr.copy( nStt, nPos - nStt )); + nStt = nPos; + } } + if( nStt != nPos ) + Insert( rStr.copy( nStt, nPos - nStt )); } void SwWrtShell::Insert( const OUString &rStr ) @@ -609,30 +609,30 @@ bool SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef& xRef, SwFlyFrame void SwWrtShell::LaunchOLEObj( long nVerb ) { - if ( GetCntType() == CNT_OLE && - !GetView().GetViewFrame()->GetFrame().IsInPlace() ) - { - svt::EmbeddedObjectRef& xRef = GetOLEObject(); - OSL_ENSURE( xRef.is(), "OLE not found" ); + if ( GetCntType() != CNT_OLE || + GetView().GetViewFrame()->GetFrame().IsInPlace() ) + return; - // LOK: we don't want to handle any other embedded objects than - // charts, there are too many problems with eg. embedded spreadsheets - // (like it creates a separate view for the calc sheet) - if (comphelper::LibreOfficeKit::isActive() && !SotExchange::IsChart(xRef->getClassID())) - return; + svt::EmbeddedObjectRef& xRef = GetOLEObject(); + OSL_ENSURE( xRef.is(), "OLE not found" ); + + // LOK: we don't want to handle any other embedded objects than + // charts, there are too many problems with eg. embedded spreadsheets + // (like it creates a separate view for the calc sheet) + if (comphelper::LibreOfficeKit::isActive() && !SotExchange::IsChart(xRef->getClassID())) + return; - SfxInPlaceClient* pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() ); - if ( !pCli ) - pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef ); + SfxInPlaceClient* pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() ); + if ( !pCli ) + pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef ); - static_cast<SwOleClient*>(pCli)->SetInDoVerb( true ); + static_cast<SwOleClient*>(pCli)->SetInDoVerb( true ); - CalcAndSetScale( xRef ); - pCli->DoVerb( nVerb ); + CalcAndSetScale( xRef ); + pCli->DoVerb( nVerb ); - static_cast<SwOleClient*>(pCli)->SetInDoVerb( false ); - CalcAndSetScale( xRef ); - } + static_cast<SwOleClient*>(pCli)->SetInDoVerb( false ); + CalcAndSetScale( xRef ); } void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef& xObj, const Point& rOffset ) @@ -936,20 +936,20 @@ void SwWrtShell::InsertColumnBreak() { SwActContext aActContext(this); ResetCursorStack(); - if( CanInsert() ) - { - StartUndo(SwUndoId::UI_INSERT_COLUMN_BREAK); + if( !CanInsert() ) + return; - if ( !IsCursorInTable() ) - { - if(HasSelection()) - DelRight(); - SwFEShell::SplitNode( false, false ); - } - SetAttrItem(SvxFormatBreakItem(SvxBreak::ColumnBefore, RES_BREAK)); + StartUndo(SwUndoId::UI_INSERT_COLUMN_BREAK); - EndUndo(SwUndoId::UI_INSERT_COLUMN_BREAK); + if ( !IsCursorInTable() ) + { + if(HasSelection()) + DelRight(); + SwFEShell::SplitNode( false, false ); } + SetAttrItem(SvxFormatBreakItem(SvxBreak::ColumnBefore, RES_BREAK)); + + EndUndo(SwUndoId::UI_INSERT_COLUMN_BREAK); } // Insert footnote @@ -958,30 +958,30 @@ void SwWrtShell::InsertColumnBreak() void SwWrtShell::InsertFootnote(const OUString &rStr, bool bEndNote, bool bEdit ) { ResetCursorStack(); - if( CanInsert() ) + if( !CanInsert() ) + return; + + if(HasSelection()) { - if(HasSelection()) - { - //collapse cursor to the end - if(!IsCursorPtAtEnd()) - SwapPam(); - ClearMark(); - } - SwPosition aPos = *GetCursor()->GetPoint(); - SwFormatFootnote aFootNote( bEndNote ); - if(!rStr.isEmpty()) - aFootNote.SetNumStr( rStr ); + //collapse cursor to the end + if(!IsCursorPtAtEnd()) + SwapPam(); + ClearMark(); + } + SwPosition aPos = *GetCursor()->GetPoint(); + SwFormatFootnote aFootNote( bEndNote ); + if(!rStr.isEmpty()) + aFootNote.SetNumStr( rStr ); - SetAttrItem(aFootNote); + SetAttrItem(aFootNote); - if( bEdit ) - { - // For editing the footnote text. - Left(CRSR_SKIP_CHARS, false, 1, false ); - GotoFootnoteText(); - } - m_aNavigationMgr.addEntry(aPos); + if( bEdit ) + { + // For editing the footnote text. + Left(CRSR_SKIP_CHARS, false, 1, false ); + GotoFootnoteText(); } + m_aNavigationMgr.addEntry(aPos); } // SplitNode; also, because @@ -991,22 +991,22 @@ void SwWrtShell::InsertFootnote(const OUString &rStr, bool bEndNote, bool bEdit void SwWrtShell::SplitNode( bool bAutoFormat ) { ResetCursorStack(); - if( CanInsert() ) - { - SwActContext aActContext(this); + if( !CanInsert() ) + return; - m_rView.GetEditWin().FlushInBuffer(); - bool bHasSel = HasSelection(); - if( bHasSel ) - { - StartUndo( SwUndoId::INSERT ); - DelRight(); - } + SwActContext aActContext(this); - SwFEShell::SplitNode( bAutoFormat ); - if( bHasSel ) - EndUndo( SwUndoId::INSERT ); + m_rView.GetEditWin().FlushInBuffer(); + bool bHasSel = HasSelection(); + if( bHasSel ) + { + StartUndo( SwUndoId::INSERT ); + DelRight(); } + + SwFEShell::SplitNode( bAutoFormat ); + if( bHasSel ) + EndUndo( SwUndoId::INSERT ); } // Turn on numbering @@ -1348,43 +1348,43 @@ void SwWrtShell::NumOrBulletOff() { const SwNumRule * pCurNumRule = GetNumRuleAtCurrCursorPos(); - if (pCurNumRule) + if (!pCurNumRule) + return; + + if (pCurNumRule->IsOutlineRule()) { - if (pCurNumRule->IsOutlineRule()) - { - SwNumRule aNumRule(*pCurNumRule); + SwNumRule aNumRule(*pCurNumRule); - SwTextNode * pTextNode = - sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode); + SwTextNode * pTextNode = + sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode); - if (pTextNode) - { - int nLevel = pTextNode->GetActualListLevel(); + if (pTextNode) + { + int nLevel = pTextNode->GetActualListLevel(); - if (nLevel < 0) - nLevel = 0; + if (nLevel < 0) + nLevel = 0; - if (nLevel >= MAXLEVEL) - nLevel = MAXLEVEL - 1; + if (nLevel >= MAXLEVEL) + nLevel = MAXLEVEL - 1; - SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel))); + SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel))); - aFormat.SetNumberingType(SVX_NUM_NUMBER_NONE); - aNumRule.Set(nLevel, aFormat); + aFormat.SetNumberingType(SVX_NUM_NUMBER_NONE); + aNumRule.Set(nLevel, aFormat); - // no start or continuation of a list - the outline style is only changed. - SetCurNumRule( aNumRule, false ); - } - } - else - { - DelNumRules(); + // no start or continuation of a list - the outline style is only changed. + SetCurNumRule( aNumRule, false ); } - - // #126346# - Cursor can not be anymore in front of - // a label, because numbering/bullet is switched off. - SetInFrontOfLabel( false ); } + else + { + DelNumRules(); + } + + // #126346# - Cursor can not be anymore in front of + // a label, because numbering/bullet is switched off. + SetInFrontOfLabel( false ); } // <- #i29560# @@ -1632,38 +1632,38 @@ void SwWrtShell::AutoUpdateFrame( SwFrameFormat* pFormat, const SfxItemSet& rSty void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar ) { ResetCursorStack(); - if(CanInsert()) + if(!CanInsert()) + return; + + bool bStarted = false; + SwRewriter aRewriter; + + if(HasSelection()) { - bool bStarted = false; - SwRewriter aRewriter; + // Only parentheses here, because the regular insert + // is already clipped to the editshell + StartAllAction(); - if(HasSelection()) - { - // Only parentheses here, because the regular insert - // is already clipped to the editshell - StartAllAction(); - - OUString aTmpStr1 = SwResId(STR_START_QUOTE) + - GetSelText() + - SwResId(STR_END_QUOTE); - OUString aTmpStr3 = SwResId(STR_START_QUOTE) + - OUStringChar(cChar) + - SwResId(STR_END_QUOTE); - aRewriter.AddRule( UndoArg1, aTmpStr1 ); - aRewriter.AddRule( UndoArg2, SwResId(STR_YIELDS) ); - aRewriter.AddRule( UndoArg3, aTmpStr3 ); - - StartUndo( SwUndoId::REPLACE, &aRewriter ); - bStarted = true; - DelRight(); - } - SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar ); + OUString aTmpStr1 = SwResId(STR_START_QUOTE) + + GetSelText() + + SwResId(STR_END_QUOTE); + OUString aTmpStr3 = SwResId(STR_START_QUOTE) + + OUStringChar(cChar) + + SwResId(STR_END_QUOTE); + aRewriter.AddRule( UndoArg1, aTmpStr1 ); + aRewriter.AddRule( UndoArg2, SwResId(STR_YIELDS) ); + aRewriter.AddRule( UndoArg3, aTmpStr3 ); + + StartUndo( SwUndoId::REPLACE, &aRewriter ); + bStarted = true; + DelRight(); + } + SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar ); - if(bStarted) - { - EndAllAction(); - EndUndo( SwUndoId::REPLACE, &aRewriter ); - } + if(bStarted) + { + EndAllAction(); + EndUndo( SwUndoId::REPLACE, &aRewriter ); } } diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index 5dc536a957be..93cd532781ff 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -150,57 +150,57 @@ void SwWrtShell::UpdateInputFields( SwInputFieldList* pLst ) } const size_t nCnt = pLst->Count(); - if(nCnt) - { - pLst->PushCursor(); + if(!nCnt) + return; + + pLst->PushCursor(); - bool bCancel = false; + bool bCancel = false; - size_t nIndex = 0; - FieldDialogPressedButton ePressedButton = FieldDialogPressedButton::NONE; + size_t nIndex = 0; + FieldDialogPressedButton ePressedButton = FieldDialogPressedButton::NONE; - SwField* pField = GetCurField(); - if (pField) + SwField* pField = GetCurField(); + if (pField) + { + for (size_t i = 0; i < nCnt; i++) { - for (size_t i = 0; i < nCnt; i++) + if (pField == pLst->GetField(i)) { - if (pField == pLst->GetField(i)) - { - nIndex = i; - break; - } + nIndex = i; + break; } } + } - while (!bCancel) + while (!bCancel) + { + bool bPrev = nIndex > 0; + bool bNext = nIndex < nCnt - 1; + pLst->GotoFieldPos(nIndex); + pField = pLst->GetField(nIndex); + if (pField->GetTyp()->Which() == SwFieldIds::Dropdown) { - bool bPrev = nIndex > 0; - bool bNext = nIndex < nCnt - 1; - pLst->GotoFieldPos(nIndex); - pField = pLst->GetField(nIndex); - if (pField->GetTyp()->Which() == SwFieldIds::Dropdown) - { - bCancel = StartDropDownFieldDlg(pField, bPrev, bNext, GetView().GetFrameWeld(), &ePressedButton); - } - else - bCancel = StartInputFieldDlg(pField, bPrev, bNext, GetView().GetFrameWeld(), &ePressedButton); + bCancel = StartDropDownFieldDlg(pField, bPrev, bNext, GetView().GetFrameWeld(), &ePressedButton); + } + else + bCancel = StartInputFieldDlg(pField, bPrev, bNext, GetView().GetFrameWeld(), &ePressedButton); - if (!bCancel) - { - // Otherwise update error at multi-selection: - pLst->GetField(nIndex)->GetTyp()->UpdateFields(); + if (!bCancel) + { + // Otherwise update error at multi-selection: + pLst->GetField(nIndex)->GetTyp()->UpdateFields(); - if (ePressedButton == FieldDialogPressedButton::Previous && nIndex > 0) - nIndex--; - else if (ePressedButton == FieldDialogPressedButton::Next && nIndex < nCnt - 1) - nIndex++; - else - bCancel = true; - } + if (ePressedButton == FieldDialogPressedButton::Previous && nIndex > 0) + nIndex--; + else if (ePressedButton == FieldDialogPressedButton::Next && nIndex < nCnt - 1) + nIndex++; + else + bCancel = true; } - - pLst->PopCursor(); } + + pLst->PopCursor(); } namespace { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits