OSDN Git Service

5678f5045b44d39592d05a5c5996163d53cc26a4
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / SciEdit.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "scintilla.h"\r
21 #include "SciLexer.h"\r
22 #include "hunspell.hxx"\r
23 #include "mythes.hxx"\r
24 #include "ProjectProperties.h"\r
25 #include "PersonalDictionary.h"\r
26 #include <regex>\r
27 \r
28 using namespace std;\r
29 \r
30 \r
31 //forward declaration\r
32 class CSciEdit;\r
33 \r
34 /**\r
35  * \ingroup Utils\r
36  * This class acts as an interface so that CSciEdit can call these methods\r
37  * on other objects which implement this interface.\r
38  * Classes implementing this interface must call RegisterContextMenuHandler()\r
39  * in CSciEdit to register themselves.\r
40  */\r
41 class CSciEditContextMenuInterface\r
42 {\r
43 public:\r
44         /**\r
45          * When the handler is called with this method, it can add entries\r
46          * to the \a mPopup context menu itself. The \a nCmd param is the command\r
47          * ID number the handler must use for its commands. For every added command,\r
48          * the handler is responsible to increment the \a nCmd param by one.\r
49          */\r
50         virtual void            InsertMenuItems(CMenu& mPopup, int& nCmd);\r
51         \r
52         /**\r
53          * The handler is called when the user clicks on any context menu entry\r
54          * which isn't handled by CSciEdit itself. That means the handler might\r
55          * be called for entries it hasn't added itself! \r
56          * \remark the handler should return \a true if it handled the call, otherwise\r
57          * it should return \a false\r
58          */\r
59         virtual bool            HandleMenuItemClick(int cmd, CSciEdit * pSciEdit);\r
60 };\r
61 \r
62 /**\r
63  * \ingroup Utils\r
64  * Encapsulates the Scintilla edit control. Usable as a replacement for the\r
65  * MFC CEdit control, but not a drop-in replacement!\r
66  * Also provides additional features like spell checking, auto completion, ...\r
67  */\r
68 class CSciEdit : public CWnd\r
69 {\r
70         DECLARE_DYNAMIC(CSciEdit)\r
71 public:\r
72         CSciEdit(void);\r
73         ~CSciEdit(void);\r
74         /**\r
75          * Initialize the scintilla control. Must be called prior to any other\r
76          * method!\r
77          */\r
78         void            Init(const ProjectProperties& props);\r
79         void            Init(LONG lLanguage = 0);\r
80         /**\r
81          * Execute a scintilla command, e.g. SCI_GETLINE.\r
82          */\r
83         LRESULT         Call(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);\r
84         /**\r
85          * The specified text is written to the scintilla control.\r
86          */\r
87         void            SetText(const CString& sText);\r
88         /**\r
89          * The specified text is inserted at the cursor position. If a text is\r
90          * selected, that text is replaced.\r
91          * \param bNewLine if set to true, a newline is appended.\r
92          */\r
93         void            InsertText(const CString& sText, bool bNewLine = false);\r
94         /**\r
95          * Retrieves the text in the scintilla control.\r
96          */\r
97         CString         GetText(void);\r
98         /**\r
99          * Sets the font for the control.\r
100          */\r
101         void            SetFont(CString sFontName, int iFontSizeInPoints);\r
102         /**\r
103          * Adds a list of words for use in auto completion.\r
104          */\r
105         void            SetAutoCompletionList(const std::set<CString>& list, const TCHAR separator = ';');\r
106         /**\r
107          * Returns the word located under the cursor.\r
108          */\r
109         CString         GetWordUnderCursor(bool bSelectWord = false);\r
110         \r
111         void            RegisterContextMenuHandler(CSciEditContextMenuInterface * object) {m_arContextHandlers.Add(object);}\r
112         \r
113         CStringA        StringForControl(const CString& text);\r
114         CString         StringFromControl(const CStringA& text);\r
115         \r
116 private:\r
117         HMODULE         m_hModule;\r
118         LRESULT         m_DirectFunction;\r
119         LRESULT         m_DirectPointer;\r
120         Hunspell *      pChecker;\r
121         MyThes *        pThesaur;\r
122         UINT            m_spellcodepage;\r
123         std::set<CString> m_autolist;\r
124         TCHAR           m_separator;\r
125         CStringA        m_sCommand;\r
126         CStringA        m_sBugID;\r
127         CString         m_sUrl;\r
128         CArray<CSciEditContextMenuInterface *, CSciEditContextMenuInterface *> m_arContextHandlers;\r
129         CPersonalDictionary m_personalDict;\r
130         static bool IsValidURLChar(unsigned char ch);\r
131 protected:\r
132         virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult);\r
133         virtual BOOL PreTranslateMessage(MSG* pMsg);\r
134         void            CheckSpelling(void);\r
135         void            SuggestSpellingAlternatives(void);\r
136         void            DoAutoCompletion(int nMinPrefixLength);\r
137         BOOL            LoadDictionaries(LONG lLanguageID);\r
138         BOOL            MarkEnteredBugID(int startstylepos, int endstylepos);\r
139         bool            StyleEnteredText(int startstylepos, int endstylepos);\r
140         void            StyleURLs(int startstylepos, int endstylepos);\r
141         bool            WrapLines(int startpos, int endpos);\r
142         bool            FindStyleChars(const char * line, char styler, int& start, int& end);\r
143         void            AdvanceUTF8(const char * str, int& pos);\r
144         BOOL            IsMisspelled(const CString& sWord);\r
145         DWORD           GetStyleAt(int pos) { return (DWORD)Call(SCI_GETSTYLEAT, pos) & 0x1f; }\r
146         bool            IsUrl(const CStringA& sText);\r
147 \r
148         afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);\r
149         afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);\r
150         DECLARE_MESSAGE_MAP()\r
151 };\r