xref: /AOO41X/main/sc/source/ui/view/editsh.cxx (revision da72173f9f5ebf442a76a058e2275842cbc3d04e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 //------------------------------------------------------------------
30 
31 #include <com/sun/star/linguistic2/XThesaurus.hpp>
32 
33 #include "scitems.hxx"
34 #include <editeng/eeitem.hxx>
35 
36 #include <svx/clipfmtitem.hxx>
37 #include <svx/svxdlg.hxx>
38 #include <editeng/cntritem.hxx>
39 #include <editeng/outliner.hxx>
40 #include <editeng/unolingu.hxx>
41 #include <editeng/crsditem.hxx>
42 #include <editeng/editeng.hxx>
43 #include <editeng/editview.hxx>
44 #include <editeng/escpitem.hxx>
45 #include <editeng/flditem.hxx>
46 #include <editeng/fontitem.hxx>
47 #include <svx/hlnkitem.hxx>
48 #include <sfx2/sidebar/EnumContext.hxx>
49 #include <editeng/postitem.hxx>
50 #include <editeng/scripttypeitem.hxx>
51 #include <editeng/shdditem.hxx>
52 #include <svl/srchitem.hxx>
53 #include <editeng/udlnitem.hxx>
54 #include <editeng/wghtitem.hxx>
55 #include <sfx2/basedlgs.hxx>
56 #include <sfx2/bindings.hxx>
57 #include <sfx2/msg.hxx>
58 #include <sfx2/objface.hxx>
59 #include <sfx2/objsh.hxx>
60 #include <sfx2/request.hxx>
61 #include <sfx2/viewfrm.hxx>
62 #include <sot/exchange.hxx>
63 #include <svtools/cliplistener.hxx>
64 #include <svl/whiter.hxx>
65 #include <vcl/msgbox.hxx>
66 #include <vcl/sound.hxx>
67 #include <sot/formats.hxx>
68 #include <svtools/transfer.hxx>
69 #include <svl/stritem.hxx>
70 
71 #define _EDITSH_CXX
72 #include "editsh.hxx"
73 
74 #include "scresid.hxx"
75 #include "global.hxx"
76 #include "sc.hrc"
77 #include "scmod.hxx"
78 #include "inputhdl.hxx"
79 #include "viewutil.hxx"
80 #include "viewdata.hxx"
81 #include "document.hxx"
82 //CHINA001 #include "namepast.hxx"
83 #include "reffind.hxx"
84 #include "tabvwsh.hxx"
85 //CHINA001 #include "textdlgs.hxx"
86 #include "editutil.hxx"
87 #include "globstr.hrc"
88 
89 #define ScEditShell
90 #include "scslots.hxx"
91 
92 #include "scui_def.hxx" //CHINA001
93 #include "scabstdlg.hxx" //CHINA001
94 
95 
96 using namespace ::com::sun::star;
97 
98 
99 TYPEINIT1( ScEditShell, SfxShell );
100 
101 SFX_IMPL_INTERFACE(ScEditShell, SfxShell, ScResId(SCSTR_EDITSHELL))
102 {
103     SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_EDIT) );
104 }
105 
106 
107 ScEditShell::ScEditShell(EditView* pView, ScViewData* pData) :
108     pEditView       (pView),
109     pViewData       (pData),
110     pClipEvtLstnr   (NULL),
111     bPastePossible  (sal_False),
112     bIsInsertMode   (sal_True)
113 {
114     SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
115     SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
116     SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("EditCell")));
117     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_EditCell));
118 }
119 
120 ScEditShell::~ScEditShell()
121 {
122     if ( pClipEvtLstnr )
123     {
124         pClipEvtLstnr->AddRemoveListener( pViewData->GetActiveWin(), sal_False );
125 
126         //  #122057# The listener may just now be waiting for the SolarMutex and call the link
127         //  afterwards, in spite of RemoveListener. So the link has to be reset, too.
128         pClipEvtLstnr->ClearCallbackLink();
129 
130         pClipEvtLstnr->release();
131     }
132 }
133 
134 ScInputHandler* ScEditShell::GetMyInputHdl()
135 {
136     return SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
137 }
138 
139 void ScEditShell::SetEditView(EditView* pView)
140 {
141     pEditView = pView;
142     pEditView->SetInsertMode( bIsInsertMode );
143     SetPool( pEditView->GetEditEngine()->GetEmptyItemSet().GetPool() );
144     SetUndoManager( &pEditView->GetEditEngine()->GetUndoManager() );
145 }
146 
147 void lcl_RemoveAttribs( EditView& rEditView )
148 {
149     ScEditEngineDefaulter* pEngine = static_cast<ScEditEngineDefaulter*>(rEditView.GetEditEngine());
150 
151     sal_Bool bOld = pEngine->GetUpdateMode();
152     pEngine->SetUpdateMode(sal_False);
153 
154     String aName = ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );
155     pEngine->GetUndoManager().EnterListAction( aName, aName );
156 
157     rEditView.RemoveAttribs(sal_True);
158     pEngine->RepeatDefaults();      // #97226# paragraph attributes from cell formats must be preserved
159 
160     pEngine->GetUndoManager().LeaveListAction();
161 
162     pEngine->SetUpdateMode(bOld);
163 }
164 
165 void lclInsertCharacter( EditView* pTableView, EditView* pTopView, sal_Unicode cChar )
166 {
167     String aString( cChar );
168     if( pTableView )
169         pTableView->InsertText( aString );
170     if( pTopView )
171         pTopView->InsertText( aString );
172 }
173 
174 void ScEditShell::Execute( SfxRequest& rReq )
175 {
176     const SfxItemSet*   pReqArgs    = rReq.GetArgs();
177     sal_uInt16              nSlot       = rReq.GetSlot();
178     SfxBindings&        rBindings   = pViewData->GetBindings();
179 
180     ScInputHandler* pHdl = GetMyInputHdl();
181     DBG_ASSERT(pHdl,"kein ScInputHandler");
182 
183     EditView* pTopView   = pHdl->GetTopView();      // hat Eingabezeile den Focus?
184     EditView* pTableView = pHdl->GetTableView();
185 
186     DBG_ASSERT(pTableView,"no EditView :-(");
187     /* #i91683# No EditView if spell-check dialog is active and positioned on
188      * an error and user immediately (without double click or F2) selected a
189      * text portion of that cell with the mouse and wanted to modify it. */
190     /* FIXME: Bailing out only cures the symptom and prevents a crash, no edit
191      * action is possible. A real fix somehow would need to create a valid
192      * EditView from the spell-check view. */
193     if (!pTableView)
194         return;
195 
196     EditEngine* pEngine = pTableView->GetEditEngine();
197 
198     pHdl->DataChanging();
199     sal_Bool bSetSelIsRef = sal_False;
200     sal_Bool bSetModified = sal_True;
201 
202     switch ( nSlot )
203     {
204         case FID_INS_CELL_CONTENTS: // Insert-Taste, weil als Acc definiert
205             bIsInsertMode = !pTableView->IsInsertMode();
206             pTableView->SetInsertMode( bIsInsertMode );
207             if (pTopView)
208                 pTopView->SetInsertMode( bIsInsertMode );
209             rBindings.Invalidate( SID_ATTR_INSERT );
210             break;
211 
212         case SID_ATTR_INSERT:
213             if ( pReqArgs )
214             {
215                 bIsInsertMode = ((const SfxBoolItem&)pReqArgs->Get(nSlot)).GetValue();
216                 pTableView->SetInsertMode( bIsInsertMode );
217                 if (pTopView)
218                     pTopView->SetInsertMode( bIsInsertMode );
219                 rBindings.Invalidate( SID_ATTR_INSERT );
220             }
221             break;
222 
223         case SID_THES:
224             {
225                 String aReplaceText;
226                 SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES , sal_False );
227                 if (pItem2)
228                     aReplaceText = pItem2->GetValue();
229                 if (aReplaceText.Len() > 0)
230                     ReplaceTextWithSynonym( *pEditView, aReplaceText );
231             }
232             break;
233 
234         case SID_COPY:
235             pTableView->Copy();
236             bSetModified = sal_False;
237             break;
238 
239         case SID_CUT:
240             pTableView->Cut();
241             if (pTopView)
242                 pTopView->DeleteSelected();
243             break;
244 
245         case SID_PASTE:
246             pTableView->PasteSpecial();
247             if (pTopView)
248                 pTopView->Paste();
249             break;
250 
251         case SID_DELETE:
252             pTableView->DeleteSelected();
253             if (pTopView)
254                 pTopView->DeleteSelected();
255             break;
256 
257         case SID_CELL_FORMAT_RESET:                 // "Standard"
258             lcl_RemoveAttribs( *pTableView );
259             if ( pTopView )
260                 lcl_RemoveAttribs( *pTopView );
261             break;
262 
263         case SID_CLIPBOARD_FORMAT_ITEMS:
264             {
265                 sal_uLong nFormat = 0;
266                 const SfxPoolItem* pItem;
267                 if ( pReqArgs &&
268                      pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
269                      pItem->ISA(SfxUInt32Item) )
270                 {
271                     nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
272                 }
273 
274                 if ( nFormat )
275                 {
276                     if (SOT_FORMAT_STRING == nFormat)
277                         pTableView->Paste();
278                     else
279                         pTableView->PasteSpecial();
280 
281                     if (pTopView)
282                         pTopView->Paste();
283                 }
284             }
285             break;
286 
287         case SID_PASTE_SPECIAL:
288             {
289                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
290                 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pViewData->GetDialogParent() );
291                 sal_uLong nFormat = 0;
292                 if ( pDlg )
293                 {
294                     pDlg->Insert( SOT_FORMAT_STRING, EMPTY_STRING );
295                     pDlg->Insert( SOT_FORMAT_RTF,    EMPTY_STRING );
296 
297                     TransferableDataHelper aDataHelper(
298                         TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
299 
300                     nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
301                     DELETEZ(pDlg);
302                 }
303 
304                 // while the dialog was open, edit mode may have been stopped
305                 if (!SC_MOD()->IsInputMode())
306                 {
307                     Sound::Beep();
308                     return;
309                 }
310 
311                 if (nFormat > 0)
312                 {
313                     if (SOT_FORMAT_STRING == nFormat)
314                         pTableView->Paste();
315                     else
316                         pTableView->PasteSpecial();
317 
318                     if (pTopView)
319                         pTopView->Paste();
320                 }
321 
322                 if (pTopView)
323                     pTopView->GetWindow()->GrabFocus();
324             }
325             break;
326 
327         case SID_SELECTALL:
328             {
329                 sal_uInt16 nPar = pEngine->GetParagraphCount();
330                 if (nPar)
331                 {
332                     xub_StrLen nLen = pEngine->GetTextLen(nPar-1);
333                     pTableView->SetSelection(ESelection(0,0,nPar-1,nLen));
334                     if (pTopView)
335                         pTopView->SetSelection(ESelection(0,0,nPar-1,nLen));
336                 }
337                 bSetModified = sal_False;
338             }
339             break;
340 
341         case SID_CHARMAP:
342             {
343                 sal_uInt16 nScript = pTableView->GetSelectedScriptType();
344                 sal_uInt16 nFontWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? EE_CHAR_FONTINFO_CJK :
345                                 ( ( nScript == SCRIPTTYPE_COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
346                                                                         EE_CHAR_FONTINFO );
347                 const SvxFontItem& rItem = (const SvxFontItem&)
348                             pTableView->GetAttribs().Get(nFontWhich);
349 
350                 String aString;
351                 SvxFontItem aNewItem( EE_CHAR_FONTINFO );
352 
353                 const SfxItemSet *pArgs = rReq.GetArgs();
354                 const SfxPoolItem* pItem = 0;
355                 if( pArgs )
356                     pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
357 
358                 if ( pItem )
359                 {
360                     aString = ((const SfxStringItem*)pItem)->GetValue();
361                     const SfxPoolItem* pFtItem = NULL;
362                     pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
363                     const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
364                     if ( pFontItem )
365                     {
366                         String aFontName(pFontItem->GetValue());
367                         Font aFont(aFontName, Size(1,1)); // Size nur wg. CTOR
368                         aNewItem = SvxFontItem( aFont.GetFamily(), aFont.GetName(),
369                                     aFont.GetStyleName(), aFont.GetPitch(),
370                                     aFont.GetCharSet(), ATTR_FONT  );
371                     }
372                     else
373                         aNewItem = rItem;
374                 }
375                 else
376                 {
377                     ScViewUtil::ExecuteCharMap( rItem, *pViewData->GetViewShell()->GetViewFrame(), aNewItem, aString );
378 
379                     // while the dialog was open, edit mode may have been stopped
380                     if (!SC_MOD()->IsInputMode())
381                     {
382                         Sound::Beep();
383                         return;
384                     }
385                 }
386 
387                 if ( aString.Len() )
388                 {
389                     //  if string contains WEAK characters, set all fonts
390                     sal_uInt8 nSetScript;
391                     ScDocument* pDoc = pViewData->GetDocument();
392                     if ( pDoc->HasStringWeakCharacters( aString ) )
393                         nSetScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
394                     else
395                         nSetScript = pDoc->GetStringScriptType( aString );
396 
397                     SfxItemSet aSet( pTableView->GetEmptyItemSet() );
398                     SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() );
399                     aSetItem.PutItemForScriptType( nSetScript, aNewItem );
400                     aSet.Put( aSetItem.GetItemSet(), sal_False );
401 
402                     //  SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
403                     pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() );
404                     pTableView->InsertText(aString);
405                     if (pTopView)
406                         pTopView->InsertText(aString);
407 
408                     SfxStringItem aStringItem( SID_CHARMAP, aString );
409                     SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem.GetFamilyName() );
410                     rReq.AppendItem( aFontItem );
411                     rReq.AppendItem( aStringItem );
412                     rReq.Done();
413 
414 
415                 }
416 
417                 if (pTopView)
418                     pTopView->GetWindow()->GrabFocus();
419             }
420             break;
421 
422         case FID_INSERT_NAME:
423             {
424                 ScDocument*     pDoc = pViewData->GetDocument();
425                 //CHINA001 ScNamePasteDlg* pDlg = new ScNamePasteDlg( pViewData->GetDialogParent(),
426                 //CHINA001                              pDoc->GetRangeName(), sal_False );
427                                                 // "Liste" disablen
428                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
429                 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
430 
431                 AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pDoc->GetRangeName(), RID_SCDLG_NAMES_PASTE, sal_False );
432                 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
433                 short nRet = pDlg->Execute();
434                 // pDlg is needed below
435 
436                 // while the dialog was open, edit mode may have been stopped
437                 if (!SC_MOD()->IsInputMode())
438                 {
439                     Sound::Beep();
440                     delete pDlg;
441                     return;
442                 }
443 
444                 if ( nRet == BTN_PASTE_NAME )
445                 {
446                     String aName = pDlg->GetSelectedName();
447                     pTableView->InsertText(aName);
448                     if (pTopView)
449                         pTopView->InsertText(aName);
450                 }
451                 delete pDlg;
452 
453                 if (pTopView)
454                     pTopView->GetWindow()->GrabFocus();
455             }
456             break;
457 
458         case SID_CHAR_DLG:
459             {
460                 SfxItemSet aAttrs( pTableView->GetAttribs() );
461 
462                 SfxObjectShell* pObjSh = pViewData->GetSfxDocShell();
463 
464                 //CHINA001 ScCharDlg* pDlg = new ScCharDlg( pViewData->GetDialogParent(), &aAttrs, pObjSh );
465                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
466                 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
467 
468                 SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg( pViewData->GetDialogParent(), &aAttrs,
469                                                                      pObjSh, RID_SCDLG_CHAR );
470                 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
471                 short nRet = pDlg->Execute();
472                 // pDlg is needed below
473 
474                 // while the dialog was open, edit mode may have been stopped
475                 if (!SC_MOD()->IsInputMode())
476                 {
477                     Sound::Beep();
478                     delete pDlg;
479                     return;
480                 }
481 
482                 if ( nRet == RET_OK )
483                 {
484                     const SfxItemSet* pOut = pDlg->GetOutputItemSet();
485                     pTableView->SetAttribs( *pOut );
486                 }
487                 delete pDlg;
488             }
489             break;
490 
491         case SID_TOGGLE_REL:
492             {
493                 sal_Bool bOk = sal_False;
494                 if (pEngine->GetParagraphCount() == 1)
495                 {
496                     String aText = pEngine->GetText();
497                     ESelection aSel = pEditView->GetSelection();    // aktuelle View
498 
499                     ScRefFinder aFinder( aText, pViewData->GetDocument() );
500                     aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos );
501                     if (aFinder.GetFound())
502                     {
503                         String aNew = aFinder.GetText();
504                         ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() );
505                         pEngine->SetText( aNew );
506                         pTableView->SetSelection( aNewSel );
507                         if ( pTopView )
508                         {
509                             pTopView->GetEditEngine()->SetText( aNew );
510                             pTopView->SetSelection( aNewSel );
511                         }
512                         bOk = sal_True;
513 
514                         //  Referenz wird selektiert -> beim Tippen nicht ueberschreiben
515                         bSetSelIsRef = sal_True;
516                     }
517                 }
518                 if (!bOk)
519                     Sound::Beep();              // keine Referenzen oder mehrere Absaetze
520             }
521             break;
522 
523         case SID_HYPERLINK_SETLINK:
524             if( pReqArgs )
525             {
526                 const SfxPoolItem* pItem;
527                 if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, sal_True, &pItem ) == SFX_ITEM_SET )
528                 {
529                     const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
530                     const String& rName     = pHyper->GetName();
531                     const String& rURL      = pHyper->GetURL();
532                     const String& rTarget   = pHyper->GetTargetFrame();
533                     SvxLinkInsertMode eMode = pHyper->GetInsertMode();
534 
535                     sal_Bool bDone = sal_False;
536                     if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
537                     {
538                         const SvxURLField* pURLField = GetURLField();
539                         if ( pURLField )
540                         {
541                             //  altes Feld selektieren
542 
543                             ESelection aSel = pTableView->GetSelection();
544                             aSel.Adjust();
545                             aSel.nEndPara = aSel.nStartPara;
546                             aSel.nEndPos = aSel.nStartPos + 1;
547                             pTableView->SetSelection( aSel );
548 
549                             //  neues Feld einfuegen
550 
551                             SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
552                             aURLField.SetTargetFrame( rTarget );
553                             SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
554                             pTableView->InsertField( aURLItem );
555                             pTableView->SetSelection( aSel );       // select inserted field
556 
557                             //  #57254# jetzt doch auch Felder in der Top-View
558 
559                             if ( pTopView )
560                             {
561                                 aSel = pTopView->GetSelection();
562                                 aSel.nEndPara = aSel.nStartPara;
563                                 aSel.nEndPos = aSel.nStartPos + 1;
564                                 pTopView->SetSelection( aSel );
565                                 pTopView->InsertField( aURLItem );
566                                 pTopView->SetSelection( aSel );     // select inserted field
567                             }
568 
569                             bDone = sal_True;
570                         }
571                     }
572 
573                     if (!bDone)
574                     {
575                         pViewData->GetViewShell()->
576                             InsertURL( rName, rURL, rTarget, (sal_uInt16) eMode );
577 
578                         //  InsertURL an der ViewShell schaltet bei "Button"
579                         //  die EditShell ab, darum sofort return
580 
581                         return;
582                     }
583                 }
584             }
585             break;
586 
587             case SID_OPEN_HYPERLINK:
588                 {
589                     const SvxURLField* pURLField = GetURLField();
590                     if ( pURLField )
591                         ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
592                     return;
593                 }
594                 //break;
595 
596         case FN_INSERT_SOFT_HYPHEN:
597             lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
598         break;
599         case FN_INSERT_HARDHYPHEN:
600             lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
601         break;
602         case FN_INSERT_HARD_SPACE:
603             lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
604         break;
605         case SID_INSERT_RLM:
606             lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
607         break;
608         case SID_INSERT_LRM:
609             lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
610         break;
611         case SID_INSERT_ZWSP:
612             lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
613         break;
614         case SID_INSERT_ZWNBSP:
615             lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
616         break;
617     }
618 
619     pHdl->DataChanged(sal_False, bSetModified);
620     if (bSetSelIsRef)
621         pHdl->SetSelIsRef(sal_True);
622 }
623 
624 void lcl_DisableAll( SfxItemSet& rSet )    // disable all slots
625 {
626     SfxWhichIter aIter( rSet );
627     sal_uInt16 nWhich = aIter.FirstWhich();
628     while (nWhich)
629     {
630         rSet.DisableItem( nWhich );
631         nWhich = aIter.NextWhich();
632     }
633 }
634 
635 void __EXPORT ScEditShell::GetState( SfxItemSet& rSet )
636 {
637     // #125326# When deactivating the view, edit mode is stopped, but the EditShell is left active
638     // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
639     // into the EditEngine, so it can have an invalid selection and must not be used.
640     if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )
641     {
642         lcl_DisableAll( rSet );
643         return;
644     }
645 
646     ScInputHandler* pHdl = GetMyInputHdl();
647     EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
648 
649     SfxWhichIter aIter( rSet );
650     sal_uInt16 nWhich = aIter.FirstWhich();
651     while (nWhich)
652     {
653         switch (nWhich)
654         {
655             case SID_ATTR_INSERT:   // Statuszeile
656                 {
657                     if ( pActiveView )
658                         rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
659                     else
660                         rSet.Put( SfxBoolItem( nWhich, 42 ) );
661                 }
662                 break;
663 
664             case SID_HYPERLINK_GETLINK:
665                 {
666                     SvxHyperlinkItem aHLinkItem;
667                     const SvxURLField* pURLField = GetURLField();
668                     if ( pURLField )
669                     {
670                         aHLinkItem.SetName( pURLField->GetRepresentation() );
671                         aHLinkItem.SetURL( pURLField->GetURL() );
672                         aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
673                     }
674                     else if ( pActiveView )
675                     {
676                         // use selected text as name for urls
677                         String sReturn = pActiveView->GetSelected();
678                         sReturn.Erase(255);
679                         sReturn.EraseTrailingChars();
680                         aHLinkItem.SetName(sReturn);
681                     }
682                     rSet.Put(aHLinkItem);
683                 }
684                 break;
685 
686             case SID_OPEN_HYPERLINK:
687                 {
688                     if ( !GetURLField() )
689                         rSet.DisableItem( nWhich );
690                 }
691                 break;
692 
693             case SID_TRANSLITERATE_HALFWIDTH:
694             case SID_TRANSLITERATE_FULLWIDTH:
695             case SID_TRANSLITERATE_HIRAGANA:
696             case SID_TRANSLITERATE_KATAGANA:
697             case SID_INSERT_RLM:
698             case SID_INSERT_LRM:
699             case SID_INSERT_ZWNBSP:
700             case SID_INSERT_ZWSP:
701                 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich );
702             break;
703 
704             case SID_THES:
705                 {
706                     String          aStatusVal;
707                     LanguageType    nLang = LANGUAGE_NONE;
708                     bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, *pActiveView );
709                     rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
710 
711                     // disable thesaurus context menu entry if there is nothing to look up
712                     sal_Bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
713                     if (!bIsLookUpWord || !bCanDoThesaurus)
714                         rSet.DisableItem( SID_THES );
715                 }
716                 break;
717 
718 
719         }
720         nWhich = aIter.NextWhich();
721     }
722 }
723 
724 const SvxURLField* ScEditShell::GetURLField()
725 {
726     ScInputHandler* pHdl = GetMyInputHdl();
727     EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
728     if ( pActiveView )
729     {
730         const SvxFieldItem* pFieldItem = pActiveView->GetFieldAtSelection();
731         if (pFieldItem)
732         {
733             const SvxFieldData* pField = pFieldItem->GetField();
734             if ( pField && pField->ISA(SvxURLField) )
735                 return (const SvxURLField*)pField;
736         }
737     }
738 
739     return NULL;
740 }
741 
742 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
743 {
744     if ( pDataHelper )
745     {
746         bPastePossible = ( pDataHelper->HasFormat( SOT_FORMAT_STRING ) || pDataHelper->HasFormat( SOT_FORMAT_RTF ) );
747 
748         SfxBindings& rBindings = pViewData->GetBindings();
749         rBindings.Invalidate( SID_PASTE );
750         rBindings.Invalidate( SID_PASTE_SPECIAL );
751         rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
752     }
753     return 0;
754 }
755 
756 void __EXPORT ScEditShell::GetClipState( SfxItemSet& rSet )
757 {
758     if ( !pClipEvtLstnr )
759     {
760         // create listener
761         pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
762         pClipEvtLstnr->acquire();
763         Window* pWin = pViewData->GetActiveWin();
764         pClipEvtLstnr->AddRemoveListener( pWin, sal_True );
765 
766         // get initial state
767         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
768         bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
769     }
770 
771     SfxWhichIter aIter( rSet );
772     sal_uInt16 nWhich = aIter.FirstWhich();
773     while (nWhich)
774     {
775         switch (nWhich)
776         {
777             case SID_PASTE:
778             case SID_PASTE_SPECIAL:
779                 if( !bPastePossible )
780                     rSet.DisableItem( nWhich );
781                 break;
782             case SID_CLIPBOARD_FORMAT_ITEMS:
783                 if( bPastePossible )
784                 {
785                     SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
786                     TransferableDataHelper aDataHelper(
787                             TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
788 
789                     if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
790                         aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
791                     if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
792                         aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
793 
794                     rSet.Put( aFormats );
795                 }
796                 else
797                     rSet.DisableItem( nWhich );
798                 break;
799         }
800         nWhich = aIter.NextWhich();
801     }
802 }
803 
804 void lcl_InvalidateUnder( SfxBindings& rBindings )
805 {
806     rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
807     rBindings.Invalidate( SID_ULINE_VAL_NONE );
808     rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
809     rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
810     rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
811 }
812 
813 void ScEditShell::ExecuteAttr(SfxRequest& rReq)
814 {
815     SfxItemSet          aSet( pEditView->GetEmptyItemSet() );
816     SfxBindings&        rBindings   = pViewData->GetBindings();
817     const SfxItemSet*   pArgs       = rReq.GetArgs();
818     sal_uInt16              nSlot       = rReq.GetSlot();
819 
820     switch ( nSlot )
821     {
822         case SID_ATTR_CHAR_FONTHEIGHT:
823         case SID_ATTR_CHAR_FONT:
824             {
825                 if (pArgs)
826                 {
827                     // #i78017 establish the same behaviour as in Writer
828                     sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
829                     if (nSlot == SID_ATTR_CHAR_FONT)
830                     {
831                         nScript = pEditView->GetSelectedScriptType();
832                         if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
833                     }
834 
835                     SfxItemPool& rPool = GetPool();
836                     SvxScriptSetItem aSetItem( nSlot, rPool );
837                     sal_uInt16 nWhich = rPool.GetWhich( nSlot );
838                     aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
839 
840                     aSet.Put( aSetItem.GetItemSet(), sal_False );
841                 }
842             }
843             break;
844 
845         case SID_ATTR_CHAR_COLOR:
846             {
847                 if (pArgs)
848                 {
849                     aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
850                     rBindings.Invalidate( nSlot );
851                 }
852             }
853             break;
854 
855         //  Toggles
856 
857         case SID_ATTR_CHAR_WEIGHT:
858             {
859                 // #i78017 establish the same behaviour as in Writer
860                 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
861 
862                 SfxItemPool& rPool = GetPool();
863 
864                 sal_Bool bOld = sal_False;
865                 SvxScriptSetItem aOldSetItem( nSlot, rPool );
866                 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False );
867                 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
868                 if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() > WEIGHT_NORMAL )
869                     bOld = sal_True;
870 
871                 SvxScriptSetItem aSetItem( nSlot, rPool );
872                 aSetItem.PutItemForScriptType( nScript,
873                             SvxWeightItem( bOld ? WEIGHT_NORMAL : WEIGHT_BOLD, EE_CHAR_WEIGHT ) );
874                 aSet.Put( aSetItem.GetItemSet(), sal_False );
875 
876                 rBindings.Invalidate( nSlot );
877             }
878             break;
879 
880         case SID_ATTR_CHAR_POSTURE:
881             {
882                 // #i78017 establish the same behaviour as in Writer
883                 sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
884 
885                 SfxItemPool& rPool = GetPool();
886 
887                 sal_Bool bOld = sal_False;
888                 SvxScriptSetItem aOldSetItem( nSlot, rPool );
889                 aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False );
890                 const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
891                 if ( pCore && ((const SvxPostureItem*)pCore)->GetValue() != ITALIC_NONE )
892                     bOld = sal_True;
893 
894                 SvxScriptSetItem aSetItem( nSlot, rPool );
895                 aSetItem.PutItemForScriptType( nScript,
896                             SvxPostureItem( bOld ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
897                 aSet.Put( aSetItem.GetItemSet(), sal_False );
898 
899                 rBindings.Invalidate( nSlot );
900             }
901             break;
902 
903         case SID_ULINE_VAL_NONE:
904             aSet.Put( SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
905             lcl_InvalidateUnder( rBindings );
906             break;
907 
908         case SID_ATTR_CHAR_UNDERLINE:   // Toggles
909         case SID_ULINE_VAL_SINGLE:
910         case SID_ULINE_VAL_DOUBLE:
911         case SID_ULINE_VAL_DOTTED:
912             {
913                 FontUnderline eOld = ((const SvxUnderlineItem&) pEditView->
914                                     GetAttribs().Get(EE_CHAR_UNDERLINE)).GetLineStyle();
915                 FontUnderline eNew = eOld;
916                 switch (nSlot)
917                 {
918                     case SID_ATTR_CHAR_UNDERLINE:
919                         eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
920                         break;
921                     case SID_ULINE_VAL_SINGLE:
922                         eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
923                         break;
924                     case SID_ULINE_VAL_DOUBLE:
925                         eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
926                         break;
927                     case SID_ULINE_VAL_DOTTED:
928                         eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
929                         break;
930                 }
931                 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
932                 lcl_InvalidateUnder( rBindings );
933             }
934             break;
935 
936         case SID_ATTR_CHAR_OVERLINE:
937             {
938                 FontUnderline eOld = ((const SvxOverlineItem&) pEditView->
939                                     GetAttribs().Get(EE_CHAR_OVERLINE)).GetLineStyle();
940                 FontUnderline eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
941                 aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) );
942                 rBindings.Invalidate( nSlot );
943             }
944             break;
945 
946         case SID_ATTR_CHAR_STRIKEOUT:
947             {
948                 sal_Bool bOld = ((const SvxCrossedOutItem&)pEditView->GetAttribs().
949                                 Get(EE_CHAR_STRIKEOUT)).GetValue() != STRIKEOUT_NONE;
950                 aSet.Put( SvxCrossedOutItem( bOld ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
951                 rBindings.Invalidate( nSlot );
952             }
953             break;
954 
955         case SID_ATTR_CHAR_SHADOWED:
956             {
957                 sal_Bool bOld = ((const SvxShadowedItem&)pEditView->GetAttribs().
958                                 Get(EE_CHAR_SHADOW)).GetValue();
959                 aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) );
960                 rBindings.Invalidate( nSlot );
961             }
962             break;
963 
964         case SID_ATTR_CHAR_CONTOUR:
965             {
966                 sal_Bool bOld = ((const SvxContourItem&)pEditView->GetAttribs().
967                                 Get(EE_CHAR_OUTLINE)).GetValue();
968                 aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) );
969                 rBindings.Invalidate( nSlot );
970             }
971             break;
972 
973         case SID_SET_SUPER_SCRIPT:
974             {
975                 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
976                         pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
977                 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUPERSCRIPT) ?
978                                         SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUPERSCRIPT;
979                 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
980                 rBindings.Invalidate( nSlot );
981             }
982             break;
983         case SID_SET_SUB_SCRIPT:
984             {
985                 SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
986                         pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
987                 SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUBSCRIPT) ?
988                                         SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUBSCRIPT;
989                 aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
990                 rBindings.Invalidate( nSlot );
991             }
992             break;
993     }
994 
995     //
996     //  anwenden
997     //
998 
999     EditEngine* pEngine = pEditView->GetEditEngine();
1000     sal_Bool bOld = pEngine->GetUpdateMode();
1001     pEngine->SetUpdateMode(sal_False);
1002 
1003     pEditView->SetAttribs( aSet );
1004 
1005     pEngine->SetUpdateMode(bOld);
1006     pEditView->Invalidate();
1007 
1008     ScInputHandler* pHdl = GetMyInputHdl();
1009     pHdl->SetModified();
1010 
1011     rReq.Done();
1012 }
1013 
1014 void ScEditShell::GetAttrState(SfxItemSet &rSet)
1015 {
1016     if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )    // #125326#
1017     {
1018         lcl_DisableAll( rSet );
1019         return;
1020     }
1021 
1022     SfxItemSet aAttribs = pEditView->GetAttribs();
1023     rSet.Put( aAttribs );
1024 
1025     //  choose font info according to selection script type
1026 
1027     sal_uInt16 nScript = pEditView->GetSelectedScriptType();
1028     if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
1029 
1030     // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1031     sal_uInt16 nInputScript = nScript;
1032     if ( !pEditView->GetSelection().HasRange() )
1033     {
1034         LanguageType nInputLang = pViewData->GetActiveWin()->GetInputLanguage();
1035         if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1036             nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1037     }
1038 
1039     // #i55929# according to spec, nInputScript is used for font and font height only
1040     if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SFX_ITEM_UNKNOWN )
1041         ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript );
1042     if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SFX_ITEM_UNKNOWN )
1043         ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript );
1044     if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SFX_ITEM_UNKNOWN )
1045         ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript );
1046     if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SFX_ITEM_UNKNOWN )
1047         ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript );
1048 
1049     //  Unterstreichung
1050 
1051     SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE, sal_True );
1052     if ( eState == SFX_ITEM_DONTCARE )
1053     {
1054         rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1055         rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1056         rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1057         rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1058     }
1059     else
1060     {
1061         FontUnderline eUnderline = ((const SvxUnderlineItem&)
1062                     aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
1063         sal_uInt16 nId = SID_ULINE_VAL_NONE;
1064         switch (eUnderline)
1065         {
1066             case UNDERLINE_SINGLE:  nId = SID_ULINE_VAL_SINGLE; break;
1067             case UNDERLINE_DOUBLE:  nId = SID_ULINE_VAL_DOUBLE; break;
1068             case UNDERLINE_DOTTED:  nId = SID_ULINE_VAL_DOTTED; break;
1069             default:
1070                 break;
1071         }
1072         rSet.Put( SfxBoolItem( nId, sal_True ) );
1073     }
1074 
1075     //! Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1076     ScInputHandler* pHdl = GetMyInputHdl();
1077     if ( pHdl && pHdl->IsFormulaMode() )
1078         rSet.ClearItem( EE_CHAR_WEIGHT );   // hervorgehobene Klammern hier nicht
1079 }
1080 
1081 String ScEditShell::GetSelectionText( sal_Bool bWholeWord )
1082 {
1083     String aStrSelection;
1084 
1085     if ( pViewData->HasEditView( pViewData->GetActivePart() ) )    // #125326#
1086     {
1087         if ( bWholeWord )
1088         {
1089             EditEngine* pEngine = pEditView->GetEditEngine();
1090             ESelection  aSel = pEditView->GetSelection();
1091             String      aStrCurrentDelimiters = pEngine->GetWordDelimiters();
1092 
1093             pEngine->SetWordDelimiters( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" .,;\"'")) );
1094             aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos );
1095             pEngine->SetWordDelimiters( aStrCurrentDelimiters );
1096         }
1097         else
1098         {
1099             aStrSelection = pEditView->GetSelected();
1100         }
1101     }
1102 
1103     return aStrSelection;
1104 }
1105 
1106 void ScEditShell::ExecuteUndo(SfxRequest& rReq)
1107 {
1108     //  #81733# Undo must be handled here because it's called for both EditViews
1109 
1110     ScInputHandler* pHdl = GetMyInputHdl();
1111     DBG_ASSERT(pHdl,"no ScInputHandler");
1112     EditView* pTopView   = pHdl->GetTopView();
1113     EditView* pTableView = pHdl->GetTableView();
1114     DBG_ASSERT(pTableView,"no EditView");
1115 
1116     pHdl->DataChanging();
1117 
1118     const SfxItemSet* pReqArgs = rReq.GetArgs();
1119     sal_uInt16 nSlot = rReq.GetSlot();
1120     switch ( nSlot )
1121     {
1122         case SID_UNDO:
1123         case SID_REDO:
1124             {
1125                 sal_Bool bIsUndo = ( nSlot == SID_UNDO );
1126 
1127                 sal_uInt16 nCount = 1;
1128                 const SfxPoolItem* pItem;
1129                 if ( pReqArgs && pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
1130                     nCount = ((const SfxUInt16Item*)pItem)->GetValue();
1131 
1132                 for (sal_uInt16 i=0; i<nCount; i++)
1133                 {
1134                     if ( bIsUndo )
1135                     {
1136                         pTableView->Undo();
1137                         if (pTopView)
1138                             pTopView->Undo();
1139                     }
1140                     else
1141                     {
1142                         pTableView->Redo();
1143                         if (pTopView)
1144                             pTopView->Redo();
1145                     }
1146                 }
1147             }
1148             break;
1149     }
1150     pViewData->GetBindings().InvalidateAll(sal_False);
1151 
1152     pHdl->DataChanged();
1153 }
1154 
1155 void ScEditShell::GetUndoState(SfxItemSet &rSet)
1156 {
1157     //  Undo state is taken from normal ViewFrame state function
1158 
1159     SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
1160     if ( pViewFrm && GetUndoManager() )
1161     {
1162         SfxWhichIter aIter(rSet);
1163         sal_uInt16 nWhich = aIter.FirstWhich();
1164         while( nWhich )
1165         {
1166             pViewFrm->GetSlotState( nWhich, NULL, &rSet );
1167             nWhich = aIter.NextWhich();
1168         }
1169     }
1170 
1171     //  disable if no action in input line EditView
1172 
1173     ScInputHandler* pHdl = GetMyInputHdl();
1174     DBG_ASSERT(pHdl,"no ScInputHandler");
1175     EditView* pTopView = pHdl->GetTopView();
1176     if (pTopView)
1177     {
1178         ::svl::IUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager();
1179         if ( rTopMgr.GetUndoActionCount() == 0 )
1180             rSet.DisableItem( SID_UNDO );
1181         if ( rTopMgr.GetRedoActionCount() == 0 )
1182             rSet.DisableItem( SID_REDO );
1183     }
1184 }
1185 
1186 void ScEditShell::ExecuteTrans( SfxRequest& rReq )
1187 {
1188     sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
1189     if ( nType )
1190     {
1191         ScInputHandler* pHdl = GetMyInputHdl();
1192         DBG_ASSERT( pHdl, "no ScInputHandler" );
1193 
1194         EditView* pTopView   = pHdl->GetTopView();
1195         EditView* pTableView = pHdl->GetTableView();
1196         DBG_ASSERT( pTableView, "no EditView" );
1197 
1198         pHdl->DataChanging();
1199 
1200         pTableView->TransliterateText( nType );
1201         if (pTopView)
1202             pTopView->TransliterateText( nType );
1203 
1204         pHdl->DataChanged();
1205     }
1206 }
1207