changed: the way how the mouse selection works when you have clicked a button (sin/cos/..)

now if there is no selection and the last character is an operator: + - / * % ^ (
         then the text is append at the end (instead of looking for beginning of the expression)
         this seems to be more comfortable


git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@353 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-06-03 23:24:32 +00:00
parent c4f316d7d3
commit 14f987012d
1 changed files with 32 additions and 9 deletions

View File

@ -145,27 +145,50 @@ int brackets;
} }
bool IsWhite(int c)
{
return c==' ' || c=='\t';
}
bool IsOpeningOperand(int c)
{
return c=='-' || c=='+' || c=='*' ||c=='/' || c=='%' ||c=='^' || c=='(';
}
bool IsOpeningOperandBefore(const char * buf, int end)
{
while( end > 0 && IsWhite(buf[end-1]) )
end -= 1;
if( end == 0 )
return false;
return IsOpeningOperand(buf[end-1]);
}
void CalcBracketsPos(HWND input, int & start, int & end) void CalcBracketsPos(HWND input, int & start, int & end)
{ {
DWORD sel_start, sel_end; DWORD sel_start, sel_end;
SendMessage(input, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end); SendMessage(input, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
if( sel_start != sel_end ) start = sel_start;
{ end = sel_end;
start = sel_start;
end = sel_end; if( start != end )
return; return;
}
char * buf = GetPrgRes()->GetBufferTemp(); char * buf = GetPrgRes()->GetBufferTemp();
start = 0; int len = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf);
end = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf);
if( end > 0 ) if( len > 0 && !IsOpeningOperandBefore(buf, end) )
{ {
start = CalcBracketsPrev(buf, sel_start); start = CalcBracketsPrev(buf, sel_start);
end = CalcBracketsNext(buf, end, sel_start); end = CalcBracketsNext(buf, len, sel_start);
} }
} }