Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / texteng.hxx
blob83e715a73816cf12bf2095efcc6c593c02f1f68d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
22 #include <memory>
23 #include <sal/config.h>
25 #include <cstddef>
27 #include <vcl/dllapi.h>
28 #include <vcl/vclptr.hxx>
29 #include <rtl/ustring.hxx>
30 #include <svl/SfxBroadcaster.hxx>
31 #include <tools/lineend.hxx>
32 #include <tools/link.hxx>
33 #include <tools/gen.hxx>
34 #include <vcl/font.hxx>
36 #include <com/sun/star/lang/Locale.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
39 class TextDoc;
40 class TextView;
41 class TextPaM;
42 class TextSelection;
43 class TEParaPortions;
44 class TextAttrib;
45 class TextCharAttrib;
46 class TextUndo;
47 class TextUndoManager;
48 class EditSelFunctionSet;
49 class Idle;
50 class IdleFormatter;
51 class TextNode;
52 class OutputDevice;
53 class SfxUndoAction;
54 class KeyEvent;
55 class Timer;
57 namespace svl
59 class IUndoManager;
62 class TextLine;
63 class TETextPortion;
65 struct TEIMEInfos;
66 class SvtCTLOptions;
68 namespace com {
69 namespace sun {
70 namespace star {
71 namespace i18n {
72 class XBreakIterator;
73 class XExtendedInputSequenceChecker;
74 }}}}
76 class LocaleDataWrapper;
78 enum class TxtAlign { Left, Center, Right };
80 typedef std::vector<TextView*> TextViews;
82 class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
84 friend class TextView;
85 friend class TextSelFunctionSet;
86 friend class ExtTextEngine;
88 friend class TextUndo;
89 friend class TextUndoManager;
90 friend class TextUndoDelPara;
91 friend class TextUndoConnectParas;
92 friend class TextUndoSplitPara;
93 friend class TextUndoInsertChars;
94 friend class TextUndoRemoveChars;
96 private:
97 TextDoc* mpDoc;
98 TEParaPortions* mpTEParaPortions;
99 VclPtr<OutputDevice> mpRefDev;
101 TextViews* mpViews;
102 TextView* mpActiveView;
104 TextUndoManager* mpUndoManager;
106 IdleFormatter* mpIdleFormatter;
108 std::unique_ptr<TEIMEInfos> mpIMEInfos;
110 css::lang::Locale maLocale;
111 css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator;
112 css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC;
114 tools::Rectangle maInvalidRect;
116 LocaleDataWrapper* mpLocaleDataWrapper;
118 vcl::Font maFont;
119 Color maTextColor;
121 sal_Int32 mnMaxTextLen;
122 long mnMaxTextWidth;
123 long mnCharHeight;
124 long mnCurTextWidth;
125 long mnCurTextHeight;
126 long mnDefTab;
128 TxtAlign meAlign;
130 bool mbIsFormatting : 1; // semaphore for the Hook's
131 bool mbFormatted : 1;
132 bool mbUpdate : 1;
133 bool mbModified : 1;
134 bool mbUndoEnabled : 1;
135 bool mbIsInUndo : 1;
136 bool mbDowning : 1;
137 bool mbRightToLeft : 1;
138 bool mbHasMultiLineParas : 1;
140 TextEngine( const TextEngine& ) : SfxBroadcaster() {}
141 TextEngine& operator=( const TextEngine& ) { return *this; }
143 protected:
145 void CursorMoved( sal_uInt32 nNode );
146 void TextModified();
148 void ImpInitDoc();
149 void ImpRemoveText();
150 TextPaM ImpDeleteText( const TextSelection& rSel );
151 TextPaM ImpInsertText( const TextSelection& rSel, sal_Unicode c, bool bOverwrite = false );
152 TextPaM ImpInsertText( const TextSelection& rSel, const OUString& rText );
153 TextPaM ImpInsertParaBreak( const TextSelection& rTextSelection );
154 TextPaM ImpInsertParaBreak( const TextPaM& rPaM );
155 void ImpRemoveChars( const TextPaM& rPaM, sal_Int32 nChars );
156 TextPaM ImpConnectParagraphs( sal_uInt32 nLeft, sal_uInt32 nRight );
157 void ImpRemoveParagraph( sal_uInt32 nPara );
158 void ImpInitWritingDirections( sal_uInt32 nPara );
159 LocaleDataWrapper* ImpGetLocaleDataWrapper();
161 // to remain compatible in the minor release we copy the above ImpInsertText
162 // function and add the extra parameter we need but make sure this function
163 // gets not exported. First and second parameter swapped to have a different signature.
164 SAL_DLLPRIVATE TextPaM ImpInsertText( sal_Unicode c, const TextSelection& rSel, bool bOverwrite, bool bIsUserInput = false );
165 // some other new functions needed that must not be exported to remain compatible
166 SAL_DLLPRIVATE css::uno::Reference< css::i18n::XExtendedInputSequenceChecker > const & GetInputSequenceChecker();
167 SAL_DLLPRIVATE bool IsInputSequenceCheckingRequired( sal_Unicode c, const TextSelection& rCurSel ) const;
169 // broadcast or adjust selections
170 void ImpParagraphInserted( sal_uInt32 nPara );
171 void ImpParagraphRemoved( sal_uInt32 nPara );
172 void ImpCharsRemoved( sal_uInt32 nPara, sal_Int32 nPos, sal_Int32 nChars );
173 void ImpCharsInserted( sal_uInt32 nPara, sal_Int32 nPos, sal_Int32 nChars );
175 DECL_LINK( IdleFormatHdl, Timer *, void );
176 void CheckIdleFormatter();
177 void IdleFormatAndUpdate( TextView* pCurView, sal_uInt16 nMaxTimerRestarts = 5 );
179 bool CreateLines( sal_uInt32 nPara );
180 void CreateAndInsertEmptyLine( sal_uInt32 nPara );
181 void ImpBreakLine( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nPortionStart, long nRemainingWidth );
182 std::size_t SplitTextPortion( sal_uInt32 nPara, sal_Int32 nPos );
183 void CreateTextPortions( sal_uInt32 nPara, sal_Int32 nStartPos );
184 void RecalcTextPortion( sal_uInt32 nPara, sal_Int32 nStartPos, sal_Int32 nNewChars );
185 void SeekCursor( sal_uInt32 nNode, sal_Int32 nPos, vcl::Font& rFont, OutputDevice* pOutDev );
187 void FormatDoc();
188 void FormatFullDoc();
189 void FormatAndUpdate( TextView* pCurView = nullptr );
190 bool IsFormatting() const { return mbIsFormatting; }
191 void UpdateViews( TextView* pCurView = nullptr );
193 void ImpPaint( OutputDevice* pOut, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection = nullptr );
195 bool IsFormatted() const { return mbFormatted; }
197 sal_Int32 GetCharPos( sal_uInt32 nPara, std::vector<TextLine>::size_type nLine, long nDocPosX );
198 tools::Rectangle GetEditCursor( const TextPaM& rPaM, bool bSpecial, bool bPreferPortionStart = false );
199 sal_Int32 ImpFindIndex( sal_uInt32 nPortion, const Point& rPosInPara );
200 long ImpGetPortionXOffset( sal_uInt32 nPara, TextLine* pLine, std::size_t nTextPortion );
201 long ImpGetXPos( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nIndex, bool bPreferPortionStart = false );
202 long ImpGetOutputOffset( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nIndex, sal_Int32 nIndex2 );
203 sal_uInt8 ImpGetRightToLeft( sal_uInt32 nPara, sal_Int32 nPos );
204 static void ImpInitLayoutMode( OutputDevice* pOutDev );
205 TxtAlign ImpGetAlign() const;
207 long CalcTextHeight();
208 long CalcParaHeight( sal_uInt32 nParagraph ) const;
209 long CalcTextWidth( sal_uInt32 nPara );
210 long CalcTextWidth( sal_uInt32 nPara, sal_Int32 nPortionStart, sal_Int32 nPortionLen);
211 Range GetInvalidYOffsets( sal_uInt32 nPortion );
213 // for Undo/Redo
214 void InsertContent( TextNode* pNode, sal_uInt32 nPara );
215 TextPaM SplitContent( sal_uInt32 nNode, sal_Int32 nSepPos );
216 TextPaM ConnectContents( sal_uInt32 nLeftNode );
218 // adjust PaM's and selections that were transferred to the API to a valid range
219 void ValidateSelection( TextSelection& rSel ) const;
220 void ValidatePaM( TextPaM& rPaM ) const;
222 public:
223 TextEngine();
224 virtual ~TextEngine() override;
226 void SetText( const OUString& rStr );
227 OUString GetText( LineEnd aSeparator = LINEEND_LF ) const;
228 OUString GetText( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
229 OUString GetTextLines( LineEnd aSeparator = LINEEND_LF ) const;
230 void ReplaceText(const TextSelection& rSel, const OUString& rText);
232 sal_Int32 GetTextLen() const;
233 sal_Int32 GetTextLen( const TextSelection& rSel ) const;
235 void SetFont( const vcl::Font& rFont );
236 const vcl::Font& GetFont() const { return maFont; }
238 void SetLeftMargin( sal_uInt16 n );
240 void SetUpdateMode( bool bUpdate );
241 bool GetUpdateMode() const { return mbUpdate; }
243 sal_uInt16 GetViewCount() const;
244 TextView* GetView( sal_uInt16 nView ) const;
245 void InsertView( TextView* pTextView );
246 void RemoveView( TextView* pTextView );
247 TextView* GetActiveView() const { return mpActiveView;}
248 void SetActiveView( TextView* pView );
250 void SetMaxTextLen( sal_Int32 nLen );
251 sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
253 void SetMaxTextWidth( long nWidth );
254 long GetMaxTextWidth() const { return mnMaxTextWidth; }
256 long GetTextHeight() const;
257 long CalcTextWidth();
258 long GetCharHeight() const { return mnCharHeight; }
260 sal_uInt32 GetParagraphCount() const;
261 OUString GetText( sal_uInt32 nParagraph ) const;
262 sal_Int32 GetTextLen( sal_uInt32 nParagraph ) const;
263 long GetTextHeight( sal_uInt32 nParagraph ) const;
265 void GetTextPortionRange(const TextPaM& rPaM, sal_Int32& nStart, sal_Int32& nEnd);
267 sal_uInt16 GetLineCount( sal_uInt32 nParagraph ) const;
268 sal_Int32 GetLineLen( sal_uInt32 nParagraph, sal_uInt16 nLine ) const;
270 void SetRightToLeft( bool bR2L );
271 bool IsRightToLeft() const { return mbRightToLeft; }
273 bool HasUndoManager() const { return mpUndoManager != nullptr; }
274 ::svl::IUndoManager&
275 GetUndoManager();
276 void UndoActionStart( sal_uInt16 nId = 0 );
277 void UndoActionEnd();
278 void InsertUndo( TextUndo* pUndo, bool bTryMerge = false );
279 bool IsInUndo() { return mbIsInUndo; }
280 void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; }
281 void ResetUndo();
283 void EnableUndo( bool bEnable );
284 bool IsUndoEnabled() { return mbUndoEnabled; }
286 void SetModified( bool bModified ) { mbModified = bModified; }
287 bool IsModified() const { return mbModified; }
289 bool Read( SvStream& rInput, const TextSelection* pSel = nullptr );
291 bool Write( SvStream& rOutput, const TextSelection* pSel = nullptr, bool bHTML = false );
293 TextPaM GetPaM( const Point& rDocPos );
294 tools::Rectangle PaMtoEditCursor( const TextPaM& rPaM, bool bSpecial = false );
295 OUString GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord = nullptr );
297 bool HasAttrib( sal_uInt16 nWhich ) const;
298 const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
299 const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
301 void RemoveAttribs( sal_uInt32 nPara, sal_uInt16 nWhich );
302 void RemoveAttrib( sal_uInt32 nPara, const TextCharAttrib& rAttrib );
303 void RemoveAttribs( sal_uInt32 nPara );
304 void SetAttrib( const TextAttrib& rAttr, sal_uInt32 nPara, sal_Int32 nStart, sal_Int32 nEnd, bool bIdleFormatAndUpdate = true );
306 TxtAlign GetTextAlign() const { return meAlign; }
307 void SetTextAlign( TxtAlign eAlign );
309 void Draw( OutputDevice* pDev, const Point& rPos );
311 void SetLocale( const css::lang::Locale& rLocale );
312 css::lang::Locale const & GetLocale();
313 css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIterator();
315 static bool DoesKeyChangeText( const KeyEvent& rKeyEvent );
316 static bool IsSimpleCharInput( const KeyEvent& rKeyEvent );
318 const Color& GetTextColor() const { return maTextColor; }
321 #endif // INCLUDED_VCL_TEXTENG_HXX
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */