1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "scintilla.h"
22 #include "hunspell.hxx"
24 #include "ProjectProperties.h"
25 #include "PersonalDictionary.h"
36 * This class acts as an interface so that CSciEdit can call these methods
37 * on other objects which implement this interface.
38 * Classes implementing this interface must call RegisterContextMenuHandler()
39 * in CSciEdit to register themselves.
41 class CSciEditContextMenuInterface
45 * When the handler is called with this method, it can add entries
46 * to the \a mPopup context menu itself. The \a nCmd param is the command
47 * ID number the handler must use for its commands. For every added command,
48 * the handler is responsible to increment the \a nCmd param by one.
50 virtual void InsertMenuItems(CMenu
& mPopup
, int& nCmd
);
53 * The handler is called when the user clicks on any context menu entry
54 * which isn't handled by CSciEdit itself. That means the handler might
55 * be called for entries it hasn't added itself!
56 * \remark the handler should return \a true if it handled the call, otherwise
57 * it should return \a false
59 virtual bool HandleMenuItemClick(int cmd
, CSciEdit
* pSciEdit
);
64 * Encapsulates the Scintilla edit control. Usable as a replacement for the
65 * MFC CEdit control, but not a drop-in replacement!
66 * Also provides additional features like spell checking, auto completion, ...
68 class CSciEdit
: public CWnd
70 DECLARE_DYNAMIC(CSciEdit
)
75 void SetAStyle(int style
, COLORREF fore
, COLORREF back
=::GetSysColor(COLOR_WINDOW
), int size
=-1, const char *face
=0);
79 * Initialize the scintilla control. Must be called prior to any other
82 void Init(const ProjectProperties
& props
);
83 void Init(LONG lLanguage
= 0,BOOL bLoadSpellCheck
=TRUE
);
85 * Execute a scintilla command, e.g. SCI_GETLINE.
87 LRESULT
Call(UINT message
, WPARAM wParam
= 0, LPARAM lParam
= 0);
89 * The specified text is written to the scintilla control.
91 void SetText(const CString
& sText
);
93 * The specified text is inserted at the cursor position. If a text is
94 * selected, that text is replaced.
95 * \param bNewLine if set to true, a newline is appended.
97 void InsertText(const CString
& sText
, bool bNewLine
= false);
99 * Retrieves the text in the scintilla control.
101 CString
GetText(void);
103 * Sets the font for the control.
105 void SetFont(CString sFontName
, int iFontSizeInPoints
);
107 * Adds a list of words for use in auto completion.
109 void SetAutoCompletionList(const std::set
<CString
>& list
, const TCHAR separator
= ';');
111 * Returns the word located under the cursor.
113 CString
GetWordUnderCursor(bool bSelectWord
= false);
115 void RegisterContextMenuHandler(CSciEditContextMenuInterface
* object
) {m_arContextHandlers
.Add(object
);}
117 CStringA
StringForControl(const CString
& text
);
118 CString
StringFromControl(const CStringA
& text
);
119 int LoadFromFile(CString
&filename
);
122 bool IsUTF8(LPVOID pBuffer
, size_t cb
);
124 LRESULT m_DirectFunction
;
125 LRESULT m_DirectPointer
;
128 UINT m_spellcodepage
;
129 std::set
<CString
> m_autolist
;
134 CArray
<CSciEditContextMenuInterface
*, CSciEditContextMenuInterface
*> m_arContextHandlers
;
135 CPersonalDictionary m_personalDict
;
137 static bool IsValidURLChar(unsigned char ch
);
139 virtual BOOL
OnChildNotify(UINT message
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pLResult
);
140 virtual BOOL
PreTranslateMessage(MSG
* pMsg
);
141 void CheckSpelling(void);
142 void SuggestSpellingAlternatives(void);
143 void DoAutoCompletion(int nMinPrefixLength
);
144 BOOL
LoadDictionaries(LONG lLanguageID
);
145 BOOL
MarkEnteredBugID(int startstylepos
, int endstylepos
);
146 bool StyleEnteredText(int startstylepos
, int endstylepos
);
147 void StyleURLs(int startstylepos
, int endstylepos
);
148 bool WrapLines(int startpos
, int endpos
);
149 bool FindStyleChars(const char * line
, char styler
, int& start
, int& end
);
150 void AdvanceUTF8(const char * str
, int& pos
);
151 BOOL
IsMisspelled(const CString
& sWord
);
152 DWORD
GetStyleAt(int pos
) { return (DWORD
)Call(SCI_GETSTYLEAT
, pos
) & 0x1f; }
153 bool IsUrl(const CStringA
& sText
);
155 virtual afx_msg
void OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
);
156 afx_msg
void OnContextMenu(CWnd
* /*pWnd*/, CPoint
/*point*/);
157 DECLARE_MESSAGE_MAP()