Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / editsh.cxx
blob92f211e13d717d2e44ba42b1bf960bf63f9624c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/linguistic2/XThesaurus.hpp>
21 #include <comphelper/string.hxx>
22 #include "scitems.hxx"
23 #include <editeng/eeitem.hxx>
24 #include <i18nutil/unicode.hxx>
26 #include <svx/clipfmtitem.hxx>
27 #include <svx/svxdlg.hxx>
28 #include <editeng/contouritem.hxx>
29 #include <editeng/outliner.hxx>
30 #include <editeng/unolingu.hxx>
31 #include <editeng/crossedoutitem.hxx>
32 #include <editeng/editeng.hxx>
33 #include <editeng/editview.hxx>
34 #include <editeng/escapementitem.hxx>
35 #include <editeng/flditem.hxx>
36 #include <editeng/flstitem.hxx>
37 #include <editeng/fontitem.hxx>
38 #include <svx/hlnkitem.hxx>
39 #include <sfx2/sidebar/EnumContext.hxx>
40 #include <editeng/postitem.hxx>
41 #include <editeng/scripttypeitem.hxx>
42 #include <editeng/shdditem.hxx>
43 #include <svl/srchitem.hxx>
44 #include <editeng/udlnitem.hxx>
45 #include <editeng/wghtitem.hxx>
46 #include <sfx2/basedlgs.hxx>
47 #include <sfx2/bindings.hxx>
48 #include <sfx2/msg.hxx>
49 #include <sfx2/objface.hxx>
50 #include <sfx2/objsh.hxx>
51 #include <sfx2/request.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sot/exchange.hxx>
54 #include <svtools/cliplistener.hxx>
55 #include <svl/whiter.hxx>
56 #include <vcl/msgbox.hxx>
57 #include <sot/formats.hxx>
58 #include <svtools/transfer.hxx>
59 #include <svl/stritem.hxx>
61 #include "editsh.hxx"
62 #include "scresid.hxx"
63 #include "global.hxx"
64 #include "sc.hrc"
65 #include "scmod.hxx"
66 #include "inputhdl.hxx"
67 #include "viewutil.hxx"
68 #include "viewdata.hxx"
69 #include "document.hxx"
70 #include "reffind.hxx"
71 #include "tabvwsh.hxx"
72 #include "editutil.hxx"
73 #include "globstr.hrc"
74 #include <gridwin.hxx>
76 #define ScEditShell
77 #include "scslots.hxx"
79 #include "scui_def.hxx"
80 #include "scabstdlg.hxx"
81 #include <memory>
83 using namespace ::com::sun::star;
86 SFX_IMPL_INTERFACE(ScEditShell, SfxShell)
88 void ScEditShell::InitInterface_Impl()
90 GetStaticInterface()->RegisterPopupMenu("celledit");
93 ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) :
94 pEditView (pView),
95 pViewData (pData),
96 pClipEvtLstnr (nullptr),
97 bPastePossible (false),
98 bIsInsertMode (true)
100 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
101 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
102 SetName("EditCell");
103 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_EditCell));
106 ScEditShell::~ScEditShell()
108 if ( pClipEvtLstnr )
110 pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false );
112 // The listener may just now be waiting for the SolarMutex and call the link
113 // afterwards, in spite of RemoveListener. So the link has to be reset, too.
114 pClipEvtLstnr->ClearCallbackLink();
116 pClipEvtLstnr->release();
120 ScInputHandler* ScEditShell::GetMyInputHdl()
122 return SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
125 void ScEditShell::SetEditView(EditView* pView)
127 pEditView = pView;
128 pEditView->SetInsertMode( bIsInsertMode );
129 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
130 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
133 static void lcl_RemoveAttribs( EditView& rEditView )
135 ScEditEngineDefaulter* pEngine = static_cast<ScEditEngineDefaulter*>(rEditView.GetEditEngine());
137 bool bOld = pEngine->GetUpdateMode();
138 pEngine->SetUpdateMode(false);
140 OUString aName = ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );
141 pEngine->GetUndoManager().EnterListAction( aName, aName );
143 rEditView.RemoveAttribs(true);
144 pEngine->RepeatDefaults(); // paragraph attributes from cell formats must be preserved
146 pEngine->GetUndoManager().LeaveListAction();
148 pEngine->SetUpdateMode(bOld);
151 void lclInsertCharacter( EditView* pTableView, EditView* pTopView, sal_Unicode cChar )
153 OUString aString( cChar );
154 if( pTableView )
155 pTableView->InsertText( aString );
156 if( pTopView )
157 pTopView->InsertText( aString );
160 void ScEditShell::Execute( SfxRequest& rReq )
162 const SfxItemSet* pReqArgs = rReq.GetArgs();
163 sal_uInt16 nSlot = rReq.GetSlot();
164 SfxBindings& rBindings = pViewData->GetBindings();
166 ScInputHandler* pHdl = GetMyInputHdl();
167 OSL_ENSURE(pHdl,"no ScInputHandler");
169 EditView* pTopView = pHdl->GetTopView(); // Has thee input cell the focus?
170 EditView* pTableView = pHdl->GetTableView();
172 OSL_ENSURE(pTableView,"no EditView :-(");
173 /* #i91683# No EditView if spell-check dialog is active and positioned on
174 * an error and user immediately (without double click or F2) selected a
175 * text portion of that cell with the mouse and wanted to modify it. */
176 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
177 * action is possible. A real fix somehow would need to create a valid
178 * EditView from the spell-check view. */
179 if (!pTableView)
180 return;
182 EditEngine* pEngine = pTableView->GetEditEngine();
184 pHdl->DataChanging();
185 bool bSetSelIsRef = false;
186 bool bSetModified = true;
188 switch ( nSlot )
190 case FID_INS_CELL_CONTENTS: // Insert taste, while defined as Acc
191 bIsInsertMode = !pTableView->IsInsertMode();
192 pTableView->SetInsertMode( bIsInsertMode );
193 if (pTopView)
194 pTopView->SetInsertMode( bIsInsertMode );
195 rBindings.Invalidate( SID_ATTR_INSERT );
196 break;
198 case SID_ATTR_INSERT:
199 if ( pReqArgs )
201 bIsInsertMode = static_cast<const SfxBoolItem&>(pReqArgs->Get(nSlot)).GetValue();
202 pTableView->SetInsertMode( bIsInsertMode );
203 if (pTopView)
204 pTopView->SetInsertMode( bIsInsertMode );
205 rBindings.Invalidate( SID_ATTR_INSERT );
207 break;
209 case SID_THES:
211 OUString aReplaceText;
212 const SfxStringItem* pItem2 = rReq.GetArg<SfxStringItem>(SID_THES);
213 if (pItem2)
214 aReplaceText = pItem2->GetValue();
215 if (!aReplaceText.isEmpty())
216 ReplaceTextWithSynonym( *pEditView, aReplaceText );
218 break;
220 case SID_COPY:
221 pTableView->Copy();
222 bSetModified = false;
223 break;
225 case SID_CUT:
226 pTableView->Cut();
227 if (pTopView)
228 pTopView->DeleteSelected();
229 break;
231 case SID_PASTE:
232 pTableView->PasteSpecial();
233 if (pTopView)
234 pTopView->Paste();
235 break;
237 case SID_DELETE:
238 pTableView->DeleteSelected();
239 if (pTopView)
240 pTopView->DeleteSelected();
241 break;
243 case SID_CELL_FORMAT_RESET: // "Standard"
244 lcl_RemoveAttribs( *pTableView );
245 if ( pTopView )
246 lcl_RemoveAttribs( *pTopView );
247 break;
249 case SID_CLIPBOARD_FORMAT_ITEMS:
251 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
252 const SfxPoolItem* pItem;
253 if ( pReqArgs &&
254 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
255 dynamic_cast<const SfxUInt32Item*>( pItem) != nullptr )
257 nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
260 if ( nFormat != SotClipboardFormatId::NONE )
262 if (SotClipboardFormatId::STRING == nFormat)
263 pTableView->Paste();
264 else
265 pTableView->PasteSpecial();
267 if (pTopView)
268 pTopView->Paste();
271 break;
273 case SID_PASTE_SPECIAL:
275 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
276 std::unique_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( pViewData->GetDialogParent() ));
277 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
278 if ( pDlg )
280 pDlg->Insert( SotClipboardFormatId::STRING, EMPTY_OUSTRING );
281 pDlg->Insert( SotClipboardFormatId::RTF, EMPTY_OUSTRING );
283 TransferableDataHelper aDataHelper(
284 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
286 nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
288 pDlg.reset();
290 // while the dialog was open, edit mode may have been stopped
291 if (!SC_MOD()->IsInputMode())
292 return;
294 if (nFormat != SotClipboardFormatId::NONE)
296 if (SotClipboardFormatId::STRING == nFormat)
297 pTableView->Paste();
298 else
299 pTableView->PasteSpecial();
301 if (pTopView)
302 pTopView->Paste();
305 if (pTopView)
306 pTopView->GetWindow()->GrabFocus();
308 break;
310 case SID_SELECTALL:
312 sal_Int32 nPar = pEngine->GetParagraphCount();
313 if (nPar)
315 sal_Int32 nLen = pEngine->GetTextLen(nPar-1);
316 pTableView->SetSelection(ESelection(0,0,nPar-1,nLen));
317 if (pTopView)
318 pTopView->SetSelection(ESelection(0,0,nPar-1,nLen));
319 rBindings.Invalidate( SID_ATTR_CHAR_FONT );
320 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
321 rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
322 rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
323 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
324 rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
325 rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
326 rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
327 rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
328 rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
329 rBindings.Invalidate( SID_SET_SUB_SCRIPT );
332 return;
333 case SID_UNICODE_NOTATION_TOGGLE:
335 EditView* pActiveView = pHdl->GetActiveView();
336 if( pActiveView )
338 OUString sInput = pEngine->GetText();
339 ESelection aSel( pActiveView->GetSelection() );
340 if( aSel.HasRange() )
341 sInput = pActiveView->GetSelected();
343 if( aSel.nStartPos > aSel.nEndPos )
344 aSel.nEndPos = aSel.nStartPos;
346 //calculate a valid end-position by reading logical characters
347 sal_Int32 nUtf16Pos=0;
348 while( (nUtf16Pos < sInput.getLength()) && (nUtf16Pos < aSel.nEndPos) )
350 sInput.iterateCodePoints(&nUtf16Pos);
351 if( nUtf16Pos > aSel.nEndPos )
352 aSel.nEndPos = nUtf16Pos;
355 ToggleUnicodeCodepoint aToggle;
356 while( nUtf16Pos && aToggle.AllowMoreInput( sInput[nUtf16Pos-1]) )
357 --nUtf16Pos;
358 OUString sReplacement = aToggle.ReplacementString();
359 if( !sReplacement.isEmpty() )
361 aSel.nStartPos = aSel.nEndPos - aToggle.StringToReplace().getLength();
362 pTableView->SetSelection( aSel );
363 pTableView->InsertText(sReplacement, true);
364 if( pTopView )
366 pTopView->SetSelection( aSel );
367 pTopView->InsertText(sReplacement, true);
372 break;
374 case SID_CHARMAP:
376 SvtScriptType nScript = pTableView->GetSelectedScriptType();
377 sal_uInt16 nFontWhich = ( nScript == SvtScriptType::ASIAN ) ? EE_CHAR_FONTINFO_CJK :
378 ( ( nScript == SvtScriptType::COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
379 EE_CHAR_FONTINFO );
380 const SvxFontItem& rItem = static_cast<const SvxFontItem&>(
381 pTableView->GetAttribs().Get(nFontWhich));
383 OUString aString;
384 SvxFontItem aNewItem( EE_CHAR_FONTINFO );
386 const SfxItemSet *pArgs = rReq.GetArgs();
387 const SfxPoolItem* pItem = nullptr;
388 if( pArgs )
389 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
391 if ( pItem )
393 aString = static_cast<const SfxStringItem*>(pItem)->GetValue();
394 const SfxPoolItem* pFtItem = nullptr;
395 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
396 const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem );
397 if ( pFontItem )
399 OUString aFontName(pFontItem->GetValue());
400 vcl::Font aFont(aFontName, Size(1,1)); // Size just because CTOR
401 aNewItem = SvxFontItem( aFont.GetFamilyType(), aFont.GetFamilyName(),
402 aFont.GetStyleName(), aFont.GetPitch(),
403 aFont.GetCharSet(), ATTR_FONT );
405 else
406 aNewItem = rItem;
408 else
410 ScViewUtil::ExecuteCharMap( rItem, *pViewData->GetViewShell()->GetViewFrame(), aNewItem, aString );
412 // while the dialog was open, edit mode may have been stopped
413 if (!SC_MOD()->IsInputMode())
414 return;
417 if ( !aString.isEmpty() )
419 // if string contains WEAK characters, set all fonts
420 SvtScriptType nSetScript;
421 ScDocument* pDoc = pViewData->GetDocument();
422 if ( pDoc->HasStringWeakCharacters( aString ) )
423 nSetScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
424 else
425 nSetScript = pDoc->GetStringScriptType( aString );
427 SfxItemSet aSet( pTableView->GetEmptyItemSet() );
428 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() );
429 aSetItem.PutItemForScriptType( nSetScript, aNewItem );
430 aSet.Put( aSetItem.GetItemSet(), false );
432 // SetAttribs on the View selects a word, when nothing is selected
433 pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() );
434 pTableView->InsertText(aString);
435 if (pTopView)
436 pTopView->InsertText(aString);
438 SfxStringItem aStringItem( SID_CHARMAP, aString );
439 SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem.GetFamilyName() );
440 rReq.AppendItem( aFontItem );
441 rReq.AppendItem( aStringItem );
442 rReq.Done();
446 if (pTopView)
447 pTopView->GetWindow()->GrabFocus();
449 break;
451 case FID_INSERT_NAME:
453 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
454 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
456 std::unique_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pViewData->GetDocShell(), false ));
457 OSL_ENSURE(pDlg, "Dialog create fail!");
458 short nRet = pDlg->Execute();
459 // pDlg is needed below
461 // while the dialog was open, edit mode may have been stopped
462 if (!SC_MOD()->IsInputMode())
463 return;
465 if ( nRet == BTN_PASTE_NAME )
467 std::vector<OUString> aNames = pDlg->GetSelectedNames();
468 if (!aNames.empty())
470 OUStringBuffer aBuffer;
471 for (std::vector<OUString>::const_iterator itr = aNames.begin();
472 itr != aNames.end(); ++itr)
474 aBuffer.append(*itr).append(' ');
476 pTableView->InsertText(aBuffer.toString());
477 if (pTopView)
478 pTopView->InsertText(aBuffer.makeStringAndClear());
481 pDlg.reset();
483 if (pTopView)
484 pTopView->GetWindow()->GrabFocus();
486 break;
488 case SID_CHAR_DLG_EFFECT:
489 case SID_CHAR_DLG:
491 SfxItemSet aAttrs( pTableView->GetAttribs() );
493 SfxObjectShell* pObjSh = pViewData->GetSfxDocShell();
495 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
496 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
498 std::unique_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
499 pViewData->GetDialogParent(), &aAttrs, pObjSh));
500 OSL_ENSURE(pDlg, "Dialog create fail!");
501 if (nSlot == SID_CHAR_DLG_EFFECT)
503 pDlg->SetCurPageId("fonteffects");
505 short nRet = pDlg->Execute();
506 // pDlg is needed below
508 // while the dialog was open, edit mode may have been stopped
509 if (!SC_MOD()->IsInputMode())
510 return;
512 if ( nRet == RET_OK )
514 const SfxItemSet* pOut = pDlg->GetOutputItemSet();
515 pTableView->SetAttribs( *pOut );
518 break;
520 case SID_TOGGLE_REL:
522 if (pEngine->GetParagraphCount() == 1)
524 OUString aText = pEngine->GetText();
525 ESelection aSel = pEditView->GetSelection(); // current View
527 ScDocument* pDoc = pViewData->GetDocument();
528 ScRefFinder aFinder(aText, pViewData->GetCurPos(), pDoc, pDoc->GetAddressConvention());
529 aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos );
530 if (aFinder.GetFound())
532 OUString aNew = aFinder.GetText();
533 ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() );
534 pEngine->SetText( aNew );
535 pTableView->SetSelection( aNewSel );
536 if ( pTopView )
538 pTopView->GetEditEngine()->SetText( aNew );
539 pTopView->SetSelection( aNewSel );
542 // refenence is being selected -> do not overwrite when typing
543 bSetSelIsRef = true;
547 break;
549 case SID_HYPERLINK_SETLINK:
550 if( pReqArgs )
552 const SfxPoolItem* pItem;
553 if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, true, &pItem ) == SfxItemState::SET )
555 const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem);
556 const OUString& rName = pHyper->GetName();
557 const OUString& rURL = pHyper->GetURL();
558 const OUString& rTarget = pHyper->GetTargetFrame();
559 SvxLinkInsertMode eMode = pHyper->GetInsertMode();
561 bool bDone = false;
562 if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
564 const SvxURLField* pURLField = GetURLField();
565 if ( pURLField )
567 // select old field
569 ESelection aSel = pTableView->GetSelection();
570 aSel.Adjust();
571 aSel.nEndPara = aSel.nStartPara;
572 aSel.nEndPos = aSel.nStartPos + 1;
573 pTableView->SetSelection( aSel );
575 // insert new field
577 SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
578 aURLField.SetTargetFrame( rTarget );
579 SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
580 pTableView->InsertField( aURLItem );
581 pTableView->SetSelection( aSel ); // select inserted field
583 // now also fields in the Top-View
585 if ( pTopView )
587 aSel = pTopView->GetSelection();
588 aSel.nEndPara = aSel.nStartPara;
589 aSel.nEndPos = aSel.nStartPos + 1;
590 pTopView->SetSelection( aSel );
591 pTopView->InsertField( aURLItem );
592 pTopView->SetSelection( aSel ); // select inserted field
595 bDone = true;
599 if (!bDone)
601 pViewData->GetViewShell()->
602 InsertURL( rName, rURL, rTarget, (sal_uInt16) eMode );
604 // when "Button", the InsertURL in ViewShell turns the EditShell off
605 // thus the immediate return statement
606 return;
610 break;
612 case SID_OPEN_HYPERLINK:
614 const SvxURLField* pURLField = GetURLField();
615 if ( pURLField )
616 ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
617 return;
620 case FN_INSERT_SOFT_HYPHEN:
621 lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
622 break;
623 case FN_INSERT_HARDHYPHEN:
624 lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
625 break;
626 case FN_INSERT_HARD_SPACE:
627 lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
628 break;
629 case SID_INSERT_RLM:
630 lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
631 break;
632 case SID_INSERT_LRM:
633 lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
634 break;
635 case SID_INSERT_ZWSP:
636 lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
637 break;
638 case SID_INSERT_ZWNBSP:
639 lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
640 break;
641 case SID_INSERT_FIELD_SHEET:
643 SvxTableField aField(pViewData->GetTabNo());
644 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
645 pTableView->InsertField(aItem);
647 break;
648 case SID_INSERT_FIELD_TITLE:
650 SvxFileField aField;
651 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
652 pTableView->InsertField(aItem);
654 break;
655 case SID_INSERT_FIELD_DATE_VAR:
657 SvxDateField aField;
658 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
659 pTableView->InsertField(aItem);
661 break;
664 pHdl->DataChanged(false, bSetModified);
665 if (bSetSelIsRef)
666 pHdl->SetSelIsRef(true);
669 static void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots
671 SfxWhichIter aIter( rSet );
672 sal_uInt16 nWhich = aIter.FirstWhich();
673 while (nWhich)
675 rSet.DisableItem( nWhich );
676 nWhich = aIter.NextWhich();
680 void ScEditShell::GetState( SfxItemSet& rSet )
682 // When deactivating the view, edit mode is stopped, but the EditShell is left active
683 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
684 // into the EditEngine, so it can have an invalid selection and must not be used.
685 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )
687 lcl_DisableAll( rSet );
688 return;
691 ScInputHandler* pHdl = GetMyInputHdl();
692 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
694 SfxWhichIter aIter( rSet );
695 sal_uInt16 nWhich = aIter.FirstWhich();
696 while (nWhich)
698 switch (nWhich)
700 case SID_ATTR_INSERT: // Status row
702 if ( pActiveView )
703 rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
704 else
706 // Here the code used to pass the value 42 and it used
707 // to "work" without warnings because the SfxBoolItem
708 // was based on 'sal_Bool', which is actually 'unsigned
709 // char'. But now it uses actual 'bool', and passing 42
710 // for a 'bool' parameter causes a warning at least with
711 // MSVC. So use 'true'. I really really hope there is
712 // not code somewhere that retrieves this "boolean" item
713 // and checks it value for the magic value 42...
714 rSet.Put( SfxBoolItem( nWhich, true) );
717 break;
719 case SID_HYPERLINK_GETLINK:
721 SvxHyperlinkItem aHLinkItem;
722 const SvxURLField* pURLField = GetURLField();
723 if ( pURLField )
725 aHLinkItem.SetName( pURLField->GetRepresentation() );
726 aHLinkItem.SetURL( pURLField->GetURL() );
727 aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
729 else if ( pActiveView )
731 // use selected text as name for urls
732 OUString sReturn = pActiveView->GetSelected();
733 sReturn = sReturn.copy(0, std::min(sReturn.getLength(), static_cast<sal_Int32>(255)));
734 aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
736 rSet.Put(aHLinkItem);
738 break;
740 case SID_OPEN_HYPERLINK:
742 if ( !GetURLField() )
743 rSet.DisableItem( nWhich );
745 break;
747 case SID_TRANSLITERATE_HALFWIDTH:
748 case SID_TRANSLITERATE_FULLWIDTH:
749 case SID_TRANSLITERATE_HIRAGANA:
750 case SID_TRANSLITERATE_KATAGANA:
751 case SID_INSERT_RLM:
752 case SID_INSERT_LRM:
753 case SID_INSERT_ZWNBSP:
754 case SID_INSERT_ZWSP:
755 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich );
756 break;
758 case SID_THES:
760 OUString aStatusVal;
761 LanguageType nLang = LANGUAGE_NONE;
762 bool bIsLookUpWord = pActiveView &&
763 GetStatusValueForThesaurusFromContext(aStatusVal, nLang, *pActiveView);
764 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
766 // disable thesaurus context menu entry if there is nothing to look up
767 bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
768 if (!bIsLookUpWord || !bCanDoThesaurus)
769 rSet.DisableItem( SID_THES );
771 break;
772 case SID_INSERT_FIELD_SHEET:
773 case SID_INSERT_FIELD_TITLE:
774 case SID_INSERT_FIELD_DATE_VAR:
775 break;
778 nWhich = aIter.NextWhich();
782 const SvxURLField* ScEditShell::GetURLField()
784 ScInputHandler* pHdl = GetMyInputHdl();
785 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
786 if ( pActiveView )
788 const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection();
789 if (pFieldItem)
791 const SvxFieldData* pField = pFieldItem->GetField();
792 if ( pField && dynamic_cast<const SvxURLField*>( pField) != nullptr )
793 return static_cast<const SvxURLField*>(pField);
797 return nullptr;
800 IMPL_LINK_TYPED( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )
802 bPastePossible = ( pDataHelper->HasFormat( SotClipboardFormatId::STRING ) || pDataHelper->HasFormat( SotClipboardFormatId::RTF ) );
804 SfxBindings& rBindings = pViewData->GetBindings();
805 rBindings.Invalidate( SID_PASTE );
806 rBindings.Invalidate( SID_PASTE_SPECIAL );
807 rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
810 void ScEditShell::GetClipState( SfxItemSet& rSet )
812 if ( !pClipEvtLstnr )
814 // create listener
815 pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
816 pClipEvtLstnr->acquire();
817 vcl::Window* pWin = pViewData->GetActiveWin();
818 pClipEvtLstnr->AddRemoveListener( pWin, true );
820 // get initial state
821 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
822 bPastePossible = ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) || aDataHelper.HasFormat( SotClipboardFormatId::RTF ) );
825 SfxWhichIter aIter( rSet );
826 sal_uInt16 nWhich = aIter.FirstWhich();
827 while (nWhich)
829 switch (nWhich)
831 case SID_PASTE:
832 case SID_PASTE_SPECIAL:
833 if( !bPastePossible )
834 rSet.DisableItem( nWhich );
835 break;
836 case SID_CLIPBOARD_FORMAT_ITEMS:
837 if( bPastePossible )
839 SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
840 TransferableDataHelper aDataHelper(
841 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
843 if ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) )
844 aFormats.AddClipbrdFormat( SotClipboardFormatId::STRING );
845 if ( aDataHelper.HasFormat( SotClipboardFormatId::RTF ) )
846 aFormats.AddClipbrdFormat( SotClipboardFormatId::RTF );
848 rSet.Put( aFormats );
850 else
851 rSet.DisableItem( nWhich );
852 break;
854 nWhich = aIter.NextWhich();
858 static void lcl_InvalidateUnder( SfxBindings& rBindings )
860 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
861 rBindings.Invalidate( SID_ULINE_VAL_NONE );
862 rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
863 rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
864 rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
867 void ScEditShell::ExecuteAttr(SfxRequest& rReq)
869 SfxItemSet aSet( pEditView->GetEmptyItemSet() );
870 SfxBindings& rBindings = pViewData->GetBindings();
871 const SfxItemSet* pArgs = rReq.GetArgs();
872 sal_uInt16 nSlot = rReq.GetSlot();
874 switch ( nSlot )
876 case SID_ATTR_CHAR_FONTHEIGHT:
877 case SID_ATTR_CHAR_FONT:
879 if (pArgs)
881 // #i78017 establish the same behaviour as in Writer
882 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
883 if (nSlot == SID_ATTR_CHAR_FONT)
885 nScript = pEditView->GetSelectedScriptType();
886 if (nScript == SvtScriptType::NONE) nScript = ScGlobal::GetDefaultScriptType();
889 SfxItemPool& rPool = GetPool();
890 SvxScriptSetItem aSetItem( nSlot, rPool );
891 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
892 aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
894 aSet.Put( aSetItem.GetItemSet(), false );
897 break;
899 case SID_ATTR_CHAR_COLOR:
901 if (pArgs)
903 aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
904 rBindings.Invalidate( nSlot );
907 break;
909 // Toggles
911 case SID_ATTR_CHAR_WEIGHT:
913 // #i78017 establish the same behaviour as in Writer
914 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
916 SfxItemPool& rPool = GetPool();
918 bool bOld = false;
919 SvxScriptSetItem aOldSetItem( nSlot, rPool );
920 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
921 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
922 if ( pCore && static_cast<const SvxWeightItem*>(pCore)->GetWeight() > WEIGHT_NORMAL )
923 bOld = true;
925 SvxScriptSetItem aSetItem( nSlot, rPool );
926 aSetItem.PutItemForScriptType( nScript,
927 SvxWeightItem( bOld ? WEIGHT_NORMAL : WEIGHT_BOLD, EE_CHAR_WEIGHT ) );
928 aSet.Put( aSetItem.GetItemSet(), false );
930 rBindings.Invalidate( nSlot );
932 break;
934 case SID_ATTR_CHAR_POSTURE:
936 // #i78017 establish the same behaviour as in Writer
937 SvtScriptType nScript = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
939 SfxItemPool& rPool = GetPool();
941 bool bOld = false;
942 SvxScriptSetItem aOldSetItem( nSlot, rPool );
943 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
944 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
945 if ( pCore && static_cast<const SvxPostureItem*>(pCore)->GetValue() != ITALIC_NONE )
946 bOld = true;
948 SvxScriptSetItem aSetItem( nSlot, rPool );
949 aSetItem.PutItemForScriptType( nScript,
950 SvxPostureItem( bOld ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
951 aSet.Put( aSetItem.GetItemSet(), false );
953 rBindings.Invalidate( nSlot );
955 break;
957 case SID_ULINE_VAL_NONE:
958 aSet.Put( SvxUnderlineItem( LINESTYLE_NONE, EE_CHAR_UNDERLINE ) );
959 lcl_InvalidateUnder( rBindings );
960 break;
962 case SID_ATTR_CHAR_UNDERLINE:
963 case SID_ULINE_VAL_SINGLE:
964 case SID_ULINE_VAL_DOUBLE:
965 case SID_ULINE_VAL_DOTTED:
967 FontLineStyle eOld = static_cast<const SvxUnderlineItem&>( pEditView->
968 GetAttribs().Get(EE_CHAR_UNDERLINE)).GetLineStyle();
969 FontLineStyle eNew = eOld;
970 switch (nSlot)
972 case SID_ATTR_CHAR_UNDERLINE:
973 if ( pArgs )
975 const SvxTextLineItem& rTextLineItem = static_cast< const SvxTextLineItem& >( pArgs->Get( pArgs->GetPool()->GetWhich(nSlot) ) );
976 eNew = rTextLineItem.GetLineStyle();
978 else
980 eNew = ( eOld != LINESTYLE_NONE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
982 break;
983 case SID_ULINE_VAL_SINGLE:
984 eNew = ( eOld == LINESTYLE_SINGLE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
985 break;
986 case SID_ULINE_VAL_DOUBLE:
987 eNew = ( eOld == LINESTYLE_DOUBLE ) ? LINESTYLE_NONE : LINESTYLE_DOUBLE;
988 break;
989 case SID_ULINE_VAL_DOTTED:
990 eNew = ( eOld == LINESTYLE_DOTTED ) ? LINESTYLE_NONE : LINESTYLE_DOTTED;
991 break;
993 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
994 lcl_InvalidateUnder( rBindings );
996 break;
998 case SID_ATTR_CHAR_OVERLINE:
1000 FontLineStyle eOld = static_cast<const SvxOverlineItem&>( pEditView->
1001 GetAttribs().Get(EE_CHAR_OVERLINE)).GetLineStyle();
1002 FontLineStyle eNew = ( eOld != LINESTYLE_NONE ) ? LINESTYLE_NONE : LINESTYLE_SINGLE;
1003 aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) );
1004 rBindings.Invalidate( nSlot );
1006 break;
1008 case SID_ATTR_CHAR_STRIKEOUT:
1010 bool bOld = static_cast<const SvxCrossedOutItem&>( pEditView->GetAttribs().
1011 Get(EE_CHAR_STRIKEOUT)).GetValue() != STRIKEOUT_NONE;
1012 aSet.Put( SvxCrossedOutItem( bOld ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
1013 rBindings.Invalidate( nSlot );
1015 break;
1017 case SID_ATTR_CHAR_SHADOWED:
1019 bool bOld = static_cast<const SvxShadowedItem&>(pEditView->GetAttribs().
1020 Get(EE_CHAR_SHADOW)).GetValue();
1021 aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) );
1022 rBindings.Invalidate( nSlot );
1024 break;
1026 case SID_ATTR_CHAR_CONTOUR:
1028 bool bOld = static_cast<const SvxContourItem&>(pEditView->GetAttribs().
1029 Get(EE_CHAR_OUTLINE)).GetValue();
1030 aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) );
1031 rBindings.Invalidate( nSlot );
1033 break;
1035 case SID_SET_SUPER_SCRIPT:
1037 SvxEscapement eOld = (SvxEscapement) static_cast<const SvxEscapementItem&>(
1038 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1039 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUPERSCRIPT) ?
1040 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUPERSCRIPT;
1041 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1042 rBindings.Invalidate( nSlot );
1044 break;
1045 case SID_SET_SUB_SCRIPT:
1047 SvxEscapement eOld = (SvxEscapement) static_cast<const SvxEscapementItem&>(
1048 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1049 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUBSCRIPT) ?
1050 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUBSCRIPT;
1051 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1052 rBindings.Invalidate( nSlot );
1054 break;
1055 case SID_ATTR_CHAR_KERNING:
1057 if(pArgs)
1059 aSet.Put ( pArgs->Get(pArgs->GetPool()->GetWhich(nSlot)));
1060 rBindings.Invalidate( nSlot );
1063 break;
1065 case SID_GROW_FONT_SIZE:
1066 case SID_SHRINK_FONT_SIZE:
1068 const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
1069 ( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
1070 const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
1071 pEditView->ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
1072 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
1074 break;
1077 // apply
1079 EditEngine* pEngine = pEditView->GetEditEngine();
1080 bool bOld = pEngine->GetUpdateMode();
1081 pEngine->SetUpdateMode(false);
1083 pEditView->SetAttribs( aSet );
1085 pEngine->SetUpdateMode(bOld);
1086 pEditView->Invalidate();
1088 ScInputHandler* pHdl = GetMyInputHdl();
1089 pHdl->SetModified();
1091 rReq.Done();
1094 void ScEditShell::GetAttrState(SfxItemSet &rSet)
1096 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )
1098 lcl_DisableAll( rSet );
1099 return;
1102 SfxItemSet aAttribs = pEditView->GetAttribs();
1103 rSet.Put( aAttribs );
1105 // choose font info according to selection script type
1107 SvtScriptType nScript = pEditView->GetSelectedScriptType();
1108 if (nScript == SvtScriptType::NONE) nScript = ScGlobal::GetDefaultScriptType();
1110 // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1111 SvtScriptType nInputScript = nScript;
1112 if ( !pEditView->GetSelection().HasRange() )
1114 LanguageType nInputLang = pViewData->GetActiveWin()->GetInputLanguage();
1115 if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1116 nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1119 // #i55929# according to spec, nInputScript is used for font and font height only
1120 if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SfxItemState::UNKNOWN )
1121 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript );
1122 if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SfxItemState::UNKNOWN )
1123 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript );
1124 if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SfxItemState::UNKNOWN )
1125 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript );
1126 if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SfxItemState::UNKNOWN )
1127 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript );
1129 // underline
1131 SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE );
1132 if ( eState == SfxItemState::DONTCARE )
1134 rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1135 rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1136 rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1137 rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1139 else
1141 FontLineStyle eUnderline = static_cast<const SvxUnderlineItem&>(
1142 aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
1143 sal_uInt16 nId = SID_ULINE_VAL_NONE;
1144 switch (eUnderline)
1146 case LINESTYLE_SINGLE: nId = SID_ULINE_VAL_SINGLE; break;
1147 case LINESTYLE_DOUBLE: nId = SID_ULINE_VAL_DOUBLE; break;
1148 case LINESTYLE_DOTTED: nId = SID_ULINE_VAL_DOTTED; break;
1149 default:
1150 break;
1152 rSet.Put( SfxBoolItem( nId, true ) );
1155 //! Testing whether brace highlighting is active !!!!
1156 ScInputHandler* pHdl = GetMyInputHdl();
1157 if ( pHdl && pHdl->IsFormulaMode() )
1158 rSet.ClearItem( EE_CHAR_WEIGHT ); // Highlighted brace not here
1160 SvxEscapement eEsc = (SvxEscapement) static_cast<const SvxEscapementItem&>(
1161 aAttribs.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
1162 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
1164 rSet.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT, true ) );
1166 else if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
1168 rSet.Put( SfxBoolItem( SID_SET_SUB_SCRIPT, true ) );
1170 pViewData->GetBindings().Invalidate( SID_SET_SUPER_SCRIPT );
1171 pViewData->GetBindings().Invalidate( SID_SET_SUB_SCRIPT );
1173 eState = aAttribs.GetItemState( EE_CHAR_KERNING );
1174 pViewData->GetBindings().Invalidate( SID_ATTR_CHAR_KERNING );
1175 if ( eState == SfxItemState::DONTCARE )
1177 rSet.InvalidateItem(EE_CHAR_KERNING);
1181 OUString ScEditShell::GetSelectionText( bool bWholeWord )
1183 OUString aStrSelection;
1185 if ( pViewData->HasEditView( pViewData->GetActivePart() ) )
1187 if ( bWholeWord )
1189 EditEngine* pEngine = pEditView->GetEditEngine();
1190 ESelection aSel = pEditView->GetSelection();
1191 OUString aStrCurrentDelimiters = pEngine->GetWordDelimiters();
1193 pEngine->SetWordDelimiters(" .,;\"'");
1194 aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos );
1195 pEngine->SetWordDelimiters( aStrCurrentDelimiters );
1197 else
1199 aStrSelection = pEditView->GetSelected();
1203 return aStrSelection;
1206 void ScEditShell::ExecuteUndo(SfxRequest& rReq)
1208 // Undo must be handled here because it's called for both EditViews
1210 ScInputHandler* pHdl = GetMyInputHdl();
1211 OSL_ENSURE(pHdl,"no ScInputHandler");
1212 EditView* pTopView = pHdl->GetTopView();
1213 EditView* pTableView = pHdl->GetTableView();
1214 OSL_ENSURE(pTableView,"no EditView");
1216 pHdl->DataChanging();
1218 const SfxItemSet* pReqArgs = rReq.GetArgs();
1219 sal_uInt16 nSlot = rReq.GetSlot();
1220 switch ( nSlot )
1222 case SID_UNDO:
1223 case SID_REDO:
1225 bool bIsUndo = ( nSlot == SID_UNDO );
1227 sal_uInt16 nCount = 1;
1228 const SfxPoolItem* pItem;
1229 if ( pReqArgs && pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
1230 nCount = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1232 for (sal_uInt16 i=0; i<nCount; i++)
1234 if ( bIsUndo )
1236 pTableView->Undo();
1237 if (pTopView)
1238 pTopView->Undo();
1240 else
1242 pTableView->Redo();
1243 if (pTopView)
1244 pTopView->Redo();
1248 break;
1250 pViewData->GetBindings().InvalidateAll(false);
1252 pHdl->DataChanged();
1255 void ScEditShell::GetUndoState(SfxItemSet &rSet)
1257 // Undo state is taken from normal ViewFrame state function
1259 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
1260 if ( pViewFrm && GetUndoManager() )
1262 SfxWhichIter aIter(rSet);
1263 sal_uInt16 nWhich = aIter.FirstWhich();
1264 while( nWhich )
1266 pViewFrm->GetSlotState( nWhich, nullptr, &rSet );
1267 nWhich = aIter.NextWhich();
1271 // disable if no action in input line EditView
1273 ScInputHandler* pHdl = GetMyInputHdl();
1274 OSL_ENSURE(pHdl,"no ScInputHandler");
1275 EditView* pTopView = pHdl->GetTopView();
1276 if (pTopView)
1278 ::svl::IUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager();
1279 if ( rTopMgr.GetUndoActionCount() == 0 )
1280 rSet.DisableItem( SID_UNDO );
1281 if ( rTopMgr.GetRedoActionCount() == 0 )
1282 rSet.DisableItem( SID_REDO );
1286 void ScEditShell::ExecuteTrans( SfxRequest& rReq )
1288 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
1289 if ( nType )
1291 ScInputHandler* pHdl = GetMyInputHdl();
1292 assert(pHdl && "no ScInputHandler");
1294 EditView* pTopView = pHdl->GetTopView();
1295 EditView* pTableView = pHdl->GetTableView();
1296 assert(pTableView && "no EditView");
1298 pHdl->DataChanging();
1300 pTableView->TransliterateText( nType );
1301 if (pTopView)
1302 pTopView->TransliterateText( nType );
1304 pHdl->DataChanged();
1308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */