KiCad PCB EDA Suite
Loading...
Searching...
No Matches
scintilla_tricks.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef SCINTILLA_TRICKS_H
21#define SCINTILLA_TRICKS_H
22
23#include <kicommon.h>
24#include <wx/stc/stc.h>
25#include <functional>
26
31class KICOMMON_API SCINTILLA_TRICKS : public wxEvtHandler
32{
33public:
34
35 SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString& aBraces, bool aSingleLine,
36 std::function<void( wxKeyEvent& )> onAcceptHandler =
37 []( wxKeyEvent& aEvent )
38 { },
39 std::function<void( wxStyledTextEvent& )> onCharAddedHandler =
40 []( wxStyledTextEvent& )
41 { } );
42
43 wxStyledTextCtrl* Scintilla() const { return m_te; }
44
45 void DoTextVarAutocomplete(
46 const std::function<void( const wxString& xRef, wxArrayString* tokens )>& getTokensFn );
47
48 void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens );
49
50 void CancelAutocomplete();
51
52protected:
53 void setupStyles();
54
55 int firstNonWhitespace( int aLine, int* aWhitespaceCount = nullptr );
56
57 bool isIMECompositionActive() const;
58
59 virtual void onCharHook( wxKeyEvent& aEvent );
60 void onChar( wxStyledTextEvent& aEvent );
61 void onModified( wxStyledTextEvent& aEvent );
62 void onScintillaUpdateUI( wxStyledTextEvent& aEvent );
63 void onThemeChanged( wxSysColourChangedEvent &aEvent );
64
65protected:
66 wxStyledTextCtrl* m_te;
67 wxString m_braces;
72 bool m_singleLine; // Treat <return> as OK, and skip special tab
73 // stop handling (including monospaced font).
74
75 // Process <return> in singleLine, and <shift> + <return> irrespective.
76 std::function<void( wxKeyEvent& aEvent )> m_onAcceptFn;
77 std::function<void( wxStyledTextEvent& aEvent )> m_onCharAddedFn;
78};
79
80#endif // SCINTILLA_TRICKS_H
wxStyledTextCtrl * Scintilla() const
std::function< void(wxKeyEvent &aEvent)> m_onAcceptFn
std::function< void(wxStyledTextEvent &aEvent)> m_onCharAddedFn
SCINTILLA_TRICKS(wxStyledTextCtrl *aScintilla, const wxString &aBraces, bool aSingleLine, std::function< void(wxKeyEvent &)> onAcceptHandler=[](wxKeyEvent &aEvent) { }, std::function< void(wxStyledTextEvent &)> onCharAddedHandler=[](wxStyledTextEvent &) { })
wxStyledTextCtrl * m_te
#define KICOMMON_API
Definition kicommon.h:27