xref: /MusicPlayer2/MusicPlayer2/ScintillaEditView.h (revision 443d2d2511be730d1b1dd3181942b7fa6539aa1a)
1 #pragma once
2 
3 #include "../scintilla/include/SciLexer.h"
4 #include "../scintilla/include/Scintilla.h"
5 #include "ColorConvert.h"
6 
7 // CScintillaEditView 视图
8 
9 #define SCINTILLA_MARGIN_LINENUMBER 0
10 #define MARGIN_FOLD_INDEX 1
11 
12 class CScintillaEditView : public CView
13 {
14 	DECLARE_DYNCREATE(CScintillaEditView)
15 
16 protected:
17 	CScintillaEditView();           // 动态创建所使用的受保护的构造函数
18 	virtual ~CScintillaEditView();
19 
20 public:
21     struct KeepCurrentLine
22     {
23         KeepCurrentLine(CScintillaEditView* view)
24             : m_view(view)
25         {
26             //保存当前行
27             current_line = m_view->GetFirstVisibleLine();
28         }
29         ~KeepCurrentLine()
30         {
31             //恢复当前行
32             m_view->SetFirstVisibleLine(current_line);
33         }
34 
35         CScintillaEditView* m_view{};
36         int current_line{};
37     };
38 
39 	virtual void OnDraw(CDC* pDC);      // 重写以绘制该视图
40 #ifdef _DEBUG
41 	virtual void AssertValid() const;
42 #ifndef _WIN32_WCE
43 	virtual void Dump(CDumpContext& dc) const;
44 #endif
45 #endif
46 
47     void SetTextW(const wstring& text);
48     void GetTextW(wstring& text);
49     const wchar_t* GetTextW(int& size);      //获取文本(返回字符串指针,需要自行释放内存)
50     const char* GetText(int& size);      //获取UTF8格式文本(返回字符串指针,需要自行释放内存)
51     std::string GetText(int start, int end);
52     void SetFontFace(const wchar_t* font_face);
53     void SetFontSize(int font_size);
54     void SetTabSize(int tab_size);
55     void SetSel(int start, int end, const wstring& edit_str);        //设置选中范围(位置以字符为单位)
56     void GetSel(int& start, int& end);      //获取选中范围(位置以字符为单位)
57     void SetBackgroundColor(COLORREF color);
58     void SetReadOnly(bool read_only);
59     bool IsReadOnly();
60 
61     void Undo();
62     void Redo();
63     void Cut();
64     void Copy();
65     void Paste();
66     void SelectAll();
67     void EmptyUndoBuffer();     //清空撤销缓存
68 
69     void SetWordWrap(bool word_wrap);
70 
71     bool IsEditChangeNotificationEnable();
72 
73     bool CanUndo();
74     bool CanRedo();
75     bool CanPaste();
76     bool IsSelectionEmpty();
77     bool IsModified();
78     void SetSavePoint();
79 
80     void SetLineNumberWidth(int width);
81     void ShowLineNumber(bool show);
82     void SetLineNumberColor(COLORREF color);
83 
84     int GetZoom();
85     void SetZoom(int zoom);
86 
87     enum eEolMode
88     {
89         EOL_CRLF,
90         EOL_CR,
91         EOL_LF
92     };
93     void SetEolMode(eEolMode eolMode);
94     eEolMode GetEolMode();
95 
96     void ConvertEolMode(eEolMode eolMode);
97 
98     void SetViewEol(bool show);
99 
100     int GetFirstVisibleLine();
101     void SetFirstVisibleLine(int line);
102 
103     //语法解析
104     void SetLexer(int lexer);
105     void SetKeywords(int id, const char* keywords);
106     void SetSyntaxColor(int id, COLORREF color);
107     void SetSyntaxFontStyle(int id, bool bold, bool italic);
108     void SetLexerNormalText();
109 
110     static eEolMode JudgeEolMode(const wstring& str);
111     static int CharactorPosToBytePos(int pos, const wchar_t* str, size_t size);     //将字符的位置转换成字节的位置(使用UTF8编码)
112     static int BytePosToCharactorPos(int pos, const char* str, size_t size);     //将字节的位置转换成字符的位置(使用UTF8编码)
113 
114     void SetContextMenu(CMenu* pMenu, CWnd* pMenuOwner);
115 
116     void GetLinePos(int line, int& start, int& end);        //获取某一行的开始和结束位置
117     void GetCurLinePos(int& start, int& end);               //获取当前行的开始和结束位置
118 
119     void SetLexerLyric(ColorTable theme_color);       //设置LRC语法解析
120 
121     std::string GetCurrentLineText();
122     std::wstring GetCurrentLineTextW();
123 
124 private:
125 
126 private:
127     bool m_change_notification_enable = true;      //如果为false,则不响应文本改变消息
128     int m_line_number_width = 36;
129     COLORREF m_line_number_color{};
130     COLORREF m_background_color{ RGB(255,255,255) };
131 
132     CMenu* m_pMenu{};
133     CWnd* m_pContextMenuOwner{};
134 
135 protected:
136 	DECLARE_MESSAGE_MAP()
137     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
138 public:
139     afx_msg void OnPaint();
140     virtual void PreSubclassWindow();
141     virtual void OnInitialUpdate();
142     afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
143 protected:
144     afx_msg LRESULT OnTabletQuerysystemgesturestatus(WPARAM wParam, LPARAM lParam);
145 };
146 
147 
148