xref: /AOO41X/main/svtools/inc/svtools/texteng.hxx (revision 4d7c9de063a797b8b4f3d45e3561e82ad1f8ef1f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _TEXTENG_HXX
24 #define _TEXTENG_HXX
25 
26 #include "svtools/svtdllapi.h"
27 
28 class TextDoc;
29 class TextView;
30 class TextPaM;
31 class TextSelection;
32 class TextViews;
33 class TEParaPortions;
34 class TextAttrib;
35 class TextCharAttrib;
36 class TextUndo;
37 class TextUndoManager;
38 class EditSelFunctionSet;
39 class EditSelEngine;
40 class IdleFormatter;
41 class TextNode;
42 class OutputDevice;
43 class SfxUndoAction;
44 class KeyEvent;
45 class Timer;
46 
47 namespace svl
48 {
49     class IUndoManager;
50 }
51 
52 class TextLine;
53 class TETextPortion;
54 #include <svl/brdcst.hxx>
55 #include <tools/link.hxx>
56 #include <vcl/font.hxx>
57 #include <tools/string.hxx>
58 #include <tools/gen.hxx>
59 
60 #ifndef _COM_SUN_STAR_LOCALE_LOCALE_HPP_
61 #include <com/sun/star/lang/Locale.hpp>
62 #endif
63 #include <com/sun/star/uno/Reference.hxx>
64 
65 struct TEIMEInfos;
66 class SvtCTLOptions;
67 
68 namespace com {
69 namespace sun {
70 namespace star {
71 namespace i18n {
72     class XBreakIterator;
73     class XExtendedInputSequenceChecker;
74 }}}}
75 
76 class LocaleDataWrapper;
77 
78 enum TxtAlign { TXTALIGN_LEFT, TXTALIGN_CENTER, TXTALIGN_RIGHT };
79 
80 class SVT_DLLPUBLIC TextEngine : public SfxBroadcaster
81 {
82     friend class        TextView;
83     friend class        TextSelFunctionSet;
84     friend class        ExtTextEngine;
85     friend class        ExtTextView;
86 
87     friend class        TextUndo;
88     friend class        TextUndoManager;
89     friend class        TextUndoDelPara;
90     friend class        TextUndoConnectParas;
91     friend class        TextUndoSplitPara;
92     friend class        TextUndoInsertChars;
93     friend class        TextUndoRemoveChars;
94     friend class        TextUndoSetAttribs;
95 
96 private:
97     TextDoc*            mpDoc;
98     TEParaPortions*     mpTEParaPortions;
99     OutputDevice*       mpRefDev;
100 
101     TextViews*          mpViews;
102     TextView*           mpActiveView;
103 
104     TextUndoManager*    mpUndoManager;
105 
106     IdleFormatter*      mpIdleFormatter;
107 
108     TEIMEInfos*         mpIMEInfos;
109 
110     ::com::sun::star::lang::Locale maLocale;
111     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > mxBreakIterator;
112 
113     Rectangle           maInvalidRec;
114     Range               maInvalidRange;
115 
116     LocaleDataWrapper*  mpLocaleDataWrapper;
117 
118     Font                maFont;
119     Color               maTextColor;
120     sal_uInt16              mnCharHeight;
121     sal_uInt16              mnFixCharWidth100;
122 
123     sal_uLong               mnMaxTextLen;
124     sal_uLong               mnMaxTextWidth;
125     sal_uLong               mnCurTextWidth;
126     sal_uLong               mnCurTextHeight;
127     sal_uLong               mnDefTab;
128 
129     TxtAlign            meAlign;
130 
131     sal_Bool                mbIsFormatting      : 1;    // Semaphore wegen der Hook's
132     sal_Bool                mbFormatted         : 1;
133     sal_Bool                mbUpdate            : 1;
134     sal_Bool                mbModified          : 1;
135     sal_Bool                mbUndoEnabled       : 1;
136     sal_Bool                mbIsInUndo          : 1;
137     sal_Bool                mbDowning           : 1;
138     sal_Bool                mbRightToLeft       : 1;
139     sal_Bool                mbHasMultiLineParas : 1;
140 
TextEngine(const TextEngine &)141                         TextEngine( const TextEngine& ) : SfxBroadcaster()  {}
operator =(const TextEngine &)142     TextEngine&         operator=( const TextEngine& )      { return *this; }
143 
144 protected:
145 
146     void                CursorMoved( sal_uLong nNode );
147     void                TextModified();
148 
149     void                ImpInitDoc();
150     void                ImpRemoveText();
151     TextPaM             ImpDeleteText( const TextSelection& rSel );
152     TextPaM             ImpInsertText( const TextSelection& rSel, sal_Unicode c, sal_Bool bOverwrite = sal_False );
153     TextPaM             ImpInsertText( const TextSelection& rSel, const String& rText );
154     TextPaM             ImpInsertParaBreak( const TextSelection& rTextSelection, sal_Bool bKeepEndingAttribs = sal_True );
155     TextPaM             ImpInsertParaBreak( const TextPaM& rPaM, sal_Bool bKeepEndingAttribs = sal_True );
156     void                ImpRemoveChars( const TextPaM& rPaM, sal_uInt16 nChars, SfxUndoAction* pCurUndo = 0 );
157     TextPaM             ImpConnectParagraphs( sal_uLong nLeft, sal_uLong nRight );
158     void                ImpRemoveParagraph( sal_uLong nPara );
159     void                ImpInitWritingDirections( sal_uLong nPara );
160     LocaleDataWrapper*  ImpGetLocaleDataWrapper();
161 
162     // to remain compatible in the minor release we copy the above ImpInsertText
163     // function and add the extra parameter we need but make sure this function
164     // gets not exported. First and seconf parameter swapped to have a different signatur.
165     SAL_DLLPRIVATE TextPaM  ImpInsertText( sal_Unicode c, const TextSelection& rSel, sal_Bool bOverwrite = sal_False, sal_Bool bIsUserInput = sal_False );
166     // some other new functions needed that must not be exported to remain compatible
167     SAL_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XExtendedInputSequenceChecker > GetInputSequenceChecker() const;
168     SAL_DLLPRIVATE sal_Bool IsInputSequenceCheckingRequired( sal_Unicode c, const TextSelection& rCurSel ) const;
169 
170     // Broadcasten bzw. Selektionen anpassen:
171     void                ImpParagraphInserted( sal_uLong nPara );
172     void                ImpParagraphRemoved( sal_uLong nPara );
173     void                ImpCharsRemoved( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
174     void                ImpCharsInserted( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16 nChars );
175     void                ImpFormattingParagraph( sal_uLong nPara );
176     void                ImpTextHeightChanged();
177     void                ImpTextFormatted();
178 
179     DECL_LINK(          IdleFormatHdl, Timer * );
180     void                CheckIdleFormatter();
181     void                IdleFormatAndUpdate( TextView* pCurView = 0, sal_uInt16 nMaxTimerRestarts = 5 );
182 
183     sal_Bool                CreateLines( sal_uLong nPara );
184     void                CreateAndInsertEmptyLine( sal_uLong nPara );
185     void                ImpBreakLine( sal_uLong nPara, TextLine* pLine, TETextPortion* pPortion, sal_uInt16 nPortionStart, long nRemainingWidth );
186     sal_uInt16              SplitTextPortion( sal_uLong nPara, sal_uInt16 nPos );
187     void                CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos );
188     void                RecalcTextPortion( sal_uLong nPara, sal_uInt16 nStartPos, short nNewChars );
189     void                SeekCursor( sal_uLong nNode, sal_uInt16 nPos, Font& rFont, OutputDevice* pOutDev );
190 
191     void                FormatDoc();
192     void                FormatFullDoc();
193     void                FormatAndUpdate( TextView* pCurView = 0 );
IsFormatting() const194     sal_Bool                IsFormatting() const { return mbIsFormatting; }
195     void                UpdateViews( TextView* pCurView = 0 );
196     void                SetUpdateMode( sal_Bool bUp, TextView* pCurView, sal_Bool bForceUpdate );
197 
198     void                ImpPaint( OutputDevice* pOut, const Point& rStartPos, Rectangle const* pPaintArea, TextSelection const* pPaintRange = 0, TextSelection const* pSelection = 0 );
199 
200     void                UpdateSelections();
201 
IsFormatted() const202     sal_Bool                IsFormatted() const { return mbFormatted; }
203 
204     sal_uInt16              GetCharPos( sal_uLong nPara, sal_uInt16 nLine, long nDocPosX, sal_Bool bSmart = sal_False );
205     Rectangle           GetEditCursor( const TextPaM& rPaM, sal_Bool bSpecial, sal_Bool bPreferPortionStart = sal_False );
206     sal_uInt16              ImpFindIndex( sal_uLong nPortion, const Point& rPosInPara, sal_Bool bSmart );
207     long                ImpGetPortionXOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nTextPortion );
208     long                ImpGetXPos( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, sal_Bool bPreferPortionStart = sal_False );
209     long                ImpGetOutputOffset( sal_uLong nPara, TextLine* pLine, sal_uInt16 nIndex, sal_uInt16 nIndex2 );
210     sal_uInt8                ImpGetRightToLeft( sal_uLong nPara, sal_uInt16 nPos, sal_uInt16* pStart = NULL, sal_uInt16* pEnd = NULL );
211     void                ImpInitLayoutMode( OutputDevice* pOutDev, sal_Bool bDrawingR2LPortion = sal_False );
212     TxtAlign            ImpGetAlign() const;
213 
214     sal_uLong               CalcTextHeight();
215     sal_uLong               CalcParaHeight( sal_uLong nParagraph ) const;
216     sal_uLong               CalcTextWidth( sal_uLong nPara );
217     sal_uLong               CalcTextWidth( sal_uLong nPara, sal_uInt16 nPortionStart, sal_uInt16 nPortionLen, const Font* pFont = 0 );
218     Range               GetInvalidYOffsets( sal_uLong nPortion );
219 
220     // Fuer Undo/Redo
221     void                InsertContent( TextNode* pNode, sal_uLong nPara );
222     TextPaM             SplitContent( sal_uLong nNode, sal_uInt16 nSepPos );
223     TextPaM             ConnectContents( sal_uLong nLeftNode );
224 
225     // Ans API uebergebene PaM's und Selektionen auf einen gueltigen Bereich einstellen
226     void                ValidateSelection( TextSelection& rSel ) const;
227     void                ValidatePaM( TextPaM& rPaM ) const;
228 
229 public:
230                         TextEngine();
231                         ~TextEngine();
232 
233     void                SetText( const String& rStr );
234     String              GetText( LineEnd aSeparator = LINEEND_LF ) const;
235     String              GetText( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
236     String              GetTextLines( LineEnd aSeparator = LINEEND_LF ) const;
237     void                ReplaceText(const TextSelection& rSel, const String& rText);
238 
239     sal_uLong               GetTextLen( LineEnd aSeparator = LINEEND_LF ) const;
240     sal_uLong               GetTextLen( const TextSelection& rSel, LineEnd aSeparator = LINEEND_LF ) const;
241 
242     void                SetFont( const Font& rFont );
GetFont() const243     const Font&         GetFont() const { return maFont; }
244 
245     void                SetDefTab( sal_uInt16 nDefTab );
246     sal_uInt16              GetDefTab() const;
247 
248     void                SetLeftMargin( sal_uInt16 n );
249     sal_uInt16              GetLeftMargin() const;
250 
251     void                SetUpdateMode( sal_Bool bUpdate );
GetUpdateMode() const252     sal_Bool                GetUpdateMode() const { return mbUpdate; }
253 
254     sal_uInt16              GetViewCount() const;
255     TextView*           GetView( sal_uInt16 nView ) const;
256     void                InsertView( TextView* pTextView );
257     void                RemoveView( TextView* pTextView );
258     TextView*           GetActiveView() const;
259     void                SetActiveView( TextView* pView );
260 
261     void                SetMaxTextLen( sal_uLong nLen );
GetMaxTextLen() const262     sal_uLong               GetMaxTextLen() const { return mnMaxTextLen; }
263 
264     void                SetMaxTextWidth( sal_uLong nWidth );
GetMaxTextWidth() const265     sal_uLong               GetMaxTextWidth() const { return mnMaxTextWidth; }
266 
267     sal_uLong               GetTextHeight() const;
268     sal_uLong               CalcTextWidth();
GetCharHeight() const269     sal_uInt16              GetCharHeight() const { return mnCharHeight; }
270 
271     sal_uLong               GetParagraphCount() const;
272     String              GetText( sal_uLong nParagraph ) const;
273     sal_uInt16              GetTextLen( sal_uLong nParagraph ) const;
274     sal_uLong               GetTextHeight( sal_uLong nParagraph ) const;
275 
276     sal_uInt16              GetLineCount( sal_uLong nParagraph ) const;
277     sal_uInt16              GetLineLen( sal_uLong nParagraph, sal_uInt16 nLine ) const;
278 
279     void                SetRightToLeft( sal_Bool bR2L );
IsRightToLeft() const280     sal_Bool                IsRightToLeft() const { return mbRightToLeft; }
281 
HasUndoManager() const282     sal_Bool            HasUndoManager() const { return mpUndoManager ? sal_True : sal_False; }
283     ::svl::IUndoManager&
284                         GetUndoManager();
285     void                UndoActionStart( sal_uInt16 nId = 0 );
286     void                UndoActionEnd();
287     void                InsertUndo( TextUndo* pUndo, sal_Bool bTryMerge = sal_False );
IsInUndo()288     sal_Bool            IsInUndo()                  { return mbIsInUndo; }
SetIsInUndo(sal_Bool bInUndo)289     void                SetIsInUndo( sal_Bool bInUndo ) { mbIsInUndo = bInUndo; }
290     void                ResetUndo();
291 
292     void                EnableUndo( sal_Bool bEnable );
IsUndoEnabled()293     sal_Bool                IsUndoEnabled()             { return mbUndoEnabled; }
294 
SetModified(sal_Bool bModified)295     void                SetModified( sal_Bool bModified )   { mbModified = bModified; }
IsModified() const296     sal_Bool                IsModified() const              { return mbModified; }
297 
298     sal_Bool                Read( SvStream& rInput, const TextSelection* pSel = NULL );
299 
300     sal_Bool                Write( SvStream& rOutput, const TextSelection* pSel = NULL, sal_Bool bHTML = sal_False );
301 
302     TextPaM             GetPaM( const Point& rDocPos, sal_Bool bSmart = sal_True );
303     Rectangle           PaMtoEditCursor( const TextPaM& rPaM, sal_Bool bSpecial = sal_False );
304     String              GetWord( const TextPaM& rCursorPos, TextPaM* pStartOfWord = 0 );
305 
306     sal_Bool                    HasAttrib( sal_uInt16 nWhich ) const;
307     const TextAttrib*       FindAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
308     const TextCharAttrib*   FindCharAttrib( const TextPaM& rPaM, sal_uInt16 nWhich ) const;
309 
310     void                RemoveAttribs( sal_uLong nPara, sal_uInt16 nWhich, sal_Bool bIdleFormatAndUpdate );
311     void                RemoveAttrib( sal_uLong nPara, const TextCharAttrib& rAttrib );
312     void                RemoveAttribs( sal_uLong nPara, sal_Bool bIdleFormatAndUpdate = sal_True );
313     void                SetAttrib( const TextAttrib& rAttr, sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd, sal_Bool bIdleFormatAndUpdate = sal_True );
314 
GetTextAlign() const315     TxtAlign            GetTextAlign() const { return meAlign; }
316     void                SetTextAlign( TxtAlign eAlign );
317 
318     void                Draw( OutputDevice* pDev, const Point& rPos );
319 
320     void                            SetLocale( const ::com::sun::star::lang::Locale& rLocale );
321     ::com::sun::star::lang::Locale  GetLocale();
322     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > GetBreakIterator();
323 
324     static sal_Bool         DoesKeyChangeText( const KeyEvent& rKeyEvent );
325     static sal_Bool         DoesKeyMoveCursor( const KeyEvent& rKeyEvent );
326     static sal_Bool         IsSimpleCharInput( const KeyEvent& rKeyEvent );
GetTextColor()327     Color               GetTextColor() {return maTextColor; };
328 };
329 
330 #endif // _TEXTENG_HXX
331 
332