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/cntritem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <editeng/unolingu.hxx>
30 #include <editeng/crsditem.hxx>
31 #include <editeng/editeng.hxx>
32 #include <editeng/editview.hxx>
33 #include <editeng/escpitem.hxx>
34 #include <editeng/flditem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include <svx/hlnkitem.hxx>
37 #include <editeng/postitem.hxx>
38 #include <editeng/scripttypeitem.hxx>
39 #include <editeng/shdditem.hxx>
40 #include <svl/srchitem.hxx>
41 #include <editeng/udlnitem.hxx>
42 #include <editeng/wghtitem.hxx>
43 #include <sfx2/basedlgs.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/msg.hxx>
46 #include <sfx2/objface.hxx>
47 #include <sfx2/objsh.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <sot/exchange.hxx>
51 #include <svtools/cliplistener.hxx>
52 #include <svl/whiter.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <sot/formats.hxx>
55 #include <svtools/transfer.hxx>
56 #include <svl/stritem.hxx>
59 #include "scresid.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"
73 #include "scslots.hxx"
75 #include "scui_def.hxx"
76 #include "scabstdlg.hxx"
78 using namespace ::com::sun::star
;
81 TYPEINIT1( ScEditShell
, SfxShell
);
83 SFX_IMPL_INTERFACE(ScEditShell
, SfxShell
, ScResId(SCSTR_EDITSHELL
))
85 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_EDIT
) );
89 ScEditShell::ScEditShell(EditView
* pView
, ScViewData
* pData
) :
93 bPastePossible (false),
94 bIsInsertMode (sal_True
)
96 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
97 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
98 SetName(rtl::OUString("EditCell"));
101 ScEditShell::~ScEditShell()
105 pClipEvtLstnr
->AddRemoveListener( pViewData
->GetActiveWin(), false );
107 // The listener may just now be waiting for the SolarMutex and call the link
108 // afterwards, in spite of RemoveListener. So the link has to be reset, too.
109 pClipEvtLstnr
->ClearCallbackLink();
111 pClipEvtLstnr
->release();
115 ScInputHandler
* ScEditShell::GetMyInputHdl()
117 return SC_MOD()->GetInputHdl( pViewData
->GetViewShell() );
120 void ScEditShell::SetEditView(EditView
* pView
)
123 pEditView
->SetInsertMode( bIsInsertMode
);
124 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
125 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
128 static void lcl_RemoveAttribs( EditView
& rEditView
)
130 ScEditEngineDefaulter
* pEngine
= static_cast<ScEditEngineDefaulter
*>(rEditView
.GetEditEngine());
132 sal_Bool bOld
= pEngine
->GetUpdateMode();
133 pEngine
->SetUpdateMode(false);
135 String aName
= ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS
);
136 pEngine
->GetUndoManager().EnterListAction( aName
, aName
);
138 rEditView
.RemoveAttribs(true);
139 pEngine
->RepeatDefaults(); // paragraph attributes from cell formats must be preserved
141 pEngine
->GetUndoManager().LeaveListAction();
143 pEngine
->SetUpdateMode(bOld
);
146 void lclInsertCharacter( EditView
* pTableView
, EditView
* pTopView
, sal_Unicode cChar
)
148 rtl::OUString
aString( cChar
);
150 pTableView
->InsertText( aString
);
152 pTopView
->InsertText( aString
);
155 void ScEditShell::Execute( SfxRequest
& rReq
)
157 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
158 sal_uInt16 nSlot
= rReq
.GetSlot();
159 SfxBindings
& rBindings
= pViewData
->GetBindings();
161 ScInputHandler
* pHdl
= GetMyInputHdl();
162 OSL_ENSURE(pHdl
,"kein ScInputHandler");
164 EditView
* pTopView
= pHdl
->GetTopView(); // hat Eingabezeile den Focus?
165 EditView
* pTableView
= pHdl
->GetTableView();
167 OSL_ENSURE(pTableView
,"no EditView :-(");
168 /* #i91683# No EditView if spell-check dialog is active and positioned on
169 * an error and user immediately (without double click or F2) selected a
170 * text portion of that cell with the mouse and wanted to modify it. */
171 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
172 * action is possible. A real fix somehow would need to create a valid
173 * EditView from the spell-check view. */
177 EditEngine
* pEngine
= pTableView
->GetEditEngine();
179 pHdl
->DataChanging();
180 sal_Bool bSetSelIsRef
= false;
181 bool bSetModified
= true;
185 case FID_INS_CELL_CONTENTS
: // Insert-Taste, weil als Acc definiert
186 bIsInsertMode
= !pTableView
->IsInsertMode();
187 pTableView
->SetInsertMode( bIsInsertMode
);
189 pTopView
->SetInsertMode( bIsInsertMode
);
190 rBindings
.Invalidate( SID_ATTR_INSERT
);
193 case SID_ATTR_INSERT
:
196 bIsInsertMode
= ((const SfxBoolItem
&)pReqArgs
->Get(nSlot
)).GetValue();
197 pTableView
->SetInsertMode( bIsInsertMode
);
199 pTopView
->SetInsertMode( bIsInsertMode
);
200 rBindings
.Invalidate( SID_ATTR_INSERT
);
207 SFX_REQUEST_ARG( rReq
, pItem2
, SfxStringItem
, SID_THES
, false );
209 aReplaceText
= pItem2
->GetValue();
210 if (aReplaceText
.Len() > 0)
211 ReplaceTextWithSynonym( *pEditView
, aReplaceText
);
217 bSetModified
= false;
223 pTopView
->DeleteSelected();
227 pTableView
->PasteSpecial();
233 pTableView
->DeleteSelected();
235 pTopView
->DeleteSelected();
238 case SID_CELL_FORMAT_RESET
: // "Standard"
239 lcl_RemoveAttribs( *pTableView
);
241 lcl_RemoveAttribs( *pTopView
);
244 case SID_CLIPBOARD_FORMAT_ITEMS
:
246 sal_uLong nFormat
= 0;
247 const SfxPoolItem
* pItem
;
249 pReqArgs
->GetItemState(nSlot
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
250 pItem
->ISA(SfxUInt32Item
) )
252 nFormat
= ((const SfxUInt32Item
*)pItem
)->GetValue();
257 if (SOT_FORMAT_STRING
== nFormat
)
260 pTableView
->PasteSpecial();
268 case SID_PASTE_SPECIAL
:
270 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
271 SfxAbstractPasteDialog
* pDlg
= pFact
->CreatePasteDialog( pViewData
->GetDialogParent() );
272 sal_uLong nFormat
= 0;
275 pDlg
->Insert( SOT_FORMAT_STRING
, EMPTY_STRING
);
276 pDlg
->Insert( SOT_FORMAT_RTF
, EMPTY_STRING
);
278 TransferableDataHelper
aDataHelper(
279 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
281 nFormat
= pDlg
->GetFormat( aDataHelper
.GetTransferable() );
285 // while the dialog was open, edit mode may have been stopped
286 if (!SC_MOD()->IsInputMode())
291 if (SOT_FORMAT_STRING
== nFormat
)
294 pTableView
->PasteSpecial();
301 pTopView
->GetWindow()->GrabFocus();
307 sal_uInt16 nPar
= pEngine
->GetParagraphCount();
310 xub_StrLen nLen
= pEngine
->GetTextLen(nPar
-1);
311 pTableView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
313 pTopView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
315 bSetModified
= sal_False
;
321 sal_uInt16 nScript
= pTableView
->GetSelectedScriptType();
322 sal_uInt16 nFontWhich
= ( nScript
== SCRIPTTYPE_ASIAN
) ? EE_CHAR_FONTINFO_CJK
:
323 ( ( nScript
== SCRIPTTYPE_COMPLEX
) ? EE_CHAR_FONTINFO_CTL
:
325 const SvxFontItem
& rItem
= (const SvxFontItem
&)
326 pTableView
->GetAttribs().Get(nFontWhich
);
329 SvxFontItem
aNewItem( EE_CHAR_FONTINFO
);
331 const SfxItemSet
*pArgs
= rReq
.GetArgs();
332 const SfxPoolItem
* pItem
= 0;
334 pArgs
->GetItemState(GetPool().GetWhich(SID_CHARMAP
), false, &pItem
);
338 aString
= ((const SfxStringItem
*)pItem
)->GetValue();
339 const SfxPoolItem
* pFtItem
= NULL
;
340 pArgs
->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR
), false, &pFtItem
);
341 const SfxStringItem
* pFontItem
= PTR_CAST( SfxStringItem
, pFtItem
);
344 String
aFontName(pFontItem
->GetValue());
345 Font
aFont(aFontName
, Size(1,1)); // Size nur wg. CTOR
346 aNewItem
= SvxFontItem( aFont
.GetFamily(), aFont
.GetName(),
347 aFont
.GetStyleName(), aFont
.GetPitch(),
348 aFont
.GetCharSet(), ATTR_FONT
);
355 ScViewUtil::ExecuteCharMap( rItem
, *pViewData
->GetViewShell()->GetViewFrame(), aNewItem
, aString
);
357 // while the dialog was open, edit mode may have been stopped
358 if (!SC_MOD()->IsInputMode())
364 // if string contains WEAK characters, set all fonts
365 sal_uInt8 nSetScript
;
366 ScDocument
* pDoc
= pViewData
->GetDocument();
367 if ( pDoc
->HasStringWeakCharacters( aString
) )
368 nSetScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
370 nSetScript
= pDoc
->GetStringScriptType( aString
);
372 SfxItemSet
aSet( pTableView
->GetEmptyItemSet() );
373 SvxScriptSetItem
aSetItem( SID_ATTR_CHAR_FONT
, GetPool() );
374 aSetItem
.PutItemForScriptType( nSetScript
, aNewItem
);
375 aSet
.Put( aSetItem
.GetItemSet(), false );
377 // SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
378 pTableView
->GetEditEngine()->QuickSetAttribs( aSet
, pTableView
->GetSelection() );
379 pTableView
->InsertText(aString
);
381 pTopView
->InsertText(aString
);
383 SfxStringItem
aStringItem( SID_CHARMAP
, aString
);
384 SfxStringItem
aFontItem( SID_ATTR_SPECIALCHAR
, aNewItem
.GetFamilyName() );
385 rReq
.AppendItem( aFontItem
);
386 rReq
.AppendItem( aStringItem
);
393 pTopView
->GetWindow()->GrabFocus();
397 case FID_INSERT_NAME
:
399 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
400 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
402 AbstractScNamePasteDlg
* pDlg
= pFact
->CreateScNamePasteDlg( pViewData
->GetDialogParent(), pViewData
->GetDocShell(), RID_SCDLG_NAMES_PASTE
, false );
403 OSL_ENSURE(pDlg
, "Dialog create fail!");
404 short nRet
= pDlg
->Execute();
405 // pDlg is needed below
407 // while the dialog was open, edit mode may have been stopped
408 if (!SC_MOD()->IsInputMode())
414 if ( nRet
== BTN_PASTE_NAME
)
416 std::vector
<rtl::OUString
> aNames
= pDlg
->GetSelectedNames();
419 rtl::OUStringBuffer aBuffer
;
420 for (std::vector
<rtl::OUString
>::const_iterator itr
= aNames
.begin();
421 itr
!= aNames
.end(); ++itr
)
423 aBuffer
.append(*itr
).append(' ');
425 pTableView
->InsertText(aBuffer
.toString());
427 pTopView
->InsertText(aBuffer
.makeStringAndClear());
433 pTopView
->GetWindow()->GrabFocus();
439 SfxItemSet
aAttrs( pTableView
->GetAttribs() );
441 SfxObjectShell
* pObjSh
= pViewData
->GetSfxDocShell();
443 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
444 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
446 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScCharDlg( pViewData
->GetDialogParent(), &aAttrs
,
447 pObjSh
, RID_SCDLG_CHAR
);
448 OSL_ENSURE(pDlg
, "Dialog create fail!");
449 short nRet
= pDlg
->Execute();
450 // pDlg is needed below
452 // while the dialog was open, edit mode may have been stopped
453 if (!SC_MOD()->IsInputMode())
459 if ( nRet
== RET_OK
)
461 const SfxItemSet
* pOut
= pDlg
->GetOutputItemSet();
462 pTableView
->SetAttribs( *pOut
);
470 if (pEngine
->GetParagraphCount() == 1)
472 String aText
= pEngine
->GetText();
473 ESelection aSel
= pEditView
->GetSelection(); // aktuelle View
475 ScDocument
* pDoc
= pViewData
->GetDocument();
476 ScRefFinder
aFinder(aText
, pViewData
->GetCurPos(), pDoc
, pDoc
->GetAddressConvention());
477 aFinder
.ToggleRel( aSel
.nStartPos
, aSel
.nEndPos
);
478 if (aFinder
.GetFound())
480 String aNew
= aFinder
.GetText();
481 ESelection
aNewSel( 0,aFinder
.GetSelStart(), 0,aFinder
.GetSelEnd() );
482 pEngine
->SetText( aNew
);
483 pTableView
->SetSelection( aNewSel
);
486 pTopView
->GetEditEngine()->SetText( aNew
);
487 pTopView
->SetSelection( aNewSel
);
490 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben
491 bSetSelIsRef
= sal_True
;
497 case SID_HYPERLINK_SETLINK
:
500 const SfxPoolItem
* pItem
;
501 if ( pReqArgs
->GetItemState( SID_HYPERLINK_SETLINK
, sal_True
, &pItem
) == SFX_ITEM_SET
)
503 const SvxHyperlinkItem
* pHyper
= (const SvxHyperlinkItem
*) pItem
;
504 const String
& rName
= pHyper
->GetName();
505 const String
& rURL
= pHyper
->GetURL();
506 const String
& rTarget
= pHyper
->GetTargetFrame();
507 SvxLinkInsertMode eMode
= pHyper
->GetInsertMode();
509 sal_Bool bDone
= false;
510 if ( eMode
== HLINK_DEFAULT
|| eMode
== HLINK_FIELD
)
512 const SvxURLField
* pURLField
= GetURLField();
515 // altes Feld selektieren
517 ESelection aSel
= pTableView
->GetSelection();
519 aSel
.nEndPara
= aSel
.nStartPara
;
520 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
521 pTableView
->SetSelection( aSel
);
523 // neues Feld einfuegen
525 SvxURLField
aURLField( rURL
, rName
, SVXURLFORMAT_REPR
);
526 aURLField
.SetTargetFrame( rTarget
);
527 SvxFieldItem
aURLItem( aURLField
, EE_FEATURE_FIELD
);
528 pTableView
->InsertField( aURLItem
);
529 pTableView
->SetSelection( aSel
); // select inserted field
531 // jetzt doch auch Felder in der Top-View
535 aSel
= pTopView
->GetSelection();
536 aSel
.nEndPara
= aSel
.nStartPara
;
537 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
538 pTopView
->SetSelection( aSel
);
539 pTopView
->InsertField( aURLItem
);
540 pTopView
->SetSelection( aSel
); // select inserted field
549 pViewData
->GetViewShell()->
550 InsertURL( rName
, rURL
, rTarget
, (sal_uInt16
) eMode
);
552 // InsertURL an der ViewShell schaltet bei "Button"
553 // die EditShell ab, darum sofort return
561 case SID_OPEN_HYPERLINK
:
563 const SvxURLField
* pURLField
= GetURLField();
565 ScGlobal::OpenURL( pURLField
->GetURL(), pURLField
->GetTargetFrame() );
570 case FN_INSERT_SOFT_HYPHEN
:
571 lclInsertCharacter( pTableView
, pTopView
, CHAR_SHY
);
573 case FN_INSERT_HARDHYPHEN
:
574 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBHY
);
576 case FN_INSERT_HARD_SPACE
:
577 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBSP
);
580 lclInsertCharacter( pTableView
, pTopView
, CHAR_RLM
);
583 lclInsertCharacter( pTableView
, pTopView
, CHAR_LRM
);
585 case SID_INSERT_ZWSP
:
586 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWSP
);
588 case SID_INSERT_ZWNBSP
:
589 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWNBSP
);
591 case SID_INSERT_FIELD_SHEET
:
593 SvxTableField
aField(pViewData
->GetTabNo());
594 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
595 pTableView
->InsertField(aItem
);
598 case SID_INSERT_FIELD_TITLE
:
601 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
602 pTableView
->InsertField(aItem
);
605 case SID_INSERT_FIELD_DATE_VAR
:
608 SvxFieldItem
aItem(aField
, EE_FEATURE_FIELD
);
609 pTableView
->InsertField(aItem
);
614 pHdl
->DataChanged(sal_False
, bSetModified
);
616 pHdl
->SetSelIsRef(sal_True
);
619 static void lcl_DisableAll( SfxItemSet
& rSet
) // disable all slots
621 SfxWhichIter
aIter( rSet
);
622 sal_uInt16 nWhich
= aIter
.FirstWhich();
625 rSet
.DisableItem( nWhich
);
626 nWhich
= aIter
.NextWhich();
630 void ScEditShell::GetState( SfxItemSet
& rSet
)
632 // When deactivating the view, edit mode is stopped, but the EditShell is left active
633 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
634 // into the EditEngine, so it can have an invalid selection and must not be used.
635 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) )
637 lcl_DisableAll( rSet
);
641 ScInputHandler
* pHdl
= GetMyInputHdl();
642 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
644 SfxWhichIter
aIter( rSet
);
645 sal_uInt16 nWhich
= aIter
.FirstWhich();
650 case SID_ATTR_INSERT
: // Statuszeile
653 rSet
.Put( SfxBoolItem( nWhich
, pActiveView
->IsInsertMode() ) );
655 rSet
.Put( SfxBoolItem( nWhich
, 42 ) );
659 case SID_HYPERLINK_GETLINK
:
661 SvxHyperlinkItem aHLinkItem
;
662 const SvxURLField
* pURLField
= GetURLField();
665 aHLinkItem
.SetName( pURLField
->GetRepresentation() );
666 aHLinkItem
.SetURL( pURLField
->GetURL() );
667 aHLinkItem
.SetTargetFrame( pURLField
->GetTargetFrame() );
669 else if ( pActiveView
)
671 // use selected text as name for urls
672 String sReturn
= pActiveView
->GetSelected();
674 aHLinkItem
.SetName(comphelper::string::stripEnd(sReturn
, ' '));
676 rSet
.Put(aHLinkItem
);
680 case SID_OPEN_HYPERLINK
:
682 if ( !GetURLField() )
683 rSet
.DisableItem( nWhich
);
687 case SID_TRANSLITERATE_HALFWIDTH
:
688 case SID_TRANSLITERATE_FULLWIDTH
:
689 case SID_TRANSLITERATE_HIRAGANA
:
690 case SID_TRANSLITERATE_KATAGANA
:
693 case SID_INSERT_ZWNBSP
:
694 case SID_INSERT_ZWSP
:
695 ScViewUtil::HideDisabledSlot( rSet
, pViewData
->GetBindings(), nWhich
);
701 LanguageType nLang
= LANGUAGE_NONE
;
702 bool bIsLookUpWord
= GetStatusValueForThesaurusFromContext( aStatusVal
, nLang
, *pActiveView
);
703 rSet
.Put( SfxStringItem( SID_THES
, aStatusVal
) );
705 // disable thesaurus context menu entry if there is nothing to look up
706 sal_Bool bCanDoThesaurus
= ScModule::HasThesaurusLanguage( nLang
);
707 if (!bIsLookUpWord
|| !bCanDoThesaurus
)
708 rSet
.DisableItem( SID_THES
);
711 case SID_INSERT_FIELD_SHEET
:
712 case SID_INSERT_FIELD_TITLE
:
713 case SID_INSERT_FIELD_DATE_VAR
:
717 nWhich
= aIter
.NextWhich();
721 const SvxURLField
* ScEditShell::GetURLField()
723 ScInputHandler
* pHdl
= GetMyInputHdl();
724 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
727 const SvxFieldItem
* pFieldItem
= pActiveView
->GetFieldAtSelection();
730 const SvxFieldData
* pField
= pFieldItem
->GetField();
731 if ( pField
&& pField
->ISA(SvxURLField
) )
732 return (const SvxURLField
*)pField
;
739 IMPL_LINK( ScEditShell
, ClipboardChanged
, TransferableDataHelper
*, pDataHelper
)
743 bPastePossible
= ( pDataHelper
->HasFormat( SOT_FORMAT_STRING
) || pDataHelper
->HasFormat( SOT_FORMAT_RTF
) );
745 SfxBindings
& rBindings
= pViewData
->GetBindings();
746 rBindings
.Invalidate( SID_PASTE
);
747 rBindings
.Invalidate( SID_PASTE_SPECIAL
);
748 rBindings
.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS
);
753 void ScEditShell::GetClipState( SfxItemSet
& rSet
)
755 if ( !pClipEvtLstnr
)
758 pClipEvtLstnr
= new TransferableClipboardListener( LINK( this, ScEditShell
, ClipboardChanged
) );
759 pClipEvtLstnr
->acquire();
760 Window
* pWin
= pViewData
->GetActiveWin();
761 pClipEvtLstnr
->AddRemoveListener( pWin
, sal_True
);
764 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
765 bPastePossible
= ( aDataHelper
.HasFormat( SOT_FORMAT_STRING
) || aDataHelper
.HasFormat( SOT_FORMAT_RTF
) );
768 SfxWhichIter
aIter( rSet
);
769 sal_uInt16 nWhich
= aIter
.FirstWhich();
775 case SID_PASTE_SPECIAL
:
776 if( !bPastePossible
)
777 rSet
.DisableItem( nWhich
);
779 case SID_CLIPBOARD_FORMAT_ITEMS
:
782 SvxClipboardFmtItem
aFormats( SID_CLIPBOARD_FORMAT_ITEMS
);
783 TransferableDataHelper
aDataHelper(
784 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
786 if ( aDataHelper
.HasFormat( SOT_FORMAT_STRING
) )
787 aFormats
.AddClipbrdFormat( SOT_FORMAT_STRING
);
788 if ( aDataHelper
.HasFormat( SOT_FORMAT_RTF
) )
789 aFormats
.AddClipbrdFormat( SOT_FORMAT_RTF
);
791 rSet
.Put( aFormats
);
794 rSet
.DisableItem( nWhich
);
797 nWhich
= aIter
.NextWhich();
801 static void lcl_InvalidateUnder( SfxBindings
& rBindings
)
803 rBindings
.Invalidate( SID_ATTR_CHAR_UNDERLINE
);
804 rBindings
.Invalidate( SID_ULINE_VAL_NONE
);
805 rBindings
.Invalidate( SID_ULINE_VAL_SINGLE
);
806 rBindings
.Invalidate( SID_ULINE_VAL_DOUBLE
);
807 rBindings
.Invalidate( SID_ULINE_VAL_DOTTED
);
810 void ScEditShell::ExecuteAttr(SfxRequest
& rReq
)
812 SfxItemSet
aSet( pEditView
->GetEmptyItemSet() );
813 SfxBindings
& rBindings
= pViewData
->GetBindings();
814 const SfxItemSet
* pArgs
= rReq
.GetArgs();
815 sal_uInt16 nSlot
= rReq
.GetSlot();
819 case SID_ATTR_CHAR_FONTHEIGHT
:
820 case SID_ATTR_CHAR_FONT
:
824 // #i78017 establish the same behaviour as in Writer
825 sal_uInt16 nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
826 if (nSlot
== SID_ATTR_CHAR_FONT
)
828 nScript
= pEditView
->GetSelectedScriptType();
829 if (nScript
== 0) nScript
= ScGlobal::GetDefaultScriptType();
832 SfxItemPool
& rPool
= GetPool();
833 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
834 sal_uInt16 nWhich
= rPool
.GetWhich( nSlot
);
835 aSetItem
.PutItemForScriptType( nScript
, pArgs
->Get( nWhich
) );
837 aSet
.Put( aSetItem
.GetItemSet(), false );
842 case SID_ATTR_CHAR_COLOR
:
846 aSet
.Put( pArgs
->Get( pArgs
->GetPool()->GetWhich( nSlot
) ) );
847 rBindings
.Invalidate( nSlot
);
854 case SID_ATTR_CHAR_WEIGHT
:
856 // #i78017 establish the same behaviour as in Writer
857 sal_uInt16 nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
859 SfxItemPool
& rPool
= GetPool();
861 sal_Bool bOld
= false;
862 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
863 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), false );
864 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
865 if ( pCore
&& ((const SvxWeightItem
*)pCore
)->GetWeight() > WEIGHT_NORMAL
)
868 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
869 aSetItem
.PutItemForScriptType( nScript
,
870 SvxWeightItem( bOld
? WEIGHT_NORMAL
: WEIGHT_BOLD
, EE_CHAR_WEIGHT
) );
871 aSet
.Put( aSetItem
.GetItemSet(), false );
873 rBindings
.Invalidate( nSlot
);
877 case SID_ATTR_CHAR_POSTURE
:
879 // #i78017 establish the same behaviour as in Writer
880 sal_uInt16 nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
882 SfxItemPool
& rPool
= GetPool();
884 sal_Bool bOld
= false;
885 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
886 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), false );
887 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
888 if ( pCore
&& ((const SvxPostureItem
*)pCore
)->GetValue() != ITALIC_NONE
)
891 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
892 aSetItem
.PutItemForScriptType( nScript
,
893 SvxPostureItem( bOld
? ITALIC_NONE
: ITALIC_NORMAL
, EE_CHAR_ITALIC
) );
894 aSet
.Put( aSetItem
.GetItemSet(), false );
896 rBindings
.Invalidate( nSlot
);
900 case SID_ULINE_VAL_NONE
:
901 aSet
.Put( SvxUnderlineItem( UNDERLINE_NONE
, EE_CHAR_UNDERLINE
) );
902 lcl_InvalidateUnder( rBindings
);
905 case SID_ATTR_CHAR_UNDERLINE
: // Toggles
906 case SID_ULINE_VAL_SINGLE
:
907 case SID_ULINE_VAL_DOUBLE
:
908 case SID_ULINE_VAL_DOTTED
:
910 FontUnderline eOld
= ((const SvxUnderlineItem
&) pEditView
->
911 GetAttribs().Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
912 FontUnderline eNew
= eOld
;
915 case SID_ATTR_CHAR_UNDERLINE
:
916 eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
918 case SID_ULINE_VAL_SINGLE
:
919 eNew
= ( eOld
== UNDERLINE_SINGLE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
921 case SID_ULINE_VAL_DOUBLE
:
922 eNew
= ( eOld
== UNDERLINE_DOUBLE
) ? UNDERLINE_NONE
: UNDERLINE_DOUBLE
;
924 case SID_ULINE_VAL_DOTTED
:
925 eNew
= ( eOld
== UNDERLINE_DOTTED
) ? UNDERLINE_NONE
: UNDERLINE_DOTTED
;
928 aSet
.Put( SvxUnderlineItem( eNew
, EE_CHAR_UNDERLINE
) );
929 lcl_InvalidateUnder( rBindings
);
933 case SID_ATTR_CHAR_OVERLINE
:
935 FontUnderline eOld
= ((const SvxOverlineItem
&) pEditView
->
936 GetAttribs().Get(EE_CHAR_OVERLINE
)).GetLineStyle();
937 FontUnderline eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
938 aSet
.Put( SvxOverlineItem( eNew
, EE_CHAR_OVERLINE
) );
939 rBindings
.Invalidate( nSlot
);
943 case SID_ATTR_CHAR_STRIKEOUT
:
945 sal_Bool bOld
= ((const SvxCrossedOutItem
&)pEditView
->GetAttribs().
946 Get(EE_CHAR_STRIKEOUT
)).GetValue() != STRIKEOUT_NONE
;
947 aSet
.Put( SvxCrossedOutItem( bOld
? STRIKEOUT_NONE
: STRIKEOUT_SINGLE
, EE_CHAR_STRIKEOUT
) );
948 rBindings
.Invalidate( nSlot
);
952 case SID_ATTR_CHAR_SHADOWED
:
954 sal_Bool bOld
= ((const SvxShadowedItem
&)pEditView
->GetAttribs().
955 Get(EE_CHAR_SHADOW
)).GetValue();
956 aSet
.Put( SvxShadowedItem( !bOld
, EE_CHAR_SHADOW
) );
957 rBindings
.Invalidate( nSlot
);
961 case SID_ATTR_CHAR_CONTOUR
:
963 sal_Bool bOld
= ((const SvxContourItem
&)pEditView
->GetAttribs().
964 Get(EE_CHAR_OUTLINE
)).GetValue();
965 aSet
.Put( SvxContourItem( !bOld
, EE_CHAR_OUTLINE
) );
966 rBindings
.Invalidate( nSlot
);
970 case SID_SET_SUPER_SCRIPT
:
972 SvxEscapement eOld
= (SvxEscapement
) ((const SvxEscapementItem
&)
973 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
974 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUPERSCRIPT
) ?
975 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUPERSCRIPT
;
976 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
977 rBindings
.Invalidate( nSlot
);
980 case SID_SET_SUB_SCRIPT
:
982 SvxEscapement eOld
= (SvxEscapement
) ((const SvxEscapementItem
&)
983 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
984 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUBSCRIPT
) ?
985 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUBSCRIPT
;
986 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
987 rBindings
.Invalidate( nSlot
);
996 EditEngine
* pEngine
= pEditView
->GetEditEngine();
997 sal_Bool bOld
= pEngine
->GetUpdateMode();
998 pEngine
->SetUpdateMode(false);
1000 pEditView
->SetAttribs( aSet
);
1002 pEngine
->SetUpdateMode(bOld
);
1003 pEditView
->Invalidate();
1005 ScInputHandler
* pHdl
= GetMyInputHdl();
1006 pHdl
->SetModified();
1011 void ScEditShell::GetAttrState(SfxItemSet
&rSet
)
1013 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
1015 lcl_DisableAll( rSet
);
1019 SfxItemSet aAttribs
= pEditView
->GetAttribs();
1020 rSet
.Put( aAttribs
);
1022 // choose font info according to selection script type
1024 sal_uInt16 nScript
= pEditView
->GetSelectedScriptType();
1025 if (nScript
== 0) nScript
= ScGlobal::GetDefaultScriptType();
1027 // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1028 sal_uInt16 nInputScript
= nScript
;
1029 if ( !pEditView
->GetSelection().HasRange() )
1031 LanguageType nInputLang
= pViewData
->GetActiveWin()->GetInputLanguage();
1032 if (nInputLang
!= LANGUAGE_DONTKNOW
&& nInputLang
!= LANGUAGE_SYSTEM
)
1033 nInputScript
= SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang
);
1036 // #i55929# according to spec, nInputScript is used for font and font height only
1037 if ( rSet
.GetItemState( EE_CHAR_FONTINFO
) != SFX_ITEM_UNKNOWN
)
1038 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTINFO
, nInputScript
);
1039 if ( rSet
.GetItemState( EE_CHAR_FONTHEIGHT
) != SFX_ITEM_UNKNOWN
)
1040 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTHEIGHT
, nInputScript
);
1041 if ( rSet
.GetItemState( EE_CHAR_WEIGHT
) != SFX_ITEM_UNKNOWN
)
1042 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_WEIGHT
, nScript
);
1043 if ( rSet
.GetItemState( EE_CHAR_ITALIC
) != SFX_ITEM_UNKNOWN
)
1044 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_ITALIC
, nScript
);
1048 SfxItemState eState
= aAttribs
.GetItemState( EE_CHAR_UNDERLINE
, sal_True
);
1049 if ( eState
== SFX_ITEM_DONTCARE
)
1051 rSet
.InvalidateItem( SID_ULINE_VAL_NONE
);
1052 rSet
.InvalidateItem( SID_ULINE_VAL_SINGLE
);
1053 rSet
.InvalidateItem( SID_ULINE_VAL_DOUBLE
);
1054 rSet
.InvalidateItem( SID_ULINE_VAL_DOTTED
);
1058 FontUnderline eUnderline
= ((const SvxUnderlineItem
&)
1059 aAttribs
.Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
1060 sal_uInt16 nId
= SID_ULINE_VAL_NONE
;
1063 case UNDERLINE_SINGLE
: nId
= SID_ULINE_VAL_SINGLE
; break;
1064 case UNDERLINE_DOUBLE
: nId
= SID_ULINE_VAL_DOUBLE
; break;
1065 case UNDERLINE_DOTTED
: nId
= SID_ULINE_VAL_DOTTED
; break;
1069 rSet
.Put( SfxBoolItem( nId
, sal_True
) );
1072 //! Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1073 ScInputHandler
* pHdl
= GetMyInputHdl();
1074 if ( pHdl
&& pHdl
->IsFormulaMode() )
1075 rSet
.ClearItem( EE_CHAR_WEIGHT
); // hervorgehobene Klammern hier nicht
1078 String
ScEditShell::GetSelectionText( sal_Bool bWholeWord
)
1080 String aStrSelection
;
1082 if ( pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
1086 EditEngine
* pEngine
= pEditView
->GetEditEngine();
1087 ESelection aSel
= pEditView
->GetSelection();
1088 String aStrCurrentDelimiters
= pEngine
->GetWordDelimiters();
1090 pEngine
->SetWordDelimiters(rtl::OUString(" .,;\"'"));
1091 aStrSelection
= pEngine
->GetWord( aSel
.nEndPara
, aSel
.nEndPos
);
1092 pEngine
->SetWordDelimiters( aStrCurrentDelimiters
);
1096 aStrSelection
= pEditView
->GetSelected();
1100 return aStrSelection
;
1103 void ScEditShell::ExecuteUndo(SfxRequest
& rReq
)
1105 // Undo must be handled here because it's called for both EditViews
1107 ScInputHandler
* pHdl
= GetMyInputHdl();
1108 OSL_ENSURE(pHdl
,"no ScInputHandler");
1109 EditView
* pTopView
= pHdl
->GetTopView();
1110 EditView
* pTableView
= pHdl
->GetTableView();
1111 OSL_ENSURE(pTableView
,"no EditView");
1113 pHdl
->DataChanging();
1115 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
1116 sal_uInt16 nSlot
= rReq
.GetSlot();
1122 sal_Bool bIsUndo
= ( nSlot
== SID_UNDO
);
1124 sal_uInt16 nCount
= 1;
1125 const SfxPoolItem
* pItem
;
1126 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlot
, sal_True
, &pItem
) == SFX_ITEM_SET
)
1127 nCount
= ((const SfxUInt16Item
*)pItem
)->GetValue();
1129 for (sal_uInt16 i
=0; i
<nCount
; i
++)
1147 pViewData
->GetBindings().InvalidateAll(false);
1149 pHdl
->DataChanged();
1152 void ScEditShell::GetUndoState(SfxItemSet
&rSet
)
1154 // Undo state is taken from normal ViewFrame state function
1156 SfxViewFrame
* pViewFrm
= pViewData
->GetViewShell()->GetViewFrame();
1157 if ( pViewFrm
&& GetUndoManager() )
1159 SfxWhichIter
aIter(rSet
);
1160 sal_uInt16 nWhich
= aIter
.FirstWhich();
1163 pViewFrm
->GetSlotState( nWhich
, NULL
, &rSet
);
1164 nWhich
= aIter
.NextWhich();
1168 // disable if no action in input line EditView
1170 ScInputHandler
* pHdl
= GetMyInputHdl();
1171 OSL_ENSURE(pHdl
,"no ScInputHandler");
1172 EditView
* pTopView
= pHdl
->GetTopView();
1175 ::svl::IUndoManager
& rTopMgr
= pTopView
->GetEditEngine()->GetUndoManager();
1176 if ( rTopMgr
.GetUndoActionCount() == 0 )
1177 rSet
.DisableItem( SID_UNDO
);
1178 if ( rTopMgr
.GetRedoActionCount() == 0 )
1179 rSet
.DisableItem( SID_REDO
);
1183 void ScEditShell::ExecuteTrans( SfxRequest
& rReq
)
1185 sal_Int32 nType
= ScViewUtil::GetTransliterationType( rReq
.GetSlot() );
1188 ScInputHandler
* pHdl
= GetMyInputHdl();
1189 OSL_ENSURE( pHdl
, "no ScInputHandler" );
1191 EditView
* pTopView
= pHdl
->GetTopView();
1192 EditView
* pTableView
= pHdl
->GetTableView();
1193 OSL_ENSURE( pTableView
, "no EditView" );
1195 pHdl
->DataChanging();
1197 pTableView
->TransliterateText( nType
);
1199 pTopView
->TransliterateText( nType
);
1201 pHdl
->DataChanged();
1205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */