X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be108f9665882ee412f00635406e894a7aa385de..3ef595d5f879ec3ed4ef511445487261304313e2:/src/stc/stc.cpp diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 248ceb73e5..5f72b1de71 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -15,17 +15,29 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#include +// 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 "ScintillaWX.h" -#include -#include -#include -#include -#include +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif // WX_PRECOMP +#include + +#include "wx/tokenzr.h" +#include "wx/mstream.h" +#include "wx/image.h" +#include "wx/file.h" + +#include "ScintillaWX.h" //---------------------------------------------------------------------- @@ -97,6 +109,7 @@ 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 ) @@ -151,19 +164,18 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, } -void wxStyledTextCtrl::Create(wxWindow *parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) +bool wxStyledTextCtrl::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) { -#ifdef __WXMAC__ style |= wxVSCROLL | wxHSCROLL; -#endif - wxControl::Create(parent, id, pos, size, - style | wxWANTS_CHARS | wxCLIP_CHILDREN, - wxDefaultValidator, name); + if (!wxControl::Create(parent, id, pos, size, + style | wxWANTS_CHARS | wxCLIP_CHILDREN, + wxDefaultValidator, name)) + return false; #ifdef LINK_LEXERS Scintilla_LinkLexers(); @@ -178,9 +190,11 @@ void wxStyledTextCtrl::Create(wxWindow *parent, SetCodePage(wxSTC_CP_UTF8); #endif + SetInitialSize(size); + // Reduces flicker on GTK+/X11 SetBackgroundStyle(wxBG_STYLE_CUSTOM); - SetBestFittingSize(size); + return true; } @@ -515,6 +529,8 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp) // convert bmp to a xpm in a string wxMemoryOutputStream strm; wxImage img = bmp.ConvertToImage(); + if (img.HasAlpha()) + img.ConvertAlphaToMask(); img.SaveFile(strm, wxBITMAP_TYPE_XPM); size_t len = strm.GetSize(); char* buff = new char[len+1]; @@ -525,6 +541,16 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp) } +// Add a set of markers to a line. +void wxStyledTextCtrl::MarkerAddSet(int line, int set) { + SendMsg(2466, line, set); +} + +// Set the alpha used for a marker that is drawn in the text area, not the margin. +void wxStyledTextCtrl::MarkerSetAlpha(int markerNumber, int alpha) { + SendMsg(2476, markerNumber, alpha); +} + // Set a margin to be either numeric or symbolic. void wxStyledTextCtrl::SetMarginType(int margin, int marginType) { SendMsg(2240, margin, marginType); @@ -620,11 +646,6 @@ void wxStyledTextCtrl::StyleSetCase(int style, int caseForce) { SendMsg(2060, style, caseForce); } -// Set the character set of the font in a style. -void wxStyledTextCtrl::StyleSetCharacterSet(int style, int characterSet) { - SendMsg(2066, style, characterSet); -} - // Set a style to be a hotspot or not. void wxStyledTextCtrl::StyleSetHotSpot(int style, bool hotspot) { SendMsg(2409, style, hotspot); @@ -640,6 +661,16 @@ void wxStyledTextCtrl::SetSelBackground(bool useSetting, const wxColour& back) { SendMsg(2068, useSetting, wxColourAsLong(back)); } +// Get the alpha of the selection. +int wxStyledTextCtrl::GetSelAlpha() { + return SendMsg(2477, 0, 0); +} + +// Set the alpha of the selection. +void wxStyledTextCtrl::SetSelAlpha(int alpha) { + SendMsg(2478, alpha, 0); +} + // Set the foreground colour of the caret. void wxStyledTextCtrl::SetCaretForeground(const wxColour& fore) { SendMsg(2069, wxColourAsLong(fore), 0); @@ -766,13 +797,13 @@ void wxStyledTextCtrl::SetCaretLineVisible(bool show) { } // Get the colour of the background of the line containing the caret. -wxColour wxStyledTextCtrl::GetCaretLineBack() { +wxColour wxStyledTextCtrl::GetCaretLineBackground() { long c = SendMsg(2097, 0, 0); return wxColourFromLong(c); } // Set the colour of the background of the line containing the caret. -void wxStyledTextCtrl::SetCaretLineBack(const wxColour& back) { +void wxStyledTextCtrl::SetCaretLineBackground(const wxColour& back) { SendMsg(2098, wxColourAsLong(back), 0); } @@ -899,6 +930,8 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) { // convert bmp to a xpm in a string wxMemoryOutputStream strm; wxImage img = bmp.ConvertToImage(); + if (img.HasAlpha()) + img.ConvertAlphaToMask(); img.SaveFile(strm, wxBITMAP_TYPE_XPM); size_t len = strm.GetSize(); char* buff = new char[len+1]; @@ -925,6 +958,28 @@ void wxStyledTextCtrl::AutoCompSetTypeSeparator(int separatorCharacter) { SendMsg(2286, separatorCharacter, 0); } +// Set the maximum width, in characters, of auto-completion and user lists. +// Set to 0 to autosize to fit longest item, which is the default. +void wxStyledTextCtrl::AutoCompSetMaxWidth(int characterCount) { + SendMsg(2208, characterCount, 0); +} + +// Get the maximum width, in characters, of auto-completion and user lists. +int wxStyledTextCtrl::AutoCompGetMaxWidth() { + return SendMsg(2209, 0, 0); +} + +// Set the maximum height, in rows, of auto-completion and user lists. +// The default is 5 rows. +void wxStyledTextCtrl::AutoCompSetMaxHeight(int rowCount) { + SendMsg(2210, rowCount, 0); +} + +// Set the maximum height, in rows, of auto-completion and user lists. +int wxStyledTextCtrl::AutoCompGetMaxHeight() { + return SendMsg(2211, 0, 0); +} + // Set the number of spaces used for one level of indentation. void wxStyledTextCtrl::SetIndent(int indentSize) { SendMsg(2122, indentSize, 0); @@ -1416,6 +1471,11 @@ void wxStyledTextCtrl::CallTipSetForegroundHighlight(const wxColour& fore) { SendMsg(2207, wxColourAsLong(fore), 0); } +// Enable use of STYLE_CALLTIP and set call tip tab size in pixels. +void wxStyledTextCtrl::CallTipUseStyle(int tabSize) { + SendMsg(2212, tabSize, 0); +} + // Find the display line of a document line taking hidden lines into account. int wxStyledTextCtrl::VisibleFromDocLine(int line) { return SendMsg(2220, line, 0); @@ -1426,6 +1486,11 @@ int wxStyledTextCtrl::DocLineFromVisible(int lineDisplay) { return SendMsg(2221, lineDisplay, 0); } +// The number of display lines needed to wrap a document line +int wxStyledTextCtrl::WrapCount(int line) { + return SendMsg(2235, line, 0); +} + // Set the fold level of a line. // This encodes an integer level along with flags indicating whether the // line is a header and whether it is effectively white space. @@ -1610,8 +1675,8 @@ void wxStyledTextCtrl::SetEndAtLastLine(bool endAtLastLine) { // Retrieve whether the maximum scroll position has the last // line at the bottom of the view. -int wxStyledTextCtrl::GetEndAtLastLine() { - return SendMsg(2278, 0, 0); +bool wxStyledTextCtrl::GetEndAtLastLine() { + return SendMsg(2278, 0, 0) != 0; } // Retrieve the height of a particular line of text in pixels. @@ -1630,8 +1695,9 @@ bool wxStyledTextCtrl::GetUseVerticalScrollBar() { } // Append a string to the end of the document without changing the selection. -void wxStyledTextCtrl::AppendText(int length, const wxString& text) { - SendMsg(2282, length, (long)(const char*)wx2stc(text)); +void wxStyledTextCtrl::AppendText(const wxString& text) { + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + SendMsg(2282, strlen(buf), (long)(const char*)buf); } // Is drawing done in two phases with backgrounds drawn before foregrounds? @@ -2410,12 +2476,52 @@ void wxStyledTextCtrl::Allocate(int bytes) { SendMsg(2446, bytes, 0); } -// Find the position of a column on a line taking into account tabs and +// Find the position of a column on a line taking into account tabs and // multi-byte characters. If beyond end of line, return line end position. int wxStyledTextCtrl::FindColumn(int line, int column) { return SendMsg(2456, line, column); } +// Can the caret preferred x position only be changed by explicit movement commands? +bool wxStyledTextCtrl::GetCaretSticky() { + return SendMsg(2457, 0, 0) != 0; +} + +// Stop the caret preferred x position changing when the user types. +void wxStyledTextCtrl::SetCaretSticky(bool useCaretStickyBehaviour) { + SendMsg(2458, useCaretStickyBehaviour, 0); +} + +// Switch between sticky and non-sticky: meant to be bound to a key. +void wxStyledTextCtrl::ToggleCaretSticky() { + SendMsg(2459, 0, 0); +} + +// Enable/Disable convert-on-paste for line endings +void wxStyledTextCtrl::SetPasteConvertEndings(bool convert) { + SendMsg(2467, convert, 0); +} + +// Get convert-on-paste setting +bool wxStyledTextCtrl::GetPasteConvertEndings() { + return SendMsg(2468, 0, 0) != 0; +} + +// Duplicate the selection. If selection empty duplicate the line containing the caret. +void wxStyledTextCtrl::SelectionDuplicate() { + SendMsg(2469, 0, 0); +} + +// Set background alpha of the caret line. +void wxStyledTextCtrl::SetCaretLineBackAlpha(int alpha) { + SendMsg(2470, alpha, 0); +} + +// Get the background alpha of the caret line. +int wxStyledTextCtrl::GetCaretLineBackAlpha() { + return SendMsg(2471, 0, 0); +} + // Start notifying the container of all key presses and commands. void wxStyledTextCtrl::StartRecord() { SendMsg(3001, 0, 0); @@ -2456,6 +2562,44 @@ void wxStyledTextCtrl::SetLexerLanguage(const wxString& language) { SendMsg(4006, 0, (long)(const char*)wx2stc(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), 0); + if (!len) return wxEmptyString; + + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(4008, (long)(const char*)wx2stc(key), (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); +} + +// 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), 0); + if (!len) return wxEmptyString; + + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(4009, (long)(const char*)wx2stc(key), (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); +} + +// Retrieve a 'property' value previously set with SetProperty, +// interpreted as an int AFTER any '$()' variable replacement. +int wxStyledTextCtrl::GetPropertyInt(const wxString& key) { + return SendMsg(4010, (long)(const char*)wx2stc(key), 0); +} + +// Retrieve the number of bits the current lexer needs for styling. +int wxStyledTextCtrl::GetStyleBitsNeeded() { + return SendMsg(4011, 0, 0); +} + // END of generated section //---------------------------------------------------------------------- @@ -2526,28 +2670,135 @@ void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { int x, y; GetTextExtent(wxT("X"), &x, &y, NULL, NULL, &font); #endif - int size = font.GetPointSize(); - wxString faceName = font.GetFaceName(); - bool bold = font.GetWeight() == wxBOLD; - bool italic = font.GetStyle() != wxNORMAL; - bool under = font.GetUnderlined(); - - // TODO: add encoding/charset mapping - StyleSetFontAttr(styleNum, size, faceName, bold, italic, under); + int size = font.GetPointSize(); + wxString faceName = font.GetFaceName(); + bool bold = font.GetWeight() == wxBOLD; + bool italic = font.GetStyle() != wxNORMAL; + bool under = font.GetUnderlined(); + wxFontEncoding encoding = font.GetEncoding(); + + StyleSetFontAttr(styleNum, size, faceName, bold, italic, under, encoding); } // Set all font style attributes at once. void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, const wxString& faceName, bool bold, bool italic, - bool underline) { + bool underline, + wxFontEncoding encoding) { StyleSetSize(styleNum, size); StyleSetFaceName(styleNum, faceName); StyleSetBold(styleNum, bold); StyleSetItalic(styleNum, italic); StyleSetUnderline(styleNum, underline); + StyleSetFontEncoding(styleNum, encoding); +} + - // TODO: add encoding/charset mapping +// Set the character set of the font in a style. Converts the Scintilla +// character set values to a wxFontEncoding. +void wxStyledTextCtrl::StyleSetCharacterSet(int style, int characterSet) +{ + wxFontEncoding encoding; + + // Translate the Scintilla characterSet to a wxFontEncoding + switch (characterSet) { + default: + case wxSTC_CHARSET_ANSI: + case wxSTC_CHARSET_DEFAULT: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_BALTIC: + encoding = wxFONTENCODING_ISO8859_13; + break; + + case wxSTC_CHARSET_CHINESEBIG5: + encoding = wxFONTENCODING_CP950; + break; + + case wxSTC_CHARSET_EASTEUROPE: + encoding = wxFONTENCODING_ISO8859_2; + break; + + case wxSTC_CHARSET_GB2312: + encoding = wxFONTENCODING_CP936; + break; + + case wxSTC_CHARSET_GREEK: + encoding = wxFONTENCODING_ISO8859_7; + break; + + case wxSTC_CHARSET_HANGUL: + encoding = wxFONTENCODING_CP949; + break; + + case wxSTC_CHARSET_MAC: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_OEM: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_RUSSIAN: + encoding = wxFONTENCODING_KOI8; + break; + + case wxSTC_CHARSET_SHIFTJIS: + encoding = wxFONTENCODING_CP932; + break; + + case wxSTC_CHARSET_SYMBOL: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_TURKISH: + encoding = wxFONTENCODING_ISO8859_9; + break; + + case wxSTC_CHARSET_JOHAB: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_HEBREW: + encoding = wxFONTENCODING_ISO8859_8; + break; + + case wxSTC_CHARSET_ARABIC: + encoding = wxFONTENCODING_ISO8859_6; + break; + + case wxSTC_CHARSET_VIETNAMESE: + encoding = wxFONTENCODING_DEFAULT; + break; + + case wxSTC_CHARSET_THAI: + encoding = wxFONTENCODING_ISO8859_11; + break; + + case wxSTC_CHARSET_CYRILLIC: + encoding = wxFONTENCODING_ISO8859_5; + break; + + case wxSTC_CHARSET_8859_15: + encoding = wxFONTENCODING_ISO8859_15;; + break; + } + + // We just have Scintilla track the wxFontEncoding for us. It gets used + // in Font::Create in PlatWX.cpp. We add one to the value so that the + // effective wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT and so when + // Scintilla internally uses SC_CHARSET_DEFAULT we will translate it back + // to wxFONENCODING_DEFAULT in Font::Create. + SendMsg(SCI_STYLESETCHARACTERSET, style, encoding+1); +} + + +// Set the font encoding to be used by a style. +void wxStyledTextCtrl::StyleSetFontEncoding(int style, wxFontEncoding encoding) +{ + SendMsg(SCI_STYLESETCHARACTERSET, style, encoding+1); } @@ -2673,6 +2924,109 @@ bool wxStyledTextCtrl::GetUseAntiAliasing() { return m_swx->GetUseAntiAliasing(); } + + + + +void wxStyledTextCtrl::AddTextRaw(const char* text) +{ + SendMsg(SCI_ADDTEXT, strlen(text), (long)text); +} + +void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text) +{ + SendMsg(SCI_INSERTTEXT, pos, (long)text); +} + +wxCharBuffer wxStyledTextCtrl::GetCurLineRaw(int* linePos) +{ + int len = LineLength(GetCurrentLine()); + if (!len) { + if (linePos) *linePos = 0; + wxCharBuffer empty; + return empty; + } + + wxCharBuffer buf(len); + int pos = SendMsg(SCI_GETCURLINE, len, (long)buf.data()); + if (linePos) *linePos = pos; + return buf; +} + +wxCharBuffer wxStyledTextCtrl::GetLineRaw(int line) +{ + int len = LineLength(line); + if (!len) { + wxCharBuffer empty; + return empty; + } + + wxCharBuffer buf(len); + SendMsg(SCI_GETLINE, line, (long)buf.data()); + return buf; +} + +wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw() +{ + int start; + int end; + + GetSelection(&start, &end); + int len = end - start; + if (!len) { + wxCharBuffer empty; + return empty; + } + + wxCharBuffer buf(len); + SendMsg(SCI_GETSELTEXT, 0, (long)buf.data()); + return buf; +} + +wxCharBuffer wxStyledTextCtrl::GetTextRangeRaw(int startPos, int endPos) +{ + if (endPos < startPos) { + int temp = startPos; + startPos = endPos; + endPos = temp; + } + int len = endPos - startPos; + if (!len) { + wxCharBuffer empty; + return empty; + } + + wxCharBuffer buf(len); + TextRange tr; + tr.lpstrText = buf.data(); + tr.chrg.cpMin = startPos; + tr.chrg.cpMax = endPos; + SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr); + return buf; +} + +void wxStyledTextCtrl::SetTextRaw(const char* text) +{ + SendMsg(SCI_SETTEXT, 0, (long)text); +} + +wxCharBuffer wxStyledTextCtrl::GetTextRaw() +{ + int len = GetTextLength(); + wxCharBuffer buf(len); + SendMsg(SCI_GETTEXT, len, (long)buf.data()); + return buf; +} + +void wxStyledTextCtrl::AppendTextRaw(const char* text) +{ + SendMsg(SCI_APPENDTEXT, strlen(text), (long)text); +} + + + + + //---------------------------------------------------------------------- // Event handlers @@ -2775,6 +3129,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(); @@ -2873,12 +3234,7 @@ static void SetEventText(wxStyledTextEvent& evt, const char* text, size_t length) { if(!text) return; - // The unicode conversion MUST have a null byte to terminate the - // string so move it into a buffer first and give it one. - wxMemoryBuffer buf(length+1); - buf.AppendData((void*)text, length); - buf.AppendByte(0); - evt.SetText(stc2wx(buf)); + evt.SetText(stc2wx(text, length)); } @@ -2956,10 +3312,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: @@ -2994,7 +3358,7 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { case SCN_CALLTIPCLICK: evt.SetEventType(wxEVT_STC_CALLTIP_CLICK); break; - + default: return; } @@ -3071,11 +3435,4 @@ wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): //---------------------------------------------------------------------- //---------------------------------------------------------------------- - - - - - - - - +#endif // wxUSE_STC