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