1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include <svx/clipfmtitem.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <editeng/contouritem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <editeng/unolingu.hxx>
30 #include <editeng/crossedoutitem.hxx>
31 #include <editeng/editeng.hxx>
32 #include <editeng/editview.hxx>
33 #include <editeng/escapementitem.hxx>
34 #include <editeng/flditem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include <svx/hlnkitem.hxx>
37 #include <sfx2/sidebar/EnumContext.hxx>
38 #include <editeng/postitem.hxx>
39 #include <editeng/scripttypeitem.hxx>
40 #include <editeng/shdditem.hxx>
41 #include <svl/srchitem.hxx>
42 #include <editeng/udlnitem.hxx>
43 #include <editeng/wghtitem.hxx>
44 #include <sfx2/basedlgs.hxx>
45 #include <sfx2/bindings.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 <sot/exchange.hxx>
52 #include <svtools/cliplistener.hxx>
53 #include <svl/whiter.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <sot/formats.hxx>
56 #include <svtools/transfer.hxx>
57 #include <svl/stritem.hxx>
60 #include "scresid.hxx"
64 #include "inputhdl.hxx"
65 #include "viewutil.hxx"
66 #include "viewdata.hxx"
67 #include "document.hxx"
68 #include "reffind.hxx"
69 #include "tabvwsh.hxx"
70 #include "editutil.hxx"
71 #include "globstr.hrc"
72 #include <gridwin.hxx>
75 #include "scslots.hxx"
77 #include "scui_def.hxx"
78 #include "scabstdlg.hxx"
79 #include <boost/scoped_ptr.hpp>
81 using namespace ::com::sun::star
;
83 TYPEINIT1( ScEditShell
, SfxShell
);
85 SFX_IMPL_INTERFACE(ScEditShell
, SfxShell
)
87 void ScEditShell::InitInterface_Impl()
89 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_EDIT
));
92 ScEditShell::ScEditShell(EditView
* pView
, ScViewData
* pData
) :
96 bPastePossible (false),
99 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
100 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
101 SetName(OUString("EditCell"));
102 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_EditCell
));
105 ScEditShell::~ScEditShell()
109 pClipEvtLstnr
->AddRemoveListener( pViewData
->GetActiveWin(), false );
111 // The listener may just now be waiting for the SolarMutex and call the link
112 // afterwards, in spite of RemoveListener. So the link has to be reset, too.
113 pClipEvtLstnr
->ClearCallbackLink();
115 pClipEvtLstnr
->release();
119 ScInputHandler
* ScEditShell::GetMyInputHdl()
121 return SC_MOD()->GetInputHdl( pViewData
->GetViewShell() );
124 void ScEditShell::SetEditView(EditView
* pView
)
127 pEditView
->SetInsertMode( bIsInsertMode
);
128 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
129 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
132 static void lcl_RemoveAttribs( EditView
& rEditView
)
134 ScEditEngineDefaulter
* pEngine
= static_cast<ScEditEngineDefaulter
*>(rEditView
.GetEditEngine());
136 bool bOld
= pEngine
->GetUpdateMode();
137 pEngine
->SetUpdateMode(false);
139 OUString aName
= ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS
);
140 pEngine
->GetUndoManager().EnterListAction( aName
, aName
);
142 rEditView
.RemoveAttribs(true);
143 pEngine
->RepeatDefaults(); // paragraph attributes from cell formats must be preserved
145 pEngine
->GetUndoManager().LeaveListAction();
147 pEngine
->SetUpdateMode(bOld
);
150 void lclInsertCharacter( EditView
* pTableView
, EditView
* pTopView
, sal_Unicode cChar
)
152 OUString
aString( cChar
);
154 pTableView
->InsertText( aString
);
156 pTopView
->InsertText( aString
);
159 void ScEditShell::Execute( SfxRequest
& rReq
)
161 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
162 sal_uInt16 nSlot
= rReq
.GetSlot();
163 SfxBindings
& rBindings
= pViewData
->GetBindings();
165 ScInputHandler
* pHdl
= GetMyInputHdl();
166 OSL_ENSURE(pHdl
,"kein ScInputHandler");
168 EditView
* pTopView
= pHdl
->GetTopView(); // hat Eingabezeile den Focus?
169 EditView
* pTableView
= pHdl
->GetTableView();
171 OSL_ENSURE(pTableView
,"no EditView :-(");
172 /* #i91683# No EditView if spell-check dialog is active and positioned on
173 * an error and user immediately (without double click or F2) selected a
174 * text portion of that cell with the mouse and wanted to modify it. */
175 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
176 * action is possible. A real fix somehow would need to create a valid
177 * EditView from the spell-check view. */
181 EditEngine
* pEngine
= pTableView
->GetEditEngine();
183 pHdl
->DataChanging();
184 bool bSetSelIsRef
= false;
185 bool bSetModified
= true;
189 case FID_INS_CELL_CONTENTS
: // Insert-Taste, weil als Acc definiert
190 bIsInsertMode
= !pTableView
->IsInsertMode();
191 pTableView
->SetInsertMode( bIsInsertMode
);
193 pTopView
->SetInsertMode( bIsInsertMode
);
194 rBindings
.Invalidate( SID_ATTR_INSERT
);
197 case SID_ATTR_INSERT
:
200 bIsInsertMode
= static_cast<const SfxBoolItem
&>(pReqArgs
->Get(nSlot
)).GetValue();
201 pTableView
->SetInsertMode( bIsInsertMode
);
203 pTopView
->SetInsertMode( bIsInsertMode
);
204 rBindings
.Invalidate( SID_ATTR_INSERT
);
210 OUString aReplaceText
;
211 SFX_REQUEST_ARG( rReq
, pItem2
, SfxStringItem
, SID_THES
, false );
213 aReplaceText
= pItem2
->GetValue();
214 if (!aReplaceText
.isEmpty())
215 ReplaceTextWithSynonym( *pEditView
, aReplaceText
);
221 bSetModified
= false;
227 pTopView
->DeleteSelected();
231 pTableView
->PasteSpecial();
237 pTableView
->DeleteSelected();
239 pTopView
->DeleteSelected();
242 case SID_CELL_FORMAT_RESET
: // "Standard"
243 lcl_RemoveAttribs( *pTableView
);
245 lcl_RemoveAttribs( *pTopView
);
248 case SID_CLIPBOARD_FORMAT_ITEMS
:
250 SotClipboardFormatId nFormat
= SotClipboardFormatId::NONE
;
251 const SfxPoolItem
* pItem
;
253 pReqArgs
->GetItemState(nSlot
, true, &pItem
) == SfxItemState::SET
&&
254 pItem
->ISA(SfxUInt32Item
) )
256 nFormat
= static_cast<SotClipboardFormatId
>(static_cast<const SfxUInt32Item
*>(pItem
)->GetValue());
259 if ( nFormat
!= SotClipboardFormatId::NONE
)
261 if (SotClipboardFormatId::STRING
== nFormat
)
264 pTableView
->PasteSpecial();
272 case SID_PASTE_SPECIAL
:
274 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
275 boost::scoped_ptr
<SfxAbstractPasteDialog
> pDlg(pFact
->CreatePasteDialog( pViewData
->GetDialogParent() ));
276 SotClipboardFormatId nFormat
= SotClipboardFormatId::NONE
;
279 pDlg
->Insert( SotClipboardFormatId::STRING
, EMPTY_OUSTRING
);
280 pDlg
->Insert( SotClipboardFormatId::RTF
, EMPTY_OUSTRING
);
282 TransferableDataHelper
aDataHelper(
283 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
285 nFormat
= pDlg
->GetFormat( aDataHelper
.GetTransferable() );
289 // while the dialog was open, edit mode may have been stopped
290 if (!SC_MOD()->IsInputMode())
293 if (nFormat
!= SotClipboardFormatId::NONE
)
295 if (SotClipboardFormatId::STRING
== nFormat
)
298 pTableView
->PasteSpecial();
305 pTopView
->GetWindow()->GrabFocus();
311 sal_Int32 nPar
= pEngine
->GetParagraphCount();
314 sal_Int32 nLen
= pEngine
->GetTextLen(nPar
-1);
315 pTableView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
317 pTopView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
318 rBindings
.Invalidate( SID_ATTR_CHAR_FONT
);
319 rBindings
.Invalidate( SID_ATTR_CHAR_FONTHEIGHT
);
320 rBindings
.Invalidate( SID_ATTR_CHAR_WEIGHT
);
321 rBindings
.Invalidate( SID_ATTR_CHAR_POSTURE
);
322 rBindings
.Invalidate( SID_ATTR_CHAR_UNDERLINE
);
323 rBindings
.Invalidate( SID_ATTR_CHAR_STRIKEOUT
);
324 rBindings
.Invalidate( SID_ATTR_CHAR_SHADOWED
);
325 rBindings
.Invalidate( SID_ATTR_CHAR_KERNING
);
326 rBindings
.Invalidate( SID_ATTR_CHAR_COLOR
);
327 rBindings
.Invalidate( SID_SET_SUPER_SCRIPT
);
328 rBindings
.Invalidate( SID_SET_SUB_SCRIPT
);
330 bSetModified
= false;
336 SvtScriptType nScript
= pTableView
->GetSelectedScriptType();
337 sal_uInt16 nFontWhich
= ( nScript
== SvtScriptType::ASIAN
) ? EE_CHAR_FONTINFO_CJK
:
338 ( ( nScript
== SvtScriptType::COMPLEX
) ? EE_CHAR_FONTINFO_CTL
:
340 const SvxFontItem
& rItem
= static_cast<const SvxFontItem
&>(
341 pTableView
->GetAttribs().Get(nFontWhich
));
344 SvxFontItem
aNewItem( EE_CHAR_FONTINFO
);
346 const SfxItemSet
*pArgs
= rReq
.GetArgs();
347 const SfxPoolItem
* pItem
= 0;
349 pArgs
->GetItemState(GetPool().GetWhich(SID_CHARMAP
), false, &pItem
);
353 aString
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
354 const SfxPoolItem
* pFtItem
= NULL
;
355 pArgs
->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR
), false, &pFtItem
);
356 const SfxStringItem
* pFontItem
= PTR_CAST( SfxStringItem
, pFtItem
);
359 OUString
aFontName(pFontItem
->GetValue());
360 vcl::Font
aFont(aFontName
, Size(1,1)); // Size nur wg. CTOR
361 aNewItem
= SvxFontItem( aFont
.GetFamily(), aFont
.GetName(),
362 aFont
.GetStyleName(), aFont
.GetPitch(),
363 aFont
.GetCharSet(), ATTR_FONT
);
370 ScViewUtil::ExecuteCharMap( rItem
, *pViewData
->GetViewShell()->GetViewFrame(), aNewItem
, aString
);
372 // while the dialog was open, edit mode may have been stopped
373 if (!SC_MOD()->IsInputMode())
377 if ( !aString
.isEmpty() )
379 // if string contains WEAK characters, set all fonts
380 SvtScriptType nSetScript
;
381 ScDocument
* pDoc
= pViewData
->GetDocument();
382 if ( pDoc
->HasStringWeakCharacters( aString
) )
383 nSetScript
= SvtScriptType::LATIN
| SvtScriptType::ASIAN
| SvtScriptType::COMPLEX
;
385 nSetScript
= pDoc
->GetStringScriptType( aString
);
387 SfxItemSet
aSet( pTableView
->GetEmptyItemSet() );
388 SvxScriptSetItem
aSetItem( SID_ATTR_CHAR_FONT
, GetPool() );
389 aSetItem
.PutItemForScriptType( nSetScript
, aNewItem
);
390 aSet
.Put( aSetItem
.GetItemSet(), false );
392 // SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
393 pTableView
->GetEditEngine()->QuickSetAttribs( aSet
, pTableView
->GetSelection() );
394 pTableView
->InsertText(aString
);
396 pTopView
->InsertText(aString
);
398 SfxStringItem
aStringItem( SID_CHARMAP
, aString
);
399 SfxStringItem
aFontItem( SID_ATTR_SPECIALCHAR
, aNewItem
.GetFamilyName() );
400 rReq
.AppendItem( aFontItem
);
401 rReq
.AppendItem( aStringItem
);
407 pTopView
->GetWindow()->GrabFocus();
411 case FID_INSERT_NAME
:
413 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
414 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
416 boost::scoped_ptr
<AbstractScNamePasteDlg
> pDlg(pFact
->CreateScNamePasteDlg( pViewData
->GetDialogParent(), pViewData
->GetDocShell(), false ));
417 OSL_ENSURE(pDlg
, "Dialog create fail!");
418 short nRet
= pDlg
->Execute();
419 // pDlg is needed below
421 // while the dialog was open, edit mode may have been stopped
422 if (!SC_MOD()->IsInputMode())
425 if ( nRet
== BTN_PASTE_NAME
)
427 std::vector
<OUString
> aNames
= pDlg
->GetSelectedNames();
430 OUStringBuffer aBuffer
;
431 for (std::vector
<OUString
>::const_iterator itr
= aNames
.begin();
432 itr
!= aNames
.end(); ++itr
)
434 aBuffer
.append(*itr
).append(' ');
436 pTableView
->InsertText(aBuffer
.toString());
438 pTopView
->InsertText(aBuffer
.makeStringAndClear());
444 pTopView
->GetWindow()->GrabFocus();
448 case SID_CHAR_DLG_EFFECT
:
451 SfxItemSet
aAttrs( pTableView
->GetAttribs() );
453 SfxObjectShell
* pObjSh
= pViewData
->GetSfxDocShell();
455 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
456 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
458 boost::scoped_ptr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateScCharDlg(
459 pViewData
->GetDialogParent(), &aAttrs
, pObjSh
));
460 OSL_ENSURE(pDlg
, "Dialog create fail!");
461 if (nSlot
== SID_CHAR_DLG_EFFECT
)
463 pDlg
->SetCurPageId("fonteffects");
465 short nRet
= pDlg
->Execute();
466 // pDlg is needed below
468 // while the dialog was open, edit mode may have been stopped
469 if (!SC_MOD()->IsInputMode())
472 if ( nRet
== RET_OK
)
474 const SfxItemSet
* pOut
= pDlg
->GetOutputItemSet();
475 pTableView
->SetAttribs( *pOut
);
482 if (pEngine
->GetParagraphCount() == 1)
484 OUString aText
= pEngine
->GetText();
485 ESelection aSel
= pEditView
->GetSelection(); // aktuelle View
487 ScDocument
* pDoc
= pViewData
->GetDocument();
488 ScRefFinder
aFinder(aText
, pViewData
->GetCurPos(), pDoc
, pDoc
->GetAddressConvention());
489 aFinder
.ToggleRel( aSel
.nStartPos
, aSel
.nEndPos
);
490 if (aFinder
.GetFound())
492 OUString aNew
= aFinder
.GetText();
493 ESelection
aNewSel( 0,aFinder
.GetSelStart(), 0,aFinder
.GetSelEnd() );
494 pEngine
->SetText( aNew
);
495 pTableView
->SetSelection( aNewSel
);
498 pTopView
->GetEditEngine()->SetText( aNew
);
499 pTopView
->SetSelection( aNewSel
);
502 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben
509 case SID_HYPERLINK_SETLINK
:
512 const SfxPoolItem
* pItem
;
513 if ( pReqArgs
->GetItemState( SID_HYPERLINK_SETLINK
, true, &pItem
) == SfxItemState::SET
)
515 const SvxHyperlinkItem
* pHyper
= static_cast<const SvxHyperlinkItem
*>(pItem
);
516 const OUString
& rName
= pHyper
->GetName();
517 const OUString
& rURL
= pHyper
->GetURL();
518 const OUString
& rTarget
= pHyper
->GetTargetFrame();
519 SvxLinkInsertMode eMode
= pHyper
->GetInsertMode();
522 if ( eMode
== HLINK_DEFAULT
|| eMode
== HLINK_FIELD
)
524 const SvxURLField
* pURLField
= GetURLField();
527 // altes Feld selektieren
529 ESelection aSel
= pTableView
->GetSelection();
531 aSel
.nEndPara
= aSel
.nStartPara
;
532 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
533 pTableView
->SetSelection( aSel
);
535 // neues Feld einfuegen
537 SvxURLField
aURLField( rURL
, rName
, SVXURLFORMAT_REPR
);
538 aURLField
.SetTargetFrame( rTarget
);
539 SvxFieldItem
aURLItem( aURLField
, EE_FEATURE_FIELD
);
540 pTableView
->InsertField( aURLItem
);
541 pTableView
->SetSelection( aSel
); // select inserted field
543 // jetzt doch auch Felder in der Top-View
547 aSel
= pTopView
->GetSelection();
548 aSel
.nEndPara
= aSel
.nStartPara
;
549 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
550 pTopView
->SetSelection( aSel
);
551 pTopView
->InsertField( aURLItem
);
552 pTopView
->SetSelection( aSel
); // select inserted field
561 pViewData
->GetViewShell()->
562 InsertURL( rName
, rURL
, rTarget
, (sal_uInt16
) eMode
);
564 // InsertURL an der ViewShell schaltet bei "Button"
565 // die EditShell ab, darum sofort return
573 case SID_OPEN_HYPERLINK
:
575 const SvxURLField
* pURLField
= GetURLField();
577 ScGlobal::OpenURL( pURLField
->GetURL(), pURLField
->GetTargetFrame() );
581 case FN_INSERT_SOFT_HYPHEN
:
582 lclInsertCharacter( pTableView
, pTopView
, CHAR_SHY
);
584 case FN_INSERT_HARDHYPHEN
:
585 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBHY
);
587 case FN_INSERT_HARD_SPACE
:
588 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBSP
);
591 lclInsertCharacter( pTableView
, pTopView
, CHAR_RLM
);
594 lclInsertCharacter( pTableView
, pTopView
, CHAR_LRM
);
596 case SID_INSERT_ZWSP
:
597 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWSP
);
599 case SID_INSERT_ZWNBSP
:
600 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWNBSP
);
602 case SID_INSERT_FIELD_SHEET
:
604 SvxTableField
aField(pViewData
->GetTabNo());
605 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
606 pTableView
->InsertField(aItem
);
609 case SID_INSERT_FIELD_TITLE
:
612 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
613 pTableView
->InsertField(aItem
);
616 case SID_INSERT_FIELD_DATE_VAR
:
619 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
620 pTableView
->InsertField(aItem
);
625 pHdl
->DataChanged(false, bSetModified
);
627 pHdl
->SetSelIsRef(true);
630 static void lcl_DisableAll( SfxItemSet
& rSet
) // disable all slots
632 SfxWhichIter
aIter( rSet
);
633 sal_uInt16 nWhich
= aIter
.FirstWhich();
636 rSet
.DisableItem( nWhich
);
637 nWhich
= aIter
.NextWhich();
641 void ScEditShell::GetState( SfxItemSet
& rSet
)
643 // When deactivating the view, edit mode is stopped, but the EditShell is left active
644 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
645 // into the EditEngine, so it can have an invalid selection and must not be used.
646 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) )
648 lcl_DisableAll( rSet
);
652 ScInputHandler
* pHdl
= GetMyInputHdl();
653 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
655 SfxWhichIter
aIter( rSet
);
656 sal_uInt16 nWhich
= aIter
.FirstWhich();
661 case SID_ATTR_INSERT
: // Statuszeile
664 rSet
.Put( SfxBoolItem( nWhich
, pActiveView
->IsInsertMode() ) );
667 // Here the code used to pass the value 42 and it used
668 // to "work" without warnings because the SfxBoolItem
669 // was based on 'sal_Bool', which is actually 'unsigned
670 // char'. But now it uses actual 'bool', and passing 42
671 // for a 'bool' parameter causes a warning at least with
672 // MSVC. So use 'true'. I really really hope there is
673 // not code somewhere that retrieves this "boolean" item
674 // and checks it value for the magic value 42...
675 rSet
.Put( SfxBoolItem( nWhich
, true) );
680 case SID_HYPERLINK_GETLINK
:
682 SvxHyperlinkItem aHLinkItem
;
683 const SvxURLField
* pURLField
= GetURLField();
686 aHLinkItem
.SetName( pURLField
->GetRepresentation() );
687 aHLinkItem
.SetURL( pURLField
->GetURL() );
688 aHLinkItem
.SetTargetFrame( pURLField
->GetTargetFrame() );
690 else if ( pActiveView
)
692 // use selected text as name for urls
693 OUString sReturn
= pActiveView
->GetSelected();
694 sReturn
= sReturn
.copy(0, std::min(sReturn
.getLength(), static_cast<sal_Int32
>(255)));
695 aHLinkItem
.SetName(comphelper::string::stripEnd(sReturn
, ' '));
697 rSet
.Put(aHLinkItem
);
701 case SID_OPEN_HYPERLINK
:
703 if ( !GetURLField() )
704 rSet
.DisableItem( nWhich
);
708 case SID_TRANSLITERATE_HALFWIDTH
:
709 case SID_TRANSLITERATE_FULLWIDTH
:
710 case SID_TRANSLITERATE_HIRAGANA
:
711 case SID_TRANSLITERATE_KATAGANA
:
714 case SID_INSERT_ZWNBSP
:
715 case SID_INSERT_ZWSP
:
716 ScViewUtil::HideDisabledSlot( rSet
, pViewData
->GetBindings(), nWhich
);
722 LanguageType nLang
= LANGUAGE_NONE
;
723 bool bIsLookUpWord
= pActiveView
&&
724 GetStatusValueForThesaurusFromContext(aStatusVal
, nLang
, *pActiveView
);
725 rSet
.Put( SfxStringItem( SID_THES
, aStatusVal
) );
727 // disable thesaurus context menu entry if there is nothing to look up
728 bool bCanDoThesaurus
= ScModule::HasThesaurusLanguage( nLang
);
729 if (!bIsLookUpWord
|| !bCanDoThesaurus
)
730 rSet
.DisableItem( SID_THES
);
733 case SID_INSERT_FIELD_SHEET
:
734 case SID_INSERT_FIELD_TITLE
:
735 case SID_INSERT_FIELD_DATE_VAR
:
739 nWhich
= aIter
.NextWhich();
743 const SvxURLField
* ScEditShell::GetURLField()
745 ScInputHandler
* pHdl
= GetMyInputHdl();
746 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
749 const SvxFieldItem
* pFieldItem
= pActiveView
->GetFieldAtSelection();
752 const SvxFieldData
* pField
= pFieldItem
->GetField();
753 if ( pField
&& pField
->ISA(SvxURLField
) )
754 return static_cast<const SvxURLField
*>(pField
);
761 IMPL_LINK( ScEditShell
, ClipboardChanged
, TransferableDataHelper
*, pDataHelper
)
765 bPastePossible
= ( pDataHelper
->HasFormat( SotClipboardFormatId::STRING
) || pDataHelper
->HasFormat( SotClipboardFormatId::RTF
) );
767 SfxBindings
& rBindings
= pViewData
->GetBindings();
768 rBindings
.Invalidate( SID_PASTE
);
769 rBindings
.Invalidate( SID_PASTE_SPECIAL
);
770 rBindings
.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS
);
775 void ScEditShell::GetClipState( SfxItemSet
& rSet
)
777 if ( !pClipEvtLstnr
)
780 pClipEvtLstnr
= new TransferableClipboardListener( LINK( this, ScEditShell
, ClipboardChanged
) );
781 pClipEvtLstnr
->acquire();
782 vcl::Window
* pWin
= pViewData
->GetActiveWin();
783 pClipEvtLstnr
->AddRemoveListener( pWin
, true );
786 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
787 bPastePossible
= ( aDataHelper
.HasFormat( SotClipboardFormatId::STRING
) || aDataHelper
.HasFormat( SotClipboardFormatId::RTF
) );
790 SfxWhichIter
aIter( rSet
);
791 sal_uInt16 nWhich
= aIter
.FirstWhich();
797 case SID_PASTE_SPECIAL
:
798 if( !bPastePossible
)
799 rSet
.DisableItem( nWhich
);
801 case SID_CLIPBOARD_FORMAT_ITEMS
:
804 SvxClipboardFormatItem
aFormats( SID_CLIPBOARD_FORMAT_ITEMS
);
805 TransferableDataHelper
aDataHelper(
806 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
808 if ( aDataHelper
.HasFormat( SotClipboardFormatId::STRING
) )
809 aFormats
.AddClipbrdFormat( SotClipboardFormatId::STRING
);
810 if ( aDataHelper
.HasFormat( SotClipboardFormatId::RTF
) )
811 aFormats
.AddClipbrdFormat( SotClipboardFormatId::RTF
);
813 rSet
.Put( aFormats
);
816 rSet
.DisableItem( nWhich
);
819 nWhich
= aIter
.NextWhich();
823 static void lcl_InvalidateUnder( SfxBindings
& rBindings
)
825 rBindings
.Invalidate( SID_ATTR_CHAR_UNDERLINE
);
826 rBindings
.Invalidate( SID_ULINE_VAL_NONE
);
827 rBindings
.Invalidate( SID_ULINE_VAL_SINGLE
);
828 rBindings
.Invalidate( SID_ULINE_VAL_DOUBLE
);
829 rBindings
.Invalidate( SID_ULINE_VAL_DOTTED
);
832 void ScEditShell::ExecuteAttr(SfxRequest
& rReq
)
834 SfxItemSet
aSet( pEditView
->GetEmptyItemSet() );
835 SfxBindings
& rBindings
= pViewData
->GetBindings();
836 const SfxItemSet
* pArgs
= rReq
.GetArgs();
837 sal_uInt16 nSlot
= rReq
.GetSlot();
841 case SID_ATTR_CHAR_FONTHEIGHT
:
842 case SID_ATTR_CHAR_FONT
:
846 // #i78017 establish the same behaviour as in Writer
847 SvtScriptType nScript
= SvtScriptType::LATIN
| SvtScriptType::ASIAN
| SvtScriptType::COMPLEX
;
848 if (nSlot
== SID_ATTR_CHAR_FONT
)
850 nScript
= pEditView
->GetSelectedScriptType();
851 if (nScript
== SvtScriptType::NONE
) nScript
= ScGlobal::GetDefaultScriptType();
854 SfxItemPool
& rPool
= GetPool();
855 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
856 sal_uInt16 nWhich
= rPool
.GetWhich( nSlot
);
857 aSetItem
.PutItemForScriptType( nScript
, pArgs
->Get( nWhich
) );
859 aSet
.Put( aSetItem
.GetItemSet(), false );
864 case SID_ATTR_CHAR_COLOR
:
868 aSet
.Put( pArgs
->Get( pArgs
->GetPool()->GetWhich( nSlot
) ) );
869 rBindings
.Invalidate( nSlot
);
876 case SID_ATTR_CHAR_WEIGHT
:
878 // #i78017 establish the same behaviour as in Writer
879 SvtScriptType nScript
= SvtScriptType::LATIN
| SvtScriptType::ASIAN
| SvtScriptType::COMPLEX
;
881 SfxItemPool
& rPool
= GetPool();
884 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
885 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), false );
886 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
887 if ( pCore
&& static_cast<const SvxWeightItem
*>(pCore
)->GetWeight() > WEIGHT_NORMAL
)
890 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
891 aSetItem
.PutItemForScriptType( nScript
,
892 SvxWeightItem( bOld
? WEIGHT_NORMAL
: WEIGHT_BOLD
, EE_CHAR_WEIGHT
) );
893 aSet
.Put( aSetItem
.GetItemSet(), false );
895 rBindings
.Invalidate( nSlot
);
899 case SID_ATTR_CHAR_POSTURE
:
901 // #i78017 establish the same behaviour as in Writer
902 SvtScriptType nScript
= SvtScriptType::LATIN
| SvtScriptType::ASIAN
| SvtScriptType::COMPLEX
;
904 SfxItemPool
& rPool
= GetPool();
907 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
908 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), false );
909 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
910 if ( pCore
&& static_cast<const SvxPostureItem
*>(pCore
)->GetValue() != ITALIC_NONE
)
913 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
914 aSetItem
.PutItemForScriptType( nScript
,
915 SvxPostureItem( bOld
? ITALIC_NONE
: ITALIC_NORMAL
, EE_CHAR_ITALIC
) );
916 aSet
.Put( aSetItem
.GetItemSet(), false );
918 rBindings
.Invalidate( nSlot
);
922 case SID_ULINE_VAL_NONE
:
923 aSet
.Put( SvxUnderlineItem( UNDERLINE_NONE
, EE_CHAR_UNDERLINE
) );
924 lcl_InvalidateUnder( rBindings
);
927 case SID_ATTR_CHAR_UNDERLINE
:
928 case SID_ULINE_VAL_SINGLE
:
929 case SID_ULINE_VAL_DOUBLE
:
930 case SID_ULINE_VAL_DOTTED
:
932 FontUnderline eOld
= static_cast<const SvxUnderlineItem
&>( pEditView
->
933 GetAttribs().Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
934 FontUnderline eNew
= eOld
;
937 case SID_ATTR_CHAR_UNDERLINE
:
940 const SvxTextLineItem
& rTextLineItem
= static_cast< const SvxTextLineItem
& >( pArgs
->Get( pArgs
->GetPool()->GetWhich(nSlot
) ) );
941 eNew
= rTextLineItem
.GetLineStyle();
945 eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
948 case SID_ULINE_VAL_SINGLE
:
949 eNew
= ( eOld
== UNDERLINE_SINGLE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
951 case SID_ULINE_VAL_DOUBLE
:
952 eNew
= ( eOld
== UNDERLINE_DOUBLE
) ? UNDERLINE_NONE
: UNDERLINE_DOUBLE
;
954 case SID_ULINE_VAL_DOTTED
:
955 eNew
= ( eOld
== UNDERLINE_DOTTED
) ? UNDERLINE_NONE
: UNDERLINE_DOTTED
;
958 aSet
.Put( SvxUnderlineItem( eNew
, EE_CHAR_UNDERLINE
) );
959 lcl_InvalidateUnder( rBindings
);
963 case SID_ATTR_CHAR_OVERLINE
:
965 FontUnderline eOld
= static_cast<const SvxOverlineItem
&>( pEditView
->
966 GetAttribs().Get(EE_CHAR_OVERLINE
)).GetLineStyle();
967 FontUnderline eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
968 aSet
.Put( SvxOverlineItem( eNew
, EE_CHAR_OVERLINE
) );
969 rBindings
.Invalidate( nSlot
);
973 case SID_ATTR_CHAR_STRIKEOUT
:
975 bool bOld
= static_cast<const SvxCrossedOutItem
&>( pEditView
->GetAttribs().
976 Get(EE_CHAR_STRIKEOUT
)).GetValue() != STRIKEOUT_NONE
;
977 aSet
.Put( SvxCrossedOutItem( bOld
? STRIKEOUT_NONE
: STRIKEOUT_SINGLE
, EE_CHAR_STRIKEOUT
) );
978 rBindings
.Invalidate( nSlot
);
982 case SID_ATTR_CHAR_SHADOWED
:
984 bool bOld
= static_cast<const SvxShadowedItem
&>(pEditView
->GetAttribs().
985 Get(EE_CHAR_SHADOW
)).GetValue();
986 aSet
.Put( SvxShadowedItem( !bOld
, EE_CHAR_SHADOW
) );
987 rBindings
.Invalidate( nSlot
);
991 case SID_ATTR_CHAR_CONTOUR
:
993 bool bOld
= static_cast<const SvxContourItem
&>(pEditView
->GetAttribs().
994 Get(EE_CHAR_OUTLINE
)).GetValue();
995 aSet
.Put( SvxContourItem( !bOld
, EE_CHAR_OUTLINE
) );
996 rBindings
.Invalidate( nSlot
);
1000 case SID_SET_SUPER_SCRIPT
:
1002 SvxEscapement eOld
= (SvxEscapement
) static_cast<const SvxEscapementItem
&>(
1003 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
1004 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUPERSCRIPT
) ?
1005 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUPERSCRIPT
;
1006 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
1007 rBindings
.Invalidate( nSlot
);
1010 case SID_SET_SUB_SCRIPT
:
1012 SvxEscapement eOld
= (SvxEscapement
) static_cast<const SvxEscapementItem
&>(
1013 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
1014 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUBSCRIPT
) ?
1015 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUBSCRIPT
;
1016 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
1017 rBindings
.Invalidate( nSlot
);
1020 case SID_ATTR_CHAR_KERNING
:
1024 aSet
.Put ( pArgs
->Get(pArgs
->GetPool()->GetWhich(nSlot
)));
1025 rBindings
.Invalidate( nSlot
);
1033 EditEngine
* pEngine
= pEditView
->GetEditEngine();
1034 bool bOld
= pEngine
->GetUpdateMode();
1035 pEngine
->SetUpdateMode(false);
1037 pEditView
->SetAttribs( aSet
);
1039 pEngine
->SetUpdateMode(bOld
);
1040 pEditView
->Invalidate();
1042 ScInputHandler
* pHdl
= GetMyInputHdl();
1043 pHdl
->SetModified();
1048 void ScEditShell::GetAttrState(SfxItemSet
&rSet
)
1050 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
1052 lcl_DisableAll( rSet
);
1056 SfxItemSet aAttribs
= pEditView
->GetAttribs();
1057 rSet
.Put( aAttribs
);
1059 // choose font info according to selection script type
1061 SvtScriptType nScript
= pEditView
->GetSelectedScriptType();
1062 if (nScript
== SvtScriptType::NONE
) nScript
= ScGlobal::GetDefaultScriptType();
1064 // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1065 SvtScriptType nInputScript
= nScript
;
1066 if ( !pEditView
->GetSelection().HasRange() )
1068 LanguageType nInputLang
= pViewData
->GetActiveWin()->GetInputLanguage();
1069 if (nInputLang
!= LANGUAGE_DONTKNOW
&& nInputLang
!= LANGUAGE_SYSTEM
)
1070 nInputScript
= SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang
);
1073 // #i55929# according to spec, nInputScript is used for font and font height only
1074 if ( rSet
.GetItemState( EE_CHAR_FONTINFO
) != SfxItemState::UNKNOWN
)
1075 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTINFO
, nInputScript
);
1076 if ( rSet
.GetItemState( EE_CHAR_FONTHEIGHT
) != SfxItemState::UNKNOWN
)
1077 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTHEIGHT
, nInputScript
);
1078 if ( rSet
.GetItemState( EE_CHAR_WEIGHT
) != SfxItemState::UNKNOWN
)
1079 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_WEIGHT
, nScript
);
1080 if ( rSet
.GetItemState( EE_CHAR_ITALIC
) != SfxItemState::UNKNOWN
)
1081 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_ITALIC
, nScript
);
1085 SfxItemState eState
= aAttribs
.GetItemState( EE_CHAR_UNDERLINE
, true );
1086 if ( eState
== SfxItemState::DONTCARE
)
1088 rSet
.InvalidateItem( SID_ULINE_VAL_NONE
);
1089 rSet
.InvalidateItem( SID_ULINE_VAL_SINGLE
);
1090 rSet
.InvalidateItem( SID_ULINE_VAL_DOUBLE
);
1091 rSet
.InvalidateItem( SID_ULINE_VAL_DOTTED
);
1095 FontUnderline eUnderline
= static_cast<const SvxUnderlineItem
&>(
1096 aAttribs
.Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
1097 sal_uInt16 nId
= SID_ULINE_VAL_NONE
;
1100 case UNDERLINE_SINGLE
: nId
= SID_ULINE_VAL_SINGLE
; break;
1101 case UNDERLINE_DOUBLE
: nId
= SID_ULINE_VAL_DOUBLE
; break;
1102 case UNDERLINE_DOTTED
: nId
= SID_ULINE_VAL_DOTTED
; break;
1106 rSet
.Put( SfxBoolItem( nId
, true ) );
1109 //! Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1110 ScInputHandler
* pHdl
= GetMyInputHdl();
1111 if ( pHdl
&& pHdl
->IsFormulaMode() )
1112 rSet
.ClearItem( EE_CHAR_WEIGHT
); // hervorgehobene Klammern hier nicht
1114 SvxEscapement eEsc
= (SvxEscapement
) static_cast<const SvxEscapementItem
&>(
1115 aAttribs
.Get( EE_CHAR_ESCAPEMENT
) ).GetEnumValue();
1116 if( eEsc
== SVX_ESCAPEMENT_SUPERSCRIPT
)
1118 rSet
.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT
, true ) );
1120 else if( eEsc
== SVX_ESCAPEMENT_SUBSCRIPT
)
1122 rSet
.Put( SfxBoolItem( SID_SET_SUB_SCRIPT
, true ) );
1124 pViewData
->GetBindings().Invalidate( SID_SET_SUPER_SCRIPT
);
1125 pViewData
->GetBindings().Invalidate( SID_SET_SUB_SCRIPT
);
1127 eState
= aAttribs
.GetItemState( EE_CHAR_KERNING
, true );
1128 pViewData
->GetBindings().Invalidate( SID_ATTR_CHAR_KERNING
);
1129 if ( eState
== SfxItemState::DONTCARE
)
1131 // rSet.InvalidateItem( SID_ATTR_CHAR_KERNING );
1132 rSet
.InvalidateItem(EE_CHAR_KERNING
);
1136 OUString
ScEditShell::GetSelectionText( bool bWholeWord
)
1138 OUString aStrSelection
;
1140 if ( pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
1144 EditEngine
* pEngine
= pEditView
->GetEditEngine();
1145 ESelection aSel
= pEditView
->GetSelection();
1146 OUString aStrCurrentDelimiters
= pEngine
->GetWordDelimiters();
1148 pEngine
->SetWordDelimiters(" .,;\"'");
1149 aStrSelection
= pEngine
->GetWord( aSel
.nEndPara
, aSel
.nEndPos
);
1150 pEngine
->SetWordDelimiters( aStrCurrentDelimiters
);
1154 aStrSelection
= pEditView
->GetSelected();
1158 return aStrSelection
;
1161 void ScEditShell::ExecuteUndo(SfxRequest
& rReq
)
1163 // Undo must be handled here because it's called for both EditViews
1165 ScInputHandler
* pHdl
= GetMyInputHdl();
1166 OSL_ENSURE(pHdl
,"no ScInputHandler");
1167 EditView
* pTopView
= pHdl
->GetTopView();
1168 EditView
* pTableView
= pHdl
->GetTableView();
1169 OSL_ENSURE(pTableView
,"no EditView");
1171 pHdl
->DataChanging();
1173 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
1174 sal_uInt16 nSlot
= rReq
.GetSlot();
1180 bool bIsUndo
= ( nSlot
== SID_UNDO
);
1182 sal_uInt16 nCount
= 1;
1183 const SfxPoolItem
* pItem
;
1184 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlot
, true, &pItem
) == SfxItemState::SET
)
1185 nCount
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
1187 for (sal_uInt16 i
=0; i
<nCount
; i
++)
1205 pViewData
->GetBindings().InvalidateAll(false);
1207 pHdl
->DataChanged();
1210 void ScEditShell::GetUndoState(SfxItemSet
&rSet
)
1212 // Undo state is taken from normal ViewFrame state function
1214 SfxViewFrame
* pViewFrm
= pViewData
->GetViewShell()->GetViewFrame();
1215 if ( pViewFrm
&& GetUndoManager() )
1217 SfxWhichIter
aIter(rSet
);
1218 sal_uInt16 nWhich
= aIter
.FirstWhich();
1221 pViewFrm
->GetSlotState( nWhich
, NULL
, &rSet
);
1222 nWhich
= aIter
.NextWhich();
1226 // disable if no action in input line EditView
1228 ScInputHandler
* pHdl
= GetMyInputHdl();
1229 OSL_ENSURE(pHdl
,"no ScInputHandler");
1230 EditView
* pTopView
= pHdl
->GetTopView();
1233 ::svl::IUndoManager
& rTopMgr
= pTopView
->GetEditEngine()->GetUndoManager();
1234 if ( rTopMgr
.GetUndoActionCount() == 0 )
1235 rSet
.DisableItem( SID_UNDO
);
1236 if ( rTopMgr
.GetRedoActionCount() == 0 )
1237 rSet
.DisableItem( SID_REDO
);
1241 void ScEditShell::ExecuteTrans( SfxRequest
& rReq
)
1243 sal_Int32 nType
= ScViewUtil::GetTransliterationType( rReq
.GetSlot() );
1246 ScInputHandler
* pHdl
= GetMyInputHdl();
1247 assert(pHdl
&& "no ScInputHandler");
1249 EditView
* pTopView
= pHdl
->GetTopView();
1250 EditView
* pTableView
= pHdl
->GetTableView();
1251 assert(pTableView
&& "no EditView");
1253 pHdl
->DataChanging();
1255 pTableView
->TransliterateText( nType
);
1257 pTopView
->TransliterateText( nType
);
1259 pHdl
->DataChanged();
1263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */