textctrl.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/textctrl.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Created: 01/02/97
  6. // Copyright: (c) 1998 Robert Roebling
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GTK_TEXTCTRL_H_
  10. #define _WX_GTK_TEXTCTRL_H_
  11. typedef struct _GtkTextMark GtkTextMark;
  12. //-----------------------------------------------------------------------------
  13. // wxTextCtrl
  14. //-----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
  16. {
  17. public:
  18. wxTextCtrl() { Init(); }
  19. wxTextCtrl(wxWindow *parent,
  20. wxWindowID id,
  21. const wxString &value = wxEmptyString,
  22. const wxPoint &pos = wxDefaultPosition,
  23. const wxSize &size = wxDefaultSize,
  24. long style = 0,
  25. const wxValidator& validator = wxDefaultValidator,
  26. const wxString &name = wxTextCtrlNameStr);
  27. virtual ~wxTextCtrl();
  28. bool Create(wxWindow *parent,
  29. wxWindowID id,
  30. const wxString &value = wxEmptyString,
  31. const wxPoint &pos = wxDefaultPosition,
  32. const wxSize &size = wxDefaultSize,
  33. long style = 0,
  34. const wxValidator& validator = wxDefaultValidator,
  35. const wxString &name = wxTextCtrlNameStr);
  36. // implement base class pure virtuals
  37. // ----------------------------------
  38. virtual void WriteText(const wxString& text);
  39. virtual wxString GetValue() const;
  40. virtual bool IsEmpty() const;
  41. virtual int GetLineLength(long lineNo) const;
  42. virtual wxString GetLineText(long lineNo) const;
  43. virtual int GetNumberOfLines() const;
  44. virtual bool IsModified() const;
  45. virtual bool IsEditable() const;
  46. virtual void GetSelection(long* from, long* to) const;
  47. virtual void Remove(long from, long to);
  48. virtual void MarkDirty();
  49. virtual void DiscardEdits();
  50. virtual bool SetStyle(long start, long end, const wxTextAttr& style);
  51. virtual bool GetStyle(long position, wxTextAttr& style);
  52. // translate between the position (which is just an index in the text ctrl
  53. // considering all its contents as a single strings) and (x, y) coordinates
  54. // which represent column and line.
  55. virtual long XYToPosition(long x, long y) const;
  56. virtual bool PositionToXY(long pos, long *x, long *y) const;
  57. virtual void ShowPosition(long pos);
  58. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
  59. virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
  60. wxTextCoord *col,
  61. wxTextCoord *row) const
  62. {
  63. return wxTextCtrlBase::HitTest(pt, col, row);
  64. }
  65. // Clipboard operations
  66. virtual void Copy();
  67. virtual void Cut();
  68. virtual void Paste();
  69. // Insertion point
  70. virtual void SetInsertionPoint(long pos);
  71. virtual long GetInsertionPoint() const;
  72. virtual wxTextPos GetLastPosition() const;
  73. virtual void SetSelection(long from, long to);
  74. virtual void SetEditable(bool editable);
  75. // Overridden wxWindow methods
  76. virtual void SetWindowStyleFlag( long style );
  77. virtual bool Enable( bool enable = true );
  78. // Implementation from now on
  79. void OnDropFiles( wxDropFilesEvent &event );
  80. void OnChar( wxKeyEvent &event );
  81. void OnCut(wxCommandEvent& event);
  82. void OnCopy(wxCommandEvent& event);
  83. void OnPaste(wxCommandEvent& event);
  84. void OnUndo(wxCommandEvent& event);
  85. void OnRedo(wxCommandEvent& event);
  86. void OnUpdateCut(wxUpdateUIEvent& event);
  87. void OnUpdateCopy(wxUpdateUIEvent& event);
  88. void OnUpdatePaste(wxUpdateUIEvent& event);
  89. void OnUpdateUndo(wxUpdateUIEvent& event);
  90. void OnUpdateRedo(wxUpdateUIEvent& event);
  91. bool SetFont(const wxFont& font);
  92. bool SetForegroundColour(const wxColour& colour);
  93. bool SetBackgroundColour(const wxColour& colour);
  94. GtkWidget* GetConnectWidget();
  95. void SetUpdateFont(bool WXUNUSED(update)) { }
  96. // implementation only from now on
  97. // tell the control to ignore next text changed signal
  98. void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
  99. // should we ignore the changed signal? always resets the flag
  100. bool IgnoreTextUpdate();
  101. // call this to indicate that the control is about to be changed
  102. // programmatically and so m_modified flag shouldn't be set
  103. void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
  104. // should we mark the control as dirty? always resets the flag
  105. bool MarkDirtyOnChange();
  106. // always let GTK have mouse release events for multiline controls
  107. virtual bool GTKProcessEvent(wxEvent& event) const;
  108. static wxVisualAttributes
  109. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  110. protected:
  111. // overridden wxWindow virtual methods
  112. virtual wxSize DoGetBestSize() const;
  113. virtual void DoApplyWidgetStyle(GtkRcStyle *style);
  114. virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
  115. virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
  116. virtual void DoFreeze();
  117. virtual void DoThaw();
  118. // Widgets that use the style->base colour for the BG colour should
  119. // override this and return true.
  120. virtual bool UseGTKStyleBase() const { return true; }
  121. virtual void DoSetValue(const wxString &value, int flags = 0);
  122. // Override this to use either GtkEntry or GtkTextView IME depending on the
  123. // kind of control we are.
  124. virtual int GTKIMFilterKeypress(GdkEventKey* event) const;
  125. virtual wxPoint DoPositionToCoords(long pos) const;
  126. // wrappers hiding the differences between functions doing the same thing
  127. // for GtkTextView and GtkEntry (all of them use current window style to
  128. // set the given characteristic)
  129. void GTKSetEditable();
  130. void GTKSetVisibility();
  131. void GTKSetActivatesDefault();
  132. void GTKSetWrapMode();
  133. void GTKSetJustification();
  134. private:
  135. void Init();
  136. // overridden wxTextEntry virtual methods
  137. virtual GtkEditable *GetEditable() const;
  138. virtual GtkEntry *GetEntry() const;
  139. virtual void EnableTextChangedEvents(bool enable);
  140. // change the font for everything in this control
  141. void ChangeFontGlobally();
  142. // get the encoding which is used in this control: this looks at our font
  143. // and default style but not the current style (i.e. the style for the
  144. // current position); returns wxFONTENCODING_SYSTEM if we have no specific
  145. // encoding
  146. wxFontEncoding GetTextEncoding() const;
  147. // returns either m_text or m_buffer depending on whether the control is
  148. // single- or multi-line; convenient for the GTK+ functions which work with
  149. // both
  150. void *GetTextObject() const
  151. {
  152. return IsMultiLine() ? static_cast<void *>(m_buffer)
  153. : static_cast<void *>(m_text);
  154. }
  155. // the widget used for single line controls
  156. GtkWidget *m_text;
  157. bool m_modified:1;
  158. bool m_dontMarkDirty:1;
  159. int m_countUpdatesToIgnore;
  160. // Our text buffer. Convenient, and holds the buffer while using
  161. // a dummy one when frozen
  162. GtkTextBuffer *m_buffer;
  163. GtkTextMark* m_showPositionOnThaw;
  164. GSList* m_anonymousMarkList;
  165. // For wxTE_AUTO_URL
  166. void OnUrlMouseEvent(wxMouseEvent&);
  167. DECLARE_EVENT_TABLE()
  168. DECLARE_DYNAMIC_CLASS(wxTextCtrl)
  169. };
  170. #endif // _WX_GTK_TEXTCTRL_H_