1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_VCL_TEXTENG_HXX
20 #define INCLUDED_VCL_TEXTENG_HXX
23 #include <sal/config.h>
28 #include <vcl/dllapi.h>
29 #include <vcl/vclptr.hxx>
30 #include <rtl/ustring.hxx>
31 #include <svl/SfxBroadcaster.hxx>
32 #include <tools/lineend.hxx>
33 #include <tools/link.hxx>
34 #include <tools/gen.hxx>
35 #include <tools/color.hxx>
36 #include <vcl/font.hxx>
37 #include <vcl/vclenum.hxx>
39 #include <com/sun/star/lang/Locale.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
50 class TextUndoManager
;
60 namespace com::sun::star::i18n
{
62 class XExtendedInputSequenceChecker
;
65 class LocaleDataWrapper
;
67 typedef std::vector
<TextView
*> TextViews
;
69 class VCL_DLLPUBLIC TextEngine
: public SfxBroadcaster
71 friend class TextView
;
72 friend class TextSelFunctionSet
;
73 friend class ExtTextEngine
;
75 friend class TextUndo
;
76 friend class TextUndoManager
;
77 friend class TextUndoDelPara
;
78 friend class TextUndoConnectParas
;
79 friend class TextUndoSplitPara
;
80 friend class TextUndoInsertChars
;
81 friend class TextUndoRemoveChars
;
83 std::unique_ptr
<TextDoc
> mpDoc
;
84 std::unique_ptr
<TEParaPortions
> mpTEParaPortions
;
85 VclPtr
<OutputDevice
> mpRefDev
;
87 std::unique_ptr
<TextViews
> mpViews
;
88 TextView
* mpActiveView
;
90 std::unique_ptr
<TextUndoManager
> mpUndoManager
;
92 std::unique_ptr
<IdleFormatter
> mpIdleFormatter
;
94 std::unique_ptr
<TEIMEInfos
> mpIMEInfos
;
96 css::lang::Locale maLocale
;
97 css::uno::Reference
< css::i18n::XBreakIterator
> mxBreakIterator
;
98 css::uno::Reference
< css::i18n::XExtendedInputSequenceChecker
> mxISC
;
100 tools::Rectangle maInvalidRect
;
102 std::unique_ptr
<LocaleDataWrapper
> mpLocaleDataWrapper
;
107 sal_Int32 mnMaxTextLen
;
108 tools::Long mnMaxTextWidth
;
109 tools::Long mnCharHeight
;
110 tools::Long mnCurTextWidth
;
111 tools::Long mnCurTextHeight
;
112 tools::Long mnDefTab
;
116 bool mbIsFormatting
: 1; // semaphore for the Hook's
117 bool mbFormatted
: 1;
120 bool mbUndoEnabled
: 1;
123 bool mbRightToLeft
: 1;
124 bool mbHasMultiLineParas
: 1;
126 SAL_DLLPRIVATE
void CursorMoved( sal_uInt32 nNode
);
127 SAL_DLLPRIVATE
void TextModified();
129 SAL_DLLPRIVATE
void ImpInitDoc();
130 SAL_DLLPRIVATE
void ImpRemoveText();
131 SAL_DLLPRIVATE TextPaM
ImpDeleteText( const TextSelection
& rSel
);
132 SAL_DLLPRIVATE TextPaM
ImpInsertText( const TextSelection
& rSel
, sal_Unicode c
, bool bOverwrite
= false );
133 SAL_DLLPRIVATE TextPaM
ImpInsertText( const TextSelection
& rSel
, const OUString
& rText
);
134 SAL_DLLPRIVATE TextPaM
ImpInsertParaBreak( const TextSelection
& rTextSelection
);
135 SAL_DLLPRIVATE TextPaM
ImpInsertParaBreak( const TextPaM
& rPaM
);
136 SAL_DLLPRIVATE
void ImpRemoveChars( const TextPaM
& rPaM
, sal_Int32 nChars
);
137 SAL_DLLPRIVATE TextPaM
ImpConnectParagraphs( sal_uInt32 nLeft
, sal_uInt32 nRight
);
138 SAL_DLLPRIVATE
void ImpRemoveParagraph( sal_uInt32 nPara
);
139 SAL_DLLPRIVATE
void ImpInitWritingDirections( sal_uInt32 nPara
);
140 SAL_DLLPRIVATE LocaleDataWrapper
* ImpGetLocaleDataWrapper();
142 // to remain compatible in the minor release we copy the above ImpInsertText
143 // function and add the extra parameter we need but make sure this function
144 // gets not exported. First and second parameter swapped to have a different signature.
145 SAL_DLLPRIVATE TextPaM
ImpInsertText( sal_Unicode c
, const TextSelection
& rSel
, bool bOverwrite
, bool bIsUserInput
= false );
146 // some other new functions needed that must not be exported to remain compatible
147 SAL_DLLPRIVATE
css::uno::Reference
< css::i18n::XExtendedInputSequenceChecker
> const & GetInputSequenceChecker();
148 SAL_DLLPRIVATE
bool IsInputSequenceCheckingRequired( sal_Unicode c
, const TextSelection
& rCurSel
) const;
150 // broadcast or adjust selections
151 SAL_DLLPRIVATE
void ImpParagraphInserted( sal_uInt32 nPara
);
152 SAL_DLLPRIVATE
void ImpParagraphRemoved( sal_uInt32 nPara
);
153 SAL_DLLPRIVATE
void ImpCharsRemoved( sal_uInt32 nPara
, sal_Int32 nPos
, sal_Int32 nChars
);
154 SAL_DLLPRIVATE
void ImpCharsInserted( sal_uInt32 nPara
, sal_Int32 nPos
, sal_Int32 nChars
);
156 DECL_DLLPRIVATE_LINK( IdleFormatHdl
, Timer
*, void );
157 SAL_DLLPRIVATE
void CheckIdleFormatter();
158 SAL_DLLPRIVATE
void IdleFormatAndUpdate( TextView
* pCurView
, sal_uInt16 nMaxTimerRestarts
= 5 );
160 SAL_DLLPRIVATE
bool CreateLines( sal_uInt32 nPara
);
161 SAL_DLLPRIVATE
void CreateAndInsertEmptyLine( sal_uInt32 nPara
);
162 SAL_DLLPRIVATE
void ImpBreakLine( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nPortionStart
, tools::Long nRemainingWidth
);
163 SAL_DLLPRIVATE
std::size_t SplitTextPortion( sal_uInt32 nPara
, sal_Int32 nPos
);
164 SAL_DLLPRIVATE
void CreateTextPortions( sal_uInt32 nPara
, sal_Int32 nStartPos
);
165 SAL_DLLPRIVATE
void RecalcTextPortion( sal_uInt32 nPara
, sal_Int32 nStartPos
, sal_Int32 nNewChars
);
166 SAL_DLLPRIVATE
void SeekCursor( sal_uInt32 nNode
, sal_Int32 nPos
, vcl::Font
& rFont
, OutputDevice
* pOutDev
);
168 SAL_DLLPRIVATE
void FormatDoc();
169 SAL_DLLPRIVATE
void FormatFullDoc();
170 SAL_DLLPRIVATE
void FormatAndUpdate( TextView
* pCurView
= nullptr );
171 bool IsFormatting() const { return mbIsFormatting
; }
172 SAL_DLLPRIVATE
void UpdateViews( TextView
* pCurView
= nullptr );
174 SAL_DLLPRIVATE
void ImpPaint( OutputDevice
* pOut
, const Point
& rStartPos
, tools::Rectangle
const* pPaintArea
, TextSelection
const* pSelection
= nullptr );
176 bool IsFormatted() const { return mbFormatted
; }
178 SAL_DLLPRIVATE sal_Int32
GetCharPos( sal_uInt32 nPara
, std::vector
<TextLine
>::size_type nLine
, tools::Long nDocPosX
);
179 SAL_DLLPRIVATE
tools::Rectangle
GetEditCursor( const TextPaM
& rPaM
, bool bSpecial
, bool bPreferPortionStart
= false );
180 SAL_DLLPRIVATE sal_Int32
ImpFindIndex( sal_uInt32 nPortion
, const Point
& rPosInPara
);
181 SAL_DLLPRIVATE
tools::Long
ImpGetPortionXOffset( sal_uInt32 nPara
, TextLine
const * pLine
, std::size_t nTextPortion
);
182 SAL_DLLPRIVATE
tools::Long
ImpGetXPos( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nIndex
, bool bPreferPortionStart
= false );
183 SAL_DLLPRIVATE
tools::Long
ImpGetOutputOffset( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nIndex
, sal_Int32 nIndex2
);
184 SAL_DLLPRIVATE
bool ImpGetRightToLeft( sal_uInt32 nPara
, sal_Int32 nPos
);
185 SAL_DLLPRIVATE
static void ImpInitLayoutMode( OutputDevice
* pOutDev
);
186 SAL_DLLPRIVATE TxtAlign
ImpGetAlign() const;
188 SAL_DLLPRIVATE
tools::Long
CalcTextHeight() const;
189 SAL_DLLPRIVATE
tools::Long
CalcParaHeight( sal_uInt32 nParagraph
) const;
190 SAL_DLLPRIVATE
tools::Long
CalcTextWidth( sal_uInt32 nPara
);
191 SAL_DLLPRIVATE
tools::Long
CalcTextWidth( sal_uInt32 nPara
, sal_Int32 nPortionStart
, sal_Int32 nPortionLen
);
192 SAL_DLLPRIVATE Range
GetInvalidYOffsets( sal_uInt32 nPortion
);
195 SAL_DLLPRIVATE
void InsertContent( std::unique_ptr
<TextNode
> pNode
, sal_uInt32 nPara
);
196 SAL_DLLPRIVATE TextPaM
SplitContent( sal_uInt32 nNode
, sal_Int32 nSepPos
);
197 SAL_DLLPRIVATE TextPaM
ConnectContents( sal_uInt32 nLeftNode
);
199 // adjust PaM's and selections that were transferred to the API to a valid range
200 SAL_DLLPRIVATE
void ValidateSelection( TextSelection
& rSel
) const;
201 SAL_DLLPRIVATE
void ValidatePaM( TextPaM
& rPaM
) const;
205 virtual ~TextEngine() override
;
206 TextEngine( const TextEngine
& ) = delete;
207 TextEngine
& operator=( const TextEngine
& ) = delete;
209 void SetText( const OUString
& rStr
);
210 SAL_DLLPRIVATE OUString
GetText( LineEnd aSeparator
= LINEEND_LF
) const;
211 OUString
GetText( const TextSelection
& rSel
, LineEnd aSeparator
= LINEEND_LF
) const;
212 SAL_DLLPRIVATE OUString
GetTextLines( LineEnd aSeparator
= LINEEND_LF
) const;
213 void ReplaceText(const TextSelection
& rSel
, const OUString
& rText
);
215 SAL_DLLPRIVATE sal_Int32
GetTextLen() const;
216 SAL_DLLPRIVATE sal_Int32
GetTextLen( const TextSelection
& rSel
) const;
218 void SetFont( const vcl::Font
& rFont
);
219 const vcl::Font
& GetFont() const { return maFont
; }
221 SAL_DLLPRIVATE
void SetLeftMargin( sal_uInt16 n
);
223 void SetUpdateMode( bool bUpdate
);
224 bool GetUpdateMode() const { return mbUpdate
; }
226 SAL_DLLPRIVATE sal_uInt16
GetViewCount() const;
227 SAL_DLLPRIVATE TextView
* GetView( sal_uInt16 nView
) const;
228 void InsertView( TextView
* pTextView
);
229 void RemoveView( TextView
* pTextView
);
230 TextView
* GetActiveView() const { return mpActiveView
;}
231 void SetActiveView( TextView
* pView
);
233 SAL_DLLPRIVATE
void SetMaxTextLen( sal_Int32 nLen
);
234 sal_Int32
GetMaxTextLen() const { return mnMaxTextLen
; }
236 void SetMaxTextWidth( tools::Long nWidth
);
237 tools::Long
GetMaxTextWidth() const { return mnMaxTextWidth
; }
239 tools::Long
GetTextHeight() const;
240 tools::Long
CalcTextWidth();
241 tools::Long
GetCharHeight() const { return mnCharHeight
; }
243 sal_uInt32
GetParagraphCount() const;
244 OUString
GetText( sal_uInt32 nParagraph
) const;
245 sal_Int32
GetTextLen( sal_uInt32 nParagraph
) const;
246 tools::Long
GetTextHeight( sal_uInt32 nParagraph
) const;
248 void GetTextPortionRange(const TextPaM
& rPaM
, sal_Int32
& nStart
, sal_Int32
& nEnd
);
250 sal_uInt16
GetLineCount( sal_uInt32 nParagraph
) const;
251 sal_Int32
GetLineLen( sal_uInt32 nParagraph
, sal_uInt16 nLine
) const;
253 SAL_DLLPRIVATE
void SetRightToLeft( bool bR2L
);
254 bool IsRightToLeft() const { return mbRightToLeft
; }
256 bool HasUndoManager() const { return mpUndoManager
!= nullptr; }
257 SfxUndoManager
& GetUndoManager();
258 SAL_DLLPRIVATE
void UndoActionStart( sal_uInt16 nId
= 0 );
259 SAL_DLLPRIVATE
void UndoActionEnd();
260 SAL_DLLPRIVATE
void InsertUndo( std::unique_ptr
<TextUndo
> pUndo
, bool bTryMerge
= false );
261 bool IsInUndo() const { return mbIsInUndo
; }
262 void SetIsInUndo( bool bInUndo
) { mbIsInUndo
= bInUndo
; }
265 void EnableUndo( bool bEnable
);
266 bool IsUndoEnabled() const { return mbUndoEnabled
; }
268 void SetModified( bool bModified
) { mbModified
= bModified
; }
269 bool IsModified() const { return mbModified
; }
271 bool Read( SvStream
& rInput
, const TextSelection
* pSel
= nullptr );
273 void Write( SvStream
& rOutput
);
275 TextPaM
GetPaM( const Point
& rDocPos
);
276 tools::Rectangle
PaMtoEditCursor( const TextPaM
& rPaM
, bool bSpecial
= false );
277 OUString
GetWord( const TextPaM
& rCursorPos
, TextPaM
* pStartOfWord
= nullptr, TextPaM
* pEndOfWord
= nullptr );
279 const TextAttrib
* FindAttrib( const TextPaM
& rPaM
, sal_uInt16 nWhich
) const;
280 SAL_DLLPRIVATE
const TextCharAttrib
* FindCharAttrib( const TextPaM
& rPaM
, sal_uInt16 nWhich
) const;
282 void RemoveAttribs( sal_uInt32 nPara
);
283 void SetAttrib( const TextAttrib
& rAttr
, sal_uInt32 nPara
, sal_Int32 nStart
, sal_Int32 nEnd
);
285 TxtAlign
GetTextAlign() const { return meAlign
; }
286 SAL_DLLPRIVATE
void SetTextAlign( TxtAlign eAlign
);
288 SAL_DLLPRIVATE
void Draw( OutputDevice
* pDev
, const Point
& rPos
);
290 SAL_DLLPRIVATE
void SetLocale( const css::lang::Locale
& rLocale
);
291 css::lang::Locale
const & GetLocale();
292 SAL_DLLPRIVATE
css::uno::Reference
< css::i18n::XBreakIterator
> const & GetBreakIterator();
294 static bool DoesKeyChangeText( const KeyEvent
& rKeyEvent
);
295 SAL_DLLPRIVATE
static bool IsSimpleCharInput( const KeyEvent
& rKeyEvent
);
297 const Color
& GetTextColor() const { return maTextColor
; }
300 #endif // INCLUDED_VCL_TEXTENG_HXX
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */