X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dc8005e2062bdc3cae2554a8519e264c6d8ce9c7..d7e2b52235d70e25d7797ce1dccd97fa6989f4b5:/src/stc/stc.h.in diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index c74907d01f..1f2622784f 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -1,5 +1,5 @@ //////////////////////////////////////////////////////////////////////////// -// 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 @@ -17,22 +17,34 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#ifndef __stc_h__ -#define __stc_h__ +/* + 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. + */ -#include -#include +#ifndef _WX_STC_STC_H_ +#define _WX_STC_STC_H_ +#include "wx/defs.h" -#ifdef WXMAKINGDLL_STC - #define WXDLLIMPEXP_STC WXEXPORT -#elif defined(WXUSINGDLL) - #define WXDLLIMPEXP_STC WXIMPORT -#else // not making nor using DLL - #define WXDLLIMPEXP_STC -#endif +#if wxUSE_STC + +#include "wx/control.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" #ifdef SWIG @@ -43,28 +55,21 @@ #endif #endif -//---------------------------------------------------------------------- - -// Should a wxPopupWindow be used for the call tips and autocomplete windows? -#ifndef wxSTC_USE_POPUP -#define wxSTC_USE_POPUP 1 -#endif //---------------------------------------------------------------------- -// 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 {{{ %(VALUES)s +//}}} +//---------------------------------------------------------------------- -//----------------------------------------- -// Commands that can be bound to keystrokes +//---------------------------------------------------------------------- +// Commands that can be bound to keystrokes section {{{ %(CMDS)s - -// END of generated section +//}}} //---------------------------------------------------------------------- class ScintillaWX; // forward declare @@ -73,13 +78,18 @@ struct SCNotification; #ifndef SWIG extern WXDLLIMPEXP_STC const wxChar* wxSTCNameStr; -class WXDLLIMPEXP_STC wxStyledTextCtrl; -class WXDLLIMPEXP_STC wxStyledTextEvent; +class WXDLLIMPEXP_FWD_STC wxStyledTextCtrl; +class WXDLLIMPEXP_FWD_STC wxStyledTextEvent; #endif //---------------------------------------------------------------------- -class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl { +class WXDLLIMPEXP_STC wxStyledTextCtrl : public wxControl + , public wxTextEntryBase +#if wxUSE_TEXTCTRL + , public wxTextAreaBase +#endif // wxUSE_TEXTCTRL +{ public: #ifdef SWIG @@ -90,7 +100,7 @@ public: const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPySTCNameStr); - %%name(PreStyledTextCtrl) wxStyledTextCtrl(); + %%RenameCtor(PreStyledTextCtrl, wxStyledTextCtrl()); #else wxStyledTextCtrl(wxWindow *parent, wxWindowID id=wxID_ANY, @@ -102,23 +112,21 @@ public: #endif - void Create(wxWindow *parent, wxWindowID id=wxID_ANY, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = wxSTCNameStr); + bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + 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 {{{ %(METHOD_DEFS)s -// END of generated section -//---------------------------------------------------------------------- -// Others... + //}}} + //---------------------------------------------------------------------- + // Manually declared methods // Returns the line number of the line with the caret. int GetCurrentLine(); @@ -138,6 +146,9 @@ public: void StyleSetSpec(int styleNum, const wxString& spec); + // Get the font of a style. + wxFont StyleGetFont(int style); + // Set style size, face, bold, italic, and underline attributes from // a wxFont's attributes. @@ -149,26 +160,26 @@ public: void StyleSetFontAttr(int styleNum, int size, const wxString& faceName, bool bold, bool italic, - bool underline); + bool underline, + wxFontEncoding encoding=wxFONTENCODING_DEFAULT); + // Set the character set of the font in a style. Converts the Scintilla + // character set values to a wxFontEncoding. + void StyleSetCharacterSet(int style, int characterSet); + + // 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); - // Set the left and right margin in the edit area, measured in pixels. void SetMargins(int left, int right); - // Retrieve the start and end positions of the current selection. -#ifdef SWIG - void GetSelection(int* OUTPUT, int* OUTPUT); -#else - void GetSelection(int* startPos, int* endPos); -#endif - // Retrieve the point in the window where a position is displayed. wxPoint PointFromPosition(int pos); @@ -182,25 +193,32 @@ public: // Send a message to Scintilla - long SendMsg(int msg, long wp=0, long lp=0); + // + // 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 + 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. - void SetVScrollBar(wxScrollBar* bar) { m_vScrollBar = bar; } + void SetVScrollBar(wxScrollBar* bar); // Set the horizontal scrollbar to use instead of the ont that's built-in. - void SetHScrollBar(wxScrollBar* bar) { m_hScrollBar = bar; } + void SetHScrollBar(wxScrollBar* bar); // Can be used to prevent the EVT_CHAR handler from adding the char 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 @@ -219,11 +237,204 @@ public: 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); + + // Insert string at a position. + void InsertTextRaw(int pos, const char* text); + + // Retrieve the text of the line containing the caret. + // Returns the index of the caret on the line. +#ifdef SWIG + wxCharBuffer GetCurLineRaw(int* OUTPUT); +#else + wxCharBuffer GetCurLineRaw(int* linePos=NULL); +#endif + + // Retrieve the contents of a line. + wxCharBuffer GetLineRaw(int line); + + // Retrieve the selected text. + wxCharBuffer GetSelectedTextRaw(); + + // Retrieve a range of text. + wxCharBuffer GetTextRangeRaw(int startPos, int endPos); + + // Replace the contents of the document with the argument text. + void SetTextRaw(const char* text); + + // Retrieve all the text in the document. + wxCharBuffer GetTextRaw(); + + // Append a string to the end of the document without changing the selection. + void AppendTextRaw(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); + } + } + +#ifdef SWIG + void GetSelection(long* OUTPUT, long* OUTPUT) const; +#else + virtual void GetSelection(long *from, long *to) const + { + if ( from ) + *from = GetSelectionStart(); + if ( to ) + *to = GetSelectionEnd(); + } + + // kept for compatibility only + void GetSelection(int *from, int *to) + { + long f, t; + GetSelection(&f, &t); + if ( from ) + *from = f; + if ( to ) + *to = t; + } +#endif + + 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 -private: +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); @@ -252,6 +463,7 @@ private: void NotifyChange(); void NotifyParent(SCNotification* scn); +private: DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(wxStyledTextCtrl) @@ -264,9 +476,13 @@ protected: 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 }; //---------------------------------------------------------------------- @@ -369,33 +585,34 @@ private: #ifndef SWIG -BEGIN_DECLARE_EVENT_TYPES() - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_CHANGE, 1650) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_STYLENEEDED, 1651) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_CHARADDED, 1652) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_SAVEPOINTREACHED, 1653) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_SAVEPOINTLEFT, 1654) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_ROMODIFYATTEMPT, 1655) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_KEY, 1656) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_DOUBLECLICK, 1657) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_UPDATEUI, 1658) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_MODIFIED, 1659) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_MACRORECORD, 1660) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_MARGINCLICK, 1661) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_NEEDSHOWN, 1662) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_PAINTED, 1664) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_USERLISTSELECTION, 1665) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_URIDROPPED, 1666) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_DWELLSTART, 1667) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_DWELLEND, 1668) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_START_DRAG, 1669) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_DRAG_OVER, 1670) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_DO_DROP, 1671) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_ZOOM, 1672) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_CLICK, 1673) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_HOTSPOT_DCLICK, 1674) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_STC, wxEVT_STC_CALLTIP_CLICK, 1675) -END_DECLARE_EVENT_TYPES() +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_CHANGE; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_STYLENEEDED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_CHARADDED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_SAVEPOINTREACHED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_SAVEPOINTLEFT; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_ROMODIFYATTEMPT; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_KEY; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_DOUBLECLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_UPDATEUI; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_MODIFIED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_MACRORECORD; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_MARGINCLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_NEEDSHOWN; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_PAINTED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_USERLISTSELECTION; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_URIDROPPED; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_DWELLSTART; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_DWELLEND; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_START_DRAG; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_DRAG_OVER; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_DO_DROP; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_ZOOM; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_HOTSPOT_CLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_HOTSPOT_DCLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_CALLTIP_CLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_AUTOCOMP_SELECTION; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_INDICATOR_CLICK; +extern WXDLLIMPEXP_STC const wxEventType wxEVT_STC_INDICATOR_RELEASE; #else enum { wxEVT_STC_CHANGE, @@ -422,7 +639,10 @@ END_DECLARE_EVENT_TYPES() wxEVT_STC_ZOOM, wxEVT_STC_HOTSPOT_CLICK, wxEVT_STC_HOTSPOT_DCLICK, - wxEVT_STC_CALLTIP_CLICK + wxEVT_STC_CALLTIP_CLICK, + wxEVT_STC_AUTOCOMP_SELECTION, + wxEVT_STC_INDICATOR_CLICK, + wxEVT_STC_INDICATOR_RELEASE }; #endif @@ -455,46 +675,13 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_ZOOM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_ZOOM, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), #define EVT_STC_HOTSPOT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_HOTSPOT_CLICK, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), #define EVT_STC_HOTSPOT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_HOTSPOT_DCLICK, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), -#define EVT_STC_CALLTIP_CLICK(id, fn)) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CALLTIP_CLICK id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), - -#endif - -//---------------------------------------------------------------------- -// Utility functions used within wxSTC - -#ifndef SWIG - -inline wxString stc2wx(const char* str) { -#if wxUSE_UNICODE - return wxString(str, wxConvUTF8); -#else - return wxString(str); -#endif -} +#define EVT_STC_CALLTIP_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CALLTIP_CLICK id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), +#define EVT_STC_AUTOCOMP_SELECTION(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_SELECTION id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), +#define EVT_STC_INDICATOR_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_INDICATOR_CLICK id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), +#define EVT_STC_INDICATOR_RELEASE(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_INDICATOR_RELEASE id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxStyledTextEventFunction, & fn ), (wxObject *) NULL ), -#if wxUSE_UNICODE -wxString stc2wx(const char* str, size_t len); -#else -inline wxString stc2wx(const char* str, size_t len) { - return wxString(str, len); -} -#endif - - -#if wxUSE_UNICODE -inline const wxWX2MBbuf wx2stc(const wxString& str) { - return str.mb_str(wxConvUTF8); -} -#else -inline const wxWX2MBbuf wx2stc(const wxString& str) { - return str.mbc_str(); -} -#endif - -#endif - - -//---------------------------------------------------------------------- #endif +#endif // wxUSE_STC +#endif // _WX_STC_STC_H_