diff -cNr old/sc/source/ui/app/inputhdl.cxx new/sc/source/ui/app/inputhdl.cxx *** old/sc/source/ui/app/inputhdl.cxx Fri Mar 7 23:10:48 2008 --- new/sc/source/ui/app/inputhdl.cxx Mon Apr 21 13:23:16 2008 *************** *** 316,321 **** --- 316,413 ---- rStr.SetChar( nPos, ' ' ); } + xub_StrLen lcl_MatchParenthesis( const String& rStr, xub_StrLen nPos ) + { + int nDir; + sal_Unicode c1, c2 = 0; + c1 = rStr.GetChar( nPos ); + switch ( c1 ) + { + case '(' : + c2 = ')'; + nDir = 1; + break; + case ')' : + c2 = '('; + nDir = -1; + break; + case '<' : + c2 = '>'; + nDir = 1; + break; + case '>' : + c2 = '<'; + nDir = -1; + break; + case '{' : + c2 = '}'; + nDir = 1; + break; + case '}' : + c2 = '{'; + nDir = -1; + break; + case '[' : + c2 = ']'; + nDir = 1; + break; + case ']' : + c2 = '['; + nDir = -1; + break; + default: + nDir = 0; + } + if ( !nDir ) + return STRING_NOTFOUND; + xub_StrLen nLen = rStr.Len(); + const sal_Unicode* p0 = rStr.GetBuffer(); + register const sal_Unicode* p; + const sal_Unicode* p1; + USHORT nQuotes = 0; + if ( nPos < nLen / 2 ) + { + p = p0; + p1 = p0 + nPos; + } + else + { + p = p0 + nPos; + p1 = p0 + nLen; + } + while ( p < p1 ) + { + if ( *p++ == '\"' ) + nQuotes++; + } + // Odd number of quotes that we find ourselves in a string + BOOL bLookInString = ((nQuotes % 2) != 0); + BOOL bInString = bLookInString; + p = p0 + nPos; + p1 = (nDir < 0 ? p0 : p0 + nLen) ; + USHORT nLevel = 1; + while ( p != p1 && nLevel ) + { + p += nDir; + if ( *p == '\"' ) + { + bInString = !bInString; + if ( bLookInString && !bInString ) + p = p1; //That's it then + } + else if ( bInString == bLookInString ) + { + if ( *p == c1 ) + nLevel++; + else if ( *p == c2 ) + nLevel--; + } + } + if ( nLevel ) + return STRING_NOTFOUND; + return (xub_StrLen) (p - p0); + } + //================================================================== ScInputHandler::ScInputHandler() *************** *** 325,331 **** --- 417,425 ---- pTopView( NULL ), pColumnData( NULL ), pFormulaData( NULL ), + pFormulaDataPara( NULL ), nTipVisible( 0 ), + nTipVisibleSec( 0 ), nAutoPos( SCPOS_INVALID ), bUseTab( FALSE ), bTextValid( TRUE ), *************** *** 384,389 **** --- 478,484 ---- delete pDelayTimer; delete pColumnData; delete pFormulaData; + delete pFormulaDataPara; } void ScInputHandler::SetRefScale( const Fraction& rX, const Fraction& rY ) *************** *** 537,575 **** if ( pFormulaData ) pFormulaData->FreeAll(); ! else ! pFormulaData = new TypedStrCollection; // MRU-Funktionen aus dem Funktions-Autopiloten // wie in ScPosWnd::FillFunctions (inputwin.cxx) ! ! const ScAppOptions& rOpt = SC_MOD()->GetAppOptions(); ! USHORT nMRUCount = rOpt.GetLRUFuncListCount(); ! const USHORT* pMRUList = rOpt.GetLRUFuncList(); ! if (pMRUList) ! { ! const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); ! ULONG nListCount = pFuncList->GetCount(); ! for (USHORT i=0; iGetFunction( j ); ! if ( pDesc->nFIndex == nId && pDesc->pFuncName ) ! { ! String aEntry = *pDesc->pFuncName; ! aEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" )); ! TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS ); ! if (!pFormulaData->Insert(pData)) ! delete pData; ! break; // nicht weitersuchen ! } ! } ! } ! } ! pDoc->GetFormulaEntries( *pFormulaData ); } } --- 632,687 ---- if ( pFormulaData ) pFormulaData->FreeAll(); ! else ! pFormulaData = new TypedStrCollection; ! ! if( pFormulaDataPara ) ! pFormulaDataPara->FreeAll(); ! else ! pFormulaDataPara = new TypedStrCollection; // MRU-Funktionen aus dem Funktions-Autopiloten // wie in ScPosWnd::FillFunctions (inputwin.cxx) ! ! const ScAppOptions& rOpt = SC_MOD()->GetAppOptions(); ! USHORT nMRUCount = rOpt.GetLRUFuncListCount(); ! const USHORT* pMRUList = rOpt.GetLRUFuncList(); ! const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); ! ULONG nListCount = pFuncList->GetCount(); ! if (pMRUList) ! { ! for (USHORT i=0; iGetFunction( j ); ! if ( pDesc->nFIndex == nId && pDesc->pFuncName ) ! { ! String aEntry = *pDesc->pFuncName; ! aEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" )); ! TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS ); ! if (!pFormulaData->Insert(pData)) ! delete pData; ! break; // nicht weitersuchen ! } ! } ! } ! } ! for(ULONG i=0;iGetFunction( i ); ! if ( pDesc->pFuncName ) ! { ! pDesc->InitArgumentInfo(); ! String aEntry = pDesc->GetSignature(); ! TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS ); ! if (!pFormulaDataPara->Insert(pData)) ! delete pData; ! } ! } pDoc->GetFormulaEntries( *pFormulaData ); + pDoc->GetFormulaEntries( *pFormulaDataPara ); } } *************** *** 582,587 **** --- 694,882 ---- } aManualTip.Erase(); } + void ScInputHandler::HideTipBelow() + { + if ( nTipVisibleSec ) + { + Help::HideTip( nTipVisibleSec ); + nTipVisibleSec = 0; + } + aManualTip.Erase(); + } + + void ScInputHandler::ShowTipCursor() + { + HideTip(); + HideTipBelow(); + EditView* pActiveView = pTopView ? pTopView : pTableView; + + if ( bFormulaMode && pActiveView && pFormulaDataPara && pEngine->GetParagraphCount() == 1 ) + { + String aFormula = pEngine->GetText( (USHORT) 0 ); + ESelection aSel = pActiveView->GetSelection(); + aSel.Adjust(); + xub_StrLen nLeftParentPos = 0; + if( aSel.nEndPos ) + { + if ( aFormula.Len() < aSel.nEndPos ) + return; + xub_StrLen nPos = aSel.nEndPos; + String aSelText = aFormula.Copy( 0, nPos ); + xub_StrLen nNextFStart = 0; + xub_StrLen nNextFEnd = 0; + xub_StrLen nArgPos = 0; + const ScFuncDesc* ppFDesc; + String** pppArgs; + USHORT nArgs; + BOOL bFound = FALSE; + + while( !bFound ) + { + aSelText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) ); + nLeftParentPos = lcl_MatchParenthesis( aSelText, aSelText.Len()-1 ); + if( nLeftParentPos != STRING_NOTFOUND ) + { + sal_Unicode c = aSelText.GetChar( nLeftParentPos-1 ); + if( !(c >= 'A' && c<= 'Z' || c>= 'a' && c<= 'z' ) ) + continue; + nNextFStart = ScFormulaUtil::GetFunctionStart( aSelText, nLeftParentPos, TRUE); + if( ScFormulaUtil::GetNextFunc( aSelText, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &pppArgs ) ) + { + if( ppFDesc->pFuncName ) + { + nArgPos = ScFormulaUtil::GetArgStart( aSelText, nNextFStart, 0 ); + nArgs = ppFDesc->nArgCount; + + USHORT nActive = 0; + USHORT nCount = 0; + USHORT nCountSemicolon = 0; + USHORT nCountDot = 0; + USHORT nStartPosition = 0; + USHORT nEndPosition = 0; + BOOL bFlag = FALSE; + String aNew; + USHORT nAutoPos = SCPOS_INVALID; + if( pFormulaDataPara->FindText( *(ppFDesc->pFuncName), aNew, nAutoPos, FALSE ) ) + { + for( USHORT i=0; i < nArgs; i++ ) + { + xub_StrLen nLength=(pppArgs[i])->Len(); + if( nArgPos <= aSelText.Len()-1 ) + { + nActive = i+1; + bFlag = TRUE; + } + nArgPos+=nLength+1; + } + if( bFlag ) + { + nCountSemicolon = aNew.GetTokenCount(';')-1; + nCountDot = aNew.GetTokenCount('.')-1; + + if( !nCountSemicolon ) + { + for( USHORT i = 0; i < aNew.Len(); i++ ) + { + sal_Unicode c = aNew.GetChar( i ); + if( c == '(' ) + { + nStartPosition = i+1; + } + } + } + else if( !nCountDot ) + { + for( USHORT i = 0; i < aNew.Len(); i++ ) + { + sal_Unicode c = aNew.GetChar( i ); + if( c == '(' ) + { + nStartPosition = i+1; + } + else if( c == ';' ) + { + nCount ++; + nEndPosition = i; + if( nCount == nActive ) + { + break; + } + nStartPosition = nEndPosition+1; + } + } + } + else + { + for( USHORT i = 0; i < aNew.Len(); i++ ) + { + sal_Unicode c = aNew.GetChar( i ); + if( c == '(' ) + { + nStartPosition = i+1; + } + else if( c == ';' ) + { + nCount ++; + nEndPosition = i; + if( nCount == nActive ) + { + break; + } + nStartPosition = nEndPosition+1; + } + else if( c == '.' ) + { + continue; + } + } + } + + if( nStartPosition ) + { + aNew.Insert( 0x25BA, nStartPosition ); + ShowTipBelow( aNew ); + bFound = TRUE; + } + } + else + { + ShowTipBelow( aNew ); + bFound = TRUE; + } + } + } + } + } + else + { + USHORT nPosition = 0; + String aText = pEngine->GetWord( 0, aSel.nEndPos-1 ); + if( aText.GetChar( aSel.nEndPos-1 ) == '=' ) + { + break; + } + String aNew; + USHORT nAutoPos = SCPOS_INVALID; + nPosition = aText.Len()+1; + if( pFormulaDataPara->FindText( aText, aNew, nAutoPos, FALSE ) ) + { + if( aFormula.GetChar( nPosition ) =='(' ) + { + ShowTipBelow( aNew ); + bFound = TRUE; + } + else + break; + } + else + { + break; + } + } + } + } + } + } void ScInputHandler::ShowTip( const String& rText ) { *************** *** 604,609 **** --- 899,927 ---- } } + void ScInputHandler::ShowTipBelow( const String& rText ) + { + HideTipBelow(); + + EditView* pActiveView = pTopView ? pTopView : pTableView; + if ( pActiveView ) + { + Point aPos; + Window* pWin = pActiveView->GetWindow(); + Cursor* pCur = pActiveView->GetCursor(); + if ( pCur ) + { + Point aLogicPos = pCur->GetPos(); + aLogicPos.Y() += pCur->GetHeight(); + aPos = pWin->LogicToPixel( aLogicPos ); + } + aPos = pWin->OutputToScreenPixel( aPos ); + Rectangle aRect( aPos, aPos ); + USHORT nAlign = QUICKHELP_LEFT | QUICKHELP_TOP; + nTipVisibleSec = Help::ShowTip(pWin, aRect, rText, nAlign); + } + } + void ScInputHandler::UseFormulaData() { EditView* pActiveView = pTopView ? pTopView : pTableView; *************** *** 624,646 **** // steht der Cursor am Ende eines Wortes? ! if ( aSel.nEndPos > 0 && ( ! aSel.nEndPos == aTotal.Len() || ! pEngine->GetWordDelimiters().Search( aTotal.GetChar(aSel.nEndPos) ) != STRING_NOTFOUND ) ) ! { ! String aText = pEngine->GetWord( 0, aSel.nEndPos-1 ); ! if (aText.Len()) ! { ! String aNew; ! nAutoPos = SCPOS_INVALID; // nix ! if ( pFormulaData->FindText( aText, aNew, nAutoPos, FALSE ) ) ! { ! ShowTip( aNew ); // als QuickHelp anzeigen ! aAutoSearch = aText; // zum Weitersuchen - nAutoPos ist gesetzt ! } ! } ! } ! } } void ScInputHandler::NextFormulaEntry( BOOL bBack ) --- 942,1092 ---- // steht der Cursor am Ende eines Wortes? ! if ( aSel.nEndPos > 0 ) ! { ! xub_StrLen nPos = aSel.nEndPos; ! String aFormula = aTotal.Copy( 0, nPos );; ! xub_StrLen nLeftParentPos = 0; ! xub_StrLen nNextFStart = 0; ! xub_StrLen nNextFEnd = 0; ! xub_StrLen nArgPos = 0; ! const ScFuncDesc* ppFDesc; ! String** pppArgs; ! USHORT nArgs; ! BOOL bFound = FALSE; ! ! String aText = pEngine->GetWord( 0, aSel.nEndPos-1 ); ! if ( aText.Len() ) ! { ! String aNew; ! nAutoPos = SCPOS_INVALID; ! if ( pFormulaData->FindText( aText, aNew, nAutoPos, FALSE ) ) ! { ! ShowTip( aNew ); ! aAutoSearch = aText; ! } ! } ! ! while( !bFound ) ! { ! aFormula.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) ); ! nLeftParentPos = lcl_MatchParenthesis( aFormula, aFormula.Len()-1 ); ! if( nLeftParentPos == STRING_NOTFOUND ) ! break; ! ! sal_Unicode c = aFormula.GetChar( nLeftParentPos-1 ); ! if( !(c >= 'A' && c<= 'Z' || c>= 'a' && c<= 'z' ) ) ! continue; ! nNextFStart = ScFormulaUtil::GetFunctionStart( aFormula, nLeftParentPos, TRUE); ! if( ScFormulaUtil::GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &pppArgs ) ) ! { ! if( ppFDesc->pFuncName ) ! { ! nArgPos = ScFormulaUtil::GetArgStart( aFormula, nNextFStart, 0 ); ! nArgs = ppFDesc->nArgCount; ! ! USHORT nActive = 0; ! USHORT nCount = 0; ! USHORT nCountSemicolon = 0; ! USHORT nCountDot = 0; ! USHORT nStartPosition = 0; ! USHORT nEndPosition = 0; ! BOOL bFlag = FALSE; ! String aNew; ! USHORT nAutoPos = SCPOS_INVALID; ! if( pFormulaDataPara->FindText( *(ppFDesc->pFuncName), aNew, nAutoPos, FALSE ) ) ! { ! for( USHORT i=0; i < nArgs; i++ ) ! { ! xub_StrLen nLength=(pppArgs[i])->Len(); ! if( nArgPos <= aFormula.Len()-1 ) ! { ! nActive = i+1; ! bFlag = TRUE; ! } ! nArgPos+=nLength+1; ! } ! if( bFlag ) ! { ! nCountSemicolon = aNew.GetTokenCount(';')-1; ! nCountDot = aNew.GetTokenCount('.')-1; ! ! if( !nCountSemicolon ) ! { ! for( USHORT i = 0; i < aNew.Len(); i++ ) ! { ! sal_Unicode c = aNew.GetChar( i ); ! if( c == '(' ) ! { ! nStartPosition = i+1; ! } ! } ! } ! else if( !nCountDot ) ! { ! for( USHORT i = 0; i < aNew.Len(); i++ ) ! { ! sal_Unicode c = aNew.GetChar( i ); ! if( c == '(' ) ! { ! nStartPosition = i+1; ! } ! else if( c == ';' ) ! { ! nCount ++; ! nEndPosition = i; ! if( nCount == nActive ) ! { ! break; ! } ! nStartPosition = nEndPosition+1; ! } ! } ! } ! else ! { ! for( USHORT i = 0; i < aNew.Len(); i++ ) ! { ! sal_Unicode c = aNew.GetChar( i ); ! if( c == '(' ) ! { ! nStartPosition = i+1; ! } ! else if( c == ';' ) ! { ! nCount ++; ! nEndPosition = i; ! if( nCount == nActive ) ! { ! break; ! } ! nStartPosition = nEndPosition+1; ! } ! else if( c == '.' ) ! { ! continue; ! } ! } ! } ! ! if( nStartPosition ) ! { ! aNew.Insert( 0x25BA, nStartPosition ); ! ShowTipBelow( aNew ); ! bFound = TRUE; ! } ! } ! else ! { ! ShowTipBelow( aNew ); ! bFound = TRUE; ! } ! } ! } ! } ! } ! } ! } } void ScInputHandler::NextFormulaEntry( BOOL bBack ) *************** *** 717,722 **** --- 1163,1169 ---- lcl_CompleteFunction( pTopView, aInsert, bParInserted ); lcl_CompleteFunction( pTableView, aInsert, bParInserted ); DataChanged(); + ShowTipCursor(); if (bParInserted) AutoParAdded(); *************** *** 1102,1199 **** // Klammern hervorheben // - xub_StrLen lcl_MatchParenthesis( const String& rStr, xub_StrLen nPos ) - { - int nDir; - sal_Unicode c1, c2 = 0; - c1 = rStr.GetChar( nPos ); - switch ( c1 ) - { - case '(' : - c2 = ')'; - nDir = 1; - break; - case ')' : - c2 = '('; - nDir = -1; - break; - case '<' : - c2 = '>'; - nDir = 1; - break; - case '>' : - c2 = '<'; - nDir = -1; - break; - case '{' : - c2 = '}'; - nDir = 1; - break; - case '}' : - c2 = '{'; - nDir = -1; - break; - case '[' : - c2 = ']'; - nDir = 1; - break; - case ']' : - c2 = '['; - nDir = -1; - break; - default: - nDir = 0; - } - if ( !nDir ) - return STRING_NOTFOUND; - xub_StrLen nLen = rStr.Len(); - const sal_Unicode* p0 = rStr.GetBuffer(); - register const sal_Unicode* p; - const sal_Unicode* p1; - USHORT nQuotes = 0; - if ( nPos < nLen / 2 ) - { - p = p0; - p1 = p0 + nPos; - } - else - { - p = p0 + nPos; - p1 = p0 + nLen; - } - while ( p < p1 ) - { - if ( *p++ == '\"' ) - nQuotes++; - } - // ungerade Anzahl Quotes: wir befinden uns in einem String - BOOL bLookInString = ((nQuotes % 2) != 0); - BOOL bInString = bLookInString; - p = p0 + nPos; - p1 = (nDir < 0 ? p0 : p0 + nLen) ; - USHORT nLevel = 1; - while ( p != p1 && nLevel ) - { - p += nDir; - if ( *p == '\"' ) - { - bInString = !bInString; - if ( bLookInString && !bInString ) - p = p1; // das war's dann - } - else if ( bInString == bLookInString ) - { - if ( *p == c1 ) - nLevel++; - else if ( *p == c2 ) - nLevel--; - } - } - if ( nLevel ) - return STRING_NOTFOUND; - return (xub_StrLen) (p - p0); - } - void ScInputHandler::UpdateParenthesis() { // Klammern suchen --- 1549,1554 ---- *************** *** 2682,2687 **** --- 3037,3047 ---- HideTip(); bUsed = TRUE; } + else if( nTipVisibleSec ) + { + HideTipBelow(); + bUsed = TRUE; + } else if (eMode != SC_INPUT_NONE) { CancelHandler(); *************** *** 2708,2713 **** --- 3068,3074 ---- ( eMode != SC_INPUT_NONE && ( bCursorKey || bInsKey ) ) ) ) { HideTip(); + HideTipBelow(); if (bSelIsRef) { *************** *** 2802,2808 **** // when the selection is changed manually or an opening parenthesis // is typed, stop overwriting parentheses ! if ( bUsed && ( nChar == '(' || bCursorKey ) ) ResetAutoPar(); if ( KEY_INSERT == nCode ) --- 3163,3169 ---- // when the selection is changed manually or an opening parenthesis // is typed, stop overwriting parentheses ! if ( bUsed && nChar == '(' ) ResetAutoPar(); if ( KEY_INSERT == nCode ) *************** *** 2811,2816 **** --- 3172,3181 ---- if (pViewFrm) pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT ); } + if( bUsed && bFormulaMode && ( bCursorKey || bInsKey || nCode == KEY_DELETE || nCode == KEY_BACKSPACE ) ) + { + ShowTipCursor(); + } } DataChanged(); // ruft auch UpdateParenthesis() *************** *** 2856,2861 **** --- 3221,3227 ---- } HideTip(); + HideTipBelow(); if ( bSelIsRef ) { *************** *** 3116,3121 **** --- 3482,3488 ---- } HideTip(); + HideTipBelow(); bInOwnChange = FALSE; } *************** *** 3174,3180 **** void ScInputHandler::InputSelection( EditView* pView ) { SyncViews( pView ); ! UpdateParenthesis(); // Selektion geaendert -> Klammer-Hervorhebung neu // when the selection is changed manually, stop overwriting parentheses --- 3541,3547 ---- void ScInputHandler::InputSelection( EditView* pView ) { SyncViews( pView ); ! ShowTipCursor(); UpdateParenthesis(); // Selektion geaendert -> Klammer-Hervorhebung neu // when the selection is changed manually, stop overwriting parentheses diff -cNr old/sc/source/ui/inc/inputhdl.hxx new/sc/source/ui/inc/inputhdl.hxx *** old/sc/source/ui/inc/inputhdl.hxx Tue Jan 17 17:02:48 2006 --- new/sc/source/ui/inc/inputhdl.hxx Wed Apr 9 15:07:38 2008 *************** *** 85,91 **** --- 85,93 ---- TypedStrCollection* pColumnData; TypedStrCollection* pFormulaData; + TypedStrCollection* pFormulaDataPara; ULONG nTipVisible; + ULONG nTipVisibleSec; String aManualTip; String aAutoSearch; USHORT nAutoPos; *************** *** 208,214 **** --- 210,219 ---- void ResetDelayTimer(); //BugId 54702 void HideTip(); + void HideTipBelow(); + void ShowTipCursor(); void ShowTip( const String& rText ); // am Cursor + void ShowTipBelow( const String& rText ); void SetRefScale( const Fraction& rX, const Fraction& rY ); void UpdateRefDevice();