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>
38 #include <com/sun/star/lang/Locale.hpp>
39 #include <com/sun/star/uno/Reference.hxx>
49 class TextUndoManager
;
64 class XExtendedInputSequenceChecker
;
67 class LocaleDataWrapper
;
69 enum class TxtAlign
{ Left
, Center
, Right
};
71 typedef std::vector
<TextView
*> TextViews
;
73 class VCL_DLLPUBLIC TextEngine
: public SfxBroadcaster
75 friend class TextView
;
76 friend class TextSelFunctionSet
;
77 friend class ExtTextEngine
;
79 friend class TextUndo
;
80 friend class TextUndoManager
;
81 friend class TextUndoDelPara
;
82 friend class TextUndoConnectParas
;
83 friend class TextUndoSplitPara
;
84 friend class TextUndoInsertChars
;
85 friend class TextUndoRemoveChars
;
87 std::unique_ptr
<TextDoc
> mpDoc
;
88 std::unique_ptr
<TEParaPortions
> mpTEParaPortions
;
89 VclPtr
<OutputDevice
> mpRefDev
;
91 std::unique_ptr
<TextViews
> mpViews
;
92 TextView
* mpActiveView
;
94 std::unique_ptr
<TextUndoManager
> mpUndoManager
;
96 std::unique_ptr
<IdleFormatter
> mpIdleFormatter
;
98 std::unique_ptr
<TEIMEInfos
> mpIMEInfos
;
100 css::lang::Locale maLocale
;
101 css::uno::Reference
< css::i18n::XBreakIterator
> mxBreakIterator
;
102 css::uno::Reference
< css::i18n::XExtendedInputSequenceChecker
> mxISC
;
104 tools::Rectangle maInvalidRect
;
106 std::unique_ptr
<LocaleDataWrapper
> mpLocaleDataWrapper
;
111 sal_Int32 mnMaxTextLen
;
115 long mnCurTextHeight
;
120 bool mbIsFormatting
: 1; // semaphore for the Hook's
121 bool mbFormatted
: 1;
124 bool mbUndoEnabled
: 1;
127 bool mbRightToLeft
: 1;
128 bool mbHasMultiLineParas
: 1;
130 void CursorMoved( sal_uInt32 nNode
);
134 void ImpRemoveText();
135 TextPaM
ImpDeleteText( const TextSelection
& rSel
);
136 TextPaM
ImpInsertText( const TextSelection
& rSel
, sal_Unicode c
, bool bOverwrite
= false );
137 TextPaM
ImpInsertText( const TextSelection
& rSel
, const OUString
& rText
);
138 TextPaM
ImpInsertParaBreak( const TextSelection
& rTextSelection
);
139 TextPaM
ImpInsertParaBreak( const TextPaM
& rPaM
);
140 void ImpRemoveChars( const TextPaM
& rPaM
, sal_Int32 nChars
);
141 TextPaM
ImpConnectParagraphs( sal_uInt32 nLeft
, sal_uInt32 nRight
);
142 void ImpRemoveParagraph( sal_uInt32 nPara
);
143 void ImpInitWritingDirections( sal_uInt32 nPara
);
144 LocaleDataWrapper
* ImpGetLocaleDataWrapper();
146 // to remain compatible in the minor release we copy the above ImpInsertText
147 // function and add the extra parameter we need but make sure this function
148 // gets not exported. First and second parameter swapped to have a different signature.
149 SAL_DLLPRIVATE TextPaM
ImpInsertText( sal_Unicode c
, const TextSelection
& rSel
, bool bOverwrite
, bool bIsUserInput
= false );
150 // some other new functions needed that must not be exported to remain compatible
151 SAL_DLLPRIVATE
css::uno::Reference
< css::i18n::XExtendedInputSequenceChecker
> const & GetInputSequenceChecker();
152 SAL_DLLPRIVATE
bool IsInputSequenceCheckingRequired( sal_Unicode c
, const TextSelection
& rCurSel
) const;
154 // broadcast or adjust selections
155 void ImpParagraphInserted( sal_uInt32 nPara
);
156 void ImpParagraphRemoved( sal_uInt32 nPara
);
157 void ImpCharsRemoved( sal_uInt32 nPara
, sal_Int32 nPos
, sal_Int32 nChars
);
158 void ImpCharsInserted( sal_uInt32 nPara
, sal_Int32 nPos
, sal_Int32 nChars
);
160 DECL_LINK( IdleFormatHdl
, Timer
*, void );
161 void CheckIdleFormatter();
162 void IdleFormatAndUpdate( TextView
* pCurView
, sal_uInt16 nMaxTimerRestarts
= 5 );
164 bool CreateLines( sal_uInt32 nPara
);
165 void CreateAndInsertEmptyLine( sal_uInt32 nPara
);
166 void ImpBreakLine( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nPortionStart
, long nRemainingWidth
);
167 std::size_t SplitTextPortion( sal_uInt32 nPara
, sal_Int32 nPos
);
168 void CreateTextPortions( sal_uInt32 nPara
, sal_Int32 nStartPos
);
169 void RecalcTextPortion( sal_uInt32 nPara
, sal_Int32 nStartPos
, sal_Int32 nNewChars
);
170 void SeekCursor( sal_uInt32 nNode
, sal_Int32 nPos
, vcl::Font
& rFont
, OutputDevice
* pOutDev
);
173 void FormatFullDoc();
174 void FormatAndUpdate( TextView
* pCurView
= nullptr );
175 bool IsFormatting() const { return mbIsFormatting
; }
176 void UpdateViews( TextView
* pCurView
= nullptr );
178 void ImpPaint( OutputDevice
* pOut
, const Point
& rStartPos
, tools::Rectangle
const* pPaintArea
, TextSelection
const* pSelection
= nullptr );
180 bool IsFormatted() const { return mbFormatted
; }
182 sal_Int32
GetCharPos( sal_uInt32 nPara
, std::vector
<TextLine
>::size_type nLine
, long nDocPosX
);
183 tools::Rectangle
GetEditCursor( const TextPaM
& rPaM
, bool bSpecial
, bool bPreferPortionStart
= false );
184 sal_Int32
ImpFindIndex( sal_uInt32 nPortion
, const Point
& rPosInPara
);
185 long ImpGetPortionXOffset( sal_uInt32 nPara
, TextLine
const * pLine
, std::size_t nTextPortion
);
186 long ImpGetXPos( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nIndex
, bool bPreferPortionStart
= false );
187 long ImpGetOutputOffset( sal_uInt32 nPara
, TextLine
* pLine
, sal_Int32 nIndex
, sal_Int32 nIndex2
);
188 bool ImpGetRightToLeft( sal_uInt32 nPara
, sal_Int32 nPos
);
189 static void ImpInitLayoutMode( OutputDevice
* pOutDev
);
190 TxtAlign
ImpGetAlign() const;
192 long CalcTextHeight();
193 long CalcParaHeight( sal_uInt32 nParagraph
) const;
194 long CalcTextWidth( sal_uInt32 nPara
);
195 long CalcTextWidth( sal_uInt32 nPara
, sal_Int32 nPortionStart
, sal_Int32 nPortionLen
);
196 Range
GetInvalidYOffsets( sal_uInt32 nPortion
);
199 void InsertContent( std::unique_ptr
<TextNode
> pNode
, sal_uInt32 nPara
);
200 TextPaM
SplitContent( sal_uInt32 nNode
, sal_Int32 nSepPos
);
201 TextPaM
ConnectContents( sal_uInt32 nLeftNode
);
203 // adjust PaM's and selections that were transferred to the API to a valid range
204 void ValidateSelection( TextSelection
& rSel
) const;
205 void ValidatePaM( TextPaM
& rPaM
) const;
209 virtual ~TextEngine() override
;
210 TextEngine( const TextEngine
& ) = delete;
211 TextEngine
& operator=( const TextEngine
& ) = delete;
213 void SetText( const OUString
& rStr
);
214 OUString
GetText( LineEnd aSeparator
= LINEEND_LF
) const;
215 OUString
GetText( const TextSelection
& rSel
, LineEnd aSeparator
= LINEEND_LF
) const;
216 OUString
GetTextLines( LineEnd aSeparator
= LINEEND_LF
) const;
217 void ReplaceText(const TextSelection
& rSel
, const OUString
& rText
);
219 sal_Int32
GetTextLen() const;
220 sal_Int32
GetTextLen( const TextSelection
& rSel
) const;
222 void SetFont( const vcl::Font
& rFont
);
223 const vcl::Font
& GetFont() const { return maFont
; }
225 void SetLeftMargin( sal_uInt16 n
);
227 void SetUpdateMode( bool bUpdate
);
228 bool GetUpdateMode() const { return mbUpdate
; }
230 sal_uInt16
GetViewCount() const;
231 TextView
* GetView( sal_uInt16 nView
) const;
232 void InsertView( TextView
* pTextView
);
233 void RemoveView( TextView
* pTextView
);
234 TextView
* GetActiveView() const { return mpActiveView
;}
235 void SetActiveView( TextView
* pView
);
237 void SetMaxTextLen( sal_Int32 nLen
);
238 sal_Int32
GetMaxTextLen() const { return mnMaxTextLen
; }
240 void SetMaxTextWidth( long nWidth
);
241 long GetMaxTextWidth() const { return mnMaxTextWidth
; }
243 long GetTextHeight() const;
244 long CalcTextWidth();
245 long GetCharHeight() const { return mnCharHeight
; }
247 sal_uInt32
GetParagraphCount() const;
248 OUString
GetText( sal_uInt32 nParagraph
) const;
249 sal_Int32
GetTextLen( sal_uInt32 nParagraph
) const;
250 long GetTextHeight( sal_uInt32 nParagraph
) const;
252 void GetTextPortionRange(const TextPaM
& rPaM
, sal_Int32
& nStart
, sal_Int32
& nEnd
);
254 sal_uInt16
GetLineCount( sal_uInt32 nParagraph
) const;
255 sal_Int32
GetLineLen( sal_uInt32 nParagraph
, sal_uInt16 nLine
) const;
257 void SetRightToLeft( bool bR2L
);
258 bool IsRightToLeft() const { return mbRightToLeft
; }
260 bool HasUndoManager() const { return mpUndoManager
!= nullptr; }
261 SfxUndoManager
& GetUndoManager();
262 void UndoActionStart( sal_uInt16 nId
= 0 );
263 void UndoActionEnd();
264 void InsertUndo( std::unique_ptr
<TextUndo
> pUndo
, bool bTryMerge
= false );
265 bool IsInUndo() const { return mbIsInUndo
; }
266 void SetIsInUndo( bool bInUndo
) { mbIsInUndo
= bInUndo
; }
269 void EnableUndo( bool bEnable
);
270 bool IsUndoEnabled() const { return mbUndoEnabled
; }
272 void SetModified( bool bModified
) { mbModified
= bModified
; }
273 bool IsModified() const { return mbModified
; }
275 bool Read( SvStream
& rInput
, const TextSelection
* pSel
= nullptr );
277 void Write( SvStream
& rOutput
);
279 TextPaM
GetPaM( const Point
& rDocPos
);
280 tools::Rectangle
PaMtoEditCursor( const TextPaM
& rPaM
, bool bSpecial
= false );
281 OUString
GetWord( const TextPaM
& rCursorPos
, TextPaM
* pStartOfWord
= nullptr );
283 const TextAttrib
* FindAttrib( const TextPaM
& rPaM
, sal_uInt16 nWhich
) const;
284 const TextCharAttrib
* FindCharAttrib( const TextPaM
& rPaM
, sal_uInt16 nWhich
) const;
286 void RemoveAttribs( sal_uInt32 nPara
);
287 void SetAttrib( const TextAttrib
& rAttr
, sal_uInt32 nPara
, sal_Int32 nStart
, sal_Int32 nEnd
);
289 TxtAlign
GetTextAlign() const { return meAlign
; }
290 void SetTextAlign( TxtAlign eAlign
);
292 void Draw( OutputDevice
* pDev
, const Point
& rPos
);
294 void SetLocale( const css::lang::Locale
& rLocale
);
295 css::lang::Locale
const & GetLocale();
296 css::uno::Reference
< css::i18n::XBreakIterator
> const & GetBreakIterator();
298 static bool DoesKeyChangeText( const KeyEvent
& rKeyEvent
);
299 static bool IsSimpleCharInput( const KeyEvent
& rKeyEvent
);
301 const Color
& GetTextColor() const { return maTextColor
; }
304 #endif // INCLUDED_VCL_TEXTENG_HXX
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */