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