]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/textctrl.h
allow dynamically changing most of text control styles in wxGTK
[wxWidgets.git] / include / wx / gtk / textctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/textctrl.h
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef __GTKTEXTCTRLH__
12 #define __GTKTEXTCTRLH__
13
14 //-----------------------------------------------------------------------------
15 // wxTextCtrl
16 //-----------------------------------------------------------------------------
17
18 class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
19 {
20 public:
21 wxTextCtrl() { Init(); }
22 wxTextCtrl(wxWindow *parent,
23 wxWindowID id,
24 const wxString &value = wxEmptyString,
25 const wxPoint &pos = wxDefaultPosition,
26 const wxSize &size = wxDefaultSize,
27 long style = 0,
28 const wxValidator& validator = wxDefaultValidator,
29 const wxString &name = wxTextCtrlNameStr);
30
31 virtual ~wxTextCtrl();
32
33 bool Create(wxWindow *parent,
34 wxWindowID id,
35 const wxString &value = wxEmptyString,
36 const wxPoint &pos = wxDefaultPosition,
37 const wxSize &size = wxDefaultSize,
38 long style = 0,
39 const wxValidator& validator = wxDefaultValidator,
40 const wxString &name = wxTextCtrlNameStr);
41
42 // implement base class pure virtuals
43 // ----------------------------------
44
45 virtual wxString GetValue() const;
46 virtual bool IsEmpty() const;
47
48 virtual int GetLineLength(long lineNo) const;
49 virtual wxString GetLineText(long lineNo) const;
50 virtual int GetNumberOfLines() const;
51
52 virtual bool IsModified() const;
53 virtual bool IsEditable() const;
54
55 // If the return values from and to are the same, there is no selection.
56 virtual void GetSelection(long* from, long* to) const;
57
58 // operations
59 // ----------
60
61 // editing
62 virtual void Clear();
63 virtual void Replace(long from, long to, const wxString& value);
64 virtual void Remove(long from, long to);
65
66 // sets/clears the dirty flag
67 virtual void MarkDirty();
68 virtual void DiscardEdits();
69
70 virtual void SetMaxLength(unsigned long len);
71
72 // writing text inserts it at the current position, appending always
73 // inserts it at the end
74 virtual void WriteText(const wxString& text);
75 virtual void AppendText(const wxString& text);
76
77 // apply text attribute to the range of text (only works with richedit
78 // controls)
79 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
80
81 // translate between the position (which is just an index in the text ctrl
82 // considering all its contents as a single strings) and (x, y) coordinates
83 // which represent column and line.
84 virtual long XYToPosition(long x, long y) const;
85 virtual bool PositionToXY(long pos, long *x, long *y) const;
86
87 virtual void ShowPosition(long pos);
88
89 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
90 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
91 wxTextCoord *col,
92 wxTextCoord *row) const
93 {
94 return wxTextCtrlBase::HitTest(pt, col, row);
95 }
96
97 // Clipboard operations
98 virtual void Copy();
99 virtual void Cut();
100 virtual void Paste();
101
102 // Undo/redo
103 virtual void Undo();
104 virtual void Redo();
105
106 virtual bool CanUndo() const;
107 virtual bool CanRedo() const;
108
109 // Insertion point
110 virtual void SetInsertionPoint(long pos);
111 virtual void SetInsertionPointEnd();
112 virtual long GetInsertionPoint() const;
113 virtual wxTextPos GetLastPosition() const;
114
115 virtual void SetSelection(long from, long to);
116 virtual void SetEditable(bool editable);
117
118 // Overridden wxWindow methods
119 virtual void SetWindowStyleFlag( long style );
120 virtual bool Enable( bool enable = true );
121
122 // Implementation from now on
123 void OnDropFiles( wxDropFilesEvent &event );
124 void OnChar( wxKeyEvent &event );
125
126 void OnCut(wxCommandEvent& event);
127 void OnCopy(wxCommandEvent& event);
128 void OnPaste(wxCommandEvent& event);
129 void OnUndo(wxCommandEvent& event);
130 void OnRedo(wxCommandEvent& event);
131
132 void OnUpdateCut(wxUpdateUIEvent& event);
133 void OnUpdateCopy(wxUpdateUIEvent& event);
134 void OnUpdatePaste(wxUpdateUIEvent& event);
135 void OnUpdateUndo(wxUpdateUIEvent& event);
136 void OnUpdateRedo(wxUpdateUIEvent& event);
137
138 bool SetFont(const wxFont& font);
139 bool SetForegroundColour(const wxColour& colour);
140 bool SetBackgroundColour(const wxColour& colour);
141
142 GtkWidget* GetConnectWidget();
143
144 void SetUpdateFont(bool WXUNUSED(update)) { }
145
146 // GTK+ textctrl is so dumb that you need to freeze/thaw it manually to
147 // avoid horrible flicker/scrolling back and forth
148 virtual void Freeze();
149 virtual void Thaw();
150
151 // implementation only from now on
152
153 // wxGTK-specific: called recursively by Enable,
154 // to give widgets an oppprtunity to correct their colours after they
155 // have been changed by Enable
156 virtual void OnParentEnable( bool enable ) ;
157
158 // tell the control to ignore next text changed signal
159 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
160
161 // should we ignore the changed signal? always resets the flag
162 bool IgnoreTextUpdate();
163
164 // call this to indicate that the control is about to be changed
165 // programmatically and so m_modified flag shouldn't be set
166 void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
167
168 // should we mark the control as dirty? always resets the flag
169 bool MarkDirtyOnChange();
170
171 // always let GTK have mouse release events for multiline controls
172 virtual bool GTKProcessEvent(wxEvent& event) const;
173
174
175 static wxVisualAttributes
176 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
177
178 // has the control been frozen by Freeze()?
179 bool IsFrozen() const { return m_frozenness > 0; }
180
181 protected:
182 virtual wxSize DoGetBestSize() const;
183 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
184 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
185
186 // common part of all ctors
187 void Init();
188
189 // Widgets that use the style->base colour for the BG colour should
190 // override this and return true.
191 virtual bool UseGTKStyleBase() const { return true; }
192
193 virtual void DoSetValue(const wxString &value, int flags = 0);
194
195 // wrappers hiding the differences between functions doing the same thing
196 // for GtkTextView and GtkEntry (all of them use current window style to
197 // set the given characteristic)
198 void GTKSetEditable();
199 void GTKSetVisibility();
200 void GTKSetWrapMode();
201 void GTKSetJustification();
202
203 private:
204 // change the font for everything in this control
205 void ChangeFontGlobally();
206
207 // get the encoding which is used in this control: this looks at our font
208 // and default style but not the current style (i.e. the style for the
209 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
210 // encoding
211 wxFontEncoding GetTextEncoding() const;
212
213
214 GtkWidget *m_text;
215
216 bool m_modified:1;
217 bool m_dontMarkDirty:1;
218
219 int m_countUpdatesToIgnore;
220
221 // Our text buffer. Convenient, and holds the buffer while using
222 // a dummy one when m_frozenness > 0
223 GtkTextBuffer *m_buffer;
224
225 // number of calls to Freeze() minus number of calls to Thaw()
226 unsigned int m_frozenness;
227
228 // For wxTE_AUTO_URL
229 void OnUrlMouseEvent(wxMouseEvent&);
230 GdkCursor *m_gdkHandCursor;
231 GdkCursor *m_gdkXTermCursor;
232
233 DECLARE_EVENT_TABLE()
234 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
235 };
236
237 #endif // __GTKTEXTCTRLH__
238