]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: textctrl.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
f96aa4d9 | 5 | // Id: $Id$ |
a81258be | 6 | // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin |
13289f04 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "textctrl.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/textctrl.h" | |
15 | #include "wx/utils.h" | |
1a5a8367 | 16 | #include <wx/intl.h> |
c801d85f | 17 | |
a81258be RR |
18 | #include <sys/types.h> |
19 | #include <sys/stat.h> | |
20 | #include <ctype.h> | |
21 | ||
c801d85f | 22 | //----------------------------------------------------------------------------- |
2f2aa628 | 23 | // "changed" |
c801d85f KB |
24 | //----------------------------------------------------------------------------- |
25 | ||
6de97a3b | 26 | static void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) |
484e45bf | 27 | { |
9406d962 | 28 | win->SetModified(); |
903f689b RR |
29 | |
30 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->m_windowId ); | |
31 | wxString val( win->GetValue() ); | |
32 | if (!val.IsNull()) event.m_commandString = WXSTRINGCAST val; | |
33 | event.SetEventObject( win ); | |
34 | win->GetEventHandler()->ProcessEvent( event ); | |
6de97a3b | 35 | } |
112892b9 | 36 | |
2f2aa628 RR |
37 | //----------------------------------------------------------------------------- |
38 | // wxTextCtrl | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) | |
42 | ||
c801d85f | 43 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) |
903f689b | 44 | EVT_CHAR(wxTextCtrl::OnChar) |
c801d85f KB |
45 | END_EVENT_TABLE() |
46 | ||
03f38c58 | 47 | wxTextCtrl::wxTextCtrl() : streambuf() |
c801d85f | 48 | { |
6de97a3b | 49 | if (allocate()) setp(base(),ebuf()); |
13289f04 | 50 | |
112892b9 | 51 | m_modified = FALSE; |
6de97a3b | 52 | } |
c801d85f | 53 | |
debe6624 | 54 | wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value, |
484e45bf | 55 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 56 | int style, const wxValidator& validator, const wxString &name ) : streambuf() |
c801d85f | 57 | { |
6de97a3b | 58 | if (allocate()) setp(base(),ebuf()); |
13289f04 | 59 | |
112892b9 | 60 | m_modified = FALSE; |
6de97a3b RR |
61 | Create( parent, id, value, pos, size, style, validator, name ); |
62 | } | |
c801d85f | 63 | |
debe6624 | 64 | bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, |
484e45bf | 65 | const wxPoint &pos, const wxSize &size, |
6de97a3b | 66 | int style, const wxValidator& validator, const wxString &name ) |
c801d85f KB |
67 | { |
68 | m_needParent = TRUE; | |
484e45bf | 69 | |
c801d85f | 70 | PreCreation( parent, id, pos, size, style, name ); |
484e45bf | 71 | |
6de97a3b RR |
72 | SetValidator( validator ); |
73 | ||
13289f04 | 74 | bool bMultiLine = (style & wxTE_MULTILINE) != 0; |
5796ed40 | 75 | if ( bMultiLine ) |
47908e25 | 76 | { |
13289f04 VZ |
77 | // a multi-line edit control: create a vertical scrollbar by default and |
78 | // horizontal if requested | |
79 | bool bHasHScrollbar = (style & wxHSCROLL) != 0; | |
80 | ||
81 | // create our control... | |
c67daf87 | 82 | m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); |
13289f04 VZ |
83 | |
84 | // ... and put into the upper left hand corner of the table | |
85 | m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE); | |
86 | gtk_table_attach(GTK_TABLE(m_widget), m_text, 0, 1, 0, 1, | |
87 | GTK_FILL | GTK_EXPAND, | |
88 | GTK_FILL | GTK_EXPAND | GTK_SHRINK, | |
89 | 0, 0); | |
90 | ||
91 | // put the horizontal scrollbar in the lower left hand corner | |
903f689b RR |
92 | if (bHasHScrollbar) |
93 | { | |
13289f04 VZ |
94 | GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj); |
95 | gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2, | |
96 | GTK_EXPAND | GTK_FILL, | |
97 | GTK_FILL, | |
98 | 0, 0); | |
99 | gtk_widget_show(hscrollbar); | |
100 | } | |
101 | ||
102 | // finally, put the vertical scrollbar in the upper right corner | |
103 | GtkWidget *vscrollbar = gtk_vscrollbar_new(GTK_TEXT(m_text)->vadj); | |
104 | gtk_table_attach(GTK_TABLE(m_widget), vscrollbar, 1, 2, 0, 1, | |
105 | GTK_FILL, | |
106 | GTK_EXPAND | GTK_FILL | GTK_SHRINK, | |
107 | 0, 0); | |
903f689b | 108 | gtk_widget_show( vscrollbar ); |
13289f04 | 109 | } |
903f689b RR |
110 | else |
111 | { | |
13289f04 VZ |
112 | // a single-line text control: no need for scrollbars |
113 | m_widget = | |
114 | m_text = gtk_entry_new(); | |
115 | } | |
484e45bf | 116 | |
c801d85f KB |
117 | wxSize newSize = size; |
118 | if (newSize.x == -1) newSize.x = 80; | |
119 | if (newSize.y == -1) newSize.y = 26; | |
120 | SetSize( newSize.x, newSize.y ); | |
484e45bf | 121 | |
c801d85f | 122 | PostCreation(); |
484e45bf | 123 | |
903f689b RR |
124 | if (bMultiLine) |
125 | { | |
13289f04 VZ |
126 | gtk_widget_realize(m_text); |
127 | gtk_widget_show(m_text); | |
128 | } | |
129 | ||
484e45bf | 130 | // we want to be notified about text changes |
13289f04 | 131 | gtk_signal_connect(GTK_OBJECT(m_text), "changed", |
484e45bf VZ |
132 | GTK_SIGNAL_FUNC(gtk_text_changed_callback), |
133 | (gpointer)this); | |
134 | ||
7f4dc78d RR |
135 | if (!value.IsNull()) |
136 | { | |
137 | gint tmp = 0; | |
13289f04 | 138 | gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp ); |
6de97a3b | 139 | } |
484e45bf | 140 | |
5796ed40 | 141 | if (style & wxTE_READONLY) |
112892b9 RR |
142 | { |
143 | } | |
144 | else | |
145 | { | |
903f689b | 146 | if (bMultiLine) |
13289f04 | 147 | gtk_text_set_editable( GTK_TEXT(m_text), 1 ); |
6de97a3b | 148 | } |
484e45bf | 149 | |
c801d85f | 150 | Show( TRUE ); |
484e45bf | 151 | |
f96aa4d9 | 152 | SetBackgroundColour( parent->GetBackgroundColour() ); |
58614078 | 153 | SetForegroundColour( parent->GetForegroundColour() ); |
f96aa4d9 | 154 | |
c801d85f | 155 | return TRUE; |
6de97a3b | 156 | } |
c801d85f | 157 | |
03f38c58 | 158 | wxString wxTextCtrl::GetValue() const |
c801d85f | 159 | { |
a81258be RR |
160 | wxCHECK_MSG( m_text != NULL, "", "invalid text ctrl" ); |
161 | ||
c801d85f KB |
162 | wxString tmp; |
163 | if (m_windowStyle & wxTE_MULTILINE) | |
164 | { | |
13289f04 | 165 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
a81258be RR |
166 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); |
167 | tmp = text; | |
168 | g_free( text ); | |
c801d85f KB |
169 | } |
170 | else | |
171 | { | |
13289f04 | 172 | tmp = gtk_entry_get_text( GTK_ENTRY(m_text) ); |
6de97a3b | 173 | } |
c801d85f | 174 | return tmp; |
6de97a3b | 175 | } |
c801d85f KB |
176 | |
177 | void wxTextCtrl::SetValue( const wxString &value ) | |
178 | { | |
f96aa4d9 RR |
179 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
180 | ||
c801d85f KB |
181 | wxString tmp = ""; |
182 | if (!value.IsNull()) tmp = value; | |
183 | if (m_windowStyle & wxTE_MULTILINE) | |
184 | { | |
13289f04 VZ |
185 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
186 | gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len ); | |
c801d85f | 187 | len = 0; |
13289f04 | 188 | gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp, tmp.Length(), &len ); |
c801d85f KB |
189 | } |
190 | else | |
191 | { | |
13289f04 | 192 | gtk_entry_set_text( GTK_ENTRY(m_text), tmp ); |
6de97a3b RR |
193 | } |
194 | } | |
c801d85f KB |
195 | |
196 | void wxTextCtrl::WriteText( const wxString &text ) | |
197 | { | |
f96aa4d9 RR |
198 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
199 | ||
c801d85f | 200 | if (text.IsNull()) return; |
484e45bf | 201 | |
c801d85f KB |
202 | if (m_windowStyle & wxTE_MULTILINE) |
203 | { | |
13289f04 VZ |
204 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); |
205 | gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len ); | |
c801d85f KB |
206 | } |
207 | else | |
208 | { | |
13289f04 | 209 | gtk_entry_append_text( GTK_ENTRY(m_text), text ); |
6de97a3b RR |
210 | } |
211 | } | |
c801d85f | 212 | |
a81258be | 213 | bool wxTextCtrl::LoadFile( const wxString &file ) |
c801d85f | 214 | { |
a81258be RR |
215 | wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" ); |
216 | ||
217 | if (!wxFileExists(file)) return FALSE; | |
2ad3a34e | 218 | |
a81258be RR |
219 | Clear(); |
220 | ||
221 | FILE *fp = NULL; | |
222 | struct stat statb; | |
223 | ||
224 | if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || | |
225 | !(fp = fopen ((char*) (const char*) file, "r"))) | |
226 | { | |
227 | return FALSE; | |
228 | } | |
229 | else | |
230 | { | |
231 | gint len = statb.st_size; | |
232 | char *text; | |
233 | if (!(text = (char*)malloc ((unsigned) (len + 1)))) | |
234 | { | |
235 | fclose (fp); | |
236 | return FALSE; | |
237 | } | |
238 | if (fread (text, sizeof (char), len, fp) != (size_t) len) | |
239 | { | |
240 | } | |
241 | fclose (fp); | |
242 | ||
243 | text[len] = 0; | |
244 | ||
245 | if (m_windowStyle & wxTE_MULTILINE) | |
246 | { | |
247 | gtk_editable_insert_text( GTK_EDITABLE(m_text), text, 0, &len ); | |
248 | } | |
249 | else | |
250 | { | |
251 | gtk_entry_set_text( GTK_ENTRY(m_text), text ); | |
252 | } | |
253 | ||
254 | free (text); | |
255 | m_modified = FALSE; | |
256 | return TRUE; | |
257 | } | |
112892b9 | 258 | return FALSE; |
6de97a3b | 259 | } |
c801d85f | 260 | |
a81258be | 261 | bool wxTextCtrl::SaveFile( const wxString &file ) |
c801d85f | 262 | { |
a81258be RR |
263 | wxCHECK_MSG( m_text != NULL, FALSE, "invalid text ctrl" ); |
264 | ||
265 | if (file == "") return FALSE; | |
266 | ||
267 | FILE *fp; | |
2ad3a34e | 268 | |
a81258be RR |
269 | if (!(fp = fopen ((char*) (const char*) file, "w"))) |
270 | { | |
271 | return FALSE; | |
272 | } | |
273 | else | |
274 | { | |
275 | char *text = NULL; | |
276 | gint len = 0; | |
277 | ||
278 | if (m_windowStyle & wxTE_MULTILINE) | |
279 | { | |
280 | len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
281 | text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
282 | } | |
283 | else | |
284 | { | |
285 | text = gtk_entry_get_text( GTK_ENTRY(m_text) ); | |
286 | } | |
287 | ||
288 | if (fwrite (text, sizeof (char), len, fp) != (size_t) len) | |
289 | { | |
290 | // Did not write whole file | |
291 | } | |
292 | ||
293 | // Make sure newline terminates the file | |
294 | if (text[len - 1] != '\n') | |
295 | fputc ('\n', fp); | |
296 | ||
297 | fclose (fp); | |
298 | ||
299 | if (m_windowStyle & wxTE_MULTILINE) g_free( text ); | |
300 | ||
301 | m_modified = FALSE; | |
302 | return TRUE; | |
303 | } | |
304 | ||
305 | return TRUE; | |
6de97a3b | 306 | } |
c801d85f | 307 | |
debe6624 | 308 | wxString wxTextCtrl::GetLineText( long lineNo ) const |
c801d85f | 309 | { |
a81258be RR |
310 | if (m_windowStyle & wxTE_MULTILINE) |
311 | { | |
312 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
313 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
314 | ||
315 | if (text) | |
316 | { | |
317 | wxString buf(""); | |
318 | long i; | |
319 | int currentLine = 0; | |
320 | for (i = 0; currentLine != lineNo && text[i]; i++ ) | |
321 | if (text[i] == '\n') | |
322 | currentLine++; | |
323 | // Now get the text | |
324 | int j; | |
325 | for (j = 0; text[i] && text[i] != '\n'; i++, j++ ) | |
326 | buf += text[i]; | |
327 | ||
328 | g_free( text ); | |
329 | return buf; | |
330 | } | |
331 | else | |
332 | return wxEmptyString; | |
333 | } | |
334 | else | |
335 | { | |
336 | if (lineNo == 0) return GetValue(); | |
337 | return wxEmptyString; | |
338 | } | |
6de97a3b | 339 | } |
c801d85f | 340 | |
a81258be RR |
341 | void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) ) |
342 | { | |
c67d8618 | 343 | wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" ); |
a81258be | 344 | } |
112892b9 | 345 | |
a81258be | 346 | long wxTextCtrl::PositionToXY( long WXUNUSED(pos), long *WXUNUSED(x), long *WXUNUSED(y) ) const |
c801d85f | 347 | { |
a81258be RR |
348 | wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); |
349 | ||
350 | return 0; | |
6de97a3b | 351 | } |
c801d85f | 352 | |
a81258be | 353 | long wxTextCtrl::XYToPosition( long WXUNUSED(x), long WXUNUSED(y) ) const |
c801d85f | 354 | { |
a81258be RR |
355 | wxFAIL_MSG( "wxTextCtrl::XYToPosition not implemented" ); |
356 | ||
357 | return 0; | |
6de97a3b | 358 | } |
c801d85f | 359 | |
a81258be | 360 | int wxTextCtrl::GetLineLength(long lineNo) const |
c801d85f | 361 | { |
a81258be RR |
362 | wxString str = GetLineText (lineNo); |
363 | return (int) str.Length(); | |
6de97a3b | 364 | } |
c801d85f | 365 | |
a81258be | 366 | int wxTextCtrl::GetNumberOfLines() const |
c801d85f | 367 | { |
a81258be RR |
368 | if (m_windowStyle & wxTE_MULTILINE) |
369 | { | |
370 | gint len = gtk_text_get_length( GTK_TEXT(m_text) ); | |
371 | char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); | |
372 | ||
373 | if (text) | |
374 | { | |
375 | int currentLine = 0; | |
376 | for (int i = 0; i < len; i++ ) | |
377 | if (text[i] == '\n') | |
378 | currentLine++; | |
379 | ||
380 | g_free( text ); | |
381 | return currentLine; | |
382 | } | |
383 | else | |
384 | return 0; | |
385 | } | |
386 | else | |
387 | { | |
388 | return 1; | |
389 | } | |
6de97a3b | 390 | } |
c801d85f | 391 | |
debe6624 | 392 | void wxTextCtrl::SetInsertionPoint( long pos ) |
c801d85f | 393 | { |
a81258be RR |
394 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
395 | ||
c801d85f KB |
396 | int tmp = (int) pos; |
397 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 398 | gtk_text_set_point( GTK_TEXT(m_text), tmp ); |
c801d85f | 399 | else |
13289f04 | 400 | gtk_entry_set_position( GTK_ENTRY(m_text), tmp ); |
6de97a3b | 401 | } |
c801d85f | 402 | |
03f38c58 | 403 | void wxTextCtrl::SetInsertionPointEnd() |
c801d85f | 404 | { |
f96aa4d9 RR |
405 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
406 | ||
c801d85f KB |
407 | int pos = 0; |
408 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 409 | pos = gtk_text_get_length( GTK_TEXT(m_text) ); |
c801d85f | 410 | else |
13289f04 | 411 | pos = GTK_ENTRY(m_text)->text_length; |
c801d85f | 412 | SetInsertionPoint( pos-1 ); |
6de97a3b | 413 | } |
c801d85f | 414 | |
debe6624 | 415 | void wxTextCtrl::SetEditable( bool editable ) |
c801d85f | 416 | { |
f96aa4d9 RR |
417 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
418 | ||
c801d85f | 419 | if (m_windowStyle & wxTE_MULTILINE) |
13289f04 | 420 | gtk_text_set_editable( GTK_TEXT(m_text), editable ); |
c801d85f | 421 | else |
13289f04 | 422 | gtk_entry_set_editable( GTK_ENTRY(m_text), editable ); |
6de97a3b | 423 | } |
c801d85f | 424 | |
debe6624 | 425 | void wxTextCtrl::SetSelection( long from, long to ) |
c801d85f | 426 | { |
f96aa4d9 RR |
427 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
428 | ||
13289f04 | 429 | gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
6de97a3b | 430 | } |
c801d85f | 431 | |
debe6624 | 432 | void wxTextCtrl::ShowPosition( long WXUNUSED(pos) ) |
c801d85f | 433 | { |
f96aa4d9 | 434 | wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" ); |
6de97a3b | 435 | } |
c801d85f | 436 | |
03f38c58 | 437 | long wxTextCtrl::GetInsertionPoint() const |
c801d85f | 438 | { |
f96aa4d9 RR |
439 | wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" ); |
440 | ||
13289f04 | 441 | return (long) GTK_EDITABLE(m_text)->current_pos; |
6de97a3b | 442 | } |
c801d85f | 443 | |
03f38c58 | 444 | long wxTextCtrl::GetLastPosition() const |
c801d85f | 445 | { |
f96aa4d9 RR |
446 | wxCHECK_MSG( m_text != NULL, 0, "invalid text ctrl" ); |
447 | ||
c801d85f KB |
448 | int pos = 0; |
449 | if (m_windowStyle & wxTE_MULTILINE) | |
13289f04 | 450 | pos = gtk_text_get_length( GTK_TEXT(m_text) ); |
c801d85f | 451 | else |
13289f04 | 452 | pos = GTK_ENTRY(m_text)->text_length; |
c801d85f | 453 | return (long)pos-1; |
6de97a3b | 454 | } |
c801d85f | 455 | |
debe6624 | 456 | void wxTextCtrl::Remove( long from, long to ) |
c801d85f | 457 | { |
f96aa4d9 RR |
458 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
459 | ||
13289f04 | 460 | gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
6de97a3b | 461 | } |
c801d85f | 462 | |
debe6624 | 463 | void wxTextCtrl::Replace( long from, long to, const wxString &value ) |
c801d85f | 464 | { |
f96aa4d9 RR |
465 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
466 | ||
13289f04 | 467 | gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); |
c801d85f KB |
468 | if (value.IsNull()) return; |
469 | gint pos = (gint)to; | |
13289f04 | 470 | gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); |
6de97a3b | 471 | } |
c801d85f | 472 | |
03f38c58 | 473 | void wxTextCtrl::Cut() |
c801d85f | 474 | { |
f96aa4d9 RR |
475 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
476 | ||
75ed1d15 GL |
477 | #if (GTK_MINOR_VERSION == 1) |
478 | gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) ); | |
479 | #else | |
13289f04 | 480 | gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 481 | #endif |
6de97a3b | 482 | } |
c801d85f | 483 | |
03f38c58 | 484 | void wxTextCtrl::Copy() |
c801d85f | 485 | { |
f96aa4d9 RR |
486 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
487 | ||
75ed1d15 GL |
488 | #if (GTK_MINOR_VERSION == 1) |
489 | gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) ); | |
490 | #else | |
13289f04 | 491 | gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 492 | #endif |
6de97a3b | 493 | } |
c801d85f | 494 | |
03f38c58 | 495 | void wxTextCtrl::Paste() |
c801d85f | 496 | { |
f96aa4d9 RR |
497 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
498 | ||
75ed1d15 GL |
499 | #if (GTK_MINOR_VERSION == 1) |
500 | gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) ); | |
501 | #else | |
13289f04 | 502 | gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 ); |
75ed1d15 | 503 | #endif |
6de97a3b | 504 | } |
c801d85f | 505 | |
03f38c58 | 506 | void wxTextCtrl::Clear() |
c801d85f KB |
507 | { |
508 | SetValue( "" ); | |
6de97a3b | 509 | } |
c801d85f | 510 | |
903f689b | 511 | void wxTextCtrl::OnChar( wxKeyEvent &key_event ) |
c801d85f | 512 | { |
903f689b RR |
513 | if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER)) |
514 | { | |
515 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
516 | event.SetEventObject(this); | |
903f689b RR |
517 | if (GetEventHandler()->ProcessEvent(event)) return; |
518 | } | |
519 | else if (key_event.KeyCode() == WXK_TAB) | |
520 | { | |
521 | wxNavigationKeyEvent event; | |
522 | event.SetDirection( key_event.m_shiftDown ); | |
523 | event.SetWindowChange(FALSE); | |
524 | event.SetEventObject(this); | |
525 | ||
526 | if (GetEventHandler()->ProcessEvent(event)) return; | |
527 | } | |
528 | key_event.Skip(); | |
6de97a3b | 529 | } |
c801d85f | 530 | |
46dc76ba | 531 | int wxTextCtrl::overflow( int WXUNUSED(c) ) |
c801d85f | 532 | { |
c801d85f KB |
533 | int len = pptr() - pbase(); |
534 | char *txt = new char[len+1]; | |
535 | strncpy(txt, pbase(), len); | |
536 | txt[len] = '\0'; | |
537 | (*this) << txt; | |
538 | setp(pbase(), epptr()); | |
539 | delete[] txt; | |
540 | return EOF; | |
6de97a3b | 541 | } |
c801d85f | 542 | |
03f38c58 | 543 | int wxTextCtrl::sync() |
c801d85f | 544 | { |
c801d85f KB |
545 | int len = pptr() - pbase(); |
546 | char *txt = new char[len+1]; | |
547 | strncpy(txt, pbase(), len); | |
548 | txt[len] = '\0'; | |
549 | (*this) << txt; | |
550 | setp(pbase(), epptr()); | |
551 | delete[] txt; | |
552 | return 0; | |
6de97a3b | 553 | } |
c801d85f | 554 | |
03f38c58 | 555 | int wxTextCtrl::underflow() |
c801d85f KB |
556 | { |
557 | return EOF; | |
6de97a3b | 558 | } |
c801d85f KB |
559 | |
560 | wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) | |
561 | { | |
562 | WriteText(s); | |
563 | return *this; | |
564 | } | |
565 | ||
debe6624 | 566 | wxTextCtrl& wxTextCtrl::operator<<(float f) |
c801d85f KB |
567 | { |
568 | static char buf[100]; | |
569 | sprintf(buf, "%.2f", f); | |
570 | WriteText(buf); | |
571 | return *this; | |
572 | } | |
573 | ||
debe6624 | 574 | wxTextCtrl& wxTextCtrl::operator<<(double d) |
c801d85f KB |
575 | { |
576 | static char buf[100]; | |
577 | sprintf(buf, "%.2f", d); | |
578 | WriteText(buf); | |
579 | return *this; | |
580 | } | |
581 | ||
debe6624 | 582 | wxTextCtrl& wxTextCtrl::operator<<(int i) |
c801d85f KB |
583 | { |
584 | static char buf[100]; | |
585 | sprintf(buf, "%i", i); | |
586 | WriteText(buf); | |
587 | return *this; | |
588 | } | |
589 | ||
debe6624 | 590 | wxTextCtrl& wxTextCtrl::operator<<(long i) |
c801d85f KB |
591 | { |
592 | static char buf[100]; | |
593 | sprintf(buf, "%ld", i); | |
594 | WriteText(buf); | |
595 | return *this; | |
596 | } | |
597 | ||
598 | wxTextCtrl& wxTextCtrl::operator<<(const char c) | |
599 | { | |
600 | char buf[2]; | |
601 | ||
602 | buf[0] = c; | |
603 | buf[1] = 0; | |
604 | WriteText(buf); | |
605 | return *this; | |
606 | } | |
607 | ||
03f38c58 | 608 | GtkWidget* wxTextCtrl::GetConnectWidget() |
e3e65dac RR |
609 | { |
610 | return GTK_WIDGET(m_text); | |
6de97a3b | 611 | } |
e3e65dac | 612 | |
903f689b RR |
613 | bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window ) |
614 | { | |
615 | if (m_windowStyle & wxTE_MULTILINE) | |
616 | return (window == GTK_TEXT(m_text)->text_area); | |
617 | else | |
618 | return (window == GTK_ENTRY(m_text)->text_area); | |
619 | } | |
e3e65dac | 620 | |
58614078 | 621 | void wxTextCtrl::SetFont( const wxFont &WXUNUSED(font) ) |
868a2826 | 622 | { |
f96aa4d9 RR |
623 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); |
624 | ||
58614078 RR |
625 | // doesn't work |
626 | } | |
627 | ||
628 | void wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) ) | |
629 | { | |
630 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); | |
868a2826 | 631 | |
a81258be | 632 | // doesn't work |
868a2826 | 633 | } |
e3e65dac | 634 | |
68dda785 VZ |
635 | void wxTextCtrl::SetBackgroundColour( const wxColour &colour ) |
636 | { | |
637 | wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); | |
a81258be RR |
638 | |
639 | wxControl::SetBackgroundColour( colour ); | |
640 | ||
f96aa4d9 | 641 | if (!m_backgroundColour.Ok()) return; |
fc54776e | 642 | |
f96aa4d9 RR |
643 | if (m_windowStyle & wxTE_MULTILINE) |
644 | { | |
645 | GdkWindow *window = GTK_TEXT(m_text)->text_area; | |
646 | m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); | |
647 | gdk_window_set_background( window, m_backgroundColour.GetColor() ); | |
648 | gdk_window_clear( window ); | |
649 | } | |
58614078 RR |
650 | } |
651 | ||
652 | void wxTextCtrl::ApplyWidgetStyle() | |
653 | { | |
654 | if (m_windowStyle & wxTE_MULTILINE) | |
655 | { | |
656 | } | |
f96aa4d9 RR |
657 | else |
658 | { | |
58614078 | 659 | SetWidgetStyle(); |
a81258be | 660 | gtk_widget_set_style( m_text, m_widgetStyle ); |
f96aa4d9 | 661 | } |
68dda785 | 662 | } |
f96aa4d9 | 663 |