Merge pull request #627 from RaiKoHoff/Dev_0825

TinyExpr: add (simple) support for rectangular selection
This commit is contained in:
Rainer Kottenhoff 2018-08-25 13:27:43 +02:00 committed by GitHub
commit 182dcea035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 58 deletions

View File

@ -614,7 +614,7 @@ int Toolbar_GetButtons(HWND hwnd,int cmdBase,LPWSTR lpszButtons,int cchButtons)
(tbb.idCommand==0)?0:tbb.idCommand-cmdBase+1);
lstrcat(tchButtons,tchItem);
}
TrimString(tchButtons);
TrimStringW(tchButtons);
lstrcpyn(lpszButtons,tchButtons,cchButtons);
return(c);
}
@ -627,7 +627,7 @@ int Toolbar_SetButtons(HWND hwnd,int cmdBase,LPCWSTR lpszButtons,LPCTBBUTTON ptb
ZeroMemory(tchButtons,COUNTOF(tchButtons)*sizeof(tchButtons[0]));
lstrcpyn(tchButtons,lpszButtons,COUNTOF(tchButtons)-2);
TrimString(tchButtons);
TrimStringW(tchButtons);
WCHAR *p = StrStr(tchButtons, L" ");
while (p) {
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));
@ -964,9 +964,9 @@ BOOL PathCreateLnk(LPCWSTR pszLnkDir,LPCWSTR pszPath)
//=============================================================================
//
// TrimString()
// TrimStringW()
//
BOOL TrimString(LPWSTR lpString)
BOOL TrimStringW(LPWSTR lpString)
{
LPWSTR psz;
@ -1007,13 +1007,13 @@ BOOL ExtractFirstArgument(LPCWSTR lpArgs,LPWSTR lpArg1,LPWSTR lpArg2)
if (lpArg2)
*lpArg2 = L'\0';
if (!TrimString(lpArg1))
if (!TrimStringW(lpArg1))
return FALSE;
if (*lpArg1 == L'\"')
{
*lpArg1 = L' ';
TrimString(lpArg1);
TrimStringW(lpArg1);
bQuoted = TRUE;
}
@ -1029,10 +1029,10 @@ BOOL ExtractFirstArgument(LPCWSTR lpArgs,LPWSTR lpArg1,LPWSTR lpArg2)
lstrcpy(lpArg2,psz + 1);
}
TrimString(lpArg1);
TrimStringW(lpArg1);
if (lpArg2)
TrimString(lpArg2);
TrimStringW(lpArg2);
return TRUE;

View File

@ -107,7 +107,7 @@ BOOL PathGetLnkPath(LPCWSTR,LPWSTR,int);
BOOL PathIsLnkToDirectory(LPCWSTR,LPWSTR,int);
BOOL PathCreateLnk(LPCWSTR,LPCWSTR);
BOOL TrimString(LPWSTR);
BOOL TrimStringW(LPWSTR);
BOOL ExtractFirstArgument(LPCWSTR, LPWSTR, LPWSTR);
LPWSTR QuotateFilenameStr(LPWSTR);

View File

@ -3177,7 +3177,7 @@ void ParseCommandLine()
lstrcpy(g_wchIniFile,L"*?");
else if (ExtractFirstArgument(lp2,lp1,lp2)) {
StrCpyN(g_wchIniFile,lp1,COUNTOF(g_wchIniFile));
TrimString(g_wchIniFile);
TrimStringW(g_wchIniFile);
PathUnquoteSpaces(g_wchIniFile);
}
break;

View File

@ -3343,7 +3343,7 @@ int Toolbar_GetButtons(HWND hwnd, int cmdBase, LPWSTR lpszButtons, int cchButton
(tbb.idCommand == 0) ? 0 : tbb.idCommand - cmdBase + 1);
StringCchCat(tchButtons, COUNTOF(tchButtons), tchItem);
}
TrimString(tchButtons);
TrimStringW(tchButtons);
StringCchCopyN(lpszButtons, cchButtons, tchButtons, COUNTOF(tchButtons));
return(c);
}
@ -3356,7 +3356,7 @@ int Toolbar_SetButtons(HWND hwnd, int cmdBase, LPCWSTR lpszButtons, LPCTBBUTTON
ZeroMemory(tchButtons, COUNTOF(tchButtons) * sizeof(tchButtons[0]));
StringCchCopyN(tchButtons, COUNTOF(tchButtons), lpszButtons, COUNTOF(tchButtons) - 2);
TrimString(tchButtons);
TrimStringW(tchButtons);
WCHAR *p = StrStr(tchButtons, L" ");
while (p) {
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));

View File

@ -1150,34 +1150,54 @@ bool StrLTrim(LPWSTR pszSource,LPCWSTR pszTrimChars)
}
#if 0
//=============================================================================
//
// TrimString()
// TrimStringA()
//
bool TrimString(LPWSTR lpString)
bool TrimStringA(LPSTR lpString)
{
if (!lpString || !*lpString)
return false;
if (!lpString || !*lpString) { return false; }
// Trim left
LPWSTR psz = lpString;
LPSTR psz = lpString;
while (*psz == ' ') { psz = CharNextA(psz); }
while (*psz == L' ') { psz = CharNext(psz); }
MoveMemory(lpString,psz,sizeof(WCHAR)*(lstrlen(psz) + 1));
MoveMemory(lpString, psz, sizeof(CHAR)*(strlen(psz) + 1));
// Trim right
psz = StrEnd(lpString);
psz = StrEndA(lpString);
while (*(psz = CharPrevA(lpString, psz)) == ' ') { *psz = '\0'; }
while (*(psz = CharPrev(lpString, psz)) == L' ') {
*psz = L'\0';
}
return true;
}
//=============================================================================
//
// TrimStringW()
//
bool TrimStringW(LPWSTR lpString)
{
if (!lpString || !*lpString) { return false; }
// Trim left
LPWSTR psz = lpString;
while (*psz == L' ') { psz = CharNextW(psz); }
MoveMemory(lpString,psz,sizeof(WCHAR)*(lstrlen(psz) + 1));
// Trim right
psz = StrEndW(lpString);
while (*(psz = CharPrevW(lpString, psz)) == L' ') { *psz = L'\0'; }
return true;
}
#endif
//=============================================================================
//
@ -1194,13 +1214,13 @@ bool ExtractFirstArgument(LPCWSTR lpArgs, LPWSTR lpArg1, LPWSTR lpArg2, int len)
if (lpArg2)
*lpArg2 = L'\0';
if (!TrimString(lpArg1))
if (!TrimStringW(lpArg1))
return false;
if (*lpArg1 == L'\"')
{
*lpArg1 = L' ';
TrimString(lpArg1);
TrimStringW(lpArg1);
bQuoted = true;
}
@ -1216,10 +1236,10 @@ bool ExtractFirstArgument(LPCWSTR lpArgs, LPWSTR lpArg1, LPWSTR lpArg2, int len)
StringCchCopy(lpArg2, len, psz + 1);
}
TrimString(lpArg1);
TrimStringW(lpArg1);
if (lpArg2)
TrimString(lpArg2);
TrimStringW(lpArg2);
return true;
}
@ -2271,7 +2291,7 @@ int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, i
static WCHAR wchTmpBuff[MIDSZ_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchCSVStrg);
TrimString(wchTmpBuff);
TrimStringW(wchTmpBuff);
// fill default
for (int i = 0; i < iCount; ++i) {
if (sDefault && *sDefault)
@ -2310,7 +2330,7 @@ int ReadVectorFromString(LPCWSTR wchStrg, int iVector[], int iCount, int iMin, i
static WCHAR wchTmpBuff[SMALL_BUFFER];
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchStrg);
TrimString(wchTmpBuff);
TrimStringW(wchTmpBuff);
// ensure single spaces only
WCHAR *p = StrStr(wchTmpBuff, L" ");
while (p) {

View File

@ -235,7 +235,16 @@ bool PathCreateFavLnk(LPCWSTR,LPCWSTR,LPCWSTR);
bool StrLTrim(LPWSTR,LPCWSTR);
bool TrimString(LPWSTR);
inline bool TrimStringA(LPSTR lpString) {
if (!lpString || !*lpString) { return false; }
StrTrimA(lpString, " ");
return true;
};
inline bool TrimStringW(LPWSTR lpString) {
if (!lpString || !*lpString) { return false; }
StrTrimW(lpString, L" ");
return true;
};
bool ExtractFirstArgument(LPCWSTR, LPWSTR, LPWSTR, int);
void PrepareFilterStr(LPWSTR);

View File

@ -7299,7 +7299,7 @@ void ParseCommandLine()
else if (StrCmpNI(lp1,L"tmpfbuf=",CSTRLEN(L"tmpfbuf=")) == 0) {
StringCchCopyN(g_szTmpFilePath,COUNTOF(g_szTmpFilePath),
lp1 + CSTRLEN(L"tmpfbuf="),len - CSTRLEN(L"tmpfbuf="));
TrimString(g_szTmpFilePath);
TrimStringW(g_szTmpFilePath);
PathUnquoteSpaces(g_szTmpFilePath);
NormalizePathEx(g_szTmpFilePath,COUNTOF(g_szTmpFilePath));
g_flagBufferFile = 1;
@ -7331,7 +7331,7 @@ void ParseCommandLine()
StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),L"*?");
else if (ExtractFirstArgument(lp2,lp1,lp2,len)) {
StringCchCopyN(g_wchIniFile,COUNTOF(g_wchIniFile),lp1,len);
TrimString(g_wchIniFile);
TrimStringW(g_wchIniFile);
PathUnquoteSpaces(g_wchIniFile);
NormalizePathEx(g_wchIniFile,COUNTOF(g_wchIniFile));
}
@ -8150,6 +8150,45 @@ static void __fastcall _CalculateStatusbarSections(int vSectionWidth[], sectionT
}
//=============================================================================
//
// _InterpRectSelTinyExpr()
//
//
static double __fastcall _InterpRectSelTinyExpr(int* piExprError)
{
#define _tmpBufCnt 256
char tmpRectSelN[_tmpBufCnt] = { '\0' };
g_pTempLineBufferMain[0] = '\0';
size_t const tmpLineBufSize = COUNTOF(g_pTempLineBufferMain);
DocPosU const selCount = SciCall_GetSelections();
bool bLastCharWasDigit = false;
for (DocPosU i = 0; i < selCount; ++i)
{
DocPos const posSelStart = SciCall_GetSelectionNStart(i);
DocPos const posSelEnd = SciCall_GetSelectionNEnd(i);
size_t const cchToCopy = (size_t)(posSelEnd - posSelStart);
StringCchCopyNA(tmpRectSelN, _tmpBufCnt, SciCall_GetRangePointer(posSelStart, (DocPos)cchToCopy), cchToCopy);
StrTrimA(tmpRectSelN, " ");
if (!StrIsEmptyA(tmpRectSelN))
{
if (IsDigit(tmpRectSelN[0]) && bLastCharWasDigit) {
StringCchCatA(g_pTempLineBufferMain, tmpLineBufSize, "+"); // default: add numbers
}
bLastCharWasDigit = IsDigit(tmpRectSelN[strlen(tmpRectSelN) - 1]);
StringCchCatA(g_pTempLineBufferMain, tmpLineBufSize, tmpRectSelN);
}
}
return te_interp(g_pTempLineBufferMain, piExprError);
}
//=============================================================================
//
// UpdateStatusbar()
@ -8359,7 +8398,6 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw)
// try calculate expression of selection
static WCHAR tchExpression[32] = { L'\0' };
static int s_iExprError = -3;
static char chExpression[1024] = { '\0' };
if (g_iStatusbarVisible[STATUS_TINYEXPR])
{
@ -8370,29 +8408,35 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw)
if (bIsSelCountable)
{
if (SciCall_GetSelText(NULL) < COUNTOF(chExpression))
if (SciCall_GetSelText(NULL) < COUNTOF(g_pTempLineBufferMain))
{
SciCall_GetSelText(chExpression);
SciCall_GetSelText(g_pTempLineBufferMain);
//StrDelChrA(chExpression, " \r\n\t\v");
StrDelChrA(chExpression, "\r\n");
g_dExpression = te_interp(chExpression, &g_iExprError);
if (!g_iExprError) {
if (fabs(g_dExpression) > 99999999.9999)
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"%.4E", g_dExpression);
else
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"%.6G", g_dExpression);
}
else
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"^[%i]", g_iExprError);
StrDelChrA(g_pTempLineBufferMain, "\r\n");
g_dExpression = te_interp(g_pTempLineBufferMain, &g_iExprError);
}
else
else {
g_iExprError = -1;
}
}
else if (SciCall_IsSelectionRectangle() && !bIsSelectionEmpty)
{
g_dExpression = _InterpRectSelTinyExpr(&g_iExprError);
}
else
g_iExprError = -2;
if (!g_iExprError) {
if (fabs(g_dExpression) > 99999999.9999)
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"%.4E", g_dExpression);
else
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"%.6G", g_dExpression);
}
else if (g_iExprError > 0) {
StringCchPrintf(tchExpression, COUNTOF(tchExpression), L"^[%i]", g_iExprError);
}
if (!g_iExprError || (s_iExprError != g_iExprError)) {
StringCchPrintf(tchStatusBar[STATUS_TINYEXPR], txtWidth, L"%s%s%s ",

View File

@ -177,6 +177,9 @@ DeclareSciCallV2(SetSelectionNCaret, SETSELECTIONNCARET, DocPosU, selnum, DocPos
DeclareSciCallV2(SetSelectionNAnchor, SETSELECTIONNANCHOR, DocPosU, selnum, DocPos, anchorPos)
DeclareSciCallV2(SetSelectionNCaretVirtualSpace, SETSELECTIONNCARETVIRTUALSPACE, DocPosU, selnum, DocPos, position)
DeclareSciCallV2(SetSelectionNAnchorVirtualSpace, SETSELECTIONNANCHORVIRTUALSPACE, DocPosU, selnum, DocPos, position)
DeclareSciCallR1(GetSelectionNStart, GETSELECTIONNSTART, DocPos, DocPosU, selnum)
DeclareSciCallR1(GetSelectionNEnd, GETSELECTIONNEND, DocPos, DocPosU, selnum)
// Zoom
DeclareSciCallR0(GetZoom, GETZOOM, int)

View File

@ -4715,7 +4715,7 @@ bool Style_StrGetFont(LPCWSTR lpszStyle,LPWSTR lpszFont,int cchFont)
p = StrChr(tch, L';');
if (p)
*p = L'\0';
TrimString(tch);
TrimStringW(tch);
if (StringCchCompareIN(tch,COUNTOF(tch),L"Default",-1) == 0)
{
@ -4748,7 +4748,7 @@ bool Style_StrGetFontQuality(LPCWSTR lpszStyle,LPWSTR lpszQuality,int cchQuality
p = StrChr(tch, L';');
if (p)
*p = L'\0';
TrimString(tch);
TrimStringW(tch);
if (StringCchCompareIN(tch,COUNTOF(tch),L"none",-1) == 0 ||
StringCchCompareIN(tch,COUNTOF(tch),L"standard",-1) == 0 ||
StringCchCompareIN(tch,COUNTOF(tch),L"cleartype",-1) == 0 ||
@ -4775,7 +4775,7 @@ bool Style_StrGetCharSet(LPCWSTR lpszStyle, int* i)
StringCchCopy(tch,COUNTOF(tch),p + CSTRLEN(L"charset:"));
p = StrChr(tch, L';');
if (p) { *p = L'\0'; }
TrimString(tch);
TrimStringW(tch);
int iValue = 0;
if (1 == swscanf_s(tch, L"%i", &iValue))
{
@ -4811,7 +4811,7 @@ bool Style_StrGetSize(LPCWSTR lpszStyle, float* f)
}
p = StrChr(tch, L';');
if (p) { *p = L'\0'; }
TrimString(tch);
TrimStringW(tch);
float fValue = 0.0;
if (Char2FloatW(tch, &fValue))
@ -4845,7 +4845,7 @@ bool Style_StrGetSizeStr(LPCWSTR lpszStyle,LPWSTR lpszSize,int cchSize)
StringCchCopy(tch, COUNTOF(tch), (p + CSTRLEN(L"size:")));
p = StrChr(tch, L';');
if (p) { *p = L'\0'; }
TrimString(tch);
TrimStringW(tch);
float fValue = 0.0f;
if (Char2FloatW(tch, &fValue)) {
@ -4953,7 +4953,7 @@ bool Style_StrGetColor(bool bFore, LPCWSTR lpszStyle, COLORREF* rgb)
p = StrChr(tch, L';');
if (p)
*p = L'\0';
TrimString(tch);
TrimStringW(tch);
int iValue = 0;
int itok = swscanf_s(tch, L"%x", &iValue);
if (itok == 1)
@ -4981,7 +4981,7 @@ bool Style_StrGetAlpha(LPCWSTR lpszStyle, int* i, bool bAlpha1st)
p = StrChr(tch, L';');
if (p)
*p = L'\0';
TrimString(tch);
TrimStringW(tch);
int iValue = 0;
int itok = swscanf_s(tch, L"%i", &iValue);
if (itok == 1) {
@ -5006,7 +5006,7 @@ bool Style_StrGetAlpha(LPCWSTR lpszStyle, int* i, bool bAlpha1st)
// p = StrChr(tch, L';');
// if (p)
// *p = L'\0';
// TrimString(tch);
// TrimStringW(tch);
// if (1 == swscanf_s(tch, L"%i", val)) { return true; }
// }
// return false;
@ -5026,7 +5026,7 @@ bool Style_StrGetCase(LPCWSTR lpszStyle, int* i)
p = StrChr(tch, L';');
if (p)
*p = L'\0';
TrimString(tch);
TrimStringW(tch);
if (tch[0] == L'u' || tch[0] == L'U') {
*i = SC_CASE_UPPER;
return true;

Binary file not shown.