textctrl.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk1/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 __GTKTEXTCTRLH__
  10. #define __GTKTEXTCTRLH__
  11. //-----------------------------------------------------------------------------
  12. // wxTextCtrl
  13. //-----------------------------------------------------------------------------
  14. class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
  15. {
  16. public:
  17. wxTextCtrl() { Init(); }
  18. wxTextCtrl(wxWindow *parent,
  19. wxWindowID id,
  20. const wxString &value = wxEmptyString,
  21. const wxPoint &pos = wxDefaultPosition,
  22. const wxSize &size = wxDefaultSize,
  23. long style = 0,
  24. const wxValidator& validator = wxDefaultValidator,
  25. const wxString &name = wxTextCtrlNameStr);
  26. virtual ~wxTextCtrl();
  27. bool Create(wxWindow *parent,
  28. wxWindowID id,
  29. const wxString &value = wxEmptyString,
  30. const wxPoint &pos = wxDefaultPosition,
  31. const wxSize &size = wxDefaultSize,
  32. long style = 0,
  33. const wxValidator& validator = wxDefaultValidator,
  34. const wxString &name = wxTextCtrlNameStr);
  35. // implement base class pure virtuals
  36. // ----------------------------------
  37. virtual int GetLineLength(long lineNo) const;
  38. virtual wxString GetLineText(long lineNo) const;
  39. virtual int GetNumberOfLines() const;
  40. virtual bool IsModified() const;
  41. virtual bool IsEditable() const;
  42. // If the return values from and to are the same, there is no selection.
  43. virtual void GetSelection(long* from, long* to) const;
  44. // operations
  45. // ----------
  46. // editing
  47. virtual void Clear();
  48. virtual void Replace(long from, long to, const wxString& value);
  49. virtual void Remove(long from, long to);
  50. // sets/clears the dirty flag
  51. virtual void MarkDirty();
  52. virtual void DiscardEdits();
  53. virtual void SetMaxLength(unsigned long len);
  54. // writing text inserts it at the current position, appending always
  55. // inserts it at the end
  56. virtual void WriteText(const wxString& text);
  57. virtual void AppendText(const wxString& text);
  58. // apply text attribute to the range of text (only works with richedit
  59. // controls)
  60. virtual bool SetStyle(long start, long end, const wxTextAttr& style);
  61. // translate between the position (which is just an index in the text ctrl
  62. // considering all its contents as a single strings) and (x, y) coordinates
  63. // which represent column and line.
  64. virtual long XYToPosition(long x, long y) const;
  65. virtual bool PositionToXY(long pos, long *x, long *y) const;
  66. virtual void ShowPosition(long pos);
  67. // Clipboard operations
  68. virtual void Copy();
  69. virtual void Cut();
  70. virtual void Paste();
  71. // Undo/redo
  72. virtual void Undo();
  73. virtual void Redo();
  74. virtual bool CanUndo() const;
  75. virtual bool CanRedo() const;
  76. // Insertion point
  77. virtual void SetInsertionPoint(long pos);
  78. virtual void SetInsertionPointEnd();
  79. virtual long GetInsertionPoint() const;
  80. virtual wxTextPos GetLastPosition() const;
  81. virtual void SetSelection(long from, long to);
  82. virtual void SetEditable(bool editable);
  83. virtual void DoEnable( bool enable );
  84. // Implementation from now on
  85. void OnDropFiles( wxDropFilesEvent &event );
  86. void OnChar( wxKeyEvent &event );
  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 OnUpdateCut(wxUpdateUIEvent& event);
  93. void OnUpdateCopy(wxUpdateUIEvent& event);
  94. void OnUpdatePaste(wxUpdateUIEvent& event);
  95. void OnUpdateUndo(wxUpdateUIEvent& event);
  96. void OnUpdateRedo(wxUpdateUIEvent& event);
  97. bool SetFont(const wxFont& font);
  98. bool SetForegroundColour(const wxColour& colour);
  99. bool SetBackgroundColour(const wxColour& colour);
  100. GtkWidget* GetConnectWidget();
  101. bool IsOwnGtkWindow( GdkWindow *window );
  102. void DoApplyWidgetStyle(GtkRcStyle *style);
  103. void CalculateScrollbar();
  104. void OnInternalIdle();
  105. void SetUpdateFont(bool update) { m_updateFont = update; }
  106. void UpdateFontIfNeeded();
  107. void SetModified() { m_modified = true; }
  108. // textctrl specific scrolling
  109. virtual bool ScrollLines(int lines);
  110. virtual bool ScrollPages(int pages);
  111. // implementation only from now on
  112. // tell the control to ignore next text changed signal
  113. void IgnoreNextTextUpdate();
  114. // should we ignore the changed signal? always resets the flag
  115. bool IgnoreTextUpdate();
  116. static wxVisualAttributes
  117. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  118. protected:
  119. virtual wxSize DoGetBestSize() const;
  120. // common part of all ctors
  121. void Init();
  122. // overridden wxWindow methods
  123. virtual void DoFreeze();
  124. virtual void DoThaw();
  125. // get the vertical adjustment, if any, NULL otherwise
  126. GtkAdjustment *GetVAdj() const;
  127. // scroll the control by the given number of pixels, return true if the
  128. // scroll position changed
  129. bool DoScroll(GtkAdjustment *adj, int diff);
  130. // Widgets that use the style->base colour for the BG colour should
  131. // override this and return true.
  132. virtual bool UseGTKStyleBase() const { return true; }
  133. virtual void DoSetValue(const wxString &value, int flags = 0);
  134. virtual wxString DoGetValue() const;
  135. private:
  136. // change the font for everything in this control
  137. void ChangeFontGlobally();
  138. GtkWidget *m_text;
  139. GtkWidget *m_vScrollbar;
  140. bool m_modified:1;
  141. bool m_vScrollbarVisible:1;
  142. bool m_updateFont:1;
  143. bool m_ignoreNextUpdate:1;
  144. DECLARE_EVENT_TABLE()
  145. DECLARE_DYNAMIC_CLASS(wxTextCtrl)
  146. };
  147. #endif // __GTKTEXTCTRLH__