textctrl.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/textctrl.h
  3. // Purpose: wxTextCtrl class
  4. // Author: Stefan Csomor
  5. // Modified by:
  6. // Created: 1998-01-01
  7. // Copyright: (c) Stefan Csomor
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_TEXTCTRL_H_
  11. #define _WX_TEXTCTRL_H_
  12. #if wxUSE_SYSTEM_OPTIONS
  13. // set this to 'true' if you want to use the 'classic' MLTE-based implementation
  14. // instead of the HIView-based implementation in 10.3 and upwards, the former
  15. // has more features (backgrounds etc.), but may show redraw artefacts and other
  16. // problems depending on your usage; hence, the default is 'false'.
  17. #define wxMAC_TEXTCONTROL_USE_MLTE wxT("mac.textcontrol-use-mlte")
  18. // set this to 'true' if you want editable text controls to have spell checking turned
  19. // on by default, you can change this setting individually on a control using MacCheckSpelling
  20. #define wxMAC_TEXTCONTROL_USE_SPELL_CHECKER wxT("mac.textcontrol-use-spell-checker")
  21. #endif
  22. #include "wx/control.h"
  23. #include "wx/textctrl.h"
  24. class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
  25. {
  26. DECLARE_DYNAMIC_CLASS(wxTextCtrl)
  27. public:
  28. wxTextCtrl()
  29. { Init(); }
  30. wxTextCtrl(wxWindow *parent,
  31. wxWindowID id,
  32. const wxString& value = wxEmptyString,
  33. const wxPoint& pos = wxDefaultPosition,
  34. const wxSize& size = wxDefaultSize,
  35. long style = 0,
  36. const wxValidator& validator = wxDefaultValidator,
  37. const wxString& name = wxTextCtrlNameStr)
  38. {
  39. Init();
  40. Create(parent, id, value, pos, size, style, validator, name);
  41. }
  42. virtual ~wxTextCtrl();
  43. bool Create(wxWindow *parent,
  44. wxWindowID id,
  45. const wxString& value = wxEmptyString,
  46. const wxPoint& pos = wxDefaultPosition,
  47. const wxSize& size = wxDefaultSize,
  48. long style = 0,
  49. const wxValidator& validator = wxDefaultValidator,
  50. const wxString& name = wxTextCtrlNameStr);
  51. // accessors
  52. // ---------
  53. virtual int GetLineLength(long lineNo) const;
  54. virtual wxString GetLineText(long lineNo) const;
  55. virtual int GetNumberOfLines() const;
  56. virtual bool IsModified() const;
  57. // operations
  58. // ----------
  59. // sets/clears the dirty flag
  60. virtual void MarkDirty();
  61. virtual void DiscardEdits();
  62. // text control under some platforms supports the text styles: these
  63. // methods apply the given text style to the given selection or to
  64. // set/get the style which will be used for all appended text
  65. virtual bool SetFont( const wxFont &font );
  66. virtual bool GetStyle(long position, wxTextAttr& style);
  67. virtual bool SetStyle(long start, long end, const wxTextAttr& style);
  68. virtual bool SetDefaultStyle(const wxTextAttr& style);
  69. // translate between the position (which is just an index into the textctrl
  70. // considering all its contents as a single strings) and (x, y) coordinates
  71. // which represent column and line.
  72. virtual long XYToPosition(long x, long y) const;
  73. virtual bool PositionToXY(long pos, long *x, long *y) const;
  74. virtual void ShowPosition(long pos);
  75. // overrides so that we can send text updated events
  76. virtual void Copy();
  77. virtual void Cut();
  78. virtual void Paste();
  79. // Implementation
  80. // --------------
  81. virtual void Command(wxCommandEvent& event);
  82. virtual bool AcceptsFocus() const;
  83. // callbacks
  84. void OnDropFiles(wxDropFilesEvent& event);
  85. void OnChar(wxKeyEvent& event); // Process 'enter' if required
  86. void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts
  87. void OnCut(wxCommandEvent& event);
  88. void OnCopy(wxCommandEvent& event);
  89. void OnPaste(wxCommandEvent& event);
  90. void OnUndo(wxCommandEvent& event);
  91. void OnRedo(wxCommandEvent& event);
  92. void OnDelete(wxCommandEvent& event);
  93. void OnSelectAll(wxCommandEvent& event);
  94. void OnUpdateCut(wxUpdateUIEvent& event);
  95. void OnUpdateCopy(wxUpdateUIEvent& event);
  96. void OnUpdatePaste(wxUpdateUIEvent& event);
  97. void OnUpdateUndo(wxUpdateUIEvent& event);
  98. void OnUpdateRedo(wxUpdateUIEvent& event);
  99. void OnUpdateDelete(wxUpdateUIEvent& event);
  100. void OnUpdateSelectAll(wxUpdateUIEvent& event);
  101. void OnContextMenu(wxContextMenuEvent& event);
  102. virtual bool MacSetupCursor( const wxPoint& pt );
  103. virtual void MacVisibilityChanged();
  104. virtual void MacSuperChangedPosition();
  105. virtual void MacCheckSpelling(bool check);
  106. protected:
  107. // common part of all ctors
  108. void Init();
  109. virtual wxSize DoGetBestSize() const;
  110. // flag is set to true when the user edits the controls contents
  111. bool m_dirty;
  112. virtual void EnableTextChangedEvents(bool WXUNUSED(enable))
  113. {
  114. // nothing to do here as the events are never generated when we change
  115. // the controls value programmatically anyhow
  116. }
  117. private :
  118. wxMenu *m_privateContextMenu;
  119. DECLARE_EVENT_TABLE()
  120. };
  121. #endif // _WX_TEXTCTRL_H_