derive wxSTC from wxTextAreaBase to provide wxTextCtrl-like methods (see #9114)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -39,6 +39,10 @@
|
||||
#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"
|
||||
@@ -1981,6 +1985,9 @@ class WXDLLIMPEXP_FWD_STC wxStyledTextEvent;
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl
|
||||
#if wxUSE_TEXTCTRL
|
||||
, public wxTextAreaBase
|
||||
#endif // wxUSE_TEXTCTRL
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -2081,7 +2088,7 @@ 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.
|
||||
@@ -2586,7 +2593,7 @@ public:
|
||||
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;
|
||||
@@ -2619,10 +2626,10 @@ public:
|
||||
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);
|
||||
@@ -3087,7 +3094,7 @@ public:
|
||||
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);
|
||||
@@ -3576,11 +3583,14 @@ 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
|
||||
@@ -3641,11 +3651,88 @@ public:
|
||||
#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);
|
||||
@@ -3689,7 +3776,7 @@ protected:
|
||||
|
||||
friend class ScintillaWX;
|
||||
friend class Platform;
|
||||
#endif
|
||||
#endif // !SWIG
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@@ -21,7 +21,7 @@ H_TEMPLATE = os.path.abspath('./stc.h.in')
|
||||
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
|
||||
@@ -144,9 +144,9 @@ methodOverrideMap = {
|
||||
|
||||
'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),
|
||||
|
||||
@@ -410,9 +410,9 @@ methodOverrideMap = {
|
||||
|
||||
'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;
|
||||
|
||||
@@ -655,6 +655,16 @@ methodOverrideMap = {
|
||||
|
||||
}
|
||||
|
||||
# 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):
|
||||
@@ -904,7 +914,8 @@ def parseFun(line, methods, docs, values, is_const):
|
||||
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) )
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
@@ -393,7 +393,7 @@ void wxStyledTextCtrl::SetViewWhiteSpace(int viewWS)
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -1439,7 +1439,7 @@ int wxStyledTextCtrl::GetFirstVisibleLine() const
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
@@ -1538,13 +1538,13 @@ void wxStyledTextCtrl::HideSelection(bool normal)
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -2464,7 +2464,7 @@ void wxStyledTextCtrl::MoveCaretInsideView()
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -3513,7 +3513,11 @@ void wxStyledTextCtrl::ScrollToColumn(int column) {
|
||||
}
|
||||
|
||||
|
||||
#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);
|
||||
|
||||
@@ -3528,7 +3532,11 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
||||
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);
|
||||
|
@@ -516,7 +516,11 @@ void wxStyledTextCtrl::ScrollToColumn(int column) {
|
||||
}
|
||||
|
||||
|
||||
#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);
|
||||
|
||||
@@ -531,7 +535,11 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
||||
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);
|
||||
|
@@ -39,6 +39,10 @@
|
||||
#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"
|
||||
@@ -80,6 +84,9 @@ class WXDLLIMPEXP_FWD_STC wxStyledTextEvent;
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl
|
||||
#if wxUSE_TEXTCTRL
|
||||
, public wxTextAreaBase
|
||||
#endif // wxUSE_TEXTCTRL
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -209,11 +216,14 @@ 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
|
||||
@@ -274,11 +284,88 @@ public:
|
||||
#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);
|
||||
@@ -322,7 +409,7 @@ protected:
|
||||
|
||||
friend class ScintillaWX;
|
||||
friend class Platform;
|
||||
#endif
|
||||
#endif // !SWIG
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user