1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //------------------------------------------------------------------ 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "scitems.hxx" 34*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <sfx2/app.hxx> 37*cdf0e10cSrcweir #include <editeng/acorrcfg.hxx> 38*cdf0e10cSrcweir #include <svx/algitem.hxx> 39*cdf0e10cSrcweir #include <editeng/adjitem.hxx> 40*cdf0e10cSrcweir #include <editeng/brshitem.hxx> 41*cdf0e10cSrcweir #include <svtools/colorcfg.hxx> 42*cdf0e10cSrcweir #include <editeng/colritem.hxx> 43*cdf0e10cSrcweir #include <editeng/editobj.hxx> 44*cdf0e10cSrcweir #include <editeng/editstat.hxx> 45*cdf0e10cSrcweir #include <editeng/editview.hxx> 46*cdf0e10cSrcweir #include <editeng/escpitem.hxx> 47*cdf0e10cSrcweir #include <editeng/forbiddencharacterstable.hxx> 48*cdf0e10cSrcweir #include <editeng/langitem.hxx> 49*cdf0e10cSrcweir #include <editeng/svxacorr.hxx> 50*cdf0e10cSrcweir #include <editeng/unolingu.hxx> 51*cdf0e10cSrcweir #include <editeng/wghtitem.hxx> 52*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 53*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 54*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 55*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 56*cdf0e10cSrcweir #include <sfx2/printer.hxx> 57*cdf0e10cSrcweir #include <svl/zforlist.hxx> 58*cdf0e10cSrcweir #include <vcl/sound.hxx> 59*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 60*cdf0e10cSrcweir #include <vcl/help.hxx> 61*cdf0e10cSrcweir #include <vcl/cursor.hxx> 62*cdf0e10cSrcweir #include <tools/urlobj.hxx> 63*cdf0e10cSrcweir #include <formula/formulahelper.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include "inputwin.hxx" 66*cdf0e10cSrcweir #include "tabvwsh.hxx" 67*cdf0e10cSrcweir #include "docsh.hxx" 68*cdf0e10cSrcweir #include "scmod.hxx" 69*cdf0e10cSrcweir #include "uiitems.hxx" 70*cdf0e10cSrcweir #include "global.hxx" 71*cdf0e10cSrcweir #include "sc.hrc" 72*cdf0e10cSrcweir #include "globstr.hrc" 73*cdf0e10cSrcweir #include "patattr.hxx" 74*cdf0e10cSrcweir #include "viewdata.hxx" 75*cdf0e10cSrcweir #include "document.hxx" 76*cdf0e10cSrcweir #include "docpool.hxx" 77*cdf0e10cSrcweir #include "editutil.hxx" 78*cdf0e10cSrcweir #include "collect.hxx" 79*cdf0e10cSrcweir #include "appoptio.hxx" 80*cdf0e10cSrcweir #include "docoptio.hxx" 81*cdf0e10cSrcweir #include "validat.hxx" 82*cdf0e10cSrcweir #include "userlist.hxx" 83*cdf0e10cSrcweir #include "rfindlst.hxx" 84*cdf0e10cSrcweir #include "inputopt.hxx" 85*cdf0e10cSrcweir #include "cell.hxx" // fuer Formel-Preview 86*cdf0e10cSrcweir #include "compiler.hxx" // fuer Formel-Preview 87*cdf0e10cSrcweir #include "editable.hxx" 88*cdf0e10cSrcweir #include "funcdesc.hxx" 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #define _INPUTHDL_CXX 91*cdf0e10cSrcweir #include "inputhdl.hxx" 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // max. Ranges im RangeFinder 94*cdf0e10cSrcweir #define RANGEFIND_MAX 32 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir using namespace formula; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // STATIC DATA ----------------------------------------------------------- 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir sal_Bool ScInputHandler::bOptLoaded = sal_False; // App-Optionen ausgewertet 101*cdf0e10cSrcweir sal_Bool ScInputHandler::bAutoComplete = sal_False; // wird in KeyInput gesetzt 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // delimiters (in addition to ScEditUtil) needed for range finder: 104*cdf0e10cSrcweir // only characters that are allowed in formulas next to references 105*cdf0e10cSrcweir // and the quotation mark (so string constants can be skipped) 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir static const sal_Char __FAR_DATA pMinDelimiters[] = " !\""; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir extern sal_uInt16 nEditAdjust; //! Member an ViewData 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir //================================================================== 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir static sal_Unicode lcl_getSheetSeparator(ScDocument* pDoc) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir ScCompiler aComp(pDoc, ScAddress()); 116*cdf0e10cSrcweir aComp.SetGrammar(pDoc->GetGrammar()); 117*cdf0e10cSrcweir return aComp.GetNativeAddressSymbol(ScCompiler::Convention::SHEET_SEPARATOR); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void ScInputHandler::InitRangeFinder( const String& rFormula ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir DeleteRangeFinder(); 123*cdf0e10cSrcweir ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell(); 124*cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 125*cdf0e10cSrcweir const sal_Unicode cSheetSep = lcl_getSheetSeparator(pDoc); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if ( !pActiveViewSh || !SC_MOD()->GetInputOptions().GetRangeFinder() ) 128*cdf0e10cSrcweir return; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // String aDelimiters = pEngine->GetWordDelimiters(); 131*cdf0e10cSrcweir String aDelimiters = ScEditUtil::ModifyDelimiters( 132*cdf0e10cSrcweir String::CreateFromAscii( pMinDelimiters ) ); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir xub_StrLen nColon = aDelimiters.Search(':'); 135*cdf0e10cSrcweir if ( nColon != STRING_NOTFOUND ) 136*cdf0e10cSrcweir aDelimiters.Erase( nColon, 1 ); // Delimiter ohne Doppelpunkt 137*cdf0e10cSrcweir xub_StrLen nDot = aDelimiters.Search(cSheetSep); 138*cdf0e10cSrcweir if ( nDot != STRING_NOTFOUND ) 139*cdf0e10cSrcweir aDelimiters.Erase( nDot, 1 ); // Delimiter ohne Punkt 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir const sal_Unicode* pChar = rFormula.GetBuffer(); 142*cdf0e10cSrcweir xub_StrLen nLen = rFormula.Len(); 143*cdf0e10cSrcweir xub_StrLen nPos = 0; 144*cdf0e10cSrcweir xub_StrLen nStart = 0; 145*cdf0e10cSrcweir sal_uInt16 nCount = 0; 146*cdf0e10cSrcweir ScRange aRange; 147*cdf0e10cSrcweir while ( nPos < nLen && nCount < RANGEFIND_MAX ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir // Trenner ueberlesen 150*cdf0e10cSrcweir while ( nPos<nLen && ScGlobal::UnicodeStrChr( aDelimiters.GetBuffer(), pChar[nPos] ) ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir if ( pChar[nPos] == '"' ) // String 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir ++nPos; 155*cdf0e10cSrcweir while (nPos<nLen && pChar[nPos] != '"') // bis zum Ende ueberlesen 156*cdf0e10cSrcweir ++nPos; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir ++nPos; // Trennzeichen oder schliessender Quote 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // Text zwischen Trennern 162*cdf0e10cSrcweir nStart = nPos; 163*cdf0e10cSrcweir handle_r1c1: 164*cdf0e10cSrcweir while ( nPos<nLen && !ScGlobal::UnicodeStrChr( aDelimiters.GetBuffer(), pChar[nPos] ) ) 165*cdf0e10cSrcweir ++nPos; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // for R1C1 '-' in R[-]... or C[-]... are not delimiters 168*cdf0e10cSrcweir // Nothing heroic here to ensure that there are '[]' around a negative 169*cdf0e10cSrcweir // integer. we need to clean up this code. 170*cdf0e10cSrcweir if( nPos < nLen && nPos > 0 && 171*cdf0e10cSrcweir '-' == pChar[nPos] && '[' == pChar[nPos-1] && 172*cdf0e10cSrcweir NULL != pDoc && 173*cdf0e10cSrcweir formula::FormulaGrammar::CONV_XL_R1C1 == pDoc->GetAddressConvention() ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir nPos++; 176*cdf0e10cSrcweir goto handle_r1c1; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if ( nPos > nStart ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir String aTest = rFormula.Copy( nStart, nPos-nStart ); 182*cdf0e10cSrcweir const ScAddress::Details aAddrDetails( pDoc, aCursorPos ); 183*cdf0e10cSrcweir sal_uInt16 nFlags = aRange.ParseAny( aTest, pDoc, aAddrDetails ); 184*cdf0e10cSrcweir if ( nFlags & SCA_VALID ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir // Tabelle setzen, wenn nicht angegeben 187*cdf0e10cSrcweir if ( (nFlags & SCA_TAB_3D) == 0 ) 188*cdf0e10cSrcweir aRange.aStart.SetTab( pActiveViewSh->GetViewData()->GetTabNo() ); 189*cdf0e10cSrcweir if ( (nFlags & SCA_TAB2_3D) == 0 ) 190*cdf0e10cSrcweir aRange.aEnd.SetTab( aRange.aStart.Tab() ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( ( nFlags & ( SCA_VALID_COL2 | SCA_VALID_ROW2 | SCA_VALID_TAB2 ) ) == 0 ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir // #i73766# if a single ref was parsed, set the same "abs" flags for ref2, 195*cdf0e10cSrcweir // so Format doesn't output a double ref because of different flags. 196*cdf0e10cSrcweir sal_uInt16 nAbsFlags = nFlags & ( SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE ); 197*cdf0e10cSrcweir nFlags |= nAbsFlags << 4; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir if (!nCount) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir pEngine->SetUpdateMode( sal_False ); 203*cdf0e10cSrcweir pRangeFindList = new ScRangeFindList( pDocSh->GetTitle() ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir ScRangeFindData* pNew = new ScRangeFindData( aRange, nFlags, nStart, nPos ); 207*cdf0e10cSrcweir pRangeFindList->Insert( pNew ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir ESelection aSel( 0, nStart, 0, nPos ); 210*cdf0e10cSrcweir SfxItemSet aSet( pEngine->GetEmptyItemSet() ); 211*cdf0e10cSrcweir aSet.Put( SvxColorItem( Color( ScRangeFindList::GetColorName( nCount ) ), 212*cdf0e10cSrcweir EE_CHAR_COLOR ) ); 213*cdf0e10cSrcweir pEngine->QuickSetAttribs( aSet, aSel ); 214*cdf0e10cSrcweir ++nCount; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir // letzten Trenner nicht ueberlesen, koennte ja ein Quote sein (?) 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if (nCount) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir pEngine->SetUpdateMode( sal_True ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir pDocSh->Broadcast( SfxSimpleHint( SC_HINT_SHOWRANGEFINDER ) ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir void lcl_Replace( EditView* pView, const String& rNewStr, const ESelection& rOldSel ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir if ( pView ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir ESelection aOldSel = pView->GetSelection(); 234*cdf0e10cSrcweir if (aOldSel.HasRange()) 235*cdf0e10cSrcweir pView->SetSelection( ESelection( aOldSel.nEndPara, aOldSel.nEndPos, 236*cdf0e10cSrcweir aOldSel.nEndPara, aOldSel.nEndPos ) ); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir EditEngine* pEngine = pView->GetEditEngine(); 239*cdf0e10cSrcweir pEngine->QuickInsertText( rNewStr, rOldSel ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // Dummy-InsertText fuer Update und Paint 242*cdf0e10cSrcweir // dafuer muss oben die Selektion aufgehoben werden (vor QuickInsertText) 243*cdf0e10cSrcweir pView->InsertText( EMPTY_STRING, sal_False ); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir xub_StrLen nLen = pEngine->GetTextLen(0); 246*cdf0e10cSrcweir ESelection aSel( 0, nLen, 0, nLen ); 247*cdf0e10cSrcweir pView->SetSelection( aSel ); // Cursor ans Ende 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void ScInputHandler::UpdateRange( sal_uInt16 nIndex, const ScRange& rNew ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir ScTabViewShell* pDocView = pRefViewSh ? pRefViewSh : pActiveViewSh; 254*cdf0e10cSrcweir if ( pDocView && pRangeFindList && nIndex < pRangeFindList->Count() ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir ScRangeFindData* pData = pRangeFindList->GetObject( nIndex ); 257*cdf0e10cSrcweir xub_StrLen nOldStart = pData->nSelStart; 258*cdf0e10cSrcweir xub_StrLen nOldEnd = pData->nSelEnd; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir ScRange aJustified = rNew; 261*cdf0e10cSrcweir aJustified.Justify(); // Ref in der Formel immer richtigherum anzeigen 262*cdf0e10cSrcweir String aNewStr; 263*cdf0e10cSrcweir ScDocument* pDoc = pDocView->GetViewData()->GetDocument(); 264*cdf0e10cSrcweir const ScAddress::Details aAddrDetails( pDoc, aCursorPos ); 265*cdf0e10cSrcweir aJustified.Format( aNewStr, pData->nFlags, pDoc, aAddrDetails ); 266*cdf0e10cSrcweir ESelection aOldSel( 0, nOldStart, 0, nOldEnd ); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir DataChanging(); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir lcl_Replace( pTopView, aNewStr, aOldSel ); 271*cdf0e10cSrcweir lcl_Replace( pTableView, aNewStr, aOldSel ); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir bInRangeUpdate = sal_True; 274*cdf0e10cSrcweir DataChanged(); 275*cdf0e10cSrcweir bInRangeUpdate = sal_False; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir long nDiff = aNewStr.Len() - (long)(nOldEnd-nOldStart); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir pData->aRef = rNew; 280*cdf0e10cSrcweir pData->nSelEnd = (xub_StrLen)(pData->nSelEnd + nDiff); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16) pRangeFindList->Count(); 283*cdf0e10cSrcweir for (sal_uInt16 i=nIndex+1; i<nCount; i++) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir ScRangeFindData* pNext = pRangeFindList->GetObject( i ); 286*cdf0e10cSrcweir pNext->nSelStart = (xub_StrLen)(pNext->nSelStart + nDiff); 287*cdf0e10cSrcweir pNext->nSelEnd = (xub_StrLen)(pNext->nSelEnd + nDiff); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir else 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir DBG_ERROR("UpdateRange: da fehlt was"); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir void ScInputHandler::DeleteRangeFinder() 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir ScTabViewShell* pPaintView = pRefViewSh ? pRefViewSh : pActiveViewSh; 299*cdf0e10cSrcweir if ( pRangeFindList && pPaintView ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell(); 302*cdf0e10cSrcweir pRangeFindList->SetHidden(sal_True); 303*cdf0e10cSrcweir pDocSh->Broadcast( SfxSimpleHint( SC_HINT_SHOWRANGEFINDER ) ); // wegnehmen 304*cdf0e10cSrcweir DELETEZ(pRangeFindList); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir //================================================================== 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir inline String GetEditText(EditEngine* pEng) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir return ScEditUtil::GetSpaceDelimitedString(*pEng); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir void lcl_RemoveTabs(String& rStr) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir xub_StrLen nPos; 318*cdf0e10cSrcweir while ( (nPos=rStr.Search('\t')) != STRING_NOTFOUND ) 319*cdf0e10cSrcweir rStr.SetChar( nPos, ' ' ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir void lcl_RemoveLineEnd(String& rStr) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir rStr.ConvertLineEnd(LINEEND_LF); 325*cdf0e10cSrcweir xub_StrLen nPos; 326*cdf0e10cSrcweir while ( (nPos=rStr.Search('\n')) != STRING_NOTFOUND ) 327*cdf0e10cSrcweir rStr.SetChar( nPos, ' ' ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir xub_StrLen lcl_MatchParenthesis( const String& rStr, xub_StrLen nPos ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir int nDir; 333*cdf0e10cSrcweir sal_Unicode c1, c2 = 0; 334*cdf0e10cSrcweir c1 = rStr.GetChar( nPos ); 335*cdf0e10cSrcweir switch ( c1 ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir case '(' : 338*cdf0e10cSrcweir c2 = ')'; 339*cdf0e10cSrcweir nDir = 1; 340*cdf0e10cSrcweir break; 341*cdf0e10cSrcweir case ')' : 342*cdf0e10cSrcweir c2 = '('; 343*cdf0e10cSrcweir nDir = -1; 344*cdf0e10cSrcweir break; 345*cdf0e10cSrcweir case '<' : 346*cdf0e10cSrcweir c2 = '>'; 347*cdf0e10cSrcweir nDir = 1; 348*cdf0e10cSrcweir break; 349*cdf0e10cSrcweir case '>' : 350*cdf0e10cSrcweir c2 = '<'; 351*cdf0e10cSrcweir nDir = -1; 352*cdf0e10cSrcweir break; 353*cdf0e10cSrcweir case '{' : 354*cdf0e10cSrcweir c2 = '}'; 355*cdf0e10cSrcweir nDir = 1; 356*cdf0e10cSrcweir break; 357*cdf0e10cSrcweir case '}' : 358*cdf0e10cSrcweir c2 = '{'; 359*cdf0e10cSrcweir nDir = -1; 360*cdf0e10cSrcweir break; 361*cdf0e10cSrcweir case '[' : 362*cdf0e10cSrcweir c2 = ']'; 363*cdf0e10cSrcweir nDir = 1; 364*cdf0e10cSrcweir break; 365*cdf0e10cSrcweir case ']' : 366*cdf0e10cSrcweir c2 = '['; 367*cdf0e10cSrcweir nDir = -1; 368*cdf0e10cSrcweir break; 369*cdf0e10cSrcweir default: 370*cdf0e10cSrcweir nDir = 0; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir if ( !nDir ) 373*cdf0e10cSrcweir return STRING_NOTFOUND; 374*cdf0e10cSrcweir xub_StrLen nLen = rStr.Len(); 375*cdf0e10cSrcweir const sal_Unicode* p0 = rStr.GetBuffer(); 376*cdf0e10cSrcweir register const sal_Unicode* p; 377*cdf0e10cSrcweir const sal_Unicode* p1; 378*cdf0e10cSrcweir sal_uInt16 nQuotes = 0; 379*cdf0e10cSrcweir if ( nPos < nLen / 2 ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir p = p0; 382*cdf0e10cSrcweir p1 = p0 + nPos; 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir else 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir p = p0 + nPos; 387*cdf0e10cSrcweir p1 = p0 + nLen; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir while ( p < p1 ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir if ( *p++ == '\"' ) 392*cdf0e10cSrcweir nQuotes++; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir // Odd number of quotes that we find ourselves in a string 395*cdf0e10cSrcweir sal_Bool bLookInString = ((nQuotes % 2) != 0); 396*cdf0e10cSrcweir sal_Bool bInString = bLookInString; 397*cdf0e10cSrcweir p = p0 + nPos; 398*cdf0e10cSrcweir p1 = (nDir < 0 ? p0 : p0 + nLen) ; 399*cdf0e10cSrcweir sal_uInt16 nLevel = 1; 400*cdf0e10cSrcweir while ( p != p1 && nLevel ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir p += nDir; 403*cdf0e10cSrcweir if ( *p == '\"' ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir bInString = !bInString; 406*cdf0e10cSrcweir if ( bLookInString && !bInString ) 407*cdf0e10cSrcweir p = p1; //That's it then 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir else if ( bInString == bLookInString ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir if ( *p == c1 ) 412*cdf0e10cSrcweir nLevel++; 413*cdf0e10cSrcweir else if ( *p == c2 ) 414*cdf0e10cSrcweir nLevel--; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir if ( nLevel ) 418*cdf0e10cSrcweir return STRING_NOTFOUND; 419*cdf0e10cSrcweir return (xub_StrLen) (p - p0); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir //================================================================== 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir ScInputHandler::ScInputHandler() 425*cdf0e10cSrcweir : pInputWin( NULL ), 426*cdf0e10cSrcweir pEngine( NULL ), 427*cdf0e10cSrcweir pTableView( NULL ), 428*cdf0e10cSrcweir pTopView( NULL ), 429*cdf0e10cSrcweir pColumnData( NULL ), 430*cdf0e10cSrcweir pFormulaData( NULL ), 431*cdf0e10cSrcweir pFormulaDataPara( NULL ), 432*cdf0e10cSrcweir pTipVisibleParent( NULL ), 433*cdf0e10cSrcweir nTipVisible( 0 ), 434*cdf0e10cSrcweir pTipVisibleSecParent( NULL ), 435*cdf0e10cSrcweir nTipVisibleSec( 0 ), 436*cdf0e10cSrcweir nAutoPos( SCPOS_INVALID ), 437*cdf0e10cSrcweir bUseTab( sal_False ), 438*cdf0e10cSrcweir bTextValid( sal_True ), 439*cdf0e10cSrcweir nFormSelStart( 0 ), 440*cdf0e10cSrcweir nFormSelEnd( 0 ), 441*cdf0e10cSrcweir nAutoPar( 0 ), 442*cdf0e10cSrcweir eMode( SC_INPUT_NONE ), 443*cdf0e10cSrcweir bModified( sal_False ), 444*cdf0e10cSrcweir bSelIsRef( sal_False ), 445*cdf0e10cSrcweir bFormulaMode( sal_False ), 446*cdf0e10cSrcweir bInRangeUpdate( sal_False ), 447*cdf0e10cSrcweir bParenthesisShown( sal_False ), 448*cdf0e10cSrcweir bCreatingFuncView( sal_False ), 449*cdf0e10cSrcweir bInEnterHandler( sal_False ), 450*cdf0e10cSrcweir bCommandErrorShown( sal_False ), 451*cdf0e10cSrcweir bInOwnChange( sal_False ), 452*cdf0e10cSrcweir bProtected( sal_False ), 453*cdf0e10cSrcweir bCellHasPercentFormat( sal_False ), 454*cdf0e10cSrcweir nValidation( 0 ), 455*cdf0e10cSrcweir eAttrAdjust( SVX_HOR_JUSTIFY_STANDARD ), 456*cdf0e10cSrcweir aScaleX( 1,1 ), 457*cdf0e10cSrcweir aScaleY( 1,1 ), 458*cdf0e10cSrcweir pRefViewSh( NULL ), 459*cdf0e10cSrcweir pLastPattern( NULL ), 460*cdf0e10cSrcweir pEditDefaults( NULL ), 461*cdf0e10cSrcweir bLastIsSymbol( sal_False ), 462*cdf0e10cSrcweir pLastState( NULL ), 463*cdf0e10cSrcweir pDelayTimer( NULL ), 464*cdf0e10cSrcweir pRangeFindList( NULL ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir // The InputHandler is constructed with the view, so SfxViewShell::Current 467*cdf0e10cSrcweir // doesn't have the right view yet. pActiveViewSh is updated in NotifyChange. 468*cdf0e10cSrcweir pActiveViewSh = NULL; 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir // Bindings (nur noch fuer Invalidate benutzt) werden bei Bedarf aktuell geholt 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir __EXPORT ScInputHandler::~ScInputHandler() 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // Wenn dies der Applikations-InputHandler ist, wird der dtor erst nach SfxApplication::Main 476*cdf0e10cSrcweir // gerufen, darf sich also auf keine Sfx-Funktionen mehr verlassen 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir if ( !SFX_APP()->IsDowning() ) // inplace 479*cdf0e10cSrcweir EnterHandler(); // Eingabe noch abschliessen 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir if (SC_MOD()->GetRefInputHdl()==this) 482*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(NULL); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir if ( pInputWin && pInputWin->GetInputHandler() == this ) 485*cdf0e10cSrcweir pInputWin->SetInputHandler( NULL ); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir delete pRangeFindList; 488*cdf0e10cSrcweir delete pEditDefaults; 489*cdf0e10cSrcweir delete pEngine; 490*cdf0e10cSrcweir delete pLastState; 491*cdf0e10cSrcweir delete pDelayTimer; 492*cdf0e10cSrcweir delete pColumnData; 493*cdf0e10cSrcweir delete pFormulaData; 494*cdf0e10cSrcweir delete pFormulaDataPara; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir void ScInputHandler::SetRefScale( const Fraction& rX, const Fraction& rY ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir if ( rX != aScaleX || rY != aScaleY ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir aScaleX = rX; 502*cdf0e10cSrcweir aScaleY = rY; 503*cdf0e10cSrcweir if (pEngine) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir MapMode aMode( MAP_100TH_MM, Point(), aScaleX, aScaleY ); 506*cdf0e10cSrcweir pEngine->SetRefMapMode( aMode ); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir void ScInputHandler::UpdateRefDevice() 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir if (!pEngine) 514*cdf0e10cSrcweir return; 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir sal_Bool bTextWysiwyg = SC_MOD()->GetInputOptions().GetTextWysiwyg(); 517*cdf0e10cSrcweir bool bInPlace = pActiveViewSh && pActiveViewSh->GetViewFrame()->GetFrame().IsInPlace(); 518*cdf0e10cSrcweir sal_uInt32 nCtrl = pEngine->GetControlWord(); 519*cdf0e10cSrcweir if ( bTextWysiwyg || bInPlace ) 520*cdf0e10cSrcweir nCtrl |= EE_CNTRL_FORMAT100; // EditEngine default: always format for 100% 521*cdf0e10cSrcweir else 522*cdf0e10cSrcweir nCtrl &= ~EE_CNTRL_FORMAT100; // when formatting for screen, use the actual MapMode 523*cdf0e10cSrcweir pEngine->SetControlWord( nCtrl ); 524*cdf0e10cSrcweir if ( bTextWysiwyg && pActiveViewSh ) 525*cdf0e10cSrcweir pEngine->SetRefDevice( pActiveViewSh->GetViewData()->GetDocument()->GetPrinter() ); 526*cdf0e10cSrcweir else 527*cdf0e10cSrcweir pEngine->SetRefDevice( NULL ); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir MapMode aMode( MAP_100TH_MM, Point(), aScaleX, aScaleY ); 530*cdf0e10cSrcweir pEngine->SetRefMapMode( aMode ); 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir // SetRefDevice(NULL) uses VirtualDevice, SetRefMapMode forces creation of a local VDev, 533*cdf0e10cSrcweir // so the DigitLanguage can be safely modified (might use an own VDev instead of NULL). 534*cdf0e10cSrcweir if ( !( bTextWysiwyg && pActiveViewSh ) ) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir pEngine->GetRefDevice()->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() ); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir void ScInputHandler::ImplCreateEditEngine() 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir if ( !pEngine ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir if ( pActiveViewSh ) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir const ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 547*cdf0e10cSrcweir pEngine = new ScFieldEditEngine( pDoc->GetEnginePool(), pDoc->GetEditPool() ); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir else 550*cdf0e10cSrcweir pEngine = new ScFieldEditEngine( EditEngine::CreatePool(), NULL, sal_True ); 551*cdf0e10cSrcweir pEngine->SetWordDelimiters( ScEditUtil::ModifyDelimiters( pEngine->GetWordDelimiters() ) ); 552*cdf0e10cSrcweir UpdateRefDevice(); // also sets MapMode 553*cdf0e10cSrcweir pEngine->SetPaperSize( Size( 1000000, 1000000 ) ); 554*cdf0e10cSrcweir pEditDefaults = new SfxItemSet( pEngine->GetEmptyItemSet() ); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir pEngine->SetControlWord( pEngine->GetControlWord() | EE_CNTRL_AUTOCORRECT ); 557*cdf0e10cSrcweir pEngine->SetModifyHdl( LINK( this, ScInputHandler, ModifyHdl ) ); 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir void ScInputHandler::UpdateAutoCorrFlag() 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir sal_uLong nCntrl = pEngine->GetControlWord(); 564*cdf0e10cSrcweir sal_uLong nOld = nCntrl; 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir // don't use pLastPattern here (may be invalid because of AutoStyle) 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir sal_Bool bDisable = bLastIsSymbol || bFormulaMode; 569*cdf0e10cSrcweir if ( bDisable ) 570*cdf0e10cSrcweir nCntrl &= ~EE_CNTRL_AUTOCORRECT; 571*cdf0e10cSrcweir else 572*cdf0e10cSrcweir nCntrl |= EE_CNTRL_AUTOCORRECT; 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir if ( nCntrl != nOld ) 575*cdf0e10cSrcweir pEngine->SetControlWord(nCntrl); 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir 578*cdf0e10cSrcweir void ScInputHandler::UpdateSpellSettings( sal_Bool bFromStartTab ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir if ( pActiveViewSh ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir ScViewData* pViewData = pActiveViewSh->GetViewData(); 583*cdf0e10cSrcweir sal_Bool bOnlineSpell = pViewData->GetDocument()->GetDocOptions().IsAutoSpell(); 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir // SetDefaultLanguage is independent of the language attributes, 586*cdf0e10cSrcweir // ScGlobal::GetEditDefaultLanguage is always used. 587*cdf0e10cSrcweir // It must be set every time in case the office language was changed. 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir pEngine->SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() ); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir // if called for changed options, update flags only if already editing 592*cdf0e10cSrcweir // if called from StartTable, always update flags 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir if ( bFromStartTab || eMode != SC_INPUT_NONE ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir sal_uLong nCntrl = pEngine->GetControlWord(); 597*cdf0e10cSrcweir sal_uLong nOld = nCntrl; 598*cdf0e10cSrcweir if( bOnlineSpell ) 599*cdf0e10cSrcweir nCntrl |= EE_CNTRL_ONLINESPELLING; 600*cdf0e10cSrcweir else 601*cdf0e10cSrcweir nCntrl &= ~EE_CNTRL_ONLINESPELLING; 602*cdf0e10cSrcweir // kein AutoCorrect auf Symbol-Font (EditEngine wertet Default nicht aus) 603*cdf0e10cSrcweir if ( pLastPattern && pLastPattern->IsSymbolFont() ) 604*cdf0e10cSrcweir nCntrl &= ~EE_CNTRL_AUTOCORRECT; 605*cdf0e10cSrcweir else 606*cdf0e10cSrcweir nCntrl |= EE_CNTRL_AUTOCORRECT; 607*cdf0e10cSrcweir if ( nCntrl != nOld ) 608*cdf0e10cSrcweir pEngine->SetControlWord(nCntrl); 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir ScDocument* pDoc = pViewData->GetDocument(); 611*cdf0e10cSrcweir pDoc->ApplyAsianEditSettings( *pEngine ); 612*cdf0e10cSrcweir pEngine->SetDefaultHorizontalTextDirection( 613*cdf0e10cSrcweir (EEHorizontalTextDirection)pDoc->GetEditTextDirection( pViewData->GetTabNo() ) ); 614*cdf0e10cSrcweir pEngine->SetFirstWordCapitalization( sal_False ); 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir // language is set separately, so the speller is needed only if online 618*cdf0e10cSrcweir // spelling is active 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir if ( bOnlineSpell ) { 621*cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1> xXSpellChecker1( LinguMgr::GetSpellChecker() ); 622*cdf0e10cSrcweir pEngine->SetSpeller( xXSpellChecker1 ); 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir sal_Bool bHyphen = pLastPattern && ((const SfxBoolItem&)pLastPattern->GetItem(ATTR_HYPHENATE)).GetValue(); 626*cdf0e10cSrcweir if ( bHyphen ) { 627*cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::linguistic2::XHyphenator> xXHyphenator( LinguMgr::GetHyphenator() ); 628*cdf0e10cSrcweir pEngine->SetHyphenator( xXHyphenator ); 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir // 634*cdf0e10cSrcweir // Funktionen/Bereichsnamen etc. als Tip-Hilfe 635*cdf0e10cSrcweir // 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir #define SC_STRTYPE_FUNCTIONS 1 638*cdf0e10cSrcweir // die anderen Typen sind in ScDocument::GetFormulaEntries festgelegt 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir void ScInputHandler::GetFormulaData() 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir if ( pActiveViewSh ) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir if ( pFormulaData ) 647*cdf0e10cSrcweir pFormulaData->FreeAll(); 648*cdf0e10cSrcweir else 649*cdf0e10cSrcweir pFormulaData = new TypedScStrCollection; 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir if( pFormulaDataPara ) 652*cdf0e10cSrcweir pFormulaDataPara->FreeAll(); 653*cdf0e10cSrcweir else 654*cdf0e10cSrcweir pFormulaDataPara = new TypedScStrCollection; 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir // MRU-Funktionen aus dem Funktions-Autopiloten 657*cdf0e10cSrcweir // wie in ScPosWnd::FillFunctions (inputwin.cxx) 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir const ScAppOptions& rOpt = SC_MOD()->GetAppOptions(); 660*cdf0e10cSrcweir sal_uInt16 nMRUCount = rOpt.GetLRUFuncListCount(); 661*cdf0e10cSrcweir const sal_uInt16* pMRUList = rOpt.GetLRUFuncList(); 662*cdf0e10cSrcweir const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); 663*cdf0e10cSrcweir sal_uLong nListCount = pFuncList->GetCount(); 664*cdf0e10cSrcweir if (pMRUList) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nMRUCount; i++) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir sal_uInt16 nId = pMRUList[i]; 669*cdf0e10cSrcweir for (sal_uLong j=0; j<nListCount; j++) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir const ScFuncDesc* pDesc = pFuncList->GetFunction( j ); 672*cdf0e10cSrcweir if ( pDesc->nFIndex == nId && pDesc->pFuncName ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir String aEntry = *pDesc->pFuncName; 675*cdf0e10cSrcweir aEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" )); 676*cdf0e10cSrcweir TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS ); 677*cdf0e10cSrcweir if (!pFormulaData->Insert(pData)) 678*cdf0e10cSrcweir delete pData; 679*cdf0e10cSrcweir break; // nicht weitersuchen 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir for(sal_uLong i=0;i<nListCount;i++) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir const ScFuncDesc* pDesc = pFuncList->GetFunction( i ); 687*cdf0e10cSrcweir if ( pDesc->pFuncName ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir pDesc->initArgumentInfo(); 690*cdf0e10cSrcweir String aEntry = pDesc->GetSignature(); 691*cdf0e10cSrcweir TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS ); 692*cdf0e10cSrcweir if (!pFormulaDataPara->Insert(pData)) 693*cdf0e10cSrcweir delete pData; 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir pDoc->GetFormulaEntries( *pFormulaData ); 697*cdf0e10cSrcweir pDoc->GetFormulaEntries( *pFormulaDataPara ); 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir IMPL_LINK( ScInputHandler, ShowHideTipVisibleParentListener, VclWindowEvent*, pEvent ) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir if( pEvent->GetId() == VCLEVENT_OBJECT_DYING || pEvent->GetId() == VCLEVENT_WINDOW_HIDE ) 704*cdf0e10cSrcweir HideTip(); 705*cdf0e10cSrcweir return 0; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir IMPL_LINK( ScInputHandler, ShowHideTipVisibleSecParentListener, VclWindowEvent*, pEvent ) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir if( pEvent->GetId() == VCLEVENT_OBJECT_DYING || pEvent->GetId() == VCLEVENT_WINDOW_HIDE ) 711*cdf0e10cSrcweir HideTipBelow(); 712*cdf0e10cSrcweir return 0; 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir void ScInputHandler::HideTip() 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir if ( nTipVisible ) 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir if (pTipVisibleParent) 720*cdf0e10cSrcweir pTipVisibleParent->RemoveEventListener( LINK( this, ScInputHandler, ShowHideTipVisibleParentListener ) ); 721*cdf0e10cSrcweir Help::HideTip( nTipVisible ); 722*cdf0e10cSrcweir nTipVisible = 0; 723*cdf0e10cSrcweir pTipVisibleParent = NULL; 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir aManualTip.Erase(); 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir void ScInputHandler::HideTipBelow() 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir if ( nTipVisibleSec ) 730*cdf0e10cSrcweir { 731*cdf0e10cSrcweir if (pTipVisibleSecParent) 732*cdf0e10cSrcweir pTipVisibleSecParent->RemoveEventListener( LINK( this, ScInputHandler, ShowHideTipVisibleSecParentListener ) ); 733*cdf0e10cSrcweir Help::HideTip( nTipVisibleSec ); 734*cdf0e10cSrcweir nTipVisibleSec = 0; 735*cdf0e10cSrcweir pTipVisibleSecParent = NULL; 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir aManualTip.Erase(); 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir void ScInputHandler::ShowTipCursor() 741*cdf0e10cSrcweir { 742*cdf0e10cSrcweir HideTip(); 743*cdf0e10cSrcweir HideTipBelow(); 744*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 745*cdf0e10cSrcweir ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell(); 746*cdf0e10cSrcweir const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0); 747*cdf0e10cSrcweir const sal_Unicode cSheetSep = lcl_getSheetSeparator(pDocSh->GetDocument()); 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir if ( bFormulaMode && pActiveView && pFormulaDataPara && pEngine->GetParagraphCount() == 1 ) 750*cdf0e10cSrcweir { 751*cdf0e10cSrcweir String aFormula = pEngine->GetText( (sal_uInt16) 0 ); 752*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 753*cdf0e10cSrcweir aSel.Adjust(); 754*cdf0e10cSrcweir xub_StrLen nLeftParentPos = 0; 755*cdf0e10cSrcweir if( aSel.nEndPos ) 756*cdf0e10cSrcweir { 757*cdf0e10cSrcweir if ( aFormula.Len() < aSel.nEndPos ) 758*cdf0e10cSrcweir return; 759*cdf0e10cSrcweir xub_StrLen nPos = aSel.nEndPos; 760*cdf0e10cSrcweir String aSelText = aFormula.Copy( 0, nPos ); 761*cdf0e10cSrcweir xub_StrLen nNextFStart = 0; 762*cdf0e10cSrcweir xub_StrLen nNextFEnd = 0; 763*cdf0e10cSrcweir xub_StrLen nArgPos = 0; 764*cdf0e10cSrcweir const IFunctionDescription* ppFDesc; 765*cdf0e10cSrcweir ::std::vector< ::rtl::OUString> aArgs; 766*cdf0e10cSrcweir sal_uInt16 nArgs; 767*cdf0e10cSrcweir sal_Bool bFound = sal_False; 768*cdf0e10cSrcweir FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr()); 769*cdf0e10cSrcweir 770*cdf0e10cSrcweir while( !bFound ) 771*cdf0e10cSrcweir { 772*cdf0e10cSrcweir aSelText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) ); 773*cdf0e10cSrcweir nLeftParentPos = lcl_MatchParenthesis( aSelText, aSelText.Len()-1 ); 774*cdf0e10cSrcweir if( nLeftParentPos != STRING_NOTFOUND ) 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir sal_Unicode c = ( nLeftParentPos > 0 ) ? aSelText.GetChar( nLeftParentPos-1 ) : 0; 777*cdf0e10cSrcweir if( !((c >= 'A' && c<= 'Z') || (c>= 'a' && c<= 'z' )) ) 778*cdf0e10cSrcweir continue; 779*cdf0e10cSrcweir nNextFStart = aHelper.GetFunctionStart( aSelText, nLeftParentPos, sal_True); 780*cdf0e10cSrcweir if( aHelper.GetNextFunc( aSelText, sal_False, nNextFStart, &nNextFEnd, &ppFDesc, &aArgs ) ) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir if( ppFDesc->getFunctionName().getLength() ) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir nArgPos = aHelper.GetArgStart( aSelText, nNextFStart, 0 ); 785*cdf0e10cSrcweir nArgs = static_cast<sal_uInt16>(ppFDesc->getParameterCount()); 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir sal_uInt16 nActive = 0; 788*cdf0e10cSrcweir sal_uInt16 nCount = 0; 789*cdf0e10cSrcweir sal_uInt16 nCountSemicolon = 0; 790*cdf0e10cSrcweir sal_uInt16 nCountDot = 0; 791*cdf0e10cSrcweir sal_uInt16 nStartPosition = 0; 792*cdf0e10cSrcweir sal_uInt16 nEndPosition = 0; 793*cdf0e10cSrcweir sal_Bool bFlag = sal_False; 794*cdf0e10cSrcweir String aNew; 795*cdf0e10cSrcweir sal_uInt16 nParAutoPos = SCPOS_INVALID; 796*cdf0e10cSrcweir if( pFormulaDataPara->FindText( ppFDesc->getFunctionName(), aNew, nParAutoPos, sal_False ) ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir for( sal_uInt16 i=0; i < nArgs; i++ ) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir xub_StrLen nLength = static_cast<xub_StrLen>(aArgs[i].getLength()); 801*cdf0e10cSrcweir if( nArgPos <= aSelText.Len()-1 ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir nActive = i+1; 804*cdf0e10cSrcweir bFlag = sal_True; 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir nArgPos+=nLength+1; 807*cdf0e10cSrcweir } 808*cdf0e10cSrcweir if( bFlag ) 809*cdf0e10cSrcweir { 810*cdf0e10cSrcweir nCountSemicolon = aNew.GetTokenCount(cSep)-1; 811*cdf0e10cSrcweir nCountDot = aNew.GetTokenCount(cSheetSep)-1; 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir if( !nCountSemicolon ) 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 818*cdf0e10cSrcweir if( cNext == '(' ) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir nStartPosition = i+1; 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir else if( !nCountDot ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 827*cdf0e10cSrcweir { 828*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 829*cdf0e10cSrcweir if( cNext == '(' ) 830*cdf0e10cSrcweir { 831*cdf0e10cSrcweir nStartPosition = i+1; 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir else if( cNext == cSep ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir nCount ++; 836*cdf0e10cSrcweir nEndPosition = i; 837*cdf0e10cSrcweir if( nCount == nActive ) 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir break; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir nStartPosition = nEndPosition+1; 842*cdf0e10cSrcweir } 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir else 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 850*cdf0e10cSrcweir if( cNext == '(' ) 851*cdf0e10cSrcweir { 852*cdf0e10cSrcweir nStartPosition = i+1; 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir else if( cNext == cSep ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir nCount ++; 857*cdf0e10cSrcweir nEndPosition = i; 858*cdf0e10cSrcweir if( nCount == nActive ) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir break; 861*cdf0e10cSrcweir } 862*cdf0e10cSrcweir nStartPosition = nEndPosition+1; 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir else if( cNext == cSheetSep ) 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir continue; 867*cdf0e10cSrcweir } 868*cdf0e10cSrcweir } 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir if( nStartPosition ) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir aNew.Insert( 0x25BA, nStartPosition ); 874*cdf0e10cSrcweir ShowTipBelow( aNew ); 875*cdf0e10cSrcweir bFound = sal_True; 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir else 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir ShowTipBelow( aNew ); 881*cdf0e10cSrcweir bFound = sal_True; 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir else 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir sal_uInt16 nPosition = 0; 890*cdf0e10cSrcweir String aText = pEngine->GetWord( 0, aSel.nEndPos-1 ); 891*cdf0e10cSrcweir if( aText.GetChar( aSel.nEndPos-1 ) == '=' ) 892*cdf0e10cSrcweir { 893*cdf0e10cSrcweir break; 894*cdf0e10cSrcweir } 895*cdf0e10cSrcweir String aNew; 896*cdf0e10cSrcweir sal_uInt16 nParAutoPos = SCPOS_INVALID; 897*cdf0e10cSrcweir nPosition = aText.Len()+1; 898*cdf0e10cSrcweir if( pFormulaDataPara->FindText( aText, aNew, nParAutoPos, sal_False ) ) 899*cdf0e10cSrcweir { 900*cdf0e10cSrcweir if( aFormula.GetChar( nPosition ) =='(' ) 901*cdf0e10cSrcweir { 902*cdf0e10cSrcweir ShowTipBelow( aNew ); 903*cdf0e10cSrcweir bFound = sal_True; 904*cdf0e10cSrcweir } 905*cdf0e10cSrcweir else 906*cdf0e10cSrcweir break; 907*cdf0e10cSrcweir } 908*cdf0e10cSrcweir else 909*cdf0e10cSrcweir { 910*cdf0e10cSrcweir break; 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir } 913*cdf0e10cSrcweir } 914*cdf0e10cSrcweir } 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir } 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir void ScInputHandler::ShowTip( const String& rText ) 919*cdf0e10cSrcweir { 920*cdf0e10cSrcweir // aManualTip muss hinterher von aussen gesetzt werden 921*cdf0e10cSrcweir HideTip(); 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 924*cdf0e10cSrcweir if (pActiveView) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir Point aPos; 927*cdf0e10cSrcweir pTipVisibleParent = pActiveView->GetWindow(); 928*cdf0e10cSrcweir Cursor* pCur = pActiveView->GetCursor(); 929*cdf0e10cSrcweir if (pCur) 930*cdf0e10cSrcweir aPos = pTipVisibleParent->LogicToPixel( pCur->GetPos() ); 931*cdf0e10cSrcweir aPos = pTipVisibleParent->OutputToScreenPixel( aPos ); 932*cdf0e10cSrcweir Rectangle aRect( aPos, aPos ); 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir sal_uInt16 nAlign = QUICKHELP_LEFT|QUICKHELP_BOTTOM; 935*cdf0e10cSrcweir nTipVisible = Help::ShowTip(pTipVisibleParent, aRect, rText, nAlign); 936*cdf0e10cSrcweir pTipVisibleParent->AddEventListener( LINK( this, ScInputHandler, ShowHideTipVisibleParentListener ) ); 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir } 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir void ScInputHandler::ShowTipBelow( const String& rText ) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir HideTipBelow(); 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 945*cdf0e10cSrcweir if ( pActiveView ) 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir Point aPos; 948*cdf0e10cSrcweir pTipVisibleSecParent = pActiveView->GetWindow(); 949*cdf0e10cSrcweir Cursor* pCur = pActiveView->GetCursor(); 950*cdf0e10cSrcweir if ( pCur ) 951*cdf0e10cSrcweir { 952*cdf0e10cSrcweir Point aLogicPos = pCur->GetPos(); 953*cdf0e10cSrcweir aLogicPos.Y() += pCur->GetHeight(); 954*cdf0e10cSrcweir aPos = pTipVisibleSecParent->LogicToPixel( aLogicPos ); 955*cdf0e10cSrcweir } 956*cdf0e10cSrcweir aPos = pTipVisibleSecParent->OutputToScreenPixel( aPos ); 957*cdf0e10cSrcweir Rectangle aRect( aPos, aPos ); 958*cdf0e10cSrcweir sal_uInt16 nAlign = QUICKHELP_LEFT | QUICKHELP_TOP | QUICKHELP_NOEVADEPOINTER; 959*cdf0e10cSrcweir nTipVisibleSec = Help::ShowTip(pTipVisibleSecParent, aRect, rText, nAlign); 960*cdf0e10cSrcweir pTipVisibleSecParent->AddEventListener( LINK( this, ScInputHandler, ShowHideTipVisibleSecParentListener ) ); 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir } 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir void ScInputHandler::UseFormulaData() 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 967*cdf0e10cSrcweir ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell(); 968*cdf0e10cSrcweir const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0); 969*cdf0e10cSrcweir const sal_Unicode cSheetSep = lcl_getSheetSeparator(pDocSh->GetDocument()); 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir // Formeln duerfen nur 1 Absatz haben 972*cdf0e10cSrcweir if ( pActiveView && pFormulaData && pEngine->GetParagraphCount() == 1 ) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir String aTotal = pEngine->GetText( (sal_uInt16) 0 ); 975*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 976*cdf0e10cSrcweir aSel.Adjust(); 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir // #59348# Durch Differenzen zwischen Tabelle und Eingabezeile 979*cdf0e10cSrcweir // (z.B. Clipboard mit Zeilenumbruechen) kann es sein, dass die Selektion 980*cdf0e10cSrcweir // nicht mehr zur EditEngine passt. Dann halt kommentarlos abbrechen: 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir if ( aSel.nEndPos > aTotal.Len() ) 983*cdf0e10cSrcweir return; 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir // steht der Cursor am Ende eines Wortes? 986*cdf0e10cSrcweir 987*cdf0e10cSrcweir if ( aSel.nEndPos > 0 ) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir xub_StrLen nPos = aSel.nEndPos; 990*cdf0e10cSrcweir String aFormula = aTotal.Copy( 0, nPos );; 991*cdf0e10cSrcweir xub_StrLen nLeftParentPos = 0; 992*cdf0e10cSrcweir xub_StrLen nNextFStart = 0; 993*cdf0e10cSrcweir xub_StrLen nNextFEnd = 0; 994*cdf0e10cSrcweir xub_StrLen nArgPos = 0; 995*cdf0e10cSrcweir const IFunctionDescription* ppFDesc; 996*cdf0e10cSrcweir ::std::vector< ::rtl::OUString> aArgs; 997*cdf0e10cSrcweir sal_uInt16 nArgs; 998*cdf0e10cSrcweir sal_Bool bFound = sal_False; 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir String aText = pEngine->GetWord( 0, aSel.nEndPos-1 ); 1001*cdf0e10cSrcweir if ( aText.Len() ) 1002*cdf0e10cSrcweir { 1003*cdf0e10cSrcweir String aNew; 1004*cdf0e10cSrcweir nAutoPos = SCPOS_INVALID; 1005*cdf0e10cSrcweir if ( pFormulaData->FindText( aText, aNew, nAutoPos, sal_False ) ) 1006*cdf0e10cSrcweir { 1007*cdf0e10cSrcweir ShowTip( aNew ); 1008*cdf0e10cSrcweir aAutoSearch = aText; 1009*cdf0e10cSrcweir } 1010*cdf0e10cSrcweir } 1011*cdf0e10cSrcweir FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr()); 1012*cdf0e10cSrcweir 1013*cdf0e10cSrcweir while( !bFound ) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir aFormula.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) ); 1016*cdf0e10cSrcweir nLeftParentPos = lcl_MatchParenthesis( aFormula, aFormula.Len()-1 ); 1017*cdf0e10cSrcweir if( nLeftParentPos == STRING_NOTFOUND ) 1018*cdf0e10cSrcweir break; 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir // #160063# nLeftParentPos can be 0 if a parenthesis is inserted before the formula 1021*cdf0e10cSrcweir sal_Unicode c = ( nLeftParentPos > 0 ) ? aFormula.GetChar( nLeftParentPos-1 ) : 0; 1022*cdf0e10cSrcweir if( !((c >= 'A' && c<= 'Z') || (c>= 'a' && c<= 'z') ) ) 1023*cdf0e10cSrcweir continue; 1024*cdf0e10cSrcweir nNextFStart = aHelper.GetFunctionStart( aFormula, nLeftParentPos, sal_True); 1025*cdf0e10cSrcweir if( aHelper.GetNextFunc( aFormula, sal_False, nNextFStart, &nNextFEnd, &ppFDesc, &aArgs ) ) 1026*cdf0e10cSrcweir { 1027*cdf0e10cSrcweir if( ppFDesc->getFunctionName().getLength() ) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir nArgPos = aHelper.GetArgStart( aFormula, nNextFStart, 0 ); 1030*cdf0e10cSrcweir nArgs = static_cast<sal_uInt16>(ppFDesc->getParameterCount()); 1031*cdf0e10cSrcweir 1032*cdf0e10cSrcweir sal_uInt16 nActive = 0; 1033*cdf0e10cSrcweir sal_uInt16 nCount = 0; 1034*cdf0e10cSrcweir sal_uInt16 nCountSemicolon = 0; 1035*cdf0e10cSrcweir sal_uInt16 nCountDot = 0; 1036*cdf0e10cSrcweir sal_uInt16 nStartPosition = 0; 1037*cdf0e10cSrcweir sal_uInt16 nEndPosition = 0; 1038*cdf0e10cSrcweir sal_Bool bFlag = sal_False; 1039*cdf0e10cSrcweir String aNew; 1040*cdf0e10cSrcweir sal_uInt16 nParAutoPos = SCPOS_INVALID; 1041*cdf0e10cSrcweir if( pFormulaDataPara->FindText( ppFDesc->getFunctionName(), aNew, nParAutoPos, sal_False ) ) 1042*cdf0e10cSrcweir { 1043*cdf0e10cSrcweir for( sal_uInt16 i=0; i < nArgs; i++ ) 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir xub_StrLen nLength = static_cast<xub_StrLen>(aArgs[i].getLength()); 1046*cdf0e10cSrcweir if( nArgPos <= aFormula.Len()-1 ) 1047*cdf0e10cSrcweir { 1048*cdf0e10cSrcweir nActive = i+1; 1049*cdf0e10cSrcweir bFlag = sal_True; 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir nArgPos+=nLength+1; 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir if( bFlag ) 1054*cdf0e10cSrcweir { 1055*cdf0e10cSrcweir nCountSemicolon = aNew.GetTokenCount(cSep)-1; 1056*cdf0e10cSrcweir nCountDot = aNew.GetTokenCount(cSheetSep)-1; 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir if( !nCountSemicolon ) 1059*cdf0e10cSrcweir { 1060*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 1061*cdf0e10cSrcweir { 1062*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 1063*cdf0e10cSrcweir if( cNext == '(' ) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir nStartPosition = i+1; 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir } 1068*cdf0e10cSrcweir } 1069*cdf0e10cSrcweir else if( !nCountDot ) 1070*cdf0e10cSrcweir { 1071*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 1074*cdf0e10cSrcweir if( cNext == '(' ) 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir nStartPosition = i+1; 1077*cdf0e10cSrcweir } 1078*cdf0e10cSrcweir else if( cNext == cSep ) 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir nCount ++; 1081*cdf0e10cSrcweir nEndPosition = i; 1082*cdf0e10cSrcweir if( nCount == nActive ) 1083*cdf0e10cSrcweir { 1084*cdf0e10cSrcweir break; 1085*cdf0e10cSrcweir } 1086*cdf0e10cSrcweir nStartPosition = nEndPosition+1; 1087*cdf0e10cSrcweir } 1088*cdf0e10cSrcweir } 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir else 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aNew.Len(); i++ ) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir sal_Unicode cNext = aNew.GetChar( i ); 1095*cdf0e10cSrcweir if( cNext == '(' ) 1096*cdf0e10cSrcweir { 1097*cdf0e10cSrcweir nStartPosition = i+1; 1098*cdf0e10cSrcweir } 1099*cdf0e10cSrcweir else if( cNext == cSep ) 1100*cdf0e10cSrcweir { 1101*cdf0e10cSrcweir nCount ++; 1102*cdf0e10cSrcweir nEndPosition = i; 1103*cdf0e10cSrcweir if( nCount == nActive ) 1104*cdf0e10cSrcweir { 1105*cdf0e10cSrcweir break; 1106*cdf0e10cSrcweir } 1107*cdf0e10cSrcweir nStartPosition = nEndPosition+1; 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir else if( cNext == cSheetSep ) 1110*cdf0e10cSrcweir { 1111*cdf0e10cSrcweir continue; 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir } 1114*cdf0e10cSrcweir } 1115*cdf0e10cSrcweir 1116*cdf0e10cSrcweir if( nStartPosition ) 1117*cdf0e10cSrcweir { 1118*cdf0e10cSrcweir aNew.Insert( 0x25BA, nStartPosition ); 1119*cdf0e10cSrcweir ShowTipBelow( aNew ); 1120*cdf0e10cSrcweir bFound = sal_True; 1121*cdf0e10cSrcweir } 1122*cdf0e10cSrcweir } 1123*cdf0e10cSrcweir else 1124*cdf0e10cSrcweir { 1125*cdf0e10cSrcweir ShowTipBelow( aNew ); 1126*cdf0e10cSrcweir bFound = sal_True; 1127*cdf0e10cSrcweir } 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir } 1130*cdf0e10cSrcweir } 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir } 1133*cdf0e10cSrcweir } 1134*cdf0e10cSrcweir } 1135*cdf0e10cSrcweir 1136*cdf0e10cSrcweir void ScInputHandler::NextFormulaEntry( sal_Bool bBack ) 1137*cdf0e10cSrcweir { 1138*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1139*cdf0e10cSrcweir if ( pActiveView && pFormulaData ) 1140*cdf0e10cSrcweir { 1141*cdf0e10cSrcweir String aNew; 1142*cdf0e10cSrcweir if ( pFormulaData->FindText( aAutoSearch, aNew, nAutoPos, bBack ) ) 1143*cdf0e10cSrcweir ShowTip( aNew ); // als QuickHelp anzeigen 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir // bei Tab wird vorher immer HideCursor gerufen 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweir if (pActiveView) 1149*cdf0e10cSrcweir pActiveView->ShowCursor(); 1150*cdf0e10cSrcweir } 1151*cdf0e10cSrcweir 1152*cdf0e10cSrcweir void lcl_CompleteFunction( EditView* pView, const String& rInsert, sal_Bool& rParInserted ) 1153*cdf0e10cSrcweir { 1154*cdf0e10cSrcweir if (pView) 1155*cdf0e10cSrcweir { 1156*cdf0e10cSrcweir ESelection aSel = pView->GetSelection(); 1157*cdf0e10cSrcweir --aSel.nStartPos; 1158*cdf0e10cSrcweir --aSel.nEndPos; 1159*cdf0e10cSrcweir pView->SetSelection(aSel); 1160*cdf0e10cSrcweir pView->SelectCurrentWord(); 1161*cdf0e10cSrcweir 1162*cdf0e10cSrcweir String aInsStr = rInsert; 1163*cdf0e10cSrcweir xub_StrLen nInsLen = aInsStr.Len(); 1164*cdf0e10cSrcweir sal_Bool bDoParen = ( nInsLen > 1 && aInsStr.GetChar(nInsLen-2) == '(' 1165*cdf0e10cSrcweir && aInsStr.GetChar(nInsLen-1) == ')' ); 1166*cdf0e10cSrcweir if ( bDoParen ) 1167*cdf0e10cSrcweir { 1168*cdf0e10cSrcweir // Klammern hinter Funktionsnamen nicht einfuegen, wenn direkt dahinter 1169*cdf0e10cSrcweir // schon eine Klammer steht (z.B. wenn der Funktionsname geaendert wurde, 1170*cdf0e10cSrcweir // #39393#). 1171*cdf0e10cSrcweir 1172*cdf0e10cSrcweir ESelection aWordSel = pView->GetSelection(); 1173*cdf0e10cSrcweir String aOld = pView->GetEditEngine()->GetText((sal_uInt16)0); 1174*cdf0e10cSrcweir sal_Unicode cNext = aOld.GetChar(aWordSel.nEndPos); 1175*cdf0e10cSrcweir if ( cNext == '(' ) 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir bDoParen = sal_False; 1178*cdf0e10cSrcweir aInsStr.Erase( nInsLen - 2 ); // Klammern weglassen 1179*cdf0e10cSrcweir } 1180*cdf0e10cSrcweir } 1181*cdf0e10cSrcweir 1182*cdf0e10cSrcweir pView->InsertText( aInsStr, sal_False ); 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir if ( bDoParen ) // Cursor zwischen die Klammern setzen 1185*cdf0e10cSrcweir { 1186*cdf0e10cSrcweir aSel = pView->GetSelection(); 1187*cdf0e10cSrcweir --aSel.nStartPos; 1188*cdf0e10cSrcweir --aSel.nEndPos; 1189*cdf0e10cSrcweir pView->SetSelection(aSel); 1190*cdf0e10cSrcweir 1191*cdf0e10cSrcweir rParInserted = sal_True; 1192*cdf0e10cSrcweir } 1193*cdf0e10cSrcweir } 1194*cdf0e10cSrcweir } 1195*cdf0e10cSrcweir 1196*cdf0e10cSrcweir void ScInputHandler::PasteFunctionData() 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir if ( pFormulaData && nAutoPos != SCPOS_INVALID ) 1199*cdf0e10cSrcweir { 1200*cdf0e10cSrcweir TypedStrData* pData = (*pFormulaData)[nAutoPos]; 1201*cdf0e10cSrcweir if (pData) 1202*cdf0e10cSrcweir { 1203*cdf0e10cSrcweir String aInsert = pData->GetString(); 1204*cdf0e10cSrcweir sal_Bool bParInserted = sal_False; 1205*cdf0e10cSrcweir 1206*cdf0e10cSrcweir DataChanging(); // kann nicht neu sein 1207*cdf0e10cSrcweir lcl_CompleteFunction( pTopView, aInsert, bParInserted ); 1208*cdf0e10cSrcweir lcl_CompleteFunction( pTableView, aInsert, bParInserted ); 1209*cdf0e10cSrcweir DataChanged(); 1210*cdf0e10cSrcweir ShowTipCursor(); 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir if (bParInserted) 1213*cdf0e10cSrcweir AutoParAdded(); 1214*cdf0e10cSrcweir } 1215*cdf0e10cSrcweir } 1216*cdf0e10cSrcweir 1217*cdf0e10cSrcweir HideTip(); 1218*cdf0e10cSrcweir 1219*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1220*cdf0e10cSrcweir if (pActiveView) 1221*cdf0e10cSrcweir pActiveView->ShowCursor(); 1222*cdf0e10cSrcweir } 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir // 1225*cdf0e10cSrcweir // Selektion berechnen und als Tip-Hilfe anzeigen 1226*cdf0e10cSrcweir // 1227*cdf0e10cSrcweir 1228*cdf0e10cSrcweir String lcl_Calculate( const String& rFormula, ScDocument* pDoc, const ScAddress &rPos ) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir //! mit ScFormulaDlg::CalcValue zusammenfassen und ans Dokument verschieben !!!! 1231*cdf0e10cSrcweir //! (Anfuehrungszeichen bei Strings werden nur hier eingefuegt) 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir String aValue; 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir if (rFormula.Len()) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir ScFormulaCell* pCell = new ScFormulaCell( pDoc, rPos, rFormula ); 1238*cdf0e10cSrcweir 1239*cdf0e10cSrcweir // #35521# HACK! um bei ColRowNames kein #REF! zu bekommen, 1240*cdf0e10cSrcweir // wenn ein Name eigentlich als Bereich in die Gesamt-Formel 1241*cdf0e10cSrcweir // eingefuegt wird, bei der Einzeldarstellung aber als 1242*cdf0e10cSrcweir // single-Zellbezug interpretiert wird 1243*cdf0e10cSrcweir sal_Bool bColRowName = pCell->HasColRowName(); 1244*cdf0e10cSrcweir if ( bColRowName ) 1245*cdf0e10cSrcweir { 1246*cdf0e10cSrcweir // ColRowName im RPN-Code? 1247*cdf0e10cSrcweir if ( pCell->GetCode()->GetCodeLen() <= 1 ) 1248*cdf0e10cSrcweir { // ==1: einzelner ist als Parameter immer Bereich 1249*cdf0e10cSrcweir // ==0: es waere vielleicht einer, wenn.. 1250*cdf0e10cSrcweir String aBraced( '(' ); 1251*cdf0e10cSrcweir aBraced += rFormula; 1252*cdf0e10cSrcweir aBraced += ')'; 1253*cdf0e10cSrcweir delete pCell; 1254*cdf0e10cSrcweir pCell = new ScFormulaCell( pDoc, rPos, aBraced ); 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir else 1257*cdf0e10cSrcweir bColRowName = sal_False; 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir sal_uInt16 nErrCode = pCell->GetErrCode(); 1261*cdf0e10cSrcweir if ( nErrCode == 0 ) 1262*cdf0e10cSrcweir { 1263*cdf0e10cSrcweir SvNumberFormatter& aFormatter = *(pDoc->GetFormatTable()); 1264*cdf0e10cSrcweir Color* pColor; 1265*cdf0e10cSrcweir if ( pCell->IsValue() ) 1266*cdf0e10cSrcweir { 1267*cdf0e10cSrcweir double n = pCell->GetValue(); 1268*cdf0e10cSrcweir sal_uLong nFormat = aFormatter.GetStandardFormat( n, 0, 1269*cdf0e10cSrcweir pCell->GetFormatType(), ScGlobal::eLnge ); 1270*cdf0e10cSrcweir aFormatter.GetInputLineString( n, nFormat, aValue ); 1271*cdf0e10cSrcweir //! display OutputString but insert InputLineString 1272*cdf0e10cSrcweir } 1273*cdf0e10cSrcweir else 1274*cdf0e10cSrcweir { 1275*cdf0e10cSrcweir String aStr; 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir pCell->GetString( aStr ); 1278*cdf0e10cSrcweir sal_uLong nFormat = aFormatter.GetStandardFormat( 1279*cdf0e10cSrcweir pCell->GetFormatType(), ScGlobal::eLnge); 1280*cdf0e10cSrcweir aFormatter.GetOutputString( aStr, nFormat, 1281*cdf0e10cSrcweir aValue, &pColor ); 1282*cdf0e10cSrcweir 1283*cdf0e10cSrcweir aValue.Insert('"',0); // in Anfuehrungszeichen 1284*cdf0e10cSrcweir aValue+='"'; 1285*cdf0e10cSrcweir //! Anfuehrungszeichen im String escapen ???? 1286*cdf0e10cSrcweir } 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir ScRange aTestRange; 1289*cdf0e10cSrcweir if ( bColRowName || (aTestRange.Parse(rFormula) & SCA_VALID) ) 1290*cdf0e10cSrcweir aValue.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ..." )); // Bereich 1291*cdf0e10cSrcweir } 1292*cdf0e10cSrcweir else 1293*cdf0e10cSrcweir aValue = ScGlobal::GetErrorString(nErrCode); 1294*cdf0e10cSrcweir delete pCell; 1295*cdf0e10cSrcweir } 1296*cdf0e10cSrcweir 1297*cdf0e10cSrcweir return aValue; 1298*cdf0e10cSrcweir } 1299*cdf0e10cSrcweir 1300*cdf0e10cSrcweir void ScInputHandler::FormulaPreview() 1301*cdf0e10cSrcweir { 1302*cdf0e10cSrcweir String aValue; 1303*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1304*cdf0e10cSrcweir if ( pActiveView && pActiveViewSh ) 1305*cdf0e10cSrcweir { 1306*cdf0e10cSrcweir String aPart = pActiveView->GetSelected(); 1307*cdf0e10cSrcweir if (!aPart.Len()) 1308*cdf0e10cSrcweir aPart = pEngine->GetText((sal_uInt16)0); 1309*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 1310*cdf0e10cSrcweir aValue = lcl_Calculate( aPart, pDoc, aCursorPos ); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir if (aValue.Len()) 1314*cdf0e10cSrcweir { 1315*cdf0e10cSrcweir ShowTip( aValue ); // als QuickHelp anzeigen 1316*cdf0e10cSrcweir aManualTip = aValue; // nach ShowTip setzen 1317*cdf0e10cSrcweir nAutoPos = SCPOS_INVALID; // Formel-Autocomplete aufheben 1318*cdf0e10cSrcweir } 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir void ScInputHandler::PasteManualTip() 1322*cdf0e10cSrcweir { 1323*cdf0e10cSrcweir // drei Punkte am Ende -> Bereichsreferenz -> nicht einfuegen 1324*cdf0e10cSrcweir // (wenn wir mal Matrix-Konstanten haben, kann das geaendert werden) 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir xub_StrLen nTipLen = aManualTip.Len(); 1327*cdf0e10cSrcweir if ( nTipLen && ( nTipLen < 3 || !aManualTip.Copy( nTipLen-3 ).EqualsAscii("...") ) ) 1328*cdf0e10cSrcweir { 1329*cdf0e10cSrcweir DataChanging(); // kann nicht neu sein 1330*cdf0e10cSrcweir 1331*cdf0e10cSrcweir String aInsert = aManualTip; 1332*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1333*cdf0e10cSrcweir if (!pActiveView->HasSelection()) 1334*cdf0e10cSrcweir { 1335*cdf0e10cSrcweir // nichts selektiert -> alles selektieren 1336*cdf0e10cSrcweir xub_StrLen nOldLen = pEngine->GetTextLen(0); 1337*cdf0e10cSrcweir ESelection aAllSel( 0, 0, 0, nOldLen ); 1338*cdf0e10cSrcweir if ( pTopView ) 1339*cdf0e10cSrcweir pTopView->SetSelection( aAllSel ); 1340*cdf0e10cSrcweir if ( pTableView ) 1341*cdf0e10cSrcweir pTableView->SetSelection( aAllSel ); 1342*cdf0e10cSrcweir } 1343*cdf0e10cSrcweir 1344*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 1345*cdf0e10cSrcweir aSel.Adjust(); 1346*cdf0e10cSrcweir DBG_ASSERT( !aSel.nStartPara && !aSel.nEndPara, "Zuviele Absaetze in Formel" ); 1347*cdf0e10cSrcweir if ( !aSel.nStartPos ) // Selektion ab Anfang? 1348*cdf0e10cSrcweir { 1349*cdf0e10cSrcweir if ( aSel.nEndPos == pEngine->GetTextLen(0) ) 1350*cdf0e10cSrcweir { 1351*cdf0e10cSrcweir // alles selektiert -> Anfuehrungszeichen weglassen 1352*cdf0e10cSrcweir if ( aInsert.GetChar(0) == '"' ) 1353*cdf0e10cSrcweir aInsert.Erase(0,1); 1354*cdf0e10cSrcweir xub_StrLen nInsLen = aInsert.Len(); 1355*cdf0e10cSrcweir if ( nInsLen && aInsert.GetChar(nInsLen-1) == '"' ) 1356*cdf0e10cSrcweir aInsert.Erase( nInsLen-1 ); 1357*cdf0e10cSrcweir } 1358*cdf0e10cSrcweir else if ( aSel.nEndPos ) 1359*cdf0e10cSrcweir { 1360*cdf0e10cSrcweir // nicht alles selektiert -> Gleichheitszeichen nicht ueberschreiben 1361*cdf0e10cSrcweir //! doppelte Gleichheitszeichen auch ??? 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir aSel.nStartPos = 1; 1364*cdf0e10cSrcweir if ( pTopView ) 1365*cdf0e10cSrcweir pTopView->SetSelection( aSel ); 1366*cdf0e10cSrcweir if ( pTableView ) 1367*cdf0e10cSrcweir pTableView->SetSelection( aSel ); 1368*cdf0e10cSrcweir } 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir if ( pTopView ) 1371*cdf0e10cSrcweir pTopView->InsertText( aInsert, sal_True ); 1372*cdf0e10cSrcweir if ( pTableView ) 1373*cdf0e10cSrcweir pTableView->InsertText( aInsert, sal_True ); 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir DataChanged(); 1376*cdf0e10cSrcweir } 1377*cdf0e10cSrcweir 1378*cdf0e10cSrcweir HideTip(); 1379*cdf0e10cSrcweir } 1380*cdf0e10cSrcweir 1381*cdf0e10cSrcweir void ScInputHandler::ResetAutoPar() 1382*cdf0e10cSrcweir { 1383*cdf0e10cSrcweir nAutoPar = 0; 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir 1386*cdf0e10cSrcweir void ScInputHandler::AutoParAdded() 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir ++nAutoPar; // closing parenthesis can be overwritten 1389*cdf0e10cSrcweir } 1390*cdf0e10cSrcweir 1391*cdf0e10cSrcweir sal_Bool ScInputHandler::CursorAtClosingPar() 1392*cdf0e10cSrcweir { 1393*cdf0e10cSrcweir // test if the cursor is before a closing parenthesis 1394*cdf0e10cSrcweir 1395*cdf0e10cSrcweir // selection from SetReference has been removed before 1396*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1397*cdf0e10cSrcweir if ( pActiveView && !pActiveView->HasSelection() && bFormulaMode ) 1398*cdf0e10cSrcweir { 1399*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 1400*cdf0e10cSrcweir xub_StrLen nPos = aSel.nStartPos; 1401*cdf0e10cSrcweir String aFormula = pEngine->GetText((sal_uInt16)0); 1402*cdf0e10cSrcweir if ( nPos < aFormula.Len() && aFormula.GetChar(nPos) == ')' ) 1403*cdf0e10cSrcweir return sal_True; 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir return sal_False; 1406*cdf0e10cSrcweir } 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir void ScInputHandler::SkipClosingPar() 1409*cdf0e10cSrcweir { 1410*cdf0e10cSrcweir // this is called when a ')' is typed and the cursor is before a ')' 1411*cdf0e10cSrcweir // that can be overwritten -> just set the cursor behind the ')' 1412*cdf0e10cSrcweir 1413*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1414*cdf0e10cSrcweir if (pActiveView) 1415*cdf0e10cSrcweir { 1416*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 1417*cdf0e10cSrcweir ++aSel.nStartPos; 1418*cdf0e10cSrcweir ++aSel.nEndPos; 1419*cdf0e10cSrcweir 1420*cdf0e10cSrcweir // this is in a formula (only one paragraph), so the selection 1421*cdf0e10cSrcweir // can be used directly for the TopView 1422*cdf0e10cSrcweir 1423*cdf0e10cSrcweir if ( pTopView ) 1424*cdf0e10cSrcweir pTopView->SetSelection( aSel ); 1425*cdf0e10cSrcweir if ( pTableView ) 1426*cdf0e10cSrcweir pTableView->SetSelection( aSel ); 1427*cdf0e10cSrcweir } 1428*cdf0e10cSrcweir 1429*cdf0e10cSrcweir DBG_ASSERT(nAutoPar, "SkipClosingPar: count is wrong"); 1430*cdf0e10cSrcweir --nAutoPar; 1431*cdf0e10cSrcweir } 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir // 1434*cdf0e10cSrcweir // Auto-Eingabe 1435*cdf0e10cSrcweir // 1436*cdf0e10cSrcweir 1437*cdf0e10cSrcweir void ScInputHandler::GetColData() 1438*cdf0e10cSrcweir { 1439*cdf0e10cSrcweir if ( pActiveViewSh ) 1440*cdf0e10cSrcweir { 1441*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 1442*cdf0e10cSrcweir 1443*cdf0e10cSrcweir if ( pColumnData ) 1444*cdf0e10cSrcweir pColumnData->FreeAll(); 1445*cdf0e10cSrcweir else 1446*cdf0e10cSrcweir { 1447*cdf0e10cSrcweir pColumnData = new TypedScStrCollection; 1448*cdf0e10cSrcweir pColumnData->SetCaseSensitive( sal_True ); // equal strings are handled in FindText 1449*cdf0e10cSrcweir } 1450*cdf0e10cSrcweir 1451*cdf0e10cSrcweir pDoc->GetDataEntries( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), 1452*cdf0e10cSrcweir *pColumnData, sal_True ); 1453*cdf0e10cSrcweir } 1454*cdf0e10cSrcweir } 1455*cdf0e10cSrcweir 1456*cdf0e10cSrcweir void ScInputHandler::UseColData() // beim Tippen 1457*cdf0e10cSrcweir { 1458*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1459*cdf0e10cSrcweir if ( pActiveView && pColumnData ) 1460*cdf0e10cSrcweir { 1461*cdf0e10cSrcweir // nur anpassen, wenn Cursor am Ende steht 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 1464*cdf0e10cSrcweir aSel.Adjust(); 1465*cdf0e10cSrcweir 1466*cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 1467*cdf0e10cSrcweir if ( aSel.nEndPara+1 == nParCnt ) 1468*cdf0e10cSrcweir { 1469*cdf0e10cSrcweir xub_StrLen nParLen = pEngine->GetTextLen( aSel.nEndPara ); 1470*cdf0e10cSrcweir if ( aSel.nEndPos == nParLen ) 1471*cdf0e10cSrcweir { 1472*cdf0e10cSrcweir String aText = GetEditText(pEngine); 1473*cdf0e10cSrcweir if (aText.Len()) 1474*cdf0e10cSrcweir { 1475*cdf0e10cSrcweir String aNew; 1476*cdf0e10cSrcweir nAutoPos = SCPOS_INVALID; // nix 1477*cdf0e10cSrcweir if ( pColumnData->FindText( aText, aNew, nAutoPos, sal_False ) ) 1478*cdf0e10cSrcweir { 1479*cdf0e10cSrcweir // #45434# durch dBase Import etc. koennen Umbrueche im String sein, 1480*cdf0e10cSrcweir // das wuerde hier mehrere Absaetze ergeben -> nicht gut 1481*cdf0e10cSrcweir //! GetExactMatch funktioniert dann auch nicht 1482*cdf0e10cSrcweir lcl_RemoveLineEnd( aNew ); 1483*cdf0e10cSrcweir 1484*cdf0e10cSrcweir // Absaetze beibehalten, nur den Rest anfuegen 1485*cdf0e10cSrcweir //! genaue Ersetzung im EnterHandler !!! 1486*cdf0e10cSrcweir 1487*cdf0e10cSrcweir // ein Space zwischen Absaetzen: 1488*cdf0e10cSrcweir sal_uLong nEdLen = pEngine->GetTextLen() + nParCnt - 1; 1489*cdf0e10cSrcweir String aIns = aNew.Copy( (xub_StrLen)nEdLen ); 1490*cdf0e10cSrcweir 1491*cdf0e10cSrcweir // selection must be "backwards", so the cursor stays behind the last 1492*cdf0e10cSrcweir // typed character 1493*cdf0e10cSrcweir ESelection aSelection( aSel.nEndPara, aSel.nEndPos + aIns.Len(), 1494*cdf0e10cSrcweir aSel.nEndPara, aSel.nEndPos ); 1495*cdf0e10cSrcweir 1496*cdf0e10cSrcweir // when editing in input line, apply to both edit views 1497*cdf0e10cSrcweir if ( pTableView ) 1498*cdf0e10cSrcweir { 1499*cdf0e10cSrcweir pTableView->InsertText( aIns, sal_False ); 1500*cdf0e10cSrcweir pTableView->SetSelection( aSelection ); 1501*cdf0e10cSrcweir } 1502*cdf0e10cSrcweir if ( pTopView ) 1503*cdf0e10cSrcweir { 1504*cdf0e10cSrcweir pTopView->InsertText( aIns, sal_False ); 1505*cdf0e10cSrcweir pTopView->SetSelection( aSelection ); 1506*cdf0e10cSrcweir } 1507*cdf0e10cSrcweir 1508*cdf0e10cSrcweir aAutoSearch = aText; // zum Weitersuchen - nAutoPos ist gesetzt 1509*cdf0e10cSrcweir 1510*cdf0e10cSrcweir if ( aText.Len() == aNew.Len() ) 1511*cdf0e10cSrcweir { 1512*cdf0e10cSrcweir // Wenn der eingegebene Text gefunden wurde, TAB nur dann 1513*cdf0e10cSrcweir // verschlucken, wenn noch etwas kommt 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir String aDummy; 1516*cdf0e10cSrcweir sal_uInt16 nNextPos = nAutoPos; 1517*cdf0e10cSrcweir bUseTab = pColumnData->FindText( aText, aDummy, nNextPos, sal_False ); 1518*cdf0e10cSrcweir } 1519*cdf0e10cSrcweir else 1520*cdf0e10cSrcweir bUseTab = sal_True; 1521*cdf0e10cSrcweir } 1522*cdf0e10cSrcweir } 1523*cdf0e10cSrcweir } 1524*cdf0e10cSrcweir } 1525*cdf0e10cSrcweir } 1526*cdf0e10cSrcweir } 1527*cdf0e10cSrcweir 1528*cdf0e10cSrcweir void ScInputHandler::NextAutoEntry( sal_Bool bBack ) 1529*cdf0e10cSrcweir { 1530*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1531*cdf0e10cSrcweir if ( pActiveView && pColumnData ) 1532*cdf0e10cSrcweir { 1533*cdf0e10cSrcweir if ( nAutoPos != SCPOS_INVALID && aAutoSearch.Len() ) 1534*cdf0e10cSrcweir { 1535*cdf0e10cSrcweir // stimmt die Selektion noch? (kann per Maus geaendert sein) 1536*cdf0e10cSrcweir 1537*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 1538*cdf0e10cSrcweir aSel.Adjust(); 1539*cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 1540*cdf0e10cSrcweir if ( aSel.nEndPara+1 == nParCnt && aSel.nStartPara == aSel.nEndPara ) 1541*cdf0e10cSrcweir { 1542*cdf0e10cSrcweir String aText = GetEditText(pEngine); 1543*cdf0e10cSrcweir xub_StrLen nSelLen = aSel.nEndPos - aSel.nStartPos; 1544*cdf0e10cSrcweir xub_StrLen nParLen = pEngine->GetTextLen( aSel.nEndPara ); 1545*cdf0e10cSrcweir if ( aSel.nEndPos == nParLen && aText.Len() == aAutoSearch.Len() + nSelLen ) 1546*cdf0e10cSrcweir { 1547*cdf0e10cSrcweir String aNew; 1548*cdf0e10cSrcweir if ( pColumnData->FindText( aAutoSearch, aNew, nAutoPos, bBack ) ) 1549*cdf0e10cSrcweir { 1550*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 1551*cdf0e10cSrcweir 1552*cdf0e10cSrcweir lcl_RemoveLineEnd( aNew ); 1553*cdf0e10cSrcweir String aIns = aNew.Copy( aAutoSearch.Len() ); 1554*cdf0e10cSrcweir 1555*cdf0e10cSrcweir // when editing in input line, apply to both edit views 1556*cdf0e10cSrcweir if ( pTableView ) 1557*cdf0e10cSrcweir { 1558*cdf0e10cSrcweir pTableView->DeleteSelected(); 1559*cdf0e10cSrcweir pTableView->InsertText( aIns, sal_False ); 1560*cdf0e10cSrcweir pTableView->SetSelection( ESelection( 1561*cdf0e10cSrcweir aSel.nEndPara, aSel.nStartPos + aIns.Len(), 1562*cdf0e10cSrcweir aSel.nEndPara, aSel.nStartPos ) ); 1563*cdf0e10cSrcweir } 1564*cdf0e10cSrcweir if ( pTopView ) 1565*cdf0e10cSrcweir { 1566*cdf0e10cSrcweir pTopView->DeleteSelected(); 1567*cdf0e10cSrcweir pTopView->InsertText( aIns, sal_False ); 1568*cdf0e10cSrcweir pTopView->SetSelection( ESelection( 1569*cdf0e10cSrcweir aSel.nEndPara, aSel.nStartPos + aIns.Len(), 1570*cdf0e10cSrcweir aSel.nEndPara, aSel.nStartPos ) ); 1571*cdf0e10cSrcweir } 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir bInOwnChange = sal_False; 1574*cdf0e10cSrcweir } 1575*cdf0e10cSrcweir else 1576*cdf0e10cSrcweir { 1577*cdf0e10cSrcweir // mehr gibts nicht 1578*cdf0e10cSrcweir 1579*cdf0e10cSrcweir Sound::Beep(); 1580*cdf0e10cSrcweir } 1581*cdf0e10cSrcweir } 1582*cdf0e10cSrcweir } 1583*cdf0e10cSrcweir } 1584*cdf0e10cSrcweir } 1585*cdf0e10cSrcweir 1586*cdf0e10cSrcweir // bei Tab wird vorher immer HideCursor gerufen 1587*cdf0e10cSrcweir 1588*cdf0e10cSrcweir if (pActiveView) 1589*cdf0e10cSrcweir pActiveView->ShowCursor(); 1590*cdf0e10cSrcweir } 1591*cdf0e10cSrcweir 1592*cdf0e10cSrcweir // 1593*cdf0e10cSrcweir // Klammern hervorheben 1594*cdf0e10cSrcweir // 1595*cdf0e10cSrcweir 1596*cdf0e10cSrcweir void ScInputHandler::UpdateParenthesis() 1597*cdf0e10cSrcweir { 1598*cdf0e10cSrcweir // Klammern suchen 1599*cdf0e10cSrcweir 1600*cdf0e10cSrcweir //! Klammer-Hervorhebung einzeln abschaltbar ???? 1601*cdf0e10cSrcweir 1602*cdf0e10cSrcweir sal_Bool bFound = sal_False; 1603*cdf0e10cSrcweir if ( bFormulaMode && eMode != SC_INPUT_TOP ) 1604*cdf0e10cSrcweir { 1605*cdf0e10cSrcweir if ( pTableView && !pTableView->HasSelection() ) // Selektion ist immer unten 1606*cdf0e10cSrcweir { 1607*cdf0e10cSrcweir ESelection aSel = pTableView->GetSelection(); 1608*cdf0e10cSrcweir if (aSel.nStartPos) 1609*cdf0e10cSrcweir { 1610*cdf0e10cSrcweir // Das Zeichen links vom Cursor wird angeschaut 1611*cdf0e10cSrcweir 1612*cdf0e10cSrcweir xub_StrLen nPos = aSel.nStartPos - 1; 1613*cdf0e10cSrcweir String aFormula = pEngine->GetText((sal_uInt16)0); 1614*cdf0e10cSrcweir sal_Unicode c = aFormula.GetChar(nPos); 1615*cdf0e10cSrcweir if ( c == '(' || c == ')' ) 1616*cdf0e10cSrcweir { 1617*cdf0e10cSrcweir xub_StrLen nOther = lcl_MatchParenthesis( aFormula, nPos ); 1618*cdf0e10cSrcweir if ( nOther != STRING_NOTFOUND ) 1619*cdf0e10cSrcweir { 1620*cdf0e10cSrcweir SfxItemSet aSet( pEngine->GetEmptyItemSet() ); 1621*cdf0e10cSrcweir aSet.Put( SvxWeightItem( WEIGHT_BOLD, EE_CHAR_WEIGHT ) ); 1622*cdf0e10cSrcweir //! Unterscheidung, wenn die Zelle schon fett ist !!!! 1623*cdf0e10cSrcweir 1624*cdf0e10cSrcweir if (bParenthesisShown) 1625*cdf0e10cSrcweir { 1626*cdf0e10cSrcweir // alte Hervorhebung wegnehmen 1627*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetParagraphCount(); 1628*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 1629*cdf0e10cSrcweir pEngine->QuickRemoveCharAttribs( i, EE_CHAR_WEIGHT ); 1630*cdf0e10cSrcweir } 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir ESelection aSelThis( 0,nPos, 0,nPos+1 ); 1633*cdf0e10cSrcweir pEngine->QuickSetAttribs( aSet, aSelThis ); 1634*cdf0e10cSrcweir ESelection aSelOther( 0,nOther, 0,nOther+1 ); 1635*cdf0e10cSrcweir pEngine->QuickSetAttribs( aSet, aSelOther ); 1636*cdf0e10cSrcweir 1637*cdf0e10cSrcweir // Dummy-InsertText fuer Update und Paint (Selektion ist leer) 1638*cdf0e10cSrcweir pTableView->InsertText( EMPTY_STRING, sal_False ); 1639*cdf0e10cSrcweir 1640*cdf0e10cSrcweir bFound = sal_True; 1641*cdf0e10cSrcweir } 1642*cdf0e10cSrcweir } 1643*cdf0e10cSrcweir } 1644*cdf0e10cSrcweir 1645*cdf0e10cSrcweir // mark parenthesis right of cursor if it will be overwritten (nAutoPar) 1646*cdf0e10cSrcweir // with different color (COL_LIGHTBLUE) ?? 1647*cdf0e10cSrcweir } 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir 1650*cdf0e10cSrcweir // alte Hervorhebung wegnehmen, wenn keine neue gesetzt 1651*cdf0e10cSrcweir 1652*cdf0e10cSrcweir if ( bParenthesisShown && !bFound && pTableView ) 1653*cdf0e10cSrcweir { 1654*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetParagraphCount(); 1655*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 1656*cdf0e10cSrcweir pTableView->RemoveCharAttribs( i, EE_CHAR_WEIGHT ); 1657*cdf0e10cSrcweir } 1658*cdf0e10cSrcweir 1659*cdf0e10cSrcweir bParenthesisShown = bFound; 1660*cdf0e10cSrcweir } 1661*cdf0e10cSrcweir 1662*cdf0e10cSrcweir void ScInputHandler::ViewShellGone(ScTabViewShell* pViewSh) // wird synchron aufgerufen! 1663*cdf0e10cSrcweir { 1664*cdf0e10cSrcweir if ( pViewSh == pActiveViewSh ) 1665*cdf0e10cSrcweir { 1666*cdf0e10cSrcweir delete pLastState; 1667*cdf0e10cSrcweir pLastState = NULL; 1668*cdf0e10cSrcweir pLastPattern = NULL; 1669*cdf0e10cSrcweir } 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir if ( pViewSh == pRefViewSh ) 1672*cdf0e10cSrcweir { 1673*cdf0e10cSrcweir //! Die Eingabe kommt aus dem EnterHandler nicht mehr an 1674*cdf0e10cSrcweir // Trotzdem wird immerhin der Editmodus beendet 1675*cdf0e10cSrcweir 1676*cdf0e10cSrcweir EnterHandler(); 1677*cdf0e10cSrcweir bFormulaMode = sal_False; 1678*cdf0e10cSrcweir pRefViewSh = NULL; 1679*cdf0e10cSrcweir SFX_APP()->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) ); 1680*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(NULL); 1681*cdf0e10cSrcweir if (pInputWin) 1682*cdf0e10cSrcweir pInputWin->SetFormulaMode(sal_False); 1683*cdf0e10cSrcweir UpdateAutoCorrFlag(); 1684*cdf0e10cSrcweir } 1685*cdf0e10cSrcweir 1686*cdf0e10cSrcweir pActiveViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); 1687*cdf0e10cSrcweir 1688*cdf0e10cSrcweir if ( pActiveViewSh && pActiveViewSh == pViewSh ) 1689*cdf0e10cSrcweir { 1690*cdf0e10cSrcweir DBG_ERROR("pActiveViewSh weg"); 1691*cdf0e10cSrcweir pActiveViewSh = NULL; 1692*cdf0e10cSrcweir } 1693*cdf0e10cSrcweir 1694*cdf0e10cSrcweir if ( SC_MOD()->GetInputOptions().GetTextWysiwyg() ) 1695*cdf0e10cSrcweir UpdateRefDevice(); // don't keep old document's printer as RefDevice 1696*cdf0e10cSrcweir } 1697*cdf0e10cSrcweir 1698*cdf0e10cSrcweir void ScInputHandler::UpdateActiveView() 1699*cdf0e10cSrcweir { 1700*cdf0e10cSrcweir ImplCreateEditEngine(); 1701*cdf0e10cSrcweir 1702*cdf0e10cSrcweir // #i20588# Don't rely on focus to find the active edit view. Instead, the 1703*cdf0e10cSrcweir // active pane at the start of editing is now stored (GetEditActivePart). 1704*cdf0e10cSrcweir // GetActiveWin (the currently active pane) fails for ref input across the 1705*cdf0e10cSrcweir // panes of a split view. 1706*cdf0e10cSrcweir 1707*cdf0e10cSrcweir Window* pShellWin = pActiveViewSh ? 1708*cdf0e10cSrcweir pActiveViewSh->GetWindowByPos( pActiveViewSh->GetViewData()->GetEditActivePart() ) : 1709*cdf0e10cSrcweir NULL; 1710*cdf0e10cSrcweir 1711*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetViewCount(); 1712*cdf0e10cSrcweir if (nCount > 0) 1713*cdf0e10cSrcweir { 1714*cdf0e10cSrcweir pTableView = pEngine->GetView(0); 1715*cdf0e10cSrcweir for (sal_uInt16 i=1; i<nCount; i++) 1716*cdf0e10cSrcweir { 1717*cdf0e10cSrcweir EditView* pThis = pEngine->GetView(i); 1718*cdf0e10cSrcweir Window* pWin = pThis->GetWindow(); 1719*cdf0e10cSrcweir if ( pWin==pShellWin ) 1720*cdf0e10cSrcweir pTableView = pThis; 1721*cdf0e10cSrcweir } 1722*cdf0e10cSrcweir } 1723*cdf0e10cSrcweir else 1724*cdf0e10cSrcweir pTableView = NULL; 1725*cdf0e10cSrcweir 1726*cdf0e10cSrcweir if (pInputWin) 1727*cdf0e10cSrcweir pTopView = pInputWin->GetEditView(); 1728*cdf0e10cSrcweir else 1729*cdf0e10cSrcweir pTopView = NULL; 1730*cdf0e10cSrcweir } 1731*cdf0e10cSrcweir 1732*cdf0e10cSrcweir void ScInputHandler::StopInputWinEngine( sal_Bool bAll ) 1733*cdf0e10cSrcweir { 1734*cdf0e10cSrcweir if (pInputWin) 1735*cdf0e10cSrcweir pInputWin->StopEditEngine( bAll ); 1736*cdf0e10cSrcweir 1737*cdf0e10cSrcweir pTopView = NULL; // invalid now 1738*cdf0e10cSrcweir } 1739*cdf0e10cSrcweir 1740*cdf0e10cSrcweir EditView* ScInputHandler::GetActiveView() 1741*cdf0e10cSrcweir { 1742*cdf0e10cSrcweir UpdateActiveView(); 1743*cdf0e10cSrcweir return pTopView ? pTopView : pTableView; 1744*cdf0e10cSrcweir } 1745*cdf0e10cSrcweir 1746*cdf0e10cSrcweir void ScInputHandler::ForgetLastPattern() 1747*cdf0e10cSrcweir { 1748*cdf0e10cSrcweir pLastPattern = NULL; 1749*cdf0e10cSrcweir if ( !pLastState && pActiveViewSh ) 1750*cdf0e10cSrcweir pActiveViewSh->UpdateInputHandler( sal_True ); // Status neu holen 1751*cdf0e10cSrcweir else 1752*cdf0e10cSrcweir NotifyChange( pLastState, sal_True ); 1753*cdf0e10cSrcweir } 1754*cdf0e10cSrcweir 1755*cdf0e10cSrcweir void ScInputHandler::UpdateAdjust( sal_Unicode cTyped ) 1756*cdf0e10cSrcweir { 1757*cdf0e10cSrcweir SvxAdjust eSvxAdjust; 1758*cdf0e10cSrcweir switch (eAttrAdjust) 1759*cdf0e10cSrcweir { 1760*cdf0e10cSrcweir case SVX_HOR_JUSTIFY_STANDARD: 1761*cdf0e10cSrcweir { 1762*cdf0e10cSrcweir sal_Bool bNumber = sal_False; 1763*cdf0e10cSrcweir if (cTyped) // neu angefangen 1764*cdf0e10cSrcweir bNumber = (cTyped>='0' && cTyped<='9'); // nur Ziffern sind Zahlen 1765*cdf0e10cSrcweir else if ( pActiveViewSh ) 1766*cdf0e10cSrcweir { 1767*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 1768*cdf0e10cSrcweir bNumber = ( pDoc->GetCellType( aCursorPos ) == CELLTYPE_VALUE ); 1769*cdf0e10cSrcweir } 1770*cdf0e10cSrcweir eSvxAdjust = bNumber ? SVX_ADJUST_RIGHT : SVX_ADJUST_LEFT; 1771*cdf0e10cSrcweir } 1772*cdf0e10cSrcweir break; 1773*cdf0e10cSrcweir case SVX_HOR_JUSTIFY_BLOCK: 1774*cdf0e10cSrcweir eSvxAdjust = SVX_ADJUST_BLOCK; 1775*cdf0e10cSrcweir break; 1776*cdf0e10cSrcweir case SVX_HOR_JUSTIFY_CENTER: 1777*cdf0e10cSrcweir eSvxAdjust = SVX_ADJUST_CENTER; 1778*cdf0e10cSrcweir break; 1779*cdf0e10cSrcweir case SVX_HOR_JUSTIFY_RIGHT: 1780*cdf0e10cSrcweir eSvxAdjust = SVX_ADJUST_RIGHT; 1781*cdf0e10cSrcweir break; 1782*cdf0e10cSrcweir default: // SVX_HOR_JUSTIFY_LEFT 1783*cdf0e10cSrcweir eSvxAdjust = SVX_ADJUST_LEFT; 1784*cdf0e10cSrcweir break; 1785*cdf0e10cSrcweir } 1786*cdf0e10cSrcweir 1787*cdf0e10cSrcweir sal_Bool bAsianVertical = pLastPattern && 1788*cdf0e10cSrcweir ((const SfxBoolItem&)pLastPattern->GetItem( ATTR_STACKED )).GetValue() && 1789*cdf0e10cSrcweir ((const SfxBoolItem&)pLastPattern->GetItem( ATTR_VERTICAL_ASIAN )).GetValue(); 1790*cdf0e10cSrcweir if ( bAsianVertical ) 1791*cdf0e10cSrcweir { 1792*cdf0e10cSrcweir // always edit at top of cell -> LEFT when editing vertically 1793*cdf0e10cSrcweir eSvxAdjust = SVX_ADJUST_LEFT; 1794*cdf0e10cSrcweir } 1795*cdf0e10cSrcweir 1796*cdf0e10cSrcweir pEditDefaults->Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) ); 1797*cdf0e10cSrcweir pEngine->SetDefaults( *pEditDefaults ); 1798*cdf0e10cSrcweir 1799*cdf0e10cSrcweir nEditAdjust = sal::static_int_cast<sal_uInt16>(eSvxAdjust); //! set at ViewData or with PostEditView 1800*cdf0e10cSrcweir 1801*cdf0e10cSrcweir pEngine->SetVertical( bAsianVertical ); 1802*cdf0e10cSrcweir } 1803*cdf0e10cSrcweir 1804*cdf0e10cSrcweir void ScInputHandler::RemoveAdjust() 1805*cdf0e10cSrcweir { 1806*cdf0e10cSrcweir // harte Ausrichtungs-Attribute loeschen 1807*cdf0e10cSrcweir 1808*cdf0e10cSrcweir sal_Bool bUndo = pEngine->IsUndoEnabled(); 1809*cdf0e10cSrcweir if ( bUndo ) 1810*cdf0e10cSrcweir pEngine->EnableUndo( sal_False ); 1811*cdf0e10cSrcweir 1812*cdf0e10cSrcweir // RemoveParaAttribs removes all paragraph attributes, including EE_PARA_JUST 1813*cdf0e10cSrcweir #if 0 1814*cdf0e10cSrcweir sal_Bool bChange = sal_False; 1815*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetParagraphCount(); 1816*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 1817*cdf0e10cSrcweir { 1818*cdf0e10cSrcweir const SfxItemSet& rOld = pEngine->GetParaAttribs( i ); 1819*cdf0e10cSrcweir if ( rOld.GetItemState( EE_PARA_JUST ) == SFX_ITEM_SET ) 1820*cdf0e10cSrcweir { 1821*cdf0e10cSrcweir SfxItemSet aNew( rOld ); 1822*cdf0e10cSrcweir aNew.ClearItem( EE_PARA_JUST ); 1823*cdf0e10cSrcweir pEngine->SetParaAttribs( i, aNew ); 1824*cdf0e10cSrcweir bChange = sal_True; 1825*cdf0e10cSrcweir } 1826*cdf0e10cSrcweir } 1827*cdf0e10cSrcweir #endif 1828*cdf0e10cSrcweir 1829*cdf0e10cSrcweir // #89403# non-default paragraph attributes (e.g. from clipboard) 1830*cdf0e10cSrcweir // must be turned into character attributes 1831*cdf0e10cSrcweir pEngine->RemoveParaAttribs(); 1832*cdf0e10cSrcweir 1833*cdf0e10cSrcweir if ( bUndo ) 1834*cdf0e10cSrcweir pEngine->EnableUndo( sal_True ); 1835*cdf0e10cSrcweir 1836*cdf0e10cSrcweir // ER 31.08.00 Only called in EnterHandler, don't change view anymore. 1837*cdf0e10cSrcweir #if 0 1838*cdf0e10cSrcweir if (bChange) 1839*cdf0e10cSrcweir { 1840*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1841*cdf0e10cSrcweir pActiveView->ShowCursor( sal_False, sal_True ); 1842*cdf0e10cSrcweir } 1843*cdf0e10cSrcweir #endif 1844*cdf0e10cSrcweir } 1845*cdf0e10cSrcweir 1846*cdf0e10cSrcweir void ScInputHandler::RemoveRangeFinder() 1847*cdf0e10cSrcweir { 1848*cdf0e10cSrcweir // pRangeFindList und Farben loeschen 1849*cdf0e10cSrcweir 1850*cdf0e10cSrcweir pEngine->SetUpdateMode(sal_False); 1851*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetParagraphCount(); // koennte gerade neu eingefuegt worden sein 1852*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 1853*cdf0e10cSrcweir pEngine->QuickRemoveCharAttribs( i, EE_CHAR_COLOR ); 1854*cdf0e10cSrcweir pEngine->SetUpdateMode(sal_True); 1855*cdf0e10cSrcweir 1856*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 1857*cdf0e10cSrcweir pActiveView->ShowCursor( sal_False, sal_True ); 1858*cdf0e10cSrcweir 1859*cdf0e10cSrcweir DeleteRangeFinder(); // loescht die Liste und die Markierungen auf der Tabelle 1860*cdf0e10cSrcweir } 1861*cdf0e10cSrcweir 1862*cdf0e10cSrcweir sal_Bool ScInputHandler::StartTable( sal_Unicode cTyped, sal_Bool bFromCommand ) 1863*cdf0e10cSrcweir { 1864*cdf0e10cSrcweir // returns sal_True if a new edit mode was started 1865*cdf0e10cSrcweir 1866*cdf0e10cSrcweir sal_Bool bNewTable = sal_False; 1867*cdf0e10cSrcweir 1868*cdf0e10cSrcweir if (!bModified && ValidCol(aCursorPos.Col())) 1869*cdf0e10cSrcweir { 1870*cdf0e10cSrcweir if (pActiveViewSh) 1871*cdf0e10cSrcweir { 1872*cdf0e10cSrcweir ImplCreateEditEngine(); 1873*cdf0e10cSrcweir UpdateActiveView(); 1874*cdf0e10cSrcweir SyncViews(); 1875*cdf0e10cSrcweir 1876*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument(); 1877*cdf0e10cSrcweir 1878*cdf0e10cSrcweir const ScMarkData& rMark = pActiveViewSh->GetViewData()->GetMarkData(); 1879*cdf0e10cSrcweir ScEditableTester aTester; 1880*cdf0e10cSrcweir if ( rMark.IsMarked() || rMark.IsMultiMarked() ) 1881*cdf0e10cSrcweir aTester.TestSelection( pDoc, rMark ); 1882*cdf0e10cSrcweir else 1883*cdf0e10cSrcweir aTester.TestSelectedBlock( pDoc, aCursorPos.Col(),aCursorPos.Row(), 1884*cdf0e10cSrcweir aCursorPos.Col(),aCursorPos.Row(), rMark ); 1885*cdf0e10cSrcweir if ( aTester.IsEditable() ) 1886*cdf0e10cSrcweir { 1887*cdf0e10cSrcweir // UpdateMode is enabled again in ScViewData::SetEditEngine (and not needed otherwise) 1888*cdf0e10cSrcweir pEngine->SetUpdateMode( sal_False ); 1889*cdf0e10cSrcweir 1890*cdf0e10cSrcweir // Attribute in EditEngine uebernehmen 1891*cdf0e10cSrcweir 1892*cdf0e10cSrcweir const ScPatternAttr* pPattern = pDoc->GetPattern( aCursorPos.Col(), 1893*cdf0e10cSrcweir aCursorPos.Row(), 1894*cdf0e10cSrcweir aCursorPos.Tab() ); 1895*cdf0e10cSrcweir if (pPattern != pLastPattern) 1896*cdf0e10cSrcweir { 1897*cdf0e10cSrcweir // Prozent-Format? 1898*cdf0e10cSrcweir 1899*cdf0e10cSrcweir const SfxItemSet& rAttrSet = pPattern->GetItemSet(); 1900*cdf0e10cSrcweir const SfxPoolItem* pItem; 1901*cdf0e10cSrcweir 1902*cdf0e10cSrcweir if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALUE_FORMAT, sal_True, &pItem ) ) 1903*cdf0e10cSrcweir { 1904*cdf0e10cSrcweir sal_uLong nFormat = ((const SfxUInt32Item*)pItem)->GetValue(); 1905*cdf0e10cSrcweir bCellHasPercentFormat = ( NUMBERFORMAT_PERCENT == 1906*cdf0e10cSrcweir pDoc->GetFormatTable()->GetType( nFormat ) ); 1907*cdf0e10cSrcweir } 1908*cdf0e10cSrcweir else 1909*cdf0e10cSrcweir bCellHasPercentFormat = sal_False; // Default: kein Prozent 1910*cdf0e10cSrcweir 1911*cdf0e10cSrcweir // Gueltigkeit angegeben? 1912*cdf0e10cSrcweir 1913*cdf0e10cSrcweir if ( SFX_ITEM_SET == rAttrSet.GetItemState( ATTR_VALIDDATA, sal_True, &pItem ) ) 1914*cdf0e10cSrcweir nValidation = ((const SfxUInt32Item*)pItem)->GetValue(); 1915*cdf0e10cSrcweir else 1916*cdf0e10cSrcweir nValidation = 0; 1917*cdf0e10cSrcweir 1918*cdf0e10cSrcweir // EditEngine Defaults 1919*cdf0e10cSrcweir 1920*cdf0e10cSrcweir // Hier auf keinen Fall SetParaAttribs, weil die EditEngine evtl. 1921*cdf0e10cSrcweir // schon gefuellt ist (bei Edit-Zellen). 1922*cdf0e10cSrcweir // SetParaAttribs wuerde dann den Inhalt aendern 1923*cdf0e10cSrcweir 1924*cdf0e10cSrcweir //! ER 30.08.00 The SetDefaults is now (since MUST/src602 1925*cdf0e10cSrcweir //! EditEngine changes) implemented as a SetParaAttribs. 1926*cdf0e10cSrcweir //! Any problems? 1927*cdf0e10cSrcweir 1928*cdf0e10cSrcweir pPattern->FillEditItemSet( pEditDefaults ); 1929*cdf0e10cSrcweir pEngine->SetDefaults( *pEditDefaults ); 1930*cdf0e10cSrcweir pLastPattern = pPattern; 1931*cdf0e10cSrcweir bLastIsSymbol = pPattern->IsSymbolFont(); 1932*cdf0e10cSrcweir 1933*cdf0e10cSrcweir // Background color must be known for automatic font color. 1934*cdf0e10cSrcweir // For transparent cell background, the document background color must be used. 1935*cdf0e10cSrcweir 1936*cdf0e10cSrcweir Color aBackCol = ((const SvxBrushItem&) 1937*cdf0e10cSrcweir pPattern->GetItem( ATTR_BACKGROUND )).GetColor(); 1938*cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 1939*cdf0e10cSrcweir // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed sal_True) 1940*cdf0e10cSrcweir if ( aBackCol.GetTransparency() > 0 || 1941*cdf0e10cSrcweir Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 1942*cdf0e10cSrcweir aBackCol.SetColor( pScMod->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor ); 1943*cdf0e10cSrcweir pEngine->SetBackgroundColor( aBackCol ); 1944*cdf0e10cSrcweir 1945*cdf0e10cSrcweir // Ausrichtung 1946*cdf0e10cSrcweir 1947*cdf0e10cSrcweir eAttrAdjust = (SvxCellHorJustify)((const SvxHorJustifyItem&)pPattern-> 1948*cdf0e10cSrcweir GetItem(ATTR_HOR_JUSTIFY)).GetValue(); 1949*cdf0e10cSrcweir if ( eAttrAdjust == SVX_HOR_JUSTIFY_REPEAT && 1950*cdf0e10cSrcweir static_cast<const SfxBoolItem&>(pPattern->GetItem(ATTR_LINEBREAK)).GetValue() ) 1951*cdf0e10cSrcweir { 1952*cdf0e10cSrcweir // #i31843# "repeat" with "line breaks" is treated as default alignment 1953*cdf0e10cSrcweir eAttrAdjust = SVX_HOR_JUSTIFY_STANDARD; 1954*cdf0e10cSrcweir } 1955*cdf0e10cSrcweir } 1956*cdf0e10cSrcweir 1957*cdf0e10cSrcweir // UpdateSpellSettings enables online spelling if needed 1958*cdf0e10cSrcweir // -> also call if attributes are unchanged 1959*cdf0e10cSrcweir 1960*cdf0e10cSrcweir UpdateSpellSettings( sal_True ); // uses pLastPattern 1961*cdf0e10cSrcweir 1962*cdf0e10cSrcweir // Edit-Engine fuellen 1963*cdf0e10cSrcweir 1964*cdf0e10cSrcweir String aStr; 1965*cdf0e10cSrcweir if (bTextValid) 1966*cdf0e10cSrcweir { 1967*cdf0e10cSrcweir pEngine->SetText(aCurrentText); 1968*cdf0e10cSrcweir aStr = aCurrentText; 1969*cdf0e10cSrcweir bTextValid = sal_False; 1970*cdf0e10cSrcweir aCurrentText.Erase(); 1971*cdf0e10cSrcweir } 1972*cdf0e10cSrcweir else 1973*cdf0e10cSrcweir aStr = GetEditText(pEngine); 1974*cdf0e10cSrcweir 1975*cdf0e10cSrcweir if (aStr.Len() > 3 && // Matrix-Formel ? 1976*cdf0e10cSrcweir aStr.GetChar(0) == '{' && 1977*cdf0e10cSrcweir aStr.GetChar(1) == '=' && 1978*cdf0e10cSrcweir aStr.GetChar(aStr.Len()-1) == '}') 1979*cdf0e10cSrcweir { 1980*cdf0e10cSrcweir aStr.Erase(0,1); 1981*cdf0e10cSrcweir aStr.Erase(aStr.Len()-1,1); 1982*cdf0e10cSrcweir pEngine->SetText(aStr); 1983*cdf0e10cSrcweir if ( pInputWin ) 1984*cdf0e10cSrcweir pInputWin->SetTextString(aStr); 1985*cdf0e10cSrcweir } 1986*cdf0e10cSrcweir 1987*cdf0e10cSrcweir UpdateAdjust( cTyped ); 1988*cdf0e10cSrcweir 1989*cdf0e10cSrcweir if ( bAutoComplete ) 1990*cdf0e10cSrcweir GetColData(); 1991*cdf0e10cSrcweir 1992*cdf0e10cSrcweir if ( ( aStr.GetChar(0) == '=' || aStr.GetChar(0) == '+' || aStr.GetChar(0) == '-' ) && 1993*cdf0e10cSrcweir !cTyped && !bCreatingFuncView ) 1994*cdf0e10cSrcweir InitRangeFinder(aStr); // Formel wird editiert -> RangeFinder 1995*cdf0e10cSrcweir 1996*cdf0e10cSrcweir bNewTable = sal_True; // -> PostEditView-Aufruf 1997*cdf0e10cSrcweir } 1998*cdf0e10cSrcweir else 1999*cdf0e10cSrcweir { 2000*cdf0e10cSrcweir bProtected = sal_True; 2001*cdf0e10cSrcweir eMode = SC_INPUT_NONE; 2002*cdf0e10cSrcweir StopInputWinEngine( sal_True ); 2003*cdf0e10cSrcweir UpdateFormulaMode(); 2004*cdf0e10cSrcweir if ( pActiveViewSh && ( !bFromCommand || !bCommandErrorShown ) ) 2005*cdf0e10cSrcweir { 2006*cdf0e10cSrcweir // #97673# Prevent repeated error messages for the same cell from command events 2007*cdf0e10cSrcweir // (for keyboard events, multiple messages are wanted). 2008*cdf0e10cSrcweir // Set the flag before showing the error message because the command handler 2009*cdf0e10cSrcweir // for the next IME command may be called when showing the dialog. 2010*cdf0e10cSrcweir if ( bFromCommand ) 2011*cdf0e10cSrcweir bCommandErrorShown = sal_True; 2012*cdf0e10cSrcweir 2013*cdf0e10cSrcweir pActiveViewSh->GetActiveWin()->GrabFocus(); 2014*cdf0e10cSrcweir pActiveViewSh->ErrorMessage(aTester.GetMessageId()); 2015*cdf0e10cSrcweir } 2016*cdf0e10cSrcweir } 2017*cdf0e10cSrcweir } 2018*cdf0e10cSrcweir 2019*cdf0e10cSrcweir if (!bProtected && pInputWin) 2020*cdf0e10cSrcweir pInputWin->SetOkCancelMode(); 2021*cdf0e10cSrcweir } 2022*cdf0e10cSrcweir 2023*cdf0e10cSrcweir return bNewTable; 2024*cdf0e10cSrcweir } 2025*cdf0e10cSrcweir 2026*cdf0e10cSrcweir void lcl_SetTopSelection( EditView* pEditView, ESelection& rSel ) 2027*cdf0e10cSrcweir { 2028*cdf0e10cSrcweir DBG_ASSERT( rSel.nStartPara==0 && rSel.nEndPara==0, "SetTopSelection: Para != 0" ); 2029*cdf0e10cSrcweir 2030*cdf0e10cSrcweir EditEngine* pEngine = pEditView->GetEditEngine(); 2031*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetParagraphCount(); 2032*cdf0e10cSrcweir if (nCount > 1) 2033*cdf0e10cSrcweir { 2034*cdf0e10cSrcweir xub_StrLen nParLen = pEngine->GetTextLen(rSel.nStartPara); 2035*cdf0e10cSrcweir while (rSel.nStartPos > nParLen && rSel.nStartPara+1 < nCount) 2036*cdf0e10cSrcweir { 2037*cdf0e10cSrcweir rSel.nStartPos -= nParLen + 1; // incl. Leerzeichen vom Umbruch 2038*cdf0e10cSrcweir nParLen = pEngine->GetTextLen(++rSel.nStartPara); 2039*cdf0e10cSrcweir } 2040*cdf0e10cSrcweir 2041*cdf0e10cSrcweir nParLen = pEngine->GetTextLen(rSel.nEndPara); 2042*cdf0e10cSrcweir while (rSel.nEndPos > nParLen && rSel.nEndPara+1 < nCount) 2043*cdf0e10cSrcweir { 2044*cdf0e10cSrcweir rSel.nEndPos -= nParLen + 1; // incl. Leerzeichen vom Umbruch 2045*cdf0e10cSrcweir nParLen = pEngine->GetTextLen(++rSel.nEndPara); 2046*cdf0e10cSrcweir } 2047*cdf0e10cSrcweir } 2048*cdf0e10cSrcweir 2049*cdf0e10cSrcweir ESelection aSel = pEditView->GetSelection(); 2050*cdf0e10cSrcweir 2051*cdf0e10cSrcweir if ( rSel.nStartPara != aSel.nStartPara || rSel.nEndPara != aSel.nEndPara 2052*cdf0e10cSrcweir || rSel.nStartPos != aSel.nStartPos || rSel.nEndPos != aSel.nEndPos ) 2053*cdf0e10cSrcweir pEditView->SetSelection( rSel ); 2054*cdf0e10cSrcweir } 2055*cdf0e10cSrcweir 2056*cdf0e10cSrcweir void ScInputHandler::SyncViews( EditView* pSourceView ) 2057*cdf0e10cSrcweir { 2058*cdf0e10cSrcweir ESelection aSel; 2059*cdf0e10cSrcweir 2060*cdf0e10cSrcweir if (pSourceView) 2061*cdf0e10cSrcweir { 2062*cdf0e10cSrcweir aSel = pSourceView->GetSelection(); 2063*cdf0e10cSrcweir if (pTopView && pTopView != pSourceView) 2064*cdf0e10cSrcweir pTopView->SetSelection( aSel ); 2065*cdf0e10cSrcweir if (pTableView && pTableView != pSourceView) 2066*cdf0e10cSrcweir lcl_SetTopSelection( pTableView, aSel ); 2067*cdf0e10cSrcweir } 2068*cdf0e10cSrcweir else if (pTopView && pTableView) 2069*cdf0e10cSrcweir { 2070*cdf0e10cSrcweir aSel = pTopView->GetSelection(); 2071*cdf0e10cSrcweir lcl_SetTopSelection( pTableView, aSel ); 2072*cdf0e10cSrcweir } 2073*cdf0e10cSrcweir } 2074*cdf0e10cSrcweir 2075*cdf0e10cSrcweir IMPL_LINK( ScInputHandler, ModifyHdl, void *, EMPTYARG ) 2076*cdf0e10cSrcweir { 2077*cdf0e10cSrcweir if ( !bInOwnChange && ( eMode==SC_INPUT_TYPE || eMode==SC_INPUT_TABLE ) && 2078*cdf0e10cSrcweir pEngine && pEngine->GetUpdateMode() && pInputWin ) 2079*cdf0e10cSrcweir { 2080*cdf0e10cSrcweir // #102745# update input line from ModifyHdl for changes that are not 2081*cdf0e10cSrcweir // wrapped by DataChanging/DataChanged calls (like Drag&Drop) 2082*cdf0e10cSrcweir 2083*cdf0e10cSrcweir String aText = GetEditText(pEngine); 2084*cdf0e10cSrcweir lcl_RemoveTabs(aText); 2085*cdf0e10cSrcweir pInputWin->SetTextString(aText); 2086*cdf0e10cSrcweir } 2087*cdf0e10cSrcweir return 0; 2088*cdf0e10cSrcweir } 2089*cdf0e10cSrcweir 2090*cdf0e10cSrcweir sal_Bool ScInputHandler::DataChanging( sal_Unicode cTyped, sal_Bool bFromCommand ) // return sal_True = new view created 2091*cdf0e10cSrcweir { 2092*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset in DataChanged) 2093*cdf0e10cSrcweir 2094*cdf0e10cSrcweir if ( eMode == SC_INPUT_NONE ) 2095*cdf0e10cSrcweir return StartTable( cTyped, bFromCommand ); 2096*cdf0e10cSrcweir else 2097*cdf0e10cSrcweir return sal_False; 2098*cdf0e10cSrcweir } 2099*cdf0e10cSrcweir 2100*cdf0e10cSrcweir void ScInputHandler::DataChanged( sal_Bool bFromTopNotify, sal_Bool bSetModified ) 2101*cdf0e10cSrcweir { 2102*cdf0e10cSrcweir ImplCreateEditEngine(); 2103*cdf0e10cSrcweir 2104*cdf0e10cSrcweir if (eMode==SC_INPUT_NONE) 2105*cdf0e10cSrcweir eMode = SC_INPUT_TYPE; 2106*cdf0e10cSrcweir 2107*cdf0e10cSrcweir if ( eMode == SC_INPUT_TOP && pTopView && !bFromTopNotify ) 2108*cdf0e10cSrcweir { 2109*cdf0e10cSrcweir // table EditEngine is formatted below, input line needs formatting after paste 2110*cdf0e10cSrcweir // #i20282# not when called from the input line's modify handler 2111*cdf0e10cSrcweir pTopView->GetEditEngine()->QuickFormatDoc( sal_True ); 2112*cdf0e10cSrcweir 2113*cdf0e10cSrcweir // #i23720# QuickFormatDoc hides the cursor, but can't show it again because it 2114*cdf0e10cSrcweir // can't safely access the EditEngine's current view, so the cursor has to be 2115*cdf0e10cSrcweir // shown again here. 2116*cdf0e10cSrcweir pTopView->ShowCursor(); 2117*cdf0e10cSrcweir } 2118*cdf0e10cSrcweir 2119*cdf0e10cSrcweir if (bSetModified) 2120*cdf0e10cSrcweir bModified = sal_True; 2121*cdf0e10cSrcweir bSelIsRef = sal_False; 2122*cdf0e10cSrcweir 2123*cdf0e10cSrcweir if ( pRangeFindList && !bInRangeUpdate ) 2124*cdf0e10cSrcweir RemoveRangeFinder(); // Attribute und Markierung loeschen 2125*cdf0e10cSrcweir 2126*cdf0e10cSrcweir UpdateParenthesis(); // Hervorhebung der Klammern neu 2127*cdf0e10cSrcweir 2128*cdf0e10cSrcweir // ER 31.08.00 New SetDefaults sets ParaAttribs, don't clear them away ... 2129*cdf0e10cSrcweir // RemoveAdjust(); // #40255# harte Ausrichtungs-Attribute loeschen 2130*cdf0e10cSrcweir 2131*cdf0e10cSrcweir if (eMode==SC_INPUT_TYPE || eMode==SC_INPUT_TABLE) 2132*cdf0e10cSrcweir { 2133*cdf0e10cSrcweir String aText = GetEditText(pEngine); 2134*cdf0e10cSrcweir lcl_RemoveTabs(aText); 2135*cdf0e10cSrcweir 2136*cdf0e10cSrcweir if ( pInputWin ) 2137*cdf0e10cSrcweir pInputWin->SetTextString(aText); 2138*cdf0e10cSrcweir } 2139*cdf0e10cSrcweir 2140*cdf0e10cSrcweir // wenn der Cursor vor dem Absatzende steht, werden Teile rechts rausgeschoben 2141*cdf0e10cSrcweir // (unabhaengig von eMode) -> View anpassen! 2142*cdf0e10cSrcweir // wenn der Cursor am Ende steht, reicht der Status-Handler an der ViewData 2143*cdf0e10cSrcweir 2144*cdf0e10cSrcweir // #93767# first make sure the status handler is called now if the cursor 2145*cdf0e10cSrcweir // is outside the visible area 2146*cdf0e10cSrcweir pEngine->QuickFormatDoc(); 2147*cdf0e10cSrcweir 2148*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 2149*cdf0e10cSrcweir if (pActiveView && pActiveViewSh) 2150*cdf0e10cSrcweir { 2151*cdf0e10cSrcweir ScViewData* pViewData = pActiveViewSh->GetViewData(); 2152*cdf0e10cSrcweir 2153*cdf0e10cSrcweir sal_Bool bNeedGrow = ( nEditAdjust != SVX_ADJUST_LEFT ); // rechtsbuendig immer 2154*cdf0e10cSrcweir if (!bNeedGrow) 2155*cdf0e10cSrcweir { 2156*cdf0e10cSrcweir // Cursor vor dem Ende? 2157*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 2158*cdf0e10cSrcweir aSel.Adjust(); 2159*cdf0e10cSrcweir bNeedGrow = ( aSel.nEndPos != pEngine->GetTextLen(aSel.nEndPara) ); 2160*cdf0e10cSrcweir } 2161*cdf0e10cSrcweir if (!bNeedGrow) 2162*cdf0e10cSrcweir { 2163*cdf0e10cSrcweir bNeedGrow = pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() ); 2164*cdf0e10cSrcweir } 2165*cdf0e10cSrcweir if (bNeedGrow) 2166*cdf0e10cSrcweir { 2167*cdf0e10cSrcweir // adjust inplace view 2168*cdf0e10cSrcweir pViewData->EditGrowY(); 2169*cdf0e10cSrcweir pViewData->EditGrowX(); 2170*cdf0e10cSrcweir } 2171*cdf0e10cSrcweir } 2172*cdf0e10cSrcweir 2173*cdf0e10cSrcweir UpdateFormulaMode(); 2174*cdf0e10cSrcweir bTextValid = sal_False; // Aenderungen sind nur in der Edit-Engine 2175*cdf0e10cSrcweir bInOwnChange = sal_False; 2176*cdf0e10cSrcweir } 2177*cdf0e10cSrcweir 2178*cdf0e10cSrcweir void ScInputHandler::UpdateFormulaMode() 2179*cdf0e10cSrcweir { 2180*cdf0e10cSrcweir SfxApplication* pSfxApp = SFX_APP(); 2181*cdf0e10cSrcweir 2182*cdf0e10cSrcweir if ( pEngine->GetParagraphCount() == 1 && 2183*cdf0e10cSrcweir ( pEngine->GetText((sal_uInt16)0).GetChar(0) == '=' || 2184*cdf0e10cSrcweir pEngine->GetText((sal_uInt16)0).GetChar(0) == '+' || 2185*cdf0e10cSrcweir pEngine->GetText((sal_uInt16)0).GetChar(0) == '-' ) && 2186*cdf0e10cSrcweir !bProtected ) 2187*cdf0e10cSrcweir { 2188*cdf0e10cSrcweir if (!bFormulaMode) 2189*cdf0e10cSrcweir { 2190*cdf0e10cSrcweir bFormulaMode = sal_True; 2191*cdf0e10cSrcweir pRefViewSh = pActiveViewSh; 2192*cdf0e10cSrcweir pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) ); 2193*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(this); 2194*cdf0e10cSrcweir if (pInputWin) 2195*cdf0e10cSrcweir pInputWin->SetFormulaMode(sal_True); 2196*cdf0e10cSrcweir 2197*cdf0e10cSrcweir if ( bAutoComplete ) 2198*cdf0e10cSrcweir GetFormulaData(); 2199*cdf0e10cSrcweir 2200*cdf0e10cSrcweir UpdateParenthesis(); 2201*cdf0e10cSrcweir UpdateAutoCorrFlag(); 2202*cdf0e10cSrcweir } 2203*cdf0e10cSrcweir } 2204*cdf0e10cSrcweir else // ausschalten 2205*cdf0e10cSrcweir { 2206*cdf0e10cSrcweir if (bFormulaMode) 2207*cdf0e10cSrcweir { 2208*cdf0e10cSrcweir ShowRefFrame(); 2209*cdf0e10cSrcweir bFormulaMode = sal_False; 2210*cdf0e10cSrcweir pRefViewSh = NULL; 2211*cdf0e10cSrcweir pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) ); 2212*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(NULL); 2213*cdf0e10cSrcweir if (pInputWin) 2214*cdf0e10cSrcweir pInputWin->SetFormulaMode(sal_False); 2215*cdf0e10cSrcweir UpdateAutoCorrFlag(); 2216*cdf0e10cSrcweir } 2217*cdf0e10cSrcweir } 2218*cdf0e10cSrcweir } 2219*cdf0e10cSrcweir 2220*cdf0e10cSrcweir void ScInputHandler::ShowRefFrame() 2221*cdf0e10cSrcweir { 2222*cdf0e10cSrcweir // #123169# Modifying pActiveViewSh here would interfere with the bInEnterHandler / bRepeat 2223*cdf0e10cSrcweir // checks in NotifyChange, and lead to keeping the wrong value in pActiveViewSh. 2224*cdf0e10cSrcweir // A local variable is used instead. 2225*cdf0e10cSrcweir ScTabViewShell* pVisibleSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); 2226*cdf0e10cSrcweir if ( pRefViewSh && pRefViewSh != pVisibleSh ) 2227*cdf0e10cSrcweir { 2228*cdf0e10cSrcweir sal_Bool bFound = sal_False; 2229*cdf0e10cSrcweir SfxViewFrame* pRefFrame = pRefViewSh->GetViewFrame(); 2230*cdf0e10cSrcweir SfxViewFrame* pOneFrame = SfxViewFrame::GetFirst(); 2231*cdf0e10cSrcweir while ( pOneFrame && !bFound ) 2232*cdf0e10cSrcweir { 2233*cdf0e10cSrcweir if ( pOneFrame == pRefFrame ) 2234*cdf0e10cSrcweir bFound = sal_True; 2235*cdf0e10cSrcweir pOneFrame = SfxViewFrame::GetNext( *pOneFrame ); 2236*cdf0e10cSrcweir } 2237*cdf0e10cSrcweir 2238*cdf0e10cSrcweir if (bFound) 2239*cdf0e10cSrcweir { 2240*cdf0e10cSrcweir // Hier wird sich darauf verlassen, dass Activate synchron funktioniert 2241*cdf0e10cSrcweir // (dabei wird pActiveViewSh umgesetzt) 2242*cdf0e10cSrcweir 2243*cdf0e10cSrcweir pRefViewSh->SetActive(); // Appear und SetViewFrame 2244*cdf0e10cSrcweir 2245*cdf0e10cSrcweir // pLastState wird im NotifyChange aus dem Activate richtig gesetzt 2246*cdf0e10cSrcweir } 2247*cdf0e10cSrcweir else 2248*cdf0e10cSrcweir { 2249*cdf0e10cSrcweir DBG_ERROR("ViewFrame fuer Referenzeingabe ist nicht mehr da"); 2250*cdf0e10cSrcweir } 2251*cdf0e10cSrcweir } 2252*cdf0e10cSrcweir } 2253*cdf0e10cSrcweir 2254*cdf0e10cSrcweir void ScInputHandler::RemoveSelection() 2255*cdf0e10cSrcweir { 2256*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 2257*cdf0e10cSrcweir if (!pActiveView) 2258*cdf0e10cSrcweir return; 2259*cdf0e10cSrcweir 2260*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 2261*cdf0e10cSrcweir aSel.nStartPara = aSel.nEndPara; 2262*cdf0e10cSrcweir aSel.nStartPos = aSel.nEndPos; 2263*cdf0e10cSrcweir if (pTableView) 2264*cdf0e10cSrcweir pTableView->SetSelection( aSel ); 2265*cdf0e10cSrcweir if (pTopView) 2266*cdf0e10cSrcweir pTopView->SetSelection( aSel ); 2267*cdf0e10cSrcweir } 2268*cdf0e10cSrcweir 2269*cdf0e10cSrcweir void ScInputHandler::InvalidateAttribs() 2270*cdf0e10cSrcweir { 2271*cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 2272*cdf0e10cSrcweir if (pViewFrm) 2273*cdf0e10cSrcweir { 2274*cdf0e10cSrcweir SfxBindings& rBindings = pViewFrm->GetBindings(); 2275*cdf0e10cSrcweir 2276*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_FONT ); 2277*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT ); 2278*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_COLOR ); 2279*cdf0e10cSrcweir 2280*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT ); 2281*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_POSTURE ); 2282*cdf0e10cSrcweir rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE ); 2283*cdf0e10cSrcweir rBindings.Invalidate( SID_ULINE_VAL_NONE ); 2284*cdf0e10cSrcweir rBindings.Invalidate( SID_ULINE_VAL_SINGLE ); 2285*cdf0e10cSrcweir rBindings.Invalidate( SID_ULINE_VAL_DOUBLE ); 2286*cdf0e10cSrcweir rBindings.Invalidate( SID_ULINE_VAL_DOTTED ); 2287*cdf0e10cSrcweir 2288*cdf0e10cSrcweir rBindings.Invalidate( SID_HYPERLINK_GETLINK ); 2289*cdf0e10cSrcweir } 2290*cdf0e10cSrcweir } 2291*cdf0e10cSrcweir 2292*cdf0e10cSrcweir 2293*cdf0e10cSrcweir // 2294*cdf0e10cSrcweir // --------------- public Methoden -------------------------------------------- 2295*cdf0e10cSrcweir // 2296*cdf0e10cSrcweir 2297*cdf0e10cSrcweir void ScInputHandler::SetMode( ScInputMode eNewMode ) 2298*cdf0e10cSrcweir { 2299*cdf0e10cSrcweir if ( eMode == eNewMode ) 2300*cdf0e10cSrcweir return; 2301*cdf0e10cSrcweir 2302*cdf0e10cSrcweir ImplCreateEditEngine(); 2303*cdf0e10cSrcweir 2304*cdf0e10cSrcweir if (bProtected) 2305*cdf0e10cSrcweir { 2306*cdf0e10cSrcweir eMode = SC_INPUT_NONE; 2307*cdf0e10cSrcweir StopInputWinEngine( sal_True ); 2308*cdf0e10cSrcweir if (pActiveViewSh) 2309*cdf0e10cSrcweir pActiveViewSh->GetActiveWin()->GrabFocus(); 2310*cdf0e10cSrcweir return; 2311*cdf0e10cSrcweir } 2312*cdf0e10cSrcweir 2313*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 2314*cdf0e10cSrcweir 2315*cdf0e10cSrcweir ScInputMode eOldMode = eMode; 2316*cdf0e10cSrcweir eMode = eNewMode; 2317*cdf0e10cSrcweir if (eOldMode == SC_INPUT_TOP && eNewMode != eOldMode) 2318*cdf0e10cSrcweir StopInputWinEngine( sal_False ); 2319*cdf0e10cSrcweir 2320*cdf0e10cSrcweir if (eMode==SC_INPUT_TOP || eMode==SC_INPUT_TABLE) 2321*cdf0e10cSrcweir { 2322*cdf0e10cSrcweir if (eOldMode == SC_INPUT_NONE) // not when switching between modes 2323*cdf0e10cSrcweir { 2324*cdf0e10cSrcweir if (StartTable(0, sal_False)) // 0 = look at existing document content for text or number 2325*cdf0e10cSrcweir { 2326*cdf0e10cSrcweir if (pActiveViewSh) 2327*cdf0e10cSrcweir pActiveViewSh->GetViewData()->GetDocShell()->PostEditView( pEngine, aCursorPos ); 2328*cdf0e10cSrcweir } 2329*cdf0e10cSrcweir } 2330*cdf0e10cSrcweir 2331*cdf0e10cSrcweir sal_uInt16 nPara = pEngine->GetParagraphCount()-1; 2332*cdf0e10cSrcweir xub_StrLen nLen = pEngine->GetText(nPara).Len(); 2333*cdf0e10cSrcweir sal_uInt16 nCount = pEngine->GetViewCount(); 2334*cdf0e10cSrcweir 2335*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 2336*cdf0e10cSrcweir { 2337*cdf0e10cSrcweir if ( eMode == SC_INPUT_TABLE && eOldMode == SC_INPUT_TOP ) 2338*cdf0e10cSrcweir { 2339*cdf0e10cSrcweir // Selektion bleibt 2340*cdf0e10cSrcweir } 2341*cdf0e10cSrcweir else 2342*cdf0e10cSrcweir { 2343*cdf0e10cSrcweir pEngine->GetView(i)-> 2344*cdf0e10cSrcweir SetSelection( ESelection( nPara, nLen, nPara, nLen ) ); 2345*cdf0e10cSrcweir } 2346*cdf0e10cSrcweir pEngine->GetView(i)->ShowCursor(sal_False); 2347*cdf0e10cSrcweir } 2348*cdf0e10cSrcweir } 2349*cdf0e10cSrcweir 2350*cdf0e10cSrcweir UpdateActiveView(); 2351*cdf0e10cSrcweir if (eMode==SC_INPUT_TABLE || eMode==SC_INPUT_TYPE) 2352*cdf0e10cSrcweir { 2353*cdf0e10cSrcweir if (pTableView) 2354*cdf0e10cSrcweir pTableView->SetEditEngineUpdateMode(sal_True); 2355*cdf0e10cSrcweir } 2356*cdf0e10cSrcweir else 2357*cdf0e10cSrcweir { 2358*cdf0e10cSrcweir if (pTopView) 2359*cdf0e10cSrcweir pTopView->SetEditEngineUpdateMode(sal_True); 2360*cdf0e10cSrcweir } 2361*cdf0e10cSrcweir 2362*cdf0e10cSrcweir if (eNewMode != eOldMode) 2363*cdf0e10cSrcweir UpdateFormulaMode(); 2364*cdf0e10cSrcweir 2365*cdf0e10cSrcweir bInOwnChange = sal_False; 2366*cdf0e10cSrcweir } 2367*cdf0e10cSrcweir 2368*cdf0e10cSrcweir //---------------------------------------------------------------------------------------- 2369*cdf0e10cSrcweir 2370*cdf0e10cSrcweir // lcl_IsNumber - sal_True, wenn nur Ziffern (dann keine Autokorrektur) 2371*cdf0e10cSrcweir 2372*cdf0e10cSrcweir sal_Bool lcl_IsNumber(const String& rString) 2373*cdf0e10cSrcweir { 2374*cdf0e10cSrcweir xub_StrLen nLen = rString.Len(); 2375*cdf0e10cSrcweir for (xub_StrLen i=0; i<nLen; i++) 2376*cdf0e10cSrcweir { 2377*cdf0e10cSrcweir sal_Unicode c = rString.GetChar(i); 2378*cdf0e10cSrcweir if ( c < '0' || c > '9' ) 2379*cdf0e10cSrcweir return sal_False; 2380*cdf0e10cSrcweir } 2381*cdf0e10cSrcweir return sal_True; 2382*cdf0e10cSrcweir } 2383*cdf0e10cSrcweir 2384*cdf0e10cSrcweir void lcl_SelectionToEnd( EditView* pView ) 2385*cdf0e10cSrcweir { 2386*cdf0e10cSrcweir if ( pView ) 2387*cdf0e10cSrcweir { 2388*cdf0e10cSrcweir EditEngine* pEngine = pView->GetEditEngine(); 2389*cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 2390*cdf0e10cSrcweir if ( nParCnt == 0 ) 2391*cdf0e10cSrcweir nParCnt = 1; 2392*cdf0e10cSrcweir ESelection aSel( nParCnt-1, pEngine->GetTextLen(nParCnt-1) ); // empty selection, cursor at the end 2393*cdf0e10cSrcweir pView->SetSelection( aSel ); 2394*cdf0e10cSrcweir } 2395*cdf0e10cSrcweir } 2396*cdf0e10cSrcweir 2397*cdf0e10cSrcweir void ScInputHandler::EnterHandler( sal_uInt8 nBlockMode ) 2398*cdf0e10cSrcweir { 2399*cdf0e10cSrcweir // #62806# Bei Makro-Aufrufen fuer Gueltigkeit kann Tod und Teufel passieren, 2400*cdf0e10cSrcweir // darum dafuer sorgen, dass EnterHandler nicht verschachtelt gerufen wird: 2401*cdf0e10cSrcweir 2402*cdf0e10cSrcweir if (bInEnterHandler) return; 2403*cdf0e10cSrcweir bInEnterHandler = sal_True; 2404*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 2405*cdf0e10cSrcweir 2406*cdf0e10cSrcweir ImplCreateEditEngine(); 2407*cdf0e10cSrcweir 2408*cdf0e10cSrcweir sal_Bool bMatrix = ( nBlockMode == SC_ENTER_MATRIX ); 2409*cdf0e10cSrcweir 2410*cdf0e10cSrcweir SfxApplication* pSfxApp = SFX_APP(); 2411*cdf0e10cSrcweir EditTextObject* pObject = NULL; 2412*cdf0e10cSrcweir ScPatternAttr* pCellAttrs = NULL; 2413*cdf0e10cSrcweir sal_Bool bAttrib = sal_False; // Formatierung vorhanden ? 2414*cdf0e10cSrcweir sal_Bool bForget = sal_False; // wegen Gueltigkeit streichen ? 2415*cdf0e10cSrcweir 2416*cdf0e10cSrcweir String aString = GetEditText(pEngine); 2417*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 2418*cdf0e10cSrcweir if (bModified && pActiveView && aString.Len() && !lcl_IsNumber(aString)) 2419*cdf0e10cSrcweir { 2420*cdf0e10cSrcweir if ( pColumnData && nAutoPos != SCPOS_INVALID ) 2421*cdf0e10cSrcweir { 2422*cdf0e10cSrcweir // #i47125# If AutoInput appended something, do the final AutoCorrect 2423*cdf0e10cSrcweir // with the cursor at the end of the input. 2424*cdf0e10cSrcweir 2425*cdf0e10cSrcweir lcl_SelectionToEnd(pTopView); 2426*cdf0e10cSrcweir lcl_SelectionToEnd(pTableView); 2427*cdf0e10cSrcweir } 2428*cdf0e10cSrcweir 2429*cdf0e10cSrcweir if (pTopView) 2430*cdf0e10cSrcweir pTopView->CompleteAutoCorrect(); // #59759# CompleteAutoCorrect fuer beide Views 2431*cdf0e10cSrcweir if (pTableView) 2432*cdf0e10cSrcweir pTableView->CompleteAutoCorrect(); 2433*cdf0e10cSrcweir aString = GetEditText(pEngine); 2434*cdf0e10cSrcweir } 2435*cdf0e10cSrcweir lcl_RemoveTabs(aString); 2436*cdf0e10cSrcweir 2437*cdf0e10cSrcweir // Test, ob zulaessig (immer mit einfachem String) 2438*cdf0e10cSrcweir 2439*cdf0e10cSrcweir if ( bModified && nValidation && pActiveViewSh ) 2440*cdf0e10cSrcweir { 2441*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocument(); 2442*cdf0e10cSrcweir const ScValidationData* pData = pDoc->GetValidationEntry( nValidation ); 2443*cdf0e10cSrcweir if (pData && pData->HasErrMsg()) 2444*cdf0e10cSrcweir { 2445*cdf0e10cSrcweir // #i67990# don't use pLastPattern in EnterHandler 2446*cdf0e10cSrcweir const ScPatternAttr* pPattern = pDoc->GetPattern( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab() ); 2447*cdf0e10cSrcweir sal_Bool bOk = pData->IsDataValid( aString, *pPattern, aCursorPos ); 2448*cdf0e10cSrcweir 2449*cdf0e10cSrcweir if (!bOk) 2450*cdf0e10cSrcweir { 2451*cdf0e10cSrcweir if ( pActiveViewSh ) // falls aus MouseButtonDown gekommen 2452*cdf0e10cSrcweir pActiveViewSh->StopMarking(); // (die InfoBox verschluckt das MouseButtonUp) 2453*cdf0e10cSrcweir 2454*cdf0e10cSrcweir //! es gibt noch Probleme, wenn die Eingabe durch Aktivieren einer 2455*cdf0e10cSrcweir //! anderen View ausgeloest wurde 2456*cdf0e10cSrcweir 2457*cdf0e10cSrcweir Window* pParent = Application::GetDefDialogParent(); 2458*cdf0e10cSrcweir if ( pData->DoError( pParent, aString, aCursorPos ) ) 2459*cdf0e10cSrcweir bForget = sal_True; // Eingabe nicht uebernehmen 2460*cdf0e10cSrcweir } 2461*cdf0e10cSrcweir } 2462*cdf0e10cSrcweir } 2463*cdf0e10cSrcweir 2464*cdf0e10cSrcweir // check for input into DataPilot table 2465*cdf0e10cSrcweir 2466*cdf0e10cSrcweir if ( bModified && pActiveViewSh && !bForget ) 2467*cdf0e10cSrcweir { 2468*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocument(); 2469*cdf0e10cSrcweir ScDPObject* pDPObj = pDoc->GetDPAtCursor( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab() ); 2470*cdf0e10cSrcweir if ( pDPObj ) 2471*cdf0e10cSrcweir { 2472*cdf0e10cSrcweir // any input within the DataPilot table is either a valid renaming 2473*cdf0e10cSrcweir // or an invalid action - normal cell input is always aborted 2474*cdf0e10cSrcweir 2475*cdf0e10cSrcweir pActiveViewSh->DataPilotInput( aCursorPos, aString ); 2476*cdf0e10cSrcweir bForget = sal_True; 2477*cdf0e10cSrcweir } 2478*cdf0e10cSrcweir } 2479*cdf0e10cSrcweir 2480*cdf0e10cSrcweir pEngine->CompleteOnlineSpelling(); 2481*cdf0e10cSrcweir sal_Bool bSpellErrors = !bFormulaMode && pEngine->HasOnlineSpellErrors(); 2482*cdf0e10cSrcweir if ( bSpellErrors ) 2483*cdf0e10cSrcweir { 2484*cdf0e10cSrcweir // #i3820# If the spell checker flags numerical input as error, 2485*cdf0e10cSrcweir // it still has to be treated as number, not EditEngine object. 2486*cdf0e10cSrcweir 2487*cdf0e10cSrcweir if ( pActiveViewSh ) 2488*cdf0e10cSrcweir { 2489*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocument(); 2490*cdf0e10cSrcweir // #i67990# don't use pLastPattern in EnterHandler 2491*cdf0e10cSrcweir const ScPatternAttr* pPattern = pDoc->GetPattern( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab() ); 2492*cdf0e10cSrcweir SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); 2493*cdf0e10cSrcweir // without conditional format, as in ScColumn::SetString 2494*cdf0e10cSrcweir sal_uInt32 nFormat = pPattern->GetNumberFormat( pFormatter ); 2495*cdf0e10cSrcweir double nVal; 2496*cdf0e10cSrcweir if ( pFormatter->IsNumberFormat( aString, nFormat, nVal ) ) 2497*cdf0e10cSrcweir { 2498*cdf0e10cSrcweir bSpellErrors = sal_False; // ignore the spelling errors 2499*cdf0e10cSrcweir } 2500*cdf0e10cSrcweir } 2501*cdf0e10cSrcweir } 2502*cdf0e10cSrcweir 2503*cdf0e10cSrcweir // After RemoveAdjust, the EditView must not be repainted (has wrong font size etc). 2504*cdf0e10cSrcweir // SetUpdateMode must come after CompleteOnlineSpelling. 2505*cdf0e10cSrcweir // The view is hidden in any case below (Broadcast). 2506*cdf0e10cSrcweir pEngine->SetUpdateMode( sal_False ); 2507*cdf0e10cSrcweir 2508*cdf0e10cSrcweir if ( bModified && !bForget ) // was wird eingeben (Text/Objekt) ? 2509*cdf0e10cSrcweir { 2510*cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 2511*cdf0e10cSrcweir if ( nParCnt == 0 ) 2512*cdf0e10cSrcweir nParCnt = 1; 2513*cdf0e10cSrcweir ESelection aSel( 0, 0, nParCnt-1, pEngine->GetTextLen(nParCnt-1) ); 2514*cdf0e10cSrcweir SfxItemSet aOldAttribs = pEngine->GetAttribs( aSel ); 2515*cdf0e10cSrcweir const SfxPoolItem* pItem = NULL; 2516*cdf0e10cSrcweir 2517*cdf0e10cSrcweir // find common (cell) attributes before RemoveAdjust 2518*cdf0e10cSrcweir 2519*cdf0e10cSrcweir if ( pActiveViewSh ) 2520*cdf0e10cSrcweir { 2521*cdf0e10cSrcweir SfxItemSet* pCommonAttrs = NULL; 2522*cdf0e10cSrcweir for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END; nId++) 2523*cdf0e10cSrcweir { 2524*cdf0e10cSrcweir SfxItemState eState = aOldAttribs.GetItemState( nId, sal_False, &pItem ); 2525*cdf0e10cSrcweir if ( eState == SFX_ITEM_SET && 2526*cdf0e10cSrcweir nId != EE_CHAR_ESCAPEMENT && nId != EE_CHAR_PAIRKERNING && 2527*cdf0e10cSrcweir nId != EE_CHAR_KERNING && nId != EE_CHAR_XMLATTRIBS && 2528*cdf0e10cSrcweir *pItem != pEditDefaults->Get(nId) ) 2529*cdf0e10cSrcweir { 2530*cdf0e10cSrcweir if ( !pCommonAttrs ) 2531*cdf0e10cSrcweir pCommonAttrs = new SfxItemSet( pEngine->GetEmptyItemSet() ); 2532*cdf0e10cSrcweir pCommonAttrs->Put( *pItem ); 2533*cdf0e10cSrcweir } 2534*cdf0e10cSrcweir } 2535*cdf0e10cSrcweir 2536*cdf0e10cSrcweir if ( pCommonAttrs ) 2537*cdf0e10cSrcweir { 2538*cdf0e10cSrcweir ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocument(); 2539*cdf0e10cSrcweir pCellAttrs = new ScPatternAttr( pDoc->GetPool() ); 2540*cdf0e10cSrcweir pCellAttrs->GetFromEditItemSet( pCommonAttrs ); 2541*cdf0e10cSrcweir delete pCommonAttrs; 2542*cdf0e10cSrcweir } 2543*cdf0e10cSrcweir } 2544*cdf0e10cSrcweir 2545*cdf0e10cSrcweir // clear ParaAttribs (including adjustment) 2546*cdf0e10cSrcweir 2547*cdf0e10cSrcweir RemoveAdjust(); 2548*cdf0e10cSrcweir 2549*cdf0e10cSrcweir // check if EditObject is needed 2550*cdf0e10cSrcweir 2551*cdf0e10cSrcweir if ( bSpellErrors || nParCnt > 1 ) 2552*cdf0e10cSrcweir bAttrib = sal_True; 2553*cdf0e10cSrcweir else 2554*cdf0e10cSrcweir { 2555*cdf0e10cSrcweir for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && !bAttrib; nId++) 2556*cdf0e10cSrcweir { 2557*cdf0e10cSrcweir SfxItemState eState = aOldAttribs.GetItemState( nId, sal_False, &pItem ); 2558*cdf0e10cSrcweir if (eState == SFX_ITEM_DONTCARE) 2559*cdf0e10cSrcweir bAttrib = sal_True; 2560*cdf0e10cSrcweir else if (eState == SFX_ITEM_SET) 2561*cdf0e10cSrcweir { 2562*cdf0e10cSrcweir // keep same items in EditEngine as in ScEditAttrTester 2563*cdf0e10cSrcweir if ( nId == EE_CHAR_ESCAPEMENT || nId == EE_CHAR_PAIRKERNING || 2564*cdf0e10cSrcweir nId == EE_CHAR_KERNING || nId == EE_CHAR_XMLATTRIBS ) 2565*cdf0e10cSrcweir { 2566*cdf0e10cSrcweir if ( *pItem != pEditDefaults->Get(nId) ) 2567*cdf0e10cSrcweir bAttrib = sal_True; 2568*cdf0e10cSrcweir } 2569*cdf0e10cSrcweir } 2570*cdf0e10cSrcweir } 2571*cdf0e10cSrcweir 2572*cdf0e10cSrcweir // Feldbefehle enthalten? 2573*cdf0e10cSrcweir 2574*cdf0e10cSrcweir SfxItemState eFieldState = aOldAttribs.GetItemState( EE_FEATURE_FIELD, sal_False ); 2575*cdf0e10cSrcweir if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET ) 2576*cdf0e10cSrcweir bAttrib = sal_True; 2577*cdf0e10cSrcweir 2578*cdf0e10cSrcweir // not converted characters? 2579*cdf0e10cSrcweir 2580*cdf0e10cSrcweir SfxItemState eConvState = aOldAttribs.GetItemState( EE_FEATURE_NOTCONV, sal_False ); 2581*cdf0e10cSrcweir if ( eConvState == SFX_ITEM_DONTCARE || eConvState == SFX_ITEM_SET ) 2582*cdf0e10cSrcweir bAttrib = sal_True; 2583*cdf0e10cSrcweir 2584*cdf0e10cSrcweir // Formeln immer als Formeln erkennen (#38309#) 2585*cdf0e10cSrcweir // (der Test vorher ist trotzdem noetig wegen Zell-Attributen) 2586*cdf0e10cSrcweir } 2587*cdf0e10cSrcweir 2588*cdf0e10cSrcweir if (bMatrix) 2589*cdf0e10cSrcweir bAttrib = sal_False; 2590*cdf0e10cSrcweir 2591*cdf0e10cSrcweir if (bAttrib) 2592*cdf0e10cSrcweir { 2593*cdf0e10cSrcweir sal_uLong nCtrl = pEngine->GetControlWord(); 2594*cdf0e10cSrcweir sal_uLong nWantBig = bSpellErrors ? EE_CNTRL_ALLOWBIGOBJS : 0; 2595*cdf0e10cSrcweir if ( ( nCtrl & EE_CNTRL_ALLOWBIGOBJS ) != nWantBig ) 2596*cdf0e10cSrcweir pEngine->SetControlWord( (nCtrl & ~EE_CNTRL_ALLOWBIGOBJS) | nWantBig ); 2597*cdf0e10cSrcweir pObject = pEngine->CreateTextObject(); 2598*cdf0e10cSrcweir } 2599*cdf0e10cSrcweir else if (bAutoComplete) // Gross-/Kleinschreibung anpassen 2600*cdf0e10cSrcweir { 2601*cdf0e10cSrcweir if (pColumnData) 2602*cdf0e10cSrcweir pColumnData->GetExactMatch( aString ); 2603*cdf0e10cSrcweir 2604*cdf0e10cSrcweir //! effizienter in der Liste suchen (ScUserList, nur einmal ToUpper) 2605*cdf0e10cSrcweir 2606*cdf0e10cSrcweir sal_uInt16 nIndex; 2607*cdf0e10cSrcweir ScUserListData* pData = ScGlobal::GetUserList()->GetData(aString); 2608*cdf0e10cSrcweir if ( pData && pData->GetSubIndex( aString, nIndex ) ) 2609*cdf0e10cSrcweir aString = pData->GetSubStr( nIndex ); 2610*cdf0e10cSrcweir } 2611*cdf0e10cSrcweir } 2612*cdf0e10cSrcweir 2613*cdf0e10cSrcweir // don't rely on ShowRefFrame switching the active view synchronously 2614*cdf0e10cSrcweir // execute the function directly on the correct view's bindings instead 2615*cdf0e10cSrcweir // pRefViewSh is reset in ShowRefFrame - get pointer before ShowRefFrame call 2616*cdf0e10cSrcweir ScTabViewShell* pExecuteSh = pRefViewSh ? pRefViewSh : pActiveViewSh; 2617*cdf0e10cSrcweir 2618*cdf0e10cSrcweir if (bFormulaMode) 2619*cdf0e10cSrcweir { 2620*cdf0e10cSrcweir ShowRefFrame(); 2621*cdf0e10cSrcweir 2622*cdf0e10cSrcweir if (pExecuteSh) 2623*cdf0e10cSrcweir { 2624*cdf0e10cSrcweir pExecuteSh->SetTabNo(aCursorPos.Tab()); 2625*cdf0e10cSrcweir pExecuteSh->ActiveGrabFocus(); 2626*cdf0e10cSrcweir } 2627*cdf0e10cSrcweir 2628*cdf0e10cSrcweir bFormulaMode = sal_False; 2629*cdf0e10cSrcweir pSfxApp->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) ); 2630*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(NULL); 2631*cdf0e10cSrcweir if (pInputWin) 2632*cdf0e10cSrcweir pInputWin->SetFormulaMode(sal_False); 2633*cdf0e10cSrcweir UpdateAutoCorrFlag(); 2634*cdf0e10cSrcweir } 2635*cdf0e10cSrcweir pRefViewSh = NULL; // auch ohne FormulaMode wegen Funktions-AP 2636*cdf0e10cSrcweir DeleteRangeFinder(); 2637*cdf0e10cSrcweir ResetAutoPar(); 2638*cdf0e10cSrcweir 2639*cdf0e10cSrcweir sal_Bool bOldMod = bModified; 2640*cdf0e10cSrcweir 2641*cdf0e10cSrcweir bModified = sal_False; 2642*cdf0e10cSrcweir bSelIsRef = sal_False; 2643*cdf0e10cSrcweir eMode = SC_INPUT_NONE; 2644*cdf0e10cSrcweir StopInputWinEngine( sal_True ); 2645*cdf0e10cSrcweir 2646*cdf0e10cSrcweir // #123344# Text input (through number formats) or ApplySelectionPattern modify 2647*cdf0e10cSrcweir // the cell's attributes, so pLastPattern is no longer valid 2648*cdf0e10cSrcweir pLastPattern = NULL; 2649*cdf0e10cSrcweir 2650*cdf0e10cSrcweir if (bOldMod && !bProtected && !bForget) 2651*cdf0e10cSrcweir { 2652*cdf0e10cSrcweir // keine typographische Anfuehrungszeichen in Formeln 2653*cdf0e10cSrcweir 2654*cdf0e10cSrcweir if ( aString.GetChar(0) == '=' ) 2655*cdf0e10cSrcweir { 2656*cdf0e10cSrcweir SvxAutoCorrect* pAuto = SvxAutoCorrCfg::Get()->GetAutoCorrect(); 2657*cdf0e10cSrcweir if ( pAuto ) 2658*cdf0e10cSrcweir { 2659*cdf0e10cSrcweir sal_Unicode cReplace = pAuto->GetStartDoubleQuote(); 2660*cdf0e10cSrcweir if( !cReplace ) 2661*cdf0e10cSrcweir cReplace = ScGlobal::pLocaleData->getDoubleQuotationMarkStart().GetChar(0); 2662*cdf0e10cSrcweir if ( cReplace != '"' ) 2663*cdf0e10cSrcweir aString.SearchAndReplaceAll( cReplace, '"' ); 2664*cdf0e10cSrcweir 2665*cdf0e10cSrcweir cReplace = pAuto->GetEndDoubleQuote(); 2666*cdf0e10cSrcweir if( !cReplace ) 2667*cdf0e10cSrcweir cReplace = ScGlobal::pLocaleData->getDoubleQuotationMarkEnd().GetChar(0); 2668*cdf0e10cSrcweir if ( cReplace != '"' ) 2669*cdf0e10cSrcweir aString.SearchAndReplaceAll( cReplace, '"' ); 2670*cdf0e10cSrcweir 2671*cdf0e10cSrcweir cReplace = pAuto->GetStartSingleQuote(); 2672*cdf0e10cSrcweir if( !cReplace ) 2673*cdf0e10cSrcweir cReplace = ScGlobal::pLocaleData->getQuotationMarkStart().GetChar(0); 2674*cdf0e10cSrcweir if ( cReplace != '\'' ) 2675*cdf0e10cSrcweir aString.SearchAndReplaceAll( cReplace, '\'' ); 2676*cdf0e10cSrcweir 2677*cdf0e10cSrcweir cReplace = pAuto->GetEndSingleQuote(); 2678*cdf0e10cSrcweir if( !cReplace ) 2679*cdf0e10cSrcweir cReplace = ScGlobal::pLocaleData->getQuotationMarkEnd().GetChar(0); 2680*cdf0e10cSrcweir if ( cReplace != '\'' ) 2681*cdf0e10cSrcweir aString.SearchAndReplaceAll( cReplace, '\'' ); 2682*cdf0e10cSrcweir } 2683*cdf0e10cSrcweir } 2684*cdf0e10cSrcweir 2685*cdf0e10cSrcweir pSfxApp->Broadcast( SfxSimpleHint( FID_KILLEDITVIEW_NOPAINT ) ); 2686*cdf0e10cSrcweir 2687*cdf0e10cSrcweir if ( pExecuteSh ) 2688*cdf0e10cSrcweir { 2689*cdf0e10cSrcweir SfxBindings& rBindings = pExecuteSh->GetViewFrame()->GetBindings(); 2690*cdf0e10cSrcweir 2691*cdf0e10cSrcweir sal_uInt16 nId = FID_INPUTLINE_ENTER; 2692*cdf0e10cSrcweir if ( nBlockMode == SC_ENTER_BLOCK ) 2693*cdf0e10cSrcweir nId = FID_INPUTLINE_BLOCK; 2694*cdf0e10cSrcweir else if ( nBlockMode == SC_ENTER_MATRIX ) 2695*cdf0e10cSrcweir nId = FID_INPUTLINE_MATRIX; 2696*cdf0e10cSrcweir 2697*cdf0e10cSrcweir ScInputStatusItem aItem( FID_INPUTLINE_STATUS, 2698*cdf0e10cSrcweir aCursorPos, aCursorPos, aCursorPos, 2699*cdf0e10cSrcweir aString, pObject ); 2700*cdf0e10cSrcweir const SfxPoolItem* aArgs[2]; 2701*cdf0e10cSrcweir aArgs[0] = &aItem; 2702*cdf0e10cSrcweir aArgs[1] = NULL; 2703*cdf0e10cSrcweir rBindings.Execute( nId, aArgs ); 2704*cdf0e10cSrcweir } 2705*cdf0e10cSrcweir 2706*cdf0e10cSrcweir delete pLastState; // pLastState enthaelt noch den alten Text 2707*cdf0e10cSrcweir pLastState = NULL; 2708*cdf0e10cSrcweir } 2709*cdf0e10cSrcweir else 2710*cdf0e10cSrcweir pSfxApp->Broadcast( SfxSimpleHint( FID_KILLEDITVIEW ) ); 2711*cdf0e10cSrcweir 2712*cdf0e10cSrcweir if ( bOldMod && pExecuteSh && pCellAttrs && !bForget ) 2713*cdf0e10cSrcweir { 2714*cdf0e10cSrcweir // mit Eingabe zusammenfassen ? 2715*cdf0e10cSrcweir pExecuteSh->ApplySelectionPattern( *pCellAttrs, sal_True, sal_True ); 2716*cdf0e10cSrcweir pExecuteSh->AdjustBlockHeight(); 2717*cdf0e10cSrcweir } 2718*cdf0e10cSrcweir 2719*cdf0e10cSrcweir delete pCellAttrs; 2720*cdf0e10cSrcweir delete pObject; 2721*cdf0e10cSrcweir 2722*cdf0e10cSrcweir HideTip(); 2723*cdf0e10cSrcweir HideTipBelow(); 2724*cdf0e10cSrcweir 2725*cdf0e10cSrcweir nFormSelStart = nFormSelEnd = 0; 2726*cdf0e10cSrcweir aFormText.Erase(); 2727*cdf0e10cSrcweir 2728*cdf0e10cSrcweir bInOwnChange = sal_False; 2729*cdf0e10cSrcweir bInEnterHandler = sal_False; 2730*cdf0e10cSrcweir } 2731*cdf0e10cSrcweir 2732*cdf0e10cSrcweir void ScInputHandler::CancelHandler() 2733*cdf0e10cSrcweir { 2734*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 2735*cdf0e10cSrcweir 2736*cdf0e10cSrcweir ImplCreateEditEngine(); 2737*cdf0e10cSrcweir 2738*cdf0e10cSrcweir bModified = sal_False; 2739*cdf0e10cSrcweir 2740*cdf0e10cSrcweir // don't rely on ShowRefFrame switching the active view synchronously 2741*cdf0e10cSrcweir // execute the function directly on the correct view's bindings instead 2742*cdf0e10cSrcweir // pRefViewSh is reset in ShowRefFrame - get pointer before ShowRefFrame call 2743*cdf0e10cSrcweir ScTabViewShell* pExecuteSh = pRefViewSh ? pRefViewSh : pActiveViewSh; 2744*cdf0e10cSrcweir 2745*cdf0e10cSrcweir if (bFormulaMode) 2746*cdf0e10cSrcweir { 2747*cdf0e10cSrcweir ShowRefFrame(); 2748*cdf0e10cSrcweir if (pExecuteSh) 2749*cdf0e10cSrcweir { 2750*cdf0e10cSrcweir pExecuteSh->SetTabNo(aCursorPos.Tab()); 2751*cdf0e10cSrcweir pExecuteSh->ActiveGrabFocus(); 2752*cdf0e10cSrcweir } 2753*cdf0e10cSrcweir bFormulaMode = sal_False; 2754*cdf0e10cSrcweir SFX_APP()->Broadcast( SfxSimpleHint( FID_REFMODECHANGED ) ); 2755*cdf0e10cSrcweir SC_MOD()->SetRefInputHdl(NULL); 2756*cdf0e10cSrcweir if (pInputWin) 2757*cdf0e10cSrcweir pInputWin->SetFormulaMode(sal_False); 2758*cdf0e10cSrcweir UpdateAutoCorrFlag(); 2759*cdf0e10cSrcweir } 2760*cdf0e10cSrcweir pRefViewSh = NULL; // auch ohne FormulaMode wegen Funktions-AP 2761*cdf0e10cSrcweir DeleteRangeFinder(); 2762*cdf0e10cSrcweir ResetAutoPar(); 2763*cdf0e10cSrcweir 2764*cdf0e10cSrcweir eMode = SC_INPUT_NONE; 2765*cdf0e10cSrcweir StopInputWinEngine( sal_True ); 2766*cdf0e10cSrcweir if (pExecuteSh) 2767*cdf0e10cSrcweir pExecuteSh->StopEditShell(); 2768*cdf0e10cSrcweir 2769*cdf0e10cSrcweir aCursorPos.Set(MAXCOL+1,0,0); // Flag, dass ungueltig 2770*cdf0e10cSrcweir pEngine->SetText(String()); 2771*cdf0e10cSrcweir 2772*cdf0e10cSrcweir if ( !pLastState && pExecuteSh ) 2773*cdf0e10cSrcweir pExecuteSh->UpdateInputHandler( sal_True ); // Status neu holen 2774*cdf0e10cSrcweir else 2775*cdf0e10cSrcweir NotifyChange( pLastState, sal_True ); 2776*cdf0e10cSrcweir 2777*cdf0e10cSrcweir nFormSelStart = nFormSelEnd = 0; 2778*cdf0e10cSrcweir aFormText.Erase(); 2779*cdf0e10cSrcweir 2780*cdf0e10cSrcweir bInOwnChange = sal_False; 2781*cdf0e10cSrcweir } 2782*cdf0e10cSrcweir 2783*cdf0e10cSrcweir sal_Bool ScInputHandler::IsModalMode( SfxObjectShell* pDocSh ) 2784*cdf0e10cSrcweir { 2785*cdf0e10cSrcweir // Referenzen auf unbenanntes Dokument gehen nicht 2786*cdf0e10cSrcweir 2787*cdf0e10cSrcweir return bFormulaMode && pRefViewSh 2788*cdf0e10cSrcweir && pRefViewSh->GetViewData()->GetDocument()->GetDocumentShell() != pDocSh 2789*cdf0e10cSrcweir && !pDocSh->HasName(); 2790*cdf0e10cSrcweir } 2791*cdf0e10cSrcweir 2792*cdf0e10cSrcweir void ScInputHandler::AddRefEntry() 2793*cdf0e10cSrcweir { 2794*cdf0e10cSrcweir const sal_Unicode cSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0); 2795*cdf0e10cSrcweir UpdateActiveView(); 2796*cdf0e10cSrcweir if (!pTableView && !pTopView) 2797*cdf0e10cSrcweir return; // z.B. FillMode 2798*cdf0e10cSrcweir 2799*cdf0e10cSrcweir DataChanging(); // kann nicht neu sein 2800*cdf0e10cSrcweir 2801*cdf0e10cSrcweir RemoveSelection(); 2802*cdf0e10cSrcweir if (pTableView) 2803*cdf0e10cSrcweir pTableView->InsertText( cSep, sal_False ); 2804*cdf0e10cSrcweir if (pTopView) 2805*cdf0e10cSrcweir pTopView->InsertText( cSep, sal_False ); 2806*cdf0e10cSrcweir 2807*cdf0e10cSrcweir DataChanged(); 2808*cdf0e10cSrcweir } 2809*cdf0e10cSrcweir 2810*cdf0e10cSrcweir void ScInputHandler::SetReference( const ScRange& rRef, ScDocument* pDoc ) 2811*cdf0e10cSrcweir { 2812*cdf0e10cSrcweir HideTip(); 2813*cdf0e10cSrcweir 2814*cdf0e10cSrcweir sal_Bool bOtherDoc = ( pRefViewSh && 2815*cdf0e10cSrcweir pRefViewSh->GetViewData()->GetDocument() != pDoc ); 2816*cdf0e10cSrcweir if (bOtherDoc) 2817*cdf0e10cSrcweir if (!pDoc->GetDocumentShell()->HasName()) 2818*cdf0e10cSrcweir { 2819*cdf0e10cSrcweir // Referenzen auf unbenanntes Dokument gehen nicht 2820*cdf0e10cSrcweir // (SetReference sollte dann auch nicht gerufen werden) 2821*cdf0e10cSrcweir 2822*cdf0e10cSrcweir return; 2823*cdf0e10cSrcweir } 2824*cdf0e10cSrcweir 2825*cdf0e10cSrcweir UpdateActiveView(); 2826*cdf0e10cSrcweir if (!pTableView && !pTopView) 2827*cdf0e10cSrcweir return; // z.B. FillMode 2828*cdf0e10cSrcweir 2829*cdf0e10cSrcweir // nie das "=" ueberschreiben! 2830*cdf0e10cSrcweir EditView* pActiveView = pTopView ? pTopView : pTableView; 2831*cdf0e10cSrcweir ESelection aSel = pActiveView->GetSelection(); 2832*cdf0e10cSrcweir aSel.Adjust(); 2833*cdf0e10cSrcweir if ( aSel.nStartPara == 0 && aSel.nStartPos == 0 ) 2834*cdf0e10cSrcweir return; 2835*cdf0e10cSrcweir 2836*cdf0e10cSrcweir DataChanging(); // kann nicht neu sein 2837*cdf0e10cSrcweir 2838*cdf0e10cSrcweir // Selektion umdrehen, falls rueckwaerts (noetig ???) 2839*cdf0e10cSrcweir 2840*cdf0e10cSrcweir if (pTableView) 2841*cdf0e10cSrcweir { 2842*cdf0e10cSrcweir ESelection aTabSel = pTableView->GetSelection(); 2843*cdf0e10cSrcweir if (aTabSel.nStartPos > aTabSel.nEndPos && aTabSel.nStartPara == aTabSel.nEndPara) 2844*cdf0e10cSrcweir { 2845*cdf0e10cSrcweir aTabSel.Adjust(); 2846*cdf0e10cSrcweir pTableView->SetSelection(aTabSel); 2847*cdf0e10cSrcweir } 2848*cdf0e10cSrcweir } 2849*cdf0e10cSrcweir if (pTopView) 2850*cdf0e10cSrcweir { 2851*cdf0e10cSrcweir ESelection aTopSel = pTopView->GetSelection(); 2852*cdf0e10cSrcweir if (aTopSel.nStartPos > aTopSel.nEndPos && aTopSel.nStartPara == aTopSel.nEndPara) 2853*cdf0e10cSrcweir { 2854*cdf0e10cSrcweir aTopSel.Adjust(); 2855*cdf0e10cSrcweir pTopView->SetSelection(aTopSel); 2856*cdf0e10cSrcweir } 2857*cdf0e10cSrcweir } 2858*cdf0e10cSrcweir 2859*cdf0e10cSrcweir // String aus Referenz erzeugen 2860*cdf0e10cSrcweir 2861*cdf0e10cSrcweir String aRefStr; 2862*cdf0e10cSrcweir const ScAddress::Details aAddrDetails( pDoc, aCursorPos ); 2863*cdf0e10cSrcweir if (bOtherDoc) 2864*cdf0e10cSrcweir { 2865*cdf0e10cSrcweir // Referenz auf anderes Dokument 2866*cdf0e10cSrcweir 2867*cdf0e10cSrcweir DBG_ASSERT(rRef.aStart.Tab()==rRef.aEnd.Tab(), "nStartTab!=nEndTab"); 2868*cdf0e10cSrcweir 2869*cdf0e10cSrcweir String aTmp; 2870*cdf0e10cSrcweir rRef.Format( aTmp, SCA_VALID|SCA_TAB_3D, pDoc, aAddrDetails ); // immer 3d 2871*cdf0e10cSrcweir 2872*cdf0e10cSrcweir SfxObjectShell* pObjSh = pDoc->GetDocumentShell(); 2873*cdf0e10cSrcweir // #i75893# convert escaped URL of the document to something user friendly 2874*cdf0e10cSrcweir // String aFileName = pObjSh->GetMedium()->GetName(); 2875*cdf0e10cSrcweir String aFileName = pObjSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); 2876*cdf0e10cSrcweir 2877*cdf0e10cSrcweir aRefStr = '\''; 2878*cdf0e10cSrcweir aRefStr += aFileName; 2879*cdf0e10cSrcweir aRefStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "'#" )); 2880*cdf0e10cSrcweir aRefStr += aTmp; 2881*cdf0e10cSrcweir } 2882*cdf0e10cSrcweir else 2883*cdf0e10cSrcweir { 2884*cdf0e10cSrcweir if ( ( rRef.aStart.Tab() != aCursorPos.Tab() || 2885*cdf0e10cSrcweir rRef.aStart.Tab() != rRef.aEnd.Tab() ) && pDoc ) 2886*cdf0e10cSrcweir rRef.Format( aRefStr, SCA_VALID|SCA_TAB_3D, pDoc, aAddrDetails ); 2887*cdf0e10cSrcweir else 2888*cdf0e10cSrcweir rRef.Format( aRefStr, SCA_VALID, pDoc, aAddrDetails ); 2889*cdf0e10cSrcweir } 2890*cdf0e10cSrcweir 2891*cdf0e10cSrcweir if (pTableView || pTopView) 2892*cdf0e10cSrcweir { 2893*cdf0e10cSrcweir if (pTableView) 2894*cdf0e10cSrcweir pTableView->InsertText( aRefStr, sal_True ); 2895*cdf0e10cSrcweir if (pTopView) 2896*cdf0e10cSrcweir pTopView->InsertText( aRefStr, sal_True ); 2897*cdf0e10cSrcweir 2898*cdf0e10cSrcweir DataChanged(); 2899*cdf0e10cSrcweir } 2900*cdf0e10cSrcweir 2901*cdf0e10cSrcweir bSelIsRef = sal_True; 2902*cdf0e10cSrcweir } 2903*cdf0e10cSrcweir 2904*cdf0e10cSrcweir void ScInputHandler::InsertFunction( const String& rFuncName, sal_Bool bAddPar ) 2905*cdf0e10cSrcweir { 2906*cdf0e10cSrcweir if ( eMode == SC_INPUT_NONE ) 2907*cdf0e10cSrcweir { 2908*cdf0e10cSrcweir DBG_ERROR("InsertFunction, nicht im Eingabemodus"); 2909*cdf0e10cSrcweir return; 2910*cdf0e10cSrcweir } 2911*cdf0e10cSrcweir 2912*cdf0e10cSrcweir UpdateActiveView(); 2913*cdf0e10cSrcweir if (!pTableView && !pTopView) 2914*cdf0e10cSrcweir return; // z.B. FillMode 2915*cdf0e10cSrcweir 2916*cdf0e10cSrcweir DataChanging(); // kann nicht neu sein 2917*cdf0e10cSrcweir 2918*cdf0e10cSrcweir String aText = rFuncName; 2919*cdf0e10cSrcweir if (bAddPar) 2920*cdf0e10cSrcweir aText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" )); 2921*cdf0e10cSrcweir 2922*cdf0e10cSrcweir if (pTableView) 2923*cdf0e10cSrcweir { 2924*cdf0e10cSrcweir pTableView->InsertText( aText, sal_False ); 2925*cdf0e10cSrcweir if (bAddPar) 2926*cdf0e10cSrcweir { 2927*cdf0e10cSrcweir ESelection aSel = pTableView->GetSelection(); 2928*cdf0e10cSrcweir --aSel.nStartPos; 2929*cdf0e10cSrcweir --aSel.nEndPos; 2930*cdf0e10cSrcweir pTableView->SetSelection(aSel); 2931*cdf0e10cSrcweir } 2932*cdf0e10cSrcweir } 2933*cdf0e10cSrcweir if (pTopView) 2934*cdf0e10cSrcweir { 2935*cdf0e10cSrcweir pTopView->InsertText( aText, sal_False ); 2936*cdf0e10cSrcweir if (bAddPar) 2937*cdf0e10cSrcweir { 2938*cdf0e10cSrcweir ESelection aSel = pTopView->GetSelection(); 2939*cdf0e10cSrcweir --aSel.nStartPos; 2940*cdf0e10cSrcweir --aSel.nEndPos; 2941*cdf0e10cSrcweir pTopView->SetSelection(aSel); 2942*cdf0e10cSrcweir } 2943*cdf0e10cSrcweir } 2944*cdf0e10cSrcweir 2945*cdf0e10cSrcweir DataChanged(); 2946*cdf0e10cSrcweir 2947*cdf0e10cSrcweir if (bAddPar) 2948*cdf0e10cSrcweir AutoParAdded(); 2949*cdf0e10cSrcweir } 2950*cdf0e10cSrcweir 2951*cdf0e10cSrcweir void ScInputHandler::ClearText() 2952*cdf0e10cSrcweir { 2953*cdf0e10cSrcweir if ( eMode == SC_INPUT_NONE ) 2954*cdf0e10cSrcweir { 2955*cdf0e10cSrcweir DBG_ERROR("ClearText, nicht im Eingabemodus"); 2956*cdf0e10cSrcweir return; 2957*cdf0e10cSrcweir } 2958*cdf0e10cSrcweir 2959*cdf0e10cSrcweir UpdateActiveView(); 2960*cdf0e10cSrcweir if (!pTableView && !pTopView) 2961*cdf0e10cSrcweir return; // z.B. FillMode 2962*cdf0e10cSrcweir 2963*cdf0e10cSrcweir DataChanging(); // darf nicht neu sein 2964*cdf0e10cSrcweir 2965*cdf0e10cSrcweir String aEmpty; 2966*cdf0e10cSrcweir if (pTableView) 2967*cdf0e10cSrcweir { 2968*cdf0e10cSrcweir pTableView->GetEditEngine()->SetText( aEmpty ); 2969*cdf0e10cSrcweir pTableView->SetSelection( ESelection(0,0, 0,0) ); 2970*cdf0e10cSrcweir } 2971*cdf0e10cSrcweir if (pTopView) 2972*cdf0e10cSrcweir { 2973*cdf0e10cSrcweir pTopView->GetEditEngine()->SetText( aEmpty ); 2974*cdf0e10cSrcweir pTopView->SetSelection( ESelection(0,0, 0,0) ); 2975*cdf0e10cSrcweir } 2976*cdf0e10cSrcweir 2977*cdf0e10cSrcweir DataChanged(); 2978*cdf0e10cSrcweir } 2979*cdf0e10cSrcweir 2980*cdf0e10cSrcweir sal_Bool ScInputHandler::KeyInput( const KeyEvent& rKEvt, sal_Bool bStartEdit /* = sal_False */ ) 2981*cdf0e10cSrcweir { 2982*cdf0e10cSrcweir if (!bOptLoaded) 2983*cdf0e10cSrcweir { 2984*cdf0e10cSrcweir bAutoComplete = SC_MOD()->GetAppOptions().GetAutoComplete(); 2985*cdf0e10cSrcweir bOptLoaded = sal_True; 2986*cdf0e10cSrcweir } 2987*cdf0e10cSrcweir 2988*cdf0e10cSrcweir KeyCode aCode = rKEvt.GetKeyCode(); 2989*cdf0e10cSrcweir sal_uInt16 nModi = aCode.GetModifier(); 2990*cdf0e10cSrcweir sal_Bool bShift = aCode.IsShift(); 2991*cdf0e10cSrcweir sal_Bool bControl = aCode.IsMod1(); 2992*cdf0e10cSrcweir sal_Bool bAlt = aCode.IsMod2(); 2993*cdf0e10cSrcweir sal_uInt16 nCode = aCode.GetCode(); 2994*cdf0e10cSrcweir sal_Unicode nChar = rKEvt.GetCharCode(); 2995*cdf0e10cSrcweir 2996*cdf0e10cSrcweir // Alt-Return is accepted, everything else with ALT, or CTRL-TAB are not: 2997*cdf0e10cSrcweir if (( bAlt && !bControl && nCode != KEY_RETURN ) || 2998*cdf0e10cSrcweir ( bControl && aCode.GetCode() == KEY_TAB )) 2999*cdf0e10cSrcweir return sal_False; 3000*cdf0e10cSrcweir 3001*cdf0e10cSrcweir sal_Bool bInputLine = ( eMode==SC_INPUT_TOP ); 3002*cdf0e10cSrcweir 3003*cdf0e10cSrcweir sal_Bool bUsed = sal_False; 3004*cdf0e10cSrcweir sal_Bool bSkip = sal_False; 3005*cdf0e10cSrcweir sal_Bool bDoEnter = sal_False; 3006*cdf0e10cSrcweir 3007*cdf0e10cSrcweir switch ( nCode ) 3008*cdf0e10cSrcweir { 3009*cdf0e10cSrcweir case KEY_RETURN: 3010*cdf0e10cSrcweir if (bControl && !bShift && !bInputLine) 3011*cdf0e10cSrcweir bDoEnter = sal_True; 3012*cdf0e10cSrcweir else if ( nModi == 0 && nTipVisible && pFormulaData && nAutoPos != SCPOS_INVALID ) 3013*cdf0e10cSrcweir { 3014*cdf0e10cSrcweir PasteFunctionData(); 3015*cdf0e10cSrcweir bUsed = sal_True; 3016*cdf0e10cSrcweir } 3017*cdf0e10cSrcweir else if ( nModi == 0 && nTipVisible && aManualTip.Len() ) 3018*cdf0e10cSrcweir { 3019*cdf0e10cSrcweir PasteManualTip(); 3020*cdf0e10cSrcweir bUsed = sal_True; 3021*cdf0e10cSrcweir } 3022*cdf0e10cSrcweir else 3023*cdf0e10cSrcweir { 3024*cdf0e10cSrcweir sal_uInt8 nMode = SC_ENTER_NORMAL; 3025*cdf0e10cSrcweir if ( bShift && bControl ) 3026*cdf0e10cSrcweir nMode = SC_ENTER_MATRIX; 3027*cdf0e10cSrcweir else if ( bAlt ) 3028*cdf0e10cSrcweir nMode = SC_ENTER_BLOCK; 3029*cdf0e10cSrcweir EnterHandler( nMode ); 3030*cdf0e10cSrcweir 3031*cdf0e10cSrcweir if (pActiveViewSh) 3032*cdf0e10cSrcweir pActiveViewSh->MoveCursorEnter( bShift && !bControl ); 3033*cdf0e10cSrcweir 3034*cdf0e10cSrcweir bUsed = sal_True; 3035*cdf0e10cSrcweir } 3036*cdf0e10cSrcweir break; 3037*cdf0e10cSrcweir case KEY_TAB: 3038*cdf0e10cSrcweir if (!bControl && !bAlt) 3039*cdf0e10cSrcweir { 3040*cdf0e10cSrcweir if ( pFormulaData && nTipVisible && nAutoPos != SCPOS_INVALID ) 3041*cdf0e10cSrcweir { 3042*cdf0e10cSrcweir // blaettern 3043*cdf0e10cSrcweir 3044*cdf0e10cSrcweir NextFormulaEntry( bShift ); 3045*cdf0e10cSrcweir } 3046*cdf0e10cSrcweir else if ( pColumnData && bUseTab && nAutoPos != SCPOS_INVALID ) 3047*cdf0e10cSrcweir { 3048*cdf0e10cSrcweir // in den Eintraegen der AutoEingabe blaettern 3049*cdf0e10cSrcweir 3050*cdf0e10cSrcweir NextAutoEntry( bShift ); 3051*cdf0e10cSrcweir } 3052*cdf0e10cSrcweir else 3053*cdf0e10cSrcweir { 3054*cdf0e10cSrcweir EnterHandler(); 3055*cdf0e10cSrcweir 3056*cdf0e10cSrcweir // TabKeyInput gibt auf manchen Rechnern unter W95 Stackueberlaeufe, 3057*cdf0e10cSrcweir // darum direkter Aufruf: 3058*cdf0e10cSrcweir if (pActiveViewSh) 3059*cdf0e10cSrcweir pActiveViewSh->FindNextUnprot( bShift ); 3060*cdf0e10cSrcweir } 3061*cdf0e10cSrcweir bUsed = sal_True; 3062*cdf0e10cSrcweir } 3063*cdf0e10cSrcweir break; 3064*cdf0e10cSrcweir case KEY_ESCAPE: 3065*cdf0e10cSrcweir if ( nTipVisible ) 3066*cdf0e10cSrcweir { 3067*cdf0e10cSrcweir HideTip(); 3068*cdf0e10cSrcweir bUsed = sal_True; 3069*cdf0e10cSrcweir } 3070*cdf0e10cSrcweir else if( nTipVisibleSec ) 3071*cdf0e10cSrcweir { 3072*cdf0e10cSrcweir HideTipBelow(); 3073*cdf0e10cSrcweir bUsed = sal_True; 3074*cdf0e10cSrcweir } 3075*cdf0e10cSrcweir else if (eMode != SC_INPUT_NONE) 3076*cdf0e10cSrcweir { 3077*cdf0e10cSrcweir CancelHandler(); 3078*cdf0e10cSrcweir bUsed = sal_True; 3079*cdf0e10cSrcweir } 3080*cdf0e10cSrcweir else 3081*cdf0e10cSrcweir bSkip = sal_True; 3082*cdf0e10cSrcweir break; 3083*cdf0e10cSrcweir case KEY_F2: 3084*cdf0e10cSrcweir if ( !bShift && !bControl && !bAlt && eMode == SC_INPUT_TABLE ) 3085*cdf0e10cSrcweir { 3086*cdf0e10cSrcweir eMode = SC_INPUT_TYPE; 3087*cdf0e10cSrcweir bUsed = sal_True; 3088*cdf0e10cSrcweir } 3089*cdf0e10cSrcweir break; 3090*cdf0e10cSrcweir } 3091*cdf0e10cSrcweir 3092*cdf0e10cSrcweir // Cursortasten nur ausfuehren, wenn schon im Edit-Modus 3093*cdf0e10cSrcweir // z.B. wegen Shift-Ctrl-PageDn (ist nicht als Accelerator definiert) 3094*cdf0e10cSrcweir 3095*cdf0e10cSrcweir sal_Bool bCursorKey = EditEngine::DoesKeyMoveCursor(rKEvt); 3096*cdf0e10cSrcweir sal_Bool bInsKey = ( nCode == KEY_INSERT && !nModi ); // Insert wie Cursortasten behandeln 3097*cdf0e10cSrcweir if ( !bUsed && !bSkip && ( bDoEnter || EditEngine::DoesKeyChangeText(rKEvt) || 3098*cdf0e10cSrcweir ( eMode != SC_INPUT_NONE && ( bCursorKey || bInsKey ) ) ) ) 3099*cdf0e10cSrcweir { 3100*cdf0e10cSrcweir HideTip(); 3101*cdf0e10cSrcweir HideTipBelow(); 3102*cdf0e10cSrcweir 3103*cdf0e10cSrcweir if (bSelIsRef) 3104*cdf0e10cSrcweir { 3105*cdf0e10cSrcweir RemoveSelection(); 3106*cdf0e10cSrcweir bSelIsRef = sal_False; 3107*cdf0e10cSrcweir } 3108*cdf0e10cSrcweir 3109*cdf0e10cSrcweir UpdateActiveView(); 3110*cdf0e10cSrcweir sal_Bool bNewView = DataChanging( nChar ); 3111*cdf0e10cSrcweir 3112*cdf0e10cSrcweir if (bProtected) // Zelle geschuetzt? 3113*cdf0e10cSrcweir bUsed = sal_True; // Key-Event nicht weiterleiten 3114*cdf0e10cSrcweir else // Aenderungen erlaubt 3115*cdf0e10cSrcweir { 3116*cdf0e10cSrcweir if (bNewView ) // neu anlegen 3117*cdf0e10cSrcweir { 3118*cdf0e10cSrcweir if (pActiveViewSh) 3119*cdf0e10cSrcweir pActiveViewSh->GetViewData()->GetDocShell()->PostEditView( pEngine, aCursorPos ); 3120*cdf0e10cSrcweir UpdateActiveView(); 3121*cdf0e10cSrcweir if (eMode==SC_INPUT_NONE) 3122*cdf0e10cSrcweir if (pTableView || pTopView) 3123*cdf0e10cSrcweir { 3124*cdf0e10cSrcweir String aStrLoP; 3125*cdf0e10cSrcweir 3126*cdf0e10cSrcweir if ( bStartEdit && bCellHasPercentFormat && ((nChar >= '0' && nChar <= '9') || nChar == '-') ) 3127*cdf0e10cSrcweir aStrLoP = '%'; 3128*cdf0e10cSrcweir 3129*cdf0e10cSrcweir if (pTableView) 3130*cdf0e10cSrcweir { 3131*cdf0e10cSrcweir pTableView->GetEditEngine()->SetText( aStrLoP ); 3132*cdf0e10cSrcweir if ( aStrLoP.Len() ) 3133*cdf0e10cSrcweir pTableView->SetSelection( ESelection(0,0, 0,0) ); // before the '%' 3134*cdf0e10cSrcweir 3135*cdf0e10cSrcweir // don't call SetSelection if the string is empty anyway, 3136*cdf0e10cSrcweir // to avoid breaking the bInitial handling in ScViewData::EditGrowY 3137*cdf0e10cSrcweir } 3138*cdf0e10cSrcweir if (pTopView) 3139*cdf0e10cSrcweir { 3140*cdf0e10cSrcweir pTopView->GetEditEngine()->SetText( aStrLoP ); 3141*cdf0e10cSrcweir if ( aStrLoP.Len() ) 3142*cdf0e10cSrcweir pTopView->SetSelection( ESelection(0,0, 0,0) ); // before the '%' 3143*cdf0e10cSrcweir } 3144*cdf0e10cSrcweir } 3145*cdf0e10cSrcweir SyncViews(); 3146*cdf0e10cSrcweir } 3147*cdf0e10cSrcweir 3148*cdf0e10cSrcweir if (pTableView || pTopView) 3149*cdf0e10cSrcweir { 3150*cdf0e10cSrcweir // pActiveView->SetEditEngineUpdateMode(sal_True); //! gibt Muell !!!! 3151*cdf0e10cSrcweir 3152*cdf0e10cSrcweir if (bDoEnter) 3153*cdf0e10cSrcweir { 3154*cdf0e10cSrcweir if (pTableView) 3155*cdf0e10cSrcweir if( pTableView->PostKeyEvent( KeyEvent( CHAR_CR, KeyCode(KEY_RETURN) ) ) ) 3156*cdf0e10cSrcweir bUsed = sal_True; 3157*cdf0e10cSrcweir if (pTopView) 3158*cdf0e10cSrcweir if( pTopView->PostKeyEvent( KeyEvent( CHAR_CR, KeyCode(KEY_RETURN) ) ) ) 3159*cdf0e10cSrcweir bUsed = sal_True; 3160*cdf0e10cSrcweir } 3161*cdf0e10cSrcweir else if ( nAutoPar && nChar == ')' && CursorAtClosingPar() ) 3162*cdf0e10cSrcweir { 3163*cdf0e10cSrcweir SkipClosingPar(); 3164*cdf0e10cSrcweir bUsed = sal_True; 3165*cdf0e10cSrcweir } 3166*cdf0e10cSrcweir else 3167*cdf0e10cSrcweir { 3168*cdf0e10cSrcweir if (pTableView) 3169*cdf0e10cSrcweir if ( pTableView->PostKeyEvent( rKEvt ) ) 3170*cdf0e10cSrcweir bUsed = sal_True; 3171*cdf0e10cSrcweir if (pTopView) 3172*cdf0e10cSrcweir if ( pTopView->PostKeyEvent( rKEvt ) ) 3173*cdf0e10cSrcweir bUsed = sal_True; 3174*cdf0e10cSrcweir } 3175*cdf0e10cSrcweir 3176*cdf0e10cSrcweir // Auto-Eingabe: 3177*cdf0e10cSrcweir 3178*cdf0e10cSrcweir if ( bUsed && bAutoComplete ) 3179*cdf0e10cSrcweir { 3180*cdf0e10cSrcweir bUseTab = sal_False; 3181*cdf0e10cSrcweir nAutoPos = SCPOS_INVALID; // do not search further 3182*cdf0e10cSrcweir 3183*cdf0e10cSrcweir KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); 3184*cdf0e10cSrcweir if ( nChar && nChar != 8 && nChar != 127 && // no 'backspace', no 'delete' 3185*cdf0e10cSrcweir KEYFUNC_CUT != eFunc) // and no 'CTRL-X' 3186*cdf0e10cSrcweir { 3187*cdf0e10cSrcweir if (bFormulaMode) 3188*cdf0e10cSrcweir UseFormulaData(); 3189*cdf0e10cSrcweir else 3190*cdf0e10cSrcweir UseColData(); 3191*cdf0e10cSrcweir } 3192*cdf0e10cSrcweir } 3193*cdf0e10cSrcweir 3194*cdf0e10cSrcweir // when the selection is changed manually or an opening parenthesis 3195*cdf0e10cSrcweir // is typed, stop overwriting parentheses 3196*cdf0e10cSrcweir if ( bUsed && nChar == '(' ) 3197*cdf0e10cSrcweir ResetAutoPar(); 3198*cdf0e10cSrcweir 3199*cdf0e10cSrcweir if ( KEY_INSERT == nCode ) 3200*cdf0e10cSrcweir { 3201*cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 3202*cdf0e10cSrcweir if (pViewFrm) 3203*cdf0e10cSrcweir pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT ); 3204*cdf0e10cSrcweir } 3205*cdf0e10cSrcweir if( bUsed && bFormulaMode && ( bCursorKey || bInsKey || nCode == KEY_DELETE || nCode == KEY_BACKSPACE ) ) 3206*cdf0e10cSrcweir { 3207*cdf0e10cSrcweir ShowTipCursor(); 3208*cdf0e10cSrcweir } 3209*cdf0e10cSrcweir } 3210*cdf0e10cSrcweir 3211*cdf0e10cSrcweir // #i114511# don't count cursor keys as modification 3212*cdf0e10cSrcweir sal_Bool bSetModified = !bCursorKey; 3213*cdf0e10cSrcweir DataChanged(sal_False, bSetModified); // also calls UpdateParenthesis() 3214*cdf0e10cSrcweir InvalidateAttribs(); //! in DataChanged ? 3215*cdf0e10cSrcweir } 3216*cdf0e10cSrcweir } 3217*cdf0e10cSrcweir 3218*cdf0e10cSrcweir if (pTopView && eMode != SC_INPUT_NONE) 3219*cdf0e10cSrcweir SyncViews(); 3220*cdf0e10cSrcweir 3221*cdf0e10cSrcweir return bUsed; 3222*cdf0e10cSrcweir } 3223*cdf0e10cSrcweir 3224*cdf0e10cSrcweir sal_Bool ScInputHandler::InputCommand( const CommandEvent& rCEvt, sal_Bool bForce ) 3225*cdf0e10cSrcweir { 3226*cdf0e10cSrcweir sal_Bool bUsed = sal_False; 3227*cdf0e10cSrcweir 3228*cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CURSORPOS ) 3229*cdf0e10cSrcweir { 3230*cdf0e10cSrcweir // #90346# for COMMAND_CURSORPOS, do as little as possible, because 3231*cdf0e10cSrcweir // with remote VCL, even a ShowCursor will generate another event. 3232*cdf0e10cSrcweir if ( eMode != SC_INPUT_NONE ) 3233*cdf0e10cSrcweir { 3234*cdf0e10cSrcweir UpdateActiveView(); 3235*cdf0e10cSrcweir if (pTableView || pTopView) 3236*cdf0e10cSrcweir { 3237*cdf0e10cSrcweir if (pTableView) 3238*cdf0e10cSrcweir pTableView->Command( rCEvt ); 3239*cdf0e10cSrcweir else if (pTopView) // call only once 3240*cdf0e10cSrcweir pTopView->Command( rCEvt ); 3241*cdf0e10cSrcweir bUsed = sal_True; 3242*cdf0e10cSrcweir } 3243*cdf0e10cSrcweir } 3244*cdf0e10cSrcweir } 3245*cdf0e10cSrcweir else 3246*cdf0e10cSrcweir { 3247*cdf0e10cSrcweir if ( bForce || eMode != SC_INPUT_NONE ) 3248*cdf0e10cSrcweir { 3249*cdf0e10cSrcweir if (!bOptLoaded) 3250*cdf0e10cSrcweir { 3251*cdf0e10cSrcweir bAutoComplete = SC_MOD()->GetAppOptions().GetAutoComplete(); 3252*cdf0e10cSrcweir bOptLoaded = sal_True; 3253*cdf0e10cSrcweir } 3254*cdf0e10cSrcweir 3255*cdf0e10cSrcweir HideTip(); 3256*cdf0e10cSrcweir HideTipBelow(); 3257*cdf0e10cSrcweir 3258*cdf0e10cSrcweir if ( bSelIsRef ) 3259*cdf0e10cSrcweir { 3260*cdf0e10cSrcweir RemoveSelection(); 3261*cdf0e10cSrcweir bSelIsRef = sal_False; 3262*cdf0e10cSrcweir } 3263*cdf0e10cSrcweir 3264*cdf0e10cSrcweir UpdateActiveView(); 3265*cdf0e10cSrcweir sal_Bool bNewView = DataChanging( 0, sal_True ); 3266*cdf0e10cSrcweir 3267*cdf0e10cSrcweir if (bProtected) // cell protected 3268*cdf0e10cSrcweir bUsed = sal_True; // event is used 3269*cdf0e10cSrcweir else // changes allowed 3270*cdf0e10cSrcweir { 3271*cdf0e10cSrcweir if (bNewView) // create new edit view 3272*cdf0e10cSrcweir { 3273*cdf0e10cSrcweir if (pActiveViewSh) 3274*cdf0e10cSrcweir pActiveViewSh->GetViewData()->GetDocShell()->PostEditView( pEngine, aCursorPos ); 3275*cdf0e10cSrcweir UpdateActiveView(); 3276*cdf0e10cSrcweir if (eMode==SC_INPUT_NONE) 3277*cdf0e10cSrcweir if (pTableView || pTopView) 3278*cdf0e10cSrcweir { 3279*cdf0e10cSrcweir String aStrLoP; 3280*cdf0e10cSrcweir if (pTableView) 3281*cdf0e10cSrcweir { 3282*cdf0e10cSrcweir pTableView->GetEditEngine()->SetText( aStrLoP ); 3283*cdf0e10cSrcweir pTableView->SetSelection( ESelection(0,0, 0,0) ); 3284*cdf0e10cSrcweir } 3285*cdf0e10cSrcweir if (pTopView) 3286*cdf0e10cSrcweir { 3287*cdf0e10cSrcweir pTopView->GetEditEngine()->SetText( aStrLoP ); 3288*cdf0e10cSrcweir pTopView->SetSelection( ESelection(0,0, 0,0) ); 3289*cdf0e10cSrcweir } 3290*cdf0e10cSrcweir } 3291*cdf0e10cSrcweir SyncViews(); 3292*cdf0e10cSrcweir } 3293*cdf0e10cSrcweir 3294*cdf0e10cSrcweir if (pTableView || pTopView) 3295*cdf0e10cSrcweir { 3296*cdf0e10cSrcweir if (pTableView) 3297*cdf0e10cSrcweir pTableView->Command( rCEvt ); 3298*cdf0e10cSrcweir if (pTopView) 3299*cdf0e10cSrcweir pTopView->Command( rCEvt ); 3300*cdf0e10cSrcweir 3301*cdf0e10cSrcweir bUsed = sal_True; 3302*cdf0e10cSrcweir 3303*cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_ENDEXTTEXTINPUT ) 3304*cdf0e10cSrcweir { 3305*cdf0e10cSrcweir // AutoInput after ext text input 3306*cdf0e10cSrcweir 3307*cdf0e10cSrcweir nAutoPos = SCPOS_INVALID; 3308*cdf0e10cSrcweir if (bFormulaMode) 3309*cdf0e10cSrcweir UseFormulaData(); 3310*cdf0e10cSrcweir else 3311*cdf0e10cSrcweir UseColData(); 3312*cdf0e10cSrcweir } 3313*cdf0e10cSrcweir } 3314*cdf0e10cSrcweir 3315*cdf0e10cSrcweir DataChanged(); // calls UpdateParenthesis() 3316*cdf0e10cSrcweir InvalidateAttribs(); //! in DataChanged ? 3317*cdf0e10cSrcweir } 3318*cdf0e10cSrcweir } 3319*cdf0e10cSrcweir 3320*cdf0e10cSrcweir if (pTopView && eMode != SC_INPUT_NONE) 3321*cdf0e10cSrcweir SyncViews(); 3322*cdf0e10cSrcweir } 3323*cdf0e10cSrcweir 3324*cdf0e10cSrcweir return bUsed; 3325*cdf0e10cSrcweir } 3326*cdf0e10cSrcweir 3327*cdf0e10cSrcweir void ScInputHandler::NotifyChange( const ScInputHdlState* pState, 3328*cdf0e10cSrcweir sal_Bool bForce, ScTabViewShell* pSourceSh, 3329*cdf0e10cSrcweir sal_Bool bStopEditing) 3330*cdf0e10cSrcweir { 3331*cdf0e10cSrcweir // #62806# Wenn der Aufruf aus einem Makro-Aufruf im EnterHandler kommt, 3332*cdf0e10cSrcweir // gleich abbrechen und nicht den Status durcheinander bringen 3333*cdf0e10cSrcweir if (bInEnterHandler) 3334*cdf0e10cSrcweir return; 3335*cdf0e10cSrcweir 3336*cdf0e10cSrcweir sal_Bool bRepeat = (pState == pLastState); 3337*cdf0e10cSrcweir if (!bRepeat && pState && pLastState) 3338*cdf0e10cSrcweir bRepeat = sal::static_int_cast<sal_Bool>(*pState == *pLastState); 3339*cdf0e10cSrcweir if (bRepeat && !bForce) 3340*cdf0e10cSrcweir return; 3341*cdf0e10cSrcweir 3342*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 3343*cdf0e10cSrcweir 3344*cdf0e10cSrcweir if ( pState && !pLastState ) // wieder enablen 3345*cdf0e10cSrcweir bForce = sal_True; 3346*cdf0e10cSrcweir 3347*cdf0e10cSrcweir sal_Bool bHadObject = pLastState && pLastState->GetEditData(); 3348*cdf0e10cSrcweir 3349*cdf0e10cSrcweir //! Before EditEngine gets eventually created (so it gets the right pools) 3350*cdf0e10cSrcweir if ( pSourceSh ) 3351*cdf0e10cSrcweir pActiveViewSh = pSourceSh; 3352*cdf0e10cSrcweir else 3353*cdf0e10cSrcweir pActiveViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current()); 3354*cdf0e10cSrcweir 3355*cdf0e10cSrcweir ImplCreateEditEngine(); 3356*cdf0e10cSrcweir 3357*cdf0e10cSrcweir if ( pState != pLastState ) 3358*cdf0e10cSrcweir { 3359*cdf0e10cSrcweir delete pLastState; 3360*cdf0e10cSrcweir pLastState = pState ? new ScInputHdlState( *pState ) : NULL; 3361*cdf0e10cSrcweir } 3362*cdf0e10cSrcweir 3363*cdf0e10cSrcweir if ( pState && pActiveViewSh ) 3364*cdf0e10cSrcweir { 3365*cdf0e10cSrcweir ScModule* pScMod = SC_MOD(); 3366*cdf0e10cSrcweir 3367*cdf0e10cSrcweir if ( pState ) 3368*cdf0e10cSrcweir { 3369*cdf0e10cSrcweir sal_Bool bIgnore = sal_False; 3370*cdf0e10cSrcweir 3371*cdf0e10cSrcweir // hier auch fremde Referenzeingabe beruecksichtigen (z.B. Funktions-AP), 3372*cdf0e10cSrcweir // FormEditData falls gerade von der Hilfe auf Calc umgeschaltet wird: 3373*cdf0e10cSrcweir 3374*cdf0e10cSrcweir if ( !bFormulaMode && !pScMod->IsFormulaMode() && !pScMod->GetFormEditData() ) 3375*cdf0e10cSrcweir { 3376*cdf0e10cSrcweir if ( bModified ) 3377*cdf0e10cSrcweir { 3378*cdf0e10cSrcweir if (pState->GetPos() != aCursorPos) 3379*cdf0e10cSrcweir { 3380*cdf0e10cSrcweir if (!bProtected) 3381*cdf0e10cSrcweir EnterHandler(); 3382*cdf0e10cSrcweir } 3383*cdf0e10cSrcweir else 3384*cdf0e10cSrcweir bIgnore = sal_True; 3385*cdf0e10cSrcweir } 3386*cdf0e10cSrcweir 3387*cdf0e10cSrcweir if ( !bIgnore /* || bRepeat */ ) 3388*cdf0e10cSrcweir { 3389*cdf0e10cSrcweir const ScAddress& rSPos = pState->GetStartPos(); 3390*cdf0e10cSrcweir const ScAddress& rEPos = pState->GetEndPos(); 3391*cdf0e10cSrcweir const EditTextObject* pData = pState->GetEditData(); 3392*cdf0e10cSrcweir String aString = pState->GetString(); 3393*cdf0e10cSrcweir sal_Bool bTxtMod = sal_False; 3394*cdf0e10cSrcweir ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell(); 3395*cdf0e10cSrcweir ScDocument* pDoc = pDocSh->GetDocument(); 3396*cdf0e10cSrcweir 3397*cdf0e10cSrcweir aCursorPos = pState->GetPos(); 3398*cdf0e10cSrcweir 3399*cdf0e10cSrcweir if ( pData /* || bRepeat */ ) 3400*cdf0e10cSrcweir bTxtMod = sal_True; 3401*cdf0e10cSrcweir else if ( bHadObject ) 3402*cdf0e10cSrcweir bTxtMod = sal_True; 3403*cdf0e10cSrcweir else if ( bTextValid ) 3404*cdf0e10cSrcweir bTxtMod = ( aString != aCurrentText ); 3405*cdf0e10cSrcweir else 3406*cdf0e10cSrcweir bTxtMod = ( aString != GetEditText(pEngine) ); 3407*cdf0e10cSrcweir 3408*cdf0e10cSrcweir if ( bTxtMod || bForce ) 3409*cdf0e10cSrcweir { 3410*cdf0e10cSrcweir if (pData) 3411*cdf0e10cSrcweir { 3412*cdf0e10cSrcweir pEngine->SetText( *pData ); 3413*cdf0e10cSrcweir aString = GetEditText(pEngine); 3414*cdf0e10cSrcweir lcl_RemoveTabs(aString); 3415*cdf0e10cSrcweir bTextValid = sal_False; 3416*cdf0e10cSrcweir aCurrentText.Erase(); 3417*cdf0e10cSrcweir } 3418*cdf0e10cSrcweir else 3419*cdf0e10cSrcweir { 3420*cdf0e10cSrcweir aCurrentText = aString; 3421*cdf0e10cSrcweir bTextValid = sal_True; //! erst nur als String merken 3422*cdf0e10cSrcweir } 3423*cdf0e10cSrcweir 3424*cdf0e10cSrcweir if ( pInputWin ) 3425*cdf0e10cSrcweir pInputWin->SetTextString(aString); 3426*cdf0e10cSrcweir } 3427*cdf0e10cSrcweir 3428*cdf0e10cSrcweir if ( pInputWin ) // Bereichsanzeige 3429*cdf0e10cSrcweir { 3430*cdf0e10cSrcweir String aPosStr; 3431*cdf0e10cSrcweir const ScAddress::Details aAddrDetails( pDoc, aCursorPos ); 3432*cdf0e10cSrcweir 3433*cdf0e10cSrcweir // Ist der Bereich ein Name? 3434*cdf0e10cSrcweir //! per Timer suchen ??? 3435*cdf0e10cSrcweir 3436*cdf0e10cSrcweir if ( pActiveViewSh ) 3437*cdf0e10cSrcweir pActiveViewSh->GetViewData()->GetDocument()-> 3438*cdf0e10cSrcweir GetRangeAtBlock( ScRange( rSPos, rEPos ), &aPosStr ); 3439*cdf0e10cSrcweir 3440*cdf0e10cSrcweir if ( !aPosStr.Len() ) // kein Name -> formatieren 3441*cdf0e10cSrcweir { 3442*cdf0e10cSrcweir sal_uInt16 nFlags = 0; 3443*cdf0e10cSrcweir if( aAddrDetails.eConv == formula::FormulaGrammar::CONV_XL_R1C1 ) 3444*cdf0e10cSrcweir nFlags |= SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE; 3445*cdf0e10cSrcweir if ( rSPos != rEPos ) 3446*cdf0e10cSrcweir { 3447*cdf0e10cSrcweir ScRange r(rSPos, rEPos); 3448*cdf0e10cSrcweir nFlags |= (nFlags << 4); 3449*cdf0e10cSrcweir r.Format( aPosStr, SCA_VALID | nFlags, pDoc, aAddrDetails ); 3450*cdf0e10cSrcweir } 3451*cdf0e10cSrcweir else 3452*cdf0e10cSrcweir aCursorPos.Format( aPosStr, SCA_VALID | nFlags, pDoc, aAddrDetails ); 3453*cdf0e10cSrcweir } 3454*cdf0e10cSrcweir //IAccessibility2 Implementation 2009----- 3455*cdf0e10cSrcweir // Disable the accessible VALUE_CHANGE event 3456*cdf0e10cSrcweir sal_Bool bIsSuppressed = pInputWin->IsAccessibilityEventsSuppressed(sal_False); 3457*cdf0e10cSrcweir pInputWin->SetAccessibilityEventsSuppressed(sal_True); 3458*cdf0e10cSrcweir pInputWin->SetPosString(aPosStr); 3459*cdf0e10cSrcweir pInputWin->SetAccessibilityEventsSuppressed(bIsSuppressed); 3460*cdf0e10cSrcweir //-----IAccessibility2 Implementation 2009 3461*cdf0e10cSrcweir pInputWin->SetSumAssignMode(); 3462*cdf0e10cSrcweir } 3463*cdf0e10cSrcweir 3464*cdf0e10cSrcweir if (bStopEditing) 3465*cdf0e10cSrcweir SFX_APP()->Broadcast( SfxSimpleHint( FID_KILLEDITVIEW ) ); 3466*cdf0e10cSrcweir 3467*cdf0e10cSrcweir // As long as the content is not edited, turn off online spelling. 3468*cdf0e10cSrcweir // Online spelling is turned back on in StartTable, after setting 3469*cdf0e10cSrcweir // the right language from cell attributes. 3470*cdf0e10cSrcweir 3471*cdf0e10cSrcweir sal_uLong nCntrl = pEngine->GetControlWord(); 3472*cdf0e10cSrcweir if ( nCntrl & EE_CNTRL_ONLINESPELLING ) 3473*cdf0e10cSrcweir pEngine->SetControlWord( nCntrl & ~EE_CNTRL_ONLINESPELLING ); 3474*cdf0e10cSrcweir 3475*cdf0e10cSrcweir bModified = sal_False; 3476*cdf0e10cSrcweir bSelIsRef = sal_False; 3477*cdf0e10cSrcweir bProtected = sal_False; 3478*cdf0e10cSrcweir bCommandErrorShown = sal_False; 3479*cdf0e10cSrcweir } 3480*cdf0e10cSrcweir } 3481*cdf0e10cSrcweir } 3482*cdf0e10cSrcweir 3483*cdf0e10cSrcweir // bProtected = sal_False; 3484*cdf0e10cSrcweir 3485*cdf0e10cSrcweir if ( pInputWin) 3486*cdf0e10cSrcweir { 3487*cdf0e10cSrcweir if(!pScMod->IsFormulaMode()&& !pScMod->IsRefDialogOpen()) //BugID 54702 3488*cdf0e10cSrcweir { //Wenn RefDialog offen, dann nicht enablen 3489*cdf0e10cSrcweir if ( !pInputWin->IsEnabled()) 3490*cdf0e10cSrcweir { 3491*cdf0e10cSrcweir pInputWin->Enable(); 3492*cdf0e10cSrcweir if(pDelayTimer ) 3493*cdf0e10cSrcweir { 3494*cdf0e10cSrcweir DELETEZ( pDelayTimer ); 3495*cdf0e10cSrcweir } 3496*cdf0e10cSrcweir } 3497*cdf0e10cSrcweir } 3498*cdf0e10cSrcweir else if(pScMod->IsRefDialogOpen()) 3499*cdf0e10cSrcweir { // Da jedes Dokument eigenes InputWin hat, sollte 3500*cdf0e10cSrcweir if ( !pDelayTimer ) // nochmals Timer gestartet werden, da sonst Ein- 3501*cdf0e10cSrcweir { // gabezeile evt. noch aktiv ist. 3502*cdf0e10cSrcweir pDelayTimer = new Timer; 3503*cdf0e10cSrcweir pDelayTimer->SetTimeout( 500 ); // 100ms Verzoegerung 3504*cdf0e10cSrcweir pDelayTimer->SetTimeoutHdl( LINK( this, ScInputHandler, DelayTimer ) ); 3505*cdf0e10cSrcweir pDelayTimer->Start(); 3506*cdf0e10cSrcweir } 3507*cdf0e10cSrcweir } 3508*cdf0e10cSrcweir } 3509*cdf0e10cSrcweir } 3510*cdf0e10cSrcweir else // !pState || !pActiveViewSh 3511*cdf0e10cSrcweir { 3512*cdf0e10cSrcweir if ( !pDelayTimer ) 3513*cdf0e10cSrcweir { 3514*cdf0e10cSrcweir pDelayTimer = new Timer; 3515*cdf0e10cSrcweir pDelayTimer->SetTimeout( 500 ); // 100ms Verzoegerung 3516*cdf0e10cSrcweir pDelayTimer->SetTimeoutHdl( LINK( this, ScInputHandler, DelayTimer ) ); 3517*cdf0e10cSrcweir pDelayTimer->Start(); 3518*cdf0e10cSrcweir } 3519*cdf0e10cSrcweir } 3520*cdf0e10cSrcweir 3521*cdf0e10cSrcweir HideTip(); 3522*cdf0e10cSrcweir HideTipBelow(); 3523*cdf0e10cSrcweir bInOwnChange = sal_False; 3524*cdf0e10cSrcweir } 3525*cdf0e10cSrcweir 3526*cdf0e10cSrcweir void ScInputHandler::UpdateCellAdjust( SvxCellHorJustify eJust ) 3527*cdf0e10cSrcweir { 3528*cdf0e10cSrcweir eAttrAdjust = eJust; 3529*cdf0e10cSrcweir UpdateAdjust( 0 ); 3530*cdf0e10cSrcweir } 3531*cdf0e10cSrcweir 3532*cdf0e10cSrcweir void ScInputHandler::ResetDelayTimer() 3533*cdf0e10cSrcweir { 3534*cdf0e10cSrcweir if(pDelayTimer!=NULL) 3535*cdf0e10cSrcweir { 3536*cdf0e10cSrcweir DELETEZ( pDelayTimer ); 3537*cdf0e10cSrcweir 3538*cdf0e10cSrcweir if ( pInputWin) 3539*cdf0e10cSrcweir { 3540*cdf0e10cSrcweir pInputWin->Enable(); 3541*cdf0e10cSrcweir } 3542*cdf0e10cSrcweir } 3543*cdf0e10cSrcweir } 3544*cdf0e10cSrcweir 3545*cdf0e10cSrcweir IMPL_LINK( ScInputHandler, DelayTimer, Timer*, pTimer ) 3546*cdf0e10cSrcweir { 3547*cdf0e10cSrcweir if ( pTimer == pDelayTimer ) 3548*cdf0e10cSrcweir { 3549*cdf0e10cSrcweir DELETEZ( pDelayTimer ); 3550*cdf0e10cSrcweir 3551*cdf0e10cSrcweir if ( NULL == pLastState || SC_MOD()->IsFormulaMode() || SC_MOD()->IsRefDialogOpen()) 3552*cdf0e10cSrcweir { 3553*cdf0e10cSrcweir //! new method at ScModule to query if function autopilot is open 3554*cdf0e10cSrcweir 3555*cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current(); 3556*cdf0e10cSrcweir if ( pViewFrm && pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) ) 3557*cdf0e10cSrcweir { 3558*cdf0e10cSrcweir if ( pInputWin) 3559*cdf0e10cSrcweir { 3560*cdf0e10cSrcweir pInputWin->EnableButtons( sal_False ); 3561*cdf0e10cSrcweir pInputWin->Disable(); 3562*cdf0e10cSrcweir } 3563*cdf0e10cSrcweir } 3564*cdf0e10cSrcweir else if ( !bFormulaMode ) // #39210# Formel auch z.B. bei Hilfe behalten 3565*cdf0e10cSrcweir { 3566*cdf0e10cSrcweir bInOwnChange = sal_True; // disable ModifyHdl (reset below) 3567*cdf0e10cSrcweir 3568*cdf0e10cSrcweir pActiveViewSh = NULL; 3569*cdf0e10cSrcweir pEngine->SetText( EMPTY_STRING ); 3570*cdf0e10cSrcweir if ( pInputWin ) 3571*cdf0e10cSrcweir { 3572*cdf0e10cSrcweir pInputWin->SetPosString( EMPTY_STRING ); 3573*cdf0e10cSrcweir pInputWin->SetTextString( EMPTY_STRING ); 3574*cdf0e10cSrcweir pInputWin->Disable(); 3575*cdf0e10cSrcweir } 3576*cdf0e10cSrcweir 3577*cdf0e10cSrcweir bInOwnChange = sal_False; 3578*cdf0e10cSrcweir } 3579*cdf0e10cSrcweir } 3580*cdf0e10cSrcweir } 3581*cdf0e10cSrcweir return 0; 3582*cdf0e10cSrcweir } 3583*cdf0e10cSrcweir 3584*cdf0e10cSrcweir void ScInputHandler::InputSelection( EditView* pView ) 3585*cdf0e10cSrcweir { 3586*cdf0e10cSrcweir SyncViews( pView ); 3587*cdf0e10cSrcweir ShowTipCursor(); 3588*cdf0e10cSrcweir UpdateParenthesis(); // Selektion geaendert -> Klammer-Hervorhebung neu 3589*cdf0e10cSrcweir 3590*cdf0e10cSrcweir // when the selection is changed manually, stop overwriting parentheses 3591*cdf0e10cSrcweir ResetAutoPar(); 3592*cdf0e10cSrcweir } 3593*cdf0e10cSrcweir 3594*cdf0e10cSrcweir void ScInputHandler::InputChanged( EditView* pView, sal_Bool bFromNotify ) 3595*cdf0e10cSrcweir { 3596*cdf0e10cSrcweir ESelection aSelection = pView->GetSelection(); 3597*cdf0e10cSrcweir 3598*cdf0e10cSrcweir UpdateActiveView(); 3599*cdf0e10cSrcweir 3600*cdf0e10cSrcweir // #i20282# DataChanged needs to know if this is from the input line's modify handler 3601*cdf0e10cSrcweir sal_Bool bFromTopNotify = ( bFromNotify && pView == pTopView ); 3602*cdf0e10cSrcweir 3603*cdf0e10cSrcweir sal_Bool bNewView = DataChanging(); //! kann das hier ueberhaupt sein? 3604*cdf0e10cSrcweir aCurrentText = pView->GetEditEngine()->GetText(); // auch den String merken 3605*cdf0e10cSrcweir pEngine->SetText( aCurrentText ); 3606*cdf0e10cSrcweir DataChanged( bFromTopNotify ); 3607*cdf0e10cSrcweir bTextValid = sal_True; // wird in DataChanged auf sal_False gesetzt 3608*cdf0e10cSrcweir 3609*cdf0e10cSrcweir if ( pActiveViewSh ) 3610*cdf0e10cSrcweir { 3611*cdf0e10cSrcweir ScViewData* pViewData = pActiveViewSh->GetViewData(); 3612*cdf0e10cSrcweir if ( bNewView ) 3613*cdf0e10cSrcweir pViewData->GetDocShell()->PostEditView( pEngine, aCursorPos ); 3614*cdf0e10cSrcweir 3615*cdf0e10cSrcweir pViewData->EditGrowY(); 3616*cdf0e10cSrcweir pViewData->EditGrowX(); 3617*cdf0e10cSrcweir } 3618*cdf0e10cSrcweir 3619*cdf0e10cSrcweir SyncViews( pView ); 3620*cdf0e10cSrcweir } 3621*cdf0e10cSrcweir 3622*cdf0e10cSrcweir const String& ScInputHandler::GetEditString() 3623*cdf0e10cSrcweir { 3624*cdf0e10cSrcweir if (pEngine) 3625*cdf0e10cSrcweir { 3626*cdf0e10cSrcweir aCurrentText = pEngine->GetText(); // immer neu aus Engine 3627*cdf0e10cSrcweir bTextValid = sal_True; 3628*cdf0e10cSrcweir } 3629*cdf0e10cSrcweir 3630*cdf0e10cSrcweir return aCurrentText; 3631*cdf0e10cSrcweir } 3632*cdf0e10cSrcweir 3633*cdf0e10cSrcweir Size ScInputHandler::GetTextSize() 3634*cdf0e10cSrcweir { 3635*cdf0e10cSrcweir Size aSize; 3636*cdf0e10cSrcweir if ( pEngine ) 3637*cdf0e10cSrcweir aSize = Size( pEngine->CalcTextWidth(), pEngine->GetTextHeight() ); 3638*cdf0e10cSrcweir 3639*cdf0e10cSrcweir return aSize; 3640*cdf0e10cSrcweir } 3641*cdf0e10cSrcweir 3642*cdf0e10cSrcweir sal_Bool ScInputHandler::GetTextAndFields( ScEditEngineDefaulter& rDestEngine ) 3643*cdf0e10cSrcweir { 3644*cdf0e10cSrcweir sal_Bool bRet = sal_False; 3645*cdf0e10cSrcweir if (pEngine) 3646*cdf0e10cSrcweir { 3647*cdf0e10cSrcweir // Feldbefehle enthalten? 3648*cdf0e10cSrcweir 3649*cdf0e10cSrcweir sal_uInt16 nParCnt = pEngine->GetParagraphCount(); 3650*cdf0e10cSrcweir SfxItemSet aSet = pEngine->GetAttribs( ESelection(0,0,nParCnt,0) ); 3651*cdf0e10cSrcweir SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, sal_False ); 3652*cdf0e10cSrcweir if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET ) 3653*cdf0e10cSrcweir { 3654*cdf0e10cSrcweir // Inhalt kopieren 3655*cdf0e10cSrcweir 3656*cdf0e10cSrcweir EditTextObject* pObj = pEngine->CreateTextObject(); 3657*cdf0e10cSrcweir rDestEngine.SetText(*pObj); 3658*cdf0e10cSrcweir delete pObj; 3659*cdf0e10cSrcweir 3660*cdf0e10cSrcweir // Attribute loeschen 3661*cdf0e10cSrcweir 3662*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nParCnt; i++) 3663*cdf0e10cSrcweir rDestEngine.QuickRemoveCharAttribs( i ); 3664*cdf0e10cSrcweir 3665*cdf0e10cSrcweir // Absaetze zusammenfassen 3666*cdf0e10cSrcweir 3667*cdf0e10cSrcweir while ( nParCnt > 1 ) 3668*cdf0e10cSrcweir { 3669*cdf0e10cSrcweir xub_StrLen nLen = rDestEngine.GetTextLen( (sal_uInt16)0 ); 3670*cdf0e10cSrcweir ESelection aSel( 0,nLen, 1,0 ); 3671*cdf0e10cSrcweir rDestEngine.QuickInsertText( ' ', aSel ); // Umbruch durch Space ersetzen 3672*cdf0e10cSrcweir --nParCnt; 3673*cdf0e10cSrcweir } 3674*cdf0e10cSrcweir 3675*cdf0e10cSrcweir bRet = sal_True; 3676*cdf0e10cSrcweir } 3677*cdf0e10cSrcweir } 3678*cdf0e10cSrcweir return bRet; 3679*cdf0e10cSrcweir } 3680*cdf0e10cSrcweir 3681*cdf0e10cSrcweir 3682*cdf0e10cSrcweir //------------------------------------------------------------------------ 3683*cdf0e10cSrcweir // Methoden fuer FunktionsAutopiloten: 3684*cdf0e10cSrcweir // InputGetSelection, InputSetSelection, InputReplaceSelection, InputGetFormulaStr 3685*cdf0e10cSrcweir //------------------------------------------------------------------------ 3686*cdf0e10cSrcweir 3687*cdf0e10cSrcweir void ScInputHandler::InputGetSelection( xub_StrLen& rStart, xub_StrLen& rEnd ) 3688*cdf0e10cSrcweir { 3689*cdf0e10cSrcweir rStart = nFormSelStart; 3690*cdf0e10cSrcweir rEnd = nFormSelEnd; 3691*cdf0e10cSrcweir } 3692*cdf0e10cSrcweir 3693*cdf0e10cSrcweir //------------------------------------------------------------------------ 3694*cdf0e10cSrcweir 3695*cdf0e10cSrcweir EditView* ScInputHandler::GetFuncEditView() 3696*cdf0e10cSrcweir { 3697*cdf0e10cSrcweir UpdateActiveView(); // wegen pTableView 3698*cdf0e10cSrcweir 3699*cdf0e10cSrcweir EditView* pView = NULL; 3700*cdf0e10cSrcweir if ( pInputWin ) 3701*cdf0e10cSrcweir { 3702*cdf0e10cSrcweir pInputWin->MakeDialogEditView(); 3703*cdf0e10cSrcweir pView = pInputWin->GetEditView(); 3704*cdf0e10cSrcweir } 3705*cdf0e10cSrcweir else 3706*cdf0e10cSrcweir { 3707*cdf0e10cSrcweir if ( eMode != SC_INPUT_TABLE ) 3708*cdf0e10cSrcweir { 3709*cdf0e10cSrcweir bCreatingFuncView = sal_True; // RangeFinder nicht anzeigen 3710*cdf0e10cSrcweir SetMode( SC_INPUT_TABLE ); 3711*cdf0e10cSrcweir bCreatingFuncView = sal_False; 3712*cdf0e10cSrcweir if ( pTableView ) 3713*cdf0e10cSrcweir pTableView->GetEditEngine()->SetText( EMPTY_STRING ); 3714*cdf0e10cSrcweir } 3715*cdf0e10cSrcweir pView = pTableView; 3716*cdf0e10cSrcweir } 3717*cdf0e10cSrcweir 3718*cdf0e10cSrcweir return pView; 3719*cdf0e10cSrcweir } 3720*cdf0e10cSrcweir 3721*cdf0e10cSrcweir //------------------------------------------------------------------------ 3722*cdf0e10cSrcweir 3723*cdf0e10cSrcweir void ScInputHandler::InputSetSelection( xub_StrLen nStart, xub_StrLen nEnd ) 3724*cdf0e10cSrcweir { 3725*cdf0e10cSrcweir if ( nStart <= nEnd ) 3726*cdf0e10cSrcweir { 3727*cdf0e10cSrcweir nFormSelStart = nStart; 3728*cdf0e10cSrcweir nFormSelEnd = nEnd; 3729*cdf0e10cSrcweir } 3730*cdf0e10cSrcweir else 3731*cdf0e10cSrcweir { 3732*cdf0e10cSrcweir nFormSelEnd = nStart; 3733*cdf0e10cSrcweir nFormSelStart = nEnd; 3734*cdf0e10cSrcweir } 3735*cdf0e10cSrcweir 3736*cdf0e10cSrcweir EditView* pView = GetFuncEditView(); 3737*cdf0e10cSrcweir if (pView) 3738*cdf0e10cSrcweir pView->SetSelection( ESelection(0,nStart, 0,nEnd) ); 3739*cdf0e10cSrcweir 3740*cdf0e10cSrcweir bModified = sal_True; 3741*cdf0e10cSrcweir } 3742*cdf0e10cSrcweir 3743*cdf0e10cSrcweir //------------------------------------------------------------------------ 3744*cdf0e10cSrcweir 3745*cdf0e10cSrcweir void ScInputHandler::InputReplaceSelection( const String& rStr ) 3746*cdf0e10cSrcweir { 3747*cdf0e10cSrcweir if (!pRefViewSh) 3748*cdf0e10cSrcweir pRefViewSh = pActiveViewSh; 3749*cdf0e10cSrcweir 3750*cdf0e10cSrcweir DBG_ASSERT(nFormSelEnd>=nFormSelStart,"Selektion kaputt..."); 3751*cdf0e10cSrcweir 3752*cdf0e10cSrcweir xub_StrLen nOldLen = nFormSelEnd-nFormSelStart; 3753*cdf0e10cSrcweir xub_StrLen nNewLen = rStr.Len(); 3754*cdf0e10cSrcweir if (nOldLen) 3755*cdf0e10cSrcweir aFormText.Erase( nFormSelStart, nOldLen ); 3756*cdf0e10cSrcweir if (nNewLen) 3757*cdf0e10cSrcweir aFormText.Insert( rStr, nFormSelStart ); 3758*cdf0e10cSrcweir nFormSelEnd = nFormSelStart + nNewLen; 3759*cdf0e10cSrcweir 3760*cdf0e10cSrcweir EditView* pView = GetFuncEditView(); 3761*cdf0e10cSrcweir if (pView) 3762*cdf0e10cSrcweir { 3763*cdf0e10cSrcweir pView->SetEditEngineUpdateMode( sal_False ); 3764*cdf0e10cSrcweir // pView->InsertText( rStr, sal_True ); 3765*cdf0e10cSrcweir pView->GetEditEngine()->SetText( aFormText ); 3766*cdf0e10cSrcweir pView->SetSelection( ESelection(0,nFormSelStart, 0,nFormSelEnd) ); 3767*cdf0e10cSrcweir pView->SetEditEngineUpdateMode( sal_True ); 3768*cdf0e10cSrcweir } 3769*cdf0e10cSrcweir bModified = sal_True; 3770*cdf0e10cSrcweir } 3771*cdf0e10cSrcweir 3772*cdf0e10cSrcweir //------------------------------------------------------------------------ 3773*cdf0e10cSrcweir 3774*cdf0e10cSrcweir String ScInputHandler::InputGetFormulaStr() 3775*cdf0e10cSrcweir { 3776*cdf0e10cSrcweir return aFormText; //! eigene Membervariable? 3777*cdf0e10cSrcweir } 3778*cdf0e10cSrcweir 3779*cdf0e10cSrcweir //======================================================================== 3780*cdf0e10cSrcweir // ScInputHdlState 3781*cdf0e10cSrcweir //======================================================================== 3782*cdf0e10cSrcweir 3783*cdf0e10cSrcweir ScInputHdlState::ScInputHdlState( const ScAddress& rCurPos, 3784*cdf0e10cSrcweir const ScAddress& rStartPos, 3785*cdf0e10cSrcweir const ScAddress& rEndPos, 3786*cdf0e10cSrcweir const String& rString, 3787*cdf0e10cSrcweir const EditTextObject* pData ) 3788*cdf0e10cSrcweir : aCursorPos ( rCurPos ), 3789*cdf0e10cSrcweir aStartPos ( rStartPos ), 3790*cdf0e10cSrcweir aEndPos ( rEndPos ), 3791*cdf0e10cSrcweir aString ( rString ), 3792*cdf0e10cSrcweir pEditData ( pData ? pData->Clone() : NULL ) 3793*cdf0e10cSrcweir { 3794*cdf0e10cSrcweir } 3795*cdf0e10cSrcweir 3796*cdf0e10cSrcweir //------------------------------------------------------------------------ 3797*cdf0e10cSrcweir 3798*cdf0e10cSrcweir ScInputHdlState::ScInputHdlState( const ScInputHdlState& rCpy ) 3799*cdf0e10cSrcweir : pEditData ( NULL ) 3800*cdf0e10cSrcweir { 3801*cdf0e10cSrcweir *this = rCpy; 3802*cdf0e10cSrcweir } 3803*cdf0e10cSrcweir 3804*cdf0e10cSrcweir //------------------------------------------------------------------------ 3805*cdf0e10cSrcweir 3806*cdf0e10cSrcweir ScInputHdlState::~ScInputHdlState() 3807*cdf0e10cSrcweir { 3808*cdf0e10cSrcweir delete pEditData; 3809*cdf0e10cSrcweir } 3810*cdf0e10cSrcweir 3811*cdf0e10cSrcweir //------------------------------------------------------------------------ 3812*cdf0e10cSrcweir 3813*cdf0e10cSrcweir int ScInputHdlState::operator==( const ScInputHdlState& r ) const 3814*cdf0e10cSrcweir { 3815*cdf0e10cSrcweir return ( (aStartPos == r.aStartPos) 3816*cdf0e10cSrcweir && (aEndPos == r.aEndPos) 3817*cdf0e10cSrcweir && (aCursorPos == r.aCursorPos) 3818*cdf0e10cSrcweir && (aString == r.aString) 3819*cdf0e10cSrcweir && ScGlobal::EETextObjEqual( pEditData, r.pEditData ) ); 3820*cdf0e10cSrcweir } 3821*cdf0e10cSrcweir 3822*cdf0e10cSrcweir //------------------------------------------------------------------------ 3823*cdf0e10cSrcweir 3824*cdf0e10cSrcweir ScInputHdlState& ScInputHdlState::operator=( const ScInputHdlState& r ) 3825*cdf0e10cSrcweir { 3826*cdf0e10cSrcweir delete pEditData; 3827*cdf0e10cSrcweir 3828*cdf0e10cSrcweir aCursorPos = r.aCursorPos; 3829*cdf0e10cSrcweir aStartPos = r.aStartPos; 3830*cdf0e10cSrcweir aEndPos = r.aEndPos; 3831*cdf0e10cSrcweir aString = r.aString; 3832*cdf0e10cSrcweir pEditData = r.pEditData ? r.pEditData->Clone() : NULL; 3833*cdf0e10cSrcweir 3834*cdf0e10cSrcweir return *this; 3835*cdf0e10cSrcweir } 3836*cdf0e10cSrcweir 3837*cdf0e10cSrcweir 3838*cdf0e10cSrcweir 3839*cdf0e10cSrcweir 3840