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