textctrlce.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/wince/textctrlce.h
  3. // Purpose: wxTextCtrl implementation for smart phones driven by WinCE
  4. // Author: Wlodzimierz ABX Skiba
  5. // Modified by:
  6. // Created: 30.08.2004
  7. // Copyright: (c) Wlodzimierz Skiba
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_TEXTCTRLCE_H_
  11. #define _WX_TEXTCTRLCE_H_
  12. #include "wx/dynarray.h"
  13. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  14. WX_DEFINE_EXPORTED_ARRAY_PTR(wxTextCtrl *, wxArrayTextSpins);
  15. class WXDLLIMPEXP_CORE wxTextCtrl : public wxTextCtrlBase
  16. {
  17. public:
  18. // creation
  19. // --------
  20. wxTextCtrl() { Init(); }
  21. wxTextCtrl(wxWindow *parent, wxWindowID id,
  22. const wxString& value = wxEmptyString,
  23. const wxPoint& pos = wxDefaultPosition,
  24. const wxSize& size = wxDefaultSize,
  25. long style = 0,
  26. const wxValidator& validator = wxDefaultValidator,
  27. const wxString& name = wxTextCtrlNameStr)
  28. {
  29. Init();
  30. Create(parent, id, value, pos, size, style, validator, name);
  31. }
  32. virtual ~wxTextCtrl();
  33. bool Create(wxWindow *parent, wxWindowID id,
  34. const wxString& value = wxEmptyString,
  35. const wxPoint& pos = wxDefaultPosition,
  36. const wxSize& size = wxDefaultSize,
  37. long style = 0,
  38. const wxValidator& validator = wxDefaultValidator,
  39. const wxString& name = wxTextCtrlNameStr);
  40. // implement base class pure virtuals
  41. // ----------------------------------
  42. virtual wxString GetValue() const;
  43. virtual void SetValue(const wxString& value) { DoSetValue(value, SetValue_SendEvent); }
  44. virtual void ChangeValue(const wxString &value) { DoSetValue(value); }
  45. virtual wxString GetRange(long from, long to) const;
  46. virtual int GetLineLength(long lineNo) const;
  47. virtual wxString GetLineText(long lineNo) const;
  48. virtual int GetNumberOfLines() const;
  49. virtual bool IsModified() const;
  50. virtual bool IsEditable() const;
  51. virtual void GetSelection(long* from, long* to) const;
  52. // operations
  53. // ----------
  54. // editing
  55. virtual void Clear();
  56. virtual void Replace(long from, long to, const wxString& value);
  57. virtual void Remove(long from, long to);
  58. // load the controls contents from the file
  59. virtual bool LoadFile(const wxString& file);
  60. // clears the dirty flag
  61. virtual void MarkDirty();
  62. virtual void DiscardEdits();
  63. virtual void SetMaxLength(unsigned long len);
  64. // writing text inserts it at the current position, appending always
  65. // inserts it at the end
  66. virtual void WriteText(const wxString& text);
  67. virtual void AppendText(const wxString& text);
  68. // translate between the position (which is just an index in the text ctrl
  69. // considering all its contents as a single strings) and (x, y) coordinates
  70. // which represent column and line.
  71. virtual long XYToPosition(long x, long y) const;
  72. virtual bool PositionToXY(long pos, long *x, long *y) const;
  73. virtual void ShowPosition(long pos);
  74. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
  75. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
  76. wxTextCoord *col,
  77. wxTextCoord *row) const
  78. {
  79. return wxTextCtrlBase::HitTest(pt, col, row);
  80. }
  81. // Clipboard operations
  82. virtual void Copy();
  83. virtual void Cut();
  84. virtual void Paste();
  85. virtual bool CanCopy() const;
  86. virtual bool CanCut() const;
  87. virtual bool CanPaste() const;
  88. // Undo/redo
  89. virtual void Undo();
  90. virtual void Redo();
  91. virtual bool CanUndo() const;
  92. virtual bool CanRedo() const;
  93. // Insertion point
  94. virtual void SetInsertionPoint(long pos);
  95. virtual void SetInsertionPointEnd();
  96. virtual long GetInsertionPoint() const;
  97. virtual wxTextPos GetLastPosition() const;
  98. virtual void SetSelection(long from, long to);
  99. virtual void SetEditable(bool editable);
  100. // Caret handling (Windows only)
  101. bool ShowNativeCaret(bool show = true);
  102. bool HideNativeCaret() { return ShowNativeCaret(false); }
  103. // Implementation from now on
  104. // --------------------------
  105. virtual void Command(wxCommandEvent& event);
  106. virtual bool MSWCommand(WXUINT param, WXWORD id);
  107. virtual void AdoptAttributesFromHWND();
  108. virtual bool AcceptsFocus() const;
  109. // callbacks
  110. void OnDropFiles(wxDropFilesEvent& event);
  111. void OnChar(wxKeyEvent& event); // Process 'enter' if required
  112. void OnCut(wxCommandEvent& event);
  113. void OnCopy(wxCommandEvent& event);
  114. void OnPaste(wxCommandEvent& event);
  115. void OnUndo(wxCommandEvent& event);
  116. void OnRedo(wxCommandEvent& event);
  117. void OnDelete(wxCommandEvent& event);
  118. void OnSelectAll(wxCommandEvent& event);
  119. void OnUpdateCut(wxUpdateUIEvent& event);
  120. void OnUpdateCopy(wxUpdateUIEvent& event);
  121. void OnUpdatePaste(wxUpdateUIEvent& event);
  122. void OnUpdateUndo(wxUpdateUIEvent& event);
  123. void OnUpdateRedo(wxUpdateUIEvent& event);
  124. void OnUpdateDelete(wxUpdateUIEvent& event);
  125. void OnUpdateSelectAll(wxUpdateUIEvent& event);
  126. // Show a context menu for Rich Edit controls (the standard
  127. // EDIT control has one already)
  128. void OnRightClick(wxMouseEvent& event);
  129. // be sure the caret remains invisible if the user
  130. // called HideNativeCaret() before
  131. void OnSetFocus(wxFocusEvent& event);
  132. // get the subclassed window proc of the buddy
  133. WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; }
  134. // intercept WM_GETDLGCODE
  135. virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  136. protected:
  137. // common part of all ctors
  138. void Init();
  139. // call this to increase the size limit (will do nothing if the current
  140. // limit is big enough)
  141. //
  142. // returns true if we increased the limit to allow entering more text,
  143. // false if we hit the limit set by SetMaxLength() and so didn't change it
  144. bool AdjustSpaceLimit();
  145. void DoSetValue(const wxString &value, int flags = 0);
  146. // replace the contents of the selection or of the entire control with the
  147. // given text
  148. void DoWriteText(const wxString& text, int flags = SetValue_SelectionOnly);
  149. // set the selection possibly without scrolling the caret into view
  150. void DoSetSelection(long from, long to, bool scrollCaret = true);
  151. // return true if there is a non empty selection in the control
  152. bool HasSelection() const;
  153. // get the length of the line containing the character at the given
  154. // position
  155. long GetLengthOfLineContainingPos(long pos) const;
  156. // send TEXT_UPDATED event, return true if it was handled, false otherwise
  157. bool SendUpdateEvent();
  158. // override some base class virtuals
  159. virtual void DoMoveWindow(int x, int y, int width, int height);
  160. virtual wxSize DoGetBestSize() const;
  161. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  162. // if true, SendUpdateEvent() will eat the next event (see comments in the
  163. // code as to why this is needed)
  164. bool m_suppressNextUpdate;
  165. // all existing wxTextCtrl - this allows to find the one corresponding to
  166. // the given buddy window in GetSpinTextCtrl()
  167. static wxArrayTextSpins ms_allTextSpins;
  168. protected:
  169. // the data for the "buddy" list
  170. WXHWND m_hwndBuddy;
  171. WXFARPROC m_wndProcBuddy;
  172. private:
  173. DECLARE_EVENT_TABLE()
  174. DECLARE_DYNAMIC_CLASS_NO_COPY(wxTextCtrl)
  175. bool m_isNativeCaretShown;
  176. };
  177. #endif // _WX_TEXTCTRLCE_H_