////////////////////////////////////////////////////////////////////////////
-// Name: stc.h
+// Name: wx/stc/stc.h
// Purpose: A wxWidgets implementation of Scintilla. This class is the
// one meant to be used directly by wx applications. It does not
// derive directly from the Scintilla classes, and in fact there
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
+/*
+ IMPORTANT: include/wx/stc/stc.h is generated by src/stc/gen_iface.py from
+ src/stc/stc.h.in, don't edit stc.h file as your changes will be
+ lost after the next regeneration, edit stc.h.in and rerun the
+ gen_iface.py script instead!
+
+ Parts of this file generated by the script are found in between
+ the special "{{{" and "}}}" markers, the rest of it is copied
+ verbatim from src.h.in.
+ */
+
#ifndef _WX_STC_STC_H_
#define _WX_STC_STC_H_
#include "wx/dnd.h"
#include "wx/stopwatch.h"
+#include "wx/textentry.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"
//----------------------------------------------------------------------
-// BEGIN generated section. The following code is automatically generated
-// by gen_iface.py. Do not edit this file. Edit stc.h.in instead
-// and regenerate
+// STC constants generated section {{{
#define wxSTC_INVALID_POSITION -1
#define wxSTC_R_INFIX 10
#define wxSTC_R_INFIXEOL 11
+//}}}
+//----------------------------------------------------------------------
-//-----------------------------------------
-// Commands that can be bound to keystrokes
+//----------------------------------------------------------------------
+// Commands that can be bound to keystrokes section {{{
// Redoes the next action on the undo history.
// Move caret right one word, position cursor at end of word, extending selection to new caret position.
#define wxSTC_CMD_WORDRIGHTENDEXTEND 2442
-
-// END of generated section
+//}}}
//----------------------------------------------------------------------
class ScintillaWX; // forward declare
//----------------------------------------------------------------------
class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl
+ , public wxTextEntryBase
+#if wxUSE_TEXTCTRL
+ , public wxTextAreaBase
+#endif // wxUSE_TEXTCTRL
{
public:
const wxString& name = wxSTCNameStr);
-//----------------------------------------------------------------------
-// BEGIN generated section. The following code is automatically generated
-// by gen_iface.py. Do not edit this file. Edit stc.h.in instead
-// and regenerate
+ //----------------------------------------------------------------------
+ // Generated method declaration section {{{
// Add text to the document at current position.
wxMemoryBuffer GetStyledText(int startPos, int endPos);
// Are there any redoable actions in the undo history?
- bool CanRedo();
+ bool CanRedo() const;
// Retrieve the line number at which a particular marker is located.
int MarkerLineFromHandle(int handle);
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 startPos,
int endPos,
wxDC* draw,
- wxDC* target,
+ wxDC* target,
wxRect renderRect,
wxRect pageRect);
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);
bool CanPaste();
// Are there any undoable actions in the undo history?
- bool CanUndo();
+ bool CanUndo() const;
// Delete the undo history.
void EmptyUndoBuffer();
void SetText(const wxString& text);
// Retrieve all the text in the document.
- wxString GetText();
+ wxString GetText() const;
// Retrieve the number of characters in the document.
int GetTextLength() const;
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);
// Retrieve the number of bits the current lexer needs for styling.
int GetStyleBitsNeeded() const;
-// END of generated section
-//----------------------------------------------------------------------
-// Others...
+ //}}}
+ //----------------------------------------------------------------------
+ // Manually declared methods
// Returns the line number of the line with the caret.
int GetCurrentLine();
// Set the font encoding to be used by a style.
void StyleSetFontEncoding(int style, wxFontEncoding encoding);
-
+
// Perform one of the operations defined by the wxSTC_CMD_* constants.
void CmdKeyExecute(int cmd);
// NB: this method is not really const as it can modify the control but it
// has to be declared as such as it's called from both const and
// non-const methods and we can't distinguish between the two
- long SendMsg(int msg, long wp=0, long lp=0) const;
+ wxIntPtr SendMsg(int msg, wxUIntPtr wp=0, wxIntPtr lp=0) const;
// Set the vertical scrollbar to use instead of the ont that's built-in.
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
bool GetUseAntiAliasing();
-
+
// The following methods are nearly equivallent to their similarly named
// cousins above. The difference is that these methods bypass wxString
// and always use a char* even if used in a unicode build of wxWidgets.
// In that case the character data will be utf-8 encoded since that is
// what is used internally by Scintilla in unicode builds.
-
+
// Add text to the document at current position.
void AddTextRaw(const char* text);
#ifdef SWIG
%pythoncode "_stc_utf8_methods.py"
#endif
-//----------------------------------------------------------------------
+ // implement wxTextEntryBase pure virtual methods
+ // ----------------------------------------------
+
+ virtual void WriteText(const wxString& text) { AddText(text); }
+ virtual wxString GetValue() const { return GetText(); }
+ virtual void Remove(long from, long to)
+ {
+ Replace(from, to, "");
+ }
+ virtual void Replace(long from, long to, const wxString& text)
+ {
+ SetTargetStart(from);
+ SetTargetEnd(to);
+ ReplaceTarget(text);
+ }
+
+ /*
+ These functions are already declared in the generated section.
+
+ virtual void Copy();
+ virtual void Cut();
+ virtual void Paste();
+
+ virtual void Undo();
+ virtual void Redo();
+
+ virtual bool CanUndo() const;
+ virtual bool CanRedo() const;
+
+ */
+
+ virtual void SetInsertionPoint(long pos) { SetCurrentPos(pos); }
+ virtual long GetInsertionPoint() const { return GetCurrentPos(); }
+ virtual long GetLastPosition() const { return GetTextLength(); }
+
+ virtual void SetSelection(long from, long to)
+ {
+ if ( from == -1 && to == -1 )
+ {
+ SelectAll();
+ }
+ else
+ {
+ SetSelectionStart(from);
+ SetSelectionEnd(to);
+ }
+ }
+
+ virtual void GetSelection(long *from, long *to) const
+ {
+ if ( from )
+ *from = GetSelectionStart();
+ if ( to )
+ *to = GetSelectionEnd();
+ }
+
+ virtual bool IsEditable() const { return !GetReadOnly(); }
+ virtual void SetEditable(bool editable) { SetReadOnly(!editable); }
+
+ // 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) { GotoPos(pos); }
+
+ // FIXME-VC6: can't use wxWindow here because of "error C2603: illegal
+ // access declaration: 'wxWindow' is not a direct base of
+ // 'wxStyledTextCtrl'" with VC6
+ using wxControl::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);
bool m_lastKeyDownConsumed;
+ // the timestamp that consists of the last wheel event
+ // added to the time taken to process that event.
+ long m_lastWheelTimestamp;
+
friend class ScintillaWX;
friend class Platform;
-#endif
+#endif // !SWIG
};
//----------------------------------------------------------------------