#include <ctype.h>
-#include "wx/stc/stc.h"
-#include "ScintillaWX.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"
//----------------------------------------------------------------------
}
-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();
#endif
SetBestFittingSize(size);
+
+ // Reduces flicker on GTK+/X11
+ SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ return true;
}
buff[len] = 0;
SendMsg(2049, markerNumber, (long)buff);
delete [] buff;
+
}
// Set a margin to be either numeric or symbolic.
buff[len] = 0;
SendMsg(2405, type, (long)buff);
delete [] buff;
+
}
// Clear all the registered images.
}
// On Windows, will draw the document into a display context such as a printer.
-int wxStyledTextCtrl::FormatRange(bool doDraw,
- int startPos,
- int endPos,
- wxDC* draw,
- wxDC* target,
- wxRect renderRect,
- wxRect pageRect) {
- RangeToFormat fr;
-
- if (endPos < startPos) {
- int temp = startPos;
- startPos = endPos;
- endPos = temp;
- }
- fr.hdc = draw;
- fr.hdcTarget = target;
- fr.rc.top = renderRect.GetTop();
- fr.rc.left = renderRect.GetLeft();
- fr.rc.right = renderRect.GetRight();
- fr.rc.bottom = renderRect.GetBottom();
- fr.rcPage.top = pageRect.GetTop();
- fr.rcPage.left = pageRect.GetLeft();
- fr.rcPage.right = pageRect.GetRight();
- fr.rcPage.bottom = pageRect.GetBottom();
- fr.chrg.cpMin = startPos;
- fr.chrg.cpMax = endPos;
-
- return SendMsg(2151, doDraw, (long)&fr);
+ int wxStyledTextCtrl::FormatRange(bool doDraw,
+ int startPos,
+ int endPos,
+ wxDC* draw,
+ wxDC* target,
+ wxRect renderRect,
+ wxRect pageRect) {
+ RangeToFormat fr;
+
+ if (endPos < startPos) {
+ int temp = startPos;
+ startPos = endPos;
+ endPos = temp;
+ }
+ fr.hdc = draw;
+ fr.hdcTarget = target;
+ fr.rc.top = renderRect.GetTop();
+ fr.rc.left = renderRect.GetLeft();
+ fr.rc.right = renderRect.GetRight();
+ fr.rc.bottom = renderRect.GetBottom();
+ fr.rcPage.top = pageRect.GetTop();
+ fr.rcPage.left = pageRect.GetLeft();
+ fr.rcPage.right = pageRect.GetRight();
+ fr.rcPage.bottom = pageRect.GetBottom();
+ fr.chrg.cpMin = startPos;
+ fr.chrg.cpMax = endPos;
+
+ return SendMsg(2151, doDraw, (long)&fr);
}
// Retrieve the display line at the top of the display.
}
// 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
+// multi-byte characters. If beyond end of line, return line end position.
+int wxStyledTextCtrl::FindColumn(int line, int column) {
+ return SendMsg(2456, line, column);
+}
+
// Start notifying the container of all key presses and commands.
void wxStyledTextCtrl::StartRecord() {
SendMsg(3001, 0, 0);
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::OnChar(wxKeyEvent& evt) {
- // On (some?) non-US keyboards the AltGr key is required to enter some
+ // On (some?) non-US PC keyboards the AltGr key is required to enter some
// common characters. It comes to us as both Alt and Ctrl down so we need
// to let the char through in that case, otherwise if only ctrl or only
// alt let's skip it.
#endif
bool skip = ((ctrl || alt) && ! (ctrl && alt));
- int key = evt.GetKeyCode();
-
-// printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n",
-// key, m_lastKeyDownConsumed, ctrl, alt, skip);
-
- if ( (key <= WXK_START || key > WXK_COMMAND) &&
- !m_lastKeyDownConsumed && !skip) {
- m_swx->DoAddChar(key);
- return;
+ if (!m_lastKeyDownConsumed && !skip) {
+#if wxUSE_UNICODE
+ int key = evt.GetUnicodeKey();
+ bool keyOk = true;
+
+ // if the unicode key code is not really a unicode character (it may
+ // be a function key or etc., the platforms appear to always give us a
+ // small value in this case) then fallback to the ascii key code but
+ // don't do anything for function keys or etc.
+ if (key <= 127) {
+ key = evt.GetKeyCode();
+ keyOk = (key <= 127);
+ }
+ if (keyOk) {
+ m_swx->DoAddChar(key);
+ return;
+ }
+#else
+ int key = evt.GetKeyCode();
+ if (key <= WXK_START || key > WXK_COMMAND) {
+ m_swx->DoAddChar(key);
+ return;
+ }
+#endif
}
+
evt.Skip();
}
void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
- int key = evt.GetKeyCode();
- bool shift = evt.ShiftDown(),
- ctrl = evt.ControlDown(),
- alt = evt.AltDown(),
- meta = evt.MetaDown();
-
- int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed);
-
-// printf("KeyDn key:%d shift:%d ctrl:%d alt:%d processed:%d consumed:%d\n",
-// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed);
-
+ int processed = m_swx->DoKeyDown(evt, &m_lastKeyDownConsumed);
if (!processed && !m_lastKeyDownConsumed)
evt.Skip();
}