// If we don't do something like this, then the linker tends to "optimize"
// them away. (eric@sourcegear.com)
-int wxForceScintillaLexers(void)
+static int wxForceScintillaLexers(void)
{
extern LexerModule lmCPP;
extern LexerModule lmHTML;
extern LexerModule lmPython;
extern LexerModule lmSQL;
extern LexerModule lmVB;
+ extern LexerModule lmLua;
if (
&lmCPP
&& &lmPython
&& &lmSQL
&& &lmVB
+ && &lmLua
)
{
return 1;
}
- else
- {
- return 0;
- }
}
//----------------------------------------------------------------------
EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp)
EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp)
EVT_CHAR (wxStyledTextCtrl::OnChar)
+ EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown)
EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus)
EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus)
EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged)
EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground)
EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu)
+ EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox)
END_EVENT_TABLE()
+
+IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent)
+
//----------------------------------------------------------------------
// Constructor and Destructor
//----------------------------------------------------------------------
-inline long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) {
+long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) {
return m_swx->WndProc(msg, wp, lp);
}
wxString wxStyledTextCtrl::GetText() {
wxString text;
int len = GetTextLength();
- char* buff = text.GetWriteBuf(len);
+ char* buff = text.GetWriteBuf(len+1);
- SendMsg(WM_GETTEXT, len, (long)buff);
+ SendMsg(SCI_GETTEXT, len, (long)buff);
+ buff[len] = 0;
text.UngetWriteBuf();
return text;
}
bool wxStyledTextCtrl::SetText(const wxString& text) {
- return SendMsg(WM_SETTEXT, 0, (long)text.c_str()) != 0;
+ return SendMsg(SCI_SETTEXT, 0, (long)text.c_str()) != 0;
}
int len = GetLineLength(line);
char* buff = text.GetWriteBuf(len+1);
- *((WORD*)buff) = len+1;
- SendMsg(EM_GETLINE, line, (long)buff);
+ SendMsg(SCI_GETLINE, line, (long)buff);
+ buff[len] = 0;
text.UngetWriteBuf();
return text;
}
void wxStyledTextCtrl::ReplaceSelection(const wxString& text) {
- SendMsg(EM_REPLACESEL, 0, (long)text.c_str());
+ SendMsg(SCI_REPLACESEL, 0, (long)text.c_str());
}
void wxStyledTextCtrl::SetReadOnly(bool readOnly) {
- SendMsg(EM_SETREADONLY, (long)readOnly);
+ SendMsg(SCI_SETREADONLY, (long)readOnly);
m_readOnly = readOnly;
}
void wxStyledTextCtrl::GetTextRange(int startPos, int endPos, char* buff) {
- TEXTRANGE tr;
+ TextRange tr;
tr.lpstrText = buff;
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
- SendMsg(EM_GETTEXTRANGE, 0, (long)&tr);
+ SendMsg(SCI_GETTEXTRANGE, 0, (long)&tr);
}
wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) {
wxString text;
int len = endPos - startPos;
- char* buff = text.GetWriteBuf(len);
+ char* buff = text.GetWriteBuf(len+1);
GetTextRange(startPos, endPos, buff);
text.UngetWriteBuf();
return text;
void wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos, char* buff) {
- TEXTRANGE tr;
+ TextRange tr;
tr.lpstrText = buff;
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
wxString wxStyledTextCtrl::GetStyledTextRange(int startPos, int endPos) {
wxString text;
int len = endPos - startPos;
- char* buff = text.GetWriteBuf(len*2);
+ char* buff = text.GetWriteBuf(len*2+1);
GetStyledTextRange(startPos, endPos, buff);
text.UngetWriteBuf(len*2);
return text;
void wxStyledTextCtrl::Cut() {
- SendMsg(WM_CUT);
+ SendMsg(SCI_CUT);
}
void wxStyledTextCtrl::Copy() {
- SendMsg(WM_COPY);
+ SendMsg(SCI_COPY);
}
void wxStyledTextCtrl::Paste() {
- SendMsg(WM_PASTE);
+ SendMsg(SCI_PASTE);
}
bool wxStyledTextCtrl::CanPaste() {
- return SendMsg(EM_CANPASTE) != 0;
+ return SendMsg(SCI_CANPASTE) != 0;
}
void wxStyledTextCtrl::ClearClipbrd() {
- SendMsg(WM_CLEAR);
+ SendMsg(SCI_CLEAR);
}
// Undo and Redo
void wxStyledTextCtrl::Undo() {
- SendMsg(WM_UNDO);
+ SendMsg(SCI_UNDO);
}
bool wxStyledTextCtrl::CanUndo() {
- return SendMsg(EM_CANUNDO) != 0;
+ return SendMsg(SCI_CANUNDO) != 0;
}
void wxStyledTextCtrl::EmptyUndoBuffer() {
- SendMsg(EM_EMPTYUNDOBUFFER);
+ SendMsg(SCI_EMPTYUNDOBUFFER);
}
void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) {
- SendMsg(EM_GETSEL, (long)startPos, (long)endPos);
+// SendMsg(EM_GETSEL, (long)startPos, (long)endPos);
+ *startPos = SendMsg(SCI_GETSELECTIONSTART);
+ *endPos = SendMsg(SCI_GETSELECTIONEND);
}
void wxStyledTextCtrl::SetSelection(int startPos, int endPos) {
- SendMsg(EM_SETSEL, startPos, endPos);
+ SendMsg(SCI_SETSEL, startPos, endPos);
}
GetSelection(&start, &end);
int len = end - start;
- char* buff = text.GetWriteBuf(len);
+ char* buff = text.GetWriteBuf(len+1);
- SendMsg(EM_GETSELTEXT, 0, (long)buff);
+ SendMsg(SCI_GETSELTEXT, 0, (long)buff);
text.UngetWriteBuf();
return text;
}
void wxStyledTextCtrl::HideSelection(bool hide) {
- SendMsg(EM_HIDESELECTION, hide);
+ SendMsg(SCI_HIDESELECTION, hide);
}
int wxStyledTextCtrl::GetTextLength() {
- return SendMsg(WM_GETTEXTLENGTH);
+ return SendMsg(SCI_GETTEXTLENGTH);
}
int wxStyledTextCtrl::GetFirstVisibleLine() {
- return SendMsg(EM_GETFIRSTVISIBLELINE);
+ return SendMsg(SCI_GETFIRSTVISIBLELINE);
}
int wxStyledTextCtrl::GetLineCount() {
- return SendMsg(EM_GETLINECOUNT);
+ return SendMsg(SCI_GETLINECOUNT);
}
bool wxStyledTextCtrl::GetModified() {
- return SendMsg(EM_GETMODIFY) != 0;
-}
-
-
-wxRect wxStyledTextCtrl::GetRect() {
- PRectangle pr;
- SendMsg(EM_GETRECT, 0, (long)&pr);
-
- wxRect rect = wxRectFromPRectangle(pr);
- return rect;
+ return SendMsg(SCI_GETMODIFY) != 0;
}
int wxStyledTextCtrl::GetLineFromPos(int pos) {
- return SendMsg(EM_LINEFROMCHAR, pos);
+ return SendMsg(SCI_LINEFROMPOSITION, pos);
}
int wxStyledTextCtrl::GetLineStartPos(int line) {
- return SendMsg(EM_LINEINDEX, line);
-}
-
-
-int wxStyledTextCtrl::GetLineLengthAtPos(int pos) {
- return SendMsg(EM_LINELENGTH, pos);
+ return SendMsg(SCI_POSITIONFROMLINE, line);
}
int len = GetLineLength(GetCurrentLine());
char* buff = text.GetWriteBuf(len+1);
- int pos = SendMsg(SCI_GETCURLINE, len+1, (long)buff);
+ int pos = SendMsg(SCI_GETCURLINE, len, (long)buff);
text.UngetWriteBuf();
if (linePos)
int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) {
- Point spt(pt.x, pt.y);
- long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
- return LOWORD(rv);
-}
-
-
-int wxStyledTextCtrl::LineFromPoint(wxPoint pt) {
- Point spt(pt.x, pt.y);
- long rv = SendMsg(EM_CHARFROMPOS, 0, (long)&spt);
- return HIWORD(rv);
+ return SendMsg(SCI_POSITIONFROMPOINT, pt.x, pt.y);
}
wxPoint wxStyledTextCtrl::PointFromPosition(int pos) {
- Point pt;
- SendMsg(EM_POSFROMCHAR, pos, (long)&pt);
- return wxPoint(pt.x, pt.y);
+ int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos);
+ int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos);
+ return wxPoint(x, y);
}
void wxStyledTextCtrl::ScrollBy(int columnDelta, int lineDelta) {
- SendMsg(EM_LINESCROLL, columnDelta, lineDelta);
+ SendMsg(SCI_LINESCROLL, columnDelta, lineDelta);
}
void wxStyledTextCtrl::ScrollToLine(int line) {
void wxStyledTextCtrl::EnsureCaretVisible() {
- SendMsg(EM_SCROLLCARET);
+ SendMsg(SCI_SCROLLCARET);
}
}
-int wxStyledTextCtrl::GetSelectionType() {
- return SendMsg(EM_SELECTIONTYPE);
+int wxStyledTextCtrl::GetLinesOnScreen() {
+ return SendMsg(SCI_LINESONSCREEN);
+}
+
+
+bool wxStyledTextCtrl::IsSelectionRectangle() {
+ return SendMsg(SCI_SELECTIONISRECTANGLE) != 0;
+}
+
+
+void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool use) {
+ SendMsg(SCI_SETHSCROLLBAR, use);
+}
+
+
+bool wxStyledTextCtrl::GetUseHorizontalScrollBar() {
+ return SendMsg(SCI_GETHSCROLLBAR) != 0;
}
+
//----------------------------------------------------------------------
// Searching
int wxStyledTextCtrl::FindText(int minPos, int maxPos,
- const wxString& text,
- bool caseSensitive, bool wholeWord) {
- FINDTEXTEX ft;
+ const wxString& text,
+ bool caseSensitive, bool wholeWord) {
+ TextToFind ft;
int flags = 0;
- flags |= caseSensitive ? FR_MATCHCASE : 0;
- flags |= wholeWord ? FR_WHOLEWORD : 0;
+ flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
+ flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
ft.chrg.cpMin = minPos;
ft.chrg.cpMax = maxPos;
ft.lpstrText = (char*)text.c_str();
- return SendMsg(EM_FINDTEXT, flags, (long)&ft);
+ return SendMsg(SCI_FINDTEXT, flags, (long)&ft);
}
int wxStyledTextCtrl::SearchNext(const wxString& text, bool caseSensitive, bool wholeWord) {
int flags = 0;
- flags |= caseSensitive ? FR_MATCHCASE : 0;
- flags |= wholeWord ? FR_WHOLEWORD : 0;
+ flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
+ flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
return SendMsg(SCI_SEARCHNEXT, flags, (long)text.c_str());
}
int wxStyledTextCtrl::SearchPrev(const wxString& text, bool caseSensitive, bool wholeWord) {
int flags = 0;
- flags |= caseSensitive ? FR_MATCHCASE : 0;
- flags |= wholeWord ? FR_WHOLEWORD : 0;
+ flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
+ flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
return SendMsg(SCI_SEARCHPREV, flags, (long)text.c_str());
}
}
+void wxStyledTextCtrl::SetLineState(int line, int value) {
+ SendMsg(SCI_SETLINESTATE, line, value);
+}
+
+
+int wxStyledTextCtrl::GetLineState(int line) {
+ return SendMsg(SCI_GETLINESTATE, line);
+}
+
+
//----------------------------------------------------------------------
// Style Definition
// face:[facename] sets the font face name to use
// size:[num] sets the font size in points
// eol turns on eol filling
+// underline turns on underlining
//
void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) {
else if (option == "italic")
StyleSetItalic(styleNum, true);
+ else if (option == "underline")
+ StyleSetUnderline(styleNum, true);
+
else if (option == "eol")
StyleSetEOLFilled(styleNum, true);
wxString faceName = font.GetFaceName();
bool bold = font.GetWeight() == wxBOLD;
bool italic = font.GetStyle() != wxNORMAL;
+ bool under = font.GetUnderlined();
- StyleSetFontAttr(styleNum, size, faceName, bold, italic);
+ StyleSetFontAttr(styleNum, size, faceName, bold, italic, under);
}
void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size,
const wxString& faceName,
- bool bold, bool italic) {
+ bool bold, bool italic,
+ bool underline) {
StyleSetSize(styleNum, size);
StyleSetFaceName(styleNum, faceName);
StyleSetBold(styleNum, bold);
StyleSetItalic(styleNum, italic);
+ StyleSetUnderline(styleNum, underline);
}
}
+void wxStyledTextCtrl::StyleSetUnderline(int styleNum, bool underline) {
+ SendMsg(SCI_STYLESETUNDERLINE, styleNum, underline);
+}
+
+
//----------------------------------------------------------------------
// Margins in the edit area
int wxStyledTextCtrl::GetLeftMargin() {
- return LOWORD(SendMsg(EM_GETMARGINS));
+ return SendMsg(SCI_GETMARGINLEFT);
}
int wxStyledTextCtrl::GetRightMargin() {
- return HIWORD(SendMsg(EM_GETMARGINS));
+ return SendMsg(SCI_GETMARGINRIGHT);
}
void wxStyledTextCtrl::SetMargins(int left, int right) {
int flag = 0;
- int val = 0;
if (right != -1) {
- flag |= EC_RIGHTMARGIN;
- val = right << 16;
+ SendMsg(SCI_SETMARGINRIGHT, 0, right);
}
if (left != -1) {
- flag |= EC_LEFTMARGIN;
- val |= (left & 0xffff);
+ SendMsg(SCI_SETMARGINLEFT, 0, left);
}
-
- SendMsg(EM_SETMARGINS, flag, val);
}
void wxStyledTextCtrl::SetCaretForeground(const wxColour& colour) {
- SendMsg(SCI_SETCARETFORE, 0, wxColourAsLong(colour));
+ SendMsg(SCI_SETCARETFORE, wxColourAsLong(colour));
}
}
+void wxStyledTextCtrl::SetIndent(int numChars) {
+ SendMsg(SCI_SETINDENT, numChars);
+}
+
+
+void wxStyledTextCtrl::SetUseTabs(bool usetabs) {
+ SendMsg(SCI_SETUSETABS, usetabs);
+}
+
+
+void wxStyledTextCtrl::SetLineIndentation(int line, int indentation) {
+ SendMsg(SCI_SETLINEINDENTATION, line, indentation);
+}
+
+
+int wxStyledTextCtrl:: GetLineIndentation(int line) {
+ return SendMsg(SCI_GETLINEINDENTATION, line);
+}
+
+
+int wxStyledTextCtrl::GetLineIndentationPos(int line) {
+ return SendMsg(SCI_GETLINEINDENTPOSITION, line);
+}
+
+
void wxStyledTextCtrl::SetWordChars(const wxString& wordChars) {
SendMsg(SCI_SETTABWIDTH, 0, (long)wordChars.c_str());
}
+void wxStyledTextCtrl::SetUsePop(bool usepopup) {
+ SendMsg(SCI_USEPOPUP, usepopup);
+}
+
+
//----------------------------------------------------------------------
// Brace highlighting
void wxStyledTextCtrl::IndicatorSetColour(int indicNum, const wxColour& colour) {
- SendMsg(SCI_INDICSETSTYLE, indicNum, wxColourAsLong(colour));
+ SendMsg(SCI_INDICSETFORE, indicNum, wxColourAsLong(colour));
}
}
+void wxStyledTextCtrl::AutoCompSetSeparator(char separator) {
+ SendMsg(SCI_AUTOCSETSEPARATOR, separator);
+}
+
+
+char wxStyledTextCtrl::AutoCompGetSeparator() {
+ return SendMsg(SCI_AUTOCGETSEPARATOR);
+}
+
+
+void wxStyledTextCtrl::AutoCompSelect(const wxString& stringtoselect) {
+ SendMsg(SCI_AUTOCSELECT, (long)stringtoselect.c_str());
+}
+
+
//----------------------------------------------------------------------
// Call tips
//----------------------------------------------------------------------
// Key bindings
+#define MAKELONG(a, b) ((a) | ((b) << 16))
+
void wxStyledTextCtrl::CmdKeyAssign(int key, int modifiers, int cmd) {
SendMsg(SCI_ASSIGNCMDKEY, MAKELONG(key, modifiers), cmd);
}
wxDC* target, // Why does it use two? Can they be the same?
wxRect renderRect,
wxRect pageRect) {
- FORMATRANGE fr;
+ RangeToFormat fr;
fr.hdc = draw;
fr.hdcTarget = target;
fr.chrg.cpMin = startPos;
fr.chrg.cpMax = endPos;
- return SendMsg(EM_FORMATRANGE, doDraw, (long)&fr);
+ return SendMsg(SCI_FORMATRANGE, doDraw, (long)&fr);
}
}
-int wxStyledTextCtrl::GetLastChild(int line) {
- return SendMsg(SCI_GETLASTCHILD, line);
+int wxStyledTextCtrl::GetLastChild(int line, int level) {
+ return SendMsg(SCI_GETLASTCHILD, line, level);
}
}
-void wxStyledTextCtrl::SetFoldExpanded(int line) {
- SendMsg(SCI_SETFOLDEXPANDED, line);
+void wxStyledTextCtrl::SetFoldExpanded(int line, bool expanded) {
+ SendMsg(SCI_SETFOLDEXPANDED, line, expanded);
}
}
+void wxStyledTextCtrl::SetFoldFlags(int flags) {
+ SendMsg(SCI_SETFOLDFLAGS, flags);
+}
+
+
+//----------------------------------------------------------------------
+// Zooming
+
+void wxStyledTextCtrl::ZoomIn() {
+ SendMsg(SCI_ZOOMIN);
+}
+
+
+void wxStyledTextCtrl::ZoomOut() {
+ SendMsg(SCI_ZOOMOUT);
+}
+
+
+void wxStyledTextCtrl::SetZoom(int zoom) {
+ SendMsg(SCI_SETZOOM, zoom);
+}
+
+
+int wxStyledTextCtrl::GetZoom() {
+ return SendMsg(SCI_GETZOOM);
+}
+
//----------------------------------------------------------------------
// Long Lines
+//----------------------------------------------------------------------
+// Event mask for Modified Event
+
+void wxStyledTextCtrl::SetModEventMask(int mask) {
+ SendMsg(SCI_SETMODEVENTMASK, mask);
+}
+
+
+//int wxStyledTextCtrl::GetModEventMask() {
+// return SendMsg(SCI_GETMODEVENTMASK);
+//}
+
//----------------------------------------------------------------------
// Event handlers
}
void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) {
- int processed = 0;
long key = evt.KeyCode();
if ((key > WXK_ESCAPE) &&
(key != WXK_DELETE) && (key < 255) &&
!evt.ControlDown() && !evt.AltDown()) {
m_swx->DoAddChar(key);
- processed = true;
}
else {
- key = toupper(key);
- processed = m_swx->DoKeyDown(key, evt.ShiftDown(),
- evt.ControlDown(), evt.AltDown());
+ evt.Skip();
}
+}
+
+void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) {
+ long key = evt.KeyCode();
+ key = toupper(key);
+ int processed = m_swx->DoKeyDown(key, evt.ShiftDown(),
+ evt.ControlDown(), evt.AltDown());
if (! processed)
evt.Skip();
}
}
+void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) {
+ m_swx->DoOnListBox();
+}
+
+
//----------------------------------------------------------------------
// Turn notifications from Scintilla into events
+
void wxStyledTextCtrl::NotifyChange() {
wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId());
GetEventHandler()->ProcessEvent(evt);
evt.SetModifiers(scn.modifiers);
if (eventType == wxEVT_STC_MODIFIED) {
evt.SetModificationType(scn.modificationType);
- evt.SetText(scn.text);
+ if (scn.text)
+ evt.SetText(wxString(scn.text, scn.length));
evt.SetLength(scn.length);
evt.SetLinesAdded(scn.linesAdded);
evt.SetLine(scn.line);