Bump for 3.6-28
[LibreOffice.git] / editeng / source / outliner / outlvw.cxx
blob85b1b265a4d12e87c23135b4b8293fbebbec9d4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <com/sun/star/i18n/WordType.hpp>
33 #include <svl/intitem.hxx>
34 #include <editeng/editeng.hxx>
35 #include <editeng/editview.hxx>
36 #include <editeng/editdata.hxx>
37 #include <editeng/eerdll.hxx>
38 #include <editeng/lrspitem.hxx>
39 #include <editeng/fhgtitem.hxx>
41 #include <svl/style.hxx>
42 #include <i18npool/mslangid.hxx>
44 #define _OUTLINER_CXX
45 #include <editeng/outliner.hxx>
46 #include <outleeng.hxx>
47 #include <paralist.hxx>
48 #include <outlundo.hxx>
49 #include <editeng/outlobj.hxx>
50 #include <editeng/flditem.hxx>
51 #include <editeng/eeitem.hxx>
52 #include <editeng/numitem.hxx>
53 #include <vcl/window.hxx>
54 #include <svl/itemset.hxx>
55 #include <editeng/editstat.hxx>
57 using namespace ::com::sun::star;
59 DBG_NAME(OutlinerView)
62 OutlinerView::OutlinerView( Outliner* pOut, Window* pWin )
64 DBG_CTOR( OutlinerView, 0 );
66 pOwner = pOut;
67 bDDCursorVisible = sal_False;
68 bInDragMode = sal_False;
69 nDDScrollLRBorderWidthWin = 0;
70 nDDScrollTBBorderWidthWin = 0;
71 pHorTabArrDoc = 0;
73 pEditView = new EditView( pOut->pEditEngine, pWin );
74 pEditView->SetSelectionMode( EE_SELMODE_TXTONLY );
77 OutlinerView::~OutlinerView()
79 DBG_DTOR(OutlinerView,0);
80 delete pEditView;
83 void OutlinerView::Paint( const Rectangle& rRect )
85 DBG_CHKTHIS(OutlinerView,0);
87 // For the first Paint/KeyInput/Drop an emty Outliner is turned into
88 // an Outliner with exactly one paragraph.
89 if( pOwner->bFirstParaIsEmpty )
90 pOwner->Insert( String() );
92 pEditView->Paint( rRect );
95 sal_Bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, Window* pFrameWin )
97 DBG_CHKTHIS( OutlinerView, 0 );
99 // For the first Paint/KeyInput/Drop an emty Outliner is turned into
100 // an Outliner with exactly one paragraph.
101 if( pOwner->bFirstParaIsEmpty )
102 pOwner->Insert( String() );
105 sal_Bool bKeyProcessed = sal_False;
106 ESelection aSel( pEditView->GetSelection() );
107 sal_Bool bSelection = aSel.HasRange();
108 KeyCode aKeyCode = rKEvt.GetKeyCode();
109 KeyFuncType eFunc = aKeyCode.GetFunction();
110 sal_uInt16 nCode = aKeyCode.GetCode();
111 sal_Bool bReadOnly = IsReadOnly();
113 if( bSelection && ( nCode != KEY_TAB ) && EditEngine::DoesKeyChangeText( rKEvt ) )
115 if ( ImpCalcSelectedPages( sal_False ) && !pOwner->ImpCanDeleteSelectedPages( this ) )
116 return sal_True;
119 if ( eFunc != KEYFUNC_DONTKNOW )
121 switch ( eFunc )
123 case KEYFUNC_CUT:
125 if ( !bReadOnly )
127 Cut();
128 bKeyProcessed = sal_True;
131 break;
132 case KEYFUNC_COPY:
134 Copy();
135 bKeyProcessed = sal_True;
137 break;
138 case KEYFUNC_PASTE:
140 if ( !bReadOnly )
142 PasteSpecial();
143 bKeyProcessed = sal_True;
146 break;
147 case KEYFUNC_DELETE:
149 if( !bReadOnly && !bSelection && ( pOwner->ImplGetOutlinerMode() != OUTLINERMODE_TEXTOBJECT ) )
151 if( aSel.nEndPos == pOwner->pEditEngine->GetTextLen( aSel.nEndPara ) )
153 Paragraph* pNext = pOwner->pParaList->GetParagraph( aSel.nEndPara+1 );
154 if( pNext && pNext->HasFlag(PARAFLAG_ISPAGE) )
156 if( !pOwner->ImpCanDeleteSelectedPages( this, aSel.nEndPara, 1 ) )
157 return sal_False;
162 break;
163 default: // is then possibly edited below.
164 eFunc = KEYFUNC_DONTKNOW;
167 if ( eFunc == KEYFUNC_DONTKNOW )
169 switch ( nCode )
171 case KEY_TAB:
173 if ( !bReadOnly && !aKeyCode.IsMod1() && !aKeyCode.IsMod2() )
175 if ( ( pOwner->ImplGetOutlinerMode() != OUTLINERMODE_TEXTOBJECT ) &&
176 ( pOwner->ImplGetOutlinerMode() != OUTLINERMODE_TITLEOBJECT ) &&
177 ( bSelection || !aSel.nStartPos ) )
179 Indent( aKeyCode.IsShift() ? (-1) : (+1) );
180 bKeyProcessed = sal_True;
182 else if ( ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_TEXTOBJECT ) &&
183 !bSelection && !aSel.nEndPos && pOwner->ImplHasBullet( aSel.nEndPara ) )
185 Indent( aKeyCode.IsShift() ? (-1) : (+1) );
186 bKeyProcessed = sal_True;
190 break;
191 case KEY_BACKSPACE:
193 if( !bReadOnly && !bSelection && aSel.nEndPara && !aSel.nEndPos )
195 Paragraph* pPara = pOwner->pParaList->GetParagraph( aSel.nEndPara );
196 Paragraph* pPrev = pOwner->pParaList->GetParagraph( aSel.nEndPara-1 );
197 if( !pPrev->IsVisible() )
198 return sal_True;
199 if( !pPara->GetDepth() )
201 if(!pOwner->ImpCanDeleteSelectedPages(this, aSel.nEndPara , 1 ) )
202 return sal_True;
206 break;
207 case KEY_RETURN:
209 if ( !bReadOnly )
211 // Special treatment: hard return at the end of a paragraph,
212 // which has collapsed subparagraphs.
213 Paragraph* pPara = pOwner->pParaList->GetParagraph( aSel.nEndPara );
215 if( !aKeyCode.IsShift() )
217 // ImpGetCursor again???
218 if( !bSelection &&
219 aSel.nEndPos == pOwner->pEditEngine->GetTextLen( aSel.nEndPara ) )
221 sal_uLong nChildren = pOwner->pParaList->GetChildCount(pPara);
222 if( nChildren && !pOwner->pParaList->HasVisibleChildren(pPara))
224 pOwner->UndoActionStart( OLUNDO_INSERT );
225 sal_uLong nTemp = aSel.nEndPara;
226 nTemp += nChildren;
227 nTemp++; // insert above next Non-Child
228 pOwner->Insert( String(),nTemp,pPara->GetDepth());
229 // Position the cursor
230 ESelection aTmpSel((sal_uInt16)nTemp,0,(sal_uInt16)nTemp,0);
231 pEditView->SetSelection( aTmpSel );
232 pEditView->ShowCursor( sal_True, sal_True );
233 pOwner->UndoActionEnd( OLUNDO_INSERT );
234 bKeyProcessed = sal_True;
238 if( !bKeyProcessed && !bSelection &&
239 !aKeyCode.IsShift() && aKeyCode.IsMod1() &&
240 ( aSel.nEndPos == pOwner->pEditEngine->GetTextLen(aSel.nEndPara) ) )
242 pOwner->UndoActionStart( OLUNDO_INSERT );
243 sal_uLong nTemp = aSel.nEndPara;
244 nTemp++;
245 pOwner->Insert( String(), nTemp, pPara->GetDepth()+1 );
247 // Position the cursor
248 ESelection aTmpSel((sal_uInt16)nTemp,0,(sal_uInt16)nTemp,0);
249 pEditView->SetSelection( aTmpSel );
250 pEditView->ShowCursor( sal_True, sal_True );
251 pOwner->UndoActionEnd( OLUNDO_INSERT );
252 bKeyProcessed = sal_True;
256 break;
260 return bKeyProcessed ? sal_True : pEditView->PostKeyEvent( rKEvt, pFrameWin );
265 sal_uLong OutlinerView::ImpCheckMousePos(const Point& rPosPix, MouseTarget& reTarget)
267 DBG_CHKTHIS(OutlinerView,0);
268 sal_uLong nPara = EE_PARA_NOT_FOUND;
270 Point aMousePosWin = pEditView->GetWindow()->PixelToLogic( rPosPix );
271 if( !pEditView->GetOutputArea().IsInside( aMousePosWin ) )
273 reTarget = MouseOutside;
275 else
277 reTarget = MouseText;
279 Point aPaperPos( aMousePosWin );
280 Rectangle aOutArea = pEditView->GetOutputArea();
281 Rectangle aVisArea = pEditView->GetVisArea();
282 aPaperPos.X() -= aOutArea.Left();
283 aPaperPos.X() += aVisArea.Left();
284 aPaperPos.Y() -= aOutArea.Top();
285 aPaperPos.Y() += aVisArea.Top();
287 sal_Bool bBullet;
288 if ( pOwner->IsTextPos( aPaperPos, 0, &bBullet ) )
290 Point aDocPos = pOwner->GetDocPos( aPaperPos );
291 nPara = pOwner->pEditEngine->FindParagraph( aDocPos.Y() );
293 if ( bBullet )
295 reTarget = MouseBullet;
297 else
299 // Check for hyperlink
300 const SvxFieldItem* pFieldItem = pEditView->GetField( aMousePosWin );
301 if ( pFieldItem && pFieldItem->GetField() && pFieldItem->GetField()->ISA( SvxURLField ) )
302 reTarget = MouseHypertext;
306 return nPara;
309 sal_Bool OutlinerView::MouseMove( const MouseEvent& rMEvt )
311 DBG_CHKTHIS(OutlinerView,0);
313 if( ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_TEXTOBJECT ) || pEditView->GetEditEngine()->IsInSelectionMode())
314 return pEditView->MouseMove( rMEvt );
316 Point aMousePosWin( pEditView->GetWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
317 if( !pEditView->GetOutputArea().IsInside( aMousePosWin ) )
318 return sal_False;
320 Pointer aPointer = GetPointer( rMEvt.GetPosPixel() );
321 pEditView->GetWindow()->SetPointer( aPointer );
322 return pEditView->MouseMove( rMEvt );
326 sal_Bool OutlinerView::MouseButtonDown( const MouseEvent& rMEvt )
328 DBG_CHKTHIS(OutlinerView,0);
329 if ( ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_TEXTOBJECT ) || pEditView->GetEditEngine()->IsInSelectionMode() )
330 return pEditView->MouseButtonDown( rMEvt );
332 Point aMousePosWin( pEditView->GetWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
333 if( !pEditView->GetOutputArea().IsInside( aMousePosWin ) )
334 return sal_False;
336 Pointer aPointer = GetPointer( rMEvt.GetPosPixel() );
337 pEditView->GetWindow()->SetPointer( aPointer );
339 MouseTarget eTarget;
340 sal_uLong nPara = ImpCheckMousePos( rMEvt.GetPosPixel(), eTarget );
341 if ( eTarget == MouseBullet )
343 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
344 sal_Bool bHasChildren = (pPara && pOwner->pParaList->HasChildren(pPara));
345 if( rMEvt.GetClicks() == 1 )
347 sal_uLong nEndPara = nPara;
348 if ( bHasChildren && pOwner->pParaList->HasVisibleChildren(pPara) )
349 nEndPara += pOwner->pParaList->GetChildCount( pPara );
350 // The selection is inverted, so that EditEngine does not scroll
351 ESelection aSel((sal_uInt16)nEndPara, 0xffff,(sal_uInt16)nPara, 0 );
352 pEditView->SetSelection( aSel );
354 else if( rMEvt.GetClicks() == 2 && bHasChildren )
355 ImpToggleExpand( pPara );
357 aDDStartPosPix = rMEvt.GetPosPixel();
358 aDDStartPosRef=pEditView->GetWindow()->PixelToLogic( aDDStartPosPix,pOwner->GetRefMapMode());
359 return sal_True;
362 // special case for outliner view in impress, check if double click hits the page icon for toggle
363 if( (nPara == EE_PARA_NOT_FOUND) && (pOwner->ImplGetOutlinerMode() == OUTLINERMODE_OUTLINEVIEW) && (eTarget == MouseText) && (rMEvt.GetClicks() == 2) )
365 ESelection aSel( pEditView->GetSelection() );
366 nPara = aSel.nStartPara;
367 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
368 if( (pPara && pOwner->pParaList->HasChildren(pPara)) && pPara->HasFlag(PARAFLAG_ISPAGE) )
370 ImpToggleExpand( pPara );
373 return pEditView->MouseButtonDown( rMEvt );
377 sal_Bool OutlinerView::MouseButtonUp( const MouseEvent& rMEvt )
379 DBG_CHKTHIS(OutlinerView,0);
380 if ( ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_TEXTOBJECT ) || pEditView->GetEditEngine()->IsInSelectionMode() )
381 return pEditView->MouseButtonUp( rMEvt );
383 Point aMousePosWin( pEditView->GetWindow()->PixelToLogic( rMEvt.GetPosPixel() ) );
384 if( !pEditView->GetOutputArea().IsInside( aMousePosWin ) )
385 return sal_False;
387 Pointer aPointer = GetPointer( rMEvt.GetPosPixel() );
388 pEditView->GetWindow()->SetPointer( aPointer );
390 return pEditView->MouseButtonUp( rMEvt );
393 void OutlinerView::ImpToggleExpand( Paragraph* pPara )
395 DBG_CHKTHIS(OutlinerView,0);
397 sal_uInt16 nPara = (sal_uInt16) pOwner->pParaList->GetAbsPos( pPara );
398 pEditView->SetSelection( ESelection( nPara, 0, nPara, 0 ) );
399 ImplExpandOrCollaps( nPara, nPara, !pOwner->pParaList->HasVisibleChildren( pPara ) );
400 pEditView->ShowCursor();
403 sal_uLong OutlinerView::Select( Paragraph* pParagraph, sal_Bool bSelect,
404 sal_Bool bWithChildren )
406 DBG_CHKTHIS(OutlinerView,0);
408 sal_uLong nPara = pOwner->pParaList->GetAbsPos( pParagraph );
409 sal_uInt16 nEnd = 0;
410 if ( bSelect )
411 nEnd = 0xffff;
413 sal_uLong nChildCount = 0;
414 if ( bWithChildren )
415 nChildCount = pOwner->pParaList->GetChildCount( pParagraph );
417 ESelection aSel( (sal_uInt16)nPara, 0,(sal_uInt16)(nPara+nChildCount), nEnd );
418 pEditView->SetSelection( aSel );
419 return nChildCount+1;
423 void OutlinerView::SetAttribs( const SfxItemSet& rAttrs )
425 DBG_CHKTHIS(OutlinerView,0);
427 sal_Bool bUpdate = pOwner->pEditEngine->GetUpdateMode();
428 pOwner->pEditEngine->SetUpdateMode( sal_False );
430 if( !pOwner->IsInUndo() && pOwner->IsUndoEnabled() )
431 pOwner->UndoActionStart( OLUNDO_ATTR );
433 ParaRange aSel = ImpGetSelectedParagraphs( sal_False );
435 pEditView->SetAttribs( rAttrs );
437 // Update Bullet text
438 for( sal_uInt16 nPara= aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
440 pOwner->ImplCheckNumBulletItem( nPara );
441 pOwner->ImplCalcBulletText( nPara, sal_False, sal_False );
443 if( !pOwner->IsInUndo() && pOwner->IsUndoEnabled() )
444 pOwner->InsertUndo( new OutlinerUndoCheckPara( pOwner, nPara ) );
447 if( !pOwner->IsInUndo() && pOwner->IsUndoEnabled() )
448 pOwner->UndoActionEnd( OLUNDO_ATTR );
450 pEditView->SetEditEngineUpdateMode( bUpdate );
453 ParaRange OutlinerView::ImpGetSelectedParagraphs( sal_Bool bIncludeHiddenChildren )
455 DBG_CHKTHIS( OutlinerView, 0 );
457 ESelection aSel = pEditView->GetSelection();
458 ParaRange aParas( aSel.nStartPara, aSel.nEndPara );
459 aParas.Adjust();
461 // Record the invisible Children of the last Parents in the selection
462 if ( bIncludeHiddenChildren )
464 Paragraph* pLast = pOwner->pParaList->GetParagraph( aParas.nEndPara );
465 if ( pOwner->pParaList->HasHiddenChildren( pLast ) )
466 aParas.nEndPara =
467 sal::static_int_cast< sal_uInt16 >(
468 aParas.nEndPara +
469 pOwner->pParaList->GetChildCount( pLast ) );
471 return aParas;
474 // TODO: Name should be changed!
475 void OutlinerView::AdjustDepth( short nDX )
477 Indent( nDX );
480 void OutlinerView::Indent( short nDiff )
482 DBG_CHKTHIS( OutlinerView, 0 );
484 if( !nDiff || ( ( nDiff > 0 ) && ImpCalcSelectedPages( sal_True ) && !pOwner->ImpCanIndentSelectedPages( this ) ) )
485 return;
487 const bool bOutlinerView = pOwner->pEditEngine->GetControlWord() & EE_CNTRL_OUTLINER;
488 sal_Bool bUpdate = pOwner->pEditEngine->GetUpdateMode();
489 pOwner->pEditEngine->SetUpdateMode( sal_False );
491 sal_Bool bUndo = !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
493 if( bUndo )
494 pOwner->UndoActionStart( OLUNDO_DEPTH );
496 sal_Int16 nMinDepth = -1; // Optimization: Not to recalculate to manny parargaphs when not really needed.
498 ParaRange aSel = ImpGetSelectedParagraphs( sal_True );
499 for ( sal_uInt16 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
501 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
503 sal_Int16 nOldDepth = pPara->GetDepth();
504 sal_Int16 nNewDepth = nOldDepth + nDiff;
506 if( bOutlinerView && nPara )
508 const bool bPage = pPara->HasFlag(PARAFLAG_ISPAGE);
509 if( (bPage && (nDiff == +1)) || (!bPage && (nDiff == -1) && (nOldDepth <= 0)) )
511 // Notify App
512 pOwner->nDepthChangedHdlPrevDepth = (sal_Int16)nOldDepth;
513 pOwner->mnDepthChangeHdlPrevFlags = pPara->nFlags;
514 pOwner->pHdlParagraph = pPara;
516 if( bPage )
517 pPara->RemoveFlag( PARAFLAG_ISPAGE );
518 else
519 pPara->SetFlag( PARAFLAG_ISPAGE );
521 pOwner->DepthChangedHdl();
522 pOwner->pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) );
524 if( bUndo )
525 pOwner->InsertUndo( new OutlinerUndoChangeParaFlags( pOwner, nPara, pOwner->mnDepthChangeHdlPrevFlags, pPara->nFlags ) );
527 continue;
531 // do not switch off numeration with tab
532 if( (nOldDepth == 0) && (nNewDepth == -1) )
533 continue;
535 // do not indent if there is no numeration enabled
536 if( nOldDepth == -1 )
537 continue;
539 if ( nNewDepth < pOwner->nMinDepth )
540 nNewDepth = pOwner->nMinDepth;
541 if ( nNewDepth > pOwner->nMaxDepth )
542 nNewDepth = pOwner->nMaxDepth;
544 if( nOldDepth < nMinDepth )
545 nMinDepth = nOldDepth;
546 if( nNewDepth < nMinDepth )
547 nMinDepth = nNewDepth;
549 if( nOldDepth != nNewDepth )
551 if ( ( nPara == aSel.nStartPara ) && aSel.nStartPara && ( pOwner->ImplGetOutlinerMode() != OUTLINERMODE_TEXTOBJECT ))
553 // Special case: the predecessor of an indented paragraph is
554 // invisible and is now on the same level as the visible
555 // paragraph. In this case, the next visible paragraph is
556 // searched for and fluffed.
557 #ifdef DBG_UTIL
558 Paragraph* _pPara = pOwner->pParaList->GetParagraph( aSel.nStartPara );
559 DBG_ASSERT(_pPara->IsVisible(),"Selected Paragraph invisible ?!");
560 #endif
561 Paragraph* pPrev= pOwner->pParaList->GetParagraph( aSel.nStartPara-1 );
563 if( !pPrev->IsVisible() && ( pPrev->GetDepth() == nNewDepth ) )
565 // Predecessor is collapsed and is on the same level
566 // => find next visible paragraph and expand it
567 pPrev = pOwner->pParaList->GetParent( pPrev );
568 while( !pPrev->IsVisible() )
569 pPrev = pOwner->pParaList->GetParent( pPrev );
571 pOwner->Expand( pPrev );
572 pOwner->InvalidateBullet( pPrev, pOwner->pParaList->GetAbsPos( pPrev ) );
576 pOwner->nDepthChangedHdlPrevDepth = (sal_Int16)nOldDepth;
577 pOwner->mnDepthChangeHdlPrevFlags = pPara->nFlags;
578 pOwner->pHdlParagraph = pPara;
580 pOwner->ImplInitDepth( nPara, nNewDepth, sal_True, sal_False );
581 pOwner->ImplCalcBulletText( nPara, sal_False, sal_False );
583 if ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_OUTLINEOBJECT )
584 pOwner->ImplSetLevelDependendStyleSheet( nPara );
586 // Notify App
587 pOwner->DepthChangedHdl();
589 else
591 // Needs at least a repaint...
592 pOwner->pEditEngine->QuickMarkInvalid( ESelection( nPara, 0, nPara, 0 ) );
596 sal_uInt16 nParas = (sal_uInt16)pOwner->pParaList->GetParagraphCount();
597 for ( sal_uInt16 n = aSel.nEndPara+1; n < nParas; n++ )
599 Paragraph* pPara = pOwner->pParaList->GetParagraph( n );
600 if ( pPara->GetDepth() < nMinDepth )
601 break;
602 pOwner->ImplCalcBulletText( n, sal_False, sal_False );
605 if ( bUpdate )
607 pEditView->SetEditEngineUpdateMode( sal_True );
608 pEditView->ShowCursor();
611 if( bUndo )
612 pOwner->UndoActionEnd( OLUNDO_DEPTH );
615 sal_Bool OutlinerView::AdjustHeight( long nDY )
617 DBG_CHKTHIS(OutlinerView,0);
618 pEditView->MoveParagraphs( nDY );
619 return sal_True; // remove return value...
622 Rectangle OutlinerView::GetVisArea() const
624 DBG_CHKTHIS(OutlinerView,0);
625 return pEditView->GetVisArea();
628 void OutlinerView::Expand()
630 DBG_CHKTHIS( OutlinerView, 0 );
631 ParaRange aParas = ImpGetSelectedParagraphs( sal_False );
632 ImplExpandOrCollaps( aParas.nStartPara, aParas.nEndPara, sal_True );
636 void OutlinerView::Collapse()
638 DBG_CHKTHIS( OutlinerView, 0 );
639 ParaRange aParas = ImpGetSelectedParagraphs( sal_False );
640 ImplExpandOrCollaps( aParas.nStartPara, aParas.nEndPara, sal_False );
644 void OutlinerView::ExpandAll()
646 DBG_CHKTHIS( OutlinerView, 0 );
647 ImplExpandOrCollaps( 0, (sal_uInt16)(pOwner->pParaList->GetParagraphCount()-1), sal_True );
651 void OutlinerView::CollapseAll()
653 DBG_CHKTHIS(OutlinerView,0);
654 ImplExpandOrCollaps( 0, (sal_uInt16)(pOwner->pParaList->GetParagraphCount()-1), sal_False );
657 void OutlinerView::ImplExpandOrCollaps( sal_uInt16 nStartPara, sal_uInt16 nEndPara, sal_Bool bExpand )
659 DBG_CHKTHIS( OutlinerView, 0 );
661 sal_Bool bUpdate = pOwner->GetUpdateMode();
662 pOwner->SetUpdateMode( sal_False );
664 sal_Bool bUndo = !pOwner->IsInUndo() && pOwner->IsUndoEnabled();
665 if( bUndo )
666 pOwner->UndoActionStart( bExpand ? OLUNDO_EXPAND : OLUNDO_COLLAPSE );
668 for ( sal_uInt16 nPara = nStartPara; nPara <= nEndPara; nPara++ )
670 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
671 sal_Bool bDone = bExpand ? pOwner->Expand( pPara ) : pOwner->Collapse( pPara );
672 if( bDone )
674 // The line under the paragraph should disappear ...
675 pOwner->pEditEngine->QuickMarkToBeRepainted( nPara );
679 if( bUndo )
680 pOwner->UndoActionEnd( bExpand ? OLUNDO_EXPAND : OLUNDO_COLLAPSE );
682 if ( bUpdate )
684 pOwner->SetUpdateMode( sal_True );
685 pEditView->ShowCursor();
689 void OutlinerView::InsertText( const OutlinerParaObject& rParaObj )
691 // Like Paste, only EditView::Insert, instead of EditView::Paste.
692 // Actually not quite true that possible indentations must be corrected,
693 // but that comes later by a universal import. The indentation level is
694 // then determined right in the Inserted method.
695 // Possible structure:
696 // pImportInfo with DestPara, DestPos, nFormat, pParaObj...
697 // Possibly problematic:
698 // EditEngine, RTF => Splitting the area, later join together.
700 DBG_CHKTHIS(OutlinerView,0);
702 if ( ImpCalcSelectedPages( sal_False ) && !pOwner->ImpCanDeleteSelectedPages( this ) )
703 return;
705 pOwner->UndoActionStart( OLUNDO_INSERT );
707 pOwner->pEditEngine->SetUpdateMode( sal_False );
708 sal_uLong nStart, nParaCount;
709 nParaCount = pOwner->pEditEngine->GetParagraphCount();
710 sal_uInt16 nSize = ImpInitPaste( nStart );
711 pEditView->InsertText( rParaObj.GetTextObject() );
712 ImpPasted( nStart, nParaCount, nSize);
713 pEditView->SetEditEngineUpdateMode( sal_True );
715 pOwner->UndoActionEnd( OLUNDO_INSERT );
717 pEditView->ShowCursor( sal_True, sal_True );
722 void OutlinerView::Cut()
724 DBG_CHKTHIS(OutlinerView,0);
725 if ( !ImpCalcSelectedPages( sal_False ) || pOwner->ImpCanDeleteSelectedPages( this ) )
726 pEditView->Cut();
729 void OutlinerView::Paste()
731 DBG_CHKTHIS(OutlinerView,0);
732 PasteSpecial(); // HACK(SD does not call PasteSpecial)
735 void OutlinerView::PasteSpecial()
737 DBG_CHKTHIS(OutlinerView,0);
738 if ( !ImpCalcSelectedPages( sal_False ) || pOwner->ImpCanDeleteSelectedPages( this ) )
740 pOwner->UndoActionStart( OLUNDO_INSERT );
742 pOwner->pEditEngine->SetUpdateMode( sal_False );
743 pOwner->bPasting = sal_True;
744 pEditView->PasteSpecial();
746 if ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_OUTLINEOBJECT )
748 const sal_uInt16 nParaCount = pOwner->pEditEngine->GetParagraphCount();
750 for( sal_uInt16 nPara = 0; nPara < nParaCount; nPara++ )
751 pOwner->ImplSetLevelDependendStyleSheet( nPara );
754 pEditView->SetEditEngineUpdateMode( sal_True );
755 pOwner->UndoActionEnd( OLUNDO_INSERT );
756 pEditView->ShowCursor( sal_True, sal_True );
760 void OutlinerView::CreateSelectionList (std::vector<Paragraph*> &aSelList)
762 DBG_CHKTHIS( OutlinerView, 0 );
764 ParaRange aParas = ImpGetSelectedParagraphs( sal_True );
766 for ( sal_uInt16 nPara = aParas.nStartPara; nPara <= aParas.nEndPara; nPara++ )
768 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
769 aSelList.push_back(pPara);
773 const SfxStyleSheet* OutlinerView::GetStyleSheet() const
775 DBG_CHKTHIS(OutlinerView,0);
776 return pEditView->GetStyleSheet();
779 SfxStyleSheet* OutlinerView::GetStyleSheet()
781 DBG_CHKTHIS(OutlinerView,0);
782 return pEditView->GetStyleSheet();
785 Pointer OutlinerView::GetPointer( const Point& rPosPixel )
787 DBG_CHKTHIS(OutlinerView,0);
789 MouseTarget eTarget;
790 ImpCheckMousePos( rPosPixel, eTarget );
792 PointerStyle ePointerStyle = POINTER_ARROW;
793 if ( eTarget == MouseText )
795 ePointerStyle = GetOutliner()->IsVertical() ? POINTER_TEXT_VERTICAL : POINTER_TEXT;
797 else if ( eTarget == MouseHypertext )
799 ePointerStyle = POINTER_REFHAND;
801 else if ( eTarget == MouseBullet )
803 ePointerStyle = POINTER_MOVE;
806 return Pointer( ePointerStyle );
810 sal_uInt16 OutlinerView::ImpInitPaste( sal_uLong& rStart )
812 DBG_CHKTHIS(OutlinerView,0);
813 pOwner->bPasting = sal_True;
814 ESelection aSelection( pEditView->GetSelection() );
815 aSelection.Adjust();
816 rStart = aSelection.nStartPara;
817 sal_uInt16 nSize = aSelection.nEndPara - aSelection.nStartPara + 1;
818 return nSize;
822 void OutlinerView::ImpPasted( sal_uLong nStart, sal_uLong nPrevParaCount, sal_uInt16 nSize)
824 DBG_CHKTHIS(OutlinerView,0);
825 pOwner->bPasting = sal_False;
826 sal_uLong nCurParaCount = (sal_uLong)pOwner->pEditEngine->GetParagraphCount();
827 if( nCurParaCount < nPrevParaCount )
828 nSize = sal::static_int_cast< sal_uInt16 >(
829 nSize - ( nPrevParaCount - nCurParaCount ) );
830 else
831 nSize = sal::static_int_cast< sal_uInt16 >(
832 nSize + ( nCurParaCount - nPrevParaCount ) );
833 pOwner->ImpTextPasted( nStart, nSize );
837 void OutlinerView::Command( const CommandEvent& rCEvt )
839 DBG_CHKTHIS(OutlinerView,0);
840 pEditView->Command( rCEvt );
844 void OutlinerView::SelectRange( sal_uLong nFirst, sal_uInt16 nCount )
846 DBG_CHKTHIS(OutlinerView,0);
847 sal_uLong nLast = nFirst+nCount;
848 nCount = (sal_uInt16)pOwner->pParaList->GetParagraphCount();
849 if( nLast <= nCount )
850 nLast = nCount - 1;
851 ESelection aSel( (sal_uInt16)nFirst, 0, (sal_uInt16)nLast, 0xffff );
852 pEditView->SetSelection( aSel );
856 sal_uInt16 OutlinerView::ImpCalcSelectedPages( sal_Bool bIncludeFirstSelected )
858 DBG_CHKTHIS(OutlinerView,0);
860 ESelection aSel( pEditView->GetSelection() );
861 aSel.Adjust();
863 sal_uInt16 nPages = 0;
864 sal_uInt16 nFirstPage = 0xFFFF;
865 sal_uInt16 nStartPara = aSel.nStartPara;
866 if ( !bIncludeFirstSelected )
867 nStartPara++; // All paragraphs after StartPara will be deleted
868 for ( sal_uInt16 nPara = nStartPara; nPara <= aSel.nEndPara; nPara++ )
870 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
871 DBG_ASSERT(pPara, "ImpCalcSelectedPages: invalid Selection? ");
872 if( pPara->HasFlag(PARAFLAG_ISPAGE) )
874 nPages++;
875 if( nFirstPage == 0xFFFF )
876 nFirstPage = nPara;
880 if( nPages )
882 pOwner->nDepthChangedHdlPrevDepth = nPages;
883 pOwner->pHdlParagraph = 0;
884 pOwner->mnFirstSelPage = nFirstPage;
887 return nPages;
891 void OutlinerView::ToggleBullets()
893 pOwner->UndoActionStart( OLUNDO_DEPTH );
895 ESelection aSel( pEditView->GetSelection() );
896 aSel.Adjust();
898 const bool bUpdate = pOwner->pEditEngine->GetUpdateMode();
899 pOwner->pEditEngine->SetUpdateMode( sal_False );
901 sal_Int16 nDepth = -2;
903 for ( sal_uInt16 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
905 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
906 DBG_ASSERT(pPara, "OutlinerView::ToggleBullets(), illegal selection?");
908 if( pPara )
910 if( nDepth == -2 )
911 nDepth = (pOwner->GetDepth(nPara) == -1) ? 0 : -1;
913 pOwner->SetDepth( pPara, nDepth );
915 if( nDepth == -1 )
917 const SfxItemSet& rAttrs = pOwner->GetParaAttribs( nPara );
918 if(rAttrs.GetItemState( EE_PARA_BULLETSTATE ) == SFX_ITEM_SET)
920 SfxItemSet aAttrs(rAttrs);
921 aAttrs.ClearItem( EE_PARA_BULLETSTATE );
922 pOwner->SetParaAttribs( nPara, aAttrs );
928 // #i100014#
929 // It is not a good idea to substract 1 from a count and cast the result
930 // to sal_uInt16 without check, if the count is 0.
931 sal_uInt16 nParaCount = (sal_uInt16) (pOwner->pParaList->GetParagraphCount());
932 pOwner->ImplCheckParagraphs( aSel.nStartPara, nParaCount );
933 pOwner->pEditEngine->QuickMarkInvalid( ESelection( aSel.nStartPara, 0, nParaCount, 0 ) );
935 pOwner->pEditEngine->SetUpdateMode( bUpdate );
937 pOwner->UndoActionEnd( OLUNDO_DEPTH );
940 void OutlinerView::EnableBullets()
942 pOwner->UndoActionStart( OLUNDO_DEPTH );
944 ESelection aSel( pEditView->GetSelection() );
945 aSel.Adjust();
947 const bool bUpdate = pOwner->pEditEngine->GetUpdateMode();
948 pOwner->pEditEngine->SetUpdateMode( sal_False );
950 for ( sal_uInt16 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
952 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
953 DBG_ASSERT(pPara, "OutlinerView::ToggleBullets(), illegal selection?");
955 if( pPara && (pOwner->GetDepth(nPara) == -1) )
957 pOwner->SetDepth( pPara, 0 );
961 // #i100014#
962 // It is not a good idea to substract 1 from a count and cast the result
963 // to sal_uInt16 without check, if the count is 0.
964 sal_uInt16 nParaCount = (sal_uInt16) (pOwner->pParaList->GetParagraphCount());
966 pOwner->ImplCheckParagraphs( aSel.nStartPara, nParaCount );
967 pOwner->pEditEngine->QuickMarkInvalid( ESelection( aSel.nStartPara, 0, nParaCount, 0 ) );
969 pOwner->pEditEngine->SetUpdateMode( bUpdate );
971 pOwner->UndoActionEnd( OLUNDO_DEPTH );
975 void OutlinerView::RemoveAttribsKeepLanguages( sal_Bool bRemoveParaAttribs )
977 RemoveAttribs( bRemoveParaAttribs, 0, sal_True /*keep language attribs*/ );
980 void OutlinerView::RemoveAttribs( sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich, sal_Bool bKeepLanguages )
982 DBG_CHKTHIS(OutlinerView,0);
983 sal_Bool bUpdate = pOwner->GetUpdateMode();
984 pOwner->SetUpdateMode( sal_False );
985 pOwner->UndoActionStart( OLUNDO_ATTR );
986 if (bKeepLanguages)
987 pEditView->RemoveAttribsKeepLanguages( bRemoveParaAttribs );
988 else
989 pEditView->RemoveAttribs( bRemoveParaAttribs, nWhich );
990 if ( bRemoveParaAttribs )
992 // Loop through all paragraphs and set indentation and level
993 ESelection aSel = pEditView->GetSelection();
994 aSel.Adjust();
995 for ( sal_uInt16 nPara = aSel.nStartPara; nPara <= aSel.nEndPara; nPara++ )
997 Paragraph* pPara = pOwner->pParaList->GetParagraph( nPara );
998 pOwner->ImplInitDepth( nPara, pPara->GetDepth(), sal_False, sal_False );
1001 pOwner->UndoActionEnd( OLUNDO_ATTR );
1002 pOwner->SetUpdateMode( bUpdate );
1007 // ======================================================================
1008 // ====================== Simple pass-through =======================
1009 // ======================================================================
1012 void OutlinerView::InsertText( const XubString& rNew, sal_Bool bSelect )
1014 DBG_CHKTHIS(OutlinerView,0);
1015 if( pOwner->bFirstParaIsEmpty )
1016 pOwner->Insert( String() );
1017 pEditView->InsertText( rNew, bSelect );
1020 void OutlinerView::SetVisArea( const Rectangle& rRec )
1022 DBG_CHKTHIS(OutlinerView,0);
1023 pEditView->SetVisArea( rRec );
1027 void OutlinerView::SetSelection( const ESelection& rSel )
1029 DBG_CHKTHIS(OutlinerView,0);
1030 pEditView->SetSelection( rSel );
1033 void OutlinerView::SetReadOnly( sal_Bool bReadOnly )
1035 DBG_CHKTHIS(OutlinerView,0);
1036 pEditView->SetReadOnly( bReadOnly );
1039 sal_Bool OutlinerView::IsReadOnly() const
1041 DBG_CHKTHIS(OutlinerView,0);
1042 return pEditView->IsReadOnly();
1045 sal_Bool OutlinerView::HasSelection() const
1047 DBG_CHKTHIS(OutlinerView,0);
1048 return pEditView->HasSelection();
1052 void OutlinerView::ShowCursor( sal_Bool bGotoCursor )
1054 DBG_CHKTHIS(OutlinerView,0);
1055 pEditView->ShowCursor( bGotoCursor );
1059 void OutlinerView::HideCursor()
1061 DBG_CHKTHIS(OutlinerView,0);
1062 pEditView->HideCursor();
1066 void OutlinerView::SetWindow( Window* pWin )
1068 DBG_CHKTHIS(OutlinerView,0);
1069 pEditView->SetWindow( pWin );
1073 Window* OutlinerView::GetWindow() const
1075 DBG_CHKTHIS(OutlinerView,0);
1076 return pEditView->GetWindow();
1080 void OutlinerView::SetOutputArea( const Rectangle& rRect )
1082 DBG_CHKTHIS(OutlinerView,0);
1083 pEditView->SetOutputArea( rRect );
1087 Rectangle OutlinerView::GetOutputArea() const
1089 DBG_CHKTHIS(OutlinerView,0);
1090 return pEditView->GetOutputArea();
1094 XubString OutlinerView::GetSelected() const
1096 DBG_CHKTHIS(OutlinerView,0);
1097 return pEditView->GetSelected();
1100 EESpellState OutlinerView::StartSpeller( sal_Bool bMultiDoc )
1102 DBG_CHKTHIS(OutlinerView,0);
1103 return pEditView->StartSpeller( bMultiDoc );
1106 EESpellState OutlinerView::StartThesaurus()
1108 DBG_CHKTHIS(OutlinerView,0);
1109 return pEditView->StartThesaurus();
1113 void OutlinerView::StartTextConversion(
1114 LanguageType nSrcLang, LanguageType nDestLang, const Font *pDestFont,
1115 sal_Int32 nOptions, sal_Bool bIsInteractive, sal_Bool bMultipleDoc )
1117 DBG_CHKTHIS(OutlinerView,0);
1118 if (
1119 (LANGUAGE_KOREAN == nSrcLang && LANGUAGE_KOREAN == nDestLang) ||
1120 (LANGUAGE_CHINESE_SIMPLIFIED == nSrcLang && LANGUAGE_CHINESE_TRADITIONAL == nDestLang) ||
1121 (LANGUAGE_CHINESE_TRADITIONAL == nSrcLang && LANGUAGE_CHINESE_SIMPLIFIED == nDestLang)
1124 pEditView->StartTextConversion( nSrcLang, nDestLang, pDestFont, nOptions, bIsInteractive, bMultipleDoc );
1126 else
1128 OSL_FAIL( "unexpected language" );
1133 sal_uInt16 OutlinerView::StartSearchAndReplace( const SvxSearchItem& rSearchItem )
1135 DBG_CHKTHIS(OutlinerView,0);
1136 return pEditView->StartSearchAndReplace( rSearchItem );
1139 void OutlinerView::TransliterateText( sal_Int32 nTransliterationMode )
1141 DBG_CHKTHIS(OutlinerView,0);
1142 pEditView->TransliterateText( nTransliterationMode );
1147 ESelection OutlinerView::GetSelection()
1149 DBG_CHKTHIS(OutlinerView,0);
1150 return pEditView->GetSelection();
1154 void OutlinerView::Scroll( long nHorzScroll, long nVertScroll )
1156 DBG_CHKTHIS(OutlinerView,0);
1157 pEditView->Scroll( nHorzScroll, nVertScroll );
1161 void OutlinerView::SetControlWord( sal_uLong nWord )
1163 DBG_CHKTHIS(OutlinerView,0);
1164 pEditView->SetControlWord( nWord );
1168 sal_uLong OutlinerView::GetControlWord() const
1170 DBG_CHKTHIS(OutlinerView,0);
1171 return pEditView->GetControlWord();
1175 void OutlinerView::SetAnchorMode( EVAnchorMode eMode )
1177 DBG_CHKTHIS(OutlinerView,0);
1178 pEditView->SetAnchorMode( eMode );
1182 EVAnchorMode OutlinerView::GetAnchorMode() const
1184 DBG_CHKTHIS(OutlinerView,0);
1185 return pEditView->GetAnchorMode();
1188 void OutlinerView::Copy()
1190 DBG_CHKTHIS(OutlinerView,0);
1191 pEditView->Copy();
1195 void OutlinerView::InsertField( const SvxFieldItem& rFld )
1197 DBG_CHKTHIS(OutlinerView,0);
1198 pEditView->InsertField( rFld );
1201 const SvxFieldItem* OutlinerView::GetFieldUnderMousePointer() const
1203 DBG_CHKTHIS(OutlinerView,0);
1204 return pEditView->GetFieldUnderMousePointer();
1207 const SvxFieldItem* OutlinerView::GetFieldAtSelection() const
1209 DBG_CHKTHIS(OutlinerView,0);
1210 return pEditView->GetFieldAtSelection();
1213 void OutlinerView::SetInvalidateMore( sal_uInt16 nPixel )
1215 DBG_CHKTHIS(OutlinerView,0);
1216 pEditView->SetInvalidateMore( nPixel );
1220 sal_uInt16 OutlinerView::GetInvalidateMore() const
1222 DBG_CHKTHIS(OutlinerView,0);
1223 return pEditView->GetInvalidateMore();
1227 sal_Bool OutlinerView::IsCursorAtWrongSpelledWord( sal_Bool bMarkIfWrong )
1229 DBG_CHKTHIS(OutlinerView,0);
1230 return pEditView->IsCursorAtWrongSpelledWord( bMarkIfWrong );
1234 sal_Bool OutlinerView::IsWrongSpelledWordAtPos( const Point& rPosPixel, sal_Bool bMarkIfWrong )
1236 DBG_CHKTHIS(OutlinerView,0);
1237 return pEditView->IsWrongSpelledWordAtPos( rPosPixel, bMarkIfWrong );
1240 void OutlinerView::ExecuteSpellPopup( const Point& rPosPixel, Link* pStartDlg )
1242 DBG_CHKTHIS(OutlinerView,0);
1243 pEditView->ExecuteSpellPopup( rPosPixel, pStartDlg );
1246 sal_uLong OutlinerView::Read( SvStream& rInput, const String& rBaseURL, EETextFormat eFormat, sal_Bool bSelect, SvKeyValueIterator* pHTTPHeaderAttrs )
1248 DBG_CHKTHIS(OutlinerView,0);
1249 sal_uInt16 nOldParaCount = pEditView->GetEditEngine()->GetParagraphCount();
1250 ESelection aOldSel = pEditView->GetSelection();
1251 aOldSel.Adjust();
1253 sal_uLong nRet = pEditView->Read( rInput, rBaseURL, eFormat, bSelect, pHTTPHeaderAttrs );
1255 long nParaDiff = pEditView->GetEditEngine()->GetParagraphCount() - nOldParaCount;
1256 sal_uInt16 nChangesStart = aOldSel.nStartPara;
1257 sal_uInt16 nChangesEnd = sal::static_int_cast< sal_uInt16 >(nChangesStart + nParaDiff + (aOldSel.nEndPara-aOldSel.nStartPara));
1259 for ( sal_uInt16 n = nChangesStart; n <= nChangesEnd; n++ )
1261 if ( eFormat == EE_FORMAT_BIN )
1263 sal_uInt16 nDepth = 0;
1264 const SfxItemSet& rAttrs = pOwner->GetParaAttribs( n );
1265 const SfxInt16Item& rLevel = (const SfxInt16Item&) rAttrs.Get( EE_PARA_OUTLLEVEL );
1266 nDepth = rLevel.GetValue();
1267 pOwner->ImplInitDepth( n, nDepth, sal_False );
1270 if ( pOwner->ImplGetOutlinerMode() == OUTLINERMODE_OUTLINEOBJECT )
1271 pOwner->ImplSetLevelDependendStyleSheet( n );
1274 if ( eFormat != EE_FORMAT_BIN )
1276 pOwner->ImpFilterIndents( nChangesStart, nChangesEnd );
1279 return nRet;
1282 void OutlinerView::SetBackgroundColor( const Color& rColor )
1284 DBG_CHKTHIS(OutlinerView,0);
1285 pEditView->SetBackgroundColor( rColor );
1289 Color OutlinerView::GetBackgroundColor()
1291 DBG_CHKTHIS(OutlinerView,0);
1292 return pEditView->GetBackgroundColor();
1295 SfxItemSet OutlinerView::GetAttribs()
1297 DBG_CHKTHIS(OutlinerView,0);
1298 return pEditView->GetAttribs();
1301 sal_uInt16 OutlinerView::GetSelectedScriptType() const
1303 DBG_CHKTHIS(OutlinerView,0);
1304 return pEditView->GetSelectedScriptType();
1307 String OutlinerView::GetSurroundingText() const
1309 DBG_CHKTHIS(OutlinerView,0);
1310 return pEditView->GetSurroundingText();
1313 Selection OutlinerView::GetSurroundingTextSelection() const
1315 DBG_CHKTHIS(OutlinerView,0);
1316 return pEditView->GetSurroundingTextSelection();
1320 // ======================================================================
1321 // ===== some code for thesaurus sub menu within context menu
1322 // ======================================================================
1324 // returns: true if a word for thesaurus look-up was found at the current cursor position.
1325 // The status string will be word + iso language string (e.g. "light#en-US")
1326 bool EDITENG_DLLPUBLIC GetStatusValueForThesaurusFromContext(
1327 String &rStatusVal,
1328 LanguageType &rLang,
1329 const EditView &rEditView )
1331 // get text and locale for thesaurus look up
1332 String aText;
1333 EditEngine *pEditEngine = rEditView.GetEditEngine();
1334 ESelection aTextSel( rEditView.GetSelection() );
1335 if (!aTextSel.HasRange())
1336 aTextSel = pEditEngine->GetWord( aTextSel, i18n::WordType::DICTIONARY_WORD );
1337 aText = pEditEngine->GetText( aTextSel );
1338 aTextSel.Adjust();
1339 LanguageType nLang = pEditEngine->GetLanguage( aTextSel.nStartPara, aTextSel.nStartPos );
1340 String aLangText( MsLangId::convertLanguageToIsoString( nLang ) );
1342 // set word and locale to look up as status value
1343 String aStatusVal( aText );
1344 aStatusVal.AppendAscii( "#" );
1345 aStatusVal += aLangText;
1347 rStatusVal = aStatusVal;
1348 rLang = nLang;
1350 return aText.Len() > 0;
1354 void EDITENG_DLLPUBLIC ReplaceTextWithSynonym( EditView &rEditView, const String &rSynonmText )
1356 // get selection to use
1357 ESelection aCurSel( rEditView.GetSelection() );
1358 if (!rEditView.HasSelection())
1360 // select the same word that was used in GetStatusValueForThesaurusFromContext by calling GetWord.
1361 // (In the end both functions will call ImpEditEngine::SelectWord)
1362 rEditView.SelectCurrentWord( i18n::WordType::DICTIONARY_WORD );
1363 aCurSel = rEditView.GetSelection();
1366 // replace word ...
1367 rEditView.InsertText( rSynonmText );
1368 rEditView.ShowCursor( sal_True, sal_False );
1372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */