LibreOffice Module vcl (master)  1
texteng.hxx
Go to the documentation of this file.
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 
38 #include <com/sun/star/lang/Locale.hpp>
39 #include <com/sun/star/uno/Reference.hxx>
40 
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;
58 
59 namespace com {
60 namespace sun {
61 namespace star {
62 namespace i18n {
63  class XBreakIterator;
64  class XExtendedInputSequenceChecker;
65 }}}}
66 
67 class LocaleDataWrapper;
68 
69 enum class TxtAlign { Left, Center, Right };
70 
71 typedef std::vector<TextView*> TextViews;
72 
74 {
75  friend class TextView;
76  friend class TextSelFunctionSet;
77  friend class ExtTextEngine;
78 
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;
86 
87  std::unique_ptr<TextDoc> mpDoc;
88  std::unique_ptr<TEParaPortions> mpTEParaPortions;
90 
91  std::unique_ptr<TextViews> mpViews;
93 
94  std::unique_ptr<TextUndoManager> mpUndoManager;
95 
96  std::unique_ptr<IdleFormatter> mpIdleFormatter;
97 
98  std::unique_ptr<TEIMEInfos> mpIMEInfos;
99 
100  css::lang::Locale maLocale;
101  css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator;
102  css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC;
103 
105 
106  std::unique_ptr<LocaleDataWrapper> mpLocaleDataWrapper;
107 
109  vcl::Font maOrigFont; // original font from SetFont
111 
112  sal_Int32 mnMaxTextLen;
117  long mnDefTab;
118 
120 
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;
130 
131  void CursorMoved( sal_uInt32 nNode );
132  void TextModified();
133 
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();
146 
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;
154 
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 );
160 
161  DECL_LINK( IdleFormatHdl, Timer *, void );
162  void CheckIdleFormatter();
163  void IdleFormatAndUpdate( TextView* pCurView, sal_uInt16 nMaxTimerRestarts = 5 );
164 
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 );
172 
173  void FormatDoc();
174  void FormatFullDoc();
175  void FormatAndUpdate( TextView* pCurView = nullptr );
176  bool IsFormatting() const { return mbIsFormatting; }
177  void UpdateViews( TextView* pCurView = nullptr );
178 
179  void ImpPaint( OutputDevice* pOut, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection = nullptr );
180 
181  bool IsFormatted() const { return mbFormatted; }
182 
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;
192 
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 );
198 
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 );
203 
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;
207 
208 public:
209  TextEngine();
210  virtual ~TextEngine() override;
211  TextEngine( const TextEngine& ) = delete;
212  TextEngine& operator=( const TextEngine& ) = delete;
213 
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);
219 
220  sal_Int32 GetTextLen() const;
221  sal_Int32 GetTextLen( const TextSelection& rSel ) const;
222 
223  void SetFont( const vcl::Font& rFont );
224  const vcl::Font& GetFont() const { return maOrigFont; }
225 
226  void SetLeftMargin( sal_uInt16 n );
227 
228  void SetUpdateMode( bool bUpdate );
229  bool GetUpdateMode() const { return mbUpdate; }
230 
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 );
237 
238  void SetMaxTextLen( sal_Int32 nLen );
239  sal_Int32 GetMaxTextLen() const { return mnMaxTextLen; }
240 
241  void SetMaxTextWidth( long nWidth );
242  long GetMaxTextWidth() const { return mnMaxTextWidth; }
243 
244  long GetTextHeight() const;
245  long CalcTextWidth();
246  long GetCharHeight() const { return mnCharHeight; }
247 
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;
252 
253  void GetTextPortionRange(const TextPaM& rPaM, sal_Int32& nStart, sal_Int32& nEnd);
254 
255  sal_uInt16 GetLineCount( sal_uInt32 nParagraph ) const;
256  sal_Int32 GetLineLen( sal_uInt32 nParagraph, sal_uInt16 nLine ) const;
257 
258  void SetRightToLeft( bool bR2L );
259  bool IsRightToLeft() const { return mbRightToLeft; }
260 
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() const { return mbIsInUndo; }
267  void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; }
268  void ResetUndo();
269 
270  void EnableUndo( bool bEnable );
271  bool IsUndoEnabled() const { return mbUndoEnabled; }
272 
273  void SetModified( bool bModified ) { mbModified = bModified; }
274  bool IsModified() const { return mbModified; }
275 
276  bool Read( SvStream& rInput, const TextSelection* pSel = nullptr );
277 
278  void Write( SvStream& rOutput );
279 
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 );
283 
284  const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
285  const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
286 
287  void RemoveAttribs( sal_uInt32 nPara );
288  void SetAttrib( const TextAttrib& rAttr, sal_uInt32 nPara, sal_Int32 nStart, sal_Int32 nEnd, bool bIdleFormatAndUpdate = true );
289 
290  TxtAlign GetTextAlign() const { return meAlign; }
291  void SetTextAlign( TxtAlign eAlign );
292 
293  void Draw( OutputDevice* pDev, const Point& rPos );
294 
295  void SetLocale( const css::lang::Locale& rLocale );
296  css::lang::Locale const & GetLocale();
297  css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIterator();
298 
299  static bool DoesKeyChangeText( const KeyEvent& rKeyEvent );
300  static bool IsSimpleCharInput( const KeyEvent& rKeyEvent );
301 
302  const Color& GetTextColor() const { return maTextColor; }
303 };
304 
305 #endif // INCLUDED_VCL_TEXTENG_HXX
306 
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TxtAlign meAlign
Definition: texteng.hxx:119
const vcl::Font & GetFont() const
Definition: texteng.hxx:224
TxtAlign
Definition: texteng.hxx:69
bool HasUndoManager() const
Definition: texteng.hxx:261
bool IsRightToLeft() const
Definition: texteng.hxx:259
TextView * mpActiveView
Definition: texteng.hxx:92
sal_Int32 mnMaxTextLen
Definition: texteng.hxx:112
void SetIsInUndo(bool bInUndo)
Definition: texteng.hxx:267
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long mnMaxTextWidth
Definition: texteng.hxx:113
std::unique_ptr< TEParaPortions > mpTEParaPortions
Definition: texteng.hxx:88
TxtAlign GetTextAlign() const
Definition: texteng.hxx:290
std::unique_ptr< TEIMEInfos > mpIMEInfos
Definition: texteng.hxx:98
const SfxBroadcaster & operator=(const SfxBroadcaster &)=delete
TextView * GetActiveView() const
Definition: texteng.hxx:235
sal_uInt16 sal_Unicode
tools::Rectangle maInvalidRect
Definition: texteng.hxx:104
std::vector< TextView * > TextViews
Definition: texteng.hxx:71
const Color & GetTextColor() const
Definition: texteng.hxx:302
css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator
Definition: texteng.hxx:101
long mnCharHeight
Definition: texteng.hxx:114
long mnCurTextWidth
Definition: texteng.hxx:115
bool IsUndoEnabled() const
Definition: texteng.hxx:271
bool IsModified() const
Definition: texteng.hxx:274
long GetMaxTextWidth() const
Definition: texteng.hxx:242
long mnCurTextHeight
Definition: texteng.hxx:116
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
TextView * GetView() const
Definition: textundo.hxx:60
Color maTextColor
Definition: texteng.hxx:110
sal_Int32 GetMaxTextLen() const
Definition: texteng.hxx:239
bool IsInUndo() const
Definition: texteng.hxx:266
LineEnd
std::unique_ptr< TextUndoManager > mpUndoManager
Definition: texteng.hxx:94
std::unique_ptr< IdleFormatter > mpIdleFormatter
Definition: texteng.hxx:96
std::unique_ptr< TextDoc > mpDoc
Definition: texteng.hxx:87
std::unique_ptr< TextViews > mpViews
Definition: texteng.hxx:91
long GetCharHeight() const
Definition: texteng.hxx:246
void SetModified(bool bModified)
Definition: texteng.hxx:273
vcl::Font maOrigFont
Definition: texteng.hxx:109
css::uno::Reference< css::i18n::XExtendedInputSequenceChecker > mxISC
Definition: texteng.hxx:102
VclPtr< OutputDevice > mpRefDev
Definition: texteng.hxx:89
bool IsFormatting() const
Definition: texteng.hxx:176
bool & mbUpdate
bool GetUpdateMode() const
Definition: texteng.hxx:229
Definition: timer.hxx:26
vcl::Font maFont
Definition: texteng.hxx:108
bool IsFormatted() const
Definition: texteng.hxx:181
std::unique_ptr< LocaleDataWrapper > mpLocaleDataWrapper
Definition: texteng.hxx:106
long mnDefTab
Definition: texteng.hxx:117
css::lang::Locale maLocale
Definition: texteng.hxx:100