Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <editeng/eeitem.hxx>
31 : :
32 : : #include <editeng/editobj.hxx>
33 : : #include <editeng/editstat.hxx>
34 : : #include <editeng/editview.hxx>
35 : : #include <editeng/flditem.hxx>
36 : : #include <svx/hlnkitem.hxx>
37 : : #include <editeng/langitem.hxx>
38 : : #include <svx/svxerr.hxx>
39 : : #include <editeng/unolingu.hxx>
40 : :
41 : : #include <sfx2/bindings.hxx>
42 : : #include <sfx2/dispatch.hxx>
43 : : #include <sfx2/docfile.hxx>
44 : : #include <sfx2/fcontnr.hxx>
45 : : #include <svtools/langtab.hxx>
46 : : #include <svtools/filter.hxx>
47 : : #include <svl/stritem.hxx>
48 : : #include <svtools/transfer.hxx>
49 : : #include <svl/urlbmk.hxx>
50 : : #include <vcl/msgbox.hxx>
51 : : #include <avmedia/mediawindow.hxx>
52 : :
53 : : #include <comphelper/storagehelper.hxx>
54 : : #include <comphelper/processfactory.hxx>
55 : :
56 : : #include "viewfunc.hxx"
57 : : #include "docsh.hxx"
58 : : #include "document.hxx"
59 : : #include "docpool.hxx"
60 : : #include "globstr.hrc"
61 : : #include "global.hxx"
62 : : #include "undoblk.hxx"
63 : : #include "undocell.hxx"
64 : : #include "cell.hxx"
65 : : #include "scmod.hxx"
66 : : #include "spelleng.hxx"
67 : : #include "patattr.hxx"
68 : : #include "sc.hrc"
69 : : #include "tabvwsh.hxx"
70 : : #include "impex.hxx"
71 : : #include "editutil.hxx"
72 : : #include "editable.hxx"
73 : : #include "dociter.hxx"
74 : : #include "reffind.hxx"
75 : : #include "compiler.hxx"
76 : :
77 : : using namespace com::sun::star;
78 : :
79 : : // STATIC DATA -----------------------------------------------------------
80 : :
81 : : sal_Bool bPasteIsDrop = false;
82 : :
83 : : //==================================================================
84 : :
85 : 0 : void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
86 : : const ::com::sun::star::uno::Reference<
87 : : ::com::sun::star::datatransfer::XTransferable >& rxTransferable )
88 : : {
89 [ # # ]: 0 : TransferableDataHelper aDataHelper( rxTransferable );
90 [ # # ][ # # ]: 0 : if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EDITENGINE ) )
91 : : {
92 [ # # ]: 0 : HideAllCursors();
93 : :
94 : 0 : ScDocument* pUndoDoc = NULL;
95 : :
96 : 0 : ScDocShell* pDocSh = GetViewData()->GetDocShell();
97 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
98 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
99 : 0 : const sal_Bool bRecord (pDoc->IsUndoEnabled());
100 : :
101 [ # # ]: 0 : const ScPatternAttr* pPattern = pDoc->GetPattern( nStartCol, nStartRow, nTab );
102 [ # # ][ # # ]: 0 : ScTabEditEngine* pEngine = new ScTabEditEngine( *pPattern, pDoc->GetEnginePool() );
[ # # ]
103 [ # # ]: 0 : pEngine->EnableUndo( false );
104 : :
105 [ # # ]: 0 : Window* pActWin = GetActiveWin();
106 [ # # ]: 0 : if (pActWin)
107 : : {
108 [ # # ]: 0 : pEngine->SetPaperSize(Size(100000,100000));
109 [ # # ]: 0 : Window aWin( pActWin );
110 [ # # ][ # # ]: 0 : EditView aEditView( pEngine, &aWin );
111 [ # # ][ # # ]: 0 : aEditView.SetOutputArea(Rectangle(0,0,100000,100000));
112 : :
113 : : // same method now for clipboard or drag&drop
114 : : // mba: clipboard always must contain absolute URLs (could be from alien source)
115 [ # # ][ # # ]: 0 : aEditView.InsertText( rxTransferable, String(), sal_True );
[ # # ][ # # ]
[ # # ]
116 : : }
117 : :
118 [ # # ]: 0 : sal_uLong nParCnt = pEngine->GetParagraphCount();
119 [ # # ]: 0 : if (nParCnt)
120 : : {
121 : 0 : SCROW nEndRow = nStartRow + static_cast<SCROW>(nParCnt) - 1;
122 [ # # ]: 0 : if (nEndRow > MAXROW)
123 : 0 : nEndRow = MAXROW;
124 : :
125 [ # # ]: 0 : if (bRecord)
126 : : {
127 [ # # ][ # # ]: 0 : pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
128 [ # # ]: 0 : pUndoDoc->InitUndo( pDoc, nTab, nTab );
129 [ # # ]: 0 : pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL, false, pUndoDoc );
130 : : }
131 : :
132 : 0 : SCROW nRow = nStartRow;
133 : :
134 : : // Temporarily turn off undo generation for this lot
135 : 0 : bool bUndoEnabled = pDoc->IsUndoEnabled();
136 [ # # ]: 0 : pDoc->EnableUndo( false );
137 [ # # ]: 0 : for( sal_uInt16 n = 0; n < nParCnt; n++ )
138 : : {
139 [ # # ]: 0 : EditTextObject* pObject = pEngine->CreateTextObject( n );
140 [ # # ]: 0 : EnterData( nStartCol, nRow, nTab, pObject, true );
141 [ # # ][ # # ]: 0 : delete pObject;
142 [ # # ]: 0 : if( ++nRow > MAXROW )
143 : 0 : break;
144 : : }
145 [ # # ]: 0 : pDoc->EnableUndo(bUndoEnabled);
146 : :
147 [ # # ]: 0 : if (bRecord)
148 : : {
149 [ # # ][ # # ]: 0 : ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
150 [ # # ]: 0 : pRedoDoc->InitUndo( pDoc, nTab, nTab );
151 [ # # ]: 0 : pDoc->CopyToDocument( nStartCol,nStartRow,nTab, nStartCol,nEndRow,nTab, IDF_ALL|IDF_NOCAPTIONS, false, pRedoDoc );
152 : :
153 [ # # ]: 0 : ScMarkData aDestMark;
154 [ # # ]: 0 : aDestMark.SelectOneTable( nTab );
155 [ # # ]: 0 : pDocSh->GetUndoManager()->AddUndoAction(
156 : : new ScUndoPaste(
157 : : pDocSh, ScRange(nStartCol, nStartRow, nTab, nStartCol, nEndRow, nTab),
158 [ # # ][ # # ]: 0 : aDestMark, pUndoDoc, pRedoDoc, IDF_ALL, NULL));
[ # # ][ # # ]
[ # # ][ # # ]
159 : : }
160 : : }
161 : :
162 [ # # ][ # # ]: 0 : delete pEngine;
163 : :
164 [ # # ]: 0 : ShowAllCursors();
165 : : }
166 : : else
167 : : {
168 [ # # ]: 0 : HideAllCursors();
169 : 0 : ScDocShell* pDocSh = GetViewData()->GetDocShell();
170 : : ScImportExport aImpEx( pDocSh->GetDocument(),
171 [ # # ]: 0 : ScAddress( nStartCol, nStartRow, GetViewData()->GetTabNo() ) );
172 : :
173 : 0 : ::rtl::OUString aStr;
174 : 0 : SotStorageStreamRef xStream;
175 [ # # ][ # # ]: 0 : if ( aDataHelper.GetSotStorageStream( SOT_FORMAT_RTF, xStream ) && xStream.Is() )
[ # # ][ # # ]
176 : : // mba: clipboard always must contain absolute URLs (could be from alien source)
177 [ # # ][ # # ]: 0 : aImpEx.ImportStream( *xStream, String(), SOT_FORMAT_RTF );
[ # # ]
178 [ # # ][ # # ]: 0 : else if ( aDataHelper.GetString( SOT_FORMAT_RTF, aStr ) )
179 [ # # ]: 0 : aImpEx.ImportString( aStr, SOT_FORMAT_RTF );
180 : :
181 [ # # ]: 0 : AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row() );
182 [ # # ]: 0 : pDocSh->UpdateOle(GetViewData());
183 [ # # ][ # # ]: 0 : ShowAllCursors();
[ # # ]
184 [ # # ]: 0 : }
185 : 0 : }
186 : 0 : void ScViewFunc::DoRefConversion( sal_Bool bRecord )
187 : : {
188 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
189 [ # # ]: 0 : ScMarkData& rMark = GetViewData()->GetMarkData();
190 [ # # ]: 0 : SCTAB nTabCount = pDoc->GetTableCount();
191 [ # # ][ # # ]: 0 : if (bRecord && !pDoc->IsUndoEnabled())
[ # # ]
192 : 0 : bRecord = false;
193 : :
194 : 0 : ScRange aMarkRange;
195 [ # # ]: 0 : rMark.MarkToSimple();
196 : 0 : sal_Bool bMulti = rMark.IsMultiMarked();
197 [ # # ]: 0 : if (bMulti)
198 [ # # ]: 0 : rMark.GetMultiMarkArea( aMarkRange );
199 [ # # ]: 0 : else if (rMark.IsMarked())
200 [ # # ]: 0 : rMark.GetMarkArea( aMarkRange );
201 : : else
202 : : {
203 : 0 : aMarkRange = ScRange( GetViewData()->GetCurX(),
204 : 0 : GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
205 : : }
206 : 0 : ScEditableTester aTester( pDoc, aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
207 [ # # ]: 0 : aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(),rMark );
208 [ # # ]: 0 : if (!aTester.IsEditable())
209 : : {
210 [ # # ][ # # ]: 0 : ErrorMessage(aTester.GetMessageId());
211 : 0 : return;
212 : : }
213 : :
214 : 0 : ScDocShell* pDocSh = GetViewData()->GetDocShell();
215 : 0 : sal_Bool bOk = false;
216 : :
217 : 0 : ScDocument* pUndoDoc = NULL;
218 [ # # ]: 0 : if (bRecord)
219 : : {
220 [ # # ][ # # ]: 0 : pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
221 : 0 : SCTAB nTab = aMarkRange.aStart.Tab();
222 [ # # ]: 0 : pUndoDoc->InitUndo( pDoc, nTab, nTab );
223 : :
224 [ # # ][ # # ]: 0 : if ( rMark.GetSelectCount() > 1 )
225 : : {
226 [ # # ][ # # ]: 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
227 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
228 [ # # ][ # # ]: 0 : if ( *itr != nTab )
229 [ # # ][ # # ]: 0 : pUndoDoc->AddUndoTab( *itr, *itr );
[ # # ]
230 : : }
231 : 0 : ScRange aCopyRange = aMarkRange;
232 : 0 : aCopyRange.aStart.SetTab(0);
233 : 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
234 [ # # ]: 0 : pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pUndoDoc, &rMark );
235 : : }
236 : :
237 : 0 : ScRangeListRef xRanges;
238 [ # # ]: 0 : GetViewData()->GetMultiArea( xRanges );
239 [ # # ]: 0 : size_t nCount = xRanges->size();
240 : :
241 [ # # ][ # # ]: 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
242 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
243 : : {
244 [ # # ]: 0 : SCTAB i = *itr;
245 [ # # ]: 0 : for (size_t j = 0; j < nCount; ++j)
246 : : {
247 [ # # ]: 0 : ScRange aRange = *(*xRanges)[j];
248 : 0 : aRange.aStart.SetTab(i);
249 : 0 : aRange.aEnd.SetTab(i);
250 [ # # ]: 0 : ScCellIterator aIter( pDoc, aRange );
251 [ # # ]: 0 : ScBaseCell* pCell = aIter.GetFirst();
252 [ # # ]: 0 : while ( pCell )
253 : : {
254 [ # # ]: 0 : if (pCell->GetCellType() == CELLTYPE_FORMULA)
255 : : {
256 : 0 : rtl::OUString aOld;
257 [ # # ][ # # ]: 0 : ((ScFormulaCell*)pCell)->GetFormula(aOld);
258 : 0 : xub_StrLen nLen = aOld.getLength();
259 [ # # ][ # # ]: 0 : ScRefFinder aFinder( aOld, aIter.GetPos(), pDoc, pDoc->GetAddressConvention() );
[ # # ][ # # ]
260 [ # # ]: 0 : aFinder.ToggleRel( 0, nLen );
261 [ # # ]: 0 : if (aFinder.GetFound())
262 : : {
263 [ # # ]: 0 : ScAddress aPos = ((ScFormulaCell*)pCell)->aPos;
264 [ # # ]: 0 : String aNew = aFinder.GetText();
265 [ # # ]: 0 : ScCompiler aComp( pDoc, aPos);
266 [ # # ][ # # ]: 0 : aComp.SetGrammar(pDoc->GetGrammar());
267 [ # # ]: 0 : ScTokenArray* pArr = aComp.CompileString( aNew );
268 : : ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos,
269 [ # # ][ # # ]: 0 : pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE );
270 [ # # ][ # # ]: 0 : pDoc->PutCell( aPos, pNewCell );
271 [ # # ][ # # ]: 0 : bOk = sal_True;
272 [ # # ]: 0 : }
273 : : }
274 [ # # ]: 0 : pCell = aIter.GetNext();
275 : : }
276 : : }
277 : : }
278 [ # # ]: 0 : if (bRecord)
279 : : {
280 [ # # ][ # # ]: 0 : ScDocument* pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
281 : 0 : SCTAB nTab = aMarkRange.aStart.Tab();
282 [ # # ]: 0 : pRedoDoc->InitUndo( pDoc, nTab, nTab );
283 : :
284 [ # # ][ # # ]: 0 : if ( rMark.GetSelectCount() > 1 )
285 : : {
286 [ # # ]: 0 : itr = rMark.begin();
287 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
288 [ # # ][ # # ]: 0 : if ( *itr != nTab )
289 [ # # ][ # # ]: 0 : pRedoDoc->AddUndoTab( *itr, *itr );
[ # # ]
290 : : }
291 : 0 : ScRange aCopyRange = aMarkRange;
292 : 0 : aCopyRange.aStart.SetTab(0);
293 : 0 : aCopyRange.aEnd.SetTab(nTabCount-1);
294 [ # # ]: 0 : pDoc->CopyToDocument( aCopyRange, IDF_ALL, bMulti, pRedoDoc, &rMark );
295 : :
296 [ # # ]: 0 : pDocSh->GetUndoManager()->AddUndoAction(
297 : : new ScUndoRefConversion( pDocSh,
298 [ # # ][ # # ]: 0 : aMarkRange, rMark, pUndoDoc, pRedoDoc, bMulti, IDF_ALL) );
[ # # ]
299 : : }
300 : :
301 [ # # ][ # # ]: 0 : pDocSh->PostPaint( aMarkRange, PAINT_GRID );
[ # # ]
302 [ # # ]: 0 : pDocSh->UpdateOle(GetViewData());
303 [ # # ]: 0 : pDocSh->SetDocumentModified();
304 [ # # ]: 0 : CellContentChanged();
305 : :
306 [ # # ]: 0 : if (!bOk)
307 [ # # ][ # # ]: 0 : ErrorMessage(STR_ERR_NOREF);
[ # # ]
308 : : }
309 : : // Thesaurus - Undo ok
310 : 0 : void ScViewFunc::DoThesaurus( sal_Bool bRecord )
311 : : {
312 : : SCCOL nCol;
313 : : SCROW nRow;
314 : : SCTAB nTab;
315 : 0 : ScDocShell* pDocSh = GetViewData()->GetDocShell();
316 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
317 [ # # ]: 0 : ScMarkData& rMark = GetViewData()->GetMarkData();
318 : 0 : ScSplitPos eWhich = GetViewData()->GetActivePart();
319 : : CellType eCellType;
320 : : EESpellState eState;
321 [ # # ][ # # ]: 0 : String sOldText, sNewString;
322 : 0 : EditTextObject* pOldTObj = NULL;
323 : 0 : const EditTextObject* pTObject = NULL;
324 : 0 : ScBaseCell* pCell = NULL;
325 : 0 : EditView* pEditView = NULL;
326 : 0 : ESelection* pEditSel = NULL;
327 : : ScEditEngineDefaulter* pThesaurusEngine;
328 : 0 : sal_Bool bIsEditMode = GetViewData()->HasEditView(eWhich);
329 [ # # ][ # # ]: 0 : if (bRecord && !pDoc->IsUndoEnabled())
[ # # ]
330 : 0 : bRecord = false;
331 [ # # ]: 0 : if (bIsEditMode) // Edit-Mode aktiv
332 : : {
333 [ # # ]: 0 : GetViewData()->GetEditView(eWhich, pEditView, nCol, nRow);
334 [ # # ][ # # ]: 0 : pEditSel = new ESelection(pEditView->GetSelection());
335 [ # # ][ # # ]: 0 : SC_MOD()->InputEnterHandler();
336 [ # # ][ # # ]: 0 : GetViewData()->GetBindings().Update(); // sonst kommt der Sfx durcheinander...
337 : : }
338 : : else
339 : : {
340 : 0 : nCol = GetViewData()->GetCurX();
341 : 0 : nRow = GetViewData()->GetCurY();
342 : : }
343 : 0 : nTab = GetViewData()->GetTabNo();
344 : :
345 [ # # ]: 0 : ScEditableTester aTester( pDoc, nCol, nRow, nCol, nRow, rMark );
346 [ # # ]: 0 : if (!aTester.IsEditable())
347 : : {
348 [ # # ][ # # ]: 0 : ErrorMessage(aTester.GetMessageId());
349 : 0 : delete pEditSel;
350 : : return;
351 : : }
352 [ # # ]: 0 : pDoc->GetCellType(nCol, nRow, nTab, eCellType);
353 [ # # ][ # # ]: 0 : if (eCellType != CELLTYPE_STRING && eCellType != CELLTYPE_EDIT)
354 : : {
355 [ # # ]: 0 : ErrorMessage(STR_THESAURUS_NO_STRING);
356 : : return;
357 : : }
358 : :
359 : : com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1>
360 [ # # ]: 0 : xSpeller = LinguMgr::GetSpellChecker();
361 : :
362 [ # # ][ # # ]: 0 : pThesaurusEngine = new ScEditEngineDefaulter( pDoc->GetEnginePool() );
[ # # ]
363 [ # # ][ # # ]: 0 : pThesaurusEngine->SetEditTextObjectPool( pDoc->GetEditPool() );
364 [ # # ][ # # ]: 0 : pThesaurusEngine->SetRefDevice(GetViewData()->GetActiveWin());
365 [ # # ]: 0 : pThesaurusEngine->SetSpeller(xSpeller);
366 [ # # ]: 0 : MakeEditView(pThesaurusEngine, nCol, nRow );
367 : 0 : const ScPatternAttr* pPattern = NULL;
368 [ # # ][ # # ]: 0 : SfxItemSet* pEditDefaults = new SfxItemSet(pThesaurusEngine->GetEmptyItemSet());
[ # # ]
369 [ # # ]: 0 : pPattern = pDoc->GetPattern(nCol, nRow, nTab);
370 [ # # ]: 0 : if (pPattern )
371 : : {
372 [ # # ]: 0 : pPattern->FillEditItemSet( pEditDefaults );
373 [ # # ]: 0 : pThesaurusEngine->SetDefaults( *pEditDefaults );
374 : : }
375 : :
376 [ # # ]: 0 : if (eCellType == CELLTYPE_STRING)
377 : : {
378 [ # # ]: 0 : pDoc->GetString(nCol, nRow, nTab, sOldText);
379 [ # # ]: 0 : pThesaurusEngine->SetText(sOldText);
380 : : }
381 [ # # ]: 0 : else if (eCellType == CELLTYPE_EDIT)
382 : : {
383 [ # # ]: 0 : pDoc->GetCell(nCol, nRow, nTab, pCell);
384 [ # # ]: 0 : if (pCell)
385 : : {
386 [ # # ]: 0 : ((ScEditCell*) pCell)->GetData(pTObject);
387 [ # # ]: 0 : if (pTObject)
388 : : {
389 [ # # ]: 0 : pOldTObj = pTObject->Clone();
390 [ # # ]: 0 : pThesaurusEngine->SetText(*pTObject);
391 : : }
392 : : }
393 : : }
394 : : else
395 : : {
396 : : OSL_FAIL("DoThesaurus: Keine String oder Editzelle");
397 : : }
398 : 0 : pEditView = GetViewData()->GetEditView(GetViewData()->GetActivePart());
399 [ # # ]: 0 : if (pEditSel)
400 [ # # ]: 0 : pEditView->SetSelection(*pEditSel);
401 : : else
402 [ # # ]: 0 : pEditView->SetSelection(ESelection(0,0,0,0));
403 : :
404 [ # # ]: 0 : pThesaurusEngine->ClearModifyFlag();
405 : :
406 : : // language is now in EditEngine attributes -> no longer passed to StartThesaurus
407 : :
408 [ # # ]: 0 : eState = pEditView->StartThesaurus();
409 : : OSL_ENSURE(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
410 : :
411 [ # # ]: 0 : if (eState == EE_SPELL_ERRORFOUND) // sollte spaeter durch Wrapper geschehen!
412 : : {
413 [ # # ]: 0 : LanguageType eLnge = ScViewUtil::GetEffLanguage( pDoc, ScAddress( nCol, nRow, nTab ) );
414 [ # # ]: 0 : SvtLanguageTable aLangTab;
415 [ # # ][ # # ]: 0 : String aErr = aLangTab.GetString(eLnge);
416 [ # # ][ # # ]: 0 : aErr += ScGlobal::GetRscString( STR_SPELLING_NO_LANG );
417 [ # # ][ # # ]: 0 : InfoBox aBox( GetViewData()->GetDialogParent(), aErr );
418 [ # # ][ # # ]: 0 : aBox.Execute();
[ # # ][ # # ]
419 : : }
420 [ # # ][ # # ]: 0 : if (pThesaurusEngine->IsModified())
421 : : {
422 : 0 : EditTextObject* pNewTObj = NULL;
423 [ # # ][ # # ]: 0 : if (pCell && pTObject)
424 : : {
425 [ # # ]: 0 : pNewTObj = pThesaurusEngine->CreateTextObject();
426 : : pCell = new ScEditCell( pNewTObj, pDoc,
427 [ # # ][ # # ]: 0 : pThesaurusEngine->GetEditTextObjectPool() );
[ # # ]
428 [ # # ]: 0 : pDoc->PutCell( nCol, nRow, nTab, pCell );
429 : : }
430 : : else
431 : : {
432 [ # # ][ # # ]: 0 : sNewString = pThesaurusEngine->GetText();
[ # # ]
433 [ # # ][ # # ]: 0 : pDoc->SetString(nCol, nRow, nTab, sNewString);
434 : : }
435 : : // erack! it's broadcasted
436 : : // pDoc->SetDirty();
437 [ # # ]: 0 : pDocSh->SetDocumentModified();
438 [ # # ]: 0 : if (bRecord)
439 : : {
440 [ # # ]: 0 : GetViewData()->GetDocShell()->GetUndoManager()->AddUndoAction(
441 : 0 : new ScUndoThesaurus( GetViewData()->GetDocShell(),
442 : : nCol, nRow, nTab,
443 [ # # ][ # # ]: 0 : sOldText, pOldTObj, sNewString, pNewTObj));
[ # # ]
444 : : }
445 [ # # ][ # # ]: 0 : delete pNewTObj;
446 : : }
447 [ # # ]: 0 : KillEditView(sal_True);
448 [ # # ][ # # ]: 0 : delete pEditDefaults;
449 [ # # ][ # # ]: 0 : delete pThesaurusEngine;
450 [ # # ][ # # ]: 0 : delete pOldTObj;
451 : 0 : delete pEditSel;
452 [ # # ][ # # ]: 0 : pDocSh->PostPaintGridAll();
[ # # ][ # # ]
[ # # ][ # # ]
453 : : }
454 : :
455 : 0 : void ScViewFunc::DoHangulHanjaConversion( sal_Bool bRecord )
456 : : {
457 [ # # ]: 0 : ScConversionParam aConvParam( SC_CONVERSION_HANGULHANJA, LANGUAGE_KOREAN, 0, true );
458 [ # # ][ # # ]: 0 : DoSheetConversion( aConvParam, bRecord );
459 : 0 : }
460 : :
461 : 0 : void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, sal_Bool bRecord )
462 : : {
463 : : SCCOL nCol;
464 : : SCROW nRow;
465 : : SCTAB nTab;
466 : 0 : ScViewData& rViewData = *GetViewData();
467 : 0 : ScDocShell* pDocSh = rViewData.GetDocShell();
468 : 0 : ScDocument* pDoc = pDocSh->GetDocument();
469 [ # # ]: 0 : ScMarkData& rMark = rViewData.GetMarkData();
470 : 0 : ScSplitPos eWhich = rViewData.GetActivePart();
471 : 0 : EditView* pEditView = NULL;
472 : 0 : sal_Bool bIsEditMode = rViewData.HasEditView(eWhich);
473 [ # # ][ # # ]: 0 : if (bRecord && !pDoc->IsUndoEnabled())
[ # # ]
474 : 0 : bRecord = false;
475 [ # # ]: 0 : if (bIsEditMode) // Edit-Mode aktiv
476 : : {
477 [ # # ]: 0 : rViewData.GetEditView(eWhich, pEditView, nCol, nRow);
478 [ # # ][ # # ]: 0 : SC_MOD()->InputEnterHandler();
479 : : }
480 : : else
481 : : {
482 : 0 : nCol = rViewData.GetCurX();
483 : 0 : nRow = rViewData.GetCurY();
484 : :
485 [ # # ]: 0 : AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP);
486 : : }
487 : 0 : nTab = rViewData.GetTabNo();
488 : :
489 [ # # ]: 0 : rMark.MarkToMulti();
490 : 0 : sal_Bool bMarked = rMark.IsMultiMarked();
491 [ # # ]: 0 : if (bMarked)
492 : : {
493 [ # # ]: 0 : ScEditableTester aTester( pDoc, rMark );
494 [ # # ]: 0 : if (!aTester.IsEditable())
495 : : {
496 [ # # ][ # # ]: 0 : ErrorMessage(aTester.GetMessageId());
497 : 0 : return;
498 [ # # ]: 0 : }
499 : : }
500 : :
501 : 0 : ScDocument* pUndoDoc = NULL;
502 : 0 : ScDocument* pRedoDoc = NULL;
503 [ # # ]: 0 : if (bRecord)
504 : : {
505 [ # # ][ # # ]: 0 : pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
506 [ # # ]: 0 : pUndoDoc->InitUndo( pDoc, nTab, nTab );
507 [ # # ][ # # ]: 0 : pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
508 [ # # ]: 0 : pRedoDoc->InitUndo( pDoc, nTab, nTab );
509 : :
510 [ # # ][ # # ]: 0 : if ( rMark.GetSelectCount() > 1 )
511 : : {
512 [ # # ][ # # ]: 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
513 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
514 [ # # ][ # # ]: 0 : if ( *itr != nTab )
515 : : {
516 [ # # ][ # # ]: 0 : pUndoDoc->AddUndoTab( *itr, *itr );
[ # # ]
517 [ # # ][ # # ]: 0 : pRedoDoc->AddUndoTab( *itr, *itr );
[ # # ]
518 : : }
519 : : }
520 : : }
521 : :
522 : : // ab hier kein return mehr
523 : :
524 : 0 : sal_Bool bOldDis = pDoc->IsIdleDisabled();
525 : 0 : pDoc->DisableIdle( true ); // stop online spelling
526 : :
527 : : // *** create and init the edit engine *** --------------------------------
528 : :
529 : 0 : ScConversionEngineBase* pEngine = NULL;
530 [ # # # ]: 0 : switch( rConvParam.GetType() )
531 : : {
532 : : case SC_CONVERSION_SPELLCHECK:
533 : : pEngine = new ScSpellingEngine(
534 [ # # ][ # # ]: 0 : pDoc->GetEnginePool(), rViewData, pUndoDoc, pRedoDoc, LinguMgr::GetSpellChecker() );
[ # # ][ # # ]
535 : 0 : break;
536 : : case SC_CONVERSION_HANGULHANJA:
537 : : case SC_CONVERSION_CHINESE_TRANSL:
538 : : pEngine = new ScTextConversionEngine(
539 [ # # ][ # # ]: 0 : pDoc->GetEnginePool(), rViewData, rConvParam, pUndoDoc, pRedoDoc );
[ # # ]
540 : 0 : break;
541 : : default:
542 : : OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
543 : : }
544 : :
545 [ # # ]: 0 : MakeEditView( pEngine, nCol, nRow );
546 [ # # ][ # # ]: 0 : pEngine->SetRefDevice( rViewData.GetActiveWin() );
547 : : // dummy Zelle simulieren:
548 : 0 : pEditView = rViewData.GetEditView( rViewData.GetActivePart() );
549 : 0 : rViewData.SetSpellingView( pEditView );
550 [ # # ]: 0 : Rectangle aRect( Point( 0, 0 ), Point( 0, 0 ) );
551 [ # # ]: 0 : pEditView->SetOutputArea( aRect );
552 [ # # ]: 0 : pEngine->SetControlWord( EE_CNTRL_USECHARATTRIBS );
553 [ # # ]: 0 : pEngine->EnableUndo( false );
554 [ # # ][ # # ]: 0 : pEngine->SetPaperSize( aRect.GetSize() );
555 [ # # ][ # # ]: 0 : pEngine->SetText( EMPTY_STRING );
556 : :
557 : : // *** do the conversion *** ----------------------------------------------
558 : :
559 [ # # ]: 0 : pEngine->ClearModifyFlag();
560 [ # # ]: 0 : pEngine->ConvertAll( *pEditView );
561 : :
562 : : // *** undo/redo *** ------------------------------------------------------
563 : :
564 [ # # ]: 0 : if( pEngine->IsAnyModified() )
565 : : {
566 [ # # ]: 0 : if (bRecord)
567 : : {
568 : 0 : SCCOL nNewCol = rViewData.GetCurX();
569 : 0 : SCROW nNewRow = rViewData.GetCurY();
570 [ # # ]: 0 : rViewData.GetDocShell()->GetUndoManager()->AddUndoAction(
571 : : new ScUndoConversion(
572 : : pDocSh, rMark,
573 : : nCol, nRow, nTab, pUndoDoc,
574 [ # # ][ # # ]: 0 : nNewCol, nNewRow, nTab, pRedoDoc, rConvParam ) );
[ # # ]
575 : : }
576 [ # # ]: 0 : pDoc->SetDirty();
577 [ # # ]: 0 : pDocSh->SetDocumentModified();
578 : : }
579 : : else
580 : : {
581 [ # # ][ # # ]: 0 : delete pUndoDoc;
582 [ # # ][ # # ]: 0 : delete pRedoDoc;
583 : : }
584 : :
585 : : // *** final cleanup *** --------------------------------------------------
586 : :
587 : 0 : rViewData.SetSpellingView( NULL );
588 [ # # ]: 0 : KillEditView(sal_True);
589 [ # # ][ # # ]: 0 : delete pEngine;
590 [ # # ]: 0 : pDocSh->PostPaintGridAll();
591 [ # # ]: 0 : rViewData.GetViewShell()->UpdateInputHandler();
592 : 0 : pDoc->DisableIdle(bOldDis);
593 : : }
594 : :
595 : : // Pasten von FORMAT_FILE-Items
596 : : // wird nicht direkt aus Drop aufgerufen, sondern asynchron -> Dialoge sind erlaubt
597 : :
598 : 0 : sal_Bool ScViewFunc::PasteFile( const Point& rPos, const String& rFile, sal_Bool bLink )
599 : : {
600 [ # # ]: 0 : INetURLObject aURL;
601 [ # # ][ # # ]: 0 : aURL.SetSmartURL( rFile );
602 [ # # ][ # # ]: 0 : String aStrURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
603 : :
604 : : // is it a media URL?
605 [ # # ][ # # ]: 0 : if( ::avmedia::MediaWindow::isMediaURL( aStrURL ) )
[ # # ]
606 : : {
607 [ # # ]: 0 : const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aStrURL );
608 [ # # ]: 0 : return sal_Bool( 0 != GetViewData()->GetDispatcher().Execute(
609 : : SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON,
610 [ # # ][ # # ]: 0 : &aMediaURLItem, 0L ) );
611 : : }
612 : :
613 [ # # ]: 0 : if (!bLink) // bei bLink nur Grafik oder URL
614 : : {
615 : : // 1. Kann ich die Datei oeffnen?
616 : 0 : const SfxFilter* pFlt = NULL;
617 : :
618 : : // nur nach eigenen Filtern suchen, ohne Auswahlbox (wie in ScDocumentLoader)
619 [ # # ][ # # ]: 0 : SfxFilterMatcher aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
[ # # ][ # # ]
[ # # ]
620 [ # # ]: 0 : SfxMedium aSfxMedium( aStrURL, (STREAM_READ | STREAM_SHARE_DENYNONE) );
621 : : // #i73992# GuessFilter no longer calls UseInteractionHandler.
622 : : // This is UI, so it can be called here.
623 [ # # ]: 0 : aSfxMedium.UseInteractionHandler(sal_True);
624 [ # # ]: 0 : ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, &pFlt );
625 : :
626 [ # # ][ # # ]: 0 : if ( pFlt && !nErr )
627 : : {
628 : : // Code aus dem SFX geklaut!
629 [ # # ]: 0 : SfxDispatcher &rDispatcher = GetViewData()->GetDispatcher();
630 [ # # ]: 0 : SfxStringItem aFileNameItem( SID_FILE_NAME, aStrURL );
631 [ # # ]: 0 : SfxStringItem aFilterItem( SID_FILTER_NAME, pFlt->GetName() );
632 : : // #i69524# add target, as in SfxApplication when the Open dialog is used
633 [ # # ][ # # ]: 0 : SfxStringItem aTargetItem( SID_TARGETNAME, rtl::OUString("_default") );
[ # # ]
634 : :
635 : : // Asynchron oeffnen, kann naemlich auch aus D&D heraus passieren
636 : : // und das bekommt dem MAC nicht so gut ...
637 : : return sal_Bool( 0 != rDispatcher.Execute( SID_OPENDOC,
638 [ # # ][ # # ]: 0 : SFX_CALLMODE_ASYNCHRON, &aFileNameItem, &aFilterItem, &aTargetItem, 0L) );
[ # # ][ # # ]
639 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
640 : : }
641 : :
642 : : // 2. Kann die Datei ueber die Grafik-Filter eingefuegt werden?
643 : : // (als Link, weil Gallery das so anbietet)
644 : :
645 : : sal_uInt16 nFilterFormat;
646 [ # # ]: 0 : Graphic aGraphic;
647 [ # # ]: 0 : GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
648 : :
649 : :
650 [ # # ]: 0 : if (!rGraphicFilter.ImportGraphic(aGraphic, aURL,
651 [ # # ]: 0 : GRFILTER_FORMAT_DONTKNOW, &nFilterFormat ))
652 : : {
653 [ # # ]: 0 : if ( bLink )
654 : : {
655 [ # # ]: 0 : String aFltName = rGraphicFilter.GetImportFormatName(nFilterFormat);
656 [ # # ][ # # ]: 0 : return PasteGraphic( rPos, aGraphic, aStrURL, aFltName );
657 : : }
658 : : else
659 : : {
660 : : // #i76709# if bLink isn't set, pass empty URL/filter, so a non-linked image is inserted
661 [ # # ][ # # ]: 0 : return PasteGraphic( rPos, aGraphic, EMPTY_STRING, EMPTY_STRING );
[ # # ]
662 : : }
663 : : }
664 : :
665 [ # # ]: 0 : if (bLink) // bei bLink alles, was nicht Grafik ist, als URL
666 : : {
667 [ # # ]: 0 : Rectangle aRect( rPos, Size(0,0) );
668 : : ScRange aRange = GetViewData()->GetDocument()->
669 [ # # ][ # # ]: 0 : GetRange( GetViewData()->GetTabNo(), aRect );
670 : 0 : SCCOL nPosX = aRange.aStart.Col();
671 : 0 : SCROW nPosY = aRange.aStart.Row();
672 : :
673 [ # # ]: 0 : InsertBookmark( aStrURL, aStrURL, nPosX, nPosY );
674 : 0 : return sal_True;
675 : : }
676 : : else
677 : : {
678 : : // 3. Kann die Datei als OLE eingefuegt werden?
679 : : // auch nicht-Storages, z.B. Sounds (#38282#)
680 [ # # ]: 0 : uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
681 : :
682 : : //TODO/LATER: what about "bLink"?
683 : :
684 [ # # ]: 0 : uno::Sequence < beans::PropertyValue > aMedium(1);
685 [ # # ][ # # ]: 0 : aMedium[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
686 [ # # ][ # # ]: 0 : aMedium[0].Value <<= ::rtl::OUString( aStrURL );
[ # # ]
687 : :
688 [ # # ]: 0 : comphelper::EmbeddedObjectContainer aCnt( xStorage );
689 : 0 : ::rtl::OUString aName;
690 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
691 [ # # ]: 0 : if( xObj.is() )
692 [ # # ]: 0 : return PasteObject( rPos, xObj );
693 : :
694 : : // If an OLE object can't be created, insert a URL button
695 : :
696 [ # # ][ # # ]: 0 : GetViewData()->GetViewShell()->InsertURLButton( aStrURL, aStrURL, EMPTY_STRING, &rPos );
697 [ # # ][ # # ]: 0 : return sal_True;
698 [ # # ][ # # ]: 0 : }
[ # # ]
699 : : }
700 : :
701 : 0 : sal_Bool ScViewFunc::PasteBookmark( sal_uLong nFormatId,
702 : : const ::com::sun::star::uno::Reference<
703 : : ::com::sun::star::datatransfer::XTransferable >& rxTransferable,
704 : : SCCOL nPosX, SCROW nPosY )
705 : : {
706 [ # # ]: 0 : INetBookmark aBookmark;
707 [ # # ]: 0 : TransferableDataHelper aDataHelper( rxTransferable );
708 [ # # ][ # # ]: 0 : if ( !aDataHelper.GetINetBookmark( nFormatId, aBookmark ) )
709 : 0 : return false;
710 : :
711 [ # # ]: 0 : InsertBookmark( aBookmark.GetDescription(), aBookmark.GetURL(), nPosX, nPosY );
712 [ # # ][ # # ]: 0 : return sal_True;
713 : : }
714 : :
715 : 0 : void ScViewFunc::InsertBookmark( const String& rDescription, const String& rURL,
716 : : SCCOL nPosX, SCROW nPosY, const String* pTarget,
717 : : sal_Bool bTryReplace )
718 : : {
719 : 0 : ScViewData* pViewData = GetViewData();
720 [ # # ][ # # : 0 : if ( pViewData->HasEditView( pViewData->GetActivePart() ) &&
# # # # #
# # # ]
721 : 0 : nPosX >= pViewData->GetEditStartCol() && nPosX <= pViewData->GetEditEndCol() &&
722 : 0 : nPosY >= pViewData->GetEditStartRow() && nPosY <= pViewData->GetEditEndRow() )
723 : : {
724 : : // in die gerade editierte Zelle einfuegen
725 : :
726 [ # # ]: 0 : String aTargetFrame;
727 [ # # ]: 0 : if (pTarget)
728 [ # # ]: 0 : aTargetFrame = *pTarget;
729 [ # # ]: 0 : pViewData->GetViewShell()->InsertURLField( rDescription, rURL, aTargetFrame );
730 [ # # ]: 0 : return;
731 : : }
732 : :
733 : : // in nicht editierte Zelle einfuegen
734 : :
735 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
736 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
737 : 0 : ScAddress aCellPos( nPosX, nPosY, nTab );
738 [ # # ]: 0 : ScBaseCell* pCell = pDoc->GetCell( aCellPos );
739 [ # # ][ # # ]: 0 : EditEngine aEngine( pDoc->GetEnginePool() );
740 [ # # ]: 0 : if (pCell)
741 : : {
742 [ # # ]: 0 : if (pCell->GetCellType() == CELLTYPE_EDIT)
743 : : {
744 : 0 : const EditTextObject* pOld = ((ScEditCell*)pCell)->GetData();
745 [ # # ]: 0 : if (pOld)
746 [ # # ]: 0 : aEngine.SetText(*pOld);
747 : : }
748 : : else
749 : : {
750 [ # # ]: 0 : String aOld;
751 [ # # ]: 0 : pDoc->GetInputString( nPosX, nPosY, nTab, aOld );
752 [ # # ]: 0 : if (aOld.Len())
753 [ # # ][ # # ]: 0 : aEngine.SetText(aOld);
754 : : }
755 : : }
756 : :
757 [ # # ]: 0 : sal_uInt16 nPara = aEngine.GetParagraphCount();
758 [ # # ]: 0 : if (nPara)
759 : 0 : --nPara;
760 [ # # ]: 0 : xub_StrLen nTxtLen = aEngine.GetTextLen(nPara);
761 : 0 : ESelection aInsSel( nPara, nTxtLen, nPara, nTxtLen );
762 : :
763 [ # # ][ # # ]: 0 : if ( bTryReplace && HasBookmarkAtCursor( NULL ) )
[ # # ][ # # ]
764 : : {
765 : : // if called from hyperlink slot and cell contains only a URL,
766 : : // replace old URL with new one
767 : :
768 : 0 : aInsSel = ESelection( 0, 0, 0, 1 ); // replace first character (field)
769 : : }
770 : :
771 [ # # ][ # # ]: 0 : SvxURLField aField( rURL, rDescription, SVXURLFORMAT_APPDEFAULT );
[ # # ]
772 [ # # ]: 0 : if (pTarget)
773 [ # # ]: 0 : aField.SetTargetFrame(*pTarget);
774 [ # # ][ # # ]: 0 : aEngine.QuickInsertField( SvxFieldItem( aField, EE_FEATURE_FIELD ), aInsSel );
[ # # ]
775 : :
776 [ # # ]: 0 : EditTextObject* pData = aEngine.CreateTextObject();
777 [ # # ]: 0 : EnterData( nPosX, nPosY, nTab, pData );
778 [ # # ][ # # ]: 0 : delete pData;
[ # # ][ # # ]
779 : : }
780 : :
781 : 0 : sal_Bool ScViewFunc::HasBookmarkAtCursor( SvxHyperlinkItem* pContent )
782 : : {
783 : 0 : ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
784 : 0 : ScDocument* pDoc = GetViewData()->GetDocShell()->GetDocument();
785 : :
786 [ # # ]: 0 : ScBaseCell* pCell = pDoc->GetCell( aPos );
787 [ # # ][ # # ]: 0 : if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT )
[ # # ]
788 : : {
789 : 0 : const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
790 [ # # ]: 0 : if (pData)
791 : : {
792 [ # # ]: 0 : sal_Bool bField = pData->IsFieldObject();
793 [ # # ]: 0 : if (bField)
794 : : {
795 [ # # ]: 0 : const SvxFieldItem* pFieldItem = pData->GetField();
796 [ # # ]: 0 : if (pFieldItem)
797 : : {
798 : 0 : const SvxFieldData* pField = pFieldItem->GetField();
799 [ # # ][ # # ]: 0 : if ( pField && pField->ISA(SvxURLField) )
[ # # ][ # # ]
[ # # ]
800 : : {
801 [ # # ]: 0 : if (pContent)
802 : : {
803 : 0 : const SvxURLField* pURLField = (const SvxURLField*)pField;
804 [ # # ][ # # ]: 0 : pContent->SetName( pURLField->GetRepresentation() );
[ # # ]
805 [ # # ][ # # ]: 0 : pContent->SetURL( pURLField->GetURL() );
[ # # ]
806 [ # # ][ # # ]: 0 : pContent->SetTargetFrame( pURLField->GetTargetFrame() );
[ # # ]
807 : : }
808 : 0 : return sal_True;
809 : : }
810 : : }
811 : : }
812 : : }
813 : : }
814 : 0 : return false;
815 : : }
816 : :
817 : :
818 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|