merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / editsh.cxx
blob771c10ac00f6cc2621b5e5dc61d639244e202f53
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>
74 #define _EDITSH_CXX
75 #include "editsh.hxx"
77 #include "scresid.hxx"
78 #include "global.hxx"
79 #include "sc.hrc"
80 #include "scmod.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"
92 #define ScEditShell
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) :
106 pEditView (pView),
107 pViewData (pData),
108 pClipEvtLstnr (NULL),
109 bPastePossible (FALSE),
110 bIsInsertMode (TRUE)
112 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
113 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
114 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("EditCell")));
117 ScEditShell::~ScEditShell()
119 if ( pClipEvtLstnr )
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)
138 pEditView = 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 );
165 if( pTableView )
166 pTableView->InsertText( aString );
167 if( pTopView )
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. */
190 if (!pTableView)
191 return;
193 EditEngine* pEngine = pTableView->GetEditEngine();
195 pHdl->DataChanging();
196 BOOL bSetSelIsRef = FALSE;
198 switch ( nSlot )
200 case FID_INS_CELL_CONTENTS: // Insert-Taste, weil als Acc definiert
201 bIsInsertMode = !pTableView->IsInsertMode();
202 pTableView->SetInsertMode( bIsInsertMode );
203 if (pTopView)
204 pTopView->SetInsertMode( bIsInsertMode );
205 rBindings.Invalidate( SID_ATTR_INSERT );
206 break;
208 case SID_ATTR_INSERT:
209 if ( pReqArgs )
211 bIsInsertMode = ((const SfxBoolItem&)pReqArgs->Get(nSlot)).GetValue();
212 pTableView->SetInsertMode( bIsInsertMode );
213 if (pTopView)
214 pTopView->SetInsertMode( bIsInsertMode );
215 rBindings.Invalidate( SID_ATTR_INSERT );
217 break;
219 case SID_COPY:
220 pTableView->Copy();
221 break;
223 case SID_CUT:
224 pTableView->Cut();
225 if (pTopView)
226 pTopView->DeleteSelected();
227 break;
229 case SID_PASTE:
230 pTableView->PasteSpecial();
231 if (pTopView)
232 pTopView->Paste();
233 break;
235 case SID_DELETE:
236 pTableView->DeleteSelected();
237 if (pTopView)
238 pTopView->DeleteSelected();
239 break;
241 case SID_CELL_FORMAT_RESET: // "Standard"
242 lcl_RemoveAttribs( *pTableView );
243 if ( pTopView )
244 lcl_RemoveAttribs( *pTopView );
245 break;
247 case SID_CLIPBOARD_FORMAT_ITEMS:
249 ULONG nFormat = 0;
250 const SfxPoolItem* pItem;
251 if ( pReqArgs &&
252 pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET &&
253 pItem->ISA(SfxUInt32Item) )
255 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
258 if ( nFormat )
260 if (SOT_FORMAT_STRING == nFormat)
261 pTableView->Paste();
262 else
263 pTableView->PasteSpecial();
265 if (pTopView)
266 pTopView->Paste();
269 break;
271 case SID_PASTE_SPECIAL:
273 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
274 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pViewData->GetDialogParent() );
275 ULONG nFormat = 0;
276 if ( pDlg )
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() );
285 DELETEZ(pDlg);
288 // while the dialog was open, edit mode may have been stopped
289 if (!SC_MOD()->IsInputMode())
291 Sound::Beep();
292 return;
295 if (nFormat > 0)
297 if (SOT_FORMAT_STRING == nFormat)
298 pTableView->Paste();
299 else
300 pTableView->PasteSpecial();
302 if (pTopView)
303 pTopView->Paste();
306 if (pTopView)
307 pTopView->GetWindow()->GrabFocus();
309 break;
311 case SID_SELECTALL:
313 USHORT nPar = pEngine->GetParagraphCount();
314 if (nPar)
316 xub_StrLen nLen = pEngine->GetTextLen(nPar-1);
317 pTableView->SetSelection(ESelection(0,0,nPar-1,nLen));
318 if (pTopView)
319 pTopView->SetSelection(ESelection(0,0,nPar-1,nLen));
322 break;
324 case SID_CHARMAP:
326 USHORT nScript = pTableView->GetSelectedScriptType();
327 USHORT nFontWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? EE_CHAR_FONTINFO_CJK :
328 ( ( nScript == SCRIPTTYPE_COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
329 EE_CHAR_FONTINFO );
330 const SvxFontItem& rItem = (const SvxFontItem&)
331 pTableView->GetAttribs().Get(nFontWhich);
333 String aString;
334 SvxFontItem aNewItem( EE_CHAR_FONTINFO );
336 const SfxItemSet *pArgs = rReq.GetArgs();
337 const SfxPoolItem* pItem = 0;
338 if( pArgs )
339 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), FALSE, &pItem);
341 if ( 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 );
347 if ( pFontItem )
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 );
355 else
356 aNewItem = rItem;
358 else
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())
365 Sound::Beep();
366 return;
370 if ( aString.Len() )
372 // if string contains WEAK characters, set all fonts
373 BYTE nSetScript;
374 ScDocument* pDoc = pViewData->GetDocument();
375 if ( pDoc->HasStringWeakCharacters( aString ) )
376 nSetScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
377 else
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);
388 if (pTopView)
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 );
395 rReq.Done();
400 if (pTopView)
401 pTopView->GetWindow()->GrabFocus();
403 break;
405 case FID_INSERT_NAME:
407 ScDocument* pDoc = pViewData->GetDocument();
408 //CHINA001 ScNamePasteDlg* pDlg = new ScNamePasteDlg( pViewData->GetDialogParent(),
409 //CHINA001 pDoc->GetRangeName(), FALSE );
410 // "Liste" disablen
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())
422 Sound::Beep();
423 delete pDlg;
424 return;
427 if ( nRet == BTN_PASTE_NAME )
429 String aName = pDlg->GetSelectedName();
430 pTableView->InsertText(aName);
431 if (pTopView)
432 pTopView->InsertText(aName);
434 delete pDlg;
436 if (pTopView)
437 pTopView->GetWindow()->GrabFocus();
439 break;
441 case SID_CHAR_DLG:
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())
460 Sound::Beep();
461 delete pDlg;
462 return;
465 if ( nRet == RET_OK )
467 const SfxItemSet* pOut = pDlg->GetOutputItemSet();
468 pTableView->SetAttribs( *pOut );
470 delete pDlg;
472 break;
474 case SID_TOGGLE_REL:
476 BOOL bOk = FALSE;
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 );
490 if ( pTopView )
492 pTopView->GetEditEngine()->SetText( aNew );
493 pTopView->SetSelection( aNewSel );
495 bOk = TRUE;
497 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben
498 bSetSelIsRef = TRUE;
501 if (!bOk)
502 Sound::Beep(); // keine Referenzen oder mehrere Absaetze
504 break;
506 case SID_HYPERLINK_SETLINK:
507 if( pReqArgs )
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();
518 BOOL bDone = FALSE;
519 if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
521 const SvxURLField* pURLField = GetURLField();
522 if ( pURLField )
524 // altes Feld selektieren
526 ESelection aSel = pTableView->GetSelection();
527 aSel.Adjust();
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
542 if ( pTopView )
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
552 bDone = TRUE;
556 if (!bDone)
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
564 return;
568 break;
570 case SID_OPEN_HYPERLINK:
572 const SvxURLField* pURLField = GetURLField();
573 if ( pURLField )
574 ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
575 return;
577 //break;
579 case FN_INSERT_SOFT_HYPHEN:
580 lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
581 break;
582 case FN_INSERT_HARDHYPHEN:
583 lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
584 break;
585 case FN_INSERT_HARD_SPACE:
586 lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
587 break;
588 case SID_INSERT_RLM:
589 lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
590 break;
591 case SID_INSERT_LRM:
592 lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
593 break;
594 case SID_INSERT_ZWSP:
595 lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
596 break;
597 case SID_INSERT_ZWNBSP:
598 lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
599 break;
602 pHdl->DataChanged();
603 if (bSetSelIsRef)
604 pHdl->SetSelIsRef(TRUE);
607 void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots
609 SfxWhichIter aIter( rSet );
610 USHORT nWhich = aIter.FirstWhich();
611 while (nWhich)
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 );
626 return;
629 ScInputHandler* pHdl = GetMyInputHdl();
630 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
632 SfxWhichIter aIter( rSet );
633 USHORT nWhich = aIter.FirstWhich();
634 while (nWhich)
636 switch (nWhich)
638 case SID_ATTR_INSERT: // Statuszeile
640 if ( pActiveView )
641 rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
642 else
643 rSet.Put( SfxBoolItem( nWhich, 42 ) );
645 break;
647 case SID_HYPERLINK_GETLINK:
649 SvxHyperlinkItem aHLinkItem;
650 const SvxURLField* pURLField = GetURLField();
651 if ( pURLField )
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();
661 sReturn.Erase(255);
662 sReturn.EraseTrailingChars();
663 aHLinkItem.SetName(sReturn);
665 rSet.Put(aHLinkItem);
667 break;
669 case SID_OPEN_HYPERLINK:
671 if ( !GetURLField() )
672 rSet.DisableItem( nWhich );
674 break;
676 case SID_TRANSLITERATE_HALFWIDTH:
677 case SID_TRANSLITERATE_FULLWIDTH:
678 case SID_TRANSLITERATE_HIRAGANA:
679 case SID_TRANSLITERATE_KATAGANA:
680 case SID_INSERT_RLM:
681 case SID_INSERT_LRM:
682 case SID_INSERT_ZWNBSP:
683 case SID_INSERT_ZWSP:
684 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich );
685 break;
687 nWhich = aIter.NextWhich();
691 const SvxURLField* ScEditShell::GetURLField()
693 ScInputHandler* pHdl = GetMyInputHdl();
694 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
695 if ( pActiveView )
697 const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection();
698 if (pFieldItem)
700 const SvxFieldData* pField = pFieldItem->GetField();
701 if ( pField && pField->ISA(SvxURLField) )
702 return (const SvxURLField*)pField;
706 return NULL;
709 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
711 if ( 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 );
720 return 0;
723 void __EXPORT ScEditShell::GetClipState( SfxItemSet& rSet )
725 if ( !pClipEvtLstnr )
727 // create listener
728 pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
729 pClipEvtLstnr->acquire();
730 Window* pWin = pViewData->GetActiveWin();
731 pClipEvtLstnr->AddRemoveListener( pWin, TRUE );
733 // get initial state
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();
740 while (nWhich)
742 switch (nWhich)
744 case SID_PASTE:
745 case SID_PASTE_SPECIAL:
746 if( !bPastePossible )
747 rSet.DisableItem( nWhich );
748 break;
749 case SID_CLIPBOARD_FORMAT_ITEMS:
750 if( bPastePossible )
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 );
763 else
764 rSet.DisableItem( nWhich );
765 break;
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();
787 switch ( nSlot )
789 case SID_ATTR_CHAR_FONTHEIGHT:
790 case SID_ATTR_CHAR_FONT:
792 if (pArgs)
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 );
810 break;
812 case SID_ATTR_CHAR_COLOR:
814 if (pArgs)
816 aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
817 rBindings.Invalidate( nSlot );
820 break;
822 // Toggles
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();
831 BOOL bOld = FALSE;
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 )
836 bOld = TRUE;
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 );
845 break;
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();
854 BOOL bOld = FALSE;
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 )
859 bOld = TRUE;
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 );
868 break;
870 case SID_ULINE_VAL_NONE:
871 aSet.Put( SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
872 lcl_InvalidateUnder( rBindings );
873 break;
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;
883 switch (nSlot)
885 case SID_ATTR_CHAR_UNDERLINE:
886 eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
887 break;
888 case SID_ULINE_VAL_SINGLE:
889 eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
890 break;
891 case SID_ULINE_VAL_DOUBLE:
892 eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
893 break;
894 case SID_ULINE_VAL_DOTTED:
895 eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
896 break;
898 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
899 lcl_InvalidateUnder( rBindings );
901 break;
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 );
911 break;
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 );
920 break;
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 );
929 break;
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 );
938 break;
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 );
949 break;
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 );
959 break;
963 // anwenden
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();
976 pHdl->SetModified();
978 rReq.Done();
981 void ScEditShell::GetAttrState(SfxItemSet &rSet)
983 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) ) // #125326#
985 lcl_DisableAll( rSet );
986 return;
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 );
1016 // Unterstreichung
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 );
1026 else
1028 FontUnderline eUnderline = ((const SvxUnderlineItem&)
1029 aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
1030 USHORT nId = SID_ULINE_VAL_NONE;
1031 switch (eUnderline)
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;
1036 default:
1037 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#
1054 if ( bWholeWord )
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 );
1064 else
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();
1087 switch ( nSlot )
1089 case SID_UNDO:
1090 case SID_REDO:
1092 BOOL bIsUndo = ( nSlot == SID_UNDO );
1094 USHORT nCount = 1;
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++)
1101 if ( bIsUndo )
1103 pTableView->Undo();
1104 if (pTopView)
1105 pTopView->Undo();
1107 else
1109 pTableView->Redo();
1110 if (pTopView)
1111 pTopView->Redo();
1115 break;
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();
1131 while( nWhich )
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();
1143 if (pTopView)
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() );
1156 if ( nType )
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 );
1168 if (pTopView)
1169 pTopView->TransliterateText( nType );
1171 pHdl->DataChanged();