Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / editsh.cxx
blob687d4ec5f93b01cde187d8fcca32aeb40416cabe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/linguistic2/XThesaurus.hpp>
21 #include <comphelper/string.hxx>
22 #include "scitems.hxx"
23 #include <editeng/eeitem.hxx>
25 #include <svx/clipfmtitem.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <editeng/contouritem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <editeng/unolingu.hxx>
30 #include <editeng/crossedoutitem.hxx>
31 #include <editeng/editeng.hxx>
32 #include <editeng/editview.hxx>
33 #include <editeng/escapementitem.hxx>
34 #include <editeng/flditem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include <svx/hlnkitem.hxx>
37 #include <sfx2/sidebar/EnumContext.hxx>
38 #include <editeng/postitem.hxx>
39 #include <editeng/scripttypeitem.hxx>
40 #include <editeng/shdditem.hxx>
41 #include <svl/srchitem.hxx>
42 #include <editeng/udlnitem.hxx>
43 #include <editeng/wghtitem.hxx>
44 #include <sfx2/basedlgs.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/msg.hxx>
47 #include <sfx2/objface.hxx>
48 #include <sfx2/objsh.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/viewfrm.hxx>
51 #include <sot/exchange.hxx>
52 #include <svtools/cliplistener.hxx>
53 #include <svl/whiter.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <sot/formats.hxx>
56 #include <svtools/transfer.hxx>
57 #include <svl/stritem.hxx>
59 #include "editsh.hxx"
60 #include "scresid.hxx"
61 #include "global.hxx"
62 #include "sc.hrc"
63 #include "scmod.hxx"
64 #include "inputhdl.hxx"
65 #include "viewutil.hxx"
66 #include "viewdata.hxx"
67 #include "document.hxx"
68 #include "reffind.hxx"
69 #include "tabvwsh.hxx"
70 #include "editutil.hxx"
71 #include "globstr.hrc"
72 #include <gridwin.hxx>
74 #define ScEditShell
75 #include "scslots.hxx"
77 #include "scui_def.hxx"
78 #include "scabstdlg.hxx"
79 #include <boost/scoped_ptr.hpp>
81 using namespace ::com::sun::star;
84 TYPEINIT1( ScEditShell, SfxShell );
86 SFX_IMPL_INTERFACE(ScEditShell, SfxShell, ScResId(SCSTR_EDITSHELL))
88 void ScEditShell::InitInterface_Impl()
90 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_EDIT));
93 ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) :
94 pEditView (pView),
95 pViewData (pData),
96 pClipEvtLstnr (NULL),
97 bPastePossible (false),
98 bIsInsertMode (true)
100 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
101 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
102 SetName(OUString("EditCell"));
103 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_EditCell));
106 ScEditShell::~ScEditShell()
108 if ( pClipEvtLstnr )
110 pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), false );
112 // The listener may just now be waiting for the SolarMutex and call the link
113 // afterwards, in spite of RemoveListener. So the link has to be reset, too.
114 pClipEvtLstnr->ClearCallbackLink();
116 pClipEvtLstnr->release();
120 ScInputHandler* ScEditShell::GetMyInputHdl()
122 return SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
125 void ScEditShell::SetEditView(EditView* pView)
127 pEditView = pView;
128 pEditView->SetInsertMode( bIsInsertMode );
129 SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
130 SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
133 static void lcl_RemoveAttribs( EditView& rEditView )
135 ScEditEngineDefaulter* pEngine = static_cast<ScEditEngineDefaulter*>(rEditView.GetEditEngine());
137 bool bOld = pEngine->GetUpdateMode();
138 pEngine->SetUpdateMode(false);
140 OUString aName = ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );
141 pEngine->GetUndoManager().EnterListAction( aName, aName );
143 rEditView.RemoveAttribs(true);
144 pEngine->RepeatDefaults(); // paragraph attributes from cell formats must be preserved
146 pEngine->GetUndoManager().LeaveListAction();
148 pEngine->SetUpdateMode(bOld);
151 void lclInsertCharacter( EditView* pTableView, EditView* pTopView, sal_Unicode cChar )
153 OUString aString( cChar );
154 if( pTableView )
155 pTableView->InsertText( aString );
156 if( pTopView )
157 pTopView->InsertText( aString );
160 void ScEditShell::Execute( SfxRequest& rReq )
162 const SfxItemSet* pReqArgs = rReq.GetArgs();
163 sal_uInt16 nSlot = rReq.GetSlot();
164 SfxBindings& rBindings = pViewData->GetBindings();
166 ScInputHandler* pHdl = GetMyInputHdl();
167 OSL_ENSURE(pHdl,"kein ScInputHandler");
169 EditView* pTopView = pHdl->GetTopView(); // hat Eingabezeile den Focus?
170 EditView* pTableView = pHdl->GetTableView();
172 OSL_ENSURE(pTableView,"no EditView :-(");
173 /* #i91683# No EditView if spell-check dialog is active and positioned on
174 * an error and user immediately (without double click or F2) selected a
175 * text portion of that cell with the mouse and wanted to modify it. */
176 /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
177 * action is possible. A real fix somehow would need to create a valid
178 * EditView from the spell-check view. */
179 if (!pTableView)
180 return;
182 EditEngine* pEngine = pTableView->GetEditEngine();
184 pHdl->DataChanging();
185 bool bSetSelIsRef = false;
186 bool bSetModified = true;
188 switch ( nSlot )
190 case FID_INS_CELL_CONTENTS: // Insert-Taste, weil als Acc definiert
191 bIsInsertMode = !pTableView->IsInsertMode();
192 pTableView->SetInsertMode( bIsInsertMode );
193 if (pTopView)
194 pTopView->SetInsertMode( bIsInsertMode );
195 rBindings.Invalidate( SID_ATTR_INSERT );
196 break;
198 case SID_ATTR_INSERT:
199 if ( pReqArgs )
201 bIsInsertMode = ((const SfxBoolItem&)pReqArgs->Get(nSlot)).GetValue();
202 pTableView->SetInsertMode( bIsInsertMode );
203 if (pTopView)
204 pTopView->SetInsertMode( bIsInsertMode );
205 rBindings.Invalidate( SID_ATTR_INSERT );
207 break;
209 case SID_THES:
211 OUString aReplaceText;
212 SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES , false );
213 if (pItem2)
214 aReplaceText = pItem2->GetValue();
215 if (!aReplaceText.isEmpty())
216 ReplaceTextWithSynonym( *pEditView, aReplaceText );
218 break;
220 case SID_COPY:
221 pTableView->Copy();
222 bSetModified = false;
223 break;
225 case SID_CUT:
226 pTableView->Cut();
227 if (pTopView)
228 pTopView->DeleteSelected();
229 break;
231 case SID_PASTE:
232 pTableView->PasteSpecial();
233 if (pTopView)
234 pTopView->Paste();
235 break;
237 case SID_DELETE:
238 pTableView->DeleteSelected();
239 if (pTopView)
240 pTopView->DeleteSelected();
241 break;
243 case SID_CELL_FORMAT_RESET: // "Standard"
244 lcl_RemoveAttribs( *pTableView );
245 if ( pTopView )
246 lcl_RemoveAttribs( *pTopView );
247 break;
249 case SID_CLIPBOARD_FORMAT_ITEMS:
251 sal_uLong nFormat = 0;
252 const SfxPoolItem* pItem;
253 if ( pReqArgs &&
254 pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET &&
255 pItem->ISA(SfxUInt32Item) )
257 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
260 if ( nFormat )
262 if (SOT_FORMAT_STRING == nFormat)
263 pTableView->Paste();
264 else
265 pTableView->PasteSpecial();
267 if (pTopView)
268 pTopView->Paste();
271 break;
273 case SID_PASTE_SPECIAL:
275 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
276 boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( pViewData->GetDialogParent() ));
277 sal_uLong nFormat = 0;
278 if ( pDlg )
280 pDlg->Insert( SOT_FORMAT_STRING, EMPTY_OUSTRING );
281 pDlg->Insert( SOT_FORMAT_RTF, EMPTY_OUSTRING );
283 TransferableDataHelper aDataHelper(
284 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
286 nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
288 pDlg.reset();
290 // while the dialog was open, edit mode may have been stopped
291 if (!SC_MOD()->IsInputMode())
292 return;
294 if (nFormat > 0)
296 if (SOT_FORMAT_STRING == nFormat)
297 pTableView->Paste();
298 else
299 pTableView->PasteSpecial();
301 if (pTopView)
302 pTopView->Paste();
305 if (pTopView)
306 pTopView->GetWindow()->GrabFocus();
308 break;
310 case SID_SELECTALL:
312 sal_Int32 nPar = pEngine->GetParagraphCount();
313 if (nPar)
315 sal_Int32 nLen = pEngine->GetTextLen(nPar-1);
316 pTableView->SetSelection(ESelection(0,0,nPar-1,nLen));
317 if (pTopView)
318 pTopView->SetSelection(ESelection(0,0,nPar-1,nLen));
319 rBindings.Invalidate( SID_ATTR_CHAR_FONT );
320 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
321 rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
322 rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
323 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
324 rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
325 rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
326 rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
327 rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
328 rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
329 rBindings.Invalidate( SID_SET_SUB_SCRIPT );
331 bSetModified = false;
333 return;
335 case SID_CHARMAP:
337 sal_uInt16 nScript = pTableView->GetSelectedScriptType();
338 sal_uInt16 nFontWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? EE_CHAR_FONTINFO_CJK :
339 ( ( nScript == SCRIPTTYPE_COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
340 EE_CHAR_FONTINFO );
341 const SvxFontItem& rItem = (const SvxFontItem&)
342 pTableView->GetAttribs().Get(nFontWhich);
344 OUString aString;
345 SvxFontItem aNewItem( EE_CHAR_FONTINFO );
347 const SfxItemSet *pArgs = rReq.GetArgs();
348 const SfxPoolItem* pItem = 0;
349 if( pArgs )
350 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
352 if ( pItem )
354 aString = ((const SfxStringItem*)pItem)->GetValue();
355 const SfxPoolItem* pFtItem = NULL;
356 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
357 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
358 if ( pFontItem )
360 OUString aFontName(pFontItem->GetValue());
361 Font aFont(aFontName, Size(1,1)); // Size nur wg. CTOR
362 aNewItem = SvxFontItem( aFont.GetFamily(), aFont.GetName(),
363 aFont.GetStyleName(), aFont.GetPitch(),
364 aFont.GetCharSet(), ATTR_FONT );
366 else
367 aNewItem = rItem;
369 else
371 ScViewUtil::ExecuteCharMap( rItem, *pViewData->GetViewShell()->GetViewFrame(), aNewItem, aString );
373 // while the dialog was open, edit mode may have been stopped
374 if (!SC_MOD()->IsInputMode())
375 return;
378 if ( !aString.isEmpty() )
380 // if string contains WEAK characters, set all fonts
381 sal_uInt8 nSetScript;
382 ScDocument* pDoc = pViewData->GetDocument();
383 if ( pDoc->HasStringWeakCharacters( aString ) )
384 nSetScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
385 else
386 nSetScript = pDoc->GetStringScriptType( aString );
388 SfxItemSet aSet( pTableView->GetEmptyItemSet() );
389 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() );
390 aSetItem.PutItemForScriptType( nSetScript, aNewItem );
391 aSet.Put( aSetItem.GetItemSet(), false );
393 // SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
394 pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() );
395 pTableView->InsertText(aString);
396 if (pTopView)
397 pTopView->InsertText(aString);
399 SfxStringItem aStringItem( SID_CHARMAP, aString );
400 SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem.GetFamilyName() );
401 rReq.AppendItem( aFontItem );
402 rReq.AppendItem( aStringItem );
403 rReq.Done();
408 if (pTopView)
409 pTopView->GetWindow()->GrabFocus();
411 break;
413 case FID_INSERT_NAME:
415 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
416 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
418 boost::scoped_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pViewData->GetDocShell(), false ));
419 OSL_ENSURE(pDlg, "Dialog create fail!");
420 short nRet = pDlg->Execute();
421 // pDlg is needed below
423 // while the dialog was open, edit mode may have been stopped
424 if (!SC_MOD()->IsInputMode())
425 return;
427 if ( nRet == BTN_PASTE_NAME )
429 std::vector<OUString> aNames = pDlg->GetSelectedNames();
430 if (!aNames.empty())
432 OUStringBuffer aBuffer;
433 for (std::vector<OUString>::const_iterator itr = aNames.begin();
434 itr != aNames.end(); ++itr)
436 aBuffer.append(*itr).append(' ');
438 pTableView->InsertText(aBuffer.toString());
439 if (pTopView)
440 pTopView->InsertText(aBuffer.makeStringAndClear());
443 pDlg.reset();
445 if (pTopView)
446 pTopView->GetWindow()->GrabFocus();
448 break;
450 case SID_CHAR_DLG_EFFECT:
451 case SID_CHAR_DLG:
453 SfxItemSet aAttrs( pTableView->GetAttribs() );
455 SfxObjectShell* pObjSh = pViewData->GetSfxDocShell();
457 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
458 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
460 boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
461 pViewData->GetDialogParent(), &aAttrs, pObjSh));
462 OSL_ENSURE(pDlg, "Dialog create fail!");
463 if (nSlot == SID_CHAR_DLG_EFFECT)
465 pDlg->SetCurPageId("fonteffects");
467 short nRet = pDlg->Execute();
468 // pDlg is needed below
470 // while the dialog was open, edit mode may have been stopped
471 if (!SC_MOD()->IsInputMode())
472 return;
474 if ( nRet == RET_OK )
476 const SfxItemSet* pOut = pDlg->GetOutputItemSet();
477 pTableView->SetAttribs( *pOut );
480 break;
482 case SID_TOGGLE_REL:
484 if (pEngine->GetParagraphCount() == 1)
486 OUString aText = pEngine->GetText();
487 ESelection aSel = pEditView->GetSelection(); // aktuelle View
489 ScDocument* pDoc = pViewData->GetDocument();
490 ScRefFinder aFinder(aText, pViewData->GetCurPos(), pDoc, pDoc->GetAddressConvention());
491 aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos );
492 if (aFinder.GetFound())
494 OUString aNew = aFinder.GetText();
495 ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() );
496 pEngine->SetText( aNew );
497 pTableView->SetSelection( aNewSel );
498 if ( pTopView )
500 pTopView->GetEditEngine()->SetText( aNew );
501 pTopView->SetSelection( aNewSel );
504 // Referenz wird selektiert -> beim Tippen nicht ueberschreiben
505 bSetSelIsRef = true;
509 break;
511 case SID_HYPERLINK_SETLINK:
512 if( pReqArgs )
514 const SfxPoolItem* pItem;
515 if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, true, &pItem ) == SFX_ITEM_SET )
517 const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
518 const OUString& rName = pHyper->GetName();
519 const OUString& rURL = pHyper->GetURL();
520 const OUString& rTarget = pHyper->GetTargetFrame();
521 SvxLinkInsertMode eMode = pHyper->GetInsertMode();
523 bool bDone = false;
524 if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
526 const SvxURLField* pURLField = GetURLField();
527 if ( pURLField )
529 // altes Feld selektieren
531 ESelection aSel = pTableView->GetSelection();
532 aSel.Adjust();
533 aSel.nEndPara = aSel.nStartPara;
534 aSel.nEndPos = aSel.nStartPos + 1;
535 pTableView->SetSelection( aSel );
537 // neues Feld einfuegen
539 SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
540 aURLField.SetTargetFrame( rTarget );
541 SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
542 pTableView->InsertField( aURLItem );
543 pTableView->SetSelection( aSel ); // select inserted field
545 // jetzt doch auch Felder in der Top-View
547 if ( pTopView )
549 aSel = pTopView->GetSelection();
550 aSel.nEndPara = aSel.nStartPara;
551 aSel.nEndPos = aSel.nStartPos + 1;
552 pTopView->SetSelection( aSel );
553 pTopView->InsertField( aURLItem );
554 pTopView->SetSelection( aSel ); // select inserted field
557 bDone = true;
561 if (!bDone)
563 pViewData->GetViewShell()->
564 InsertURL( rName, rURL, rTarget, (sal_uInt16) eMode );
566 // InsertURL an der ViewShell schaltet bei "Button"
567 // die EditShell ab, darum sofort return
569 return;
573 break;
575 case SID_OPEN_HYPERLINK:
577 const SvxURLField* pURLField = GetURLField();
578 if ( pURLField )
579 ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
580 return;
582 //break;
584 case FN_INSERT_SOFT_HYPHEN:
585 lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
586 break;
587 case FN_INSERT_HARDHYPHEN:
588 lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
589 break;
590 case FN_INSERT_HARD_SPACE:
591 lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
592 break;
593 case SID_INSERT_RLM:
594 lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
595 break;
596 case SID_INSERT_LRM:
597 lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
598 break;
599 case SID_INSERT_ZWSP:
600 lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
601 break;
602 case SID_INSERT_ZWNBSP:
603 lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
604 break;
605 case SID_INSERT_FIELD_SHEET:
607 SvxTableField aField(pViewData->GetTabNo());
608 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
609 pTableView->InsertField(aItem);
611 break;
612 case SID_INSERT_FIELD_TITLE:
614 SvxFileField aField;
615 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
616 pTableView->InsertField(aItem);
618 break;
619 case SID_INSERT_FIELD_DATE_VAR:
621 SvxDateField aField;
622 SvxFieldItem aItem(aField, EE_FEATURE_FIELD);
623 pTableView->InsertField(aItem);
625 break;
628 pHdl->DataChanged(false, bSetModified);
629 if (bSetSelIsRef)
630 pHdl->SetSelIsRef(true);
633 static void lcl_DisableAll( SfxItemSet& rSet ) // disable all slots
635 SfxWhichIter aIter( rSet );
636 sal_uInt16 nWhich = aIter.FirstWhich();
637 while (nWhich)
639 rSet.DisableItem( nWhich );
640 nWhich = aIter.NextWhich();
644 void ScEditShell::GetState( SfxItemSet& rSet )
646 // When deactivating the view, edit mode is stopped, but the EditShell is left active
647 // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
648 // into the EditEngine, so it can have an invalid selection and must not be used.
649 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )
651 lcl_DisableAll( rSet );
652 return;
655 ScInputHandler* pHdl = GetMyInputHdl();
656 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
658 SfxWhichIter aIter( rSet );
659 sal_uInt16 nWhich = aIter.FirstWhich();
660 while (nWhich)
662 switch (nWhich)
664 case SID_ATTR_INSERT: // Statuszeile
666 if ( pActiveView )
667 rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
668 else
670 // Here the code used to pass the value 42 and it used
671 // to "work" without warnings because the SfxBoolItem
672 // was based on 'sal_Bool', which is actually 'unsigned
673 // char'. But now it uses actual 'bool', and passing 42
674 // for a 'bool' parameter causes a warning at least with
675 // MSVC. So use 'true'. I really really hope there is
676 // not code somewhere that retrieves this "boolean" item
677 // and checks it value for the magic value 42...
678 rSet.Put( SfxBoolItem( nWhich, true) );
681 break;
683 case SID_HYPERLINK_GETLINK:
685 SvxHyperlinkItem aHLinkItem;
686 const SvxURLField* pURLField = GetURLField();
687 if ( pURLField )
689 aHLinkItem.SetName( pURLField->GetRepresentation() );
690 aHLinkItem.SetURL( pURLField->GetURL() );
691 aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
693 else if ( pActiveView )
695 // use selected text as name for urls
696 OUString sReturn = pActiveView->GetSelected();
697 sReturn = sReturn.copy(0, std::min(sReturn.getLength(), static_cast<sal_Int32>(255)));
698 aHLinkItem.SetName(comphelper::string::stripEnd(sReturn, ' '));
700 rSet.Put(aHLinkItem);
702 break;
704 case SID_OPEN_HYPERLINK:
706 if ( !GetURLField() )
707 rSet.DisableItem( nWhich );
709 break;
711 case SID_TRANSLITERATE_HALFWIDTH:
712 case SID_TRANSLITERATE_FULLWIDTH:
713 case SID_TRANSLITERATE_HIRAGANA:
714 case SID_TRANSLITERATE_KATAGANA:
715 case SID_INSERT_RLM:
716 case SID_INSERT_LRM:
717 case SID_INSERT_ZWNBSP:
718 case SID_INSERT_ZWSP:
719 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich );
720 break;
722 case SID_THES:
724 OUString aStatusVal;
725 LanguageType nLang = LANGUAGE_NONE;
726 bool bIsLookUpWord = pActiveView ?
727 GetStatusValueForThesaurusFromContext(aStatusVal, nLang, *pActiveView) : false;
728 rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
730 // disable thesaurus context menu entry if there is nothing to look up
731 bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
732 if (!bIsLookUpWord || !bCanDoThesaurus)
733 rSet.DisableItem( SID_THES );
735 break;
736 case SID_INSERT_FIELD_SHEET:
737 case SID_INSERT_FIELD_TITLE:
738 case SID_INSERT_FIELD_DATE_VAR:
739 break;
742 nWhich = aIter.NextWhich();
746 const SvxURLField* ScEditShell::GetURLField()
748 ScInputHandler* pHdl = GetMyInputHdl();
749 EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
750 if ( pActiveView )
752 const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection();
753 if (pFieldItem)
755 const SvxFieldData* pField = pFieldItem->GetField();
756 if ( pField && pField->ISA(SvxURLField) )
757 return (const SvxURLField*)pField;
761 return NULL;
764 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
766 if ( pDataHelper )
768 bPastePossible = ( pDataHelper->HasFormat( SOT_FORMAT_STRING ) || pDataHelper->HasFormat( SOT_FORMAT_RTF ) );
770 SfxBindings& rBindings = pViewData->GetBindings();
771 rBindings.Invalidate( SID_PASTE );
772 rBindings.Invalidate( SID_PASTE_SPECIAL );
773 rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
775 return 0;
778 void ScEditShell::GetClipState( SfxItemSet& rSet )
780 if ( !pClipEvtLstnr )
782 // create listener
783 pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
784 pClipEvtLstnr->acquire();
785 Window* pWin = pViewData->GetActiveWin();
786 pClipEvtLstnr->AddRemoveListener( pWin, true );
788 // get initial state
789 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
790 bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
793 SfxWhichIter aIter( rSet );
794 sal_uInt16 nWhich = aIter.FirstWhich();
795 while (nWhich)
797 switch (nWhich)
799 case SID_PASTE:
800 case SID_PASTE_SPECIAL:
801 if( !bPastePossible )
802 rSet.DisableItem( nWhich );
803 break;
804 case SID_CLIPBOARD_FORMAT_ITEMS:
805 if( bPastePossible )
807 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
808 TransferableDataHelper aDataHelper(
809 TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
811 if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
812 aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
813 if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
814 aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
816 rSet.Put( aFormats );
818 else
819 rSet.DisableItem( nWhich );
820 break;
822 nWhich = aIter.NextWhich();
826 static void lcl_InvalidateUnder( SfxBindings& rBindings )
828 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
829 rBindings.Invalidate( SID_ULINE_VAL_NONE );
830 rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
831 rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
832 rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
835 void ScEditShell::ExecuteAttr(SfxRequest& rReq)
837 SfxItemSet aSet( pEditView->GetEmptyItemSet() );
838 SfxBindings& rBindings = pViewData->GetBindings();
839 const SfxItemSet* pArgs = rReq.GetArgs();
840 sal_uInt16 nSlot = rReq.GetSlot();
842 switch ( nSlot )
844 case SID_ATTR_CHAR_FONTHEIGHT:
845 case SID_ATTR_CHAR_FONT:
847 if (pArgs)
849 // #i78017 establish the same behaviour as in Writer
850 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
851 if (nSlot == SID_ATTR_CHAR_FONT)
853 nScript = pEditView->GetSelectedScriptType();
854 if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
857 SfxItemPool& rPool = GetPool();
858 SvxScriptSetItem aSetItem( nSlot, rPool );
859 sal_uInt16 nWhich = rPool.GetWhich( nSlot );
860 aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
862 aSet.Put( aSetItem.GetItemSet(), false );
865 break;
867 case SID_ATTR_CHAR_COLOR:
869 if (pArgs)
871 aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
872 rBindings.Invalidate( nSlot );
875 break;
877 // Toggles
879 case SID_ATTR_CHAR_WEIGHT:
881 // #i78017 establish the same behaviour as in Writer
882 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
884 SfxItemPool& rPool = GetPool();
886 bool bOld = false;
887 SvxScriptSetItem aOldSetItem( nSlot, rPool );
888 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
889 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
890 if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() > WEIGHT_NORMAL )
891 bOld = true;
893 SvxScriptSetItem aSetItem( nSlot, rPool );
894 aSetItem.PutItemForScriptType( nScript,
895 SvxWeightItem( bOld ? WEIGHT_NORMAL : WEIGHT_BOLD, EE_CHAR_WEIGHT ) );
896 aSet.Put( aSetItem.GetItemSet(), false );
898 rBindings.Invalidate( nSlot );
900 break;
902 case SID_ATTR_CHAR_POSTURE:
904 // #i78017 establish the same behaviour as in Writer
905 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
907 SfxItemPool& rPool = GetPool();
909 bool bOld = false;
910 SvxScriptSetItem aOldSetItem( nSlot, rPool );
911 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), false );
912 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
913 if ( pCore && ((const SvxPostureItem*)pCore)->GetValue() != ITALIC_NONE )
914 bOld = true;
916 SvxScriptSetItem aSetItem( nSlot, rPool );
917 aSetItem.PutItemForScriptType( nScript,
918 SvxPostureItem( bOld ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
919 aSet.Put( aSetItem.GetItemSet(), false );
921 rBindings.Invalidate( nSlot );
923 break;
925 case SID_ULINE_VAL_NONE:
926 aSet.Put( SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
927 lcl_InvalidateUnder( rBindings );
928 break;
930 case SID_ATTR_CHAR_UNDERLINE:
931 case SID_ULINE_VAL_SINGLE:
932 case SID_ULINE_VAL_DOUBLE:
933 case SID_ULINE_VAL_DOTTED:
935 FontUnderline eOld = ((const SvxUnderlineItem&) pEditView->
936 GetAttribs().Get(EE_CHAR_UNDERLINE)).GetLineStyle();
937 FontUnderline eNew = eOld;
938 switch (nSlot)
940 case SID_ATTR_CHAR_UNDERLINE:
941 if ( pArgs )
943 const SvxTextLineItem& rTextLineItem = static_cast< const SvxTextLineItem& >( pArgs->Get( pArgs->GetPool()->GetWhich(nSlot) ) );
944 eNew = rTextLineItem.GetLineStyle();
946 else
948 eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
950 break;
951 case SID_ULINE_VAL_SINGLE:
952 eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
953 break;
954 case SID_ULINE_VAL_DOUBLE:
955 eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
956 break;
957 case SID_ULINE_VAL_DOTTED:
958 eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
959 break;
961 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
962 lcl_InvalidateUnder( rBindings );
964 break;
966 case SID_ATTR_CHAR_OVERLINE:
968 FontUnderline eOld = ((const SvxOverlineItem&) pEditView->
969 GetAttribs().Get(EE_CHAR_OVERLINE)).GetLineStyle();
970 FontUnderline eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
971 aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) );
972 rBindings.Invalidate( nSlot );
974 break;
976 case SID_ATTR_CHAR_STRIKEOUT:
978 bool bOld = ((const SvxCrossedOutItem&)pEditView->GetAttribs().
979 Get(EE_CHAR_STRIKEOUT)).GetValue() != STRIKEOUT_NONE;
980 aSet.Put( SvxCrossedOutItem( bOld ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
981 rBindings.Invalidate( nSlot );
983 break;
985 case SID_ATTR_CHAR_SHADOWED:
987 bool bOld = ((const SvxShadowedItem&)pEditView->GetAttribs().
988 Get(EE_CHAR_SHADOW)).GetValue();
989 aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) );
990 rBindings.Invalidate( nSlot );
992 break;
994 case SID_ATTR_CHAR_CONTOUR:
996 bool bOld = ((const SvxContourItem&)pEditView->GetAttribs().
997 Get(EE_CHAR_OUTLINE)).GetValue();
998 aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) );
999 rBindings.Invalidate( nSlot );
1001 break;
1003 case SID_SET_SUPER_SCRIPT:
1005 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
1006 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1007 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUPERSCRIPT) ?
1008 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUPERSCRIPT;
1009 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1010 rBindings.Invalidate( nSlot );
1012 break;
1013 case SID_SET_SUB_SCRIPT:
1015 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
1016 pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1017 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUBSCRIPT) ?
1018 SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUBSCRIPT;
1019 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1020 rBindings.Invalidate( nSlot );
1022 break;
1023 case SID_ATTR_CHAR_KERNING:
1025 if(pArgs)
1027 aSet.Put ( pArgs->Get(pArgs->GetPool()->GetWhich(nSlot)));
1028 rBindings.Invalidate( nSlot );
1031 break;
1035 // anwenden
1038 EditEngine* pEngine = pEditView->GetEditEngine();
1039 bool bOld = pEngine->GetUpdateMode();
1040 pEngine->SetUpdateMode(false);
1042 pEditView->SetAttribs( aSet );
1044 pEngine->SetUpdateMode(bOld);
1045 pEditView->Invalidate();
1047 ScInputHandler* pHdl = GetMyInputHdl();
1048 pHdl->SetModified();
1050 rReq.Done();
1053 void ScEditShell::GetAttrState(SfxItemSet &rSet)
1055 if ( !pViewData->HasEditView( pViewData->GetActivePart() ) ) // #125326#
1057 lcl_DisableAll( rSet );
1058 return;
1061 SfxItemSet aAttribs = pEditView->GetAttribs();
1062 rSet.Put( aAttribs );
1064 // choose font info according to selection script type
1066 sal_uInt16 nScript = pEditView->GetSelectedScriptType();
1067 if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
1069 // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1070 sal_uInt16 nInputScript = nScript;
1071 if ( !pEditView->GetSelection().HasRange() )
1073 LanguageType nInputLang = pViewData->GetActiveWin()->GetInputLanguage();
1074 if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1075 nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1078 // #i55929# according to spec, nInputScript is used for font and font height only
1079 if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SFX_ITEM_UNKNOWN )
1080 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript );
1081 if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SFX_ITEM_UNKNOWN )
1082 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript );
1083 if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SFX_ITEM_UNKNOWN )
1084 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript );
1085 if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SFX_ITEM_UNKNOWN )
1086 ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript );
1088 // Unterstreichung
1090 SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE, true );
1091 if ( eState == SFX_ITEM_DONTCARE )
1093 rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1094 rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1095 rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1096 rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1098 else
1100 FontUnderline eUnderline = ((const SvxUnderlineItem&)
1101 aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
1102 sal_uInt16 nId = SID_ULINE_VAL_NONE;
1103 switch (eUnderline)
1105 case UNDERLINE_SINGLE: nId = SID_ULINE_VAL_SINGLE; break;
1106 case UNDERLINE_DOUBLE: nId = SID_ULINE_VAL_DOUBLE; break;
1107 case UNDERLINE_DOTTED: nId = SID_ULINE_VAL_DOTTED; break;
1108 default:
1109 break;
1111 rSet.Put( SfxBoolItem( nId, true ) );
1114 //! Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1115 ScInputHandler* pHdl = GetMyInputHdl();
1116 if ( pHdl && pHdl->IsFormulaMode() )
1117 rSet.ClearItem( EE_CHAR_WEIGHT ); // hervorgehobene Klammern hier nicht
1119 SvxEscapement eEsc = (SvxEscapement) ( (const SvxEscapementItem&)
1120 aAttribs.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
1121 if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
1123 rSet.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT, true ) );
1125 else if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
1127 rSet.Put( SfxBoolItem( SID_SET_SUB_SCRIPT, true ) );
1129 pViewData->GetBindings().Invalidate( SID_SET_SUPER_SCRIPT );
1130 pViewData->GetBindings().Invalidate( SID_SET_SUB_SCRIPT );
1132 eState = aAttribs.GetItemState( EE_CHAR_KERNING, true );
1133 pViewData->GetBindings().Invalidate( SID_ATTR_CHAR_KERNING );
1134 if ( eState == SFX_ITEM_DONTCARE )
1136 // rSet.InvalidateItem( SID_ATTR_CHAR_KERNING );
1137 rSet.InvalidateItem(EE_CHAR_KERNING);
1141 OUString ScEditShell::GetSelectionText( bool bWholeWord )
1143 OUString aStrSelection;
1145 if ( pViewData->HasEditView( pViewData->GetActivePart() ) ) // #125326#
1147 if ( bWholeWord )
1149 EditEngine* pEngine = pEditView->GetEditEngine();
1150 ESelection aSel = pEditView->GetSelection();
1151 OUString aStrCurrentDelimiters = pEngine->GetWordDelimiters();
1153 pEngine->SetWordDelimiters(" .,;\"'");
1154 aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos );
1155 pEngine->SetWordDelimiters( aStrCurrentDelimiters );
1157 else
1159 aStrSelection = pEditView->GetSelected();
1163 return aStrSelection;
1166 void ScEditShell::ExecuteUndo(SfxRequest& rReq)
1168 // Undo must be handled here because it's called for both EditViews
1170 ScInputHandler* pHdl = GetMyInputHdl();
1171 OSL_ENSURE(pHdl,"no ScInputHandler");
1172 EditView* pTopView = pHdl->GetTopView();
1173 EditView* pTableView = pHdl->GetTableView();
1174 OSL_ENSURE(pTableView,"no EditView");
1176 pHdl->DataChanging();
1178 const SfxItemSet* pReqArgs = rReq.GetArgs();
1179 sal_uInt16 nSlot = rReq.GetSlot();
1180 switch ( nSlot )
1182 case SID_UNDO:
1183 case SID_REDO:
1185 bool bIsUndo = ( nSlot == SID_UNDO );
1187 sal_uInt16 nCount = 1;
1188 const SfxPoolItem* pItem;
1189 if ( pReqArgs && pReqArgs->GetItemState( nSlot, true, &pItem ) == SFX_ITEM_SET )
1190 nCount = ((const SfxUInt16Item*)pItem)->GetValue();
1192 for (sal_uInt16 i=0; i<nCount; i++)
1194 if ( bIsUndo )
1196 pTableView->Undo();
1197 if (pTopView)
1198 pTopView->Undo();
1200 else
1202 pTableView->Redo();
1203 if (pTopView)
1204 pTopView->Redo();
1208 break;
1210 pViewData->GetBindings().InvalidateAll(false);
1212 pHdl->DataChanged();
1215 void ScEditShell::GetUndoState(SfxItemSet &rSet)
1217 // Undo state is taken from normal ViewFrame state function
1219 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
1220 if ( pViewFrm && GetUndoManager() )
1222 SfxWhichIter aIter(rSet);
1223 sal_uInt16 nWhich = aIter.FirstWhich();
1224 while( nWhich )
1226 pViewFrm->GetSlotState( nWhich, NULL, &rSet );
1227 nWhich = aIter.NextWhich();
1231 // disable if no action in input line EditView
1233 ScInputHandler* pHdl = GetMyInputHdl();
1234 OSL_ENSURE(pHdl,"no ScInputHandler");
1235 EditView* pTopView = pHdl->GetTopView();
1236 if (pTopView)
1238 ::svl::IUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager();
1239 if ( rTopMgr.GetUndoActionCount() == 0 )
1240 rSet.DisableItem( SID_UNDO );
1241 if ( rTopMgr.GetRedoActionCount() == 0 )
1242 rSet.DisableItem( SID_REDO );
1246 void ScEditShell::ExecuteTrans( SfxRequest& rReq )
1248 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
1249 if ( nType )
1251 ScInputHandler* pHdl = GetMyInputHdl();
1252 OSL_ENSURE( pHdl, "no ScInputHandler" );
1254 EditView* pTopView = pHdl->GetTopView();
1255 EditView* pTableView = pHdl->GetTableView();
1256 OSL_ENSURE( pTableView, "no EditView" );
1258 pHdl->DataChanging();
1260 pTableView->TransliterateText( nType );
1261 if (pTopView)
1262 pTopView->TransliterateText( nType );
1264 pHdl->DataChanged();
1268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */