📄 ccrystaltextview.h
字号:
////////////////////////////////////////////////////////////////////////////
// File: ccrystaltextview.h
// Version: 1.0.0.0
// Created: 29-Dec-1998
//
// Author: Stcherbatchenko Andrei
// E-mail: windfall@gmx.de
//
// Interface of the CCrystalTextView class, a part of Crystal Edit -
// syntax coloring text editor.
//
// You are free to use or modify this code to the following restrictions:
// - Acknowledge me somewhere in your about box, simple "Parts of code by.."
// will be enough. If you can't (or don't want to), contact me personally.
// - LEAVE THIS HEADER INTACT
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// 19-Jul-99
// Ferdinand Prantl:
// + FEATURE: see cpps ...
//
// ... it's being edited very rapidly so sorry for non-commented
// and maybe "ugly" code ...
////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_CCRYSTALTEXTVIEW_H__AD7F2F41_6CB3_11D2_8C32_0080ADB86836__INCLUDED_)
#define AFX_CCRYSTALTEXTVIEW_H__AD7F2F41_6CB3_11D2_8C32_0080ADB86836__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "regexp.h"
#include "crystalparser.h"
////////////////////////////////////////////////////////////////////////////
// Forward class declarations
class CCrystalTextBuffer;
class CUpdateContext;
////////////////////////////////////////////////////////////////////////////
// CCrystalTextView class declaration
// CCrystalTextView::FindText() flags
enum
{
FIND_MATCH_CASE = 0x0001,
FIND_WHOLE_WORD = 0x0002,
FIND_REGEXP = 0x0004,
FIND_DIRECTION_UP = 0x0010,
REPLACE_SELECTION = 0x0100
};
// CCrystalTextView::UpdateView() flags
enum
{
UPDATE_HORZRANGE = 0x0001, // update horz scrollbar
UPDATE_VERTRANGE = 0x0002, // update vert scrollbar
UPDATE_SINGLELINE = 0x0100, // single line has changed
UPDATE_FLAGSONLY = 0x0200, // only line-flags were changed
UPDATE_RESET = 0x1000 // document was reloaded, update all!
};
class EDITPADC_CLASS CCrystalTextView : public CView
{
DECLARE_DYNCREATE (CCrystalTextView)
//BEGIN SW
friend CCrystalParser;
//END SW
protected:
// Search parameters
BOOL m_bLastSearch;
DWORD m_dwLastSearchFlags;
LPTSTR m_pszLastFindWhat;
BOOL m_bMultipleSearch; // More search
private :
BOOL m_bCursorHidden;
// Painting caching bitmap
CBitmap *m_pCacheBitmap;
// Line/character dimensions
int m_nLineHeight, m_nCharWidth;
void CalcLineCharDim ();
// Text attributes
int m_nTabSize;
BOOL m_bViewTabs;
BOOL m_bSelMargin;
DWORD m_dwFlags;
// Amount of lines/characters that completely fits the client area
int m_nScreenLines, m_nScreenChars;
//BEGIN SW
/**
Contains for each line the number of sublines. If the line is not
wrapped, the value for this line is 1. The value of a line is invalid,
if it is -1.
Must create pointer, because contructor uses AFX_ZERO_INIT_OBJECT to
initialize the member objects. This would destroy a CArray object.
*/
CArray<int, int> *m_panSubLines;
//END SW
int m_nMaxLineLength;
int m_nIdealCharPos;
BOOL m_bFocused;
CPoint m_ptAnchor;
LOGFONT m_lfBaseFont;
CFont *m_apFonts[4];
// Parsing stuff
DWORD *m_pdwParseCookies;
int m_nParseArraySize;
DWORD GetParseCookie (int nLineIndex);
// Pre-calculated line lengths (in characters)
int m_nActualLengthArraySize;
int *m_pnActualLineLength;
BOOL m_bPreparingToDrag;
BOOL m_bDraggingText;
BOOL m_bDragSelection, m_bWordSelection, m_bLineSelection;
UINT m_nDragSelTimer;
CPoint m_ptDrawSelStart, m_ptDrawSelEnd;
CPoint m_ptCursorPos, m_ptCursorLast;
CPoint m_ptSelStart, m_ptSelEnd;
void PrepareSelBounds ();
// Helper functions
void ExpandChars (LPCTSTR pszChars, int nOffset, int nCount, CString & line);
int ApproxActualOffset (int nLineIndex, int nOffset);
void AdjustTextPoint (CPoint & point);
void DrawLineHelperImpl (CDC * pdc, CPoint & ptOrigin, const CRect & rcClip,
LPCTSTR pszChars, int nOffset, int nCount);
BOOL IsInsideSelBlock (CPoint ptTextPos);
BOOL m_bBookmarkExist; // More bookmarks
public :
virtual void ResetView ();
virtual int GetLineCount ();
protected :
CPoint WordToRight (CPoint pt);
CPoint WordToLeft (CPoint pt);
bool m_bSingle;
CImageList * m_pIcons;
CCrystalTextBuffer *m_pTextBuffer;
HACCEL m_hAccel;
BOOL m_bVertScrollBarLocked, m_bHorzScrollBarLocked;
CPoint m_ptDraggedTextBegin, m_ptDraggedTextEnd;
void UpdateCaret ();
void SetAnchor (const CPoint & ptNewAnchor);
int GetMarginWidth ();
bool IsValidTextPos (const CPoint &point);
bool IsValidTextPosX (const CPoint &point);
bool IsValidTextPosY (const CPoint &point);
BOOL m_bShowInactiveSelection;
// [JRT]
BOOL m_bDisableDragAndDrop;
//BEGIN SW
BOOL m_bWordWrap;
CCrystalParser *m_pParser;
//END SW
CPoint ClientToText (const CPoint & point);
CPoint TextToClient (const CPoint & point);
void InvalidateLines (int nLine1, int nLine2, BOOL bInvalidateMargin = FALSE);
int CalculateActualOffset (int nLineIndex, int nCharIndex);
// Printing
int m_nPrintPages;
int *m_pnPages;
CFont *m_pPrintFont;
int m_nPrintLineHeight;
BOOL m_bPrintHeader, m_bPrintFooter;
CRect m_ptPageArea, m_rcPrintArea;
int PrintLineHeight (CDC * pdc, int nLine);
void RecalcPageLayouts (CDC * pdc, CPrintInfo * pInfo);
virtual void PrintHeader (CDC * pdc, int nPageNum);
virtual void PrintFooter (CDC * pdc, int nPageNum);
virtual void GetPrintHeaderText (int nPageNum, CString & text);
virtual void GetPrintFooterText (int nPageNum, CString & text);
// Keyboard handlers
void MoveLeft (BOOL bSelect);
void MoveRight (BOOL bSelect);
void MoveWordLeft (BOOL bSelect);
void MoveWordRight (BOOL bSelect);
void MoveUp (BOOL bSelect);
void MoveDown (BOOL bSelect);
void MoveHome (BOOL bSelect);
void MoveEnd (BOOL bSelect);
void MovePgUp (BOOL bSelect);
void MovePgDn (BOOL bSelect);
void MoveCtrlHome (BOOL bSelect);
void MoveCtrlEnd (BOOL bSelect);
void SelectAll ();
void Copy ();
BOOL IsSelection ();
BOOL IsInsideSelection (const CPoint & ptTextPos);
void GetSelection (CPoint & ptStart, CPoint & ptEnd);
void SetSelection (const CPoint & ptStart, const CPoint & ptEnd);
int m_nTopLine, m_nOffsetChar;
//BEGIN SW
/**
The index of the subline that is the first visible line on the screen.
*/
int m_nTopSubLine;
//END SW
BOOL m_bSmoothScroll;
int GetLineHeight ();
//BEGIN SW
/**
Returns the number of sublines the given line contains of.
Allway "1", if word wrapping is disabled.
@param nLineIndex Index of the line to get the subline count of.
@return Number of sublines the given line contains of
*/
int GetSubLines( int nLineIndex );
/**
Converts the given character position for the given line into a point.
After the call the x-member of the returned point contains the
character position relative to the beginning of the subline. The y-member
contains the zero based index of the subline relative to the line, the
character position was given for.
@param nLineIndex Zero based index of the line, nCharPos refers to.
@param nCharPos The character position, the point shoult be calculated for.
@param charPoint Reference to a point, which should receive the result.
@return The character position of the beginning of the subline charPoint.y.
*/
int CharPosToPoint( int nLineIndex, int nCharPos, CPoint &charPoint );
/**
Converts the given cursor point for the given line to the character position
for the given line.
The y-member of the cursor position specifies the subline inside the given
line, the cursor is placed on and the x-member specifies the cursor position
(in character widths) relative to the beginning of that subline.
@param nLineIndex Zero based index of the line the cursor position refers to.
@param curPoint Position of the cursor relative to the line in sub lines and
char widths.
@return The character position the best matches the cursor position.
*/
int CursorPointToCharPos( int nLineIndex, const CPoint &curPoint );
/**
Converts the given cursor position to a text position.
The x-member of the subLinePos parameter describes the cursor position in
char widths relative to the beginning of the subline described by the
y-member. The subline is the zero based number of the subline relative to
the beginning of the text buffer.
<p>
The returned point contains a valid text position, where the y-member is
the zero based index of the textline and the x-member is the character
position inside this line.
@param subLinePos The sublinebased cursor position
(see text above for detailed description).
@param textPos The calculated line and character position that best matches
the cursor position (see text above for detailed descritpion).
*/
void SubLineCursorPosToTextPos( const CPoint &subLinePos, CPoint &textPos );
/**
Returns the character position relative to the given line, that matches
the end of the given sub line.
@param nLineIndex Zero based index of the line to work on.
@param nSubLineOffset Zero based index of the subline inside the given line.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -