]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/textctrl.h
Add IM and full wxEVT_CHAR support to wxTextCtrl and wxComboBox 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 _WX_GTK_TEXTCTRL_H_
12 #define _WX_GTK_TEXTCTRL_H_
13
14 typedef struct _GtkTextMark GtkTextMark;
15
16 //-----------------------------------------------------------------------------
17 // wxTextCtrl
18 //-----------------------------------------------------------------------------
19
20 class WXDLLIMPEXP_CORE wxTextCtrl: public wxTextCtrlBase
21 {
22 public:
23 wxTextCtrl() { Init(); }
24 wxTextCtrl(wxWindow *parent,
25 wxWindowID id,
26 const wxString &value = wxEmptyString,
27 const wxPoint &pos = wxDefaultPosition,
28 const wxSize &size = wxDefaultSize,
29 long style = 0,
30 const wxValidator& validator = wxDefaultValidator,
31 const wxString &name = wxTextCtrlNameStr);
32
33 virtual ~wxTextCtrl();
34
35 bool Create(wxWindow *parent,
36 wxWindowID id,
37 const wxString &value = wxEmptyString,
38 const wxPoint &pos = wxDefaultPosition,
39 const wxSize &size = wxDefaultSize,
40 long style = 0,
41 const wxValidator& validator = wxDefaultValidator,
42 const wxString &name = wxTextCtrlNameStr);
43
44 // implement base class pure virtuals
45 // ----------------------------------
46
47 virtual void WriteText(const wxString& text);
48 virtual wxString GetValue() const;
49 virtual bool IsEmpty() const;
50
51 virtual int GetLineLength(long lineNo) const;
52 virtual wxString GetLineText(long lineNo) const;
53 virtual int GetNumberOfLines() const;
54
55 virtual bool IsModified() const;
56 virtual bool IsEditable() const;
57
58 virtual void GetSelection(long* from, long* to) const;
59
60 virtual void Remove(long from, long to);
61
62 virtual void MarkDirty();
63 virtual void DiscardEdits();
64
65 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
66 virtual bool GetStyle(long position, wxTextAttr& style);
67
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
74 virtual void ShowPosition(long pos);
75
76 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
77 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
78 wxTextCoord *col,
79 wxTextCoord *row) const
80 {
81 return wxTextCtrlBase::HitTest(pt, col, row);
82 }
83
84 // Clipboard operations
85 virtual void Copy();
86 virtual void Cut();
87 virtual void Paste();
88
89 // Insertion point
90 virtual void SetInsertionPoint(long pos);
91 virtual long GetInsertionPoint() const;
92 virtual wxTextPos GetLastPosition() const;
93
94 virtual void SetSelection(long from, long to);
95 virtual void SetEditable(bool editable);
96
97 // Overridden wxWindow methods
98 virtual void SetWindowStyleFlag( long style );
99 virtual bool Enable( bool enable = true );
100
101 // Implementation from now on
102 void OnDropFiles( wxDropFilesEvent &event );
103 void OnChar( wxKeyEvent &event );
104
105 void OnCut(wxCommandEvent& event);
106 void OnCopy(wxCommandEvent& event);
107 void OnPaste(wxCommandEvent& event);
108 void OnUndo(wxCommandEvent& event);
109 void OnRedo(wxCommandEvent& event);
110
111 void OnUpdateCut(wxUpdateUIEvent& event);
112 void OnUpdateCopy(wxUpdateUIEvent& event);
113 void OnUpdatePaste(wxUpdateUIEvent& event);
114 void OnUpdateUndo(wxUpdateUIEvent& event);
115 void OnUpdateRedo(wxUpdateUIEvent& event);
116
117 bool SetFont(const wxFont& font);
118 bool SetForegroundColour(const wxColour& colour);
119 bool SetBackgroundColour(const wxColour& colour);
120
121 GtkWidget* GetConnectWidget();
122
123 void SetUpdateFont(bool WXUNUSED(update)) { }
124
125 // implementation only from now on
126
127 // tell the control to ignore next text changed signal
128 void IgnoreNextTextUpdate(int n = 1) { m_countUpdatesToIgnore = n; }
129
130 // should we ignore the changed signal? always resets the flag
131 bool IgnoreTextUpdate();
132
133 // call this to indicate that the control is about to be changed
134 // programmatically and so m_modified flag shouldn't be set
135 void DontMarkDirtyOnNextChange() { m_dontMarkDirty = true; }
136
137 // should we mark the control as dirty? always resets the flag
138 bool MarkDirtyOnChange();
139
140 // always let GTK have mouse release events for multiline controls
141 virtual bool GTKProcessEvent(wxEvent& event) const;
142
143
144 static wxVisualAttributes
145 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
146
147 protected:
148 // wxGTK-specific: called recursively by Enable,
149 // to give widgets an oppprtunity to correct their colours after they
150 // have been changed by Enable
151 virtual void OnEnabled(bool enable);
152
153 // overridden wxWindow virtual methods
154 virtual wxSize DoGetBestSize() const;
155 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
156 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
157
158 virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
159
160 virtual void DoFreeze();
161 virtual void DoThaw();
162
163 // Widgets that use the style->base colour for the BG colour should
164 // override this and return true.
165 virtual bool UseGTKStyleBase() const { return true; }
166
167 virtual void DoSetValue(const wxString &value, int flags = 0);
168
169 // Override this to use either GtkEntry or GtkTextView IME depending on the
170 // kind of control we are.
171 virtual int GTKIMFilterKeypress(GdkEventKey* event) const;
172
173 virtual wxPoint DoPositionToCoords(long pos) const;
174
175 // wrappers hiding the differences between functions doing the same thing
176 // for GtkTextView and GtkEntry (all of them use current window style to
177 // set the given characteristic)
178 void GTKSetEditable();
179 void GTKSetVisibility();
180 void GTKSetActivatesDefault();
181 void GTKSetWrapMode();
182 void GTKSetJustification();
183
184 private:
185 void Init();
186
187 // overridden wxTextEntry virtual methods
188 virtual GtkEditable *GetEditable() const;
189 virtual GtkEntry *GetEntry() const;
190 virtual void EnableTextChangedEvents(bool enable);
191
192 // change the font for everything in this control
193 void ChangeFontGlobally();
194
195 // get the encoding which is used in this control: this looks at our font
196 // and default style but not the current style (i.e. the style for the
197 // current position); returns wxFONTENCODING_SYSTEM if we have no specific
198 // encoding
199 wxFontEncoding GetTextEncoding() const;
200
201 // returns either m_text or m_buffer depending on whether the control is
202 // single- or multi-line; convenient for the GTK+ functions which work with
203 // both
204 void *GetTextObject() const
205 {
206 return IsMultiLine() ? static_cast<void *>(m_buffer)
207 : static_cast<void *>(m_text);
208 }
209
210
211 // the widget used for single line controls
212 GtkWidget *m_text;
213
214 bool m_modified:1;
215 bool m_dontMarkDirty:1;
216
217 int m_countUpdatesToIgnore;
218
219 // Our text buffer. Convenient, and holds the buffer while using
220 // a dummy one when frozen
221 GtkTextBuffer *m_buffer;
222
223 GtkTextMark* m_showPositionOnThaw;
224 GSList* m_anonymousMarkList;
225
226 // For wxTE_AUTO_URL
227 void OnUrlMouseEvent(wxMouseEvent&);
228
229 DECLARE_EVENT_TABLE()
230 DECLARE_DYNAMIC_CLASS(wxTextCtrl)
231 };
232
233 #endif // _WX_GTK_TEXTCTRL_H_