2002-04-01 06:41:59 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2002-06-04 14:09:20 -04:00
|
|
|
// Name: wx/x11/textctrl.h
|
2002-04-01 06:41:59 -05:00
|
|
|
// Purpose:
|
|
|
|
// Author: Robert Roebling
|
|
|
|
// Created: 01/02/97
|
|
|
|
// Id: $Id$
|
|
|
|
// Copyright: (c) 1998 Robert Roebling
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2002-04-01 06:41:59 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __X11TEXTCTRLH__
|
|
|
|
#define __X11TEXTCTRLH__
|
|
|
|
|
2003-08-08 15:39:16 -04:00
|
|
|
// Set to 1 to use wxUniv's implementation, 0
|
|
|
|
// to use wxX11's.
|
|
|
|
#define wxUSE_UNIV_TEXTCTRL 1
|
|
|
|
|
|
|
|
#if wxUSE_UNIV_TEXTCTRL
|
|
|
|
#include "wx/univ/textctrl.h"
|
|
|
|
#else
|
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
#include "wx/scrolwin.h"
|
2003-09-11 17:01:31 -04:00
|
|
|
#include "wx/arrstr.h"
|
2002-04-01 06:41:59 -05:00
|
|
|
#include "wx/datetime.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxTextCtrl;
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// helpers
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum wxSourceUndo
|
|
|
|
{
|
|
|
|
wxSOURCE_UNDO_LINE,
|
|
|
|
wxSOURCE_UNDO_ENTER,
|
|
|
|
wxSOURCE_UNDO_BACK,
|
|
|
|
wxSOURCE_UNDO_INSERT_LINE,
|
|
|
|
wxSOURCE_UNDO_DELETE,
|
|
|
|
wxSOURCE_UNDO_PASTE
|
|
|
|
};
|
|
|
|
|
|
|
|
class wxSourceUndoStep: public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxSourceUndoStep( wxSourceUndo type, int y1, int y2, wxTextCtrl *owner );
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
void Undo();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxSourceUndo m_type;
|
|
|
|
int m_y1;
|
|
|
|
int m_y2;
|
|
|
|
int m_cursorX;
|
|
|
|
int m_cursorY;
|
|
|
|
wxTextCtrl *m_owner;
|
|
|
|
wxString m_text;
|
|
|
|
wxArrayString m_lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
class wxSourceLine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxSourceLine( const wxString &text = wxEmptyString )
|
|
|
|
{
|
|
|
|
m_text = text;
|
|
|
|
}
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxString m_text;
|
|
|
|
};
|
|
|
|
|
|
|
|
WX_DECLARE_OBJARRAY(wxSourceLine, wxSourceLineArray);
|
|
|
|
|
|
|
|
enum wxSourceLanguage
|
|
|
|
{
|
|
|
|
wxSOURCE_LANG_NONE,
|
|
|
|
wxSOURCE_LANG_CPP,
|
|
|
|
wxSOURCE_LANG_PERL,
|
|
|
|
wxSOURCE_LANG_PYTHON
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxTextCtrl
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-02 14:16:51 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase, public wxScrollHelper
|
2002-04-01 06:41:59 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTextCtrl() { Init(); }
|
|
|
|
wxTextCtrl(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString &value = wxEmptyString,
|
|
|
|
const wxPoint &pos = wxDefaultPosition,
|
|
|
|
const wxSize &size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString &name = wxTextCtrlNameStr);
|
2003-09-11 17:01:31 -04:00
|
|
|
virtual ~wxTextCtrl();
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString &value = wxEmptyString,
|
|
|
|
const wxPoint &pos = wxDefaultPosition,
|
|
|
|
const wxSize &size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString &name = wxTextCtrlNameStr);
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
// required for scrolling with wxScrollHelper
|
|
|
|
// ------------------------------------------
|
|
|
|
|
|
|
|
virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
// implement base class pure virtuals
|
|
|
|
// ----------------------------------
|
|
|
|
|
2006-10-08 13:46:12 -04:00
|
|
|
virtual void ChangeValue(const wxString &value);
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
virtual int GetLineLength(long lineNo) const;
|
|
|
|
virtual wxString GetLineText(long lineNo) const;
|
|
|
|
virtual int GetNumberOfLines() const;
|
|
|
|
|
|
|
|
virtual bool IsModified() const;
|
|
|
|
virtual bool IsEditable() const;
|
|
|
|
|
|
|
|
// more readable flag testing methods
|
|
|
|
// ----------------------------------
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
|
2004-11-08 15:03:12 -05:00
|
|
|
bool WrapLines() const { return false; }
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
// If the return values from and to are the same, there is no selection.
|
|
|
|
virtual void GetSelection(long* from, long* to) const;
|
|
|
|
|
|
|
|
// operations
|
|
|
|
// ----------
|
|
|
|
|
|
|
|
// editing
|
|
|
|
virtual void Clear();
|
|
|
|
virtual void Replace(long from, long to, const wxString& value);
|
|
|
|
virtual void Remove(long from, long to);
|
|
|
|
|
|
|
|
// clears the dirty flag
|
|
|
|
virtual void DiscardEdits();
|
|
|
|
|
|
|
|
virtual void SetMaxLength(unsigned long len);
|
|
|
|
|
|
|
|
// writing text inserts it at the current position, appending always
|
|
|
|
// inserts it at the end
|
|
|
|
virtual void WriteText(const wxString& text);
|
|
|
|
virtual void AppendText(const wxString& text);
|
|
|
|
|
|
|
|
// apply text attribute to the range of text (only works with richedit
|
|
|
|
// controls)
|
|
|
|
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
|
|
|
|
|
|
|
|
// translate between the position (which is just an index in the text ctrl
|
|
|
|
// considering all its contents as a single strings) and (x, y) coordinates
|
|
|
|
// which represent column and line.
|
|
|
|
virtual long XYToPosition(long x, long y) const;
|
|
|
|
virtual bool PositionToXY(long pos, long *x, long *y) const;
|
|
|
|
|
|
|
|
virtual void ShowPosition(long pos);
|
|
|
|
|
|
|
|
// Clipboard operations
|
|
|
|
virtual void Copy();
|
|
|
|
virtual void Cut();
|
|
|
|
virtual void Paste();
|
|
|
|
|
|
|
|
// Undo/redo
|
|
|
|
virtual void Undo();
|
|
|
|
virtual void Redo() {}
|
|
|
|
|
|
|
|
virtual bool CanUndo() const { return (m_undos.GetCount() > 0); }
|
2005-01-19 11:25:34 -05:00
|
|
|
virtual bool CanRedo() const { return false; }
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
// Insertion point
|
|
|
|
virtual void SetInsertionPoint(long pos);
|
|
|
|
virtual void SetInsertionPointEnd();
|
|
|
|
virtual long GetInsertionPoint() const;
|
2005-01-19 11:25:34 -05:00
|
|
|
virtual wxTextPos GetLastPosition() const;
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
virtual void SetSelection(long from, long to);
|
|
|
|
virtual void SetEditable(bool editable);
|
|
|
|
|
2005-01-19 11:25:34 -05:00
|
|
|
virtual bool Enable( bool enable = true );
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
void OnCut(wxCommandEvent& event);
|
|
|
|
void OnCopy(wxCommandEvent& event);
|
|
|
|
void OnPaste(wxCommandEvent& event);
|
|
|
|
void OnUndo(wxCommandEvent& event);
|
|
|
|
void OnRedo(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnUpdateCut(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateCopy(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdatePaste(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateUndo(wxUpdateUIEvent& event);
|
|
|
|
void OnUpdateRedo(wxUpdateUIEvent& event);
|
|
|
|
|
|
|
|
bool SetFont(const wxFont& font);
|
|
|
|
bool SetForegroundColour(const wxColour& colour);
|
|
|
|
bool SetBackgroundColour(const wxColour& colour);
|
|
|
|
|
2005-01-19 11:25:34 -05:00
|
|
|
void SetModified() { m_modified = true; }
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
virtual void Freeze();
|
|
|
|
virtual void Thaw();
|
|
|
|
|
|
|
|
// textctrl specific scrolling
|
|
|
|
virtual bool ScrollLines(int lines);
|
|
|
|
virtual bool ScrollPages(int pages);
|
|
|
|
|
|
|
|
// not part of the wxTextCtrl API from now on..
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-07 06:18:46 -04:00
|
|
|
void SetLanguage( wxSourceLanguage lang = wxSOURCE_LANG_NONE );
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
void Delete();
|
|
|
|
void DeleteLine();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
void Indent();
|
|
|
|
void Unindent();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
bool HasSelection();
|
|
|
|
void ClearSelection();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int GetCursorX() { return m_cursorX; }
|
|
|
|
int GetCursorY() { return m_cursorY; }
|
|
|
|
bool IsModified() { return m_modified; }
|
|
|
|
bool OverwriteMode() { return m_overwrite; }
|
|
|
|
|
|
|
|
// implementation from now on...
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-06 13:11:36 -05:00
|
|
|
int PosToPixel( int line, int pos );
|
|
|
|
int PixelToPos( int line, int pixel );
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
void SearchForBrackets();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
void DoChar( char c );
|
|
|
|
void DoBack();
|
|
|
|
void DoDelete();
|
|
|
|
void DoReturn();
|
|
|
|
void DoDClick();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-07 06:18:46 -04:00
|
|
|
wxString GetNextToken( wxString &line, size_t &pos );
|
|
|
|
|
|
|
|
void DrawLinePart( wxDC &dc, int x, int y, const wxString &toDraw, const wxString &origin, const wxColour &colour);
|
2002-04-01 06:41:59 -05:00
|
|
|
void DrawLine( wxDC &dc, int x, int y, const wxString &line, int lineNum );
|
|
|
|
void OnPaint( wxPaintEvent &event );
|
2002-04-07 06:18:46 -04:00
|
|
|
void OnEraseBackground( wxEraseEvent &event );
|
2002-04-01 06:41:59 -05:00
|
|
|
void OnMouse( wxMouseEvent &event );
|
|
|
|
void OnChar( wxKeyEvent &event );
|
2002-04-07 18:47:20 -04:00
|
|
|
void OnSetFocus( wxFocusEvent& event );
|
|
|
|
void OnKillFocus( wxFocusEvent& event );
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2003-07-09 06:15:21 -04:00
|
|
|
void OnInternalIdle();
|
2002-04-01 06:41:59 -05:00
|
|
|
void RefreshLine( int n );
|
|
|
|
void RefreshDown( int n );
|
2005-01-19 11:25:34 -05:00
|
|
|
void MoveCursor( int new_x, int new_y, bool shift = false, bool centre = false );
|
2002-04-01 06:41:59 -05:00
|
|
|
void MyAdjustScrollbars();
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
protected:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
virtual wxSize DoGetBestSize() const;
|
|
|
|
|
2006-10-08 18:40:14 -04:00
|
|
|
virtual void DoSetValue(const wxString& value, int flags = 0);
|
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
friend class wxSourceUndoStep;
|
|
|
|
|
|
|
|
wxSourceLineArray m_lines;
|
|
|
|
|
|
|
|
wxFont m_sourceFont;
|
|
|
|
wxColour m_sourceColour;
|
|
|
|
wxColour m_commentColour;
|
|
|
|
wxColour m_stringColour;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int m_cursorX;
|
|
|
|
int m_cursorY;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int m_selStartX,m_selStartY;
|
|
|
|
int m_selEndX,m_selEndY;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int m_lineHeight;
|
|
|
|
int m_charWidth;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int m_longestLine;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
bool m_overwrite;
|
|
|
|
bool m_modified;
|
|
|
|
bool m_editable;
|
|
|
|
bool m_ignoreInput;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxArrayString m_keywords;
|
|
|
|
wxColour m_keywordColour;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxArrayString m_defines;
|
|
|
|
wxColour m_defineColour;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxArrayString m_variables;
|
|
|
|
wxColour m_variableColour;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxSourceLanguage m_lang;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
wxList m_undos;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
bool m_capturing;
|
2002-06-04 14:09:20 -04:00
|
|
|
|
2002-04-01 06:41:59 -05:00
|
|
|
int m_bracketX;
|
|
|
|
int m_bracketY;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxTextCtrl);
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// this is superfluous here but helps to compile
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// cursor movement and also selection and delete operations
|
|
|
|
#define wxACTION_TEXT_GOTO _T("goto") // to pos in numArg
|
|
|
|
#define wxACTION_TEXT_FIRST _T("first") // go to pos 0
|
|
|
|
#define wxACTION_TEXT_LAST _T("last") // go to last pos
|
|
|
|
#define wxACTION_TEXT_HOME _T("home")
|
|
|
|
#define wxACTION_TEXT_END _T("end")
|
|
|
|
#define wxACTION_TEXT_LEFT _T("left")
|
|
|
|
#define wxACTION_TEXT_RIGHT _T("right")
|
|
|
|
#define wxACTION_TEXT_UP _T("up")
|
|
|
|
#define wxACTION_TEXT_DOWN _T("down")
|
|
|
|
#define wxACTION_TEXT_WORD_LEFT _T("wordleft")
|
|
|
|
#define wxACTION_TEXT_WORD_RIGHT _T("wordright")
|
|
|
|
#define wxACTION_TEXT_PAGE_UP _T("pageup")
|
|
|
|
#define wxACTION_TEXT_PAGE_DOWN _T("pagedown")
|
|
|
|
|
|
|
|
// clipboard operations
|
|
|
|
#define wxACTION_TEXT_COPY _T("copy")
|
|
|
|
#define wxACTION_TEXT_CUT _T("cut")
|
|
|
|
#define wxACTION_TEXT_PASTE _T("paste")
|
|
|
|
|
|
|
|
// insert text at the cursor position: the text is in strArg of PerformAction
|
|
|
|
#define wxACTION_TEXT_INSERT _T("insert")
|
|
|
|
|
|
|
|
// if the action starts with either of these prefixes and the rest of the
|
|
|
|
// string is one of the movement commands, it means to select/delete text from
|
|
|
|
// the current cursor position to the new one
|
|
|
|
#define wxACTION_TEXT_PREFIX_SEL _T("sel")
|
|
|
|
#define wxACTION_TEXT_PREFIX_DEL _T("del")
|
|
|
|
|
|
|
|
// mouse selection
|
|
|
|
#define wxACTION_TEXT_ANCHOR_SEL _T("anchorsel")
|
|
|
|
#define wxACTION_TEXT_EXTEND_SEL _T("extendsel")
|
|
|
|
#define wxACTION_TEXT_SEL_WORD _T("wordsel")
|
|
|
|
#define wxACTION_TEXT_SEL_LINE _T("linesel")
|
|
|
|
|
|
|
|
// undo or redo
|
|
|
|
#define wxACTION_TEXT_UNDO _T("undo")
|
|
|
|
#define wxACTION_TEXT_REDO _T("redo")
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTextCtrl types
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxStdTextCtrlInputHandler : public wxStdInputHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxStdTextCtrlInputHandler(wxInputHandler *inphand) : wxStdInputHandler(inphand) {}
|
|
|
|
|
|
|
|
virtual bool HandleKey(wxInputConsumer *consumer,
|
|
|
|
const wxKeyEvent& event,
|
2005-01-19 11:25:34 -05:00
|
|
|
bool pressed) { return false; }
|
|
|
|
virtual bool HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
|
|
|
|
virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event) { return false; }
|
|
|
|
virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event) { return false; }
|
2002-04-01 06:41:59 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// get the position of the mouse click
|
|
|
|
static wxTextPos HitTest(const wxTextCtrl *text, const wxPoint& pos) { return 0; }
|
|
|
|
|
|
|
|
// capture data
|
|
|
|
wxTextCtrl *m_winCapture;
|
|
|
|
};
|
|
|
|
|
2003-08-08 15:39:16 -04:00
|
|
|
#endif
|
|
|
|
// wxUSE_UNIV_TEXTCTRL
|
|
|
|
|
|
|
|
#endif // __X11TEXTCTRLH__
|
2002-04-01 06:41:59 -05:00
|
|
|
|