/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void SmGetLeftSelectionPart(const ESelection &rSel,
sal_Int32 &nPara, sal_uInt16 &nPos) // returns paragraph number and position of the selections left part
{ // compare start and end of selection and use the one that comes first if (rSel.start < rSel.end)
{ nPara = rSel.start.nPara;
nPos = rSel.start.nIndex;
} else
{ nPara = rSel.end.nPara;
nPos = rSel.end.nIndex;
}
}
// forces new settings to be used // unfortunately this resets the whole edit engine // thus we need to save at least the text
OUString aTxt( pEditEngine->GetText() );
pEditEngine->Clear(); //incorrect font size
pEditEngine->SetText( aTxt );
Resize();
}
// Apply zoom to smeditwindow text static_cast<SmEditEngine*>(GetEditEngine())->executeZoom(GetEditView());
}
IMPL_LINK_NOARG(SmEditTextWindow, CursorMoveTimerHdl, Timer *, void) // every once in a while check cursor position (selection) of edit // window and if it has changed (try to) set the formula-cursor // according to that.
{ if (SmViewShell::IsInlineEditEnabled()) return;
ESelection aNewSelection(GetSelection());
if (aNewSelection != aOldSelection)
{ if (SmViewShell *pViewSh = mrEditWindow.GetView())
{ // get row and column to look for
sal_Int32 nRow;
sal_uInt16 nCol;
SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
pViewSh->GetGraphicWidget().SetCursorPos(static_cast<sal_uInt16>(nRow), nCol);
aOldSelection = aNewSelection;
}
}
aCursorMoveIdle.Stop();
}
bool autoClose = false;
EditView* pEditView = GetEditView();
ESelection aSelection = pEditView->GetSelection(); // as we don't support RTL in Math, we need to swap values from selection when they were done // in RTL form
aSelection.Adjust();
OUString selected = pEditView->getEditEngine().GetText(aSelection);
// Check is auto close brackets/braces is disabled
SmModule* pMod = SmModule::get(); if (pMod && !pMod->GetConfig()->IsAutoCloseBrackets())
autoClose = false; elseif (o3tl::trim(selected) == u">")
autoClose = true; elseif (selected.isEmpty() && !aSelection.HasRange())
{
selected = pEditView->getEditEngine().GetText(aSelection.end.nPara); if (!selected.isEmpty())
{
sal_Int32 index = selected.indexOf("\n", aSelection.end.nIndex); if (index != -1)
{
selected = selected.copy(index, sal_Int32(aSelection.end.nIndex-index)); if (o3tl::trim(selected).empty())
autoClose = true;
} else
{
sal_Int32 length = selected.getLength(); if (aSelection.end.nIndex == length)
autoClose = true; else
{
selected = selected.copy(aSelection.end.nIndex); if (o3tl::trim(selected).empty())
autoClose = true;
}
}
} else
autoClose = true;
}
bool bConsumed = WeldEditView::KeyInput(rKEvt); if (!bConsumed)
{
SmViewShell *pView = mrEditWindow.GetView(); if (pView)
bConsumed = pView->KeyInput(rKEvt); if (pView && !bConsumed)
{ // F1 (help) leads to the destruction of this
Flush(); if ( aModifyIdle.IsActive() )
aModifyIdle.Stop();
} else
{ // SFX has maybe called a slot of the view and thus (because of a hack in SFX) // set the focus to the view
SmViewShell* pVShell = mrEditWindow.GetView(); if ( pVShell && pVShell->GetGraphicWidget().HasFocus() )
{
GrabFocus();
}
}
} else
{
UserPossiblyChangedText();
}
// get the current char of the key event
sal_Unicode cCharCode = rKEvt.GetCharCode();
OUString sClose;
// auto close the current character only when needed if (!sClose.isEmpty() && autoClose)
{
pEditView->InsertText(sClose); // position it at center of brackets
aSelection.start.nIndex += 2;
aSelection.end.nIndex = aSelection.start.nIndex;
pEditView->SetSelection(aSelection);
}
void SmEditTextWindow::UserPossiblyChangedText()
{ // have doc-shell modified only for formula input/change and not // cursor travelling and such things...
SmDocShell *pDocShell = mrEditWindow.GetDoc();
EditEngine *pEditEngine = GetEditEngine(); if (pDocShell && pEditEngine && pEditEngine->IsModified())
pDocShell->SetModified(true);
aModifyIdle.Start();
}
EditEngine *pEditEngine = GetEditEngine(); //! pEditEngine may be 0. //! For example when the program is used by the document-converter if (!pEditEngine) return;
// Restarting the timer here, prevents calling the handlers for other (currently inactive) // math tasks
aModifyIdle.Start();
// Apply zoom to smeditwindow text static_cast<SmEditEngine&>(pEditView->getEditEngine()).executeZoom(pEditView);
pEditView->SetSelection(eSelection);
}
void SmEditWindow::SelNextMark()
{ if (!mxTextControl) return;
mxTextControl->SelNextMark();
}
// Makes selection to next <?> symbol void SmEditTextWindow::SelNextMark()
{
EditEngine *pEditEngine = GetEditEngine(); if (!pEditEngine) return;
EditView* pEditView = GetEditView(); if (!pEditView) return;
ESelection SmEditTextWindow::GetSelection() const
{ // pointer may be 0 when reloading a document and the old view // was already destroyed if (EditView* pEditView = GetEditView()) return pEditView->GetSelection(); return ESelection();
}
// 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.start.nPara; nParaPos++)
nStartIndex = aCurrentFormula.indexOf("\n", nStartIndex) + 1;
nStartIndex += aSelection.start.nIndex;
// 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.start.nIndex > 0 && aCurrentFormula[nStartIndex - 1] != ' ')
string = " " + string;
pEditView->InsertText(string);
// Remember start of the selection and move the cursor there afterwards.
aSelection.end.nPara = aSelection.start.nPara; if (HasMark(string))
{
aSelection.end.nIndex = aSelection.start.nIndex;
pEditView->SetSelection(aSelection);
SelNextMark();
} else
{ // set selection after inserted text
aSelection.end.nIndex = aSelection.start.nIndex + string.getLength();
aSelection.start.nIndex = aSelection.end.nIndex;
pEditView->SetSelection(aSelection);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.