/src/libreoffice/include/vcl/texteng.hxx
Line | Count | Source |
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_TEXTENG_HXX |
20 | | #define INCLUDED_VCL_TEXTENG_HXX |
21 | | |
22 | | #include <memory> |
23 | | #include <sal/config.h> |
24 | | |
25 | | #include <cstddef> |
26 | | #include <vector> |
27 | | |
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> |
38 | | |
39 | | #include <com/sun/star/lang/Locale.hpp> |
40 | | #include <com/sun/star/uno/Reference.hxx> |
41 | | |
42 | | class TextDoc; |
43 | | class TextView; |
44 | | class TextPaM; |
45 | | class TextSelection; |
46 | | class TEParaPortions; |
47 | | class TextAttrib; |
48 | | class TextCharAttrib; |
49 | | class TextUndo; |
50 | | class TextUndoManager; |
51 | | class IdleFormatter; |
52 | | class TextNode; |
53 | | class OutputDevice; |
54 | | class KeyEvent; |
55 | | class Timer; |
56 | | class SfxUndoManager; |
57 | | class TextLine; |
58 | | struct TEIMEInfos; |
59 | | |
60 | | namespace com::sun::star::i18n { |
61 | | class XBreakIterator; |
62 | | class XExtendedInputSequenceChecker; |
63 | | } |
64 | | |
65 | | class LocaleDataWrapper; |
66 | | |
67 | | typedef std::vector<TextView*> TextViews; |
68 | | |
69 | | class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster |
70 | | { |
71 | | friend class TextView; |
72 | | friend class TextSelFunctionSet; |
73 | | friend class ExtTextEngine; |
74 | | |
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; |
82 | | |
83 | | std::unique_ptr<TextDoc> mpDoc; |
84 | | std::unique_ptr<TEParaPortions> mpTEParaPortions; |
85 | | VclPtr<OutputDevice> mpRefDev; |
86 | | |
87 | | std::unique_ptr<TextViews> mpViews; |
88 | | TextView* mpActiveView; |
89 | | |
90 | | std::unique_ptr<TextUndoManager> mpUndoManager; |
91 | | |
92 | | std::unique_ptr<IdleFormatter> mpIdleFormatter; |
93 | | |
94 | | std::unique_ptr<TEIMEInfos> mpIMEInfos; |
95 | | |
96 | | css::lang::Locale maLocale; |
97 | | css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator; |
98 | | css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC; |
99 | | |
100 | | tools::Rectangle maInvalidRect; |
101 | | |
102 | | std::unique_ptr<LocaleDataWrapper> mpLocaleDataWrapper; |
103 | | |
104 | | vcl::Font maFont; |
105 | | Color maTextColor; |
106 | | |
107 | | sal_Int32 mnMaxTextLen; |
108 | | tools::Long mnMaxTextWidth; |
109 | | tools::Long mnCharHeight; |
110 | | tools::Long mnCurTextWidth; |
111 | | tools::Long mnCurTextHeight; |
112 | | tools::Long mnDefTab; |
113 | | |
114 | | TxtAlign meAlign; |
115 | | |
116 | | bool mbIsFormatting : 1; // semaphore for the Hook's |
117 | | bool mbFormatted : 1; |
118 | | bool mbUpdate : 1; |
119 | | bool mbModified : 1; |
120 | | bool mbUndoEnabled : 1; |
121 | | bool mbIsInUndo : 1; |
122 | | bool mbDowning : 1; |
123 | | bool mbRightToLeft : 1; |
124 | | bool mbHasMultiLineParas : 1; |
125 | | |
126 | | SAL_DLLPRIVATE void CursorMoved( sal_uInt32 nNode ); |
127 | | SAL_DLLPRIVATE void TextModified(); |
128 | | |
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(); |
141 | | |
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; |
149 | | |
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 ); |
155 | | |
156 | | DECL_DLLPRIVATE_LINK( IdleFormatHdl, Timer *, void ); |
157 | | SAL_DLLPRIVATE void CheckIdleFormatter(); |
158 | | SAL_DLLPRIVATE void IdleFormatAndUpdate( TextView* pCurView, sal_uInt16 nMaxTimerRestarts = 5 ); |
159 | | |
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 ); |
167 | | |
168 | | SAL_DLLPRIVATE void FormatDoc(); |
169 | | SAL_DLLPRIVATE void FormatFullDoc(); |
170 | | SAL_DLLPRIVATE void FormatAndUpdate( TextView* pCurView = nullptr ); |
171 | 0 | bool IsFormatting() const { return mbIsFormatting; } |
172 | | SAL_DLLPRIVATE void UpdateViews( TextView* pCurView = nullptr ); |
173 | | |
174 | | SAL_DLLPRIVATE void ImpPaint( OutputDevice* pOut, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection = nullptr ); |
175 | | |
176 | 0 | bool IsFormatted() const { return mbFormatted; } |
177 | | |
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; |
187 | | |
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 ); |
193 | | |
194 | | // for Undo/Redo |
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 ); |
198 | | |
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; |
202 | | |
203 | | public: |
204 | | TextEngine(); |
205 | | virtual ~TextEngine() override; |
206 | | TextEngine( const TextEngine& ) = delete; |
207 | | TextEngine& operator=( const TextEngine& ) = delete; |
208 | | |
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); |
214 | | |
215 | | SAL_DLLPRIVATE sal_Int32 GetTextLen() const; |
216 | | SAL_DLLPRIVATE sal_Int32 GetTextLen( const TextSelection& rSel ) const; |
217 | | |
218 | | void SetFont( const vcl::Font& rFont ); |
219 | 0 | const vcl::Font& GetFont() const { return maFont; } |
220 | | |
221 | | SAL_DLLPRIVATE void SetLeftMargin( sal_uInt16 n ); |
222 | | |
223 | | void SetUpdateMode( bool bUpdate ); |
224 | 0 | bool GetUpdateMode() const { return mbUpdate; } |
225 | | |
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 | 0 | TextView* GetActiveView() const { return mpActiveView;} |
231 | | void SetActiveView( TextView* pView ); |
232 | | |
233 | | SAL_DLLPRIVATE void SetMaxTextLen( sal_Int32 nLen ); |
234 | 0 | sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; } |
235 | | |
236 | | void SetMaxTextWidth( tools::Long nWidth ); |
237 | 0 | tools::Long GetMaxTextWidth() const { return mnMaxTextWidth; } |
238 | | |
239 | | tools::Long GetTextHeight() const; |
240 | | tools::Long CalcTextWidth(); |
241 | 0 | tools::Long GetCharHeight() const { return mnCharHeight; } |
242 | | |
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; |
247 | | |
248 | | void GetTextPortionRange(const TextPaM& rPaM, sal_Int32& nStart, sal_Int32& nEnd); |
249 | | |
250 | | sal_uInt16 GetLineCount( sal_uInt32 nParagraph ) const; |
251 | | sal_Int32 GetLineLen( sal_uInt32 nParagraph, sal_uInt16 nLine ) const; |
252 | | |
253 | | SAL_DLLPRIVATE void SetRightToLeft( bool bR2L ); |
254 | 0 | bool IsRightToLeft() const { return mbRightToLeft; } |
255 | | |
256 | 0 | 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 | 0 | bool IsInUndo() const { return mbIsInUndo; } |
262 | 0 | void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; } |
263 | | void ResetUndo(); |
264 | | |
265 | | void EnableUndo( bool bEnable ); |
266 | 0 | bool IsUndoEnabled() const { return mbUndoEnabled; } |
267 | | |
268 | 0 | void SetModified( bool bModified ) { mbModified = bModified; } |
269 | 0 | bool IsModified() const { return mbModified; } |
270 | | |
271 | | bool Read( SvStream& rInput, const TextSelection* pSel = nullptr ); |
272 | | |
273 | | void Write( SvStream& rOutput ); |
274 | | |
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 ); |
278 | | |
279 | | const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const; |
280 | | SAL_DLLPRIVATE const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const; |
281 | | |
282 | | void RemoveAttribs( sal_uInt32 nPara ); |
283 | | void SetAttrib( const TextAttrib& rAttr, sal_uInt32 nPara, sal_Int32 nStart, sal_Int32 nEnd ); |
284 | | |
285 | 0 | TxtAlign GetTextAlign() const { return meAlign; } |
286 | | SAL_DLLPRIVATE void SetTextAlign( TxtAlign eAlign ); |
287 | | |
288 | | SAL_DLLPRIVATE void Draw( OutputDevice* pDev, const Point& rPos ); |
289 | | |
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(); |
293 | | |
294 | | static bool DoesKeyChangeText( const KeyEvent& rKeyEvent ); |
295 | | SAL_DLLPRIVATE static bool IsSimpleCharInput( const KeyEvent& rKeyEvent ); |
296 | | |
297 | 0 | const Color& GetTextColor() const { return maTextColor; } |
298 | | }; |
299 | | |
300 | | #endif // INCLUDED_VCL_TEXTENG_HXX |
301 | | |
302 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |