From 14f987012dc424d00f3ea0d717a07c0ab6171fb5 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 3 Jun 2011 23:24:32 +0000 Subject: [PATCH] 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 --- src/tabs.cpp | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/tabs.cpp b/src/tabs.cpp index 693bc5f..5899f01 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -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) { DWORD sel_start, 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; - } char * buf = GetPrgRes()->GetBufferTemp(); - start = 0; - end = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf); + int len = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf); - if( end > 0 ) + if( len > 0 && !IsOpeningOperandBefore(buf, end) ) { start = CalcBracketsPrev(buf, sel_start); - end = CalcBracketsNext(buf, end, sel_start); + end = CalcBracketsNext(buf, len, sel_start); } }