📄 stc.cpp.in
字号:
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);
}
// Perform one of the operations defined by the wxSTC_CMD_* constants.
void wxStyledTextCtrl::CmdKeyExecute(int cmd) {
SendMsg(cmd);
}
// Set the left and right margin in the edit area, measured in pixels.
void wxStyledTextCtrl::SetMargins(int left, int right) {
SetMarginLeft(left);
SetMarginRight(right);
}
// Retrieve the start and end positions of the current selection.
void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) {
if (startPos != NULL)
*startPos = SendMsg(SCI_GETSELECTIONSTART);
if (endPos != NULL)
*endPos = SendMsg(SCI_GETSELECTIONEND);
}
// Retrieve the point in the window where a position is displayed.
wxPoint wxStyledTextCtrl::PointFromPosition(int pos) {
int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos);
int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos);
return wxPoint(x, y);
}
// Scroll enough to make the given line visible
void wxStyledTextCtrl::ScrollToLine(int line) {
m_swx->DoScrollToLine(line);
}
// Scroll enough to make the given column visible
void wxStyledTextCtrl::ScrollToColumn(int column) {
m_swx->DoScrollToColumn(column);
}
bool wxStyledTextCtrl::SaveFile(const wxString& filename)
{
wxFile file(filename, wxFile::write);
if (!file.IsOpened())
return false;
bool success = file.Write(GetText(), *wxConvCurrent);
if (success)
SetSavePoint();
return success;
}
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
{
bool success = false;
wxFile file(filename, wxFile::read);
if (file.IsOpened())
{
wxString contents;
// get the file size (assume it is not huge file...)
ssize_t len = (ssize_t)file.Length();
if (len > 0)
{
#if wxUSE_UNICODE
wxMemoryBuffer buffer(len+1);
success = (file.Read(buffer.GetData(), len) == len);
if (success) {
((char*)buffer.GetData())[len] = 0;
contents = wxString(buffer, *wxConvCurrent, len);
}
#else
wxString buffer;
success = (file.Read(wxStringBuffer(buffer, len), len) == len);
contents = buffer;
#endif
}
else
{
if (len == 0)
success = true; // empty file is ok
else
success = false; // len == wxInvalidOffset
}
if (success)
{
SetText(contents);
EmptyUndoBuffer();
SetSavePoint();
}
}
return success;
}
#if wxUSE_DRAG_AND_DROP
wxDragResult wxStyledTextCtrl::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
return m_swx->DoDragOver(x, y, def);
}
bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
return m_swx->DoDropText(x, y, data);
}
#endif
void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) {
m_swx->SetUseAntiAliasing(useAA);
}
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
void wxStyledTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(evt)) {
wxPaintDC dc(this);
m_swx->DoPaint(&dc, GetUpdateRegion().GetBox());
}
void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) {
if (evt.GetOrientation() == wxHORIZONTAL)
m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
else
m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
}
void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) {
wxScrollBar* sb = wxDynamicCast(evt.GetEventObject(), wxScrollBar);
if (sb) {
if (sb->IsVertical())
m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition());
else
m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition());
}
}
void wxStyledTextCtrl::OnSize(wxSizeEvent& WXUNUSED(evt)) {
if (m_swx) {
wxSize sz = GetClientSize();
m_swx->DoSize(sz.x, sz.y);
}
}
void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) {
SetFocus();
wxPoint pt = evt.GetPosition();
m_swx->DoLeftButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ShiftDown(), evt.ControlDown(), evt.AltDown());
}
void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition();
m_swx->DoLeftButtonMove(Point(pt.x, pt.y));
}
void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) {
wxPoint pt = evt.GetPosition();
m_swx->DoLeftButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(),
evt.ControlDown());
}
void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -