diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-29 11:35:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-01-31 10:41:34 +0100 |
commit | 8a722c086deb751054d02f9f73e92d045cd73e1f (patch) | |
tree | 22f1bc523ab0019850a014ce94dbf69eb4ce075d /starmath/source/edit.cxx | |
parent | 07ec9edc26f675646f04721acb3f1f0334a34530 (diff) |
loplugin:flatten in starmath
Change-Id: Iaadd8af404e3eee5ebd49846a02a33735e9c18ba
Reviewed-on: https://gerrit.libreoffice.org/67170
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/source/edit.cxx')
-rw-r--r-- | starmath/source/edit.cxx | 278 |
1 files changed, 139 insertions, 139 deletions
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx index 7e0d5c8b88a5..d4ee00cd7a37 100644 --- a/starmath/source/edit.cxx +++ b/starmath/source/edit.cxx @@ -502,35 +502,35 @@ void SmEditWindow::CreateEditView() //! pEditEngine and pEditView may be 0. //! For example when the program is used by the document-converter - if (!pEditView && pEditEngine) - { - pEditView.reset(new EditView(pEditEngine, this)); - pEditEngine->InsertView( pEditView.get() ); - - if (!pVScrollBar) - pVScrollBar = VclPtr<ScrollBar>::Create(this, WinBits(WB_VSCROLL)); - if (!pHScrollBar) - pHScrollBar = VclPtr<ScrollBar>::Create(this, WinBits(WB_HSCROLL)); - if (!pScrollBox) - pScrollBox = VclPtr<ScrollBarBox>::Create(this); - pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl)); - pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl)); - pVScrollBar->EnableDrag(); - pHScrollBar->EnableDrag(); + if (pEditView || !pEditEngine) + return; - pEditView->SetOutputArea(AdjustScrollBars()); + pEditView.reset(new EditView(pEditEngine, this)); + pEditEngine->InsertView( pEditView.get() ); - ESelection eSelection; + if (!pVScrollBar) + pVScrollBar = VclPtr<ScrollBar>::Create(this, WinBits(WB_VSCROLL)); + if (!pHScrollBar) + pHScrollBar = VclPtr<ScrollBar>::Create(this, WinBits(WB_HSCROLL)); + if (!pScrollBox) + pScrollBox = VclPtr<ScrollBarBox>::Create(this); + pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl)); + pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl)); + pVScrollBar->EnableDrag(); + pHScrollBar->EnableDrag(); - pEditView->SetSelection(eSelection); - Update(); - pEditView->ShowCursor(); + pEditView->SetOutputArea(AdjustScrollBars()); - pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) ); - SetPointer(pEditView->GetPointer()); + ESelection eSelection; - SetScrollBarRanges(); - } + pEditView->SetSelection(eSelection); + Update(); + pEditView->ShowCursor(); + + pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) ); + SetPointer(pEditView->GetPointer()); + + SetScrollBarRanges(); } @@ -594,23 +594,23 @@ void SmEditWindow::SetScrollBarRanges() void SmEditWindow::InitScrollBars() { - if (pVScrollBar && pHScrollBar && pScrollBox && pEditView) - { - const Size aOut( pEditView->GetOutputArea().GetSize() ); - pVScrollBar->SetVisibleSize(aOut.Height()); - pVScrollBar->SetPageSize(aOut.Height() * 8 / 10); - pVScrollBar->SetLineSize(aOut.Height() * 2 / 10); + if (!(pVScrollBar && pHScrollBar && pScrollBox && pEditView)) + return; - pHScrollBar->SetVisibleSize(aOut.Width()); - pHScrollBar->SetPageSize(aOut.Width() * 8 / 10); - pHScrollBar->SetLineSize(SCROLL_LINE ); + const Size aOut( pEditView->GetOutputArea().GetSize() ); + pVScrollBar->SetVisibleSize(aOut.Height()); + pVScrollBar->SetPageSize(aOut.Height() * 8 / 10); + pVScrollBar->SetLineSize(aOut.Height() * 2 / 10); - SetScrollBarRanges(); + pHScrollBar->SetVisibleSize(aOut.Width()); + pHScrollBar->SetPageSize(aOut.Width() * 8 / 10); + pHScrollBar->SetLineSize(SCROLL_LINE ); - pVScrollBar->Show(); - pHScrollBar->Show(); - pScrollBox->Show(); - } + SetScrollBarRanges(); + + pVScrollBar->Show(); + pHScrollBar->Show(); + pScrollBox->Show(); } @@ -629,22 +629,22 @@ void SmEditWindow::SetText(const OUString& rText) { EditEngine *pEditEngine = GetEditEngine(); OSL_ENSURE( pEditEngine, "EditEngine missing" ); - if (pEditEngine && !pEditEngine->IsModified()) - { - if (!pEditView) - CreateEditView(); + if (!pEditEngine || pEditEngine->IsModified()) + return; - ESelection eSelection = pEditView->GetSelection(); + if (!pEditView) + CreateEditView(); - pEditEngine->SetText(rText); - pEditEngine->ClearModifyFlag(); + ESelection eSelection = pEditView->GetSelection(); - // Restarting the timer here, prevents calling the handlers for other (currently inactive) - // math tasks - aModifyIdle.Start(); + pEditEngine->SetText(rText); + pEditEngine->ClearModifyFlag(); - pEditView->SetSelection(eSelection); - } + // Restarting the timer here, prevents calling the handlers for other (currently inactive) + // math tasks + aModifyIdle.Start(); + + pEditView->SetSelection(eSelection); } @@ -742,26 +742,26 @@ void SmEditWindow::SelNextMark() EditEngine *pEditEngine = GetEditEngine(); OSL_ENSURE( pEditView, "NULL pointer" ); OSL_ENSURE( pEditEngine, "NULL pointer" ); - if (pEditEngine && pEditView) - { - ESelection eSelection = pEditView->GetSelection(); - sal_Int32 nPos = eSelection.nEndPos; - sal_Int32 nCounts = pEditEngine->GetParagraphCount(); + if (!pEditEngine || !pEditView) + return; - while (eSelection.nEndPara < nCounts) - { - OUString aText = pEditEngine->GetText(eSelection.nEndPara); - nPos = aText.indexOf("<?>", nPos); - if (nPos != -1) - { - pEditView->SetSelection(ESelection( - eSelection.nEndPara, nPos, eSelection.nEndPara, nPos + 3)); - break; - } + ESelection eSelection = pEditView->GetSelection(); + sal_Int32 nPos = eSelection.nEndPos; + sal_Int32 nCounts = pEditEngine->GetParagraphCount(); - nPos = 0; - eSelection.nEndPara++; + while (eSelection.nEndPara < nCounts) + { + OUString aText = pEditEngine->GetText(eSelection.nEndPara); + nPos = aText.indexOf("<?>", nPos); + if (nPos != -1) + { + pEditView->SetSelection(ESelection( + eSelection.nEndPara, nPos, eSelection.nEndPara, nPos + 3)); + break; } + + nPos = 0; + eSelection.nEndPara++; } } @@ -770,24 +770,24 @@ void SmEditWindow::SelPrevMark() EditEngine *pEditEngine = GetEditEngine(); OSL_ENSURE( pEditEngine, "NULL pointer" ); OSL_ENSURE( pEditView, "NULL pointer" ); - if (pEditEngine && pEditView) + if (!(pEditEngine && pEditView)) + return; + + ESelection eSelection = pEditView->GetSelection(); + sal_Int32 nPara = eSelection.nStartPara; + sal_Int32 nMax = eSelection.nStartPos; + OUString aText(pEditEngine->GetText(nPara)); + const OUString aMark("<?>"); + sal_Int32 nPos; + + while ( (nPos = aText.lastIndexOf(aMark, nMax)) < 0 ) { - ESelection eSelection = pEditView->GetSelection(); - sal_Int32 nPara = eSelection.nStartPara; - sal_Int32 nMax = eSelection.nStartPos; - OUString aText(pEditEngine->GetText(nPara)); - const OUString aMark("<?>"); - sal_Int32 nPos; - - while ( (nPos = aText.lastIndexOf(aMark, nMax)) < 0 ) - { - if (--nPara < 0) - return; - aText = pEditEngine->GetText(nPara); - nMax = aText.getLength(); - } - pEditView->SetSelection(ESelection(nPara, nPos, nPara, nPos + 3)); + if (--nPara < 0) + return; + aText = pEditEngine->GetText(nPara); + nMax = aText.getLength(); } + pEditView->SetSelection(ESelection(nPara, nPos, nPara, nPos + 3)); } bool SmEditWindow::HasMark(const OUString& rText) @@ -893,64 +893,64 @@ void SmEditWindow::Delete() void SmEditWindow::InsertText(const OUString& rText) { OSL_ENSURE( pEditView, "EditView missing" ); - if (pEditView) - { - // Note: Insertion of a space in front of commands is done here and - // in SmEditWindow::InsertCommand. - ESelection aSelection = pEditView->GetSelection(); - OUString aCurrentFormula = pEditView->GetEditEngine()->GetText(); - sal_Int32 nStartIndex = 0; - - // get the start position (when we get a multi line formula) - for (sal_Int32 nParaPos = 0; nParaPos < aSelection.nStartPara; nParaPos++) - nStartIndex = aCurrentFormula.indexOf("\n", nStartIndex) + 1; - - nStartIndex += aSelection.nStartPos; - - // TODO: unify this function with the InsertCommand: The do the same thing for different - // callers - OUString string(rText); - - OUString selected(pEditView->GetSelected()); - // if we have text selected, use it in the first placeholder - if (!selected.isEmpty()) - string = string.replaceFirst("<?>", selected); - - // put a space before a new command if not in the beginning of a line - if (aSelection.nStartPos > 0 && aCurrentFormula[nStartIndex - 1] != ' ') - string = " " + string; - - /* - fdo#65588 - Elements Dock: Scrollbar moves into input window - This change "solves" the visual problem. But I don't think so - this is the best solution. - */ - pVScrollBar->Hide(); - pHScrollBar->Hide(); - pEditView->InsertText(string); - AdjustScrollBars(); - pVScrollBar->Show(); - pHScrollBar->Show(); - - // Remember start of the selection and move the cursor there afterwards. - aSelection.nEndPara = aSelection.nStartPara; - if (HasMark(string)) - { - aSelection.nEndPos = aSelection.nStartPos; - pEditView->SetSelection(aSelection); - SelNextMark(); - } - else - { // set selection after inserted text - aSelection.nEndPos = aSelection.nStartPos + string.getLength(); - aSelection.nStartPos = aSelection.nEndPos; - pEditView->SetSelection(aSelection); - } + if (!pEditView) + return; - aModifyIdle.Start(); - StartCursorMove(); - GrabFocus(); + // Note: Insertion of a space in front of commands is done here and + // in SmEditWindow::InsertCommand. + ESelection aSelection = pEditView->GetSelection(); + OUString aCurrentFormula = pEditView->GetEditEngine()->GetText(); + sal_Int32 nStartIndex = 0; + + // get the start position (when we get a multi line formula) + for (sal_Int32 nParaPos = 0; nParaPos < aSelection.nStartPara; nParaPos++) + nStartIndex = aCurrentFormula.indexOf("\n", nStartIndex) + 1; + + nStartIndex += aSelection.nStartPos; + + // TODO: unify this function with the InsertCommand: The do the same thing for different + // callers + OUString string(rText); + + OUString selected(pEditView->GetSelected()); + // if we have text selected, use it in the first placeholder + if (!selected.isEmpty()) + string = string.replaceFirst("<?>", selected); + + // put a space before a new command if not in the beginning of a line + if (aSelection.nStartPos > 0 && aCurrentFormula[nStartIndex - 1] != ' ') + string = " " + string; + + /* + fdo#65588 - Elements Dock: Scrollbar moves into input window + This change "solves" the visual problem. But I don't think so + this is the best solution. + */ + pVScrollBar->Hide(); + pHScrollBar->Hide(); + pEditView->InsertText(string); + AdjustScrollBars(); + pVScrollBar->Show(); + pHScrollBar->Show(); + + // Remember start of the selection and move the cursor there afterwards. + aSelection.nEndPara = aSelection.nStartPara; + if (HasMark(string)) + { + aSelection.nEndPos = aSelection.nStartPos; + pEditView->SetSelection(aSelection); + SelNextMark(); + } + else + { // set selection after inserted text + aSelection.nEndPos = aSelection.nStartPos + string.getLength(); + aSelection.nStartPos = aSelection.nEndPos; + pEditView->SetSelection(aSelection); } + + aModifyIdle.Start(); + StartCursorMove(); + GrabFocus(); } void SmEditWindow::Flush() |