1 ////////////////////////////////////////////////////////////////////////////
2 // File: ccrystaltextview.h
4 // Created: 29-Dec-1998
6 // Author: Stcherbatchenko Andrei
7 // E-mail: windfall@gmx.de
9 // Interface of the CCrystalTextView class, a part of Crystal Edit -
10 // syntax coloring text editor.
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 ////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////
21 // + FEATURE: see cpps ...
23 // ... it's being edited very rapidly so sorry for non-commented
24 // and maybe "ugly" code ...
25 ////////////////////////////////////////////////////////////////////////////
27 * @file ccrystaltextview.h
29 * @brief Declaration file for CCrystalTextView
35 #include "crystalparser.h"
36 #include "parsers/crystallineparser.h"
37 #include "renderers/ccrystalrenderer.h"
38 #include "utils/cregexp.h"
39 #include "utils/icu.hpp"
41 ////////////////////////////////////////////////////////////////////////////
42 // Forward class declarations
44 class CCrystalTextBuffer;
46 struct ViewableWhitespaceChars;
49 struct LastSearchInfos;
50 class CCrystalTextMarkers;
52 ////////////////////////////////////////////////////////////////////////////
53 // CCrystalTextView class declaration
55 // CCrystalTextView::FindText() flags
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
67 // CCrystalTextView::UpdateView() flags
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
75 UPDATE_RESET = 0x1000U // document was reloaded, update all!
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.
85 class EDITPADC_CLASS CCrystalTextView : public CView
87 DECLARE_DYNCREATE (CCrystalTextView)
89 friend CCrystalParser;
90 friend CCrystalTextBuffer;
95 DWORD m_dwLastSearchFlags;
96 LPTSTR m_pszLastFindWhat;
97 bool m_bMultipleSearch; // More search
98 CFindTextDlg *m_pFindTextDlg;
101 bool m_bCursorHidden;
103 // Painting caching bitmap
104 CBitmap *m_pCacheBitmap;
106 // Line/character dimensions
107 int m_nLineHeight, m_nCharWidth;
108 void CalcLineCharDim ();
113 bool m_bDistinguishEols;
116 bool m_bViewLineNumbers;
119 // Amount of lines/characters that completely fits the client area
120 int m_nScreenLines, m_nScreenChars;
122 SyntaxColors * m_pColors;
123 CCrystalTextMarkers * m_pMarkers;
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,
131 Must create pointer, because contructor uses AFX_ZERO_INIT_OBJECT to
132 initialize the member objects. This would destroy a CArray object.
134 CArray<int, int> *m_panSubLines;
135 CArray<int, int> *m_panSubLineIndexCache;
136 int m_nLastLineIndexCalculatedSubLineIndex;
145 LOGFONT m_lfBaseFont;
146 LOGFONT m_lfSavedBaseFont;
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.
162 std::vector<DWORD> *m_ParseCookies;
163 DWORD GetParseCookie (int nLineIndex);
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).
171 std::vector<int> *m_pnActualLineLength;
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;
181 CPoint m_ptDrawSelStart, m_ptDrawSelEnd;
183 CPoint m_ptCursorPos, m_ptCursorLast;
184 CPoint m_ptSelStart, m_ptSelEnd;
185 void PrepareSelBounds ();
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;
194 int ApproxActualOffset (int nLineIndex, int nOffset);
195 void AdjustTextPoint (CPoint & point);
196 void DrawLineHelperImpl (CPoint & ptOrigin, const CRect & rcClip,
198 int nBgColorIndex, COLORREF crText, COLORREF crBkgnd, int nLineIndex, int nOffset, int nCount, int &nActualOffset);
199 bool IsInsideSelBlock (CPoint ptTextPos);
201 bool m_bBookmarkExist; // More bookmarks
202 void ToggleBookmark(int nLine);
205 enum class RENDERING_MODE
210 DWRITE_GDI_CLASSIC = 2,
211 DWRITE_GDI_NATURAL = 3,
213 DWRITE_NATURAL_SYMMETRIC = 5,
216 virtual void ResetView ();
217 virtual int GetLineCount ();
218 virtual void OnUpdateCaret ();
219 bool IsTextBufferInitialized () const;
220 CString GetTextBufferEol (int nLine) const;
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; }
229 CPoint WordToRight (CPoint pt);
230 CPoint WordToLeft (CPoint pt);
234 CCrystalTextBuffer *m_pTextBuffer;
236 bool m_bVertScrollBarLocked, m_bHorzScrollBarLocked;
237 CPoint m_ptDraggedTextBegin, m_ptDraggedTextEnd;
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);
246 bool m_bShowInactiveSelection;
248 bool m_bDisableDragAndDrop;
253 CCrystalParser *m_pParser;
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);
268 int m_nPrintLineHeight;
269 bool m_bPrintHeader, m_bPrintFooter;
270 CRect m_ptPageArea, m_rcPrintArea;
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);
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);
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);
305 int m_nTopLine, m_nOffsetChar;
308 The index of the subline that is the first visible line on the screen.
312 bool m_bSmoothScroll;
314 int GetLineHeight ();
317 Returns the number of sublines the given line contains of.
318 Allway "1", if word wrapping is disabled.
320 @param nLineIndex Index of the line to get the subline count of.
322 @return Number of sublines the given line contains of
324 int GetSubLines( int nLineIndex );
326 virtual int GetEmptySubLines( int nLineIndex ) { return 0; }
327 bool IsEmptySubLineIndex( int nSubLineIndex );
330 Converts the given character position for the given line into a point.
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.
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.
341 @return The character position of the beginning of the subline charPoint.y.
343 int CharPosToPoint( int nLineIndex, int nCharPos, CPoint &charPoint, int* pnColumn = nullptr );
346 Converts the given cursor point for the given line to the character position
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.
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
357 @return The character position the best matches the cursor position.
359 int CursorPointToCharPos( int nLineIndex, const CPoint &curPoint );
362 Converts the given cursor position to a text position.
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.
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.
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).
379 void SubLineCursorPosToTextPos( const CPoint &subLinePos, CPoint &textPos );
382 Returns the character position relative to the given line, that matches
383 the end of the given sub line.
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.
388 @return Character position that matches the end of the given subline, relative
391 int SubLineEndToCharPos( int nLineIndex, int nSubLineOffset );
394 Returns the character position relative to the given line, that matches
395 the start of the given sub line.
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.
400 @return Character position that matches the start of the given subline, relative
403 int SubLineHomeToCharPos( int nLineIndex, int nSubLineOffset );
406 int GetMaxLineLength (int nTopLine, int nLines);
407 int GetScreenLines ();
408 int GetScreenChars ();
410 void RecalcVertScrollBar (bool bPositionOnly = false, bool bRedraw = true);
411 virtual void RecalcHorzScrollBar (bool bPositionOnly = false, bool bRedraw = true);
414 void ScrollToChar (int nNewOffsetChar, bool bNoSmoothScroll = false, bool bTrackScrollBar = true);
415 void ScrollToLine (int nNewTopLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true);
419 Scrolls to the given sub line, so that the sub line is the first visible
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,
427 virtual void ScrollToSubLine( int nNewTopSubLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true );
431 virtual void UpdateSiblingScrollPos (bool bHorz);
432 virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, bool bHorz);
433 CCrystalTextView *GetSiblingView (int nRow, int nCol);
437 Returns the number of sublines in the whole text buffer.
439 The number of sublines is the sum of all sublines of all lines.
441 @return Number of sublines in the whole text buffer.
443 virtual int GetSubLineCount();
446 Returns the zero-based subline index of the given line.
448 @param nLineIndex Index of the line to calculate the subline index of
450 @return The zero-based subline index of the given line.
452 virtual int GetSubLineIndex( int nLineIndex );
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
460 virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine);
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;
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);
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);
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;
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);
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);
496 inline int GetCharCellCountFromChar(const TCHAR *pch)
499 if (ch >= _T('\x00') && ch <= _T('\x7F'))
501 if (ch <= _T('\x1F') && ch != '\t')
503 if (ch == '\r' && pch[1] == '\n')
511 // This assumes a fixed width font
512 // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
514 return GetCharCellCountUnicodeChar(pch);
520 int GetMarginIconSize() const
522 return MulDiv(CCrystalRenderer::MARGIN_ICON_SIZE, GetSystemMetrics(SM_CXSMICON), 16);
526 bool m_bChWidthsCalculated[65536/256];
527 int m_iChDoubleWidthFlags[65536/32];
528 int GetCharCellCountUnicodeChar(const wchar_t *pch);
530 void ResetCharWidths();
536 Called to wrap the line with the given index into sublines.
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.
542 <b>Attention:</b> Never call this function directly,
543 call WrapLineCached() instead, which calls this method.
545 @param nLineIndex The index of the line to wrap
547 @param nMaxLineWidth The number of characters a subline of this line should
548 not exceed (except whitespaces)
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).
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.
558 @see WrapLineCached()
560 virtual void WrapLine( int nLineIndex, int nMaxLineWidth, std::vector<int> *anBreaks, int &nBreaks );
563 Called to wrap the line with the given index into sublines.
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).
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.
574 @param nLineIndex The index of the line to wrap
576 @param nMaxLineWidth The number of characters a subline of this line should
577 not exceed (except whitespaces)
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).
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.
590 void WrapLineCached( int nLineIndex, int nMaxLineWidth, std::vector<int> *anBreaks, int &nBreaks );
593 Invalidates the cached data for the given lines.
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.
599 @param nLineIndex1 The index of the first line to invalidate.
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.
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();
611 virtual HINSTANCE GetResourceHandle ();
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 );
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);
630 virtual CString GetHTMLLine (int nLineIndex, LPCTSTR pszTag);
631 virtual CString GetHTMLStyles ();
632 std::vector<CrystalLineParser::TEXTBLOCK> GetTextBlocks(int nLineIndex);
634 virtual CString GetHTMLAttribute (int nColorIndex, int nBgColorIndex, COLORREF crText, COLORREF crBkgnd);
637 // helpers for incremental search
640 Called each time the position-information in the status bar
641 is updated. Use this to change the text of the message field
645 Pointer to the status bar
647 void OnUpdateStatusMessage( CStatusBar *pStatusBar );
650 Called by OnFindIncrementalForward() and OnFindIncrementalBackward().
652 @param bFindNextOccurence
653 true, if the method should look for the next occurence of the
654 search string in search direction.
656 @see #OnFindIncrementalForward
657 @see #OnFindIncrementalBackward
659 void OnEditFindIncremental( bool bFindNextOccurence = false );
661 /** true if incremental forward search is active, false otherwise */
662 bool m_bIncrementalSearchForward;
664 /** true if incremental backward search is active, false otherwise */
665 bool m_bIncrementalSearchBackward;
668 /** true if we found the string to search for */
669 bool m_bIncrementalFound;
671 /** String we are looking for.*/
672 CString *m_pstrIncrementalSearchString;
674 /** String we looked for last time.*/
675 CString *m_pstrIncrementalSearchStringOld;
677 /** Start of selection at the time the incremental search started */
678 CPoint m_selStartBeforeIncrementalSearch;
680 /** Start of selection at the time the incremental search started */
681 CPoint m_selEndBeforeIncrementalSearch;
683 /** Cursor position at the time the incremental search started */
684 CPoint m_cursorPosBeforeIncrementalSearch;
686 /** position to start the incremental search at */
687 CPoint m_incrementalSearchStartPos;
692 void GoToLine (int nLine, bool bRelative);
693 unsigned ParseLine (unsigned dwCookie, const TCHAR *pszChars, int nLength, CrystalLineParser::TEXTBLOCK * pBuf, int &nActualItems);
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);
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; }
718 bool GetDisableDragAndDrop () const { return m_bDisableDragAndDrop; }
719 void SetDisableDragAndDrop (bool bDDAD) { m_bDisableDragAndDrop = bDDAD; }
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);
727 bool GetWordWrapping() const;
728 virtual void SetWordWrapping( bool bWordWrap );
730 virtual void CopyProperties(CCrystalTextView *pSource);
733 Sets the Parser to use to parse the file.
735 @param pParser Pointer to parser to use. Set to `nullptr` to use no parser.
737 @return Pointer to parser used before or `nullptr`, if no parser has been used before.
739 CCrystalParser *SetParser( CCrystalParser *pParser );
742 bool GetEnableHideLines () const { return m_bHideLines; }
743 void SetEnableHideLines (bool bHideLines) { m_bHideLines = bHideLines; }
744 bool GetLineVisible (int nLineIndex) const;
746 // Default handle to resources
747 static HINSTANCE s_hResourceInst;
749 int m_nLastFindWhatLen;
751 RxMatchRes m_rxmatch;
753 static LOGFONT m_LogFont;
754 static RENDERING_MODE s_nRenderingModeDefault;
755 RENDERING_MODE m_nRenderingMode;
757 std::unique_ptr<CCrystalRenderer> m_pCrystalRenderer;
758 CCrystalRenderer *m_pCrystalRendererSaved;
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 ();
773 virtual void ReAttachToBuffer (CCrystalTextBuffer * pBuf = nullptr);
774 virtual void AttachToBuffer (CCrystalTextBuffer * pBuf = nullptr);
775 virtual void DetachFromBuffer ();
777 // Buffer-view interaction, multiple views
778 virtual CCrystalTextBuffer *LocateTextBuffer ();
779 virtual void UpdateView (CCrystalTextView * pSource, CUpdateContext * pContext, DWORD dwFlags, int nLineIndex = -1);
782 CPoint GetCursorPos () const { return m_ptCursorPos; }
783 virtual void SetCursorPos (const CPoint & ptCursorPos);
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); }
791 virtual void EnsureVisible (CPoint pt);
792 virtual void EnsureVisible (CPoint ptStart, CPoint ptEnd);
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);
803 // IME (input method editor)
804 void UpdateCompositionWindowPos();
805 void UpdateCompositionWindowFont();
807 // Overridable: an opportunity for Auto-Indent, Smart-Indent etc.
808 virtual void OnEditOperation (int nAction, LPCTSTR pszText, size_t cchText);
811 // ClassWizard generated virtual function overrides
812 //{{AFX_VIRTUAL(CCrystalTextView)
814 virtual void OnDraw (CDC * pDC); // overridden to draw this view
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);
821 virtual void OnInitialUpdate (); // called first time after construct
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);
832 ~CCrystalTextView ();
836 // Generated message map functions
839 void AssertValidTextPos (const CPoint & pt);
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 );
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);
874 afx_msg void OnFilePageSetup ();
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 ();
906 afx_msg void OnToggleBookmark (); // More bookmarks
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);
915 afx_msg void ScrollUp ();
916 afx_msg void ScrollDown ();
917 afx_msg void ScrollLeft ();
918 afx_msg void ScrollRight ();
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 ();
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);
943 afx_msg void OnToggleColumnSelection ();
945 DECLARE_MESSAGE_MAP ()
949 #define ASSERT_VALIDTEXTPOS(pt) AssertValidTextPos(pt);
951 #define ASSERT_VALIDTEXTPOS(pt)
955 inline bool CCrystalTextView::IsDraggingText () const
957 return m_bDraggingText;