fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / vcl / texteng.hxx
blob85b5a7b59a259ef8e676a5c02bfdedb04ee66e44
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 _TEXTENG_HXX
20 #define _TEXTENG_HXX
22 #include <vcl/dllapi.h>
24 class TextDoc;
25 class TextView;
26 class TextPaM;
27 class TextSelection;
28 class TEParaPortions;
29 class TextAttrib;
30 class TextCharAttrib;
31 class TextUndo;
32 class TextUndoManager;
33 class EditSelFunctionSet;
34 class IdleFormatter;
35 class TextNode;
36 class OutputDevice;
37 class SfxUndoAction;
38 class KeyEvent;
39 class Timer;
41 namespace svl
43 class IUndoManager;
46 class TextLine;
47 class TETextPortion;
48 #include <svl/brdcst.hxx>
49 #include <tools/link.hxx>
50 #include <vcl/font.hxx>
51 #include <tools/string.hxx>
52 #include <tools/gen.hxx>
54 #include <com/sun/star/lang/Locale.hpp>
55 #include <com/sun/star/uno/Reference.hxx>
57 struct TEIMEInfos;
58 class SvtCTLOptions;
60 namespace com {
61 namespace sun {
62 namespace star {
63 namespace i18n {
64 class XBreakIterator;
65 class XExtendedInputSequenceChecker;
66 }}}}
68 class LocaleDataWrapper;
70 enum TxtAlign { TXTALIGN_LEFT, TXTALIGN_CENTER, TXTALIGN_RIGHT };
72 typedef std::vector<TextView*> TextViews;
74 class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
76 friend class TextView;
77 friend class TextSelFunctionSet;
78 friend class ExtTextEngine;
79 friend class ExtTextView;
81 friend class TextUndo;
82 friend class TextUndoManager;
83 friend class TextUndoDelPara;
84 friend class TextUndoConnectParas;
85 friend class TextUndoSplitPara;
86 friend class TextUndoInsertChars;
87 friend class TextUndoRemoveChars;
88 friend class TextUndoSetAttribs;
90 private:
91 TextDoc* mpDoc;
92 TEParaPortions* mpTEParaPortions;
93 OutputDevice* mpRefDev;
95 TextViews* mpViews;
96 TextView* mpActiveView;
98 TextUndoManager* mpUndoManager;
100 IdleFormatter* mpIdleFormatter;
102 TEIMEInfos* mpIMEInfos;
104 ::com::sun::star::lang::Locale maLocale;
105 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIterator;
107 Rectangle maInvalidRect;
108 Range maInvalidRange;
110 LocaleDataWrapper* mpLocaleDataWrapper;
112 Font maFont;
113 Color maTextColor;
114 sal_uInt16 mnCharHeight;
115 sal_uInt16 mnFixCharWidth100;
117 sal_uLong mnMaxTextLen;
118 sal_uLong mnMaxTextWidth;
119 sal_uLong mnCurTextWidth;
120 sal_uLong mnCurTextHeight;
121 sal_uLong mnDefTab;
123 TxtAlign meAlign;
125 sal_Bool mbIsFormatting : 1; // semaphore for the Hook's
126 sal_Bool mbFormatted : 1;
127 sal_Bool mbUpdate : 1;
128 sal_Bool mbModified : 1;
129 sal_Bool mbUndoEnabled : 1;
130 sal_Bool mbIsInUndo : 1;
131 sal_Bool mbDowning : 1;
132 sal_Bool mbRightToLeft : 1;
133 sal_Bool mbHasMultiLineParas : 1;
135 TextEngine( const TextEngine& ) : SfxBroadcaster() {}
136 TextEngine& operator=( const TextEngine& ) { return *this; }
138 protected:
140 void CursorMoved( sal_uLong nNode );
141 void TextModified();
143 void ImpInitDoc();
144 void ImpRemoveText();
145 TextPaM ImpDeleteText( const TextSelection& rSel );
146 TextPaM ImpInsertText( const TextSelection& rSel, sal_Unicode c, sal_Bool bOverwrite = sal_False );
147 TextPaM ImpInsertText( const TextSelection& rSel, const String& rText );
148 TextPaM ImpInsertParaBreak( const TextSelection& rTextSelection, sal_Bool bKeepEndingAttribs = sal_True );
149 TextPaM ImpInsertParaBreak( const TextPaM& rPaM, sal_Bool bKeepEndingAttribs = sal_True );
150 void ImpRemoveChars( const TextPaM& rPaM, sal_uInt16 nChars, SfxUndoAction* pCurUndo = 0 );
151 TextPaM ImpConnectParagraphs( sal_uLong nLeft, sal_uLong nRight );
152 void ImpRemoveParagraph( sal_uLong nPara );
153 void ImpInitWritingDirections( sal_uLong nPara );
154 LocaleDataWrapper* ImpGetLocaleDataWrapper();
156 // to remain compatible in the minor release we copy the above ImpInsertText
157 // function and add the extra parameter we need but make sure this function
158 // gets not exported. First and seconf parameter swapped to have a different signatur.
159 SAL_DLLPRIVATE TextPaM ImpInsertText( sal_Unicode c, const TextSelection& rSel, sal_Bool bOverwrite = sal_False, sal_Bool bIsUserInput = sal_False );
160 // some other new functions needed that must not be exported to remain compatible
161 SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > GetInputSequenceChecker() const;
162 SAL_DLLPRIVATE sal_Bool IsInputSequenceCheckingRequired( sal_Unicode c, const TextSelection& rCurSel ) const;
164 // broadcast or adjust selections
165 void ImpParagraphInserted( sal_uLong nPara );
166 void ImpParagraphRemoved( sal_uLong nPara );
167 void ImpCharsRemoved( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
168 void ImpCharsInserted( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
169 void ImpFormattingParagraph( sal_uLong nPara );
170 void ImpTextHeightChanged();
171 void ImpTextFormatted();
173 DECL_LINK( IdleFormatHdl, void * );
174 void CheckIdleFormatter();
175 void IdleFormatAndUpdate( TextView* pCurView = 0, sal_uInt16 nMaxTimerRestarts = 5 );
177 sal_Bool CreateLines( sal_uLong nPara );
178 void CreateAndInsertEmptyLine( sal_uLong nPara );
179 void ImpBreakLine( sal_uLong nPara, TextLine* pLine, TETextPortion* pPortion, sal_uInt16 nPortionStart, long nRemainingWidth );
180 sal_uInt16 SplitTextPortion( sal_uLong nPara, sal_uInt16 nPos );
181 void CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos );
182 void RecalcTextPortion( sal_uLong nPara, sal_uInt16 nStartPos, short nNewChars );
183 void SeekCursor( sal_uLong nNode, sal_uInt16 nPos, Font& rFont, OutputDevice* pOutDev );
185 void FormatDoc();
186 void FormatFullDoc();
187 void FormatAndUpdate( TextView* pCurView = 0 );
188 sal_Bool IsFormatting() const { return mbIsFormatting; }
189 void UpdateViews( TextView* pCurView = 0 );
191 void ImpPaint( OutputDevice* pOut, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange = 0, TextSelection const* pSelection = 0 );
193 void UpdateSelections();
195 sal_Bool IsFormatted() const { return mbFormatted; }
197 sal_uInt16 GetCharPos( sal_uLong nPara, sal_uInt16 nLine, long nDocPosX, sal_Bool bSmart = sal_False );
198 Rectangle GetEditCursor( const TextPaM& rPaM, sal_Bool bSpecial, sal_Bool bPreferPortionStart = sal_False );
199 sal_uInt16 ImpFindIndex( sal_uLong nPortion, const Point& rPosInPara, sal_Bool bSmart );
200 long ImpGetPortionXOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nTextPortion );
201 long ImpGetXPos( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, sal_Bool bPreferPortionStart = sal_False );
202 long ImpGetOutputOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, sal_uInt16 nIndex2 );
203 sal_uInt8 ImpGetRightToLeft( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16* pStart = NULL, sal_uInt16* pEnd = NULL );
204 void ImpInitLayoutMode( OutputDevice* pOutDev, sal_Bool bDrawingR2LPortion = sal_False );
205 TxtAlign ImpGetAlign() const;
207 sal_uLong CalcTextHeight();
208 sal_uLong CalcParaHeight( sal_uLong nParagraph ) const;
209 sal_uLong CalcTextWidth( sal_uLong nPara );
210 sal_uLong CalcTextWidth( sal_uLong nPara, sal_uInt16 nPortionStart, sal_uInt16 nPortionLen, const Font* pFont = 0 );
211 Range GetInvalidYOffsets( sal_uLong nPortion );
213 // for Undo/Redo
214 void InsertContent( TextNode* pNode, sal_uLong nPara );
215 TextPaM SplitContent( sal_uLong nNode, sal_uInt16 nSepPos );
216 TextPaM ConnectContents( sal_uLong nLeftNode );
218 // adjust PaM's and selections that were transfered to the API to a valid range
219 void ValidateSelection( TextSelection& rSel ) const;
220 void ValidatePaM( TextPaM& rPaM ) const;
222 public:
223 TextEngine();
224 ~TextEngine();
226 void SetText( const OUString& rStr );
227 String GetText( LineEnd aSeparator = LINEEND_LF ) const;
228 String GetText( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
229 String GetTextLines( LineEnd aSeparator = LINEEND_LF ) const;
230 void ReplaceText(const TextSelection& rSel, const String& rText);
232 sal_uLong GetTextLen( LineEnd aSeparator = LINEEND_LF ) const;
233 sal_uLong GetTextLen( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
235 void SetFont( const Font& rFont );
236 const Font& GetFont() const { return maFont; }
238 sal_uInt16 GetDefTab() const;
240 void SetLeftMargin( sal_uInt16 n );
241 sal_uInt16 GetLeftMargin() const;
243 void SetUpdateMode( sal_Bool bUpdate );
244 sal_Bool GetUpdateMode() const { return mbUpdate; }
246 sal_uInt16 GetViewCount() const;
247 TextView* GetView( sal_uInt16 nView ) const;
248 void InsertView( TextView* pTextView );
249 void RemoveView( TextView* pTextView );
250 TextView* GetActiveView() const;
251 void SetActiveView( TextView* pView );
253 void SetMaxTextLen( sal_uLong nLen );
254 sal_uLong GetMaxTextLen() const { return mnMaxTextLen; }
256 void SetMaxTextWidth( sal_uLong nWidth );
257 sal_uLong GetMaxTextWidth() const { return mnMaxTextWidth; }
259 sal_uLong GetTextHeight() const;
260 sal_uLong CalcTextWidth();
261 sal_uInt16 GetCharHeight() const { return mnCharHeight; }
263 sal_uLong GetParagraphCount() const;
264 String GetText( sal_uLong nParagraph ) const;
265 sal_uInt16 GetTextLen( sal_uLong nParagraph ) const;
266 sal_uLong GetTextHeight( sal_uLong nParagraph ) const;
268 sal_uInt16 GetLineCount( sal_uLong nParagraph ) const;
269 sal_uInt16 GetLineLen( sal_uLong nParagraph, sal_uInt16 nLine ) const;
271 void SetRightToLeft( sal_Bool bR2L );
272 sal_Bool IsRightToLeft() const { return mbRightToLeft; }
274 sal_Bool HasUndoManager() const { return mpUndoManager ? sal_True : sal_False; }
275 ::svl::IUndoManager&
276 GetUndoManager();
277 void UndoActionStart( sal_uInt16 nId = 0 );
278 void UndoActionEnd();
279 void InsertUndo( TextUndo* pUndo, sal_Bool bTryMerge = sal_False );
280 sal_Bool IsInUndo() { return mbIsInUndo; }
281 void SetIsInUndo( sal_Bool bInUndo ) { mbIsInUndo = bInUndo; }
282 void ResetUndo();
284 void EnableUndo( sal_Bool bEnable );
285 sal_Bool IsUndoEnabled() { return mbUndoEnabled; }
287 void SetModified( sal_Bool bModified ) { mbModified = bModified; }
288 sal_Bool IsModified() const { return mbModified; }
290 sal_Bool Read( SvStream& rInput, const TextSelection* pSel = NULL );
292 sal_Bool Write( SvStream& rOutput, const TextSelection* pSel = NULL, sal_Bool bHTML = sal_False );
294 TextPaM GetPaM( const Point& rDocPos, sal_Bool bSmart = sal_True );
295 Rectangle PaMtoEditCursor( const TextPaM& rPaM, sal_Bool bSpecial = sal_False );
296 String GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord = 0 );
298 sal_Bool HasAttrib( sal_uInt16 nWhich ) const;
299 const TextAttrib* FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
300 const TextCharAttrib* FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
302 void RemoveAttribs( sal_uLong nPara, sal_uInt16 nWhich, sal_Bool bIdleFormatAndUpdate );
303 void RemoveAttrib( sal_uLong nPara, const TextCharAttrib& rAttrib );
304 void RemoveAttribs( sal_uLong nPara, sal_Bool bIdleFormatAndUpdate = sal_True );
305 void SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd, sal_Bool bIdleFormatAndUpdate = sal_True );
307 TxtAlign GetTextAlign() const { return meAlign; }
308 void SetTextAlign( TxtAlign eAlign );
310 void Draw( OutputDevice* pDev, const Point& rPos );
312 void SetLocale( const ::com::sun::star::lang::Locale& rLocale );
313 ::com::sun::star::lang::Locale GetLocale();
314 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > GetBreakIterator();
316 static sal_Bool DoesKeyChangeText( const KeyEvent& rKeyEvent );
317 static sal_Bool IsSimpleCharInput( const KeyEvent& rKeyEvent );
320 #endif // _TEXTENG_HXX
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */