1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 28 29 //------------------------------------------------------------------ 30 31 #include <com/sun/star/linguistic2/XThesaurus.hpp> 32 33 #include "scitems.hxx" 34 #include <editeng/eeitem.hxx> 35 36 #include <svx/clipfmtitem.hxx> 37 #include <svx/svxdlg.hxx> 38 #include <editeng/cntritem.hxx> 39 #include <editeng/outliner.hxx> 40 #include <editeng/unolingu.hxx> 41 #include <editeng/crsditem.hxx> 42 #include <editeng/editeng.hxx> 43 #include <editeng/editview.hxx> 44 #include <editeng/escpitem.hxx> 45 #include <editeng/flditem.hxx> 46 #include <editeng/fontitem.hxx> 47 #include <svx/hlnkitem.hxx> 48 #include <sfx2/sidebar/EnumContext.hxx> 49 #include <editeng/postitem.hxx> 50 #include <editeng/scripttypeitem.hxx> 51 #include <editeng/shdditem.hxx> 52 #include <svl/srchitem.hxx> 53 #include <editeng/udlnitem.hxx> 54 #include <editeng/wghtitem.hxx> 55 #include <sfx2/basedlgs.hxx> 56 #include <sfx2/bindings.hxx> 57 #include <sfx2/msg.hxx> 58 #include <sfx2/objface.hxx> 59 #include <sfx2/objsh.hxx> 60 #include <sfx2/request.hxx> 61 #include <sfx2/viewfrm.hxx> 62 #include <sot/exchange.hxx> 63 #include <svtools/cliplistener.hxx> 64 #include <svl/whiter.hxx> 65 #include <vcl/msgbox.hxx> 66 #include <vcl/sound.hxx> 67 #include <sot/formats.hxx> 68 #include <svtools/transfer.hxx> 69 #include <svl/stritem.hxx> 70 71 #define _EDITSH_CXX 72 #include "editsh.hxx" 73 74 #include "scresid.hxx" 75 #include "global.hxx" 76 #include "sc.hrc" 77 #include "scmod.hxx" 78 #include "inputhdl.hxx" 79 #include "viewutil.hxx" 80 #include "viewdata.hxx" 81 #include "document.hxx" 82 //CHINA001 #include "namepast.hxx" 83 #include "reffind.hxx" 84 #include "tabvwsh.hxx" 85 //CHINA001 #include "textdlgs.hxx" 86 #include "editutil.hxx" 87 #include "globstr.hrc" 88 89 #define ScEditShell 90 #include "scslots.hxx" 91 92 #include "scui_def.hxx" //CHINA001 93 #include "scabstdlg.hxx" //CHINA001 94 95 96 using namespace ::com::sun::star; 97 98 99 TYPEINIT1( ScEditShell, SfxShell ); 100 101 SFX_IMPL_INTERFACE(ScEditShell, SfxShell, ScResId(SCSTR_EDITSHELL)) 102 { 103 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_EDIT) ); 104 } 105 106 107 ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) : 108 pEditView (pView), 109 pViewData (pData), 110 pClipEvtLstnr (NULL), 111 bPastePossible (sal_False), 112 bIsInsertMode (sal_True) 113 { 114 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() ); 115 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() ); 116 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("EditCell"))); 117 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_EditCell)); 118 } 119 120 ScEditShell::~ScEditShell() 121 { 122 if ( pClipEvtLstnr ) 123 { 124 pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), sal_False ); 125 126 // #122057# The listener may just now be waiting for the SolarMutex and call the link 127 // afterwards, in spite of RemoveListener. So the link has to be reset, too. 128 pClipEvtLstnr->ClearCallbackLink(); 129 130 pClipEvtLstnr->release(); 131 } 132 } 133 134 ScInputHandler* ScEditShell::GetMyInputHdl() 135 { 136 return SC_MOD()->GetInputHdl( pViewData->GetViewShell() ); 137 } 138 139 void ScEditShell::SetEditView(EditView* pView) 140 { 141 pEditView = pView; 142 pEditView->SetInsertMode( bIsInsertMode ); 143 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() ); 144 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() ); 145 } 146 147 void lcl_RemoveAttribs( EditView& rEditView ) 148 { 149 ScEditEngineDefaulter* pEngine = static_cast<ScEditEngineDefaulter*>(rEditView.GetEditEngine()); 150 151 sal_Bool bOld = pEngine->GetUpdateMode(); 152 pEngine->SetUpdateMode(sal_False); 153 154 String aName = ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS ); 155 pEngine->GetUndoManager().EnterListAction( aName, aName ); 156 157 rEditView.RemoveAttribs(sal_True); 158 pEngine->RepeatDefaults(); // #97226# paragraph attributes from cell formats must be preserved 159 160 pEngine->GetUndoManager().LeaveListAction(); 161 162 pEngine->SetUpdateMode(bOld); 163 } 164 165 void lclInsertCharacter( EditView* pTableView, EditView* pTopView, sal_Unicode cChar ) 166 { 167 String aString( cChar ); 168 if( pTableView ) 169 pTableView->InsertText( aString ); 170 if( pTopView ) 171 pTopView->InsertText( aString ); 172 } 173 174 void ScEditShell::Execute( SfxRequest& rReq ) 175 { 176 const SfxItemSet* pReqArgs = rReq.GetArgs(); 177 sal_uInt16 nSlot = rReq.GetSlot(); 178 SfxBindings& rBindings = pViewData->GetBindings(); 179 180 ScInputHandler* pHdl = GetMyInputHdl(); 181 DBG_ASSERT(pHdl,"kein ScInputHandler"); 182 183 EditView* pTopView = pHdl->GetTopView(); // hat Eingabezeile den Focus? 184 EditView* pTableView = pHdl->GetTableView(); 185 186 DBG_ASSERT(pTableView,"no EditView :-("); 187 /* #i91683# No EditView if spell-check dialog is active and positioned on 188 * an error and user immediately (without double click or F2) selected a 189 * text portion of that cell with the mouse and wanted to modify it. */ 190 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit 191 * action is possible. A real fix somehow would need to create a valid 192 * EditView from the spell-check view. */ 193 if (!pTableView) 194 return; 195 196 EditEngine* pEngine = pTableView->GetEditEngine(); 197 198 pHdl->DataChanging(); 199 sal_Bool bSetSelIsRef = sal_False; 200 sal_Bool bSetModified = sal_True; 201 202 switch ( nSlot ) 203 { 204 case FID_INS_CELL_CONTENTS: // Insert-Taste, weil als Acc definiert 205 bIsInsertMode = !pTableView->IsInsertMode(); 206 pTableView->SetInsertMode( bIsInsertMode ); 207 if (pTopView) 208 pTopView->SetInsertMode( bIsInsertMode ); 209 rBindings.Invalidate( SID_ATTR_INSERT ); 210 break; 211 212 case SID_ATTR_INSERT: 213 if ( pReqArgs ) 214 { 215 bIsInsertMode = ((const SfxBoolItem&)pReqArgs->Get(nSlot)).GetValue(); 216 pTableView->SetInsertMode( bIsInsertMode ); 217 if (pTopView) 218 pTopView->SetInsertMode( bIsInsertMode ); 219 rBindings.Invalidate( SID_ATTR_INSERT ); 220 } 221 break; 222 223 case SID_THES: 224 { 225 String aReplaceText; 226 SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES , sal_False ); 227 if (pItem2) 228 aReplaceText = pItem2->GetValue(); 229 if (aReplaceText.Len() > 0) 230 ReplaceTextWithSynonym( *pEditView, aReplaceText ); 231 } 232 break; 233 234 case SID_COPY: 235 pTableView->Copy(); 236 bSetModified = sal_False; 237 break; 238 239 case SID_CUT: 240 pTableView->Cut(); 241 if (pTopView) 242 pTopView->DeleteSelected(); 243 break; 244 245 case SID_PASTE: 246 pTableView->PasteSpecial(); 247 if (pTopView) 248 pTopView->Paste(); 249 break; 250 251 case SID_DELETE: 252 pTableView->DeleteSelected(); 253 if (pTopView) 254 pTopView->DeleteSelected(); 255 break; 256 257 case SID_CELL_FORMAT_RESET: // "Standard" 258 lcl_RemoveAttribs( *pTableView ); 259 if ( pTopView ) 260 lcl_RemoveAttribs( *pTopView ); 261 break; 262 263 case SID_CLIPBOARD_FORMAT_ITEMS: 264 { 265 sal_uLong nFormat = 0; 266 const SfxPoolItem* pItem; 267 if ( pReqArgs && 268 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET && 269 pItem->ISA(SfxUInt32Item) ) 270 { 271 nFormat = ((const SfxUInt32Item*)pItem)->GetValue(); 272 } 273 274 if ( nFormat ) 275 { 276 if (SOT_FORMAT_STRING == nFormat) 277 pTableView->Paste(); 278 else 279 pTableView->PasteSpecial(); 280 281 if (pTopView) 282 pTopView->Paste(); 283 } 284 } 285 break; 286 287 case SID_PASTE_SPECIAL: 288 { 289 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 290 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pViewData->GetDialogParent() ); 291 sal_uLong nFormat = 0; 292 if ( pDlg ) 293 { 294 pDlg->Insert( SOT_FORMAT_STRING, EMPTY_STRING ); 295 pDlg->Insert( SOT_FORMAT_RTF, EMPTY_STRING ); 296 297 TransferableDataHelper aDataHelper( 298 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) ); 299 300 nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() ); 301 DELETEZ(pDlg); 302 } 303 304 // while the dialog was open, edit mode may have been stopped 305 if (!SC_MOD()->IsInputMode()) 306 { 307 Sound::Beep(); 308 return; 309 } 310 311 if (nFormat > 0) 312 { 313 if (SOT_FORMAT_STRING == nFormat) 314 pTableView->Paste(); 315 else 316 pTableView->PasteSpecial(); 317 318 if (pTopView) 319 pTopView->Paste(); 320 } 321 322 if (pTopView) 323 pTopView->GetWindow()->GrabFocus(); 324 } 325 break; 326 327 case SID_SELECTALL: 328 { 329 sal_uInt16 nPar = pEngine->GetParagraphCount(); 330 if (nPar) 331 { 332 xub_StrLen nLen = pEngine->GetTextLen(nPar-1); 333 pTableView->SetSelection(ESelection(0,0,nPar-1,nLen)); 334 if (pTopView) 335 pTopView->SetSelection(ESelection(0,0,nPar-1,nLen)); 336 rBindings.Invalidate( SID_ATTR_CHAR_FONT ); 337 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT ); 338 rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT ); 339 rBindings.Invalidate( SID_ATTR_CHAR_POSTURE ); 340 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE ); 341 rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT ); 342 rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED ); 343 rBindings.Invalidate( SID_ATTR_CHAR_KERNING ); 344 rBindings.Invalidate( SID_ATTR_CHAR_COLOR ); 345 rBindings.Invalidate( SID_SET_SUPER_SCRIPT ); 346 rBindings.Invalidate( SID_SET_SUB_SCRIPT ); 347 } 348 bSetModified = sal_False; 349 } 350 break; 351 352 case SID_CHARMAP: 353 { 354 sal_uInt16 nScript = pTableView->GetSelectedScriptType(); 355 sal_uInt16 nFontWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? EE_CHAR_FONTINFO_CJK : 356 ( ( nScript == SCRIPTTYPE_COMPLEX ) ? EE_CHAR_FONTINFO_CTL : 357 EE_CHAR_FONTINFO ); 358 const SvxFontItem& rItem = (const SvxFontItem&) 359 pTableView->GetAttribs().Get(nFontWhich); 360 361 String aString; 362 SvxFontItem aNewItem( EE_CHAR_FONTINFO ); 363 364 const SfxItemSet *pArgs = rReq.GetArgs(); 365 const SfxPoolItem* pItem = 0; 366 if( pArgs ) 367 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem); 368 369 if ( pItem ) 370 { 371 aString = ((const SfxStringItem*)pItem)->GetValue(); 372 const SfxPoolItem* pFtItem = NULL; 373 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem); 374 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem ); 375 if ( pFontItem ) 376 { 377 String aFontName(pFontItem->GetValue()); 378 Font aFont(aFontName, Size(1,1)); // Size nur wg. CTOR 379 aNewItem = SvxFontItem( aFont.GetFamily(), aFont.GetName(), 380 aFont.GetStyleName(), aFont.GetPitch(), 381 aFont.GetCharSet(), ATTR_FONT ); 382 } 383 else 384 aNewItem = rItem; 385 } 386 else 387 { 388 ScViewUtil::ExecuteCharMap( rItem, *pViewData->GetViewShell()->GetViewFrame(), aNewItem, aString ); 389 390 // while the dialog was open, edit mode may have been stopped 391 if (!SC_MOD()->IsInputMode()) 392 { 393 Sound::Beep(); 394 return; 395 } 396 } 397 398 if ( aString.Len() ) 399 { 400 // if string contains WEAK characters, set all fonts 401 sal_uInt8 nSetScript; 402 ScDocument* pDoc = pViewData->GetDocument(); 403 if ( pDoc->HasStringWeakCharacters( aString ) ) 404 nSetScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX; 405 else 406 nSetScript = pDoc->GetStringScriptType( aString ); 407 408 SfxItemSet aSet( pTableView->GetEmptyItemSet() ); 409 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() ); 410 aSetItem.PutItemForScriptType( nSetScript, aNewItem ); 411 aSet.Put( aSetItem.GetItemSet(), sal_False ); 412 413 // SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist 414 pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() ); 415 pTableView->InsertText(aString); 416 if (pTopView) 417 pTopView->InsertText(aString); 418 419 SfxStringItem aStringItem( SID_CHARMAP, aString ); 420 SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem.GetFamilyName() ); 421 rReq.AppendItem( aFontItem ); 422 rReq.AppendItem( aStringItem ); 423 rReq.Done(); 424 425 426 } 427 428 if (pTopView) 429 pTopView->GetWindow()->GrabFocus(); 430 } 431 break; 432 433 case FID_INSERT_NAME: 434 { 435 ScDocument* pDoc = pViewData->GetDocument(); 436 //CHINA001 ScNamePasteDlg* pDlg = new ScNamePasteDlg( pViewData->GetDialogParent(), 437 //CHINA001 pDoc->GetRangeName(), sal_False ); 438 // "Liste" disablen 439 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 440 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 441 442 AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pDoc->GetRangeName(), RID_SCDLG_NAMES_PASTE, sal_False ); 443 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 444 short nRet = pDlg->Execute(); 445 // pDlg is needed below 446 447 // while the dialog was open, edit mode may have been stopped 448 if (!SC_MOD()->IsInputMode()) 449 { 450 Sound::Beep(); 451 delete pDlg; 452 return; 453 } 454 455 if ( nRet == BTN_PASTE_NAME ) 456 { 457 String aName = pDlg->GetSelectedName(); 458 pTableView->InsertText(aName); 459 if (pTopView) 460 pTopView->InsertText(aName); 461 } 462 delete pDlg; 463 464 if (pTopView) 465 pTopView->GetWindow()->GrabFocus(); 466 } 467 break; 468 469 case SID_CHAR_DLG_EFFECT: 470 case SID_CHAR_DLG: 471 { 472 SfxItemSet aAttrs( pTableView->GetAttribs() ); 473 474 SfxObjectShell* pObjSh = pViewData->GetSfxDocShell(); 475 476 //CHINA001 ScCharDlg* pDlg = new ScCharDlg( pViewData->GetDialogParent(), &aAttrs, pObjSh ); 477 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 478 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 479 480 SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg( pViewData->GetDialogParent(), &aAttrs, 481 pObjSh, RID_SCDLG_CHAR ); 482 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 483 if (nSlot == SID_CHAR_DLG_EFFECT) 484 { 485 pDlg->SetCurPageId(RID_SVXPAGE_CHAR_EFFECTS); 486 } 487 short nRet = pDlg->Execute(); 488 // pDlg is needed below 489 490 // while the dialog was open, edit mode may have been stopped 491 if (!SC_MOD()->IsInputMode()) 492 { 493 Sound::Beep(); 494 delete pDlg; 495 return; 496 } 497 498 if ( nRet == RET_OK ) 499 { 500 const SfxItemSet* pOut = pDlg->GetOutputItemSet(); 501 pTableView->SetAttribs( *pOut ); 502 } 503 delete pDlg; 504 } 505 break; 506 507 case SID_TOGGLE_REL: 508 { 509 sal_Bool bOk = sal_False; 510 if (pEngine->GetParagraphCount() == 1) 511 { 512 String aText = pEngine->GetText(); 513 ESelection aSel = pEditView->GetSelection(); // aktuelle View 514 515 ScRefFinder aFinder( aText, pViewData->GetDocument() ); 516 aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos ); 517 if (aFinder.GetFound()) 518 { 519 String aNew = aFinder.GetText(); 520 ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() ); 521 pEngine->SetText( aNew ); 522 pTableView->SetSelection( aNewSel ); 523 if ( pTopView ) 524 { 525 pTopView->GetEditEngine()->SetText( aNew ); 526 pTopView->SetSelection( aNewSel ); 527 } 528 bOk = sal_True; 529 530 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben 531 bSetSelIsRef = sal_True; 532 } 533 } 534 if (!bOk) 535 Sound::Beep(); // keine Referenzen oder mehrere Absaetze 536 } 537 break; 538 539 case SID_HYPERLINK_SETLINK: 540 if( pReqArgs ) 541 { 542 const SfxPoolItem* pItem; 543 if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, sal_True, &pItem ) == SFX_ITEM_SET ) 544 { 545 const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem; 546 const String& rName = pHyper->GetName(); 547 const String& rURL = pHyper->GetURL(); 548 const String& rTarget = pHyper->GetTargetFrame(); 549 SvxLinkInsertMode eMode = pHyper->GetInsertMode(); 550 551 sal_Bool bDone = sal_False; 552 if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD ) 553 { 554 const SvxURLField* pURLField = GetURLField(); 555 if ( pURLField ) 556 { 557 // altes Feld selektieren 558 559 ESelection aSel = pTableView->GetSelection(); 560 aSel.Adjust(); 561 aSel.nEndPara = aSel.nStartPara; 562 aSel.nEndPos = aSel.nStartPos + 1; 563 pTableView->SetSelection( aSel ); 564 565 // neues Feld einfuegen 566 567 SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR ); 568 aURLField.SetTargetFrame( rTarget ); 569 SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD ); 570 pTableView->InsertField( aURLItem ); 571 pTableView->SetSelection( aSel ); // select inserted field 572 573 // #57254# jetzt doch auch Felder in der Top-View 574 575 if ( pTopView ) 576 { 577 aSel = pTopView->GetSelection(); 578 aSel.nEndPara = aSel.nStartPara; 579 aSel.nEndPos = aSel.nStartPos + 1; 580 pTopView->SetSelection( aSel ); 581 pTopView->InsertField( aURLItem ); 582 pTopView->SetSelection( aSel ); // select inserted field 583 } 584 585 bDone = sal_True; 586 } 587 } 588 589 if (!bDone) 590 { 591 pViewData->GetViewShell()-> 592 InsertURL( rName, rURL, rTarget, (sal_uInt16) eMode ); 593 594 // InsertURL an der ViewShell schaltet bei "Button" 595 // die EditShell ab, darum sofort return 596 597 return; 598 } 599 } 600 } 601 break; 602 603 case SID_OPEN_HYPERLINK: 604 { 605 const SvxURLField* pURLField = GetURLField(); 606 if ( pURLField ) 607 ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() ); 608 return; 609 } 610 //break; 611 612 case FN_INSERT_SOFT_HYPHEN: 613 lclInsertCharacter( pTableView, pTopView, CHAR_SHY ); 614 break; 615 case FN_INSERT_HARDHYPHEN: 616 lclInsertCharacter( pTableView, pTopView, CHAR_NBHY ); 617 break; 618 case FN_INSERT_HARD_SPACE: 619 lclInsertCharacter( pTableView, pTopView, CHAR_NBSP ); 620 break; 621 case SID_INSERT_RLM: 622 lclInsertCharacter( pTableView, pTopView, CHAR_RLM ); 623 break; 624 case SID_INSERT_LRM: 625 lclInsertCharacter( pTableView, pTopView, CHAR_LRM ); 626 break; 627 case SID_INSERT_ZWSP: 628 lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP ); 629 break; 630 case SID_INSERT_ZWNBSP: 631 lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP ); 632 break; 633 } 634 635 pHdl->DataChanged(sal_False, bSetModified); 636 if (bSetSelIsRef) 637 pHdl->SetSelIsRef(sal_True); 638 } 639 640 void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots 641 { 642 SfxWhichIter aIter( rSet ); 643 sal_uInt16 nWhich = aIter.FirstWhich(); 644 while (nWhich) 645 { 646 rSet.DisableItem( nWhich ); 647 nWhich = aIter.NextWhich(); 648 } 649 } 650 651 void __EXPORT ScEditShell::GetState( SfxItemSet& rSet ) 652 { 653 // #125326# When deactivating the view, edit mode is stopped, but the EditShell is left active 654 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted 655 // into the EditEngine, so it can have an invalid selection and must not be used. 656 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) ) 657 { 658 lcl_DisableAll( rSet ); 659 return; 660 } 661 662 ScInputHandler* pHdl = GetMyInputHdl(); 663 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView; 664 665 SfxWhichIter aIter( rSet ); 666 sal_uInt16 nWhich = aIter.FirstWhich(); 667 while (nWhich) 668 { 669 switch (nWhich) 670 { 671 case SID_ATTR_INSERT: // Statuszeile 672 { 673 if ( pActiveView ) 674 rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) ); 675 else 676 rSet.Put( SfxBoolItem( nWhich, 42 ) ); 677 } 678 break; 679 680 case SID_HYPERLINK_GETLINK: 681 { 682 SvxHyperlinkItem aHLinkItem; 683 const SvxURLField* pURLField = GetURLField(); 684 if ( pURLField ) 685 { 686 aHLinkItem.SetName( pURLField->GetRepresentation() ); 687 aHLinkItem.SetURL( pURLField->GetURL() ); 688 aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() ); 689 } 690 else if ( pActiveView ) 691 { 692 // use selected text as name for urls 693 String sReturn = pActiveView->GetSelected(); 694 sReturn.Erase(255); 695 sReturn.EraseTrailingChars(); 696 aHLinkItem.SetName(sReturn); 697 } 698 rSet.Put(aHLinkItem); 699 } 700 break; 701 702 case SID_OPEN_HYPERLINK: 703 { 704 if ( !GetURLField() ) 705 rSet.DisableItem( nWhich ); 706 } 707 break; 708 709 case SID_TRANSLITERATE_HALFWIDTH: 710 case SID_TRANSLITERATE_FULLWIDTH: 711 case SID_TRANSLITERATE_HIRAGANA: 712 case SID_TRANSLITERATE_KATAGANA: 713 case SID_INSERT_RLM: 714 case SID_INSERT_LRM: 715 case SID_INSERT_ZWNBSP: 716 case SID_INSERT_ZWSP: 717 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich ); 718 break; 719 720 case SID_THES: 721 { 722 String aStatusVal; 723 LanguageType nLang = LANGUAGE_NONE; 724 bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, *pActiveView ); 725 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) ); 726 727 // disable thesaurus context menu entry if there is nothing to look up 728 sal_Bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang ); 729 if (!bIsLookUpWord || !bCanDoThesaurus) 730 rSet.DisableItem( SID_THES ); 731 } 732 break; 733 734 735 } 736 nWhich = aIter.NextWhich(); 737 } 738 } 739 740 const SvxURLField* ScEditShell::GetURLField() 741 { 742 ScInputHandler* pHdl = GetMyInputHdl(); 743 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView; 744 if ( pActiveView ) 745 { 746 const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection(); 747 if (pFieldItem) 748 { 749 const SvxFieldData* pField = pFieldItem->GetField(); 750 if ( pField && pField->ISA(SvxURLField) ) 751 return (const SvxURLField*)pField; 752 } 753 } 754 755 return NULL; 756 } 757 758 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper ) 759 { 760 if ( pDataHelper ) 761 { 762 bPastePossible = ( pDataHelper->HasFormat( SOT_FORMAT_STRING ) || pDataHelper->HasFormat( SOT_FORMAT_RTF ) ); 763 764 SfxBindings& rBindings = pViewData->GetBindings(); 765 rBindings.Invalidate( SID_PASTE ); 766 rBindings.Invalidate( SID_PASTE_SPECIAL ); 767 rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS ); 768 } 769 return 0; 770 } 771 772 void __EXPORT ScEditShell::GetClipState( SfxItemSet& rSet ) 773 { 774 if ( !pClipEvtLstnr ) 775 { 776 // create listener 777 pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) ); 778 pClipEvtLstnr->acquire(); 779 Window* pWin = pViewData->GetActiveWin(); 780 pClipEvtLstnr->AddRemoveListener( pWin, sal_True ); 781 782 // get initial state 783 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) ); 784 bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) ); 785 } 786 787 SfxWhichIter aIter( rSet ); 788 sal_uInt16 nWhich = aIter.FirstWhich(); 789 while (nWhich) 790 { 791 switch (nWhich) 792 { 793 case SID_PASTE: 794 case SID_PASTE_SPECIAL: 795 if( !bPastePossible ) 796 rSet.DisableItem( nWhich ); 797 break; 798 case SID_CLIPBOARD_FORMAT_ITEMS: 799 if( bPastePossible ) 800 { 801 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS ); 802 TransferableDataHelper aDataHelper( 803 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) ); 804 805 if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) ) 806 aFormats.AddClipbrdFormat( SOT_FORMAT_STRING ); 807 if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) ) 808 aFormats.AddClipbrdFormat( SOT_FORMAT_RTF ); 809 810 rSet.Put( aFormats ); 811 } 812 else 813 rSet.DisableItem( nWhich ); 814 break; 815 } 816 nWhich = aIter.NextWhich(); 817 } 818 } 819 820 void lcl_InvalidateUnder( SfxBindings& rBindings ) 821 { 822 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE ); 823 rBindings.Invalidate( SID_ULINE_VAL_NONE ); 824 rBindings.Invalidate( SID_ULINE_VAL_SINGLE ); 825 rBindings.Invalidate( SID_ULINE_VAL_DOUBLE ); 826 rBindings.Invalidate( SID_ULINE_VAL_DOTTED ); 827 } 828 829 void ScEditShell::ExecuteAttr(SfxRequest& rReq) 830 { 831 SfxItemSet aSet( pEditView->GetEmptyItemSet() ); 832 SfxBindings& rBindings = pViewData->GetBindings(); 833 const SfxItemSet* pArgs = rReq.GetArgs(); 834 sal_uInt16 nSlot = rReq.GetSlot(); 835 836 switch ( nSlot ) 837 { 838 case SID_ATTR_CHAR_FONTHEIGHT: 839 case SID_ATTR_CHAR_FONT: 840 { 841 if (pArgs) 842 { 843 // #i78017 establish the same behaviour as in Writer 844 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX; 845 if (nSlot == SID_ATTR_CHAR_FONT) 846 { 847 nScript = pEditView->GetSelectedScriptType(); 848 if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType(); 849 } 850 851 SfxItemPool& rPool = GetPool(); 852 SvxScriptSetItem aSetItem( nSlot, rPool ); 853 sal_uInt16 nWhich = rPool.GetWhich( nSlot ); 854 aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) ); 855 856 aSet.Put( aSetItem.GetItemSet(), sal_False ); 857 } 858 } 859 break; 860 861 case SID_ATTR_CHAR_COLOR: 862 { 863 if (pArgs) 864 { 865 aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) ); 866 rBindings.Invalidate( nSlot ); 867 } 868 } 869 break; 870 871 // Toggles 872 873 case SID_ATTR_CHAR_WEIGHT: 874 { 875 // #i78017 establish the same behaviour as in Writer 876 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX; 877 878 SfxItemPool& rPool = GetPool(); 879 880 sal_Bool bOld = sal_False; 881 SvxScriptSetItem aOldSetItem( nSlot, rPool ); 882 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False ); 883 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript ); 884 if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() > WEIGHT_NORMAL ) 885 bOld = sal_True; 886 887 SvxScriptSetItem aSetItem( nSlot, rPool ); 888 aSetItem.PutItemForScriptType( nScript, 889 SvxWeightItem( bOld ? WEIGHT_NORMAL : WEIGHT_BOLD, EE_CHAR_WEIGHT ) ); 890 aSet.Put( aSetItem.GetItemSet(), sal_False ); 891 892 rBindings.Invalidate( nSlot ); 893 } 894 break; 895 896 case SID_ATTR_CHAR_POSTURE: 897 { 898 // #i78017 establish the same behaviour as in Writer 899 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX; 900 901 SfxItemPool& rPool = GetPool(); 902 903 sal_Bool bOld = sal_False; 904 SvxScriptSetItem aOldSetItem( nSlot, rPool ); 905 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False ); 906 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript ); 907 if ( pCore && ((const SvxPostureItem*)pCore)->GetValue() != ITALIC_NONE ) 908 bOld = sal_True; 909 910 SvxScriptSetItem aSetItem( nSlot, rPool ); 911 aSetItem.PutItemForScriptType( nScript, 912 SvxPostureItem( bOld ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) ); 913 aSet.Put( aSetItem.GetItemSet(), sal_False ); 914 915 rBindings.Invalidate( nSlot ); 916 } 917 break; 918 919 case SID_ULINE_VAL_NONE: 920 aSet.Put( SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE ) ); 921 lcl_InvalidateUnder( rBindings ); 922 break; 923 924 case SID_ATTR_CHAR_UNDERLINE: // Toggles 925 case SID_ULINE_VAL_SINGLE: 926 case SID_ULINE_VAL_DOUBLE: 927 case SID_ULINE_VAL_DOTTED: 928 { 929 FontUnderline eOld = ((const SvxUnderlineItem&) pEditView-> 930 GetAttribs().Get(EE_CHAR_UNDERLINE)).GetLineStyle(); 931 FontUnderline eNew = eOld; 932 switch (nSlot) 933 { 934 case SID_ATTR_CHAR_UNDERLINE: 935 eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE; 936 break; 937 case SID_ULINE_VAL_SINGLE: 938 eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE; 939 break; 940 case SID_ULINE_VAL_DOUBLE: 941 eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE; 942 break; 943 case SID_ULINE_VAL_DOTTED: 944 eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED; 945 break; 946 } 947 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) ); 948 lcl_InvalidateUnder( rBindings ); 949 } 950 break; 951 952 case SID_ATTR_CHAR_OVERLINE: 953 { 954 FontUnderline eOld = ((const SvxOverlineItem&) pEditView-> 955 GetAttribs().Get(EE_CHAR_OVERLINE)).GetLineStyle(); 956 FontUnderline eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE; 957 aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) ); 958 rBindings.Invalidate( nSlot ); 959 } 960 break; 961 962 case SID_ATTR_CHAR_STRIKEOUT: 963 { 964 sal_Bool bOld = ((const SvxCrossedOutItem&)pEditView->GetAttribs(). 965 Get(EE_CHAR_STRIKEOUT)).GetValue() != STRIKEOUT_NONE; 966 aSet.Put( SvxCrossedOutItem( bOld ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) ); 967 rBindings.Invalidate( nSlot ); 968 } 969 break; 970 971 case SID_ATTR_CHAR_SHADOWED: 972 { 973 sal_Bool bOld = ((const SvxShadowedItem&)pEditView->GetAttribs(). 974 Get(EE_CHAR_SHADOW)).GetValue(); 975 aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) ); 976 rBindings.Invalidate( nSlot ); 977 } 978 break; 979 980 case SID_ATTR_CHAR_CONTOUR: 981 { 982 sal_Bool bOld = ((const SvxContourItem&)pEditView->GetAttribs(). 983 Get(EE_CHAR_OUTLINE)).GetValue(); 984 aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) ); 985 rBindings.Invalidate( nSlot ); 986 } 987 break; 988 989 case SID_SET_SUPER_SCRIPT: 990 { 991 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&) 992 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue(); 993 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUPERSCRIPT) ? 994 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUPERSCRIPT; 995 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) ); 996 rBindings.Invalidate( nSlot ); 997 } 998 break; 999 case SID_SET_SUB_SCRIPT: 1000 { 1001 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&) 1002 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue(); 1003 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUBSCRIPT) ? 1004 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUBSCRIPT; 1005 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) ); 1006 rBindings.Invalidate( nSlot ); 1007 } 1008 break; 1009 case SID_ATTR_CHAR_KERNING: 1010 { 1011 if(pArgs) 1012 { 1013 aSet.Put ( pArgs->Get(pArgs->GetPool()->GetWhich(nSlot))); 1014 rBindings.Invalidate( nSlot ); 1015 } 1016 } 1017 break; 1018 } 1019 1020 // 1021 // anwenden 1022 // 1023 1024 EditEngine* pEngine = pEditView->GetEditEngine(); 1025 sal_Bool bOld = pEngine->GetUpdateMode(); 1026 pEngine->SetUpdateMode(sal_False); 1027 1028 pEditView->SetAttribs( aSet ); 1029 1030 pEngine->SetUpdateMode(bOld); 1031 pEditView->Invalidate(); 1032 1033 ScInputHandler* pHdl = GetMyInputHdl(); 1034 pHdl->SetModified(); 1035 1036 rReq.Done(); 1037 } 1038 1039 void ScEditShell::GetAttrState(SfxItemSet &rSet) 1040 { 1041 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) ) // #125326# 1042 { 1043 lcl_DisableAll( rSet ); 1044 return; 1045 } 1046 1047 SfxItemSet aAttribs = pEditView->GetAttribs(); 1048 rSet.Put( aAttribs ); 1049 1050 // choose font info according to selection script type 1051 1052 sal_uInt16 nScript = pEditView->GetSelectedScriptType(); 1053 if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType(); 1054 1055 // #i55929# input-language-dependent script type (depends on input language if nothing selected) 1056 sal_uInt16 nInputScript = nScript; 1057 if ( !pEditView->GetSelection().HasRange() ) 1058 { 1059 LanguageType nInputLang = pViewData->GetActiveWin()->GetInputLanguage(); 1060 if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM) 1061 nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang ); 1062 } 1063 1064 // #i55929# according to spec, nInputScript is used for font and font height only 1065 if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SFX_ITEM_UNKNOWN ) 1066 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript ); 1067 if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SFX_ITEM_UNKNOWN ) 1068 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript ); 1069 if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SFX_ITEM_UNKNOWN ) 1070 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript ); 1071 if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SFX_ITEM_UNKNOWN ) 1072 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript ); 1073 1074 // Unterstreichung 1075 1076 SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE, sal_True ); 1077 if ( eState == SFX_ITEM_DONTCARE ) 1078 { 1079 rSet.InvalidateItem( SID_ULINE_VAL_NONE ); 1080 rSet.InvalidateItem( SID_ULINE_VAL_SINGLE ); 1081 rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE ); 1082 rSet.InvalidateItem( SID_ULINE_VAL_DOTTED ); 1083 } 1084 else 1085 { 1086 FontUnderline eUnderline = ((const SvxUnderlineItem&) 1087 aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle(); 1088 sal_uInt16 nId = SID_ULINE_VAL_NONE; 1089 switch (eUnderline) 1090 { 1091 case UNDERLINE_SINGLE: nId = SID_ULINE_VAL_SINGLE; break; 1092 case UNDERLINE_DOUBLE: nId = SID_ULINE_VAL_DOUBLE; break; 1093 case UNDERLINE_DOTTED: nId = SID_ULINE_VAL_DOTTED; break; 1094 default: 1095 break; 1096 } 1097 rSet.Put( SfxBoolItem( nId, sal_True ) ); 1098 } 1099 1100 //! Testen, ob Klammer-Hervorhebung aktiv ist !!!! 1101 ScInputHandler* pHdl = GetMyInputHdl(); 1102 if ( pHdl && pHdl->IsFormulaMode() ) 1103 rSet.ClearItem( EE_CHAR_WEIGHT ); // hervorgehobene Klammern hier nicht 1104 1105 SvxEscapement eEsc = (SvxEscapement) ( (const SvxEscapementItem&) 1106 aAttribs.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue(); 1107 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT ) 1108 { 1109 rSet.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT, sal_True ) ); 1110 } 1111 else if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT ) 1112 { 1113 rSet.Put( SfxBoolItem( SID_SET_SUB_SCRIPT, sal_True ) ); 1114 } 1115 pViewData->GetBindings().Invalidate( SID_SET_SUPER_SCRIPT ); 1116 pViewData->GetBindings().Invalidate( SID_SET_SUB_SCRIPT ); 1117 1118 eState = aAttribs.GetItemState( EE_CHAR_KERNING, sal_True ); 1119 pViewData->GetBindings().Invalidate( SID_ATTR_CHAR_KERNING ); 1120 if ( eState == SFX_ITEM_DONTCARE ) 1121 { 1122 // rSet.InvalidateItem( SID_ATTR_CHAR_KERNING ); 1123 rSet.InvalidateItem(EE_CHAR_KERNING); 1124 } 1125 } 1126 1127 String ScEditShell::GetSelectionText( sal_Bool bWholeWord ) 1128 { 1129 String aStrSelection; 1130 1131 if ( pViewData->HasEditView( pViewData->GetActivePart() ) ) // #125326# 1132 { 1133 if ( bWholeWord ) 1134 { 1135 EditEngine* pEngine = pEditView->GetEditEngine(); 1136 ESelection aSel = pEditView->GetSelection(); 1137 String aStrCurrentDelimiters = pEngine->GetWordDelimiters(); 1138 1139 pEngine->SetWordDelimiters( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" .,;\"'")) ); 1140 aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos ); 1141 pEngine->SetWordDelimiters( aStrCurrentDelimiters ); 1142 } 1143 else 1144 { 1145 aStrSelection = pEditView->GetSelected(); 1146 } 1147 } 1148 1149 return aStrSelection; 1150 } 1151 1152 void ScEditShell::ExecuteUndo(SfxRequest& rReq) 1153 { 1154 // #81733# Undo must be handled here because it's called for both EditViews 1155 1156 ScInputHandler* pHdl = GetMyInputHdl(); 1157 DBG_ASSERT(pHdl,"no ScInputHandler"); 1158 EditView* pTopView = pHdl->GetTopView(); 1159 EditView* pTableView = pHdl->GetTableView(); 1160 DBG_ASSERT(pTableView,"no EditView"); 1161 1162 pHdl->DataChanging(); 1163 1164 const SfxItemSet* pReqArgs = rReq.GetArgs(); 1165 sal_uInt16 nSlot = rReq.GetSlot(); 1166 switch ( nSlot ) 1167 { 1168 case SID_UNDO: 1169 case SID_REDO: 1170 { 1171 sal_Bool bIsUndo = ( nSlot == SID_UNDO ); 1172 1173 sal_uInt16 nCount = 1; 1174 const SfxPoolItem* pItem; 1175 if ( pReqArgs && pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET ) 1176 nCount = ((const SfxUInt16Item*)pItem)->GetValue(); 1177 1178 for (sal_uInt16 i=0; i<nCount; i++) 1179 { 1180 if ( bIsUndo ) 1181 { 1182 pTableView->Undo(); 1183 if (pTopView) 1184 pTopView->Undo(); 1185 } 1186 else 1187 { 1188 pTableView->Redo(); 1189 if (pTopView) 1190 pTopView->Redo(); 1191 } 1192 } 1193 } 1194 break; 1195 } 1196 pViewData->GetBindings().InvalidateAll(sal_False); 1197 1198 pHdl->DataChanged(); 1199 } 1200 1201 void ScEditShell::GetUndoState(SfxItemSet &rSet) 1202 { 1203 // Undo state is taken from normal ViewFrame state function 1204 1205 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame(); 1206 if ( pViewFrm && GetUndoManager() ) 1207 { 1208 SfxWhichIter aIter(rSet); 1209 sal_uInt16 nWhich = aIter.FirstWhich(); 1210 while( nWhich ) 1211 { 1212 pViewFrm->GetSlotState( nWhich, NULL, &rSet ); 1213 nWhich = aIter.NextWhich(); 1214 } 1215 } 1216 1217 // disable if no action in input line EditView 1218 1219 ScInputHandler* pHdl = GetMyInputHdl(); 1220 DBG_ASSERT(pHdl,"no ScInputHandler"); 1221 EditView* pTopView = pHdl->GetTopView(); 1222 if (pTopView) 1223 { 1224 ::svl::IUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager(); 1225 if ( rTopMgr.GetUndoActionCount() == 0 ) 1226 rSet.DisableItem( SID_UNDO ); 1227 if ( rTopMgr.GetRedoActionCount() == 0 ) 1228 rSet.DisableItem( SID_REDO ); 1229 } 1230 } 1231 1232 void ScEditShell::ExecuteTrans( SfxRequest& rReq ) 1233 { 1234 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() ); 1235 if ( nType ) 1236 { 1237 ScInputHandler* pHdl = GetMyInputHdl(); 1238 DBG_ASSERT( pHdl, "no ScInputHandler" ); 1239 1240 EditView* pTopView = pHdl->GetTopView(); 1241 EditView* pTableView = pHdl->GetTableView(); 1242 DBG_ASSERT( pTableView, "no EditView" ); 1243 1244 pHdl->DataChanging(); 1245 1246 pTableView->TransliterateText( nType ); 1247 if (pTopView) 1248 pTopView->TransliterateText( nType ); 1249 1250 pHdl->DataChanged(); 1251 } 1252 } 1253