X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/170acdc90e9f92f8b8120fa6c04acdbf45c89582..658741180583e3219bdd26b83a798cf3c8a59df7:/src/stc/stc.cpp?ds=sidebyside diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 0bf46f60b4..634b988471 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -15,15 +15,29 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_STC + +#include "wx/stc/stc.h" +#include "wx/stc/private.h" + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif // WX_PRECOMP + #include -#include "wx/wx.h" #include "wx/tokenzr.h" #include "wx/mstream.h" #include "wx/image.h" #include "wx/file.h" -#include "wx/stc/stc.h" #include "ScintillaWX.h" //---------------------------------------------------------------------- @@ -96,7 +110,9 @@ DEFINE_EVENT_TYPE( wxEVT_STC_ZOOM ) DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_CLICK ) DEFINE_EVENT_TYPE( wxEVT_STC_HOTSPOT_DCLICK ) DEFINE_EVENT_TYPE( wxEVT_STC_CALLTIP_CLICK ) -DEFINE_EVENT_TYPE( wxEVT_STC_AUTOCOMP_SELECTION ) +DEFINE_EVENT_TYPE( wxEVT_STC_AUTOCOMP_SELECTION ) +DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_CLICK ) +DEFINE_EVENT_TYPE( wxEVT_STC_INDICATOR_RELEASE ) @@ -158,9 +174,7 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, long style, const wxString& name) { -#ifdef __WXMAC__ style |= wxVSCROLL | wxHSCROLL; -#endif if (!wxControl::Create(parent, id, pos, size, style | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name)) @@ -183,6 +197,10 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, // Reduces flicker on GTK+/X11 SetBackgroundStyle(wxBG_STYLE_CUSTOM); + + // Make sure it can take the focus + SetCanFocus(true); + return true; } @@ -630,6 +648,81 @@ void wxStyledTextCtrl::StyleSetUnderline(int style, bool underline) { SendMsg(2059, style, underline); } +// Get the foreground colour of a style. +wxColour wxStyledTextCtrl::StyleGetForeground(int style) { + long c = SendMsg(2481, style, 0); + return wxColourFromLong(c); +} + +// Get the background colour of a style. +wxColour wxStyledTextCtrl::StyleGetBackground(int style) { + long c = SendMsg(2482, style, 0); + return wxColourFromLong(c); +} + +// Get is a style bold or not. +bool wxStyledTextCtrl::StyleGetBold(int style) { + return SendMsg(2483, style, 0) != 0; +} + +// Get is a style italic or not. +bool wxStyledTextCtrl::StyleGetItalic(int style) { + return SendMsg(2484, style, 0) != 0; +} + +// Get the size of characters of a style. +int wxStyledTextCtrl::StyleGetSize(int style) { + return SendMsg(2485, style, 0); +} + +// Get the font facename of a style +wxString wxStyledTextCtrl::StyleGetFaceName(int style) { + long msg = 2486; + long len = SendMsg(msg, style, 0); + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(msg, style, (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); +} + +// Get is a style to have its end of line filled or not. +bool wxStyledTextCtrl::StyleGetEOLFilled(int style) { + return SendMsg(2487, style, 0) != 0; +} + +// Get is a style underlined or not. +bool wxStyledTextCtrl::StyleGetUnderline(int style) { + return SendMsg(2488, style, 0) != 0; +} + +// Get is a style mixed case, or to force upper or lower case. +int wxStyledTextCtrl::StyleGetCase(int style) { + return SendMsg(2489, style, 0); +} + +// Get the character set of the font in a style. +int wxStyledTextCtrl::StyleGetCharacterSet(int style) { + return SendMsg(2490, style, 0); +} + +// Get is a style visible or not. +bool wxStyledTextCtrl::StyleGetVisible(int style) { + return SendMsg(2491, style, 0) != 0; +} + +// Get is a style changeable or not (read only). +// Experimental feature, currently buggy. +bool wxStyledTextCtrl::StyleGetChangeable(int style) { + return SendMsg(2492, style, 0) != 0; +} + +// Get is a style a hotspot or not. +bool wxStyledTextCtrl::StyleGetHotSpot(int style) { + return SendMsg(2493, style, 0) != 0; +} + // Set a style to be mixed case, or to force upper or lower case. void wxStyledTextCtrl::StyleSetCase(int style, int caseForce) { SendMsg(2060, style, caseForce); @@ -660,6 +753,16 @@ void wxStyledTextCtrl::SetSelAlpha(int alpha) { SendMsg(2478, alpha, 0); } +// Is the selection end of line filled? +bool wxStyledTextCtrl::GetSelEOLFilled() { + return SendMsg(2479, 0, 0) != 0; +} + +// Set the selection to have its end of line filled or not. +void wxStyledTextCtrl::SetSelEOLFilled(bool filled) { + SendMsg(2480, filled, 0); +} + // Set the foreground colour of the caret. void wxStyledTextCtrl::SetCaretForeground(const wxColour& fore) { SendMsg(2069, wxColourAsLong(fore), 0); @@ -738,6 +841,16 @@ wxColour wxStyledTextCtrl::IndicatorGetForeground(int indic) { return wxColourFromLong(c); } +// Set an indicator to draw under text or over(default). +void wxStyledTextCtrl::IndicatorSetUnder(int indic, bool under) { + SendMsg(2510, indic, under); +} + +// Retrieve whether indicator drawn under or over text. +bool wxStyledTextCtrl::IndicatorGetUnder(int indic) { + return SendMsg(2511, indic, 0) != 0; +} + // Set the foreground colour of all whitespace and whether to use this setting. void wxStyledTextCtrl::SetWhitespaceForeground(bool useSetting, const wxColour& fore) { SendMsg(2084, useSetting, wxColourAsLong(fore)); @@ -1021,13 +1134,13 @@ bool wxStyledTextCtrl::GetUseHorizontalScrollBar() { } // Show or hide indentation guides. -void wxStyledTextCtrl::SetIndentationGuides(bool show) { - SendMsg(2132, show, 0); +void wxStyledTextCtrl::SetIndentationGuides(int indentView) { + SendMsg(2132, indentView, 0); } // Are the indentation guides visible? -bool wxStyledTextCtrl::GetIndentationGuides() { - return SendMsg(2133, 0, 0) != 0; +int wxStyledTextCtrl::GetIndentationGuides() { + return SendMsg(2133, 0, 0); } // Set the highlighted indentation guide column. @@ -1648,6 +1761,16 @@ int wxStyledTextCtrl::GetScrollWidth() { return SendMsg(2275, 0, 0); } +// Sets whether the maximum width line displayed is used to set scroll width. +void wxStyledTextCtrl::SetScrollWidthTracking(bool tracking) { + SendMsg(2516, tracking, 0); +} + +// Retrieve whether the scroll width tracks wide lines. +bool wxStyledTextCtrl::GetScrollWidthTracking() { + return SendMsg(2517, 0, 0) != 0; +} + // Measure the pixel width of some text in a particular style. // NUL terminated text argument. // Does not handle tab or control characters. @@ -1911,6 +2034,11 @@ void wxStyledTextCtrl::DelWordRight() { SendMsg(2336, 0, 0); } +// Delete the word to the right of the caret, but not the trailing non-word characters. +void wxStyledTextCtrl::DelWordRightEnd() { + SendMsg(2518, 0, 0); +} + // Cut the line containing the caret. void wxStyledTextCtrl::LineCut() { SendMsg(2337, 0, 0); @@ -2285,21 +2413,43 @@ void wxStyledTextCtrl::SetHotspotActiveForeground(bool useSetting, const wxColou SendMsg(2410, useSetting, wxColourAsLong(fore)); } +// Get the fore colour for active hotspots. +wxColour wxStyledTextCtrl::GetHotspotActiveForeground() { + long c = SendMsg(2494, 0, 0); + return wxColourFromLong(c); +} + // Set a back colour for active hotspots. void wxStyledTextCtrl::SetHotspotActiveBackground(bool useSetting, const wxColour& back) { SendMsg(2411, useSetting, wxColourAsLong(back)); } +// Get the back colour for active hotspots. +wxColour wxStyledTextCtrl::GetHotspotActiveBackground() { + long c = SendMsg(2495, 0, 0); + return wxColourFromLong(c); +} + // Enable / Disable underlining active hotspots. void wxStyledTextCtrl::SetHotspotActiveUnderline(bool underline) { SendMsg(2412, underline, 0); } +// Get whether underlining for active hotspots. +bool wxStyledTextCtrl::GetHotspotActiveUnderline() { + return SendMsg(2496, 0, 0) != 0; +} + // Limit hotspots to single line so hotspots on two lines don't merge. void wxStyledTextCtrl::SetHotspotSingleLine(bool singleLine) { SendMsg(2421, singleLine, 0); } +// Get the HotspotSingleLine property +bool wxStyledTextCtrl::GetHotspotSingleLine() { + return SendMsg(2497, 0, 0) != 0; +} + // Move caret between paragraphs (delimited by empty lines). void wxStyledTextCtrl::ParaDown() { SendMsg(2413, 0, 0); @@ -2511,6 +2661,76 @@ int wxStyledTextCtrl::GetCaretLineBackAlpha() { return SendMsg(2471, 0, 0); } +// Set the style of the caret to be drawn. +void wxStyledTextCtrl::SetCaretStyle(int caretStyle) { + SendMsg(2512, caretStyle, 0); +} + +// Returns the current style of the caret. +int wxStyledTextCtrl::GetCaretStyle() { + return SendMsg(2513, 0, 0); +} + +// Set the indicator used for IndicatorFillRange and IndicatorClearRange +void wxStyledTextCtrl::SetIndicatorCurrent(int indicator) { + SendMsg(2500, indicator, 0); +} + +// Get the current indicator +int wxStyledTextCtrl::GetIndicatorCurrent() { + return SendMsg(2501, 0, 0); +} + +// Set the value used for IndicatorFillRange +void wxStyledTextCtrl::SetIndicatorValue(int value) { + SendMsg(2502, value, 0); +} + +// Get the current indicator vaue +int wxStyledTextCtrl::GetIndicatorValue() { + return SendMsg(2503, 0, 0); +} + +// Turn a indicator on over a range. +void wxStyledTextCtrl::IndicatorFillRange(int position, int fillLength) { + SendMsg(2504, position, fillLength); +} + +// Turn a indicator off over a range. +void wxStyledTextCtrl::IndicatorClearRange(int position, int clearLength) { + SendMsg(2505, position, clearLength); +} + +// Are any indicators present at position? +int wxStyledTextCtrl::IndicatorAllOnFor(int position) { + return SendMsg(2506, position, 0); +} + +// What value does a particular indicator have at at a position? +int wxStyledTextCtrl::IndicatorValueAt(int indicator, int position) { + return SendMsg(2507, indicator, position); +} + +// Where does a particular indicator start? +int wxStyledTextCtrl::IndicatorStart(int indicator, int position) { + return SendMsg(2508, indicator, position); +} + +// Where does a particular indicator end? +int wxStyledTextCtrl::IndicatorEnd(int indicator, int position) { + return SendMsg(2509, indicator, position); +} + +// Set number of entries in position cache +void wxStyledTextCtrl::SetPositionCacheSize(int size) { + SendMsg(2514, size, 0); +} + +// How many entries are allocated to the position cache? +int wxStyledTextCtrl::GetPositionCacheSize() { + return SendMsg(2515, 0, 0); +} + // Start notifying the container of all key presses and commands. void wxStyledTextCtrl::StartRecord() { SendMsg(3001, 0, 0); @@ -2553,7 +2773,7 @@ void wxStyledTextCtrl::SetLexerLanguage(const wxString& language) { // Retrieve a 'property' value previously set with SetProperty. wxString wxStyledTextCtrl::GetProperty(const wxString& key) { - int len = SendMsg(SCI_GETPROPERTY, (long)(const char*)wx2stc(key), (long)NULL); + int len = SendMsg(SCI_GETPROPERTY, (long)(const char*)wx2stc(key), 0); if (!len) return wxEmptyString; wxMemoryBuffer mbuf(len+1); @@ -2567,7 +2787,7 @@ wxString wxStyledTextCtrl::GetProperty(const wxString& key) { // Retrieve a 'property' value previously set with SetProperty, // with '$()' variable replacement on returned buffer. wxString wxStyledTextCtrl::GetPropertyExpanded(const wxString& key) { - int len = SendMsg(SCI_GETPROPERTYEXPANDED, (long)(const char*)wx2stc(key), (long)NULL); + int len = SendMsg(SCI_GETPROPERTYEXPANDED, (long)(const char*)wx2stc(key), 0); if (!len) return wxEmptyString; wxMemoryBuffer mbuf(len+1); @@ -2651,6 +2871,25 @@ void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { } +// Get the font of a style +wxFont wxStyledTextCtrl::StyleGetFont(int style) { + wxFont font; + font.SetPointSize(StyleGetSize(style)); + font.SetFaceName(StyleGetFaceName(style)); + if( StyleGetBold(style) ) + font.SetWeight(wxFONTWEIGHT_BOLD); + else + font.SetWeight(wxFONTWEIGHT_NORMAL); + + if( StyleGetItalic(style) ) + font.SetStyle(wxFONTSTYLE_ITALIC); + else + font.SetStyle(wxFONTSTYLE_NORMAL); + + return font; +} + + // Set style size, face, bold, italic, and underline attributes from // a wxFont's attributes. void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { @@ -2665,7 +2904,7 @@ void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { bool italic = font.GetStyle() != wxNORMAL; bool under = font.GetUnderlined(); wxFontEncoding encoding = font.GetEncoding(); - + StyleSetFontAttr(styleNum, size, faceName, bold, italic, under, encoding); } @@ -2769,7 +3008,7 @@ void wxStyledTextCtrl::StyleSetCharacterSet(int style, int characterSet) case wxSTC_CHARSET_CYRILLIC: encoding = wxFONTENCODING_ISO8859_5; break; - + case wxSTC_CHARSET_8859_15: encoding = wxFONTENCODING_ISO8859_15;; break; @@ -2965,7 +3204,7 @@ wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() if (!len) { wxCharBuffer empty; return empty; - } + } wxCharBuffer buf(len); SendMsg(SCI_GETSELTEXT, 0, (long)buf.data()); @@ -2983,7 +3222,7 @@ wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos) if (!len) { wxCharBuffer empty; return empty; - } + } wxCharBuffer buf(len); TextRange tr; @@ -3118,6 +3357,13 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { #endif bool skip = ((ctrl || alt) && ! (ctrl && alt)); +#if wxUSE_UNICODE + // apparently if we don't do this, Unicode keys pressed after non-char + // ASCII ones (e.g. Enter, Tab) are not taken into account (patch 1615989) + if (m_lastKeyDownConsumed && evt.GetUnicodeKey() > 255) + m_lastKeyDownConsumed = false; +#endif + if (!m_lastKeyDownConsumed && !skip) { #if wxUSE_UNICODE int key = evt.GetUnicodeKey(); @@ -3143,7 +3389,7 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { } #endif } - + evt.Skip(); } @@ -3294,10 +3540,18 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { evt.SetEventType(wxEVT_STC_PAINTED); break; + case SCN_AUTOCSELECTION: + evt.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION); + evt.SetListType(scn.listType); + SetEventText(evt, scn.text, strlen(scn.text)); + evt.SetPosition(scn.lParam); + break; + case SCN_USERLISTSELECTION: evt.SetEventType(wxEVT_STC_USERLISTSELECTION); evt.SetListType(scn.listType); SetEventText(evt, scn.text, strlen(scn.text)); + evt.SetPosition(scn.lParam); break; case SCN_URIDROPPED: @@ -3333,10 +3587,14 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { evt.SetEventType(wxEVT_STC_CALLTIP_CLICK); break; - case SCN_AUTOCSELECTION: - evt.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION); + case SCN_INDICATORCLICK: + evt.SetEventType(wxEVT_STC_INDICATOR_CLICK); break; - + + case SCN_INDICATORRELEASE: + evt.SetEventType(wxEVT_STC_INDICATOR_RELEASE); + break; + default: return; } @@ -3413,11 +3671,4 @@ wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): //---------------------------------------------------------------------- //---------------------------------------------------------------------- - - - - - - - - +#endif // wxUSE_STC