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