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