+
+// Returns the line number of the line with the caret.
+int wxStyledTextCtrl::GetCurrentLine() {
+ int line = LineFromPosition(GetCurrentPos());
+ return line;
+}
+
+
+// Extract style settings from a spec-string which is composed of one or
+// more of the following comma separated elements:
+//
+// bold turns on bold
+// italic turns on italics
+// fore:[name or #RRGGBB] sets the foreground colour
+// back:[name or #RRGGBB] sets the background colour
+// 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) {
+
+ wxStringTokenizer tkz(spec, wxT(","));
+ while (tkz.HasMoreTokens()) {
+ wxString token = tkz.GetNextToken();
+
+ wxString option = token.BeforeFirst(':');
+ wxString val = token.AfterFirst(':');
+
+ if (option == wxT("bold"))
+ StyleSetBold(styleNum, true);
+
+ else if (option == wxT("italic"))
+ StyleSetItalic(styleNum, true);
+
+ else if (option == wxT("underline"))
+ StyleSetUnderline(styleNum, true);
+
+ else if (option == wxT("eol"))
+ StyleSetEOLFilled(styleNum, true);
+
+ else if (option == wxT("size")) {
+ long points;
+ if (val.ToLong(&points))
+ StyleSetSize(styleNum, points);
+ }
+
+ else if (option == wxT("face"))
+ StyleSetFaceName(styleNum, val);
+
+ else if (option == wxT("fore"))
+ StyleSetForeground(styleNum, wxColourFromSpec(val));
+
+ else if (option == wxT("back"))
+ StyleSetBackground(styleNum, wxColourFromSpec(val));
+ }
+}
+
+
+// Set style size, face, bold, italic, and underline attributes from
+// a wxFont's attributes.
+void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) {
+#ifdef __WXGTK__
+ // Ensure that the native font is initialized
+ 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);
+}
+
+// Set all font style attributes at once.
+void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size,
+ const wxString& faceName,
+ bool bold, bool italic,
+ bool underline) {
+ StyleSetSize(styleNum, size);
+ StyleSetFaceName(styleNum, faceName);
+ StyleSetBold(styleNum, bold);
+ StyleSetItalic(styleNum, italic);
+ StyleSetUnderline(styleNum, underline);
+
+ // TODO: add encoding/charset mapping
+}
+
+
+// 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;