LibreOffice Module sc (master)  1
editsh.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <comphelper/string.hxx>
21 #include <scitems.hxx>
22 #include <editeng/eeitem.hxx>
23 #include <i18nutil/unicode.hxx>
24 
25 #include <svx/clipfmtitem.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <editeng/contouritem.hxx>
28 #include <editeng/outliner.hxx>
30 #include <editeng/editeng.hxx>
31 #include <editeng/editview.hxx>
33 #include <editeng/flditem.hxx>
34 #include <editeng/flstitem.hxx>
35 #include <editeng/fontitem.hxx>
37 #include <svx/hlnkitem.hxx>
38 #include <vcl/EnumContext.hxx>
39 #include <editeng/postitem.hxx>
41 #include <editeng/shdditem.hxx>
42 #include <editeng/udlnitem.hxx>
43 #include <editeng/wghtitem.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/msg.hxx>
47 #include <sfx2/objface.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/viewfrm.hxx>
51 #include <svtools/cliplistener.hxx>
52 #include <svl/whiter.hxx>
53 #include <sot/formats.hxx>
54 #include <vcl/transfer.hxx>
55 #include <vcl/unohelp2.hxx>
56 #include <svl/stritem.hxx>
57 #include <editeng/colritem.hxx>
58 
59 #include <editsh.hxx>
60 #include <global.hxx>
61 #include <sc.hrc>
62 #include <scmod.hxx>
63 #include <inputhdl.hxx>
64 #include <viewutil.hxx>
65 #include <viewdata.hxx>
66 #include <document.hxx>
67 #include <reffind.hxx>
68 #include <tabvwsh.hxx>
69 #include <editutil.hxx>
70 #include <globstr.hrc>
71 #include <scresid.hxx>
72 #include <gridwin.hxx>
73 
74 #define ShellClass_ScEditShell
75 #include <scslots.hxx>
76 
77 #include <scui_def.hxx>
78 #include <scabstdlg.hxx>
79 #include <memory>
80 
81 using namespace ::com::sun::star;
82 
83 
85 
86 void ScEditShell::InitInterface_Impl()
87 {
88  GetStaticInterface()->RegisterPopupMenu("celledit");
89 }
90 
92  pEditView (pView),
93  rViewData (rData),
94  bPastePossible (false),
95  bIsInsertMode (true)
96 {
99  SetName("EditCell");
101 }
102 
104 {
105  if ( mxClipEvtLstnr.is() )
106  {
107  mxClipEvtLstnr->RemoveListener( rViewData.GetActiveWin() );
108 
109  // The listener may just now be waiting for the SolarMutex and call the link
110  // afterwards, in spite of RemoveListener. So the link has to be reset, too.
111  mxClipEvtLstnr->ClearCallbackLink();
112  }
113 }
114 
116 {
117  return SC_MOD()->GetInputHdl( rViewData.GetViewShell() );
118 }
119 
121 {
122  pEditView = pView;
126 }
127 
128 static void lcl_RemoveAttribs( EditView& rEditView )
129 {
130  ScEditEngineDefaulter* pEngine = static_cast<ScEditEngineDefaulter*>(rEditView.GetEditEngine());
131 
132  bool bOld = pEngine->GetUpdateMode();
133  pEngine->SetUpdateMode(false);
134 
135  OUString aName = ScResId( STR_UNDO_DELETECONTENTS );
136  ViewShellId nViewShellId(-1);
138  nViewShellId = pViewSh->GetViewShellId();
139  pEngine->GetUndoManager().EnterListAction( aName, aName, 0, nViewShellId );
140 
141  rEditView.RemoveAttribs(true);
142  pEngine->RepeatDefaults(); // paragraph attributes from cell formats must be preserved
143 
144  pEngine->GetUndoManager().LeaveListAction();
145 
146  pEngine->SetUpdateMode(bOld);
147 }
148 
149 static void lclInsertCharacter( EditView* pTableView, EditView* pTopView, sal_Unicode cChar )
150 {
151  OUString aString( cChar );
152  if( pTableView )
153  pTableView->InsertText( aString );
154  if( pTopView )
155  pTopView->InsertText( aString );
156 }
157 
159 {
160  const SfxItemSet* pReqArgs = rReq.GetArgs();
161  sal_uInt16 nSlot = rReq.GetSlot();
162  SfxBindings& rBindings = rViewData.GetBindings();
163 
164  ScInputHandler* pHdl = GetMyInputHdl();
165  OSL_ENSURE(pHdl,"no ScInputHandler");
166 
167  EditView* pTopView = pHdl->GetTopView(); // Has thee input cell the focus?
168  EditView* pTableView = pHdl->GetTableView();
169 
170  OSL_ENSURE(pTableView,"no EditView :-(");
171  /* #i91683# No EditView if spell-check dialog is active and positioned on
172  * an error and user immediately (without double click or F2) selected a
173  * text portion of that cell with the mouse and wanted to modify it. */
174  /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
175  * action is possible. A real fix somehow would need to create a valid
176  * EditView from the spell-check view. */
177  if (!pTableView)
178  return;
179 
180  EditEngine* pEngine = pTableView->GetEditEngine();
181 
182  pHdl->DataChanging();
183  bool bSetSelIsRef = false;
184  bool bSetModified = true;
185 
186  switch ( nSlot )
187  {
188  case SID_ATTR_INSERT:
189  case FID_INS_CELL_CONTENTS: // Insert taste, while defined as Acc
190  bIsInsertMode = !pTableView->IsInsertMode();
191  pTableView->SetInsertMode( bIsInsertMode );
192  if (pTopView)
193  pTopView->SetInsertMode( bIsInsertMode );
194  rBindings.Invalidate( SID_ATTR_INSERT );
195  break;
196 
197  case SID_THES:
198  {
199  OUString aReplaceText;
200  const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES);
201  if (pItem2)
202  aReplaceText = pItem2->GetValue();
203  if (!aReplaceText.isEmpty())
204  ReplaceTextWithSynonym( *pEditView, aReplaceText );
205  }
206  break;
207 
208  case SID_COPY:
209  pTableView->Copy();
210  bSetModified = false;
211  break;
212 
213  case SID_CUT:
214  pTableView->Cut();
215  if (pTopView)
216  pTopView->DeleteSelected();
217  break;
218 
219  case SID_PASTE:
220  {
221  EVControlBits nControl = pTableView->GetControlWord();
222  if (pTopView)
223  {
224  pTopView->Paste();
225  pTableView->SetControlWord(nControl | EVControlBits::SINGLELINEPASTE);
226  }
227 
228  pTableView->PasteSpecial();
229  pTableView->SetControlWord(nControl);
230  }
231  break;
232 
233  case SID_DELETE:
234  pTableView->DeleteSelected();
235  if (pTopView)
236  pTopView->DeleteSelected();
237  break;
238 
239  case SID_CELL_FORMAT_RESET: // "Standard"
240  lcl_RemoveAttribs( *pTableView );
241  if ( pTopView )
242  lcl_RemoveAttribs( *pTopView );
243  break;
244 
245  case SID_CLIPBOARD_FORMAT_ITEMS:
246  {
247  SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
248  const SfxPoolItem* pItem;
249  if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
250  if (auto pIntItem = dynamic_cast<const SfxUInt32Item*>( pItem))
251  nFormat = static_cast<SotClipboardFormatId>(pIntItem->GetValue());
252 
253  if ( nFormat != SotClipboardFormatId::NONE )
254  {
255  if (SotClipboardFormatId::STRING == nFormat)
256  pTableView->Paste();
257  else
258  pTableView->PasteSpecial();
259 
260  if (pTopView)
261  pTopView->Paste();
262  }
263  }
264  break;
265 
266  case SID_PASTE_SPECIAL:
267  {
269  ScopedVclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog(rViewData.GetDialogParent()));
270  SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
271  pDlg->Insert( SotClipboardFormatId::STRING, EMPTY_OUSTRING );
272  pDlg->Insert( SotClipboardFormatId::RTF, EMPTY_OUSTRING );
273  pDlg->Insert( SotClipboardFormatId::RICHTEXT, EMPTY_OUSTRING );
274  // Do not offer SotClipboardFormatId::STRING_TSVC for
275  // in-cell paste.
276 
277  TransferableDataHelper aDataHelper(
279 
280  nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
281  pDlg.disposeAndClear();
282 
283  // while the dialog was open, edit mode may have been stopped
284  if (!SC_MOD()->IsInputMode())
285  return;
286 
287  if (nFormat != SotClipboardFormatId::NONE)
288  {
289  if (SotClipboardFormatId::STRING == nFormat)
290  pTableView->Paste();
291  else
292  pTableView->PasteSpecial();
293 
294  if (pTopView)
295  pTopView->Paste();
296  }
297 
298  if (vcl::Window* pViewWindow = pTopView ? pTopView->GetWindow() : nullptr)
299  pViewWindow->GrabFocus();
300  }
301  break;
302 
303  case SID_PASTE_UNFORMATTED:
304  {
305  pTableView->Paste();
306 
307  if (pTopView)
308  {
309  pTopView->Paste();
310  if (vcl::Window* pViewWindow = pTopView->GetWindow())
311  pViewWindow->GrabFocus();
312  }
313  }
314  break;
315 
316  case SID_SELECTALL:
317  {
318  sal_Int32 nPar = pEngine->GetParagraphCount();
319  if (nPar)
320  {
321  sal_Int32 nLen = pEngine->GetTextLen(nPar-1);
322  pTableView->SetSelection(ESelection(0,0,nPar-1,nLen));
323  if (pTopView)
324  pTopView->SetSelection(ESelection(0,0,nPar-1,nLen));
325  rBindings.Invalidate( SID_ATTR_CHAR_FONT );
326  rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
327  rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
328  rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
329  rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
330  rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
331  rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
332  rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
333  rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
334  rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
335  rBindings.Invalidate( SID_SET_SUB_SCRIPT );
336  }
337  }
338  return;
339  case SID_UNICODE_NOTATION_TOGGLE:
340  {
341  EditView* pActiveView = pHdl->GetActiveView();
342  if( pActiveView )
343  {
344  OUString sInput = pEngine->GetText();
345  ESelection aSel( pActiveView->GetSelection() );
346  if( aSel.HasRange() )
347  sInput = pActiveView->GetSelected();
348 
349  if( aSel.nStartPos > aSel.nEndPos )
350  aSel.nEndPos = aSel.nStartPos;
351 
352  //calculate a valid end-position by reading logical characters
353  sal_Int32 nUtf16Pos=0;
354  while( (nUtf16Pos < sInput.getLength()) && (nUtf16Pos < aSel.nEndPos) )
355  {
356  sInput.iterateCodePoints(&nUtf16Pos);
357  if( nUtf16Pos > aSel.nEndPos )
358  aSel.nEndPos = nUtf16Pos;
359  }
360 
361  ToggleUnicodeCodepoint aToggle;
362  while( nUtf16Pos && aToggle.AllowMoreInput( sInput[nUtf16Pos-1]) )
363  --nUtf16Pos;
364  OUString sReplacement = aToggle.ReplacementString();
365  if( !sReplacement.isEmpty() )
366  {
367  aSel.nStartPos = aSel.nEndPos - aToggle.StringToReplace().getLength();
368  pTableView->SetSelection( aSel );
369  pTableView->InsertText(sReplacement, true);
370  if( pTopView )
371  {
372  pTopView->SetSelection( aSel );
373  pTopView->InsertText(sReplacement, true);
374  }
375  }
376  }
377  }
378  break;
379 
380  case SID_CHARMAP:
381  {
382  SvtScriptType nScript = pTableView->GetSelectedScriptType();
383  sal_uInt16 nFontWhich = ( nScript == SvtScriptType::ASIAN ) ? EE_CHAR_FONTINFO_CJK :
384  ( ( nScript == SvtScriptType::COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
386  const SvxFontItem& rItem = static_cast<const SvxFontItem&>(
387  pTableView->GetAttribs().Get(nFontWhich));
388 
389  OUString aString;
390  std::shared_ptr<SvxFontItem> aNewItem(std::make_shared<SvxFontItem>(EE_CHAR_FONTINFO));
391 
392  const SfxItemSet *pArgs = rReq.GetArgs();
393  const SfxPoolItem* pItem = nullptr;
394  if( pArgs )
395  pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
396 
397  if ( pItem )
398  {
399  aString = static_cast<const SfxStringItem*>(pItem)->GetValue();
400  const SfxPoolItem* pFtItem = nullptr;
401  pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
402  const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem );
403  if ( pFontItem )
404  {
405  const OUString& aFontName(pFontItem->GetValue());
406  vcl::Font aFont(aFontName, Size(1,1)); // Size just because CTOR
407  // tdf#125054 see comment in drtxob.cxx, same ID
408  aNewItem = std::make_shared<SvxFontItem>(
409  aFont.GetFamilyType(), aFont.GetFamilyName(),
410  aFont.GetStyleName(), aFont.GetPitch(),
411  aFont.GetCharSet(), ATTR_FONT);
412  }
413  else
414  {
415  aNewItem.reset(rItem.Clone());
416  }
417 
418  // tdf#125054 force Item to correct intended ID
419  aNewItem->SetWhich(EE_CHAR_FONTINFO);
420  }
421  else
422  {
424 
425  // while the dialog was open, edit mode may have been stopped
426  if (!SC_MOD()->IsInputMode())
427  return;
428  }
429 
430  if ( !aString.isEmpty() )
431  {
432  // if string contains WEAK characters, set all fonts
433  SvtScriptType nSetScript;
434  ScDocument& rDoc = rViewData.GetDocument();
435  if ( rDoc.HasStringWeakCharacters( aString ) )
436  nSetScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
437  else
438  nSetScript = rDoc.GetStringScriptType( aString );
439 
440  SfxItemSet aSet( pTableView->GetEmptyItemSet() );
441  SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() );
442  aSetItem.PutItemForScriptType( nSetScript, *aNewItem );
443  aSet.Put( aSetItem.GetItemSet(), false );
444 
445  // SetAttribs on the View selects a word, when nothing is selected
446  pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() );
447  pTableView->InsertText(aString);
448  if (pTopView)
449  pTopView->InsertText(aString);
450 
451  SfxStringItem aStringItem( SID_CHARMAP, aString );
452  SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem->GetFamilyName() );
453  rReq.AppendItem( aFontItem );
454  rReq.AppendItem( aStringItem );
455  rReq.Done();
456 
457  }
458 
459  if (vcl::Window* pViewWindow = pTopView ? pTopView->GetWindow() : nullptr)
460  pViewWindow->GrabFocus();
461  }
462  break;
463 
464  case FID_INSERT_NAME:
465  {
467 
469  short nRet = pDlg->Execute();
470  // pDlg is needed below
471 
472  // while the dialog was open, edit mode may have been stopped
473  if (!SC_MOD()->IsInputMode())
474  return;
475 
476  if ( nRet == BTN_PASTE_NAME )
477  {
478  std::vector<OUString> aNames = pDlg->GetSelectedNames();
479  if (!aNames.empty())
480  {
481  OUStringBuffer aBuffer;
482  for (const auto& rName : aNames)
483  {
484  aBuffer.append(rName).append(' ');
485  }
486  pTableView->InsertText(aBuffer.toString());
487  if (pTopView)
488  pTopView->InsertText(aBuffer.makeStringAndClear());
489  }
490  }
491  pDlg.disposeAndClear();
492 
493  if (vcl::Window* pViewWindow = pTopView ? pTopView->GetWindow() : nullptr)
494  pViewWindow->GrabFocus();
495  }
496  break;
497 
498  case SID_CHAR_DLG_EFFECT:
499  case SID_CHAR_DLG:
500  {
501  SfxItemSet aAttrs( pTableView->GetAttribs() );
502 
504 
506 
508  rViewData.GetDialogParent(), &aAttrs, pObjSh, false));
509  if (nSlot == SID_CHAR_DLG_EFFECT)
510  {
511  pDlg->SetCurPageId("fonteffects");
512  }
513  short nRet = pDlg->Execute();
514  // pDlg is needed below
515 
516  // while the dialog was open, edit mode may have been stopped
517  if (!SC_MOD()->IsInputMode())
518  return;
519 
520  if ( nRet == RET_OK )
521  {
522  const SfxItemSet* pOut = pDlg->GetOutputItemSet();
523  pTableView->SetAttribs( *pOut );
524  }
525  }
526  break;
527 
528  case SID_TOGGLE_REL:
529  {
530  if (pEngine->GetParagraphCount() == 1)
531  {
532  OUString aText = pEngine->GetText();
533  ESelection aSel = pEditView->GetSelection(); // current View
534 
535  ScDocument& rDoc = rViewData.GetDocument();
536  ScRefFinder aFinder(aText, rViewData.GetCurPos(), rDoc, rDoc.GetAddressConvention());
537  aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos );
538  if (aFinder.GetFound())
539  {
540  const OUString& aNew = aFinder.GetText();
541  ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() );
542  pEngine->SetText( aNew );
543  pTableView->SetSelection( aNewSel );
544  if ( pTopView )
545  {
546  pTopView->GetEditEngine()->SetText( aNew );
547  pTopView->SetSelection( aNewSel );
548  }
549 
550  // reference is being selected -> do not overwrite when typing
551  bSetSelIsRef = true;
552  }
553  }
554  }
555  break;
556 
557  case SID_HYPERLINK_SETLINK:
558  if( pReqArgs )
559  {
560  const SfxPoolItem* pItem;
561  if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, true, &pItem ) == SfxItemState::SET )
562  {
563  const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem);
564  const OUString& rName = pHyper->GetName();
565  const OUString& rURL = pHyper->GetURL();
566  const OUString& rTarget = pHyper->GetTargetFrame();
568 
569  bool bDone = false;
570  if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
571  {
572  const SvxURLField* pURLField = GetURLField();
573  if ( pURLField )
574  {
575  // select old field
576 
577  ESelection aSel = pTableView->GetSelection();
578  aSel.Adjust();
579  aSel.nEndPara = aSel.nStartPara;
580  aSel.nEndPos = aSel.nStartPos + 1;
581  pTableView->SetSelection( aSel );
582 
583  // insert new field
584 
585  SvxURLField aURLField( rURL, rName, SvxURLFormat::Repr );
586  aURLField.SetTargetFrame( rTarget );
587  SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
588  pTableView->InsertField( aURLItem );
589  pTableView->SetSelection( aSel ); // select inserted field
590 
591  // now also fields in the Top-View
592 
593  if ( pTopView )
594  {
595  aSel = pTopView->GetSelection();
596  aSel.nEndPara = aSel.nStartPara;
597  aSel.nEndPos = aSel.nStartPos + 1;
598  pTopView->SetSelection( aSel );
599  pTopView->InsertField( aURLItem );
600  pTopView->SetSelection( aSel ); // select inserted field
601  }
602 
603  bDone = true;
604  }
605  }
606 
607  if (!bDone)
608  {
610  InsertURL( rName, rURL, rTarget, static_cast<sal_uInt16>(eMode) );
611 
612  // when "Button", the InsertURL in ViewShell turns the EditShell off
613  // thus the immediate return statement
614  return;
615  }
616  }
617  }
618  break;
619 
620  case SID_OPEN_HYPERLINK:
621  {
622  const SvxURLField* pURLField = GetURLField();
623  if ( pURLField )
624  ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame(), true );
625  return;
626  }
627  case SID_EDIT_HYPERLINK:
628  {
629  // Ensure the field is selected first
632  SID_HYPERLINK_DIALOG);
633  }
634  break;
635  case SID_COPY_HYPERLINK_LOCATION:
636  {
637  const SvxFieldData* pField = pEditView->GetFieldAtCursor();
638  if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
639  {
640  uno::Reference<datatransfer::clipboard::XClipboard> xClipboard = GetSystemClipboard();
641 
642  vcl::unohelper::TextDataObject::CopyStringTo(pURLField->GetURL(), xClipboard, SfxViewShell::Current());
643  }
644  }
645  break;
646  case SID_REMOVE_HYPERLINK:
647  {
649  }
650  break;
651 
652  case FN_INSERT_SOFT_HYPHEN:
653  lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
654  break;
655  case FN_INSERT_HARDHYPHEN:
656  lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
657  break;
658  case FN_INSERT_HARD_SPACE:
659  lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
660  break;
661  case FN_INSERT_NNBSP:
662  lclInsertCharacter( pTableView, pTopView, CHAR_NNBSP );
663  break;
664  case SID_INSERT_RLM:
665  lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
666  break;
667  case SID_INSERT_LRM:
668  lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
669  break;
670  case SID_INSERT_ZWSP:
671  lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
672  break;
673  case SID_INSERT_ZWNBSP:
674  lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
675  break;
676  case SID_INSERT_FIELD_SHEET:
677  {
678  SvxTableField aField(rViewData.GetTabNo());
679  SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
680  pTableView->InsertField(aItem);
681  }
682  break;
683  case SID_INSERT_FIELD_TITLE:
684  {
685  SvxFileField aField;
686  SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
687  pTableView->InsertField(aItem);
688  }
689  break;
690  case SID_INSERT_FIELD_DATE_VAR:
691  {
692  SvxDateField aField;
693  SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
694  pTableView->InsertField(aItem);
695  }
696  break;
697  }
698 
699  pHdl->DataChanged(false, bSetModified);
700  if (bSetSelIsRef)
701  pHdl->SetSelIsRef(true);
702 }
703 
704 static void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots
705 {
706  SfxWhichIter aIter( rSet );
707  sal_uInt16 nWhich = aIter.FirstWhich();
708  while (nWhich)
709  {
710  rSet.DisableItem( nWhich );
711  nWhich = aIter.NextWhich();
712  }
713 }
714 
716 {
717  // When deactivating the view, edit mode is stopped, but the EditShell is left active
718  // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
719  // into the EditEngine, so it can have an invalid selection and must not be used.
721  {
722  lcl_DisableAll( rSet );
723  return;
724  }
725 
726  ScInputHandler* pHdl = GetMyInputHdl();
727  EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
728 
729  SfxWhichIter aIter( rSet );
730  sal_uInt16 nWhich = aIter.FirstWhich();
731  while (nWhich)
732  {
733  switch (nWhich)
734  {
735  case SID_ATTR_INSERT: // Status row
736  {
737  if ( pActiveView )
738  rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
739  else
740  {
741  // Here the code used to pass the value 42 and it used
742  // to "work" without warnings because the SfxBoolItem
743  // was based on 'sal_Bool', which is actually 'unsigned
744  // char'. But now it uses actual 'bool', and passing 42
745  // for a 'bool' parameter causes a warning at least with
746  // MSVC. So use 'true'. I really really hope there is
747  // not code somewhere that retrieves this "boolean" item
748  // and checks it value for the magic value 42...
749  rSet.Put( SfxBoolItem( nWhich, true) );
750  }
751  }
752  break;
753 
754  case SID_HYPERLINK_GETLINK:
755  {
756  SvxHyperlinkItem aHLinkItem;
757  const SvxURLField* pURLField = GetURLField();
758  if ( pURLField )
759  {
760  aHLinkItem.SetName( pURLField->GetRepresentation() );
761  aHLinkItem.SetURL( pURLField->GetURL() );
762  aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
763  }
764  else if ( pActiveView )
765  {
766  // use selected text as name for urls
767  OUString sReturn = pActiveView->GetSelected();
768  sReturn = sReturn.copy(0, std::min(sReturn.getLength(), static_cast<sal_Int32>(255)));
769  aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
770  }
771  rSet.Put(aHLinkItem);
772  }
773  break;
774 
775  case SID_OPEN_HYPERLINK:
776  case SID_EDIT_HYPERLINK:
777  case SID_COPY_HYPERLINK_LOCATION:
778  case SID_REMOVE_HYPERLINK:
779  {
781  rSet.DisableItem (nWhich);
782  }
783  break;
784 
785  case SID_TRANSLITERATE_HALFWIDTH:
786  case SID_TRANSLITERATE_FULLWIDTH:
787  case SID_TRANSLITERATE_HIRAGANA:
788  case SID_TRANSLITERATE_KATAKANA:
789  case SID_INSERT_RLM:
790  case SID_INSERT_LRM:
792  break;
793 
794  case SID_THES:
795  {
796  OUString aStatusVal;
797  LanguageType nLang = LANGUAGE_NONE;
798  bool bIsLookUpWord = pActiveView &&
799  GetStatusValueForThesaurusFromContext(aStatusVal, nLang, *pActiveView);
800  rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
801 
802  // disable thesaurus context menu entry if there is nothing to look up
803  bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
804  if (!bIsLookUpWord || !bCanDoThesaurus)
805  rSet.DisableItem( SID_THES );
806  }
807  break;
808  case SID_INSERT_FIELD_SHEET:
809  case SID_INSERT_FIELD_TITLE:
810  case SID_INSERT_FIELD_DATE_VAR:
811  break;
812  case SID_COPY:
813  case SID_CUT:
814  if (GetObjectShell() && GetObjectShell()->isContentExtractionLocked())
815  {
816  rSet.DisableItem(SID_COPY);
817  rSet.DisableItem(SID_CUT);
818  }
819  break;
820 
821  }
822  nWhich = aIter.NextWhich();
823  }
824 }
825 
827 {
828  ScInputHandler* pHdl = GetMyInputHdl();
829  EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
830  if (!pActiveView)
831  return nullptr;
832 
833  const SvxFieldData* pField = pActiveView->GetFieldAtCursor();
834  if (auto pURLField = dynamic_cast<const SvxURLField*>(pField))
835  return pURLField;
836 
837  return nullptr;
838 }
839 
840 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )
841 {
842  bPastePossible = ( pDataHelper->HasFormat( SotClipboardFormatId::STRING )
843  || pDataHelper->HasFormat( SotClipboardFormatId::RTF )
844  || pDataHelper->HasFormat( SotClipboardFormatId::RICHTEXT ));
845 
846  SfxBindings& rBindings = rViewData.GetBindings();
847  rBindings.Invalidate( SID_PASTE );
848  rBindings.Invalidate( SID_PASTE_SPECIAL );
849  rBindings.Invalidate( SID_PASTE_UNFORMATTED );
850  rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
851 }
852 
854 {
855  // Do not offer SotClipboardFormatId::STRING_TSVC for in-cell paste.
856 
857  if ( !mxClipEvtLstnr.is() )
858  {
859  // create listener
860  mxClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
862  mxClipEvtLstnr->AddListener( pWin );
863 
864  // get initial state
866  bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING )
867  || aDataHelper.HasFormat( SotClipboardFormatId::RTF )
868  || aDataHelper.HasFormat( SotClipboardFormatId::RICHTEXT ) );
869  }
870 
871  SfxWhichIter aIter( rSet );
872  sal_uInt16 nWhich = aIter.FirstWhich();
873  while (nWhich)
874  {
875  switch (nWhich)
876  {
877  case SID_PASTE:
878  case SID_PASTE_SPECIAL:
879  case SID_PASTE_UNFORMATTED:
880  if( !bPastePossible )
881  rSet.DisableItem( nWhich );
882  break;
883  case SID_CLIPBOARD_FORMAT_ITEMS:
884  if( bPastePossible )
885  {
886  SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
887  TransferableDataHelper aDataHelper(
889 
890  if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) )
891  aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
892  if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
893  aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
894 
895  rSet.Put( aFormats );
896  }
897  else
898  rSet.DisableItem( nWhich );
899  break;
900  }
901  nWhich = aIter.NextWhich();
902  }
903 }
904 
905 static void lcl_InvalidateUnder( SfxBindings& rBindings )
906 {
907  rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
908  rBindings.Invalidate( SID_ULINE_VAL_NONE );
909  rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
910  rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
911  rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
912 }
913 
915 {
917  SfxBindings& rBindings = rViewData.GetBindings();
918  const SfxItemSet* pArgs = rReq.GetArgs();
919  sal_uInt16 nSlot = rReq.GetSlot();
920 
921  switch ( nSlot )
922  {
923  case SID_ATTR_CHAR_FONTHEIGHT:
924  case SID_ATTR_CHAR_FONT:
925  {
926  if (pArgs)
927  {
928  // #i78017 establish the same behaviour as in Writer
929  SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
930  if (nSlot == SID_ATTR_CHAR_FONT)
931  {
932  nScript = pEditView->GetSelectedScriptType();
933  if (nScript == SvtScriptType::NONE) nScript = ScGlobal::GetDefaultScriptType();
934  }
935 
936  SfxItemPool& rPool = GetPool();
937  SvxScriptSetItem aSetItem( nSlot, rPool );
938  sal_uInt16 nWhich = rPool.GetWhich( nSlot );
939  aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
940 
941  aSet.Put( aSetItem.GetItemSet(), false );
942  }
943  }
944  break;
945 
946  case SID_ATTR_CHAR_COLOR:
947  {
948  if (pArgs)
949  {
950  const SfxPoolItem* pColorStringItem = nullptr;
951 
952  if ( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_ATTR_COLOR_STR, false, &pColorStringItem ) )
953  {
954  Color aColor;
955  OUString sColor = static_cast<const SfxStringItem*>( pColorStringItem )->GetValue();
956  if ( sColor == "transparent" )
957  aColor = COL_TRANSPARENT;
958  else
959  aColor = Color( ColorTransparency, sColor.toInt32( 16 ) );
960 
961  aSet.Put( SvxColorItem( aColor, EE_CHAR_COLOR ) );
962  }
963  else
964  {
965  aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
966  }
967  rBindings.Invalidate( nSlot );
968  }
969  }
970  break;
971 
972  // Toggles
973 
974  case SID_ATTR_CHAR_WEIGHT:
975  {
976  // #i78017 establish the same behaviour as in Writer
977  SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
978 
979  SfxItemPool& rPool = GetPool();
980 
981  bool bOld = false;
982  SvxScriptSetItem aOldSetItem( nSlot, rPool );
983  aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
984  const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
985  if ( pCore && static_cast<const SvxWeightItem*>(pCore)->GetWeight() > WEIGHT_NORMAL )
986  bOld = true;
987 
988  SvxScriptSetItem aSetItem( nSlot, rPool );
989  aSetItem.PutItemForScriptType( nScript,
991  aSet.Put( aSetItem.GetItemSet(), false );
992 
993  rBindings.Invalidate( nSlot );
994  }
995  break;
996 
997  case SID_ATTR_CHAR_POSTURE:
998  {
999  // #i78017 establish the same behaviour as in Writer
1000  SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
1001 
1002  SfxItemPool& rPool = GetPool();
1003 
1004  bool bOld = false;
1005  SvxScriptSetItem aOldSetItem( nSlot, rPool );
1006  aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
1007  const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
1008  if ( pCore && static_cast<const SvxPostureItem*>(pCore)->GetValue() != ITALIC_NONE )
1009  bOld = true;
1010 
1011  SvxScriptSetItem aSetItem( nSlot, rPool );
1012  aSetItem.PutItemForScriptType( nScript,
1014  aSet.Put( aSetItem.GetItemSet(), false );
1015 
1016  rBindings.Invalidate( nSlot );
1017  }
1018  break;
1019 
1020  case SID_ULINE_VAL_NONE:
1022  lcl_InvalidateUnder( rBindings );
1023  break;
1024 
1025  case SID_ATTR_CHAR_UNDERLINE:
1026  case SID_ULINE_VAL_SINGLE:
1027  case SID_ULINE_VAL_DOUBLE:
1028  case SID_ULINE_VAL_DOTTED:
1029  {
1030  FontLineStyle eOld = pEditView->GetAttribs().Get(EE_CHAR_UNDERLINE).GetLineStyle();
1031  FontLineStyle eNew = eOld;
1032  switch (nSlot)
1033  {
1034  case SID_ATTR_CHAR_UNDERLINE:
1035  if ( pArgs )
1036  {
1037  const SvxTextLineItem& rTextLineItem = static_cast< const SvxTextLineItem& >( pArgs->Get( pArgs->GetPool()->GetWhich(nSlot) ) );
1038  eNew = rTextLineItem.GetLineStyle();
1039  }
1040  else
1041  {
1042  eNew = ( eOld != LINESTYLE_NONE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
1043  }
1044  break;
1045  case SID_ULINE_VAL_SINGLE:
1046  eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
1047  break;
1048  case SID_ULINE_VAL_DOUBLE:
1049  eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
1050  break;
1051  case SID_ULINE_VAL_DOTTED:
1052  eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
1053  break;
1054  }
1055  aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
1056  lcl_InvalidateUnder( rBindings );
1057  }
1058  break;
1059 
1060  case SID_ATTR_CHAR_OVERLINE:
1061  {
1062  FontLineStyle eOld = pEditView->GetAttribs().Get(EE_CHAR_OVERLINE).GetLineStyle();
1064  aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) );
1065  rBindings.Invalidate( nSlot );
1066  }
1067  break;
1068 
1069  case SID_ATTR_CHAR_STRIKEOUT:
1070  {
1071  bool bOld = pEditView->GetAttribs().Get(EE_CHAR_STRIKEOUT).GetValue() != STRIKEOUT_NONE;
1073  rBindings.Invalidate( nSlot );
1074  }
1075  break;
1076 
1077  case SID_ATTR_CHAR_SHADOWED:
1078  {
1079  bool bOld = pEditView->GetAttribs().Get(EE_CHAR_SHADOW).GetValue();
1080  aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) );
1081  rBindings.Invalidate( nSlot );
1082  }
1083  break;
1084 
1085  case SID_ATTR_CHAR_CONTOUR:
1086  {
1087  bool bOld = pEditView->GetAttribs().Get(EE_CHAR_OUTLINE).GetValue();
1088  aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) );
1089  rBindings.Invalidate( nSlot );
1090  }
1091  break;
1092 
1093  case SID_SET_SUPER_SCRIPT:
1094  {
1095  SvxEscapement eOld = static_cast<SvxEscapement>(pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT).GetEnumValue());
1096  SvxEscapement eNew = (eOld == SvxEscapement::Superscript) ?
1097  SvxEscapement::Off : SvxEscapement::Superscript;
1098  aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1099  rBindings.Invalidate( nSlot );
1100  }
1101  break;
1102  case SID_SET_SUB_SCRIPT:
1103  {
1104  SvxEscapement eOld = static_cast<SvxEscapement>(pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT).GetEnumValue());
1105  SvxEscapement eNew = (eOld == SvxEscapement::Subscript) ?
1106  SvxEscapement::Off : SvxEscapement::Subscript;
1107  aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1108  rBindings.Invalidate( nSlot );
1109  }
1110  break;
1111  case SID_ATTR_CHAR_KERNING:
1112  {
1113  if(pArgs)
1114  {
1115  aSet.Put ( pArgs->Get(pArgs->GetPool()->GetWhich(nSlot)));
1116  rBindings.Invalidate( nSlot );
1117  }
1118  }
1119  break;
1120 
1121  case SID_GROW_FONT_SIZE:
1122  case SID_SHRINK_FONT_SIZE:
1123  {
1124  const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
1125  ( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
1126  const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
1127  pEditView->ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
1128  rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
1129  }
1130  break;
1131  }
1132 
1133  // apply
1134 
1135  EditEngine* pEngine = pEditView->GetEditEngine();
1136  bool bOld = pEngine->GetUpdateMode();
1137  pEngine->SetUpdateMode(false);
1138 
1139  pEditView->SetAttribs( aSet );
1140 
1141  pEngine->SetUpdateMode(bOld);
1142  pEditView->Invalidate();
1143 
1144  ScInputHandler* pHdl = GetMyInputHdl();
1145  pHdl->SetModified();
1146 
1147  rReq.Done();
1148 }
1149 
1151 {
1153  {
1154  lcl_DisableAll( rSet );
1155  return;
1156  }
1157 
1158  SfxItemSet aAttribs = pEditView->GetAttribs();
1159  rSet.Put( aAttribs );
1160 
1161  // choose font info according to selection script type
1162 
1164  if (nScript == SvtScriptType::NONE) nScript = ScGlobal::GetDefaultScriptType();
1165 
1166  // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1167  SvtScriptType nInputScript = nScript;
1168  if ( !pEditView->GetSelection().HasRange() )
1169  {
1171  if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1172  nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1173  }
1174 
1175  // #i55929# according to spec, nInputScript is used for font and font height only
1176  if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SfxItemState::UNKNOWN )
1177  ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript );
1178  if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SfxItemState::UNKNOWN )
1179  ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript );
1180  if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SfxItemState::UNKNOWN )
1181  ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript );
1182  if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SfxItemState::UNKNOWN )
1183  ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript );
1184 
1185  // underline
1186  SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE );
1187  if ( eState == SfxItemState::DONTCARE )
1188  {
1189  rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1190  rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1191  rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1192  rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1193  }
1194  else
1195  {
1196  FontLineStyle eUnderline = aAttribs.Get(EE_CHAR_UNDERLINE).GetLineStyle();
1197  rSet.Put(SfxBoolItem(SID_ULINE_VAL_SINGLE, eUnderline == LINESTYLE_SINGLE));
1198  rSet.Put(SfxBoolItem(SID_ULINE_VAL_DOUBLE, eUnderline == LINESTYLE_DOUBLE));
1199  rSet.Put(SfxBoolItem(SID_ULINE_VAL_DOTTED, eUnderline == LINESTYLE_DOTTED));
1200  rSet.Put(SfxBoolItem(SID_ULINE_VAL_NONE, eUnderline == LINESTYLE_NONE));
1201  }
1202 
1204  ScInputHandler* pHdl = GetMyInputHdl();
1205  if ( pHdl && pHdl->IsFormulaMode() )
1206  rSet.ClearItem( EE_CHAR_WEIGHT ); // Highlighted brace not here
1207 
1208  SvxEscapement eEsc = static_cast<SvxEscapement>(aAttribs.Get( EE_CHAR_ESCAPEMENT ).GetEnumValue());
1209  rSet.Put(SfxBoolItem(SID_SET_SUPER_SCRIPT, eEsc == SvxEscapement::Superscript));
1210  rSet.Put(SfxBoolItem(SID_SET_SUB_SCRIPT, eEsc == SvxEscapement::Subscript));
1211  rViewData.GetBindings().Invalidate( SID_SET_SUPER_SCRIPT );
1212  rViewData.GetBindings().Invalidate( SID_SET_SUB_SCRIPT );
1213 
1214  eState = aAttribs.GetItemState( EE_CHAR_KERNING );
1215  rViewData.GetBindings().Invalidate( SID_ATTR_CHAR_KERNING );
1216  if ( eState == SfxItemState::DONTCARE )
1217  {
1219  }
1220 }
1221 
1222 OUString ScEditShell::GetSelectionText( bool bWholeWord )
1223 {
1224  OUString aStrSelection;
1225 
1227  {
1228  if ( bWholeWord )
1229  {
1230  EditEngine* pEngine = pEditView->GetEditEngine();
1231  ESelection aSel = pEditView->GetSelection();
1232  OUString aStrCurrentDelimiters = pEngine->GetWordDelimiters();
1233 
1234  pEngine->SetWordDelimiters(" .,;\"'");
1235  aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos );
1236  pEngine->SetWordDelimiters( aStrCurrentDelimiters );
1237  }
1238  else
1239  {
1240  aStrSelection = pEditView->GetSelected();
1241  }
1242  }
1243 
1244  return aStrSelection;
1245 }
1246 
1248 {
1249  // Undo must be handled here because it's called for both EditViews
1250 
1251  ScInputHandler* pHdl = GetMyInputHdl();
1252  OSL_ENSURE(pHdl,"no ScInputHandler");
1253  EditView* pTopView = pHdl->GetTopView();
1254  EditView* pTableView = pHdl->GetTableView();
1255  OSL_ENSURE(pTableView,"no EditView");
1256 
1257  pHdl->DataChanging();
1258 
1259  const SfxItemSet* pReqArgs = rReq.GetArgs();
1260  sal_uInt16 nSlot = rReq.GetSlot();
1261  switch ( nSlot )
1262  {
1263  case SID_UNDO:
1264  case SID_REDO:
1265  {
1266  bool bIsUndo = ( nSlot == SID_UNDO );
1267 
1268  sal_uInt16 nCount = 1;
1269  const SfxPoolItem* pItem;
1270  if ( pReqArgs && pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1271  nCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1272 
1273  for (sal_uInt16 i=0; i<nCount; i++)
1274  {
1275  if ( bIsUndo )
1276  {
1277  pTableView->Undo();
1278  if (pTopView)
1279  pTopView->Undo();
1280  }
1281  else
1282  {
1283  pTableView->Redo();
1284  if (pTopView)
1285  pTopView->Redo();
1286  }
1287  }
1288  }
1289  break;
1290  }
1292 
1293  pHdl->DataChanged();
1294 }
1295 
1297 {
1298  // Undo state is taken from normal ViewFrame state function
1299 
1301  if ( pViewFrm && GetUndoManager() )
1302  {
1303  SfxWhichIter aIter(rSet);
1304  sal_uInt16 nWhich = aIter.FirstWhich();
1305  while( nWhich )
1306  {
1307  pViewFrm->GetSlotState( nWhich, nullptr, &rSet );
1308  nWhich = aIter.NextWhich();
1309  }
1310  }
1311 
1312  // disable if no action in input line EditView
1313 
1314  ScInputHandler* pHdl = GetMyInputHdl();
1315  OSL_ENSURE(pHdl,"no ScInputHandler");
1316  EditView* pTopView = pHdl->GetTopView();
1317  if (pTopView)
1318  {
1319  SfxUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager();
1320  if ( rTopMgr.GetUndoActionCount() == 0 )
1321  rSet.DisableItem( SID_UNDO );
1322  if ( rTopMgr.GetRedoActionCount() == 0 )
1323  rSet.DisableItem( SID_REDO );
1324  }
1325 }
1326 
1328 {
1330  if ( nType == TransliterationFlags::NONE )
1331  return;
1332 
1333  ScInputHandler* pHdl = GetMyInputHdl();
1334  assert(pHdl && "no ScInputHandler");
1335 
1336  EditView* pTopView = pHdl->GetTopView();
1337  EditView* pTableView = pHdl->GetTableView();
1338  assert(pTableView && "no EditView");
1339 
1340  pHdl->DataChanging();
1341 
1342  pTableView->TransliterateText( nType );
1343  if (pTopView)
1344  pTopView->TransliterateText( nType );
1345 
1346  pHdl->DataChanged();
1347 }
1348 
1349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OString stripEnd(const OString &rIn, char c)
void SetURL(const OUString &rURL)
SfxViewFrame * GetViewFrame() const
ScInputHandler * GetMyInputHdl()
Definition: editsh.cxx:115
void Adjust()
void SetControlWord(EVControlBits nWord)
#define LANGUAGE_NONE
void PasteSpecial()
OUString GetText(LineEnd eEnd=LINEEND_LF) const
static void CopyStringTo(const OUString &rContent, const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rxClipboard, const vcl::ILibreOfficeKitNotifier *pNotifier=nullptr)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
void SetTargetFrame(const OUString &rFrm)
sal_Int32 nStartPara
static void HideDisabledSlot(SfxItemSet &rSet, SfxBindings &rBindings, sal_uInt16 nSlotId)
Definition: viewutil.cxx:285
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
OUString GetWord(sal_Int32 nPara, sal_Int32 nIndex)
ScEditShell(EditView *pView, ScViewData &rData)
Definition: editsh.cxx:91
const SvxURLField * GetURLField()
Definition: editsh.cxx:826
constexpr TypedWhichId< SvxKerningItem > EE_CHAR_KERNING(EE_CHAR_START+12)
static void lclInsertCharacter(EditView *pTableView, EditView *pTopView, sal_Unicode cChar)
Definition: editsh.cxx:149
void PutItemForScriptType(SvtScriptType nScriptType, const SfxPoolItem &rItem)
void Execute(SfxRequest &rReq)
Definition: editsh.cxx:158
#define SFX_IMPL_INTERFACE(Class, SuperClass)
#define EMPTY_OUSTRING
Definition: global.hxx:216
void Cut()
const sal_Unicode CHAR_ZWSP
Definition: global.hxx:67
static void PutItemScript(SfxItemSet &rShellSet, const SfxItemSet &rCoreSet, sal_uInt16 nWhichId, SvtScriptType nScript)
Definition: viewutil.cxx:49
void SetModified()
Definition: inputhdl.hxx:245
const SfxItemSet & GetEmptyItemSet() const
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
void SetUpdateMode(bool bUpdate, bool bRestoring=false)
bool IsFormulaMode() const
Definition: inputhdl.hxx:262
const sal_Unicode CHAR_NNBSP
Definition: global.hxx:72
const sal_Unicode CHAR_ZWNBSP
Definition: global.hxx:71
const OUString & GetTargetFrame() const
bool DataChanging(sal_Unicode cTyped=0, bool bFromCommand=false)
Definition: inputhdl.cxx:2574
SfxDispatcher * GetDispatcher()
static SvxAbstractDialogFactory * Create()
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
void disposeAndClear()
virtual VclPtr< AbstractScNamePasteDlg > CreateScNamePasteDlg(weld::Window *pParent, ScDocShell *pShell)=0
FilterGroup & rTarget
OUString ReplacementString()
void Redo()
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
static void OpenURL(const OUString &rURL, const OUString &rTarget, bool bIgnoreSettings=false)
Open the specified URL.
Definition: global.cxx:759
void InvalidateItem(sal_uInt16 nWhich)
sal_uInt16 FirstWhich()
const SfxItemSet & GetEmptyItemSet() const
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:564
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
css::uno::Reference< css::datatransfer::clipboard::XClipboard > VCL_DLLPUBLIC GetSystemClipboard()
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
void Done(bool bRemove=false)
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
void ChangeFontSize(bool bGrow, const FontList *pList)
void ToggleRel(sal_Int32 nStartPos, sal_Int32 nEndPos)
Definition: reffind.cxx:234
static bool HasThesaurusLanguage(LanguageType nLang)
Definition: scmod.cxx:2201
static SfxObjectShell * Current()
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
virtual SfxUndoManager * GetUndoManager()
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
void SetWordDelimiters(const OUString &rDelimiters)
virtual short Execute()=0
bool HasStringWeakCharacters(const OUString &rString)
Definition: documen6.cxx:51
void GetUndoState(SfxItemSet &rSet)
Definition: editsh.cxx:1296
static void lcl_RemoveAttribs(EditView &rEditView)
Definition: editsh.cxx:128
bool HasFormat(SotClipboardFormatId nFormat) const
const OUString & GetTargetFrame() const
void SetEditView(EditView *pView)
Definition: editsh.cxx:120
virtual SvxFontItem * Clone(SfxItemPool *pPool=nullptr) const override
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:488
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
const OUString & GetWordDelimiters() const
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
sal_uInt16 NextWhich()
EditView * GetTableView()
Definition: inputhdl.hxx:237
SvtScriptType GetSelectedScriptType() const
EditView * GetActiveView()
Definition: inputhdl.cxx:2220
WEIGHT_BOLD
sal_uInt16 sal_Unicode
OUString GetSelectionText(bool bWholeWord)
Definition: editsh.cxx:1222
bool bPastePossible
Definition: editsh.hxx:43
void SetTargetFrame(const OUString &rTarget)
void Copy()
LINESTYLE_NONE
void SetText(const OUString &rStr)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
static void lcl_DisableAll(SfxItemSet &rSet)
Definition: editsh.cxx:704
void TransliterateText(TransliterationFlags nTransliterationMode)
virtual VclPtr< SfxAbstractTabDialog > CreateScCharDlg(weld::Window *pParent, const SfxItemSet *pAttr, const SfxObjectShell *pDocShell, bool bDrawText)=0
int nCount
static SfxViewShell * Current()
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
oslFileHandle & pOut
Mode eMode
void SetUndoManager(SfxUndoManager *pNewUndoMgr)
SotClipboardFormatId
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
sal_Int32 nEndPos
virtual size_t GetRedoActionCount(bool const i_currentLevel=CurrentLevel) const
STRIKEOUT_SINGLE
constexpr TypedWhichId< SvxContourItem > EE_CHAR_OUTLINE(EE_CHAR_START+8)
TransliterationFlags
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
SfxItemPool & GetPool() const
const sal_Unicode CHAR_SHY
Definition: global.hxx:66
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
void InsertField(const SvxFieldItem &rFld)
constexpr TypedWhichId< SvxShadowedItem > EE_CHAR_SHADOW(EE_CHAR_START+9)
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
void SelectFieldAtCursor()
sal_Int32 nEndPara
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SvtScriptType
const OUString & GetURL() const
void ExecuteTrans(const SfxRequest &rReq)
Definition: editsh.cxx:1327
const SvxFieldData * GetFieldAtCursor() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
OUString StringToReplace()
const sal_Unicode CHAR_RLM
Definition: global.hxx:69
sal_uInt32 GetTextLen() const
bool bIsInsertMode
Definition: editsh.hxx:44
SfxBindings & GetBindings()
Definition: viewdata.cxx:3034
#define LANGUAGE_SYSTEM
void SetAttribs(const SfxItemSet &rSet)
SfxItemSet GetAttribs()
EditEngine * GetEditEngine() const
#define SC_MOD()
Definition: scmod.hxx:250
void GetClipState(SfxItemSet &rSet)
Definition: editsh.cxx:853
void RepeatDefaults()
Re-apply existing defaults if set, same as in SetText, but without EnableUndo/SetUpdateMode.
Definition: editutil.cxx:627
SfxUndoManager & GetUndoManager()
const OUString & GetValue() const
const T * GetArg(sal_uInt16 nSlotId) const
const sal_Unicode CHAR_NBSP
Definition: global.hxx:65
void SetPool(SfxItemPool *pNewPool)
SvxLinkInsertMode
WEIGHT_NORMAL
LINESTYLE_SINGLE
void ExecuteAttr(SfxRequest &rReq)
Definition: editsh.cxx:914
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
virtual void SetCurPageId(const OString &rName)=0
vcl::Window * GetWindow() const
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper)=0
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3062
#define LANGUAGE_DONTKNOW
HLINK_FIELD
void RemoveAttribs(bool bRemoveParaAttribs=false, sal_uInt16 nWhich=0)
void Undo()
const OUString & GetRepresentation() const
void InsertText(const OUString &rNew, bool bSelect=false)
ColorTransparency
void SetName(const OUString &rName)
static void lcl_InvalidateUnder(SfxBindings &rBindings)
Definition: editsh.cxx:905
ITALIC_NONE
void SetName(const OUString &rName)
weld::Window * GetDialogParent()
Definition: viewdata.cxx:3056
const sal_Unicode CHAR_NBHY
Definition: global.hxx:70
virtual size_t GetUndoActionCount(bool const i_currentLevel=CurrentLevel) const
SfxItemPool * GetPool() const
static void RemoveURLField(EditView &pEditView)
sal_Int32 GetParagraphCount() const
size_t LeaveListAction()
void SetInsertMode(bool bInsert)
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName)=0
const OUString & GetURL() const
ScAddress GetCurPos() const
Definition: viewdata.cxx:4007
FontLineStyle GetLineStyle() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const sal_Unicode CHAR_LRM
Definition: global.hxx:68
sal_uInt16 GetSlot() const
static const OUString & GetContextName(const Context eContext)
constexpr TypedWhichId< SvxCrossedOutItem > EE_CHAR_STRIKEOUT(EE_CHAR_START+6)
static SC_DLLPUBLIC SvtScriptType GetDefaultScriptType()
Definition: global.cxx:849
HLINK_DEFAULT
std::unique_ptr< char[]> aBuffer
ScViewData & rViewData
Definition: editsh.hxx:41
bool HasRange() const
void GetAttrState(SfxItemSet &rSet)
Definition: editsh.cxx:1150
bool EDITENG_DLLPUBLIC GetStatusValueForThesaurusFromContext(OUString &rStatusVal, LanguageType &rLang, const EditView &rEditView)
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1020
SfxItemState
void DisableItem(sal_uInt16 nWhich)
bool AllowMoreInput(sal_Unicode uChar)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
static TransliterationFlags GetTransliterationType(sal_uInt16 nSlotID)
Definition: viewutil.cxx:98
ITALIC_NORMAL
IMPL_LINK(ScEditShell, ClipboardChanged, TransferableDataHelper *, pDataHelper, void)
Definition: editsh.cxx:840
#define GetWhich(nSlot)
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
LINESTYLE_DOTTED
bool GetUpdateMode() const
OUString aName
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
RET_OK
virtual ~ScEditShell() override
Definition: editsh.cxx:103
constexpr TypedWhichId< SvxOverlineItem > EE_CHAR_OVERLINE(EE_CHAR_START+29)
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
void DataChanged(bool bFromTopNotify=false, bool bSetModified=true)
Definition: inputhdl.cxx:2586
EVControlBits
static void ExecuteCharMap(const SvxFontItem &rOldFont, SfxViewFrame &rFrame)
Definition: viewutil.cxx:320
void Invalidate()
void SetSelection(const ESelection &rNewSel)
void AddClipbrdFormat(SotClipboardFormatId nId)
SvxEscapement
constexpr TypedWhichId< SvxUnderlineItem > EE_CHAR_UNDERLINE(EE_CHAR_START+5)
const OUString & GetName() const
void DeleteSelected()
SvxLinkInsertMode GetInsertMode() const
void InvalidateAll(bool bWithMsg)
rtl::Reference< TransferableClipboardListener > mxClipEvtLstnr
Definition: editsh.hxx:42
void AppendItem(const SfxPoolItem &)
SfxObjectShell * GetSfxDocShell() const
Definition: viewdata.hxx:358
ESelection GetSelection() const
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
LINESTYLE_DOUBLE
const FontList * GetFontList() const
OUString GetSelected() const
STRIKEOUT_NONE
LanguageType GetInputLanguage() const
FontLineStyle
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
void SetSelIsRef(bool bSet)
Definition: inputhdl.hxx:248
void Paste()
static bool IsCursorAtURLField(const EditView &pEditView)
void ExecuteUndo(const SfxRequest &rReq)
Definition: editsh.cxx:1247
void SetContextName(const OUString &rsContextName)
EditView * GetTopView()
Definition: inputhdl.hxx:238
void GetState(SfxItemSet &rSet)
Definition: editsh.cxx:715
const SfxPoolItem * GetItemOfScript(SvtScriptType nScript) const
virtual SfxObjectShell * GetObjectShell()
void EDITENG_DLLPUBLIC ReplaceTextWithSynonym(EditView &rEditView, const OUString &rSynonmText)
virtual std::vector< OUString > GetSelectedNames() const =0
EVControlBits GetControlWord() const
bool IsInsertMode() const
EditView * pEditView
Definition: editsh.hxx:40
#define BTN_PASTE_NAME
Definition: scui_def.hxx:62
sal_Int32 nStartPos
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo