bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / vcl / texteng.hxx
blob95da903bc1d41b7707cde48077b304fec385e3c2
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>
26 #include <vector>
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>
41 class TextDoc;
42 class TextView;
43 class TextPaM;
44 class TextSelection;
45 class TEParaPortions;
46 class TextAttrib;
47 class TextCharAttrib;
48 class TextUndo;
49 class TextUndoManager;
50 class IdleFormatter;
51 class TextNode;
52 class OutputDevice;
53 class KeyEvent;
54 class Timer;
55 class SfxUndoManager;
56 class TextLine;
57 struct TEIMEInfos;
59 namespace com {
60 namespace sun {
61 namespace star {
62 namespace i18n {
63 class XBreakIterator;
64 class XExtendedInputSequenceChecker;
65 }}}}
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;
108 vcl::Font maFont;
109 vcl::Font maOrigFont; // original font from SetFont
110 Color maTextColor;
112 sal_Int32 mnMaxTextLen;
113 long mnMaxTextWidth;
114 long mnCharHeight;
115 long mnCurTextWidth;
116 long mnCurTextHeight;
117 long mnDefTab;
119 TxtAlign meAlign;
121 bool mbIsFormatting : 1; // semaphore for the Hook's
122 bool mbFormatted : 1;
123 bool mbUpdate : 1;
124 bool mbModified : 1;
125 bool mbUndoEnabled : 1;
126 bool mbIsInUndo : 1;
127 bool mbDowning : 1;
128 bool mbRightToLeft : 1;
129 bool mbHasMultiLineParas : 1;
131 void CursorMoved( sal_uInt32 nNode );
132 void TextModified();
134 void ImpInitDoc();
135 void ImpRemoveText();
136 TextPaM ImpDeleteText( const TextSelection& rSel );
137 TextPaM ImpInsertText( const TextSelection& rSel, sal_Unicode c, bool bOverwrite = false );
138 TextPaM ImpInsertText( const TextSelection& rSel, const OUString& rText );
139 TextPaM ImpInsertParaBreak( const TextSelection& rTextSelection );
140 TextPaM ImpInsertParaBreak( const TextPaM& rPaM );
141 void ImpRemoveChars( const TextPaM& rPaM, sal_Int32 nChars );
142 TextPaM ImpConnectParagraphs( sal_uInt32 nLeft, sal_uInt32 nRight );
143 void ImpRemoveParagraph( sal_uInt32 nPara );
144 void ImpInitWritingDirections( sal_uInt32 nPara );
145 LocaleDataWrapper* ImpGetLocaleDataWrapper();
147 // to remain compatible in the minor release we copy the above ImpInsertText
148 // function and add the extra parameter we need but make sure this function
149 // gets not exported. First and second parameter swapped to have a different signature.
150 SAL_DLLPRIVATE TextPaM ImpInsertText( sal_Unicode c, const TextSelection& rSel, bool bOverwrite, bool bIsUserInput = false );
151 // some other new functions needed that must not be exported to remain compatible
152 SAL_DLLPRIVATE css::uno::Reference< css::i18n::XExtendedInputSequenceChecker > const & GetInputSequenceChecker();
153 SAL_DLLPRIVATE bool IsInputSequenceCheckingRequired( sal_Unicode c, const TextSelection& rCurSel ) const;
155 // broadcast or adjust selections
156 void ImpParagraphInserted( sal_uInt32 nPara );
157 void ImpParagraphRemoved( sal_uInt32 nPara );
158 void ImpCharsRemoved( sal_uInt32 nPara, sal_Int32 nPos, sal_Int32 nChars );
159 void ImpCharsInserted( sal_uInt32 nPara, sal_Int32 nPos, sal_Int32 nChars );
161 DECL_LINK( IdleFormatHdl, Timer *, void );
162 void CheckIdleFormatter();
163 void IdleFormatAndUpdate( TextView* pCurView, sal_uInt16 nMaxTimerRestarts = 5 );
165 bool CreateLines( sal_uInt32 nPara );
166 void CreateAndInsertEmptyLine( sal_uInt32 nPara );
167 void ImpBreakLine( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nPortionStart, long nRemainingWidth );
168 std::size_t SplitTextPortion( sal_uInt32 nPara, sal_Int32 nPos );
169 void CreateTextPortions( sal_uInt32 nPara, sal_Int32 nStartPos );
170 void RecalcTextPortion( sal_uInt32 nPara, sal_Int32 nStartPos, sal_Int32 nNewChars );
171 void SeekCursor( sal_uInt32 nNode, sal_Int32 nPos, vcl::Font& rFont, OutputDevice* pOutDev );
173 void FormatDoc();
174 void FormatFullDoc();
175 void FormatAndUpdate( TextView* pCurView = nullptr );
176 bool IsFormatting() const { return mbIsFormatting; }
177 void UpdateViews( TextView* pCurView = nullptr );
179 void ImpPaint( OutputDevice* pOut, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection = nullptr );
181 bool IsFormatted() const { return mbFormatted; }
183 sal_Int32 GetCharPos( sal_uInt32 nPara, std::vector<TextLine>::size_type nLine, long nDocPosX );
184 tools::Rectangle GetEditCursor( const TextPaM& rPaM, bool bSpecial, bool bPreferPortionStart = false );
185 sal_Int32 ImpFindIndex( sal_uInt32 nPortion, const Point& rPosInPara );
186 long ImpGetPortionXOffset( sal_uInt32 nPara, TextLine const * pLine, std::size_t nTextPortion );
187 long ImpGetXPos( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nIndex, bool bPreferPortionStart = false );
188 long ImpGetOutputOffset( sal_uInt32 nPara, TextLine* pLine, sal_Int32 nIndex, sal_Int32 nIndex2 );
189 bool ImpGetRightToLeft( sal_uInt32 nPara, sal_Int32 nPos );
190 static void ImpInitLayoutMode( OutputDevice* pOutDev );
191 TxtAlign ImpGetAlign() const;
193 long CalcTextHeight();
194 long CalcParaHeight( sal_uInt32 nParagraph ) const;
195 long CalcTextWidth( sal_uInt32 nPara );
196 long CalcTextWidth( sal_uInt32 nPara, sal_Int32 nPortionStart, sal_Int32 nPortionLen);
197 Range GetInvalidYOffsets( sal_uInt32 nPortion );
199 // for Undo/Redo
200 void InsertContent( std::unique_ptr<TextNode> pNode, sal_uInt32 nPara );
201 TextPaM SplitContent( sal_uInt32 nNode, sal_Int32 nSepPos );
202 TextPaM ConnectContents( sal_uInt32 nLeftNode );
204 // adjust PaM's and selections that were transferred to the API to a valid range
205 void ValidateSelection( TextSelection& rSel ) const;
206 void ValidatePaM( TextPaM& rPaM ) const;
208 public:
209 TextEngine();
210 virtual ~TextEngine() override;
211 TextEngine( const TextEngine& ) = delete;
212 TextEngine& operator=( const TextEngine& ) = delete;
214 void SetText( const OUString& rStr );
215 OUString GetText( LineEnd aSeparator = LINEEND_LF ) const;
216 OUString GetText( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
217 OUString GetTextLines( LineEnd aSeparator = LINEEND_LF ) const;
218 void ReplaceText(const TextSelection& rSel, const OUString& rText);
220 sal_Int32 GetTextLen() const;
221 sal_Int32 GetTextLen( const TextSelection& rSel ) const;
223 void SetFont( const vcl::Font& rFont );
224 const vcl::Font& GetFont() const { return maOrigFont; }
226 void SetLeftMargin( sal_uInt16 n );
228 void SetUpdateMode( bool bUpdate );
229 bool GetUpdateMode() const { return mbUpdate; }
231 sal_uInt16 GetViewCount() const;
232 TextView* GetView( sal_uInt16 nView ) const;
233 void InsertView( TextView* pTextView );
234 void RemoveView( TextView* pTextView );
235 TextView* GetActiveView() const { return mpActiveView;}
236 void SetActiveView( TextView* pView );
238 void SetMaxTextLen( sal_Int32 nLen );
239 sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
241 void SetMaxTextWidth( long nWidth );
242 long GetMaxTextWidth() const { return mnMaxTextWidth; }
244 long GetTextHeight() const;
245 long CalcTextWidth();
246 long GetCharHeight() const { return mnCharHeight; }
248 sal_uInt32 GetParagraphCount() const;
249 OUString GetText( sal_uInt32 nParagraph ) const;
250 sal_Int32 GetTextLen( sal_uInt32 nParagraph ) const;
251 long GetTextHeight( sal_uInt32 nParagraph ) const;
253 void GetTextPortionRange(const TextPaM& rPaM, sal_Int32& nStart, sal_Int32& nEnd);
255 sal_uInt16 GetLineCount( sal_uInt32 nParagraph ) const;
256 sal_Int32 GetLineLen( sal_uInt32 nParagraph, sal_uInt16 nLine ) const;
258 void SetRightToLeft( bool bR2L );
259 bool IsRightToLeft() const { return mbRightToLeft; }
261 bool HasUndoManager() const { return mpUndoManager != nullptr; }
262 SfxUndoManager& GetUndoManager();
263 void UndoActionStart( sal_uInt16 nId = 0 );
264 void UndoActionEnd();
265 void InsertUndo( std::unique_ptr<TextUndo> pUndo, bool bTryMerge = false );
266 bool IsInUndo() { return mbIsInUndo; }
267 void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; }
268 void ResetUndo();
270 void EnableUndo( bool bEnable );
271 bool IsUndoEnabled() { return mbUndoEnabled; }
273 void SetModified( bool bModified ) { mbModified = bModified; }
274 bool IsModified() const { return mbModified; }
276 bool Read( SvStream& rInput, const TextSelection* pSel = nullptr );
278 void Write( SvStream& rOutput );
280 TextPaM GetPaM( const Point& rDocPos );
281 tools::Rectangle PaMtoEditCursor( const TextPaM& rPaM, bool bSpecial = false );
282 OUString GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord = nullptr );
284 const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
285 const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
287 void RemoveAttribs( sal_uInt32 nPara, sal_uInt16 nWhich );
288 std::unique_ptr<TextCharAttrib> RemoveAttrib( sal_uInt32 nPara, const TextCharAttrib& rAttrib );
289 void RemoveAttribs( sal_uInt32 nPara );
290 void SetAttrib( const TextAttrib& rAttr, sal_uInt32 nPara, sal_Int32 nStart, sal_Int32 nEnd, bool bIdleFormatAndUpdate = true );
292 TxtAlign GetTextAlign() const { return meAlign; }
293 void SetTextAlign( TxtAlign eAlign );
295 void Draw( OutputDevice* pDev, const Point& rPos );
297 void SetLocale( const css::lang::Locale& rLocale );
298 css::lang::Locale const & GetLocale();
299 css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIterator();
301 static bool DoesKeyChangeText( const KeyEvent& rKeyEvent );
302 static bool IsSimpleCharInput( const KeyEvent& rKeyEvent );
304 const Color& GetTextColor() const { return maTextColor; }
307 #endif // INCLUDED_VCL_TEXTENG_HXX
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */