Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / texteng.hxx
blob626094035db029b474862eb2ea709d262dc23d1e
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 <vcl/dllapi.h>
23 #include <vcl/vclptr.hxx>
25 class TextDoc;
26 class TextView;
27 class TextPaM;
28 class TextSelection;
29 class TEParaPortions;
30 class TextAttrib;
31 class TextCharAttrib;
32 class TextUndo;
33 class TextUndoManager;
34 class EditSelFunctionSet;
35 class Idle;
36 class IdleFormatter;
37 class TextNode;
38 class OutputDevice;
39 class SfxUndoAction;
40 class KeyEvent;
41 class Timer;
43 namespace svl
45 class IUndoManager;
48 class TextLine;
49 class TETextPortion;
50 #include <rtl/ustring.hxx>
51 #include <svl/SfxBroadcaster.hxx>
52 #include <tools/lineend.hxx>
53 #include <tools/link.hxx>
54 #include <tools/gen.hxx>
55 #include <vcl/font.hxx>
57 #include <com/sun/star/lang/Locale.hpp>
58 #include <com/sun/star/uno/Reference.hxx>
60 struct TEIMEInfos;
61 class SvtCTLOptions;
63 namespace com {
64 namespace sun {
65 namespace star {
66 namespace i18n {
67 class XBreakIterator;
68 class XExtendedInputSequenceChecker;
69 }}}}
71 class LocaleDataWrapper;
73 enum TxtAlign { TXTALIGN_LEFT, TXTALIGN_CENTER, TXTALIGN_RIGHT };
75 typedef std::vector<TextView*> TextViews;
77 class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
79 friend class TextView;
80 friend class TextSelFunctionSet;
81 friend class ExtTextEngine;
82 friend class ExtTextView;
84 friend class TextUndo;
85 friend class TextUndoManager;
86 friend class TextUndoDelPara;
87 friend class TextUndoConnectParas;
88 friend class TextUndoSplitPara;
89 friend class TextUndoInsertChars;
90 friend class TextUndoRemoveChars;
91 friend class TextUndoSetAttribs;
93 private:
94 TextDoc* mpDoc;
95 TEParaPortions* mpTEParaPortions;
96 VclPtr<OutputDevice> mpRefDev;
98 TextViews* mpViews;
99 TextView* mpActiveView;
101 TextUndoManager* mpUndoManager;
103 IdleFormatter* mpIdleFormatter;
105 TEIMEInfos* mpIMEInfos;
107 ::com::sun::star::lang::Locale maLocale;
108 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIterator;
109 css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > mxISC;
111 Rectangle maInvalidRect;
112 Range maInvalidRange;
114 LocaleDataWrapper* mpLocaleDataWrapper;
116 vcl::Font maFont;
117 Color maTextColor;
118 long mnCharHeight;
119 sal_uInt16 mnFixCharWidth100;
121 sal_uLong mnMaxTextLen;
122 sal_uLong mnMaxTextWidth;
123 sal_uLong mnCurTextWidth;
124 sal_uLong mnCurTextHeight;
125 sal_uLong mnDefTab;
127 TxtAlign meAlign;
129 bool mbIsFormatting : 1; // semaphore for the Hook's
130 bool mbFormatted : 1;
131 bool mbUpdate : 1;
132 bool mbModified : 1;
133 bool mbUndoEnabled : 1;
134 bool mbIsInUndo : 1;
135 bool mbDowning : 1;
136 bool mbRightToLeft : 1;
137 bool mbHasMultiLineParas : 1;
139 TextEngine( const TextEngine& ) : SfxBroadcaster() {}
140 TextEngine& operator=( const TextEngine& ) { return *this; }
142 protected:
144 void CursorMoved( sal_uLong nNode );
145 void TextModified();
147 void ImpInitDoc();
148 void ImpRemoveText();
149 TextPaM ImpDeleteText( const TextSelection& rSel );
150 TextPaM ImpInsertText( const TextSelection& rSel, sal_Unicode c, bool bOverwrite = false );
151 TextPaM ImpInsertText( const TextSelection& rSel, const OUString& rText );
152 TextPaM ImpInsertParaBreak( const TextSelection& rTextSelection, bool bKeepEndingAttribs = true );
153 TextPaM ImpInsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs = true );
154 void ImpRemoveChars( const TextPaM& rPaM, sal_uInt16 nChars, SfxUndoAction* pCurUndo = 0 );
155 TextPaM ImpConnectParagraphs( sal_uLong nLeft, sal_uLong nRight );
156 void ImpRemoveParagraph( sal_uLong nPara );
157 void ImpInitWritingDirections( sal_uLong nPara );
158 LocaleDataWrapper* ImpGetLocaleDataWrapper();
160 // to remain compatible in the minor release we copy the above ImpInsertText
161 // function and add the extra parameter we need but make sure this function
162 // gets not exported. First and seconf parameter swapped to have a different signatur.
163 SAL_DLLPRIVATE TextPaM ImpInsertText( sal_Unicode c, const TextSelection& rSel, bool bOverwrite = false, bool bIsUserInput = false );
164 // some other new functions needed that must not be exported to remain compatible
165 SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > GetInputSequenceChecker();
166 SAL_DLLPRIVATE bool IsInputSequenceCheckingRequired( sal_Unicode c, const TextSelection& rCurSel ) const;
168 // broadcast or adjust selections
169 void ImpParagraphInserted( sal_uLong nPara );
170 void ImpParagraphRemoved( sal_uLong nPara );
171 void ImpCharsRemoved( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
172 void ImpCharsInserted( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
173 void ImpFormattingParagraph( sal_uLong nPara );
174 void ImpTextHeightChanged();
175 void ImpTextFormatted();
177 DECL_LINK_TYPED( IdleFormatHdl, Idle *, void );
178 void CheckIdleFormatter();
179 void IdleFormatAndUpdate( TextView* pCurView = 0, sal_uInt16 nMaxTimerRestarts = 5 );
181 bool CreateLines( sal_uLong nPara );
182 void CreateAndInsertEmptyLine( sal_uLong nPara );
183 void ImpBreakLine( sal_uLong nPara, TextLine* pLine, TETextPortion* pPortion, sal_uInt16 nPortionStart, long nRemainingWidth );
184 sal_uInt16 SplitTextPortion( sal_uLong nPara, sal_uInt16 nPos );
185 void CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos );
186 void RecalcTextPortion( sal_uLong nPara, sal_uInt16 nStartPos, short nNewChars );
187 void SeekCursor( sal_uLong nNode, sal_uInt16 nPos, vcl::Font& rFont, OutputDevice* pOutDev );
189 void FormatDoc();
190 void FormatFullDoc();
191 void FormatAndUpdate( TextView* pCurView = 0 );
192 bool IsFormatting() const { return mbIsFormatting; }
193 void UpdateViews( TextView* pCurView = 0 );
195 void ImpPaint( OutputDevice* pOut, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange = 0, TextSelection const* pSelection = 0 );
197 bool IsFormatted() const { return mbFormatted; }
199 sal_uInt16 GetCharPos( sal_uLong nPara, sal_uInt16 nLine, long nDocPosX, bool bSmart = false );
200 Rectangle GetEditCursor( const TextPaM& rPaM, bool bSpecial, bool bPreferPortionStart = false );
201 sal_uInt16 ImpFindIndex( sal_uLong nPortion, const Point& rPosInPara, bool bSmart );
202 long ImpGetPortionXOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nTextPortion );
203 long ImpGetXPos( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, bool bPreferPortionStart = false );
204 long ImpGetOutputOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, sal_uInt16 nIndex2 );
205 sal_uInt8 ImpGetRightToLeft( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16* pStart = NULL, sal_uInt16* pEnd = NULL );
206 static void ImpInitLayoutMode( OutputDevice* pOutDev, bool bDrawingR2LPortion = false );
207 TxtAlign ImpGetAlign() const;
209 sal_uLong CalcTextHeight();
210 sal_uLong CalcParaHeight( sal_uLong nParagraph ) const;
211 sal_uLong CalcTextWidth( sal_uLong nPara );
212 sal_uLong CalcTextWidth( sal_uLong nPara, sal_uInt16 nPortionStart, sal_uInt16 nPortionLen, const vcl::Font* pFont = 0 );
213 Range GetInvalidYOffsets( sal_uLong nPortion );
215 // for Undo/Redo
216 void InsertContent( TextNode* pNode, sal_uLong nPara );
217 TextPaM SplitContent( sal_uLong nNode, sal_uInt16 nSepPos );
218 TextPaM ConnectContents( sal_uLong nLeftNode );
220 // adjust PaM's and selections that were transferred to the API to a valid range
221 void ValidateSelection( TextSelection& rSel ) const;
222 void ValidatePaM( TextPaM& rPaM ) const;
224 public:
225 TextEngine();
226 virtual ~TextEngine();
228 void SetText( const OUString& rStr );
229 OUString GetText( LineEnd aSeparator = LINEEND_LF ) const;
230 OUString GetText( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
231 OUString GetTextLines( LineEnd aSeparator = LINEEND_LF ) const;
232 void ReplaceText(const TextSelection& rSel, const OUString& rText);
234 sal_uLong GetTextLen( LineEnd aSeparator = LINEEND_LF ) const;
235 sal_uLong GetTextLen( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
237 void SetFont( const vcl::Font& rFont );
238 const vcl::Font& GetFont() const { return maFont; }
240 sal_uInt16 GetDefTab() const;
242 void SetLeftMargin( sal_uInt16 n );
244 void SetUpdateMode( bool bUpdate );
245 bool GetUpdateMode() const { return mbUpdate; }
247 sal_uInt16 GetViewCount() const;
248 TextView* GetView( sal_uInt16 nView ) const;
249 void InsertView( TextView* pTextView );
250 void RemoveView( TextView* pTextView );
251 TextView* GetActiveView() const { return mpActiveView;}
252 void SetActiveView( TextView* pView );
254 void SetMaxTextLen( sal_uLong nLen );
255 sal_uLong GetMaxTextLen() const { return mnMaxTextLen; }
257 void SetMaxTextWidth( sal_uLong nWidth );
258 sal_uLong GetMaxTextWidth() const { return mnMaxTextWidth; }
260 sal_uLong GetTextHeight() const;
261 sal_uLong CalcTextWidth();
262 long GetCharHeight() const { return mnCharHeight; }
264 sal_uLong GetParagraphCount() const;
265 OUString GetText( sal_uLong nParagraph ) const;
266 sal_uInt16 GetTextLen( sal_uLong nParagraph ) const;
267 sal_uLong GetTextHeight( sal_uLong nParagraph ) const;
269 sal_uInt16 GetLineCount( sal_uLong nParagraph ) const;
270 sal_uInt16 GetLineLen( sal_uLong nParagraph, sal_uInt16 nLine ) const;
272 void SetRightToLeft( bool bR2L );
273 bool IsRightToLeft() const { return mbRightToLeft; }
275 bool HasUndoManager() const { return mpUndoManager != nullptr; }
276 ::svl::IUndoManager&
277 GetUndoManager();
278 void UndoActionStart( sal_uInt16 nId = 0 );
279 void UndoActionEnd();
280 void InsertUndo( TextUndo* pUndo, bool bTryMerge = false );
281 bool IsInUndo() { return mbIsInUndo; }
282 void SetIsInUndo( bool bInUndo ) { mbIsInUndo = bInUndo; }
283 void ResetUndo();
285 void EnableUndo( bool bEnable );
286 bool IsUndoEnabled() { return mbUndoEnabled; }
288 void SetModified( bool bModified ) { mbModified = bModified; }
289 bool IsModified() const { return mbModified; }
291 bool Read( SvStream& rInput, const TextSelection* pSel = NULL );
293 bool Write( SvStream& rOutput, const TextSelection* pSel = NULL, bool bHTML = false );
295 TextPaM GetPaM( const Point& rDocPos, bool bSmart = true );
296 Rectangle PaMtoEditCursor( const TextPaM& rPaM, bool bSpecial = false );
297 OUString GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord = 0 );
299 bool HasAttrib( sal_uInt16 nWhich ) const;
300 const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
301 const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
303 void RemoveAttribs( sal_uLong nPara, sal_uInt16 nWhich, bool bIdleFormatAndUpdate );
304 void RemoveAttrib( sal_uLong nPara, const TextCharAttrib& rAttrib );
305 void RemoveAttribs( sal_uLong nPara, bool bIdleFormatAndUpdate = true );
306 void SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd, bool bIdleFormatAndUpdate = true );
308 TxtAlign GetTextAlign() const { return meAlign; }
309 void SetTextAlign( TxtAlign eAlign );
311 void Draw( OutputDevice* pDev, const Point& rPos );
313 void SetLocale( const ::com::sun::star::lang::Locale& rLocale );
314 ::com::sun::star::lang::Locale GetLocale();
315 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > GetBreakIterator();
317 static bool DoesKeyChangeText( const KeyEvent& rKeyEvent );
318 static bool IsSimpleCharInput( const KeyEvent& rKeyEvent );
320 Color GetTextColor() const { return maTextColor; }
323 #endif // INCLUDED_VCL_TEXTENG_HXX
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */