22 #include <string_view>
61 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
63 #include <osl/diagnose.h>
66 #include <inputwin.hxx>
70 #include <uiitems.hxx>
73 #include <globstr.hrc>
77 #include <document.hxx>
86 #include <compiler.hxx>
90 #include <tokenarray.hxx>
96 #define RANGEFIND_MAX 128
105 const sal_Unicode cParenthesesReplacement = 0x0001;
107 ScTypedCaseStrSet::const_iterator findText(
108 const ScTypedCaseStrSet& rDataSet, ScTypedCaseStrSet::const_iterator
const & itPos,
109 const OUString& rStart, OUString& rResult,
bool bBack)
116 ScTypedCaseStrSet::const_reverse_iterator it = rDataSet.rbegin(), itEnd = rDataSet.rend();
117 if (itPos != rDataSet.end())
119 size_t nPos = std::distance(rDataSet.begin(), itPos);
120 size_t nRPos = rDataSet.size() - 1 - nPos;
121 std::advance(it, nRPos);
125 it = std::find_if(it, itEnd, lIsMatch);
128 rResult = it->GetString();
129 return (++it).base();
134 ScTypedCaseStrSet::const_iterator it = rDataSet.begin(), itEnd = rDataSet.end();
137 it = std::next(itPos);
140 it = std::find_if(it, itEnd, lIsMatch);
143 rResult = it->GetString();
148 return rDataSet.end();
151 OUString getExactMatch(
const ScTypedCaseStrSet& rDataSet,
const OUString& rString)
153 auto it = std::find_if(rDataSet.begin(), rDataSet.end(),
158 if (it != rDataSet.end())
159 return it->GetString();
165 sal_Int32 getLongestCommonPrefixLength(
const std::vector<OUString>& rResults,
const OUString& rUserEntry, sal_Int32 nRingOrigin)
167 sal_Int32 nResults = rResults.size();
172 return rResults[0].getLength();
174 sal_Int32 nMinLen = rUserEntry.getLength();
175 sal_Int32 nLastIdx = nRingOrigin ? nRingOrigin - 1 : nResults - 1;
176 const OUString& rFirst = rResults[nRingOrigin];
177 const OUString& rLast = rResults[nLastIdx];
178 const sal_Int32 nMaxLen = std::min(rFirst.getLength(), rLast.getLength());
180 for (sal_Int32 nLen = nMaxLen; nLen > nMinLen; --nLen)
189 ScTypedCaseStrSet::const_iterator findTextAll(
190 const ScTypedCaseStrSet& rDataSet, ScTypedCaseStrSet::const_iterator
const & itPos,
191 const OUString& rStart, ::std::vector< OUString > &rResultVec,
bool bBack, sal_Int32* pLongestPrefixLen =
nullptr)
195 if (!rDataSet.size())
196 return rDataSet.end();
198 sal_Int32 nRingOrigin = 0;
200 ScTypedCaseStrSet::const_iterator retit;
203 ScTypedCaseStrSet::const_reverse_iterator it, itEnd;
204 if ( itPos == rDataSet.end() )
206 it = rDataSet.rend();
212 it = rDataSet.rbegin();
213 size_t nPos = std::distance(rDataSet.begin(), itPos);
214 size_t nRPos = rDataSet.size() - 1 - nPos;
215 std::advance(it, nRPos);
216 if ( it == rDataSet.rend() )
217 it = rDataSet.rbegin();
220 bool bFirstTime =
true;
222 while ( it != itEnd || bFirstTime )
225 if ( it == rDataSet.rend() )
227 it = rDataSet.rbegin();
228 nRingOrigin = nCount;
246 retit = rDataSet.begin();
247 size_t nRPos = std::distance(rDataSet.rbegin(), it);
248 size_t nPos = rDataSet.size() - 1 - nRPos;
249 std::advance(retit, nPos);
256 ScTypedCaseStrSet::const_iterator it, itEnd;
258 if ( it == rDataSet.end() )
259 it = --rDataSet.end();
261 bool bFirstTime =
true;
263 while ( it != itEnd || bFirstTime )
266 if ( it == rDataSet.end() )
268 it = rDataSet.begin();
269 nRingOrigin = nCount;
290 if (pLongestPrefixLen)
292 if (nRingOrigin >= static_cast<sal_Int32>(nCount))
299 *pLongestPrefixLen = getLongestCommonPrefixLength(rResultVec, rStart, nRingOrigin);
304 return rDataSet.end();
310 const std::vector<ReferenceMark>& rReferenceMarks )
317 std::stringstream ss;
319 ss <<
"{ \"marks\": [ ";
321 for (
size_t i = 0;
i < rReferenceMarks.size();
i++ )
323 if ( rReferenceMarks[
i].Is() )
328 ss <<
"{ \"rectangle\": \""
329 << rReferenceMarks[
i].nX <<
", "
330 << rReferenceMarks[
i].nY <<
", "
331 << rReferenceMarks[
i].nWidth <<
", "
332 << rReferenceMarks[
i].nHeight <<
"\", "
333 "\"color\": \"" << rReferenceMarks[
i].aColor.AsRGBHexString() <<
"\", "
334 "\"part\": \"" << rReferenceMarks[
i].nTab <<
"\" } ";
342 OString aPayload = ss.str().c_str();
344 LOK_CALLBACK_REFERENCE_MARKS, aPayload.getStr() );
350 if ( !pActiveViewSh || !
SC_MOD()->GetInputOptions().GetRangeFinder() )
361 sal_Int32 nColon = aDelimiters.indexOf(
':' );
363 aDelimiters = aDelimiters.replaceAt( nColon, 1,
u"");
364 sal_Int32 nDot = aDelimiters.indexOf(cSheetSep);
366 aDelimiters = aDelimiters.replaceAt( nDot, 1 ,
u"");
369 sal_Int32 nLen = rFormula.getLength();
371 sal_Int32 nStart = 0;
379 if ( pChar[nPos] ==
'"' )
382 while (nPos<nLen && pChar[nPos] !=
'"')
392 bool bSingleQuoted =
false;
397 if (pChar[nPos] ==
'\'')
399 bSingleQuoted = !bSingleQuoted;
401 else if (!bSingleQuoted)
413 if( nPos < nLen && nPos > 0 &&
414 '-' == pChar[nPos] &&
'[' == pChar[nPos-1] &&
423 OUString aTest = rFormula.copy( nStart, nPos-nStart );
430 aRange.
aStart.
SetTab( pActiveViewSh->GetViewData().GetTabNo() );
445 mpEditEngine->SetUpdateLayout(
false );
452 SfxItemSet aSet( mpEditEngine->GetEmptyItemSet() );
454 mpEditEngine->QuickSetAttribs( aSet, aSel );
462 UpdateLokReferenceMarks();
466 mpEditEngine->SetUpdateLayout(
true );
468 pDocSh->Broadcast(
SfxHint( SfxHintId::ScShowRangeFinder ) );
480 comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
482 SCCOL nCol1 = nX1, nCol2 = nX2;
483 SCROW nRow1 = nY1, nRow2 = nY2;
486 if (nCol1 == nCol2 && nRow1 == nRow2)
491 tools::Long nSizeX = aBottomRight.X() - aTopLeft.X() - 1;
492 tools::Long nSizeY = aBottomRight.Y() - aTopLeft.Y() - 1;
494 return ReferenceMark(aTopLeft.X(), aTopLeft.Y(), nSizeX, nSizeY, nTab, rColor);
509 nTab, nPPTX, nPPTY,
false,
false );
537 if ( !pRangeFinder && !rViewData.
IsRefMode() )
540 sal_uInt16 nAdditionalMarks = 0;
541 std::vector<ReferenceMark> aReferenceMarks( 1 );
545 nAdditionalMarks = 1;
566 sal_uInt16
nCount = pRangeFinder ?
567 (
static_cast<sal_uInt16
>( pRangeFinder->
Count() ) + nAdditionalMarks ) : nAdditionalMarks;
568 aReferenceMarks.resize( nCount );
570 if ( nCount && pRangeFinder && !pRangeFinder->
IsHidden() &&
573 for (sal_uInt16
i = 0;
i < nCount - nAdditionalMarks;
i++)
599 aReferenceMarks.clear();
606 mbDocumentDisposing = b;
633 ScTabViewShell* pDocView = pRefViewSh ? pRefViewSh : pActiveViewSh;
634 if ( pDocView && pRangeFindList && nIndex < pRangeFindList->
Count() )
638 sal_Int32 nOldEnd = rData.
nSelEnd;
639 Color nNewColor = pRangeFindList->FindColor( rNew, nIndex );
645 OUString aNewStr(aJustified.
Format(rDoc, rData.
nFlags, aAddrDetails));
646 ESelection aOldSel( 0, nOldStart, 0, nOldEnd );
647 SfxItemSet aSet( mpEditEngine->GetEmptyItemSet() );
654 mpEditEngine->QuickSetAttribs( aSet, aOldSel );
656 bInRangeUpdate =
true;
658 bInRangeUpdate =
false;
666 sal_uInt16
nCount =
static_cast<sal_uInt16
>(pRangeFindList->Count());
667 for (sal_uInt16
i=nIndex+1;
i<nCount;
i++)
674 EditView* pActiveView = pTopView ? pTopView : pTableView;
679 OSL_FAIL(
"UpdateRange: we're missing something");
685 ScTabViewShell* pPaintView = pRefViewSh ? pRefViewSh : pActiveViewSh;
686 if ( pRangeFindList && pPaintView )
689 pRangeFindList->SetHidden(
true);
690 pDocSh->Broadcast(
SfxHint( SfxHintId::ScShowRangeFinder ) );
691 pRangeFindList.reset();
702 rStr = rStr.replace(
'\t',
' ');
708 rStr = rStr.replace(
'\n',
' ');
755 sal_Int32 nLen = rStr.getLength();
759 sal_uInt16 nQuotes = 0;
760 if ( nPos < nLen / 2 )
776 bool bLookInString = ((nQuotes % 2) != 0);
777 bool bInString = bLookInString;
779 p1 = (nDir < 0 ? p0 : p0 + nLen) ;
780 sal_uInt16 nLevel = 1;
781 while ( p != p1 && nLevel )
786 bInString = !bInString;
787 if ( bLookInString && !bInString )
790 else if ( bInString == bLookInString )
800 return static_cast<sal_Int32
>(p - p0);
804 : pInputWin( nullptr ),
805 pTableView( nullptr ),
807 pTipVisibleParent( nullptr ),
808 nTipVisible( nullptr ),
809 pTipVisibleSecParent( nullptr ),
810 nTipVisibleSec( nullptr ),
813 nCellPercentFormatDecSep( 0 ),
820 bFormulaMode(
false ),
821 bInRangeUpdate(
false ),
822 bParenthesisShown(
false ),
823 bCreatingFuncView(
false ),
824 bInEnterHandler(
false ),
825 bCommandErrorShown(
false ),
826 bInOwnChange(
false ),
828 bLastIsSymbol(
false ),
829 mbDocumentDisposing(
false),
830 mbPartialPrefix(
false),
835 pRefViewSh( nullptr ),
836 pLastPattern( nullptr )
856 if (
SC_MOD()->GetRefInputHdl() ==
this)
857 SC_MOD()->SetRefInputHdl(
nullptr);
882 bool bTextWysiwyg =
SC_MOD()->GetInputOptions().GetTextWysiwyg();
885 if ( bTextWysiwyg || bInPlace )
886 nCtrl |= EEControlBits::FORMAT100;
925 mpEditEngine->SetReplaceLeadingSingleQuotationMark(
false );
939 nCntrl |= EEControlBits::AUTOCORRECT;
941 if ( nCntrl != nOld )
967 nCntrl |= EEControlBits::ONLINESPELLING;
972 nCntrl &= ~EEControlBits::AUTOCORRECT;
974 nCntrl |= EEControlBits::AUTOCORRECT;
975 if ( nCntrl != nOld )
986 if ( bOnlineSpell ) {
1020 const OUString aParenthesesReplacement( cParenthesesReplacement);
1022 sal_uInt32 nListCount = pFuncList->
GetCount();
1023 for(sal_uInt32
i=0;
i<nListCount;
i++)
1029 const sal_Int32 nLen = pDesc->
mxFuncName->getLength();
1031 for ( sal_Int32 j = 0; j < nLen; j++ )
1036 OUString aFuncName = *pDesc->
mxFuncName + aParenthesesReplacement;
1048 for (sal_uInt16
i = 0;
i < nMRUCount;
i++)
1050 const sal_uInt16
nId = pMRUList[
i];
1051 for (sal_uInt32 j = 0; j < nListCount; j++)
1056 const OUString aEntry = *pDesc->
mxFuncName + aParenthesesReplacement;;
1073 if (rEvent.GetId() == VclEventId::ObjectDying || rEvent.GetId() == VclEventId::WindowHide
1074 || rEvent.GetId() == VclEventId::WindowLoseFocus)
1080 if (rEvent.GetId() == VclEventId::ObjectDying || rEvent.GetId() == VclEventId::WindowHide
1081 || rEvent.GetId() == VclEventId::WindowLoseFocus)
1111 bool lcl_hasSingleToken(std::u16string_view s,
sal_Unicode c)
1113 return !s.empty() && s.find(c) == std::u16string_view::npos;
1129 bool bFound =
false;
1134 if( nLeftParentPos != -1 )
1136 sal_Int32 nNextFStart = aHelper.
GetFunctionStart( rSelText, nLeftParentPos,
true);
1138 ::std::vector< OUString> aArgs;
1139 if( aHelper.
GetNextFunc( rSelText,
false, nNextFStart,
nullptr, &ppFDesc, &aArgs ) )
1143 sal_Int32 nArgPos = aHelper.
GetArgStart( rSelText, nNextFStart, 0 );
1147 ScTypedCaseStrSet::const_iterator it =
1152 sal_uInt16 nActive = 0;
1153 for( sal_uInt16
i=0;
i < nArgs;
i++ )
1155 sal_Int32
nLength = aArgs[
i].getLength();
1156 if( nArgPos <= rSelText.getLength()-1 )
1165 sal_Int32 nStartPosition = 0;
1166 sal_Int32 nEndPosition = 0;
1168 if( lcl_hasSingleToken(aNew, cSep) )
1170 for (sal_Int32
i = 0;
i < aNew.getLength(); ++
i)
1175 nStartPosition =
i+1;
1179 else if( lcl_hasSingleToken(aNew, cSheetSep) )
1182 for (sal_Int32
i = 0;
i < aNew.getLength(); ++
i)
1187 nStartPosition =
i+1;
1189 else if( cNext == cSep )
1193 if( nCount == nActive )
1197 nStartPosition = nEndPosition+1;
1204 for (sal_Int32
i = 0;
i < aNew.getLength(); ++
i)
1209 nStartPosition =
i+1;
1211 else if( cNext == cSep )
1215 if( nCount == nActive )
1219 nStartPosition = nEndPosition+1;
1221 else if( cNext == cSheetSep )
1228 if (nStartPosition > 0)
1231 sal_Int16 nVarArgsSet = 0;
1242 if ( nVarArgsSet > 0 && nActive > nArgs )
1243 nActive = nArgs - (nActive - nArgs) % nVarArgsSet;
1244 aNew = OUString::Concat(aNew.subView(0, nStartPosition)) +
1246 aNew.subView(nStartPosition) +
1290 if ( aParagraph.getLength() < aSel.
nEndPos )
1295 OUString aSelText( aParagraph.copy( 0, aSel.
nEndPos ));
1327 QuickHelpFlags const nAlign = QuickHelpFlags::Left|QuickHelpFlags::Bottom;
1351 Point aLogicPos = pCur->GetPos();
1352 aLogicPos.AdjustY(pCur->GetHeight() );
1359 QuickHelpFlags const nAlign = QuickHelpFlags::Left | QuickHelpFlags::Top | QuickHelpFlags::NoEvadePointer;
1366 if ( aStart.isEmpty() )
1370 sal_Int32
nPos = aStart.getLength() - 1;
1373 ::std::set< sal_Unicode >::const_iterator
p =
maFormulaChar.find( c );
1377 ::std::vector<sal_Unicode> aTemp { c };
1378 for(sal_Int32
i = nPos - 1;
i >= 0; --
i)
1386 aTemp.push_back( c );
1389 ::std::vector<sal_Unicode>::reverse_iterator rIt = aTemp.rbegin();
1390 aResult = OUString( *rIt++ );
1391 while ( rIt != aTemp.rend() )
1392 aResult += OUStringChar( *rIt++ );
1399 OString escapeJSON(
const OUString &aStr)
1401 OUString aEscaped = aStr;
1402 aEscaped = aEscaped.replaceAll(
"\n",
" ");
1403 aEscaped = aEscaped.replaceAll(
"\"",
"'");
1419 OUString aFuncNameStr;
1420 OUString aDescFuncNameStr;
1421 OStringBuffer aPayload;
1422 aPayload.append(
"[ ");
1423 for (
const OUString& rFunc : rFuncStrVec)
1425 if ( rFunc[rFunc.getLength()-1] == cParenthesesReplacement )
1427 aFuncNameStr = rFunc.copy(0, rFunc.getLength()-1);
1431 aFuncNameStr = rFunc;
1435 aDescFuncNameStr = aFuncNameStr +
"()";
1436 sal_Int32 nNextFStart = 0;
1438 ::std::vector< OUString > aArgs;
1439 OUString eqPlusFuncName =
"=" + aDescFuncNameStr;
1440 if ( aHelper.
GetNextFunc( eqPlusFuncName,
false, nNextFStart,
nullptr, &ppFDesc, &aArgs ) )
1444 aPayload.append(
"{");
1445 aPayload.append(
"\"index\": ");
1446 aPayload.append(static_cast<sal_Int64>(nCurIndex));
1447 aPayload.append(
", ");
1448 aPayload.append(
"\"signature\": \"");
1450 aPayload.append(
"\", ");
1451 aPayload.append(
"\"description\": \"");
1453 aPayload.append(
"\"}, ");
1457 if (nCurIndex == nSize)
1460 sal_Int32 nLen = aPayload.getLength();
1461 aPayload[nLen - 2] =
' ';
1462 aPayload[nLen - 1] =
']';
1464 OString s = aPayload.makeStringAndClear();
1471 OUStringBuffer aTipStr;
1472 OUString aFuncNameStr;
1473 OUString aDescFuncNameStr;
1474 ::std::vector<OUString>::const_iterator itStr = rFuncStrVec.begin();
1475 sal_Int32 nMaxFindNumber = 3;
1476 sal_Int32 nRemainFindNumber = nMaxFindNumber;
1477 for ( ; itStr != rFuncStrVec.end(); ++itStr )
1479 const OUString& rFunc = *itStr;
1480 if ( rFunc[rFunc.getLength()-1] == cParenthesesReplacement )
1482 aFuncNameStr = rFunc.copy(0, rFunc.getLength()-1);
1486 aFuncNameStr = rFunc;
1488 if ( itStr == rFuncStrVec.begin() )
1491 aDescFuncNameStr = aFuncNameStr +
"()";
1495 aTipStr.append(
", ");
1497 aTipStr.append(aFuncNameStr);
1498 if ( itStr == rFuncStrVec.begin() )
1499 aTipStr.append(
"]");
1500 if ( --nRemainFindNumber <= 0 )
1503 sal_Int32 nRemainNumber = rFuncStrVec.size() - nMaxFindNumber;
1504 if ( nRemainFindNumber == 0 && nRemainNumber > 0 )
1506 OUString aMessage(
ScResId( STR_FUNCTIONS_FOUND ) );
1507 aMessage = aMessage.replaceFirst(
"%2", OUString::number(nRemainNumber));
1508 aMessage = aMessage.replaceFirst(
"%1", aTipStr.makeStringAndClear());
1512 sal_Int32 nNextFStart = 0;
1514 ::std::vector< OUString > aArgs;
1515 OUString eqPlusFuncName =
"=" + aDescFuncNameStr;
1516 if ( aHelper.
GetNextFunc( eqPlusFuncName,
false, nNextFStart,
nullptr, &ppFDesc, &aArgs ) )
1523 ShowTip( aTipStr.makeStringAndClear() );
1541 if ( aSel.
nEndPos > aParagraph.getLength() )
1544 if ( aParagraph.getLength() > aSel.
nEndPos &&
1546 aParagraph[ aSel.
nEndPos ] ==
'_' ||
1547 aParagraph[ aSel.
nEndPos ] ==
'.' ||
1548 aParagraph[ aSel.
nEndPos ] ==
'$' ) )
1555 OUString aSelText( aParagraph.copy( 0, aSel.
nEndPos ));
1562 ::std::vector<OUString> aNewVec;
1569 for (
int n = 0;
n < aSelText.getLength();
n++ )
1573 if (aSelText[
n] == cBetweenQuotes)
1576 else if ( aSelText[
n ] ==
'"' )
1577 cBetweenQuotes =
'"';
1578 else if ( aSelText[
n ] ==
'\'' )
1579 cBetweenQuotes =
'\'';
1581 if ( cBetweenQuotes )
1600 ::std::vector<OUString> aNewVec;
1616 void completeFunction(
EditView* pView,
const OUString& rInsert,
bool& rParInserted )
1623 bool bNoInitialLetter =
false;
1636 bNoInitialLetter =
true;
1643 bNoInitialLetter =
true;
1650 if(!bNoInitialLetter)
1652 const sal_Int32 nMinLen = std::max(aSel.
nEndPos - aSel.
nStartPos, sal_Int32(1));
1664 for (sal_Int32 n = aAll.getLength();
n >= nMinLen && aMatch.isEmpty(); --
n)
1666 const OUString aTest = aAll.copy(aAll.getLength() -
n);
1675 OUString aInsStr = rInsert;
1676 sal_Int32 nInsLen = aInsStr.getLength();
1677 bool bDoParen = ( nInsLen > 1 && aInsStr[nInsLen-2] ==
'('
1678 && aInsStr[nInsLen-1] ==
')' );
1686 if (aWordSel.
nEndPos < aOld.getLength())
1692 aInsStr = aInsStr.copy( 0, nInsLen - 2 );
1706 rParInserted =
true;
1718 if (aInsert[aInsert.getLength()-1] == cParenthesesReplacement)
1719 aInsert = OUString::Concat(aInsert.subView( 0, aInsert.getLength()-1)) +
"()";
1720 bool bParInserted =
false;
1723 completeFunction(
pTopView, aInsert, bParInserted );
1724 completeFunction(
pTableView, aInsert, bParInserted );
1762 aFormula = pEditEngine->
GetText(0);
1763 bEdit = aFormula.getLength() > 1 && (aFormula[0] ==
'=' || aFormula[0] ==
'+' || aFormula[0] ==
'-');
1768 OUString aNewFormula(
'=');
1769 if ( aFormula.startsWith(
"=") )
1770 aNewFormula = aFormula;
1778 ScTypedCaseStrSet::const_iterator aPos = findText(*
pFormulaData,
pFormulaData->begin(), rFunctionName, aNew,
false);
1789 const OUString& rText,
1792 OUString aSelection =
1793 OUString::number(rSelection.
nStartPos) +
";" + OUString::number(rSelection.
nEndPos);
1795 std::unique_ptr<jsdialog::ActionDataMap>
pData = std::make_unique<jsdialog::ActionDataMap>();
1796 (*pData)[
"action_type"] =
"setText";
1797 (*pData)[
"text"] = rText;
1798 (*pData)[
"selection"] = aSelection;
1800 sal_uInt64 nCurrentShellId =
reinterpret_cast<sal_uInt64
>(
pActiveViewSh);
1801 std::string sWindowId = std::to_string(nCurrentShellId) +
"formulabar";
1811 if(rFormula.isEmpty())
1814 std::optional<ScSimpleFormulaCalculator> pCalc( std::in_place, rDoc, rPos, rFormula,
false );
1818 bool bColRowName = pCalc->HasColRowName();
1822 if ( pCalc->GetCode()->GetCodeLen() <= 1 )
1825 OUString aBraced =
"(" + rFormula +
")";
1826 pCalc.emplace( rDoc, rPos, aBraced,
false );
1829 bColRowName =
false;
1833 if ( nErrCode != FormulaError::NONE )
1838 if ( pCalc->IsValue() )
1840 double n = pCalc->GetValue();
1848 OUString aStr = pCalc->GetString().getString();
1852 const Color* pColor;
1857 aValue =
"\"" + aValue +
"\"";
1875 if (aPart.isEmpty())
1881 if (!aValue.isEmpty())
1897 sal_uInt32
const nTipLen2(sal::static_int_cast<sal_uInt32>(nTipLen));
1898 if ( nTipLen && ( nTipLen < 3 ||
aManualTip.subView( nTipLen2-3 ) !=
u"..." ) )
1923 if ( aInsert[0] ==
'"' )
1924 aInsert = aInsert.copy(1);
1925 sal_Int32 nInsLen = aInsert.getLength();
1926 if ( aInsert.endsWith(
"\"") )
1927 aInsert = aInsert.copy( 0, nInsLen-1 );
1971 if ( nPos < aFormula.getLength() && aFormula[nPos] ==
')' )
1998 OSL_ENSURE(
nAutoPar,
"SkipClosingPar: count is wrong");
2016 std::vector<ScTypedStrData>
aEntries;
2019 if (!aEntries.empty())
2020 pColumnData->insert(aEntries.begin(), aEntries.end());
2040 if ( aSel.
nEndPos != nParLen )
2044 if (aText.isEmpty())
2047 std::vector< OUString > aResultVec;
2049 sal_Int32 nLongestPrefixLen = 0;
2054 if (nLongestPrefixLen <= 0 || aResultVec.empty())
2057 if (aResultVec.size() > 1)
2064 aNew = aResultVec[0].copy(0, nLongestPrefixLen);
2068 aNew = aResultVec[0];
2079 sal_Int32 nEdLen =
mpEditEngine->GetTextLen() + nParCnt - 1;
2080 OUString aIns = aNew.copy(nEdLen);
2118 if ( aSel.
nEndPos == nParLen && aText.getLength() ==
aAutoSearch.getLength() + nSelLen )
2121 ScTypedCaseStrSet::const_iterator itNew =
2132 OUString aIns = aNew.copy(
aAutoSearch.getLength());
2169 bool bFound =
false;
2181 if ( c ==
'(' || c ==
')' )
2194 for (sal_Int32
i=0;
i<nCount;
i++)
2200 ESelection aSelOther( 0,nOther, 0,nOther+1 );
2220 for (sal_Int32
i=0;
i<nCount;
i++)
2243 SC_MOD()->SetRefInputHdl(
nullptr);
2253 OSL_FAIL(
"pActiveViewSh is gone");
2257 if (
SC_MOD()->GetInputOptions().GetTextWysiwyg() )
2278 for (sal_uInt16
i=1;
i<nCount;
i++)
2282 if ( pWin==pShellWin )
2343 case SvxCellHorJustify::Standard:
2345 bool bNumber =
false;
2347 bNumber = (cTyped>=
'0' && cTyped<=
'9');
2353 eSvxAdjust = bNumber ? SvxAdjust::Right : SvxAdjust::Left;
2356 case SvxCellHorJustify::Block:
2357 eSvxAdjust = SvxAdjust::Block;
2359 case SvxCellHorJustify::Center:
2360 eSvxAdjust = SvxAdjust::Center;
2362 case SvxCellHorJustify::Right:
2363 eSvxAdjust = SvxAdjust::Right;
2366 eSvxAdjust = SvxAdjust::Left;
2373 if ( bAsianVertical )
2376 eSvxAdjust = SvxAdjust::Left;
2410 for (sal_Int32
i=0;
i<nCount;
i++)
2423 bool bNewTable =
false;
2448 bool bStartInputMode =
true;
2476 bStartInputMode =
false;
2480 if (bStartInputMode)
2496 sal_uInt32 nFormat = pItem->GetValue();
2568 if (aStr.startsWith(
"{=") && aStr.endsWith(
"}") )
2570 aStr = aStr.copy(1, aStr.getLength() -2);
2578 if (
SC_MOD()->GetAppOptions().GetAutoComplete() )
2581 if ( !aStr.isEmpty() && ( aStr[0] ==
'=' || aStr[0] ==
'+' || aStr[0] ==
'-' ) &&
2637 bool bSelectionForTopView =
false;
2639 bSelectionForTopView =
true;
2640 bool bSelectionForTableView =
false;
2642 bSelectionForTableView =
true;
2643 if (bSelectionForTopView || bSelectionForTableView)
2646 if (bSelectionForTopView)
2648 if (bSelectionForTableView)
2663 mpEditEngine && mpEditEngine->IsUpdateLayout() && pInputWin )
2669 pInputWin->SetTextString(aText);
2683 return StartTable( cTyped, bFromCommand,
false,
nullptr );
2752 bool bNeedGrow = ( rViewData.
GetEditAdjust() != SvxAdjust::Left );
2792 bIsFormula = !rText.isEmpty() &&
2793 (rText[0] ==
'=' || rText[0] ==
'+' || rText[0] ==
'-');
2802 pSfxApp->Broadcast(
SfxHint( SfxHintId::ScRefModeChanged ) );
2824 pSfxApp->Broadcast(
SfxHint( SfxHintId::ScRefModeChanged ) );
2825 SC_MOD()->SetRefInputHdl(
nullptr);
2842 bool bFound =
false;
2845 while ( pOneFrame && !bFound )
2847 if ( pOneFrame == pRefFrame )
2862 OSL_FAIL(
"ViewFrame for reference input is not here anymore");
2890 rBindings.
Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
2893 rBindings.
Invalidate( SID_ATTR_CHAR_WEIGHT );
2894 rBindings.
Invalidate( SID_ATTR_CHAR_POSTURE );
2895 rBindings.
Invalidate( SID_ATTR_CHAR_UNDERLINE );
2896 rBindings.
Invalidate( SID_ATTR_CHAR_OVERLINE );
2898 rBindings.
Invalidate( SID_ULINE_VAL_SINGLE );
2899 rBindings.
Invalidate( SID_ULINE_VAL_DOUBLE );
2900 rBindings.
Invalidate( SID_ULINE_VAL_DOTTED );
2902 rBindings.
Invalidate( SID_HYPERLINK_GETLINK );
2904 rBindings.
Invalidate( SID_ATTR_CHAR_KERNING );
2905 rBindings.
Invalidate( SID_SET_SUPER_SCRIPT );
2907 rBindings.
Invalidate( SID_ATTR_CHAR_STRIKEOUT );
2908 rBindings.
Invalidate( SID_ATTR_CHAR_SHADOWED );
2918 if (
eMode == eNewMode )
2961 sal_Int32 nLen =
mpEditEngine->GetText(nPara).getLength();
2964 for (sal_uInt16
i=0;
i<nCount;
i++)
2973 SetSelection(
ESelection( nPara, nLen, nPara, nLen ) );
2991 if (eNewMode != eOldMode)
3002 sal_Int32 nLen = rString.getLength();
3003 for (sal_Int32
i=0;
i<nLen;
i++)
3006 if ( c < '0' || c >
'9' )
3043 std::unique_ptr<EditTextObject>
pObject;
3044 std::unique_ptr<ScPatternAttr> pCellAttrs;
3045 bool bForget =
false;
3048 OUString aPreAutoCorrectString(aString);
3102 pSelEngine->ReleaseMouse();
3105 if (bBeforeSavingInLOK)
3135 std::vector<editeng::MisspellRanges> aMisspellRanges;
3155 bSpellErrors =
false;
3172 bool bUniformAttribs =
true;
3174 for (sal_Int32 nPara = 1; nPara < nParCnt; ++nPara)
3177 if (!(aPara1Attribs == aPara2Attribs))
3180 bUniformAttribs =
false;
3192 std::optional<SfxItemSet> pCommonAttrs;
3196 if ( eState == SfxItemState::SET &&
3201 if ( !pCommonAttrs )
3202 pCommonAttrs.emplace(
mpEditEngine->GetEmptyItemSet() );
3203 pCommonAttrs->Put( *pItem );
3210 pCellAttrs = std::make_unique<ScPatternAttr>(rDoc.
GetPool());
3211 pCellAttrs->GetFromEditItemSet( &*pCommonAttrs );
3218 bool bAttrib =
false;
3228 if (eState == SfxItemState::DONTCARE)
3230 else if (eState == SfxItemState::SET)
3244 if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
3249 if ( eConvState == SfxItemState::DONTCARE || eConvState == SfxItemState::SET )
3267 else if (
SC_MOD()->GetAppOptions().GetAutoComplete())
3291 pSfxApp->Broadcast(
SfxHint( SfxHintId::ScRefModeChanged ) );
3292 SC_MOD()->SetRefInputHdl(
nullptr);
3314 bool bInsertPreCorrectedString =
true;
3316 if (aString.startsWith(
"="))
3321 bInsertPreCorrectedString =
false;
3323 if( aReplace.isEmpty() )
3325 if( aReplace !=
"\"" )
3326 aString = aString.replaceAll( aReplace,
"\"" );
3329 if( aReplace.isEmpty() )
3331 if( aReplace !=
"\"" )
3332 aString = aString.replaceAll( aReplace,
"\"" );
3335 if( aReplace.isEmpty() )
3337 if( aReplace !=
"'" )
3338 aString = aString.replaceAll( aReplace,
"'" );
3341 if( aReplace.isEmpty() )
3343 if( aReplace !=
"'" )
3344 aString = aString.replaceAll( aReplace,
"'");
3348 pSfxApp->Broadcast(
SfxHint( SfxHintId::ScKillEditViewNoPaint ) );
3354 sal_uInt16
nId = FID_INPUTLINE_ENTER;
3356 nId = FID_INPUTLINE_BLOCK;
3358 nId = FID_INPUTLINE_MATRIX;
3363 if ( bInsertPreCorrectedString && aString != aPreAutoCorrectString )
3367 aPreAutoCorrectString, pObject.get());
3369 rBindings.
Execute(nId, aArgs);
3374 aString, pObject.get());
3375 if ( !aMisspellRanges.empty() )
3378 aArgs[0] = &aItemCorrected;
3379 rBindings.
Execute(nId, aArgs);
3385 pSfxApp->Broadcast(
SfxHint( SfxHintId::ScKillEditView ) );
3387 if ( bOldMod && pExecuteSh && pCellAttrs && !bForget )
3428 SC_MOD()->SetRefInputHdl(
nullptr);
3458 std::vector<ReferenceMark> aReferenceMarks;
3483 sal_Int32
nPos = aText.getLength() - 1;
3486 cLastChar = aText[nPos];
3487 if (cLastChar !=
' ')
3492 bool bAppendSeparator = (cLastChar !=
'(' && cLastChar != cSep && cLastChar !=
'=');
3493 if (bAppendSeparator)
3511 bool bOtherDoc = (pThisDoc != &rDoc);
3569 switch(aAddrDetails.
eConv)
3574 aRefStr =
"[\'" + aFileName +
"']";
3578 aRefStr =
"\'" + aFileName +
"'#";
3592 bool bLOKShowSelect =
true;
3594 bLOKShowSelect =
false;
3613 OSL_FAIL(
"InsertFunction, not during input mode");
3623 OUString aText = rFuncName;
3660 OSL_FAIL(
"ClearText, not during input mode");
3688 bool bShift = aCode.
IsShift();
3689 bool bControl = aCode.
IsMod1();
3690 bool bAlt = aCode.
IsMod2();
3694 if (bAlt && !bControl && nCode !=
KEY_RETURN)
3714 if (!bControl && nCode ==
KEY_TAB)
3728 bool bDoEnter =
false;
3735 if ((
pInputWin && bInputLine && bControl != bShift) || (!bInputLine && bControl && !bShift))
3752 if ( bShift && bControl )
3765 if (bControl && !bAlt)
3812 bool bInsKey = ( nCode ==
KEY_INSERT && !nModi );
3851 if ( !aStrLoP.isEmpty() )
3860 if ( !aStrLoP.isEmpty() )
3906 if ( bUsed &&
SC_MOD()->GetAppOptions().GetAutoComplete() )
3915 if ( nChar && nChar != 8 && nChar != 127 &&
3916 KeyFuncType::CUT != eFunc)
3927 if ( bUsed && nChar ==
'(' )
3948 bool bSetModified = !bCursorKey;
4018 if ( rCEvt.
GetCommand() == CommandEventId::CursorPos )
4034 else if ( rCEvt.
GetCommand() == CommandEventId::QueryCharPosition )
4093 if ( rCEvt.
GetCommand() == CommandEventId::EndExtTextInput )
4130 if (bRepeat && !bForce)
4164 bool bIgnore =
false;
4182 bool bTxtMod =
false;
4190 else if ( bHadObject )
4197 if ( bTxtMod || bForce )
4232 bool bSheetLocal =
false;
4239 GetRangeAtBlock(
ScRange( rSPos, rEPos ), aPosStr, &bSheetLocal);
4241 if ( aPosStr.isEmpty() )
4246 if ( rSPos != rEPos )
4255 else if (bSheetLocal)
4284 if ( nCntrl & EEControlBits::ONLINESPELLING )
4285 mpEditEngine->SetControlWord( nCntrl & ~EEControlBits::ONLINESPELLING );
4344 if ( !(
nullptr == pLastState ||
SC_MOD()->IsFormulaMode() ||
SC_MOD()->IsRefDialogOpen()))
4349 if ( pViewFrm && pViewFrm->
GetChildWindow( SID_OPENDLG_FUNCTION ) )
4353 pInputWin->EnableButtons(
false );
4354 pInputWin->Disable();
4357 else if ( !bFormulaMode )
4359 bInOwnChange =
true;
4361 pActiveViewSh =
nullptr;
4362 mpEditEngine->SetTextCurrentDefaults( OUString() );
4365 pInputWin->SetPosString( OUString() );
4366 pInputWin->SetTextString( OUString() );
4367 pInputWin->Disable();
4370 bInOwnChange =
false;
4396 bool bFromTopNotify = ( bFromNotify && pView ==
pTopView );
4446 if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
4449 std::unique_ptr<EditTextObject> pObj =
mpEditEngine->CreateTextObject();
4454 for (sal_Int32
i=0;
i<nParCnt;
i++)
4458 while ( nParCnt > 1 )
4460 sal_Int32 nLen = rDestEngine.
GetTextLen( 0 );
4510 if ( nStart <= nEnd )
4536 sal_Int32 nNewLen = rStr.getLength();
4540 aBuf.remove(nFormSelStart, nOldLen);
4542 aBuf.insert(nFormSelStart, rStr);
4579 const OUString& rString,
4581 : aCursorPos ( rCurPos ),
4582 aStartPos ( rStartPos ),
4583 aEndPos ( rEndPos ),
4584 aString ( rString ),
4585 pEditData ( pData ? pData->
Clone() : nullptr )
ScMarkData & GetMarkData()
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
void FindNextUnprot(bool bShift, bool bInSelection)
SfxViewFrame * GetViewFrame() const
#define LINK(Instance, Class, Member)
sal_Unicode GetEndDoubleQuote() const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
List of spreadsheet functions.
void FillInfo(ScTableInfo &rTabInfo, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab, double fColScale, double fRowScale, bool bPageMode, bool bFormulaMode, const ScMarkData *pMarkData=nullptr)
void SetControlWord(EVControlBits nWord)
OUString GetText(LineEnd eEnd=LINEEND_LF) const
bool IsDataValid(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos) const
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
ScDocShell * GetDocShell() const
void SetEditAdjust(SvxAdjust eNewEditAdjust)
void DataPilotInput(const ScAddress &rPos, const OUString &rString)
constexpr TypedWhichId< SvxAutoKernItem > EE_CHAR_PAIRKERNING(EE_CHAR_START+11)
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
bool AdjustBlockHeight(bool bPaint=true, ScMarkData *pMarkData=nullptr)
static SvxAutoCorrCfg & Get()
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
bool GetAutoComplete() const
SfxChildWindow * GetChildWindow(sal_uInt16)
constexpr TypedWhichId< SvxKerningItem > EE_CHAR_KERNING(EE_CHAR_START+12)
void TestSelection(const ScDocument &rDoc, const ScMarkData &rMark)
OUString ScResId(TranslateId aId)
bool isLOKMobilePhone() const
void ErrorMessage(TranslateId pGlobStrId)
void PostEditView(ScEditEngineDefaulter *pEditEngine, const ScAddress &rCursorPos)
void SetAccessibilityEventsSuppressed(bool bSuppressed)
static bool EETextObjEqual(const EditTextObject *pObj1, const EditTextObject *pObj2)
OUString GetTitle(sal_uInt16 nMaxLen=0) const
bool Command(const CommandEvent &rCEvt)
const Fraction & GetZoomX() const
void CompleteAutoCorrect(vcl::Window const *pFrameWin=nullptr)
bool IsTransparent() const
constexpr TypedWhichId< SfxBoolItem > ATTR_VERTICAL_ASIAN(137)
std::unique_ptr< sal_Int32[]> pData
Point GetPrintTwipsPos(SCCOL nCol, SCROW nRow) const
returns the position (top-left corner) of the requested cell in print twips coordinates.
bool IsDataValidCustom(const OUString &rTest, const ScPatternAttr &rPattern, const ScAddress &rPos, const CustomValidationPrivateAccess &) const
SCROW GetRefStartY() const
sal_uInt16 GetLRUFuncListCount() const
void SetPasteMode(ScPasteFlags nFlags)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
svtools::ColorConfig & GetColorConfig()
void ShowCursor(bool bGotoCursor=true, bool bForceVisCursor=true, bool bActivate=false)
vcl::Window * GetFrameWin() const
bool HasSelection() const
SC_DLLPUBLIC sal_Unicode GetSheetSeparator() const
Obtain the sheet separator corresponding to the document's grammar.
SvxAdjust GetEditAdjust() const
const ContentProperties & rData
sal_uInt16 GetCode() const
ScSplitPos GetActivePart() const
ScDocument & GetDocument() const
Selection GetSurroundingTextSelection() const
void EditGrowY(bool bInitial=false)
Extend the output area for the edit engine view in a vertical direction as needed.
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
const OUString & getQuotationMarkStart() const
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
OUString GetSurroundingText() const
void Invalidate(sal_uInt16 nId)
void SelectCurrentWord(sal_Int16 nWordType=css::i18n::WordType::ANYWORD_IGNOREWHITESPACES)
void ApplyAsianEditSettings(ScEditEngineDefaulter &rEngine)