summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-28 10:33:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-29 08:51:48 +0200
commit1ffba0e356608fb6dbf568248e2a953b4d7fb5d6 (patch)
tree5da59640441292421f2137bc85ee7291daed137e /starmath
parentce9a41dc387966c74c1af92783a97565b5af3668 (diff)
loplugin:flatten check for throw in then clause
also make the plugin ignore the case where we have var decl's in the clause we want to flatten, which could lead to problematic extension of variable lifetime Change-Id: I3061f7104e8c6a460bf74f5eac325a516ec50c59 Reviewed-on: https://gerrit.libreoffice.org/42889 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/source/accessibility.cxx131
1 files changed, 64 insertions, 67 deletions
diff --git a/starmath/source/accessibility.cxx b/starmath/source/accessibility.cxx
index 60c7d0b916c4..c6bd06327f67 100644
--- a/starmath/source/accessibility.cxx
+++ b/starmath/source/accessibility.cxx
@@ -448,65 +448,63 @@ awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nInde
if (!pWin)
throw RuntimeException();
- else
- {
- // get accessible text
- SmViewShell *pView = pWin->GetView();
- SmDocShell *pDoc = pView ? pView->GetDoc() : nullptr;
- if (!pDoc)
- throw RuntimeException();
- OUString aTxt( GetAccessibleText_Impl() );
- if (!(0 <= nIndex && nIndex <= aTxt.getLength())) // aTxt.getLength() is valid
- throw IndexOutOfBoundsException();
-
- // find a reasonable rectangle for position aTxt.getLength().
- bool bWasBehindText = (nIndex == aTxt.getLength());
- if (bWasBehindText && nIndex)
- --nIndex;
-
- const SmNode *pTree = pDoc->GetFormulaTree();
- const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( nIndex );
- //! pNode may be 0 if the index belongs to a char that was inserted
- //! only for the accessible text!
- if (pNode)
- {
- sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
- OSL_ENSURE( nAccIndex >= 0, "invalid accessible index" );
- OSL_ENSURE( nIndex >= nAccIndex, "index out of range" );
-
- OUStringBuffer aBuf;
- pNode->GetAccessibleText(aBuf);
- OUString aNodeText = aBuf.makeStringAndClear();
- sal_Int32 nNodeIndex = nIndex - nAccIndex;
- if (0 <= nNodeIndex && nNodeIndex < aNodeText.getLength())
- {
- // get appropriate rectangle
- Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
- Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
- aTLPos.X() -= 0;
- Size aSize (pNode->GetSize());
- long* pXAry = new long[ aNodeText.getLength() ];
- pWin->SetFont( pNode->GetFont() );
- pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.getLength() );
- aTLPos.X() += nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0;
- aSize.Width() = nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex];
- delete[] pXAry;
+ // get accessible text
+ SmViewShell *pView = pWin->GetView();
+ SmDocShell *pDoc = pView ? pView->GetDoc() : nullptr;
+ if (!pDoc)
+ throw RuntimeException();
+ OUString aTxt( GetAccessibleText_Impl() );
+ if (!(0 <= nIndex && nIndex <= aTxt.getLength())) // aTxt.getLength() is valid
+ throw IndexOutOfBoundsException();
- aTLPos = pWin->LogicToPixel( aTLPos );
- aSize = pWin->LogicToPixel( aSize );
- aRes.X = aTLPos.X();
- aRes.Y = aTLPos.Y();
- aRes.Width = aSize.Width();
- aRes.Height = aSize.Height();
- }
- }
+ // find a reasonable rectangle for position aTxt.getLength().
+ bool bWasBehindText = (nIndex == aTxt.getLength());
+ if (bWasBehindText && nIndex)
+ --nIndex;
- // take rectangle from last character and move it to the right
- if (bWasBehindText)
- aRes.X += aRes.Width;
+ const SmNode *pTree = pDoc->GetFormulaTree();
+ const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( nIndex );
+ //! pNode may be 0 if the index belongs to a char that was inserted
+ //! only for the accessible text!
+ if (pNode)
+ {
+ sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
+ OSL_ENSURE( nAccIndex >= 0, "invalid accessible index" );
+ OSL_ENSURE( nIndex >= nAccIndex, "index out of range" );
+
+ OUStringBuffer aBuf;
+ pNode->GetAccessibleText(aBuf);
+ OUString aNodeText = aBuf.makeStringAndClear();
+ sal_Int32 nNodeIndex = nIndex - nAccIndex;
+ if (0 <= nNodeIndex && nNodeIndex < aNodeText.getLength())
+ {
+ // get appropriate rectangle
+ Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
+ Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
+ aTLPos.X() -= 0;
+ Size aSize (pNode->GetSize());
+
+ long* pXAry = new long[ aNodeText.getLength() ];
+ pWin->SetFont( pNode->GetFont() );
+ pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.getLength() );
+ aTLPos.X() += nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0;
+ aSize.Width() = nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex];
+ delete[] pXAry;
+
+ aTLPos = pWin->LogicToPixel( aTLPos );
+ aSize = pWin->LogicToPixel( aSize );
+ aRes.X = aTLPos.X();
+ aRes.Y = aTLPos.Y();
+ aRes.Width = aSize.Width();
+ aRes.Height = aSize.Height();
+ }
}
+ // take rectangle from last character and move it to the right
+ if (bWasBehindText)
+ aRes.X += aRes.Width;
+
return aRes;
}
@@ -701,25 +699,24 @@ sal_Bool SAL_CALL SmGraphicAccessible::copyText(
if (!pWin)
throw RuntimeException();
- else
+
+ Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
+ if ( xClipboard.is() )
{
- Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
- if ( xClipboard.is() )
- {
- OUString sText( getTextRange(nStartIndex, nEndIndex) );
+ OUString sText( getTextRange(nStartIndex, nEndIndex) );
- vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText );
- SolarMutexReleaser aReleaser;
- xClipboard->setContents( pDataObj, nullptr );
+ vcl::unohelper::TextDataObject* pDataObj = new vcl::unohelper::TextDataObject( sText );
+ SolarMutexReleaser aReleaser;
+ xClipboard->setContents( pDataObj, nullptr );
- Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
- if( xFlushableClipboard.is() )
- xFlushableClipboard->flushClipboard();
+ Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
+ if( xFlushableClipboard.is() )
+ xFlushableClipboard->flushClipboard();
- bReturn = true;
- }
+ bReturn = true;
}
+
return bReturn;
}