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