Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name editeng.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D EDITENG_DLLIMPLEMENTATION -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/editeng/inc -I /home/maarten/src/libreoffice/core/editeng/source/editeng -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/editeng/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx

/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <memory>
21#include <utility>
22
23#include <comphelper/lok.hxx>
24#include <config_global.h>
25#include <vcl/weld.hxx>
26#include <vcl/svapp.hxx>
27
28#include <tools/stream.hxx>
29
30#include <editeng/svxfont.hxx>
31#include "impedit.hxx"
32#include <editeng/editeng.hxx>
33#include <editeng/editview.hxx>
34#include <editeng/editstat.hxx>
35#include <editeng/eerdll.hxx>
36#include <editeng/editrids.hrc>
37#include <editeng/flditem.hxx>
38#include <editeng/txtrange.hxx>
39#include <editeng/cmapitem.hxx>
40
41#include <editeng/autokernitem.hxx>
42#include <editeng/contouritem.hxx>
43#include <editeng/colritem.hxx>
44#include <editeng/crossedoutitem.hxx>
45#include <editeng/escapementitem.hxx>
46#include <editeng/fhgtitem.hxx>
47#include <editeng/fontitem.hxx>
48#include <editeng/kernitem.hxx>
49#include <editeng/lrspitem.hxx>
50#include <editeng/postitem.hxx>
51#include <editeng/shdditem.hxx>
52#include <editeng/udlnitem.hxx>
53#include <editeng/wghtitem.hxx>
54#include <editeng/wrlmitem.hxx>
55#include <editeng/langitem.hxx>
56#include <editeng/emphasismarkitem.hxx>
57#include <editeng/charscaleitem.hxx>
58#include <editeng/charreliefitem.hxx>
59
60#include <sot/exchange.hxx>
61#include <sot/formats.hxx>
62
63#include <editeng/numitem.hxx>
64#include <rtl/strbuf.hxx>
65#include <sal/log.hxx>
66#include <vcl/help.hxx>
67#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
68
69#if OSL_DEBUG_LEVEL1 > 1
70#include <editeng/frmdiritem.hxx>
71#endif
72#include <basegfx/polygon/b2dpolygon.hxx>
73
74using namespace ::com::sun::star;
75using namespace ::com::sun::star::uno;
76using namespace ::com::sun::star::linguistic2;
77
78
79#if (OSL_DEBUG_LEVEL1 > 1) || defined ( DBG_UTIL )
80static bool bDebugPaint = false;
81#endif
82
83static SfxItemPool* pGlobalPool=nullptr;
84
85EditEngine::EditEngine( SfxItemPool* pItemPool )
86{
87 pImpEditEngine.reset( new ImpEditEngine( this, pItemPool ) );
88}
89
90EditEngine::~EditEngine()
91{
92}
93
94void EditEngine::EnableUndo( bool bEnable )
95{
96 pImpEditEngine->EnableUndo( bEnable );
97}
98
99bool EditEngine::IsUndoEnabled() const
100{
101 return pImpEditEngine->IsUndoEnabled();
102}
103
104bool EditEngine::IsInUndo() const
105{
106 return pImpEditEngine->IsInUndo();
107}
108
109SfxUndoManager& EditEngine::GetUndoManager()
110{
111 return pImpEditEngine->GetUndoManager();
112}
113
114SfxUndoManager* EditEngine::SetUndoManager(SfxUndoManager* pNew)
115{
116 return pImpEditEngine->SetUndoManager(pNew);
117}
118
119void EditEngine::UndoActionStart( sal_uInt16 nId )
120{
121 DBG_ASSERT( !pImpEditEngine->IsInUndo(), "Calling UndoActionStart in Undomode!" )do { if (true && (!(!pImpEditEngine->IsInUndo())))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "121" ": "), "%s", "Calling UndoActionStart in Undomode!"
); } } while (false)
;
122 if ( !pImpEditEngine->IsInUndo() )
123 pImpEditEngine->UndoActionStart( nId );
124}
125
126void EditEngine::UndoActionStart(sal_uInt16 nId, const ESelection& rSel)
127{
128 pImpEditEngine->UndoActionStart(nId, rSel);
129}
130
131void EditEngine::UndoActionEnd()
132{
133 DBG_ASSERT( !pImpEditEngine->IsInUndo(), "Calling UndoActionEnd in Undomode!" )do { if (true && (!(!pImpEditEngine->IsInUndo())))
{ sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "133" ": "), "%s", "Calling UndoActionEnd in Undomode!")
; } } while (false)
;
134 if ( !pImpEditEngine->IsInUndo() )
135 pImpEditEngine->UndoActionEnd();
136}
137
138bool EditEngine::HasTriedMergeOnLastAddUndo() const
139{
140 return pImpEditEngine->mbLastTryMerge;
141}
142
143void EditEngine::SetRefDevice( OutputDevice* pRefDev )
144{
145 pImpEditEngine->SetRefDevice( pRefDev );
146}
147
148OutputDevice* EditEngine::GetRefDevice() const
149{
150 return pImpEditEngine->GetRefDevice();
151}
152
153void EditEngine::SetRefMapMode( const MapMode& rMapMode )
154{
155 pImpEditEngine->SetRefMapMode( rMapMode );
156}
157
158MapMode const & EditEngine::GetRefMapMode() const
159{
160 return pImpEditEngine->GetRefMapMode();
161}
162
163void EditEngine::SetBackgroundColor( const Color& rColor )
164{
165 pImpEditEngine->SetBackgroundColor( rColor );
166}
167
168Color const & EditEngine::GetBackgroundColor() const
169{
170 return pImpEditEngine->GetBackgroundColor();
171}
172
173Color EditEngine::GetAutoColor() const
174{
175 return pImpEditEngine->GetAutoColor();
176}
177
178void EditEngine::EnableAutoColor( bool b )
179{
180 pImpEditEngine->EnableAutoColor( b );
181}
182
183void EditEngine::ForceAutoColor( bool b )
184{
185 pImpEditEngine->ForceAutoColor( b );
186}
187
188bool EditEngine::IsForceAutoColor() const
189{
190 return pImpEditEngine->IsForceAutoColor();
191}
192
193const SfxItemSet& EditEngine::GetEmptyItemSet() const
194{
195 return pImpEditEngine->GetEmptyItemSet();
196}
197
198void EditEngine::Draw( OutputDevice* pOutDev, const tools::Rectangle& rOutRect )
199{
200 Draw( pOutDev, rOutRect, Point( 0, 0 ) );
201}
202
203void EditEngine::Draw( OutputDevice* pOutDev, const Point& rStartPos, short nOrientation )
204{
205 // Create with 2 points, as with positive points it will end up with
206 // LONGMAX as Size, Bottom and Right in the range > LONGMAX.
207 tools::Rectangle aBigRect( -0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF );
208 if( pOutDev->GetConnectMetaFile() )
209 pOutDev->Push();
210 Point aStartPos( rStartPos );
211 if ( IsVertical() )
212 {
213 aStartPos.AdjustX(GetPaperSize().Width() );
214 aStartPos = Rotate( aStartPos, nOrientation, rStartPos );
215 }
216 pImpEditEngine->Paint( pOutDev, aBigRect, aStartPos, false, nOrientation );
217 if( pOutDev->GetConnectMetaFile() )
218 pOutDev->Pop();
219}
220
221void EditEngine::Draw( OutputDevice* pOutDev, const tools::Rectangle& rOutRect, const Point& rStartDocPos )
222{
223 Draw( pOutDev, rOutRect, rStartDocPos, true );
224}
225
226void EditEngine::Draw( OutputDevice* pOutDev, const tools::Rectangle& rOutRect, const Point& rStartDocPos, bool bClip )
227{
228#if defined( DBG_UTIL ) || (OSL_DEBUG_LEVEL1 > 1)
229 if ( bDebugPaint )
230 DumpData(this, false);
231#endif
232
233 // Align to the pixel boundary, so that it becomes exactly the same
234 // as Paint ()
235 tools::Rectangle aOutRect( pOutDev->LogicToPixel( rOutRect ) );
236 aOutRect = pOutDev->PixelToLogic( aOutRect );
237
238 Point aStartPos;
239 if ( !IsVertical() )
240 {
241 aStartPos.setX( aOutRect.Left() - rStartDocPos.X() );
242 aStartPos.setY( aOutRect.Top() - rStartDocPos.Y() );
243 }
244 else
245 {
246 aStartPos.setX( aOutRect.Right() + rStartDocPos.Y() );
247 aStartPos.setY( aOutRect.Top() - rStartDocPos.X() );
248 }
249
250 bool bClipRegion = pOutDev->IsClipRegion();
251 bool bMetafile = pOutDev->GetConnectMetaFile();
252 vcl::Region aOldRegion = pOutDev->GetClipRegion();
253
254 // If one existed => intersection!
255 // Use Push/pop for creating the Meta file
256 if ( bMetafile )
257 pOutDev->Push();
258
259 // Always use the Intersect method, it is a must for Metafile!
260 if ( bClip )
261 {
262 // Clip only if necessary...
263 if ( rStartDocPos.X() || rStartDocPos.Y() ||
264 ( rOutRect.GetHeight() < static_cast<long>(GetTextHeight()) ) ||
265 ( rOutRect.GetWidth() < static_cast<long>(CalcTextWidth()) ) )
266 {
267 // Some printer drivers cause problems if characters graze the
268 // ClipRegion, therefore rather add a pixel more ...
269 tools::Rectangle aClipRect( aOutRect );
270 if ( pOutDev->GetOutDevType() == OUTDEV_PRINTER )
271 {
272 Size aPixSz( 1, 0 );
273 aPixSz = pOutDev->PixelToLogic( aPixSz );
274 aClipRect.AdjustRight(aPixSz.Width() );
275 aClipRect.AdjustBottom(aPixSz.Width() );
276 }
277 pOutDev->IntersectClipRegion( aClipRect );
278 }
279 }
280
281 pImpEditEngine->Paint( pOutDev, aOutRect, aStartPos );
282
283 if ( bMetafile )
284 pOutDev->Pop();
285 else if ( bClipRegion )
286 pOutDev->SetClipRegion( aOldRegion );
287 else
288 pOutDev->SetClipRegion();
289}
290
291void EditEngine::InsertView(EditView* pEditView, size_t nIndex)
292{
293
294 if ( nIndex > pImpEditEngine->GetEditViews().size() )
295 nIndex = pImpEditEngine->GetEditViews().size();
296
297 ImpEditEngine::ViewsType& rViews = pImpEditEngine->GetEditViews();
298 rViews.insert(rViews.begin()+nIndex, pEditView);
299
300 EditSelection aStartSel = pImpEditEngine->GetEditDoc().GetStartPaM();
301 pEditView->pImpEditView->SetEditSelection( aStartSel );
302 if ( !pImpEditEngine->GetActiveView() )
303 pImpEditEngine->SetActiveView( pEditView );
304
305 pEditView->pImpEditView->AddDragAndDropListeners();
306}
307
308EditView* EditEngine::RemoveView( EditView* pView )
309{
310
311 pView->HideCursor();
312 EditView* pRemoved = nullptr;
313 ImpEditEngine::ViewsType& rViews = pImpEditEngine->GetEditViews();
314 ImpEditEngine::ViewsType::iterator it = std::find(rViews.begin(), rViews.end(), pView);
315
316 DBG_ASSERT( it != rViews.end(), "RemoveView with invalid index" )do { if (true && (!(it != rViews.end()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "316" ": "), "%s", "RemoveView with invalid index"); } }
while (false)
;
317 if (it != rViews.end())
318 {
319 pRemoved = *it;
320 rViews.erase(it);
321 if ( pImpEditEngine->GetActiveView() == pView )
322 {
323 pImpEditEngine->SetActiveView( nullptr );
324 pImpEditEngine->GetSelEngine().SetCurView( nullptr );
325 }
326 pView->pImpEditView->RemoveDragAndDropListeners();
327
328 }
329 return pRemoved;
330}
331
332void EditEngine::RemoveView(size_t nIndex)
333{
334 ImpEditEngine::ViewsType& rViews = pImpEditEngine->GetEditViews();
335 if (nIndex >= rViews.size())
336 return;
337
338 EditView* pView = rViews[nIndex];
339 if ( pView )
340 RemoveView( pView );
341}
342
343EditView* EditEngine::GetView(size_t nIndex) const
344{
345 return pImpEditEngine->GetEditViews()[nIndex];
346}
347
348size_t EditEngine::GetViewCount() const
349{
350 return pImpEditEngine->GetEditViews().size();
351}
352
353bool EditEngine::HasView( EditView* pView ) const
354{
355 ImpEditEngine::ViewsType& rViews = pImpEditEngine->GetEditViews();
356 return std::find(rViews.begin(), rViews.end(), pView) != rViews.end();
357}
358
359EditView* EditEngine::GetActiveView() const
360{
361 return pImpEditEngine->GetActiveView();
362}
363
364void EditEngine::SetActiveView(EditView* pView)
365{
366 pImpEditEngine->SetActiveView(pView);
367}
368
369void EditEngine::SetDefTab( sal_uInt16 nDefTab )
370{
371 pImpEditEngine->GetEditDoc().SetDefTab( nDefTab );
372 if ( pImpEditEngine->IsFormatted() )
373 {
374 pImpEditEngine->FormatFullDoc();
375 pImpEditEngine->UpdateViews();
376 }
377}
378
379void EditEngine::SetPaperSize( const Size& rNewSize )
380{
381
382 Size aOldSize( pImpEditEngine->GetPaperSize() );
383 pImpEditEngine->SetValidPaperSize( rNewSize );
384 Size aNewSize( pImpEditEngine->GetPaperSize() );
385
386 bool bAutoPageSize = pImpEditEngine->GetStatus().AutoPageSize();
387 if ( !(bAutoPageSize || ( aNewSize.Width() != aOldSize.Width() )) )
388 return;
389
390 for (EditView* pView : pImpEditEngine->aEditViews)
391 {
392 if ( bAutoPageSize )
393 pView->pImpEditView->RecalcOutputArea();
394 else if ( pView->pImpEditView->DoAutoSize() )
395 {
396 pView->pImpEditView->ResetOutputArea( tools::Rectangle(
397 pView->pImpEditView->GetOutputArea().TopLeft(), aNewSize ) );
398 }
399 }
400
401 if ( bAutoPageSize || pImpEditEngine->IsFormatted() )
402 {
403 // Changing the width has no effect for AutoPageSize, as this is
404 // determined by the text width.
405 // Optimization first after Vobis delivery was enabled ...
406 pImpEditEngine->FormatFullDoc();
407
408 pImpEditEngine->UpdateViews( pImpEditEngine->GetActiveView() );
409
410 if ( pImpEditEngine->GetUpdateMode() && pImpEditEngine->GetActiveView() )
411 pImpEditEngine->pActiveView->ShowCursor( false, false );
412 }
413}
414
415const Size& EditEngine::GetPaperSize() const
416{
417 return pImpEditEngine->GetPaperSize();
418}
419
420void EditEngine::SetVertical(bool bVertical)
421{
422 pImpEditEngine->SetVertical(bVertical);
423}
424
425void EditEngine::SetRotation(TextRotation nRotation)
426{
427 pImpEditEngine->SetRotation(nRotation);
428}
429
430TextRotation EditEngine::GetRotation() const
431{
432 return pImpEditEngine->GetRotation();
433}
434
435bool EditEngine::IsVertical() const
436{
437 return pImpEditEngine->IsVertical();
438}
439
440bool EditEngine::IsTopToBottom() const
441{
442 return pImpEditEngine->IsTopToBottom();
443}
444
445bool EditEngine::GetDirectVertical() const
446{
447 return pImpEditEngine->GetDirectVertical();
448}
449
450void EditEngine::SetFixedCellHeight( bool bUseFixedCellHeight )
451{
452 pImpEditEngine->SetFixedCellHeight( bUseFixedCellHeight );
453}
454
455void EditEngine::SetDefaultHorizontalTextDirection( EEHorizontalTextDirection eHTextDir )
456{
457 pImpEditEngine->SetDefaultHorizontalTextDirection( eHTextDir );
458}
459
460EEHorizontalTextDirection EditEngine::GetDefaultHorizontalTextDirection() const
461{
462 return pImpEditEngine->GetDefaultHorizontalTextDirection();
463}
464
465SvtScriptType EditEngine::GetScriptType( const ESelection& rSelection ) const
466{
467 EditSelection aSel( pImpEditEngine->CreateSel( rSelection ) );
468 return pImpEditEngine->GetItemScriptType( aSel );
469}
470
471LanguageType EditEngine::GetLanguage(const EditPaM& rPaM) const
472{
473 return pImpEditEngine->GetLanguage(rPaM);
474}
475
476LanguageType EditEngine::GetLanguage( sal_Int32 nPara, sal_Int32 nPos ) const
477{
478 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
479 DBG_ASSERT( pNode, "GetLanguage - nPara is invalid!" )do { if (true && (!(pNode))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "479" ": "), "%s", "GetLanguage - nPara is invalid!"); }
} while (false)
;
480 return pNode ? pImpEditEngine->GetLanguage( EditPaM( pNode, nPos ) ) : LANGUAGE_DONTKNOWLanguageType(0x03FF);
481}
482
483
484void EditEngine::TransliterateText( const ESelection& rSelection, TransliterationFlags nTransliterationMode )
485{
486 pImpEditEngine->TransliterateText( pImpEditEngine->CreateSel( rSelection ), nTransliterationMode );
487}
488
489EditSelection EditEngine::TransliterateText(const EditSelection& rSelection, TransliterationFlags nTransliterationMode)
490{
491 return pImpEditEngine->TransliterateText(rSelection, nTransliterationMode);
492}
493
494void EditEngine::SetAsianCompressionMode( CharCompressType n )
495{
496 pImpEditEngine->SetAsianCompressionMode( n );
497}
498
499void EditEngine::SetKernAsianPunctuation( bool b )
500{
501 pImpEditEngine->SetKernAsianPunctuation( b );
502}
503
504void EditEngine::SetAddExtLeading( bool b )
505{
506 pImpEditEngine->SetAddExtLeading( b );
507}
508
509void EditEngine::SetPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon )
510{
511 SetPolygon( rPolyPolygon, nullptr );
512}
513
514void EditEngine::SetPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, const basegfx::B2DPolyPolygon* pLinePolyPolygon)
515{
516 bool bSimple(false);
517
518 if(pLinePolyPolygon && 1 == rPolyPolygon.count())
519 {
520 if(rPolyPolygon.getB2DPolygon(0).isClosed())
521 {
522 // open polygon
523 bSimple = true;
524 }
525 }
526
527 TextRanger* pRanger = new TextRanger( rPolyPolygon, pLinePolyPolygon, 30, 2, 2, bSimple, true );
528 pImpEditEngine->SetTextRanger( std::unique_ptr<TextRanger>(pRanger) );
529 pImpEditEngine->SetPaperSize( pRanger->GetBoundRect().GetSize() );
530}
531
532void EditEngine::ClearPolygon()
533{
534 pImpEditEngine->SetTextRanger( nullptr );
535}
536
537const Size& EditEngine::GetMinAutoPaperSize() const
538{
539 return pImpEditEngine->GetMinAutoPaperSize();
540}
541
542void EditEngine::SetMinAutoPaperSize( const Size& rSz )
543{
544 pImpEditEngine->SetMinAutoPaperSize( rSz );
545}
546
547const Size& EditEngine::GetMaxAutoPaperSize() const
548{
549 return pImpEditEngine->GetMaxAutoPaperSize();
550}
551
552void EditEngine::SetMaxAutoPaperSize( const Size& rSz )
553{
554 pImpEditEngine->SetMaxAutoPaperSize( rSz );
555}
556
557OUString EditEngine::GetText( LineEnd eEnd ) const
558{
559 return pImpEditEngine->GetEditDoc().GetText( eEnd );
560}
561
562OUString EditEngine::GetText( const ESelection& rESelection ) const
563{
564 EditSelection aSel( pImpEditEngine->CreateSel( rESelection ) );
565 return pImpEditEngine->GetSelected( aSel );
566}
567
568sal_uInt32 EditEngine::GetTextLen() const
569{
570 return pImpEditEngine->GetEditDoc().GetTextLen();
571}
572
573sal_Int32 EditEngine::GetParagraphCount() const
574{
575 return pImpEditEngine->aEditDoc.Count();
576}
577
578sal_Int32 EditEngine::GetLineCount( sal_Int32 nParagraph ) const
579{
580 if ( !pImpEditEngine->IsFormatted() )
581 pImpEditEngine->FormatDoc();
582 return pImpEditEngine->GetLineCount( nParagraph );
583}
584
585sal_Int32 EditEngine::GetLineLen( sal_Int32 nParagraph, sal_Int32 nLine ) const
586{
587 if ( !pImpEditEngine->IsFormatted() )
588 pImpEditEngine->FormatDoc();
589 return pImpEditEngine->GetLineLen( nParagraph, nLine );
590}
591
592void EditEngine::GetLineBoundaries( /*out*/sal_Int32& rStart, /*out*/sal_Int32& rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const
593{
594 if ( !pImpEditEngine->IsFormatted() )
595 pImpEditEngine->FormatDoc();
596 return pImpEditEngine->GetLineBoundaries( rStart, rEnd, nParagraph, nLine );
597}
598
599sal_Int32 EditEngine::GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const
600{
601 if ( !pImpEditEngine->IsFormatted() )
602 pImpEditEngine->FormatDoc();
603 return pImpEditEngine->GetLineNumberAtIndex( nPara, nIndex );
604}
605
606sal_uInt32 EditEngine::GetLineHeight( sal_Int32 nParagraph )
607{
608 // If someone calls GetLineHeight() with an empty Engine.
609 if ( !pImpEditEngine->IsFormatted() )
610 pImpEditEngine->FormatDoc();
611 return pImpEditEngine->GetLineHeight( nParagraph, 0 );
612}
613
614tools::Rectangle EditEngine::GetParaBounds( sal_Int32 nPara )
615{
616 if ( !pImpEditEngine->IsFormatted() )
617 pImpEditEngine->FormatDoc();
618
619 Point aPnt = GetDocPosTopLeft( nPara );
620
621 if( IsVertical() )
622 {
623 sal_Int32 nTextHeight = pImpEditEngine->GetTextHeight();
624 sal_Int32 nParaWidth = pImpEditEngine->CalcParaWidth( nPara, true );
625 sal_uLong nParaHeight = pImpEditEngine->GetParaHeight( nPara );
626
627 return tools::Rectangle( nTextHeight - aPnt.Y() - nParaHeight, 0, nTextHeight - aPnt.Y(), nParaWidth );
628 }
629 else
630 {
631 sal_Int32 nParaWidth = pImpEditEngine->CalcParaWidth( nPara, true );
632 sal_uLong nParaHeight = pImpEditEngine->GetParaHeight( nPara );
633
634 return tools::Rectangle( 0, aPnt.Y(), nParaWidth, aPnt.Y() + nParaHeight );
635 }
636}
637
638sal_uInt32 EditEngine::GetTextHeight( sal_Int32 nParagraph ) const
639{
640 if ( !pImpEditEngine->IsFormatted() )
641 pImpEditEngine->FormatDoc();
642
643 sal_uInt32 nHeight = pImpEditEngine->GetParaHeight( nParagraph );
644 return nHeight;
645}
646
647OUString EditEngine::GetWord( sal_Int32 nPara, sal_Int32 nIndex )
648{
649 ESelection aESel( nPara, nIndex, nPara, nIndex );
650 EditSelection aSel( pImpEditEngine->CreateSel( aESel ) );
651 aSel = pImpEditEngine->SelectWord( aSel );
652 return pImpEditEngine->GetSelected( aSel );
653}
654
655ESelection EditEngine::GetWord( const ESelection& rSelection, sal_uInt16 nWordType ) const
656{
657 // ImpEditEngine-Iteration-Methods should be const!
658 EditEngine* pE = const_cast<EditEngine*>(this);
659
660 EditSelection aSel( pE->pImpEditEngine->CreateSel( rSelection ) );
661 aSel = pE->pImpEditEngine->SelectWord( aSel, nWordType );
662 return pE->pImpEditEngine->CreateESel( aSel );
663}
664
665void EditEngine::CursorMoved(const ContentNode* pPrevNode)
666{
667 pImpEditEngine->CursorMoved(pPrevNode);
668}
669
670void EditEngine::CheckIdleFormatter()
671{
672 pImpEditEngine->CheckIdleFormatter();
673}
674
675bool EditEngine::IsIdleFormatterActive() const
676{
677 return pImpEditEngine->aIdleFormatter.IsActive();
678}
679
680ParaPortion* EditEngine::FindParaPortion(ContentNode const * pNode)
681{
682 return pImpEditEngine->FindParaPortion(pNode);
683}
684
685const ParaPortion* EditEngine::FindParaPortion(ContentNode const * pNode) const
686{
687 return pImpEditEngine->FindParaPortion(pNode);
688}
689
690const ParaPortion* EditEngine::GetPrevVisPortion(const ParaPortion* pCurPortion) const
691{
692 return pImpEditEngine->GetPrevVisPortion(pCurPortion);
693}
694
695SvtScriptType EditEngine::GetScriptType(const EditSelection& rSel) const
696{
697 return pImpEditEngine->GetItemScriptType(rSel);
698}
699
700void EditEngine::RemoveParaPortion(sal_Int32 nNode)
701{
702 pImpEditEngine->GetParaPortions().Remove(nNode);
703}
704
705void EditEngine::SetCallParaInsertedOrDeleted(bool b)
706{
707 pImpEditEngine->SetCallParaInsertedOrDeleted(b);
708}
709
710bool EditEngine::IsCallParaInsertedOrDeleted() const
711{
712 return pImpEditEngine->IsCallParaInsertedOrDeleted();
713}
714
715void EditEngine::AppendDeletedNodeInfo(DeletedNodeInfo* pInfo)
716{
717 pImpEditEngine->aDeletedNodes.push_back(std::unique_ptr<DeletedNodeInfo>(pInfo));
718}
719
720void EditEngine::UpdateSelections()
721{
722 pImpEditEngine->UpdateSelections();
723}
724
725void EditEngine::InsertContent(ContentNode* pNode, sal_Int32 nPos)
726{
727 pImpEditEngine->InsertContent(pNode, nPos);
728}
729
730EditPaM EditEngine::SplitContent(sal_Int32 nNode, sal_Int32 nSepPos)
731{
732 return pImpEditEngine->SplitContent(nNode, nSepPos);
733}
734
735EditPaM EditEngine::ConnectContents(sal_Int32 nLeftNode, bool bBackward)
736{
737 return pImpEditEngine->ConnectContents(nLeftNode, bBackward);
738}
739
740void EditEngine::InsertFeature(const EditSelection& rEditSelection, const SfxPoolItem& rItem)
741{
742 pImpEditEngine->ImpInsertFeature(rEditSelection, rItem);
743}
744
745EditSelection EditEngine::MoveParagraphs(const Range& rParagraphs, sal_Int32 nNewPos)
746{
747 return pImpEditEngine->MoveParagraphs(rParagraphs, nNewPos, nullptr);
748}
749
750void EditEngine::RemoveCharAttribs(sal_Int32 nPara, sal_uInt16 nWhich, bool bRemoveFeatures)
751{
752 pImpEditEngine->RemoveCharAttribs(nPara, nWhich, bRemoveFeatures);
753}
754
755void EditEngine::RemoveCharAttribs(const EditSelection& rSel, bool bRemoveParaAttribs, sal_uInt16 nWhich)
756{
757 pImpEditEngine->RemoveCharAttribs(rSel, bRemoveParaAttribs, nWhich);
758}
759
760EditEngine::ViewsType& EditEngine::GetEditViews()
761{
762 return pImpEditEngine->GetEditViews();
763}
764
765const EditEngine::ViewsType& EditEngine::GetEditViews() const
766{
767 return pImpEditEngine->GetEditViews();
768}
769
770void EditEngine::SetUndoMode(bool b)
771{
772 pImpEditEngine->SetUndoMode(b);
773}
774
775void EditEngine::FormatAndUpdate(EditView* pCurView, bool bCalledFromUndo)
776{
777 pImpEditEngine->FormatAndUpdate(pCurView, bCalledFromUndo);
778}
779
780void EditEngine::Undo(EditView* pView)
781{
782 pImpEditEngine->Undo(pView);
783}
784
785void EditEngine::Redo(EditView* pView)
786{
787 pImpEditEngine->Redo(pView);
788}
789
790uno::Reference<datatransfer::XTransferable> EditEngine::CreateTransferable(const EditSelection& rSelection)
791{
792 return pImpEditEngine->CreateTransferable(rSelection);
793}
794
795void EditEngine::ParaAttribsToCharAttribs(ContentNode* pNode)
796{
797 pImpEditEngine->ParaAttribsToCharAttribs(pNode);
798}
799
800EditPaM EditEngine::CreateEditPaM(const EPaM& rEPaM)
801{
802 return pImpEditEngine->CreateEditPaM(rEPaM);
803}
804
805EditPaM EditEngine::ConnectParagraphs(
806 ContentNode* pLeft, ContentNode* pRight, bool bBackward)
807{
808 return pImpEditEngine->ImpConnectParagraphs(pLeft, pRight, bBackward);
809}
810
811EditPaM EditEngine::InsertField(const EditSelection& rEditSelection, const SvxFieldItem& rFld)
812{
813 return pImpEditEngine->InsertField(rEditSelection, rFld);
814}
815
816EditPaM EditEngine::InsertText(const EditSelection& aCurEditSelection, const OUString& rStr)
817{
818 return pImpEditEngine->InsertText(aCurEditSelection, rStr);
819}
820
821EditSelection EditEngine::InsertText(const EditTextObject& rTextObject, const EditSelection& rSel)
822{
823 return pImpEditEngine->InsertText(rTextObject, rSel);
824}
825
826EditSelection EditEngine::InsertText(
827 uno::Reference<datatransfer::XTransferable > const & rxDataObj,
828 const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial)
829{
830 return pImpEditEngine->PasteText(rxDataObj, rBaseURL, rPaM, bUseSpecial);
831}
832
833EditPaM EditEngine::EndOfWord(const EditPaM& rPaM)
834{
835 return pImpEditEngine->EndOfWord(rPaM);
836}
837
838EditPaM EditEngine::GetPaM(const Point& aDocPos, bool bSmart)
839{
840 return pImpEditEngine->GetPaM(aDocPos, bSmart);
841}
842
843EditSelection EditEngine::SelectWord(
844 const EditSelection& rCurSelection, sal_Int16 nWordType)
845{
846 return pImpEditEngine->SelectWord(rCurSelection, nWordType);
847}
848
849long EditEngine::GetXPos(
850 const ParaPortion* pParaPortion, const EditLine* pLine, sal_Int32 nIndex, bool bPreferPortionStart) const
851{
852 return pImpEditEngine->GetXPos(pParaPortion, pLine, nIndex, bPreferPortionStart);
853}
854
855Range EditEngine::GetLineXPosStartEnd(
856 const ParaPortion* pParaPortion, const EditLine* pLine) const
857{
858 return pImpEditEngine->GetLineXPosStartEnd(pParaPortion, pLine);
859}
860
861bool EditEngine::IsFormatted() const
862{
863 return pImpEditEngine->IsFormatted();
864}
865
866EditPaM EditEngine::CursorLeft(const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode)
867{
868 return pImpEditEngine->CursorLeft(rPaM, nCharacterIteratorMode);
869}
870
871EditPaM EditEngine::CursorRight(const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode)
872{
873 return pImpEditEngine->CursorRight(rPaM, nCharacterIteratorMode);
874}
875
876InternalEditStatus& EditEngine::GetInternalEditStatus()
877{
878 return pImpEditEngine->GetStatus();
879}
880
881EditDoc& EditEngine::GetEditDoc()
882{
883 return pImpEditEngine->GetEditDoc();
884}
885
886const EditDoc& EditEngine::GetEditDoc() const
887{
888 return pImpEditEngine->GetEditDoc();
889}
890
891void EditEngine::dumpAsXmlEditDoc(xmlTextWriterPtr pWriter) const
892{
893 pImpEditEngine->GetEditDoc().dumpAsXml(pWriter);
894}
895
896ParaPortionList& EditEngine::GetParaPortions()
897{
898 return pImpEditEngine->GetParaPortions();
899}
900
901const ParaPortionList& EditEngine::GetParaPortions() const
902{
903 return pImpEditEngine->GetParaPortions();
904}
905
906void EditEngine::SeekCursor(ContentNode* pNode, sal_Int32 nPos, SvxFont& rFont)
907{
908 pImpEditEngine->SeekCursor(pNode, nPos, rFont);
909}
910
911EditPaM EditEngine::DeleteSelection(const EditSelection& rSel)
912{
913 return pImpEditEngine->ImpDeleteSelection(rSel);
914}
915
916ESelection EditEngine::CreateESelection(const EditSelection& rSel)
917{
918 return pImpEditEngine->CreateESel(rSel);
919}
920
921EditSelection EditEngine::CreateSelection(const ESelection& rSel)
922{
923 return pImpEditEngine->CreateSel(rSel);
924}
925
926const SfxItemSet& EditEngine::GetBaseParaAttribs(sal_Int32 nPara) const
927{
928 return pImpEditEngine->GetParaAttribs(nPara);
929}
930
931void EditEngine::SetParaAttribsOnly(sal_Int32 nPara, const SfxItemSet& rSet)
932{
933 pImpEditEngine->SetParaAttribs(nPara, rSet);
934}
935
936void EditEngine::SetAttribs(const EditSelection& rSel, const SfxItemSet& rSet, SetAttribsMode nSpecial)
937{
938 pImpEditEngine->SetAttribs(rSel, rSet, nSpecial);
939}
940
941OUString EditEngine::GetSelected(const EditSelection& rSel) const
942{
943 return pImpEditEngine->GetSelected(rSel);
944}
945
946EditPaM EditEngine::DeleteSelected(const EditSelection& rSel)
947{
948 return pImpEditEngine->DeleteSelected(rSel);
949}
950
951void EditEngine::HandleBeginPasteOrDrop(PasteOrDropInfos& rInfos)
952{
953 pImpEditEngine->aBeginPasteOrDropHdl.Call(rInfos);
954}
955
956void EditEngine::HandleEndPasteOrDrop(PasteOrDropInfos& rInfos)
957{
958 pImpEditEngine->aEndPasteOrDropHdl.Call(rInfos);
959}
960
961bool EditEngine::HasText() const
962{
963 return pImpEditEngine->ImplHasText();
964}
965
966const EditSelectionEngine& EditEngine::GetSelectionEngine() const
967{
968 return pImpEditEngine->aSelEngine;
969}
970
971void EditEngine::SetInSelectionMode(bool b)
972{
973 pImpEditEngine->bInSelection = b;
974}
975
976bool EditEngine::PostKeyEvent( const KeyEvent& rKeyEvent, EditView* pEditView, vcl::Window const * pFrameWin )
977{
978 DBG_ASSERT( pEditView, "no View - no cookie !" )do { if (true && (!(pEditView))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "978" ": "), "%s", "no View - no cookie !"); } } while (
false)
;
979
980 bool bDone = true;
981
982 bool bModified = false;
983 bool bMoved = false;
984 bool bAllowIdle = true;
985 bool bReadOnly = pEditView->IsReadOnly();
986
987 GetCursorFlags nNewCursorFlags = GetCursorFlags::NONE;
988 bool bSetCursorFlags = true;
989
990 EditSelection aCurSel( pEditView->pImpEditView->GetEditSelection() );
991 DBG_ASSERT( !aCurSel.IsInvalid(), "Blinde Selection in EditEngine::PostKeyEvent" )do { if (true && (!(!aCurSel.IsInvalid()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "991" ": "), "%s", "Blinde Selection in EditEngine::PostKeyEvent"
); } } while (false)
;
992
993 OUString aAutoText( pImpEditEngine->GetAutoCompleteText() );
994 if (!pImpEditEngine->GetAutoCompleteText().isEmpty())
995 pImpEditEngine->SetAutoCompleteText(OUString(), true);
996
997 sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode();
998 KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
999 if ( eFunc != KeyFuncType::DONTKNOW )
1000 {
1001 switch ( eFunc )
1002 {
1003 case KeyFuncType::UNDO:
1004 {
1005 if ( !bReadOnly )
1006 pEditView->Undo();
1007 return true;
1008 }
1009 case KeyFuncType::REDO:
1010 {
1011 if ( !bReadOnly )
1012 pEditView->Redo();
1013 return true;
1014 }
1015
1016 default: // is then possible edited below.
1017 eFunc = KeyFuncType::DONTKNOW;
1018 }
1019 }
1020
1021 if ( eFunc == KeyFuncType::DONTKNOW )
1022 {
1023 switch ( nCode )
1024 {
1025#if defined( DBG_UTIL ) || (OSL_DEBUG_LEVEL1 > 1)
1026 case KEY_F1:
1027 {
1028 if ( rKeyEvent.GetKeyCode().IsMod1() && rKeyEvent.GetKeyCode().IsMod2() )
1029 {
1030 sal_Int32 nParas = GetParagraphCount();
1031 Point aPos;
1032 Point aViewStart( pEditView->GetOutputArea().TopLeft() );
1033 long n20 = 40 * pImpEditEngine->nOnePixelInRef;
1034 for ( sal_Int32 n = 0; n < nParas; n++ )
1035 {
1036 long nH = GetTextHeight( n );
1037 Point P1( aViewStart.X() + n20 + n20*(n%2), aViewStart.Y() + aPos.Y() );
1038 Point P2( P1 );
1039 P2.AdjustX(n20 );
1040 P2.AdjustY(nH );
1041 pEditView->GetWindow()->SetLineColor();
1042 pEditView->GetWindow()->SetFillColor( (n%2) ? COL_YELLOW : COL_LIGHTGREEN );
1043 pEditView->GetWindow()->DrawRect( tools::Rectangle( P1, P2 ) );
1044 aPos.AdjustY(nH );
1045 }
1046 }
1047 bDone = false;
1048 }
1049 break;
1050 case KEY_F11:
1051 {
1052 if ( rKeyEvent.GetKeyCode().IsMod1() && rKeyEvent.GetKeyCode().IsMod2() )
1053 {
1054 bDebugPaint = !bDebugPaint;
1055 OStringBuffer aInfo("DebugPaint: ");
1056 aInfo.append(bDebugPaint ? "On" : "Off");
1057 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pEditView->GetWindow()->GetFrameWeld(),
1058 VclMessageType::Info, VclButtonsType::Ok,
1059 OStringToOUString(aInfo.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)))));
1060 xInfoBox->run();
1061
1062 }
1063 bDone = false;
1064 }
1065 break;
1066 case KEY_F12:
1067 {
1068 if ( rKeyEvent.GetKeyCode().IsMod1() && rKeyEvent.GetKeyCode().IsMod2() )
1069 DumpData(this, true);
1070 bDone = false;
1071 }
1072 break;
1073#endif
1074 case KEY_UP:
1075 case KEY_DOWN:
1076 case KEY_LEFT:
1077 case KEY_RIGHT:
1078 case KEY_HOME:
1079 case KEY_END:
1080 case KEY_PAGEUP:
1081 case KEY_PAGEDOWN:
1082 case css::awt::Key::MOVE_WORD_FORWARD:
1083 case css::awt::Key::SELECT_WORD_FORWARD:
1084 case css::awt::Key::MOVE_WORD_BACKWARD:
1085 case css::awt::Key::SELECT_WORD_BACKWARD:
1086 case css::awt::Key::MOVE_TO_BEGIN_OF_LINE:
1087 case css::awt::Key::MOVE_TO_END_OF_LINE:
1088 case css::awt::Key::SELECT_TO_BEGIN_OF_LINE:
1089 case css::awt::Key::SELECT_TO_END_OF_LINE:
1090 case css::awt::Key::MOVE_TO_BEGIN_OF_PARAGRAPH:
1091 case css::awt::Key::MOVE_TO_END_OF_PARAGRAPH:
1092 case css::awt::Key::SELECT_TO_BEGIN_OF_PARAGRAPH:
1093 case css::awt::Key::SELECT_TO_END_OF_PARAGRAPH:
1094 case css::awt::Key::MOVE_TO_BEGIN_OF_DOCUMENT:
1095 case css::awt::Key::MOVE_TO_END_OF_DOCUMENT:
1096 case css::awt::Key::SELECT_TO_BEGIN_OF_DOCUMENT:
1097 case css::awt::Key::SELECT_TO_END_OF_DOCUMENT:
1098 {
1099 if ( !rKeyEvent.GetKeyCode().IsMod2() || ( nCode == KEY_LEFT ) || ( nCode == KEY_RIGHT ) )
1100 {
1101 if ( pImpEditEngine->DoVisualCursorTraveling() && ( ( nCode == KEY_LEFT ) || ( nCode == KEY_RIGHT ) /* || ( nCode == KEY_HOME ) || ( nCode == KEY_END ) */ ) )
1102 bSetCursorFlags = false; // Will be manipulated within visual cursor move
1103
1104 aCurSel = pImpEditEngine->MoveCursor( rKeyEvent, pEditView );
1105
1106 if ( aCurSel.HasRange() ) {
1107 if (vcl::Window* pWindow = pEditView->GetWindow()) {
1108 Reference<css::datatransfer::clipboard::XClipboard> aSelection(pWindow->GetPrimarySelection());
1109 pEditView->pImpEditView->CutCopy( aSelection, false );
1110 }
1111 }
1112
1113 bMoved = true;
1114 if ( nCode == KEY_HOME )
1115 nNewCursorFlags |= GetCursorFlags::StartOfLine;
1116 else if ( nCode == KEY_END )
1117 nNewCursorFlags |= GetCursorFlags::EndOfLine;
1118
1119 }
1120#if OSL_DEBUG_LEVEL1 > 1
1121 GetLanguage( pImpEditEngine->GetEditDoc().GetPos( aCurSel.Max().GetNode() ), aCurSel.Max().GetIndex() );
1122#endif
1123 }
1124 break;
1125 case KEY_BACKSPACE:
1126 case KEY_DELETE:
1127 case css::awt::Key::DELETE_WORD_BACKWARD:
1128 case css::awt::Key::DELETE_WORD_FORWARD:
1129 case css::awt::Key::DELETE_TO_BEGIN_OF_PARAGRAPH:
1130 case css::awt::Key::DELETE_TO_END_OF_PARAGRAPH:
1131 {
1132 if ( !bReadOnly && !rKeyEvent.GetKeyCode().IsMod2() )
1133 {
1134 // check if we are behind a bullet and using the backspace key
1135 ContentNode *pNode = aCurSel.Min().GetNode();
1136 const SvxNumberFormat *pFmt = pImpEditEngine->GetNumberFormat( pNode );
1137 if (pFmt && nCode == KEY_BACKSPACE &&
1138 !aCurSel.HasRange() && aCurSel.Min().GetIndex() == 0)
1139 {
1140 // if the bullet is still visible, just make it invisible.
1141 // Otherwise continue as usual.
1142
1143
1144 sal_Int32 nPara = pImpEditEngine->GetEditDoc().GetPos( pNode );
1145 SfxBoolItem aBulletState( pImpEditEngine->GetParaAttrib( nPara, EE_PARA_BULLETSTATE ) );
1146
1147 if ( aBulletState.GetValue() )
1148 {
1149
1150 aBulletState.SetValue( false );
1151 SfxItemSet aSet( pImpEditEngine->GetParaAttribs( nPara ) );
1152 aSet.Put( aBulletState );
1153 pImpEditEngine->SetParaAttribs( nPara, aSet );
1154
1155 // have this and the following paragraphs formatted and repainted.
1156 // (not painting a numbering in the list may cause the following
1157 // numberings to have different numbers than before and thus the
1158 // length may have changed as well )
1159 pImpEditEngine->FormatAndUpdate( pImpEditEngine->GetActiveView() );
1160
1161 break;
1162 }
1163 }
1164
1165 sal_uInt8 nDel = 0;
1166 DeleteMode nMode = DeleteMode::Simple;
1167 switch( nCode )
1168 {
1169 case css::awt::Key::DELETE_WORD_BACKWARD:
1170 nMode = DeleteMode::RestOfWord;
1171 nDel = DEL_LEFT1;
1172 break;
1173 case css::awt::Key::DELETE_WORD_FORWARD:
1174 nMode = DeleteMode::RestOfWord;
1175 nDel = DEL_RIGHT2;
1176 break;
1177 case css::awt::Key::DELETE_TO_BEGIN_OF_PARAGRAPH:
1178 nMode = DeleteMode::RestOfContent;
1179 nDel = DEL_LEFT1;
1180 break;
1181 case css::awt::Key::DELETE_TO_END_OF_PARAGRAPH:
1182 nMode = DeleteMode::RestOfContent;
1183 nDel = DEL_RIGHT2;
1184 break;
1185 default:
1186 nDel = ( nCode == KEY_DELETE ) ? DEL_RIGHT2 : DEL_LEFT1;
1187 nMode = rKeyEvent.GetKeyCode().IsMod1() ? DeleteMode::RestOfWord : DeleteMode::Simple;
1188 if ( ( nMode == DeleteMode::RestOfWord ) && rKeyEvent.GetKeyCode().IsShift() )
1189 nMode = DeleteMode::RestOfContent;
1190 break;
1191 }
1192
1193 pEditView->pImpEditView->DrawSelectionXOR();
1194 pImpEditEngine->UndoActionStart( EDITUNDO_DELETE108 );
1195 aCurSel = pImpEditEngine->DeleteLeftOrRight( aCurSel, nDel, nMode );
1196 pImpEditEngine->UndoActionEnd();
1197 bModified = true;
1198 bAllowIdle = false;
1199 }
1200 }
1201 break;
1202 case KEY_TAB:
1203 {
1204 if ( !bReadOnly && !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() )
1205 {
1206 bool bShift = rKeyEvent.GetKeyCode().IsShift();
1207 if ( !bShift )
1208 {
1209 bool bSel = pEditView->HasSelection();
1210 if ( bSel )
1211 pImpEditEngine->UndoActionStart( EDITUNDO_INSERT111 );
1212 if ( pImpEditEngine->GetStatus().DoAutoCorrect() )
1213 aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin );
1214 aCurSel = pImpEditEngine->InsertTab( aCurSel );
1215 if ( bSel )
1216 pImpEditEngine->UndoActionEnd();
1217 bModified = true;
1218 }
1219 }
1220 else
1221 bDone = false;
1222 }
1223 break;
1224 case KEY_RETURN:
1225 {
1226 if ( !bReadOnly )
1227 {
1228 pEditView->pImpEditView->DrawSelectionXOR();
1229 if ( !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() )
1230 {
1231 pImpEditEngine->UndoActionStart( EDITUNDO_INSERT111 );
1232 if ( rKeyEvent.GetKeyCode().IsShift() )
1233 {
1234 aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin );
1235 aCurSel = pImpEditEngine->InsertLineBreak( aCurSel );
1236 }
1237 else
1238 {
1239 if (aAutoText.isEmpty())
1240 {
1241 if ( pImpEditEngine->GetStatus().DoAutoCorrect() )
1242 aCurSel = pImpEditEngine->AutoCorrect( aCurSel, 0, !pEditView->IsInsertMode(), pFrameWin );
1243 aCurSel = pImpEditEngine->InsertParaBreak( aCurSel );
1244 }
1245 else
1246 {
1247 DBG_ASSERT( !aCurSel.HasRange(), "Selection on complete?!" )do { if (true && (!(!aCurSel.HasRange()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1247" ": "), "%s", "Selection on complete?!"); } } while
(false)
;
1248 EditPaM aStart( pImpEditEngine->WordLeft( aCurSel.Max() ) );
1249 aCurSel = pImpEditEngine->InsertText(
1250 EditSelection( aStart, aCurSel.Max() ), aAutoText );
1251 pImpEditEngine->SetAutoCompleteText( OUString(), true );
1252 }
1253 }
1254 pImpEditEngine->UndoActionEnd();
1255 bModified = true;
1256 }
1257 }
1258 }
1259 break;
1260 case KEY_INSERT:
1261 {
1262 if ( !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() )
1263 pEditView->SetInsertMode( !pEditView->IsInsertMode() );
1264 }
1265 break;
1266 default:
1267 {
1268 #if (OSL_DEBUG_LEVEL1 > 1) && defined(DBG_UTIL)
1269 if ( ( nCode == KEY_W ) && rKeyEvent.GetKeyCode().IsMod1() && rKeyEvent.GetKeyCode().IsMod2() )
1270 {
1271 SfxItemSet aAttribs = pEditView->GetAttribs();
1272 const SvxFrameDirectionItem& rCurrentWritingMode = (const SvxFrameDirectionItem&)aAttribs.Get( EE_PARA_WRITINGDIR );
1273 SvxFrameDirectionItem aNewItem( SvxFrameDirection::Horizontal_LR_TB, EE_PARA_WRITINGDIR );
1274 if ( rCurrentWritingMode.GetValue() != SvxFrameDirection::Horizontal_RL_TB )
1275 aNewItem.SetValue( SvxFrameDirection::Horizontal_RL_TB );
1276 aAttribs.Put( aNewItem );
1277 pEditView->SetAttribs( aAttribs );
1278 }
1279 #endif
1280 if ( !bReadOnly && IsSimpleCharInput( rKeyEvent ) )
1281 {
1282 sal_Unicode nCharCode = rKeyEvent.GetCharCode();
1283 pEditView->pImpEditView->DrawSelectionXOR();
1284 // Autocorrection?
1285 if ( ( pImpEditEngine->GetStatus().DoAutoCorrect() ) &&
1286 ( SvxAutoCorrect::IsAutoCorrectChar( nCharCode ) ||
1287 pImpEditEngine->IsNbspRunNext() ) )
1288 {
1289 aCurSel = pImpEditEngine->AutoCorrect(
1290 aCurSel, nCharCode, !pEditView->IsInsertMode(), pFrameWin );
1291 }
1292 else
1293 {
1294 aCurSel = pImpEditEngine->InsertTextUserInput( aCurSel, nCharCode, !pEditView->IsInsertMode() );
1295 }
1296 // AutoComplete ???
1297 if ( pImpEditEngine->GetStatus().DoAutoComplete() && ( nCharCode != ' ' ) )
1298 {
1299 // Only at end of word...
1300 sal_Int32 nIndex = aCurSel.Max().GetIndex();
1301 if ( ( nIndex >= aCurSel.Max().GetNode()->Len() ) ||
1302 ( pImpEditEngine->aWordDelimiters.indexOf( aCurSel.Max().GetNode()->GetChar( nIndex ) ) != -1 ) )
1303 {
1304 EditPaM aStart( pImpEditEngine->WordLeft( aCurSel.Max() ) );
1305 OUString aWord = pImpEditEngine->GetSelected( EditSelection( aStart, aCurSel.Max() ) );
1306 if ( aWord.getLength() >= 3 )
1307 {
1308 OUString aComplete;
1309
1310 LanguageType eLang = pImpEditEngine->GetLanguage( EditPaM( aStart.GetNode(), aStart.GetIndex()+1));
1311 LanguageTag aLanguageTag( eLang);
1312
1313 if (!pImpEditEngine->xLocaleDataWrapper.isInitialized())
1314 pImpEditEngine->xLocaleDataWrapper.init( SvtSysLocale().GetLocaleData().getComponentContext(), aLanguageTag);
1315 else
1316 pImpEditEngine->xLocaleDataWrapper.changeLocale( aLanguageTag);
1317
1318 if (!pImpEditEngine->xTransliterationWrapper.isInitialized())
1319 pImpEditEngine->xTransliterationWrapper.init( SvtSysLocale().GetLocaleData().getComponentContext(), eLang);
1320 else
1321 pImpEditEngine->xTransliterationWrapper.changeLocale( eLang);
1322
1323 const ::utl::TransliterationWrapper* pTransliteration = pImpEditEngine->xTransliterationWrapper.get();
1324 Sequence< i18n::CalendarItem2 > xItem = pImpEditEngine->xLocaleDataWrapper->getDefaultCalendarDays();
1325 sal_Int32 nCount = xItem.getLength();
1326 const i18n::CalendarItem2* pArr = xItem.getArray();
1327 for( sal_Int32 n = 0; n <= nCount; ++n )
1328 {
1329 const OUString& rDay = pArr[n].FullName;
1330 if( pTransliteration->isMatch( aWord, rDay) )
1331 {
1332 aComplete = rDay;
1333 break;
1334 }
1335 }
1336
1337 if ( aComplete.isEmpty() )
1338 {
1339 xItem = pImpEditEngine->xLocaleDataWrapper->getDefaultCalendarMonths();
1340 sal_Int32 nMonthCount = xItem.getLength();
1341 const i18n::CalendarItem2* pMonthArr = xItem.getArray();
1342 for( sal_Int32 n = 0; n <= nMonthCount; ++n )
1343 {
1344 const OUString& rMon = pMonthArr[n].FullName;
1345 if( pTransliteration->isMatch( aWord, rMon) )
1346 {
1347 aComplete = rMon;
1348 break;
1349 }
1350 }
1351 }
1352
1353 if( !aComplete.isEmpty() && ( ( aWord.getLength() + 1 ) < aComplete.getLength() ) )
1354 {
1355 pImpEditEngine->SetAutoCompleteText( aComplete, false );
1356 Point aPos = pImpEditEngine->PaMtoEditCursor( aCurSel.Max() ).TopLeft();
1357 aPos = pEditView->pImpEditView->GetWindowPos( aPos );
1358 aPos = pEditView->pImpEditView->GetWindow()->LogicToPixel( aPos );
1359 aPos = pEditView->GetWindow()->OutputToScreenPixel( aPos );
1360 aPos.AdjustY( -3 );
1361 Help::ShowQuickHelp( pEditView->GetWindow(), tools::Rectangle( aPos, Size( 1, 1 ) ), aComplete, QuickHelpFlags::Bottom|QuickHelpFlags::Left );
1362 }
1363 }
1364 }
1365 }
1366 bModified = true;
1367 }
1368 else
1369 bDone = false;
1370 }
1371 }
1372 }
1373
1374 pEditView->pImpEditView->SetEditSelection( aCurSel );
1375 if (comphelper::LibreOfficeKit::isActive())
1376 {
1377 pEditView->pImpEditView->DrawSelectionXOR();
1378 }
1379 pImpEditEngine->UpdateSelections();
1380
1381 if ( ( !IsVertical() && ( nCode != KEY_UP ) && ( nCode != KEY_DOWN ) ) ||
1382 ( IsVertical() && ( nCode != KEY_LEFT ) && ( nCode != KEY_RIGHT ) ))
1383 {
1384 pEditView->pImpEditView->nTravelXPos = TRAVEL_X_DONTKNOW0xFFFFFFFF;
1385 }
1386
1387 if ( /* ( nCode != KEY_HOME ) && ( nCode != KEY_END ) && */
1388 ( !IsVertical() && ( nCode != KEY_LEFT ) && ( nCode != KEY_RIGHT ) ) ||
1389 ( IsVertical() && ( nCode != KEY_UP ) && ( nCode != KEY_DOWN ) ))
1390 {
1391 pEditView->pImpEditView->SetCursorBidiLevel( CURSOR_BIDILEVEL_DONTKNOW0xFFFF );
1392 }
1393
1394 if ( bSetCursorFlags )
1395 pEditView->pImpEditView->nExtraCursorFlags = nNewCursorFlags;
1396
1397 if ( bModified )
1398 {
1399 DBG_ASSERT( !bReadOnly, "ReadOnly but modified???" )do { if (true && (!(!bReadOnly))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1399" ": "), "%s", "ReadOnly but modified???"); } } while
(false)
;
1400 // Idle-Formatter only when AnyInput.
1401 if ( bAllowIdle && pImpEditEngine->GetStatus().UseIdleFormatter()
1402 && Application::AnyInput( VclInputFlags::KEYBOARD) )
1403 pImpEditEngine->IdleFormatAndUpdate( pEditView );
1404 else
1405 pImpEditEngine->FormatAndUpdate( pEditView );
1406 }
1407 else if ( bMoved )
1408 {
1409 bool bGotoCursor = pEditView->pImpEditView->DoAutoScroll();
1410 pEditView->pImpEditView->ShowCursor( bGotoCursor, true );
1411 pImpEditEngine->CallStatusHdl();
1412 }
1413
1414 return bDone;
1415}
1416
1417sal_uInt32 EditEngine::GetTextHeight() const
1418{
1419
1420 if ( !pImpEditEngine->IsFormatted() )
1421 pImpEditEngine->FormatDoc();
1422
1423 sal_uInt32 nHeight = !IsVertical() ? pImpEditEngine->GetTextHeight() : pImpEditEngine->CalcTextWidth( true );
1424 return nHeight;
1425}
1426
1427sal_uInt32 EditEngine::GetTextHeightNTP() const
1428{
1429
1430 if ( !pImpEditEngine->IsFormatted() )
1431 pImpEditEngine->FormatDoc();
1432
1433 if ( IsVertical() )
1434 return pImpEditEngine->CalcTextWidth( true );
1435
1436 return pImpEditEngine->GetTextHeightNTP();
1437}
1438
1439sal_uInt32 EditEngine::CalcTextWidth()
1440{
1441
1442 if ( !pImpEditEngine->IsFormatted() )
1443 pImpEditEngine->FormatDoc();
1444
1445 sal_uInt32 nWidth = !IsVertical() ? pImpEditEngine->CalcTextWidth( true ) : pImpEditEngine->GetTextHeight();
1446 return nWidth;
1447}
1448
1449void EditEngine::SetUpdateMode(bool bUpdate, bool bRestoring)
1450{
1451 pImpEditEngine->SetUpdateMode( bUpdate );
1452 if (pImpEditEngine->pActiveView)
1453 {
1454 // Not an activation if we are restoring the previous update mode.
1455 pImpEditEngine->pActiveView->ShowCursor(false, false, /*bActivate=*/!bRestoring);
1456 }
1457}
1458
1459bool EditEngine::GetUpdateMode() const
1460{
1461 return pImpEditEngine->GetUpdateMode();
1462}
1463
1464void EditEngine::Clear()
1465{
1466 pImpEditEngine->Clear();
1467}
1468
1469void EditEngine::SetText( const OUString& rText )
1470{
1471 pImpEditEngine->SetText( rText );
1472 if ( !rText.isEmpty() )
1473 pImpEditEngine->FormatAndUpdate();
1474}
1475
1476ErrCode EditEngine::Read( SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, SvKeyValueIterator* pHTTPHeaderAttrs /* = NULL */ )
1477{
1478 bool bUndoEnabled = pImpEditEngine->IsUndoEnabled();
1479 pImpEditEngine->EnableUndo( false );
1480 pImpEditEngine->SetText( OUString() );
1481 EditPaM aPaM( pImpEditEngine->GetEditDoc().GetStartPaM() );
1482 pImpEditEngine->Read( rInput, rBaseURL, eFormat, EditSelection( aPaM, aPaM ), pHTTPHeaderAttrs );
1483 pImpEditEngine->EnableUndo( bUndoEnabled );
1484 return rInput.GetError();
1485}
1486
1487void EditEngine::Write( SvStream& rOutput, EETextFormat eFormat )
1488{
1489 EditPaM aStartPaM( pImpEditEngine->GetEditDoc().GetStartPaM() );
1490 EditPaM aEndPaM( pImpEditEngine->GetEditDoc().GetEndPaM() );
1491 pImpEditEngine->Write( rOutput, eFormat, EditSelection( aStartPaM, aEndPaM ) );
1492}
1493
1494std::unique_ptr<EditTextObject> EditEngine::CreateTextObject()
1495{
1496 return pImpEditEngine->CreateTextObject();
1497}
1498
1499std::unique_ptr<EditTextObject> EditEngine::CreateTextObject( const ESelection& rESelection )
1500{
1501 EditSelection aSel( pImpEditEngine->CreateSel( rESelection ) );
1502 return pImpEditEngine->CreateTextObject( aSel );
1503}
1504
1505std::unique_ptr<EditTextObject> EditEngine::GetEmptyTextObject() const
1506{
1507 return pImpEditEngine->GetEmptyTextObject();
1508}
1509
1510
1511void EditEngine::SetText( const EditTextObject& rTextObject )
1512{
1513 pImpEditEngine->SetText( rTextObject );
1514 pImpEditEngine->FormatAndUpdate();
1515}
1516
1517void EditEngine::ShowParagraph( sal_Int32 nParagraph, bool bShow )
1518{
1519 pImpEditEngine->ShowParagraph( nParagraph, bShow );
1520}
1521
1522void EditEngine::SetNotifyHdl( const Link<EENotify&,void>& rLink )
1523{
1524 pImpEditEngine->SetNotifyHdl( rLink );
1525}
1526
1527Link<EENotify&,void> const & EditEngine::GetNotifyHdl() const
1528{
1529 return pImpEditEngine->GetNotifyHdl();
1530}
1531
1532void EditEngine::SetStatusEventHdl( const Link<EditStatus&, void>& rLink )
1533{
1534 pImpEditEngine->SetStatusEventHdl( rLink );
1535}
1536
1537Link<EditStatus&, void> const & EditEngine::GetStatusEventHdl() const
1538{
1539 return pImpEditEngine->GetStatusEventHdl();
1540}
1541
1542void EditEngine::SetHtmlImportHdl( const Link<HtmlImportInfo&,void>& rLink )
1543{
1544 pImpEditEngine->aHtmlImportHdl = rLink;
1545}
1546
1547const Link<HtmlImportInfo&,void>& EditEngine::GetHtmlImportHdl() const
1548{
1549 return pImpEditEngine->aHtmlImportHdl;
1550}
1551
1552void EditEngine::SetRtfImportHdl( const Link<RtfImportInfo&,void>& rLink )
1553{
1554 pImpEditEngine->aRtfImportHdl = rLink;
1555}
1556
1557const Link<RtfImportInfo&,void>& EditEngine::GetRtfImportHdl() const
1558{
1559 return pImpEditEngine->aRtfImportHdl;
1560}
1561
1562void EditEngine::SetBeginMovingParagraphsHdl( const Link<MoveParagraphsInfo&,void>& rLink )
1563{
1564 pImpEditEngine->aBeginMovingParagraphsHdl = rLink;
1565}
1566
1567void EditEngine::SetEndMovingParagraphsHdl( const Link<MoveParagraphsInfo&,void>& rLink )
1568{
1569 pImpEditEngine->aEndMovingParagraphsHdl = rLink;
1570}
1571
1572void EditEngine::SetBeginPasteOrDropHdl( const Link<PasteOrDropInfos&,void>& rLink )
1573{
1574
1575 pImpEditEngine->aBeginPasteOrDropHdl = rLink;
1576}
1577
1578void EditEngine::SetEndPasteOrDropHdl( const Link<PasteOrDropInfos&,void>& rLink )
1579{
1580 pImpEditEngine->aEndPasteOrDropHdl = rLink;
1581}
1582
1583std::unique_ptr<EditTextObject> EditEngine::CreateTextObject( sal_Int32 nPara, sal_Int32 nParas )
1584{
1585 DBG_ASSERT( 0 <= nPara && nPara < pImpEditEngine->GetEditDoc().Count(), "CreateTextObject: Startpara out of Range" )do { if (true && (!(0 <= nPara && nPara <
pImpEditEngine->GetEditDoc().Count()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1585" ": "), "%s", "CreateTextObject: Startpara out of Range"
); } } while (false)
;
1586 DBG_ASSERT( nParas <= pImpEditEngine->GetEditDoc().Count() - nPara, "CreateTextObject: Endpara out of Range" )do { if (true && (!(nParas <= pImpEditEngine->GetEditDoc
().Count() - nPara))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1586" ": "), "%s", "CreateTextObject: Endpara out of Range"
); } } while (false)
;
1587
1588 ContentNode* pStartNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
1589 ContentNode* pEndNode = pImpEditEngine->GetEditDoc().GetObject( nPara+nParas-1 );
1590 DBG_ASSERT( pStartNode, "Start-Paragraph does not exist: CreateTextObject" )do { if (true && (!(pStartNode))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1590" ": "), "%s", "Start-Paragraph does not exist: CreateTextObject"
); } } while (false)
;
1591 DBG_ASSERT( pEndNode, "End-Paragraph does not exist: CreateTextObject" )do { if (true && (!(pEndNode))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1591" ": "), "%s", "End-Paragraph does not exist: CreateTextObject"
); } } while (false)
;
1592
1593 if ( pStartNode && pEndNode )
1594 {
1595 EditSelection aTmpSel;
1596 aTmpSel.Min() = EditPaM( pStartNode, 0 );
1597 aTmpSel.Max() = EditPaM( pEndNode, pEndNode->Len() );
1598 return pImpEditEngine->CreateTextObject( aTmpSel );
1599 }
1600 return nullptr;
1601}
1602
1603void EditEngine::RemoveParagraph( sal_Int32 nPara )
1604{
1605 DBG_ASSERT( pImpEditEngine->GetEditDoc().Count() > 1, "The first paragraph should not be deleted!" )do { if (true && (!(pImpEditEngine->GetEditDoc().Count
() > 1))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1605" ": "), "%s", "The first paragraph should not be deleted!"
); } } while (false)
;
1606 if( pImpEditEngine->GetEditDoc().Count() <= 1 )
1607 return;
1608
1609 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
1610 const ParaPortion* pPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nPara );
1611 DBG_ASSERT( pPortion && pNode, "Paragraph not found: RemoveParagraph" )do { if (true && (!(pPortion && pNode))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1611" ": "), "%s", "Paragraph not found: RemoveParagraph"
); } } while (false)
;
1612 if ( pNode && pPortion )
1613 {
1614 // No Undo encapsulation needed.
1615 pImpEditEngine->ImpRemoveParagraph( nPara );
1616 pImpEditEngine->InvalidateFromParagraph( nPara );
1617 pImpEditEngine->UpdateSelections();
1618 pImpEditEngine->FormatAndUpdate();
1619 }
1620}
1621
1622sal_Int32 EditEngine::GetTextLen( sal_Int32 nPara ) const
1623{
1624 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
1625 DBG_ASSERT( pNode, "Paragraph not found: GetTextLen" )do { if (true && (!(pNode))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1625" ": "), "%s", "Paragraph not found: GetTextLen"); }
} while (false)
;
1626 if ( pNode )
1627 return pNode->Len();
1628 return 0;
1629}
1630
1631OUString EditEngine::GetText( sal_Int32 nPara ) const
1632{
1633 OUString aStr;
1634 if ( 0 <= nPara && nPara < pImpEditEngine->GetEditDoc().Count() )
1635 aStr = pImpEditEngine->GetEditDoc().GetParaAsString( nPara );
1636 return aStr;
1637}
1638
1639void EditEngine::SetModifyHdl( const Link<LinkParamNone*,void>& rLink )
1640{
1641 pImpEditEngine->SetModifyHdl( rLink );
1642}
1643
1644Link<LinkParamNone*,void> const & EditEngine::GetModifyHdl() const
1645{
1646 return pImpEditEngine->GetModifyHdl();
1647}
1648
1649
1650void EditEngine::ClearModifyFlag()
1651{
1652 pImpEditEngine->SetModifyFlag( false );
1653}
1654
1655void EditEngine::SetModified()
1656{
1657 pImpEditEngine->SetModifyFlag( true );
1658}
1659
1660bool EditEngine::IsModified() const
1661{
1662 return pImpEditEngine->IsModified();
1663}
1664
1665bool EditEngine::IsInSelectionMode() const
1666{
1667 return ( pImpEditEngine->IsInSelectionMode() ||
1668 pImpEditEngine->GetSelEngine().IsInSelection() );
1669}
1670
1671void EditEngine::InsertParagraph( sal_Int32 nPara, const EditTextObject& rTxtObj, bool bAppend )
1672{
1673 if ( nPara > GetParagraphCount() )
1674 {
1675 SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" )do { if (true && (nPara != ((sal_Int32) 0x7FFFFFFF)))
{ switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN,
"editeng")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1675" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Paragraph number too large, but not EE_PARA_APPEND!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1675" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Paragraph number too large, but not EE_PARA_APPEND!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1675" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Paragraph number too large, but not EE_PARA_APPEND!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1675" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1676 nPara = GetParagraphCount();
1677 }
1678
1679 pImpEditEngine->UndoActionStart( EDITUNDO_INSERT111 );
1680
1681 // No Undo compounding needed.
1682 EditPaM aPaM( pImpEditEngine->InsertParagraph( nPara ) );
1683 // When InsertParagraph from the outside, no hard attributes
1684 // should be taken over!
1685 pImpEditEngine->RemoveCharAttribs( nPara );
1686 pImpEditEngine->InsertText( rTxtObj, EditSelection( aPaM, aPaM ) );
1687
1688 if ( bAppend && nPara )
1689 pImpEditEngine->ConnectContents( nPara-1, /*bBackwards=*/false );
1690
1691 pImpEditEngine->UndoActionEnd();
1692
1693 pImpEditEngine->FormatAndUpdate();
1694}
1695
1696void EditEngine::InsertParagraph(sal_Int32 nPara, const OUString& rTxt)
1697{
1698 if ( nPara > GetParagraphCount() )
1699 {
1700 SAL_WARN_IF( nPara != EE_PARA_APPEND, "editeng", "Paragraph number too large, but not EE_PARA_APPEND!" )do { if (true && (nPara != ((sal_Int32) 0x7FFFFFFF)))
{ switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN,
"editeng")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1700" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Paragraph number too large, but not EE_PARA_APPEND!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1700" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Paragraph number too large, but not EE_PARA_APPEND!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1700" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Paragraph number too large, but not EE_PARA_APPEND!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Paragraph number too large, but not EE_PARA_APPEND!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("editeng"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1700" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1701 nPara = GetParagraphCount();
1702 }
1703
1704 pImpEditEngine->UndoActionStart( EDITUNDO_INSERT111 );
1705 EditPaM aPaM( pImpEditEngine->InsertParagraph( nPara ) );
1706 // When InsertParagraph from the outside, no hard attributes
1707 // should be taken over!
1708 pImpEditEngine->RemoveCharAttribs( nPara );
1709 pImpEditEngine->UndoActionEnd();
1710 pImpEditEngine->ImpInsertText( EditSelection( aPaM, aPaM ), rTxt );
1711 pImpEditEngine->FormatAndUpdate();
1712}
1713
1714void EditEngine::SetText(sal_Int32 nPara, const OUString& rTxt)
1715{
1716 std::unique_ptr<EditSelection> pSel = pImpEditEngine->SelectParagraph( nPara );
1717 if ( pSel )
1718 {
1719 pImpEditEngine->UndoActionStart( EDITUNDO_INSERT111 );
1720 pImpEditEngine->ImpInsertText( *pSel, rTxt );
1721 pImpEditEngine->UndoActionEnd();
1722 pImpEditEngine->FormatAndUpdate();
1723 }
1724}
1725
1726void EditEngine::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
1727{
1728 pImpEditEngine->SetParaAttribs( nPara, rSet );
1729 pImpEditEngine->FormatAndUpdate();
1730}
1731
1732const SfxItemSet& EditEngine::GetParaAttribs( sal_Int32 nPara ) const
1733{
1734 return pImpEditEngine->GetParaAttribs( nPara );
1735}
1736
1737bool EditEngine::HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const
1738{
1739 return pImpEditEngine->HasParaAttrib( nPara, nWhich );
1740}
1741
1742const SfxPoolItem& EditEngine::GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich )
1743{
1744 return pImpEditEngine->GetParaAttrib( nPara, nWhich );
1745}
1746
1747void EditEngine::SetCharAttribs(sal_Int32 nPara, const SfxItemSet& rSet)
1748{
1749 EditSelection aSel(pImpEditEngine->ConvertSelection(nPara, 0, nPara, GetTextLen(nPara)));
1750 pImpEditEngine->SetAttribs(aSel, rSet);
1751 pImpEditEngine->FormatAndUpdate();
1752}
1753
1754void EditEngine::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const
1755{
1756 pImpEditEngine->GetCharAttribs( nPara, rLst );
1757}
1758
1759SfxItemSet EditEngine::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib )
1760{
1761 EditSelection aSel( pImpEditEngine->
1762 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
1763 return pImpEditEngine->GetAttribs( aSel, nOnlyHardAttrib );
1764}
1765
1766SfxItemSet EditEngine::GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags ) const
1767{
1768 return pImpEditEngine->GetAttribs( nPara, nStart, nEnd, nFlags );
1769}
1770
1771void EditEngine::RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich )
1772{
1773
1774 pImpEditEngine->UndoActionStart( EDITUNDO_RESETATTRIBS121 );
1775 EditSelection aSel( pImpEditEngine->ConvertSelection( rSelection.nStartPara, rSelection.nStartPos, rSelection.nEndPara, rSelection.nEndPos ) );
1776 pImpEditEngine->RemoveCharAttribs( aSel, bRemoveParaAttribs, nWhich );
1777 pImpEditEngine->UndoActionEnd();
1778 pImpEditEngine->FormatAndUpdate();
1779}
1780
1781vcl::Font EditEngine::GetStandardFont( sal_Int32 nPara )
1782{
1783 return GetStandardSvxFont( nPara );
1784}
1785
1786SvxFont EditEngine::GetStandardSvxFont( sal_Int32 nPara )
1787{
1788 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
1789 return pNode->GetCharAttribs().GetDefFont();
1790}
1791
1792void EditEngine::StripPortions()
1793{
1794 ScopedVclPtrInstance< VirtualDevice > aTmpDev;
1795 tools::Rectangle aBigRect( Point( 0, 0 ), Size( 0x7FFFFFFF, 0x7FFFFFFF ) );
1796 if ( IsVertical() )
1797 {
1798 if( IsTopToBottom() )
1799 {
1800 aBigRect.SetRight( 0 );
1801 aBigRect.SetLeft( -0x7FFFFFFF );
1802 }
1803 else
1804 {
1805 aBigRect.SetTop( -0x7FFFFFFF );
1806 aBigRect.SetBottom( 0 );
1807 }
1808 }
1809 pImpEditEngine->Paint( aTmpDev.get(), aBigRect, Point(), true );
1810}
1811
1812void EditEngine::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList )
1813{
1814 if ( !pImpEditEngine->IsFormatted() )
1815 pImpEditEngine->FormatFullDoc();
1816
1817 const ParaPortion* pParaPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nPara );
1818 if ( pParaPortion )
1819 {
1820 sal_Int32 nEnd = 0;
1821 sal_Int32 nTextPortions = pParaPortion->GetTextPortions().Count();
1822 for ( sal_Int32 n = 0; n < nTextPortions; n++ )
1823 {
1824 nEnd = nEnd + pParaPortion->GetTextPortions()[n].GetLen();
1825 rList.push_back( nEnd );
1826 }
1827 }
1828}
1829
1830void EditEngine::SetFlatMode( bool bFlat)
1831{
1832 pImpEditEngine->SetFlatMode( bFlat );
1833}
1834
1835bool EditEngine::IsFlatMode() const
1836{
1837 return !( pImpEditEngine->aStatus.UseCharAttribs() );
1838}
1839
1840void EditEngine::SetControlWord( EEControlBits nWord )
1841{
1842
1843 if ( nWord == pImpEditEngine->aStatus.GetControlWord() )
1844 return;
1845
1846 EEControlBits nPrev = pImpEditEngine->aStatus.GetControlWord();
1847 pImpEditEngine->aStatus.GetControlWord() = nWord;
1848
1849 EEControlBits nChanges = nPrev ^ nWord;
1850 if ( pImpEditEngine->IsFormatted() )
1851 {
1852 // possibly reformat:
1853 if ( ( nChanges & EEControlBits::USECHARATTRIBS ) ||
1854 ( nChanges & EEControlBits::ONECHARPERLINE ) ||
1855 ( nChanges & EEControlBits::STRETCHING ) ||
1856 ( nChanges & EEControlBits::OUTLINER ) ||
1857 ( nChanges & EEControlBits::NOCOLORS ) ||
1858 ( nChanges & EEControlBits::OUTLINER2 ) )
1859 {
1860 if ( nChanges & EEControlBits::USECHARATTRIBS )
1861 {
1862 pImpEditEngine->GetEditDoc().CreateDefFont( true );
1863 }
1864
1865 pImpEditEngine->FormatFullDoc();
1866 pImpEditEngine->UpdateViews( pImpEditEngine->GetActiveView() );
1867 }
1868 }
1869
1870 bool bSpellingChanged = bool(nChanges & EEControlBits::ONLINESPELLING);
1871
1872 if ( !bSpellingChanged )
1873 return;
1874
1875 pImpEditEngine->StopOnlineSpellTimer();
1876 if (nWord & EEControlBits::ONLINESPELLING)
1877 {
1878 // Create WrongList, start timer...
1879 sal_Int32 nNodes = pImpEditEngine->GetEditDoc().Count();
1880 for ( sal_Int32 n = 0; n < nNodes; n++ )
1881 {
1882 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( n );
1883 pNode->CreateWrongList();
1884 }
1885 if (pImpEditEngine->IsFormatted())
1886 pImpEditEngine->StartOnlineSpellTimer();
1887 }
1888 else
1889 {
1890 long nY = 0;
1891 sal_Int32 nNodes = pImpEditEngine->GetEditDoc().Count();
1892 for ( sal_Int32 n = 0; n < nNodes; n++ )
1893 {
1894 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( n );
1895 const ParaPortion* pPortion = pImpEditEngine->GetParaPortions()[n];
1896 bool bWrongs = false;
1897 if (pNode->GetWrongList() != nullptr)
1898 bWrongs = !pNode->GetWrongList()->empty();
1899 pNode->DestroyWrongList();
1900 if ( bWrongs )
1901 {
1902 pImpEditEngine->aInvalidRect.SetLeft( 0 );
1903 pImpEditEngine->aInvalidRect.SetRight( pImpEditEngine->GetPaperSize().Width() );
1904 pImpEditEngine->aInvalidRect.SetTop( nY+1 );
1905 pImpEditEngine->aInvalidRect.SetBottom( nY+pPortion->GetHeight()-1 );
1906 pImpEditEngine->UpdateViews( pImpEditEngine->pActiveView );
1907 }
1908 nY += pPortion->GetHeight();
1909 }
1910 }
1911}
1912
1913EEControlBits EditEngine::GetControlWord() const
1914{
1915 return pImpEditEngine->aStatus.GetControlWord();
1916}
1917
1918long EditEngine::GetFirstLineStartX( sal_Int32 nParagraph )
1919{
1920
1921 long nX = 0;
1922 const ParaPortion* pPPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nParagraph );
1923 if ( pPPortion )
1924 {
1925 DBG_ASSERT( pImpEditEngine->IsFormatted() || !pImpEditEngine->IsFormatting(), "GetFirstLineStartX: Doc not formatted - unable to format!" )do { if (true && (!(pImpEditEngine->IsFormatted() ||
!pImpEditEngine->IsFormatting()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1925" ": "), "%s", "GetFirstLineStartX: Doc not formatted - unable to format!"
); } } while (false)
;
1926 if ( !pImpEditEngine->IsFormatted() )
1927 pImpEditEngine->FormatDoc();
1928 const EditLine& rFirstLine = pPPortion->GetLines()[0];
1929 nX = rFirstLine.GetStartPosX();
1930 }
1931 return nX;
1932}
1933
1934Point EditEngine::GetDocPos( const Point& rPaperPos ) const
1935{
1936 Point aDocPos( rPaperPos );
1937 if ( IsVertical() )
1938 {
1939 if ( IsTopToBottom() )
1940 {
1941 aDocPos.setX( rPaperPos.Y() );
1942 aDocPos.setY( GetPaperSize().Width() - rPaperPos.X() );
1943 }
1944 else
1945 {
1946 aDocPos.setX( rPaperPos.Y() );
1947 aDocPos.setY( rPaperPos.X() );
1948 }
1949 }
1950 return aDocPos;
1951}
1952
1953Point EditEngine::GetDocPosTopLeft( sal_Int32 nParagraph )
1954{
1955 const ParaPortion* pPPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nParagraph );
1956 DBG_ASSERT( pPPortion, "Paragraph not found: GetWindowPosTopLeft" )do { if (true && (!(pPPortion))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1956" ": "), "%s", "Paragraph not found: GetWindowPosTopLeft"
); } } while (false)
;
1957 Point aPoint;
1958 if ( pPPortion )
1959 {
1960
1961 // If someone calls GetLineHeight() with an empty Engine.
1962 DBG_ASSERT( pImpEditEngine->IsFormatted() || !pImpEditEngine->IsFormatting(), "GetDocPosTopLeft: Doc not formatted - unable to format!" )do { if (true && (!(pImpEditEngine->IsFormatted() ||
!pImpEditEngine->IsFormatting()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "1962" ": "), "%s", "GetDocPosTopLeft: Doc not formatted - unable to format!"
); } } while (false)
;
1963 if ( !pImpEditEngine->IsFormatted() )
1964 pImpEditEngine->FormatAndUpdate();
1965 if ( pPPortion->GetLines().Count() )
1966 {
1967 // Correct it if large Bullet.
1968 const EditLine& rFirstLine = pPPortion->GetLines()[0];
1969 aPoint.setX( rFirstLine.GetStartPosX() );
1970 }
1971 else
1972 {
1973 const SvxLRSpaceItem& rLRItem = pImpEditEngine->GetLRSpaceItem( pPPortion->GetNode() );
1974// TL_NF_LR aPoint.X() = pImpEditEngine->GetXValue( (short)(rLRItem.GetTextLeft() + rLRItem.GetTextFirstLineOffset()) );
1975 sal_Int32 nSpaceBefore = 0;
1976 pImpEditEngine->GetSpaceBeforeAndMinLabelWidth( pPPortion->GetNode(), &nSpaceBefore );
1977 short nX = static_cast<short>(rLRItem.GetTextLeft()
1978 + rLRItem.GetTextFirstLineOffset()
1979 + nSpaceBefore);
1980 aPoint.setX( pImpEditEngine->GetXValue( nX
1981 ) );
1982 }
1983 aPoint.setY( pImpEditEngine->GetParaPortions().GetYOffset( pPPortion ) );
1984 }
1985 return aPoint;
1986}
1987
1988const SvxNumberFormat* EditEngine::GetNumberFormat( sal_Int32 ) const
1989{
1990 // derived objects may override this function to give access to
1991 // bullet information (see Outliner)
1992 return nullptr;
1993}
1994
1995bool EditEngine::IsRightToLeft( sal_Int32 nPara ) const
1996{
1997 return pImpEditEngine->IsRightToLeft( nPara );
1998}
1999
2000bool EditEngine::IsTextPos( const Point& rPaperPos, sal_uInt16 nBorder )
2001{
2002
2003 if ( !pImpEditEngine->IsFormatted() )
2004 pImpEditEngine->FormatDoc();
2005
2006 bool bTextPos = false;
2007 // take unrotated positions for calculation here
2008 Point aDocPos = GetDocPos( rPaperPos );
2009
2010 if ( ( aDocPos.Y() > 0 ) && ( aDocPos.Y() < static_cast<long>(pImpEditEngine->GetTextHeight()) ) )
2011 {
2012 EditPaM aPaM = pImpEditEngine->GetPaM( aDocPos, false );
2013 if ( aPaM.GetNode() )
2014 {
2015 const ParaPortion* pParaPortion = pImpEditEngine->FindParaPortion( aPaM.GetNode() );
2016 DBG_ASSERT( pParaPortion, "ParaPortion?" )do { if (true && (!(pParaPortion))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "2016" ": "), "%s", "ParaPortion?"); } } while (false)
;
2017
2018 sal_Int32 nLine = pParaPortion->GetLineNumber( aPaM.GetIndex() );
2019 const EditLine& rLine = pParaPortion->GetLines()[nLine];
2020 Range aLineXPosStartEnd = pImpEditEngine->GetLineXPosStartEnd( pParaPortion, &rLine );
2021 if ( ( aDocPos.X() >= aLineXPosStartEnd.Min() - nBorder ) &&
2022 ( aDocPos.X() <= aLineXPosStartEnd.Max() + nBorder ) )
2023 {
2024 bTextPos = true;
2025 }
2026 }
2027 }
2028 return bTextPos;
2029}
2030
2031void EditEngine::SetEditTextObjectPool( SfxItemPool* pPool )
2032{
2033 pImpEditEngine->SetEditTextObjectPool( pPool );
2034}
2035
2036SfxItemPool* EditEngine::GetEditTextObjectPool() const
2037{
2038 return pImpEditEngine->GetEditTextObjectPool();
2039}
2040
2041void EditEngine::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
2042{
2043
2044 EditSelection aSel( pImpEditEngine->
2045 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
2046
2047 pImpEditEngine->SetAttribs( aSel, rSet );
2048}
2049
2050void EditEngine::QuickMarkInvalid( const ESelection& rSel )
2051{
2052 DBG_ASSERT( rSel.nStartPara < pImpEditEngine->GetEditDoc().Count(), "MarkInvalid: Start out of Range!" )do { if (true && (!(rSel.nStartPara < pImpEditEngine
->GetEditDoc().Count()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "2052" ": "), "%s", "MarkInvalid: Start out of Range!");
} } while (false)
;
2053 DBG_ASSERT( rSel.nEndPara < pImpEditEngine->GetEditDoc().Count(), "MarkInvalid: End out of Range!" )do { if (true && (!(rSel.nEndPara < pImpEditEngine
->GetEditDoc().Count()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "2053" ": "), "%s", "MarkInvalid: End out of Range!"); }
} while (false)
;
2054 for ( sal_Int32 nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ )
2055 {
2056 ParaPortion* pPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nPara );
2057 if ( pPortion )
2058 pPortion->MarkSelectionInvalid( 0 );
2059 }
2060}
2061
2062void EditEngine::QuickInsertText(const OUString& rText, const ESelection& rSel)
2063{
2064
2065 EditSelection aSel( pImpEditEngine->
2066 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
2067
2068 pImpEditEngine->ImpInsertText( aSel, rText );
2069}
2070
2071void EditEngine::QuickDelete( const ESelection& rSel )
2072{
2073
2074 EditSelection aSel( pImpEditEngine->
2075 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
2076
2077 pImpEditEngine->ImpDeleteSelection( aSel );
2078}
2079
2080void EditEngine::QuickMarkToBeRepainted( sal_Int32 nPara )
2081{
2082 ParaPortion* pPortion = pImpEditEngine->GetParaPortions().SafeGetObject( nPara );
2083 if ( pPortion )
2084 pPortion->SetMustRepaint( true );
2085}
2086
2087void EditEngine::QuickInsertLineBreak( const ESelection& rSel )
2088{
2089
2090 EditSelection aSel( pImpEditEngine->
2091 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
2092
2093 pImpEditEngine->InsertLineBreak( aSel );
2094}
2095
2096void EditEngine::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
2097{
2098
2099 EditSelection aSel( pImpEditEngine->
2100 ConvertSelection( rSel.nStartPara, rSel.nStartPos, rSel.nEndPara, rSel.nEndPos ) );
2101
2102 pImpEditEngine->ImpInsertFeature( aSel, rFld );
2103}
2104
2105void EditEngine::QuickFormatDoc( bool bFull )
2106{
2107 if ( bFull )
2108 pImpEditEngine->FormatFullDoc();
2109 else
2110 pImpEditEngine->FormatDoc();
2111
2112 // Don't pass active view, maybe selection is not updated yet...
2113 pImpEditEngine->UpdateViews();
2114}
2115
2116void EditEngine::SetStyleSheet(const EditSelection& aSel, SfxStyleSheet* pStyle)
2117{
2118 pImpEditEngine->SetStyleSheet(aSel, pStyle);
2119}
2120
2121void EditEngine::SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle )
2122{
2123 pImpEditEngine->SetStyleSheet( nPara, pStyle );
2124}
2125
2126const SfxStyleSheet* EditEngine::GetStyleSheet( sal_Int32 nPara ) const
2127{
2128 return pImpEditEngine->GetStyleSheet( nPara );
2129}
2130
2131SfxStyleSheet* EditEngine::GetStyleSheet( sal_Int32 nPara )
2132{
2133 return pImpEditEngine->GetStyleSheet( nPara );
2134}
2135
2136void EditEngine::SetStyleSheetPool( SfxStyleSheetPool* pSPool )
2137{
2138 pImpEditEngine->SetStyleSheetPool( pSPool );
2139}
2140
2141SfxStyleSheetPool* EditEngine::GetStyleSheetPool()
2142{
2143 return pImpEditEngine->GetStyleSheetPool();
2144}
2145
2146void EditEngine::SetWordDelimiters( const OUString& rDelimiters )
2147{
2148 pImpEditEngine->aWordDelimiters = rDelimiters;
2149 if (pImpEditEngine->aWordDelimiters.indexOf(CH_FEATUREu'\x0001') == -1)
2150 pImpEditEngine->aWordDelimiters += OUStringChar(CH_FEATUREu'\x0001');
2151}
2152
2153const OUString& EditEngine::GetWordDelimiters() const
2154{
2155 return pImpEditEngine->aWordDelimiters;
2156}
2157
2158void EditEngine::EraseVirtualDevice()
2159{
2160 pImpEditEngine->EraseVirtualDevice();
1
Calling 'ImpEditEngine::EraseVirtualDevice'
2161}
2162
2163void EditEngine::SetSpeller( Reference< XSpellChecker1 > const &xSpeller )
2164{
2165 pImpEditEngine->SetSpeller( xSpeller );
2166}
2167
2168Reference< XSpellChecker1 > const & EditEngine::GetSpeller()
2169{
2170 return pImpEditEngine->GetSpeller();
2171}
2172
2173void EditEngine::SetHyphenator( Reference< XHyphenator > const & xHyph )
2174{
2175 pImpEditEngine->SetHyphenator( xHyph );
2176}
2177
2178void EditEngine::GetAllMisspellRanges( std::vector<editeng::MisspellRanges>& rRanges ) const
2179{
2180 pImpEditEngine->GetAllMisspellRanges(rRanges);
2181}
2182
2183void EditEngine::SetAllMisspellRanges( const std::vector<editeng::MisspellRanges>& rRanges )
2184{
2185 pImpEditEngine->SetAllMisspellRanges(rRanges);
2186}
2187
2188void EditEngine::SetForbiddenCharsTable(const std::shared_ptr<SvxForbiddenCharactersTable>& xForbiddenChars)
2189{
2190 ImpEditEngine::SetForbiddenCharsTable( xForbiddenChars );
2191}
2192
2193void EditEngine::SetDefaultLanguage( LanguageType eLang )
2194{
2195 pImpEditEngine->SetDefaultLanguage( eLang );
2196}
2197
2198LanguageType EditEngine::GetDefaultLanguage() const
2199{
2200 return pImpEditEngine->GetDefaultLanguage();
2201}
2202
2203bool EditEngine::SpellNextDocument()
2204{
2205 return false;
2206}
2207
2208EESpellState EditEngine::HasSpellErrors()
2209{
2210 if ( !pImpEditEngine->GetSpeller().is() )
2211 return EESpellState::NoSpeller;
2212
2213 return pImpEditEngine->HasSpellErrors();
2214}
2215
2216void EditEngine::ClearSpellErrors()
2217{
2218 pImpEditEngine->ClearSpellErrors();
2219}
2220
2221bool EditEngine::SpellSentence(EditView const & rView, svx::SpellPortions& rToFill )
2222{
2223 return pImpEditEngine->SpellSentence( rView, rToFill );
2224}
2225
2226void EditEngine::PutSpellingToSentenceStart( EditView const & rEditView )
2227{
2228 pImpEditEngine->PutSpellingToSentenceStart( rEditView );
2229}
2230
2231void EditEngine::ApplyChangedSentence(EditView const & rEditView, const svx::SpellPortions& rNewPortions, bool bRecheck )
2232{
2233 pImpEditEngine->ApplyChangedSentence( rEditView, rNewPortions, bRecheck );
2234}
2235
2236bool EditEngine::HasConvertibleTextPortion( LanguageType nLang )
2237{
2238 return pImpEditEngine->HasConvertibleTextPortion( nLang );
2239}
2240
2241bool EditEngine::ConvertNextDocument()
2242{
2243 return false;
2244}
2245
2246bool EditEngine::HasText( const SvxSearchItem& rSearchItem )
2247{
2248 return pImpEditEngine->HasText( rSearchItem );
2249}
2250
2251void EditEngine::SetGlobalCharStretching( sal_uInt16 nX, sal_uInt16 nY )
2252{
2253 pImpEditEngine->SetCharStretching( nX, nY );
2254}
2255
2256void EditEngine::GetGlobalCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const
2257{
2258 pImpEditEngine->GetCharStretching( rX, rY );
2259}
2260
2261bool EditEngine::ShouldCreateBigTextObject() const
2262{
2263 sal_Int32 nTextPortions = 0;
2264 sal_Int32 nParas = pImpEditEngine->GetEditDoc().Count();
2265 for ( sal_Int32 nPara = 0; nPara < nParas; nPara++ )
2266 {
2267 ParaPortion* pParaPortion = pImpEditEngine->GetParaPortions()[nPara];
2268 nTextPortions = nTextPortions + pParaPortion->GetTextPortions().Count();
2269 }
2270 return nTextPortions >= pImpEditEngine->GetBigTextObjectStart();
2271}
2272
2273sal_uInt16 EditEngine::GetFieldCount( sal_Int32 nPara ) const
2274{
2275 sal_uInt16 nFields = 0;
2276 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
2277 if ( pNode )
2278 {
2279 for (auto const& attrib : pNode->GetCharAttribs().GetAttribs())
2280 {
2281 if (attrib->Which() == EE_FEATURE_FIELD)
2282 ++nFields;
2283 }
2284 }
2285
2286 return nFields;
2287}
2288
2289EFieldInfo EditEngine::GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const
2290{
2291 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
2292 if ( pNode )
2293 {
2294 sal_uInt16 nCurrentField = 0;
2295 for (auto const& attrib : pNode->GetCharAttribs().GetAttribs())
2296 {
2297 const EditCharAttrib& rAttr = *attrib;
2298 if (rAttr.Which() == EE_FEATURE_FIELD)
2299 {
2300 if ( nCurrentField == nField )
2301 {
2302 const SvxFieldItem* p = static_cast<const SvxFieldItem*>(rAttr.GetItem());
2303 EFieldInfo aInfo(*p, nPara, rAttr.GetStart());
2304 aInfo.aCurrentText = static_cast<const EditCharAttribField&>(rAttr).GetFieldValue();
2305 return aInfo;
2306 }
2307
2308 ++nCurrentField;
2309 }
2310 }
2311 }
2312 return EFieldInfo();
2313}
2314
2315
2316bool EditEngine::UpdateFields()
2317{
2318 bool bChanges = pImpEditEngine->UpdateFields();
2319 if ( bChanges )
2320 pImpEditEngine->FormatAndUpdate();
2321 return bChanges;
2322}
2323
2324bool EditEngine::UpdateFieldsOnly()
2325{
2326 return pImpEditEngine->UpdateFields();
2327}
2328
2329void EditEngine::RemoveFields( const std::function<bool ( const SvxFieldData* )>& isFieldData )
2330{
2331 pImpEditEngine->UpdateFields();
2332
2333 sal_Int32 nParas = pImpEditEngine->GetEditDoc().Count();
2334 for ( sal_Int32 nPara = 0; nPara < nParas; nPara++ )
2335 {
2336 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( nPara );
2337 const CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
2338 for (size_t nAttr = rAttrs.size(); nAttr; )
2339 {
2340 const EditCharAttrib& rAttr = *rAttrs[--nAttr];
2341 if (rAttr.Which() == EE_FEATURE_FIELD)
2342 {
2343 const SvxFieldData* pFldData = static_cast<const SvxFieldItem*>(rAttr.GetItem())->GetField();
2344 if ( pFldData && ( isFieldData( pFldData ) ) )
2345 {
2346 DBG_ASSERT( dynamic_cast<const SvxFieldItem*>(rAttr.GetItem()), "no field item..." )do { if (true && (!(dynamic_cast<const SvxFieldItem
*>(rAttr.GetItem())))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "2346" ": "), "%s", "no field item..."); } } while (false
)
;
2347 EditSelection aSel( EditPaM(pNode, rAttr.GetStart()), EditPaM(pNode, rAttr.GetEnd()) );
2348 OUString aFieldText = static_cast<const EditCharAttribField&>(rAttr).GetFieldValue();
2349 pImpEditEngine->ImpInsertText( aSel, aFieldText );
2350 }
2351 }
2352 }
2353 }
2354}
2355
2356bool EditEngine::HasOnlineSpellErrors() const
2357{
2358 sal_Int32 nNodes = pImpEditEngine->GetEditDoc().Count();
2359 for ( sal_Int32 n = 0; n < nNodes; n++ )
2360 {
2361 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( n );
2362 if ( pNode->GetWrongList() && !pNode->GetWrongList()->empty() )
2363 return true;
2364 }
2365 return false;
2366}
2367
2368void EditEngine::CompleteOnlineSpelling()
2369{
2370 if ( pImpEditEngine->GetStatus().DoOnlineSpelling() )
2371 {
2372 if( !pImpEditEngine->IsFormatted() )
2373 pImpEditEngine->FormatAndUpdate();
2374
2375 pImpEditEngine->StopOnlineSpellTimer();
2376 pImpEditEngine->DoOnlineSpelling( nullptr, true, false );
2377 }
2378}
2379
2380sal_Int32 EditEngine::FindParagraph( long nDocPosY )
2381{
2382 return pImpEditEngine->GetParaPortions().FindParagraph( nDocPosY );
2383}
2384
2385EPosition EditEngine::FindDocPosition( const Point& rDocPos ) const
2386{
2387 EPosition aPos;
2388 // From the point of the API, this is const...
2389 EditPaM aPaM = const_cast<EditEngine*>(this)->pImpEditEngine->GetPaM( rDocPos, false );
2390 if ( aPaM.GetNode() )
2391 {
2392 aPos.nPara = pImpEditEngine->aEditDoc.GetPos( aPaM.GetNode() );
2393 aPos.nIndex = aPaM.GetIndex();
2394 }
2395 return aPos;
2396}
2397
2398tools::Rectangle EditEngine::GetCharacterBounds( const EPosition& rPos ) const
2399{
2400 tools::Rectangle aBounds;
2401 ContentNode* pNode = pImpEditEngine->GetEditDoc().GetObject( rPos.nPara );
2402
2403 // Check against index, not paragraph
2404 if ( pNode && ( rPos.nIndex < pNode->Len() ) )
2405 {
2406 aBounds = pImpEditEngine->PaMtoEditCursor( EditPaM( pNode, rPos.nIndex ), GetCursorFlags::TextOnly );
2407 tools::Rectangle aR2 = pImpEditEngine->PaMtoEditCursor( EditPaM( pNode, rPos.nIndex+1 ), GetCursorFlags::TextOnly|GetCursorFlags::EndOfLine );
2408 if ( aR2.Right() > aBounds.Right() )
2409 aBounds.SetRight( aR2.Right() );
2410 }
2411 return aBounds;
2412}
2413
2414ParagraphInfos EditEngine::GetParagraphInfos( sal_Int32 nPara )
2415{
2416
2417 // This only works if not already in the format ...
2418 if ( !pImpEditEngine->IsFormatted() )
2419 pImpEditEngine->FormatDoc();
2420
2421 ParagraphInfos aInfos;
2422 aInfos.bValid = pImpEditEngine->IsFormatted();
2423 if ( pImpEditEngine->IsFormatted() )
2424 {
2425 const ParaPortion* pParaPortion = pImpEditEngine->GetParaPortions()[nPara];
2426 const EditLine* pLine = (pParaPortion && pParaPortion->GetLines().Count()) ?
2427 &pParaPortion->GetLines()[0] : nullptr;
2428 DBG_ASSERT( pParaPortion && pLine, "GetParagraphInfos - Paragraph out of range" )do { if (true && (!(pParaPortion && pLine))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/editeng.cxx"
":" "2428" ": "), "%s", "GetParagraphInfos - Paragraph out of range"
); } } while (false)
;
2429 if ( pParaPortion && pLine )
2430 {
2431 aInfos.nFirstLineHeight = pLine->GetHeight();
2432 aInfos.nFirstLineTextHeight = pLine->GetTxtHeight();
2433 aInfos.nFirstLineMaxAscent = pLine->GetMaxAscent();
2434 }
2435 }
2436 return aInfos;
2437}
2438
2439css::uno::Reference< css::datatransfer::XTransferable >
2440 EditEngine::CreateTransferable( const ESelection& rSelection ) const
2441{
2442 EditSelection aSel( pImpEditEngine->CreateSel( rSelection ) );
2443 return pImpEditEngine->CreateTransferable( aSel );
2444}
2445
2446
2447// ====================== Virtual Methods ========================
2448
2449void EditEngine::DrawingText( const Point&, const OUString&, sal_Int32, sal_Int32,
2450 const long*, const SvxFont&, sal_Int32 /*nPara*/, sal_uInt8 /*nRightToLeft*/,
2451 const EEngineData::WrongSpellVector*, const SvxFieldData*, bool, bool,
2452 const css::lang::Locale*, const Color&, const Color&)
2453
2454{
2455}
2456
2457void EditEngine::DrawingTab( const Point& /*rStartPos*/, long /*nWidth*/,
2458 const OUString& /*rChar*/, const SvxFont& /*rFont*/,
2459 sal_Int32 /*nPara*/, sal_uInt8 /*nRightToLeft*/, bool /*bEndOfLine*/,
2460 bool /*bEndOfParagraph*/, const Color& /*rOverlineColor*/,
2461 const Color& /*rTextLineColor*/)
2462{
2463}
2464
2465void EditEngine::PaintingFirstLine( sal_Int32, const Point&, long, const Point&, short, OutputDevice* )
2466{
2467}
2468
2469void EditEngine::ParagraphInserted( sal_Int32 nPara )
2470{
2471
2472 if ( GetNotifyHdl().IsSet() )
2473 {
2474 EENotify aNotify( EE_NOTIFY_PARAGRAPHINSERTED );
2475 aNotify.nParagraph = nPara;
2476 pImpEditEngine->GetNotifyHdl().Call( aNotify );
2477 }
2478}
2479
2480void EditEngine::ParagraphDeleted( sal_Int32 nPara )
2481{
2482
2483 if ( GetNotifyHdl().IsSet() )
2484 {
2485 EENotify aNotify( EE_NOTIFY_PARAGRAPHREMOVED );
2486 aNotify.nParagraph = nPara;
2487 pImpEditEngine->GetNotifyHdl().Call( aNotify );
2488 }
2489}
2490void EditEngine::ParagraphConnected( sal_Int32 /*nLeftParagraph*/, sal_Int32 /*nRightParagraph*/ )
2491{
2492}
2493
2494void EditEngine::ParaAttribsChanged( sal_Int32 /* nParagraph */ )
2495{
2496}
2497
2498void EditEngine::StyleSheetChanged( SfxStyleSheet* /* pStyle */ )
2499{
2500}
2501
2502void EditEngine::ParagraphHeightChanged( sal_Int32 nPara )
2503{
2504
2505 if ( GetNotifyHdl().IsSet() )
2506 {
2507 EENotify aNotify( EE_NOTIFY_TextHeightChanged );
2508 aNotify.nParagraph = nPara;
2509 pImpEditEngine->GetNotifyHdl().Call( aNotify );
2510 }
2511}
2512
2513OUString EditEngine::GetUndoComment( sal_uInt16 nId ) const
2514{
2515 OUString aComment;
2516 switch ( nId )
2517 {
2518 case EDITUNDO_REMOVECHARS100:
2519 case EDITUNDO_CONNECTPARAS101:
2520 case EDITUNDO_DELCONTENT107:
2521 case EDITUNDO_DELETE108:
2522 case EDITUNDO_CUT109:
2523 aComment = EditResId(RID_EDITUNDO_DELreinterpret_cast<char const *>("RID_EDITUNDO_DEL" "\004"
u8"Delete")
);
2524 break;
2525 case EDITUNDO_MOVEPARAGRAPHS103:
2526 case EDITUNDO_MOVEPARAS113:
2527 case EDITUNDO_DRAGANDDROP116:
2528 aComment = EditResId(RID_EDITUNDO_MOVEreinterpret_cast<char const *>("RID_EDITUNDO_MOVE" "\004"
u8"Move")
);
2529 break;
2530 case EDITUNDO_INSERTFEATURE104:
2531 case EDITUNDO_SPLITPARA105:
2532 case EDITUNDO_INSERTCHARS106:
2533 case EDITUNDO_PASTE110:
2534 case EDITUNDO_INSERT111:
2535 case EDITUNDO_READ117:
2536 aComment = EditResId(RID_EDITUNDO_INSERTreinterpret_cast<char const *>("RID_EDITUNDO_INSERT" "\004"
u8"Insert")
);
2537 break;
2538 case EDITUNDO_REPLACEALL119:
2539 aComment = EditResId(RID_EDITUNDO_REPLACEreinterpret_cast<char const *>("RID_EDITUNDO_REPLACE" "\004"
u8"Replace")
);
2540 break;
2541 case EDITUNDO_ATTRIBS115:
2542 case EDITUNDO_PARAATTRIBS114:
2543 aComment = EditResId(RID_EDITUNDO_SETATTRIBSreinterpret_cast<char const *>("RID_EDITUNDO_SETATTRIBS"
"\004" u8"Apply attributes")
);
2544 break;
2545 case EDITUNDO_RESETATTRIBS121:
2546 aComment = EditResId(RID_EDITUNDO_RESETATTRIBSreinterpret_cast<char const *>("RID_EDITUNDO_RESETATTRIBS"
"\004" u8"Reset attributes")
);
2547 break;
2548 case EDITUNDO_STYLESHEET118:
2549 aComment = EditResId(RID_EDITUNDO_SETSTYLEreinterpret_cast<char const *>("RID_EDITUNDO_SETSTYLE" "\004"
u8"Apply Styles")
);
2550 break;
2551 case EDITUNDO_TRANSLITERATE125:
2552 aComment = EditResId(RID_EDITUNDO_TRANSLITERATEreinterpret_cast<char const *>("RID_EDITUNDO_TRANSLITERATE"
"\004" u8"Change Case")
);
2553 break;
2554 case EDITUNDO_INDENTBLOCK122:
2555 case EDITUNDO_UNINDENTBLOCK123:
2556 aComment = EditResId(RID_EDITUNDO_INDENTreinterpret_cast<char const *>("RID_EDITUNDO_INDENT" "\004"
u8"Indent")
);
2557 break;
2558 }
2559 return aComment;
2560}
2561
2562tools::Rectangle EditEngine::GetBulletArea( sal_Int32 )
2563{
2564 return tools::Rectangle( Point(), Point() );
2565}
2566
2567OUString EditEngine::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, std::optional<Color>&, std::optional<Color>& )
2568{
2569 return OUString(' ');
2570}
2571
2572void EditEngine::FieldClicked( const SvxFieldItem& )
2573{
2574}
2575
2576
2577// ====================== Static Methods =======================
2578
2579SfxItemPool* EditEngine::CreatePool()
2580{
2581 SfxItemPool* pPool = new EditEngineItemPool();
2582 return pPool;
2583}
2584
2585SfxItemPool& EditEngine::GetGlobalItemPool()
2586{
2587 if ( !pGlobalPool )
2588 pGlobalPool = CreatePool();
2589 return *pGlobalPool;
2590}
2591
2592void EditEngine::SetFontInfoInItemSet( SfxItemSet& rSet, const vcl::Font& rFont )
2593{
2594 SvxFont aSvxFont( rFont );
2595 SetFontInfoInItemSet( rSet, aSvxFont );
2596
2597}
2598
2599void EditEngine::SetFontInfoInItemSet( SfxItemSet& rSet, const SvxFont& rFont )
2600{
2601 rSet.Put( SvxLanguageItem( rFont.GetLanguage(), EE_CHAR_LANGUAGE ) );
2602 rSet.Put( SvxFontItem( rFont.GetFamilyType(), rFont.GetFamilyName(), OUString(), rFont.GetPitch(), rFont.GetCharSet(), EE_CHAR_FONTINFO ) );
2603 rSet.Put( SvxFontHeightItem( rFont.GetFontSize().Height(), 100, EE_CHAR_FONTHEIGHT ) );
2604 rSet.Put( SvxCharScaleWidthItem( 100, EE_CHAR_FONTWIDTH ) );
2605 rSet.Put( SvxShadowedItem( rFont.IsShadow(), EE_CHAR_SHADOW ) );
2606 rSet.Put( SvxEscapementItem( rFont.GetEscapement(), rFont.GetPropr(), EE_CHAR_ESCAPEMENT ) );
2607 rSet.Put( SvxWeightItem( rFont.GetWeight(), EE_CHAR_WEIGHT ) );
2608 rSet.Put( SvxColorItem( rFont.GetColor(), EE_CHAR_COLOR ) );
2609 rSet.Put( SvxBackgroundColorItem( rFont.GetFillColor(), EE_CHAR_BKGCOLOR ) );
2610 rSet.Put( SvxUnderlineItem( rFont.GetUnderline(), EE_CHAR_UNDERLINE ) );
2611 rSet.Put( SvxOverlineItem( rFont.GetOverline(), EE_CHAR_OVERLINE ) );
2612 rSet.Put( SvxCrossedOutItem( rFont.GetStrikeout(), EE_CHAR_STRIKEOUT ) );
2613 rSet.Put( SvxCaseMapItem( rFont.GetCaseMap(), EE_CHAR_CASEMAP ) );
2614 rSet.Put( SvxPostureItem( rFont.GetItalic(), EE_CHAR_ITALIC ) );
2615 rSet.Put( SvxContourItem( rFont.IsOutline(), EE_CHAR_OUTLINE ) );
2616 rSet.Put( SvxAutoKernItem( rFont.IsKerning(), EE_CHAR_PAIRKERNING ) );
2617 rSet.Put( SvxKerningItem( rFont.GetFixKerning(), EE_CHAR_KERNING ) );
2618 rSet.Put( SvxWordLineModeItem( rFont.IsWordLineMode(), EE_CHAR_WLM ) );
2619 rSet.Put( SvxEmphasisMarkItem( rFont.GetEmphasisMark(), EE_CHAR_EMPHASISMARK ) );
2620 rSet.Put( SvxCharReliefItem( rFont.GetRelief(), EE_CHAR_RELIEF ) );
2621}
2622
2623vcl::Font EditEngine::CreateFontFromItemSet( const SfxItemSet& rItemSet, SvtScriptType nScriptType )
2624{
2625 SvxFont aFont;
2626 CreateFont( aFont, rItemSet, true, nScriptType );
2627#if HAVE_P1155R30
2628 return aFont;
2629#else
2630 return std::move(aFont);
2631#endif
2632}
2633
2634SvxFont EditEngine::CreateSvxFontFromItemSet( const SfxItemSet& rItemSet )
2635{
2636 SvxFont aFont;
2637 CreateFont( aFont, rItemSet );
2638 return aFont;
2639}
2640
2641bool EditEngine::DoesKeyMoveCursor( const KeyEvent& rKeyEvent )
2642{
2643 bool bDoesMove = false;
2644
2645 switch ( rKeyEvent.GetKeyCode().GetCode() )
2646 {
2647 case KEY_UP:
2648 case KEY_DOWN:
2649 case KEY_LEFT:
2650 case KEY_RIGHT:
2651 case KEY_HOME:
2652 case KEY_END:
2653 case KEY_PAGEUP:
2654 case KEY_PAGEDOWN:
2655 {
2656 if ( !rKeyEvent.GetKeyCode().IsMod2() )
2657 bDoesMove = true;
2658 }
2659 break;
2660 }
2661 return bDoesMove;
2662}
2663
2664bool EditEngine::DoesKeyChangeText( const KeyEvent& rKeyEvent )
2665{
2666 bool bDoesChange = false;
2667
2668 KeyFuncType eFunc = rKeyEvent.GetKeyCode().GetFunction();
2669 if ( eFunc != KeyFuncType::DONTKNOW )
2670 {
2671 switch ( eFunc )
2672 {
2673 case KeyFuncType::UNDO:
2674 case KeyFuncType::REDO:
2675 case KeyFuncType::CUT:
2676 case KeyFuncType::PASTE: bDoesChange = true;
2677 break;
2678 default: // is then possibly edited below.
2679 eFunc = KeyFuncType::DONTKNOW;
2680 }
2681 }
2682 if ( eFunc == KeyFuncType::DONTKNOW )
2683 {
2684 switch ( rKeyEvent.GetKeyCode().GetCode() )
2685 {
2686 case KEY_DELETE:
2687 case KEY_BACKSPACE: bDoesChange = true;
2688 break;
2689 case KEY_RETURN:
2690 case KEY_TAB:
2691 {
2692 if ( !rKeyEvent.GetKeyCode().IsMod1() && !rKeyEvent.GetKeyCode().IsMod2() )
2693 bDoesChange = true;
2694 }
2695 break;
2696 default:
2697 {
2698 bDoesChange = IsSimpleCharInput( rKeyEvent );
2699 }
2700 }
2701 }
2702 return bDoesChange;
2703}
2704
2705bool EditEngine::IsSimpleCharInput( const KeyEvent& rKeyEvent )
2706{
2707 return EditEngine::IsPrintable( rKeyEvent.GetCharCode() ) &&
2708 ( KEY_MOD2 != (rKeyEvent.GetKeyCode().GetModifier() & ~KEY_SHIFT ) ) &&
2709 ( KEY_MOD1 != (rKeyEvent.GetKeyCode().GetModifier() & ~KEY_SHIFT ) );
2710}
2711
2712bool EditEngine::HasValidData( const css::uno::Reference< css::datatransfer::XTransferable >& rTransferable )
2713{
2714 bool bValidData = false;
2715
2716 if ( comphelper::LibreOfficeKit::isActive())
2717 return true;
2718
2719 if ( rTransferable.is() )
2720 {
2721 // Every application that copies rtf or any other text format also copies plain text into the clipboard...
2722 datatransfer::DataFlavor aFlavor;
2723 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
2724 bValidData = rTransferable->isDataFlavorSupported( aFlavor );
2725 }
2726
2727 return bValidData;
2728}
2729
2730/** sets a link that is called at the beginning of a drag operation at an edit view */
2731void EditEngine::SetBeginDropHdl( const Link<EditView*,void>& rLink )
2732{
2733 pImpEditEngine->SetBeginDropHdl( rLink );
2734}
2735
2736Link<EditView*,void> const & EditEngine::GetBeginDropHdl() const
2737{
2738 return pImpEditEngine->GetBeginDropHdl();
2739}
2740
2741/** sets a link that is called at the end of a drag operation at an edit view */
2742void EditEngine::SetEndDropHdl( const Link<EditView*,void>& rLink )
2743{
2744 pImpEditEngine->SetEndDropHdl( rLink );
2745}
2746
2747Link<EditView*,void> const & EditEngine::GetEndDropHdl() const
2748{
2749 return pImpEditEngine->GetEndDropHdl();
2750}
2751
2752void EditEngine::SetFirstWordCapitalization( bool bCapitalize )
2753{
2754 pImpEditEngine->SetFirstWordCapitalization( bCapitalize );
2755}
2756
2757void EditEngine::SetReplaceLeadingSingleQuotationMark( bool bReplace )
2758{
2759 pImpEditEngine->SetReplaceLeadingSingleQuotationMark( bReplace );
2760}
2761
2762bool EditEngine::IsHtmlImportHandlerSet() const
2763{
2764 return pImpEditEngine->aHtmlImportHdl.IsSet();
2765}
2766
2767bool EditEngine::IsRtfImportHandlerSet() const
2768{
2769 return pImpEditEngine->aRtfImportHdl.IsSet();
2770}
2771
2772bool EditEngine::IsImportRTFStyleSheetsSet() const
2773{
2774 return pImpEditEngine->GetStatus().DoImportRTFStyleSheets();
2775}
2776
2777void EditEngine::CallHtmlImportHandler(HtmlImportInfo& rInfo)
2778{
2779 pImpEditEngine->aHtmlImportHdl.Call(rInfo);
2780}
2781
2782void EditEngine::CallRtfImportHandler(RtfImportInfo& rInfo)
2783{
2784 pImpEditEngine->aRtfImportHdl.Call(rInfo);
2785}
2786
2787EditPaM EditEngine::InsertParaBreak(const EditSelection& rEditSelection)
2788{
2789 return pImpEditEngine->ImpInsertParaBreak(rEditSelection);
2790}
2791
2792EditPaM EditEngine::InsertLineBreak(const EditSelection& rEditSelection)
2793{
2794 return pImpEditEngine->InsertLineBreak(rEditSelection);
2795}
2796
2797sal_Int32 EditEngine::GetOverflowingParaNum() const {
2798 return pImpEditEngine->GetOverflowingParaNum();
2799}
2800
2801sal_Int32 EditEngine::GetOverflowingLineNum() const {
2802 return pImpEditEngine->GetOverflowingLineNum();
2803}
2804
2805void EditEngine::ClearOverflowingParaNum() {
2806 pImpEditEngine->ClearOverflowingParaNum();
2807}
2808
2809bool EditEngine::IsPageOverflow() {
2810 pImpEditEngine->CheckPageOverflow();
2811 return pImpEditEngine->IsPageOverflow();
2812}
2813
2814void EditEngine::DisableAttributeExpanding() {
2815 pImpEditEngine->GetEditDoc().DisableAttributeExpanding();
2816}
2817
2818void EditEngine::SetLOKSpecialPaperSize(const Size& rSize)
2819{
2820 pImpEditEngine->SetLOKSpecialPaperSize(rSize);
2821}
2822
2823const Size& EditEngine::GetLOKSpecialPaperSize() const
2824{
2825 return pImpEditEngine->GetLOKSpecialPaperSize();
2826}
2827
2828EFieldInfo::EFieldInfo()
2829{
2830}
2831
2832
2833EFieldInfo::EFieldInfo( const SvxFieldItem& rFieldItem, sal_Int32 nPara, sal_Int32 nPos ) :
2834 pFieldItem( new SvxFieldItem( rFieldItem ) ),
2835 aPosition( nPara, nPos )
2836{
2837}
2838
2839EFieldInfo::~EFieldInfo()
2840{
2841}
2842
2843EFieldInfo::EFieldInfo( const EFieldInfo& rFldInfo )
2844{
2845 *this = rFldInfo;
2846}
2847
2848EFieldInfo& EFieldInfo::operator= ( const EFieldInfo& rFldInfo )
2849{
2850 if( this == &rFldInfo )
2851 return *this;
2852
2853 pFieldItem.reset( rFldInfo.pFieldItem ? new SvxFieldItem( *rFldInfo.pFieldItem ) : nullptr );
2854 aCurrentText = rFldInfo.aCurrentText;
2855 aPosition = rFldInfo.aPosition;
2856
2857 return *this;
2858}
2859
2860/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#pragma once
20
21#include <eerdll2.hxx>
22#include <editdoc.hxx>
23#include "editsel.hxx"
24#include "editundo.hxx"
25#include "editstt2.hxx"
26#include <editeng/editdata.hxx>
27#include <editeng/SpellPortions.hxx>
28#include <editeng/editeng.hxx>
29#include <editeng/editview.hxx>
30#include <svtools/colorcfg.hxx>
31#include <editeng/outliner.hxx>
32#include <vcl/virdev.hxx>
33#include <vcl/cursor.hxx>
34#include <vcl/vclptr.hxx>
35#include <tools/fract.hxx>
36#include <vcl/idle.hxx>
37#include <vcl/commandevent.hxx>
38#include <vcl/ptrstyle.hxx>
39
40#include <vcl/dndhelp.hxx>
41#include <svl/ondemand.hxx>
42#include <svl/languageoptions.hxx>
43#include <com/sun/star/linguistic2/XSpellAlternatives.hpp>
44#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
45#include <com/sun/star/linguistic2/XHyphenator.hpp>
46#include <com/sun/star/lang/Locale.hpp>
47#include <com/sun/star/i18n/XBreakIterator.hpp>
48#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
49#include <com/sun/star/i18n/WordType.hpp>
50#include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp>
51#include <com/sun/star/uno/Sequence.hxx>
52
53#include <i18nlangtag/lang.h>
54#include <o3tl/deleter.hxx>
55#include <o3tl/typed_flags_set.hxx>
56
57#include <optional>
58#include <memory>
59#include <vector>
60
61class EditView;
62class EditEngine;
63class OutlinerSearchable;
64
65class SvxSearchItem;
66class SvxLRSpaceItem;
67class TextRanger;
68class SvKeyValueIterator;
69class SvxForbiddenCharactersTable;
70class SvtCTLOptions;
71namespace vcl { class Window; }
72class SvxNumberFormat;
73namespace com::sun::star::datatransfer::clipboard {
74 class XClipboard;
75}
76
77namespace editeng {
78 struct MisspellRanges;
79}
80
81#define DEL_LEFT1 1
82#define DEL_RIGHT2 2
83#define TRAVEL_X_DONTKNOW0xFFFFFFFF 0xFFFFFFFF
84#define CURSOR_BIDILEVEL_DONTKNOW0xFFFF 0xFFFF
85#define MAXCHARSINPARA0x3FFF-16 0x3FFF-CHARPOSGROW16 // Max 16K, because WYSIWYG array
86#define LINE_SEP'\x0A' '\x0A'
87
88#define ATTRSPECIAL_WHOLEWORD1 1
89#define ATTRSPECIAL_EDGE2 2
90
91enum class GetCursorFlags {
92 NONE = 0x0000,
93 TextOnly = 0x0001,
94 StartOfLine = 0x0002,
95 EndOfLine = 0x0004,
96 PreferPortionStart = 0x0008,
97};
98namespace o3tl {
99 template<> struct typed_flags<GetCursorFlags> : is_typed_flags<GetCursorFlags, 0x0f> {};
100}
101
102
103struct DragAndDropInfo
104{
105 tools::Rectangle aCurCursor;
106 tools::Rectangle aCurSavedCursor;
107 sal_uInt16 nSensibleRange;
108 sal_uInt16 nCursorWidth;
109 ESelection aBeginDragSel;
110 EditPaM aDropDest;
111 sal_Int32 nOutlinerDropDest;
112 ESelection aDropSel;
113 VclPtr<VirtualDevice> pBackground;
114 const SvxFieldItem* pField;
115 bool bVisCursor : 1;
116 bool bDroppedInMe : 1;
117 bool bStarterOfDD : 1;
118 bool bHasValidData : 1;
119 bool bUndoAction : 1;
120 bool bOutlinerMode : 1;
121 bool bDragAccepted : 1;
122
123 DragAndDropInfo()
124 : nSensibleRange(0), nCursorWidth(0), nOutlinerDropDest(0), pBackground(nullptr),
125 pField(nullptr), bVisCursor(false), bDroppedInMe(false), bStarterOfDD(false),
126 bHasValidData(false), bUndoAction(false), bOutlinerMode(false), bDragAccepted(false)
127 {
128 }
129 ~DragAndDropInfo()
130 {
131 pBackground.disposeAndClear();
132 }
133};
134
135struct ImplIMEInfos
136{
137 OUString aOldTextAfterStartPos;
138 std::unique_ptr<ExtTextInputAttr[]> pAttribs;
139 EditPaM aPos;
140 sal_Int32 nLen;
141 bool bWasCursorOverwrite;
142
143 ImplIMEInfos( const EditPaM& rPos, const OUString& rOldTextAfterStartPos );
144 ~ImplIMEInfos();
145
146 void CopyAttribs( const ExtTextInputAttr* pA, sal_uInt16 nL );
147 void DestroyAttribs();
148};
149
150// #i18881# to be able to identify the positions of changed words
151// the positions of each portion need to be saved
152typedef std::vector<EditSelection> SpellContentSelections;
153
154struct SpellInfo
155{
156 EESpellState eState;
157 EPaM aSpellStart;
158 EPaM aSpellTo;
159 EditPaM aCurSentenceStart;
160 bool bSpellToEnd;
161 bool bMultipleDoc;
162 svx::SpellPortions aLastSpellPortions;
163 SpellContentSelections aLastSpellContentSelections;
164 SpellInfo() : eState(EESpellState::Ok), bSpellToEnd(true), bMultipleDoc(false)
165 { }
166};
167
168// used for text conversion
169struct ConvInfo
170{
171 EPaM aConvStart;
172 EPaM aConvTo;
173 EPaM aConvContinue; // position to start search for next text portion (word) with
174 bool bConvToEnd;
175 bool bMultipleDoc;
176
177 ConvInfo() : bConvToEnd(true), bMultipleDoc(false) {}
178};
179
180struct FormatterFontMetric
181{
182 sal_uInt16 nMaxAscent;
183 sal_uInt16 nMaxDescent;
184
185 FormatterFontMetric() : nMaxAscent(0), nMaxDescent(0) { /* nMinLeading = 0xFFFF; */ }
186 sal_uInt16 GetHeight() const { return nMaxAscent+nMaxDescent; }
187};
188
189class IdleFormattter : public Idle
190{
191private:
192 EditView* pView;
193 int nRestarts;
194
195public:
196 IdleFormattter();
197 virtual ~IdleFormattter() override;
198
199 void DoIdleFormat( EditView* pV );
200 void ForceTimeout();
201 void ResetRestarts() { nRestarts = 0; }
202 EditView* GetView() { return pView; }
203};
204
205class ImpEditView;
206/// This is meant just for Calc, where all positions in logical units (twips for LOK) are computed by
207/// doing independent pixel-alignment for each cell's size. LOKSpecialPositioning stores
208/// both 'output-area' and 'visible-doc-position' in pure logical unit (twips for LOK).
209/// This allows the cursor/selection messages to be in regular(print) twips unit like in Writer.
210class LOKSpecialPositioning
211{
212public:
213 LOKSpecialPositioning(const ImpEditView& rImpEditView, MapUnit eUnit, const tools::Rectangle& rOutputArea,
214 const Point& rVisDocStartPos);
215
216 void ReInit(MapUnit eUnit, const tools::Rectangle& rOutputArea, const Point& rVisDocStartPos);
217
218 void SetOutputArea(const tools::Rectangle& rOutputArea);
219 const tools::Rectangle& GetOutputArea() const;
220 void SetVisDocStartPos(const Point& rVisDocStartPos);
221
222 bool IsVertical() const;
223 bool IsTopToBottom() const;
224
225 long GetVisDocLeft() const { return maVisDocStartPos.X(); }
226 long GetVisDocTop() const { return maVisDocStartPos.Y(); }
227 long GetVisDocRight() const { return maVisDocStartPos.X() + (!IsVertical() ? maOutArea.GetWidth() : maOutArea.GetHeight()); }
228 long GetVisDocBottom() const { return maVisDocStartPos.Y() + (!IsVertical() ? maOutArea.GetHeight() : maOutArea.GetWidth()); }
229 tools::Rectangle GetVisDocArea() const;
230
231 Point GetWindowPos(const Point& rDocPos, MapUnit eDocPosUnit) const;
232 tools::Rectangle GetWindowPos(const tools::Rectangle& rDocRect, MapUnit eDocRectUnit) const;
233
234 Point GetRefPoint() const;
235
236private:
237 Point convertUnit(const Point& rPos, MapUnit ePosUnit) const;
238 tools::Rectangle convertUnit(const tools::Rectangle& rRect, MapUnit eRectUnit) const;
239
240 const ImpEditView& mrImpEditView;
241 tools::Rectangle maOutArea;
242 Point maVisDocStartPos;
243 MapUnit meUnit;
244};
245
246
247
248class ImpEditView : public vcl::unohelper::DragAndDropClient
249{
250 friend class EditView;
251 friend class EditEngine;
252 friend class ImpEditEngine;
253 using vcl::unohelper::DragAndDropClient::dragEnter;
254 using vcl::unohelper::DragAndDropClient::dragExit;
255 using vcl::unohelper::DragAndDropClient::dragOver;
256
257private:
258 EditView* pEditView;
259 std::unique_ptr<vcl::Cursor, o3tl::default_delete<vcl::Cursor>> pCursor;
260 std::unique_ptr<Color> pBackgroundColor;
261 /// Containing view shell, if any.
262 OutlinerViewShell* mpViewShell;
263 /// Another shell, just listening to our state, if any.
264 OutlinerViewShell* mpOtherShell;
265 EditEngine* pEditEngine;
266 VclPtr<vcl::Window> pOutWin;
267 EditView::OutWindowSet aOutWindowSet;
268 std::optional<PointerStyle> mxPointer;
269 std::unique_ptr<DragAndDropInfo> pDragAndDropInfo;
270
271 css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
272
273
274 long nInvMore;
275 EVControlBits nControl;
276 sal_uInt32 nTravelXPos;
277 GetCursorFlags nExtraCursorFlags;
278 sal_uInt16 nCursorBidiLevel;
279 sal_uInt16 nScrollDiffX;
280 bool bReadOnly;
281 bool bClickedInSelection;
282 bool bActiveDragAndDropListener;
283
284 Point aAnchorPoint;
285 tools::Rectangle aOutArea;
286 Point aVisDocStartPos;
287 EESelectionMode eSelectionMode;
288 EditSelection aEditSelection;
289 EEAnchorMode eAnchorMode;
290
291 /// mechanism to change from the classic refresh mode that simply
292 // invalidates the area where text was changed. When set, the invalidate
293 // and the direct repaint of the Window-plugged EditView will be suppressed.
294 // Instead, a consumer that has registered using an EditViewCallbacks
295 // incarnation has to handle that. Used e.g. to represent the edited text
296 // in Draw/Impress in an OverlayObject which avoids evtl. expensive full
297 // repaints of the EditView(s)
298 EditViewCallbacks* mpEditViewCallbacks;
299 std::unique_ptr<LOKSpecialPositioning> mpLOKSpecialPositioning;
300 bool mbBroadcastLOKViewCursor:1;
301 bool mbSuppressLOKMessages:1;
302
303 EditViewCallbacks* getEditViewCallbacks() const
304 {
305 return mpEditViewCallbacks;
306 }
307
308 void lokSelectionCallback(const std::unique_ptr<tools::PolyPolygon> &pPolyPoly, bool bStartHandleVisible, bool bEndHandleVisible);
309
310 void setEditViewCallbacks(EditViewCallbacks* pEditViewCallbacks)
311 {
312 mpEditViewCallbacks = pEditViewCallbacks;
313 }
314
315 void InvalidateAtWindow(const tools::Rectangle& rRect);
316
317 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const;
318 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetSelection() const;
319
320 void SetBroadcastLOKViewCursor(bool bSet)
321 {
322 mbBroadcastLOKViewCursor = bSet;
323 }
324
325protected:
326
327 // DragAndDropClient
328 void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
329 void dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent& dsde ) override;
330 void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
331 void dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) override;
332 void dragExit( const css::datatransfer::dnd::DropTargetEvent& dte ) override;
333 void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
334
335 void ShowDDCursor( const tools::Rectangle& rRect );
336 void HideDDCursor();
337
338 void ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly );
339 tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags nShowCursorFlags,
340 sal_Int32& nTextPortionStart, const ParaPortion* pParaPortion) const;
341
342public:
343 ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindow );
344 virtual ~ImpEditView() override;
345
346 EditView* GetEditViewPtr() { return pEditView; }
347
348 sal_uInt16 GetScrollDiffX() const { return nScrollDiffX; }
349 void SetScrollDiffX( sal_uInt16 n ) { nScrollDiffX = n; }
350
351 sal_uInt16 GetCursorBidiLevel() const { return nCursorBidiLevel; }
352 void SetCursorBidiLevel( sal_uInt16 n ) { nCursorBidiLevel = n; }
353
354 Point GetDocPos( const Point& rWindowPos ) const;
355 Point GetWindowPos( const Point& rDocPos ) const;
356 tools::Rectangle GetWindowPos( const tools::Rectangle& rDocPos ) const;
357
358 void SetOutputArea( const tools::Rectangle& rRect );
359 void ResetOutputArea( const tools::Rectangle& rRect );
360 const tools::Rectangle& GetOutputArea() const { return aOutArea; }
361
362 bool IsVertical() const;
363 bool IsTopToBottom() const;
364
365 bool PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * pFrameWin );
366
367 bool MouseButtonUp( const MouseEvent& rMouseEvent );
368 bool MouseButtonDown( const MouseEvent& rMouseEvent );
369 void ReleaseMouse();
370 bool MouseMove( const MouseEvent& rMouseEvent );
371 void Command( const CommandEvent& rCEvt );
372
373 void CutCopy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bCut );
374 void Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial = false );
375
376 void SetVisDocStartPos( const Point& rPos ) { aVisDocStartPos = rPos; }
377
378 long GetVisDocLeft() const { return aVisDocStartPos.X(); }
379 long GetVisDocTop() const { return aVisDocStartPos.Y(); }
380 long GetVisDocRight() const { return aVisDocStartPos.X() + ( !IsVertical() ? aOutArea.GetWidth() : aOutArea.GetHeight() ); }
381 long GetVisDocBottom() const { return aVisDocStartPos.Y() + ( !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth() ); }
382 tools::Rectangle GetVisDocArea() const;
383
384 const EditSelection& GetEditSelection() const { return aEditSelection; }
385 void SetEditSelection( const EditSelection& rEditSelection );
386 bool HasSelection() const { return aEditSelection.HasRange(); }
387
388 void SelectionChanged();
389 void DrawSelectionXOR() { DrawSelectionXOR( aEditSelection ); }
390 void DrawSelectionXOR( EditSelection, vcl::Region* pRegion = nullptr, OutputDevice* pTargetDevice = nullptr );
391 void GetSelectionRectangles(EditSelection aTmpSel, std::vector<tools::Rectangle>& rLogicRects);
392
393 vcl::Window* GetWindow() const { return pOutWin; }
394
395 void SetSelectionMode( EESelectionMode eMode );
396
397 inline PointerStyle GetPointer();
398
399 inline vcl::Cursor* GetCursor();
400
401 void AddDragAndDropListeners();
402 void RemoveDragAndDropListeners();
403
404 bool IsBulletArea( const Point& rPos, sal_Int32* pPara );
405
406// For the Selection Engine...
407 void CreateAnchor();
408 void DeselectAll();
409 bool SetCursorAtPoint( const Point& rPointPixel );
410 bool IsSelectionAtPoint( const Point& rPosPixel );
411 bool IsInSelection( const EditPaM& rPaM );
412
413
414 void SetAnchorMode( EEAnchorMode eMode );
415 EEAnchorMode GetAnchorMode() const { return eAnchorMode; }
416 void CalcAnchorPoint();
417 void RecalcOutputArea();
418
419 tools::Rectangle GetEditCursor() const;
420
421 void ShowCursor( bool bGotoCursor, bool bForceVisCursor );
422 Pair Scroll( long ndX, long ndY, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );
423
424 void SetInsertMode( bool bInsert );
425 bool IsInsertMode() const { return !( nControl & EVControlBits::OVERWRITE ); }
426
427 bool IsPasteEnabled() const { return bool( nControl & EVControlBits::ENABLEPASTE ); }
428
429 bool DoSingleLinePaste() const { return bool( nControl & EVControlBits::SINGLELINEPASTE ); }
430 bool DoAutoScroll() const { return bool( nControl & EVControlBits::AUTOSCROLL ); }
431 bool DoAutoSize() const { return bool( nControl & EVControlBits::AUTOSIZE ); }
432 bool DoAutoWidth() const { return bool( nControl & EVControlBits::AUTOSIZEX); }
433 bool DoAutoHeight() const { return bool( nControl & EVControlBits::AUTOSIZEY); }
434 bool DoInvalidateMore() const { return bool( nControl & EVControlBits::INVONEMORE ); }
435
436 void SetBackgroundColor( const Color& rColor );
437 const Color& GetBackgroundColor() const {
438 return ( pBackgroundColor ? *pBackgroundColor : pOutWin->GetBackground().GetColor() ); }
439
440 /// Informs this edit view about which view shell contains it.
441 void RegisterViewShell(OutlinerViewShell* pViewShell);
442 const OutlinerViewShell* GetViewShell() const;
443 /// Informs this edit view about which other shell listens to it.
444 void RegisterOtherShell(OutlinerViewShell* pViewShell);
445
446 bool IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong );
447 OUString SpellIgnoreWord();
448
449 const SvxFieldItem* GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const;
450 void DeleteSelected();
451
452 // If possible invalidate more than OutputArea, for the DrawingEngine text frame
453 void SetInvalidateMore( sal_uInt16 nPixel ) { nInvMore = nPixel; }
454 sal_uInt16 GetInvalidateMore() const { return static_cast<sal_uInt16>(nInvMore); }
455
456 void InitLOKSpecialPositioning(MapUnit eUnit, const tools::Rectangle& rOutputArea,
457 const Point& rVisDocStartPos);
458 void SetLOKSpecialOutputArea(const tools::Rectangle& rOutputArea);
459 tools::Rectangle GetLOKSpecialOutputArea() const;
460 void SetLOKSpecialVisArea(const tools::Rectangle& rVisArea);
461 tools::Rectangle GetLOKSpecialVisArea() const;
462 bool HasLOKSpecialPositioning() const;
463
464 void SuppressLOKMessages(bool bSet) { mbSuppressLOKMessages = bSet; }
465 bool IsSuppressLOKMessages() const { return mbSuppressLOKMessages; }
466};
467
468
469// ImpEditEngine
470
471
472class ImpEditEngine : public SfxListener
473{
474 friend class EditEngine;
475
476 typedef EditEngine::ViewsType ViewsType;
477
478private:
479 std::shared_ptr<editeng::SharedVclResources> pSharedVCL;
480
481
482 // Data ...
483
484
485 // Document Specific data ...
486 ParaPortionList aParaPortionList; // Formatting
487 Size aPaperSize; // Layout
488 Size aMinAutoPaperSize; // Layout ?
489 Size aMaxAutoPaperSize; // Layout ?
490 EditDoc aEditDoc; // Document content
491
492 // Engine Specific data ...
493 EditEngine* pEditEngine;
494 ViewsType aEditViews;
495 EditView* pActiveView;
496 std::unique_ptr<TextRanger> pTextRanger;
497
498 SfxStyleSheetPool* pStylePool;
499 SfxItemPool* pTextObjectPool;
500
501 VclPtr< VirtualDevice> pVirtDev;
502 VclPtr< OutputDevice > pRefDev;
503 VclPtr<VirtualDevice> mpOwnDev;
504
505 svtools::ColorConfig maColorConfig;
506 mutable std::unique_ptr<SvtCTLOptions> pCTLOptions;
507
508 mutable std::unique_ptr<SfxItemSet> pEmptyItemSet;
509 EditUndoManager* pUndoManager;
510 std::unique_ptr<ESelection> pUndoMarkSelection;
511
512 std::unique_ptr<ImplIMEInfos> mpIMEInfos;
513
514 OUString aWordDelimiters;
515
516 EditSelFunctionSet aSelFuncSet;
517 EditSelectionEngine aSelEngine;
518
519 Color maBackgroundColor;
520
521 sal_uInt16 nStretchX;
522 sal_uInt16 nStretchY;
523
524 CharCompressType nAsianCompressionMode;
525
526 EEHorizontalTextDirection eDefaultHorizontalTextDirection;
527
528 sal_Int32 nBigTextObjectStart;
529 css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpeller;
530 css::uno::Reference< css::linguistic2::XHyphenator > xHyphenator;
531 std::unique_ptr<SpellInfo> pSpellInfo;
532 mutable css::uno::Reference < css::i18n::XBreakIterator > xBI;
533 mutable css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC;
534
535 std::unique_ptr<ConvInfo> pConvInfo;
536
537 OUString aAutoCompleteText;
538
539 InternalEditStatus aStatus;
540
541 LanguageType eDefLanguage;
542
543 OnDemandLocaleDataWrapper xLocaleDataWrapper;
544 OnDemandTransliterationWrapper xTransliterationWrapper;
545
546 // For Formatting / Update...
547 std::vector<std::unique_ptr<DeletedNodeInfo> > aDeletedNodes;
548 tools::Rectangle aInvalidRect;
549 sal_uInt32 nCurTextHeight;
550 sal_uInt32 nCurTextHeightNTP; // without trailing empty paragraphs
551 sal_uInt16 nOnePixelInRef;
552
553 IdleFormattter aIdleFormatter;
554
555 Timer aOnlineSpellTimer;
556
557 // For Chaining
558 sal_Int32 mnOverflowingPara = -1;
559 sal_Int32 mnOverflowingLine = -1;
560 bool mbNeedsChainingHandling = false;
561
562 // If it is detected at one point that the StatusHdl has to be called, but
563 // this should not happen immediately (critical section):
564 Timer aStatusTimer;
565 Size aLOKSpecialPaperSize;
566
567 Link<EditStatus&,void> aStatusHdlLink;
568 Link<EENotify&,void> aNotifyHdl;
569 Link<HtmlImportInfo&,void> aHtmlImportHdl;
570 Link<RtfImportInfo&,void> aRtfImportHdl;
571 Link<MoveParagraphsInfo&,void> aBeginMovingParagraphsHdl;
572 Link<MoveParagraphsInfo&,void> aEndMovingParagraphsHdl;
573 Link<PasteOrDropInfos&,void> aBeginPasteOrDropHdl;
574 Link<PasteOrDropInfos&,void> aEndPasteOrDropHdl;
575 Link<LinkParamNone*,void> aModifyHdl;
576 Link<EditView*,void> maBeginDropHdl;
577 Link<EditView*,void> maEndDropHdl;
578
579 bool bKernAsianPunctuation:1;
580 bool bAddExtLeading:1;
581 bool bIsFormatting:1;
582 bool bFormatted:1;
583 bool bInSelection:1;
584 bool bIsInUndo:1;
585 bool bUpdate:1;
586 bool bUndoEnabled:1;
587 bool bDowning:1;
588 bool bUseAutoColor:1;
589 bool bForceAutoColor:1;
590 bool bCallParaInsertedOrDeleted:1;
591 bool bFirstWordCapitalization:1; // specifies if auto-correction should capitalize the first word or not
592 bool mbLastTryMerge:1;
593 bool mbReplaceLeadingSingleQuotationMark:1;
594
595 bool mbNbspRunNext; // can't be a bitfield as it is passed as bool&
596
597
598 // Methods...
599
600
601 void CursorMoved( const ContentNode* pPrevNode );
602 void ParaAttribsChanged( ContentNode const * pNode, bool bIgnoreUndoCheck = false );
603 void TextModified();
604 void CalcHeight( ParaPortion* pPortion );
605
606 void InsertUndo( std::unique_ptr<EditUndo> pUndo, bool bTryMerge = false );
607 void ResetUndoManager();
608 bool HasUndoManager() const { return pUndoManager != nullptr; }
609
610 std::unique_ptr<EditUndoSetAttribs> CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet );
611
612 std::unique_ptr<EditTextObject> GetEmptyTextObject();
613
614 EditPaM GetPaM( Point aDocPos, bool bSmart = true );
615 EditPaM GetPaM( ParaPortion* pPortion, Point aPos, bool bSmart );
616 long GetXPos(const ParaPortion* pParaPortion, const EditLine* pLine, sal_Int32 nIndex, bool bPreferPortionStart = false) const;
617 long GetPortionXOffset(const ParaPortion* pParaPortion, const EditLine* pLine, sal_Int32 nTextPortion) const;
618 sal_Int32 GetChar(const ParaPortion* pParaPortion, const EditLine* pLine, long nX, bool bSmart = true);
619 Range GetInvalidYOffsets( ParaPortion* pPortion );
620 Range GetLineXPosStartEnd( const ParaPortion* pParaPortion, const EditLine* pLine ) const;
621
622 void ParaAttribsToCharAttribs( ContentNode* pNode );
623 void GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const;
624
625 std::unique_ptr<EditTextObject>
626 CreateTextObject(EditSelection aSelection, SfxItemPool*, bool bAllowBigObjects = false, sal_Int32 nBigObjStart = 0);
627 EditSelection InsertTextObject( const EditTextObject&, EditPaM aPaM );
628 EditSelection PasteText( css::uno::Reference< css::datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial );
629
630 void CheckPageOverflow();
631
632 void Clear();
633 EditPaM RemoveText();
634 bool CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY );
635 void CreateAndInsertEmptyLine( ParaPortion* pParaPortion );
636 bool FinishCreateLines( ParaPortion* pParaPortion );
637 void CreateTextPortions( ParaPortion* pParaPortion, sal_Int32& rStartPos /*, sal_Bool bCreateBlockPortions */ );
638 void RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nStartPos, sal_Int32 nNewChars );
639 sal_Int32 SplitTextPortion( ParaPortion* pParaPortion, sal_Int32 nPos, EditLine* pCurLine = nullptr );
640 void SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFont, OutputDevice* pOut = nullptr );
641 void RecalcFormatterFontMetrics( FormatterFontMetric& rCurMetrics, SvxFont& rFont );
642 void CheckAutoPageSize();
643
644 void ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, TextPortion const * pPortion, sal_Int32 nPortionStart, long nRemainingWidth, bool bCanHyphenate );
645 void ImpAdjustBlocks( ParaPortion* pParaPortion, EditLine* pLine, long nRemainingSpace );
646 EditPaM ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pRight, bool bBackward = false );
647 EditPaM ImpDeleteSelection(const EditSelection& rCurSel);
648 EditPaM ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttribs = true );
649 EditPaM ImpInsertParaBreak( const EditSelection& rEditSelection );
650 EditPaM ImpInsertText(const EditSelection& aCurEditSelection, const OUString& rStr);
651 EditPaM ImpInsertFeature(const EditSelection& rCurSel, const SfxPoolItem& rItem);
652 void ImpRemoveChars( const EditPaM& rPaM, sal_Int32 nChars );
653 void ImpRemoveParagraph( sal_Int32 nPara );
654 EditSelection ImpMoveParagraphs( Range aParagraphs, sal_Int32 nNewPos );
655
656 EditPaM ImpFastInsertText( EditPaM aPaM, const OUString& rStr );
657 EditPaM ImpFastInsertParagraph( sal_Int32 nPara );
658
659 bool ImpCheckRefMapMode();
660
661 bool ImplHasText() const;
662
663 void ImpFindKashidas( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, std::vector<sal_Int32>& rArray );
664
665 void InsertContent( ContentNode* pNode, sal_Int32 nPos );
666 EditPaM SplitContent( sal_Int32 nNode, sal_Int32 nSepPos );
667 EditPaM ConnectContents( sal_Int32 nLeftNode, bool bBackward );
668
669 void ShowParagraph( sal_Int32 nParagraph, bool bShow );
670
671 EditPaM PageUp( const EditPaM& rPaM, EditView const * pView);
672 EditPaM PageDown( const EditPaM& rPaM, EditView const * pView);
673 EditPaM CursorUp( const EditPaM& rPaM, EditView const * pEditView );
674 EditPaM CursorDown( const EditPaM& rPaM, EditView const * pEditView );
675 EditPaM CursorLeft( const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode = css::i18n::CharacterIteratorMode::SKIPCELL );
676 EditPaM CursorRight( const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode = css::i18n::CharacterIteratorMode::SKIPCELL );
677 EditPaM CursorStartOfLine( const EditPaM& rPaM );
678 EditPaM CursorEndOfLine( const EditPaM& rPaM );
679 static EditPaM CursorStartOfParagraph( const EditPaM& rPaM );
680 static EditPaM CursorEndOfParagraph( const EditPaM& rPaM );
681 EditPaM CursorStartOfDoc();
682 EditPaM CursorEndOfDoc();
683 EditPaM WordLeft( const EditPaM& rPaM );
684 EditPaM WordRight( const EditPaM& rPaM, sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
685 EditPaM StartOfWord( const EditPaM& rPaM );
686 EditPaM EndOfWord( const EditPaM& rPaM );
687 EditSelection SelectWord( const EditSelection& rCurSelection, sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, bool bAcceptStartOfWord = true );
688 EditSelection SelectSentence( const EditSelection& rCurSel ) const;
689 EditPaM CursorVisualLeftRight( EditView const * pEditView, const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode, bool bToLeft );
690 EditPaM CursorVisualStartEnd( EditView const * pEditView, const EditPaM& rPaM, bool bStart );
691
692
693 void InitScriptTypes( sal_Int32 nPara );
694 sal_uInt16 GetI18NScriptType( const EditPaM& rPaM, sal_Int32* pEndPos = nullptr ) const;
695 SvtScriptType GetItemScriptType( const EditSelection& rSel ) const;
696 bool IsScriptChange( const EditPaM& rPaM ) const;
697 bool HasScriptType( sal_Int32 nPara, sal_uInt16 nType ) const;
698
699 bool ImplCalcAsianCompression( ContentNode* pNode, TextPortion* pTextPortion, sal_Int32 nStartPos,
700 long* pDXArray, sal_uInt16 n100thPercentFromMax, bool bManipulateDXArray );
701 void ImplExpandCompressedPortions( EditLine* pLine, ParaPortion* pParaPortion, long nRemainingWidth );
702
703 void ImplInitLayoutMode( OutputDevice* pOutDev, sal_Int32 nPara, sal_Int32 nIndex );
704 LanguageType ImplCalcDigitLang(LanguageType eCurLang) const;
705 void ImplInitDigitMode(OutputDevice* pOutDev, LanguageType eLang);
706 static OUString convertDigits(const OUString &rString, sal_Int32 nStt, sal_Int32 nLen, LanguageType eDigitLang);
707
708 EditPaM ReadText( SvStream& rInput, EditSelection aSel );
709 EditPaM ReadRTF( SvStream& rInput, EditSelection aSel );
710 EditPaM ReadXML( SvStream& rInput, EditSelection aSel );
711 EditPaM ReadHTML( SvStream& rInput, const OUString& rBaseURL, EditSelection aSel, SvKeyValueIterator* pHTTPHeaderAttrs );
712 ErrCode WriteText( SvStream& rOutput, EditSelection aSel );
713 ErrCode WriteRTF( SvStream& rOutput, EditSelection aSel );
714 void WriteXML(SvStream& rOutput, const EditSelection& rSel);
715
716 void WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput, sal_Int32 nPara, sal_Int32 nPos,
717 std::vector<std::unique_ptr<SvxFontItem>>& rFontTable, SvxColorList& rColorList );
718 bool WriteItemListAsRTF( ItemList& rLst, SvStream& rOutput, sal_Int32 nPara, sal_Int32 nPos,
719 std::vector<std::unique_ptr<SvxFontItem>>& rFontTable, SvxColorList& rColorList );
720 sal_Int32 LogicToTwips( sal_Int32 n );
721
722 inline short GetXValue( short nXValue ) const;
723 inline long GetXValue( long nXValue ) const;
724
725 inline short GetYValue( short nYValue ) const;
726 inline sal_uInt16 GetYValue( sal_uInt16 nYValue ) const;
727
728 ContentNode* GetPrevVisNode( ContentNode const * pCurNode );
729 ContentNode* GetNextVisNode( ContentNode const * pCurNode );
730
731 const ParaPortion* GetPrevVisPortion( const ParaPortion* pCurPortion ) const;
732 const ParaPortion* GetNextVisPortion( const ParaPortion* pCurPortion ) const;
733
734 void SetBackgroundColor( const Color& rColor ) { maBackgroundColor = rColor; }
735 const Color& GetBackgroundColor() const { return maBackgroundColor; }
736
737 long CalcVertLineSpacing(Point& rStartPos) const;
738
739 Color GetAutoColor() const;
740 void EnableAutoColor( bool b ) { bUseAutoColor = b; }
741 bool IsAutoColorEnabled() const { return bUseAutoColor; }
742 void ForceAutoColor( bool b ) { bForceAutoColor = b; }
743 bool IsForceAutoColor() const { return bForceAutoColor; }
744
745 inline VirtualDevice* GetVirtualDevice( const MapMode& rMapMode, DrawModeFlags nDrawMode );
746 void EraseVirtualDevice() { pVirtDev.disposeAndClear(); }
2
Calling 'VclPtr::disposeAndClear'
747
748 DECL_LINK( StatusTimerHdl, Timer *, void)static void LinkStubStatusTimerHdl(void *, Timer *); void StatusTimerHdl
(Timer *)
;
749 DECL_LINK( IdleFormatHdl, Timer *, void)static void LinkStubIdleFormatHdl(void *, Timer *); void IdleFormatHdl
(Timer *)
;
750 DECL_LINK( OnlineSpellHdl, Timer *, void)static void LinkStubOnlineSpellHdl(void *, Timer *); void OnlineSpellHdl
(Timer *)
;
751 DECL_LINK( DocModified, LinkParamNone*, void )static void LinkStubDocModified(void *, LinkParamNone*); void
DocModified(LinkParamNone*)
;
752
753 void CheckIdleFormatter();
754
755 inline const ParaPortion* FindParaPortion( const ContentNode* pNode ) const;
756 inline ParaPortion* FindParaPortion( ContentNode const * pNode );
757
758 css::uno::Reference< css::datatransfer::XTransferable > CreateTransferable( const EditSelection& rSelection );
759
760 void SetValidPaperSize( const Size& rSz );
761
762 css::uno::Reference < css::i18n::XBreakIterator > const & ImplGetBreakIterator() const;
763 css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker() const;
764
765 void ImplUpdateOverflowingParaNum( sal_uInt32 );
766 void ImplUpdateOverflowingLineNum( sal_uInt32, sal_uInt32, sal_uInt32 );
767
768 void CreateSpellInfo( bool bMultipleDocs );
769 /// Obtains a view shell ID from the active EditView.
770 ViewShellId CreateViewShellId();
771
772 ImpEditEngine(EditEngine* pEditEngine, SfxItemPool* pPool);
773 void InitDoc(bool bKeepParaAttribs);
774 EditDoc& GetEditDoc() { return aEditDoc; }
775 const EditDoc& GetEditDoc() const { return aEditDoc; }
776
777 const ParaPortionList& GetParaPortions() const { return aParaPortionList; }
778 ParaPortionList& GetParaPortions() { return aParaPortionList; }
779
780protected:
781 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
782
783public:
784 virtual ~ImpEditEngine() override;
785 ImpEditEngine(const ImpEditEngine&) = delete;
786 ImpEditEngine& operator=(const ImpEditEngine&) = delete;
787
788 inline EditUndoManager& GetUndoManager();
789 inline SfxUndoManager* SetUndoManager(SfxUndoManager* pNew);
790
791 void SetUpdateMode( bool bUp, EditView* pCurView = nullptr, bool bForceUpdate = false );
792 bool GetUpdateMode() const { return bUpdate; }
793
794 ViewsType& GetEditViews() { return aEditViews; }
795 const ViewsType& GetEditViews() const { return aEditViews; }
796
797 const Size& GetPaperSize() const { return aPaperSize; }
798 void SetPaperSize( const Size& rSz ) { aPaperSize = rSz; }
799
800 void SetVertical( bool bVertical);
801 bool IsVertical() const { return GetEditDoc().IsVertical(); }
802 bool IsTopToBottom() const { return GetEditDoc().IsTopToBottom(); }
803 bool GetDirectVertical() const { return GetEditDoc().GetDirectVertical(); }
804 void SetRotation( TextRotation nRotation);
805 TextRotation GetRotation() const { return GetEditDoc().GetRotation(); }
806
807 bool IsPageOverflow( ) const;
808
809 void SetFixedCellHeight( bool bUseFixedCellHeight );
810 bool IsFixedCellHeight() const { return GetEditDoc().IsFixedCellHeight(); }
811
812 void SetDefaultHorizontalTextDirection( EEHorizontalTextDirection eHTextDir ) { eDefaultHorizontalTextDirection = eHTextDir; }
813 EEHorizontalTextDirection GetDefaultHorizontalTextDirection() const { return eDefaultHorizontalTextDirection; }
814
815
816 void InitWritingDirections( sal_Int32 nPara );
817 bool IsRightToLeft( sal_Int32 nPara ) const;
818 sal_uInt8 GetRightToLeft( sal_Int32 nPara, sal_Int32 nChar, sal_Int32* pStart = nullptr, sal_Int32* pEnd = nullptr );
819 bool HasDifferentRTLLevels( const ContentNode* pNode );
820
821 void SetTextRanger( std::unique_ptr<TextRanger> pRanger );
822 TextRanger* GetTextRanger() const { return pTextRanger.get(); }
823
824 const Size& GetMinAutoPaperSize() const { return aMinAutoPaperSize; }
825 void SetMinAutoPaperSize( const Size& rSz ) { aMinAutoPaperSize = rSz; }
826
827 const Size& GetMaxAutoPaperSize() const { return aMaxAutoPaperSize; }
828 void SetMaxAutoPaperSize( const Size& rSz ) { aMaxAutoPaperSize = rSz; }
829
830 void FormatDoc();
831 void FormatFullDoc();
832 void UpdateViews( EditView* pCurView = nullptr );
833 void Paint( ImpEditView* pView, const tools::Rectangle& rRect, OutputDevice* pTargetDevice );
834 void Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Point aStartPos, bool bStripOnly = false, short nOrientation = 0 );
835
836 bool MouseButtonUp( const MouseEvent& rMouseEvent, EditView* pView );
837 bool MouseButtonDown( const MouseEvent& rMouseEvent, EditView* pView );
838 void ReleaseMouse();
839 bool MouseMove( const MouseEvent& rMouseEvent, EditView* pView );
840 void Command( const CommandEvent& rCEvt, EditView* pView );
841
842 EditSelectionEngine& GetSelEngine() { return aSelEngine; }
843 OUString GetSelected( const EditSelection& rSel ) const;
844
845 const SfxItemSet& GetEmptyItemSet() const;
846
847 void UpdateSelections();
848
849 void EnableUndo( bool bEnable );
850 bool IsUndoEnabled() const { return bUndoEnabled; }
851 void SetUndoMode( bool b ) { bIsInUndo = b; }
852 bool IsInUndo() const { return bIsInUndo; }
853
854 void SetCallParaInsertedOrDeleted( bool b ) { bCallParaInsertedOrDeleted = b; }
855 bool IsCallParaInsertedOrDeleted() const { return bCallParaInsertedOrDeleted; }
856
857 bool IsFormatted() const { return bFormatted; }
858 bool IsFormatting() const { return bIsFormatting; }
859
860 void SetText(const OUString& rText);
861 EditPaM DeleteSelected(const EditSelection& rEditSelection);
862 EditPaM InsertTextUserInput( const EditSelection& rCurEditSelection, sal_Unicode c, bool bOverwrite );
863 EditPaM InsertText(const EditSelection& aCurEditSelection, const OUString& rStr);
864 EditPaM AutoCorrect( const EditSelection& rCurEditSelection, sal_Unicode c, bool bOverwrite, vcl::Window const * pFrameWin = nullptr );
865 EditPaM DeleteLeftOrRight( const EditSelection& rEditSelection, sal_uInt8 nMode, DeleteMode nDelMode );
866 EditPaM InsertParaBreak(const EditSelection& rEditSelection);
867 EditPaM InsertLineBreak(const EditSelection& aEditSelection);
868 EditPaM InsertTab(const EditSelection& rEditSelection);
869 EditPaM InsertField(const EditSelection& rCurSel, const SvxFieldItem& rFld);
870 bool UpdateFields();
871
872 EditPaM Read(SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, const EditSelection& rSel, SvKeyValueIterator* pHTTPHeaderAttrs = nullptr);
873 void Write(SvStream& rOutput, EETextFormat eFormat, const EditSelection& rSel);
874
875 std::unique_ptr<EditTextObject> CreateTextObject();
876 std::unique_ptr<EditTextObject> CreateTextObject(const EditSelection& rSel);
877 void SetText( const EditTextObject& rTextObject );
878 EditSelection InsertText( const EditTextObject& rTextObject, EditSelection aSel );
879
880 EditSelection const & MoveCursor( const KeyEvent& rKeyEvent, EditView* pEditView );
881
882 EditSelection MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos, EditView* pCurView );
883
884 sal_uInt32 CalcTextHeight( sal_uInt32* pHeightNTP );
885 sal_uInt32 GetTextHeight() const;
886 sal_uInt32 GetTextHeightNTP() const;
887 sal_uInt32 CalcTextWidth( bool bIgnoreExtraSpace);
888 sal_uInt32 CalcParaWidth( sal_Int32 nParagraph, bool bIgnoreExtraSpace );
889 sal_uInt32 CalcLineWidth( ParaPortion* pPortion, EditLine* pLine, bool bIgnoreExtraSpace);
890 sal_Int32 GetLineCount( sal_Int32 nParagraph ) const;
891 sal_Int32 GetLineLen( sal_Int32 nParagraph, sal_Int32 nLine ) const;
892 void GetLineBoundaries( /*out*/sal_Int32& rStart, /*out*/sal_Int32& rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const;
893 sal_Int32 GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const;
894 sal_uInt16 GetLineHeight( sal_Int32 nParagraph, sal_Int32 nLine );
895 sal_uInt32 GetParaHeight( sal_Int32 nParagraph );
896
897 SfxItemSet GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags = GetAttribsFlags::ALL ) const;
898 SfxItemSet GetAttribs( EditSelection aSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs::All );
899 void SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial = SetAttribsMode::NONE );
900 void RemoveCharAttribs( EditSelection aSel, bool bRemoveParaAttribs, sal_uInt16 nWhich );
901 void RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich = 0, bool bRemoveFeatures = false );
902 void SetFlatMode( bool bFlat );
903
904 void SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet );
905 const SfxItemSet& GetParaAttribs( sal_Int32 nPara ) const;
906
907 bool HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const;
908 const SfxPoolItem& GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const;
909 template<class T>
910 const T& GetParaAttrib( sal_Int32 nPara, TypedWhichId<T> nWhich ) const
911 {
912 return static_cast<const T&>(GetParaAttrib(nPara, sal_uInt16(nWhich)));
913 }
914
915 tools::Rectangle PaMtoEditCursor( EditPaM aPaM, GetCursorFlags nFlags = GetCursorFlags::NONE );
916 tools::Rectangle GetEditCursor( ParaPortion* pPortion, sal_Int32 nIndex, GetCursorFlags nFlags = GetCursorFlags::NONE );
917
918 bool IsModified() const { return aEditDoc.IsModified(); }
919 void SetModifyFlag( bool b ) { aEditDoc.SetModified( b ); }
920 void SetModifyHdl( const Link<LinkParamNone*,void>& rLink ) { aModifyHdl = rLink; }
921 const Link<LinkParamNone*,void>& GetModifyHdl() const { return aModifyHdl; }
922
923 bool IsInSelectionMode() const { return bInSelection; }
924
925// For Undo/Redo
926 void Undo( EditView* pView );
927 void Redo( EditView* pView );
928
929// OV-Special
930 void InvalidateFromParagraph( sal_Int32 nFirstInvPara );
931 EditPaM InsertParagraph( sal_Int32 nPara );
932 std::unique_ptr<EditSelection> SelectParagraph( sal_Int32 nPara );
933
934 void SetStatusEventHdl( const Link<EditStatus&, void>& rLink ) { aStatusHdlLink = rLink; }
935 const Link<EditStatus&,void>& GetStatusEventHdl() const { return aStatusHdlLink; }
936
937 void SetNotifyHdl( const Link<EENotify&,void>& rLink ) { aNotifyHdl = rLink; }
938 const Link<EENotify&,void>& GetNotifyHdl() const { return aNotifyHdl; }
939
940 void FormatAndUpdate( EditView* pCurView = nullptr, bool bCalledFromUndo = false );
941 inline void IdleFormatAndUpdate( EditView* pCurView );
942
943 const svtools::ColorConfig& GetColorConfig() const { return maColorConfig; }
944 bool IsVisualCursorTravelingEnabled();
945 bool DoVisualCursorTraveling();
946
947 EditSelection ConvertSelection( sal_Int32 nStartPara, sal_Int32 nStartPos, sal_Int32 nEndPara, sal_Int32 nEndPos );
948 inline EPaM CreateEPaM( const EditPaM& rPaM );
949 inline EditPaM CreateEditPaM( const EPaM& rEPaM );
950 inline ESelection CreateESel( const EditSelection& rSel );
951 inline EditSelection CreateSel( const ESelection& rSel );
952
953 void SetStyleSheetPool( SfxStyleSheetPool* pSPool );
954 SfxStyleSheetPool* GetStyleSheetPool() const { return pStylePool; }
955
956 void SetStyleSheet( EditSelection aSel, SfxStyleSheet* pStyle );
957 void SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle );
958 const SfxStyleSheet* GetStyleSheet( sal_Int32 nPara ) const;
959 SfxStyleSheet* GetStyleSheet( sal_Int32 nPara );
960
961 void UpdateParagraphsWithStyleSheet( SfxStyleSheet* pStyle );
962 void RemoveStyleFromParagraphs( SfxStyleSheet const * pStyle );
963
964 OutputDevice* GetRefDevice() const { return pRefDev.get(); }
965 void SetRefDevice( OutputDevice* pRefDef );
966
967 const MapMode& GetRefMapMode() const { return pRefDev->GetMapMode(); }
968 void SetRefMapMode( const MapMode& rMapMode );
969
970 InternalEditStatus& GetStatus() { return aStatus; }
971 void CallStatusHdl();
972 void DelayedCallStatusHdl() { aStatusTimer.Start(); }
973
974 void UndoActionStart( sal_uInt16 nId );
975 void UndoActionStart( sal_uInt16 nId, const ESelection& rSel );
976 void UndoActionEnd();
977
978 EditView* GetActiveView() const { return pActiveView; }
979 void SetActiveView( EditView* pView );
980
981 css::uno::Reference< css::linguistic2::XSpellChecker1 > const &
982 GetSpeller();
983 void SetSpeller( css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpl )
984 { xSpeller = xSpl; }
985 const css::uno::Reference< css::linguistic2::XHyphenator >&
986 GetHyphenator() const { return xHyphenator; }
987 void SetHyphenator( css::uno::Reference< css::linguistic2::XHyphenator > const &xHyph )
988 { xHyphenator = xHyph; }
989
990 void GetAllMisspellRanges( std::vector<editeng::MisspellRanges>& rRanges ) const;
991 void SetAllMisspellRanges( const std::vector<editeng::MisspellRanges>& rRanges );
992
993 SpellInfo* GetSpellInfo() const { return pSpellInfo.get(); }
994
995 void SetDefaultLanguage( LanguageType eLang ) { eDefLanguage = eLang; }
996 LanguageType GetDefaultLanguage() const { return eDefLanguage; }
997
998 LanguageType GetLanguage( const EditPaM& rPaM, sal_Int32* pEndPos = nullptr ) const;
999 css::lang::Locale GetLocale( const EditPaM& rPaM ) const;
1000
1001 void DoOnlineSpelling( ContentNode* pThisNodeOnly = nullptr, bool bSpellAtCursorPos = false, bool bInterruptible = true );
1002 EESpellState Spell( EditView* pEditView, bool bMultipleDoc );
1003 EESpellState HasSpellErrors();
1004 void ClearSpellErrors();
1005 EESpellState StartThesaurus( EditView* pEditView );
1006 css::uno::Reference< css::linguistic2::XSpellAlternatives >
1007 ImpSpell( EditView* pEditView );
1008
1009 // text conversion functions
1010 void Convert( EditView* pEditView, LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont, sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc );
1011 void ImpConvert( OUString &rConvTxt, LanguageType &rConvTxtLang, EditView* pEditView, LanguageType nSrcLang, const ESelection &rConvRange,
1012 bool bAllowImplicitChangesForNotConvertibleText, LanguageType nTargetLang, const vcl::Font *pTargetFont );
1013 ConvInfo * GetConvInfo() const { return pConvInfo.get(); }
1014 bool HasConvertibleTextPortion( LanguageType nLang );
1015 void SetLanguageAndFont( const ESelection &rESel,
1016 LanguageType nLang, sal_uInt16 nLangWhichId,
1017 const vcl::Font *pFont, sal_uInt16 nFontWhichId );
1018
1019 // returns true if input sequence checking should be applied
1020 bool IsInputSequenceCheckingRequired( sal_Unicode nChar, const EditSelection& rCurSel ) const;
1021
1022 //find the next error within the given selection - forward only!
1023 css::uno::Reference< css::linguistic2::XSpellAlternatives >
1024 ImpFindNextError(EditSelection& rSelection);
1025 //spell and return a sentence
1026 bool SpellSentence(EditView const & rView, svx::SpellPortions& rToFill );
1027 //put spelling back to start of current sentence - needed after switch of grammar support
1028 void PutSpellingToSentenceStart( EditView const & rEditView );
1029 //applies a changed sentence
1030 void ApplyChangedSentence(EditView const & rEditView, const svx::SpellPortions& rNewPortions, bool bRecheck );
1031 //adds one or more portions of text to the SpellPortions depending on language changes
1032 void AddPortionIterated(
1033 EditView const & rEditView,
1034 const EditSelection &rSel,
1035 const css::uno::Reference< css::linguistic2::XSpellAlternatives >& xAlt,
1036 svx::SpellPortions& rToFill);
1037 //adds one portion to the SpellPortions
1038 void AddPortion(
1039 const EditSelection &rSel,
1040 const css::uno::Reference< css::linguistic2::XSpellAlternatives >& xAlt,
1041 svx::SpellPortions& rToFill,
1042 bool bIsField );
1043
1044 bool Search( const SvxSearchItem& rSearchItem, EditView* pView );
1045 bool ImpSearch( const SvxSearchItem& rSearchItem, const EditSelection& rSearchSelection, const EditPaM& rStartPos, EditSelection& rFoundSel );
1046 sal_Int32 StartSearchAndReplace( EditView* pEditView, const SvxSearchItem& rSearchItem );
1047 bool HasText( const SvxSearchItem& rSearchItem );
1048
1049 void SetEditTextObjectPool( SfxItemPool* pP ) { pTextObjectPool = pP; }
1050 SfxItemPool* GetEditTextObjectPool() const { return pTextObjectPool; }
1051
1052 const SvxNumberFormat * GetNumberFormat( const ContentNode* pNode ) const;
1053 sal_Int32 GetSpaceBeforeAndMinLabelWidth( const ContentNode *pNode, sal_Int32 *pnSpaceBefore = nullptr, sal_Int32 *pnMinLabelWidth = nullptr ) const;
1054
1055 const SvxLRSpaceItem& GetLRSpaceItem( ContentNode* pNode );
1056 SvxAdjust GetJustification( sal_Int32 nPara ) const;
1057 SvxCellJustifyMethod GetJustifyMethod( sal_Int32 nPara ) const;
1058 SvxCellVerJustify GetVerJustification( sal_Int32 nPara ) const;
1059
1060 void SetCharStretching( sal_uInt16 nX, sal_uInt16 nY );
1061 inline void GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const;
1062
1063 sal_Int32 GetBigTextObjectStart() const { return nBigTextObjectStart; }
1064
1065 EditEngine* GetEditEnginePtr() const { return pEditEngine; }
1066
1067 void StartOnlineSpellTimer() { aOnlineSpellTimer.Start(); }
1068 void StopOnlineSpellTimer() { aOnlineSpellTimer.Stop(); }
1069
1070 const OUString& GetAutoCompleteText() const { return aAutoCompleteText; }
1071 void SetAutoCompleteText(const OUString& rStr, bool bUpdateTipWindow);
1072
1073 EditSelection TransliterateText( const EditSelection& rSelection, TransliterationFlags nTransliterationMode );
1074 short ReplaceTextOnly( ContentNode* pNode, sal_Int32 nCurrentStart, const OUString& rText, const css::uno::Sequence< sal_Int32 >& rOffsets );
1075
1076 void SetAsianCompressionMode( CharCompressType n );
1077 CharCompressType GetAsianCompressionMode() const { return nAsianCompressionMode; }
1078
1079 void SetKernAsianPunctuation( bool b );
1080 bool IsKernAsianPunctuation() const { return bKernAsianPunctuation; }
1081
1082 sal_Int32 GetOverflowingParaNum() const { return mnOverflowingPara; }
1083 sal_Int32 GetOverflowingLineNum() const { return mnOverflowingLine; }
1084 void ClearOverflowingParaNum() { mnOverflowingPara = -1; }
1085
1086
1087 void SetAddExtLeading( bool b );
1088 bool IsAddExtLeading() const { return bAddExtLeading; }
1089
1090 static std::shared_ptr<SvxForbiddenCharactersTable> const & GetForbiddenCharsTable();
1091 static void SetForbiddenCharsTable( const std::shared_ptr<SvxForbiddenCharactersTable>& xForbiddenChars );
1092
1093 /** sets a link that is called at the beginning of a drag operation at an edit view */
1094 void SetBeginDropHdl( const Link<EditView*,void>& rLink ) { maBeginDropHdl = rLink; }
1095 const Link<EditView*,void>& GetBeginDropHdl() const { return maBeginDropHdl; }
1096
1097 /** sets a link that is called at the end of a drag operation at an edit view */
1098 void SetEndDropHdl( const Link<EditView*,void>& rLink ) { maEndDropHdl = rLink; }
1099 const Link<EditView*,void>& GetEndDropHdl() const { return maEndDropHdl; }
1100
1101 /// specifies if auto-correction should capitalize the first word or not (default is on)
1102 void SetFirstWordCapitalization( bool bCapitalize ) { bFirstWordCapitalization = bCapitalize; }
1103 bool IsFirstWordCapitalization() const { return bFirstWordCapitalization; }
1104
1105 /** specifies if auto-correction should replace a leading single quotation
1106 mark (apostrophe) or not (default is on) */
1107 void SetReplaceLeadingSingleQuotationMark( bool bReplace ) { mbReplaceLeadingSingleQuotationMark = bReplace; }
1108 bool IsReplaceLeadingSingleQuotationMark() const { return mbReplaceLeadingSingleQuotationMark; }
1109
1110 /** Whether last AutoCorrect inserted a NO-BREAK SPACE that may need to be removed again. */
1111 bool IsNbspRunNext() const { return mbNbspRunNext; }
1112
1113 void Dispose();
1114 void SetLOKSpecialPaperSize(const Size& rSize) { aLOKSpecialPaperSize = rSize; }
1115 const Size& GetLOKSpecialPaperSize() const { return aLOKSpecialPaperSize; }
1116};
1117
1118inline EPaM ImpEditEngine::CreateEPaM( const EditPaM& rPaM )
1119{
1120 const ContentNode* pNode = rPaM.GetNode();
1121 return EPaM( aEditDoc.GetPos( pNode ), rPaM.GetIndex() );
1122}
1123
1124inline EditPaM ImpEditEngine::CreateEditPaM( const EPaM& rEPaM )
1125{
1126 DBG_ASSERT( rEPaM.nPara < aEditDoc.Count(), "CreateEditPaM: invalid paragraph" )do { if (true && (!(rEPaM.nPara < aEditDoc.Count()
))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1126" ": "), "%s", "CreateEditPaM: invalid paragraph");
} } while (false)
;
1127 DBG_ASSERT( aEditDoc[ rEPaM.nPara ]->Len() >= rEPaM.nIndex, "CreateEditPaM: invalid Index" )do { if (true && (!(aEditDoc[ rEPaM.nPara ]->Len()
>= rEPaM.nIndex))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1127" ": "), "%s", "CreateEditPaM: invalid Index"); } }
while (false)
;
1128 return EditPaM( aEditDoc[ rEPaM.nPara], rEPaM.nIndex );
1129}
1130
1131inline ESelection ImpEditEngine::CreateESel( const EditSelection& rSel )
1132{
1133 const ContentNode* pStartNode = rSel.Min().GetNode();
1134 const ContentNode* pEndNode = rSel.Max().GetNode();
1135 ESelection aESel;
1136 aESel.nStartPara = aEditDoc.GetPos( pStartNode );
1137 aESel.nStartPos = rSel.Min().GetIndex();
1138 aESel.nEndPara = aEditDoc.GetPos( pEndNode );
1139 aESel.nEndPos = rSel.Max().GetIndex();
1140 return aESel;
1141}
1142
1143inline EditSelection ImpEditEngine::CreateSel( const ESelection& rSel )
1144{
1145 DBG_ASSERT( rSel.nStartPara < aEditDoc.Count(), "CreateSel: invalid start paragraph" )do { if (true && (!(rSel.nStartPara < aEditDoc.Count
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1145" ": "), "%s", "CreateSel: invalid start paragraph"
); } } while (false)
;
1146 DBG_ASSERT( rSel.nEndPara < aEditDoc.Count(), "CreateSel: invalid end paragraph" )do { if (true && (!(rSel.nEndPara < aEditDoc.Count
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1146" ": "), "%s", "CreateSel: invalid end paragraph");
} } while (false)
;
1147 EditSelection aSel;
1148 aSel.Min().SetNode( aEditDoc[ rSel.nStartPara ] );
1149 aSel.Min().SetIndex( rSel.nStartPos );
1150 aSel.Max().SetNode( aEditDoc[ rSel.nEndPara ] );
1151 aSel.Max().SetIndex( rSel.nEndPos );
1152 DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "CreateSel: incorrect selection!" )do { if (true && (!(!aSel.DbgIsBuggy( aEditDoc )))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1152" ": "), "%s", "CreateSel: incorrect selection!"); }
} while (false)
;
1153 return aSel;
1154}
1155
1156inline VirtualDevice* ImpEditEngine::GetVirtualDevice( const MapMode& rMapMode, DrawModeFlags nDrawMode )
1157{
1158 if ( !pVirtDev )
1159 pVirtDev = VclPtr<VirtualDevice>::Create();
1160
1161 if ( ( pVirtDev->GetMapMode().GetMapUnit() != rMapMode.GetMapUnit() ) ||
1162 ( pVirtDev->GetMapMode().GetScaleX() != rMapMode.GetScaleX() ) ||
1163 ( pVirtDev->GetMapMode().GetScaleY() != rMapMode.GetScaleY() ) )
1164 {
1165 MapMode aMapMode( rMapMode );
1166 aMapMode.SetOrigin( Point( 0, 0 ) );
1167 pVirtDev->SetMapMode( aMapMode );
1168 }
1169
1170 pVirtDev->SetDrawMode( nDrawMode );
1171
1172 return pVirtDev;
1173}
1174
1175inline void ImpEditEngine::IdleFormatAndUpdate( EditView* pCurView )
1176{
1177 aIdleFormatter.DoIdleFormat( pCurView );
1178}
1179
1180inline EditUndoManager& ImpEditEngine::GetUndoManager()
1181{
1182 if ( !pUndoManager )
1183 {
1184 pUndoManager = new EditUndoManager();
1185 pUndoManager->SetEditEngine(pEditEngine);
1186 }
1187 return *pUndoManager;
1188}
1189
1190inline SfxUndoManager* ImpEditEngine::SetUndoManager(SfxUndoManager* pNew)
1191{
1192 SfxUndoManager* pRetval = pUndoManager;
1193
1194 if(pUndoManager)
1195 {
1196 pUndoManager->SetEditEngine(nullptr);
1197 }
1198
1199 pUndoManager = dynamic_cast< EditUndoManager* >(pNew);
1200
1201 if(pUndoManager)
1202 {
1203 pUndoManager->SetEditEngine(pEditEngine);
1204 }
1205
1206 return pRetval;
1207}
1208
1209inline const ParaPortion* ImpEditEngine::FindParaPortion( const ContentNode* pNode ) const
1210{
1211 sal_Int32 nPos = aEditDoc.GetPos( pNode );
1212 DBG_ASSERT( nPos < GetParaPortions().Count(), "Portionloser Node?" )do { if (true && (!(nPos < GetParaPortions().Count
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1212" ": "), "%s", "Portionloser Node?"); } } while (false
)
;
1213 return GetParaPortions()[ nPos ];
1214}
1215
1216inline ParaPortion* ImpEditEngine::FindParaPortion( ContentNode const * pNode )
1217{
1218 sal_Int32 nPos = aEditDoc.GetPos( pNode );
1219 DBG_ASSERT( nPos < GetParaPortions().Count(), "Portionloser Node?" )do { if (true && (!(nPos < GetParaPortions().Count
()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"
), ("/home/maarten/src/libreoffice/core/editeng/source/editeng/impedit.hxx"
":" "1219" ": "), "%s", "Portionloser Node?"); } } while (false
)
;
1220 return GetParaPortions()[ nPos ];
1221}
1222
1223inline void ImpEditEngine::GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const
1224{
1225 rX = nStretchX;
1226 rY = nStretchY;
1227}
1228
1229inline short ImpEditEngine::GetXValue( short nXValue ) const
1230{
1231 if ( !aStatus.DoStretch() || ( nStretchX == 100 ) )
1232 return nXValue;
1233
1234 return static_cast<short>(static_cast<long>(nXValue)*nStretchX/100);
1235}
1236
1237
1238inline long ImpEditEngine::GetXValue( long nXValue ) const
1239{
1240 if ( !aStatus.DoStretch() || ( nStretchX == 100 ) )
1241 return nXValue;
1242
1243 return nXValue*nStretchX/100;
1244}
1245
1246inline short ImpEditEngine::GetYValue( short nYValue ) const
1247{
1248 if ( !aStatus.DoStretch() || ( nStretchY == 100 ) )
1249 return nYValue;
1250
1251 return static_cast<short>(static_cast<long>(nYValue)*nStretchY/100);
1252}
1253
1254inline sal_uInt16 ImpEditEngine::GetYValue( sal_uInt16 nYValue ) const
1255{
1256 if ( !aStatus.DoStretch() || ( nStretchY == 100 ) )
1257 return nYValue;
1258
1259 return static_cast<sal_uInt16>(static_cast<long>(nYValue)*nStretchY/100);
1260}
1261
1262inline PointerStyle ImpEditView::GetPointer()
1263{
1264 if ( !mxPointer )
1265 {
1266 mxPointer = IsVertical() ? PointerStyle::TextVertical : PointerStyle::Text;
1267 return *mxPointer;
1268 }
1269
1270 if(PointerStyle::Text == *mxPointer && IsVertical())
1271 {
1272 mxPointer = PointerStyle::TextVertical;
1273 }
1274 else if(PointerStyle::TextVertical == *mxPointer && !IsVertical())
1275 {
1276 mxPointer = PointerStyle::Text;
1277 }
1278
1279 return *mxPointer;
1280}
1281
1282inline vcl::Cursor* ImpEditView::GetCursor()
1283{
1284 if ( !pCursor )
1285 pCursor.reset( new vcl::Cursor );
1286 return pCursor.get();
1287}
1288
1289void ConvertItem( std::unique_ptr<SfxPoolItem>& rPoolItem, MapUnit eSourceUnit, MapUnit eDestUnit );
1290void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const MapUnit* pSourceUnit = nullptr, const MapUnit* pDestUnit = nullptr );
1291AsianCompressionFlags GetCharTypeForCompression( sal_Unicode cChar );
1292Point Rotate( const Point& rPoint, short nOrientation, const Point& rOrigin );
1293
1294
1295/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
3
Calling copy constructor for 'Reference<VirtualDevice>'
6
Returning from copy constructor for 'Reference<VirtualDevice>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
7
Calling 'Reference::clear'
14
Returning; memory was released
205 if (aTmp.get()) {
15
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
4
Assuming field 'm_pBody' is non-null
5
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
7.1
Field 'm_pBody' is non-null
)
8
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
9
Calling 'VclReferenceBase::release'
13
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
16
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
10
Assuming the condition is true
11
Taking true branch
40 delete this;
12
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif