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