1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\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
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
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
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
28 using namespace std;
\r
31 //forward declaration
\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
41 class CSciEditContextMenuInterface
\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
50 virtual void InsertMenuItems(CMenu& mPopup, int& nCmd);
\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
59 virtual bool HandleMenuItemClick(int cmd, CSciEdit * pSciEdit);
\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
68 class CSciEdit : public CWnd
\r
70 DECLARE_DYNAMIC(CSciEdit)
\r
75 * Initialize the scintilla control. Must be called prior to any other
\r
78 void Init(const ProjectProperties& props);
\r
79 void Init(LONG lLanguage = 0);
\r
81 * Execute a scintilla command, e.g. SCI_GETLINE.
\r
83 LRESULT Call(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
\r
85 * The specified text is written to the scintilla control.
\r
87 void SetText(const CString& sText);
\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
93 void InsertText(const CString& sText, bool bNewLine = false);
\r
95 * Retrieves the text in the scintilla control.
\r
97 CString GetText(void);
\r
99 * Sets the font for the control.
\r
101 void SetFont(CString sFontName, int iFontSizeInPoints);
\r
103 * Adds a list of words for use in auto completion.
\r
105 void SetAutoCompletionList(const std::set<CString>& list, const TCHAR separator = ';');
\r
107 * Returns the word located under the cursor.
\r
109 CString GetWordUnderCursor(bool bSelectWord = false);
\r
111 void RegisterContextMenuHandler(CSciEditContextMenuInterface * object) {m_arContextHandlers.Add(object);}
\r
113 CStringA StringForControl(const CString& text);
\r
114 CString StringFromControl(const CStringA& text);
\r
118 LRESULT m_DirectFunction;
\r
119 LRESULT m_DirectPointer;
\r
120 Hunspell * pChecker;
\r
122 UINT m_spellcodepage;
\r
123 std::set<CString> m_autolist;
\r
125 CStringA m_sCommand;
\r
128 CArray<CSciEditContextMenuInterface *, CSciEditContextMenuInterface *> m_arContextHandlers;
\r
129 CPersonalDictionary m_personalDict;
\r
130 static bool IsValidURLChar(unsigned char ch);
\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
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