xref: /trunk/main/sc/source/ui/view/editsh.cxx (revision c2eaa082)
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 
SFX_IMPL_INTERFACE(ScEditShell,SfxShell,ScResId (SCSTR_EDITSHELL))101 SFX_IMPL_INTERFACE(ScEditShell, SfxShell, ScResId(SCSTR_EDITSHELL))
102 {
103 	SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_EDIT) );
104 }
105 
106 
ScEditShell(EditView * pView,ScViewData * pData)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 
~ScEditShell()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 
GetMyInputHdl()134 ScInputHandler* ScEditShell::GetMyInputHdl()
135 {
136 	return SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
137 }
138 
SetEditView(EditView * pView)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 
lcl_RemoveAttribs(EditView & rEditView)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 
lclInsertCharacter(EditView * pTableView,EditView * pTopView,sal_Unicode cChar)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 
Execute(SfxRequest & rReq)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_uInt32 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 					rBindings.Invalidate( SID_ATTR_CHAR_FONT );
337 					rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
338 					rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
339 					rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
340 					rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
341 					rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
342 					rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
343 					rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
344 					rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
345 					rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
346 					rBindings.Invalidate( SID_SET_SUB_SCRIPT );
347 				}
348                 bSetModified = sal_False;
349 			}
350 			break;
351 
352 		case SID_CHARMAP:
353 			{
354 				sal_uInt16 nScript = pTableView->GetSelectedScriptType();
355 				sal_uInt16 nFontWhich = ( nScript == SCRIPTTYPE_ASIAN ) ? EE_CHAR_FONTINFO_CJK :
356 								( ( nScript == SCRIPTTYPE_COMPLEX ) ? EE_CHAR_FONTINFO_CTL :
357 																		EE_CHAR_FONTINFO );
358 				const SvxFontItem& rItem = (const SvxFontItem&)
359 							pTableView->GetAttribs().Get(nFontWhich);
360 
361 				String aString;
362 				SvxFontItem aNewItem( EE_CHAR_FONTINFO );
363 
364 				const SfxItemSet *pArgs = rReq.GetArgs();
365 				const SfxPoolItem* pItem = 0;
366 				if( pArgs )
367 					pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), sal_False, &pItem);
368 
369 				if ( pItem )
370 				{
371 					aString = ((const SfxStringItem*)pItem)->GetValue();
372 					const SfxPoolItem* pFtItem = NULL;
373 					pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), sal_False, &pFtItem);
374 					const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
375 					if ( pFontItem )
376 					{
377 						String aFontName(pFontItem->GetValue());
378 					    Font aFont(aFontName, Size(1,1)); // Size nur wg. CTOR
379 						aNewItem = SvxFontItem( aFont.GetFamily(), aFont.GetName(),
380 									aFont.GetStyleName(), aFont.GetPitch(),
381                                     aFont.GetCharSet(), ATTR_FONT  );
382 					}
383 					else
384 						aNewItem = rItem;
385 				}
386 				else
387 				{
388                     ScViewUtil::ExecuteCharMap( rItem, *pViewData->GetViewShell()->GetViewFrame(), aNewItem, aString );
389 
390 					// while the dialog was open, edit mode may have been stopped
391 					if (!SC_MOD()->IsInputMode())
392 					{
393 						Sound::Beep();
394 						return;
395 					}
396 				}
397 
398 				if ( aString.Len() )
399 				{
400 					//	if string contains WEAK characters, set all fonts
401 					sal_uInt8 nSetScript;
402 					ScDocument* pDoc = pViewData->GetDocument();
403 					if ( pDoc->HasStringWeakCharacters( aString ) )
404 						nSetScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
405 					else
406 						nSetScript = pDoc->GetStringScriptType( aString );
407 
408 					SfxItemSet aSet( pTableView->GetEmptyItemSet() );
409 					SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT, GetPool() );
410 					aSetItem.PutItemForScriptType( nSetScript, aNewItem );
411 					aSet.Put( aSetItem.GetItemSet(), sal_False );
412 
413 					//	SetAttribs an der View selektiert ein Wort, wenn nichts selektiert ist
414 					pTableView->GetEditEngine()->QuickSetAttribs( aSet, pTableView->GetSelection() );
415 					pTableView->InsertText(aString);
416 					if (pTopView)
417 						pTopView->InsertText(aString);
418 
419 					SfxStringItem aStringItem( SID_CHARMAP, aString );
420 					SfxStringItem aFontItem( SID_ATTR_SPECIALCHAR, aNewItem.GetFamilyName() );
421 					rReq.AppendItem( aFontItem );
422 					rReq.AppendItem( aStringItem );
423 					rReq.Done();
424 
425 
426 				}
427 
428 				if (pTopView)
429 					pTopView->GetWindow()->GrabFocus();
430 			}
431 			break;
432 
433 		case FID_INSERT_NAME:
434 			{
435 				ScDocument*		pDoc = pViewData->GetDocument();
436 				//CHINA001 ScNamePasteDlg* pDlg = new ScNamePasteDlg( pViewData->GetDialogParent(),
437 				//CHINA001 								pDoc->GetRangeName(), sal_False );
438 												// "Liste" disablen
439 				ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
440 				DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
441 
442 				AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pDoc->GetRangeName(), RID_SCDLG_NAMES_PASTE, sal_False );
443 				DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
444 				short nRet = pDlg->Execute();
445 				// pDlg is needed below
446 
447 				// while the dialog was open, edit mode may have been stopped
448 				if (!SC_MOD()->IsInputMode())
449 				{
450 					Sound::Beep();
451 					delete pDlg;
452 					return;
453 				}
454 
455 				if ( nRet == BTN_PASTE_NAME )
456 				{
457 					String aName = pDlg->GetSelectedName();
458 					pTableView->InsertText(aName);
459 					if (pTopView)
460 						pTopView->InsertText(aName);
461 				}
462 				delete pDlg;
463 
464 				if (pTopView)
465 					pTopView->GetWindow()->GrabFocus();
466 			}
467 			break;
468 
469 		case SID_CHAR_DLG_EFFECT:
470 		case SID_CHAR_DLG:
471 			{
472 				SfxItemSet aAttrs( pTableView->GetAttribs() );
473 
474 				SfxObjectShell* pObjSh = pViewData->GetSfxDocShell();
475 
476 				//CHINA001 ScCharDlg* pDlg = new ScCharDlg( pViewData->GetDialogParent(), &aAttrs, pObjSh );
477 				ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
478 				DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
479 
480 				SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg( pViewData->GetDialogParent(), &aAttrs,
481 																	 pObjSh, RID_SCDLG_CHAR );
482 				DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
483 				if (nSlot == SID_CHAR_DLG_EFFECT)
484 				{
485 					pDlg->SetCurPageId(RID_SVXPAGE_CHAR_EFFECTS);
486 				}
487 				short nRet = pDlg->Execute();
488 				// pDlg is needed below
489 
490 				// while the dialog was open, edit mode may have been stopped
491 				if (!SC_MOD()->IsInputMode())
492 				{
493 					Sound::Beep();
494 					delete pDlg;
495 					return;
496 				}
497 
498 				if ( nRet == RET_OK )
499 				{
500 					const SfxItemSet* pOut = pDlg->GetOutputItemSet();
501 					pTableView->SetAttribs( *pOut );
502 				}
503 				delete pDlg;
504 			}
505 			break;
506 
507 		case SID_TOGGLE_REL:
508 			{
509 				sal_Bool bOk = sal_False;
510 				if (pEngine->GetParagraphCount() == 1)
511 				{
512 					String aText = pEngine->GetText();
513 					ESelection aSel = pEditView->GetSelection();	// aktuelle View
514 
515 					ScRefFinder aFinder( aText, pViewData->GetDocument() );
516 					aFinder.ToggleRel( aSel.nStartPos, aSel.nEndPos );
517 					if (aFinder.GetFound())
518 					{
519 						String aNew = aFinder.GetText();
520 						ESelection aNewSel( 0,aFinder.GetSelStart(), 0,aFinder.GetSelEnd() );
521 						pEngine->SetText( aNew );
522 						pTableView->SetSelection( aNewSel );
523 						if ( pTopView )
524 						{
525 							pTopView->GetEditEngine()->SetText( aNew );
526 							pTopView->SetSelection( aNewSel );
527 						}
528 						bOk = sal_True;
529 
530 						//	Referenz wird selektiert -> beim Tippen nicht ueberschreiben
531 						bSetSelIsRef = sal_True;
532 					}
533 				}
534 				if (!bOk)
535                     Sound::Beep();              // keine Referenzen oder mehrere Absaetze
536 			}
537 			break;
538 
539 		case SID_HYPERLINK_SETLINK:
540 			if( pReqArgs )
541 			{
542 				const SfxPoolItem* pItem;
543 				if ( pReqArgs->GetItemState( SID_HYPERLINK_SETLINK, sal_True, &pItem ) == SFX_ITEM_SET )
544 				{
545 					const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
546 					const String& rName		= pHyper->GetName();
547 					const String& rURL		= pHyper->GetURL();
548 					const String& rTarget	= pHyper->GetTargetFrame();
549 					SvxLinkInsertMode eMode = pHyper->GetInsertMode();
550 
551 					sal_Bool bDone = sal_False;
552 					if ( eMode == HLINK_DEFAULT || eMode == HLINK_FIELD )
553 					{
554 						const SvxURLField* pURLField = GetURLField();
555 						if ( pURLField )
556 						{
557 							//	altes Feld selektieren
558 
559 							ESelection aSel = pTableView->GetSelection();
560 							aSel.Adjust();
561 							aSel.nEndPara = aSel.nStartPara;
562 							aSel.nEndPos = aSel.nStartPos + 1;
563 							pTableView->SetSelection( aSel );
564 
565 							//	neues Feld einfuegen
566 
567 							SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
568 							aURLField.SetTargetFrame( rTarget );
569                             SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
570 							pTableView->InsertField( aURLItem );
571 							pTableView->SetSelection( aSel );		// select inserted field
572 
573 							//	#57254# jetzt doch auch Felder in der Top-View
574 
575 							if ( pTopView )
576 							{
577 								aSel = pTopView->GetSelection();
578 								aSel.nEndPara = aSel.nStartPara;
579 								aSel.nEndPos = aSel.nStartPos + 1;
580 								pTopView->SetSelection( aSel );
581 								pTopView->InsertField( aURLItem );
582 								pTopView->SetSelection( aSel );		// select inserted field
583 							}
584 
585 							bDone = sal_True;
586 						}
587 					}
588 
589 					if (!bDone)
590 					{
591 						pViewData->GetViewShell()->
592 							InsertURL( rName, rURL, rTarget, (sal_uInt16) eMode );
593 
594 						//	InsertURL an der ViewShell schaltet bei "Button"
595 						//	die EditShell ab, darum sofort return
596 
597 						return;
598 					}
599 				}
600 			}
601 			break;
602 
603             case SID_OPEN_HYPERLINK:
604                 {
605                     const SvxURLField* pURLField = GetURLField();
606                     if ( pURLField )
607                         ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
608                     return;
609                 }
610                 //break;
611 
612         case FN_INSERT_SOFT_HYPHEN:
613             lclInsertCharacter( pTableView, pTopView, CHAR_SHY );
614         break;
615         case FN_INSERT_HARDHYPHEN:
616             lclInsertCharacter( pTableView, pTopView, CHAR_NBHY );
617         break;
618         case FN_INSERT_HARD_SPACE:
619             lclInsertCharacter( pTableView, pTopView, CHAR_NBSP );
620         break;
621         case SID_INSERT_RLM:
622             lclInsertCharacter( pTableView, pTopView, CHAR_RLM );
623         break;
624         case SID_INSERT_LRM:
625             lclInsertCharacter( pTableView, pTopView, CHAR_LRM );
626         break;
627         case SID_INSERT_ZWSP:
628             lclInsertCharacter( pTableView, pTopView, CHAR_ZWSP );
629         break;
630         case SID_INSERT_ZWNBSP:
631             lclInsertCharacter( pTableView, pTopView, CHAR_ZWNBSP );
632         break;
633 	}
634 
635     pHdl->DataChanged(sal_False, bSetModified);
636 	if (bSetSelIsRef)
637 		pHdl->SetSelIsRef(sal_True);
638 }
639 
lcl_DisableAll(SfxItemSet & rSet)640 void lcl_DisableAll( SfxItemSet& rSet )    // disable all slots
641 {
642     SfxWhichIter aIter( rSet );
643     sal_uInt16 nWhich = aIter.FirstWhich();
644     while (nWhich)
645     {
646         rSet.DisableItem( nWhich );
647         nWhich = aIter.NextWhich();
648     }
649 }
650 
GetState(SfxItemSet & rSet)651 void __EXPORT ScEditShell::GetState( SfxItemSet& rSet )
652 {
653     // #125326# When deactivating the view, edit mode is stopped, but the EditShell is left active
654     // (a shell can't be removed from within Deactivate). In that state, the EditView isn't inserted
655     // into the EditEngine, so it can have an invalid selection and must not be used.
656     if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )
657     {
658         lcl_DisableAll( rSet );
659         return;
660     }
661 
662 	ScInputHandler*	pHdl = GetMyInputHdl();
663 	EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
664 
665 	SfxWhichIter aIter( rSet );
666 	sal_uInt16 nWhich = aIter.FirstWhich();
667 	while (nWhich)
668 	{
669 		switch (nWhich)
670 		{
671 			case SID_ATTR_INSERT:	// Statuszeile
672 				{
673 					if ( pActiveView )
674 						rSet.Put( SfxBoolItem( nWhich, pActiveView->IsInsertMode() ) );
675 					else
676 						rSet.Put( SfxBoolItem( nWhich, 42 ) );
677 				}
678 				break;
679 
680 			case SID_HYPERLINK_GETLINK:
681 				{
682 					SvxHyperlinkItem aHLinkItem;
683 					const SvxURLField* pURLField = GetURLField();
684 					if ( pURLField )
685 					{
686 						aHLinkItem.SetName( pURLField->GetRepresentation() );
687 						aHLinkItem.SetURL( pURLField->GetURL() );
688 						aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
689 					}
690 					else if ( pActiveView )
691 					{
692 						// use selected text as name for urls
693 						String sReturn = pActiveView->GetSelected();
694 						sReturn.Erase(255);
695 						sReturn.EraseTrailingChars();
696 						aHLinkItem.SetName(sReturn);
697 					}
698 					rSet.Put(aHLinkItem);
699 				}
700 				break;
701 
702             case SID_OPEN_HYPERLINK:
703                 {
704                     if ( !GetURLField() )
705                         rSet.DisableItem( nWhich );
706                 }
707                 break;
708 
709 			case SID_TRANSLITERATE_HALFWIDTH:
710 			case SID_TRANSLITERATE_FULLWIDTH:
711 			case SID_TRANSLITERATE_HIRAGANA:
712 			case SID_TRANSLITERATE_KATAGANA:
713             case SID_INSERT_RLM:
714             case SID_INSERT_LRM:
715             case SID_INSERT_ZWNBSP:
716             case SID_INSERT_ZWSP:
717                 ScViewUtil::HideDisabledSlot( rSet, pViewData->GetBindings(), nWhich );
718             break;
719 
720             case SID_THES:
721                 {
722                     String          aStatusVal;
723                     LanguageType    nLang = LANGUAGE_NONE;
724                     bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, *pActiveView );
725                     rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
726 
727                     // disable thesaurus context menu entry if there is nothing to look up
728                     sal_Bool bCanDoThesaurus = ScModule::HasThesaurusLanguage( nLang );
729                     if (!bIsLookUpWord || !bCanDoThesaurus)
730                         rSet.DisableItem( SID_THES );
731                 }
732                 break;
733 
734 
735 		}
736 		nWhich = aIter.NextWhich();
737 	}
738 }
739 
GetURLField()740 const SvxURLField* ScEditShell::GetURLField()
741 {
742 	ScInputHandler*	pHdl = GetMyInputHdl();
743 	EditView* pActiveView = pHdl ? pHdl->GetActiveView() : pEditView;
744 	if ( pActiveView )
745 	{
746 		const SvxFieldItem*	pFieldItem = pActiveView->GetFieldAtSelection();
747 		if (pFieldItem)
748 		{
749 			const SvxFieldData* pField = pFieldItem->GetField();
750 			if ( pField && pField->ISA(SvxURLField) )
751 				return (const SvxURLField*)pField;
752 		}
753 	}
754 
755 	return NULL;
756 }
757 
IMPL_LINK(ScEditShell,ClipboardChanged,TransferableDataHelper *,pDataHelper)758 IMPL_LINK( ScEditShell, ClipboardChanged, TransferableDataHelper*, pDataHelper )
759 {
760 	if ( pDataHelper )
761 	{
762 		bPastePossible = ( pDataHelper->HasFormat( SOT_FORMAT_STRING ) || pDataHelper->HasFormat( SOT_FORMAT_RTF ) );
763 
764 		SfxBindings& rBindings = pViewData->GetBindings();
765 		rBindings.Invalidate( SID_PASTE );
766         rBindings.Invalidate( SID_PASTE_SPECIAL );
767 		rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS );
768 	}
769 	return 0;
770 }
771 
GetClipState(SfxItemSet & rSet)772 void __EXPORT ScEditShell::GetClipState( SfxItemSet& rSet )
773 {
774 	if ( !pClipEvtLstnr )
775 	{
776 		// create listener
777 		pClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScEditShell, ClipboardChanged ) );
778 		pClipEvtLstnr->acquire();
779 		Window* pWin = pViewData->GetActiveWin();
780 		pClipEvtLstnr->AddRemoveListener( pWin, sal_True );
781 
782 		// get initial state
783 		TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
784 		bPastePossible = ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) || aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
785 	}
786 
787 	SfxWhichIter aIter( rSet );
788 	sal_uInt16 nWhich = aIter.FirstWhich();
789 	while (nWhich)
790 	{
791 		switch (nWhich)
792 		{
793 			case SID_PASTE:
794             case SID_PASTE_SPECIAL:
795 				if( !bPastePossible )
796 					rSet.DisableItem( nWhich );
797 				break;
798 			case SID_CLIPBOARD_FORMAT_ITEMS:
799 				if( bPastePossible )
800 				{
801 					SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
802 					TransferableDataHelper aDataHelper(
803 							TransferableDataHelper::CreateFromSystemClipboard( pViewData->GetActiveWin() ) );
804 
805 					if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
806 						aFormats.AddClipbrdFormat( SOT_FORMAT_STRING );
807 					if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
808 						aFormats.AddClipbrdFormat( SOT_FORMAT_RTF );
809 
810 					rSet.Put( aFormats );
811 				}
812 				else
813 					rSet.DisableItem( nWhich );
814 				break;
815 		}
816 		nWhich = aIter.NextWhich();
817 	}
818 }
819 
lcl_InvalidateUnder(SfxBindings & rBindings)820 void lcl_InvalidateUnder( SfxBindings& rBindings )
821 {
822 	rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
823 	rBindings.Invalidate( SID_ULINE_VAL_NONE );
824 	rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
825 	rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
826 	rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
827 }
828 
ExecuteAttr(SfxRequest & rReq)829 void ScEditShell::ExecuteAttr(SfxRequest& rReq)
830 {
831 	SfxItemSet			aSet( pEditView->GetEmptyItemSet() );
832 	SfxBindings&		rBindings	= pViewData->GetBindings();
833 	const SfxItemSet*	pArgs		= rReq.GetArgs();
834 	sal_uInt16				nSlot		= rReq.GetSlot();
835 
836 	switch ( nSlot )
837 	{
838 		case SID_ATTR_CHAR_FONTHEIGHT:
839 		case SID_ATTR_CHAR_FONT:
840 			{
841 				if (pArgs)
842 				{
843 					// #i78017 establish the same behaviour as in Writer
844 					sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
845 					if (nSlot == SID_ATTR_CHAR_FONT)
846 					{
847 						nScript = pEditView->GetSelectedScriptType();
848 						if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
849 					}
850 
851 					SfxItemPool& rPool = GetPool();
852 					SvxScriptSetItem aSetItem( nSlot, rPool );
853 					sal_uInt16 nWhich = rPool.GetWhich( nSlot );
854 					aSetItem.PutItemForScriptType( nScript, pArgs->Get( nWhich ) );
855 
856 					aSet.Put( aSetItem.GetItemSet(), sal_False );
857 				}
858 			}
859 			break;
860 
861 		case SID_ATTR_CHAR_COLOR:
862 			{
863 				if (pArgs)
864 				{
865 					aSet.Put( pArgs->Get( pArgs->GetPool()->GetWhich( nSlot ) ) );
866 					rBindings.Invalidate( nSlot );
867 				}
868 			}
869 			break;
870 
871 		//	Toggles
872 
873 		case SID_ATTR_CHAR_WEIGHT:
874 			{
875 				// #i78017 establish the same behaviour as in Writer
876 				sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
877 
878 				SfxItemPool& rPool = GetPool();
879 
880 				sal_Bool bOld = sal_False;
881 				SvxScriptSetItem aOldSetItem( nSlot, rPool );
882 				aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False );
883 				const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
884 				if ( pCore && ((const SvxWeightItem*)pCore)->GetWeight() > WEIGHT_NORMAL )
885 					bOld = sal_True;
886 
887 				SvxScriptSetItem aSetItem( nSlot, rPool );
888 				aSetItem.PutItemForScriptType( nScript,
889 							SvxWeightItem( bOld ? WEIGHT_NORMAL : WEIGHT_BOLD, EE_CHAR_WEIGHT ) );
890 				aSet.Put( aSetItem.GetItemSet(), sal_False );
891 
892 				rBindings.Invalidate( nSlot );
893 			}
894 			break;
895 
896 		case SID_ATTR_CHAR_POSTURE:
897 			{
898 				// #i78017 establish the same behaviour as in Writer
899 				sal_uInt16 nScript = SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN | SCRIPTTYPE_COMPLEX;
900 
901 				SfxItemPool& rPool = GetPool();
902 
903 				sal_Bool bOld = sal_False;
904 				SvxScriptSetItem aOldSetItem( nSlot, rPool );
905 				aOldSetItem.GetItemSet().Put( pEditView->GetAttribs(), sal_False );
906 				const SfxPoolItem* pCore = aOldSetItem.GetItemOfScript( nScript );
907 				if ( pCore && ((const SvxPostureItem*)pCore)->GetValue() != ITALIC_NONE )
908 					bOld = sal_True;
909 
910 				SvxScriptSetItem aSetItem( nSlot, rPool );
911 				aSetItem.PutItemForScriptType( nScript,
912 							SvxPostureItem( bOld ? ITALIC_NONE : ITALIC_NORMAL, EE_CHAR_ITALIC ) );
913 				aSet.Put( aSetItem.GetItemSet(), sal_False );
914 
915 				rBindings.Invalidate( nSlot );
916 			}
917 			break;
918 
919 		case SID_ULINE_VAL_NONE:
920 			aSet.Put( SvxUnderlineItem( UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
921 			lcl_InvalidateUnder( rBindings );
922 			break;
923 
924         case SID_ATTR_CHAR_UNDERLINE:
925         case SID_ULINE_VAL_SINGLE:
926         case SID_ULINE_VAL_DOUBLE:
927         case SID_ULINE_VAL_DOTTED:
928             {
929                 FontUnderline eOld = ((const SvxUnderlineItem&) pEditView->
930                                     GetAttribs().Get(EE_CHAR_UNDERLINE)).GetLineStyle();
931                 FontUnderline eNew = eOld;
932                 switch (nSlot)
933                 {
934                     case SID_ATTR_CHAR_UNDERLINE:
935                         if ( pArgs )
936                         {
937                             const SvxTextLineItem& rTextLineItem = static_cast< const SvxTextLineItem& >( pArgs->Get( pArgs->GetPool()->GetWhich(nSlot) ) );
938                             eNew = rTextLineItem.GetLineStyle();
939                         }
940                         else
941                         {
942                             eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
943                         }
944                         break;
945                     case SID_ULINE_VAL_SINGLE:
946                         eNew = ( eOld == UNDERLINE_SINGLE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
947                         break;
948                     case SID_ULINE_VAL_DOUBLE:
949                         eNew = ( eOld == UNDERLINE_DOUBLE ) ? UNDERLINE_NONE : UNDERLINE_DOUBLE;
950                         break;
951                     case SID_ULINE_VAL_DOTTED:
952                         eNew = ( eOld == UNDERLINE_DOTTED ) ? UNDERLINE_NONE : UNDERLINE_DOTTED;
953                         break;
954                 }
955                 aSet.Put( SvxUnderlineItem( eNew, EE_CHAR_UNDERLINE ) );
956                 lcl_InvalidateUnder( rBindings );
957             }
958             break;
959 
960 		case SID_ATTR_CHAR_OVERLINE:
961 			{
962 				FontUnderline eOld = ((const SvxOverlineItem&) pEditView->
963 									GetAttribs().Get(EE_CHAR_OVERLINE)).GetLineStyle();
964 				FontUnderline eNew = ( eOld != UNDERLINE_NONE ) ? UNDERLINE_NONE : UNDERLINE_SINGLE;
965 				aSet.Put( SvxOverlineItem( eNew, EE_CHAR_OVERLINE ) );
966 				rBindings.Invalidate( nSlot );
967 			}
968 			break;
969 
970 		case SID_ATTR_CHAR_STRIKEOUT:
971 			{
972 				sal_Bool bOld = ((const SvxCrossedOutItem&)pEditView->GetAttribs().
973 								Get(EE_CHAR_STRIKEOUT)).GetValue() != STRIKEOUT_NONE;
974 				aSet.Put( SvxCrossedOutItem( bOld ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, EE_CHAR_STRIKEOUT ) );
975 				rBindings.Invalidate( nSlot );
976 			}
977 			break;
978 
979 		case SID_ATTR_CHAR_SHADOWED:
980 			{
981 				sal_Bool bOld = ((const SvxShadowedItem&)pEditView->GetAttribs().
982 								Get(EE_CHAR_SHADOW)).GetValue();
983 				aSet.Put( SvxShadowedItem( !bOld, EE_CHAR_SHADOW ) );
984 				rBindings.Invalidate( nSlot );
985 			}
986 			break;
987 
988 		case SID_ATTR_CHAR_CONTOUR:
989 			{
990 				sal_Bool bOld = ((const SvxContourItem&)pEditView->GetAttribs().
991 								Get(EE_CHAR_OUTLINE)).GetValue();
992 				aSet.Put( SvxContourItem( !bOld, EE_CHAR_OUTLINE ) );
993 				rBindings.Invalidate( nSlot );
994 			}
995 			break;
996 
997 		case SID_SET_SUPER_SCRIPT:
998 			{
999 				SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
1000 						pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1001 				SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUPERSCRIPT) ?
1002 										SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUPERSCRIPT;
1003 				aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1004 				rBindings.Invalidate( nSlot );
1005 			}
1006 			break;
1007 		case SID_SET_SUB_SCRIPT:
1008 			{
1009 				SvxEscapement eOld = (SvxEscapement) ((const SvxEscapementItem&)
1010 						pEditView->GetAttribs().Get(EE_CHAR_ESCAPEMENT)).GetEnumValue();
1011 				SvxEscapement eNew = (eOld == SVX_ESCAPEMENT_SUBSCRIPT) ?
1012 										SVX_ESCAPEMENT_OFF : SVX_ESCAPEMENT_SUBSCRIPT;
1013 				aSet.Put( SvxEscapementItem( eNew, EE_CHAR_ESCAPEMENT ) );
1014 				rBindings.Invalidate( nSlot );
1015 			}
1016 			break;
1017 		case SID_ATTR_CHAR_KERNING:
1018 			{
1019 				if(pArgs)
1020 				{
1021 					aSet.Put ( pArgs->Get(pArgs->GetPool()->GetWhich(nSlot)));
1022 					rBindings.Invalidate( nSlot );
1023 				}
1024 			}
1025 			break;
1026 	}
1027 
1028 	//
1029 	//	anwenden
1030 	//
1031 
1032 	EditEngine* pEngine = pEditView->GetEditEngine();
1033 	sal_Bool bOld = pEngine->GetUpdateMode();
1034 	pEngine->SetUpdateMode(sal_False);
1035 
1036 	pEditView->SetAttribs( aSet );
1037 
1038 	pEngine->SetUpdateMode(bOld);
1039 	pEditView->Invalidate();
1040 
1041 	ScInputHandler* pHdl = GetMyInputHdl();
1042 	pHdl->SetModified();
1043 
1044 	rReq.Done();
1045 }
1046 
GetAttrState(SfxItemSet & rSet)1047 void ScEditShell::GetAttrState(SfxItemSet &rSet)
1048 {
1049     if ( !pViewData->HasEditView( pViewData->GetActivePart() ) )    // #125326#
1050     {
1051         lcl_DisableAll( rSet );
1052         return;
1053     }
1054 
1055 	SfxItemSet aAttribs = pEditView->GetAttribs();
1056 	rSet.Put( aAttribs );
1057 
1058 	//	choose font info according to selection script type
1059 
1060 	sal_uInt16 nScript = pEditView->GetSelectedScriptType();
1061 	if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
1062 
1063     // #i55929# input-language-dependent script type (depends on input language if nothing selected)
1064     sal_uInt16 nInputScript = nScript;
1065     if ( !pEditView->GetSelection().HasRange() )
1066     {
1067         LanguageType nInputLang = pViewData->GetActiveWin()->GetInputLanguage();
1068         if (nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
1069             nInputScript = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
1070     }
1071 
1072     // #i55929# according to spec, nInputScript is used for font and font height only
1073 	if ( rSet.GetItemState( EE_CHAR_FONTINFO ) != SFX_ITEM_UNKNOWN )
1074 		ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTINFO, nInputScript );
1075 	if ( rSet.GetItemState( EE_CHAR_FONTHEIGHT ) != SFX_ITEM_UNKNOWN )
1076 		ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_FONTHEIGHT, nInputScript );
1077 	if ( rSet.GetItemState( EE_CHAR_WEIGHT ) != SFX_ITEM_UNKNOWN )
1078 		ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_WEIGHT, nScript );
1079 	if ( rSet.GetItemState( EE_CHAR_ITALIC ) != SFX_ITEM_UNKNOWN )
1080 		ScViewUtil::PutItemScript( rSet, aAttribs, EE_CHAR_ITALIC, nScript );
1081 
1082 	//	Unterstreichung
1083 
1084 	SfxItemState eState = aAttribs.GetItemState( EE_CHAR_UNDERLINE, sal_True );
1085 	if ( eState == SFX_ITEM_DONTCARE )
1086 	{
1087 		rSet.InvalidateItem( SID_ULINE_VAL_NONE );
1088 		rSet.InvalidateItem( SID_ULINE_VAL_SINGLE );
1089 		rSet.InvalidateItem( SID_ULINE_VAL_DOUBLE );
1090 		rSet.InvalidateItem( SID_ULINE_VAL_DOTTED );
1091 	}
1092 	else
1093 	{
1094 		FontUnderline eUnderline = ((const SvxUnderlineItem&)
1095 					aAttribs.Get(EE_CHAR_UNDERLINE)).GetLineStyle();
1096 		sal_uInt16 nId = SID_ULINE_VAL_NONE;
1097 		switch (eUnderline)
1098 		{
1099 			case UNDERLINE_SINGLE:	nId = SID_ULINE_VAL_SINGLE;	break;
1100 			case UNDERLINE_DOUBLE:	nId = SID_ULINE_VAL_DOUBLE;	break;
1101 			case UNDERLINE_DOTTED:	nId = SID_ULINE_VAL_DOTTED;	break;
1102 			default:
1103 				break;
1104 		}
1105 		rSet.Put( SfxBoolItem( nId, sal_True ) );
1106 	}
1107 
1108 	//!	Testen, ob Klammer-Hervorhebung aktiv ist !!!!
1109 	ScInputHandler* pHdl = GetMyInputHdl();
1110 	if ( pHdl && pHdl->IsFormulaMode() )
1111 		rSet.ClearItem( EE_CHAR_WEIGHT );	// hervorgehobene Klammern hier nicht
1112 
1113 	SvxEscapement eEsc = (SvxEscapement) ( (const SvxEscapementItem&)
1114 					aAttribs.Get( EE_CHAR_ESCAPEMENT ) ).GetEnumValue();
1115 	if( eEsc == SVX_ESCAPEMENT_SUPERSCRIPT )
1116 	{
1117 		rSet.Put( SfxBoolItem( SID_SET_SUPER_SCRIPT, sal_True ) );
1118 	}
1119 	else if( eEsc == SVX_ESCAPEMENT_SUBSCRIPT )
1120 	{
1121 		rSet.Put( SfxBoolItem( SID_SET_SUB_SCRIPT, sal_True ) );
1122 	}
1123 	pViewData->GetBindings().Invalidate( SID_SET_SUPER_SCRIPT );
1124 	pViewData->GetBindings().Invalidate( SID_SET_SUB_SCRIPT );
1125 
1126 	eState = aAttribs.GetItemState( EE_CHAR_KERNING, sal_True );
1127 	pViewData->GetBindings().Invalidate( SID_ATTR_CHAR_KERNING );
1128 	if ( eState == SFX_ITEM_DONTCARE )
1129 	{
1130 	//	rSet.InvalidateItem( SID_ATTR_CHAR_KERNING );
1131 		rSet.InvalidateItem(EE_CHAR_KERNING);
1132 	}
1133 }
1134 
GetSelectionText(sal_Bool bWholeWord)1135 String ScEditShell::GetSelectionText( sal_Bool bWholeWord )
1136 {
1137 	String aStrSelection;
1138 
1139     if ( pViewData->HasEditView( pViewData->GetActivePart() ) )    // #125326#
1140     {
1141         if ( bWholeWord )
1142         {
1143             EditEngine* pEngine = pEditView->GetEditEngine();
1144             ESelection  aSel = pEditView->GetSelection();
1145             String      aStrCurrentDelimiters = pEngine->GetWordDelimiters();
1146 
1147             pEngine->SetWordDelimiters( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(" .,;\"'")) );
1148             aStrSelection = pEngine->GetWord( aSel.nEndPara, aSel.nEndPos );
1149             pEngine->SetWordDelimiters( aStrCurrentDelimiters );
1150         }
1151         else
1152         {
1153             aStrSelection = pEditView->GetSelected();
1154         }
1155     }
1156 
1157 	return aStrSelection;
1158 }
1159 
ExecuteUndo(SfxRequest & rReq)1160 void ScEditShell::ExecuteUndo(SfxRequest& rReq)
1161 {
1162 	//	#81733# Undo must be handled here because it's called for both EditViews
1163 
1164 	ScInputHandler* pHdl = GetMyInputHdl();
1165 	DBG_ASSERT(pHdl,"no ScInputHandler");
1166 	EditView* pTopView	 = pHdl->GetTopView();
1167 	EditView* pTableView = pHdl->GetTableView();
1168 	DBG_ASSERT(pTableView,"no EditView");
1169 
1170 	pHdl->DataChanging();
1171 
1172 	const SfxItemSet* pReqArgs = rReq.GetArgs();
1173 	sal_uInt16 nSlot = rReq.GetSlot();
1174 	switch ( nSlot )
1175 	{
1176 		case SID_UNDO:
1177 		case SID_REDO:
1178 			{
1179 				sal_Bool bIsUndo = ( nSlot == SID_UNDO );
1180 
1181 				sal_uInt16 nCount = 1;
1182 				const SfxPoolItem* pItem;
1183 				if ( pReqArgs && pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
1184 					nCount = ((const SfxUInt16Item*)pItem)->GetValue();
1185 
1186 				for (sal_uInt16 i=0; i<nCount; i++)
1187 				{
1188 					if ( bIsUndo )
1189 					{
1190 						pTableView->Undo();
1191 						if (pTopView)
1192 							pTopView->Undo();
1193 					}
1194 					else
1195 					{
1196 						pTableView->Redo();
1197 						if (pTopView)
1198 							pTopView->Redo();
1199 					}
1200 				}
1201 			}
1202 			break;
1203 	}
1204 	pViewData->GetBindings().InvalidateAll(sal_False);
1205 
1206 	pHdl->DataChanged();
1207 }
1208 
GetUndoState(SfxItemSet & rSet)1209 void ScEditShell::GetUndoState(SfxItemSet &rSet)
1210 {
1211 	//	Undo state is taken from normal ViewFrame state function
1212 
1213 	SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
1214 	if ( pViewFrm && GetUndoManager() )
1215 	{
1216 		SfxWhichIter aIter(rSet);
1217 		sal_uInt16 nWhich = aIter.FirstWhich();
1218 		while( nWhich )
1219 		{
1220 			pViewFrm->GetSlotState( nWhich, NULL, &rSet );
1221 			nWhich = aIter.NextWhich();
1222 		}
1223 	}
1224 
1225 	//	disable if no action in input line EditView
1226 
1227 	ScInputHandler* pHdl = GetMyInputHdl();
1228 	DBG_ASSERT(pHdl,"no ScInputHandler");
1229 	EditView* pTopView = pHdl->GetTopView();
1230 	if (pTopView)
1231 	{
1232 		::svl::IUndoManager& rTopMgr = pTopView->GetEditEngine()->GetUndoManager();
1233 		if ( rTopMgr.GetUndoActionCount() == 0 )
1234 			rSet.DisableItem( SID_UNDO );
1235 		if ( rTopMgr.GetRedoActionCount() == 0 )
1236 			rSet.DisableItem( SID_REDO );
1237 	}
1238 }
1239 
ExecuteTrans(SfxRequest & rReq)1240 void ScEditShell::ExecuteTrans( SfxRequest& rReq )
1241 {
1242 	sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
1243 	if ( nType )
1244 	{
1245 		ScInputHandler* pHdl = GetMyInputHdl();
1246 		DBG_ASSERT( pHdl, "no ScInputHandler" );
1247 
1248 		EditView* pTopView	 = pHdl->GetTopView();
1249 		EditView* pTableView = pHdl->GetTableView();
1250 		DBG_ASSERT( pTableView, "no EditView" );
1251 
1252 		pHdl->DataChanging();
1253 
1254 		pTableView->TransliterateText( nType );
1255 		if (pTopView)
1256 			pTopView->TransliterateText( nType );
1257 
1258 		pHdl->DataChanged();
1259 	}
1260 }
1261