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