#include "wx/dnd.h"
#include "wx/stopwatch.h"
+#if wxUSE_TEXTCTRL
+ #include "wx/textctrl.h"
+#endif // wxUSE_TEXTCTRL
+
class WXDLLIMPEXP_FWD_CORE wxScrollBar;
// SWIG can't handle "#if" type of conditionals, only "#ifdef"
//----------------------------------------------------------------------
class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl
+#if wxUSE_TEXTCTRL
+ , public wxTextAreaBase
+#endif // wxUSE_TEXTCTRL
{
public:
void SetViewWhiteSpace(int viewWS);
// Find the position from a point within the window.
- int PositionFromPoint(wxPoint pt);
+ int PositionFromPoint(wxPoint pt) const;
// Find the position from a point within the window but return
// INVALID_POSITION if not close to text.
int GetFirstVisibleLine() const;
// Retrieve the contents of a line.
- wxString GetLine(int line);
+ wxString GetLine(int line) const;
// Returns the number of lines in the document. There is always at least one.
int GetLineCount() const;
void HideSelection(bool normal);
// Retrieve the line containing a position.
- int LineFromPosition(int pos);
+ int LineFromPosition(int pos) const;
// Retrieve the position at the start of a line.
- int PositionFromLine(int line);
+ int PositionFromLine(int line) const;
// Scroll horizontally and vertically.
void LineScroll(int columns, int lines);
void MoveCaretInsideView();
// How many characters are on a line, not including end of line characters?
- int LineLength(int line);
+ int LineLength(int line) const;
// Highlight the characters at two positions.
void BraceHighlight(int pos1, int pos2);
bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; }
void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; }
+ // if we derive from wxTextAreaBase it already provides these methods
+#if !wxUSE_TEXTCTRL
// Write the contents of the editor to filename
bool SaveFile(const wxString& filename);
// Load the contents of filename into the editor
bool LoadFile(const wxString& filename);
+#endif // !wxUSE_TEXTCTRL
#ifdef STC_USE_DND
// Allow for simulating a DnD DragOver
#ifdef SWIG
%pythoncode "_stc_utf8_methods.py"
#endif
-//----------------------------------------------------------------------
+ // implement wxTextAreaBase pure virtual methods
+ // ---------------------------------------------
+
+ virtual int GetLineLength(long n) const { return GetLine(n).length(); }
+ virtual wxString GetLineText(long n) const { return GetLine(n); }
+ virtual int GetNumberOfLines() const { return GetLineCount(); }
+
+ virtual bool IsModified() const { return GetModify(); }
+ virtual void MarkDirty() { wxFAIL_MSG("not implemented"); }
+ virtual void DiscardEdits() { SetSavePoint(); }
+
+ virtual bool SetStyle(long WXUNUSED(start), long WXUNUSED(end),
+ const wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual bool GetStyle(long WXUNUSED(position), wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual bool SetDefaultStyle(const wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual long XYToPosition(long x, long y) const
+ {
+ long pos = PositionFromLine(y);
+ pos += x;
+ return pos;
+ }
+
+ virtual bool PositionToXY(long pos, long *x, long *y) const
+ {
+ if ( x )
+ *x = -1; // TODO
+
+ if ( y )
+ {
+ long l = LineFromPosition(pos);
+ if ( l == -1 )
+ return false;
+ *y = l;
+ }
+
+ return true;
+ }
+
+ virtual void ShowPosition(long pos)
+ {
+ EnsureVisible(LineFromPosition(pos));
+ }
+
+ using wxWindow::HitTest;
+
+ virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const
+ {
+ const long l = PositionFromPoint(pt);
+ if ( l == -1 )
+ return wxTE_HT_BELOW; // we don't really know where it was
+
+ if ( pos )
+ *pos = l;
+
+ return wxTE_HT_ON_TEXT;
+ }
+
#ifndef SWIG
protected:
+ virtual bool DoLoadFile(const wxString& file, int fileType);
+ virtual bool DoSaveFile(const wxString& file, int fileType);
+
// Event handlers
void OnPaint(wxPaintEvent& evt);
void OnScrollWin(wxScrollWinEvent& evt);
friend class ScintillaWX;
friend class Platform;
-#endif
+#endif // !SWIG
};
//----------------------------------------------------------------------
CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
CPP_DEST = os.path.abspath('./stc.cpp')
-DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
+DOCSTR_DEST = '/dev/null' #os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
# Value prefixes to convert
'PositionFromPoint' :
(0,
- 'int %s(wxPoint pt);',
+ 'int %s(wxPoint pt) const;',
- '''int %s(wxPoint pt) {
+ '''int %s(wxPoint pt) const {
return SendMsg(%s, pt.x, pt.y);''',
0),
'GetLine' :
(0,
- 'wxString %s(int line);',
+ 'wxString %s(int line) const;',
- '''wxString %s(int line) {
+ '''wxString %s(int line) const {
int len = LineLength(line);
if (!len) return wxEmptyString;
}
+# all Scintilla getters are transformed into const member of wxSTC class but
+# some non-getter methods are also logically const and this set contains their
+# names (notice that it's useless to include here methods manually overridden
+# above)
+constNonGetterMethods = set((
+ 'LineFromPosition',
+ 'PositionFromLine',
+ 'LineLength',
+))
+
#----------------------------------------------------------------------------
def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
if not FUNC_FOR_CMD:
return
- methods.append( (retType, name, number, param1, param2, tuple(docs), is_const) )
+ methods.append( (retType, name, number, param1, param2, tuple(docs),
+ is_const or name in constNonGetterMethods) )
#----------------------------------------------------------------------------
}
// Find the position from a point within the window.
-int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) {
+int wxStyledTextCtrl::PositionFromPoint(wxPoint pt) const {
return SendMsg(2022, pt.x, pt.y);
}
}
// Retrieve the contents of a line.
-wxString wxStyledTextCtrl::GetLine(int line) {
+wxString wxStyledTextCtrl::GetLine(int line) const {
int len = LineLength(line);
if (!len) return wxEmptyString;
}
// Retrieve the line containing a position.
-int wxStyledTextCtrl::LineFromPosition(int pos)
+int wxStyledTextCtrl::LineFromPosition(int pos) const
{
return SendMsg(2166, pos, 0);
}
// Retrieve the position at the start of a line.
-int wxStyledTextCtrl::PositionFromLine(int line)
+int wxStyledTextCtrl::PositionFromLine(int line) const
{
return SendMsg(2167, line, 0);
}
}
// How many characters are on a line, not including end of line characters?
-int wxStyledTextCtrl::LineLength(int line)
+int wxStyledTextCtrl::LineLength(int line) const
{
return SendMsg(2350, line, 0);
}
}
+#if wxUSE_TEXTCTRL
+bool wxStyledTextCtrl::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
+#else
bool wxStyledTextCtrl::SaveFile(const wxString& filename)
+#endif
{
wxFile file(filename, wxFile::write);
return success;
}
+#if wxUSE_TEXTCTRL
+bool wxStyledTextCtrl::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
+#else
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
+#endif
{
bool success = false;
wxFile file(filename, wxFile::read);
}
+#if wxUSE_TEXTCTRL
+bool wxStyledTextCtrl::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
+#else
bool wxStyledTextCtrl::SaveFile(const wxString& filename)
+#endif
{
wxFile file(filename, wxFile::write);
return success;
}
+#if wxUSE_TEXTCTRL
+bool wxStyledTextCtrl::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
+#else
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
+#endif
{
bool success = false;
wxFile file(filename, wxFile::read);
#include "wx/dnd.h"
#include "wx/stopwatch.h"
+#if wxUSE_TEXTCTRL
+ #include "wx/textctrl.h"
+#endif // wxUSE_TEXTCTRL
+
class WXDLLIMPEXP_FWD_CORE wxScrollBar;
// SWIG can't handle "#if" type of conditionals, only "#ifdef"
//----------------------------------------------------------------------
class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl
+#if wxUSE_TEXTCTRL
+ , public wxTextAreaBase
+#endif // wxUSE_TEXTCTRL
{
public:
bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; }
void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; }
+ // if we derive from wxTextAreaBase it already provides these methods
+#if !wxUSE_TEXTCTRL
// Write the contents of the editor to filename
bool SaveFile(const wxString& filename);
// Load the contents of filename into the editor
bool LoadFile(const wxString& filename);
+#endif // !wxUSE_TEXTCTRL
#ifdef STC_USE_DND
// Allow for simulating a DnD DragOver
#ifdef SWIG
%%pythoncode "_stc_utf8_methods.py"
#endif
-//----------------------------------------------------------------------
+ // implement wxTextAreaBase pure virtual methods
+ // ---------------------------------------------
+
+ virtual int GetLineLength(long n) const { return GetLine(n).length(); }
+ virtual wxString GetLineText(long n) const { return GetLine(n); }
+ virtual int GetNumberOfLines() const { return GetLineCount(); }
+
+ virtual bool IsModified() const { return GetModify(); }
+ virtual void MarkDirty() { wxFAIL_MSG("not implemented"); }
+ virtual void DiscardEdits() { SetSavePoint(); }
+
+ virtual bool SetStyle(long WXUNUSED(start), long WXUNUSED(end),
+ const wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual bool GetStyle(long WXUNUSED(position), wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual bool SetDefaultStyle(const wxTextAttr& WXUNUSED(style))
+ {
+ wxFAIL_MSG("not implemented");
+
+ return false;
+ }
+
+ virtual long XYToPosition(long x, long y) const
+ {
+ long pos = PositionFromLine(y);
+ pos += x;
+ return pos;
+ }
+
+ virtual bool PositionToXY(long pos, long *x, long *y) const
+ {
+ if ( x )
+ *x = -1; // TODO
+
+ if ( y )
+ {
+ long l = LineFromPosition(pos);
+ if ( l == -1 )
+ return false;
+ *y = l;
+ }
+
+ return true;
+ }
+
+ virtual void ShowPosition(long pos)
+ {
+ EnsureVisible(LineFromPosition(pos));
+ }
+
+ using wxWindow::HitTest;
+
+ virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const
+ {
+ const long l = PositionFromPoint(pt);
+ if ( l == -1 )
+ return wxTE_HT_BELOW; // we don't really know where it was
+
+ if ( pos )
+ *pos = l;
+
+ return wxTE_HT_ON_TEXT;
+ }
+
#ifndef SWIG
protected:
+ virtual bool DoLoadFile(const wxString& file, int fileType);
+ virtual bool DoSaveFile(const wxString& file, int fileType);
+
// Event handlers
void OnPaint(wxPaintEvent& evt);
void OnScrollWin(wxScrollWinEvent& evt);
friend class ScintillaWX;
friend class Platform;
-#endif
+#endif // !SWIG
};
//----------------------------------------------------------------------