#include <ctype.h>
-#include <wx/wx.h>
-#include <wx/tokenzr.h>
-#include <wx/mstream.h>
-#include <wx/image.h>
-#include <wx/file.h>
+#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"
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 )
}
-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();
// Reduces flicker on GTK+/X11
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ return true;
}
// 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];
}
+// 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);
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);
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);
}
// 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);
}
// 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];
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);
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);
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.
// 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.
}
// 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?
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);
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), (long)NULL);
+ 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), (long)NULL);
+ 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
//----------------------------------------------------------------------
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);
+}
+
+
+// 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);
+}
+
- // TODO: add encoding/charset mapping
+// Set the font encoding to be used by a style.
+void wxStyledTextCtrl::StyleSetFontEncoding(int style, wxFontEncoding encoding)
+{
+ SendMsg(SCI_STYLESETCHARACTERSET, style, encoding+1);
}
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
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));
}
evt.SetEventType(wxEVT_STC_CALLTIP_CLICK);
break;
+ case SCN_AUTOCSELECTION:
+ evt.SetEventType(wxEVT_STC_AUTOCOMP_SELECTION);
+ break;
+
default:
return;
}