1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editsh.cxx,v $
10 * $Revision: 1.35.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
41 #include <svx/clipfmtitem.hxx>
42 #include <svx/svxdlg.hxx>
43 #include <svx/cntritem.hxx>
44 //CHINA001 #include <svx/chardlg.hxx>
45 #include <svx/crsditem.hxx>
46 #include <svx/editeng.hxx>
47 #include <svx/editview.hxx>
48 #include <svx/escpitem.hxx>
49 #include <svx/flditem.hxx>
50 #include <svx/fontitem.hxx>
51 #include <svx/hlnkitem.hxx>
52 #include <svx/postitem.hxx>
53 #include <svx/scripttypeitem.hxx>
54 #include <svx/shdditem.hxx>
55 #include <svx/srchitem.hxx>
56 #include <svx/udlnitem.hxx>
57 #include <svx/wghtitem.hxx>
58 #include <sfx2/basedlgs.hxx>
59 #include <sfx2/bindings.hxx>
60 #include <sfx2/msg.hxx>
61 #include <sfx2/objface.hxx>
62 #include <sfx2/objsh.hxx>
63 #include <sfx2/request.hxx>
64 #include <sfx2/viewfrm.hxx>
65 #include <sot/exchange.hxx>
66 #include <svtools/cliplistener.hxx>
67 #include <svtools/whiter.hxx>
68 #include <vcl/msgbox.hxx>
69 #include <vcl/sound.hxx>
70 #include <sot/formats.hxx>
71 #include <svtools/transfer.hxx>
72 #include <svtools/stritem.hxx>
77 #include "scresid.hxx"
81 #include "inputhdl.hxx"
82 #include "viewutil.hxx"
83 #include "viewdata.hxx"
84 #include "document.hxx"
85 //CHINA001 #include "namepast.hxx"
86 #include "reffind.hxx"
87 #include "tabvwsh.hxx"
88 //CHINA001 #include "textdlgs.hxx"
89 #include "editutil.hxx"
90 #include "globstr.hrc"
93 #include "scslots.hxx"
95 #include "scui_def.hxx" //CHINA001
96 #include "scabstdlg.hxx" //CHINA001
97 TYPEINIT1( ScEditShell
, SfxShell
);
99 SFX_IMPL_INTERFACE(ScEditShell
, SfxShell
, ScResId(SCSTR_EDITSHELL
))
101 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_EDIT
) );
105 ScEditShell::ScEditShell(EditView
* pView
, ScViewData
* pData
) :
108 pClipEvtLstnr (NULL
),
109 bPastePossible (FALSE
),
112 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
113 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
114 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("EditCell")));
117 ScEditShell::~ScEditShell()
121 pClipEvtLstnr
->AddRemoveListener( pViewData
->GetActiveWin(), FALSE
);
123 // #122057# The listener may just now be waiting for the SolarMutex and call the link
124 // afterwards, in spite of RemoveListener. So the link has to be reset, too.
125 pClipEvtLstnr
->ClearCallbackLink();
127 pClipEvtLstnr
->release();
131 ScInputHandler
* ScEditShell::GetMyInputHdl()
133 return SC_MOD()->GetInputHdl( pViewData
->GetViewShell() );
136 void ScEditShell::SetEditView(EditView
* pView
)
139 pEditView
->SetInsertMode( bIsInsertMode
);
140 SetPool( pEditView
->GetEditEngine()->GetEmptyItemSet().GetPool() );
141 SetUndoManager( &pEditView
->GetEditEngine()->GetUndoManager() );
144 void lcl_RemoveAttribs( EditView
& rEditView
)
146 ScEditEngineDefaulter
* pEngine
= static_cast<ScEditEngineDefaulter
*>(rEditView
.GetEditEngine());
148 BOOL bOld
= pEngine
->GetUpdateMode();
149 pEngine
->SetUpdateMode(FALSE
);
151 String aName
= ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS
);
152 pEngine
->GetUndoManager().EnterListAction( aName
, aName
);
154 rEditView
.RemoveAttribs(TRUE
);
155 pEngine
->RepeatDefaults(); // #97226# paragraph attributes from cell formats must be preserved
157 pEngine
->GetUndoManager().LeaveListAction();
159 pEngine
->SetUpdateMode(bOld
);
162 void lclInsertCharacter( EditView
* pTableView
, EditView
* pTopView
, sal_Unicode cChar
)
164 String
aString( cChar
);
166 pTableView
->InsertText( aString
);
168 pTopView
->InsertText( aString
);
171 void ScEditShell::Execute( SfxRequest
& rReq
)
173 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
174 USHORT nSlot
= rReq
.GetSlot();
175 SfxBindings
& rBindings
= pViewData
->GetBindings();
177 ScInputHandler
* pHdl
= GetMyInputHdl();
178 DBG_ASSERT(pHdl
,"kein ScInputHandler");
180 EditView
* pTopView
= pHdl
->GetTopView(); // hat Eingabezeile den Focus?
181 EditView
* pTableView
= pHdl
->GetTableView();
183 DBG_ASSERT(pTableView
,"no EditView :-(");
184 /* #i91683# No EditView if spell-check dialog is active and positioned on
185 * an error and user immediately (without double click or F2) selected a
186 * text portion of that cell with the mouse and wanted to modify it. */
187 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
188 * action is possible. A real fix somehow would need to create a valid
189 * EditView from the spell-check view. */
193 EditEngine
* pEngine
= pTableView
->GetEditEngine();
195 pHdl
->DataChanging();
196 BOOL bSetSelIsRef
= FALSE
;
200 case FID_INS_CELL_CONTENTS
: // Insert-Taste, weil als Acc definiert
201 bIsInsertMode
= !pTableView
->IsInsertMode();
202 pTableView
->SetInsertMode( bIsInsertMode
);
204 pTopView
->SetInsertMode( bIsInsertMode
);
205 rBindings
.Invalidate( SID_ATTR_INSERT
);
208 case SID_ATTR_INSERT
:
211 bIsInsertMode
= ((const SfxBoolItem
&)pReqArgs
->Get(nSlot
)).GetValue();
212 pTableView
->SetInsertMode( bIsInsertMode
);
214 pTopView
->SetInsertMode( bIsInsertMode
);
215 rBindings
.Invalidate( SID_ATTR_INSERT
);
226 pTopView
->DeleteSelected();
230 pTableView
->PasteSpecial();
236 pTableView
->DeleteSelected();
238 pTopView
->DeleteSelected();
241 case SID_CELL_FORMAT_RESET
: // "Standard"
242 lcl_RemoveAttribs( *pTableView
);
244 lcl_RemoveAttribs( *pTopView
);
247 case SID_CLIPBOARD_FORMAT_ITEMS
:
250 const SfxPoolItem
* pItem
;
252 pReqArgs
->GetItemState(nSlot
, TRUE
, &pItem
) == SFX_ITEM_SET
&&
253 pItem
->ISA(SfxUInt32Item
) )
255 nFormat
= ((const SfxUInt32Item
*)pItem
)->GetValue();
260 if (SOT_FORMAT_STRING
== nFormat
)
263 pTableView
->PasteSpecial();
271 case SID_PASTE_SPECIAL
:
273 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
274 SfxAbstractPasteDialog
* pDlg
= pFact
->CreatePasteDialog( pViewData
->GetDialogParent() );
278 pDlg
->Insert( SOT_FORMAT_STRING
, EMPTY_STRING
);
279 pDlg
->Insert( SOT_FORMAT_RTF
, EMPTY_STRING
);
281 TransferableDataHelper
aDataHelper(
282 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
284 nFormat
= pDlg
->GetFormat( aDataHelper
.GetTransferable() );
288 // while the dialog was open, edit mode may have been stopped
289 if (!SC_MOD()->IsInputMode())
297 if (SOT_FORMAT_STRING
== nFormat
)
300 pTableView
->PasteSpecial();
307 pTopView
->GetWindow()->GrabFocus();
313 USHORT nPar
= pEngine
->GetParagraphCount();
316 xub_StrLen nLen
= pEngine
->GetTextLen(nPar
-1);
317 pTableView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
319 pTopView
->SetSelection(ESelection(0,0,nPar
-1,nLen
));
326 USHORT nScript
= pTableView
->GetSelectedScriptType();
327 USHORT nFontWhich
= ( nScript
== SCRIPTTYPE_ASIAN
) ? EE_CHAR_FONTINFO_CJK
:
328 ( ( nScript
== SCRIPTTYPE_COMPLEX
) ? EE_CHAR_FONTINFO_CTL
:
330 const SvxFontItem
& rItem
= (const SvxFontItem
&)
331 pTableView
->GetAttribs().Get(nFontWhich
);
334 SvxFontItem
aNewItem( EE_CHAR_FONTINFO
);
336 const SfxItemSet
*pArgs
= rReq
.GetArgs();
337 const SfxPoolItem
* pItem
= 0;
339 pArgs
->GetItemState(GetPool().GetWhich(SID_CHARMAP
), FALSE
, &pItem
);
343 aString
= ((const SfxStringItem
*)pItem
)->GetValue();
344 const SfxPoolItem
* pFtItem
= NULL
;
345 pArgs
->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR
), FALSE
, &pFtItem
);
346 const SfxStringItem
* pFontItem
= PTR_CAST( SfxStringItem
, pFtItem
);
349 String
aFontName(pFontItem
->GetValue());
350 Font
aFont(aFontName
, Size(1,1)); // Size nur wg. CTOR
351 aNewItem
= SvxFontItem( aFont
.GetFamily(), aFont
.GetName(),
352 aFont
.GetStyleName(), aFont
.GetPitch(),
353 aFont
.GetCharSet(), ATTR_FONT
);
360 ScViewUtil::ExecuteCharMap( rItem
, *pViewData
->GetViewShell()->GetViewFrame(), aNewItem
, aString
);
362 // while the dialog was open, edit mode may have been stopped
363 if (!SC_MOD()->IsInputMode())
372 // if string contains WEAK characters, set all fonts
374 ScDocument
* pDoc
= pViewData
->GetDocument();
375 if ( pDoc
->HasStringWeakCharacters( aString
) )
376 nSetScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
378 nSetScript
= pDoc
->GetStringScriptType( aString
);
380 SfxItemSet
aSet( pTableView
->GetEmptyItemSet() );
381 SvxScriptSetItem
aSetItem( SID_ATTR_CHAR_FONT
, GetPool() );
382 aSetItem
.PutItemForScriptType( nSetScript
, aNewItem
);
383 aSet
.Put( aSetItem
.GetItemSet(), FALSE
);
385 // SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
386 pTableView
->GetEditEngine()->QuickSetAttribs( aSet
, pTableView
->GetSelection() );
387 pTableView
->InsertText(aString
);
389 pTopView
->InsertText(aString
);
391 SfxStringItem
aStringItem( SID_CHARMAP
, aString
);
392 SfxStringItem
aFontItem( SID_ATTR_SPECIALCHAR
, aNewItem
.GetFamilyName() );
393 rReq
.AppendItem( aFontItem
);
394 rReq
.AppendItem( aStringItem
);
401 pTopView
->GetWindow()->GrabFocus();
405 case FID_INSERT_NAME
:
407 ScDocument
* pDoc
= pViewData
->GetDocument();
408 //CHINA001 ScNamePasteDlg* pDlg = new ScNamePasteDlg( pViewData->GetDialogParent(),
409 //CHINA001 pDoc->GetRangeName(), FALSE );
411 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
412 DBG_ASSERT(pFact
, "ScAbstractFactory create fail!");//CHINA001
414 AbstractScNamePasteDlg
* pDlg
= pFact
->CreateScNamePasteDlg( pViewData
->GetDialogParent(), pDoc
->GetRangeName(), RID_SCDLG_NAMES_PASTE
, FALSE
);
415 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
416 short nRet
= pDlg
->Execute();
417 // pDlg is needed below
419 // while the dialog was open, edit mode may have been stopped
420 if (!SC_MOD()->IsInputMode())
427 if ( nRet
== BTN_PASTE_NAME
)
429 String aName
= pDlg
->GetSelectedName();
430 pTableView
->InsertText(aName
);
432 pTopView
->InsertText(aName
);
437 pTopView
->GetWindow()->GrabFocus();
443 SfxItemSet
aAttrs( pTableView
->GetAttribs() );
445 SfxObjectShell
* pObjSh
= pViewData
->GetSfxDocShell();
447 //CHINA001 ScCharDlg* pDlg = new ScCharDlg( pViewData->GetDialogParent(), &aAttrs, pObjSh );
448 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
449 DBG_ASSERT(pFact
, "ScAbstractFactory create fail!");//CHINA001
451 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScCharDlg( pViewData
->GetDialogParent(), &aAttrs
,
452 pObjSh
, RID_SCDLG_CHAR
);
453 DBG_ASSERT(pDlg
, "Dialog create fail!");//CHINA001
454 short nRet
= pDlg
->Execute();
455 // pDlg is needed below
457 // while the dialog was open, edit mode may have been stopped
458 if (!SC_MOD()->IsInputMode())
465 if ( nRet
== RET_OK
)
467 const SfxItemSet
* pOut
= pDlg
->GetOutputItemSet();
468 pTableView
->SetAttribs( *pOut
);
477 if (pEngine
->GetParagraphCount() == 1)
479 String aText
= pEngine
->GetText();
480 ESelection aSel
= pEditView
->GetSelection(); // aktuelle View
482 ScRefFinder
aFinder( aText
, pViewData
->GetDocument() );
483 aFinder
.ToggleRel( aSel
.nStartPos
, aSel
.nEndPos
);
484 if (aFinder
.GetFound())
486 String aNew
= aFinder
.GetText();
487 ESelection
aNewSel( 0,aFinder
.GetSelStart(), 0,aFinder
.GetSelEnd() );
488 pEngine
->SetText( aNew
);
489 pTableView
->SetSelection( aNewSel
);
492 pTopView
->GetEditEngine()->SetText( aNew
);
493 pTopView
->SetSelection( aNewSel
);
497 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben
502 Sound::Beep(); // keine Referenzen oder mehrere Absaetze
506 case SID_HYPERLINK_SETLINK
:
509 const SfxPoolItem
* pItem
;
510 if ( pReqArgs
->GetItemState( SID_HYPERLINK_SETLINK
, TRUE
, &pItem
) == SFX_ITEM_SET
)
512 const SvxHyperlinkItem
* pHyper
= (const SvxHyperlinkItem
*) pItem
;
513 const String
& rName
= pHyper
->GetName();
514 const String
& rURL
= pHyper
->GetURL();
515 const String
& rTarget
= pHyper
->GetTargetFrame();
516 SvxLinkInsertMode eMode
= pHyper
->GetInsertMode();
519 if ( eMode
== HLINK_DEFAULT
|| eMode
== HLINK_FIELD
)
521 const SvxURLField
* pURLField
= GetURLField();
524 // altes Feld selektieren
526 ESelection aSel
= pTableView
->GetSelection();
528 aSel
.nEndPara
= aSel
.nStartPara
;
529 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
530 pTableView
->SetSelection( aSel
);
532 // neues Feld einfuegen
534 SvxURLField
aURLField( rURL
, rName
, SVXURLFORMAT_REPR
);
535 aURLField
.SetTargetFrame( rTarget
);
536 SvxFieldItem
aURLItem( aURLField
, EE_FEATURE_FIELD
);
537 pTableView
->InsertField( aURLItem
);
538 pTableView
->SetSelection( aSel
); // select inserted field
540 // #57254# jetzt doch auch Felder in der Top-View
544 aSel
= pTopView
->GetSelection();
545 aSel
.nEndPara
= aSel
.nStartPara
;
546 aSel
.nEndPos
= aSel
.nStartPos
+ 1;
547 pTopView
->SetSelection( aSel
);
548 pTopView
->InsertField( aURLItem
);
549 pTopView
->SetSelection( aSel
); // select inserted field
558 pViewData
->GetViewShell()->
559 InsertURL( rName
, rURL
, rTarget
, (USHORT
) eMode
);
561 // InsertURL an der ViewShell schaltet bei "Button"
562 // die EditShell ab, darum sofort return
570 case SID_OPEN_HYPERLINK
:
572 const SvxURLField
* pURLField
= GetURLField();
574 ScGlobal::OpenURL( pURLField
->GetURL(), pURLField
->GetTargetFrame() );
579 case FN_INSERT_SOFT_HYPHEN
:
580 lclInsertCharacter( pTableView
, pTopView
, CHAR_SHY
);
582 case FN_INSERT_HARDHYPHEN
:
583 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBHY
);
585 case FN_INSERT_HARD_SPACE
:
586 lclInsertCharacter( pTableView
, pTopView
, CHAR_NBSP
);
589 lclInsertCharacter( pTableView
, pTopView
, CHAR_RLM
);
592 lclInsertCharacter( pTableView
, pTopView
, CHAR_LRM
);
594 case SID_INSERT_ZWSP
:
595 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWSP
);
597 case SID_INSERT_ZWNBSP
:
598 lclInsertCharacter( pTableView
, pTopView
, CHAR_ZWNBSP
);
604 pHdl
->SetSelIsRef(TRUE
);
607 void lcl_DisableAll( SfxItemSet
& rSet
) // disable all slots
609 SfxWhichIter
aIter( rSet
);
610 USHORT nWhich
= aIter
.FirstWhich();
613 rSet
.DisableItem( nWhich
);
614 nWhich
= aIter
.NextWhich();
618 void __EXPORT
ScEditShell::GetState( SfxItemSet
& rSet
)
620 // #125326# When deactivating the view, edit mode is stopped, but the EditShell is left active
621 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
622 // into the EditEngine, so it can have an invalid selection and must not be used.
623 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) )
625 lcl_DisableAll( rSet
);
629 ScInputHandler
* pHdl
= GetMyInputHdl();
630 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
632 SfxWhichIter
aIter( rSet
);
633 USHORT nWhich
= aIter
.FirstWhich();
638 case SID_ATTR_INSERT
: // Statuszeile
641 rSet
.Put( SfxBoolItem( nWhich
, pActiveView
->IsInsertMode() ) );
643 rSet
.Put( SfxBoolItem( nWhich
, 42 ) );
647 case SID_HYPERLINK_GETLINK
:
649 SvxHyperlinkItem aHLinkItem
;
650 const SvxURLField
* pURLField
= GetURLField();
653 aHLinkItem
.SetName( pURLField
->GetRepresentation() );
654 aHLinkItem
.SetURL( pURLField
->GetURL() );
655 aHLinkItem
.SetTargetFrame( pURLField
->GetTargetFrame() );
657 else if ( pActiveView
)
659 // use selected text as name for urls
660 String sReturn
= pActiveView
->GetSelected();
662 sReturn
.EraseTrailingChars();
663 aHLinkItem
.SetName(sReturn
);
665 rSet
.Put(aHLinkItem
);
669 case SID_OPEN_HYPERLINK
:
671 if ( !GetURLField() )
672 rSet
.DisableItem( nWhich
);
676 case SID_TRANSLITERATE_HALFWIDTH
:
677 case SID_TRANSLITERATE_FULLWIDTH
:
678 case SID_TRANSLITERATE_HIRAGANA
:
679 case SID_TRANSLITERATE_KATAGANA
:
682 case SID_INSERT_ZWNBSP
:
683 case SID_INSERT_ZWSP
:
684 ScViewUtil::HideDisabledSlot( rSet
, pViewData
->GetBindings(), nWhich
);
687 nWhich
= aIter
.NextWhich();
691 const SvxURLField
* ScEditShell::GetURLField()
693 ScInputHandler
* pHdl
= GetMyInputHdl();
694 EditView
* pActiveView
= pHdl
? pHdl
->GetActiveView() : pEditView
;
697 const SvxFieldItem
* pFieldItem
= pActiveView
->GetFieldAtSelection();
700 const SvxFieldData
* pField
= pFieldItem
->GetField();
701 if ( pField
&& pField
->ISA(SvxURLField
) )
702 return (const SvxURLField
*)pField
;
709 IMPL_LINK( ScEditShell
, ClipboardChanged
, TransferableDataHelper
*, pDataHelper
)
713 bPastePossible
= ( pDataHelper
->HasFormat( SOT_FORMAT_STRING
) || pDataHelper
->HasFormat( SOT_FORMAT_RTF
) );
715 SfxBindings
& rBindings
= pViewData
->GetBindings();
716 rBindings
.Invalidate( SID_PASTE
);
717 rBindings
.Invalidate( SID_PASTE_SPECIAL
);
718 rBindings
.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS
);
723 void __EXPORT
ScEditShell::GetClipState( SfxItemSet
& rSet
)
725 if ( !pClipEvtLstnr
)
728 pClipEvtLstnr
= new TransferableClipboardListener( LINK( this, ScEditShell
, ClipboardChanged
) );
729 pClipEvtLstnr
->acquire();
730 Window
* pWin
= pViewData
->GetActiveWin();
731 pClipEvtLstnr
->AddRemoveListener( pWin
, TRUE
);
734 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
735 bPastePossible
= ( aDataHelper
.HasFormat( SOT_FORMAT_STRING
) || aDataHelper
.HasFormat( SOT_FORMAT_RTF
) );
738 SfxWhichIter
aIter( rSet
);
739 USHORT nWhich
= aIter
.FirstWhich();
745 case SID_PASTE_SPECIAL
:
746 if( !bPastePossible
)
747 rSet
.DisableItem( nWhich
);
749 case SID_CLIPBOARD_FORMAT_ITEMS
:
752 SvxClipboardFmtItem
aFormats( SID_CLIPBOARD_FORMAT_ITEMS
);
753 TransferableDataHelper
aDataHelper(
754 TransferableDataHelper::CreateFromSystemClipboard( pViewData
->GetActiveWin() ) );
756 if ( aDataHelper
.HasFormat( SOT_FORMAT_STRING
) )
757 aFormats
.AddClipbrdFormat( SOT_FORMAT_STRING
);
758 if ( aDataHelper
.HasFormat( SOT_FORMAT_RTF
) )
759 aFormats
.AddClipbrdFormat( SOT_FORMAT_RTF
);
761 rSet
.Put( aFormats
);
764 rSet
.DisableItem( nWhich
);
767 nWhich
= aIter
.NextWhich();
771 void lcl_InvalidateUnder( SfxBindings
& rBindings
)
773 rBindings
.Invalidate( SID_ATTR_CHAR_UNDERLINE
);
774 rBindings
.Invalidate( SID_ULINE_VAL_NONE
);
775 rBindings
.Invalidate( SID_ULINE_VAL_SINGLE
);
776 rBindings
.Invalidate( SID_ULINE_VAL_DOUBLE
);
777 rBindings
.Invalidate( SID_ULINE_VAL_DOTTED
);
780 void ScEditShell::ExecuteAttr(SfxRequest
& rReq
)
782 SfxItemSet
aSet( pEditView
->GetEmptyItemSet() );
783 SfxBindings
& rBindings
= pViewData
->GetBindings();
784 const SfxItemSet
* pArgs
= rReq
.GetArgs();
785 USHORT nSlot
= rReq
.GetSlot();
789 case SID_ATTR_CHAR_FONTHEIGHT
:
790 case SID_ATTR_CHAR_FONT
:
794 // #i78017 establish the same behaviour as in Writer
795 USHORT nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
796 if (nSlot
== SID_ATTR_CHAR_FONT
)
798 nScript
= pEditView
->GetSelectedScriptType();
799 if (nScript
== 0) nScript
= ScGlobal::GetDefaultScriptType();
802 SfxItemPool
& rPool
= GetPool();
803 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
804 USHORT nWhich
= rPool
.GetWhich( nSlot
);
805 aSetItem
.PutItemForScriptType( nScript
, pArgs
->Get( nWhich
) );
807 aSet
.Put( aSetItem
.GetItemSet(), FALSE
);
812 case SID_ATTR_CHAR_COLOR
:
816 aSet
.Put( pArgs
->Get( pArgs
->GetPool()->GetWhich( nSlot
) ) );
817 rBindings
.Invalidate( nSlot
);
824 case SID_ATTR_CHAR_WEIGHT
:
826 // #i78017 establish the same behaviour as in Writer
827 USHORT nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
829 SfxItemPool
& rPool
= GetPool();
832 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
833 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), FALSE
);
834 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
835 if ( pCore
&& ((const SvxWeightItem
*)pCore
)->GetWeight() > WEIGHT_NORMAL
)
838 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
839 aSetItem
.PutItemForScriptType( nScript
,
840 SvxWeightItem( bOld
? WEIGHT_NORMAL
: WEIGHT_BOLD
, EE_CHAR_WEIGHT
) );
841 aSet
.Put( aSetItem
.GetItemSet(), FALSE
);
843 rBindings
.Invalidate( nSlot
);
847 case SID_ATTR_CHAR_POSTURE
:
849 // #i78017 establish the same behaviour as in Writer
850 USHORT nScript
= SCRIPTTYPE_LATIN
| SCRIPTTYPE_ASIAN
| SCRIPTTYPE_COMPLEX
;
852 SfxItemPool
& rPool
= GetPool();
855 SvxScriptSetItem
aOldSetItem( nSlot
, rPool
);
856 aOldSetItem
.GetItemSet().Put( pEditView
->GetAttribs(), FALSE
);
857 const SfxPoolItem
* pCore
= aOldSetItem
.GetItemOfScript( nScript
);
858 if ( pCore
&& ((const SvxPostureItem
*)pCore
)->GetValue() != ITALIC_NONE
)
861 SvxScriptSetItem
aSetItem( nSlot
, rPool
);
862 aSetItem
.PutItemForScriptType( nScript
,
863 SvxPostureItem( bOld
? ITALIC_NONE
: ITALIC_NORMAL
, EE_CHAR_ITALIC
) );
864 aSet
.Put( aSetItem
.GetItemSet(), FALSE
);
866 rBindings
.Invalidate( nSlot
);
870 case SID_ULINE_VAL_NONE
:
871 aSet
.Put( SvxUnderlineItem( UNDERLINE_NONE
, EE_CHAR_UNDERLINE
) );
872 lcl_InvalidateUnder( rBindings
);
875 case SID_ATTR_CHAR_UNDERLINE
: // Toggles
876 case SID_ULINE_VAL_SINGLE
:
877 case SID_ULINE_VAL_DOUBLE
:
878 case SID_ULINE_VAL_DOTTED
:
880 FontUnderline eOld
= ((const SvxUnderlineItem
&) pEditView
->
881 GetAttribs().Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
882 FontUnderline eNew
= eOld
;
885 case SID_ATTR_CHAR_UNDERLINE
:
886 eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
888 case SID_ULINE_VAL_SINGLE
:
889 eNew
= ( eOld
== UNDERLINE_SINGLE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
891 case SID_ULINE_VAL_DOUBLE
:
892 eNew
= ( eOld
== UNDERLINE_DOUBLE
) ? UNDERLINE_NONE
: UNDERLINE_DOUBLE
;
894 case SID_ULINE_VAL_DOTTED
:
895 eNew
= ( eOld
== UNDERLINE_DOTTED
) ? UNDERLINE_NONE
: UNDERLINE_DOTTED
;
898 aSet
.Put( SvxUnderlineItem( eNew
, EE_CHAR_UNDERLINE
) );
899 lcl_InvalidateUnder( rBindings
);
903 case SID_ATTR_CHAR_OVERLINE
:
905 FontUnderline eOld
= ((const SvxOverlineItem
&) pEditView
->
906 GetAttribs().Get(EE_CHAR_OVERLINE
)).GetLineStyle();
907 FontUnderline eNew
= ( eOld
!= UNDERLINE_NONE
) ? UNDERLINE_NONE
: UNDERLINE_SINGLE
;
908 aSet
.Put( SvxOverlineItem( eNew
, EE_CHAR_OVERLINE
) );
909 rBindings
.Invalidate( nSlot
);
913 case SID_ATTR_CHAR_STRIKEOUT
:
915 BOOL bOld
= ((const SvxCrossedOutItem
&)pEditView
->GetAttribs().
916 Get(EE_CHAR_STRIKEOUT
)).GetValue() != STRIKEOUT_NONE
;
917 aSet
.Put( SvxCrossedOutItem( bOld
? STRIKEOUT_NONE
: STRIKEOUT_SINGLE
, EE_CHAR_STRIKEOUT
) );
918 rBindings
.Invalidate( nSlot
);
922 case SID_ATTR_CHAR_SHADOWED
:
924 BOOL bOld
= ((const SvxShadowedItem
&)pEditView
->GetAttribs().
925 Get(EE_CHAR_SHADOW
)).GetValue();
926 aSet
.Put( SvxShadowedItem( !bOld
, EE_CHAR_SHADOW
) );
927 rBindings
.Invalidate( nSlot
);
931 case SID_ATTR_CHAR_CONTOUR
:
933 BOOL bOld
= ((const SvxContourItem
&)pEditView
->GetAttribs().
934 Get(EE_CHAR_OUTLINE
)).GetValue();
935 aSet
.Put( SvxContourItem( !bOld
, EE_CHAR_OUTLINE
) );
936 rBindings
.Invalidate( nSlot
);
940 case SID_SET_SUPER_SCRIPT
:
942 SvxEscapement eOld
= (SvxEscapement
) ((const SvxEscapementItem
&)
943 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
944 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUPERSCRIPT
) ?
945 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUPERSCRIPT
;
946 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
947 rBindings
.Invalidate( nSlot
);
950 case SID_SET_SUB_SCRIPT
:
952 SvxEscapement eOld
= (SvxEscapement
) ((const SvxEscapementItem
&)
953 pEditView
->GetAttribs().Get(EE_CHAR_ESCAPEMENT
)).GetEnumValue();
954 SvxEscapement eNew
= (eOld
== SVX_ESCAPEMENT_SUBSCRIPT
) ?
955 SVX_ESCAPEMENT_OFF
: SVX_ESCAPEMENT_SUBSCRIPT
;
956 aSet
.Put( SvxEscapementItem( eNew
, EE_CHAR_ESCAPEMENT
) );
957 rBindings
.Invalidate( nSlot
);
966 EditEngine
* pEngine
= pEditView
->GetEditEngine();
967 BOOL bOld
= pEngine
->GetUpdateMode();
968 pEngine
->SetUpdateMode(FALSE
);
970 pEditView
->SetAttribs( aSet
);
972 pEngine
->SetUpdateMode(bOld
);
973 pEditView
->Invalidate();
975 ScInputHandler
* pHdl
= GetMyInputHdl();
981 void ScEditShell::GetAttrState(SfxItemSet
&rSet
)
983 if ( !pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
985 lcl_DisableAll( rSet
);
989 SfxItemSet aAttribs
= pEditView
->GetAttribs();
990 rSet
.Put( aAttribs
);
992 // choose font info according to selection script type
994 USHORT nScript
= pEditView
->GetSelectedScriptType();
995 if (nScript
== 0) nScript
= ScGlobal::GetDefaultScriptType();
997 // #i55929# input-language-dependent script type (depends on input language if nothing selected)
998 USHORT nInputScript
= nScript
;
999 if ( !pEditView
->GetSelection().HasRange() )
1001 LanguageType nInputLang
= pViewData
->GetActiveWin()->GetInputLanguage();
1002 if (nInputLang
!= LANGUAGE_DONTKNOW
&& nInputLang
!= LANGUAGE_SYSTEM
)
1003 nInputScript
= SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang
);
1006 // #i55929# according to spec, nInputScript is used for font and font height only
1007 if ( rSet
.GetItemState( EE_CHAR_FONTINFO
) != SFX_ITEM_UNKNOWN
)
1008 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTINFO
, nInputScript
);
1009 if ( rSet
.GetItemState( EE_CHAR_FONTHEIGHT
) != SFX_ITEM_UNKNOWN
)
1010 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_FONTHEIGHT
, nInputScript
);
1011 if ( rSet
.GetItemState( EE_CHAR_WEIGHT
) != SFX_ITEM_UNKNOWN
)
1012 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_WEIGHT
, nScript
);
1013 if ( rSet
.GetItemState( EE_CHAR_ITALIC
) != SFX_ITEM_UNKNOWN
)
1014 ScViewUtil::PutItemScript( rSet
, aAttribs
, EE_CHAR_ITALIC
, nScript
);
1018 SfxItemState eState
= aAttribs
.GetItemState( EE_CHAR_UNDERLINE
, TRUE
);
1019 if ( eState
== SFX_ITEM_DONTCARE
)
1021 rSet
.InvalidateItem( SID_ULINE_VAL_NONE
);
1022 rSet
.InvalidateItem( SID_ULINE_VAL_SINGLE
);
1023 rSet
.InvalidateItem( SID_ULINE_VAL_DOUBLE
);
1024 rSet
.InvalidateItem( SID_ULINE_VAL_DOTTED
);
1028 FontUnderline eUnderline
= ((const SvxUnderlineItem
&)
1029 aAttribs
.Get(EE_CHAR_UNDERLINE
)).GetLineStyle();
1030 USHORT nId
= SID_ULINE_VAL_NONE
;
1033 case UNDERLINE_SINGLE
: nId
= SID_ULINE_VAL_SINGLE
; break;
1034 case UNDERLINE_DOUBLE
: nId
= SID_ULINE_VAL_DOUBLE
; break;
1035 case UNDERLINE_DOTTED
: nId
= SID_ULINE_VAL_DOTTED
; break;
1039 rSet
.Put( SfxBoolItem( nId
, TRUE
) );
1042 //! Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1043 ScInputHandler
* pHdl
= GetMyInputHdl();
1044 if ( pHdl
&& pHdl
->IsFormulaMode() )
1045 rSet
.ClearItem( EE_CHAR_WEIGHT
); // hervorgehobene Klammern hier nicht
1048 String
ScEditShell::GetSelectionText( BOOL bWholeWord
)
1050 String aStrSelection
;
1052 if ( pViewData
->HasEditView( pViewData
->GetActivePart() ) ) // #125326#
1056 EditEngine
* pEngine
= pEditView
->GetEditEngine();
1057 ESelection aSel
= pEditView
->GetSelection();
1058 String aStrCurrentDelimiters
= pEngine
->GetWordDelimiters();
1060 pEngine
->SetWordDelimiters( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" .,;\"'")) );
1061 aStrSelection
= pEngine
->GetWord( aSel
.nEndPara
, aSel
.nEndPos
);
1062 pEngine
->SetWordDelimiters( aStrCurrentDelimiters
);
1066 aStrSelection
= pEditView
->GetSelected();
1070 return aStrSelection
;
1073 void ScEditShell::ExecuteUndo(SfxRequest
& rReq
)
1075 // #81733# Undo must be handled here because it's called for both EditViews
1077 ScInputHandler
* pHdl
= GetMyInputHdl();
1078 DBG_ASSERT(pHdl
,"no ScInputHandler");
1079 EditView
* pTopView
= pHdl
->GetTopView();
1080 EditView
* pTableView
= pHdl
->GetTableView();
1081 DBG_ASSERT(pTableView
,"no EditView");
1083 pHdl
->DataChanging();
1085 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
1086 USHORT nSlot
= rReq
.GetSlot();
1092 BOOL bIsUndo
= ( nSlot
== SID_UNDO
);
1095 const SfxPoolItem
* pItem
;
1096 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlot
, TRUE
, &pItem
) == SFX_ITEM_SET
)
1097 nCount
= ((const SfxUInt16Item
*)pItem
)->GetValue();
1099 for (USHORT i
=0; i
<nCount
; i
++)
1117 pViewData
->GetBindings().InvalidateAll(FALSE
);
1119 pHdl
->DataChanged();
1122 void ScEditShell::GetUndoState(SfxItemSet
&rSet
)
1124 // Undo state is taken from normal ViewFrame state function
1126 SfxViewFrame
* pViewFrm
= pViewData
->GetViewShell()->GetViewFrame();
1127 if ( pViewFrm
&& GetUndoManager() )
1129 SfxWhichIter
aIter(rSet
);
1130 USHORT nWhich
= aIter
.FirstWhich();
1133 pViewFrm
->GetSlotState( nWhich
, NULL
, &rSet
);
1134 nWhich
= aIter
.NextWhich();
1138 // disable if no action in input line EditView
1140 ScInputHandler
* pHdl
= GetMyInputHdl();
1141 DBG_ASSERT(pHdl
,"no ScInputHandler");
1142 EditView
* pTopView
= pHdl
->GetTopView();
1145 SfxUndoManager
& rTopMgr
= pTopView
->GetEditEngine()->GetUndoManager();
1146 if ( rTopMgr
.GetUndoActionCount() == 0 )
1147 rSet
.DisableItem( SID_UNDO
);
1148 if ( rTopMgr
.GetRedoActionCount() == 0 )
1149 rSet
.DisableItem( SID_REDO
);
1153 void ScEditShell::ExecuteTrans( SfxRequest
& rReq
)
1155 sal_Int32 nType
= ScViewUtil::GetTransliterationType( rReq
.GetSlot() );
1158 ScInputHandler
* pHdl
= GetMyInputHdl();
1159 DBG_ASSERT( pHdl
, "no ScInputHandler" );
1161 EditView
* pTopView
= pHdl
->GetTopView();
1162 EditView
* pTableView
= pHdl
->GetTableView();
1163 DBG_ASSERT( pTableView
, "no EditView" );
1165 pHdl
->DataChanging();
1167 pTableView
->TransliterateText( nType
);
1169 pTopView
->TransliterateText( nType
);
1171 pHdl
->DataChanged();