OSDN Git Service

- Fix an issue where the horizontal scrollbar was not disabled when comparing files...
[winmerge-jp/winmerge-jp.git] / Externals / crystaledit / editlib / ccrystaltextview.h
1 ////////////////////////////////////////////////////////////////////////////
2 //  File:       ccrystaltextview.h
3 //  Version:    1.0.0.0
4 //  Created:    29-Dec-1998
5 //
6 //  Author:     Stcherbatchenko Andrei
7 //  E-mail:     windfall@gmx.de
8 //
9 //  Interface of the CCrystalTextView class, a part of Crystal Edit -
10 //  syntax coloring text editor.
11 //
12 //  You are free to use or modify this code to the following restrictions:
13 //  - Acknowledge me somewhere in your about box, simple "Parts of code by.."
14 //  will be enough. If you can't (or don't want to), contact me personally.
15 //  - LEAVE THIS HEADER INTACT
16 ////////////////////////////////////////////////////////////////////////////
17
18 ////////////////////////////////////////////////////////////////////////////
19 //  19-Jul-99
20 //      Ferdinand Prantl:
21 //  +   FEATURE: see cpps ...
22 //
23 //  ... it's being edited very rapidly so sorry for non-commented
24 //        and maybe "ugly" code ...
25 ////////////////////////////////////////////////////////////////////////////
26 /** 
27  * @file  ccrystaltextview.h
28  *
29  * @brief Declaration file for CCrystalTextView
30  */
31
32 #pragma once
33
34 #include <vector>
35 #include "crystalparser.h"
36 #include "parsers/crystallineparser.h"
37 #include "renderers/ccrystalrenderer.h"
38 #include "utils/cregexp.h"
39 #include "utils/icu.hpp"
40
41 ////////////////////////////////////////////////////////////////////////////
42 // Forward class declarations
43
44 class CCrystalTextBuffer;
45 class CUpdateContext;
46 struct ViewableWhitespaceChars;
47 class SyntaxColors;
48 class CFindTextDlg;
49 struct LastSearchInfos;
50 class CCrystalTextMarkers;
51
52 ////////////////////////////////////////////////////////////////////////////
53 // CCrystalTextView class declaration
54
55 //  CCrystalTextView::FindText() flags
56 enum : unsigned
57 {
58   FIND_MATCH_CASE = 0x0001U,
59   FIND_WHOLE_WORD = 0x0002U,
60   FIND_REGEXP = 0x0004U,
61   FIND_DIRECTION_UP = 0x0010U,
62   REPLACE_SELECTION = 0x0100U, 
63   FIND_NO_WRAP = 0x200U,
64   FIND_NO_CLOSE = 0x400U
65 };
66
67 //  CCrystalTextView::UpdateView() flags
68 enum : unsigned
69 {
70   UPDATE_HORZRANGE = 0x0001U,  //  update horz scrollbar
71   UPDATE_VERTRANGE = 0x0002U, //  update vert scrollbar
72   UPDATE_SINGLELINE = 0x0100U,    //  single line has changed
73   UPDATE_FLAGSONLY = 0x0200U, //  only line-flags were changed
74
75   UPDATE_RESET = 0x1000U       //  document was reloaded, update all!
76 };
77
78 /**
79  * @brief Class for text view.
80  * This class implements class for text viewing. Class implements all
81  * the routines we need for showing, selecting text etc. BUT it does
82  * not implement text editing. There are classes inherited from this
83  * class which implement text editing.
84  */
85 class EDITPADC_CLASS CCrystalTextView : public CView
86   {
87     DECLARE_DYNCREATE (CCrystalTextView)
88
89     friend CCrystalParser;
90     friend CCrystalTextBuffer;
91
92 protected:
93     //  Search parameters
94     bool m_bLastSearch;
95     DWORD m_dwLastSearchFlags;
96     LPTSTR m_pszLastFindWhat;
97     bool m_bMultipleSearch;       // More search
98     CFindTextDlg *m_pFindTextDlg;
99
100 private :
101     bool m_bCursorHidden;
102
103     //  Painting caching bitmap
104     CBitmap *m_pCacheBitmap;
105
106     //  Line/character dimensions
107     int m_nLineHeight, m_nCharWidth;
108     void CalcLineCharDim ();
109
110     //  Text attributes
111     bool m_bViewTabs;
112     bool m_bViewEols;
113     bool m_bDistinguishEols;
114     bool m_bTopMargin;
115     bool m_bSelMargin;
116     bool m_bViewLineNumbers;
117     DWORD m_dwFlags;
118
119     //  Amount of lines/characters that completely fits the client area
120     int m_nScreenLines, m_nScreenChars;
121
122     SyntaxColors * m_pColors;
123     CCrystalTextMarkers * m_pMarkers;
124
125     //BEGIN SW
126     /**
127     Contains for each line the number of sublines. If the line is not
128     wrapped, the value for this line is 1. The value of a line is invalid,
129     if it is -1.
130
131     Must create pointer, because contructor uses AFX_ZERO_INIT_OBJECT to
132     initialize the member objects. This would destroy a CArray object.
133     */
134     CArray<int, int> *m_panSubLines;
135     CArray<int, int> *m_panSubLineIndexCache;
136     int m_nLastLineIndexCalculatedSubLineIndex;
137     //END SW
138
139     int m_nIdealCharPos;
140
141     bool m_bFocused;
142 protected:
143     CPoint m_ptAnchor;
144 private:
145     LOGFONT m_lfBaseFont;
146     LOGFONT m_lfSavedBaseFont;
147
148     //  Parsing stuff
149
150     /**  
151     This array must be initialized to (DWORD) - 1, code for invalid values (not yet computed).
152     We prefer to limit the recomputing delay to the moment when we need to read
153     a parseCookie value for drawing.
154     GetParseCookie must always be used to read the m_ParseCookies value of a line.
155     If the actual value is invalid code, GetParseCookie computes the value, 
156     stores it in m_ParseCookies, and returns the new valid value.
157     When we edit the text, the parse cookies value may change for the modified line
158     and all the lines below (As m_ParseCookies[line i] depends on m_ParseCookies[line (i-1)])
159     It would be a loss of time to recompute all these values after each action.
160     So we just set all these values to invalid code (DWORD) - 1.
161     */
162     std::vector<DWORD> *m_ParseCookies;
163     DWORD GetParseCookie (int nLineIndex);
164
165     /**
166     Pre-calculated line lengths (in characters)
167     This array works as the parse cookie Array
168     and must be initialized to - 1, code for invalid values (not yet computed).
169     for the same reason.
170     */
171     std::vector<int> *m_pnActualLineLength;
172
173 protected:
174     bool m_bPreparingToDrag;
175     bool m_bDraggingText;
176     bool m_bDragSelection, m_bWordSelection, m_bLineSelection, m_bRectangularSelection, m_bColumnSelection;
177     int m_nColumnResizing;
178     UINT_PTR m_nDragSelTimer;
179     DWORD m_dwLastDblClickTime;
180
181     CPoint m_ptDrawSelStart, m_ptDrawSelEnd;
182
183     CPoint m_ptCursorPos, m_ptCursorLast;
184     CPoint m_ptSelStart, m_ptSelEnd;
185     void PrepareSelBounds ();
186
187     //  Helper functions
188     int ExpandChars (int nLineIndex, int nOffset, int nCount, CString & line, int nActualOffset);
189     int ExpandCharsTableEditingNoWrap (int nLineIndex, int nOffset, int nCount, CString & line, int nActualOffset);
190     void AutoFitColumn(int nColumn = -1);
191     enum TextLayoutMode { TEXTLAYOUT_NOWORDWRAP, TEXTLAYOUT_WORDWRAP, TEXTLAYOUT_TABLE_NOWORDWRAP, TEXTLAYOUT_TABLE_WORDWRAP };
192     TextLayoutMode GetTextLayoutMode() const;
193
194     int ApproxActualOffset (int nLineIndex, int nOffset);
195     void AdjustTextPoint (CPoint & point);
196     void DrawLineHelperImpl (CPoint & ptOrigin, const CRect & rcClip,
197  int nColorIndex,
198                              int nBgColorIndex, COLORREF crText, COLORREF crBkgnd, int nLineIndex, int nOffset, int nCount, int &nActualOffset);
199     bool IsInsideSelBlock (CPoint ptTextPos);
200
201     bool m_bBookmarkExist;        // More bookmarks
202     void ToggleBookmark(int nLine);
203
204 public :
205     enum class RENDERING_MODE
206     {
207       GDI = -1,
208       DWRITE_DFEAULT = 0,
209       DWRITE_ALIASED = 1,
210       DWRITE_GDI_CLASSIC = 2,
211       DWRITE_GDI_NATURAL = 3,
212       DWRITE_NATURAL = 4,
213       DWRITE_NATURAL_SYMMETRIC = 5,
214     };
215
216     virtual void ResetView ();
217     virtual int GetLineCount ();
218     virtual void OnUpdateCaret ();
219     bool IsTextBufferInitialized () const;
220     CString GetTextBufferEol (int nLine) const;
221
222     SyntaxColors * GetSyntaxColors() { return m_pColors; }
223     void SetColorContext(SyntaxColors * pColors) { m_pColors = pColors; }
224     CCrystalTextMarkers * GetMarkers() const { return m_pMarkers; }
225     void SetMarkersContext(CCrystalTextMarkers * pMarkers);
226     static CLIPFORMAT GetClipTcharTextFormat() { return sizeof(TCHAR) == 1 ? CF_TEXT : CF_UNICODETEXT; }
227
228 protected :
229     CPoint WordToRight (CPoint pt);
230     CPoint WordToLeft (CPoint pt);
231     bool m_bOvrMode;
232
233     bool m_bSingle;
234     CCrystalTextBuffer *m_pTextBuffer;
235     HACCEL m_hAccel;
236     bool m_bVertScrollBarLocked, m_bHorzScrollBarLocked;
237     CPoint m_ptDraggedTextBegin, m_ptDraggedTextEnd;
238     void UpdateCaret ();
239     void SetAnchor (const CPoint & ptNewAnchor);
240     int GetTopMarginHeight ();
241     int GetMarginWidth (CDC *pdc = nullptr);
242     bool IsValidTextPos (const CPoint &point);
243     bool IsValidTextPosX (const CPoint &point);
244     bool IsValidTextPosY (const CPoint &point);
245
246     bool m_bShowInactiveSelection;
247     //  [JRT]
248     bool m_bDisableDragAndDrop;
249
250     //BEGIN SW
251     bool m_bWordWrap;
252     bool m_bHideLines;
253     CCrystalParser *m_pParser;
254     //END SW
255
256     int ClientToIdealTextPos (int x);
257     CPoint ClientToText (const CPoint & point);
258     int ClientToColumn (int x);
259     int ClientToColumnResizing (int x);
260     CPoint TextToClient (const CPoint & point);
261     int ColumnToClient (int nColumn);
262     void InvalidateLines (int nLine1, int nLine2, bool bInvalidateMargin = false);
263     int CalculateActualOffset (int nLineIndex, int nCharIndex, bool bAccumulate = false);
264
265     //  Printing
266     int m_nPrintPages;
267     CFont *m_pPrintFont;
268     int m_nPrintLineHeight;
269     bool m_bPrintHeader, m_bPrintFooter;
270     CRect m_ptPageArea, m_rcPrintArea;
271     bool m_bPrinting;
272     void GetPrintMargins (long & nLeft, long & nTop, long & nRight, long & nBottom);
273     virtual void RecalcPageLayouts (CDC * pdc, CPrintInfo * pInfo);
274     virtual void PrintHeader (CDC * pdc, int nPageNum);
275     virtual void PrintFooter (CDC * pdc, int nPageNum);
276     virtual void GetPrintHeaderText (int nPageNum, CString & text);
277     virtual void GetPrintFooterText (int nPageNum, CString & text);
278
279     //  Keyboard handlers
280     void MoveLeft (bool bSelect);
281     void MoveRight (bool bSelect);
282     void MoveWordLeft (bool bSelect);
283     void MoveWordRight (bool bSelect);
284     void MoveUp (bool bSelect);
285     void MoveDown (bool bSelect);
286     void MoveHome (bool bSelect);
287     void MoveEnd (bool bSelect);
288     void MovePgUp (bool bSelect);
289     void MovePgDn (bool bSelect);
290     void MoveCtrlHome (bool bSelect);
291     void MoveCtrlEnd (bool bSelect);
292
293     void SelectAll ();
294     void Copy ();
295
296     bool IsSelection () const;
297     bool IsInsideSelection (const CPoint & ptTextPos);
298     bool GetColumnSelection (int nLine, int & nLeftTextPos, int & nRightTextPos);
299     std::pair<CPoint, CPoint> GetSelection ();
300     void GetSelection (CPoint & ptStart, CPoint & ptEnd)
301       { std::tie(ptStart, ptEnd) = GetSelection(); }
302     void GetFullySelectedLines(int & firstLine, int & lastLine);
303     virtual void SetSelection (const CPoint & ptStart, const CPoint & ptEnd, bool bUpdateView = true);
304
305     int m_nTopLine, m_nOffsetChar;
306     //BEGIN SW
307     /**
308     The index of the subline that is the first visible line on the screen.
309     */
310     int m_nTopSubLine;
311     //END SW
312     bool m_bSmoothScroll;
313
314     int GetLineHeight ();
315     //BEGIN SW
316     /**
317     Returns the number of sublines the given line contains of.
318     Allway "1", if word wrapping is disabled.
319
320     @param nLineIndex Index of the line to get the subline count of.
321
322     @return Number of sublines the given line contains of
323     */
324     int GetSubLines( int nLineIndex );
325
326     virtual int GetEmptySubLines( int nLineIndex ) { return 0; }
327     bool IsEmptySubLineIndex( int nSubLineIndex );
328
329     /**
330     Converts the given character position for the given line into a point.
331
332     After the call the x-member of the returned point contains the
333     character position relative to the beginning of the subline. The y-member
334     contains the zero based index of the subline relative to the line, the
335     character position was given for.
336
337     @param nLineIndex Zero based index of the line, nCharPos refers to.
338     @param nCharPos The character position, the point shoult be calculated for.
339     @param charPoint Reference to a point, which should receive the result.
340
341     @return The character position of the beginning of the subline charPoint.y.
342     */
343     int CharPosToPoint( int nLineIndex, int nCharPos, CPoint &charPoint, int* pnColumn = nullptr );
344
345     /**
346     Converts the given cursor point for the given line to the character position
347     for the given line.
348
349     The y-member of the cursor position specifies the subline inside the given
350     line, the cursor is placed on and the x-member specifies the cursor position
351     (in character widths) relative to the beginning of that subline.
352
353     @param nLineIndex Zero based index of the line the cursor position refers to.
354     @param curPoint Position of the cursor relative to the line in sub lines and
355         char widths.
356
357     @return The character position the best matches the cursor position.
358     */
359     int CursorPointToCharPos( int nLineIndex, const CPoint &curPoint );
360
361     /**
362     Converts the given cursor position to a text position.
363
364     The x-member of the subLinePos parameter describes the cursor position in
365     char widths relative to the beginning of the subline described by the
366     y-member. The subline is the zero based number of the subline relative to
367     the beginning of the text buffer.
368
369     <p>
370     The returned point contains a valid text position, where the y-member is
371     the zero based index of the textline and the x-member is the character
372     position inside this line.
373
374     @param subLinePos The sublinebased cursor position
375         (see text above for detailed description).
376     @param textPos The calculated line and character position that best matches
377         the cursor position (see text above for detailed descritpion).
378     */
379     void SubLineCursorPosToTextPos( const CPoint &subLinePos, CPoint &textPos );
380
381     /**
382     Returns the character position relative to the given line, that matches
383     the end of the given sub line.
384
385     @param nLineIndex Zero based index of the line to work on.
386     @param nSubLineOffset Zero based index of the subline inside the given line.
387
388     @return Character position that matches the end of the given subline, relative
389         to the given line.
390     */
391     int SubLineEndToCharPos( int nLineIndex, int nSubLineOffset );
392
393     /**
394     Returns the character position relative to the given line, that matches
395     the start of the given sub line.
396
397     @param nLineIndex Zero based index of the line to work on.
398     @param nSubLineOffset Zero based index of the subline inside the given line.
399
400     @return Character position that matches the start of the given subline, relative
401         to the given line.
402     */
403     int SubLineHomeToCharPos( int nLineIndex, int nSubLineOffset );
404     //END SW
405     int GetCharWidth ();
406     int GetMaxLineLength (int nTopLine, int nLines);
407     int GetScreenLines ();
408     int GetScreenChars ();
409
410     void RecalcVertScrollBar (bool bPositionOnly = false, bool bRedraw = true);
411     virtual void RecalcHorzScrollBar (bool bPositionOnly = false, bool bRedraw = true);
412
413     //  Scrolling helpers
414     void ScrollToChar (int nNewOffsetChar, bool bNoSmoothScroll = false, bool bTrackScrollBar = true);
415     void ScrollToLine (int nNewTopLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true);
416
417     //BEGIN SW
418     /**
419     Scrolls to the given sub line, so that the sub line is the first visible
420     line on the screen.
421
422     @param nNewTopSubLine Index of the sub line to scroll to.
423     @param bNoSmoothScroll true to disable smooth scrolling, else false.
424     @param bTrackScrollBar true to recalculate the scroll bar after scrolling,
425         else false.
426     */
427     virtual void ScrollToSubLine( int nNewTopSubLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true );
428     //END SW
429
430     //  Splitter support
431     virtual void UpdateSiblingScrollPos (bool bHorz);
432     virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, bool bHorz);
433     CCrystalTextView *GetSiblingView (int nRow, int nCol);
434
435     //BEGIN SW
436     /**
437     Returns the number of sublines in the whole text buffer.
438
439     The number of sublines is the sum of all sublines of all lines.
440
441     @return Number of sublines in the whole text buffer.
442     */
443     virtual int GetSubLineCount();
444
445     /**
446     Returns the zero-based subline index of the given line.
447
448     @param nLineIndex Index of the line to calculate the subline index of
449
450     @return The zero-based subline index of the given line.
451     */
452     virtual int GetSubLineIndex( int nLineIndex );
453
454     /**
455      * @brief Splits the given subline index into line and sub line of this line.
456      * @param [in] nSubLineIndex The zero based index of the subline to get info about
457      * @param [out] nLine Gets the line number the give subline is included in
458      * @param [out] nSubLine Get the subline of the given subline relative to nLine
459      */
460     virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine);
461
462 public:
463     virtual int GetLineLength (int nLineIndex) const;
464     virtual int GetFullLineLength (int nLineIndex) const;
465     virtual int GetViewableLineLength(int nLineIndex) const;
466     virtual int GetLineActualLength (int nLineIndex);
467     virtual LPCTSTR GetLineChars (int nLineIndex) const;
468 protected:
469     virtual DWORD GetLineFlags (int nLineIndex) const;
470     virtual void GetText (const CPoint & ptStart, const CPoint & ptEnd, CString & text, bool bExcludeInvisibleLines = true);
471     virtual void GetTextInColumnSelection (CString & text, bool bExcludeInvisibleLines = true);
472
473     //  Clipboard overridable
474     virtual bool TextInClipboard ();
475     virtual bool PutToClipboard (LPCTSTR pszText, int cchText, bool bColumnSelection = false);
476     virtual bool GetFromClipboard (CString & text, bool & bColumnSelection);
477
478     //  Drag-n-drop overrideable
479     virtual HGLOBAL PrepareDragData ();
480     virtual DROPEFFECT GetDropEffect () { return DROPEFFECT_COPY; }
481     virtual void OnDropSource (DROPEFFECT de);
482     bool IsDraggingText () const;
483
484     virtual COLORREF GetColor (int nColorIndex) const;
485     virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
486                                 COLORREF & crText, bool & bDrawWhitespace);
487     virtual bool GetItalic (int nColorIndex);
488     virtual bool GetBold (int nColorIndex);
489
490     void DrawLineHelper (CPoint & ptOrigin, const CRect & rcClip, int nColorIndex, int nBgColorIndex,
491                          COLORREF crText, COLORREF crBkgnd, int nLineIndex, int nOffset, int nCount, int &nActualOffset, CPoint ptTextPos);
492     virtual void DrawSingleLine (const CRect & rect, int nLineIndex);
493     virtual void DrawTopMargin (const CRect & rect);
494     virtual void DrawMargin (const CRect & rect, int nLineIndex, int nLineNumber);
495
496     inline int GetCharCellCountFromChar(const TCHAR *pch)
497     {
498         TCHAR ch = *pch;
499         if (ch >= _T('\x00') && ch <= _T('\x7F'))
500           {
501             if (ch <= _T('\x1F') && ch != '\t')
502               {
503                 if (ch == '\r' && pch[1] == '\n')
504                   return 6;
505                 else
506                   return 3;
507               }
508             else
509                 return 1;
510         } 
511         // This assumes a fixed width font
512         // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
513 #ifdef _UNICODE
514         return GetCharCellCountUnicodeChar(pch);
515 #else
516         return 1;
517 #endif
518     }
519
520     int GetMarginIconSize() const
521     {
522         return MulDiv(CCrystalRenderer::MARGIN_ICON_SIZE, GetSystemMetrics(SM_CXSMICON), 16);
523     }
524
525 #ifdef _UNICODE
526     bool m_bChWidthsCalculated[65536/256];
527     int m_iChDoubleWidthFlags[65536/32];
528     int GetCharCellCountUnicodeChar(const wchar_t *pch);
529 #endif
530     void ResetCharWidths();
531
532     //BEGIN SW
533     // word wrapping
534
535     /**
536     Called to wrap the line with the given index into sublines.
537
538     The standard implementation wraps the line at the first non-whitespace after
539     an whitespace that exceeds the visible line width (nMaxLineWidth). Override
540     this function to provide your own word wrapping.
541
542     <b>Attention:</b> Never call this function directly,
543     call WrapLineCached() instead, which calls this method.
544
545     @param nLineIndex The index of the line to wrap
546
547     @param nMaxLineWidth The number of characters a subline of this line should
548     not exceed (except whitespaces)
549
550     @param anBreaks An array of integers. Put the positions where to wrap the line
551     in that array (its allready allocated). If this pointer is `nullptr`, the function
552     has only to compute the number of breaks (the parameter nBreaks).
553
554     @param nBreaks The number of breaks this line has (number of sublines - 1). When
555     the function is called, this variable is 0. If the line is not wrapped, this value
556     should be 0 after the call.
557
558     @see WrapLineCached()
559     */
560     virtual void WrapLine( int nLineIndex, int nMaxLineWidth, std::vector<int> *anBreaks, int &nBreaks );
561
562     /**
563     Called to wrap the line with the given index into sublines.
564
565     Call this method instead of WrapLine() (which is called internal by this
566     method). This function uses an internal cache which contains the number
567     of sublines for each line, so it has only to call WrapLine(), if the
568     cache for the given line is invalid or if the caller wants to get the
569     wrap postions (anBreaks != nullptr).
570
571     This functions also tests m_bWordWrap -- you can call it even if
572     word wrapping is disabled and you will retrieve a valid value.
573
574     @param nLineIndex The index of the line to wrap
575
576     @param nMaxLineWidth The number of characters a subline of this line should
577     not exceed (except whitespaces)
578
579     @param anBreaks An array of integers. Put the positions where to wrap the line
580     in that array (its allready allocated). If this pointer is `nullptr`, the function
581     has only to compute the number of breaks (the parameter nBreaks).
582
583     @param nBreaks The number of breaks this line has (number of sublines - 1). When
584     the function is called, this variable is 0. If the line is not wrapped, this value
585     should be 0 after the call.
586
587     @see WrapLine()
588     @see m_anSubLines
589     */
590     void WrapLineCached( int nLineIndex, int nMaxLineWidth, std::vector<int> *anBreaks, int &nBreaks );
591
592     /**
593     Invalidates the cached data for the given lines.
594
595     <b>Remarks:</b> Override this method, if your derived class caches other
596     view specific line info, which becomes invalid, when this line changes.
597     Call this standard implementation in your overriding.
598
599     @param nLineIndex1 The index of the first line to invalidate.
600
601     @param nLineIndex2 The index of the last line to invalidate. If this value is
602     -1 (default) all lines from nLineIndex1 to the end are invalidated.
603     */
604     virtual void InvalidateLineCache( int nLineIndex1, int nLineIndex2 );
605     virtual void InvalidateSubLineIndexCache( int nLineIndex1 );
606     void InvalidateScreenRect(bool bInvalidateView = true);
607     void InvalidateVertScrollBar();
608     void InvalidateHorzScrollBar();
609     //END SW
610
611     virtual HINSTANCE GetResourceHandle ();
612
613     //BEGIN SW
614     // function to draw a single screen line
615     // (a wrapped line can consist of many screen lines
616     virtual void DrawScreenLine( CPoint &ptOrigin, const CRect &rcClip,
617          const std::vector<CrystalLineParser::TEXTBLOCK>& blocks,
618         int &nActualItem, COLORREF crText,
619         COLORREF crBkgnd, bool bDrawWhitespace,
620         int nLineIndex, int nOffset,
621         int nCount, int &nActualOffset, CPoint ptTextPos );
622     //END SW
623
624     std::vector<CrystalLineParser::TEXTBLOCK> MergeTextBlocks(const std::vector<CrystalLineParser::TEXTBLOCK>& blocks1, const std::vector<CrystalLineParser::TEXTBLOCK>& blocks2) const;
625     virtual std::vector<CrystalLineParser::TEXTBLOCK> GetWhitespaceTextBlocks(int nLineIndex) const;
626     virtual std::vector<CrystalLineParser::TEXTBLOCK> GetMarkerTextBlocks(int nLineIndex) const;
627     virtual std::vector<CrystalLineParser::TEXTBLOCK> GetAdditionalTextBlocks (int nLineIndex);
628
629 public:
630     virtual CString GetHTMLLine (int nLineIndex, LPCTSTR pszTag);
631     virtual CString GetHTMLStyles ();
632     std::vector<CrystalLineParser::TEXTBLOCK> GetTextBlocks(int nLineIndex);
633 protected:
634     virtual CString GetHTMLAttribute (int nColorIndex, int nBgColorIndex, COLORREF crText, COLORREF crBkgnd);
635
636     //BEGIN SW
637     // helpers for incremental search
638
639     /**
640     Called each time the position-information in the status bar
641     is updated. Use this to change the text of the message field
642     in the status bar.
643
644     @param pStatusBar
645         Pointer to the status bar
646     */
647     void OnUpdateStatusMessage( CStatusBar *pStatusBar );
648
649     /**
650     Called by OnFindIncrementalForward() and OnFindIncrementalBackward().
651
652     @param bFindNextOccurence
653         true, if the method should look for the next occurence of the
654         search string in search direction.
655
656     @see #OnFindIncrementalForward
657     @see #OnFindIncrementalBackward
658     */
659     void OnEditFindIncremental( bool bFindNextOccurence = false );
660
661     /** true if incremental forward search is active, false otherwise */
662     bool m_bIncrementalSearchForward;
663
664     /** true if incremental backward search is active, false otherwise */
665     bool m_bIncrementalSearchBackward;
666
667 private:
668     /** true if we found the string to search for */
669     bool m_bIncrementalFound;
670
671     /** String we are looking for.*/
672     CString *m_pstrIncrementalSearchString;
673
674     /** String we looked for last time.*/
675     CString *m_pstrIncrementalSearchStringOld;
676
677     /** Start of selection at the time the incremental search started */
678     CPoint m_selStartBeforeIncrementalSearch;
679
680     /** Start of selection at the time the incremental search started */
681     CPoint m_selEndBeforeIncrementalSearch;
682
683     /** Cursor position at the time the incremental search started */
684     CPoint m_cursorPosBeforeIncrementalSearch;
685
686     /** position to start the incremental search at */
687     CPoint m_incrementalSearchStartPos;
688
689     //END SW
690
691 public :
692     void GoToLine (int nLine, bool bRelative);
693     unsigned ParseLine (unsigned dwCookie, const TCHAR *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems);
694
695     // Attributes
696 public :
697     enum class CRLFSTYLE GetCRLFMode ();
698     void SetCRLFMode (CRLFSTYLE nCRLFMode);
699     bool GetViewTabs () const { return m_bViewTabs; }
700     void SetViewTabs (bool bViewTabs);
701     bool GetViewEols () const { return m_bViewEols; }
702     void SetViewEols (bool bViewEols, bool bDistinguishEols);
703     int GetTabSize ();
704     void SetTabSize (int nTabSize);
705     bool GetTopMargin () const { return m_bTopMargin; }
706     void SetTopMargin (bool bTopMargin);
707     bool GetSelectionMargin () const { return m_bSelMargin; }
708     void SetSelectionMargin (bool bSelMargin);
709     bool GetViewLineNumbers() const { return m_bViewLineNumbers; }
710     void SetViewLineNumbers(bool bViewLineNumbers);
711     void GetFont (LOGFONT & lf) const { lf = m_lfBaseFont; }
712     void SetFont (const LOGFONT & lf);
713     DWORD GetFlags () const { return m_dwFlags; }
714     void SetFlags (DWORD dwFlags);
715     bool GetSmoothScroll () const { return m_bSmoothScroll; }
716     void SetSmoothScroll (bool bSmoothScroll) { m_bSmoothScroll = bSmoothScroll; }
717     //  [JRT]:
718     bool GetDisableDragAndDrop () const { return m_bDisableDragAndDrop; }
719     void SetDisableDragAndDrop (bool bDDAD) { m_bDisableDragAndDrop = bDDAD; }
720
721     static RENDERING_MODE GetRenderingModeDefault() { return s_nRenderingModeDefault;  }
722     static void SetRenderingModeDefault(RENDERING_MODE nRenderingMode) { s_nRenderingModeDefault = nRenderingMode;  }
723     RENDERING_MODE GetRenderingMode() const { return m_nRenderingMode;  }
724     void SetRenderingMode(RENDERING_MODE nRenderingMode);
725
726     //BEGIN SW
727     bool GetWordWrapping() const;
728     virtual void SetWordWrapping( bool bWordWrap );
729
730     virtual void CopyProperties(CCrystalTextView *pSource);
731
732     /**
733     Sets the Parser to use to parse the file.
734
735     @param pParser Pointer to parser to use. Set to `nullptr` to use no parser.
736
737     @return Pointer to parser used before or `nullptr`, if no parser has been used before.
738     */
739     CCrystalParser *SetParser( CCrystalParser *pParser );
740     //END SW
741
742     bool GetEnableHideLines () const { return m_bHideLines; }
743     void SetEnableHideLines (bool bHideLines) { m_bHideLines = bHideLines; }
744     bool GetLineVisible (int nLineIndex) const;
745
746     //  Default handle to resources
747     static HINSTANCE s_hResourceInst;
748
749     int m_nLastFindWhatLen;
750     RxNode *m_rxnode;
751     RxMatchRes m_rxmatch;
752     LPTSTR m_pszMatched;
753     static LOGFONT m_LogFont;
754     static RENDERING_MODE s_nRenderingModeDefault;
755     RENDERING_MODE m_nRenderingMode;
756
757     std::unique_ptr<CCrystalRenderer> m_pCrystalRenderer;
758     CCrystalRenderer *m_pCrystalRendererSaved;
759
760     //  Source type
761     CrystalLineParser::TextDefinition *m_CurSourceDef;
762     bool m_bRememberLastPos;
763     virtual bool DoSetTextType (CrystalLineParser::TextDefinition *def);
764     virtual bool SetTextType (LPCTSTR pszExt);
765     virtual bool SetTextType (CrystalLineParser::TextType enuType);
766     virtual bool SetTextType (CrystalLineParser::TextDefinition *def);
767     virtual bool SetTextTypeByContent (LPCTSTR pszContent);
768     static void LoadSettings ();
769     static void SaveSettings ();
770
771     // Operations
772 public :
773     virtual void ReAttachToBuffer (CCrystalTextBuffer * pBuf = nullptr);
774     virtual void AttachToBuffer (CCrystalTextBuffer * pBuf = nullptr);
775     virtual void DetachFromBuffer ();
776
777     //  Buffer-view interaction, multiple views
778     virtual CCrystalTextBuffer *LocateTextBuffer ();
779     virtual void UpdateView (CCrystalTextView * pSource, CUpdateContext * pContext, DWORD dwFlags, int nLineIndex = -1);
780
781     //  Attributes
782     CPoint GetCursorPos () const { return m_ptCursorPos; }
783     virtual void SetCursorPos (const CPoint & ptCursorPos);
784     void ShowCursor ();
785     void HideCursor ();
786     CPoint GetAnchor() const { return m_ptAnchor; }
787     void SetNewAnchor (const CPoint & ptNewAnchor) { SetAnchor(ptNewAnchor); }
788     void SetNewSelection (const CPoint & ptStart, const CPoint & ptEnd, bool bUpdateView = true) { SetSelection(ptStart, ptEnd, bUpdateView); }
789
790     //  Operations
791     virtual void EnsureVisible (CPoint pt);
792     virtual void EnsureVisible (CPoint ptStart, CPoint ptEnd);
793
794     //  Text search helpers
795     CPoint GetSearchPos (DWORD dwSearchFlags);
796     bool FindText (LPCTSTR pszText, const CPoint & ptStartPos, DWORD dwFlags, bool bWrapSearch, CPoint * pptFoundPos);
797     bool FindTextInBlock (LPCTSTR pszText, const CPoint & ptStartPos, const CPoint & ptBlockBegin, const CPoint & ptBlockEnd,
798                           DWORD dwFlags, bool bWrapSearch, CPoint * pptFoundPos);
799     bool FindText (const LastSearchInfos * lastSearch);
800     bool HighlightText (const CPoint & ptStartPos, int nLength,
801       bool bCursorToLeft = false);
802
803     // IME (input method editor)
804     void UpdateCompositionWindowPos();
805     void UpdateCompositionWindowFont();
806
807     //  Overridable: an opportunity for Auto-Indent, Smart-Indent etc.
808     virtual void OnEditOperation (int nAction, LPCTSTR pszText, size_t cchText);
809
810     // Overrides
811     // ClassWizard generated virtual function overrides
812     //{{AFX_VIRTUAL(CCrystalTextView)
813 public :
814     virtual void OnDraw (CDC * pDC);  // overridden to draw this view
815
816     virtual BOOL PreCreateWindow (CREATESTRUCT & cs);
817     virtual BOOL PreTranslateMessage (MSG * pMsg);
818     virtual void OnPrepareDC (CDC * pDC, CPrintInfo * pInfo = nullptr);
819     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO *pHandlerInfo);
820 protected :
821     virtual void OnInitialUpdate ();  // called first time after construct
822
823     virtual BOOL OnPreparePrinting (CPrintInfo * pInfo);
824     virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
825     virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
826     virtual void OnPrint (CDC * pDC, CPrintInfo * pInfo);
827     //}}AFX_VIRTUAL
828
829     // Implementation
830 public :
831     CCrystalTextView ();
832     ~CCrystalTextView ();
833
834 protected :
835
836     // Generated message map functions
837 protected :
838 #ifdef _DEBUG
839     void AssertValidTextPos (const CPoint & pt);
840 #endif
841
842     //{{AFX_MSG(CCrystalTextView)
843     afx_msg void OnDestroy ();
844     afx_msg BOOL OnEraseBkgnd (CDC * pDC);
845     afx_msg void OnSize (UINT nType, int cx, int cy);
846     afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
847     afx_msg BOOL OnSetCursor (CWnd * pWnd, UINT nHitTest, UINT message);
848     afx_msg void OnLButtonDown (UINT nFlags, CPoint point);
849     afx_msg void OnSetFocus (CWnd * pOldWnd);
850     afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
851     afx_msg void OnLButtonUp (UINT nFlags, CPoint point);
852     afx_msg void OnMouseMove (UINT nFlags, CPoint point);
853     afx_msg void OnTimer (UINT_PTR nIDEvent);
854     afx_msg void OnKillFocus (CWnd * pNewWnd);
855     afx_msg void OnLButtonDblClk (UINT nFlags, CPoint point);
856     afx_msg void OnLButtonTrippleClk (UINT nFlags, CPoint point);
857     afx_msg void OnEditCopy ();
858     afx_msg void OnUpdateEditCopy (CCmdUI * pCmdUI);
859     afx_msg void OnEditSelectAll ();
860     afx_msg void OnRButtonDown (UINT nFlags, CPoint point);
861     afx_msg void OnSysColorChange ();
862     afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
863     afx_msg void OnEditFind ();
864     afx_msg void OnEditRepeat ();
865     afx_msg void OnUpdateEditRepeat (CCmdUI * pCmdUI);
866     afx_msg void OnEditMark ();
867     afx_msg void OnEditDeleteBack();
868     afx_msg void OnChar( wchar_t nChar, UINT nRepCnt, UINT nFlags );
869
870     afx_msg BOOL OnMouseWheel (UINT nFlags, short zDelta, CPoint pt);
871     afx_msg void OnMouseHWheel (UINT nFlags, short zDelta, CPoint pt);
872     LRESULT OnImeStartComposition(WPARAM wParam, LPARAM lParam);
873     //}}AFX_MSG
874     afx_msg void OnFilePageSetup ();
875
876     afx_msg void OnCharLeft ();
877     afx_msg void OnExtCharLeft ();
878     afx_msg void OnCharRight ();
879     afx_msg void OnExtCharRight ();
880     afx_msg void OnWordLeft ();
881     afx_msg void OnExtWordLeft ();
882     afx_msg void OnWordRight ();
883     afx_msg void OnExtWordRight ();
884     afx_msg void OnLineUp ();
885     afx_msg void OnExtLineUp ();
886     afx_msg void OnLineDown ();
887     afx_msg void OnExtLineDown ();
888     afx_msg void OnPageUp ();
889     afx_msg void OnExtPageUp ();
890     afx_msg void OnPageDown ();
891     afx_msg void OnExtPageDown ();
892     afx_msg void OnLineEnd ();
893     afx_msg void OnExtLineEnd ();
894     afx_msg void OnHome ();
895     afx_msg void OnExtHome ();
896     afx_msg void OnTextBegin ();
897     afx_msg void OnExtTextBegin ();
898     afx_msg void OnTextEnd ();
899     afx_msg void OnExtTextEnd ();
900     afx_msg void OnUpdateIndicatorCRLF (CCmdUI * pCmdUI);
901     afx_msg void OnUpdateIndicatorPosition (CCmdUI * pCmdUI);
902     afx_msg void OnToggleBookmark (UINT nCmdID);
903     afx_msg void OnGoBookmark (UINT nCmdID);
904     afx_msg void OnClearBookmarks ();
905
906     afx_msg void OnToggleBookmark ();     // More bookmarks
907
908     afx_msg void OnClearAllBookmarks ();
909     afx_msg void OnNextBookmark ();
910     afx_msg void OnPrevBookmark ();
911     afx_msg void OnUpdateClearAllBookmarks (CCmdUI * pCmdUI);
912     afx_msg void OnUpdateNextBookmark (CCmdUI * pCmdUI);
913     afx_msg void OnUpdatePrevBookmark (CCmdUI * pCmdUI);
914
915     afx_msg void ScrollUp ();
916     afx_msg void ScrollDown ();
917     afx_msg void ScrollLeft ();
918     afx_msg void ScrollRight ();
919
920     afx_msg void OnSourceType (UINT nId);
921     afx_msg void OnUpdateSourceType (CCmdUI * pCmdUI);
922     afx_msg void OnMatchBrace ();
923     afx_msg void OnUpdateMatchBrace (CCmdUI * pCmdUI);
924     afx_msg void OnEditGoTo ();
925     afx_msg void OnUpdateToggleSourceHeader (CCmdUI * pCmdUI);
926     afx_msg void OnToggleSourceHeader ();
927     afx_msg void OnUpdateTopMargin (CCmdUI * pCmdUI);
928     afx_msg void OnTopMargin ();
929     afx_msg void OnUpdateSelMargin (CCmdUI * pCmdUI);
930     afx_msg void OnSelMargin ();
931     afx_msg void OnUpdateWordWrap (CCmdUI * pCmdUI);
932     afx_msg void OnWordWrap ();
933     afx_msg void OnForceRedraw ();
934
935     //BEGIN SW
936     // incremental search
937     afx_msg void OnEditFindIncrementalForward();
938     afx_msg void OnEditFindIncrementalBackward();
939     afx_msg void OnUpdateEditFindIncrementalForward(CCmdUI* pCmdUI);
940     afx_msg void OnUpdateEditFindIncrementalBackward(CCmdUI* pCmdUI);
941     //END SW
942
943     afx_msg void OnToggleColumnSelection ();
944
945     DECLARE_MESSAGE_MAP ()
946   };
947
948 #ifdef _DEBUG
949 #define ASSERT_VALIDTEXTPOS(pt)     AssertValidTextPos(pt);
950 #else
951 #define ASSERT_VALIDTEXTPOS(pt)
952 #endif
953
954
955 inline bool CCrystalTextView::IsDraggingText () const
956 {
957   return m_bDraggingText;
958 }