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 :
21 : #include <sal/macros.h>
22 : #include <vcl/wrkwin.hxx>
23 : #include <vcl/dialog.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <vcl/svapp.hxx>
26 :
27 : #include <com/sun/star/i18n/WordType.hpp>
28 : #include <com/sun/star/i18n/ScriptType.hpp>
29 : #include <vcl/metric.hxx>
30 :
31 : #include <i18nlangtag/languagetag.hxx>
32 : #include <i18nlangtag/mslangid.hxx>
33 : #include <svl/languageoptions.hxx>
34 : #include <svtools/ctrltool.hxx>
35 : #include <svtools/langtab.hxx>
36 : #include <vcl/graphicfilter.hxx>
37 :
38 : #include <svl/srchitem.hxx>
39 :
40 : #include <impedit.hxx>
41 : #include <editeng/editeng.hxx>
42 : #include <editeng/editview.hxx>
43 : #include <editeng/flditem.hxx>
44 : #include <editeng/svxacorr.hxx>
45 : #include <editeng/langitem.hxx>
46 : #include <editeng/fhgtitem.hxx>
47 : #include <editeng/eerdll.hxx>
48 : #include <eerdll2.hxx>
49 : #include <editeng.hrc>
50 : #include <helpid.hrc>
51 : #include <i18nlangtag/lang.h>
52 : #include <vcl/menu.hxx>
53 : #include <vcl/window.hxx>
54 : #include <editeng/acorrcfg.hxx>
55 : #include <editeng/unolingu.hxx>
56 : #include <editeng/fontitem.hxx>
57 : #include <unotools/lingucfg.hxx>
58 : #include <osl/file.hxx>
59 :
60 : #include <com/sun/star/frame/XStorable.hpp>
61 : #include <com/sun/star/beans/PropertyValues.hpp>
62 : #include <com/sun/star/lang/Locale.hpp>
63 : #include <linguistic/lngprops.hxx>
64 : #include <vcl/settings.hxx>
65 : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
66 :
67 : #include <com/sun/star/lang/XServiceInfo.hpp>
68 :
69 : using namespace com::sun::star;
70 : using namespace com::sun::star::uno;
71 : using namespace com::sun::star::beans;
72 :
73 :
74 : // static
75 0 : LanguageType EditView::CheckLanguage(
76 : const OUString &rText,
77 : Reference< linguistic2::XSpellChecker1 > xSpell,
78 : Reference< linguistic2::XLanguageGuessing > xLangGuess,
79 : bool bIsParaText )
80 : {
81 0 : LanguageType nLang = LANGUAGE_NONE;
82 0 : if (bIsParaText) // check longer texts with language-guessing...
83 : {
84 0 : if (!xLangGuess.is())
85 0 : return nLang;
86 :
87 0 : LanguageTag aGuessTag( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
88 :
89 : // If the result from language guessing does not provide a 'Country'
90 : // part, try to get it by looking up the locale setting of the office,
91 : // "Tools/Options - Language Settings - Languages: Locale setting", if
92 : // the language matches.
93 0 : if ( aGuessTag.getCountry().isEmpty() )
94 : {
95 0 : const LanguageTag& rAppLocaleTag = Application::GetSettings().GetLanguageTag();
96 0 : if (rAppLocaleTag.getLanguage() == aGuessTag.getLanguage())
97 0 : nLang = rAppLocaleTag.getLanguageType();
98 : }
99 0 : if (nLang == LANGUAGE_NONE) // language not found by looking up the system language...
100 0 : nLang = aGuessTag.makeFallback().getLanguageType(); // best known locale match
101 0 : if (nLang == LANGUAGE_SYSTEM)
102 0 : nLang = Application::GetSettings().GetLanguageTag().getLanguageType();
103 0 : if (nLang == LANGUAGE_DONTKNOW)
104 0 : nLang = LANGUAGE_NONE;
105 : }
106 : else // check single word
107 : {
108 0 : if (!xSpell.is())
109 0 : return nLang;
110 :
111 :
112 : // build list of languages to check
113 :
114 : LanguageType aLangList[4];
115 0 : const AllSettings& rSettings = Application::GetSettings();
116 0 : SvtLinguOptions aLinguOpt;
117 0 : SvtLinguConfig().GetOptions( aLinguOpt );
118 : // The default document language from "Tools/Options - Language Settings - Languages: Western"
119 : aLangList[0] = MsLangId::resolveSystemLanguageByScriptType( aLinguOpt.nDefaultLanguage,
120 0 : ::com::sun::star::i18n::ScriptType::LATIN);
121 : // The one from "Tools/Options - Language Settings - Languages: User interface"
122 0 : aLangList[1] = rSettings.GetUILanguageTag().getLanguageType();
123 : // The one from "Tools/Options - Language Settings - Languages: Locale setting"
124 0 : aLangList[2] = rSettings.GetLanguageTag().getLanguageType();
125 : // en-US
126 0 : aLangList[3] = LANGUAGE_ENGLISH_US;
127 : #ifdef DEBUG
128 : lang::Locale a0( LanguageTag::convertToLocale( aLangList[0] ) );
129 : lang::Locale a1( LanguageTag::convertToLocale( aLangList[1] ) );
130 : lang::Locale a2( LanguageTag::convertToLocale( aLangList[2] ) );
131 : lang::Locale a3( LanguageTag::convertToLocale( aLangList[3] ) );
132 : #endif
133 :
134 0 : sal_Int32 nCount = sizeof (aLangList) / sizeof (aLangList[0]);
135 0 : for (sal_Int32 i = 0; i < nCount; i++)
136 : {
137 0 : sal_Int16 nTmpLang = aLangList[i];
138 0 : if (nTmpLang != LANGUAGE_NONE && nTmpLang != LANGUAGE_DONTKNOW)
139 : {
140 0 : if (xSpell->hasLanguage( nTmpLang ) &&
141 0 : xSpell->isValid( rText, nTmpLang, Sequence< PropertyValue >() ))
142 : {
143 0 : nLang = nTmpLang;
144 0 : break;
145 : }
146 : }
147 0 : }
148 : }
149 :
150 0 : return nLang;
151 : }
152 :
153 : // class EditView
154 :
155 377 : EditView::EditView( EditEngine* pEng, vcl::Window* pWindow )
156 : {
157 377 : pImpEditView = new ImpEditView( this, pEng, pWindow );
158 377 : }
159 :
160 1128 : EditView::~EditView()
161 : {
162 376 : delete pImpEditView;
163 752 : }
164 :
165 252 : ImpEditEngine* EditView::GetImpEditEngine() const
166 : {
167 252 : return pImpEditView->pEditEngine->pImpEditEngine;
168 : }
169 :
170 1218 : EditEngine* EditView::GetEditEngine() const
171 : {
172 1218 : return pImpEditView->pEditEngine;
173 : }
174 :
175 323 : void EditView::Invalidate()
176 : {
177 323 : if ( !pImpEditView->DoInvalidateMore() )
178 323 : pImpEditView->GetWindow()->Invalidate( pImpEditView->aOutArea );
179 : else
180 : {
181 0 : Rectangle aRect( pImpEditView->aOutArea );
182 0 : long nMore = pImpEditView->GetWindow()->PixelToLogic( Size( pImpEditView->GetInvalidateMore(), 0 ) ).Width();
183 0 : aRect.Left() -= nMore;
184 0 : aRect.Right() += nMore;
185 0 : aRect.Top() -= nMore;
186 0 : aRect.Bottom() += nMore;
187 0 : pImpEditView->GetWindow()->Invalidate( aRect );
188 : }
189 323 : }
190 :
191 108 : void EditView::SetReadOnly( bool bReadOnly )
192 : {
193 108 : pImpEditView->bReadOnly = bReadOnly;
194 108 : }
195 :
196 30 : bool EditView::IsReadOnly() const
197 : {
198 30 : return pImpEditView->bReadOnly;
199 : }
200 :
201 216 : void EditView::SetSelection( const ESelection& rESel )
202 : {
203 : // If someone has just left an empty attribute, and then the outliner
204 : // manipulates the selection:
205 216 : if ( !pImpEditView->GetEditSelection().HasRange() )
206 : {
207 214 : ContentNode* pNode = pImpEditView->GetEditSelection().Max().GetNode();
208 214 : pImpEditView->pEditEngine->CursorMoved( pNode );
209 : }
210 : EditSelection aNewSelection( pImpEditView->pEditEngine->pImpEditEngine->ConvertSelection(
211 216 : rESel.nStartPara, rESel.nStartPos, rESel.nEndPara, rESel.nEndPos ) );
212 :
213 : // If the selection is manipulated after a KeyInput:
214 216 : pImpEditView->pEditEngine->CheckIdleFormatter();
215 :
216 : // Selection may not start/end at an invisible paragraph:
217 216 : const ParaPortion* pPortion = pImpEditView->pEditEngine->FindParaPortion( aNewSelection.Min().GetNode() );
218 216 : if ( !pPortion->IsVisible() )
219 : {
220 0 : pPortion = pImpEditView->pEditEngine->GetPrevVisPortion( pPortion );
221 0 : ContentNode* pNode = pPortion ? pPortion->GetNode() : pImpEditView->pEditEngine->GetEditDoc().GetObject( 0 );
222 0 : aNewSelection.Min() = EditPaM( pNode, pNode->Len() );
223 : }
224 216 : pPortion = pImpEditView->pEditEngine->FindParaPortion( aNewSelection.Max().GetNode() );
225 216 : if ( !pPortion->IsVisible() )
226 : {
227 0 : pPortion = pImpEditView->pEditEngine->GetPrevVisPortion( pPortion );
228 0 : ContentNode* pNode = pPortion ? pPortion->GetNode() : pImpEditView->pEditEngine->GetEditDoc().GetObject( 0 );
229 0 : aNewSelection.Max() = EditPaM( pNode, pNode->Len() );
230 : }
231 :
232 216 : pImpEditView->DrawSelection();
233 216 : pImpEditView->SetEditSelection( aNewSelection );
234 216 : pImpEditView->DrawSelection();
235 216 : bool bGotoCursor = pImpEditView->DoAutoScroll();
236 216 : ShowCursor( bGotoCursor );
237 216 : }
238 :
239 396 : ESelection EditView::GetSelection() const
240 : {
241 396 : ESelection aSelection;
242 :
243 396 : aSelection.nStartPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( pImpEditView->GetEditSelection().Min().GetNode() );
244 396 : aSelection.nEndPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( pImpEditView->GetEditSelection().Max().GetNode() );
245 :
246 396 : aSelection.nStartPos = pImpEditView->GetEditSelection().Min().GetIndex();
247 396 : aSelection.nEndPos = pImpEditView->GetEditSelection().Max().GetIndex();
248 :
249 396 : return aSelection;
250 : }
251 :
252 550 : bool EditView::HasSelection() const
253 : {
254 550 : return pImpEditView->HasSelection();
255 : }
256 :
257 3 : void EditView::DeleteSelected()
258 : {
259 3 : pImpEditView->DeleteSelected();
260 3 : }
261 :
262 0 : SvtScriptType EditView::GetSelectedScriptType() const
263 : {
264 0 : return pImpEditView->pEditEngine->GetScriptType( pImpEditView->GetEditSelection() );
265 : }
266 :
267 605 : void EditView::Paint( const Rectangle& rRect, OutputDevice* pTargetDevice )
268 : {
269 605 : pImpEditView->pEditEngine->pImpEditEngine->Paint( pImpEditView, rRect, pTargetDevice );
270 605 : }
271 :
272 0 : void EditView::SetEditEngine( EditEngine* pEditEng )
273 : {
274 0 : pImpEditView->pEditEngine = pEditEng;
275 0 : EditSelection aStartSel;
276 0 : aStartSel = pImpEditView->pEditEngine->GetEditDoc().GetStartPaM();
277 0 : pImpEditView->SetEditSelection( aStartSel );
278 0 : }
279 :
280 113 : void EditView::SetWindow( vcl::Window* pWin )
281 : {
282 113 : pImpEditView->pOutWin = pWin;
283 113 : pImpEditView->pEditEngine->pImpEditEngine->GetSelEngine().Reset();
284 113 : }
285 :
286 412 : vcl::Window* EditView::GetWindow() const
287 : {
288 412 : return pImpEditView->pOutWin;
289 : }
290 :
291 179 : void EditView::SetVisArea( const Rectangle& rRect )
292 : {
293 179 : pImpEditView->SetVisDocStartPos( rRect.TopLeft() );
294 179 : }
295 :
296 2425 : const Rectangle& EditView::GetVisArea() const
297 : {
298 : // Change return value to Rectangle in next incompatible build !!!
299 2425 : static Rectangle aRect;
300 2425 : aRect = pImpEditView->GetVisDocArea();
301 2425 : return aRect;
302 : }
303 :
304 568 : void EditView::SetOutputArea( const Rectangle& rRect )
305 : {
306 568 : pImpEditView->SetOutputArea( rRect );
307 :
308 : // the rest here only if it is an API call:
309 568 : pImpEditView->CalcAnchorPoint();
310 568 : if ( pImpEditView->pEditEngine->pImpEditEngine->GetStatus().AutoPageSize() )
311 9 : pImpEditView->RecalcOutputArea();
312 568 : pImpEditView->ShowCursor( false, false );
313 568 : }
314 :
315 210 : const Rectangle& EditView::GetOutputArea() const
316 : {
317 210 : return pImpEditView->GetOutputArea();
318 : }
319 :
320 45 : const Pointer& EditView::GetPointer() const
321 : {
322 45 : return pImpEditView->GetPointer();
323 : }
324 :
325 86 : vcl::Cursor* EditView::GetCursor() const
326 : {
327 86 : return pImpEditView->pCursor;
328 : }
329 :
330 16 : void EditView::InsertText( const OUString& rStr, bool bSelect )
331 : {
332 :
333 16 : EditEngine* pEE = pImpEditView->pEditEngine;
334 16 : pImpEditView->DrawSelection();
335 :
336 16 : EditPaM aPaM1;
337 16 : if ( bSelect )
338 : {
339 0 : EditSelection aTmpSel( pImpEditView->GetEditSelection() );
340 0 : aTmpSel.Adjust( pEE->GetEditDoc() );
341 0 : aPaM1 = aTmpSel.Min();
342 : }
343 :
344 16 : pEE->UndoActionStart( EDITUNDO_INSERT );
345 16 : EditPaM aPaM2( pEE->InsertText( pImpEditView->GetEditSelection(), rStr ) );
346 16 : pEE->UndoActionEnd( EDITUNDO_INSERT );
347 :
348 16 : if ( bSelect )
349 : {
350 : DBG_ASSERT( !aPaM1.DbgIsBuggy( pEE->GetEditDoc() ), "Insert: PaM broken" );
351 0 : pImpEditView->SetEditSelection( EditSelection( aPaM1, aPaM2 ) );
352 : }
353 : else
354 16 : pImpEditView->SetEditSelection( EditSelection( aPaM2, aPaM2 ) );
355 :
356 16 : pEE->FormatAndUpdate( this );
357 16 : }
358 :
359 3 : bool EditView::PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window* pFrameWin )
360 : {
361 3 : return pImpEditView->PostKeyEvent( rKeyEvent, pFrameWin );
362 : }
363 :
364 1 : bool EditView::MouseButtonUp( const MouseEvent& rMouseEvent )
365 : {
366 1 : return pImpEditView->MouseButtonUp( rMouseEvent );
367 : }
368 :
369 0 : void EditView::ReleaseMouse()
370 : {
371 0 : return pImpEditView->ReleaseMouse();
372 : }
373 :
374 1 : bool EditView::MouseButtonDown( const MouseEvent& rMouseEvent )
375 : {
376 1 : return pImpEditView->MouseButtonDown( rMouseEvent );
377 : }
378 :
379 0 : bool EditView::MouseMove( const MouseEvent& rMouseEvent )
380 : {
381 0 : return pImpEditView->MouseMove( rMouseEvent );
382 : }
383 :
384 0 : void EditView::Command( const CommandEvent& rCEvt )
385 : {
386 0 : pImpEditView->Command( rCEvt );
387 0 : }
388 :
389 2363 : void EditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor )
390 : {
391 2363 : if ( pImpEditView->pEditEngine->HasView( this ) )
392 : {
393 : // The control word is more important:
394 2363 : if ( !pImpEditView->DoAutoScroll() )
395 89 : bGotoCursor = false;
396 2363 : pImpEditView->ShowCursor( bGotoCursor, bForceVisCursor );
397 :
398 2363 : if (pImpEditView->isTiledRendering())
399 53 : pImpEditView->libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(true).getStr());
400 : }
401 2363 : }
402 :
403 945 : void EditView::HideCursor()
404 : {
405 945 : pImpEditView->GetCursor()->Hide();
406 945 : if (pImpEditView->isTiledRendering())
407 33 : pImpEditView->libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(false).getStr());
408 945 : }
409 :
410 165 : Pair EditView::Scroll( long ndX, long ndY, sal_uInt8 nRangeCheck )
411 : {
412 165 : return pImpEditView->Scroll( ndX, ndY, nRangeCheck );
413 : }
414 :
415 0 : const SfxItemSet& EditView::GetEmptyItemSet()
416 : {
417 0 : return pImpEditView->pEditEngine->GetEmptyItemSet();
418 : }
419 :
420 181 : void EditView::SetAttribs( const SfxItemSet& rSet )
421 : {
422 : DBG_ASSERT( !pImpEditView->aEditSelection.IsInvalid(), "Blind Selection in ...." );
423 :
424 181 : pImpEditView->DrawSelection();
425 181 : pImpEditView->pEditEngine->SetAttribs( pImpEditView->GetEditSelection(), rSet, ATTRSPECIAL_WHOLEWORD );
426 181 : pImpEditView->pEditEngine->FormatAndUpdate( this );
427 181 : }
428 :
429 0 : void EditView::RemoveAttribsKeepLanguages( bool bRemoveParaAttribs )
430 : {
431 :
432 0 : pImpEditView->DrawSelection();
433 0 : pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
434 0 : EditSelection aSelection( pImpEditView->GetEditSelection() );
435 :
436 0 : for (sal_uInt16 nWID = EE_ITEMS_START; nWID <= EE_ITEMS_END; ++nWID)
437 : {
438 0 : bool bIsLang = EE_CHAR_LANGUAGE == nWID ||
439 0 : EE_CHAR_LANGUAGE_CJK == nWID ||
440 0 : EE_CHAR_LANGUAGE_CTL == nWID;
441 0 : if (!bIsLang)
442 0 : pImpEditView->pEditEngine->RemoveCharAttribs( aSelection, bRemoveParaAttribs, nWID );
443 : }
444 :
445 0 : pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
446 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
447 0 : }
448 :
449 0 : void EditView::RemoveAttribs( bool bRemoveParaAttribs, sal_uInt16 nWhich )
450 : {
451 :
452 0 : pImpEditView->DrawSelection();
453 0 : pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
454 0 : pImpEditView->pEditEngine->RemoveCharAttribs( pImpEditView->GetEditSelection(), bRemoveParaAttribs, nWhich );
455 0 : pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
456 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
457 0 : }
458 :
459 0 : void EditView::RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich )
460 : {
461 0 : pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS );
462 0 : pImpEditView->pEditEngine->RemoveCharAttribs( nPara, nWhich );
463 0 : pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_RESETATTRIBS );
464 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
465 0 : }
466 :
467 84 : SfxItemSet EditView::GetAttribs()
468 : {
469 : DBG_ASSERT( !pImpEditView->aEditSelection.IsInvalid(), "Blind Selection in ...." );
470 84 : return pImpEditView->pEditEngine->pImpEditEngine->GetAttribs( pImpEditView->GetEditSelection() );
471 : }
472 :
473 0 : void EditView::Undo()
474 : {
475 0 : pImpEditView->pEditEngine->Undo( this );
476 0 : }
477 :
478 0 : void EditView::Redo()
479 : {
480 0 : pImpEditView->pEditEngine->Redo( this );
481 0 : }
482 :
483 0 : sal_uInt32 EditView::Read( SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, bool bSelect, SvKeyValueIterator* pHTTPHeaderAttrs )
484 : {
485 0 : EditSelection aOldSel( pImpEditView->GetEditSelection() );
486 0 : pImpEditView->DrawSelection();
487 0 : pImpEditView->pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_READ );
488 0 : EditPaM aEndPaM = pImpEditView->pEditEngine->pImpEditEngine->Read( rInput, rBaseURL, eFormat, aOldSel, pHTTPHeaderAttrs );
489 0 : pImpEditView->pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_READ );
490 0 : EditSelection aNewSel( aEndPaM, aEndPaM );
491 0 : if ( bSelect )
492 : {
493 0 : aOldSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
494 0 : aNewSel.Min() = aOldSel.Min();
495 : }
496 :
497 0 : pImpEditView->SetEditSelection( aNewSel );
498 0 : bool bGotoCursor = pImpEditView->DoAutoScroll();
499 0 : ShowCursor( bGotoCursor );
500 :
501 0 : return rInput.GetError();
502 : }
503 :
504 0 : void EditView::Cut()
505 : {
506 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
507 0 : pImpEditView->CutCopy( aClipBoard, true );
508 0 : }
509 :
510 0 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > EditView::GetTransferable()
511 : {
512 : uno::Reference< datatransfer::XTransferable > xData =
513 0 : GetEditEngine()->CreateTransferable( pImpEditView->GetEditSelection() );
514 0 : return xData;
515 : }
516 :
517 0 : void EditView::Copy()
518 : {
519 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
520 0 : pImpEditView->CutCopy( aClipBoard, false );
521 0 : }
522 :
523 0 : void EditView::Paste()
524 : {
525 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
526 0 : pImpEditView->Paste( aClipBoard, false );
527 0 : }
528 :
529 0 : void EditView::PasteSpecial()
530 : {
531 0 : Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipBoard(GetWindow()->GetClipboard());
532 0 : pImpEditView->Paste(aClipBoard, true );
533 0 : }
534 :
535 0 : Point EditView::GetWindowPosTopLeft( sal_Int32 nParagraph )
536 : {
537 0 : Point aDocPos( pImpEditView->pEditEngine->GetDocPosTopLeft( nParagraph ) );
538 0 : return pImpEditView->GetWindowPos( aDocPos );
539 : }
540 :
541 106 : void EditView::SetSelectionMode( EESelectionMode eMode )
542 : {
543 106 : pImpEditView->SetSelectionMode( eMode );
544 106 : }
545 :
546 5 : OUString EditView::GetSelected()
547 : {
548 5 : return pImpEditView->pEditEngine->pImpEditEngine->GetSelected( pImpEditView->GetEditSelection() );
549 : }
550 :
551 0 : void EditView::MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos )
552 : {
553 0 : pImpEditView->pEditEngine->pImpEditEngine->UndoActionStart( EDITUNDO_MOVEPARAS );
554 0 : pImpEditView->pEditEngine->pImpEditEngine->MoveParagraphs( aParagraphs, nNewPos, this );
555 0 : pImpEditView->pEditEngine->pImpEditEngine->UndoActionEnd( EDITUNDO_MOVEPARAS );
556 0 : }
557 :
558 0 : void EditView::MoveParagraphs( long nDiff )
559 : {
560 0 : ESelection aSel = GetSelection();
561 0 : Range aRange( aSel.nStartPara, aSel.nEndPara );
562 0 : aRange.Justify();
563 0 : long nDest = ( nDiff > 0 ? aRange.Max() : aRange.Min() ) + nDiff;
564 0 : if ( nDiff > 0 )
565 0 : nDest++;
566 : DBG_ASSERT( ( nDest >= 0 ) && ( nDest <= pImpEditView->pEditEngine->GetParagraphCount() ), "MoveParagraphs - wrong Parameters!" );
567 0 : MoveParagraphs( aRange, sal::static_int_cast< sal_Int32 >( nDest ) );
568 0 : }
569 :
570 95 : void EditView::SetBackgroundColor( const Color& rColor )
571 : {
572 95 : pImpEditView->SetBackgroundColor( rColor );
573 95 : }
574 :
575 0 : Color EditView::GetBackgroundColor() const
576 : {
577 0 : return pImpEditView->GetBackgroundColor();
578 : }
579 :
580 9 : void EditView::setTiledRendering(bool bTiledRendering)
581 : {
582 9 : pImpEditView->setTiledRendering(bTiledRendering);
583 9 : }
584 :
585 516 : bool EditView::isTiledRendering()
586 : {
587 516 : return pImpEditView->isTiledRendering();
588 : }
589 :
590 9 : void EditView::registerLibreOfficeKitCallback(LibreOfficeKitCallback pCallback, void* pLibreOfficeKitData)
591 : {
592 9 : pImpEditView->registerLibreOfficeKitCallback(pCallback, pLibreOfficeKitData);
593 9 : }
594 :
595 284 : void EditView::SetControlWord( EVControlBits nWord )
596 : {
597 284 : pImpEditView->nControl = nWord;
598 284 : }
599 :
600 284 : EVControlBits EditView::GetControlWord() const
601 : {
602 284 : return pImpEditView->nControl;
603 : }
604 :
605 0 : EditTextObject* EditView::CreateTextObject()
606 : {
607 0 : return pImpEditView->pEditEngine->pImpEditEngine->CreateTextObject( pImpEditView->GetEditSelection() );
608 : }
609 :
610 0 : void EditView::InsertText( const EditTextObject& rTextObject )
611 : {
612 0 : pImpEditView->DrawSelection();
613 :
614 0 : pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_INSERT );
615 0 : EditSelection aTextSel( pImpEditView->pEditEngine->InsertText( rTextObject, pImpEditView->GetEditSelection() ) );
616 0 : pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_INSERT );
617 :
618 0 : aTextSel.Min() = aTextSel.Max(); // Selection not retained.
619 0 : pImpEditView->SetEditSelection( aTextSel );
620 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
621 0 : }
622 :
623 0 : void EditView::InsertText( ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xDataObj, const OUString& rBaseURL, bool bUseSpecial )
624 : {
625 0 : pImpEditView->pEditEngine->UndoActionStart( EDITUNDO_INSERT );
626 0 : pImpEditView->DeleteSelected();
627 : EditSelection aTextSel =
628 0 : pImpEditView->pEditEngine->InsertText(xDataObj, rBaseURL, pImpEditView->GetEditSelection().Max(), bUseSpecial);
629 0 : pImpEditView->pEditEngine->UndoActionEnd( EDITUNDO_INSERT );
630 :
631 0 : aTextSel.Min() = aTextSel.Max(); // Selection not retained.
632 0 : pImpEditView->SetEditSelection( aTextSel );
633 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
634 0 : }
635 :
636 181 : void EditView::SetEditEngineUpdateMode( bool bUpdate )
637 : {
638 181 : pImpEditView->pEditEngine->pImpEditEngine->SetUpdateMode( bUpdate, this );
639 181 : }
640 :
641 124 : void EditView::ForceUpdate()
642 : {
643 124 : pImpEditView->pEditEngine->pImpEditEngine->SetUpdateMode( true, this, true );
644 124 : }
645 :
646 0 : SfxStyleSheet* EditView::GetStyleSheet()
647 : {
648 0 : EditSelection aSel( pImpEditView->GetEditSelection() );
649 0 : aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
650 0 : sal_Int32 nStartPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( aSel.Min().GetNode() );
651 0 : sal_Int32 nEndPara = pImpEditView->pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() );
652 :
653 0 : SfxStyleSheet* pStyle = NULL;
654 0 : for ( sal_Int32 n = nStartPara; n <= nEndPara; n++ )
655 : {
656 0 : SfxStyleSheet* pTmpStyle = pImpEditView->pEditEngine->GetStyleSheet( n );
657 0 : if ( ( n != nStartPara ) && ( pStyle != pTmpStyle ) )
658 0 : return NULL; // Not unique.
659 0 : pStyle = pTmpStyle;
660 : }
661 0 : return pStyle;
662 : }
663 :
664 0 : const SfxStyleSheet* EditView::GetStyleSheet() const
665 : {
666 0 : return const_cast< EditView* >( this )->GetStyleSheet();
667 : }
668 :
669 83 : bool EditView::IsInsertMode() const
670 : {
671 83 : return pImpEditView->IsInsertMode();
672 : }
673 :
674 239 : void EditView::SetInsertMode( bool bInsert )
675 : {
676 239 : pImpEditView->SetInsertMode( bInsert );
677 239 : }
678 :
679 9 : void EditView::SetAnchorMode( EVAnchorMode eMode )
680 : {
681 9 : pImpEditView->SetAnchorMode( eMode );
682 9 : }
683 :
684 0 : EVAnchorMode EditView::GetAnchorMode() const
685 : {
686 0 : return pImpEditView->GetAnchorMode();
687 : }
688 :
689 0 : void EditView::TransliterateText( sal_Int32 nTransliterationMode )
690 : {
691 0 : EditSelection aOldSel( pImpEditView->GetEditSelection() );
692 0 : EditSelection aNewSel = pImpEditView->pEditEngine->TransliterateText( pImpEditView->GetEditSelection(), nTransliterationMode );
693 0 : if ( aNewSel != aOldSel )
694 : {
695 0 : pImpEditView->DrawSelection();
696 0 : pImpEditView->SetEditSelection( aNewSel );
697 0 : pImpEditView->DrawSelection();
698 : }
699 0 : }
700 :
701 0 : void EditView::CompleteAutoCorrect( vcl::Window* pFrameWin )
702 : {
703 0 : if ( !pImpEditView->HasSelection() && pImpEditView->pEditEngine->pImpEditEngine->GetStatus().DoAutoCorrect() )
704 : {
705 0 : pImpEditView->DrawSelection();
706 0 : EditSelection aSel = pImpEditView->GetEditSelection();
707 0 : aSel = pImpEditView->pEditEngine->EndOfWord( aSel.Max() );
708 0 : aSel = pImpEditView->pEditEngine->pImpEditEngine->AutoCorrect( aSel, 0, !IsInsertMode(), pFrameWin );
709 0 : pImpEditView->SetEditSelection( aSel );
710 0 : if ( pImpEditView->pEditEngine->IsModified() )
711 0 : pImpEditView->pEditEngine->FormatAndUpdate( this );
712 : }
713 0 : }
714 :
715 84 : EESpellState EditView::StartSpeller( bool bMultipleDoc )
716 : {
717 84 : if ( !pImpEditView->pEditEngine->pImpEditEngine->GetSpeller().is() )
718 0 : return EE_SPELL_NOSPELLER;
719 :
720 84 : return pImpEditView->pEditEngine->pImpEditEngine->Spell( this, bMultipleDoc );
721 : }
722 :
723 0 : EESpellState EditView::StartThesaurus()
724 : {
725 0 : if ( !pImpEditView->pEditEngine->pImpEditEngine->GetSpeller().is() )
726 0 : return EE_SPELL_NOSPELLER;
727 :
728 0 : return pImpEditView->pEditEngine->pImpEditEngine->StartThesaurus( this );
729 : }
730 :
731 0 : void EditView::StartTextConversion(
732 : LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont,
733 : sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc )
734 : {
735 0 : pImpEditView->pEditEngine->pImpEditEngine->Convert( this, nSrcLang, nDestLang, pDestFont, nOptions, bIsInteractive, bMultipleDoc );
736 0 : }
737 :
738 :
739 11 : sal_Int32 EditView::StartSearchAndReplace( const SvxSearchItem& rSearchItem )
740 : {
741 11 : return pImpEditView->pEditEngine->pImpEditEngine->StartSearchAndReplace( this, rSearchItem );
742 : }
743 :
744 0 : bool EditView::IsCursorAtWrongSpelledWord( bool bMarkIfWrong )
745 : {
746 0 : bool bIsWrong = false;
747 0 : if ( !HasSelection() )
748 : {
749 0 : EditPaM aPaM = pImpEditView->GetEditSelection().Max();
750 0 : bIsWrong = pImpEditView->IsWrongSpelledWord( aPaM, bMarkIfWrong );
751 : }
752 0 : return bIsWrong;
753 : }
754 :
755 0 : bool EditView::IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWrong )
756 : {
757 0 : Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
758 0 : aPos = pImpEditView->GetDocPos( aPos );
759 0 : EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
760 0 : return pImpEditView->IsWrongSpelledWord( aPaM , bMarkIfWrong );
761 : }
762 :
763 0 : void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<>* pCallBack )
764 : {
765 :
766 0 : Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
767 0 : aPos = pImpEditView->GetDocPos( aPos );
768 0 : EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aPos, false);
769 0 : Reference< linguistic2::XSpellChecker1 > xSpeller( pImpEditView->pEditEngine->pImpEditEngine->GetSpeller() );
770 0 : ESelection aOldSel = GetSelection();
771 0 : if ( xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, true ) )
772 : {
773 0 : PopupMenu aPopupMenu( EditResId( RID_MENU_SPELL ) );
774 0 : PopupMenu *pAutoMenu = aPopupMenu.GetPopupMenu( MN_AUTOCORR );
775 0 : PopupMenu *pInsertMenu = aPopupMenu.GetPopupMenu( MN_INSERT ); // add word to user-dictionaries
776 0 : pInsertMenu->SetMenuFlags( MenuFlags::NoAutoMnemonics ); //! necessary to retrieve the correct dictionary names later
777 :
778 0 : EditPaM aPaM2( aPaM );
779 0 : aPaM2.SetIndex( aPaM2.GetIndex()+1 );
780 :
781 : // Are there any replace suggestions?
782 0 : OUString aSelected( GetSelected() );
783 :
784 : // restrict the maximal number of suggestions displayed
785 : // in the context menu.
786 : // Note: That could of course be done by clipping the
787 : // resulting sequence but the current third party
788 : // implementations result differs greatly if the number of
789 : // suggestions to be retuned gets changed. Statistically
790 : // it gets much better if told to return e.g. only 7 strings
791 : // than returning e.g. 16 suggestions and using only the
792 : // first 7. Thus we hand down the value to use to that
793 : // implementation here by providing an additional parameter.
794 0 : Sequence< PropertyValue > aPropVals(1);
795 0 : PropertyValue &rVal = aPropVals.getArray()[0];
796 0 : rVal.Name = UPN_MAX_NUMBER_OF_SUGGESTIONS;
797 0 : rVal.Value <<= (sal_Int16) 7;
798 :
799 : // Are there any replace suggestions?
800 : Reference< linguistic2::XSpellAlternatives > xSpellAlt =
801 0 : xSpeller->spell( aSelected, pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 ), aPropVals );
802 :
803 0 : Reference< linguistic2::XLanguageGuessing > xLangGuesser( EE_DLL().GetGlobalData()->GetLanguageGuesser() );
804 :
805 : // check if text might belong to a different language...
806 0 : LanguageType nGuessLangWord = LANGUAGE_NONE;
807 0 : LanguageType nGuessLangPara = LANGUAGE_NONE;
808 0 : if (xSpellAlt.is() && xLangGuesser.is())
809 : {
810 0 : OUString aParaText;
811 0 : ContentNode *pNode = aPaM.GetNode();
812 0 : if (pNode)
813 : {
814 0 : aParaText = pNode->GetString();
815 : }
816 : else
817 : {
818 : OSL_FAIL( "content node is NULL" );
819 : }
820 :
821 0 : nGuessLangWord = CheckLanguage( xSpellAlt->getWord(), xSpeller, xLangGuesser, false );
822 0 : nGuessLangPara = CheckLanguage( aParaText, xSpeller, xLangGuesser, true );
823 : }
824 0 : if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
825 : {
826 : // make sure LANGUAGE_NONE gets not used as menu entry
827 0 : if (nGuessLangWord == LANGUAGE_NONE)
828 0 : nGuessLangWord = nGuessLangPara;
829 0 : if (nGuessLangPara == LANGUAGE_NONE)
830 0 : nGuessLangPara = nGuessLangWord;
831 :
832 0 : aPopupMenu.InsertSeparator();
833 0 : OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
834 0 : OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
835 0 : OUString aWordStr( EE_RESSTR( RID_STR_WORD ) );
836 0 : aWordStr = aWordStr.replaceFirst( "%x", aTmpWord );
837 0 : OUString aParaStr( EE_RESSTR( RID_STR_PARAGRAPH ) );
838 0 : aParaStr = aParaStr.replaceFirst( "%x", aTmpPara );
839 0 : aPopupMenu.InsertItem( MN_WORDLANGUAGE, aWordStr );
840 0 : aPopupMenu.SetHelpId( MN_WORDLANGUAGE, HID_EDITENG_SPELLER_WORDLANGUAGE );
841 0 : aPopupMenu.InsertItem( MN_PARALANGUAGE, aParaStr );
842 0 : aPopupMenu.SetHelpId( MN_PARALANGUAGE, HID_EDITENG_SPELLER_PARALANGUAGE );
843 : }
844 :
845 : // ## Create mnemonics here
846 0 : if ( Application::IsAutoMnemonicEnabled() )
847 : {
848 0 : aPopupMenu.CreateAutoMnemonics();
849 0 : aPopupMenu.SetMenuFlags( aPopupMenu.GetMenuFlags() | MenuFlags::NoAutoMnemonics );
850 : }
851 :
852 : // Replace suggestions...
853 0 : Sequence< OUString > aAlt;
854 0 : if (xSpellAlt.is())
855 0 : aAlt = xSpellAlt->getAlternatives();
856 0 : const OUString *pAlt = aAlt.getConstArray();
857 0 : sal_uInt16 nWords = (sal_uInt16) aAlt.getLength();
858 0 : if ( nWords )
859 : {
860 0 : for ( sal_uInt16 nW = 0; nW < nWords; nW++ )
861 : {
862 0 : OUString aAlternate( pAlt[nW] );
863 0 : aPopupMenu.InsertItem( MN_ALTSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
864 0 : pAutoMenu->InsertItem( MN_AUTOSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
865 0 : }
866 0 : aPopupMenu.InsertSeparator(OString(), nWords);
867 : }
868 : else
869 0 : aPopupMenu.RemoveItem( MN_AUTOCORR ); // delete?
870 :
871 0 : SvtLinguConfig aCfg;
872 :
873 0 : Reference< linguistic2::XSearchableDictionaryList > xDicList( SvxGetDictionaryList() );
874 0 : Sequence< Reference< linguistic2::XDictionary > > aDics;
875 0 : if (xDicList.is())
876 : {
877 0 : const Reference< linguistic2::XDictionary > *pDic = NULL;
878 : // add the default positive dictionary to dic-list (if not already done).
879 : // This is to ensure that there is at least one dictionary to which
880 : // words could be added.
881 0 : uno::Reference< linguistic2::XDictionary > xDic( SvxGetOrCreatePosDic( xDicList ) );
882 0 : if (xDic.is())
883 0 : xDic->setActive( sal_True );
884 :
885 0 : aDics = xDicList->getDictionaries();
886 0 : pDic = aDics.getConstArray();
887 0 : sal_uInt16 nCheckedLanguage = pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 );
888 0 : sal_uInt16 nDicCount = (sal_uInt16)aDics.getLength();
889 0 : for (sal_uInt16 i = 0; i < nDicCount; i++)
890 : {
891 0 : uno::Reference< linguistic2::XDictionary > xDicTmp( pDic[i], uno::UNO_QUERY );
892 0 : if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
893 0 : continue;
894 :
895 0 : uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
896 0 : LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
897 0 : if( xDicTmp->isActive()
898 0 : && xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
899 0 : && (nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
900 0 : && (!xStor.is() || !xStor->isReadonly()) )
901 : {
902 : // the extra 1 is because of the (possible) external
903 : // linguistic entry above
904 0 : sal_uInt16 nPos = MN_DICTSTART + i;
905 0 : pInsertMenu->InsertItem( nPos, xDicTmp->getName() );
906 0 : aDicNameSingle = xDicTmp->getName();
907 :
908 0 : uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
909 0 : if (xSvcInfo.is())
910 : {
911 : OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
912 0 : xSvcInfo->getImplementationName()) );
913 0 : if (!aDictionaryImageUrl.isEmpty() )
914 : {
915 0 : Image aImage( aDictionaryImageUrl );
916 0 : pInsertMenu->SetItemImage( nPos, aImage );
917 0 : }
918 0 : }
919 : }
920 0 : }
921 : }
922 0 : if ( pInsertMenu->GetItemCount() != 1)
923 0 : aPopupMenu.EnableItem( MN_INSERT_SINGLE, false );
924 0 : if ( pInsertMenu->GetItemCount() < 2 )
925 0 : aPopupMenu.EnableItem( MN_INSERT, false );
926 :
927 0 : aPopupMenu.RemoveDisabledEntries( true, true );
928 :
929 0 : Rectangle aTempRect = pImpEditView->pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GETCRSR_TXTONLY );
930 0 : Point aScreenPos = pImpEditView->GetWindowPos( aTempRect.TopLeft() );
931 0 : aScreenPos = pImpEditView->GetWindow()->OutputToScreenPixel( aScreenPos );
932 0 : aTempRect = pImpEditView->GetWindow()->LogicToPixel( Rectangle(aScreenPos, aTempRect.GetSize() ));
933 :
934 0 : sal_uInt16 nId = aPopupMenu.Execute( pImpEditView->GetWindow(), aTempRect, PopupMenuFlags::NoMouseUpClose );
935 0 : if ( nId == MN_IGNORE )
936 : {
937 0 : OUString aWord = pImpEditView->SpellIgnoreOrAddWord( false );
938 0 : if ( pCallBack )
939 : {
940 0 : SpellCallbackInfo aInf( SpellCallbackCommand::IGNOREWORD, aWord );
941 0 : pCallBack->Call( &aInf );
942 : }
943 0 : SetSelection( aOldSel );
944 : }
945 0 : else if ( ( nId == MN_WORDLANGUAGE ) || ( nId == MN_PARALANGUAGE ) )
946 : {
947 0 : LanguageType nLangToUse = (nId == MN_WORDLANGUAGE) ? nGuessLangWord : nGuessLangPara;
948 0 : SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
949 :
950 0 : SfxItemSet aAttrs = GetEditEngine()->GetEmptyItemSet();
951 0 : if (nScriptType == SvtScriptType::LATIN)
952 0 : aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE ) );
953 0 : if (nScriptType == SvtScriptType::COMPLEX)
954 0 : aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
955 0 : if (nScriptType == SvtScriptType::ASIAN)
956 0 : aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
957 0 : if ( nId == MN_PARALANGUAGE )
958 : {
959 0 : ESelection aSel = GetSelection();
960 0 : aSel.nStartPos = 0;
961 0 : aSel.nEndPos = EE_TEXTPOS_ALL;
962 0 : SetSelection( aSel );
963 : }
964 0 : SetAttribs( aAttrs );
965 0 : pImpEditView->pEditEngine->pImpEditEngine->StartOnlineSpellTimer();
966 :
967 0 : if ( pCallBack )
968 : {
969 0 : SpellCallbackInfo aInf( ( nId == MN_WORDLANGUAGE ) ? SpellCallbackCommand::WORDLANGUAGE : SpellCallbackCommand::PARALANGUAGE, nLangToUse );
970 0 : pCallBack->Call( &aInf );
971 : }
972 0 : SetSelection( aOldSel );
973 : }
974 0 : else if ( nId == MN_SPELLING )
975 : {
976 0 : if ( !pCallBack )
977 : {
978 : // Set Cursor before word...
979 0 : EditPaM aCursor = pImpEditView->GetEditSelection().Min();
980 0 : pImpEditView->DrawSelection();
981 0 : pImpEditView->SetEditSelection( EditSelection( aCursor, aCursor ) );
982 0 : pImpEditView->DrawSelection();
983 : // Crashes when no SfxApp
984 0 : pImpEditView->pEditEngine->pImpEditEngine->Spell( this, false );
985 : }
986 : else
987 : {
988 0 : SpellCallbackInfo aInf( SpellCallbackCommand::STARTSPELLDLG, OUString() );
989 0 : pCallBack->Call( &aInf );
990 : }
991 : }
992 0 : else if ( nId >= MN_DICTSTART || nId == MN_INSERT_SINGLE )
993 : {
994 0 : OUString aDicName;
995 0 : if (nId >= MN_DICTSTART)
996 0 : aDicName = pInsertMenu->GetItemText(nId);
997 : else
998 0 : aDicName = aDicNameSingle;
999 :
1000 0 : uno::Reference< linguistic2::XDictionary > xDic;
1001 0 : if (xDicList.is())
1002 0 : xDic = xDicList->getDictionaryByName( aDicName );
1003 :
1004 0 : if (xDic.is())
1005 0 : xDic->add( aSelected, sal_False, OUString() );
1006 : // save modified user-dictionary if it is persistent
1007 0 : Reference< frame::XStorable > xSavDic( xDic, UNO_QUERY );
1008 0 : if (xSavDic.is())
1009 0 : xSavDic->store();
1010 :
1011 0 : aPaM.GetNode()->GetWrongList()->ResetInvalidRange(0, aPaM.GetNode()->Len());
1012 0 : pImpEditView->pEditEngine->pImpEditEngine->StartOnlineSpellTimer();
1013 :
1014 0 : if ( pCallBack )
1015 : {
1016 0 : SpellCallbackInfo aInf( SpellCallbackCommand::ADDTODICTIONARY, aSelected );
1017 0 : pCallBack->Call( &aInf );
1018 : }
1019 0 : SetSelection( aOldSel );
1020 : }
1021 0 : else if ( nId >= MN_AUTOSTART )
1022 : {
1023 : DBG_ASSERT(nId - MN_AUTOSTART < aAlt.getLength(), "index out of range");
1024 0 : OUString aWord = pAlt[nId - MN_AUTOSTART];
1025 0 : SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
1026 0 : if ( pAutoCorrect )
1027 0 : pAutoCorrect->PutText( aSelected, aWord, pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 ) );
1028 0 : InsertText( aWord );
1029 : }
1030 0 : else if ( nId >= MN_ALTSTART ) // Replace
1031 : {
1032 : DBG_ASSERT(nId - MN_ALTSTART < aAlt.getLength(), "index out of range");
1033 0 : OUString aWord = pAlt[nId - MN_ALTSTART];
1034 0 : InsertText( aWord );
1035 : }
1036 : else
1037 : {
1038 0 : SetSelection( aOldSel );
1039 0 : }
1040 0 : }
1041 0 : }
1042 :
1043 0 : bool EditView::SelectCurrentWord( sal_Int16 nWordType )
1044 : {
1045 0 : EditSelection aCurSel( pImpEditView->GetEditSelection() );
1046 0 : pImpEditView->DrawSelection();
1047 0 : aCurSel = pImpEditView->pEditEngine->SelectWord(aCurSel.Max(), nWordType);
1048 0 : pImpEditView->SetEditSelection( aCurSel );
1049 0 : pImpEditView->DrawSelection();
1050 0 : ShowCursor( true, false );
1051 0 : return aCurSel.HasRange();
1052 : }
1053 :
1054 0 : void EditView::InsertField( const SvxFieldItem& rFld )
1055 : {
1056 0 : EditEngine* pEE = pImpEditView->pEditEngine;
1057 0 : pImpEditView->DrawSelection();
1058 0 : pEE->UndoActionStart( EDITUNDO_INSERT );
1059 0 : EditPaM aPaM( pEE->InsertField( pImpEditView->GetEditSelection(), rFld ) );
1060 0 : pEE->UndoActionEnd( EDITUNDO_INSERT );
1061 0 : pImpEditView->SetEditSelection( EditSelection( aPaM, aPaM ) );
1062 0 : pEE->UpdateFields();
1063 0 : pEE->FormatAndUpdate( this );
1064 0 : }
1065 :
1066 1 : const SvxFieldItem* EditView::GetFieldUnderMousePointer() const
1067 : {
1068 : sal_Int32 nPara;
1069 : sal_Int32 nPos;
1070 1 : return GetFieldUnderMousePointer( nPara, nPos );
1071 : }
1072 :
1073 1 : const SvxFieldItem* EditView::GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const
1074 : {
1075 1 : return pImpEditView->GetField( rPos, pPara, pPos );
1076 : }
1077 :
1078 1 : const SvxFieldItem* EditView::GetFieldUnderMousePointer( sal_Int32& nPara, sal_Int32& nPos ) const
1079 : {
1080 1 : Point aPos = pImpEditView->GetWindow()->GetPointerPosPixel();
1081 1 : aPos = pImpEditView->GetWindow()->PixelToLogic( aPos );
1082 1 : return GetField( aPos, &nPara, &nPos );
1083 : }
1084 :
1085 0 : const SvxFieldItem* EditView::GetFieldAtSelection() const
1086 : {
1087 0 : EditSelection aSel( pImpEditView->GetEditSelection() );
1088 0 : aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
1089 : // Only when cursor is in font of field, no selection,
1090 : // or only selecting field
1091 0 : if ( ( aSel.Min().GetNode() == aSel.Max().GetNode() ) &&
1092 0 : ( ( aSel.Max().GetIndex() == aSel.Min().GetIndex() ) ||
1093 0 : ( aSel.Max().GetIndex() == aSel.Min().GetIndex()+1 ) ) )
1094 : {
1095 0 : EditPaM aPaM = aSel.Min();
1096 0 : const CharAttribList::AttribsType& rAttrs = aPaM.GetNode()->GetCharAttribs().GetAttribs();
1097 0 : const sal_Int32 nXPos = aPaM.GetIndex();
1098 0 : for (size_t nAttr = rAttrs.size(); nAttr; )
1099 : {
1100 0 : const EditCharAttrib& rAttr = rAttrs[--nAttr];
1101 0 : if (rAttr.GetStart() == nXPos)
1102 0 : if (rAttr.Which() == EE_FEATURE_FIELD)
1103 : {
1104 : DBG_ASSERT(rAttr.GetItem()->ISA( SvxFieldItem ), "No FeldItem...");
1105 0 : return static_cast<const SvxFieldItem*>(rAttr.GetItem());
1106 : }
1107 : }
1108 : }
1109 0 : return 0;
1110 : }
1111 :
1112 7 : void EditView::SetInvalidateMore( sal_uInt16 nPixel )
1113 : {
1114 7 : pImpEditView->SetInvalidateMore( nPixel );
1115 7 : }
1116 :
1117 26 : sal_uInt16 EditView::GetInvalidateMore() const
1118 : {
1119 26 : return (sal_uInt16)pImpEditView->GetInvalidateMore();
1120 : }
1121 :
1122 0 : static void ChangeFontSizeImpl( EditView* pEditView, bool bGrow, const ESelection& rSel, const FontList* pFontList )
1123 : {
1124 0 : pEditView->SetSelection( rSel );
1125 :
1126 0 : SfxItemSet aSet( pEditView->GetAttribs() );
1127 0 : if( EditView::ChangeFontSize( bGrow, aSet, pFontList ) )
1128 : {
1129 0 : SfxItemSet aNewSet( pEditView->GetEmptyItemSet() );
1130 0 : aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT ), EE_CHAR_FONTHEIGHT );
1131 0 : aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CJK ), EE_CHAR_FONTHEIGHT_CJK );
1132 0 : aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CTL ), EE_CHAR_FONTHEIGHT_CTL );
1133 0 : pEditView->SetAttribs( aNewSet );
1134 0 : }
1135 0 : }
1136 :
1137 0 : void EditView::ChangeFontSize( bool bGrow, const FontList* pFontList )
1138 : {
1139 :
1140 0 : EditEngine& rEditEngine = *pImpEditView->pEditEngine;
1141 :
1142 0 : ESelection aSel( GetSelection() );
1143 0 : ESelection aOldSelection( aSel );
1144 0 : aSel.Adjust();
1145 :
1146 0 : if( !aSel.HasRange() )
1147 : {
1148 0 : aSel = rEditEngine.GetWord( aSel, com::sun::star::i18n::WordType::DICTIONARY_WORD );
1149 : }
1150 :
1151 0 : if( aSel.HasRange() )
1152 : {
1153 0 : for( sal_Int32 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
1154 : {
1155 0 : std::vector<sal_Int32> aPortions;
1156 0 : rEditEngine.GetPortions( nPara, aPortions );
1157 :
1158 0 : if( aPortions.empty() )
1159 0 : aPortions.push_back( rEditEngine.GetTextLen(nPara) );
1160 :
1161 0 : const sal_Int32 nBeginPos = (nPara == aSel.nStartPara) ? aSel.nStartPos : 0;
1162 0 : const sal_Int32 nEndPos = (nPara == aSel.nEndPara) ? aSel.nEndPos : EE_TEXTPOS_ALL;
1163 :
1164 0 : for ( size_t nPos = 0; nPos < aPortions.size(); ++nPos )
1165 : {
1166 0 : sal_Int32 nPortionEnd = aPortions[ nPos ];
1167 0 : sal_Int32 nPortionStart = nPos > 0 ? aPortions[ nPos - 1 ] : 0;
1168 :
1169 0 : if( (nPortionEnd < nBeginPos) || (nPortionStart > nEndPos) )
1170 0 : continue;
1171 :
1172 0 : if( nPortionStart < nBeginPos )
1173 0 : nPortionStart = nBeginPos;
1174 0 : if( nPortionEnd > nEndPos )
1175 0 : nPortionEnd = nEndPos;
1176 :
1177 0 : if( nPortionStart == nPortionEnd )
1178 0 : continue;
1179 :
1180 0 : ESelection aPortionSel( nPara, nPortionStart, nPara, nPortionEnd );
1181 0 : ChangeFontSizeImpl( this, bGrow, aPortionSel, pFontList );
1182 : }
1183 0 : }
1184 : }
1185 : else
1186 : {
1187 0 : ChangeFontSizeImpl( this, bGrow, aSel, pFontList );
1188 : }
1189 :
1190 0 : SetSelection( aOldSelection );
1191 0 : }
1192 :
1193 0 : bool EditView::ChangeFontSize( bool bGrow, SfxItemSet& rSet, const FontList* pFontList )
1194 : {
1195 : static const sal_uInt16 gFontSizeWichMap[] = { EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT_CJK, EE_CHAR_FONTHEIGHT_CTL, 0 };
1196 :
1197 0 : const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(&rSet.Get( EE_CHAR_FONTINFO ));
1198 0 : if( !pFontItem || !pFontList )
1199 0 : return false;
1200 :
1201 0 : bool bRet = false;
1202 :
1203 0 : const sal_uInt16* pWhich = gFontSizeWichMap;
1204 0 : while( *pWhich )
1205 : {
1206 0 : SvxFontHeightItem aFontHeightItem( static_cast<const SvxFontHeightItem&>(rSet.Get( *pWhich )) );
1207 0 : long nHeight = aFontHeightItem.GetHeight();
1208 0 : const SfxMapUnit eUnit = rSet.GetPool()->GetMetric( *pWhich );
1209 0 : nHeight = OutputDevice::LogicToLogic( nHeight * 10, (MapUnit)eUnit, MAP_POINT );
1210 :
1211 0 : vcl::FontInfo aFontInfo = pFontList->Get( pFontItem->GetFamilyName(), pFontItem->GetStyleName() );
1212 0 : const sal_IntPtr* pAry = pFontList->GetSizeAry( aFontInfo );
1213 :
1214 0 : if( bGrow )
1215 : {
1216 0 : while( *pAry )
1217 : {
1218 0 : if( *pAry > nHeight )
1219 : {
1220 0 : nHeight = *pAry;
1221 0 : break;
1222 : }
1223 0 : pAry++;
1224 : }
1225 :
1226 0 : if( *pAry == 0 )
1227 : {
1228 0 : nHeight += (nHeight + 5) / 10;
1229 0 : if( nHeight > 9999 )
1230 0 : nHeight = 9999;
1231 : }
1232 :
1233 : }
1234 0 : else if( *pAry )
1235 : {
1236 0 : bool bFound = false;
1237 0 : if( *pAry < nHeight )
1238 : {
1239 0 : pAry++;
1240 0 : while( *pAry )
1241 : {
1242 0 : if( *pAry >= nHeight )
1243 : {
1244 0 : nHeight = pAry[-1];
1245 0 : bFound = true;
1246 0 : break;
1247 : }
1248 0 : pAry++;
1249 : }
1250 : }
1251 :
1252 0 : if( !bFound )
1253 : {
1254 0 : nHeight -= (nHeight + 5) / 10;
1255 0 : if( nHeight < 2 )
1256 0 : nHeight = 2;
1257 : }
1258 : }
1259 :
1260 0 : if( (nHeight >= 2) && (nHeight <= 9999 ) )
1261 : {
1262 0 : nHeight = OutputDevice::LogicToLogic( nHeight, MAP_POINT, (MapUnit)eUnit ) / 10;
1263 :
1264 0 : if( nHeight != (long)aFontHeightItem.GetHeight() )
1265 : {
1266 0 : aFontHeightItem.SetHeight( nHeight );
1267 0 : rSet.Put( aFontHeightItem, *pWhich );
1268 0 : bRet = true;
1269 : }
1270 : }
1271 0 : pWhich++;
1272 0 : }
1273 0 : return bRet;
1274 : }
1275 :
1276 0 : OUString EditView::GetSurroundingText() const
1277 : {
1278 0 : EditSelection aSel( pImpEditView->GetEditSelection() );
1279 0 : aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
1280 :
1281 0 : if( HasSelection() )
1282 : {
1283 0 : OUString aStr = pImpEditView->pEditEngine->GetSelected(aSel);
1284 :
1285 : // Stop reconversion if the selected text includes a line break.
1286 0 : if ( aStr.indexOf( 0x0A ) == -1 )
1287 0 : return aStr;
1288 : else
1289 0 : return OUString();
1290 : }
1291 : else
1292 : {
1293 0 : aSel.Min().SetIndex( 0 );
1294 0 : aSel.Max().SetIndex( aSel.Max().GetNode()->Len() );
1295 0 : return pImpEditView->pEditEngine->GetSelected(aSel);
1296 : }
1297 : }
1298 :
1299 0 : Selection EditView::GetSurroundingTextSelection() const
1300 : {
1301 0 : ESelection aSelection( GetSelection() );
1302 0 : aSelection.Adjust();
1303 :
1304 0 : if( HasSelection() )
1305 : {
1306 0 : EditSelection aSel( pImpEditView->GetEditSelection() );
1307 0 : aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
1308 0 : OUString aStr = pImpEditView->pEditEngine->GetSelected(aSel);
1309 :
1310 : // Stop reconversion if the selected text includes a line break.
1311 0 : if ( aStr.indexOf( 0x0A ) == -1 )
1312 0 : return Selection( 0, aSelection.nEndPos - aSelection.nStartPos );
1313 : else
1314 0 : return Selection( 0, 0 );
1315 : }
1316 : else
1317 : {
1318 0 : return Selection( aSelection.nStartPos, aSelection.nEndPos );
1319 : }
1320 : }
1321 :
1322 1 : void EditView::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark)
1323 : {
1324 1 : Point aDocPos(pImpEditView->GetDocPos(rPosition));
1325 1 : EditPaM aPaM = pImpEditView->pEditEngine->GetPaM(aDocPos);
1326 1 : EditSelection aSelection(pImpEditView->GetEditSelection());
1327 :
1328 : // Explicitly create or delete the selection.
1329 1 : if (bClearMark)
1330 : {
1331 0 : pImpEditView->DeselectAll();
1332 0 : aSelection = pImpEditView->GetEditSelection();
1333 : }
1334 : else
1335 1 : pImpEditView->CreateAnchor();
1336 :
1337 1 : if (bPoint)
1338 1 : aSelection.Max() = aPaM;
1339 : else
1340 0 : aSelection.Min() = aPaM;
1341 :
1342 1 : if (pImpEditView->GetEditSelection().Min() != aSelection.Min())
1343 1 : pImpEditView->pEditEngine->CursorMoved(pImpEditView->GetEditSelection().Min().GetNode());
1344 1 : pImpEditView->DrawSelection(aSelection);
1345 1 : if (pImpEditView->GetEditSelection() != aSelection)
1346 1 : pImpEditView->SetEditSelection(aSelection);
1347 1 : ShowCursor(/*bGotoCursor=*/false, /*bForceCursor=*/true);
1348 445 : }
1349 :
1350 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|