1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editview.cxx,v $
10 * $Revision: 1.52.74.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <eeng_pch.hxx>
35 #include <com/sun/star/i18n/WordType.hpp>
36 #include <vcl/metric.hxx>
38 #define _SOLAR__PRIVATE 1
40 #include <i18npool/mslangid.hxx>
41 #include <svtools/languageoptions.hxx>
42 #include <svtools/ctrltool.hxx>
44 #include <sfx2/srchitem.hxx>
46 #define _SVSTDARR_USHORTS
47 #include <svtools/svstdarr.hxx>
49 #include <impedit.hxx>
50 #include <svx/editeng.hxx>
51 #include <svx/editview.hxx>
52 #include <svx/flditem.hxx>
53 #include <svx/svxacorr.hxx>
54 #include <svx/langitem.hxx>
55 #include <svx/fhgtitem.hxx>
57 #include <eerdll2.hxx>
58 #include <editeng.hrc>
59 #include <dlgutil.hxx>
61 #include <i18npool/lang.h>
62 #include <vcl/menu.hxx>
63 #include <vcl/window.hxx>
64 #include <acorrcfg.hxx>
65 #include <unolingu.hxx>
66 #include <fontitem.hxx>
68 #include <com/sun/star/frame/XStorable.hpp>
69 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUES_HDL_
70 #include <com/sun/star/beans/PropertyValues.hdl>
72 #include <com/sun/star/lang/Locale.hpp>
73 #include <linguistic/lngprops.hxx>
74 #include <vcl/svapp.hxx>
75 #include <vcl/settings.hxx>
76 #include <svtools/lingucfg.hxx>
79 using ::rtl::OUString
;
80 using namespace com::sun::star
;
81 using namespace com::sun::star::uno
;
82 using namespace com::sun::star::beans
;
83 using namespace com::sun::star::linguistic2
;
89 // From SW => Create common method
90 LanguageType
lcl_CheckLanguage(
91 const OUString
&rText
,
92 Reference
< XSpellChecker1
> xSpell
,
93 Reference
< linguistic2::XLanguageGuessing
> xLangGuess
,
94 sal_Bool bIsParaText
)
96 LanguageType nLang
= LANGUAGE_NONE
;
97 if (bIsParaText
) // check longer texts with language-guessing...
102 lang::Locale
aLocale( xLangGuess
->guessPrimaryLanguage( rText
, 0, rText
.getLength()) );
104 // get language as from "Tools/Options - Language Settings - Languages: Locale setting"
105 LanguageType nTmpLang
= Application::GetSettings().GetLanguage();
107 // if the result from language guessing does not provide a 'Country' part
108 // try to get it by looking up the locale setting of the office.
109 if (aLocale
.Country
.getLength() == 0)
111 lang::Locale aTmpLocale
= SvxCreateLocale( nTmpLang
);
112 if (aTmpLocale
.Language
== aLocale
.Language
)
115 if (nLang
== LANGUAGE_NONE
) // language not found by looking up the sytem language...
116 nLang
= MsLangId::convertLocaleToLanguageWithFallback( aLocale
);
117 if (nLang
== LANGUAGE_SYSTEM
)
119 if (nLang
== LANGUAGE_DONTKNOW
)
120 nLang
= LANGUAGE_NONE
;
122 else // check single word
128 // build list of languages to check
130 LanguageType aLangList
[4];
131 const AllSettings
& rSettings
= Application::GetSettings();
132 SvtLinguOptions aLinguOpt
;
133 SvtLinguConfig().GetOptions( aLinguOpt
);
134 // The default document language from "Tools/Options - Language Settings - Languages: Western"
135 aLangList
[0] = aLinguOpt
.nDefaultLanguage
;
136 // The one from "Tools/Options - Language Settings - Languages: User interface"
137 aLangList
[1] = rSettings
.GetUILanguage();
138 // The one from "Tools/Options - Language Settings - Languages: Locale setting"
139 aLangList
[2] = rSettings
.GetLanguage();
141 aLangList
[3] = LANGUAGE_ENGLISH_US
;
143 lang::Locale
a0( SvxCreateLocale( aLangList
[0] ) );
144 lang::Locale
a1( SvxCreateLocale( aLangList
[1] ) );
145 lang::Locale
a2( SvxCreateLocale( aLangList
[2] ) );
146 lang::Locale
a3( SvxCreateLocale( aLangList
[3] ) );
149 INT32 nCount
= sizeof(aLangList
) / sizeof(aLangList
[0]);
150 for (INT32 i
= 0; i
< nCount
; i
++)
152 INT16 nTmpLang
= aLangList
[i
];
153 if (nTmpLang
!= LANGUAGE_NONE
&& nTmpLang
!= LANGUAGE_DONTKNOW
)
155 if (xSpell
->hasLanguage( nTmpLang
) &&
156 xSpell
->isValid( rText
, nTmpLang
, Sequence
< PropertyValue
>() ))
169 \f// ----------------------------------------------------------------------
171 // ----------------------------------------------------------------------
172 EditView::EditView( EditEngine
* pEng
, Window
* pWindow
)
174 DBG_CTOR( EditView
, 0 );
175 pImpEditView
= new ImpEditView( this, pEng
, pWindow
);
178 EditView::~EditView()
180 DBG_DTOR( EditView
, 0 );
184 ImpEditEngine
* EditView::GetImpEditEngine() const
186 DBG_CHKTHIS( EditView
, 0 );
187 return pImpEditView
->pEditEngine
->pImpEditEngine
;
190 EditEngine
* EditView::GetEditEngine() const
192 DBG_CHKTHIS( EditView
, 0 );
193 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
194 return pImpEditView
->pEditEngine
;
197 void EditView::Invalidate()
199 DBG_CHKTHIS( EditView
, 0 );
200 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
201 if ( !pImpEditView
->DoInvalidateMore() )
202 pImpEditView
->GetWindow()->Invalidate( pImpEditView
->aOutArea
);
205 Rectangle
aRect( pImpEditView
->aOutArea
);
206 long nMore
= pImpEditView
->GetWindow()->PixelToLogic( Size( pImpEditView
->GetInvalidateMore(), 0 ) ).Width();
207 aRect
.Left() -= nMore
;
208 aRect
.Right() += nMore
;
209 aRect
.Top() -= nMore
;
210 aRect
.Bottom() += nMore
;
211 pImpEditView
->GetWindow()->Invalidate( aRect
);
215 void EditView::SetReadOnly( sal_Bool bReadOnly
)
217 DBG_CHKTHIS( EditView
, 0 );
218 pImpEditView
->bReadOnly
= bReadOnly
;
221 sal_Bool
EditView::IsReadOnly() const
223 DBG_CHKTHIS( EditView
, 0 );
224 return pImpEditView
->bReadOnly
;
227 void EditView::SetSelection( const ESelection
& rESel
)
229 DBG_CHKTHIS( EditView
, 0 );
230 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
232 // Falls jemand gerade ein leeres Attribut hinterlassen hat,
233 // und dann der Outliner die Selektion manipulitert:
234 if ( !pImpEditView
->GetEditSelection().HasRange() )
236 ContentNode
* pNode
= pImpEditView
->GetEditSelection().Max().GetNode();
237 PIMPEE
->CursorMoved( pNode
);
239 EditSelection
aNewSelection( PIMPEE
->ConvertSelection( rESel
.nStartPara
, rESel
.nStartPos
, rESel
.nEndPara
, rESel
.nEndPos
) );
241 // Wenn nach einem KeyInput die Selection manipuliert wird:
242 PIMPEE
->CheckIdleFormatter();
244 // Selektion darf nicht bei einem unsichtbaren Absatz Starten/Enden:
245 ParaPortion
* pPortion
= PIMPEE
->FindParaPortion( aNewSelection
.Min().GetNode() );
246 if ( !pPortion
->IsVisible() )
248 pPortion
= PIMPEE
->GetPrevVisPortion( pPortion
);
249 ContentNode
* pNode
= pPortion
? pPortion
->GetNode() : PIMPEE
->GetEditDoc().GetObject( 0 );
250 aNewSelection
.Min() = EditPaM( pNode
, pNode
->Len() );
252 pPortion
= PIMPEE
->FindParaPortion( aNewSelection
.Max().GetNode() );
253 if ( !pPortion
->IsVisible() )
255 pPortion
= PIMPEE
->GetPrevVisPortion( pPortion
);
256 ContentNode
* pNode
= pPortion
? pPortion
->GetNode() : PIMPEE
->GetEditDoc().GetObject( 0 );
257 aNewSelection
.Max() = EditPaM( pNode
, pNode
->Len() );
260 pImpEditView
->DrawSelection(); // alte Selektion 'weg-zeichnen'
261 pImpEditView
->SetEditSelection( aNewSelection
);
262 pImpEditView
->DrawSelection();
263 sal_Bool bGotoCursor
= pImpEditView
->DoAutoScroll();
264 ShowCursor( bGotoCursor
);
267 ESelection
EditView::GetSelection() const
269 DBG_CHKTHIS( EditView
, 0 );
270 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
272 ESelection aSelection
;
274 aSelection
.nStartPara
= PIMPEE
->GetEditDoc().GetPos( pImpEditView
->GetEditSelection().Min().GetNode() );
275 aSelection
.nEndPara
= PIMPEE
->GetEditDoc().GetPos( pImpEditView
->GetEditSelection().Max().GetNode() );
277 aSelection
.nStartPos
= pImpEditView
->GetEditSelection().Min().GetIndex();
278 aSelection
.nEndPos
= pImpEditView
->GetEditSelection().Max().GetIndex();
283 sal_Bool
EditView::HasSelection() const
285 DBG_CHKTHIS( EditView
, 0 );
286 return pImpEditView
->HasSelection();
289 void EditView::DeleteSelected()
291 DBG_CHKTHIS( EditView
, 0 );
292 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
293 pImpEditView
->DeleteSelected();
296 USHORT
EditView::GetSelectedScriptType() const
298 DBG_CHKTHIS( EditView
, 0 );
299 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
300 return PIMPEE
->GetScriptType( pImpEditView
->GetEditSelection() );
303 void EditView::Paint( const Rectangle
& rRect
)
305 DBG_CHKTHIS( EditView
, 0 );
306 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
307 PIMPEE
->Paint( pImpEditView
, rRect
);
310 void EditView::SetEditEngine( EditEngine
* pEditEng
)
312 DBG_CHKTHIS( EditView
, 0 );
313 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
314 pImpEditView
->pEditEngine
= pEditEng
;
315 EditSelection aStartSel
;
316 aStartSel
= PIMPEE
->GetEditDoc().GetStartPaM();
317 pImpEditView
->SetEditSelection( aStartSel
);
320 void EditView::SetWindow( Window
* pWin
)
322 DBG_CHKTHIS( EditView
, 0 );
323 pImpEditView
->pOutWin
= pWin
;
324 PIMPEE
->GetSelEngine().Reset();
327 Window
* EditView::GetWindow() const
329 DBG_CHKTHIS( EditView
, 0 );
330 return pImpEditView
->pOutWin
;
333 void EditView::SetVisArea( const Rectangle
& rRec
)
335 DBG_CHKTHIS( EditView
, 0 );
336 pImpEditView
->SetVisDocStartPos( rRec
.TopLeft() );
339 const Rectangle
& EditView::GetVisArea() const
341 DBG_CHKTHIS( EditView
, 0 );
342 // Change return value to Rectangle in next incompatible build !!!
343 static Rectangle aRect
;
344 aRect
= pImpEditView
->GetVisDocArea();
348 void EditView::SetOutputArea( const Rectangle
& rRec
)
350 DBG_CHKTHIS( EditView
, 0 );
351 pImpEditView
->SetOutputArea( rRec
);
353 // Rest nur hier, wenn API-Aufruf:
354 pImpEditView
->CalcAnchorPoint();
355 if ( PIMPEE
->GetStatus().AutoPageSize() )
356 pImpEditView
->RecalcOutputArea();
357 pImpEditView
->ShowCursor( sal_False
, sal_False
);
360 const Rectangle
& EditView::GetOutputArea() const
362 DBG_CHKTHIS( EditView
, 0 );
363 return pImpEditView
->GetOutputArea();
366 void EditView::SetPointer( const Pointer
& rPointer
)
368 DBG_CHKTHIS( EditView
, 0 );
369 pImpEditView
->SetPointer( rPointer
);
372 const Pointer
& EditView::GetPointer() const
374 DBG_CHKTHIS( EditView
, 0 );
375 return pImpEditView
->GetPointer();
378 void EditView::SetCursor( const Cursor
& rCursor
)
380 DBG_CHKTHIS( EditView
, 0 );
381 delete pImpEditView
->pCursor
;
382 pImpEditView
->pCursor
= new Cursor( rCursor
);
385 Cursor
* EditView::GetCursor() const
387 DBG_CHKTHIS( EditView
, 0 );
388 return pImpEditView
->pCursor
;
391 void EditView::InsertText( const XubString
& rStr
, sal_Bool bSelect
)
393 DBG_CHKTHIS( EditView
, 0 );
394 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
396 ImpEditEngine
* pImpEE
= PIMPEE
;
397 pImpEditView
->DrawSelection();
402 EditSelection
aTmpSel( pImpEditView
->GetEditSelection() );
403 aTmpSel
.Adjust( pImpEE
->GetEditDoc() );
404 aPaM1
= aTmpSel
.Min();
407 pImpEE
->UndoActionStart( EDITUNDO_INSERT
);
408 EditPaM
aPaM2( pImpEE
->InsertText( pImpEditView
->GetEditSelection(), rStr
) );
409 pImpEE
->UndoActionEnd( EDITUNDO_INSERT
);
413 DBG_ASSERT( !aPaM1
.DbgIsBuggy( pImpEE
->GetEditDoc() ), "Insert: PaM kaputt" );
414 pImpEditView
->SetEditSelection( EditSelection( aPaM1
, aPaM2
) );
417 pImpEditView
->SetEditSelection( EditSelection( aPaM2
, aPaM2
) );
419 pImpEE
->FormatAndUpdate( this );
422 sal_Bool
EditView::PostKeyEvent( const KeyEvent
& rKeyEvent
, Window
* pFrameWin
)
424 DBG_CHKTHIS( EditView
, 0 );
425 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
426 return pImpEditView
->PostKeyEvent( rKeyEvent
, pFrameWin
);
429 sal_Bool
EditView::MouseButtonUp( const MouseEvent
& rMouseEvent
)
431 DBG_CHKTHIS( EditView
, 0 );
432 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
433 return pImpEditView
->MouseButtonUp( rMouseEvent
);
436 sal_Bool
EditView::MouseButtonDown( const MouseEvent
& rMouseEvent
)
438 DBG_CHKTHIS( EditView
, 0 );
439 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
440 return pImpEditView
->MouseButtonDown( rMouseEvent
);
443 sal_Bool
EditView::MouseMove( const MouseEvent
& rMouseEvent
)
445 DBG_CHKTHIS( EditView
, 0 );
446 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
447 return pImpEditView
->MouseMove( rMouseEvent
);
450 void EditView::Command( const CommandEvent
& rCEvt
)
452 DBG_CHKTHIS( EditView
, 0 );
453 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
454 pImpEditView
->Command( rCEvt
);
457 void EditView::ShowCursor( sal_Bool bGotoCursor
, sal_Bool bForceVisCursor
)
459 DBG_CHKTHIS( EditView
, 0 );
460 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
462 // Draw vertraegt die Assertion nicht, spaeter mal aktivieren
463 // DBG_ASSERT( pImpEditView->pEditEngine->HasView( this ), "ShowCursor - View nicht angemeldet!" );
464 // DBG_ASSERT( !GetWindow()->IsInPaint(), "ShowCursor - Why in Paint ?!" );
466 if ( pImpEditView
->pEditEngine
->HasView( this ) )
468 // Das ControlWord hat mehr Gewicht:
469 if ( !pImpEditView
->DoAutoScroll() )
470 bGotoCursor
= sal_False
;
471 pImpEditView
->ShowCursor( bGotoCursor
, bForceVisCursor
);
475 void EditView::HideCursor()
477 DBG_CHKTHIS( EditView
, 0 );
478 pImpEditView
->GetCursor()->Hide();
481 Pair
EditView::Scroll( long ndX
, long ndY
, BYTE nRangeCheck
)
483 DBG_CHKTHIS( EditView
, 0 );
484 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
485 return pImpEditView
->Scroll( ndX
, ndY
, nRangeCheck
);
488 const SfxItemSet
& EditView::GetEmptyItemSet()
490 DBG_CHKTHIS( EditView
, 0 );
491 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
492 return PIMPEE
->GetEmptyItemSet();
495 void EditView::SetAttribs( const SfxItemSet
& rSet
)
497 DBG_CHKTHIS( EditView
, 0 );
498 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
499 DBG_ASSERT( !pImpEditView
->aEditSelection
.IsInvalid(), "Blinde Selection in ...." );
501 // Kein Undo-Kappseln noetig...
502 pImpEditView
->DrawSelection();
503 PIMPEE
->SetAttribs( pImpEditView
->GetEditSelection(), rSet
, ATTRSPECIAL_WHOLEWORD
);
504 PIMPEE
->FormatAndUpdate( this );
507 void EditView::SetParaAttribs( const SfxItemSet
& rSet
, sal_uInt16 nPara
)
509 DBG_CHKTHIS( EditView
, 0 );
510 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
511 // Kein Undo-Kappseln noetig...
512 PIMPEE
->SetParaAttribs( nPara
, rSet
);
513 // Beim Aendern von Absatzattributen muss immer formatiert werden...
514 PIMPEE
->FormatAndUpdate( this );
517 void EditView::RemoveAttribsKeepLanguages( sal_Bool bRemoveParaAttribs
)
519 DBG_CHKTHIS( EditView
, 0 );
520 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
522 pImpEditView
->DrawSelection();
523 PIMPEE
->UndoActionStart( EDITUNDO_RESETATTRIBS
);
524 EditSelection
aSelection( pImpEditView
->GetEditSelection() );
526 for (sal_uInt16 nWID
= EE_ITEMS_START
; nWID
<= EE_ITEMS_END
; ++nWID
)
528 bool bIsLang
= EE_CHAR_LANGUAGE
== nWID
||
529 EE_CHAR_LANGUAGE_CJK
== nWID
||
530 EE_CHAR_LANGUAGE_CTL
== nWID
;
532 PIMPEE
->RemoveCharAttribs( aSelection
, bRemoveParaAttribs
, nWID
);
535 PIMPEE
->UndoActionEnd( EDITUNDO_RESETATTRIBS
);
536 PIMPEE
->FormatAndUpdate( this );
539 void EditView::RemoveAttribs( sal_Bool bRemoveParaAttribs
, sal_uInt16 nWhich
)
541 DBG_CHKTHIS( EditView
, 0 );
542 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
544 pImpEditView
->DrawSelection();
545 PIMPEE
->UndoActionStart( EDITUNDO_RESETATTRIBS
);
546 PIMPEE
->RemoveCharAttribs( pImpEditView
->GetEditSelection(), bRemoveParaAttribs
, nWhich
);
547 PIMPEE
->UndoActionEnd( EDITUNDO_RESETATTRIBS
);
548 PIMPEE
->FormatAndUpdate( this );
551 void EditView::RemoveCharAttribs( sal_uInt16 nPara
, sal_uInt16 nWhich
)
553 DBG_CHKTHIS( EditView
, 0 );
554 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
555 PIMPEE
->UndoActionStart( EDITUNDO_RESETATTRIBS
);
556 PIMPEE
->RemoveCharAttribs( nPara
, nWhich
);
557 PIMPEE
->UndoActionEnd( EDITUNDO_RESETATTRIBS
);
558 PIMPEE
->FormatAndUpdate( this );
561 SfxItemSet
EditView::GetAttribs()
563 DBG_CHKTHIS( EditView
, 0 );
564 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
565 DBG_ASSERT( !pImpEditView
->aEditSelection
.IsInvalid(), "Blinde Selection in ...." );
566 return PIMPEE
->GetAttribs( pImpEditView
->GetEditSelection() );
569 void EditView::Undo()
571 DBG_CHKTHIS( EditView
, 0 );
572 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
573 PIMPEE
->Undo( this );
576 void EditView::Redo()
578 DBG_CHKTHIS( EditView
, 0 );
579 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
580 PIMPEE
->Redo( this );
583 ULONG
EditView::Read( SvStream
& rInput
, const String
& rBaseURL
, EETextFormat eFormat
, sal_Bool bSelect
, SvKeyValueIterator
* pHTTPHeaderAttrs
)
585 DBG_CHKTHIS( EditView
, 0 );
586 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
587 EditSelection
aOldSel( pImpEditView
->GetEditSelection() );
588 pImpEditView
->DrawSelection();
589 PIMPEE
->UndoActionStart( EDITUNDO_READ
);
590 EditPaM aEndPaM
= PIMPEE
->Read( rInput
, rBaseURL
, eFormat
, aOldSel
, pHTTPHeaderAttrs
);
591 PIMPEE
->UndoActionEnd( EDITUNDO_READ
);
592 EditSelection
aNewSel( aEndPaM
, aEndPaM
);
595 aOldSel
.Adjust( PIMPEE
->GetEditDoc() );
596 aNewSel
.Min() = aOldSel
.Min();
599 pImpEditView
->SetEditSelection( aNewSel
);
600 sal_Bool bGotoCursor
= pImpEditView
->DoAutoScroll();
601 ShowCursor( bGotoCursor
);
603 return rInput
.GetError();
607 ULONG
EditView::Write( SvStream
& rOutput
, EETextFormat eFormat
)
609 DBG_CHKTHIS( EditView
, 0 );
610 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
611 PIMPEE
->Write( rOutput
, eFormat
, pImpEditView
->GetEditSelection() );
613 return rOutput
.GetError();
619 DBG_CHKTHIS( EditView
, 0 );
620 Reference
<com::sun::star::datatransfer::clipboard::XClipboard
> aClipBoard(GetWindow()->GetClipboard());
621 pImpEditView
->CutCopy( aClipBoard
, sal_True
);
624 ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> EditView::GetTransferable()
626 uno::Reference
< datatransfer::XTransferable
> xData
= GetEditEngine()->pImpEditEngine
->CreateTransferable( pImpEditView
->GetEditSelection() );
630 void EditView::Copy()
632 DBG_CHKTHIS( EditView
, 0 );
633 Reference
<com::sun::star::datatransfer::clipboard::XClipboard
> aClipBoard(GetWindow()->GetClipboard());
634 pImpEditView
->CutCopy( aClipBoard
, sal_False
);
637 void EditView::Paste()
639 DBG_CHKTHIS( EditView
, 0 );
640 Reference
<com::sun::star::datatransfer::clipboard::XClipboard
> aClipBoard(GetWindow()->GetClipboard());
641 pImpEditView
->Paste( aClipBoard
, sal_False
);
644 void EditView::PasteSpecial()
646 DBG_CHKTHIS( EditView
, 0 );
647 Reference
<com::sun::star::datatransfer::clipboard::XClipboard
> aClipBoard(GetWindow()->GetClipboard());
648 pImpEditView
->Paste(aClipBoard
, sal_True
);
651 void EditView::EnablePaste( sal_Bool bEnable
)
653 DBG_CHKTHIS( EditView
, 0 );
654 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
655 pImpEditView
->EnablePaste( bEnable
);
658 sal_Bool
EditView::IsPasteEnabled() const
660 DBG_CHKTHIS( EditView
, 0 );
661 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
662 return pImpEditView
->IsPasteEnabled();
665 Point
EditView::GetWindowPosTopLeft( sal_uInt16 nParagraph
)
667 DBG_CHKTHIS( EditView
, 0 );
668 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
669 Point
aDocPos( pImpEditView
->pEditEngine
->GetDocPosTopLeft( nParagraph
) );
670 return pImpEditView
->GetWindowPos( aDocPos
);
673 sal_uInt16
EditView::GetParagraph( const Point
& rMousePosPixel
)
675 DBG_CHKTHIS( EditView
, 0 );
676 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
677 Point
aMousePos( rMousePosPixel
);
678 aMousePos
= GetWindow()->PixelToLogic( aMousePos
);
679 Point
aDocPos( pImpEditView
->GetDocPos( aMousePos
) );
680 sal_uInt16 nParagraph
= PIMPEE
->GetParaPortions().FindParagraph( aDocPos
.Y() );
684 void EditView::IndentBlock()
686 DBG_CHKTHIS( EditView
, 0 );
687 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
689 PIMPEE
->IndentBlock( this, sal_True
);
692 void EditView::UnindentBlock()
694 DBG_CHKTHIS( EditView
, 0 );
695 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
697 PIMPEE
->IndentBlock( this, sal_False
);
700 EESelectionMode
EditView::GetSelectionMode() const
702 DBG_CHKTHIS( EditView
, 0 );
703 return pImpEditView
->GetSelectionMode();
706 void EditView::SetSelectionMode( EESelectionMode eMode
)
708 DBG_CHKTHIS( EditView
, 0 );
709 pImpEditView
->SetSelectionMode( eMode
);
712 XubString
EditView::GetSelected()
714 DBG_CHKTHIS( EditView
, 0 );
715 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
716 return PIMPEE
->GetSelected( pImpEditView
->GetEditSelection() );
719 void EditView::MoveParagraphs( Range aParagraphs
, sal_uInt16 nNewPos
)
721 DBG_CHKTHIS( EditView
, 0 );
722 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
723 PIMPEE
->UndoActionStart( EDITUNDO_MOVEPARAS
);
724 PIMPEE
->MoveParagraphs( aParagraphs
, nNewPos
, this );
725 PIMPEE
->UndoActionEnd( EDITUNDO_MOVEPARAS
);
728 void EditView::MoveParagraphs( long nDiff
)
730 DBG_CHKTHIS( EditView
, 0 );
731 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
732 ESelection aSel
= GetSelection();
733 Range
aRange( aSel
.nStartPara
, aSel
.nEndPara
);
735 long nDest
= ( nDiff
> 0 ? aRange
.Max() : aRange
.Min() ) + nDiff
;
738 DBG_ASSERT( ( nDest
>= 0 ) && ( nDest
<= pImpEditView
->pEditEngine
->GetParagraphCount() ), "MoveParagraphs - wrong Parameters!" );
739 MoveParagraphs( aRange
,
740 sal::static_int_cast
< USHORT
>( nDest
) );
743 void EditView::SetBackgroundColor( const Color
& rColor
)
745 DBG_CHKTHIS( EditView
, 0 );
746 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
747 pImpEditView
->SetBackgroundColor( rColor
);
750 Color
EditView::GetBackgroundColor() const
752 DBG_CHKTHIS( EditView
, 0 );
753 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
754 return pImpEditView
->GetBackgroundColor();
757 void EditView::SetControlWord( sal_uInt32 nWord
)
759 DBG_CHKTHIS( EditView
, 0 );
760 pImpEditView
->nControl
= nWord
;
763 sal_uInt32
EditView::GetControlWord() const
765 DBG_CHKTHIS( EditView
, 0 );
766 return pImpEditView
->nControl
;
769 EditTextObject
* EditView::CreateTextObject()
771 DBG_CHKTHIS( EditView
, 0 );
772 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
773 return PIMPEE
->CreateTextObject( pImpEditView
->GetEditSelection() );
776 void EditView::InsertText( const EditTextObject
& rTextObject
)
778 DBG_CHKTHIS( EditView
, 0 );
779 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
780 pImpEditView
->DrawSelection();
782 PIMPEE
->UndoActionStart( EDITUNDO_INSERT
);
783 EditSelection
aTextSel( PIMPEE
->InsertText( rTextObject
, pImpEditView
->GetEditSelection() ) );
784 PIMPEE
->UndoActionEnd( EDITUNDO_INSERT
);
786 aTextSel
.Min() = aTextSel
.Max(); // Selektion nicht behalten.
787 pImpEditView
->SetEditSelection( aTextSel
);
788 PIMPEE
->FormatAndUpdate( this );
791 void EditView::InsertText( ::com::sun::star::uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> xDataObj
, const String
& rBaseURL
, BOOL bUseSpecial
)
793 DBG_CHKTHIS( EditView
, 0 );
794 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
796 PIMPEE
->UndoActionStart( EDITUNDO_INSERT
);
797 pImpEditView
->DeleteSelected();
798 EditSelection
aTextSel( PIMPEE
->InsertText( xDataObj
, rBaseURL
, pImpEditView
->GetEditSelection().Max(), bUseSpecial
) );
799 PIMPEE
->UndoActionEnd( EDITUNDO_INSERT
);
801 aTextSel
.Min() = aTextSel
.Max(); // Selektion nicht behalten.
802 pImpEditView
->SetEditSelection( aTextSel
);
803 PIMPEE
->FormatAndUpdate( this );
806 sal_Bool
EditView::Drop( const DropEvent
& )
811 ESelection
EditView::GetDropPos()
813 DBG_ERROR( "GetDropPos - Why?!" );
817 sal_Bool
EditView::QueryDrop( DropEvent
& )
822 void EditView::SetEditEngineUpdateMode( sal_Bool bUpdate
)
824 DBG_CHKTHIS( EditView
, 0 );
825 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
826 PIMPEE
->SetUpdateMode( bUpdate
, this );
829 void EditView::ForceUpdate()
831 DBG_CHKTHIS( EditView
, 0 );
832 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
833 PIMPEE
->SetUpdateMode( sal_True
, this, sal_True
);
836 void EditView::SetStyleSheet( SfxStyleSheet
* pStyle
)
838 DBG_CHKTHIS( EditView
, 0 );
839 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
841 EditSelection
aSel( pImpEditView
->GetEditSelection() );
842 PIMPEE
->UndoActionStart( EDITUNDO_STYLESHEET
);
843 PIMPEE
->SetStyleSheet( aSel
, pStyle
);
844 PIMPEE
->UndoActionEnd( EDITUNDO_STYLESHEET
);
847 SfxStyleSheet
* EditView::GetStyleSheet() const
849 DBG_CHKTHIS( EditView
, 0 );
850 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
853 EditSelection
aSel( pImpEditView
->GetEditSelection() );
854 aSel
.Adjust( PIMPEE
->GetEditDoc() );
855 sal_uInt16 nStartPara
= PIMPEE
->GetEditDoc().GetPos( aSel
.Min().GetNode() );
856 sal_uInt16 nEndPara
= PIMPEE
->GetEditDoc().GetPos( aSel
.Max().GetNode() );
858 SfxStyleSheet
* pStyle
= NULL
;
859 for ( sal_uInt16 n
= nStartPara
; n
<= nEndPara
; n
++ )
861 SfxStyleSheet
* pTmpStyle
= PIMPEE
->GetStyleSheet( n
);
862 if ( ( n
!= nStartPara
) && ( pStyle
!= pTmpStyle
) )
863 return NULL
; // Nicht eindeutig.
869 sal_Bool
EditView::IsInsertMode() const
871 DBG_CHKTHIS( EditView
, 0 );
872 return pImpEditView
->IsInsertMode();
875 void EditView::SetInsertMode( sal_Bool bInsert
)
877 DBG_CHKTHIS( EditView
, 0 );
878 pImpEditView
->SetInsertMode( bInsert
);
881 void EditView::SetAnchorMode( EVAnchorMode eMode
)
883 DBG_CHKTHIS( EditView
, 0 );
884 pImpEditView
->SetAnchorMode( eMode
);
887 EVAnchorMode
EditView::GetAnchorMode() const
889 DBG_CHKTHIS( EditView
, 0 );
890 return pImpEditView
->GetAnchorMode();
893 void EditView::TransliterateText( sal_Int32 nTransliterationMode
)
895 DBG_CHKTHIS( EditView
, 0 );
896 EditSelection
aOldSel( pImpEditView
->GetEditSelection() );
897 EditSelection aNewSel
= PIMPEE
->TransliterateText( pImpEditView
->GetEditSelection(), nTransliterationMode
);
898 if ( aNewSel
!= aOldSel
)
900 pImpEditView
->DrawSelection(); // alte Selektion 'weg-zeichnen'
901 pImpEditView
->SetEditSelection( aNewSel
);
902 pImpEditView
->DrawSelection();
907 sal_Bool
EditView::MatchGroup()
909 DBG_CHKTHIS( EditView
, 0 );
910 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
911 EditSelection
aNewSel( PIMPEE
->MatchGroup( pImpEditView
->GetEditSelection() ) );
912 if ( aNewSel
.HasRange() )
914 pImpEditView
->DrawSelection();
915 pImpEditView
->SetEditSelection( aNewSel
);
916 pImpEditView
->DrawSelection();
923 void EditView::CompleteAutoCorrect( Window
* pFrameWin
)
925 DBG_CHKTHIS( EditView
, 0 );
926 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
927 if ( !pImpEditView
->HasSelection() && PIMPEE
->GetStatus().DoAutoCorrect() )
929 pImpEditView
->DrawSelection();
930 EditSelection aSel
= pImpEditView
->GetEditSelection();
931 aSel
= PIMPEE
->EndOfWord( aSel
.Max() );
932 // MT 06/00: Why pass EditSelection to AutoCorrect, not EditPaM?!
933 aSel
= PIMPEE
->AutoCorrect( aSel
, 0, !IsInsertMode(), pFrameWin
);
934 pImpEditView
->SetEditSelection( aSel
);
935 if ( PIMPEE
->IsModified() )
936 PIMPEE
->FormatAndUpdate( this );
940 EESpellState
EditView::StartSpeller( sal_Bool bMultipleDoc
)
943 return EE_SPELL_NOSPELLER
;
945 DBG_CHKTHIS( EditView
, 0 );
946 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
947 if ( !PIMPEE
->GetSpeller().is() )
948 return EE_SPELL_NOSPELLER
;
950 return PIMPEE
->Spell( this, bMultipleDoc
);
954 EESpellState
EditView::StartThesaurus()
957 return EE_SPELL_NOSPELLER
;
959 DBG_CHKTHIS( EditView
, 0 );
960 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
961 if ( !PIMPEE
->GetSpeller().is() )
962 return EE_SPELL_NOSPELLER
;
964 return PIMPEE
->StartThesaurus( this );
969 void EditView::StartTextConversion(
970 LanguageType nSrcLang
, LanguageType nDestLang
, const Font
*pDestFont
,
971 INT32 nOptions
, BOOL bIsInteractive
, BOOL bMultipleDoc
)
975 DBG_CHKTHIS( EditView
, 0 );
976 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
977 PIMPEE
->Convert( this, nSrcLang
, nDestLang
, pDestFont
, nOptions
, bIsInteractive
, bMultipleDoc
);
982 sal_uInt16
EditView::StartSearchAndReplace( const SvxSearchItem
& rSearchItem
)
984 DBG_CHKTHIS( EditView
, 0 );
985 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
986 return PIMPEE
->StartSearchAndReplace( this, rSearchItem
);
989 sal_Bool
EditView::IsCursorAtWrongSpelledWord( sal_Bool bMarkIfWrong
)
991 DBG_CHKTHIS( EditView
, 0 );
992 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
993 sal_Bool bIsWrong
= sal_False
;
994 if ( !HasSelection() )
996 EditPaM aPaM
= pImpEditView
->GetEditSelection().Max();
997 bIsWrong
= pImpEditView
->IsWrongSpelledWord( aPaM
, bMarkIfWrong
);
1002 sal_Bool
EditView::IsWrongSpelledWordAtPos( const Point
& rPosPixel
, sal_Bool bMarkIfWrong
)
1004 DBG_CHKTHIS( EditView
, 0 );
1005 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1006 Point
aPos ( pImpEditView
->GetWindow()->PixelToLogic( rPosPixel
) );
1007 aPos
= pImpEditView
->GetDocPos( aPos
);
1008 EditPaM aPaM
= pImpEditView
->pEditEngine
->pImpEditEngine
->GetPaM( aPos
, sal_False
);
1009 return pImpEditView
->IsWrongSpelledWord( aPaM
, bMarkIfWrong
);
1012 void EditView::ExecuteSpellPopup( const Point
& rPosPixel
, Link
* pCallBack
)
1015 DBG_CHKTHIS( EditView
, 0 );
1016 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1018 Point
aPos ( pImpEditView
->GetWindow()->PixelToLogic( rPosPixel
) );
1019 aPos
= pImpEditView
->GetDocPos( aPos
);
1020 EditPaM aPaM
= pImpEditView
->pEditEngine
->pImpEditEngine
->GetPaM( aPos
, sal_False
);
1021 Reference
< XSpellChecker1
> xSpeller( PIMPEE
->GetSpeller() );
1022 ESelection aOldSel
= GetSelection();
1023 if ( xSpeller
.is() && pImpEditView
->IsWrongSpelledWord( aPaM
, sal_True
) )
1025 PopupMenu
aPopupMenu( EditResId( RID_MENU_SPELL
) );
1026 PopupMenu
*pAutoMenu
= aPopupMenu
.GetPopupMenu( MN_AUTOCORR
);
1027 PopupMenu
*pInsertMenu
= aPopupMenu
.GetPopupMenu( MN_INSERT
);
1029 EditPaM
aPaM2( aPaM
);
1032 // Gibt es Replace-Vorschlaege?
1033 String
aSelected( GetSelected() );
1035 // restrict the maximal number of suggestions displayed
1036 // in the context menu.
1037 // Note: That could of course be done by clipping the
1038 // resulting sequence but the current third party
1039 // implementations result differs greatly if the number of
1040 // suggestions to be retuned gets changed. Statistically
1041 // it gets much better if told to return e.g. only 7 strings
1042 // than returning e.g. 16 suggestions and using only the
1043 // first 7. Thus we hand down the value to use to that
1044 // implementation here by providing an additional parameter.
1045 Sequence
< PropertyValue
> aPropVals(1);
1046 PropertyValue
&rVal
= aPropVals
.getArray()[0];
1047 rVal
.Name
= OUString::createFromAscii( UPN_MAX_NUMBER_OF_SUGGESTIONS
);
1048 rVal
.Value
<<= (INT16
) 7;
1050 // Gibt es Replace-Vorschlaege?
1051 Reference
< XSpellAlternatives
> xSpellAlt
=
1052 xSpeller
->spell( aSelected
, PIMPEE
->GetLanguage( aPaM2
), aPropVals
);
1054 Reference
< XLanguageGuessing
> xLangGuesser( EE_DLL()->GetGlobalData()->GetLanguageGuesser() );
1056 // check if text might belong to a different language...
1057 LanguageType nGuessLangWord
= LANGUAGE_NONE
;
1058 LanguageType nGuessLangPara
= LANGUAGE_NONE
;
1059 if (xSpellAlt
.is() && xLangGuesser
.is())
1062 ContentNode
*pNode
= aPaM
.GetNode();
1069 DBG_ERROR( "content node is NULL" );
1072 nGuessLangWord
= lcl_CheckLanguage( xSpellAlt
->getWord(), xSpeller
, xLangGuesser
, sal_False
);
1073 nGuessLangPara
= lcl_CheckLanguage( aParaText
, xSpeller
, xLangGuesser
, sal_True
);
1075 if (nGuessLangWord
!= LANGUAGE_NONE
|| nGuessLangPara
!= LANGUAGE_NONE
)
1077 // make sure LANGUAGE_NONE gets not used as menu entry
1078 if (nGuessLangWord
== LANGUAGE_NONE
)
1079 nGuessLangWord
= nGuessLangPara
;
1080 if (nGuessLangPara
== LANGUAGE_NONE
)
1081 nGuessLangPara
= nGuessLangWord
;
1083 aPopupMenu
.InsertSeparator();
1084 String
aTmpWord( ::GetLanguageString( nGuessLangWord
) );
1085 String
aTmpPara( ::GetLanguageString( nGuessLangPara
) );
1086 String
aWordStr( EditResId( RID_STR_WORD
) );
1087 aWordStr
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%x" ) ), aTmpWord
);
1088 String
aParaStr( EditResId( RID_STR_PARAGRAPH
) );
1089 aParaStr
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%x" ) ), aTmpPara
);
1090 aPopupMenu
.InsertItem( MN_WORDLANGUAGE
, aWordStr
);
1091 aPopupMenu
.SetHelpId( MN_WORDLANGUAGE
, HID_EDITENG_SPELLER_WORDLANGUAGE
);
1092 aPopupMenu
.InsertItem( MN_PARALANGUAGE
, aParaStr
);
1093 aPopupMenu
.SetHelpId( MN_PARALANGUAGE
, HID_EDITENG_SPELLER_PARALANGUAGE
);
1096 // ## Create mnemonics here
1097 if ( Application::IsAutoMnemonicEnabled() )
1099 aPopupMenu
.CreateAutoMnemonics();
1100 aPopupMenu
.SetMenuFlags( aPopupMenu
.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
1103 // Replace suggestions...
1104 Sequence
< OUString
> aAlt
;
1106 aAlt
= xSpellAlt
->getAlternatives();
1107 const OUString
*pAlt
= aAlt
.getConstArray();
1108 sal_uInt16 nWords
= (USHORT
) aAlt
.getLength();
1111 for ( sal_uInt16 nW
= 0; nW
< nWords
; nW
++ )
1113 String
aAlternate( pAlt
[nW
] );
1114 aPopupMenu
.InsertItem( MN_ALTSTART
+nW
, aAlternate
, 0, nW
);
1115 pAutoMenu
->InsertItem( MN_AUTOSTART
+nW
, aAlternate
, 0, nW
);
1117 aPopupMenu
.InsertSeparator( nWords
);
1120 aPopupMenu
.RemoveItem( MN_AUTOCORR
); // Loeschen?
1122 Reference
< XDictionaryList
> xDicList( SvxGetDictionaryList() );
1124 Sequence
< Reference
< XDictionary
> > aDics
;
1126 aDics
= xDicList
->getDictionaries();
1127 const Reference
< XDictionary
> *pDic
= aDics
.getConstArray();
1128 sal_uInt16 nLanguage
= PIMPEE
->GetLanguage( aPaM2
);
1129 sal_uInt16 nDicCount
= (USHORT
)aDics
.getLength();
1130 for ( sal_uInt16 i
= 0; i
< nDicCount
; i
++ )
1132 Reference
< XDictionary
> xDic( pDic
[i
], UNO_QUERY
);
1135 sal_uInt16 nActLanguage
= SvxLocaleToLanguage( xDic
->getLocale() );
1136 if( xDic
->isActive() &&
1137 xDic
->getDictionaryType() == DictionaryType_POSITIVE
&&
1138 (nLanguage
== nActLanguage
|| LANGUAGE_NONE
== nActLanguage
) )
1140 pInsertMenu
->InsertItem( MN_DICTSTART
+ i
, xDic
->getName() );
1145 if ( !pInsertMenu
->GetItemCount() )
1146 aPopupMenu
.EnableItem( MN_INSERT
, sal_False
);
1148 aPopupMenu
.RemoveDisabledEntries( sal_True
, sal_True
);
1150 Rectangle aTempRect
= PIMPEE
->PaMtoEditCursor( aPaM
, GETCRSR_TXTONLY
);
1151 Point aScreenPos
= pImpEditView
->GetWindowPos( aTempRect
.TopLeft() );
1152 aScreenPos
= pImpEditView
->GetWindow()->OutputToScreenPixel( aScreenPos
);
1153 aTempRect
= pImpEditView
->GetWindow()->LogicToPixel( Rectangle(aScreenPos
, aTempRect
.GetSize() ));
1155 sal_uInt16 nId
= aPopupMenu
.Execute( pImpEditView
->GetWindow(), aTempRect
, POPUPMENU_NOMOUSEUPCLOSE
);
1156 if ( nId
== MN_IGNORE
)
1158 String aWord
= pImpEditView
->SpellIgnoreOrAddWord( sal_False
);
1161 SpellCallbackInfo
aInf( SPELLCMD_IGNOREWORD
, aWord
);
1162 pCallBack
->Call( &aInf
);
1164 SetSelection( aOldSel
);
1166 else if ( ( nId
== MN_WORDLANGUAGE
) || ( nId
== MN_PARALANGUAGE
) )
1168 LanguageType nLangToUse
= (nId
== MN_WORDLANGUAGE
) ? nGuessLangWord
: nGuessLangPara
;
1169 sal_uInt16 nScriptType
= SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse
);
1171 SfxItemSet aAttrs
= GetEditEngine()->GetEmptyItemSet();
1172 if (nScriptType
== SCRIPTTYPE_LATIN
)
1173 aAttrs
.Put( SvxLanguageItem( nLangToUse
, EE_CHAR_LANGUAGE
) );
1174 if (nScriptType
== SCRIPTTYPE_COMPLEX
)
1175 aAttrs
.Put( SvxLanguageItem( nLangToUse
, EE_CHAR_LANGUAGE_CTL
) );
1176 if (nScriptType
== SCRIPTTYPE_ASIAN
)
1177 aAttrs
.Put( SvxLanguageItem( nLangToUse
, EE_CHAR_LANGUAGE_CJK
) );
1178 if ( nId
== MN_PARALANGUAGE
)
1180 ESelection aSel
= GetSelection();
1182 aSel
.nEndPos
= 0xFFFF;
1183 SetSelection( aSel
);
1185 SetAttribs( aAttrs
);
1186 PIMPEE
->StartOnlineSpellTimer();
1190 SpellCallbackInfo
aInf( ( nId
== MN_WORDLANGUAGE
) ? SPELLCMD_WORDLANGUAGE
: SPELLCMD_PARALANGUAGE
, nLangToUse
);
1191 pCallBack
->Call( &aInf
);
1193 SetSelection( aOldSel
);
1195 else if ( nId
== MN_SPELLING
)
1199 // Cursor vor das Wort setzen...
1200 EditPaM aCursor
= pImpEditView
->GetEditSelection().Min();
1201 pImpEditView
->DrawSelection(); // alte Selektion 'weg-zeichnen'
1202 pImpEditView
->SetEditSelection( EditSelection( aCursor
, aCursor
) );
1203 pImpEditView
->DrawSelection();
1204 // Stuerzt ab, wenn keine SfxApp
1205 PIMPEE
->Spell( this, sal_False
);
1209 SpellCallbackInfo
aInf( SPELLCMD_STARTSPELLDLG
, String() );
1210 pCallBack
->Call( &aInf
);
1213 else if ( nId
>= MN_DICTSTART
)
1215 Reference
< XDictionary
> xDic( pDic
[nId
- MN_DICTSTART
], UNO_QUERY
);
1217 xDic
->add( aSelected
, sal_False
, String() );
1218 // save modified user-dictionary if it is persistent
1219 Reference
< frame::XStorable
> xSavDic( xDic
, UNO_QUERY
);
1223 aPaM
.GetNode()->GetWrongList()->GetInvalidStart() = 0;
1224 aPaM
.GetNode()->GetWrongList()->GetInvalidEnd() = aPaM
.GetNode()->Len();
1225 PIMPEE
->StartOnlineSpellTimer();
1229 SpellCallbackInfo
aInf( SPELLCMD_ADDTODICTIONARY
, aSelected
);
1230 pCallBack
->Call( &aInf
);
1232 SetSelection( aOldSel
);
1234 else if ( nId
>= MN_AUTOSTART
)
1236 DBG_ASSERT(nId
- MN_AUTOSTART
< aAlt
.getLength(), "index out of range");
1237 String aWord
= pAlt
[nId
- MN_AUTOSTART
];
1238 SvxAutoCorrect
* pAutoCorrect
= SvxAutoCorrCfg::Get()->GetAutoCorrect();
1240 pAutoCorrect
->PutText( aSelected
, aWord
, PIMPEE
->GetLanguage( aPaM2
) );
1241 InsertText( aWord
);
1243 else if ( nId
>= MN_ALTSTART
) // Replace
1245 DBG_ASSERT(nId
- MN_ALTSTART
< aAlt
.getLength(), "index out of range");
1246 String aWord
= pAlt
[nId
- MN_ALTSTART
];
1247 InsertText( aWord
);
1251 SetSelection( aOldSel
);
1257 void EditView::SpellIgnoreWord()
1259 DBG_CHKTHIS( EditView
, 0 );
1260 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1261 pImpEditView
->SpellIgnoreOrAddWord( sal_False
);
1264 sal_Bool
EditView::SelectCurrentWord()
1266 DBG_CHKTHIS( EditView
, 0 );
1267 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1268 EditSelection
aCurSel( pImpEditView
->GetEditSelection() );
1269 pImpEditView
->DrawSelection();
1270 aCurSel
= PIMPEE
->SelectWord( aCurSel
.Max() );
1271 pImpEditView
->SetEditSelection( aCurSel
);
1272 pImpEditView
->DrawSelection();
1273 ShowCursor( sal_True
, sal_False
);
1274 return aCurSel
.HasRange() ? sal_True
: sal_False
;
1277 void EditView::InsertField( const SvxFieldItem
& rFld
)
1279 DBG_CHKTHIS( EditView
, 0 );
1280 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1282 ImpEditEngine
* pImpEE
= PIMPEE
;
1283 pImpEditView
->DrawSelection();
1284 pImpEE
->UndoActionStart( EDITUNDO_INSERT
);
1285 EditPaM
aPaM( pImpEE
->InsertField( pImpEditView
->GetEditSelection(), rFld
) );
1286 pImpEE
->UndoActionEnd( EDITUNDO_INSERT
);
1287 pImpEditView
->SetEditSelection( EditSelection( aPaM
, aPaM
) );
1288 pImpEE
->UpdateFields();
1289 pImpEE
->FormatAndUpdate( this );
1292 const SvxFieldItem
* EditView::GetFieldUnderMousePointer() const
1294 DBG_CHKTHIS( EditView
, 0 );
1295 sal_uInt16 nPara
, nPos
;
1296 return GetFieldUnderMousePointer( nPara
, nPos
);
1299 const SvxFieldItem
* EditView::GetField( const Point
& rPos
, sal_uInt16
* pPara
, sal_uInt16
* pPos
) const
1301 DBG_CHKTHIS( EditView
, 0 );
1302 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1303 return pImpEditView
->GetField( rPos
, pPara
, pPos
);
1306 const SvxFieldItem
* EditView::GetFieldUnderMousePointer( sal_uInt16
& nPara
, sal_uInt16
& nPos
) const
1308 DBG_CHKTHIS( EditView
, 0 );
1309 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1310 Point aPos
= pImpEditView
->GetWindow()->GetPointerPosPixel();
1311 aPos
= pImpEditView
->GetWindow()->PixelToLogic( aPos
);
1312 return GetField( aPos
, &nPara
, &nPos
);
1315 const SvxFieldItem
* EditView::GetFieldAtSelection() const
1317 EditSelection
aSel( pImpEditView
->GetEditSelection() );
1318 aSel
.Adjust( pImpEditView
->pEditEngine
->pImpEditEngine
->GetEditDoc() );
1319 // Nur wenn Cursor vor Feld, keine Selektion, oder nur Feld selektiert
1320 if ( ( aSel
.Min().GetNode() == aSel
.Max().GetNode() ) &&
1321 ( ( aSel
.Max().GetIndex() == aSel
.Min().GetIndex() ) ||
1322 ( aSel
.Max().GetIndex() == aSel
.Min().GetIndex()+1 ) ) )
1324 EditPaM aPaM
= aSel
.Min();
1325 const CharAttribArray
& rAttrs
= aPaM
.GetNode()->GetCharAttribs().GetAttribs();
1326 sal_uInt16 nXPos
= aPaM
.GetIndex();
1327 for ( sal_uInt16 nAttr
= rAttrs
.Count(); nAttr
; )
1329 EditCharAttrib
* pAttr
= rAttrs
[--nAttr
];
1330 if ( pAttr
->GetStart() == nXPos
)
1331 if ( pAttr
->Which() == EE_FEATURE_FIELD
)
1333 DBG_ASSERT( pAttr
->GetItem()->ISA( SvxFieldItem
), "Kein FeldItem..." );
1334 return (const SvxFieldItem
*)pAttr
->GetItem();
1341 XubString
EditView::GetWordUnderMousePointer() const
1343 DBG_CHKTHIS( EditView
, 0 );
1344 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1347 return GetWordUnderMousePointer( aRect
);
1350 XubString
EditView::GetWordUnderMousePointer( Rectangle
& rWordRect
) const
1352 DBG_CHKTHIS( EditView
, 0 );
1353 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1355 Point aPos
= pImpEditView
->GetWindow()->GetPointerPosPixel();
1356 aPos
= pImpEditView
->GetWindow()->PixelToLogic( aPos
);
1360 if( GetOutputArea().IsInside( aPos
) )
1362 ImpEditEngine
* pImpEE
= pImpEditView
->pEditEngine
->pImpEditEngine
;
1363 Point
aDocPos( pImpEditView
->GetDocPos( aPos
) );
1364 EditPaM aPaM
= pImpEE
->GetPaM( aDocPos
, sal_False
);
1365 EditSelection aWordSel
= pImpEE
->SelectWord( aPaM
);
1367 Rectangle
aTopLeftRec( pImpEE
->PaMtoEditCursor( aWordSel
.Min() ) );
1368 Rectangle
aBottomRightRec( pImpEE
->PaMtoEditCursor( aWordSel
.Max() ) );
1370 #if OSL_DEBUG_LEVEL > 1
1371 DBG_ASSERT( aTopLeftRec
.Top() == aBottomRightRec
.Top(), "Top() in einer Zeile unterschiedlich?" );
1374 Point
aPnt1( pImpEditView
->GetWindowPos( aTopLeftRec
.TopLeft() ) );
1375 Point
aPnt2( pImpEditView
->GetWindowPos( aBottomRightRec
.BottomRight()) );
1376 rWordRect
= Rectangle( aPnt1
, aPnt2
);
1377 aWord
= pImpEE
->GetSelected( aWordSel
);
1383 void EditView::SetInvalidateMore( sal_uInt16 nPixel
)
1385 DBG_CHKTHIS( EditView
, 0 );
1386 pImpEditView
->SetInvalidateMore( nPixel
);
1389 sal_uInt16
EditView::GetInvalidateMore() const
1391 DBG_CHKTHIS( EditView
, 0 );
1392 return (sal_uInt16
)pImpEditView
->GetInvalidateMore();
1395 static void ChangeFontSizeImpl( EditView
* pEditView
, bool bGrow
, const ESelection
& rSel
, const FontList
* pFontList
)
1397 pEditView
->SetSelection( rSel
);
1399 SfxItemSet
aSet( pEditView
->GetAttribs() );
1400 if( EditView::ChangeFontSize( bGrow
, aSet
, pFontList
) )
1402 SfxItemSet
aNewSet( pEditView
->GetEmptyItemSet() );
1403 aNewSet
.Put( aSet
.Get( EE_CHAR_FONTHEIGHT
), EE_CHAR_FONTHEIGHT
);
1404 aNewSet
.Put( aSet
.Get( EE_CHAR_FONTHEIGHT_CJK
), EE_CHAR_FONTHEIGHT_CJK
);
1405 aNewSet
.Put( aSet
.Get( EE_CHAR_FONTHEIGHT_CTL
), EE_CHAR_FONTHEIGHT_CTL
);
1406 pEditView
->SetAttribs( aNewSet
);
1410 void EditView::ChangeFontSize( bool bGrow
, const FontList
* pFontList
)
1412 DBG_CHKTHIS( EditView
, 0 );
1413 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1415 EditEngine
& rEditEngine
= *pImpEditView
->pEditEngine
;
1417 ESelection
aSel( GetSelection() );
1418 ESelection
aOldSelection( aSel
);
1421 if( !aSel
.HasRange() )
1423 aSel
= rEditEngine
.GetWord( aSel
, com::sun::star::i18n::WordType::DICTIONARY_WORD
);
1426 if( aSel
.HasRange() )
1428 for( USHORT nPara
= aSel
.nStartPara
; nPara
<= aSel
.nEndPara
; nPara
++ )
1430 SvUShorts aPortions
;
1431 rEditEngine
.GetPortions( nPara
, aPortions
);
1433 if( aPortions
.Count() == 0 )
1434 aPortions
.Insert( rEditEngine
.GetTextLen(nPara
), 0 );
1436 const USHORT nBeginPos
= (nPara
== aSel
.nStartPara
) ? aSel
.nStartPos
: 0;
1437 const USHORT nEndPos
= (nPara
== aSel
.nEndPara
) ? aSel
.nEndPos
: 0xffff;
1439 for ( USHORT nPos
= 0; nPos
< aPortions
.Count(); ++nPos
)
1441 USHORT nPortionEnd
= aPortions
.GetObject( nPos
);
1442 USHORT nPortionStart
= nPos
> 0 ? aPortions
.GetObject( nPos
- 1 ) : 0;
1444 if( (nPortionEnd
< nBeginPos
) || (nPortionStart
> nEndPos
) )
1447 if( nPortionStart
< nBeginPos
)
1448 nPortionStart
= nBeginPos
;
1449 if( nPortionEnd
> nEndPos
)
1450 nPortionEnd
= nEndPos
;
1452 if( nPortionStart
== nPortionEnd
)
1455 ESelection
aPortionSel( nPara
, nPortionStart
, nPara
, nPortionEnd
);
1456 ChangeFontSizeImpl( this, bGrow
, aPortionSel
, pFontList
);
1462 ChangeFontSizeImpl( this, bGrow
, aSel
, pFontList
);
1465 SetSelection( aOldSelection
);
1468 bool EditView::ChangeFontSize( bool bGrow
, SfxItemSet
& rSet
, const FontList
* pFontList
)
1470 static const sal_uInt16 gFontSizeWichMap
[] = { EE_CHAR_FONTHEIGHT
, EE_CHAR_FONTHEIGHT_CJK
, EE_CHAR_FONTHEIGHT_CTL
, 0 };
1472 const SvxFontItem
* pFontItem
= static_cast<const SvxFontItem
*>(&rSet
.Get( EE_CHAR_FONTINFO
));
1473 if( !pFontItem
|| !pFontList
)
1478 const sal_uInt16
* pWhich
= gFontSizeWichMap
;
1481 SvxFontHeightItem
aFontHeightItem( static_cast<const SvxFontHeightItem
&>(rSet
.Get( *pWhich
)) );
1482 long nHeight
= aFontHeightItem
.GetHeight();
1483 const SfxMapUnit eUnit
= rSet
.GetPool()->GetMetric( *pWhich
);
1484 nHeight
= OutputDevice::LogicToLogic( nHeight
* 10, (MapUnit
)eUnit
, MAP_POINT
);
1486 FontInfo aFontInfo
= pFontList
->Get( pFontItem
->GetFamilyName(), pFontItem
->GetStyleName() );
1487 const long* pAry
= pFontList
->GetSizeAry( aFontInfo
);
1493 if( *pAry
> nHeight
)
1503 nHeight
+= (nHeight
+ 5) / 10;
1504 if( nHeight
> 9999 )
1511 bool bFound
= false;
1512 if( *pAry
< nHeight
)
1517 if( *pAry
>= nHeight
)
1529 nHeight
-= (nHeight
+ 5) / 10;
1535 if( (nHeight
>= 2) && (nHeight
<= 9999 ) )
1537 nHeight
= OutputDevice::LogicToLogic( nHeight
, MAP_POINT
, (MapUnit
)eUnit
) / 10;
1539 if( nHeight
!= (long)aFontHeightItem
.GetHeight() )
1541 aFontHeightItem
.SetHeight( nHeight
);
1542 rSet
.Put( aFontHeightItem
, *pWhich
);
1551 String
EditView::GetSurroundingText() const
1553 DBG_CHKTHIS( EditView
, 0 );
1554 DBG_CHKOBJ( pImpEditView
->pEditEngine
, EditEngine
, 0 );
1556 EditSelection
aSel( pImpEditView
->GetEditSelection() );
1557 aSel
.Adjust( PIMPEE
->GetEditDoc() );
1559 if( HasSelection() )
1561 XubString aStr
= PIMPEE
->GetSelected( aSel
);
1563 // Stop reconversion if the selected text includes a line break.
1564 if ( aStr
.Search( 0x0A ) == STRING_NOTFOUND
)
1571 aSel
.Min().SetIndex( 0 );
1572 aSel
.Max().SetIndex( aSel
.Max().GetNode()->Len() );
1573 return PIMPEE
->GetSelected( aSel
);
1577 Selection
EditView::GetSurroundingTextSelection() const
1579 DBG_CHKTHIS( EditView
, 0 );
1581 ESelection
aSelection( GetSelection() );
1582 aSelection
.Adjust();
1584 if( HasSelection() )
1586 EditSelection
aSel( pImpEditView
->GetEditSelection() );
1587 aSel
.Adjust( PIMPEE
->GetEditDoc() );
1588 XubString aStr
= PIMPEE
->GetSelected( aSel
);
1590 // Stop reconversion if the selected text includes a line break.
1591 if ( aStr
.Search( 0x0A ) == STRING_NOTFOUND
)
1592 return Selection( 0, aSelection
.nEndPos
- aSelection
.nStartPos
);
1594 return Selection( 0, 0 );
1598 return Selection( aSelection
.nStartPos
, aSelection
.nEndPos
);